@yorab/react-paint 0.11.21 → 0.12.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/README.md +3 -1
- package/dist/canvas/components/Canvas.d.ts +10 -10
- package/dist/canvas/components/EditTextBox.d.ts +1 -2
- package/dist/canvas/constants/app.d.ts +12 -0
- package/dist/canvas/constants/zoom.d.ts +5 -0
- package/dist/canvas/hooks/useComponent.d.ts +4 -3
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +12 -8
- package/dist/canvas/hooks/usePinchZoomAndMove.d.ts +17 -0
- package/dist/canvas/hooks/useReactPaint.d.ts +40 -27
- package/dist/canvas/hooks/useResizeObserver.d.ts +1 -1
- package/dist/canvas/hooks/useShapes.d.ts +2 -2
- package/dist/canvas/hooks/useZoom.d.ts +21 -0
- package/dist/canvas/utils/file.d.ts +5 -1
- package/dist/canvas/utils/grid.d.ts +1 -1
- package/dist/canvas/utils/intersect.d.ts +9 -3
- package/dist/canvas/utils/shapes/index.d.ts +1 -0
- package/dist/canvas/utils/shapes/path.d.ts +1 -1
- package/dist/canvas/utils/shapes/picture.d.ts +1 -1
- package/dist/canvas/utils/shapes/rectangle.d.ts +1 -1
- package/dist/canvas/utils/transform.d.ts +1 -1
- package/dist/canvas/utils/trigo.d.ts +2 -0
- package/dist/canvas/utils/zoom.d.ts +58 -0
- package/dist/common/types/Canvas.d.ts +8 -0
- package/dist/common/types/Mode.d.ts +3 -1
- package/dist/common/utils/util.d.ts +2 -0
- package/dist/editor/components/common/Modal.d.ts +3 -2
- package/dist/editor/components/common/Panel.d.ts +3 -1
- package/dist/editor/components/settings/Layouts.d.ts +3 -2
- package/dist/editor/components/settings/SettingsBar.d.ts +6 -3
- package/dist/editor/components/settings/ZoomButton.d.ts +8 -0
- package/dist/editor/components/toolbox/ExportModal.d.ts +7 -0
- package/dist/editor/components/toolbox/MenuGroup.d.ts +3 -3
- package/dist/editor/components/toolbox/Toolbar.d.ts +5 -5
- package/dist/editor/constants/icons.d.ts +4 -4
- package/dist/editor/hooks/useDrag.d.ts +2 -2
- package/dist/react-paint.css +1 -1
- package/dist/react-paint.js +1168 -1021
- package/dist/react-paint.umd.cjs +1 -1
- package/package.json +18 -23
package/dist/react-paint.js
CHANGED
|
@@ -1,509 +1,538 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { jsx as p, jsxs as R, Fragment as
|
|
3
|
-
const Ii = '<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>', Rt = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', It = '<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>', Wt = '<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>', Wi = '<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>', qt = '<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>', zt = '<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>', zi = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', Oi = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', $i = '<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>', Jt = '<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>', Kt = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', ei = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', ti = '<svg><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM10 16.583Q10.896 16.583 11.708 16.365Q12.521 16.146 13.25 15.729L4.292 6.75Q3.875 7.479 3.646 8.292Q3.417 9.104 3.417 10Q3.417 12.729 5.344 14.656Q7.271 16.583 10 16.583ZM17 14.562 15.708 13.271Q16.125 12.542 16.354 11.719Q16.583 10.896 16.583 10Q16.583 7.271 14.656 5.344Q12.729 3.417 10 3.417Q9.104 3.417 8.292 3.646Q7.479 3.875 6.75 4.292L5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562ZM11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771Q11.229 8.771 11.229 8.771ZM8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Q8.771 11.229 8.771 11.229Z"/></svg>', ii = '<svg ><path d="M16.354 18.833 14.521 17Q13.542 17.646 12.396 17.99Q11.25 18.333 10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.729 2.01 7.594Q2.354 6.458 3 5.458L1.167 3.625L2.396 2.396L17.583 17.604ZM17 14.562 5.458 3Q6.458 2.354 7.594 2.01Q8.729 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.271 17.979 12.417Q17.625 13.562 17 14.562Z"/></svg>', ce = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Fe = [0, 1, 2], ni = [[1, 0], [1, 2], [4, 6]], rt = "serif", b1 = 2, Ui = 3, C1 = 4, ee = "react-paint-", Ot = { type: "picture", id: `${ee}picture`, icon: zt, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, Bi = { type: "brush", id: `${ee}brush`, icon: Ii, label: "Brosse", settings: { strokeColor: { values: ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Fe, default: 0 } } }, Gi = { type: "line", id: `${ee}line`, icon: Oi, label: "Ligne", settings: { strokeColor: { values: ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, Xi = { type: "polygon", id: `${ee}polygon`, icon: Wt, label: "Polygone", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 }, pointsCount: { min: 3, max: 10, step: 1, default: 3 } } }, Yi = { type: "curve", id: `${ee}curve`, icon: $i, label: "Courbe", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 }, pointsCount: { min: 3, max: 10, step: 1, default: 3 } } }, ji = { type: "rect", id: `${ee}rect`, icon: Rt, label: "Rectangle", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 } } }, _i = { type: "square", id: `${ee}square`, icon: Rt, label: "Carré", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 } } }, qi = { type: "circle", id: `${ee}circle`, icon: It, label: "Cercle", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 } } }, Ji = { type: "ellipse", id: `${ee}ellipse`, icon: It, label: "Ellipse", settings: { strokeColor: { values: ce, default: "black" }, fillColor: { values: ce, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Fe, default: 0 } } }, Ki = { type: "text", id: `${ee}text`, icon: zi, label: "Texte", settings: { strokeColor: { values: ce, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: rt }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Ae = { id: `${ee}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" }, Xe = { id: `${ee}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" }, Ye = { id: `${ee}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" }, je = { id: `${ee}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" }, kt = { id: `${ee}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" }, ai = { id: `${ee}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" }, Lt = { id: `${ee}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" }, si = { id: `${ee}upload-picture`, type: "uploadpicture", icon: zt, label: "Upload picture" }, e1 = 2, t1 = "blue", Te = 14, i1 = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], n1 = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle"], a1 = "react-paint-canvas-drawcanvas", s1 = "react-paint-canvas-selectioncanvas", oi = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [Bi, Gi, Xi, Yi, ji, _i, qi, Ji, Ot, Ki], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !1, withSkeleton: !0, canvasSelectionPadding: 0 }, w1 = { canvasBackgroundColor: "white", canvasSelectionColor: t1, canvasSelectionWidth: e1 }, o1 = (e, i) => !!(e.target instanceof Node && i) && i.contains(e.target), ut = 300, Zt = (e, i) => {
|
|
4
|
-
const
|
|
5
|
-
for (const n of e) delete
|
|
6
|
-
return
|
|
7
|
-
},
|
|
8
|
-
const n = Array.isArray(
|
|
9
|
-
return s.reduce((a,
|
|
10
|
-
},
|
|
11
|
-
if (!
|
|
12
|
-
const n = { ...
|
|
13
|
-
for (const s in
|
|
1
|
+
import _i, { useState as F, useEffect as q, useRef as G, useCallback as D, useMemo as ji, useImperativeHandle as Un, useTransition as Ki } from "react";
|
|
2
|
+
import { jsx as p, jsxs as R, Fragment as Se } from "react/jsx-runtime";
|
|
3
|
+
const Ji = '<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>', Kt = '<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>', Jt = '<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>', ei = '<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>', en = '<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>', di = '<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>', ti = '<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>', tn = '<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>', nn = '<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>', an = '<svg><path d="M7.521 17.5Q6.125 17.5 5.146 16.51Q4.167 15.521 4.167 14.125V7.417Q3.438 7.125 2.969 6.49Q2.5 5.854 2.5 5.042Q2.5 3.979 3.24 3.24Q3.979 2.5 5.042 2.5Q6.104 2.5 6.844 3.24Q7.583 3.979 7.583 5.042Q7.583 5.854 7.115 6.49Q6.646 7.125 5.917 7.417V14.125Q5.917 14.792 6.385 15.271Q6.854 15.75 7.521 15.75Q8.188 15.75 8.656 15.271Q9.125 14.792 9.125 14.125V5.875Q9.125 4.479 10.104 3.49Q11.083 2.5 12.479 2.5Q13.875 2.5 14.854 3.49Q15.833 4.479 15.833 5.875V12.583Q16.562 12.875 17.031 13.51Q17.5 14.146 17.5 14.958Q17.5 16.021 16.76 16.76Q16.021 17.5 14.958 17.5Q13.896 17.5 13.156 16.76Q12.417 16.021 12.417 14.958Q12.417 14.146 12.885 13.5Q13.354 12.854 14.083 12.583V5.875Q14.083 5.208 13.615 4.729Q13.146 4.25 12.479 4.25Q11.812 4.25 11.344 4.729Q10.875 5.208 10.875 5.875V14.125Q10.875 15.521 9.896 16.51Q8.917 17.5 7.521 17.5Z"/></svg>', hi = '<svg><path d="M5.833 15V3.333H10.375Q11.812 3.333 12.885 4.156Q13.958 4.979 13.958 6.375Q13.958 7.375 13.49 7.969Q13.021 8.562 12.396 8.875V9.042Q13.312 9.354 13.844 10.021Q14.375 10.688 14.375 11.75Q14.375 13.312 13.229 14.156Q12.083 15 10.5 15ZM8.125 8.042H10.188Q10.854 8.042 11.302 7.656Q11.75 7.271 11.75 6.708Q11.75 6.167 11.302 5.771Q10.854 5.375 10.188 5.375H8.125ZM8.125 12.917H10.354Q11.167 12.917 11.625 12.51Q12.083 12.104 12.083 11.458Q12.083 10.812 11.625 10.406Q11.167 10 10.354 10H8.125Z"/></svg>', ui = '<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>', pi = '<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>', gi = '<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>', fi = '<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>', sn = '<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>', he = ["transparent", "black", "white", "red", "green", "blue", "yellow"], Re = [0, 1, 2], vi = [[1, 0], [1, 2], [4, 6]], ht = "serif", Xn = 2, on = 3, Yn = 4, ee = "react-paint-", ii = { type: "picture", id: `${ee}picture`, icon: ti, label: "Image", settings: { opacity: { min: 0, max: 100, step: 1, default: 100 } } }, rn = { type: "brush", id: `${ee}brush`, icon: Ji, label: "Brosse", settings: { strokeColor: { values: he, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 6, max: 20, step: 2, default: 10 }, lineDash: { values: Re, default: 0 } } }, ln = { type: "line", id: `${ee}line`, icon: nn, label: "Ligne", settings: { strokeColor: { values: he, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 }, lineArrow: { values: [0, 1, 2, 3], default: 0 } } }, cn = { type: "polygon", id: `${ee}polygon`, icon: ei, label: "Polygone", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 }, pointsCount: { min: 3, max: 10, step: 1, default: 3 } } }, dn = { type: "curve", id: `${ee}curve`, icon: an, label: "Courbe", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 }, pointsCount: { min: 3, max: 10, step: 1, default: 3 } } }, hn = { type: "rect", id: `${ee}rect`, icon: Kt, label: "Rectangle", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 } } }, un = { type: "square", id: `${ee}square`, icon: Kt, label: "Carré", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 } } }, pn = { type: "circle", id: `${ee}circle`, icon: Jt, label: "Cercle", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 } } }, gn = { type: "ellipse", id: `${ee}ellipse`, icon: Jt, label: "Ellipse", settings: { strokeColor: { values: he, default: "black" }, fillColor: { values: he, default: "transparent" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, lineWidth: { min: 1, max: 20, step: 1, default: 1 }, lineDash: { values: Re, default: 0 } } }, fn = { type: "text", id: `${ee}text`, icon: tn, label: "Texte", settings: { strokeColor: { values: he, default: "black" }, opacity: { min: 0, max: 100, step: 1, default: 100 }, fontFamily: { values: ["arial", "serif", "monospace"], default: ht }, fontBold: { values: [!1, !0], default: !1 }, fontItalic: { values: [!1, !0], default: !1 } } }, Ze = { id: `${ee}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" }, _e = { id: `${ee}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" }, je = { id: `${ee}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" }, Ke = { id: `${ee}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" }, Et = { id: `${ee}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" }, mi = { id: `${ee}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" }, Dt = { id: `${ee}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" }, Wt = { id: `${ee}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" }, yi = { id: `${ee}upload-picture`, type: "uploadpicture", icon: ti, label: "Upload picture" }, vn = 2, mn = "blue", Ve = 14, yn = [[0, 0], [0.5, 0], [1, 0], [1, 0.5], [1, 1], [0.5, 1], [0, 1], [0, 0.5]], Qn = ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle"], Sn = "react-paint-canvas-drawcanvas", bn = "react-paint-canvas-selectioncanvas", Qi = { layersManipulation: !0, grid: 0, canGrow: !1, canShrink: !0, withExport: !0, withLoadAndSave: !0, withUploadPicture: !0, withUrlPicture: !1, availableTools: [rn, ln, cn, dn, hn, un, pn, gn, ii, fn], clearCallback: "empty", brushAlgo: "simple", isBrushShapeDoneOnMouseUp: !0, withFrameSelection: !1, withSkeleton: !0, canvasSelectionPadding: 0, size: "fixed", canZoom: "never" }, qn = { canvasBackgroundColor: "white", canvasSelectionColor: mn, canvasSelectionWidth: vn }, Cn = (e, t) => !!(e.target instanceof Node && t) && t.contains(e.target), Qt = 300, Ut = (e, t) => {
|
|
4
|
+
const i = { ...t };
|
|
5
|
+
for (const n of e) delete i[n];
|
|
6
|
+
return i;
|
|
7
|
+
}, fe = (e, t, i) => {
|
|
8
|
+
const n = Array.isArray(i) ? [...i] : { ...i }, s = Array.isArray(e) ? e : typeof e == "string" ? e.split(".") : [e];
|
|
9
|
+
return s.reduce((a, o, r) => (a[o] = Xt(a[o]) ? { ...a[o] } : Array.isArray(a[o]) ? [...a[o]] : a[o] === void 0 || a[o] === null ? {} : a[o], r === s.length - 1 && (a[o] = t), a[o]), n), n;
|
|
10
|
+
}, Xt = (e) => typeof e == "object" && !Array.isArray(e) && e !== null, He = (e, t, i) => {
|
|
11
|
+
if (!Xt(t) || !Xt(i)) return i;
|
|
12
|
+
const n = { ...t };
|
|
13
|
+
for (const s in i) i.hasOwnProperty(s) && (n.hasOwnProperty(s) ? n[s] = e(n[s], i[s], s) ?? He(e, n[s], i[s]) : n[s] = i[s]);
|
|
14
14
|
return n;
|
|
15
|
-
},
|
|
16
|
-
if (e ===
|
|
17
|
-
if (typeof e != "object" || typeof
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
for (const s of
|
|
15
|
+
}, wn = (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 s of i) if (!n.includes(s) || !wn(e[s], t[s])) return !1;
|
|
21
21
|
return !0;
|
|
22
|
-
},
|
|
23
|
-
e.lineCap = "round", e.lineJoin = "round";
|
|
24
|
-
},
|
|
25
|
-
const { lineCap:
|
|
26
|
-
e.lineCap =
|
|
27
|
-
},
|
|
28
|
-
e.save(), e.scale(
|
|
29
|
-
},
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
},
|
|
33
|
-
const
|
|
34
|
-
return
|
|
35
|
-
},
|
|
36
|
-
const
|
|
37
|
-
return
|
|
38
|
-
},
|
|
39
|
-
const
|
|
40
|
-
return
|
|
41
|
-
},
|
|
42
|
-
const
|
|
43
|
-
return
|
|
44
|
-
},
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (!c.length) return;
|
|
50
|
-
if (c.length === 1) d.rect(...Qe(c[0], l, h, n.scaleX, n.scaleY), 1, 1);
|
|
51
|
-
else if (d.moveTo(...Qe(c[0], l, h, n.scaleX, n.scaleY)), s === "quadratic") {
|
|
52
|
-
for (let u = 0; u < c.slice(1).length - 2; u++) {
|
|
53
|
-
const g = Qe(c[u], l, h, n.scaleX, n.scaleY), f = Qe(c[u + 1], l, h, n.scaleX, n.scaleY), x = (g[0] + f[0]) / 2, w = (g[1] + f[1]) / 2;
|
|
54
|
-
d.quadraticCurveTo(...g, x, w);
|
|
55
|
-
}
|
|
56
|
-
d.quadraticCurveTo(...Qe(c[c.length - 2], l, h, n.scaleX, n.scaleY), ...Qe(c[c.length - 1], l, h, n.scaleX, n.scaleY));
|
|
57
|
-
} else for (const u of c.slice(1)) d.lineTo(...Qe(u, l, h, n.scaleX, n.scaleY));
|
|
58
|
-
}
|
|
59
|
-
return d;
|
|
60
|
-
})(e, i);
|
|
61
|
-
return { ...e, path: t, selection: Ke(t, e, i) };
|
|
62
|
-
}, M1 = Je, Ft = (e) => 180 * e / Math.PI, d1 = (e, i) => {
|
|
63
|
-
const t = i.x - Math.min(Math.max(i.x, e.x), e.x + e.width), n = i.y - Math.min(Math.max(i.y, e.y), e.y + e.height);
|
|
64
|
-
return Math.sqrt(t * t + n * n) <= i.radius;
|
|
65
|
-
}, ve = ({ origin: e = [0, 0], point: i, rotation: t }) => {
|
|
66
|
-
const n = [i[0] - e[0], i[1] - e[1]], s = n[1] * Math.cos(t) - n[0] * Math.sin(t);
|
|
67
|
-
return [n[1] * Math.sin(t) + n[0] * Math.cos(t) + e[0], s + e[1]];
|
|
68
|
-
}, ri = (e) => (e + 2 * Math.PI) % (2 * Math.PI), li = ({ targetVector: [e, i], radian: t = !0, originVector: n }) => {
|
|
69
|
-
const s = ri(Math.atan2(i[1] - e[1], i[0] - e[0]));
|
|
22
|
+
}, Rt = {}, le = (e = "") => (Rt[e] || (Rt[e] = 0), `${e}${++Rt[e]}`), We = (e, t, i) => Math.max(t, Math.min(e, i)), xn = (e) => {
|
|
23
|
+
e.reset(), e.lineCap = "round", e.lineJoin = "round";
|
|
24
|
+
}, $e = (e, t = {}) => {
|
|
25
|
+
const { lineCap: i = "round", fillColor: n = "transparent", opacity: s = 100, strokeColor: a = mn, lineWidth: o = vn, lineDash: r = 0 } = t;
|
|
26
|
+
e.lineCap = i, e.globalAlpha = s / 100, e.fillStyle = n, e.strokeStyle = a, e.lineWidth = o, e.setLineDash(r === 0 ? [] : [vi[r][0] * o, vi[r][1] * o]);
|
|
27
|
+
}, ni = (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
|
+
}, St = (e) => {
|
|
30
|
+
const t = new Path2D();
|
|
31
|
+
return t.rect(e.x, e.y, e.width, e.height), t;
|
|
32
|
+
}, bt = (e) => {
|
|
33
|
+
const t = new Path2D();
|
|
34
|
+
return t.arc(e.x, e.y, e.radius, 0, 2 * Math.PI), t;
|
|
35
|
+
}, Yt = (e) => {
|
|
36
|
+
const t = new Path2D();
|
|
37
|
+
return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t;
|
|
38
|
+
}, Gn = (e) => {
|
|
39
|
+
const t = new Path2D();
|
|
40
|
+
return t.moveTo(...e.points[0]), t.lineTo(...e.points[1]), t.lineTo(...e.points[2]), t.lineTo(...e.points[0]), t;
|
|
41
|
+
}, qt = (e) => 180 * e / Math.PI, Mn = (e, t) => {
|
|
42
|
+
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);
|
|
43
|
+
return Math.sqrt(i * i + n * n) <= t.radius;
|
|
44
|
+
}, me = ({ origin: e = [0, 0], point: t, rotation: i }) => {
|
|
45
|
+
const n = [t[0] - e[0], t[1] - e[1]], s = n[1] * Math.cos(i) - n[0] * Math.sin(i);
|
|
46
|
+
return [n[1] * Math.sin(i) + n[0] * Math.cos(i) + e[0], s + e[1]];
|
|
47
|
+
}, Si = (e) => (e + 2 * Math.PI) % (2 * Math.PI), bi = ({ targetVector: [e, t], radian: i = !0, originVector: n }) => {
|
|
48
|
+
const s = Si(Math.atan2(t[1] - e[1], t[0] - e[0]));
|
|
70
49
|
if (n) {
|
|
71
|
-
const [a,
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
return t ? s : Ft(s);
|
|
75
|
-
}, De = (e, i = 2) => Math.round(e * 10 ** i) / 10 ** i, Qe = (e, i, t, n = 1, s = 1) => [i + (e[0] - i) * n, t + (e[1] - t) * s], B = (e, i, t = 0) => {
|
|
76
|
-
if (!i.gridGap) return De(e);
|
|
77
|
-
const n = e + t, s = n >= 0 ? i.gridGap : -i.gridGap;
|
|
78
|
-
return n + s / 2 - (n + s / 2) % s - t;
|
|
79
|
-
}, k1 = (e, i, t = 0) => i.gridGap ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : De(e, 3), L1 = (e, i, t, n, s, a) => {
|
|
80
|
-
switch (n.mode) {
|
|
81
|
-
case "brush":
|
|
82
|
-
return ((r, o, l) => {
|
|
83
|
-
const h = { ...r, points: de(r.points.length - 1, [...r.points[r.points.length - 1], [Math.round(o[0]), Math.round(o[1])]], r.points) };
|
|
84
|
-
return Je(h, l);
|
|
85
|
-
})(i, t, s);
|
|
86
|
-
case "translate":
|
|
87
|
-
return Nt(t, n.originalShape, n.cursorStartPosition, s);
|
|
88
|
-
case "rotate":
|
|
89
|
-
return O1(i, t, n.originalShape, n.cursorStartPosition, n.center, s);
|
|
90
|
-
case "resize":
|
|
91
|
-
return $1(e, i, t, n.originalShape, n, s, a);
|
|
92
|
-
default:
|
|
93
|
-
return i;
|
|
50
|
+
const [a, o] = n, r = Math.atan2(o[1] - a[1], o[0] - a[0]), l = Si(s - r);
|
|
51
|
+
return i ? l : qt(l);
|
|
94
52
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
53
|
+
return i ? s : qt(s);
|
|
54
|
+
}, kn = (e, t) => Math.sqrt((e[0] - t[0]) ** 2 + (e[1] - t[1]) ** 2), tt = (e, t, i) => {
|
|
55
|
+
const { borders: n } = K(t, i);
|
|
56
|
+
return { border: St(n), shapePath: e, line: Yt({ points: [[n.x + n.width / 2, n.y], [n.x + n.width / 2, n.y - 23 / i.canvasSize.scaleRatio]] }), anchors: [bt({ x: n.x + n.width / 2, y: n.y - 23 / i.canvasSize.scaleRatio, radius: 7 / i.canvasSize.scaleRatio }), ...yn.map((s) => bt({ x: n.x + n.width * s[0], y: n.y + n.height * s[1], radius: 7 / i.canvasSize.scaleRatio }))] };
|
|
57
|
+
}, Ci = ({ borderStart: e, borderSize: t, vector: i, settings: n, invertedAxe: s, anchor: a }) => {
|
|
99
58
|
switch (a) {
|
|
100
59
|
case 0: {
|
|
101
60
|
if (s) {
|
|
102
|
-
const
|
|
103
|
-
return [e +
|
|
61
|
+
const r = t - 2 * n.selectionPadding;
|
|
62
|
+
return [e + r, i - r];
|
|
104
63
|
}
|
|
105
|
-
const
|
|
106
|
-
return [e +
|
|
64
|
+
const o = Math.max(2 * n.selectionPadding, t - i);
|
|
65
|
+
return [e + t - o, o];
|
|
107
66
|
}
|
|
108
67
|
case 0.5:
|
|
109
|
-
return [e,
|
|
68
|
+
return [e, t];
|
|
110
69
|
case 1:
|
|
111
70
|
if (s) {
|
|
112
|
-
const
|
|
113
|
-
return [e +
|
|
71
|
+
const o = t + i;
|
|
72
|
+
return [e + o, 2 * n.selectionPadding - o];
|
|
114
73
|
}
|
|
115
|
-
return [e, Math.max(2 * n.selectionPadding,
|
|
74
|
+
return [e, Math.max(2 * n.selectionPadding, t + i)];
|
|
116
75
|
default:
|
|
117
76
|
return [0, 0];
|
|
118
77
|
}
|
|
119
|
-
},
|
|
120
|
-
const
|
|
121
|
-
return { borderX: De(e +
|
|
122
|
-
}, Ge = (e,
|
|
123
|
-
const { center: a, borders:
|
|
78
|
+
}, wi = ({ borderX: e, borderWidth: t, borderY: i, borderHeight: n, center: s, originalShape: a }) => {
|
|
79
|
+
const o = [e + t / 2 - s[0], i + n / 2 - s[1]], [r, l] = me({ point: o, rotation: -a.rotation });
|
|
80
|
+
return { borderX: De(e + r - o[0]), borderWidth: De(t), borderY: De(i + l - o[1]), borderHeight: De(n) };
|
|
81
|
+
}, Ge = (e, t, i, n, s = !1) => {
|
|
82
|
+
const { center: a, borders: o } = K(t, n), r = me({ origin: a, point: e, rotation: t.rotation }), l = i.anchor[0] === 0 && r[0] >= o.x + o.width || i.anchor[0] === 1 && r[0] <= o.x, d = i.anchor[1] === 0 && r[1] >= o.y + o.height || i.anchor[1] === 1 && r[1] <= o.y, c = [U(r[0], n, i.anchor[0] === 0 && !l || i.anchor[0] === 1 && l ? n.selectionPadding : -n.selectionPadding), U(r[1], n, i.anchor[1] === 0 && !d || i.anchor[1] === 1 && d ? n.selectionPadding : -n.selectionPadding)], h = n.gridGap ? [i.anchor[0] === 0 ? o.x : i.anchor[0] === 0.5 ? o.x + o.width / 2 : o.x + o.width, i.anchor[1] === 0 ? o.y : i.anchor[1] === 0.5 ? o.y + o.height / 2 : o.y + o.height] : me({ origin: a, point: i.cursorStartPosition, rotation: t.rotation }), u = [c[0] - h[0], c[1] - h[1]], [f, v] = Ci({ borderStart: o.x, borderSize: o.width, vector: u[0], settings: n, invertedAxe: l, anchor: i.anchor[0] }), [k, C] = Ci({ borderStart: o.y, borderSize: o.height, vector: u[1], settings: n, invertedAxe: d, anchor: i.anchor[1] });
|
|
124
83
|
if (s) {
|
|
125
|
-
const
|
|
126
|
-
const { selectionPadding: y } =
|
|
127
|
-
let
|
|
128
|
-
return
|
|
129
|
-
})(u,
|
|
130
|
-
return
|
|
84
|
+
const b = ((Q, w, M, L, Z, z, T, $, H, N) => {
|
|
85
|
+
const { selectionPadding: y } = N, E = (w.width - 2 * y || 1) / (w.height - 2 * y || 1), B = (Z - 2 * y) / (T - 2 * y);
|
|
86
|
+
let x, V, m, g;
|
|
87
|
+
return H.anchor[0] !== 0.5 && H.anchor[1] !== 0.5 ? B < E ? (V = z, g = T, m = (T - 2 * y) * E + 2 * y, x = H.anchor[0] === 0 ? w.width - Q[0] > y ? w.x + (w.width - m) : w.x + w.width - 2 * y : w.width + Q[0] > y ? w.x : w.x - m + 2 * y) : (x = L, m = Z, g = (Z - 2 * y) / E + 2 * y, V = H.anchor[1] === 0 ? w.height - Q[1] > y ? w.y + (w.height - g) : w.y + w.height - 2 * y : w.height + Q[1] > y ? w.y : w.y - g + 2 * y) : H.anchor[0] !== 0.5 ? (x = L, m = Z, g = (Z - 2 * y) / E + 2 * y, V = w.y + (w.height - g) / 2) : (V = z, g = T, m = (T - 2 * y) * E + 2 * y, x = w.x + (w.width - m) / 2), { borderX: x, borderWidth: m, borderY: V, borderHeight: g, center: M, originalShape: $ };
|
|
88
|
+
})(u, o, a, f, v, k, C, t, i, n);
|
|
89
|
+
return wi(b);
|
|
90
|
+
}
|
|
91
|
+
return wi({ borderX: f, borderWidth: v, borderY: k, borderHeight: C, center: a, originalShape: t });
|
|
92
|
+
}, it = (e, t) => {
|
|
93
|
+
const i = ((n, { brushAlgo: s }) => {
|
|
94
|
+
if (n.points.length < 1 || n.style?.strokeColor === "transparent") return;
|
|
95
|
+
const a = n.points.flat(), o = a.map((h) => h[0]), r = a.map((h) => h[1]), l = Math.min(...o), d = Math.min(...r), c = new Path2D();
|
|
96
|
+
for (const h of n.points) {
|
|
97
|
+
if (!h.length) return;
|
|
98
|
+
if (h.length === 1) c.rect(...Ce(h[0], l, d, n.scaleX, n.scaleY), 1, 1);
|
|
99
|
+
else if (c.moveTo(...Ce(h[0], l, d, n.scaleX, n.scaleY)), s === "quadratic") {
|
|
100
|
+
for (let u = 0; u < h.slice(1).length - 2; u++) {
|
|
101
|
+
const f = Ce(h[u], l, d, n.scaleX, n.scaleY), v = Ce(h[u + 1], l, d, n.scaleX, n.scaleY), k = (f[0] + v[0]) / 2, C = (f[1] + v[1]) / 2;
|
|
102
|
+
c.quadraticCurveTo(...f, k, C);
|
|
103
|
+
}
|
|
104
|
+
c.quadraticCurveTo(...Ce(h[h.length - 2], l, d, n.scaleX, n.scaleY), ...Ce(h[h.length - 1], l, d, n.scaleX, n.scaleY));
|
|
105
|
+
} else for (const u of h.slice(1)) c.lineTo(...Ce(u, l, d, n.scaleX, n.scaleY));
|
|
106
|
+
}
|
|
107
|
+
return c;
|
|
108
|
+
})(e, t);
|
|
109
|
+
return { ...e, path: i, selection: tt(i, e, t) };
|
|
110
|
+
}, _n = it, De = (e, t = 2) => Math.round(e * 10 ** t) / 10 ** t, Ce = (e, t, i, n = 1, s = 1) => [t + (e[0] - t) * n, i + (e[1] - i) * s], U = (e, t, i = 0) => {
|
|
111
|
+
if (!t.gridGap) return De(e);
|
|
112
|
+
const n = e + i, s = n >= 0 ? t.gridGap : -t.gridGap;
|
|
113
|
+
return n + s / 2 - (n + s / 2) % s - i;
|
|
114
|
+
}, jn = (e, t) => t.gridGap ? e + Math.PI / 18 / 2 - (e + Math.PI / 18 / 2) % (Math.PI / 18) : De(e, 3), Kn = (e, t, i, n, s, a) => {
|
|
115
|
+
switch (n.mode) {
|
|
116
|
+
case "brush":
|
|
117
|
+
return ((o, r, l) => {
|
|
118
|
+
const d = { ...o, points: fe(o.points.length - 1, [...o.points[o.points.length - 1], [Math.round(r[0]), Math.round(r[1])]], o.points) };
|
|
119
|
+
return it(d, l);
|
|
120
|
+
})(t, i, s);
|
|
121
|
+
case "translate":
|
|
122
|
+
return jt(i, n.originalShape, n.cursorStartPosition, s);
|
|
123
|
+
case "rotate":
|
|
124
|
+
return ga(t, i, n.originalShape, n.cursorStartPosition, n.center, s);
|
|
125
|
+
case "resize":
|
|
126
|
+
return fa(e, t, i, n.originalShape, n, s, a);
|
|
127
|
+
default:
|
|
128
|
+
return t;
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}, hi = (e) => "touches" in e, Oe = (e, i, [t, n], [s, a]) => ve({ origin: [t - s, n - a], point: e, rotation: i }), dt = (e, i, t) => t ? d1(e, { x: i[0], y: i[1], radius: t }) : ((n, s) => s[0] >= n.x && s[0] <= n.x + n.width && s[1] >= n.y && s[1] <= n.y + n.height)(e, i), st = (e, i, t, n = !1, s = 0) => {
|
|
130
|
+
}, Ln = (e) => {
|
|
131
|
+
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 : {};
|
|
132
|
+
return { clientX: t, clientY: i };
|
|
133
|
+
}, Nt = (e, t, i) => {
|
|
134
|
+
const { clientX: n, clientY: s } = Ln(e), a = t?.getBoundingClientRect() ?? { left: 0, top: 0, width: i.canvasSize.width, height: i.canvasSize.height };
|
|
135
|
+
return [(n - a.left) * (i.canvasSize.width / a.width) / i.canvasSize.scaleRatio - i.canvasOffset[0], (s - a.top) * (i.canvasSize.height / a.height) / i.canvasSize.scaleRatio - i.canvasOffset[1]];
|
|
136
|
+
}, rt = (e) => "touches" in e, Be = (e, t, [i, n]) => me({ origin: [i, n], point: e, rotation: t }), ft = (e, t, i) => i ? Mn(e, { x: t[0], y: t[1], radius: i }) : ((n, s) => s[0] >= n.x && s[0] <= n.x + n.width && s[1] >= n.y && s[1] <= n.y + n.height)(e, t), ct = (e, t, i, n = !1, s = 0) => {
|
|
140
137
|
if (e.locked) return !1;
|
|
141
|
-
const { canvasSize: { scaleRatio: a } } =
|
|
138
|
+
const { canvasSize: { scaleRatio: a } } = i, { borders: o, center: r } = K(e, i), l = Be(t, e.rotation, r);
|
|
142
139
|
if (n) if (e.type === "line" || e.type === "polygon" || e.type === "curve") {
|
|
143
|
-
for (let
|
|
140
|
+
for (let d = 0; d < e.points.length; d++) if (ft({ x: e.points[d][0] - 7 / a, y: e.points[d][1] - 7 / a, width: Ve / a, height: Ve / a }, l, s)) return { mode: "resize", anchor: d };
|
|
144
141
|
} else {
|
|
145
|
-
if (
|
|
146
|
-
for (const
|
|
142
|
+
if (ft({ x: o.x + o.width / 2 - 7 / a, y: o.y - Ve / a - 16 / a, width: Ve / a, height: Ve / a }, l, s)) return { mode: "rotate" };
|
|
143
|
+
for (const d of yn) if (ft({ x: o.x + o.width * d[0] - 7 / a, y: o.y + o.height * d[1] - 7 / a, width: Ve / a, height: Ve / a }, l, s)) return { mode: "resize", anchor: d };
|
|
147
144
|
}
|
|
148
|
-
return !!
|
|
149
|
-
},
|
|
150
|
-
if (
|
|
151
|
-
const { center: s } =
|
|
152
|
-
return "path" in
|
|
145
|
+
return !!ft(o, l, s) && { mode: "translate" };
|
|
146
|
+
}, Hn = (e, t, i, n) => {
|
|
147
|
+
if (t.locked) return !1;
|
|
148
|
+
const { center: s } = K(t, n), a = Be(i, t.rotation, s);
|
|
149
|
+
return "path" in t && t.path ? t.style?.fillColor && t.style?.fillColor !== "transparent" ? !!e.isPointInPath(t.path, a[0], a[1]) && { mode: "translate" } : (e.lineWidth = (t.style?.lineWidth ?? 0) + 15 / n.canvasZoom, !!e.isPointInStroke(t.path, a[0], a[1]) && { mode: "translate" }) : ct(t, i, n, !1);
|
|
153
150
|
};
|
|
154
|
-
function
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
151
|
+
function Gt(e, t) {
|
|
152
|
+
const i = Math.max(e.x, t.x), n = Math.max(e.y, t.y), s = 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));
|
|
153
|
+
if (i < s && n < a) return { x: i, y: n, width: s - i, height: a - n };
|
|
157
154
|
}
|
|
158
|
-
const
|
|
159
|
-
for (let a = 0; a < n; a += n / 2) for (let
|
|
155
|
+
const xi = ({ ctx: e, path: t, rect: i, offset: n, checkFill: s }) => {
|
|
156
|
+
for (let a = 0; a < n; a += n / 2) for (let o = 0; o < n; o += n / 2) for (let r = a + i.x; r < i.x + i.width; r += n) for (let l = o + i.y; l < i.y + i.height; l += n) if (s ? e.isPointInPath(t, r, l) : e.isPointInStroke(t, r, l)) return !0;
|
|
160
157
|
return !1;
|
|
161
|
-
},
|
|
162
|
-
const
|
|
158
|
+
}, ai = (e, t, i, n = !1) => {
|
|
159
|
+
const { borders: s } = K(t, i);
|
|
160
|
+
return { border: St(s), shapePath: e, anchors: [...t.points.map((a, o) => n && o > 0 && o < t.points.length - 1 ? St({ x: a[0] - 7, y: a[1] - 7, width: Ve / i.canvasSize.scaleRatio, height: Ve / i.canvasSize.scaleRatio }) : bt({ x: a[0], y: a[1], radius: 7 / i.canvasSize.scaleRatio }))] };
|
|
161
|
+
}, pe = [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8], Mi = ({ size: e, zoom: t, newOffset: [i, n], canvasSize: s }) => e === "infinite" ? { zoom: t, offset: [i, n] } : t < 1 ? { zoom: t, offset: [-(s.realWidth - s.realWidth / t) / 2, -(s.realHeight - s.realHeight / t) / 2] } : { zoom: t, offset: [We(i, s.realWidth / t - s.realWidth, 0), We(n, s.realHeight / t - s.realHeight, 0)] }, _t = ({ size: e, canvasSize: t, currentOffset: i, currentZoom: n, zoom: s, centerPoint: a }) => {
|
|
162
|
+
const o = e === "fixed" && s < 1 ? [t.realWidth / 2, t.realHeight / 2] : a, r = i[0] - (o[0] / n - o[0] / s), l = i[1] - (o[1] / n - o[1] / s);
|
|
163
|
+
return { offset: e === "infinite" ? [r, l] : s < 1 ? [-(t.realWidth - t.realWidth / s) / 2, -(t.realHeight - t.realHeight / s) / 2] : [We(r, t.realWidth / s - t.realWidth, 0), We(l, t.realHeight / s - t.realHeight, 0)], zoom: s };
|
|
164
|
+
}, Pn = (e) => {
|
|
165
|
+
const { canvasSize: { width: t, height: i, scaleRatioWithNoZoom: n }, canvasZoom: s, canvasOffset: a } = e;
|
|
166
|
+
return { x: a[0] * s * n, y: a[1] * s * n, width: t * s, height: i * s };
|
|
167
|
+
}, Vn = (e, t) => {
|
|
168
|
+
const { canvasZoom: i, size: n } = t;
|
|
169
|
+
if (n !== "fixed" || i >= 1) return;
|
|
170
|
+
const s = Pn(t);
|
|
171
|
+
e.beginPath(), e.rect(s.x, s.y, s.width, s.height), e.closePath(), e.clip();
|
|
172
|
+
}, Ot = (e, t) => t.size !== "fixed" || e[0] > 0 && e[0] < t.canvasSize.realWidth && e[1] > 0 && e[1] < t.canvasSize.realHeight, Jn = (e, t) => {
|
|
173
|
+
const i = Math.abs(e.deltaY) < 50 && t < 50, n = e.ctrlKey, s = typeof navigator < "u" && navigator.userAgent.includes("Macintosh") && i && n;
|
|
174
|
+
switch (e.deltaMode) {
|
|
175
|
+
case WheelEvent.DOM_DELTA_LINE:
|
|
176
|
+
return { deltaX: 16 * e.deltaX, deltaY: 16 * e.deltaY };
|
|
177
|
+
case WheelEvent.DOM_DELTA_PAGE:
|
|
178
|
+
return { deltaX: e.deltaX * window.innerHeight, deltaY: e.deltaY * window.innerHeight };
|
|
179
|
+
default:
|
|
180
|
+
return s ? { deltaX: 5 * e.deltaX, deltaY: 5 * e.deltaY } : { deltaX: e.deltaX, deltaY: e.deltaY };
|
|
181
|
+
}
|
|
182
|
+
}, Ct = (e, t) => {
|
|
183
|
+
const i = bt(e);
|
|
184
|
+
return { ...e, path: i, selection: tt(i, e, t) };
|
|
185
|
+
}, ea = Ct, Je = (e, t) => {
|
|
186
|
+
const i = ((n) => {
|
|
163
187
|
if (n.points.length < 1) return;
|
|
164
188
|
const s = new Path2D();
|
|
165
189
|
s.moveTo(...n.points[0]);
|
|
166
190
|
for (const a of n.points.slice(1)) s.lineTo(...a);
|
|
167
191
|
return s.lineTo(...n.points[0]), s;
|
|
168
192
|
})(e);
|
|
169
|
-
return { ...e, path:
|
|
170
|
-
},
|
|
171
|
-
const
|
|
172
|
-
return { x:
|
|
173
|
-
},
|
|
174
|
-
const
|
|
193
|
+
return { ...e, path: i, selection: ai(i, e, t) };
|
|
194
|
+
}, ta = Je, Zn = (e, t) => {
|
|
195
|
+
const i = Math.min(...e.points.map((a) => a[0])) - t.selectionPadding, n = Math.max(...e.points.map((a) => a[0])) + t.selectionPadding, s = Math.min(...e.points.map((a) => a[1])) - t.selectionPadding;
|
|
196
|
+
return { x: i, width: n - i, y: s, height: Math.max(...e.points.map((a) => a[1])) + t.selectionPadding - s };
|
|
197
|
+
}, et = (e, t) => {
|
|
198
|
+
const i = ((n) => {
|
|
175
199
|
if (n.points.length < 3) return;
|
|
176
200
|
const s = new Path2D();
|
|
177
201
|
s.moveTo(...n.points[0]);
|
|
178
202
|
for (let a = 1; a < n.points.length - 1; a++) s.quadraticCurveTo(...n.points[a], n.points.length - 2 === a ? n.points[a + 1][0] : (n.points[a + 1][0] - n.points[a][0]) / 2 + n.points[a][0], n.points.length - 2 === a ? n.points[a + 1][1] : (n.points[a + 1][1] - n.points[a][1]) / 2 + n.points[a][1]);
|
|
179
203
|
return s;
|
|
180
204
|
})(e);
|
|
181
|
-
return { ...e, path:
|
|
182
|
-
},
|
|
183
|
-
const
|
|
205
|
+
return { ...e, path: i, selection: ai(i, e, t, !0) };
|
|
206
|
+
}, ia = et, na = Zn, wt = (e, t) => {
|
|
207
|
+
const i = ((n) => {
|
|
184
208
|
const s = new Path2D();
|
|
185
209
|
return s.ellipse(n.x, n.y, n.radiusX, n.radiusY, 0, 0, 2 * Math.PI), s;
|
|
186
210
|
})(e);
|
|
187
|
-
return { ...e, path:
|
|
188
|
-
},
|
|
189
|
-
return
|
|
190
|
-
var
|
|
191
|
-
},
|
|
192
|
-
e.globalAlpha !== 0 &&
|
|
193
|
-
},
|
|
194
|
-
const
|
|
211
|
+
return { ...e, path: i, selection: tt(i, e, t) };
|
|
212
|
+
}, aa = wt, ki = (e) => {
|
|
213
|
+
return i = { ...e, type: "triangle" }, { ...i, path: Gn(i) };
|
|
214
|
+
var i;
|
|
215
|
+
}, sa = (e, t) => {
|
|
216
|
+
e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
|
|
217
|
+
}, xt = (e, t) => {
|
|
218
|
+
const i = [];
|
|
195
219
|
let n;
|
|
196
220
|
if (e.style?.lineArrow === 1 || e.style?.lineArrow === 2 || e.style?.lineArrow === 3) {
|
|
197
|
-
const s = Math.PI / 2 -
|
|
198
|
-
e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 ||
|
|
199
|
-
const a = (({ line:
|
|
200
|
-
const
|
|
201
|
-
let
|
|
221
|
+
const s = Math.PI / 2 - bi({ targetVector: [e.points[0], e.points[1]] });
|
|
222
|
+
e.style?.lineArrow !== 1 && e.style?.lineArrow !== 3 || i.push(ki(Li(e.points[0], s, e.style))), e.style?.lineArrow !== 2 && e.style?.lineArrow !== 3 || i.push(ki(Li(e.points[1], s + Math.PI, e.style)));
|
|
223
|
+
const a = (({ line: o, size: r, direction: l }) => {
|
|
224
|
+
const d = Math.PI / 2 - bi({ targetVector: [o.points[0], o.points[1]] }), c = [o.points[0][0] + (o.points[1][0] - o.points[0][0]) / 2, o.points[0][1] + (o.points[1][1] - o.points[0][1]) / 2];
|
|
225
|
+
let h, u;
|
|
202
226
|
if (["start", "both"].includes(l)) {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
} else
|
|
227
|
+
const f = me({ point: o.points[0], origin: c, rotation: -d });
|
|
228
|
+
h = me({ point: [f[0], f[1] + r], origin: c, rotation: d });
|
|
229
|
+
} else h = [...o.points[0]];
|
|
206
230
|
if (["end", "both"].includes(l)) {
|
|
207
|
-
const
|
|
208
|
-
u =
|
|
209
|
-
} else u = [...
|
|
210
|
-
return { points: [
|
|
231
|
+
const f = me({ point: o.points[1], origin: c, rotation: -d });
|
|
232
|
+
u = me({ point: [f[0], f[1] - r], origin: c, rotation: d });
|
|
233
|
+
} else u = [...o.points[1]];
|
|
234
|
+
return { points: [h, u] };
|
|
211
235
|
})({ line: e, size: 10 + 2 * (e.style?.lineWidth ?? 0), direction: e.style?.lineArrow === 1 ? "start" : e.style?.lineArrow === 2 ? "end" : "both" });
|
|
212
|
-
n =
|
|
213
|
-
} else n =
|
|
214
|
-
return { ...e, path: n, selection:
|
|
215
|
-
},
|
|
216
|
-
const n = [
|
|
217
|
-
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: { ...
|
|
218
|
-
},
|
|
219
|
-
const
|
|
220
|
-
return { ...e, path:
|
|
221
|
-
},
|
|
222
|
-
e.globalAlpha !== 0 &&
|
|
223
|
-
},
|
|
224
|
-
const [a,
|
|
225
|
-
if (!(
|
|
226
|
-
const u =
|
|
227
|
-
if (u >
|
|
228
|
-
const
|
|
229
|
-
return [
|
|
236
|
+
n = Yt(a);
|
|
237
|
+
} else n = Yt(e);
|
|
238
|
+
return { ...e, path: n, selection: ai(n, e, t), arrows: i, style: { ...e.style, lineCap: e.style?.lineArrow ? "butt" : "round" } };
|
|
239
|
+
}, oa = xt, Li = (e, t, i) => {
|
|
240
|
+
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 })];
|
|
241
|
+
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" } };
|
|
242
|
+
}, Mt = (e, t) => {
|
|
243
|
+
const i = St(e);
|
|
244
|
+
return { ...e, path: i, selection: tt(i, e, t) };
|
|
245
|
+
}, ra = Mt, la = (e, t) => {
|
|
246
|
+
e.globalAlpha !== 0 && t.path && (t.style?.fillColor !== "transparent" && e.fill(t.path), t.style?.strokeColor !== "transparent" && e.stroke(t.path));
|
|
247
|
+
}, Hi = (e, t) => ({ x: e.x - t.selectionPadding, width: e.width + 2 * t.selectionPadding, y: e.y - t.selectionPadding, height: e.height + 2 * t.selectionPadding }), Pi = (e, t, i, [n, s] = [!1, !1]) => ((a, o, [r, l]) => me({ origin: [r, l], point: a, rotation: -o }))([e[0] === 0.5 ? i.x + i.width / 2 : e[0] === 0 ? i.x + (n ? 0 : i.width) : i.x + (n ? i.width : 0), e[1] === 0.5 ? i.y + i.height / 2 : e[1] === 0 ? i.y + (s ? 0 : i.height) : i.y + (s ? i.height : 0)], i.rotation, t), kt = (e, t) => ({ ...e, selection: tt(void 0, e, t) }), ca = kt, It = (e, t, i, n, s) => {
|
|
248
|
+
const [a, o] = ((r, l, d, c, h = !1) => {
|
|
249
|
+
if (!(r && l && c && d)) return [Qt, Qt];
|
|
250
|
+
const u = r / l;
|
|
251
|
+
if (u > d / c) {
|
|
252
|
+
const v = h ? d : Math.min(r, d);
|
|
253
|
+
return [v, v / u];
|
|
230
254
|
}
|
|
231
|
-
const
|
|
232
|
-
return [
|
|
233
|
-
})(e.width, e.height,
|
|
234
|
-
return
|
|
235
|
-
},
|
|
236
|
-
const
|
|
237
|
-
|
|
255
|
+
const f = h ? c : Math.min(l, c);
|
|
256
|
+
return [f * u, f];
|
|
257
|
+
})(e.width, e.height, i, n, !0);
|
|
258
|
+
return kt({ toolId: ii.id, type: "picture", id: le("picture_"), x: -s.canvasOffset[0] + s.canvasSize.realWidth / s.canvasZoom / 2 - a / 2, y: -s.canvasOffset[1] + s.canvasSize.realHeight / s.canvasZoom / 2 - o / 2, width: a, height: o, src: t, img: e, rotation: 0 }, s);
|
|
259
|
+
}, da = (e, t, i, n) => new Promise((s, a) => {
|
|
260
|
+
const o = new Image();
|
|
261
|
+
o.onerror = () => {
|
|
238
262
|
a(new Error("Some images could not be loaded"));
|
|
239
263
|
}, setTimeout(() => {
|
|
240
264
|
a(new Error("Timeout while loading images"));
|
|
241
|
-
}, 4e3), e instanceof File ? ((
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
URL.revokeObjectURL(
|
|
246
|
-
const
|
|
247
|
-
l(
|
|
248
|
-
},
|
|
249
|
-
}) : (
|
|
250
|
-
URL.revokeObjectURL(
|
|
251
|
-
const
|
|
252
|
-
l(
|
|
253
|
-
},
|
|
254
|
-
})(
|
|
255
|
-
|
|
256
|
-
URL.revokeObjectURL(
|
|
257
|
-
const
|
|
258
|
-
l(
|
|
259
|
-
},
|
|
260
|
-
|
|
265
|
+
}, 4e3), e instanceof File ? ((r, l, d, c, h, u) => {
|
|
266
|
+
An(d) ? d.text().then((f) => {
|
|
267
|
+
const v = zn(f);
|
|
268
|
+
r.onload = async () => {
|
|
269
|
+
URL.revokeObjectURL(r.src);
|
|
270
|
+
const k = It(r, f, c, h, u);
|
|
271
|
+
l(k);
|
|
272
|
+
}, r.src = v;
|
|
273
|
+
}) : (r.onload = async () => {
|
|
274
|
+
URL.revokeObjectURL(r.src);
|
|
275
|
+
const f = It(r, r.src, c, h, u);
|
|
276
|
+
l(f);
|
|
277
|
+
}, r.src = URL.createObjectURL(d));
|
|
278
|
+
})(o, s, e, t, i, n) : ((r, l, d, c, h, u) => {
|
|
279
|
+
r.onload = () => {
|
|
280
|
+
URL.revokeObjectURL(r.src);
|
|
281
|
+
const f = It(r, d, c, h, u);
|
|
282
|
+
l(f);
|
|
283
|
+
}, En(d).then((f) => {
|
|
284
|
+
r.src = f;
|
|
261
285
|
}).catch(() => {
|
|
262
|
-
|
|
286
|
+
r.src = "";
|
|
263
287
|
});
|
|
264
|
-
})(
|
|
265
|
-
}),
|
|
288
|
+
})(o, s, e, t, i, n);
|
|
289
|
+
}), Ft = ["Texte"], Lt = (e, t) => ({ ...e, selection: tt(void 0, e, t) }), ha = Lt, si = (e, t, i, n, s, a = ht) => {
|
|
266
290
|
e.font = `${s ? "italic" : ""} ${n ? "bold" : ""} 1px ${a}`;
|
|
267
|
-
const
|
|
268
|
-
return Math.min(...
|
|
269
|
-
},
|
|
270
|
-
const s = { ...
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
return Math.max(...
|
|
274
|
-
})(e, s.value, s.fontSize, s.style?.fontBold ?? !1, s.style?.fontItalic ?? !1, s.style?.fontFamily),
|
|
275
|
-
return { ...
|
|
276
|
-
},
|
|
277
|
-
const s = [
|
|
278
|
-
switch (
|
|
291
|
+
const o = t.map((r) => i / e.measureText(r).width);
|
|
292
|
+
return Math.min(...o) || 36;
|
|
293
|
+
}, ua = (e, t, i, n) => {
|
|
294
|
+
const s = { ...t, value: i }, a = ((v, k, C, b, Q, w = ht) => {
|
|
295
|
+
v.font = `${Q ? "italic" : ""} ${b ? "bold" : ""} ${C}px ${w}`;
|
|
296
|
+
const M = k.map((L) => v.measureText(L).width);
|
|
297
|
+
return Math.max(...M) || 20;
|
|
298
|
+
})(e, s.value, s.fontSize, s.style?.fontBold ?? !1, s.style?.fontItalic ?? !1, s.style?.fontFamily), o = s.fontSize * s.value.length, r = { ...s, width: a, height: o }, { center: l } = K(t, n), { center: d } = K(r, n), [c, h] = Pi([1, 1], l, t), [u, f] = Pi([1, 1], d, r, [!1, !1]);
|
|
299
|
+
return { ...r, x: r.x - (u - c), y: r.y - (f - h) };
|
|
300
|
+
}, Vi = (e, t, i, n) => {
|
|
301
|
+
const s = [U(i[0], n), U(i[1], n)];
|
|
302
|
+
switch (t.type) {
|
|
279
303
|
case "brush":
|
|
280
|
-
return ((a,
|
|
304
|
+
return ((a, o, r) => it({ toolId: a.id, type: a.type, id: le(`${a.type}_`), points: [[o]], rotation: 0, 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 } }, r))(t, s, n);
|
|
281
305
|
case "line":
|
|
282
|
-
return ((a,
|
|
283
|
-
const l = { toolId: a.id, type: a.type, id:
|
|
284
|
-
return
|
|
285
|
-
})(
|
|
306
|
+
return ((a, o, r) => {
|
|
307
|
+
const l = { toolId: a.id, type: a.type, id: le(`${a.type}_`), points: [o, o], rotation: 0, 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 } };
|
|
308
|
+
return xt(l, r);
|
|
309
|
+
})(t, s, n);
|
|
286
310
|
case "polygon":
|
|
287
|
-
return ((a,
|
|
311
|
+
return ((a, o, r) => Je({ toolId: a.id, type: a.type, id: le(`${a.type}_`), points: new Array(a.settings.pointsCount.default).fill(o), rotation: 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, pointsCount: a.settings.pointsCount.default } }, r))(t, s, n);
|
|
288
312
|
case "curve":
|
|
289
|
-
return ((a,
|
|
313
|
+
return ((a, o, r) => et({ toolId: a.id, type: a.type, id: le(`${a.type}_`), points: new Array(a.settings.pointsCount.default).fill(o), rotation: 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, pointsCount: a.settings.pointsCount.default } }, r))(t, s, n);
|
|
290
314
|
case "rect":
|
|
291
315
|
case "square":
|
|
292
|
-
return ((a,
|
|
293
|
-
const
|
|
294
|
-
return
|
|
295
|
-
})(
|
|
316
|
+
return ((a, o, r, l = 0, d = 0) => {
|
|
317
|
+
const c = { toolId: a.id, type: a.type, id: le(`${a.type}_`), x: o[0], y: o[1], width: l, height: d, rotation: 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 } };
|
|
318
|
+
return Mt(c, r);
|
|
319
|
+
})(t, s, n);
|
|
296
320
|
case "text":
|
|
297
|
-
return ((a,
|
|
298
|
-
const
|
|
299
|
-
return
|
|
300
|
-
})(e,
|
|
321
|
+
return ((a, o, r, l) => {
|
|
322
|
+
const d = si(a, Ft, 150, o.settings?.fontBold.default ?? !1, o.settings?.fontItalic.default ?? !1, o.settings.fontFamily.default), c = d * (Ft.length || 1);
|
|
323
|
+
return Lt({ toolId: o.id, type: o.type, id: le(`${o.type}_`), x: r[0] - 150, y: r[1] - c, value: Ft, fontSize: d, width: 150, height: c, rotation: 0, style: { opacity: o.settings.opacity.default, strokeColor: o.settings.strokeColor.default, fontFamily: o.settings.fontFamily.default, fontItalic: o.settings.fontItalic.default, fontBold: o.settings.fontBold.default } }, l);
|
|
324
|
+
})(e, t, s, n);
|
|
301
325
|
case "ellipse":
|
|
302
|
-
return ((a,
|
|
326
|
+
return ((a, o, r) => wt({ toolId: a.id, type: a.type, id: le(`${a.type}_`), x: o[0], y: o[1], radiusX: 0, radiusY: 0, rotation: 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 } }, r))(t, s, n);
|
|
303
327
|
case "circle":
|
|
304
|
-
return ((a,
|
|
328
|
+
return ((a, o, r) => Ct({ toolId: a.id, type: a.type, id: le(`${a.type}_`), x: o[0], y: o[1], radius: 0, rotation: 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 } }, r))(t, s, n);
|
|
305
329
|
}
|
|
306
|
-
},
|
|
307
|
-
if (
|
|
308
|
-
const { center: n } =
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
330
|
+
}, Tn = (e, t, i) => {
|
|
331
|
+
if (t.visible === !1) return;
|
|
332
|
+
const { center: n, outerBorders: s } = K(t, i), a = ((o) => {
|
|
333
|
+
const { canvasSize: { width: r, height: l, scaleRatioWithNoZoom: d }, canvasZoom: c, canvasOffset: h } = o;
|
|
334
|
+
return { x: -h[0], y: -h[1], width: r / c / d, height: l / c / d };
|
|
335
|
+
})(i);
|
|
336
|
+
if (Gt(s, a)) {
|
|
337
|
+
switch (ni(e, i, t.rotation, n), $e(e, t.style), t.type) {
|
|
338
|
+
case "brush":
|
|
339
|
+
((o, r) => {
|
|
340
|
+
r.points.length < 1 || !r.path || o.globalAlpha !== 0 && r.style?.strokeColor !== "transparent" && o.globalAlpha !== 0 && o.stroke(r.path);
|
|
341
|
+
})(e, t);
|
|
342
|
+
break;
|
|
343
|
+
case "text":
|
|
344
|
+
((o, r) => {
|
|
345
|
+
if (o.globalAlpha !== 0 && r.style?.strokeColor && r.style.strokeColor !== "transparent") {
|
|
346
|
+
o.font = `${r.style?.fontItalic ? "italic" : ""} ${r.style?.fontBold ? "bold" : ""} ${r.fontSize}px ${r.style?.fontFamily ?? ht}`, o.textBaseline = "top", o.fillStyle = r.style.strokeColor;
|
|
347
|
+
for (let l = 0; l < r.value.length; l++) o.fillText(r.value[l], r.x, r.y + l * r.fontSize, r.width);
|
|
348
|
+
}
|
|
349
|
+
})(e, t);
|
|
350
|
+
break;
|
|
351
|
+
case "line":
|
|
352
|
+
((o, r) => {
|
|
353
|
+
if (o.globalAlpha !== 0 && r.path) {
|
|
354
|
+
r.style?.fillColor !== "transparent" && o.fill(r.path), r.style?.strokeColor !== "transparent" && o.stroke(r.path);
|
|
355
|
+
for (const l of r.arrows ?? []) $e(o, l.style), sa(o, l);
|
|
356
|
+
}
|
|
357
|
+
})(e, t);
|
|
358
|
+
break;
|
|
359
|
+
case "polygon":
|
|
360
|
+
((o, r) => {
|
|
361
|
+
r.path && o.globalAlpha !== 0 && (r.style?.fillColor !== "transparent" && o.fill(r.path), r.style?.strokeColor !== "transparent" && o.stroke(r.path));
|
|
362
|
+
})(e, t);
|
|
363
|
+
break;
|
|
364
|
+
case "curve":
|
|
365
|
+
((o, r) => {
|
|
366
|
+
r.path && o.globalAlpha !== 0 && (r.style?.fillColor !== "transparent" && o.fill(r.path), r.style?.strokeColor !== "transparent" && o.stroke(r.path));
|
|
367
|
+
})(e, t);
|
|
368
|
+
break;
|
|
369
|
+
case "circle":
|
|
370
|
+
((o, r) => {
|
|
371
|
+
o.globalAlpha !== 0 && r.path && (r.style?.fillColor !== "transparent" && o.fill(r.path), r.style?.strokeColor !== "transparent" && o.stroke(r.path));
|
|
372
|
+
})(e, t);
|
|
373
|
+
break;
|
|
374
|
+
case "ellipse":
|
|
375
|
+
((o, r) => {
|
|
376
|
+
o.globalAlpha !== 0 && r.path && (r.style?.fillColor !== "transparent" && o.fill(r.path), r.style?.strokeColor !== "transparent" && o.stroke(r.path));
|
|
377
|
+
})(e, t);
|
|
378
|
+
break;
|
|
379
|
+
case "rect":
|
|
380
|
+
case "square":
|
|
381
|
+
la(e, t);
|
|
382
|
+
break;
|
|
383
|
+
case "picture":
|
|
384
|
+
((o, r) => {
|
|
385
|
+
o.globalAlpha !== 0 && (o.beginPath(), o.drawImage(r.img, r.x, r.y, r.width, r.height));
|
|
386
|
+
})(e, t);
|
|
387
|
+
}
|
|
388
|
+
e.restore();
|
|
359
389
|
}
|
|
360
|
-
|
|
361
|
-
}, z1 = (e, i) => {
|
|
390
|
+
}, pa = (e, t) => {
|
|
362
391
|
switch (e.type) {
|
|
363
392
|
case "brush":
|
|
364
|
-
return ((
|
|
365
|
-
const s =
|
|
366
|
-
return { x: a - n, width: l - a + n, y:
|
|
367
|
-
})(e,
|
|
393
|
+
return ((i, { selectionPadding: n }) => {
|
|
394
|
+
const s = i.points.flat(), a = Math.min(...s.map((c) => c[0])), o = Math.min(...s.map((c) => c[1])), r = s.map((c) => Ce(c, a, o, i.scaleX, i.scaleY)), l = Math.max(...r.map((c) => c[0])) + n, d = Math.max(...r.map((c) => c[1])) + n;
|
|
395
|
+
return { x: a - n, width: l - a + n, y: o - n, height: d - o + n };
|
|
396
|
+
})(e, t);
|
|
368
397
|
case "line":
|
|
369
|
-
return ((
|
|
398
|
+
return ((i, n) => ({ x: Math.min(i.points[0][0], i.points[1][0]) - n.selectionPadding, width: Math.abs(i.points[0][0] - i.points[1][0]) + 2 * n.selectionPadding, y: Math.min(i.points[0][1], i.points[1][1]) - n.selectionPadding, height: Math.abs(i.points[0][1] - i.points[1][1]) + 2 * n.selectionPadding }))(e, t);
|
|
370
399
|
case "polygon":
|
|
371
|
-
return
|
|
400
|
+
return Zn(e, t);
|
|
372
401
|
case "curve":
|
|
373
|
-
return
|
|
402
|
+
return na(e, t);
|
|
374
403
|
case "circle":
|
|
375
|
-
return ((
|
|
404
|
+
return ((i, n) => ({ x: i.x - i.radius - n.selectionPadding, width: 2 * (i.radius + n.selectionPadding), y: i.y - i.radius - n.selectionPadding, height: 2 * (i.radius + n.selectionPadding) }))(e, t);
|
|
376
405
|
case "ellipse":
|
|
377
|
-
return ((
|
|
406
|
+
return ((i, n) => ({ x: i.x - i.radiusX - n.selectionPadding, width: 2 * (i.radiusX + n.selectionPadding), y: i.y - i.radiusY - n.selectionPadding, height: 2 * (i.radiusY + n.selectionPadding) }))(e, t);
|
|
378
407
|
case "rect":
|
|
379
408
|
case "square":
|
|
380
|
-
return
|
|
409
|
+
return Hi(e, t);
|
|
381
410
|
case "text":
|
|
382
|
-
return ((
|
|
411
|
+
return ((i, n) => ({ x: i.x - n.selectionPadding, width: i.width + 2 * n.selectionPadding, y: i.y - n.selectionPadding, height: i.height + 2 * n.selectionPadding }))(e, t);
|
|
383
412
|
case "picture":
|
|
384
|
-
return ((
|
|
413
|
+
return ((i, n) => Hi(i, n))(e, t);
|
|
385
414
|
default:
|
|
386
415
|
return { x: 0, y: 0, width: 100, height: 100 };
|
|
387
416
|
}
|
|
388
|
-
},
|
|
389
|
-
const t =
|
|
390
|
-
return { borders:
|
|
391
|
-
},
|
|
392
|
-
const
|
|
393
|
-
return { ...e, rotation:
|
|
394
|
-
},
|
|
417
|
+
}, K = (e, t) => {
|
|
418
|
+
const i = pa(e, t), n = { x: i.x - (e.style?.lineWidth ?? 0), y: i.y - (e.style?.lineWidth ?? 0), width: i.width + 2 * (e.style?.lineWidth ?? 0), height: i.height + 2 * (e.style?.lineWidth ?? 0) }, s = ((a) => [a.x + a.width / 2, a.y + a.height / 2])(i);
|
|
419
|
+
return { borders: i, outerBorders: n, center: s };
|
|
420
|
+
}, ga = (e, t, i, n, s, a) => {
|
|
421
|
+
const o = s[0] - n[0], r = s[1] - n[1], l = s[0] - t[0], d = s[1] - t[1], c = i.rotation + Math.atan2(d, l) - Math.atan2(r, o);
|
|
422
|
+
return { ...e, rotation: jn(c, a) };
|
|
423
|
+
}, fa = (e, t, i, n, s, a, o) => {
|
|
395
424
|
switch (n.type) {
|
|
396
425
|
case "line":
|
|
397
|
-
return ((
|
|
398
|
-
const
|
|
399
|
-
return
|
|
400
|
-
})(
|
|
426
|
+
return ((r, l, d, c) => {
|
|
427
|
+
const h = [U(r[0], c), U(r[1], c)], { center: u } = K(l, c), f = Be(h, l.rotation, u), v = fe(["points", d.anchor], f, l);
|
|
428
|
+
return xt(v, c);
|
|
429
|
+
})(i, n, s, a);
|
|
401
430
|
case "polygon":
|
|
402
|
-
return ((
|
|
403
|
-
const
|
|
404
|
-
return
|
|
405
|
-
})(
|
|
431
|
+
return ((r, l, d, c) => {
|
|
432
|
+
const h = [U(r[0], c), U(r[1], c)], { center: u } = K(l, c), f = Be(h, l.rotation, u), v = fe(["points", d.anchor], f, l);
|
|
433
|
+
return Je(v, c);
|
|
434
|
+
})(i, n, s, a);
|
|
406
435
|
case "curve":
|
|
407
|
-
return ((
|
|
408
|
-
const
|
|
409
|
-
return
|
|
410
|
-
})(
|
|
436
|
+
return ((r, l, d, c) => {
|
|
437
|
+
const h = [U(r[0], c), U(r[1], c)], { center: u } = K(l, c), f = Be(h, l.rotation, u), v = fe(["points", d.anchor], f, l);
|
|
438
|
+
return et(v, c);
|
|
439
|
+
})(i, n, s, a);
|
|
411
440
|
case "brush":
|
|
412
|
-
return ((
|
|
413
|
-
const { borders: u } =
|
|
414
|
-
if (!
|
|
415
|
-
const T = De(
|
|
416
|
-
return
|
|
417
|
-
})(
|
|
441
|
+
return ((r, l, d, c, h) => {
|
|
442
|
+
const { borders: u } = K({ ...l, scaleX: 1, scaleY: 1 }, c), { borders: f } = K(l, c), { borderX: v, borderHeight: k, borderY: C, borderWidth: b } = Ge(r, l, d, c, h), Q = Math.max(0, u.width - 2 * c.selectionPadding), w = Math.max(0, u.height - 2 * c.selectionPadding), M = Math.max(0, b - 2 * c.selectionPadding), L = Math.max(0, k - 2 * c.selectionPadding), Z = Q ? M / Q : 1, z = w ? L / w : 1;
|
|
443
|
+
if (!Q || !w) return l;
|
|
444
|
+
const T = De(v - f.x), $ = De(C - f.y);
|
|
445
|
+
return it({ ...l, points: l.points.map((H) => H.map(([N, y]) => [N + T, y + $])), scaleX: Z, scaleY: z }, c);
|
|
446
|
+
})(i, n, s, a, o);
|
|
418
447
|
case "circle":
|
|
419
|
-
return ((
|
|
420
|
-
const { borderX:
|
|
421
|
-
return
|
|
422
|
-
})(
|
|
448
|
+
return ((r, l, d, c) => {
|
|
449
|
+
const { borderX: h, borderHeight: u, borderY: f, borderWidth: v } = Ge(r, l, d, c, !0);
|
|
450
|
+
return Ct({ ...l, radius: Math.max(0, v / 2 - c.selectionPadding), x: h + v / 2, y: f + u / 2 }, c);
|
|
451
|
+
})(i, n, s, a);
|
|
423
452
|
case "ellipse":
|
|
424
|
-
return ((
|
|
425
|
-
const { borderX: u, borderHeight:
|
|
426
|
-
return
|
|
427
|
-
})(
|
|
453
|
+
return ((r, l, d, c, h = !1) => {
|
|
454
|
+
const { borderX: u, borderHeight: f, borderY: v, borderWidth: k } = Ge(r, l, d, c, h);
|
|
455
|
+
return wt({ ...l, radiusX: Math.max(0, k / 2 - c.selectionPadding), radiusY: Math.max(0, f / 2 - c.selectionPadding), x: u + k / 2, y: v + f / 2 }, c);
|
|
456
|
+
})(i, n, s, a, o);
|
|
428
457
|
case "rect":
|
|
429
458
|
case "square":
|
|
430
|
-
return ((
|
|
431
|
-
const { borderX: u, borderHeight:
|
|
432
|
-
return
|
|
433
|
-
})(
|
|
459
|
+
return ((r, l, d, c, h = !1) => {
|
|
460
|
+
const { borderX: u, borderHeight: f, borderY: v, borderWidth: k } = Ge(r, l, d, c, h);
|
|
461
|
+
return Mt({ ...l, width: Math.max(0, k - 2 * c.selectionPadding), height: Math.max(0, f - 2 * c.selectionPadding), x: u + c.selectionPadding, y: v + c.selectionPadding }, c);
|
|
462
|
+
})(i, n, s, a, t.type === "square" || o);
|
|
434
463
|
case "text":
|
|
435
|
-
return ((
|
|
436
|
-
const { borderX: u, borderHeight:
|
|
437
|
-
return { ...
|
|
438
|
-
})(e,
|
|
464
|
+
return ((r, l, d, c, h) => {
|
|
465
|
+
const { borderX: u, borderHeight: f, borderY: v, borderWidth: k } = Ge(l, d, c, h, !0), C = Lt({ ...d, width: Math.max(0, k - 2 * h.selectionPadding), height: Math.max(0, f - 2 * h.selectionPadding), x: u + h.selectionPadding, y: v + h.selectionPadding }, h);
|
|
466
|
+
return { ...C, fontSize: si(r, C.value, C.width, C.style?.fontBold ?? !1, C.style?.fontItalic ?? !1, C.style?.fontFamily) };
|
|
467
|
+
})(e, i, n, s, a);
|
|
439
468
|
case "picture":
|
|
440
|
-
return ((
|
|
441
|
-
const { borderX:
|
|
442
|
-
return
|
|
443
|
-
})(
|
|
469
|
+
return ((r, l, d, c) => {
|
|
470
|
+
const { borderX: h, borderHeight: u, borderY: f, borderWidth: v } = Ge(r, l, d, c, !0);
|
|
471
|
+
return kt({ ...l, width: Math.max(0, v - 2 * c.selectionPadding), height: Math.max(0, u - 2 * c.selectionPadding), x: h + c.selectionPadding, y: f + c.selectionPadding }, c);
|
|
472
|
+
})(i, n, s, a);
|
|
444
473
|
default:
|
|
445
474
|
return n;
|
|
446
475
|
}
|
|
447
|
-
},
|
|
448
|
-
switch (
|
|
476
|
+
}, jt = (e, t, i, n) => {
|
|
477
|
+
switch (t.type) {
|
|
449
478
|
case "rect":
|
|
450
479
|
case "square":
|
|
451
|
-
return ((s, a,
|
|
480
|
+
return ((s, a, o, r) => Mt({ ...a, x: U(a.x + s[0] - o[0], r), y: U(a.y + s[1] - o[1], r) }, r))(e, t, i, n);
|
|
452
481
|
case "ellipse":
|
|
453
|
-
return ((s, a,
|
|
482
|
+
return ((s, a, o, r) => wt({ ...a, x: U(a.x + s[0] - o[0], r), y: U(a.y + s[1] - o[1], r) }, r))(e, t, i, n);
|
|
454
483
|
case "circle":
|
|
455
|
-
return ((s, a,
|
|
484
|
+
return ((s, a, o, r) => Ct({ ...a, x: U(a.x + s[0] - o[0], r), y: U(a.y + s[1] - o[1], r) }, r))(e, t, i, n);
|
|
456
485
|
case "picture":
|
|
457
|
-
return ((s, a,
|
|
486
|
+
return ((s, a, o, r) => kt({ ...a, x: U(a.x + s[0] - o[0], r), y: U(a.y + s[1] - o[1], r) }, r))(e, t, i, n);
|
|
458
487
|
case "text":
|
|
459
|
-
return ((s, a,
|
|
488
|
+
return ((s, a, o, r) => Lt({ ...a, x: U(a.x + s[0] - o[0], r), y: U(a.y + s[1] - o[1], r) }, r))(e, t, i, n);
|
|
460
489
|
case "line":
|
|
461
|
-
return ((s, a,
|
|
490
|
+
return ((s, a, o, r) => xt({ ...a, points: a.points.map(([l, d]) => [U(l + s[0] - o[0], r), U(d + s[1] - o[1], r)]) }, r))(e, t, i, n);
|
|
462
491
|
case "polygon":
|
|
463
|
-
return ((s, a,
|
|
464
|
-
const { borders: l } =
|
|
465
|
-
return
|
|
466
|
-
})(e,
|
|
492
|
+
return ((s, a, o, r) => {
|
|
493
|
+
const { borders: l } = K(a, r);
|
|
494
|
+
return Je({ ...a, points: a.points.map(([d, c]) => r.gridGap ? [d + U(l.x + s[0] - o[0], r) - l.x, c + U(l.y + s[1] - o[1], r) - l.y] : [U(d + s[0] - o[0], r), U(c + s[1] - o[1], r)]) }, r);
|
|
495
|
+
})(e, t, i, n);
|
|
467
496
|
case "curve":
|
|
468
|
-
return ((s, a,
|
|
469
|
-
const { borders: l } =
|
|
470
|
-
return
|
|
471
|
-
})(e,
|
|
497
|
+
return ((s, a, o, r) => {
|
|
498
|
+
const { borders: l } = K(a, r);
|
|
499
|
+
return et({ ...a, points: a.points.map(([d, c]) => r.gridGap ? [d + U(l.x + s[0] - o[0], r) - l.x, c + U(l.y + s[1] - o[1], r) - l.y] : [U(d + s[0] - o[0], r), U(c + s[1] - o[1], r)]) }, r);
|
|
500
|
+
})(e, t, i, n);
|
|
472
501
|
case "brush":
|
|
473
|
-
return ((s, a,
|
|
474
|
-
const { borders: l } =
|
|
475
|
-
return
|
|
476
|
-
})(e,
|
|
502
|
+
return ((s, a, o, r) => {
|
|
503
|
+
const { borders: l } = K(a, r), d = r.gridGap ? U(l.x + s[0] - o[0], r) - l.x : s[0] - o[0], c = r.gridGap ? U(l.y + s[1] - o[1], r) - l.y : s[1] - o[1];
|
|
504
|
+
return it({ ...a, points: a.points.map((h) => h.map(([u, f]) => [u + d, f + c])) }, r);
|
|
505
|
+
})(e, t, i, n);
|
|
477
506
|
default:
|
|
478
|
-
return
|
|
507
|
+
return t;
|
|
479
508
|
}
|
|
480
|
-
},
|
|
509
|
+
}, dt = (e, t) => {
|
|
481
510
|
switch (e.type) {
|
|
482
511
|
case "rect":
|
|
483
512
|
case "square":
|
|
484
|
-
return
|
|
513
|
+
return ra(e, t);
|
|
485
514
|
case "ellipse":
|
|
486
|
-
return
|
|
515
|
+
return aa(e, t);
|
|
487
516
|
case "circle":
|
|
488
|
-
return
|
|
517
|
+
return ea(e, t);
|
|
489
518
|
case "picture":
|
|
490
|
-
return
|
|
519
|
+
return ca(e, t);
|
|
491
520
|
case "text":
|
|
492
|
-
return
|
|
521
|
+
return ha(e, t);
|
|
493
522
|
case "line":
|
|
494
|
-
return
|
|
523
|
+
return oa(e, t);
|
|
495
524
|
case "polygon":
|
|
496
|
-
return
|
|
525
|
+
return ta(e, t);
|
|
497
526
|
case "curve":
|
|
498
|
-
return
|
|
527
|
+
return ia(e, t);
|
|
499
528
|
case "brush":
|
|
500
|
-
return
|
|
529
|
+
return _n(e, t);
|
|
501
530
|
default:
|
|
502
531
|
return e;
|
|
503
532
|
}
|
|
504
|
-
},
|
|
505
|
-
const { center:
|
|
506
|
-
switch (
|
|
533
|
+
}, Zi = ({ ctx: e, shape: t, settings: i, selectionWidth: n, selectionColor: s, withAnchors: a = !0 }) => {
|
|
534
|
+
const { center: o } = K(t, i);
|
|
535
|
+
switch (ni(e, i, t.rotation, o), t.type) {
|
|
507
536
|
case "rect":
|
|
508
537
|
case "square":
|
|
509
538
|
case "circle":
|
|
@@ -511,794 +540,912 @@ const ui = ({ ctx: e, path: i, rect: t, offset: n, checkFill: s }) => {
|
|
|
511
540
|
case "picture":
|
|
512
541
|
case "text":
|
|
513
542
|
case "brush":
|
|
514
|
-
((
|
|
515
|
-
if (l.selection && (
|
|
516
|
-
l.selection.shapePath &&
|
|
517
|
-
for (const
|
|
543
|
+
((r, l, d, c, h, u) => {
|
|
544
|
+
if (l.selection && ($e(r, { fillColor: "transparent", strokeColor: d, lineWidth: c / h.canvasSize.scaleRatio }), l.selection.shapePath ? r.stroke(l.selection.shapePath) : r.stroke(l.selection.border), u && !l.locked)) {
|
|
545
|
+
l.selection.shapePath && r.stroke(l.selection.border), r.stroke(l.selection.line), $e(r, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / h.canvasSize.scaleRatio });
|
|
546
|
+
for (const f of l.selection.anchors) r.fill(f), r.stroke(f);
|
|
518
547
|
}
|
|
519
|
-
})(e,
|
|
548
|
+
})(e, t, s, n, i, a);
|
|
520
549
|
break;
|
|
521
550
|
case "polygon":
|
|
522
551
|
case "line":
|
|
523
552
|
case "curve":
|
|
524
|
-
(({ ctx:
|
|
525
|
-
if (l.selection && (
|
|
526
|
-
|
|
527
|
-
for (const
|
|
553
|
+
(({ ctx: r, shape: l, withAnchors: d, selectionWidth: c, selectionColor: h, settings: u }) => {
|
|
554
|
+
if (l.selection && ($e(r, { fillColor: "transparent", strokeColor: h, lineWidth: c / u.canvasSize.scaleRatio }), l.selection.shapePath && r.stroke(l.selection.shapePath), d && !l.locked)) {
|
|
555
|
+
$e(r, { fillColor: "rgb(255,255,255)", strokeColor: "rgb(150,150,150)", lineWidth: 2 / u.canvasSize.scaleRatio });
|
|
556
|
+
for (const f of l.selection.anchors) r.fill(f), r.stroke(f);
|
|
528
557
|
}
|
|
529
|
-
})({ ctx: e, shape:
|
|
558
|
+
})({ ctx: e, shape: t, withAnchors: a, selectionWidth: n, selectionColor: s, settings: i });
|
|
530
559
|
}
|
|
531
560
|
e.restore();
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
})(e,
|
|
536
|
-
},
|
|
537
|
-
const
|
|
561
|
+
}, va = ({ ctx: e, selectionFrame: t, settings: i }) => {
|
|
562
|
+
ni(e, i), ((n, s, a) => {
|
|
563
|
+
$e(n, { fillColor: "rgba(170,170,170, 0.1)", strokeColor: "rgb(170,170,170)", lineWidth: 1 / a.canvasSize.scaleRatio }), n.fillRect(s[0][0], s[0][1], s[1][0] - s[0][0], s[1][1] - s[0][1]), n.strokeRect(s[0][0], s[0][1], s[1][0] - s[0][0], s[1][1] - s[0][1]);
|
|
564
|
+
})(e, t, i), e.restore();
|
|
565
|
+
}, oi = (e) => e.filter((t) => t != null), zn = (e) => {
|
|
566
|
+
const t = new DOMParser().parseFromString(e, "text/xml").getElementsByTagName("svg")[0], i = t.getAttribute("width"), n = t.getAttribute("height");
|
|
538
567
|
let s;
|
|
539
|
-
if (
|
|
568
|
+
if (i || n) s = e;
|
|
540
569
|
else {
|
|
541
|
-
const
|
|
542
|
-
|
|
570
|
+
const o = t.getAttribute("viewBox") ?? "0 0 300 300", [, , r, l] = o.split(" ");
|
|
571
|
+
t.setAttribute("width", r ?? Qt), t.setAttribute("height", l ?? Qt), s = new XMLSerializer().serializeToString(t);
|
|
543
572
|
}
|
|
544
573
|
const a = new Blob([s], { type: "image/svg+xml" });
|
|
545
574
|
return URL.createObjectURL(a);
|
|
546
|
-
},
|
|
547
|
-
const
|
|
548
|
-
|
|
549
|
-
},
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
const n =
|
|
553
|
-
return n ? (n.drawImage(
|
|
554
|
-
})(e.img),
|
|
555
|
-
const
|
|
556
|
-
|
|
557
|
-
const a =
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
575
|
+
}, An = (e) => (e instanceof File ? e.name : e).includes(".svg"), En = (e) => An(e) ? fetch(e).then((t) => t.text()).then((t) => zn(t)) : fetch(e).then((t) => t.blob()).then((t) => URL.createObjectURL(t)), Ti = (e, t) => {
|
|
576
|
+
const i = document.createElement("a");
|
|
577
|
+
i.href = e, i.download = t, document.body.appendChild(i), i.click(), document.body.removeChild(i);
|
|
578
|
+
}, ma = (e) => e.src.includes("<svg") ? e.src : ((t) => {
|
|
579
|
+
const i = document.createElement("canvas");
|
|
580
|
+
i.width = t.width, i.height = t.height;
|
|
581
|
+
const n = i.getContext("2d");
|
|
582
|
+
return n ? (n.drawImage(t, 0, 0), i.toDataURL("image/png")) : "";
|
|
583
|
+
})(e.img), $t = ({ shapes: e, settings: t }) => {
|
|
584
|
+
const i = document.createElement("canvas"), n = i.getContext("2d");
|
|
585
|
+
if (!n) throw new Error("No context found for canvas");
|
|
586
|
+
const { realHeight: s, realWidth: a } = t.canvasSize;
|
|
587
|
+
i.width = a, i.height = s, n.clearRect(0, 0, a, s), xn(n);
|
|
588
|
+
for (let o = e.length - 1; o >= 0; o--) Tn(n, e[o], t);
|
|
589
|
+
return i.toDataURL("image/png");
|
|
590
|
+
}, zi = ({ shapes: e, settings: t, view: i }) => {
|
|
591
|
+
if (i === "fitToShapes" && !e.length) throw new Error("No image found to export");
|
|
592
|
+
if (i === "fitToShapes") {
|
|
593
|
+
const s = e.map((c) => {
|
|
594
|
+
const h = K(c, t).borders, u = (c.style?.lineWidth ?? 0) / 2;
|
|
595
|
+
return { minX: h.x - u, minY: h.y - u, maxX: h.x + h.width + u, maxY: h.y + h.height + u };
|
|
596
|
+
}), a = Math.min(...s.map((c) => c.minX)), o = Math.max(...s.map((c) => c.maxX)), r = Math.min(...s.map((c) => c.minY)), l = Math.max(...s.map((c) => c.maxY)), d = { ...t, canvasOffset: [-a, -r], canvasZoom: 1, canvasSize: { realWidth: o - a, realHeight: l - r, width: o - a, height: l - r, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
|
|
597
|
+
return $t({ shapes: e, settings: d });
|
|
598
|
+
}
|
|
599
|
+
if (i === "defaultView") {
|
|
600
|
+
const s = { ...t, canvasOffset: [0, 0], canvasZoom: 1, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: 1, scaleRatioWithNoZoom: 1 } };
|
|
601
|
+
return $t({ shapes: e, settings: s });
|
|
602
|
+
}
|
|
603
|
+
const n = { ...t, canvasSize: { ...t.canvasSize, width: t.canvasSize.realWidth, height: t.canvasSize.realHeight, scaleRatio: t.canvasZoom, scaleRatioWithNoZoom: 1 } };
|
|
604
|
+
return $t({ shapes: e, settings: n });
|
|
605
|
+
}, ya = (e, t, i) => {
|
|
606
|
+
return s = ri(e, t, i), `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(s))}`;
|
|
564
607
|
var s;
|
|
565
|
-
},
|
|
566
|
-
const
|
|
567
|
-
return e.map((
|
|
568
|
-
},
|
|
569
|
-
const n =
|
|
570
|
-
u((
|
|
571
|
-
}, [
|
|
572
|
-
n.current = [
|
|
573
|
-
}, []),
|
|
574
|
-
if (
|
|
575
|
-
const W = n.current.find((
|
|
576
|
-
|
|
577
|
-
}, [e,
|
|
578
|
-
const
|
|
579
|
-
return
|
|
580
|
-
}, [
|
|
581
|
-
n.current = n.current.map((S) => S.id ===
|
|
582
|
-
}, [
|
|
583
|
-
const
|
|
584
|
-
n.current =
|
|
585
|
-
}, [
|
|
586
|
-
l((
|
|
587
|
-
}, [
|
|
588
|
-
u((
|
|
589
|
-
const S =
|
|
590
|
-
return n.current =
|
|
608
|
+
}, Qa = (e) => {
|
|
609
|
+
const t = ["img", "id", "selection", "path", "arrows"];
|
|
610
|
+
return e.map((i) => i.type !== "picture" || i.src.startsWith("http") ? Ut(t, i) : Ut(t, { ...i, src: ma(i) }));
|
|
611
|
+
}, ri = (e, t, i) => ({ shapes: Qa(e), config: { width: t, height: i } }), Ai = (e, t) => dt({ ...e, id: le(`${e.type}_`) }, t), Sa = (e, t, i) => {
|
|
612
|
+
const n = G([]), s = G({ dataChanged: [] }), [a, o] = F(void 0), [r, l] = F(void 0), [d, c] = F(void 0), [h, u] = F({ states: [{ shapes: [], selectedShape: void 0, source: "remote" }], cursor: 0 }), f = h.cursor > 0, v = h.cursor < h.states.length - 1, k = n.current.length > 0, C = D(() => {
|
|
613
|
+
u((m) => wn(m.states[m.cursor].shapes, n.current) ? m : { states: [...m.states.slice(0, m.cursor + 1), { shapes: n.current, selectedShape: r, source: "user" }], cursor: m.cursor + 1 });
|
|
614
|
+
}, [r]), b = D((m) => {
|
|
615
|
+
n.current = [m, ...n.current];
|
|
616
|
+
}, []), Q = D((m, g, S, P) => {
|
|
617
|
+
if (m.target && "className" in m.target && ![Sn, bn].includes(m.target.className) || !P) return void c(void 0);
|
|
618
|
+
const W = n.current.find((O) => O.id === r?.id ? !!ct(r, S, e) : !!Hn(g, O, S, e));
|
|
619
|
+
c(W);
|
|
620
|
+
}, [e, r]), w = D(async (m, g = 300, S = 300) => {
|
|
621
|
+
const P = await da(m, g, S, e);
|
|
622
|
+
return b(P), C(), P;
|
|
623
|
+
}, [b, C, e]), M = D((m, g = !1) => {
|
|
624
|
+
n.current = n.current.map((S) => S.id === r?.id ? m : S), l((S) => S?.id === m.id ? m : S), g && C();
|
|
625
|
+
}, [r, C]), L = D((m) => {
|
|
626
|
+
const g = m.map((S) => Ut(["chosen"], S));
|
|
627
|
+
n.current = g, C();
|
|
628
|
+
}, [C]), Z = D((m) => {
|
|
629
|
+
l((g) => g?.id === m.id ? void 0 : g), n.current = n.current.filter((g) => g.id !== m.id), C();
|
|
630
|
+
}, [C]), z = D((m) => {
|
|
631
|
+
u((g) => {
|
|
632
|
+
const S = m(g);
|
|
633
|
+
return n.current = g.states[S].shapes, l(g.states[S].selectedShape), fe("cursor", S, g);
|
|
591
634
|
});
|
|
592
|
-
}, []), T =
|
|
593
|
-
|
|
594
|
-
}, [
|
|
595
|
-
|
|
596
|
-
}, [
|
|
597
|
-
l(void 0), n.current =
|
|
598
|
-
}, []),
|
|
599
|
-
const S = n.current,
|
|
600
|
-
var O,
|
|
601
|
-
|
|
602
|
-
}, [
|
|
603
|
-
const
|
|
635
|
+
}, []), T = D(() => {
|
|
636
|
+
z((m) => Math.max(0, m.cursor - 1));
|
|
637
|
+
}, [z]), $ = D(() => {
|
|
638
|
+
z((m) => Math.min(m.states.length - 1, m.cursor + 1));
|
|
639
|
+
}, [z]), H = D((m, g) => {
|
|
640
|
+
l(void 0), n.current = m, u((S) => g.clearHistory ? { states: [{ shapes: m, selectedShape: void 0, source: g.source }], cursor: 0 } : { states: [...S.states.slice(0, S.cursor + 1), { shapes: m, selectedShape: void 0, source: g.source }], cursor: S.cursor + 1 });
|
|
641
|
+
}, []), N = D((m, g) => {
|
|
642
|
+
const S = n.current, P = S.findIndex((J) => J.id === m), W = S.findIndex((J) => J.id === g);
|
|
643
|
+
var O, Y, A;
|
|
644
|
+
L((O = S, A = W, (Y = P) < 0 || A < 0 || Y > O.length - 1 || A > O.length - 1 ? O : Y < A ? [...O.slice(0, Y), ...O.slice(Y + 1, A + 1), O[Y], ...O.slice(A + 1, O.length)] : [...O.slice(0, A), O[Y], ...O.slice(A, Y), ...O.slice(Y + 1, O.length)]));
|
|
645
|
+
}, [L]), y = D((m) => {
|
|
646
|
+
const g = n.current, S = g.findIndex((W) => W.id === m.id);
|
|
604
647
|
if (S < 0) return;
|
|
605
|
-
const
|
|
606
|
-
l((
|
|
607
|
-
}, [
|
|
608
|
-
const
|
|
648
|
+
const P = fe("visible", m.visible === !1, m);
|
|
649
|
+
l((W) => W?.id === P.id ? P : W), L(fe(S, P, g));
|
|
650
|
+
}, [L]), E = D((m) => {
|
|
651
|
+
const g = n.current, S = g.findIndex((W) => W.id === m.id);
|
|
609
652
|
if (S < 0) return;
|
|
610
|
-
const
|
|
611
|
-
l((
|
|
612
|
-
}, [
|
|
613
|
-
s.current.hasOwnProperty(
|
|
614
|
-
}, []),
|
|
615
|
-
if (s.current.hasOwnProperty(
|
|
616
|
-
const S = s.current[
|
|
617
|
-
s.current[
|
|
618
|
-
} else s.current[
|
|
653
|
+
const P = fe("locked", !m.locked, m);
|
|
654
|
+
l((W) => W?.id === P.id ? P : W), L(fe(S, P, g));
|
|
655
|
+
}, [L]), B = D((m, g) => {
|
|
656
|
+
s.current.hasOwnProperty(m) && (s.current[m] = [...s.current[m], g]);
|
|
657
|
+
}, []), x = D((m, g) => {
|
|
658
|
+
if (s.current.hasOwnProperty(m)) if (g) {
|
|
659
|
+
const S = s.current[m].indexOf(g);
|
|
660
|
+
s.current[m] = [...s.current[m].slice(0, S), ...s.current[m].slice(S + 1)];
|
|
661
|
+
} else s.current[m] = [];
|
|
619
662
|
}, []);
|
|
620
|
-
|
|
621
|
-
const
|
|
622
|
-
for (const S of s.current.dataChanged) S(
|
|
623
|
-
}, [
|
|
624
|
-
n.current = n.current.map((
|
|
663
|
+
q(() => {
|
|
664
|
+
const m = h.states[h.cursor], g = ri(m.shapes, t, i);
|
|
665
|
+
for (const S of s.current.dataChanged) S(g, m.source);
|
|
666
|
+
}, [t, i, h]), q(() => {
|
|
667
|
+
n.current = n.current.map((m) => dt(m, e)), l((m) => m === void 0 ? void 0 : n.current.find((g) => g.id === m.id));
|
|
625
668
|
}, [e]);
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
const
|
|
629
|
-
const { selectionPadding:
|
|
630
|
-
if (!
|
|
631
|
-
if (
|
|
632
|
-
if (
|
|
633
|
-
const
|
|
634
|
-
for (const
|
|
635
|
-
if (
|
|
636
|
-
if (
|
|
637
|
-
const
|
|
638
|
-
if (
|
|
669
|
+
const V = D((m, g) => {
|
|
670
|
+
o((S) => {
|
|
671
|
+
const P = [S?.[0] ?? [g[0], g[1]], [g[0], g[1]]], W = n.current.filter((O) => ((Y, A, J, j) => {
|
|
672
|
+
const { selectionPadding: se } = j, { center: oe, borders: I } = K(A, j), ce = Be(J[0], A.rotation, oe), re = Be(J[1], A.rotation, oe), be = Math.round(Math.min(ce[0], re[0]) - se / 2), Te = Math.round(Math.max(ce[0], re[0]) + se), we = Math.round(Math.min(ce[1], re[1]) - se / 2), ie = { x: be, y: we, width: Te - be, height: Math.round(Math.max(ce[1], re[1]) + se) - we }, xe = Gt(I, ie);
|
|
673
|
+
if (!xe) return !1;
|
|
674
|
+
if (I.width <= 1 || I.height <= 1 || !("path" in A) || !A.path) return !0;
|
|
675
|
+
if (Y.lineWidth = (A.style?.lineWidth ?? 0) + 10, A.type === "brush") {
|
|
676
|
+
const Ye = A.points.flat(), de = Math.min(...Ye.map((ue) => ue[0])), ze = Math.min(...Ye.map((ue) => ue[1]));
|
|
677
|
+
for (const ue of A.points) {
|
|
678
|
+
if (ue.length < 1) break;
|
|
679
|
+
if (ue.length < 2) {
|
|
680
|
+
const ne = Ce(ue[0], de, ze, A.scaleX, A.scaleY);
|
|
681
|
+
if (Mn(xe, { x: ne[0], y: ne[1], radius: (A.style?.lineWidth ?? 1) / 2 })) return !0;
|
|
639
682
|
}
|
|
640
|
-
for (let
|
|
641
|
-
const
|
|
642
|
-
if (
|
|
643
|
-
const
|
|
644
|
-
if (
|
|
683
|
+
for (let ne = 0; ne < ue.length - 1; ne++) {
|
|
684
|
+
const Pe = Ce(ue[ne], de, ze, A.scaleX, A.scaleY), Me = Ce(ue[ne + 1], de, ze, A.scaleX, A.scaleY), qe = Gt({ x: Math.min(Pe[0], Me[0]), y: Math.min(Pe[1], Me[1]), width: Math.abs(Pe[0] - Me[0]), height: Math.abs(Pe[1] - Me[1]) }, ie);
|
|
685
|
+
if (qe) {
|
|
686
|
+
const Ae = new Path2D();
|
|
687
|
+
if (Ae.moveTo(...Pe), Ae.lineTo(...Me), xi({ ctx: Y, path: Ae, rect: qe, offset: 10, checkFill: !1 })) return !0;
|
|
645
688
|
}
|
|
646
689
|
}
|
|
647
690
|
}
|
|
648
691
|
return !1;
|
|
649
692
|
}
|
|
650
|
-
const
|
|
651
|
-
return
|
|
652
|
-
})(
|
|
653
|
-
return l(
|
|
693
|
+
const Xe = !(!A.style?.fillColor || A.style?.fillColor === "transparent");
|
|
694
|
+
return xi({ ctx: Y, path: A.path, rect: xe, offset: 10, checkFill: Xe });
|
|
695
|
+
})(m, O, P, e));
|
|
696
|
+
return l(W?.[0]), P;
|
|
654
697
|
});
|
|
655
698
|
}, [e]);
|
|
656
|
-
return { registerEvent:
|
|
657
|
-
},
|
|
658
|
-
const t =
|
|
699
|
+
return { registerEvent: B, unregisterEvent: x, shapesRef: n, selectedShape: r, hoveredShape: d, selectionFrame: a, setSelectionFrame: o, refreshSelectedShapes: V, addShape: b, addPictureShape: w, moveShapes: N, saveShapes: C, setSelectedShape: l, refreshHoveredShape: Q, toggleShapeVisibility: y, toggleShapeLock: E, removeShape: Z, updateShape: M, backwardShape: T, forwardShape: $, clearShapes: H, canGoBackward: f, canGoForward: v, canClear: k };
|
|
700
|
+
}, Ei = (e) => {
|
|
701
|
+
const t = [e[0].clientX, e[0].clientY], i = [e[1].clientX, e[1].clientY];
|
|
702
|
+
var n, s;
|
|
703
|
+
return { diff: kn(t, i), center: (s = i, [((n = t)[0] + s[0]) / 2, (n[1] + s[1]) / 2]) };
|
|
704
|
+
}, ba = ({ canvasElt: e, canvasTransformation: t, canvasSize: i, size: n, setCanvasTransformation: s }) => {
|
|
705
|
+
const a = G([]), [o, r] = F(a.current.length > 0), l = G(null), d = G(t);
|
|
706
|
+
d.current = t;
|
|
707
|
+
const c = D(({ startDiff: h, startZoom: u, startCenter: f, startOffset: v, currentDiff: k, currentCenter: C, isMoving: b, isZooming: Q }) => {
|
|
708
|
+
if (!e || !k || !h) return;
|
|
709
|
+
const w = (({ canvasBoundingRect: M, canvasSize: L, size: Z, startDiff: z, startZoom: T, startCenter: $, startOffset: H, currentDiff: N, currentCenter: y, isMoving: E, isZooming: B }) => {
|
|
710
|
+
const x = B ? We(N / z * T, pe[0], pe[pe.length - 1]) : T, V = E ? [H[0] + (y[0] - $[0]) * (L.width / M.width) / L.scaleRatio / T, H[1] + (y[1] - $[1]) * (L.height / M.height) / L.scaleRatio / T] : [H[0], H[1]], m = [(y[0] - M.left) / L.scaleRatio, (y[1] - M.top) / L.scaleRatio];
|
|
711
|
+
return _t({ size: Z, canvasSize: L, currentOffset: V, currentZoom: T, zoom: x, centerPoint: m });
|
|
712
|
+
})({ canvasBoundingRect: e.getBoundingClientRect(), canvasSize: i, size: n, startDiff: h, startZoom: u, startCenter: f, startOffset: v, currentDiff: k, currentCenter: C, isMoving: b, isZooming: Q });
|
|
713
|
+
s(w);
|
|
714
|
+
}, [e, i, n, s]);
|
|
715
|
+
q(() => {
|
|
716
|
+
if (!e) return;
|
|
717
|
+
const h = (u) => {
|
|
718
|
+
if (a.current = [...a.current, u], r(a.current.length > 0), a.current.length === 2) {
|
|
719
|
+
u.stopPropagation();
|
|
720
|
+
const { diff: f, center: v } = Ei(a.current);
|
|
721
|
+
l.current = { startDiff: f, startCenter: v, startZoom: d.current.zoom, startOffset: d.current.offset, isMoving: !1, isZooming: !1 };
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
return e.addEventListener("pointerdown", h), () => {
|
|
725
|
+
e.removeEventListener("pointerdown", h);
|
|
726
|
+
};
|
|
727
|
+
}, [e]), q(() => {
|
|
728
|
+
if (!o) return;
|
|
729
|
+
const h = (f) => {
|
|
730
|
+
const v = a.current.findIndex((k) => k.pointerId === f.pointerId);
|
|
731
|
+
if (v > -1 && (a.current[v] = f), a.current.length === 2 && l.current) {
|
|
732
|
+
const { diff: k, center: C } = Ei(a.current), b = l.current.isZooming || ((w, M) => Math.abs(w - M.startDiff) > 30)(k, l.current), Q = l.current.isMoving || b || ((w, M) => Math.abs(kn(w, M.startCenter)) > 10)(C, l.current);
|
|
733
|
+
l.current = { ...l.current, isMoving: Q, isZooming: b }, c({ ...l.current, currentDiff: k, currentCenter: C });
|
|
734
|
+
}
|
|
735
|
+
}, u = (f) => {
|
|
736
|
+
a.current = a.current.filter((v) => v.pointerId !== f.pointerId), r(a.current.length > 0);
|
|
737
|
+
};
|
|
738
|
+
return document.addEventListener("pointermove", h), document.addEventListener("pointerup", u), document.addEventListener("pointerout", u), document.addEventListener("pointercancel", u), document.addEventListener("pointerleave", u), () => {
|
|
739
|
+
document.removeEventListener("pointermove", h), document.removeEventListener("pointerup", u), document.removeEventListener("pointerout", u), document.removeEventListener("pointercancel", u), document.removeEventListener("pointerleave", u);
|
|
740
|
+
};
|
|
741
|
+
}, [o, c]);
|
|
742
|
+
}, Ca = ({ canvasSize: e, size: t, zoomEnabled: i, canvasElt: n }) => {
|
|
743
|
+
const [s, a] = F({ offset: [0, 0], zoom: 1 }), o = G(0), r = D((d) => {
|
|
744
|
+
a(({ zoom: c }) => Mi({ zoom: c, size: t, canvasSize: e, newOffset: d }));
|
|
745
|
+
}, [e, t]), l = D((d) => {
|
|
746
|
+
a(({ offset: c, zoom: h }) => (({ size: u, canvasSize: f, currentOffset: v, currentZoom: k, action: C }) => {
|
|
747
|
+
const b = C === "default" ? pe[4] : C === "zoom" ? pe[We(pe.length - 1 - pe.slice(0).reverse().findIndex((w) => w <= k) + 1, 0, pe.length - 1)] : pe[We(pe.findIndex((w) => w >= k) - 1, 0, pe.length - 1)], Q = [f.realWidth / 2, f.realHeight / 2];
|
|
748
|
+
return _t({ size: u, canvasSize: f, currentOffset: v, currentZoom: k, zoom: b, centerPoint: Q });
|
|
749
|
+
})({ size: t, canvasSize: e, currentOffset: c, currentZoom: h, action: d }));
|
|
750
|
+
}, [e, t]);
|
|
751
|
+
return ba({ canvasElt: n, canvasTransformation: s, canvasSize: e, size: t, setCanvasTransformation: a }), q(() => {
|
|
752
|
+
if (!i || !n) return;
|
|
753
|
+
const d = (c) => {
|
|
754
|
+
const h = c.ctrlKey, { deltaX: u, deltaY: f } = Jn(c, c.timeStamp - o.current);
|
|
755
|
+
if (o.current = c.timeStamp, h) {
|
|
756
|
+
c.preventDefault();
|
|
757
|
+
const b = ((Q, w, M) => {
|
|
758
|
+
const { clientX: L, clientY: Z } = Ln(Q), z = w.getBoundingClientRect();
|
|
759
|
+
return [(L - z.left) / M.scaleRatio, (Z - z.top) / M.scaleRatio];
|
|
760
|
+
})(c, n, e);
|
|
761
|
+
return void a(({ offset: Q, zoom: w }) => (({ size: M, canvasSize: L, currentOffset: Z, currentZoom: z, delta: T, centerPoint: $ }) => {
|
|
762
|
+
const H = We(z * (1 - T / 1e3), pe[0], pe[pe.length - 1]);
|
|
763
|
+
return _t({ size: M, canvasSize: L, currentOffset: Z, currentZoom: z, zoom: H, centerPoint: $ });
|
|
764
|
+
})({ size: t, canvasSize: e, currentOffset: Q, currentZoom: w, delta: f, centerPoint: b }));
|
|
765
|
+
}
|
|
766
|
+
const v = c.shiftKey, [k, C] = v ? [f, u] : [u, f];
|
|
767
|
+
a(({ offset: b, zoom: Q }) => {
|
|
768
|
+
const w = [b[0] - k / Q, b[1] - C / Q], M = Mi({ zoom: Q, size: t, canvasSize: e, newOffset: w });
|
|
769
|
+
return M.offset[0] === b[0] && M.offset[1] === b[1] || c.preventDefault(), M;
|
|
770
|
+
});
|
|
771
|
+
};
|
|
772
|
+
return n.addEventListener("wheel", d, { passive: !1 }), () => {
|
|
773
|
+
n.removeEventListener("wheel", d);
|
|
774
|
+
};
|
|
775
|
+
}, [n, t, e, i]), { setCanvasTransformation: a, setCanvasOffset: r, setCanvasZoom: l, canvasTransformation: s };
|
|
776
|
+
}, Di = (e, t = !1) => {
|
|
777
|
+
const i = (s, a) => {
|
|
659
778
|
if (Array.isArray(s)) return a;
|
|
660
779
|
}, n = e.map((s) => {
|
|
661
780
|
if (typeof s != "object") return null;
|
|
662
781
|
switch (s.type) {
|
|
663
782
|
case "brush":
|
|
664
|
-
return
|
|
783
|
+
return He(i, rn, s);
|
|
665
784
|
case "circle":
|
|
666
|
-
return
|
|
785
|
+
return He(i, pn, s);
|
|
667
786
|
case "curve":
|
|
668
|
-
return
|
|
787
|
+
return He(i, dn, s);
|
|
669
788
|
case "ellipse":
|
|
670
|
-
return
|
|
789
|
+
return He(i, gn, s);
|
|
671
790
|
case "line":
|
|
672
|
-
return
|
|
791
|
+
return He(i, ln, s);
|
|
673
792
|
case "polygon":
|
|
674
|
-
return
|
|
793
|
+
return He(i, cn, s);
|
|
675
794
|
case "rect":
|
|
676
|
-
return
|
|
795
|
+
return He(i, hn, s);
|
|
677
796
|
case "square":
|
|
678
|
-
return
|
|
797
|
+
return He(i, un, s);
|
|
679
798
|
case "text":
|
|
680
|
-
return
|
|
799
|
+
return He(i, fn, s);
|
|
681
800
|
}
|
|
682
801
|
return null;
|
|
683
802
|
});
|
|
684
|
-
return
|
|
685
|
-
},
|
|
686
|
-
const { layersManipulation:
|
|
687
|
-
|
|
688
|
-
}, []), [
|
|
689
|
-
const [
|
|
690
|
-
return
|
|
691
|
-
if (!
|
|
692
|
-
const
|
|
693
|
-
Ie(
|
|
803
|
+
return oi(t ? [...n, ii] : n);
|
|
804
|
+
}, rs = ({ width: e = 1e3, height: t = 600, shapes: i, mode: n = "editor", disabled: s = !1, options: a = Qi } = {}) => {
|
|
805
|
+
const { layersManipulation: o, brushAlgo: r, isBrushShapeDoneOnMouseUp: l, grid: d, canGrow: c, canShrink: h, withExport: u, withLoadAndSave: f, withUploadPicture: v, withUrlPicture: k, withSkeleton: C, withFrameSelection: b, clearCallback: Q, availableTools: w, canvasSelectionPadding: M, size: L, canZoom: Z } = { ...Qi, ...a }, z = n !== "viewer", T = G(null), $ = G(null), H = G(!1), N = D((_) => {
|
|
806
|
+
T.current = _;
|
|
807
|
+
}, []), [y, E] = F(void 0), [B, x] = F(Ze), [V, m] = F({ mode: "default" }), [g, S] = F(d), [P, W] = F({ realWidth: e, realHeight: t, width: e, height: t, scaleRatio: 1 }), O = Z === "always" && !s, { canvasTransformation: Y, setCanvasTransformation: A, setCanvasOffset: J, setCanvasZoom: j } = Ca({ canvasSize: P, size: L, canvasElt: $.current, zoomEnabled: O }), { offset: se, zoom: oe } = Y, I = ji(() => ({ brushAlgo: r, isBrushShapeDoneOnMouseUp: l, canvasSize: { realWidth: P.realWidth, realHeight: P.realHeight, width: P.width, height: P.height, scaleRatioWithNoZoom: P.scaleRatio, scaleRatio: P.scaleRatio * oe }, size: L, canvasOffset: se, canvasZoom: oe, gridGap: g, selectionPadding: M, features: { edition: z && !s, zoom: O } }), [M, g, r, l, oe, se, P, L, s, O, z]), [ce, re] = F(Di(w, v || k)), { isInsideComponent: be } = (({ settings: _, componentRef: Qe }) => {
|
|
808
|
+
const [at, Ie] = F(!1), Fe = !_.features.edition && !_.features.zoom;
|
|
809
|
+
return q(() => {
|
|
810
|
+
if (!Fe) {
|
|
811
|
+
const ke = (st) => {
|
|
812
|
+
Ie(Cn(st, Qe.current));
|
|
694
813
|
};
|
|
695
|
-
return document.addEventListener("mousedown",
|
|
696
|
-
document.removeEventListener("mousedown",
|
|
814
|
+
return document.addEventListener("mousedown", ke, { passive: !0 }), document.addEventListener("touchstart", ke, { passive: !0 }), () => {
|
|
815
|
+
document.removeEventListener("mousedown", ke), document.removeEventListener("touchstart", ke);
|
|
697
816
|
};
|
|
698
817
|
}
|
|
699
818
|
Ie(!1);
|
|
700
|
-
}, [
|
|
701
|
-
})({
|
|
702
|
-
|
|
703
|
-
}, [
|
|
704
|
-
|
|
705
|
-
}, [
|
|
706
|
-
|
|
707
|
-
}, [
|
|
708
|
-
const
|
|
709
|
-
if (!
|
|
710
|
-
|
|
711
|
-
}, [
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
const it = await (async (Ie, He) => {
|
|
819
|
+
}, [Fe, Qe]), { isInsideComponent: at };
|
|
820
|
+
})({ settings: I, componentRef: T }), { registerEvent: Te, unregisterEvent: we, shapesRef: ie, selectedShape: xe, selectionFrame: Xe, hoveredShape: Ye, addShape: de, addPictureShape: ze, moveShapes: ue, setSelectedShape: ne, setSelectionFrame: Pe, refreshSelectedShapes: Me, refreshHoveredShape: qe, removeShape: Ae, updateShape: ye, backwardShape: ut, forwardShape: pt, clearShapes: gt, saveShapes: Pt, toggleShapeVisibility: Vt, toggleShapeLock: Zt, canGoBackward: Tt, canGoForward: zt, canClear: ae } = Sa(I, e, t), te = D((_) => {
|
|
821
|
+
ne(void 0), x(_);
|
|
822
|
+
}, [ne]), Ne = D((_, Qe) => {
|
|
823
|
+
gt(_, Qe), te(Ze), A({ offset: [0, 0], zoom: 1 });
|
|
824
|
+
}, [te, gt, A]), Ee = D((_) => {
|
|
825
|
+
x(Ze), ne(_);
|
|
826
|
+
}, [ne]), nt = D(() => {
|
|
827
|
+
const _ = ya(ie.current, e, t);
|
|
828
|
+
if (!_) throw new Error("L'encodage a échoué");
|
|
829
|
+
Ti(_, "drawing.json");
|
|
830
|
+
}, [ie, e, t]), Wn = D((_) => {
|
|
831
|
+
const Qe = zi({ shapes: ie.current, settings: I, view: _ });
|
|
832
|
+
Ti(Qe, "drawing.png");
|
|
833
|
+
}, [ie, I]), Rn = D((_) => zi({ shapes: ie.current, settings: I, view: _ }), [ie, I]), Nn = D(() => ri(ie.current, e, t), [ie, e, t]);
|
|
834
|
+
q(() => {
|
|
835
|
+
be || ne(void 0);
|
|
836
|
+
}, [be, ne]);
|
|
837
|
+
const Oe = D(async (_, Qe) => {
|
|
838
|
+
const at = await (async (Ie, Fe) => {
|
|
721
839
|
if (!Ie) return [];
|
|
722
|
-
const
|
|
723
|
-
if (!
|
|
724
|
-
if (
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
URL.revokeObjectURL(
|
|
728
|
-
},
|
|
729
|
-
|
|
840
|
+
const ke = [], st = oi(Ie.map((ve) => {
|
|
841
|
+
if (!ve || !Qn.includes(ve.type)) return null;
|
|
842
|
+
if (ve.type === "picture") {
|
|
843
|
+
const Le = new Image(), $n = new Promise((ot, Bn) => {
|
|
844
|
+
Le.onload = () => {
|
|
845
|
+
URL.revokeObjectURL(Le.src), ot();
|
|
846
|
+
}, Le.onerror = () => {
|
|
847
|
+
Bn(new Error("Some images could not be loaded"));
|
|
730
848
|
};
|
|
731
849
|
});
|
|
732
|
-
if (
|
|
733
|
-
|
|
850
|
+
if (ke.push($n), ve.src.startsWith("http")) En(ve.src).then((ot) => {
|
|
851
|
+
Le.src = ot;
|
|
734
852
|
}).catch(() => {
|
|
735
|
-
|
|
853
|
+
Le.src = "";
|
|
736
854
|
});
|
|
737
|
-
else if (
|
|
738
|
-
const
|
|
739
|
-
|
|
740
|
-
} else
|
|
741
|
-
return
|
|
855
|
+
else if (ve.src.includes("<svg")) {
|
|
856
|
+
const ot = new Blob([ve.src], { type: "image/svg+xml" });
|
|
857
|
+
Le.src = URL.createObjectURL(ot);
|
|
858
|
+
} else Le.src = ve.src;
|
|
859
|
+
return Ai({ ...ve, img: Le }, Fe);
|
|
742
860
|
}
|
|
743
|
-
return
|
|
861
|
+
return Ai(ve, Fe);
|
|
744
862
|
}));
|
|
745
|
-
return await Promise.all(
|
|
746
|
-
})(
|
|
747
|
-
|
|
748
|
-
}, [
|
|
749
|
-
|
|
750
|
-
const
|
|
751
|
-
|
|
863
|
+
return await Promise.all(ke), st;
|
|
864
|
+
})(_, I);
|
|
865
|
+
Ne(at, Qe);
|
|
866
|
+
}, [Ne, I]), At = G(Oe);
|
|
867
|
+
At.current = Oe;
|
|
868
|
+
const On = D((_ = [], Qe = !0) => {
|
|
869
|
+
At.current?.(_, { clearHistory: Qe, source: "remote" });
|
|
752
870
|
}, []);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
}, [
|
|
756
|
-
const
|
|
757
|
-
const
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
const
|
|
761
|
-
if (!
|
|
762
|
-
const
|
|
763
|
-
Ie(
|
|
764
|
-
},
|
|
765
|
-
}))(
|
|
766
|
-
await
|
|
767
|
-
}, [
|
|
768
|
-
typeof
|
|
769
|
-
}, [
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
}, [
|
|
773
|
-
const
|
|
774
|
-
return { editorProps: { shapesRef:
|
|
775
|
-
},
|
|
776
|
-
let
|
|
871
|
+
q(() => {
|
|
872
|
+
H.current || (H.current = !0, i && At.current?.(i, { clearHistory: !0, source: "remote" }));
|
|
873
|
+
}, [i]);
|
|
874
|
+
const In = D(async (_) => {
|
|
875
|
+
const Qe = await (async (at) => new Promise((Ie, Fe) => {
|
|
876
|
+
const ke = new FileReader();
|
|
877
|
+
ke.onload = (st) => {
|
|
878
|
+
const ve = st.target?.result;
|
|
879
|
+
if (!ve) return Fe("Impossible de récupérer les données du fichier");
|
|
880
|
+
const Le = JSON.parse(ve);
|
|
881
|
+
Ie(Le);
|
|
882
|
+
}, ke.readAsText(at);
|
|
883
|
+
}))(_);
|
|
884
|
+
await Oe(Qe.shapes ?? [], { clearHistory: !0, source: "remote" });
|
|
885
|
+
}, [Oe]), Fn = D(() => {
|
|
886
|
+
typeof Q != "string" ? Oe(Q(), { clearHistory: !1, source: "user" }) : Q === "defaultShapes" && i !== void 0 ? Oe(i, { clearHistory: !1, source: "user" }) : Ne([], { clearHistory: !1, source: "user" });
|
|
887
|
+
}, [Ne, Oe, i, Q]);
|
|
888
|
+
q(() => {
|
|
889
|
+
re(Di(w, v || k));
|
|
890
|
+
}, [w, v, k]);
|
|
891
|
+
const ci = { canvas: $, editor: T, setEditor: N };
|
|
892
|
+
return { annotationsProps: { style: { "user-select": "none", "touch-action": "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": I.canvasZoom, "--react-paint-canvas-offset-x": I.canvasOffset[0], "--react-paint-canvas-offset-y": I.canvasOffset[1], "--react-paint-app-canvaswidth": e, "--react-paint-app-canvasheight": t } }, editorProps: { shapesRef: ie, addPictureShape: ze, moveShapes: ue, toggleShapeVisibility: Vt, toggleShapeLock: Zt, canGoBackward: Tt, canGoForward: zt, canClear: ae, selectedShape: xe, removeShape: Ae, updateShape: ye, backwardShape: ut, forwardShape: pt, refs: ci, width: e, height: t, selectTool: te, selectShape: Ee, activeTool: B, setActiveTool: x, setAvailableTools: re, isEditMode: z, availableTools: ce, gridGap: g, setGridGap: S, loadFile: In, exportPicture: Wn, exportData: nt, clearCanvas: Fn, settings: I, setCanvasZoom: j, canvas: { canGrow: c, canShrink: h, layersManipulation: o, withExport: u, withLoadAndSave: f, withUploadPicture: v, withUrlPicture: k } }, canvasProps: { shapesRef: ie, selectedShape: xe, selectionFrame: Xe, hoveredShape: Ye, addShape: de, setSelectedShape: ne, setSelectionFrame: Pe, refreshSelectedShapes: Me, refreshHoveredShape: qe, removeShape: Ae, updateShape: ye, backwardShape: ut, forwardShape: pt, saveShapes: Pt, refs: ci, width: e, height: t, settings: I, setCanvasSize: W, setCanvasOffset: J, setCanvasZoom: j, selectShape: Ee, activeTool: B, setActiveTool: x, isInsideComponent: be, isEditMode: z, canvas: { withSkeleton: C, withFrameSelection: b, canGrow: c, canShrink: h }, canvasOffsetStartData: y, setCanvasOffsetStartData: E, selectionMode: V, setSelectionMode: m }, registerEvent: Te, unregisterEvent: we, resetCanvas: On, getCurrentImage: Rn, getCurrentData: Nn, setCanvasOffset: J, setCanvasZoom: j };
|
|
893
|
+
}, wa = (e, t, i, n, s, a, o) => {
|
|
894
|
+
let r = !1;
|
|
777
895
|
if (s) {
|
|
778
|
-
|
|
779
|
-
const
|
|
780
|
-
if (
|
|
781
|
-
if (
|
|
782
|
-
const { center:
|
|
783
|
-
return { mode: "rotate", cursorStartPosition: u, originalShape:
|
|
896
|
+
r = ct(s, i, n, !0, a ? 20 : void 0);
|
|
897
|
+
const d = ((c, h, u, f) => {
|
|
898
|
+
if (c.mode === "translate") return { mode: "translate", cursorStartPosition: u, originalShape: h };
|
|
899
|
+
if (c.mode === "rotate") {
|
|
900
|
+
const { center: v } = K(h, f);
|
|
901
|
+
return { mode: "rotate", cursorStartPosition: u, originalShape: h, center: [v[0], v[1]] };
|
|
784
902
|
}
|
|
785
|
-
return
|
|
786
|
-
})(
|
|
787
|
-
if (
|
|
903
|
+
return c.mode === "resize" ? { mode: "resize", cursorStartPosition: u, originalShape: h, anchor: c.anchor } : void 0;
|
|
904
|
+
})(r || { mode: "default" }, s, i, n);
|
|
905
|
+
if (d?.mode === "resize" || d?.mode === "rotate") return { shape: s, mode: d };
|
|
788
906
|
}
|
|
789
|
-
const l =
|
|
790
|
-
return l ? { shape: l, mode: { mode: "translate", cursorStartPosition:
|
|
791
|
-
},
|
|
792
|
-
const [
|
|
793
|
-
const
|
|
794
|
-
const
|
|
795
|
-
|
|
907
|
+
const l = t.find((d) => d.id === s?.id ? !!r : !!Hn(e, d, i, n));
|
|
908
|
+
return l ? { shape: l, mode: { mode: "translate", cursorStartPosition: i, originalShape: l } } : { shape: void 0, mode: { mode: o ? "selectionFrame" : "default" } };
|
|
909
|
+
}, xa = ({ addShape: e, drawCanvasRef: t, setActiveTool: i, refreshHoveredShape: n, shapes: s, selectionMode: a, activeTool: o, isInsideComponent: r, setCanvasOffset: l, selectedShape: d, canvasOffsetStartData: c, refreshSelectedShapes: h, setSelectedShape: u, setSelectionFrame: f, setCanvasOffsetStartData: v, updateSingleShape: k, saveShapes: C, setSelectionMode: b, settings: Q, isShiftPressed: w, withFrameSelection: M }) => {
|
|
910
|
+
const [L, Z] = F({ mode: "default" }), { registerDoubleClickEvent: z, unRegisterDoubleClickEvent: T } = (() => {
|
|
911
|
+
const x = G(void 0), V = G(void 0), m = (g) => {
|
|
912
|
+
const S = Date.now();
|
|
913
|
+
x.current && S < x.current + 300 && V.current?.(g), x.current = Date.now();
|
|
796
914
|
};
|
|
797
|
-
return { registerDoubleClickEvent: (
|
|
798
|
-
|
|
799
|
-
}, unRegisterDoubleClickEvent: (
|
|
800
|
-
|
|
915
|
+
return { registerDoubleClickEvent: (g, S) => {
|
|
916
|
+
V.current = S, g.addEventListener("click", m), g.addEventListener("touchend", m);
|
|
917
|
+
}, unRegisterDoubleClickEvent: (g) => {
|
|
918
|
+
g.removeEventListener("click", m), g.removeEventListener("touchend", m);
|
|
801
919
|
} };
|
|
802
|
-
})();
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
if (
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
920
|
+
})(), $ = G(null);
|
|
921
|
+
$.current = (x) => ((V, m, g, S, P, W, O, Y, A, J, j, se) => {
|
|
922
|
+
if (rt(V) && V.touches.length > 1) return;
|
|
923
|
+
const oe = m.current?.getContext("2d");
|
|
924
|
+
if (!oe) return;
|
|
925
|
+
const I = Nt(V, m.current, j);
|
|
926
|
+
if (P !== void 0) return void A([I[0] + j.canvasOffset[0] - P.start[0], I[1] + j.canvasOffset[1] - P.start[1]]);
|
|
927
|
+
if (S.mode === "selectionFrame") return void J(oe, I, j);
|
|
928
|
+
const ce = Ot(I, j);
|
|
929
|
+
if (rt(V) || O(V, oe, I, ce), g === void 0 || g.locked) W({ mode: "default", outOfView: !ce });
|
|
930
|
+
else if (S.mode === "default" || S.mode === "textedition") {
|
|
931
|
+
if (!ce) return void W({ mode: "default" });
|
|
932
|
+
W(ct(g, I, j, !0) || { mode: "default" });
|
|
933
|
+
} else {
|
|
934
|
+
const re = m.current?.getContext("2d");
|
|
935
|
+
if (!re) return;
|
|
936
|
+
Y(Kn(re, g, I, S, j, se));
|
|
937
|
+
}
|
|
938
|
+
})(x, t, d, a, c, Z, n, k, l, h, Q, w), q(() => {
|
|
939
|
+
if (r) {
|
|
940
|
+
const x = (V) => $.current?.(V);
|
|
941
|
+
return document.addEventListener("mousemove", x), document.addEventListener("touchmove", x), () => {
|
|
942
|
+
document.removeEventListener("mousemove", x), document.removeEventListener("touchmove", x);
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
}, [r]);
|
|
946
|
+
const { isBrushShapeDoneOnMouseUp: H } = Q, N = G(null);
|
|
947
|
+
N.current = (x) => {
|
|
948
|
+
rt(x) && x.touches.length > 1 || (c ? v(void 0) : a.mode !== "textedition" && a.mode !== "default" && (a.mode === "brush" && H && u(void 0), b({ mode: "default" }), f(void 0), C()));
|
|
949
|
+
}, q(() => {
|
|
950
|
+
if (r) {
|
|
951
|
+
const x = (V) => N.current?.(V);
|
|
952
|
+
return document.addEventListener("mouseup", x), document.addEventListener("touchend", x), () => {
|
|
953
|
+
document.removeEventListener("mouseup", x), document.removeEventListener("touchend", x);
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
}, [r]);
|
|
957
|
+
const y = !Q.features.edition && Q.features.zoom, E = !Q.features.edition && !Q.features.zoom, B = G(null);
|
|
958
|
+
return B.current = (x, V) => {
|
|
959
|
+
if (x.preventDefault(), rt(x) && x.touches.length > 1) return;
|
|
960
|
+
const m = V?.getContext("2d");
|
|
961
|
+
if (!m) return;
|
|
962
|
+
const g = Nt(x, t.current, Q);
|
|
963
|
+
if ("button" in x && x.button === 1 || o.type === "move") v({ start: g, originalOffset: Q.canvasOffset });
|
|
964
|
+
else if (!y) {
|
|
965
|
+
if (!Ot(g, Q)) return u(void 0), void b({ mode: "default" });
|
|
838
966
|
if (o.type === "selection") {
|
|
839
|
-
const { shape:
|
|
840
|
-
|
|
841
|
-
} else if (
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
if (!v) return;
|
|
967
|
+
const { shape: S, mode: P } = wa(m, s, g, Q, d, rt(x), M);
|
|
968
|
+
u(S), b(P), P.mode === "selectionFrame" && f([[g[0], g[1]], [g[0], g[1]]]);
|
|
969
|
+
} else if (Qn.some((S) => S === o.type)) {
|
|
970
|
+
const S = t.current?.getContext("2d");
|
|
971
|
+
if (!S) return;
|
|
845
972
|
if (o.type === "brush") {
|
|
846
973
|
if (d?.type === "brush") {
|
|
847
|
-
const
|
|
848
|
-
const
|
|
849
|
-
return
|
|
850
|
-
})(d,
|
|
851
|
-
|
|
974
|
+
const P = ((W, O, Y) => {
|
|
975
|
+
const A = { ...W, points: fe(W.points.length, [[Math.round(O[0]), Math.round(O[1])]], W.points) };
|
|
976
|
+
return it(A, Y);
|
|
977
|
+
})(d, g, Q);
|
|
978
|
+
k(P);
|
|
852
979
|
} else {
|
|
853
|
-
const
|
|
854
|
-
if (!
|
|
855
|
-
|
|
980
|
+
const P = Vi(S, o, g, Q);
|
|
981
|
+
if (!P) return;
|
|
982
|
+
e(P), u(P);
|
|
856
983
|
}
|
|
857
984
|
b({ mode: "brush" });
|
|
858
985
|
} else if (o.type !== "picture") {
|
|
859
|
-
const
|
|
860
|
-
|
|
986
|
+
const P = Vi(S, o, g, Q);
|
|
987
|
+
e(P), i(Ze), u(P), b({ mode: "resize", cursorStartPosition: [g[0] + Q.selectionPadding, g[1] + Q.selectionPadding], originalShape: P, anchor: o.type === "line" || o.type === "polygon" || o.type === "curve" ? 0 : [1, 1] });
|
|
861
988
|
}
|
|
862
989
|
}
|
|
990
|
+
}
|
|
991
|
+
}, q(() => {
|
|
992
|
+
if (E) return;
|
|
993
|
+
const x = t.current;
|
|
994
|
+
if (!x) return;
|
|
995
|
+
const V = (m) => B.current?.(m, x);
|
|
996
|
+
return x.addEventListener("mousedown", V, { passive: !1 }), x.addEventListener("touchstart", V, { passive: !1 }), () => {
|
|
997
|
+
x.removeEventListener("mousedown", V), x.removeEventListener("touchstart", V);
|
|
863
998
|
};
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
const y = c.current;
|
|
869
|
-
if (y)
|
|
870
|
-
return l ? (C(y, (N) => {
|
|
999
|
+
}, [E, t]), q(() => {
|
|
1000
|
+
const x = t.current;
|
|
1001
|
+
if (x)
|
|
1002
|
+
return r ? (z(x, (V) => {
|
|
871
1003
|
if (o.type === "selection" && d?.type === "text") {
|
|
872
|
-
const
|
|
873
|
-
|
|
1004
|
+
const m = Nt(V, t.current, Q);
|
|
1005
|
+
if (!Ot(m, Q)) return;
|
|
1006
|
+
ct(d, m, Q) && b({ mode: "textedition", defaultValue: d.value });
|
|
874
1007
|
}
|
|
875
1008
|
}), () => {
|
|
876
|
-
|
|
1009
|
+
T(x);
|
|
877
1010
|
}) : void 0;
|
|
878
|
-
}, [
|
|
879
|
-
},
|
|
880
|
-
const o =
|
|
881
|
-
|
|
1011
|
+
}, [z, T, r, t, o, d, b, Q]), { hoverMode: L };
|
|
1012
|
+
}, Dn = (e) => e.childNodes.length ? Array.from(e.childNodes).map((t) => Dn(t)).join("") : e.nodeValue ?? "", Ma = ({ disabled: e = !1, shape: t, defaultValue: i, updateValue: n, saveShapes: s, settings: a }) => {
|
|
1013
|
+
const o = G(null), r = G(s);
|
|
1014
|
+
q(() => {
|
|
882
1015
|
if (!o.current) return;
|
|
883
|
-
const d = o.current, c = (
|
|
884
|
-
|
|
885
|
-
const
|
|
886
|
-
document.execCommand("insertText", !1,
|
|
1016
|
+
const d = o.current, c = (h) => {
|
|
1017
|
+
h.preventDefault();
|
|
1018
|
+
const u = h.clipboardData?.getData("text/plain");
|
|
1019
|
+
document.execCommand("insertText", !1, u);
|
|
887
1020
|
};
|
|
888
1021
|
d.addEventListener("paste", c), d.innerText = "";
|
|
889
|
-
for (const
|
|
890
|
-
const
|
|
891
|
-
|
|
1022
|
+
for (const h of i) {
|
|
1023
|
+
const u = document.createElement("div");
|
|
1024
|
+
h === "" ? u.innerHTML = "<br/>" : u.innerText = h, d.appendChild(u);
|
|
892
1025
|
}
|
|
893
1026
|
return d.focus(), () => {
|
|
894
1027
|
d.removeEventListener("paste", c);
|
|
895
1028
|
};
|
|
896
|
-
}, [
|
|
897
|
-
const d =
|
|
1029
|
+
}, [i]), q(() => {
|
|
1030
|
+
const d = r.current;
|
|
898
1031
|
return () => {
|
|
899
1032
|
d();
|
|
900
1033
|
};
|
|
901
1034
|
}, []);
|
|
902
|
-
const
|
|
903
|
-
const { borders: d, center: c } =
|
|
904
|
-
return
|
|
905
|
-
}, [t,
|
|
1035
|
+
const l = ji(() => {
|
|
1036
|
+
const { borders: d, center: c } = K(t, a);
|
|
1037
|
+
return me({ point: [d.x, d.y], rotation: -t.rotation, origin: c });
|
|
1038
|
+
}, [t, a]);
|
|
906
1039
|
return p("div", { className: "react-paint-editor-toolbox-edittextbox", ref: o, "data-fontbold": t.style?.fontBold ?? !1, "data-fontitalic": t.style?.fontItalic ?? !1, contentEditable: !e, onInput: (d) => {
|
|
907
|
-
const c = Array.from(d.target.childNodes).map((
|
|
908
|
-
|
|
909
|
-
}, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${
|
|
910
|
-
},
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1040
|
+
const c = Array.from(d.target.childNodes).map((h) => Dn(h));
|
|
1041
|
+
n(c);
|
|
1042
|
+
}, style: { "--react-paint-editor-toolbox-edittextbox-transform": `translate3D(${(l[0] + a.canvasOffset[0]) * a.canvasSize.scaleRatio}px, ${(l[1] + a.canvasOffset[1]) * a.canvasSize.scaleRatio}px, 0) rotate(${qt(t.rotation)}deg)`, "--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 ?? ht } });
|
|
1043
|
+
}, ka = (e, t, i, n, s) => {
|
|
1044
|
+
xn(e), ((a, o) => {
|
|
1045
|
+
const { canvasZoom: r, size: l, canvasSize: { width: d, height: c } } = o;
|
|
1046
|
+
if (l !== "fixed" || r >= 1) return;
|
|
1047
|
+
a.fillStyle = "#f5f5f5", a.fillRect(0, 0, d, c);
|
|
1048
|
+
const h = Pn(o);
|
|
1049
|
+
a.clearRect(h.x, h.y, h.width, h.height), Vn(a, o);
|
|
1050
|
+
})(e, i), ((a, o) => {
|
|
1051
|
+
const { canvasSize: { width: r, height: l }, gridGap: d, canvasOffset: c, canvasSize: { scaleRatio: h } } = o;
|
|
1052
|
+
if (!d) return;
|
|
1053
|
+
a.strokeStyle = "rgb(220,220,220)", a.lineWidth = 1, a.save(), a.scale(h, h), a.beginPath();
|
|
1054
|
+
const u = c[0] % d, f = c[1] % d, v = Math.ceil(r / h / d) + 2, k = Math.ceil(l / h / d) + 2;
|
|
1055
|
+
for (let C = -5; C < v; C++) a.moveTo(u + (C + 1) * d, f - d), a.lineTo(u + (C + 1) * d, f + l / h + d);
|
|
1056
|
+
for (let C = -5; C < k; C++) a.moveTo(u - d, f + (C + 1) * d), a.lineTo(u + r / h + d, f + (C + 1) * d);
|
|
1057
|
+
a.stroke(), a.restore();
|
|
1058
|
+
})(e, i);
|
|
1059
|
+
for (let a = n.length - 1; a >= 0; a--) t.mode === "textedition" && n[a] === s || Tn(e, n[a], i);
|
|
1060
|
+
}, La = _i.forwardRef(({ canGrow: e, shapes: t, addShape: i, updateSingleShape: n, selectedShape: s, setSelectedShape: a, setSelectionFrame: o, hoveredShape: r, selectionFrame: l, refreshHoveredShape: d, refreshSelectedShapes: c, saveShapes: h, activeTool: u, setActiveTool: f, canvasOffsetStartData: v, setCanvasOffsetStartData: k, setCanvasOffset: C, isInsideComponent: b, selectionMode: Q, setSelectionMode: w, selectionWidth: M, selectionColor: L, settings: Z, isEditMode: z, isShiftPressed: T, withFrameSelection: $, withSkeleton: H }, N) => {
|
|
1061
|
+
const y = G(null), E = G(null), B = Z.canvasSize, x = z;
|
|
1062
|
+
Un(N, () => y.current);
|
|
1063
|
+
const { hoverMode: V } = xa({ addShape: i, drawCanvasRef: y, setActiveTool: f, shapes: t, selectionMode: Q, activeTool: u, isInsideComponent: b, setCanvasOffset: C, selectedShape: s, canvasOffsetStartData: v, setCanvasOffsetStartData: k, setSelectedShape: a, setSelectionFrame: o, refreshHoveredShape: d, refreshSelectedShapes: c, updateSingleShape: n, saveShapes: h, setSelectionMode: w, isShiftPressed: T, withFrameSelection: $, settings: Z }), m = D((g) => {
|
|
1064
|
+
if (s?.type !== "text") return;
|
|
1065
|
+
const S = y.current?.getContext("2d");
|
|
927
1066
|
if (!S) return;
|
|
928
|
-
const
|
|
929
|
-
|
|
930
|
-
}, [
|
|
931
|
-
return
|
|
932
|
-
const
|
|
933
|
-
|
|
934
|
-
}, [
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
S.
|
|
938
|
-
})(
|
|
939
|
-
}, [
|
|
940
|
-
}),
|
|
941
|
-
const [
|
|
942
|
-
return
|
|
943
|
-
const
|
|
944
|
-
|
|
945
|
-
},
|
|
946
|
-
|
|
947
|
-
},
|
|
948
|
-
|
|
949
|
-
},
|
|
950
|
-
if (
|
|
951
|
-
if (
|
|
952
|
-
if (
|
|
1067
|
+
const P = dt(ua(S, s, g, Z), Z);
|
|
1068
|
+
n(P);
|
|
1069
|
+
}, [n, s, Z]);
|
|
1070
|
+
return q(() => {
|
|
1071
|
+
const g = y.current?.getContext("2d");
|
|
1072
|
+
g && window.requestAnimationFrame(() => ka(g, Q, Z, t, s));
|
|
1073
|
+
}, [t, Q, s, Z]), q(() => {
|
|
1074
|
+
const g = E.current?.getContext("2d");
|
|
1075
|
+
g && window.requestAnimationFrame(() => ((S, P, W, O, Y, A, J, j, se, oe) => {
|
|
1076
|
+
S.reset(), Vn(S, W), oe && j && j.id !== J?.id && O.type === "selection" && P.mode === "default" && Zi({ ctx: S, shape: j, settings: W, selectionWidth: Y, selectionColor: A, withAnchors: !1 }), J && O.type !== "brush" && Zi({ ctx: S, shape: J, settings: W, selectionWidth: Y, selectionColor: A, withAnchors: P.mode !== "textedition" }), se && va({ ctx: S, selectionFrame: se, settings: W });
|
|
1077
|
+
})(g, Q, Z, u, M, L, s, r, l, H));
|
|
1078
|
+
}, [r, l, Q, s, u, Z, M, L, H]), p("div", { className: "react-paint-canvas-box", style: { "--react-paint-canvas-cursor": v ? "grabbing" : V.outOfView ? "default" : u.type !== "selection" && u.type !== "move" || V.mode === "resize" ? "crosshair" : V.mode === "translate" ? "move" : V.mode === "rotate" || u.type === "move" ? "grab" : "default" }, children: R("div", { className: "react-paint-canvas-container", "data-grow": e, children: [p("canvas", { className: Sn, ref: y, "data-grow": e, width: B.width, height: B.height }), x && p("canvas", { className: bn, ref: E, width: B.width, height: B.height, "data-grow": e }), z && Q.mode === "textedition" && s?.type === "text" && p(Ma, { disabled: !Z.features.edition, shape: s, defaultValue: Q.defaultValue, updateValue: m, saveShapes: h, settings: Z })] }) });
|
|
1079
|
+
}), Wi = "ArrowUp", Ri = "ArrowDown", Ni = "ArrowLeft", Oi = "ArrowRight", Ha = "Delete", Pa = "Backspace", Va = "Escape", Ii = "Shift", Za = "z", Ta = "Z", za = "y", Aa = "Y", Fi = "copy", $i = "paste", Ea = ({ isInsideComponent: e, selectedShape: t, isEditingText: i, settings: n, setSelectedShape: s, removeShape: a, pasteShape: o, updateShape: r, backwardShape: l, forwardShape: d, setShiftPressed: c }) => {
|
|
1080
|
+
const [h, u] = F(void 0);
|
|
1081
|
+
return q(() => {
|
|
1082
|
+
const f = (b) => {
|
|
1083
|
+
t && (i || (b.preventDefault(), u({ ...t })));
|
|
1084
|
+
}, v = (b) => {
|
|
1085
|
+
h && (i || (b.preventDefault(), o(((Q, w) => ({ ...jt([20, 20], Q, [0, 0], w), id: le(`${Q.type}_`) }))(h, n))));
|
|
1086
|
+
}, k = (b) => {
|
|
1087
|
+
b.key === Ii && c(!1);
|
|
1088
|
+
}, C = (b) => {
|
|
1089
|
+
if (b.metaKey || b.ctrlKey) {
|
|
1090
|
+
if (b.key === Ta || b.key === Za) return b.preventDefault(), b.stopPropagation(), void l();
|
|
1091
|
+
if (b.key === Aa || b.key === za) return b.preventDefault(), b.stopPropagation(), void d();
|
|
953
1092
|
}
|
|
954
|
-
if (
|
|
955
|
-
if (!
|
|
956
|
-
if (
|
|
957
|
-
if (
|
|
958
|
-
const
|
|
959
|
-
switch (
|
|
960
|
-
case
|
|
961
|
-
case
|
|
962
|
-
case
|
|
963
|
-
case
|
|
964
|
-
|
|
1093
|
+
if (b.key === Ii) return void c(!0);
|
|
1094
|
+
if (!t) return;
|
|
1095
|
+
if (b.key === Va) return void s(void 0);
|
|
1096
|
+
if (i) return;
|
|
1097
|
+
const Q = { [Ni]: [n.gridGap ? -n.gridGap : -1, 0], [Oi]: [n.gridGap ? n.gridGap : 1, 0], [Ri]: [0, n.gridGap ? n.gridGap : 1], [Wi]: [0, n.gridGap ? -n.gridGap : -1] };
|
|
1098
|
+
switch (b.key) {
|
|
1099
|
+
case Ni:
|
|
1100
|
+
case Oi:
|
|
1101
|
+
case Ri:
|
|
1102
|
+
case Wi:
|
|
1103
|
+
b.preventDefault(), b.stopPropagation(), r(jt(Q[b.key], t, [0, 0], n));
|
|
965
1104
|
break;
|
|
966
|
-
case
|
|
967
|
-
case
|
|
968
|
-
|
|
1105
|
+
case Ha:
|
|
1106
|
+
case Pa:
|
|
1107
|
+
b.preventDefault(), b.stopPropagation(), a(t);
|
|
969
1108
|
}
|
|
970
1109
|
};
|
|
971
|
-
if (e) return document.addEventListener("keydown",
|
|
972
|
-
document.removeEventListener("keydown",
|
|
1110
|
+
if (e) return document.addEventListener("keydown", C), document.addEventListener("keyup", k), document.addEventListener(Fi, f), document.addEventListener($i, v), () => {
|
|
1111
|
+
document.removeEventListener("keydown", C), document.removeEventListener("keyup", k), document.removeEventListener(Fi, f), document.removeEventListener($i, v);
|
|
973
1112
|
};
|
|
974
|
-
}, [e,
|
|
975
|
-
},
|
|
976
|
-
const { shapesRef: s, selectedShape: a, selectionFrame:
|
|
977
|
-
l(
|
|
978
|
-
}, [l,
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
ne(be, Ee);
|
|
1113
|
+
}, [e, h, i, t, n, r, a, s, o, l, d, c]), {};
|
|
1114
|
+
}, ls = ({ options: e, className: t, style: i, canvasProps: n }) => {
|
|
1115
|
+
const { shapesRef: s, selectedShape: a, selectionFrame: o, hoveredShape: r, addShape: l, setSelectedShape: d, setSelectionFrame: c, refreshSelectedShapes: h, refreshHoveredShape: u, removeShape: f, updateShape: v, backwardShape: k, forwardShape: C, saveShapes: b, refs: Q, width: w, height: M, settings: L, setCanvasSize: Z, setCanvasOffset: z, selectShape: T, activeTool: $, setActiveTool: H, isInsideComponent: N, isEditMode: y, canvas: { withSkeleton: E, withFrameSelection: B, canGrow: x, canShrink: V }, canvasOffsetStartData: m, setCanvasOffsetStartData: g, selectionMode: S, setSelectionMode: P } = n, { canvasBackgroundColor: W, canvasSelectionColor: O, canvasSelectionWidth: Y } = { ...qn, ...e }, A = G(null), [J, j] = F(!1), se = D((I) => {
|
|
1116
|
+
l(I), T(I);
|
|
1117
|
+
}, [l, T]), oe = D((I) => {
|
|
1118
|
+
Z({ realWidth: w, realHeight: M, width: I, height: M * I / w, scaleRatio: I / w });
|
|
1119
|
+
}, [w, M, Z]);
|
|
1120
|
+
return Ea({ isInsideComponent: N, isEditingText: S.mode === "textedition", settings: L, selectedShape: a, setSelectedShape: d, removeShape: f, pasteShape: se, updateShape: v, backwardShape: k, forwardShape: C, setShiftPressed: j }), (({ onResized: I, element: ce }) => {
|
|
1121
|
+
q(() => {
|
|
1122
|
+
const re = ce.current;
|
|
1123
|
+
if (!re) return;
|
|
1124
|
+
const be = new ResizeObserver((Te) => {
|
|
1125
|
+
const we = Te?.[0]?.borderBoxSize?.[0], { width: ie, height: xe } = we ? { width: we.inlineSize, height: we.blockSize } : Te?.[0].contentRect ?? {};
|
|
1126
|
+
I(ie, xe);
|
|
989
1127
|
});
|
|
990
|
-
return
|
|
991
|
-
|
|
1128
|
+
return be.observe(re), () => {
|
|
1129
|
+
be.unobserve(re);
|
|
992
1130
|
};
|
|
993
|
-
}, [
|
|
994
|
-
})({ element:
|
|
995
|
-
},
|
|
996
|
-
const [
|
|
997
|
-
return
|
|
1131
|
+
}, [ce, I]);
|
|
1132
|
+
})({ element: A, onResized: oe }), p("div", { ref: A, className: "react-paint-app-row" + (t ? ` ${t}` : ""), "data-grow": x, "data-shrink": V, style: { "--react-paint-app-row-width": L.canvasSize.width, "--react-paint-app-canvaswidth": w, "--react-paint-app-canvasheight": M, "--react-paint-app-row-aspectratio": `calc(${L.canvasSize.width} / ${L.canvasSize.height})`, "--react-paint-app-canvas-bg": W, ...i }, children: p(La, { ref: Q.canvas, canGrow: x, isInsideComponent: N, activeTool: $, setActiveTool: H, canvasOffsetStartData: m, setCanvasOffsetStartData: g, shapes: s.current, addShape: l, updateSingleShape: v, selectedShape: a, selectionFrame: o, setSelectedShape: d, setSelectionFrame: c, hoveredShape: r, refreshHoveredShape: u, refreshSelectedShapes: h, settings: L, setCanvasOffset: z, saveShapes: b, selectionMode: S, setSelectionMode: P, selectionColor: O, selectionWidth: Y, isEditMode: y, isShiftPressed: J, withFrameSelection: B, withSkeleton: E }) });
|
|
1133
|
+
}, Da = ({ isLoading: e = !1 }) => {
|
|
1134
|
+
const [t, i] = F("hidden");
|
|
1135
|
+
return q(() => {
|
|
998
1136
|
if (!e) {
|
|
999
|
-
|
|
1000
|
-
const n = setTimeout(() =>
|
|
1137
|
+
i("fadeOut");
|
|
1138
|
+
const n = setTimeout(() => i("hidden"), 300);
|
|
1001
1139
|
return () => {
|
|
1002
1140
|
clearTimeout(n);
|
|
1003
1141
|
};
|
|
1004
1142
|
}
|
|
1005
|
-
|
|
1006
|
-
}, [e]),
|
|
1007
|
-
},
|
|
1008
|
-
const [n, s] =
|
|
1009
|
-
return
|
|
1143
|
+
i("visible");
|
|
1144
|
+
}, [e]), t === "hidden" ? null : p("div", { className: "react-paint-editor-loading", "data-loading": t, style: { "--react-paint-editor-loading-zindex": Xn, "--react-paint-editor-loading-transition-duration": "300ms" }, children: R("div", { className: "react-paint-editor-loader", children: [p("div", {}), p("div", {}), p("div", {}), p("div", {})] }) });
|
|
1145
|
+
}, Wa = "infos", Ra = 4e3, Na = ({ type: e, text: t, duration: i }) => {
|
|
1146
|
+
const [n, s] = F(!1);
|
|
1147
|
+
return q(() => {
|
|
1010
1148
|
const a = setTimeout(() => {
|
|
1011
1149
|
s(!0);
|
|
1012
|
-
}, 100),
|
|
1150
|
+
}, 100), o = setTimeout(() => {
|
|
1013
1151
|
s(!1);
|
|
1014
|
-
},
|
|
1152
|
+
}, i - 500 - 100);
|
|
1015
1153
|
return () => {
|
|
1016
|
-
clearTimeout(a), clearTimeout(
|
|
1154
|
+
clearTimeout(a), clearTimeout(o);
|
|
1017
1155
|
};
|
|
1018
|
-
}, [
|
|
1019
|
-
},
|
|
1156
|
+
}, [i]), p("div", { className: "react-paint-editor-snackbar", "data-is-shown": +n, "data-type": e, style: { "--react-paint-editor-panel-transition-duration": "500ms" }, children: t });
|
|
1157
|
+
}, Oa = ({ snackbarList: e }) => p("div", { className: "react-paint-editor-snackbar-container", style: { "--react-paint-editor-snackbar-zindex": Yn }, children: e.map((t) => p(Na, { ...t }, t.id)) }), X = _i.forwardRef((e, t) => {
|
|
1020
1158
|
if (e.type === "file" || e.type === "color") {
|
|
1021
|
-
const { hidden:
|
|
1022
|
-
return R("label", { className: `react-paint-editor-button ${
|
|
1159
|
+
const { hidden: c = !1, disabled: h = !1, selected: u = !1, icon: f, children: v, className: k = "", title: C, onClick: b, ...Q } = e;
|
|
1160
|
+
return R("label", { className: `react-paint-editor-button ${k}`, title: C, onClick: b, "data-disabled": +h, "data-selected": +u, "data-hidden": +c, children: [p("input", { ref: t, disabled: h, ...Q }), R("span", { className: "react-paint-editor-button-content", children: [v && p("span", { className: "react-paint-editor-button-children", children: v }), f && p("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: f } })] })] });
|
|
1023
1161
|
}
|
|
1024
|
-
const { hidden:
|
|
1025
|
-
return p("button", { className: `react-paint-editor-button ${l}`, ref:
|
|
1026
|
-
}),
|
|
1162
|
+
const { hidden: i = !1, disabled: n = !1, selected: s = !1, icon: a, children: o, type: r = "button", className: l = "", ...d } = e;
|
|
1163
|
+
return p("button", { className: `react-paint-editor-button ${l}`, ref: t, disabled: n, "data-disabled": +n, "data-selected": +s, "data-hidden": +i, type: r, ...d, children: R("span", { className: "react-paint-editor-button-content", children: [o && p("span", { className: "react-paint-editor-button-children", children: o }), a && p("span", { className: "react-paint-editor-button-icon", dangerouslySetInnerHTML: { __html: a } })] }) });
|
|
1164
|
+
}), Ue = ({ children: e, title: t = "", className: i = "", position: n = "bottom", fitContainer: s = !1, alignment: a = "center", style: o, ...r }) => R("div", { className: `react-paint-editor-panel ${i}`, "data-fitcontainer": s, "data-position": n, "data-alignment": a, style: { ...o, "--react-paint-editor-panel-zindex": on }, ...r, children: [t && p("h3", { className: "react-paint-editor-panel-title", children: t }), e] }), Ia = (e) => {
|
|
1027
1165
|
switch (e) {
|
|
1028
1166
|
case "brush":
|
|
1029
|
-
return
|
|
1167
|
+
return Ji;
|
|
1030
1168
|
case "line":
|
|
1031
|
-
return
|
|
1169
|
+
return nn;
|
|
1032
1170
|
case "polygon":
|
|
1033
|
-
return
|
|
1171
|
+
return ei;
|
|
1034
1172
|
case "curve":
|
|
1035
|
-
return
|
|
1173
|
+
return an;
|
|
1036
1174
|
case "rect":
|
|
1037
1175
|
case "square":
|
|
1038
|
-
return
|
|
1176
|
+
return Kt;
|
|
1039
1177
|
case "circle":
|
|
1040
1178
|
case "ellipse":
|
|
1041
|
-
return
|
|
1179
|
+
return Jt;
|
|
1042
1180
|
case "text":
|
|
1043
|
-
return
|
|
1181
|
+
return tn;
|
|
1044
1182
|
case "picture":
|
|
1045
|
-
return
|
|
1183
|
+
return ti;
|
|
1046
1184
|
case "triangle":
|
|
1047
1185
|
return "";
|
|
1048
1186
|
}
|
|
1049
|
-
},
|
|
1050
|
-
const
|
|
1051
|
-
const [
|
|
1052
|
-
return
|
|
1053
|
-
|
|
1054
|
-
}, [
|
|
1055
|
-
const
|
|
1056
|
-
if (!
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1059
|
-
},
|
|
1060
|
-
|
|
1061
|
-
},
|
|
1062
|
-
|
|
1063
|
-
},
|
|
1064
|
-
|
|
1065
|
-
},
|
|
1066
|
-
return u || (
|
|
1067
|
-
u || (
|
|
1187
|
+
}, Fa = ({ disabled: e = !1, shape: t, selected: i, layoutDragging: n, toggleShapeVisibility: s, toggleShapeLock: a, setLayoutDragging: o, handleRemove: r, handleSelect: l, onMoveShapes: d }) => {
|
|
1188
|
+
const c = G(null), { isOver: h } = (({ disabled: u = !1, ref: f, shape: v, layoutDragging: k, setLayoutDragging: C, handleSelect: b, onMoveShapes: Q }) => {
|
|
1189
|
+
const [w, M] = F(!1);
|
|
1190
|
+
return q(() => {
|
|
1191
|
+
k || M(!1);
|
|
1192
|
+
}, [k]), q(() => {
|
|
1193
|
+
const L = f.current;
|
|
1194
|
+
if (!L) return;
|
|
1195
|
+
const Z = () => {
|
|
1196
|
+
C(void 0);
|
|
1197
|
+
}, z = (y) => (y.preventDefault && y.preventDefault(), !1), T = (y) => {
|
|
1198
|
+
b(v), y.dataTransfer && (y.dataTransfer.effectAllowed = "move", y.dataTransfer.setData("draggableShapeId", v.id), C(v.id));
|
|
1199
|
+
}, $ = () => {
|
|
1200
|
+
k !== v.id && M(!0);
|
|
1201
|
+
}, H = () => {
|
|
1202
|
+
M(!1);
|
|
1203
|
+
}, N = (y) => (y.stopPropagation(), y.dataTransfer && Q(y.dataTransfer.getData("draggableShapeId"), v.id), !1);
|
|
1204
|
+
return u || (L.addEventListener("dragstart", T), L.addEventListener("dragend", Z), L.addEventListener("dragover", z), L.addEventListener("dragenter", $), L.addEventListener("dragleave", H), L.addEventListener("drop", N)), () => {
|
|
1205
|
+
u || (L.removeEventListener("dragstart", T), L.removeEventListener("dragend", Z), L.removeEventListener("dragover", z), L.removeEventListener("dragenter", $), L.removeEventListener("dragleave", H), L.removeEventListener("drop", N));
|
|
1068
1206
|
};
|
|
1069
|
-
}, [u,
|
|
1070
|
-
})({ disabled: e, ref:
|
|
1071
|
-
return R("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n ===
|
|
1072
|
-
e || (u.preventDefault(), u.stopPropagation(), l(
|
|
1073
|
-
}, "data-selected": +
|
|
1074
|
-
e || (u.preventDefault(), u.stopPropagation(), s(
|
|
1075
|
-
}, icon:
|
|
1076
|
-
e || (u.preventDefault(), u.stopPropagation(), a(
|
|
1077
|
-
}, icon:
|
|
1078
|
-
e || (u.preventDefault(), u.stopPropagation(),
|
|
1079
|
-
}, icon:
|
|
1080
|
-
},
|
|
1081
|
-
const [
|
|
1082
|
-
return
|
|
1083
|
-
},
|
|
1084
|
-
const [
|
|
1085
|
-
return a.length ? R(
|
|
1086
|
-
|
|
1087
|
-
}, icon:
|
|
1088
|
-
l(
|
|
1089
|
-
}, children:
|
|
1090
|
-
const u = +
|
|
1091
|
-
l(
|
|
1092
|
-
}, children: p("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": a.includes(
|
|
1093
|
-
},
|
|
1094
|
-
t
|
|
1095
|
-
}, icon:
|
|
1096
|
-
const [
|
|
1097
|
-
return
|
|
1098
|
-
|
|
1099
|
-
} }),
|
|
1100
|
-
|
|
1207
|
+
}, [u, f, v, C, b, Q, k]), { isOver: w };
|
|
1208
|
+
})({ disabled: e, ref: c, shape: t, layoutDragging: n, setLayoutDragging: o, handleSelect: l, onMoveShapes: d });
|
|
1209
|
+
return R("div", { className: "react-paint-editor-layout", "data-disabled": +e, draggable: !e, "data-is-dragging": +(n === t.id), "data-is-over": +h, onClick: (u) => {
|
|
1210
|
+
e || (u.preventDefault(), u.stopPropagation(), l(t));
|
|
1211
|
+
}, "data-selected": +i, ref: c, tabIndex: -1, children: [p("span", { dangerouslySetInnerHTML: { __html: Ia(t.type) } }), p("span", { children: t.id }), p("div", { className: "react-paint-editor-layouts-separator" }), p(X, { className: "react-paint-editor-layouts-visible-button", title: t.visible ? "Hide" : "Show", "data-visible": t.visible !== !1, disabled: e, selected: i, onClick: (u) => {
|
|
1212
|
+
e || (u.preventDefault(), u.stopPropagation(), s(t));
|
|
1213
|
+
}, 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>' }), p(X, { className: "react-paint-editor-layouts-locked-button", title: t.locked ? "Locked" : "Unlocked", "data-locked": !!t.locked, disabled: e, selected: i, onClick: (u) => {
|
|
1214
|
+
e || (u.preventDefault(), u.stopPropagation(), a(t));
|
|
1215
|
+
}, 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>' }), p(X, { className: "react-paint-editor-layouts-remove-button", title: "Remove", disabled: e, onClick: (u) => {
|
|
1216
|
+
e || (u.preventDefault(), u.stopPropagation(), r(t));
|
|
1217
|
+
}, icon: en })] });
|
|
1218
|
+
}, $a = ({ gridFormat: e, setGridFormat: t, settings: i, shapes: n, removeShape: s, toggleShapeVisibility: a, toggleShapeLock: o, selectedShape: r, moveShapes: l, selectShape: d, isLayoutPanelShown: c }) => {
|
|
1219
|
+
const [h, u] = F(void 0), f = !i.features.edition;
|
|
1220
|
+
return c ? p(Ue, { alignment: "right", className: "react-paint-editor-layouts-panel", children: p("div", { className: "react-paint-editor-layouts-panel-content", children: R("div", { className: "react-paint-editor-layouts-scrolling-content", children: [R("div", { className: "react-paint-editor-layouts-row", children: [p("span", { className: "react-paint-editor-layouts-subtitle", children: "Grid" }), p(X, { icon: '<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>', className: "react-paint-editor-layouts-grid-button", selected: e === "none", disabled: f, onClick: () => t("none") }), ["small", "medium", "large"].map((v) => p(X, { className: "react-paint-editor-layouts-grid-button", selected: e === v, disabled: f, onClick: () => t(v), children: v.charAt(0).toUpperCase() }, v))] }), p("hr", {}), p("div", { className: "react-paint-editor-layouts", children: n.length === 0 ? p("div", { className: "react-paint-editor-layouts-placeholder", children: "No layer yet" }) : n.map((v) => p(Fa, { shape: v, disabled: f, layoutDragging: h, setLayoutDragging: u, selected: r?.id === v.id, handleSelect: d, handleRemove: s, onMoveShapes: l, toggleShapeVisibility: a, toggleShapeLock: o }, v.id)) })] }) }) }) : null;
|
|
1221
|
+
}, Ht = ({ children: e, onClose: t, position: i = "center", title: n, className: s = "" }) => R("div", { className: "react-paint-editor-modal", "data-position": i, style: { "--react-paint-editor-modal-zindex": on }, role: "dialog", "aria-modal": "true", "aria-labelledby": n, children: [p("div", { className: "react-paint-editor-modal-mask", onClick: t }), p("div", { className: `react-paint-editor-modal-panel ${s}`, children: e })] }), vt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez une couleur", mode: n = "fill", disabled: s = !1, values: a, field: o, value: r = "", valueChanged: l }) => {
|
|
1222
|
+
const [d] = F(le("settings_")), c = e === d;
|
|
1223
|
+
return a.length ? R(Se, { children: [p(X, { selected: c, title: i, disabled: s, onClick: () => {
|
|
1224
|
+
t((h) => h === d ? void 0 : d);
|
|
1225
|
+
}, icon: r === "transparent" ? n === "fill" ? fi : gi : void 0, children: r !== "transparent" && p("div", { className: "react-paint-editor-colorfield-color", "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": r } }) }), c && p(Ue, { title: i, alignment: "left", children: R("div", { className: "react-paint-editor-colorfield-wrapper", children: [a.map((h) => p(X, { title: h, selected: h === r, color: h, icon: h === "transparent" ? n === "fill" ? fi : gi : void 0, onClick: () => {
|
|
1226
|
+
l(o, h);
|
|
1227
|
+
}, children: h !== "transparent" && p("div", { className: "react-paint-editor-colorfield-color", color: h, "data-mode": n, style: { "--react-paint-editor-colorfield-color-value": h } }) }, h)), p(X, { type: "color", title: "Custom color", selected: !a.includes(r), value: r, onChange: (h) => {
|
|
1228
|
+
const u = +h.target.value;
|
|
1229
|
+
l(o, Number.isNaN(u) ? h.target.value : u);
|
|
1230
|
+
}, children: p("div", { className: "react-paint-editor-colorfield-customcolor", style: { "--react-paint-editor-colorfield-color-value": a.includes(r) ? "var(--react-paint-editor-app-font-color)" : r }, children: p("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;
|
|
1231
|
+
}, Ba = ({ disabled: e = !1, selectedShape: t, removeShape: i }) => p(X, { title: "Delete", disabled: e, "data-disabled": +e, onClick: () => {
|
|
1232
|
+
i(t);
|
|
1233
|
+
}, icon: en }), li = ({ CustomOption: e, selectedSettings: t, setSelectedSettings: i, title: n = "Choisissez l'option", disabled: s = !1, field: a, icon: o, values: r, defaultValue: l, valueChanged: d }) => {
|
|
1234
|
+
const [c] = F(le("settings_")), h = t === c;
|
|
1235
|
+
return r.length ? R(Se, { children: [p(X, { selected: h, title: n, icon: o, disabled: s, onClick: () => {
|
|
1236
|
+
i((u) => u === c ? void 0 : c);
|
|
1237
|
+
} }), h && p(Ue, { title: n, alignment: "left", fitContainer: !0, children: p("div", { className: "react-paint-editor-selectfield-wrapper", children: r.map((u) => p(X, { title: `${u}`, onClick: () => ((f) => {
|
|
1238
|
+
d(a, f);
|
|
1101
1239
|
})(u), selected: l === u, style: { "--react-paint-editor-button-padding": "16px" }, children: p(e, { children: u }) }, u)) }) })] }) : null;
|
|
1102
|
-
},
|
|
1103
|
-
const u = Math.round(
|
|
1104
|
-
|
|
1105
|
-
|
|
1240
|
+
}, Ua = ({ children: e }) => p("span", { className: "react-paint-editor-fontfamily-option", style: { "--react-paint-editor-fontfamily-family": e }, children: e }), Bi = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: s, valueChanged: a }) => n.length ? p(li, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ua, 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: s, valueChanged: a }) : null, Xa = ({ disabled: e, toggleLayoutPanel: t }) => p(X, { 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" }), Ya = ({ children: e }) => R("span", { className: "react-paint-editor-linearrow-option", "data-type": e, children: [p("span", { className: "react-paint-editor-linearrow-left" }), p("span", { className: "react-paint-editor-linearrow-right" })] }), Ui = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: s, valueChanged: a }) => n.length ? p(li, { selectedSettings: e, setSelectedSettings: t, CustomOption: Ya, 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: s, valueChanged: a }) : null, qa = ({ children: e }) => R("span", { className: "react-paint-editor-linetype-option", "data-type": e, children: [p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {}), p("span", {})] }), Xi = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, values: n, defaultValue: s, valueChanged: a }) => n.length ? p(li, { selectedSettings: e, setSelectedSettings: t, CustomOption: qa, 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: s, valueChanged: a }) : null, lt = ({ selectedSettings: e, setSelectedSettings: t, title: i = "Choisissez l'intervalle", icon: n, disabled: s = !1, field: a, value: o = 1, min: r = 1, max: l = 20, step: d = 1, unity: c = "", valueChanged: h }) => {
|
|
1241
|
+
const u = Math.round(o), [f] = F(le("settings_")), v = G(null);
|
|
1242
|
+
q(() => () => {
|
|
1243
|
+
v.current && clearTimeout(v.current);
|
|
1106
1244
|
}, []);
|
|
1107
|
-
const
|
|
1108
|
-
return
|
|
1109
|
-
|
|
1110
|
-
} }),
|
|
1111
|
-
const
|
|
1112
|
-
|
|
1113
|
-
|
|
1245
|
+
const k = e === f;
|
|
1246
|
+
return r === l ? null : R(Se, { children: [p(X, { selected: k, title: i, disabled: s, icon: n, onClick: () => {
|
|
1247
|
+
t((C) => C === f ? void 0 : f);
|
|
1248
|
+
} }), k && p(Ue, { title: i, alignment: "left", fitContainer: !0, children: p("div", { children: R("label", { className: "react-paint-editor-rangefield", children: [p("input", { type: "range", min: r, max: l, step: d, value: o, onChange: (C) => {
|
|
1249
|
+
const b = +C.target.value;
|
|
1250
|
+
h(a, Number.isNaN(b) ? C.target.value : b, !1), v.current && clearTimeout(v.current), v.current = setTimeout(() => {
|
|
1251
|
+
h(a, Number.isNaN(b) ? C.target.value : b, !0);
|
|
1114
1252
|
}, 1e3);
|
|
1115
|
-
} }), R("span", { children: [u,
|
|
1116
|
-
},
|
|
1117
|
-
const [
|
|
1118
|
-
return s.length !== 2 ? null : p(
|
|
1119
|
-
e((l) => l ===
|
|
1120
|
-
}, selected: a, disabled:
|
|
1121
|
-
},
|
|
1122
|
-
const [
|
|
1123
|
-
|
|
1124
|
-
},
|
|
1125
|
-
o ? (d(
|
|
1126
|
-
},
|
|
1253
|
+
} }), R("span", { children: [u, c] })] }) }) })] });
|
|
1254
|
+
}, Yi = ({ selectedSettings: e, setSelectedSettings: t, disabled: i = !1, min: n, max: s, step: a, value: o, valueChanged: r }) => n === s ? null : p(lt, { selectedSettings: e, setSelectedSettings: t, icon: ei, title: "Nombre de points", disabled: i, field: "pointsCount", min: n, max: s, step: a, unity: "", value: o, valueChanged: r }), Ga = ({ disabled: e = !1, className: t, toggleZoomPanel: i }) => p(X, { title: "Toggle zoom panel", disabled: e, onClick: i, icon: sn, className: t ? ` ${t}` : "" }), mt = ({ setSelectedSettings: e, disabled: t = !1, field: i, icon: n, values: s, value: a = !1, valueChanged: o }) => {
|
|
1255
|
+
const [r] = F(le("settings_"));
|
|
1256
|
+
return s.length !== 2 ? null : p(X, { onClick: () => {
|
|
1257
|
+
e((l) => l === r ? void 0 : r), o(i, !a);
|
|
1258
|
+
}, selected: a, disabled: t, icon: n });
|
|
1259
|
+
}, Bt = ({ activeTool: e, selectedShape: t, selectedShapeTool: i, disabled: n, selectedSettings: s, setSelectedSettings: a, handleShapeStyleChange: o, handlePolygonLinesCount: r, handleShapeFontFamilyChange: l }) => t ? i && R(Se, { children: ["strokeColor" in i.settings && !i.settings.strokeColor.hidden && p(vt, { selectedSettings: s, setSelectedSettings: a, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: t.style?.strokeColor, valueChanged: o, values: i.settings.strokeColor.values }), "fillColor" in i.settings && !i.settings.fillColor.hidden && p(vt, { selectedSettings: s, setSelectedSettings: a, title: "Couleur de fond", disabled: n, field: "fillColor", value: t.style?.fillColor, valueChanged: o, values: i.settings.fillColor.values }), "lineWidth" in i.settings && !i.settings.lineWidth.hidden && p(lt, { selectedSettings: s, setSelectedSettings: a, title: "Epaisseur du trait", icon: pi, disabled: n, field: "lineWidth", value: t.style?.lineWidth, valueChanged: o, 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 && p(Xi, { selectedSettings: s, setSelectedSettings: a, disabled: n, defaultValue: t.style?.lineDash, valueChanged: o, values: i.settings.lineDash.values }), "lineArrow" in i.settings && !i.settings.lineArrow.hidden && p(Ui, { selectedSettings: s, setSelectedSettings: a, disabled: n, defaultValue: t.style?.lineArrow, valueChanged: o, values: i.settings.lineArrow.values }), "pointsCount" in i.settings && !i.settings.pointsCount.hidden && p(Yi, { selectedSettings: s, setSelectedSettings: a, disabled: n, valueChanged: r, min: i.settings.pointsCount.min, max: i.settings.pointsCount.max, step: i.settings.pointsCount.step, value: t.style?.pointsCount }), "fontFamily" in i.settings && !i.settings.fontFamily.hidden && p(Bi, { selectedSettings: s, setSelectedSettings: a, disabled: n, valueChanged: l, values: i.settings.fontFamily.values, defaultValue: t.style?.fontFamily }), "fontBold" in i.settings && !i.settings.fontBold.hidden && p(mt, { setSelectedSettings: a, disabled: n, field: "fontBold", icon: hi, valueChanged: l, values: i.settings.fontBold.values, value: t.style?.fontBold }), "fontItalic" in i.settings && !i.settings.fontItalic.hidden && p(mt, { setSelectedSettings: a, disabled: n, field: "fontItalic", icon: ui, valueChanged: l, values: i.settings.fontItalic.values, value: t.style?.fontItalic }), "opacity" in i.settings && !i.settings.opacity.hidden && p(lt, { selectedSettings: s, setSelectedSettings: a, title: "Opacité", icon: di, min: i.settings.opacity.min, max: i.settings.opacity.max, step: i.settings.opacity.step, unity: "%", disabled: n, field: "opacity", value: t.style?.opacity ?? 100, valueChanged: o })] }) : "settings" in e ? R(Se, { children: ["strokeColor" in e.settings && !e.settings.strokeColor.hidden && p(vt, { selectedSettings: s, setSelectedSettings: a, title: "Couleur du trait", mode: "stroke", disabled: n, field: "strokeColor", value: e.settings.strokeColor.default, valueChanged: o, values: e.settings.strokeColor.values }), "fillColor" in e.settings && !e.settings.fillColor.hidden && p(vt, { selectedSettings: s, setSelectedSettings: a, title: "Couleur de fond", disabled: n, field: "fillColor", value: e.settings.fillColor.default, valueChanged: o, values: e.settings.fillColor.values }), "lineWidth" in e.settings && !e.settings.lineWidth.hidden && p(lt, { selectedSettings: s, setSelectedSettings: a, title: "Epaisseur du trait", disabled: n, field: "lineWidth", icon: pi, value: e.settings.lineWidth.default, valueChanged: o, 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 && p(Xi, { selectedSettings: s, setSelectedSettings: a, disabled: n, defaultValue: e.settings.lineDash.default, valueChanged: o, values: e.settings.lineDash.values }), "lineArrow" in e.settings && !e.settings.lineArrow.hidden && p(Ui, { selectedSettings: s, setSelectedSettings: a, disabled: n, defaultValue: e.settings.lineArrow.default, valueChanged: o, values: e.settings.lineArrow.values }), "pointsCount" in e.settings && !e.settings.pointsCount.hidden && p(Yi, { selectedSettings: s, setSelectedSettings: a, disabled: n, valueChanged: r, min: e.settings.pointsCount.min, max: e.settings.pointsCount.max, step: e.settings.pointsCount.step, value: e.settings.pointsCount.default }), "fontFamily" in e.settings && !e.settings.fontFamily.hidden && p(Bi, { selectedSettings: s, setSelectedSettings: a, disabled: n, valueChanged: l, values: e.settings.fontFamily.values, defaultValue: e.settings.fontFamily.default }), "fontBold" in e.settings && !e.settings.fontBold.hidden && p(mt, { setSelectedSettings: a, disabled: n, field: "fontBold", icon: hi, valueChanged: l, values: e.settings.fontBold.values, value: e.settings.fontBold.default }), "fontItalic" in e.settings && !e.settings.fontItalic.hidden && p(mt, { setSelectedSettings: a, disabled: n, field: "fontItalic", icon: ui, valueChanged: l, values: e.settings.fontItalic.values, value: e.settings.fontItalic.default }), "opacity" in e.settings && !e.settings.opacity.hidden && p(lt, { selectedSettings: s, setSelectedSettings: a, title: "Opacité", icon: di, 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: o })] }) : null, _a = ({ width: e, availableTools: t, updateToolSettings: i, layersManipulation: n = !1, toggleLayoutPanel: s, activeTool: a, selectedShape: o, canvas: r, settings: l, updateShape: d, removeShape: c, isZoomPanelShown: h, setIsZoomPanelShown: u }) => {
|
|
1260
|
+
const [f, v] = F(void 0), [k, C] = F(!1), b = l.size === "infinite" || l.features.zoom, Q = !l.features.edition, w = () => {
|
|
1261
|
+
C((H) => !H);
|
|
1262
|
+
}, M = o ? t.find((H) => H.id === o.toolId) || t.find((H) => H.type === o.type) : void 0, L = (M ? Object.keys(M.settings).length + 1 : "settings" in a ? Object.keys(a.settings).length : 0) + +n + +b, Z = e < 40 * L, z = (H, N, y = !0) => {
|
|
1263
|
+
o ? (d(dt(fe(["style", H], N, o), l), y), M && i(M.id, H, N)) : i(a.id, H, N);
|
|
1264
|
+
}, T = (H, N) => {
|
|
1127
1265
|
if (o) {
|
|
1128
1266
|
if (o.type !== "text") return;
|
|
1129
|
-
const
|
|
1130
|
-
if (!
|
|
1131
|
-
const
|
|
1132
|
-
d(
|
|
1133
|
-
} else
|
|
1134
|
-
},
|
|
1267
|
+
const y = r?.getContext("2d");
|
|
1268
|
+
if (!y) return;
|
|
1269
|
+
const E = fe(["style", H], N, o), B = si(y, E.value, E.width, E.style?.fontBold ?? !1, E.style?.fontItalic ?? !1, E.style?.fontFamily), x = dt({ ...E, fontSize: B, height: B * E.value.length }, l);
|
|
1270
|
+
d(x, !0), M && i(M.id, H, N);
|
|
1271
|
+
} else i(a.id, H, N);
|
|
1272
|
+
}, $ = (H, N) => {
|
|
1135
1273
|
if (o) {
|
|
1136
1274
|
if (o.type !== "polygon" && o.type !== "curve") return;
|
|
1137
|
-
d(o.type === "polygon" ? ((
|
|
1138
|
-
const
|
|
1139
|
-
if (
|
|
1140
|
-
if (
|
|
1141
|
-
const
|
|
1142
|
-
return
|
|
1275
|
+
d(o.type === "polygon" ? ((y, E, B) => {
|
|
1276
|
+
const x = y.points.length;
|
|
1277
|
+
if (x === E) return y;
|
|
1278
|
+
if (x > E) {
|
|
1279
|
+
const S = y.points.slice(0, E);
|
|
1280
|
+
return Je({ ...y, points: S, style: { ...y.style, pointsCount: S.length } }, B);
|
|
1143
1281
|
}
|
|
1144
|
-
const
|
|
1145
|
-
return
|
|
1146
|
-
})(o,
|
|
1147
|
-
const
|
|
1148
|
-
if (
|
|
1149
|
-
if (
|
|
1150
|
-
const
|
|
1151
|
-
return
|
|
1282
|
+
const V = E - x, m = new Array(V).fill(void 0).map((S, P) => [y.points[0][0] + (y.points[1][0] - y.points[0][0]) * (P + 1) / (V + 1), y.points[0][1] + (y.points[1][1] - y.points[0][1]) * (P + 1) / (V + 1)]), g = [y.points[0], ...m, ...y.points.slice(1, y.points.length)];
|
|
1283
|
+
return Je({ ...y, points: g, style: { ...y.style, pointsCount: g.length } }, B);
|
|
1284
|
+
})(o, N, l) : ((y, E, B) => {
|
|
1285
|
+
const x = y.points.length;
|
|
1286
|
+
if (x === E) return y;
|
|
1287
|
+
if (x > E) {
|
|
1288
|
+
const S = y.points.slice(0, E);
|
|
1289
|
+
return et({ ...y, points: S, style: { ...y.style, pointsCount: S.length } }, B);
|
|
1152
1290
|
}
|
|
1153
|
-
const
|
|
1154
|
-
return
|
|
1155
|
-
})(o,
|
|
1156
|
-
} else
|
|
1291
|
+
const V = E - x, m = new Array(V).fill(void 0).map((S, P) => [y.points[0][0] + (y.points[1][0] - y.points[0][0]) * (P + 1) / (V + 1), y.points[0][1] + (y.points[1][1] - y.points[0][1]) * (P + 1) / (V + 1)]), g = [y.points[0], ...m, ...y.points.slice(1, y.points.length)];
|
|
1292
|
+
return et({ ...y, points: g, style: { ...y.style, pointsCount: g.length } }, B);
|
|
1293
|
+
})(o, N, l), !0), M && i(M.id, H, N);
|
|
1294
|
+
} else i(a.id, H, N);
|
|
1157
1295
|
};
|
|
1158
|
-
return R(
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1296
|
+
return R(Se, { children: [R("div", { className: "react-paint-editor-settings-bar", children: [R("div", { className: "react-paint-editor-settings-shrinkable", children: [b && p(Ga, { className: h ? "react-paint-editor-bar-zoom-button-opened" : void 0, toggleZoomPanel: () => {
|
|
1297
|
+
u((H) => !H);
|
|
1298
|
+
} }), Z && L > 2 && p(X, { disabled: Q, onClick: w, 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>' }), o ? M && R(Se, { children: [!Z && p(Bt, { activeTool: a, selectedShape: o, selectedShapeTool: M, disabled: Q, selectedSettings: f, setSelectedSettings: v, handleShapeStyleChange: z, handlePolygonLinesCount: $, handleShapeFontFamilyChange: T }), a.type === "selection" && p(Ba, { disabled: Q, selectedShape: o, removeShape: c })] }) : !Z && p(Bt, { activeTool: a, selectedShape: o, selectedShapeTool: M, disabled: Q, selectedSettings: f, setSelectedSettings: v, handleShapeStyleChange: z, handlePolygonLinesCount: $, handleShapeFontFamilyChange: T })] }), p("div", { className: "react-paint-editor-settings-separator" }), n && p(Xa, { disabled: Q, toggleLayoutPanel: s })] }), k && p(Ht, { className: "react-paint-editor-settings-modal", onClose: w, position: "bottom", title: "Settings", children: p(Bt, { activeTool: a, selectedShape: o, selectedShapeTool: M, disabled: Q, selectedSettings: f, setSelectedSettings: v, handleShapeStyleChange: z, handlePolygonLinesCount: $, handleShapeFontFamilyChange: T }) })] });
|
|
1299
|
+
}, qi = ({ disabled: e = !1, withText: t = !1, loadFile: i, type: n, img: s, accept: a }) => {
|
|
1300
|
+
const o = G(null);
|
|
1301
|
+
return p(X, { ref: o, type: "file", onClick: (r) => {
|
|
1302
|
+
r.stopPropagation(), o.current && (o.current.value = "");
|
|
1303
|
+
}, onChange: (r) => {
|
|
1304
|
+
const l = r.target.files?.item(0);
|
|
1305
|
+
l && i(l);
|
|
1306
|
+
}, accept: a, title: n.label ?? n.type, icon: s, disabled: e, children: t ? n.label : void 0 });
|
|
1307
|
+
}, ge = ({ type: e, img: t, isActive: i, withText: n = !1, disabled: s = !1, setActive: a }) => p(X, { disabled: s, selected: i, onClick: () => {
|
|
1168
1308
|
a(e);
|
|
1169
|
-
}, title: e.label ?? e.type, icon:
|
|
1170
|
-
const [
|
|
1171
|
-
return
|
|
1172
|
-
if (!
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1309
|
+
}, title: e.label ?? e.type, icon: t, children: n ? e.label : void 0 }), ja = ({ activeTool: e, withActionsInMenu: t, hasActionToUndo: i = !1, hasActionToRedo: n = !1, hasActionToClear: s = !1, undoAction: a, redoAction: o, clearCanvas: r, alignment: l, group: d, vertical: c = !1, disabled: h = !1, withLoadAndSave: u, withExport: f, addPicture: v, loadFile: k, togglePictureUrlModal: C, saveFile: b, toggleExportModal: Q, withUploadPicture: w, withUrlPicture: M }) => {
|
|
1310
|
+
const [L, Z] = F(!1), [, z] = Ki(), T = d?.tools?.some((H) => H === e.type), $ = (T ? e.icon : d.img) ?? d.title;
|
|
1311
|
+
return q(() => {
|
|
1312
|
+
if (!L) return;
|
|
1313
|
+
const H = () => {
|
|
1314
|
+
Z(!1);
|
|
1175
1315
|
};
|
|
1176
|
-
return document.addEventListener("click",
|
|
1177
|
-
document.removeEventListener("click",
|
|
1316
|
+
return document.addEventListener("click", H), () => {
|
|
1317
|
+
document.removeEventListener("click", H);
|
|
1178
1318
|
};
|
|
1179
|
-
}, [
|
|
1180
|
-
|
|
1181
|
-
|
|
1319
|
+
}, [L]), t || w || M || u || f ? R("div", { className: "react-paint-editor-toolbox-relative", children: [p(X, { selected: T, title: d.title, disabled: h, onClick: () => {
|
|
1320
|
+
z(() => {
|
|
1321
|
+
Z(!0);
|
|
1182
1322
|
});
|
|
1183
|
-
}, icon:
|
|
1184
|
-
|
|
1185
|
-
}, img:
|
|
1186
|
-
|
|
1187
|
-
}, img:
|
|
1188
|
-
},
|
|
1189
|
-
const
|
|
1190
|
-
return
|
|
1191
|
-
|
|
1192
|
-
}, []), p(
|
|
1323
|
+
}, icon: $ }), L && p(Ue, { alignment: l, position: "top", children: R("div", { className: "react-paint-editor-toolbox-panel-content", "data-vertical": +c, children: [t && R(Se, { children: [p(ge, { withText: !0, type: _e, disabled: h || !i, img: _e.icon, isActive: e.id === _e.id, setActive: a }), p(ge, { withText: !0, type: je, disabled: h || !n, img: je.icon, isActive: e.id === je.id, setActive: o }), p(ge, { withText: !0, type: Ke, disabled: h || !s, img: Ke.icon, isActive: e.id === Ke.id, setActive: r }), (w || M || u) && p("hr", {})] }), w && p(qi, { withText: !0, type: yi, disabled: h, loadFile: async (H) => {
|
|
1324
|
+
Z(!1), await v(H);
|
|
1325
|
+
}, img: yi.icon, accept: "image/png, image/gif, image/jpeg, image/svg+xml" }), M && p(X, { disabled: h, selected: !1, onClick: C, title: "Add picture from URL", icon: '<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>', children: "Add picture from URL" }), (w || M) && u && p("hr", {}), u && R(Se, { children: [p(qi, { withText: !0, type: mi, disabled: h, loadFile: (H) => {
|
|
1326
|
+
Z(!1), k(H);
|
|
1327
|
+
}, img: mi.icon, accept: "application/JSON" }), p(ge, { withText: !0, disabled: h, type: Dt, img: Dt.icon, isActive: e.id === Dt.id, setActive: b })] }), f && p(ge, { withText: !0, disabled: h, type: Et, img: Et.icon, isActive: e.id === Et.id, setActive: Q })] }) })] }) : null;
|
|
1328
|
+
}, Ka = ({ togglePictureUrlModal: e, addPicture: t }) => {
|
|
1329
|
+
const i = G(null);
|
|
1330
|
+
return q(() => {
|
|
1331
|
+
i.current && i.current.focus();
|
|
1332
|
+
}, []), p(Ht, { className: "react-paint-editor-toolbox-pictureinput-modal", onClose: e, title: "Add picture from URL", children: R("form", { onSubmit: async (n) => {
|
|
1193
1333
|
n.preventDefault();
|
|
1194
|
-
const s =
|
|
1195
|
-
s && (await
|
|
1196
|
-
}, children: [R("label", { children: ["URL ", p("input", { type: "text", ref:
|
|
1197
|
-
},
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1334
|
+
const s = i.current?.value;
|
|
1335
|
+
s && (await t(s), e());
|
|
1336
|
+
}, children: [R("label", { children: ["URL ", p("input", { type: "text", ref: i })] }), p(X, { onClick: e, children: "Annuler" }), p(X, { type: "submit", selected: !0, children: "Ajouter" })] }) });
|
|
1337
|
+
}, Gi = "Choose export settings", Ja = ({ toggleExportModal: e, exportCanvasInFile: t }) => {
|
|
1338
|
+
const i = async (n) => {
|
|
1339
|
+
t(n), e();
|
|
1340
|
+
};
|
|
1341
|
+
return R(Ht, { className: "react-paint-editor-toolbox-export-modal", onClose: e, title: Gi, children: [p("h3", { children: Gi }), p("hr", {}), p(X, { onClick: () => i("currentZoom"), children: "Exporter la vue actuelle" }), p(X, { onClick: () => i("defaultView"), children: "Exporter le canvas entier" }), p(X, { onClick: () => i("fitToShapes"), children: "Exporter dans les limites du dessin" }), p(X, { selected: !0, onClick: e, children: "Annuler" })] });
|
|
1342
|
+
}, es = ({ activeTool: e, alignment: t, group: i, disabled: n = !1, setActiveToolFromId: s }) => {
|
|
1343
|
+
const a = G(null), [o, r] = F(!1), [, l] = Ki(), [d, c] = F(void 0), h = (v) => {
|
|
1344
|
+
c(v), s(v.id);
|
|
1200
1345
|
};
|
|
1201
|
-
if (
|
|
1202
|
-
if (!
|
|
1203
|
-
const
|
|
1204
|
-
!
|
|
1346
|
+
if (q(() => {
|
|
1347
|
+
if (!o) return;
|
|
1348
|
+
const v = (k) => {
|
|
1349
|
+
!Cn(k, a.current) && r(!1);
|
|
1205
1350
|
};
|
|
1206
|
-
return document.addEventListener("mousedown",
|
|
1207
|
-
document.removeEventListener("mousedown",
|
|
1351
|
+
return document.addEventListener("mousedown", v, { passive: !1 }), document.addEventListener("touchstart", v, { passive: !1 }), () => {
|
|
1352
|
+
document.removeEventListener("mousedown", v), document.removeEventListener("touchstart", v);
|
|
1208
1353
|
};
|
|
1209
|
-
}, [
|
|
1210
|
-
if (!
|
|
1211
|
-
if (
|
|
1212
|
-
const u =
|
|
1213
|
-
return R("div", { className: "react-paint-editor-toolbargroup-relative", children: [p(
|
|
1214
|
-
|
|
1215
|
-
|
|
1354
|
+
}, [o]), "type" in i) return p(ge, { disabled: n, type: i, img: i.icon, isActive: e.id === i.id, setActive: h });
|
|
1355
|
+
if (!i.toolsType.length) return null;
|
|
1356
|
+
if (i.toolsType?.length === 1) return p(ge, { disabled: n, type: i.toolsType[0], img: i.toolsType[0].icon, isActive: e.id === i.toolsType[0].id, setActive: h });
|
|
1357
|
+
const u = i?.toolsType.find((v) => v.type === e.type) !== void 0, f = (d ? d.icon : i.toolsType?.[0]?.icon) ?? i.title;
|
|
1358
|
+
return R("div", { className: "react-paint-editor-toolbargroup-relative", children: [p(X, { selected: u, title: i.title, disabled: n, onClick: () => {
|
|
1359
|
+
d ? s(d.id) : i.toolsType?.[0] && h(i.toolsType[0]), l(() => {
|
|
1360
|
+
r(!0);
|
|
1216
1361
|
});
|
|
1217
|
-
}, icon:
|
|
1218
|
-
},
|
|
1219
|
-
const
|
|
1220
|
-
const
|
|
1221
|
-
if (typeof
|
|
1222
|
-
const
|
|
1223
|
-
return
|
|
1362
|
+
}, icon: f }), o && p(Ue, { alignment: t, position: "top", children: p("div", { className: "react-paint-editor-toolbargroup-panel-content", "data-vertical": +i.vertical, ref: a, children: i.toolsType.map((v) => p(ge, { disabled: n, type: v, img: v.icon, isActive: e.id === v.id, setActive: h }, v.id)) }) })] });
|
|
1363
|
+
}, ts = [{ title: "brush", toolsType: ["brush"], vertical: !1 }, { title: "lines", toolsType: ["line", "curve", "polygon"], vertical: !1 }, { title: "shapes", toolsType: ["rect", "square", "circle", "ellipse"], vertical: !1 }, "text"], is = ({ settings: e, width: t, activeTool: i, hasActionToUndo: n = !1, hasActionToRedo: s = !1, hasActionToClear: a = !1, withLoadAndSave: o, withExport: r, clearCanvas: l, setActiveTool: d, undoAction: c, redoAction: h, addPicture: u, loadFile: f, saveFile: v, exportCanvasInFile: k, availableTools: C, withUrlPicture: b, withUploadPicture: Q }) => {
|
|
1364
|
+
const w = ((g, S) => {
|
|
1365
|
+
const P = S.flatMap((W) => {
|
|
1366
|
+
if (typeof W != "object") return g.filter((Y) => Y.type === W);
|
|
1367
|
+
const O = g.filter((Y) => W.toolsType.includes(Y.type));
|
|
1368
|
+
return O ? { ...W, toolsType: O } : null;
|
|
1224
1369
|
});
|
|
1225
|
-
return
|
|
1226
|
-
})(
|
|
1227
|
-
|
|
1228
|
-
},
|
|
1229
|
-
|
|
1230
|
-
},
|
|
1231
|
-
|
|
1232
|
-
},
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
},
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1370
|
+
return oi(P);
|
|
1371
|
+
})(C, ts), M = !e.features.edition, L = t < 40 * (6 + w.length), Z = t < 40 * (3 + w.length), [z, T] = F(!1), [$, H] = F(!1), [N, y] = F(!1), E = () => {
|
|
1372
|
+
T((g) => !g);
|
|
1373
|
+
}, B = () => {
|
|
1374
|
+
y((g) => !g);
|
|
1375
|
+
}, x = (g) => {
|
|
1376
|
+
d(g), T(!1);
|
|
1377
|
+
}, V = (g) => {
|
|
1378
|
+
x(C.find((S) => S.id === g) ?? i);
|
|
1379
|
+
}, m = C.find((g) => g.type === i.type) !== void 0;
|
|
1380
|
+
return R(Se, { children: [R("div", { className: "react-paint-editor-toolbar-toolbox", style: { "--react-paint-editor-toolbar-minwidth": "160px" }, children: [R("div", { className: "react-paint-editor-toolbar-shrinkable", children: [p(ge, { type: Ze, disabled: M, img: Ze.icon, isActive: i.id === Ze.id, setActive: x }), (e.size === "infinite" || e.features.zoom) && p(ge, { type: Wt, disabled: M, img: Wt.icon, isActive: i.id === Wt.id, setActive: x }), Z ? p(X, { disabled: M, onClick: E, title: "Toggle tools", icon: '<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>', selected: m }) : w.map((g) => p(es, { disabled: M, activeTool: i, group: g, setActiveToolFromId: V }, "id" in g ? g.id : g.title))] }), !L && R(Se, { children: [p(ge, { type: _e, disabled: M || !n, img: _e.icon, isActive: i.id === _e.id, setActive: c }), p(ge, { type: je, disabled: M || !s, img: je.icon, isActive: i.id === je.id, setActive: h }), p(ge, { type: Ke, disabled: M || !a, img: Ke.icon, isActive: i.id === Ke.id, setActive: l })] }), p(ja, { withActionsInMenu: L, disabled: M, vertical: !0, alignment: "right", group: { title: "Menu", img: '<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>' }, activeTool: i, addPicture: u, loadFile: f, saveFile: v, togglePictureUrlModal: () => {
|
|
1381
|
+
H(!0);
|
|
1382
|
+
}, toggleExportModal: B, withUploadPicture: Q, withUrlPicture: b, withLoadAndSave: o, withExport: r, hasActionToUndo: n, hasActionToRedo: s, hasActionToClear: a, undoAction: c, redoAction: h, clearCanvas: l })] }), z && p(Ht, { className: "react-paint-editor-toolbar-modal", onClose: E, title: "Outils", children: C.map((g) => g.type === "picture" ? null : p(ge, { disabled: M, type: g, img: g.icon, withText: !1, isActive: i.id === g.id, setActive: x }, g.id)) }), $ && p(Ka, { togglePictureUrlModal: () => {
|
|
1383
|
+
H((g) => !g);
|
|
1384
|
+
}, addPicture: u }), N && p(Ja, { toggleExportModal: B, exportCanvasInFile: k })] });
|
|
1385
|
+
}, yt = { none: 0, small: 10, medium: 20, large: 40 }, ns = { toolbarBackgroundColor: "white", dividerColor: "#36418129", fontRadius: 8, fontDisabledColor: "#3641812b", fontDisabledBackgroundColor: "transparent", fontColor: "#364181", fontBackgroundColor: "transparent", fontSelectedColor: "white", fontSelectedBackgroundColor: "#364181", fontHoverColor: "#364181", fontHoverBackgroundColor: "#afd8d8" }, as = () => {
|
|
1386
|
+
const e = G([]), [t, i] = F([]);
|
|
1387
|
+
return q(() => () => {
|
|
1241
1388
|
for (const n of e.current) clearTimeout(n);
|
|
1242
|
-
}, []), { snackbarList:
|
|
1243
|
-
const
|
|
1244
|
-
|
|
1245
|
-
return
|
|
1246
|
-
var
|
|
1389
|
+
}, []), { snackbarList: t, addSnackbar: ({ type: n = Wa, duration: s = Ra, text: a }) => {
|
|
1390
|
+
const o = { id: le("snackbar_"), duration: s, type: n, text: a };
|
|
1391
|
+
i((r) => [...r, o]), e.current = [...e.current, setTimeout(() => {
|
|
1392
|
+
return r = o.id, void i((l) => l.filter((d) => d.id !== r));
|
|
1393
|
+
var r;
|
|
1247
1394
|
}, s)];
|
|
1248
1395
|
} };
|
|
1249
|
-
},
|
|
1250
|
-
const { shapesRef: a, addPictureShape:
|
|
1251
|
-
|
|
1252
|
-
}, [
|
|
1253
|
-
|
|
1254
|
-
}, [
|
|
1255
|
-
|
|
1256
|
-
}, [
|
|
1257
|
-
|
|
1396
|
+
}, cs = ({ editorProps: e, className: t, style: i, options: n, children: s }) => {
|
|
1397
|
+
const { shapesRef: a, addPictureShape: o, moveShapes: r, toggleShapeVisibility: l, toggleShapeLock: d, canGoBackward: c, canGoForward: h, canClear: u, selectedShape: f, removeShape: v, updateShape: k, backwardShape: C, forwardShape: b, refs: Q, width: w, height: M, selectTool: L, selectShape: Z, activeTool: z, setActiveTool: T, setAvailableTools: $, isEditMode: H, availableTools: N, gridGap: y, setGridGap: E, loadFile: B, exportPicture: x, exportData: V, clearCanvas: m, settings: g, setCanvasZoom: S, canvas: { canGrow: P, layersManipulation: W, withExport: O, withLoadAndSave: Y, withUploadPicture: A, withUrlPicture: J } } = e, { toolbarBackgroundColor: j, dividerColor: se, fontRadius: oe, fontDisabledColor: I, fontDisabledBackgroundColor: ce, fontColor: re, fontBackgroundColor: be, fontSelectedColor: Te, fontSelectedBackgroundColor: we, fontHoverColor: ie, fontHoverBackgroundColor: xe } = { ...ns, ...n }, Xe = g.size === "infinite" || g.features.zoom, [Ye, de] = F(!1), [ze, ue] = F(!1), [ne, Pe] = F(Xe), Me = Xe && ne, qe = y >= yt.large ? "large" : y >= yt.medium ? "medium" : y >= yt.small ? "small" : "none", { snackbarList: Ae, addSnackbar: ye } = as(), ut = D((ae, te, Ne) => {
|
|
1398
|
+
$((Ee) => Ee.map((nt) => nt.id === ae ? fe(["settings", te, "default"], Ne, nt) : nt)), T((Ee) => Ee.id === ae ? fe(["settings", te, "default"], Ne, Ee) : Ee);
|
|
1399
|
+
}, [T, $]), pt = D(() => {
|
|
1400
|
+
L(Ze), C();
|
|
1401
|
+
}, [L, C]), gt = D(() => {
|
|
1402
|
+
L(Ze), b();
|
|
1403
|
+
}, [L, b]), Pt = D((ae) => {
|
|
1404
|
+
de(!0);
|
|
1258
1405
|
try {
|
|
1259
|
-
|
|
1260
|
-
} catch (
|
|
1261
|
-
|
|
1406
|
+
x(ae);
|
|
1407
|
+
} catch (te) {
|
|
1408
|
+
te instanceof Error && ye({ type: "error", text: `L'export a échoué : ${te.message}` }), console.warn(te);
|
|
1262
1409
|
} finally {
|
|
1263
|
-
|
|
1410
|
+
de(!1);
|
|
1264
1411
|
}
|
|
1265
|
-
}, [
|
|
1266
|
-
|
|
1412
|
+
}, [x, ye]), Vt = D(() => {
|
|
1413
|
+
de(!0);
|
|
1267
1414
|
try {
|
|
1268
|
-
|
|
1269
|
-
} catch (
|
|
1270
|
-
|
|
1415
|
+
V(), de(!1);
|
|
1416
|
+
} catch (ae) {
|
|
1417
|
+
ae instanceof Error && ye({ type: "error", text: "L'enregistrement a échoué" }), console.warn(ae);
|
|
1271
1418
|
} finally {
|
|
1272
|
-
|
|
1419
|
+
de(!1);
|
|
1273
1420
|
}
|
|
1274
|
-
}, [
|
|
1275
|
-
|
|
1421
|
+
}, [V, ye]), Zt = D(async (ae) => {
|
|
1422
|
+
de(!0);
|
|
1276
1423
|
try {
|
|
1277
|
-
await
|
|
1278
|
-
} catch (
|
|
1279
|
-
|
|
1424
|
+
await B(ae), ye({ type: "success", text: "Fichier chargé !" });
|
|
1425
|
+
} catch (te) {
|
|
1426
|
+
te instanceof Error && ye({ type: "error", text: "Le chargement a échoué" }), console.warn(te);
|
|
1280
1427
|
} finally {
|
|
1281
|
-
|
|
1428
|
+
de(!1);
|
|
1282
1429
|
}
|
|
1283
|
-
}, [
|
|
1284
|
-
|
|
1430
|
+
}, [B, ye]), Tt = D(async (ae) => {
|
|
1431
|
+
de(!0);
|
|
1285
1432
|
try {
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1288
|
-
} catch (
|
|
1289
|
-
|
|
1433
|
+
const te = await o(ae, w, M);
|
|
1434
|
+
Z(te);
|
|
1435
|
+
} catch (te) {
|
|
1436
|
+
te instanceof Error && ye({ type: "error", text: "Le chargement a échoué" }), console.warn(te);
|
|
1290
1437
|
} finally {
|
|
1291
|
-
|
|
1438
|
+
de(!1);
|
|
1292
1439
|
}
|
|
1293
|
-
}, [
|
|
1294
|
-
return R("div", { ref:
|
|
1295
|
-
|
|
1296
|
-
},
|
|
1297
|
-
|
|
1298
|
-
}, updateToolSettings:
|
|
1440
|
+
}, [o, Z, ye, w, M]), zt = `${t ? `${t} ` : ""}${ze ? "react-paint-editor-layout-opened " : ""}react-paint-editor-app`;
|
|
1441
|
+
return R("div", { ref: Q.setEditor, className: zt, style: { "--react-paint-editor-app-maxWidth": P ? "100%" : `${w}px`, "--react-paint-editor-app-toolbar-bg": j, "--react-paint-editor-app-divider-color": se, "--react-paint-editor-app-font-radius": oe, "--react-paint-editor-app-font-disabled-color": I, "--react-paint-editor-app-font-disabled-bg": ce, "--react-paint-editor-app-font-color": re, "--react-paint-editor-app-font-bg": be, "--react-paint-editor-app-font-selected-color": Te, "--react-paint-editor-app-font-selected-bg": we, "--react-paint-editor-app-font-hover-color": ie, "--react-paint-editor-app-font-hover-bg": xe, ...i }, children: [H && p(is, { settings: g, width: g.canvasSize.width, activeTool: z, clearCanvas: m, setActiveTool: L, exportCanvasInFile: Pt, saveFile: Vt, loadFile: Zt, addPicture: Tt, hasActionToUndo: c, hasActionToRedo: h, hasActionToClear: u, undoAction: pt, redoAction: gt, availableTools: N, withExport: O, withLoadAndSave: Y, withUploadPicture: A, withUrlPicture: J }), s, H && W && p($a, { gridFormat: qe, setGridFormat: (ae) => {
|
|
1442
|
+
E(yt[ae]);
|
|
1443
|
+
}, shapes: a.current, moveShapes: r, selectedShape: f, removeShape: v, selectShape: Z, toggleShapeVisibility: l, toggleShapeLock: d, isLayoutPanelShown: ze, settings: g }), Me && R(Ue, { alignment: "left", className: "react-paint-editor-layouts-panel", "data-edit": +H, children: [p(X, { 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: () => S("unzoom") }), R(X, { className: "react-paint-editor-zoom-button react-paint-editor-zoom-button-value", onClick: () => S("default"), children: [Math.round(100 * g.canvasZoom), "%"] }), p(X, { className: "react-paint-editor-zoom-button", icon: sn, onClick: () => S("zoom") })] }), H && R(Se, { children: [p(_a, { setCanvasZoom: S, width: g.canvasSize.width, activeTool: z, availableTools: N, selectedShape: f, settings: g, removeShape: v, updateShape: k, canvas: Q.canvas.current, layersManipulation: W, toggleLayoutPanel: () => {
|
|
1444
|
+
ue((ae) => !ae);
|
|
1445
|
+
}, isZoomPanelShown: Me, setIsZoomPanelShown: Pe, updateToolSettings: ut }), p(Da, { isLoading: Ye }), p(Oa, { snackbarList: Ae })] })] });
|
|
1299
1446
|
};
|
|
1300
1447
|
export {
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1448
|
+
ls as Canvas,
|
|
1449
|
+
cs as Editor,
|
|
1450
|
+
rs as useReactPaint
|
|
1304
1451
|
};
|