@yorab/react-paint 0.14.0 → 0.15.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 +46 -283
- package/dist/canvas/components/Canvas.d.ts +1 -0
- package/dist/canvas/components/EditTextBox.d.ts +2 -2
- package/dist/canvas/constants/app.d.ts +2 -0
- package/dist/canvas/constants/keyboard.d.ts +24 -0
- package/dist/canvas/hooks/useComponent.d.ts +3 -1
- package/dist/canvas/hooks/useDebounce.d.ts +2 -0
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +2 -1
- package/dist/canvas/hooks/useKeyboard.d.ts +5 -1
- package/dist/canvas/hooks/useReactPaint.d.ts +1845 -8
- package/dist/canvas/hooks/useShapes.d.ts +1378 -4
- package/dist/canvas/index.d.ts +3 -3
- package/dist/canvas/utils/data.d.ts +2 -2
- package/dist/canvas/utils/file.d.ts +233 -4
- package/dist/canvas/utils/intersect.d.ts +4 -4
- package/dist/canvas/utils/selection/groupSelection.d.ts +2 -2
- package/dist/canvas/utils/selection/lineSelection.d.ts +6 -2
- package/dist/canvas/utils/selection/rectSelection.d.ts +9 -4
- package/dist/canvas/utils/selection.d.ts +1 -1
- package/dist/canvas/utils/shapes/brush.d.ts +14 -11
- package/dist/canvas/utils/shapes/circle.d.ts +13 -9
- package/dist/canvas/utils/shapes/curve.d.ts +15 -10
- package/dist/canvas/utils/shapes/ellipse.d.ts +13 -9
- package/dist/canvas/utils/shapes/index.d.ts +19 -10
- package/dist/canvas/utils/shapes/line.d.ts +13 -8
- package/dist/canvas/utils/shapes/path.d.ts +18 -2
- package/dist/canvas/utils/shapes/picture.d.ts +13 -9
- package/dist/canvas/utils/shapes/polygon.d.ts +14 -8
- package/dist/canvas/utils/shapes/rectangle.d.ts +54 -9
- package/dist/canvas/utils/shapes/text.d.ts +12 -7
- package/dist/canvas/utils/shapes/triangle.d.ts +4 -3
- package/dist/canvas/utils/trigo.d.ts +1 -1
- package/dist/common/types/Shapes.d.ts +63 -26
- package/dist/common/types/utils.d.ts +1 -1
- package/dist/editor/components/common/Button.d.ts +2 -2
- package/dist/editor/components/common/FileInput.d.ts +13 -0
- package/dist/editor/index.d.ts +11 -11
- package/dist/react-paint.css +1 -1
- package/dist/react-paint.js +1185 -1143
- package/dist/react-paint.umd.cjs +1 -1
- package/package.json +19 -15
package/dist/react-paint.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(He,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],f):f((He=typeof globalThis<"u"?globalThis:He||self)["react-paint"]={},He.React,He.jsxRuntime)})(this,function(He,f,p){"use strict";const dn='<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>',zt='<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>',At='<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>',Et='<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>',hn='<svg><path d="M4.125 5.083V3.333H7.062L7.896 2.5H12.104L12.938 3.333H15.875V5.083ZM6.75 17.5Q6.021 17.5 5.51 16.99Q5 16.479 5 15.75V5.958H15V15.75Q15 16.479 14.49 16.99Q13.979 17.5 13.25 17.5Z"/></svg>',un='<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>',Rt='<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>',pn='<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>',gn='<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>',fn='<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>',vn='<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>',mn='<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>',yn='<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>',Sn='<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>',Qn='<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>',xn='<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>',ge=["transparent","black","white","red","green","blue","yellow"],We=[0,1,2],bn=[[1,0],[1,2],[4,6]],rt="serif",es=2,wn=3,ts=4,se="react-paint-",Cn={strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0}},Dt={type:"picture",id:`${se}picture`,icon:Rt,label:"Image",settings:{opacity:{min:0,max:100,step:1,default:100}}},Mn={type:"brush",id:`${se}brush`,icon:dn,label:"Brosse",settings:{strokeColor:{values:ge,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:We,default:0}}},kn={type:"line",id:`${se}line`,icon:gn,label:"Ligne",settings:{strokeColor:{values:ge,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0},lineArrow:{values:[0,1,2,3],default:0}}},Pn={type:"polygon",id:`${se}polygon`,icon:Et,label:"Polygone",settings:{strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0},closedPoints:{default:0}}},jn={type:"curve",id:`${se}curve`,icon:fn,label:"Courbe",settings:{strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0},closedPoints:{default:0}}},Ln={type:"rect",id:`${se}rect`,icon:zt,label:"Rectangle",settings:Cn},Vn={type:"square",id:`${se}square`,icon:zt,label:"Carré",settings:{strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0}}},Zn={type:"circle",id:`${se}circle`,icon:At,label:"Cercle",settings:{strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0}}},Hn={type:"ellipse",id:`${se}ellipse`,icon:At,label:"Ellipse",settings:{strokeColor:{values:ge,default:"black"},fillColor:{values:ge,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:We,default:0}}},Tn={type:"text",id:`${se}text`,icon:pn,label:"Texte",settings:{strokeColor:{values:ge,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}}},Te={id:`${se}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"},qe={id:`${se}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"},Ge={id:`${se}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"},_e={id:`${se}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"},Nt={id:`${se}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"},zn={id:`${se}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"},Wt={id:`${se}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"},It={id:`${se}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"},An={id:`${se}upload-picture`,type:"uploadpicture",icon:Rt,label:"Upload picture"},En=2,Rn="blue",Fe=14,Dn=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],Nn=["brush","rect","square","line","polygon","circle","curve","ellipse","picture","text","triangle","group"],Wn="react-paint-canvas-drawcanvas",In="react-paint-canvas-selectioncanvas",Fn={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,availableTools:[Mn,kn,Pn,jn,Ln,Vn,Zn,Hn,Dt,Tn],clearCallback:"empty",brushAlgo:"simple",isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:"fixed",canZoom:"never"},ns={canvasBackgroundColor:"white",canvasSelectionColor:Rn,canvasSelectionWidth:En},On=(e,t)=>!!(e.target instanceof Node&&t)&&t.contains(e.target),Bn=300,Ft=(e,t)=>{const n={...t};for(const i of e)delete n[i];return n},ve=(e,t,n)=>{const i=Array.isArray(n)?[...n]:{...n},s=Array.isArray(e)?e:typeof e=="string"?e.split("."):[e];return s.reduce((a,o,l)=>(a[o]=Ot(a[o])?{...a[o]}:Array.isArray(a[o])?[...a[o]]:a[o]===void 0||a[o]===null?{}:a[o],l===s.length-1&&(a[o]=t),a[o]),i),i},Ot=e=>typeof e=="object"&&!Array.isArray(e)&&e!==null,Pe=(e,t,n)=>{if(!Ot(t)||!Ot(n))return n;const i={...t};for(const s in n)n.hasOwnProperty(s)&&(i.hasOwnProperty(s)?i[s]=e(i[s],n[s],s)??Pe(e,i[s],n[s]):i[s]=n[s]);return i},$n=(e,t)=>{if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const n=Object.keys(e),i=Object.keys(t);if(n.length!==i.length)return!1;for(const s of n)if(!i.includes(s)||!$n(e[s],t[s]))return!1;return!0},Bt={},he=(e="")=>(Bt[e]||(Bt[e]=0),`${e}${++Bt[e]}`),je=(e,t,n)=>Math.max(t,Math.min(e,n)),Un=()=>typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),Yn=e=>{e.reset(),e.lineCap="round",e.lineJoin="round"},Ce=(e,t={})=>{const{lineCap:n="round",fillColor:i="transparent",opacity:s=100,strokeColor:a=Rn,lineWidth:o=En,lineDash:l=0,shadowColor:r="transparent",shadowBlur:d=0}=t;e.lineCap=n,e.globalAlpha=s/100,e.fillStyle=i,e.strokeStyle=a,e.lineWidth=o,e.setLineDash(l===0?[]:[bn[l][0]*o,bn[l][1]*o]),e.shadowColor=r,e.shadowBlur=d},pt=(e,t,n,i)=>{e.save(),e.scale(t.canvasSize.scaleRatio,t.canvasSize.scaleRatio),e.translate(t.canvasOffset[0],t.canvasOffset[1]),n&&i&&(e.translate(i[0],i[1]),e.rotate(n),e.translate(-i[0],-i[1]))},Ke=(e,t)=>{const n=os(e,t);return{...e,path:n,selection:Je(n,e,t)}},is=Ke,$t=e=>180*e/Math.PI,Xn=(e,t)=>{const n=t.x-Math.min(Math.max(t.x,e.x),e.x+e.width),i=t.y-Math.min(Math.max(t.y,e.y),e.y+e.height);return Math.sqrt(n*n+i*i)<=t.radius},me=({origin:e=[0,0],point:t,rotation:n})=>{const i=[t[0]-e[0],t[1]-e[1]],s=i[1]*Math.cos(n)-i[0]*Math.sin(n);return[i[1]*Math.sin(n)+i[0]*Math.cos(n)+e[0],s+e[1]]},qn=e=>(e+2*Math.PI)%(2*Math.PI),Gn=({targetVector:[e,t],radian:n=!0,originVector:i})=>{const s=qn(Math.atan2(t[1]-e[1],t[0]-e[0]));if(i){const[a,o]=i,l=Math.atan2(o[1]-a[1],o[0]-a[0]),r=qn(s-l);return n?r:$t(r)}return n?s:$t(s)},_n=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),Ie=(e,t=2)=>Math.round(e*10**t)/10**t,Me=(e,t,n,i=1,s=1)=>[t+(e[0]-t)*i,n+(e[1]-n)*s],O=(e,t,n=0)=>{if(!t.gridGap)return Ie(e);const i=e+n,s=i>=0?t.gridGap:-t.gridGap;return i+s/2-(i+s/2)%s-n},ss=(e,t,n)=>t.gridGap||n?e+Math.PI/18/2-(e+Math.PI/18/2)%(Math.PI/18):Ie(e,3),ze=(e,t)=>t?[Math.abs(e[0])>Math.abs(e[1])?e[0]:0,Math.abs(e[1])>Math.abs(e[0])?e[1]:0]:e,as=(e,t,n,i,s,a,o)=>fe($(t).map(l=>{switch(i.mode){case"brush":return((r,d,h)=>{const c={...r,points:ve(r.points.length-1,[...r.points[r.points.length-1],[Math.round(d[0]),Math.round(d[1])]],r.points)};return Ke(c,h)})(l,n,s);case"translate":return en(n,$(i.originalShape).find(r=>r.id===l.id),i.cursorStartPosition,s,a);case"rotate":return Ps(l,n,$(i.originalShape).find(r=>r.id===l.id),i.cursorStartPosition,i.center,s,a);case"resize":return js(e,l,n,$(i.originalShape).find(r=>r.id===l.id),i,s,a,o);default:return l}}),s),Ut=e=>{const t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},gt=e=>{const t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},ft=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},os=(e,{brushAlgo:t})=>{if(e.points.length<1||e.style?.strokeColor==="transparent")return;const n=e.points.flat(),i=n.map(r=>r[0]),s=n.map(r=>r[1]),a=Math.min(...i),o=Math.min(...s),l=new Path2D;for(const r of e.points){if(!r.length)return;if(r.length===1)l.rect(...Me(r[0],a,o,e.scaleX,e.scaleY),1,1);else if(l.moveTo(...Me(r[0],a,o,e.scaleX,e.scaleY)),t==="quadratic"){for(let d=0;d<r.slice(1).length-2;d++){const h=Me(r[d],a,o,e.scaleX,e.scaleY),c=Me(r[d+1],a,o,e.scaleX,e.scaleY),u=(h[0]+c[0])/2,m=(h[1]+c[1])/2;l.quadraticCurveTo(...h,u,m)}l.quadraticCurveTo(...Me(r[r.length-2],a,o,e.scaleX,e.scaleY),...Me(r[r.length-1],a,o,e.scaleX,e.scaleY))}else for(const d of r.slice(1))l.lineTo(...Me(d,a,o,e.scaleX,e.scaleY))}return l},Kn=(e,t)=>e.style?.closedPoints===1&&t.length>2?[t[t.length-2],...t,t[0],t[1]]:[t[0],...t,t[t.length-1]],Jn=(e,t,n,i,s)=>{const a=n[0]+(i[0]-t[0])/6,o=n[1]+(i[1]-t[1])/6,l=i[0]-(s[0]-n[0])/6,r=i[1]-(s[1]-n[1])/6;e.bezierCurveTo(a,o,l,r,i[0],i[1])},ei=e=>{const t=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(t.length<2)return;const n=new Path2D;n.moveTo(...t[0]);for(const i of t.slice(1))n.lineTo(...i);return t.length>2&&e.style?.closedPoints===1&&n.lineTo(...t[0]),n},rs=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t.lineTo(...e.points[2]),t.lineTo(...e.points[0]),t},Je=(e,t,n,i=!1)=>{const{borders:s}=J(t,n);return{border:Ut(s),shapePath:e,line:i?void 0:ft({points:[[s.x+s.width/2,s.y],[s.x+s.width/2,s.y-23/n.canvasSize.scaleRatio]]}),anchors:i?[]:[gt({x:s.x+s.width/2,y:s.y-23/n.canvasSize.scaleRatio,radius:7/n.canvasSize.scaleRatio}),...Dn.map(a=>gt({x:s.x+s.width*a[0],y:s.y+s.height*a[1],radius:7/n.canvasSize.scaleRatio}))]}},ti=({borderStart:e,borderSize:t,vector:n,settings:i,invertedAxe:s,anchor:a})=>{switch(a){case 0:{if(s){const l=t-2*i.selectionPadding;return[e+l,n-l]}const o=Math.max(2*i.selectionPadding,t-n);return[e+t-o,o]}case .5:return[e,t];case 1:if(s){const o=t+n;return[e+o,2*i.selectionPadding-o]}return[e,Math.max(2*i.selectionPadding,t+n)];default:return[0,0]}},et=(e,t,n,i,s=!1,a=!1)=>{const{center:o,borders:l}=J(t,i),r=me({origin:o,point:e,rotation:t.rotation}),d=n.anchor[0]===0&&r[0]>=l.x+l.width||n.anchor[0]===1&&r[0]<=l.x,h=n.anchor[1]===0&&r[1]>=l.y+l.height||n.anchor[1]===1&&r[1]<=l.y,c=[O(r[0],i,n.anchor[0]===0&&!d||n.anchor[0]===1&&d?i.selectionPadding:-i.selectionPadding),O(r[1],i,n.anchor[1]===0&&!h||n.anchor[1]===1&&h?i.selectionPadding:-i.selectionPadding)],u=i.gridGap?[n.anchor[0]===0?l.x:n.anchor[0]===.5?l.x+l.width/2:l.x+l.width,n.anchor[1]===0?l.y:n.anchor[1]===.5?l.y+l.height/2:l.y+l.height]:me({origin:o,point:n.cursorStartPosition,rotation:t.rotation}),m=[c[0]-u[0],c[1]-u[1]],[v,b]=ti({borderStart:l.x,borderSize:l.width,vector:m[0],settings:i,invertedAxe:d,anchor:n.anchor[0]}),[k,j]=ti({borderStart:l.y,borderSize:l.height,vector:m[1],settings:i,invertedAxe:h,anchor:n.anchor[1]}),C=s?((S,y,Q,E,H,z,T,V,W,N)=>{const{selectionPadding:A}=N,I=(y.width-2*A||1)/(y.height-2*A||1),X=(H-2*A)/(T-2*A);let B,M,g,w;return W.anchor[0]!==.5&&W.anchor[1]!==.5?X<I?(M=z,w=T,g=(T-2*A)*I+2*A,B=W.anchor[0]===0?y.width-S[0]>A?y.x+(y.width-g):y.x+y.width-2*A:y.width+S[0]>A?y.x:y.x-g+2*A):(B=E,g=H,w=(H-2*A)/I+2*A,M=W.anchor[1]===0?y.height-S[1]>A?y.y+(y.height-w):y.y+y.height-2*A:y.height+S[1]>A?y.y:y.y-w+2*A):W.anchor[0]!==.5?(B=E,g=H,w=(H-2*A)/I+2*A,M=y.y+(y.height-w)/2):(M=z,w=T,g=(T-2*A)*I+2*A,B=y.x+(y.width-g)/2),{borderX:B,borderWidth:g,borderY:M,borderHeight:w,center:Q,originalShape:V}})(m,l,o,v,b,k,j,t,n,i):{borderX:v,borderWidth:b,borderY:k,borderHeight:j,center:o,originalShape:t};return(({borderX:S,borderWidth:y,borderY:Q,borderHeight:E,center:H,originalShape:z})=>{const T=[S+y/2-H[0],Q+E/2-H[1]],[V,W]=me({point:T,rotation:-z.rotation});return{borderX:Ie(S+V-T[0]),borderWidth:Ie(y),borderY:Ie(Q+W-T[1]),borderHeight:Ie(E)}})(a?((S,y,Q,E)=>{const H=y.x+y.width/2,z=y.y+y.height/2,T=Q?2*S.borderWidth+y.width:Math.abs(y.width+2*(S.borderWidth-y.width)),V=E?2*S.borderHeight+y.height:Math.abs(y.height+2*(S.borderHeight-y.height));return{...S,borderHeight:V,borderWidth:T,borderX:H-T/2,borderY:z-V/2}})(C,l,d,h):C)},vt=(e,t,n=!1)=>{const i=Ut(e);return{...e,path:i,selection:Je(i,e,t,n)}},ls=vt,ni=(e,t,n,i=!1,s=0,a=0)=>{const o={toolId:e.id,type:e.type,id:he(`${e.type}_`),x:t[0],y:t[1],width:s,height:a,rotation:0,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}};return vt(o,n,i)},cs=(e,t)=>{e.globalAlpha!==0&&t.path&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},ii=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),si=(e,t,n,[i,s]=[!1,!1])=>{const a=e[0]===.5?n.x+n.width/2:e[0]===0?n.x+(i?0:n.width):n.x+(i?n.width:0),o=e[1]===.5?n.y+n.height/2:e[1]===0?n.y+(s?0:n.height):n.y+(s?n.height:0);return us([a,o],n.rotation,t)},ai=(e,t,n,i,s,a,o,l)=>{let r=!1;if(s){r=lt(e,s,n,i,!0,a?20:void 0);const h=((c,u,m,v)=>{if(c.mode==="translate")return{mode:"translate",cursorStartPosition:m,originalShape:u,dateStart:Date.now()};if(c.mode==="rotate"){const{center:b}=J(u,v);return{mode:"rotate",cursorStartPosition:m,originalShape:u,center:[b[0],b[1]]}}return c.mode==="resize"?{mode:"resize",cursorStartPosition:m,originalShape:u,anchor:c.anchor}:void 0})(r||{mode:"default"},s,n,i);if(h?.mode==="resize"||h?.mode==="rotate")return{shape:s,mode:h}}const d=t.find(h=>$(s).find(c=>h.id===c?.id)?r&&l?lt(e,h,n,i,!0,a?20:void 0):!!r:!!hi(e,h,n,i));if(d){if(l){const c=$(s).find(u=>u.id===d?.id)?fe(hs(s,d),i):fe(ri(s,[d]),i);return{shape:c,mode:{mode:"translate",cursorStartPosition:n,dateStart:Date.now(),originalShape:c}}}const h=$(s).find(c=>c.id===d?.id)?s:fe([d],i);return{shape:h,mode:{mode:"translate",cursorStartPosition:n,dateStart:Date.now(),originalShape:h}}}return l?{shape:s,mode:{mode:o?"selectionFrame":"default"}}:{shape:void 0,mode:{mode:o?"selectionFrame":"default"}}},ds=(e,t,n=!0)=>{const i=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]];if(!n)return i;const s=[e.x+e.width/2,e.y+e.height/2];return i.map(a=>me({point:[a[0],a[1]],origin:s,rotation:t}))},fe=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];let n=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;const o=e.some(h=>h.rotation!==e[0].rotation),l=o?0:e[0].rotation;for(const h of e){const{borders:c}=J(h,t),u=ds(c,h.rotation,o);n=Math.min(u[0][0],u[1][0],u[2][0],u[3][0],n),s=Math.max(u[0][0],u[1][0],u[2][0],u[3][0],s),i=Math.min(u[0][1],u[1][1],u[2][1],u[3][1],i),a=Math.max(u[0][1],u[1][1],u[2][1],u[3][1],a)}const r=ni({id:"test",type:"rect",settings:Cn},[n,i],t,!0,s-n,a-i),d=e.slice(1).reduce((h,c)=>{const u=c.style??{},m={};for(const v in u)h[v]!==void 0&&u[v]!==void 0&&h[v]===u[v]&&(m[v]=h[v]);return m},e[0].style??{});return{id:e.map(h=>h.id).join("-"),type:"group",shapes:e,rotation:l,visible:!0,locked:!1,selection:r.selection,x:r.x,y:r.y,width:r.width,height:r.height,style:d}},oi=(e,t)=>n=>{if(!n)return;const i=n.type==="group"?n.shapes.map(s=>e(s,t)):[e(n,t)];return fe(i,t)},$=e=>e?e.type==="group"?e.shapes:[e]:[],ri=(e,t)=>{const n=$(e);return[...new Set([...n,...t])]},hs=(e,t)=>$(e).filter(n=>n.id!==t.id),li=e=>{const{clientX:t=0,clientY:n=0}="touches"in e&&e.touches[0]?e.touches[0]:"changedTouches"in e&&e.changedTouches[0]?e.changedTouches[0]:"clientX"in e?e:{};return{clientX:t,clientY:n}},ci=(e,t,n)=>{const{clientX:i,clientY:s}=li(e),a=t.getBoundingClientRect();return[(i-a.left)/n.scaleRatio,(s-a.top)/n.scaleRatio]},tt=(e,t,n)=>{const{clientX:i,clientY:s}=li(e),a=t?.getBoundingClientRect()??{left:0,top:0,width:n.canvasSize.width,height:n.canvasSize.height};return[(i-a.left)*(n.canvasSize.width/a.width)/n.canvasSize.scaleRatio-n.canvasOffset[0],(s-a.top)*(n.canvasSize.height/a.height)/n.canvasSize.scaleRatio-n.canvasOffset[1]]},nt=e=>"touches"in e,ke=(e,t,[n,i])=>me({origin:[n,i],point:e,rotation:t}),us=(e,t,[n,i])=>me({origin:[n,i],point:e,rotation:-t}),mt=(e,t,n)=>n?Xn(e,{x:t[0],y:t[1],radius:n}):((i,s)=>s[0]>=i.x&&s[0]<=i.x+i.width&&s[1]>=i.y&&s[1]<=i.y+i.height)(e,t),lt=(e,t,n,i,s=!1,a=0)=>{if(t.locked)return!1;const{canvasSize:{scaleRatio:o}}=i,{borders:l,center:r}=J(t,i),d=ke(n,t.rotation,r),h=$(t);if(s){if(h.length!==1||h[0]?.type!=="line"&&h[0]?.type!=="polygon"&&h[0]?.type!=="curve"){if(h.length===1){if(mt({x:l.x+l.width/2-7/o,y:l.y-Fe/o-16/o,width:Fe/o,height:Fe/o},d,a))return{mode:"rotate"};for(const c of Dn)if(mt({x:l.x+l.width*c[0]-7/o,y:l.y+l.height*c[1]-7/o,width:Fe/o,height:Fe/o},d,a))return{mode:"resize",anchor:c}}}else for(let c=0;c<h[0].points.length;c++)if(mt({x:h[0].points[c][0]-7/o,y:h[0].points[c][1]-7/o,width:Fe/o,height:Fe/o},d,a))return{mode:"resize",anchor:c}}return(mt(l,d,a)||!!(t.type==="curve"&&"path"in t&&t.path&&e.isPointInPath(t.path,d[0],d[1])))&&{mode:"translate"}},di=(e,t,n,i,s=50)=>{if(t.locked||t.points.length<2)return!1;const{center:a}=J(t,i),o=ke(n,t.rotation,a);e.lineWidth=(t.style?.lineWidth??0)+s/i.canvasZoom;const l=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let r=0;r<l.length-1;r++){const d=ft({points:[l[r],l[r+1]]});if(e.isPointInStroke(d,o[0],o[1]))return{lineIndex:r}}return!1},hi=(e,t,n,i)=>{if(t.locked)return!1;const{center:s}=J(t,i),a=ke(n,t.rotation,s);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/i.canvasZoom,!!e.isPointInStroke(t.path,a[0],a[1])&&{mode:"translate"}):lt(e,t,n,i,!1)};function Yt(e,t){const n=Math.max(e.x,t.x),i=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));if(n<s&&i<a)return{x:n,y:i,width:s-n,height:a-i}}const ui=({ctx:e,path:t,rect:n,offset:i,checkFill:s})=>{for(let a=0;a<i;a+=i/2)for(let o=0;o<i;o+=i/2)for(let l=a+n.x;l<n.x+n.width;l+=i)for(let r=o+n.y;r<n.y+n.height;r+=i)if(s?e.isPointInPath(t,l,r):e.isPointInStroke(t,l,r))return!0;return!1},Xt=(e,t,n)=>{const{borders:i}=J(t,n);return{border:Ut(i),shapePath:e,anchors:[...t.points.map(s=>gt({x:s[0],y:s[1],radius:7/n.canvasSize.scaleRatio}))]}},ye=[.05,.1,.25,.5,1,2,4,8],qt=({size:e,zoom:t,newOffset:[n,i],canvasSize:s})=>e==="infinite"?{zoom:t,offset:[n,i]}:t<1?{zoom:t,offset:[-(s.realWidth-s.realWidth/t)/2,-(s.realHeight-s.realHeight/t)/2]}:{zoom:t,offset:[je(n,s.realWidth/t-s.realWidth,0),je(i,s.realHeight/t-s.realHeight,0)]},Gt=({size:e,canvasSize:t,currentOffset:n,currentZoom:i,zoom:s,centerPoint:a})=>{const o=e==="fixed"&&s<1?[t.realWidth/2,t.realHeight/2]:a,l=n[0]-(o[0]/i-o[0]/s),r=n[1]-(o[1]/i-o[1]/s);return{offset:e==="infinite"?[l,r]:s<1?[-(t.realWidth-t.realWidth/s)/2,-(t.realHeight-t.realHeight/s)/2]:[je(l,t.realWidth/s-t.realWidth,0),je(r,t.realHeight/s-t.realHeight,0)],zoom:s}},pi=e=>{const{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:i},canvasZoom:s,canvasOffset:a}=e;return{x:a[0]*s*i,y:a[1]*s*i,width:t*s,height:n*s}},gi=(e,t)=>{const{canvasZoom:n,size:i}=t;if(i!=="fixed"||n>=1)return;const s=pi(t);e.beginPath(),e.rect(s.x,s.y,s.width,s.height),e.closePath(),e.clip()},ct=(e,t)=>t.size!=="fixed"||e[0]>0&&e[0]<t.canvasSize.realWidth&&e[1]>0&&e[1]<t.canvasSize.realHeight,yt=(e,t)=>{const n=gt(e);return{...e,path:n,selection:Je(n,e,t)}},ps=yt,it=(e,t)=>{const n=ei(e);return{...e,path:n,selection:Xt(n,e,t)}},gs=it,fi=(e,t)=>{const n=Math.min(...e.points.map(a=>a[0]))-t.selectionPadding,i=Math.max(...e.points.map(a=>a[0]))+t.selectionPadding,s=Math.min(...e.points.map(a=>a[1]))-t.selectionPadding;return{x:n,width:i-n,y:s,height:Math.max(...e.points.map(a=>a[1]))+t.selectionPadding-s}},fs=(e,t,n,i)=>{if(t<0||t>e.points.length-1)return e;const s=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return it({...e,points:s},i)},vi=(e,t,n,i=!1)=>{const s=[O(t[0],n),O(t[1],n)],{center:a}=J(e,n),o=ke(s,e.rotation,a),l={...e,points:i?e.points:[...e.points,o],tempPoint:i?o:void 0};return it(l,n)},st=(e,t)=>{const n=(i=>{const s=i.tempPoint?[...i.points,i.tempPoint]:i.points;if(s.length<2)return;if(s.length<3)return ei(i);const a=i.style?.closedPoints===1&&s.length>2,o=new Path2D;o.moveTo(...s[0]);const l=Kn(i,s);for(let r=1;r<l.length-2;r++){const d=l[r-1],h=l[r],c=l[r+1],u=l[r+2];Jn(o,d,h,c,u)}return a&&o.closePath(),o})(e);return{...e,path:n,selection:Xt(n,e,t)}},vs=st,ms=fi,ys=(e,t,n,i)=>{if(t<0||t>e.points.length-1)return e;const s=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return st({...e,points:s},i)},mi=(e,t,n,i=!1)=>{const s=[O(t[0],n),O(t[1],n)],{center:a}=J(e,n),o=ke(s,e.rotation,a),l={...e,points:i?e.points:[...e.points,o],tempPoint:i?o:void 0};return st(l,n)},St=(e,t)=>{const n=(i=>{const s=new Path2D;return s.ellipse(i.x,i.y,i.radiusX,i.radiusY,0,0,2*Math.PI),s})(e);return{...e,path:n,selection:Je(n,e,t)}},Ss=St,yi=e=>{return n={...e,type:"triangle"},{...n,path:rs(n)};var n},Qs=(e,t)=>{e.globalAlpha!==0&&t.path&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},Qt=(e,t)=>{const n=[];let i;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){const s=Math.PI/2-Gn({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||n.push(yi(Si(e.points[0],s,e.style))),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||n.push(yi(Si(e.points[1],s+Math.PI,e.style)));const a=(({line:o,size:l,direction:r})=>{const d=Math.PI/2-Gn({targetVector:[o.points[0],o.points[1]]}),h=[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];let c,u;if(["start","both"].includes(r)){const m=me({point:o.points[0],origin:h,rotation:-d});c=me({point:[m[0],m[1]+l],origin:h,rotation:d})}else c=[...o.points[0]];if(["end","both"].includes(r)){const m=me({point:o.points[1],origin:h,rotation:-d});u=me({point:[m[0],m[1]-l],origin:h,rotation:d})}else u=[...o.points[1]];return{points:[c,u]}})({line:e,size:10+2*(e.style?.lineWidth??0),direction:e.style?.lineArrow===1?"start":e.style?.lineArrow===2?"end":"both"});i=ft(a)}else i=ft(e);return{...e,path:i,selection:Xt(i,e,t),arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"}}},xs=Qt,Si=(e,t,n)=>{const i=[me({point:[0,0],rotation:t}),me({point:[-(5+(n.lineWidth??0)),10+2*(n.lineWidth??0)],rotation:t}),me({point:[5+(n.lineWidth??0),10+2*(n.lineWidth??0)],rotation:t})];return{points:[[e[0]+i[0][0],e[1]+i[0][1]],[e[0]+i[1][0],e[1]+i[1][1]],[e[0]+i[2][0],e[1]+i[2][1]]],style:{...n,fillColor:n.strokeColor,strokeColor:"transparent"}}},xt=(e,t)=>({...e,selection:Je(void 0,e,t)}),bs=xt,_t=(e,t,n,i,s)=>{const[a,o]=((l,r,d,h,c=!1)=>{if(!(l&&r&&h&&d))return[Bn,Bn];const u=l/r;if(u>d/h){const v=c?d:Math.min(l,d);return[v,v/u]}const m=c?h:Math.min(r,h);return[m*u,m]})(e.width,e.height,n,i,!0);return xt({toolId:Dt.id,type:"picture",id:he("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)},ws=(e,t,n,i)=>new Promise((s,a)=>{const o=new Image;o.onerror=()=>{a(new Error("Some images could not be loaded"))},setTimeout(()=>{a(new Error("Timeout while loading images"))},4e3),e instanceof File?((l,r,d,h,c,u)=>{Mi(d)?d.text().then(m=>{const v=Ci(m);l.onload=async()=>{URL.revokeObjectURL(l.src);const b=_t(l,m,h,c,u);r(b)},l.src=v}):(l.onload=async()=>{URL.revokeObjectURL(l.src);const m=_t(l,l.src,h,c,u);r(m)},l.src=URL.createObjectURL(d))})(o,s,e,t,n,i):((l,r,d,h,c,u)=>{l.onload=()=>{URL.revokeObjectURL(l.src);const m=_t(l,d,h,c,u);r(m)},ki(d).then(m=>{l.src=m}).catch(()=>{l.src=""})})(o,s,e,t,n,i)}),Kt=["Texte"],bt=(e,t)=>({...e,selection:Je(void 0,e,t)}),Cs=bt,Jt=(e,t,n,i,s,a=rt)=>{e.font=`${s?"italic":""} ${i?"bold":""} 1px ${a}`;const o=t.map(l=>n/e.measureText(l).width);return Math.min(...o)||36},Ms=(e,t,n,i)=>{const s={...t,value:n},a=((v,b,k,j,C,S=rt)=>{v.font=`${C?"italic":""} ${j?"bold":""} ${k}px ${S}`;const y=b.map(Q=>v.measureText(Q).width);return Math.max(...y)||20})(e,s.value,s.fontSize,s.style?.fontBold??!1,s.style?.fontItalic??!1,s.style?.fontFamily),o=s.fontSize*s.value.length,l={...s,width:a,height:o},{center:r}=J(t,i),{center:d}=J(l,i),[h,c]=si([1,1],r,t),[u,m]=si([1,1],d,l,[!1,!1]);return{...l,x:l.x-(u-h),y:l.y-(m-c)}},Qi=(e,t,n,i)=>{const s=[O(n[0],i),O(n[1],i)];switch(t.type){case"brush":return((a,o,l)=>Ke({toolId:a.id,type:a.type,id:he(`${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}},l))(t,s,i);case"line":return((a,o,l)=>{const r={toolId:a.id,type:a.type,id:he(`${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}};return Qt(r,l)})(t,s,i);case"polygon":return((a,o,l)=>it({toolId:a.id,type:a.type,id:he(`${a.type}_`),points:[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,closedPoints:a.settings.closedPoints.default}},l))(t,s,i);case"curve":return((a,o,l)=>st({toolId:a.id,type:a.type,id:he(`${a.type}_`),points:[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,closedPoints:a.settings.closedPoints.default}},l))(t,s,i);case"rect":case"square":return ni(t,s,i);case"text":return((a,o,l,r)=>{const d=Jt(a,Kt,150,o.settings?.fontBold.default??!1,o.settings?.fontItalic.default??!1,o.settings.fontFamily.default),h=d*(Kt.length||1);return bt({toolId:o.id,type:o.type,id:he(`${o.type}_`),x:l[0]-150,y:l[1]-h,value:Kt,fontSize:d,width:150,height:h,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}},r)})(e,t,s,i);case"ellipse":return((a,o,l)=>St({toolId:a.id,type:a.type,id:he(`${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}},l))(t,s,i);case"circle":return((a,o,l)=>yt({toolId:a.id,type:a.type,id:he(`${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}},l))(t,s,i)}},xi=(e,t)=>{switch(t.type){case"brush":((n,i)=>{i.points.length<1||!i.path||n.globalAlpha!==0&&i.style?.strokeColor!=="transparent"&&n.globalAlpha!==0&&n.stroke(i.path)})(e,t);break;case"text":((n,i)=>{if(n.globalAlpha!==0&&i.style?.strokeColor&&i.style.strokeColor!=="transparent"){n.font=`${i.style?.fontItalic?"italic":""} ${i.style?.fontBold?"bold":""} ${i.fontSize}px ${i.style?.fontFamily??rt}`,n.textBaseline="top",n.fillStyle=i.style.strokeColor;for(let s=0;s<i.value.length;s++)n.fillText(i.value[s],i.x,i.y+s*i.fontSize,i.width)}})(e,t);break;case"line":((n,i)=>{if(n.globalAlpha!==0&&i.path){i.style?.fillColor!=="transparent"&&n.fill(i.path),i.style?.strokeColor!=="transparent"&&n.stroke(i.path);for(const s of i.arrows??[])Ce(n,s.style),Qs(n,s)}})(e,t);break;case"polygon":((n,i)=>{i.path&&n.globalAlpha!==0&&(i.style?.fillColor!=="transparent"&&n.fill(i.path),i.style?.strokeColor!=="transparent"&&n.stroke(i.path))})(e,t);break;case"curve":((n,i)=>{i.path&&n.globalAlpha!==0&&(i.style?.fillColor!=="transparent"&&n.fill(i.path),i.style?.strokeColor!=="transparent"&&n.stroke(i.path))})(e,t);break;case"circle":((n,i)=>{n.globalAlpha!==0&&i.path&&(i.style?.fillColor!=="transparent"&&n.fill(i.path),i.style?.strokeColor!=="transparent"&&n.stroke(i.path))})(e,t);break;case"ellipse":((n,i)=>{n.globalAlpha!==0&&i.path&&(i.style?.fillColor!=="transparent"&&n.fill(i.path),i.style?.strokeColor!=="transparent"&&n.stroke(i.path))})(e,t);break;case"rect":case"square":cs(e,t);break;case"picture":((n,i)=>{n.globalAlpha!==0&&(n.beginPath(),n.drawImage(i.img,i.x,i.y,i.width,i.height))})(e,t)}},bi=(e,t,n)=>{if(t.visible===!1)return;const{center:i,outerBorders:s}=J(t,n),a=(o=>{const{canvasSize:{width:l,height:r,scaleRatioWithNoZoom:d},canvasZoom:h,canvasOffset:c}=o;return{x:-c[0],y:-c[1],width:l/h/d,height:r/h/d}})(n);if(Yt(s,a)){if(pt(e,n,t.rotation,i),Ce(e,t.style),e.globalAlpha!==1)return((o,l,r)=>{const d=document.createElement("canvas"),h=d.getContext("2d");if(!h)throw new Error("No context found for canvas");const c={width:2*r.width,height:2*r.height};d.width=c.width,d.height=c.height,h.translate(c.width/4-r.x,c.height/4-r.y),Ce(h,{...l.style,opacity:100}),xi(h,l),o.drawImage(d,r.x-c.width/4,r.y-c.height/4)})(e,t,s),void e.restore();xi(e,t),e.restore()}},ks=(e,t)=>{switch(e.type){case"brush":return((n,{selectionPadding:i})=>{const s=n.points.flat(),a=Math.min(...s.map(h=>h[0])),o=Math.min(...s.map(h=>h[1])),l=s.map(h=>Me(h,a,o,n.scaleX,n.scaleY)),r=Math.max(...l.map(h=>h[0]))+i,d=Math.max(...l.map(h=>h[1]))+i;return{x:a-i,width:r-a+i,y:o-i,height:d-o+i}})(e,t);case"line":return((n,i)=>({x:Math.min(n.points[0][0],n.points[1][0])-i.selectionPadding,width:Math.abs(n.points[0][0]-n.points[1][0])+2*i.selectionPadding,y:Math.min(n.points[0][1],n.points[1][1])-i.selectionPadding,height:Math.abs(n.points[0][1]-n.points[1][1])+2*i.selectionPadding}))(e,t);case"polygon":return fi(e,t);case"curve":return ms(e,t);case"circle":return((n,i)=>({x:n.x-n.radius-i.selectionPadding,width:2*(n.radius+i.selectionPadding),y:n.y-n.radius-i.selectionPadding,height:2*(n.radius+i.selectionPadding)}))(e,t);case"ellipse":return((n,i)=>({x:n.x-n.radiusX-i.selectionPadding,width:2*(n.radiusX+i.selectionPadding),y:n.y-n.radiusY-i.selectionPadding,height:2*(n.radiusY+i.selectionPadding)}))(e,t);case"rect":case"square":case"group":return ii(e,t);case"text":return((n,i)=>({x:n.x-i.selectionPadding,width:n.width+2*i.selectionPadding,y:n.y-i.selectionPadding,height:n.height+2*i.selectionPadding}))(e,t);case"picture":return((n,i)=>ii(n,i))(e,t);default:return{x:0,y:0,width:100,height:100}}},J=(e,t)=>{const n=ks(e,t),i={x:n.x-(e.style?.lineWidth??0),y:n.y-(e.style?.lineWidth??0),width:n.width+2*(e.style?.lineWidth??0),height:n.height+2*(e.style?.lineWidth??0)},s=(a=>[a.x+a.width/2,a.y+a.height/2])(n);return{borders:n,outerBorders:i,center:s}},Ps=(e,t,n,i,s,a,o)=>{const l=s[0]-i[0],r=s[1]-i[1],d=s[0]-t[0],h=s[1]-t[1],c=n.rotation+Math.atan2(h,d)-Math.atan2(r,l);return{...e,rotation:ss(c,a,o)}},js=(e,t,n,i,s,a,o,l)=>{switch(i.type){case"line":return((r,d,h,c)=>{const u=[O(r[0],c),O(r[1],c)],{center:m}=J(d,c),v=ke(u,d.rotation,m),b=ve(["points",h.anchor],v,d);return Qt(b,c)})(n,i,s,a);case"polygon":return((r,d,h,c)=>{const u=[O(r[0],c),O(r[1],c)],{center:m}=J(d,c),v=ke(u,d.rotation,m),b=ve(["points",h.anchor],v,d);return it(b,c)})(n,i,s,a);case"curve":return((r,d,h,c)=>{const u=[O(r[0],c),O(r[1],c)],{center:m}=J(d,c),v=ke(u,d.rotation,m),b=ve(["points",h.anchor],v,d);return st(b,c)})(n,i,s,a);case"brush":return((r,d,h,c,u,m)=>{const{borders:v}=J({...d,scaleX:1,scaleY:1},c),{borders:b}=J(d,c),{borderX:k,borderHeight:j,borderY:C,borderWidth:S}=et(r,d,h,c,u,m),y=Math.max(0,v.width-2*c.selectionPadding),Q=Math.max(0,v.height-2*c.selectionPadding),E=Math.max(0,S-2*c.selectionPadding),H=Math.max(0,j-2*c.selectionPadding),z=y?E/y:1,T=Q?H/Q:1;if(!y||!Q)return d;const V=Ie(k-b.x),W=Ie(C-b.y);return Ke({...d,points:d.points.map(N=>N.map(([A,I])=>[A+V,I+W])),scaleX:z,scaleY:T},c)})(n,i,s,a,o,l);case"circle":return((r,d,h,c,u)=>{const{borderX:m,borderHeight:v,borderY:b,borderWidth:k}=et(r,d,h,c,!0,u);return yt({...d,radius:Math.max(0,k/2-c.selectionPadding),x:m+k/2,y:b+v/2},c)})(n,i,s,a,l);case"ellipse":return((r,d,h,c,u=!1,m=!1)=>{const{borderX:v,borderHeight:b,borderY:k,borderWidth:j}=et(r,d,h,c,u,m);return St({...d,radiusX:Math.max(0,j/2-c.selectionPadding),radiusY:Math.max(0,b/2-c.selectionPadding),x:v+j/2,y:k+b/2},c)})(n,i,s,a,o,l);case"rect":case"square":return((r,d,h,c,u=!1,m=!1)=>{const{borderX:v,borderHeight:b,borderY:k,borderWidth:j}=et(r,d,h,c,u,m);return vt({...d,width:Math.max(0,j-2*c.selectionPadding),height:Math.max(0,b-2*c.selectionPadding),x:v+c.selectionPadding,y:k+c.selectionPadding},c)})(n,i,s,a,t.type==="square"||o,l);case"text":return((r,d,h,c,u,m)=>{const{borderX:v,borderHeight:b,borderY:k,borderWidth:j}=et(d,h,c,u,!0,m),C=bt({...h,width:Math.max(0,j-2*u.selectionPadding),height:Math.max(0,b-2*u.selectionPadding),x:v+u.selectionPadding,y:k+u.selectionPadding},u);return{...C,fontSize:Jt(r,C.value,C.width,C.style?.fontBold??!1,C.style?.fontItalic??!1,C.style?.fontFamily)}})(e,n,i,s,a,l);case"picture":return((r,d,h,c,u)=>{const{borderX:m,borderHeight:v,borderY:b,borderWidth:k}=et(r,d,h,c,!0,u);return xt({...d,width:Math.max(0,k-2*c.selectionPadding),height:Math.max(0,v-2*c.selectionPadding),x:m+c.selectionPadding,y:b+c.selectionPadding},c)})(n,i,s,a,l);default:return i}},en=(e,t,n,i,s)=>{switch(t.type){case"rect":case"square":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return vt({...o,x:O(o.x+h[0],r),y:O(o.y+h[1],r)},r)})(e,t,n,i,s);case"ellipse":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return St({...o,x:O(o.x+h[0],r),y:O(o.y+h[1],r)},r)})(e,t,n,i,s);case"circle":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return yt({...o,x:O(o.x+h[0],r),y:O(o.y+h[1],r)},r)})(e,t,n,i,s);case"picture":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return xt({...o,x:O(o.x+h[0],r),y:O(o.y+h[1],r)},r)})(e,t,n,i,s);case"text":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return bt({...o,x:O(o.x+h[0],r),y:O(o.y+h[1],r)},r)})(e,t,n,i,s);case"line":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d);return Qt({...o,points:o.points.map(([c,u])=>[O(c+h[0],r),O(u+h[1],r)])},r)})(e,t,n,i,s);case"polygon":return((a,o,l,r,d)=>{const h=ze([a[0]-l[0],a[1]-l[1]],d),{borders:c}=J(o,r);return it({...o,points:o.points.map(([u,m])=>r.gridGap?[u+O(c.x+h[0],r)-c.x,m+O(c.y+h[1],r)-c.y]:[O(u+a[0]-l[0],r),O(m+a[1]-l[1],r)])},r)})(e,t,n,i,s);case"curve":return((a,o,l,r,d)=>{const{borders:h}=J(o,r),c=ze([a[0]-l[0],a[1]-l[1]],d);return st({...o,points:o.points.map(([u,m])=>r.gridGap?[u+O(h.x+c[0],r)-h.x,m+O(h.y+c[1],r)-h.y]:[O(u+c[0],r),O(m+c[1],r)])},r)})(e,t,n,i,s);case"brush":return((a,o,l,r,d)=>{const{borders:h}=J(o,r),c=ze([a[0]-l[0],a[1]-l[1]],d),u=r.gridGap?O(h.x+c[0],r)-h.x:c[0],m=r.gridGap?O(h.y+c[1],r)-h.y:c[1];return Ke({...o,points:o.points.map(v=>v.map(([b,k])=>[b+u,k+m]))},r)})(e,t,n,i,s);default:return t}},at=(e,t)=>{switch(e.type){case"rect":case"square":return ls(e,t);case"ellipse":return Ss(e,t);case"circle":return ps(e,t);case"picture":return bs(e,t);case"text":return Cs(e,t);case"line":return xs(e,t);case"polygon":return gs(e,t);case"curve":return vs(e,t);case"brush":return is(e,t);default:return e}},wi=({ctx:e,shape:t,settings:n,selectionWidth:i,selectionColor:s,hoverMode:a,withAnchors:o=!0})=>{const{center:l}=J(t,n);switch(pt(e,n,t.rotation,l),t.type){case"rect":case"square":case"circle":case"ellipse":case"picture":case"text":case"brush":((r,d,h,c,u,m)=>{if(d.selection&&(Ce(r,{fillColor:"transparent",strokeColor:h,lineWidth:c/u.canvasSize.scaleRatio}),d.selection.shapePath?r.stroke(d.selection.shapePath):r.stroke(d.selection.border),m&&!d.locked)){d.selection.shapePath&&r.stroke(d.selection.border),d.selection.line&&r.stroke(d.selection.line),Ce(r,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/u.canvasSize.scaleRatio,shadowColor:h,shadowBlur:0});for(const v of d.selection.anchors)r.fill(v),r.stroke(v)}})(e,t,s,i,n,o);break;case"group":((r,d,h,c,u,m)=>{if(d.selection){if(Ce(r,{fillColor:"transparent",strokeColor:h,lineWidth:c/u.canvasSize.scaleRatio}),m&&!d.locked){r.stroke(d.selection.border),d.selection.line&&r.stroke(d.selection.line),Ce(r,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/u.canvasSize.scaleRatio});for(const v of d.selection.anchors)r.fill(v),r.stroke(v)}d.shapes.forEach(v=>{r.restore(),Ce(r,{fillColor:"transparent",strokeColor:h,lineWidth:c/u.canvasSize.scaleRatio});const{center:b}=J(v,u);pt(r,u,v.rotation,b),v.selection?.shapePath&&r.stroke(v.selection.shapePath)})}})(e,t,s,i,n,o);break;case"polygon":case"line":case"curve":(({ctx:r,shape:d,withAnchors:h,selectionWidth:c,selectionColor:u,hoverMode:m,settings:v})=>{if(d.selection&&(Ce(r,{fillColor:"transparent",strokeColor:u,lineWidth:c/v.canvasSize.scaleRatio}),d.selection.shapePath&&r.stroke(d.selection.shapePath),h&&!d.locked)){Ce(r,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/v.canvasSize.scaleRatio,shadowColor:u,shadowBlur:0});for(let b=0;b<d.selection.anchors.length;b++){const k=d.selection.anchors[b];m.mode==="resize"&&m.anchor===b?(r.shadowBlur=10,r.fill(k),r.shadowBlur=0):r.fill(k),r.stroke(k)}}})({ctx:e,shape:t,withAnchors:o,selectionWidth:i,selectionColor:s,hoverMode:a,settings:n})}e.restore()},Ls=({ctx:e,selectionFrame:t,settings:n})=>{pt(e,n),((i,s,a)=>{Ce(i,{fillColor:"rgba(170,170,170, 0.1)",strokeColor:"rgb(170,170,170)",lineWidth:1/a.canvasSize.scaleRatio}),i.fillRect(s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1]),i.strokeRect(s[0][0],s[0][1],s[1][0]-s[0][0],s[1][1]-s[0][1])})(e,t.frame,n),e.restore()},tn=e=>e.filter(t=>t!=null),Ci=e=>{const t=new DOMParser().parseFromString(e,"text/xml").getElementsByTagName("svg")[0];if(!t)return"";const n=t.getAttribute("width"),i=t.getAttribute("height");let s;if(n||i)s=e;else{const o=t.getAttribute("viewBox")??"0 0 300 300",[,,l,r]=o.split(" ");t.setAttribute("width",l??"300"),t.setAttribute("height",r??"300"),s=new XMLSerializer().serializeToString(t)}const a=new Blob([s],{type:"image/svg+xml"});return URL.createObjectURL(a)},Mi=e=>(e instanceof File?e.name:e).includes(".svg"),ki=e=>Mi(e)?fetch(e).then(t=>t.text()).then(t=>Ci(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),Pi=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},Vs=e=>e.src.includes("<svg")?e.src:(t=>{const n=document.createElement("canvas");n.width=t.width,n.height=t.height;const i=n.getContext("2d");return i?(i.drawImage(t,0,0),n.toDataURL("image/png")):""})(e.img),nn=({shapes:e,settings:t})=>{const n=document.createElement("canvas"),i=n.getContext("2d");if(!i)throw new Error("No context found for canvas");const{realHeight:s,realWidth:a}=t.canvasSize;n.width=a,n.height=s,i.clearRect(0,0,a,s),Yn(i);for(let o=e.length-1;o>=0;o--)bi(i,e[o],t);return n.toDataURL("image/png")},ji=({shapes:e,settings:t,view:n})=>{if(n==="fitToShapes"&&!e.length)throw new Error("No image found to export");if(n==="fitToShapes"){const s=e.map(h=>{const c=J(h,t).borders,u=(h.style?.lineWidth??0)/2;return{minX:c.x-u,minY:c.y-u,maxX:c.x+c.width+u,maxY:c.y+c.height+u}}),a=Math.min(...s.map(h=>h.minX)),o=Math.max(...s.map(h=>h.maxX)),l=Math.min(...s.map(h=>h.minY)),r=Math.max(...s.map(h=>h.maxY)),d={...t,canvasOffset:[-a,-l],canvasZoom:1,canvasSize:{realWidth:o-a,realHeight:r-l,width:o-a,height:r-l,scaleRatio:1,scaleRatioWithNoZoom:1}};return nn({shapes:e,settings:d})}if(n==="defaultView"){const s={...t,canvasOffset:[0,0],canvasZoom:1,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:1,scaleRatioWithNoZoom:1}};return nn({shapes:e,settings:s})}const i={...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}};return nn({shapes:e,settings:i})},Zs=(e,t,n)=>{return s=sn(e,t,n),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(s))}`;var s},Hs=e=>{const t=["img","id","selection","path","arrows","tempPoint"];return e.map(n=>n.type!=="picture"||n.src.startsWith("http")?Ft(t,n):Ft(t,{...n,src:Vs(n)}))},sn=(e,t,n)=>({shapes:Hs(e),config:{width:t,height:n}}),Li=(e,t)=>at({...e,id:he(`${e.type}_`)},t),Ts=(e,t,n,i)=>{const s=f.useRef([]),a=f.useRef({dataChanged:[]}),[o,l]=f.useState(void 0),[r,d]=f.useState(void 0),[h,c]=f.useState(void 0),[u,m]=f.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),v=u.cursor>0,b=u.cursor<u.states.length-1,k=s.current.length>0,j=f.useCallback(()=>{m(g=>$n(g.states[g.cursor]?.shapes,s.current)?g:{states:[...g.states.slice(0,g.cursor+1),{shapes:s.current,selectedShape:r,source:"user"}],cursor:g.cursor+1})},[r]),C=f.useCallback(g=>{s.current=[...g,...s.current]},[]),S=f.useCallback((g,w,x,L)=>{if(g.target&&"className"in g.target&&![Wn,In].includes(g.target.className)||!L)return void c(void 0);const P=s.current.find(R=>!$(r)?.map(Z=>Z.id).includes(R.id)&&!!hi(w,R,x,e));c(P)},[e,r]),y=f.useCallback(async(g,w=300,x=300)=>{const L=await ws(g,w,x,e);return C([L]),j(),L},[C,j,e]),Q=f.useCallback((g,w=!1)=>{s.current=s.current.map(x=>g.find(L=>L.id===x.id)??x),d(x=>x&&fe($(x).map(L=>g.find(P=>P.id===L.id)??L),e)),w&&j()},[j,e]),E=f.useCallback(g=>{const w=g.map(x=>Ft(["chosen"],x));s.current=w,j()},[j]),H=f.useCallback(g=>{const w=new Set(g.map(x=>x.id));d(x=>{const L=$(x).map(P=>P.id);return L&&w.size&&L.find(P=>w.has(P))?void 0:x}),s.current=s.current.filter(x=>!w?.has(x.id)),j()},[j]),z=f.useCallback(g=>{m(w=>{const x=g(w);return s.current=w.states[x]?.shapes??[],d(w.states[x]?.selectedShape),ve("cursor",x,w)})},[]),T=f.useCallback(()=>{z(g=>Math.max(0,g.cursor-1))},[z]),V=f.useCallback(()=>{z(g=>Math.min(g.states.length-1,g.cursor+1))},[z]),W=f.useCallback((g,w)=>{d(void 0),s.current=g,m(x=>w.clearHistory?{states:[{shapes:g,selectedShape:void 0,source:w.source}],cursor:0}:{states:[...x.states.slice(0,x.cursor+1),{shapes:g,selectedShape:void 0,source:w.source}],cursor:x.cursor+1})},[]),N=f.useCallback((g,w)=>{const x=s.current,L=x.findIndex(F=>F.id===g),P=x.findIndex(F=>F.id===w);var R,Z,U;E((R=x,U=P,(Z=L)<0||U<0||Z>R.length-1||U>R.length-1?R:Z<U?[...R.slice(0,Z),...R.slice(Z+1,U+1),R[Z],...R.slice(U+1,R.length)]:[...R.slice(0,U),R[Z],...R.slice(U,Z),...R.slice(Z+1,R.length)]))},[E]),A=f.useCallback(g=>{const w=s.current,x=new Set(g.map(P=>P.id)),L=w.map(P=>x.has(P.id)?ve("visible",P.visible===!1,P):P);d(oi(P=>ve("visible",P.visible===!1,P),e)),E(L)},[E,e]),I=f.useCallback(g=>{const w=s.current,x=new Set(g.map(P=>P.id)),L=w.map(P=>x.has(P.id)?ve("locked",!P.locked,P):P);d(oi(P=>ve("locked",!P.locked,P),e)),E(L)},[E,e]),X=f.useCallback((g,w)=>{a.current.hasOwnProperty(g)&&(a.current[g]=[...a.current[g],w])},[]),B=f.useCallback((g,w)=>{if(a.current.hasOwnProperty(g))if(w){const x=a.current[g].indexOf(w);a.current[g]=[...a.current[g].slice(0,x),...a.current[g].slice(x+1)]}else a.current[g]=[]},[]);f.useEffect(()=>{const g=u.states[u.cursor],w=sn(g.shapes,t,n);for(const x of a.current.dataChanged)x(w,g.source)},[t,n,u]),f.useEffect(()=>{s.current=s.current.map(g=>at(g,e)),d(g=>g===void 0?void 0:fe($(g).map(w=>at(w,e)),e))},[e]);const M=f.useCallback((g,w)=>{l(x=>{const L=[x?.frame[0]??[w[0],w[1]],[w[0],w[1]]],P=s.current.filter(Z=>((U,F,oe,D)=>{const{selectionPadding:te}=D,{center:Y,borders:ae}=J(F,D),G=ke(oe[0],F.rotation,Y),ne=ke(oe[1],F.rotation,Y),ee=Math.round(Math.min(G[0],ne[0])-te/2),Qe=Math.round(Math.max(G[0],ne[0])+te),K=Math.round(Math.min(G[1],ne[1])-te/2),le={x:ee,y:K,width:Qe-ee,height:Math.round(Math.max(G[1],ne[1])+te)-K},Le=Yt(ae,le);if(!Le)return!1;if(ae.width<=1||ae.height<=1||!("path"in F)||!F.path)return!0;if(U.lineWidth=(F.style?.lineWidth??0)+10,F.type==="brush"){const pe=F.points.flat(),Ae=Math.min(...pe.map(xe=>xe[0])),Be=Math.min(...pe.map(xe=>xe[1]));for(const xe of F.points){if(xe.length<1)break;if(xe.length<2){const we=Me(xe[0],Ae,Be,F.scaleX,F.scaleY);if(Xn(Le,{x:we[0],y:we[1],radius:(F.style?.lineWidth??1)/2}))return!0}for(let we=0;we<xe.length-1;we++){const Ee=Me(xe[we],Ae,Be,F.scaleX,F.scaleY),Re=Me(xe[we+1],Ae,Be,F.scaleX,F.scaleY),ie=Yt({x:Math.min(Ee[0],Re[0]),y:Math.min(Ee[1],Re[1]),width:Math.abs(Ee[0]-Re[0]),height:Math.abs(Ee[1]-Re[1])},le);if(ie){const $e=new Path2D;if($e.moveTo(...Ee),$e.lineTo(...Re),ui({ctx:U,path:$e,rect:ie,offset:10,checkFill:!1}))return!0}}}return!1}const ue=!(!F.style?.fillColor||F.style?.fillColor==="transparent");return ui({ctx:U,path:F.path,rect:Le,offset:10,checkFill:ue})})(g,Z,L,e)),R=fe(P,e);return d(i?fe(ri(x?.oldSelection,P),e):R),{oldSelection:x?.oldSelection,frame:L}})},[e,i]);return{registerEvent:X,unregisterEvent:B,shapesRef:s,selectedShape:r,hoveredShape:h,selectionFrame:o,setSelectionFrame:l,refreshSelectedShapes:M,addShapes:C,addPictureShape:y,moveShapes:N,saveShapes:j,setSelectedShape:d,refreshHoveredShape:S,toggleShapeVisibility:A,toggleShapeLock:I,removeShape:H,updateShape:Q,backwardShape:T,forwardShape:V,clearShapes:W,canGoBackward:v,canGoForward:b,canClear:k}},Vi=e=>{const t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];var i,s;return{diff:_n(t,n),center:(s=n,[((i=t)[0]+s[0])/2,(i[1]+s[1])/2])}},zs=({canvasElt:e,canvasTransformation:t,canvasSize:n,size:i,setCanvasTransformation:s})=>{const a=f.useRef([]),[o,l]=f.useState(a.current.length>0),r=f.useRef(null),d=f.useRef(t);d.current=t;const h=f.useCallback(({startDiff:c,startZoom:u,startCenter:m,startOffset:v,currentDiff:b,currentCenter:k,isMoving:j,isZooming:C})=>{if(!e||!b||!c)return;const S=(({canvasBoundingRect:y,canvasSize:Q,size:E,startDiff:H,startZoom:z,startCenter:T,startOffset:V,currentDiff:W,currentCenter:N,isMoving:A,isZooming:I})=>{const X=I?je(W/H*z,ye[0],ye[ye.length-1]):z,B=A?[V[0]+(N[0]-T[0])*(Q.width/y.width)/Q.scaleRatio/z,V[1]+(N[1]-T[1])*(Q.height/y.height)/Q.scaleRatio/z]:[V[0],V[1]],M=[(N[0]-y.left)/Q.scaleRatio,(N[1]-y.top)/Q.scaleRatio];return Gt({size:E,canvasSize:Q,currentOffset:B,currentZoom:z,zoom:X,centerPoint:M})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:n,size:i,startDiff:c,startZoom:u,startCenter:m,startOffset:v,currentDiff:b,currentCenter:k,isMoving:j,isZooming:C});s(S)},[e,n,i,s]);f.useEffect(()=>{if(!e)return;const c=u=>{if(a.current=[...a.current,u],l(a.current.length>0),a.current.length===2){u.stopPropagation();const{diff:m,center:v}=Vi(a.current);r.current={startDiff:m,startCenter:v,startZoom:d.current.zoom,startOffset:d.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",c),()=>{e.removeEventListener("pointerdown",c)}},[e]),f.useEffect(()=>{if(!o)return;const c=m=>{const v=a.current.findIndex(b=>b.pointerId===m.pointerId);if(v>-1&&(a.current[v]=m),a.current.length===2&&r.current){const{diff:b,center:k}=Vi(a.current),j=r.current.isZooming||((S,y)=>Math.abs(S-y.startDiff)>30)(b,r.current),C=r.current.isMoving||j||((S,y)=>Math.abs(_n(S,y.startCenter))>10)(k,r.current);r.current={...r.current,isMoving:C,isZooming:j},h({...r.current,currentDiff:b,currentCenter:k})}},u=m=>{a.current=a.current.filter(v=>v.pointerId!==m.pointerId),l(a.current.length>0)};return document.addEventListener("pointermove",c),document.addEventListener("pointerup",u),document.addEventListener("pointerout",u),document.addEventListener("pointercancel",u),document.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",c),document.removeEventListener("pointerup",u),document.removeEventListener("pointerout",u),document.removeEventListener("pointercancel",u),document.removeEventListener("pointerleave",u)}},[o,h])},Zi={offset:[0,0],zoom:1},As=({canvasSize:e,size:t,zoomEnabled:n,canvasElt:i})=>{const[s,a]=f.useState(Zi),o=f.useRef(0),l=f.useCallback(h=>{a(({zoom:c})=>qt({zoom:c,size:t,canvasSize:e,newOffset:h}))},[e,t]),r=f.useCallback(h=>{a(({offset:c,zoom:u})=>(({size:m,canvasSize:v,currentOffset:b,currentZoom:k,action:j})=>{const C=j==="default"?ye[4]:j==="zoom"?ye[je(ye.length-1-ye.slice(0).reverse().findIndex(y=>y<=k)+1,0,ye.length-1)]:ye[je(ye.findIndex(y=>y>=k)-1,0,ye.length-1)],S=[v.realWidth/2,v.realHeight/2];return Gt({size:m,canvasSize:v,currentOffset:b,currentZoom:k,zoom:C,centerPoint:S})})({size:t,canvasSize:e,currentOffset:c,currentZoom:u,action:h}))},[e,t]);zs({canvasElt:i,canvasTransformation:s,canvasSize:e,size:t,setCanvasTransformation:a});const d=f.useCallback(()=>{a(Zi)},[]);return f.useEffect(()=>{if(!n||!i)return;const h=c=>{const u=c.ctrlKey,{deltaX:m,deltaY:v}=((C,S)=>{const y=Math.abs(C.deltaY)<50&&S<50,Q=C.ctrlKey,E=Un()&&y&&Q;switch(C.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:16*C.deltaX,deltaY:16*C.deltaY};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:C.deltaX*window.innerHeight,deltaY:C.deltaY*window.innerHeight};default:return E?{deltaX:5*C.deltaX,deltaY:5*C.deltaY}:{deltaX:C.deltaX,deltaY:C.deltaY}}})(c,c.timeStamp-o.current);if(o.current=c.timeStamp,u){c.preventDefault();const C=ci(c,i,e);return void a(({offset:S,zoom:y})=>(({size:Q,canvasSize:E,currentOffset:H,currentZoom:z,delta:T,centerPoint:V})=>{const W=je(z*(1-T/1e3),ye[0],ye[ye.length-1]);return Gt({size:Q,canvasSize:E,currentOffset:H,currentZoom:z,zoom:W,centerPoint:V})})({size:t,canvasSize:e,currentOffset:S,currentZoom:y,delta:v,centerPoint:C}))}const b=c.shiftKey,[k,j]=b?[v,m]:[m,v];a(({offset:C,zoom:S})=>{const y=[C[0]-k/S,C[1]-j/S],Q=qt({zoom:S,size:t,canvasSize:e,newOffset:y});return Q.offset[0]===C[0]&&Q.offset[1]===C[1]||c.preventDefault(),Q})};return i.addEventListener("wheel",h,{passive:!1}),()=>{i.removeEventListener("wheel",h)}},[i,t,e,n]),{setCanvasTransformation:a,setCanvasOffset:l,setCanvasZoom:r,resetZoom:d,canvasTransformation:s}},Hi=(e,t=!1)=>{const n=(s,a)=>{if(Array.isArray(s))return a},i=e.map(s=>{if(typeof s!="object")return null;switch(s.type){case"brush":return Pe(n,Mn,s);case"circle":return Pe(n,Zn,s);case"curve":return Pe(n,jn,s);case"ellipse":return Pe(n,Hn,s);case"line":return Pe(n,kn,s);case"polygon":return Pe(n,Pn,s);case"rect":return Pe(n,Ln,s);case"square":return Pe(n,Vn,s);case"text":return Pe(n,Tn,s)}return null});return tn(t?[...i,Dt]:i)},Es=({addShapes:e,drawCanvasRef:t,setActiveTool:n,refreshHoveredShape:i,shapes:s,selectionMode:a,activeTool:o,isInsideComponent:l,setCanvasOffset:r,selectedShape:d,canvasOffsetStartData:h,refreshSelectedShapes:c,setSelectedShape:u,setSelectionFrame:m,setCanvasOffsetStartData:v,updateSingleShape:b,saveShapes:k,setSelectionMode:j,setCanvasMoveAcceleration:C,settings:S,isShiftPressed:y,isAltPressed:Q,withFrameSelection:E})=>{const[H,z]=f.useState({mode:"default"}),{registerDoubleClickEvent:T,unRegisterDoubleClickEvent:V}=(()=>{const M=f.useRef(void 0),g=f.useRef(void 0),w=x=>{const L=Date.now();M.current&&L<M.current+300&&g.current?.(x),M.current=Date.now()};return{registerDoubleClickEvent:(x,L)=>{g.current=L,x.addEventListener("click",w),x.addEventListener("touchend",w)},unRegisterDoubleClickEvent:x=>{x.removeEventListener("click",w),x.removeEventListener("touchend",w)}}})(),W=f.useRef(null);W.current=M=>((g,w,x,L,P,R,Z,U,F,oe,D,te,Y,ae,G)=>{if(nt(g)&&g.touches.length>1)return;const ne=w.current?.getContext("2d");if(!ne)return;const ee=tt(g,w.current,D);if(L.mode==="selectionFrame"){oe(ne,ee,D);const K=ci(g,w.current,D.canvasSize);return void G([Math.ceil(je(K[0]*D.canvasZoom<50?K[0]*D.canvasZoom-50:K[0]*D.canvasZoom>D.canvasSize.width/D.canvasSize.scaleRatioWithNoZoom-50?K[0]*D.canvasZoom-(D.canvasSize.width/D.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/D.canvasZoom),Math.ceil(je(K[1]*D.canvasZoom<50?K[1]*D.canvasZoom-50:K[1]*D.canvasZoom>D.canvasSize.height/D.canvasSize.scaleRatioWithNoZoom-50?K[1]*D.canvasZoom-(D.canvasSize.height/D.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/D.canvasZoom)])}if(P!==void 0)return void F([ee[0]+D.canvasOffset[0]-P.start[0],ee[1]+D.canvasOffset[1]-P.start[1]]);if(L.mode==="preview"){const K=$(x)[0];if(K?.type==="curve"){const le=mi(K,ee,D,!0);return void ae(fe([le],D))}if(K?.type==="polygon"){const le=vi(K,ee,D,!0);return void ae(fe([le],D))}}const Qe=ct(ee,D);if(nt(g)||Z(g,ne,ee,Qe),x===void 0||x.locked)R({mode:"default",outOfView:!Qe});else if(L.mode==="default"||L.mode==="textedition"){if(!Qe)return void R({mode:"default"});R(lt(ne,x,ee,D,!0)||{mode:"default"})}else{const K=w.current?.getContext("2d");if(!K)return;const le=as(K,x,ee,L,D,te,Y);U($(le))}})(M,t,d,a,h,z,i,b,r,c,S,y,Q,u,C),f.useEffect(()=>{if(l){const M=g=>W.current?.(g);return document.addEventListener("mousemove",M),document.addEventListener("touchmove",M),()=>{document.removeEventListener("mousemove",M),document.removeEventListener("touchmove",M)}}},[l]);const{isBrushShapeDoneOnMouseUp:N}=S,A=f.useRef(null);A.current=M=>{if(nt(M)&&M.touches.length>1)return;const g=t.current?.getContext("2d");if(!g)return;if("button"in M&&M.button===2)return u(void 0),n(Te),j({mode:"default"}),void m(void 0);if(h)return void v(void 0);if(a.mode==="textedition"||a.mode==="preview")return;const w=tt(M,t.current,S);if(a.mode==="translate"&&Date.now()-a.dateStart<=500&&w[0]===a.cursorStartPosition[0]&&w[1]===a.cursorStartPosition[1]){if(!(M.ctrlKey||M.shiftKey||M.metaKey)){const{shape:x}=ai(g,s,w,S,void 0,nt(M),E,!1);u(x)}return j({mode:"default"}),m(void 0),void k()}a.mode!=="default"&&(a.mode==="brush"&&N&&u(void 0),j({mode:"default"}),m(void 0),k())},f.useEffect(()=>{if(l){const M=g=>A.current?.(g);return document.addEventListener("mouseup",M),document.addEventListener("touchend",M),()=>{document.removeEventListener("mouseup",M),document.removeEventListener("touchend",M)}}},[l]);const I=!S.features.edition&&S.features.zoom,X=!S.features.edition&&!S.features.zoom,B=f.useRef(null);return B.current=(M,g)=>{if(M.preventDefault(),nt(M)&&M.touches.length>1)return;const w=g?.getContext("2d");if(!w)return;const x=tt(M,t.current,S),L="button"in M&&M.button===1;if(!("button"in M&&M.button===2)){if(L||o.type==="move")v({start:x,originalOffset:S.canvasOffset});else if(!I){if(!ct(x,S))return u(void 0),void j({mode:"default"});if(o.type==="selection"){const P=M.ctrlKey||M.shiftKey||M.metaKey,{shape:R,mode:Z}=ai(w,s,x,S,d,nt(M),E,P);u(R),j(Z),Z.mode==="selectionFrame"&&m({oldSelection:R,frame:[[x[0],x[1]],[x[0],x[1]]]})}else if(Nn.some(P=>P===o.type)){const P=$(d)[0],R=t.current?.getContext("2d");if(!R)return;if(o.type==="brush"){if(P?.type==="brush"){const Z=((U,F,oe)=>{const D={...U,points:ve(U.points.length,[[Math.round(F[0]),Math.round(F[1])]],U.points)};return Ke(D,oe)})(P,x,S);b([Z])}else{const Z=Qi(R,o,x,S);if(!Z)return;e([Z]),u(fe([Z],S))}j({mode:"brush"})}else if(a.mode!=="preview"||P?.type!=="polygon"&&P?.type!=="curve"){if(o.type!=="picture"){const Z=Qi(R,o,x,S);if(!Z)return;e([Z]);const U=fe([Z],S);u(U),Z.type==="polygon"||Z.type==="curve"?j({mode:"preview"}):(n(Te),j({mode:"resize",cursorStartPosition:[x[0]+S.selectionPadding,x[1]+S.selectionPadding],originalShape:U,anchor:Z.type==="line"?0:[1,1]}))}}else{const Z=P.type==="polygon"?vi(P,x,S):mi(P,x,S);u(fe([Z],S)),b([Z],!0)}}}}},f.useEffect(()=>{if(X)return;const M=t.current;if(!M)return;const g=w=>B.current?.(w,M);return M.addEventListener("mousedown",g,{passive:!1}),M.addEventListener("touchstart",g,{passive:!1}),()=>{M.removeEventListener("mousedown",g),M.removeEventListener("touchstart",g)}},[X,t]),f.useEffect(()=>{const M=t.current,g=t.current?.getContext("2d");if(!(!M||!g))return l?(T(M,w=>{if(o.type==="selection"){if($(d).length!==1)return;const x=$(d)[0];if(x?.type==="text"){const L=tt(w,t.current,S);return ct(L,S)?void(lt(g,d,L,S)&&j({mode:"textedition",defaultValue:x.value})):void 0}if(x?.type==="polygon"){const L=tt(w,t.current,S);if(!ct(L,S))return;const P=di(g,x,L,S);return void(P&&b([fs(x,P.lineIndex,L,S)]))}if(x?.type==="curve"){const L=tt(w,t.current,S);if(!ct(L,S))return;const P=((R,Z,U,F,oe=50)=>{if(Z.locked||Z.points.length<2)return!1;if(Z.points.length<3)return di(R,Z,U,F,oe);const{center:D}=J(Z,F),te=ke(U,Z.rotation,D);R.lineWidth=(Z.style?.lineWidth??0)+oe/F.canvasZoom;const Y=Kn(Z,Z.points),ae=new Path2D;ae.moveTo(...Y[0]);for(let G=1;G<Y.length-2;G++){const ne=Y[G-1],ee=Y[G],Qe=Y[G+1],K=Y[G+2];if(Jn(ae,ne,ee,Qe,K),R.isPointInStroke(ae,te[0],te[1]))return{lineIndex:G-1}}return!1})(g,x,L,S);return void(P&&b([ys(x,P.lineIndex,L,S)]))}}}),()=>{V(M)}):void 0},[b,T,V,l,t,o,d,j,S]),{hoverMode:H}},Ti=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>Ti(t)).join(""):e.nodeValue??"",Rs=({disabled:e=!1,shape:t,defaultValue:n,updateValue:i,saveShapes:s,settings:a})=>{const o=f.useRef(null),l=f.useRef(s);f.useEffect(()=>{if(!o.current)return;const d=o.current,h=c=>{c.preventDefault();const u=c.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,u)};d.addEventListener("paste",h),d.innerText="";for(const c of n){const u=document.createElement("div");c===""?u.innerHTML="<br/>":u.innerText=c,d.appendChild(u)}return d.focus(),()=>{d.removeEventListener("paste",h)}},[n]),f.useEffect(()=>{const d=l.current;return()=>{d()}},[]);const r=f.useMemo(()=>{const{borders:d,center:h}=J(t,a);return me({point:[d.x,d.y],rotation:-t.rotation,origin:h})},[t,a]);return p.jsx("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=>{const h=Array.from(d.target.childNodes).map(c=>Ti(c));i(h)},style:{"--react-paint-editor-toolbox-edittextbox-transform":`translate3D(${(r[0]+a.canvasOffset[0])*a.canvasSize.scaleRatio}px, ${(r[1]+a.canvasOffset[1])*a.canvasSize.scaleRatio}px, 0) rotate(${$t(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??rt}})},Ds=(e,t,n,i,s)=>{Yn(e),((a,o)=>{const{canvasZoom:l,size:r,canvasSize:{width:d,height:h}}=o;if(r!=="fixed"||l>=1)return;a.fillStyle="#f5f5f5",a.fillRect(0,0,d,h);const c=pi(o);a.clearRect(c.x,c.y,c.width,c.height),gi(a,o)})(e,n),((a,o)=>{const{canvasSize:{width:l,height:r},gridGap:d,canvasOffset:h,canvasSize:{scaleRatio:c}}=o;if(!d)return;a.strokeStyle="rgb(220,220,220)",a.lineWidth=1,a.save(),a.scale(c,c),a.beginPath();const u=h[0]%d,m=h[1]%d,v=Math.ceil(l/c/d)+2,b=Math.ceil(r/c/d)+2;for(let k=-5;k<v;k++)a.moveTo(u+(k+1)*d,m-d),a.lineTo(u+(k+1)*d,m+r/c+d);for(let k=-5;k<b;k++)a.moveTo(u-d,m+(k+1)*d),a.lineTo(u+l/c+d,m+(k+1)*d);a.stroke(),a.restore()})(e,n);for(let a=i.length-1;a>=0;a--)t.mode==="textedition"&&i[a]===s||bi(e,$(s).find(o=>o.id===i[a].id)??i[a],n)},Ns=f.forwardRef(({canGrow:e,shapes:t,addShapes:n,updateSingleShape:i,selectedShape:s,setSelectedShape:a,setSelectionFrame:o,hoveredShape:l,selectionFrame:r,refreshHoveredShape:d,refreshSelectedShapes:h,saveShapes:c,activeTool:u,setActiveTool:m,canvasOffsetStartData:v,setCanvasOffsetStartData:b,setCanvasOffset:k,setCanvasMoveAcceleration:j,isInsideComponent:C,selectionMode:S,setSelectionMode:y,selectionWidth:Q,selectionColor:E,settings:H,isEditMode:z,isShiftPressed:T,isAltPressed:V,withFrameSelection:W,withSkeleton:N},A)=>{const I=f.useRef(null),X=f.useRef(null),B=H.canvasSize,M=z;f.useImperativeHandle(A,()=>I.current);const{hoverMode:g}=Es({addShapes:n,drawCanvasRef:I,setActiveTool:m,shapes:t,selectionMode:S,activeTool:u,isInsideComponent:C,setCanvasOffset:k,selectedShape:s,canvasOffsetStartData:v,setCanvasOffsetStartData:b,setSelectedShape:a,setSelectionFrame:o,refreshHoveredShape:d,refreshSelectedShapes:h,updateSingleShape:i,saveShapes:c,setSelectionMode:y,setCanvasMoveAcceleration:j,isShiftPressed:T,isAltPressed:V,withFrameSelection:W,settings:H}),w=f.useCallback(L=>{const P=$(s)[0];if(P?.type!=="text")return;const R=I.current?.getContext("2d");if(!R)return;const Z=at(Ms(R,P,L,H),H);i([Z])},[i,s,H]),x=L=>{if(z)return L.preventDefault(),L.stopPropagation(),!1};return f.useEffect(()=>{const L=I.current?.getContext("2d");L&&window.requestAnimationFrame(()=>Ds(L,S,H,t,s))},[t,S,s,H]),f.useEffect(()=>{const L=X.current?.getContext("2d");L&&window.requestAnimationFrame(()=>((P,R,Z,U,F,oe,D,te,Y,ae,G)=>{P.reset(),gi(P,Z),G&&te&&!$(D).find(ne=>ne.id===te.id)&&U.type==="selection"&&R.mode==="default"&&wi({ctx:P,shape:te,settings:Z,selectionWidth:F,selectionColor:oe,hoverMode:Y,withAnchors:!1}),D&&U.type!=="brush"&&wi({ctx:P,shape:D,settings:Z,selectionWidth:F,selectionColor:oe,hoverMode:Y,withAnchors:R.mode!=="textedition"}),ae&&Ls({ctx:P,selectionFrame:ae,settings:Z})})(L,S,H,u,Q,E,s,l,g,r,N))},[l,g,r,S,s,u,H,Q,E,N]),p.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":v?"grabbing":g.outOfView?"default":g.mode==="resize"?"pointer":u.type!=="selection"&&u.type!=="move"?"crosshair":g.mode==="translate"?"move":g.mode==="rotate"||u.type==="move"?"grab":"default"},children:p.jsxs("div",{className:"react-paint-canvas-container","data-grow":e,children:[p.jsx("canvas",{className:Wn,ref:I,"data-grow":e,width:B.width,height:B.height,onContextMenu:x}),M&&p.jsx("canvas",{className:In,ref:X,width:B.width,height:B.height,"data-grow":e,onContextMenu:x}),z&&S.mode==="textedition"&&$(s)[0]?.type==="text"&&p.jsx(Rs,{disabled:!H.features.edition,shape:$(s)[0],defaultValue:S.defaultValue,updateValue:w,saveShapes:c,settings:H})]})})}),zi="ArrowUp",Ai="ArrowDown",Ei="ArrowLeft",Ri="ArrowRight",Ws="Delete",Is="Backspace",Fs="Escape",Di="Shift",Ni="Alt",Wi="Option",Os="z",Bs="Z",$s="y",Us="Y",Ii="copy",Fi="paste",Ys=({isInsideComponent:e,selectedShape:t,isEditingText:n,settings:i,setSelectedShape:s,setActiveTool:a,setSelectionMode:o,setSelectionFrame:l,removeShape:r,pasteShapes:d,updateShapes:h,backwardShape:c,forwardShape:u,setShiftPressed:m,setAltPressed:v})=>{const[b,k]=f.useState(void 0);return f.useEffect(()=>{const j=Q=>{t&&(n||(Q.preventDefault(),k({...t})))},C=Q=>{b&&(n||(Q.preventDefault(),d(((E,H)=>$(E).map(z=>({...en([20,20],z,[0,0],H,!1),id:he(`${z.type}_`)})))(b,i))))},S=Q=>{switch(Q.key){case Di:m(!1);break;case Ni:case Wi:v(!1)}},y=Q=>{if(Q.metaKey||Q.ctrlKey){if(Q.key===Bs||Q.key===Os)return Q.preventDefault(),Q.stopPropagation(),void(Q.shiftKey?u():c());if(!Un()&&(Q.key===Us||Q.key===$s))return Q.preventDefault(),Q.stopPropagation(),void u()}if(Q.key===Di)return Q.preventDefault(),Q.stopPropagation(),void m(!0);if(Q.key===Ni||Q.key===Wi)return Q.preventDefault(),Q.stopPropagation(),void v(!0);if(!t)return;if(Q.key===Fs)return s(void 0),a(Te),o({mode:"default"}),void l(void 0);if(n)return;const E={[Ei]:[i.gridGap?-i.gridGap:-1,0],[Ri]:[i.gridGap?i.gridGap:1,0],[Ai]:[0,i.gridGap?i.gridGap:1],[zi]:[0,i.gridGap?-i.gridGap:-1]};switch(Q.key){case Ei:case Ri:case Ai:case zi:Q.preventDefault(),Q.stopPropagation(),h(((H,z,T,V,W)=>$(z).map(N=>en(H,N,T,V,W)))(E[Q.key],t,[0,0],i,!1));break;case Ws:case Is:Q.preventDefault(),Q.stopPropagation(),r($(t))}};if(e)return document.addEventListener("keydown",y),document.addEventListener("keyup",S),document.addEventListener(Ii,j),document.addEventListener(Fi,C),()=>{document.removeEventListener("keydown",y),document.removeEventListener("keyup",S),document.removeEventListener(Ii,j),document.removeEventListener(Fi,C)}},[e,b,n,t,i,h,r,s,d,c,u,m,v,a,o,l]),{}},Xs=({isLoading:e=!1})=>{const[t,n]=f.useState("hidden");return f.useEffect(()=>{if(!e){n("fadeOut");const i=setTimeout(()=>n("hidden"),300);return()=>{clearTimeout(i)}}n("visible")},[e]),t==="hidden"?null:p.jsx("div",{className:"react-paint-editor-loading","data-loading":t,style:{"--react-paint-editor-loading-zindex":es,"--react-paint-editor-loading-transition-duration":"300ms"},children:p.jsxs("div",{className:"react-paint-editor-loader",children:[p.jsx("div",{}),p.jsx("div",{}),p.jsx("div",{}),p.jsx("div",{})]})})},qs="infos",Gs=4e3,_s=({type:e,text:t,duration:n})=>{const[i,s]=f.useState(!1);return f.useEffect(()=>{const a=setTimeout(()=>{s(!0)},100),o=setTimeout(()=>{s(!1)},n-500-100);return()=>{clearTimeout(a),clearTimeout(o)}},[n]),p.jsx("div",{className:"react-paint-editor-snackbar","data-is-shown":+i,"data-type":e,style:{"--react-paint-editor-panel-transition-duration":"500ms"},children:t})},Ks=({snackbarList:e})=>p.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":ts},children:e.map(t=>p.jsx(_s,{...t},t.id))}),q=f.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color"){const{hidden:h=!1,disabled:c=!1,selected:u=!1,icon:m,children:v,className:b="",title:k,onClick:j,...C}=e;return p.jsxs("label",{className:`react-paint-editor-button ${b}`,title:k,onClick:j,"data-disabled":+c,"data-selected":+u,"data-hidden":+h,children:[p.jsx("input",{ref:t,disabled:c,...C}),p.jsxs("span",{className:"react-paint-editor-button-content",children:[v&&p.jsx("span",{className:"react-paint-editor-button-children",children:v}),m&&p.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:m}})]})]})}const{hidden:n=!1,disabled:i=!1,selected:s=!1,icon:a,children:o,type:l="button",className:r="",...d}=e;return p.jsx("button",{className:`react-paint-editor-button ${r}`,ref:t,disabled:i,"data-disabled":+i,"data-selected":+s,"data-hidden":+n,type:l,...d,children:p.jsxs("span",{className:"react-paint-editor-button-content",children:[o&&p.jsx("span",{className:"react-paint-editor-button-children",children:o}),a&&p.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:a}})]})})}),Oe=({children:e,title:t="",className:n="",position:i="bottom",fitContainer:s=!1,alignment:a="center",style:o,...l})=>p.jsxs("div",{className:`react-paint-editor-panel ${n}`,"data-fitcontainer":s,"data-position":i,"data-alignment":a,style:{...o,"--react-paint-editor-panel-zindex":wn},...l,children:[t&&p.jsx("h3",{className:"react-paint-editor-panel-title",children:t}),e]}),Js=e=>{switch(e){case"brush":return dn;case"line":return gn;case"polygon":return Et;case"curve":return fn;case"rect":case"square":return zt;case"circle":case"ellipse":return At;case"text":return pn;case"picture":return Rt;case"group":return'<svg><path d="M3.333 17.5V16.667H7.5V17.5ZM3.333 14.167V13.333H9.167V14.167ZM3.333 10.833V10H10.833V10.833ZM3.333 7.5V6.667H12.5V7.5ZM3.333 4.167V3.333H13.333V4.167ZM3.333 0.833V0H16.667V0.833Z"/></svg>';case"triangle":return""}},ea=({disabled:e=!1,shape:t,selected:n,layoutDragging:i,toggleShapeVisibility:s,toggleShapeLock:a,setLayoutDragging:o,handleRemove:l,handleSelect:r,onMoveShapes:d})=>{const h=f.useRef(null),{isOver:c}=(({disabled:u=!1,ref:m,shape:v,layoutDragging:b,setLayoutDragging:k,handleSelect:j,onMoveShapes:C})=>{const[S,y]=f.useState(!1);return f.useEffect(()=>{b||y(!1)},[b]),f.useEffect(()=>{const Q=m.current;if(!Q)return;const E=()=>{k(void 0)},H=N=>(N.preventDefault&&N.preventDefault(),!1),z=N=>{j([v]),N.dataTransfer&&(N.dataTransfer.effectAllowed="move",N.dataTransfer.setData("draggableShapeId",v.id),k(v.id))},T=()=>{b!==v.id&&y(!0)},V=()=>{y(!1)},W=N=>(N.stopPropagation(),N.dataTransfer&&C(N.dataTransfer.getData("draggableShapeId"),v.id),!1);return u||(Q.addEventListener("dragstart",z),Q.addEventListener("dragend",E),Q.addEventListener("dragover",H),Q.addEventListener("dragenter",T),Q.addEventListener("dragleave",V),Q.addEventListener("drop",W)),()=>{u||(Q.removeEventListener("dragstart",z),Q.removeEventListener("dragend",E),Q.removeEventListener("dragover",H),Q.removeEventListener("dragenter",T),Q.removeEventListener("dragleave",V),Q.removeEventListener("drop",W))}},[u,m,v,k,j,C,b]),{isOver:S}})({disabled:e,ref:h,shape:t,layoutDragging:i,setLayoutDragging:o,handleSelect:r,onMoveShapes:d});return p.jsxs("div",{className:"react-paint-editor-layout","data-disabled":+e,draggable:!e,"data-is-dragging":+(i===t.id),"data-is-over":+c,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),r([t]))},"data-selected":+n,ref:h,tabIndex:-1,children:[p.jsx("span",{dangerouslySetInnerHTML:{__html:Js(t.type)}}),p.jsx("span",{children:t.id}),p.jsx("div",{className:"react-paint-editor-layouts-separator"}),p.jsx(q,{className:"react-paint-editor-layouts-visible-button",title:t.visible?"Hide":"Show","data-visible":t.visible!==!1,disabled:e,selected:n,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),s([t]))},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.jsx(q,{className:"react-paint-editor-layouts-locked-button",title:t.locked?"Locked":"Unlocked","data-locked":!!t.locked,disabled:e,selected:n,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),a([t]))},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.jsx(q,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),l([t]))},icon:hn})]})},ta=({gridFormat:e,setGridFormat:t,settings:n,shapes:i,removeShape:s,toggleShapeVisibility:a,toggleShapeLock:o,selectedShapes:l,moveShapes:r,selectShapes:d,isLayoutPanelShown:h})=>{const[c,u]=f.useState(void 0),m=!n.features.edition;return h?p.jsx(Oe,{alignment:"right",className:"react-paint-editor-layouts-panel",children:p.jsx("div",{className:"react-paint-editor-layouts-panel-content",children:p.jsxs("div",{className:"react-paint-editor-layouts-scrolling-content",children:[p.jsxs("div",{className:"react-paint-editor-layouts-row",children:[p.jsx("span",{className:"react-paint-editor-layouts-subtitle",children:"Grid"}),p.jsx(q,{icon:'<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>',className:"react-paint-editor-layouts-grid-button",selected:e==="none",disabled:m,onClick:()=>t("none")}),["small","medium","large"].map(v=>p.jsx(q,{className:"react-paint-editor-layouts-grid-button",selected:e===v,disabled:m,onClick:()=>t(v),children:v.charAt(0).toUpperCase()},v))]}),p.jsx("hr",{}),p.jsx("div",{className:"react-paint-editor-layouts",children:i.length===0?p.jsx("div",{className:"react-paint-editor-layouts-placeholder",children:"No layer yet"}):i.map(v=>p.jsx(ea,{shape:v,disabled:m,layoutDragging:c,setLayoutDragging:u,selected:$(l).some(b=>b.id===v.id)??!1,handleSelect:d,handleRemove:s,onMoveShapes:r,toggleShapeVisibility:a,toggleShapeLock:o},v.id))})]})})}):null},wt=({children:e,onClose:t,position:n="center",title:i,className:s=""})=>p.jsxs("div",{className:"react-paint-editor-modal","data-position":n,style:{"--react-paint-editor-modal-zindex":wn},role:"dialog","aria-modal":"true","aria-labelledby":i,children:[p.jsx("div",{className:"react-paint-editor-modal-mask",onClick:t}),p.jsx("div",{className:`react-paint-editor-modal-panel ${s}`,children:e})]}),Ct=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez une couleur",mode:i="fill",disabled:s=!1,values:a,field:o,value:l="",valueChanged:r})=>{const[d]=f.useState(he("settings_")),h=e===d;return a.length?p.jsxs(p.Fragment,{children:[p.jsx(q,{selected:h,title:n,disabled:s,onClick:()=>{t(c=>c===d?void 0:d)},icon:l==="transparent"?i==="fill"?Qn:Sn:void 0,children:l!=="transparent"&&p.jsx("div",{className:"react-paint-editor-colorfield-color","data-mode":i,style:{"--react-paint-editor-colorfield-color-value":l}})}),h&&p.jsx(Oe,{title:n,alignment:"left",children:p.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[a.map(c=>p.jsx(q,{title:c,selected:c===l,color:c,icon:c==="transparent"?i==="fill"?Qn:Sn:void 0,onClick:()=>{r(o,c)},children:c!=="transparent"&&p.jsx("div",{className:"react-paint-editor-colorfield-color",color:c,"data-mode":i,style:{"--react-paint-editor-colorfield-color-value":c}})},c)),p.jsx(q,{type:"color",title:"Custom color",selected:l!==""&&!a.includes(l),value:l,onChange:c=>{const u=+c.target.value;r(o,Number.isNaN(u)?c.target.value:u)},children:p.jsx("div",{className:"react-paint-editor-colorfield-customcolor",style:{"--react-paint-editor-colorfield-color-value":a.includes(l)?"var(--react-paint-editor-app-font-color)":l},children:p.jsx("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},na=({disabled:e=!1,selectedShape:t,removeShape:n})=>p.jsx(q,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{n($(t))},icon:hn}),Mt=({CustomOption:e,selectedSettings:t,setSelectedSettings:n,title:i="Choisissez l'option",disabled:s=!1,field:a,icon:o,values:l,defaultValue:r,valueChanged:d})=>{const[h]=f.useState(he("settings_")),c=t===h;return l.length?p.jsxs(p.Fragment,{children:[p.jsx(q,{selected:c,title:i,icon:o,disabled:s,onClick:()=>{n(u=>u===h?void 0:h)}}),c&&p.jsx(Oe,{title:i,alignment:"left",fitContainer:!0,children:p.jsx("div",{className:"react-paint-editor-selectfield-wrapper",children:l.map(u=>p.jsx(q,{title:`${u}`,onClick:()=>(m=>{d(a,m)})(u),selected:r===u,style:{"--react-paint-editor-button-padding":"16px"},children:p.jsx(e,{children:u})},u))})})]}):null},ia=({children:e})=>p.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),Oi=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:i,defaultValue:s,valueChanged:a})=>i.length?p.jsx(Mt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ia,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:n,field:"fontFamily",values:i,defaultValue:s,valueChanged:a}):null,sa=({disabled:e,toggleLayoutPanel:t})=>p.jsx(q,{title:"Toggle layers panel",disabled:e,onClick:t,icon:'<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>',className:"react-paint-editor-layout-button"}),aa=({children:e})=>p.jsxs("span",{className:"react-paint-editor-linearrow-option","data-type":e,children:[p.jsx("span",{className:"react-paint-editor-linearrow-left"}),p.jsx("span",{className:"react-paint-editor-linearrow-right"})]}),Bi=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:i,defaultValue:s,valueChanged:a})=>i.length?p.jsx(Mt,{selectedSettings:e,setSelectedSettings:t,CustomOption:aa,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:n,field:"lineArrow",values:i,defaultValue:s,valueChanged:a}):null,oa=({children:e})=>p.jsxs("span",{className:"react-paint-editor-linetype-option","data-type":e,children:[p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{}),p.jsx("span",{})]}),$i=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:i,defaultValue:s,valueChanged:a})=>i.length?p.jsx(Mt,{selectedSettings:e,setSelectedSettings:t,CustomOption:oa,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:n,field:"lineDash",values:i,defaultValue:s,valueChanged:a}):null,kt=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez l'intervalle",icon:i,disabled:s=!1,field:a,value:o,min:l=1,max:r=20,step:d=1,unity:h="",valueChanged:c})=>{const u=o===void 0,m=u?"N/A":`${Math.round(o)}${h}`,[v]=f.useState(he("settings_")),b=f.useRef(null);f.useEffect(()=>()=>{b.current&&clearTimeout(b.current)},[]);const k=e===v;return l===r?null:p.jsxs(p.Fragment,{children:[p.jsx(q,{selected:k,title:n,disabled:s,icon:i,onClick:()=>{t(j=>j===v?void 0:v)}}),k&&p.jsx(Oe,{title:n,alignment:"left",fitContainer:!0,children:p.jsx("div",{children:p.jsxs("label",{className:"react-paint-editor-rangefield",children:[p.jsx("input",{type:"range",min:l,max:r,step:d,value:o??(r+l)/2,"data-indeterminate":+u,onChange:j=>{const C=+j.target.value;c(a,Number.isNaN(C)?j.target.value:C,!1),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{c(a,Number.isNaN(C)?j.target.value:C,!0)},1e3)}}),p.jsx("span",{children:m})]})})})]})},ra=({children:e})=>p.jsx("span",{children:e===0?"Non":"Oui"}),la=[0,1],Ui=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,defaultValue:i,valueChanged:s})=>p.jsx(Mt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ra,title:"Fermer les points",icon:Et,disabled:n,field:"closedPoints",values:la,defaultValue:i,valueChanged:s}),ca=({disabled:e=!1,className:t,toggleZoomPanel:n})=>p.jsx(q,{title:"Toggle zoom panel",disabled:e,onClick:n,icon:xn,className:t?` ${t}`:""}),Pt=({setSelectedSettings:e,disabled:t=!1,field:n,icon:i,values:s,value:a=!1,valueChanged:o})=>{const[l]=f.useState(he("settings_"));return s.length!==2?null:p.jsx(q,{onClick:()=>{e(r=>r===l?void 0:l),o(n,!a)},selected:a,disabled:t,icon:i})},an=({activeTool:e,selectedShape:t,selectedShapeTool:n,disabled:i,selectedSettings:s,setSelectedSettings:a,handleShapeStyleChange:o,handleShapeFontFamilyChange:l})=>t?n&&p.jsxs(p.Fragment,{children:["strokeColor"in n.settings&&!n.settings.strokeColor.hidden&&p.jsx(Ct,{selectedSettings:s,setSelectedSettings:a,title:"Couleur du trait",mode:"stroke",disabled:i,field:"strokeColor",value:t.style?.strokeColor,valueChanged:o,values:n.settings.strokeColor.values}),"fillColor"in n.settings&&!n.settings.fillColor.hidden&&p.jsx(Ct,{selectedSettings:s,setSelectedSettings:a,title:"Couleur de fond",disabled:i,field:"fillColor",value:t.style?.fillColor,valueChanged:o,values:n.settings.fillColor.values}),"lineWidth"in n.settings&&!n.settings.lineWidth.hidden&&p.jsx(kt,{selectedSettings:s,setSelectedSettings:a,title:"Epaisseur du trait",icon:yn,disabled:i,field:"lineWidth",value:t.style?.lineWidth,valueChanged:o,unity:"px",min:n.settings.lineWidth.min,max:n.settings.lineWidth.max,step:n.settings.lineWidth.step}),"lineDash"in n.settings&&!n.settings.lineDash.hidden&&p.jsx($i,{selectedSettings:s,setSelectedSettings:a,disabled:i,defaultValue:t.style?.lineDash,valueChanged:o,values:n.settings.lineDash.values}),"lineArrow"in n.settings&&!n.settings.lineArrow.hidden&&p.jsx(Bi,{selectedSettings:s,setSelectedSettings:a,disabled:i,defaultValue:t.style?.lineArrow,valueChanged:o,values:n.settings.lineArrow.values}),"closedPoints"in n.settings&&!n.settings.closedPoints.hidden&&p.jsx(Ui,{selectedSettings:s,setSelectedSettings:a,disabled:i,valueChanged:o,defaultValue:t.style?.closedPoints}),"fontFamily"in n.settings&&!n.settings.fontFamily.hidden&&p.jsx(Oi,{selectedSettings:s,setSelectedSettings:a,disabled:i,valueChanged:l,values:n.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),"fontBold"in n.settings&&!n.settings.fontBold.hidden&&p.jsx(Pt,{setSelectedSettings:a,disabled:i,field:"fontBold",icon:vn,valueChanged:l,values:n.settings.fontBold.values,value:t.style?.fontBold}),"fontItalic"in n.settings&&!n.settings.fontItalic.hidden&&p.jsx(Pt,{setSelectedSettings:a,disabled:i,field:"fontItalic",icon:mn,valueChanged:l,values:n.settings.fontItalic.values,value:t.style?.fontItalic}),"opacity"in n.settings&&!n.settings.opacity.hidden&&p.jsx(kt,{selectedSettings:s,setSelectedSettings:a,title:"Opacité",icon:un,min:n.settings.opacity.min,max:n.settings.opacity.max,step:n.settings.opacity.step,unity:"%",disabled:i,field:"opacity",value:t.style?.opacity,valueChanged:o})]}):"settings"in e?p.jsxs(p.Fragment,{children:["strokeColor"in e.settings&&!e.settings.strokeColor.hidden&&p.jsx(Ct,{selectedSettings:s,setSelectedSettings:a,title:"Couleur du trait",mode:"stroke",disabled:i,field:"strokeColor",value:e.settings.strokeColor.default,valueChanged:o,values:e.settings.strokeColor.values}),"fillColor"in e.settings&&!e.settings.fillColor.hidden&&p.jsx(Ct,{selectedSettings:s,setSelectedSettings:a,title:"Couleur de fond",disabled:i,field:"fillColor",value:e.settings.fillColor.default,valueChanged:o,values:e.settings.fillColor.values}),"lineWidth"in e.settings&&!e.settings.lineWidth.hidden&&p.jsx(kt,{selectedSettings:s,setSelectedSettings:a,title:"Epaisseur du trait",disabled:i,field:"lineWidth",icon:yn,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.jsx($i,{selectedSettings:s,setSelectedSettings:a,disabled:i,defaultValue:e.settings.lineDash.default,valueChanged:o,values:e.settings.lineDash.values}),"lineArrow"in e.settings&&!e.settings.lineArrow.hidden&&p.jsx(Bi,{selectedSettings:s,setSelectedSettings:a,disabled:i,defaultValue:e.settings.lineArrow.default,valueChanged:o,values:e.settings.lineArrow.values}),"closedPoints"in e.settings&&!e.settings.closedPoints.hidden&&p.jsx(Ui,{selectedSettings:s,setSelectedSettings:a,disabled:i,valueChanged:o,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&p.jsx(Oi,{selectedSettings:s,setSelectedSettings:a,disabled:i,valueChanged:l,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),"fontBold"in e.settings&&!e.settings.fontBold.hidden&&p.jsx(Pt,{setSelectedSettings:a,disabled:i,field:"fontBold",icon:vn,valueChanged:l,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),"fontItalic"in e.settings&&!e.settings.fontItalic.hidden&&p.jsx(Pt,{setSelectedSettings:a,disabled:i,field:"fontItalic",icon:mn,valueChanged:l,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),"opacity"in e.settings&&!e.settings.opacity.hidden&&p.jsx(kt,{selectedSettings:s,setSelectedSettings:a,title:"Opacité",icon:un,min:e.settings.opacity.min,max:e.settings.opacity.max,step:e.settings.opacity.step,unity:"%",disabled:i,field:"opacity",value:e.settings.opacity.default,valueChanged:o})]}):null,da=({width:e,availableTools:t,updateToolSettings:n,layersManipulation:i=!1,toggleLayoutPanel:s,activeTool:a,selectedShape:o,canvas:l,settings:r,updateShape:d,removeShape:h,isZoomPanelShown:c,setIsZoomPanelShown:u})=>{const[m,v]=f.useState(void 0),[b,k]=f.useState(!1),j=r.size==="infinite"||r.features.zoom,C=!r.features.edition,S=()=>{k(T=>!T)},y=((T,V)=>{const W=$(T).map(A=>V.find(I=>I.id===A?.toolId)||V.find(I=>I.type===A?.type)).filter(A=>A!==void 0);if(!W.length)return;if(W.length===1)return W[0];const N=W.slice(1).reduce((A,I)=>{const X={};for(const B in I.settings){if(A[B]===void 0||I.settings[B]?.hidden||A[B]?.hidden)continue;const M=A[B],g=I.settings[B],w={};"min"in g&&"min"in M&&g.min===M.min&&"max"in g&&"max"in M&&g.max===M.max&&"step"in g&&"step"in M&&g.step===M.step&&(w.min=g.min,w.max=g.max,w.step=g.step),"values"in g&&"values"in M&&g.values?.join(",")===M.values?.join(",")&&(w.values=g.values),(Object.keys(w).length>0||B==="closedPoints")&&(X[B]=w)}return X},W[0].settings);return{id:W.map(A=>A.id).join("-"),icon:"",label:"group",type:"group",settings:N}})(o,t),Q=(y?Object.keys(y.settings).length+1:"settings"in a?Object.keys(a.settings).length:0)+ +i+ +j,E=e<40*Q,H=(T,V,W=!0)=>{if($(o).length){const N=$(o).map(A=>at(ve(["style",T],V,A),r));d(N,W),y&&n(y.id,T,V)}else n(a.id,T,V)},z=(T,V)=>{if($(o).length){const W=$(o).map(N=>{if(N.type!=="text")return N;const A=l?.getContext("2d");if(!A)return N;const I=ve(["style",T],V,N),X=Jt(A,I.value,I.width,I.style?.fontBold??!1,I.style?.fontItalic??!1,I.style?.fontFamily);return at({...I,fontSize:X,height:X*I.value.length},r)});d(W,!0),y&&n(y.id,T,V)}else n(a.id,T,V)};return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"react-paint-editor-settings-bar",children:[p.jsxs("div",{className:"react-paint-editor-settings-shrinkable",children:[j&&p.jsx(ca,{className:c?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{u(T=>!T)}}),E&&Q>2&&p.jsx(q,{disabled:C,onClick:S,title:"Toggle settings",icon:'<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>'}),o?y&&p.jsxs(p.Fragment,{children:[!E&&p.jsx(an,{activeTool:a,selectedShape:o,selectedShapeTool:y,disabled:C,selectedSettings:m,setSelectedSettings:v,handleShapeStyleChange:H,handleShapeFontFamilyChange:z}),a.type==="selection"&&p.jsx(na,{disabled:C,selectedShape:o,removeShape:h})]}):!E&&p.jsx(an,{activeTool:a,selectedShape:o,selectedShapeTool:y,disabled:C,selectedSettings:m,setSelectedSettings:v,handleShapeStyleChange:H,handleShapeFontFamilyChange:z})]}),p.jsx("div",{className:"react-paint-editor-settings-separator"}),i&&p.jsx(sa,{disabled:C,toggleLayoutPanel:s})]}),b&&p.jsx(wt,{className:"react-paint-editor-settings-modal",onClose:S,position:"bottom",title:"Settings",children:p.jsx(an,{activeTool:a,selectedShape:o,selectedShapeTool:y,disabled:C,selectedSettings:m,setSelectedSettings:v,handleShapeStyleChange:H,handleShapeFontFamilyChange:z})})]})},Yi=({disabled:e=!1,withText:t=!1,loadFile:n,type:i,img:s,accept:a})=>{const o=f.useRef(null);return p.jsx(q,{ref:o,type:"file",onClick:l=>{l.stopPropagation(),o.current&&(o.current.value="")},onChange:l=>{const r=l.target.files?.item(0);r&&n(r)},accept:a,title:i.label??i.type,icon:s,disabled:e,children:t?i.label:void 0})},Se=({type:e,img:t,isActive:n,withText:i=!1,disabled:s=!1,setActive:a})=>p.jsx(q,{disabled:s,selected:n,onClick:()=>{a(e)},title:e.label??e.type,icon:t,children:i?e.label:void 0}),ha=({activeTool:e,withActionsInMenu:t,hasActionToUndo:n=!1,hasActionToRedo:i=!1,hasActionToClear:s=!1,undoAction:a,redoAction:o,clearCanvas:l,alignment:r,group:d,vertical:h=!1,disabled:c=!1,withLoadAndSave:u,withExport:m,addPicture:v,loadFile:b,togglePictureUrlModal:k,saveFile:j,toggleExportModal:C,withUploadPicture:S,withUrlPicture:y})=>{const[Q,E]=f.useState(!1),[,H]=f.useTransition(),z=d?.tools?.some(V=>V===e.type),T=(z?e.icon:d.img)??d.title;return f.useEffect(()=>{if(!Q)return;const V=()=>{E(!1)};return document.addEventListener("click",V),()=>{document.removeEventListener("click",V)}},[Q]),t||S||y||u||m?p.jsxs("div",{className:"react-paint-editor-toolbox-relative",children:[p.jsx(q,{selected:z,title:d.title,disabled:c,onClick:()=>{H(()=>{E(!0)})},icon:T}),Q&&p.jsx(Oe,{alignment:r,position:"top",children:p.jsxs("div",{className:"react-paint-editor-toolbox-panel-content","data-vertical":+h,children:[t&&p.jsxs(p.Fragment,{children:[p.jsx(Se,{withText:!0,type:qe,disabled:c||!n,img:qe.icon,isActive:e.id===qe.id,setActive:a}),p.jsx(Se,{withText:!0,type:Ge,disabled:c||!i,img:Ge.icon,isActive:e.id===Ge.id,setActive:o}),p.jsx(Se,{withText:!0,type:_e,disabled:c||!s,img:_e.icon,isActive:e.id===_e.id,setActive:l}),(S||y||u)&&p.jsx("hr",{})]}),S&&p.jsx(Yi,{withText:!0,type:An,disabled:c,loadFile:async V=>{E(!1),await v(V)},img:An.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),y&&p.jsx(q,{disabled:c,selected:!1,onClick:k,title:"Add picture from URL",icon:'<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>',children:"Add picture from URL"}),(S||y)&&u&&p.jsx("hr",{}),u&&p.jsxs(p.Fragment,{children:[p.jsx(Yi,{withText:!0,type:zn,disabled:c,loadFile:V=>{E(!1),b(V)},img:zn.icon,accept:"application/JSON"}),p.jsx(Se,{withText:!0,disabled:c,type:Wt,img:Wt.icon,isActive:e.id===Wt.id,setActive:j})]}),m&&p.jsx(Se,{withText:!0,disabled:c,type:Nt,img:Nt.icon,isActive:e.id===Nt.id,setActive:C})]})})]}):null},ua=({togglePictureUrlModal:e,addPicture:t})=>{const n=f.useRef(null);return f.useEffect(()=>{n.current&&n.current.focus()},[]),p.jsx(wt,{className:"react-paint-editor-toolbox-pictureinput-modal",onClose:e,title:"Add picture from URL",children:p.jsxs("form",{onSubmit:async i=>{i.preventDefault();const s=n.current?.value;s&&(await t(s),e())},children:[p.jsxs("label",{children:["URL ",p.jsx("input",{type:"text",ref:n})]}),p.jsx(q,{onClick:e,children:"Annuler"}),p.jsx(q,{type:"submit",selected:!0,children:"Ajouter"})]})})},Xi="Choose export settings",pa=({toggleExportModal:e,exportCanvasInFile:t})=>{const n=async i=>{t(i),e()};return p.jsxs(wt,{className:"react-paint-editor-toolbox-export-modal",onClose:e,title:Xi,children:[p.jsx("h3",{children:Xi}),p.jsx("hr",{}),p.jsx(q,{onClick:()=>n("currentZoom"),children:"Exporter la vue actuelle"}),p.jsx(q,{onClick:()=>n("defaultView"),children:"Exporter le canvas entier"}),p.jsx(q,{onClick:()=>n("fitToShapes"),children:"Exporter dans les limites du dessin"}),p.jsx(q,{selected:!0,onClick:e,children:"Annuler"})]})},ga=({activeTool:e,alignment:t,group:n,disabled:i=!1,setActiveToolFromId:s})=>{const a=f.useRef(null),[o,l]=f.useState(!1),[,r]=f.useTransition(),[d,h]=f.useState(void 0),c=v=>{h(v),s(v.id)};if(f.useEffect(()=>{if(!o)return;const v=b=>{!On(b,a.current)&&l(!1)};return document.addEventListener("mousedown",v,{passive:!1}),document.addEventListener("touchstart",v,{passive:!1}),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("touchstart",v)}},[o]),"type"in n)return p.jsx(Se,{disabled:i,type:n,img:n.icon,isActive:e.id===n.id,setActive:c});if(!n.toolsType.length)return null;if(n.toolsType?.length===1)return p.jsx(Se,{disabled:i,type:n.toolsType[0],img:n.toolsType[0].icon,isActive:e.id===n.toolsType[0].id,setActive:c});const u=n?.toolsType.find(v=>v.type===e.type)!==void 0,m=(d?d.icon:n.toolsType?.[0]?.icon)??n.title;return p.jsxs("div",{className:"react-paint-editor-toolbargroup-relative",children:[p.jsx(q,{selected:u,title:n.title,disabled:i,onClick:()=>{d?s(d.id):n.toolsType?.[0]&&c(n.toolsType[0]),r(()=>{l(!0)})},icon:m}),o&&p.jsx(Oe,{alignment:t,position:"top",children:p.jsx("div",{className:"react-paint-editor-toolbargroup-panel-content","data-vertical":+n.vertical,ref:a,children:n.toolsType.map(v=>p.jsx(Se,{disabled:i,type:v,img:v.icon,isActive:e.id===v.id,setActive:c},v.id))})})]})},fa=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],va=({settings:e,width:t,activeTool:n,hasActionToUndo:i=!1,hasActionToRedo:s=!1,hasActionToClear:a=!1,withLoadAndSave:o,withExport:l,clearCanvas:r,setActiveTool:d,undoAction:h,redoAction:c,addPicture:u,loadFile:m,saveFile:v,exportCanvasInFile:b,availableTools:k,withUrlPicture:j,withUploadPicture:C})=>{const S=((g,w)=>{const x=w.flatMap(L=>{if(typeof L!="object")return g.filter(R=>R.type===L);const P=g.filter(R=>L.toolsType.includes(R.type));return P?{...L,toolsType:P}:null});return tn(x)})(k,fa),y=!e.features.edition,Q=t<40*(6+S.length),E=t<40*(3+S.length),[H,z]=f.useState(!1),[T,V]=f.useState(!1),[W,N]=f.useState(!1),A=()=>{z(g=>!g)},I=()=>{N(g=>!g)},X=g=>{d(g),z(!1)},B=g=>{X(k.find(w=>w.id===g)??n)},M=k.find(g=>g.type===n.type)!==void 0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"react-paint-editor-toolbar-toolbox",style:{"--react-paint-editor-toolbar-minwidth":"160px"},children:[p.jsxs("div",{className:"react-paint-editor-toolbar-shrinkable",children:[p.jsx(Se,{type:Te,disabled:y,img:Te.icon,isActive:n.id===Te.id,setActive:X}),(e.size==="infinite"||e.features.zoom)&&p.jsx(Se,{type:It,disabled:y,img:It.icon,isActive:n.id===It.id,setActive:X}),E?p.jsx(q,{disabled:y,onClick:A,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}):S.map(g=>p.jsx(ga,{disabled:y,activeTool:n,group:g,setActiveToolFromId:B},"id"in g?g.id:g.title))]}),!Q&&p.jsxs(p.Fragment,{children:[p.jsx(Se,{type:qe,disabled:y||!i,img:qe.icon,isActive:n.id===qe.id,setActive:h}),p.jsx(Se,{type:Ge,disabled:y||!s,img:Ge.icon,isActive:n.id===Ge.id,setActive:c}),p.jsx(Se,{type:_e,disabled:y||!a,img:_e.icon,isActive:n.id===_e.id,setActive:r})]}),p.jsx(ha,{withActionsInMenu:Q,disabled:y,vertical:!0,alignment:"right",group:{title:"Menu",img:'<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>'},activeTool:n,addPicture:u,loadFile:m,saveFile:v,togglePictureUrlModal:()=>{V(!0)},toggleExportModal:I,withUploadPicture:C,withUrlPicture:j,withLoadAndSave:o,withExport:l,hasActionToUndo:i,hasActionToRedo:s,hasActionToClear:a,undoAction:h,redoAction:c,clearCanvas:r})]}),H&&p.jsx(wt,{className:"react-paint-editor-toolbar-modal",onClose:A,title:"Outils",children:k.map(g=>g.type==="picture"?null:p.jsx(Se,{disabled:y,type:g,img:g.icon,withText:!1,isActive:n.id===g.id,setActive:X},g.id))}),T&&p.jsx(ua,{togglePictureUrlModal:()=>{V(g=>!g)},addPicture:u}),W&&p.jsx(pa,{toggleExportModal:I,exportCanvasInFile:b})]})},jt={none:0,small:10,medium:20,large:40},ma={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},ya=()=>{const e=f.useRef([]),[t,n]=f.useState([]);return f.useEffect(()=>()=>{for(const i of e.current)clearTimeout(i)},[]),{snackbarList:t,addSnackbar:({type:i=qs,duration:s=Gs,text:a})=>{const o={id:he("snackbar_"),duration:s,type:i,text:a};n(l=>[...l,o]),e.current=[...e.current,setTimeout(()=>{return l=o.id,void n(r=>r.filter(d=>d.id!==l));var l},s)]}}};He.Canvas=({options:e,className:t,style:n,canvasProps:i})=>{const{shapesRef:s,selectedShape:a,selectionFrame:o,hoveredShape:l,addShape:r,setSelectedShape:d,setSelectionFrame:h,refreshSelectedShapes:c,refreshHoveredShape:u,removeShape:m,updateShape:v,backwardShape:b,forwardShape:k,saveShapes:j,refs:C,width:S,height:y,settings:Q,setCanvasSize:E,setCanvasOffset:H,selectShapes:z,activeTool:T,setActiveTool:V,isInsideComponent:W,isEditMode:N,canvas:{withSkeleton:A,withFrameSelection:I,canGrow:X,canShrink:B},canvasOffsetStartData:M,setCanvasOffsetStartData:g,selectionMode:w,setSelectionMode:x,setCanvasMoveAcceleration:L,isShiftPressed:P,isAltPressed:R,setShiftPressed:Z,setAltPressed:U}=i,{canvasBackgroundColor:F,canvasSelectionColor:oe,canvasSelectionWidth:D}={...ns,...e},te=f.useRef(null),Y=f.useCallback(G=>{r(G),z(G)},[r,z]),ae=f.useCallback(G=>{E({realWidth:S,realHeight:y,width:G,height:y*G/S,scaleRatio:G/S})},[S,y,E]);return Ys({isInsideComponent:W,isEditingText:w.mode==="textedition",settings:Q,selectedShape:a,setSelectedShape:d,removeShape:m,pasteShapes:Y,updateShapes:v,backwardShape:b,forwardShape:k,setShiftPressed:Z,setAltPressed:U,setActiveTool:V,setSelectionMode:x,setSelectionFrame:h}),(({onResized:G,element:ne})=>{f.useEffect(()=>{const ee=ne.current;if(!ee)return;const Qe=new ResizeObserver(K=>{const le=K?.[0]?.borderBoxSize?.[0],{width:Le,height:ue}=le?{width:le.inlineSize,height:le.blockSize}:K?.[0]?.contentRect??{};Le!==void 0&&ue!==void 0&&G(Le,ue)});return Qe.observe(ee),()=>{Qe.unobserve(ee)}},[ne,G])})({element:te,onResized:ae}),p.jsx("div",{ref:te,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":X,"data-shrink":B,style:{"--react-paint-app-row-width":Q.canvasSize.width,"--react-paint-app-canvaswidth":S,"--react-paint-app-canvasheight":y,"--react-paint-app-row-aspectratio":`calc(${Q.canvasSize.width} / ${Q.canvasSize.height})`,"--react-paint-app-canvas-bg":F,...n},children:p.jsx(Ns,{ref:C.canvas,canGrow:X,isInsideComponent:W,activeTool:T,setActiveTool:V,canvasOffsetStartData:M,setCanvasOffsetStartData:g,shapes:s.current,addShapes:r,updateSingleShape:v,selectedShape:a,selectionFrame:o,setSelectedShape:d,setSelectionFrame:h,hoveredShape:l,refreshHoveredShape:u,refreshSelectedShapes:c,settings:Q,setCanvasOffset:H,saveShapes:j,selectionMode:w,setSelectionMode:x,setCanvasMoveAcceleration:L,selectionColor:oe,selectionWidth:D,isEditMode:N,isShiftPressed:P,isAltPressed:R,withFrameSelection:I,withSkeleton:A})})},He.Editor=({editorProps:e,className:t,style:n,options:i,children:s})=>{const{shapesRef:a,addPictureShape:o,moveShapes:l,toggleShapeVisibility:r,toggleShapeLock:d,canGoBackward:h,canGoForward:c,canClear:u,selectedShape:m,removeShape:v,updateShape:b,backwardShape:k,forwardShape:j,refs:C,width:S,height:y,selectTool:Q,selectShapes:E,activeTool:H,setActiveTool:z,setAvailableTools:T,isEditMode:V,availableTools:W,gridGap:N,setGridGap:A,loadFile:I,exportPicture:X,exportData:B,clearCanvas:M,settings:g,setCanvasZoom:w,canvas:{canGrow:x,layersManipulation:L,withExport:P,withLoadAndSave:R,withUploadPicture:Z,withUrlPicture:U}}=e,{toolbarBackgroundColor:F,dividerColor:oe,fontRadius:D,fontDisabledColor:te,fontDisabledBackgroundColor:Y,fontColor:ae,fontBackgroundColor:G,fontSelectedColor:ne,fontSelectedBackgroundColor:ee,fontHoverColor:Qe,fontHoverBackgroundColor:K}={...ma,...i},le=g.size==="infinite"||g.features.zoom,[Le,ue]=f.useState(!1),[pe,Ae]=f.useState(!1),[Be,xe]=f.useState(le),we=le&&Be,Ee=N>=jt.large?"large":N>=jt.medium?"medium":N>=jt.small?"small":"none",{snackbarList:Re,addSnackbar:ie}=ya(),$e=f.useCallback((re,ce,Ht)=>{T(Ue=>Ue.map(dt=>dt.id===re?ve(["settings",ce,"default"],Ht,dt):dt)),z(Ue=>Ue.id===re?ve(["settings",ce,"default"],Ht,Ue):Ue)},[z,T]),on=f.useCallback(re=>{ue(!0);try{X(re)}catch(ce){ce instanceof Error&&ie({type:"error",text:`L'export a échoué : ${ce.message}`}),console.warn(ce)}finally{ue(!1)}},[X,ie]),rn=f.useCallback(()=>{ue(!0);try{B(),ue(!1)}catch(re){re instanceof Error&&ie({type:"error",text:"L'enregistrement a échoué"}),console.warn(re)}finally{ue(!1)}},[B,ie]),Lt=f.useCallback(async re=>{ue(!0);try{await I(re),ie({type:"success",text:"Fichier chargé !"})}catch(ce){ce instanceof Error&&ie({type:"error",text:"Le chargement a échoué"}),console.warn(ce)}finally{ue(!1)}},[I,ie]),Vt=f.useCallback(async re=>{ue(!0);try{const ce=await o(re,S,y);E([ce])}catch(ce){ce instanceof Error&&ie({type:"error",text:"Le chargement a échoué"}),console.warn(ce)}finally{ue(!1)}},[o,E,ie,S,y]),Zt=`${t?`${t} `:""}${pe?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return p.jsxs("div",{ref:C.setEditor,className:Zt,style:{"--react-paint-editor-app-maxWidth":x?"100%":`${S}px`,"--react-paint-editor-app-toolbar-bg":F,"--react-paint-editor-app-divider-color":oe,"--react-paint-editor-app-font-radius":D,"--react-paint-editor-app-font-disabled-color":te,"--react-paint-editor-app-font-disabled-bg":Y,"--react-paint-editor-app-font-color":ae,"--react-paint-editor-app-font-bg":G,"--react-paint-editor-app-font-selected-color":ne,"--react-paint-editor-app-font-selected-bg":ee,"--react-paint-editor-app-font-hover-color":Qe,"--react-paint-editor-app-font-hover-bg":K,...n},children:[V&&p.jsx(va,{settings:g,width:g.canvasSize.width,activeTool:H,clearCanvas:M,setActiveTool:Q,exportCanvasInFile:on,saveFile:rn,loadFile:Lt,addPicture:Vt,hasActionToUndo:h,hasActionToRedo:c,hasActionToClear:u,undoAction:k,redoAction:j,availableTools:W,withExport:P,withLoadAndSave:R,withUploadPicture:Z,withUrlPicture:U}),s,V&&L&&p.jsx(ta,{gridFormat:Ee,setGridFormat:re=>{A(jt[re])},shapes:a.current,moveShapes:l,selectedShapes:m,removeShape:v,selectShapes:E,toggleShapeVisibility:r,toggleShapeLock:d,isLayoutPanelShown:pe,settings:g}),we&&p.jsxs(Oe,{alignment:"left",className:"react-paint-editor-layouts-panel","data-edit":+V,children:[p.jsx(q,{className:"react-paint-editor-zoom-button",icon:'<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>',onClick:()=>w("unzoom")}),p.jsxs(q,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>w("default"),children:[Math.round(100*g.canvasZoom),"%"]}),p.jsx(q,{className:"react-paint-editor-zoom-button",icon:xn,onClick:()=>w("zoom")})]}),V&&p.jsxs(p.Fragment,{children:[p.jsx(da,{setCanvasZoom:w,width:g.canvasSize.width,activeTool:H,availableTools:W,selectedShape:m,settings:g,removeShape:v,updateShape:b,canvas:C.canvas.current,layersManipulation:L,toggleLayoutPanel:()=>{Ae(re=>!re)},isZoomPanelShown:we,setIsZoomPanelShown:xe,updateToolSettings:$e}),p.jsx(Xs,{isLoading:Le}),p.jsx(Ks,{snackbarList:Re})]})]})},He.useReactPaint=({width:e=1e3,height:t=600,shapes:n,mode:i="editor",disabled:s=!1,options:a=Fn}={})=>{const{layersManipulation:o,brushAlgo:l,isBrushShapeDoneOnMouseUp:r,grid:d,canGrow:h,canShrink:c,withExport:u,withLoadAndSave:m,withUploadPicture:v,withUrlPicture:b,withSkeleton:k,withFrameSelection:j,clearCallback:C,availableTools:S,canvasSelectionPadding:y,size:Q,canZoom:E}={...Fn,...a},H=i!=="viewer",z=f.useRef(null),T=f.useRef(null),V=f.useRef(!1),W=f.useCallback(_=>{z.current=_},[]),[N,A]=f.useState(void 0),[I,X]=f.useState(Te),[B,M]=f.useState({mode:"default"}),[g,w]=f.useState(d),[x,L]=f.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),P=E==="always"&&!s,{canvasTransformation:R,setCanvasTransformation:Z,setCanvasOffset:U,setCanvasZoom:F,resetZoom:oe}=As({canvasSize:x,size:Q,canvasElt:T.current,zoomEnabled:P}),{offset:D,zoom:te}=R,Y=f.useMemo(()=>({brushAlgo:l,isBrushShapeDoneOnMouseUp:r,canvasSize:{realWidth:x.realWidth,realHeight:x.realHeight,width:x.width,height:x.height,scaleRatioWithNoZoom:x.scaleRatio,scaleRatio:x.scaleRatio*te},size:Q,canvasOffset:D,canvasZoom:te,gridGap:g,selectionPadding:y,features:{edition:H&&!s,zoom:P}}),[y,g,l,r,te,D,x,Q,s,P,H]),[ae,G]=f.useState(Hi(S,v||b)),{isInsideComponent:ne}=(({settings:_,componentRef:de})=>{const[De,Ne]=f.useState(!1),Xe=!_.features.edition&&!_.features.zoom;return f.useEffect(()=>{if(!Xe){const Ve=ht=>{Ne(On(ht,de.current))};return document.addEventListener("mousedown",Ve,{passive:!0}),document.addEventListener("touchstart",Ve,{passive:!0}),()=>{document.removeEventListener("mousedown",Ve),document.removeEventListener("touchstart",Ve)}}Ne(!1)},[Xe,de]),{isInsideComponent:De}})({settings:Y,componentRef:z}),[ee,Qe]=f.useState(!1),[K,le]=f.useState(!1),{registerEvent:Le,unregisterEvent:ue,shapesRef:pe,selectedShape:Ae,selectionFrame:Be,hoveredShape:xe,addShapes:we,addPictureShape:Ee,moveShapes:Re,setSelectedShape:ie,setSelectionFrame:$e,refreshSelectedShapes:on,refreshHoveredShape:rn,removeShape:Lt,updateShape:Vt,backwardShape:Zt,forwardShape:re,clearShapes:ce,saveShapes:Ht,toggleShapeVisibility:Ue,toggleShapeLock:dt,canGoBackward:Sa,canGoForward:Qa,canClear:xa}=Ts(Y,e,t,ee),ln=f.useCallback(_=>{ie(void 0),X(_)},[ie]),[ot,qi]=f.useState([0,0]),Gi=B.mode==="preview";f.useEffect(()=>{if(Gi)return()=>M(_=>_.mode==="preview"?{mode:"default"}:_)},[Ae?.id,Gi]);const _i=B.mode==="selectionFrame";f.useEffect(()=>{if(_i)return()=>qi([0,0])},[_i]),f.useEffect(()=>{if(ot[0]!==0||ot[1]!==0){const _=setInterval(()=>{Z(({offset:de,zoom:De})=>{const Ne=[de[0]-ot[0],de[1]-ot[1]];return qt({zoom:De,size:Q,canvasSize:x,newOffset:Ne})})},20);return()=>clearInterval(_)}},[ot[0],ot[1],Z,Q,x]);const Tt=f.useCallback((_,de)=>{ce(_,de),ln(Te),Z({offset:[0,0],zoom:1})},[ln,ce,Z]),Ki=f.useCallback(_=>{ie(de=>(de?.id!==_.map(De=>De.id).join("-")&&X(Te),fe(_,Y)))},[ie,Y]),ba=f.useCallback(()=>{const _=Zs(pe.current,e,t);if(!_)throw new Error("L'encodage a échoué");Pi(_,"drawing.json")},[pe,e,t]),wa=f.useCallback(_=>{const de=ji({shapes:pe.current,settings:Y,view:_});Pi(de,"drawing.png")},[pe,Y]),Ca=f.useCallback(_=>ji({shapes:pe.current,settings:Y,view:_}),[pe,Y]),Ma=f.useCallback(()=>sn(pe.current,e,t),[pe,e,t]);f.useEffect(()=>{ne||ie(void 0)},[ne,ie]);const Ye=f.useCallback(async(_,de)=>{const De=await(async(Ne,Xe)=>{if(!Ne)return[];const Ve=[],ht=tn(Ne.map(be=>{if(!be||!Nn.includes(be.type))return null;if(be.type==="picture"){const Ze=new Image,La=new Promise((ut,Va)=>{Ze.onload=()=>{URL.revokeObjectURL(Ze.src),ut()},Ze.onerror=()=>{Va(new Error("Some images could not be loaded"))}});if(Ve.push(La),be.src.startsWith("http"))ki(be.src).then(ut=>{Ze.src=ut}).catch(()=>{Ze.src=""});else if(be.src.includes("<svg")){const ut=new Blob([be.src],{type:"image/svg+xml"});Ze.src=URL.createObjectURL(ut)}else Ze.src=be.src;return Li({...be,img:Ze},Xe)}return Li(be,Xe)}));return await Promise.all(Ve),ht})(_,Y);Tt(De,de)},[Tt,Y]),cn=f.useRef(Ye);cn.current=Ye;const ka=f.useCallback((_=[],de=!0)=>{cn.current?.(_,{clearHistory:de,source:"remote"})},[]);f.useEffect(()=>{V.current||(V.current=!0,n&&cn.current?.(n,{clearHistory:!0,source:"remote"}))},[n]);const Pa=f.useCallback(async _=>{const de=await(async De=>new Promise((Ne,Xe)=>{const Ve=new FileReader;Ve.onload=ht=>{const be=ht.target?.result;if(!be)return Xe("Impossible de récupérer les données du fichier");const Ze=JSON.parse(be);Ne(Ze)},Ve.readAsText(De)}))(_);await Ye(de.shapes??[],{clearHistory:!0,source:"remote"})},[Ye]),ja=f.useCallback(()=>{typeof C!="string"?Ye(C(),{clearHistory:!1,source:"user"}):C==="defaultShapes"&&n!==void 0?Ye(n,{clearHistory:!1,source:"user"}):Tt([],{clearHistory:!1,source:"user"})},[Tt,Ye,n,C]);f.useEffect(()=>{G(Hi(S,v||b))},[S,v,b]);const Ji={canvas:T,editor:z,setEditor:W};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":Y.canvasZoom,"--react-paint-canvas-offset-x":Y.canvasOffset[0],"--react-paint-canvas-offset-y":Y.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:pe,addPictureShape:Ee,moveShapes:Re,toggleShapeVisibility:Ue,toggleShapeLock:dt,canGoBackward:Sa,canGoForward:Qa,canClear:xa,selectedShape:Ae,removeShape:Lt,updateShape:Vt,backwardShape:Zt,forwardShape:re,refs:Ji,width:e,height:t,selectTool:ln,selectShapes:Ki,activeTool:I,setActiveTool:X,setAvailableTools:G,isEditMode:H,availableTools:ae,gridGap:g,setGridGap:w,loadFile:Pa,exportPicture:wa,exportData:ba,clearCanvas:ja,settings:Y,setCanvasZoom:F,canvas:{canGrow:h,canShrink:c,layersManipulation:o,withExport:u,withLoadAndSave:m,withUploadPicture:v,withUrlPicture:b}},canvasProps:{shapesRef:pe,selectedShape:Ae,selectionFrame:Be,hoveredShape:xe,addShape:we,setSelectedShape:ie,setSelectionFrame:$e,refreshSelectedShapes:on,refreshHoveredShape:rn,removeShape:Lt,updateShape:Vt,backwardShape:Zt,forwardShape:re,saveShapes:Ht,refs:Ji,width:e,height:t,settings:Y,setCanvasSize:L,setCanvasOffset:U,setCanvasZoom:F,selectShapes:Ki,activeTool:I,setActiveTool:X,isInsideComponent:ne,isEditMode:H,canvas:{withSkeleton:k,withFrameSelection:j,canGrow:h,canShrink:c},canvasOffsetStartData:N,setCanvasOffsetStartData:A,selectionMode:B,setSelectionMode:M,setCanvasMoveAcceleration:qi,isShiftPressed:ee,isAltPressed:K,setShiftPressed:Qe,setAltPressed:le},registerEvent:Le,unregisterEvent:ue,resetCanvas:ka,resetZoom:oe,getCurrentImage:Ca,getCurrentData:Ma,setCanvasOffset:U,setCanvasZoom:F}},Object.defineProperty(He,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(Ae,v){typeof exports=="object"&&typeof module<"u"?v(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],v):v((Ae=typeof globalThis<"u"?globalThis:Ae||self)["react-paint"]={},Ae.React,Ae.jsxRuntime)})(this,function(Ae,v,h){"use strict";const yn='<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>',At='<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>',Et='<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>',Rt='<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>',Sn='<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>',xn='<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>',It='<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>',bn='<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>',Qn='<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>',Cn='<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>',wn='<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>',Mn='<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>',kn='<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>',Pn='<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>',jn='<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>',Ln='<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>',ve=["transparent","black","white","red","green","blue","yellow"],Ne=[0,1,2],Vn=[[1,0],[1,2],[4,6]],ut="serif",pi=2,Zn=3,gi=4,re="react-paint-",Tn={strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0}},Nt={type:"picture",id:`${re}picture`,icon:It,label:"Image",settings:{opacity:{min:0,max:100,step:1,default:100}}},Hn={type:"brush",id:`${re}brush`,icon:yn,label:"Brosse",settings:{strokeColor:{values:ve,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:Ne,default:0}}},zn={type:"line",id:`${re}line`,icon:Qn,label:"Ligne",settings:{strokeColor:{values:ve,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0},lineArrow:{values:[0,1,2,3],default:0}}},An={type:"polygon",id:`${re}polygon`,icon:Rt,label:"Polygone",settings:{strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0},closedPoints:{default:0}}},En={type:"curve",id:`${re}curve`,icon:Cn,label:"Courbe",settings:{strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0},closedPoints:{default:0}}},Rn={type:"rect",id:`${re}rect`,icon:At,label:"Rectangle",settings:Tn},In={type:"square",id:`${re}square`,icon:At,label:"Carré",settings:{strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0}}},Nn={type:"circle",id:`${re}circle`,icon:Et,label:"Cercle",settings:{strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0}}},Dn={type:"ellipse",id:`${re}ellipse`,icon:Et,label:"Ellipse",settings:{strokeColor:{values:ve,default:"black"},fillColor:{values:ve,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ne,default:0}}},Wn={type:"text",id:`${re}text`,icon:bn,label:"Texte",settings:{strokeColor:{values:ve,default:"black"},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:["arial","serif","monospace"],default:ut},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}}},Ee={id:`${re}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"},Ke={id:`${re}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:`${re}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"},et={id:`${re}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"},Dt={id:`${re}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"},Fn={id:`${re}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"},Wt={id:`${re}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"},Ft={id:`${re}move`,type:"move",icon:'<svg viewBox="0 -960 960 960"><path d="M412-48q-21.95 0-40.98-9Q352-66 338-83L48-434l27-28q17-17 41.5-20.5T162-473l126 74v-381q0-15.3 10.29-25.65Q308.58-816 323.79-816t25.71 10.35Q360-795.3 360-780v300h80v-396q0-15.3 10.29-25.65Q460.58-912 475.79-912t25.71 10.35Q512-891.3 512-876v396h80v-348q0-15.3 10.29-25.65Q612.58-864 627.79-864t25.71 10.35Q664-843.3 664-828v348h80v-252q0-15.3 10.29-25.65Q764.58-768 779.79-768t25.71 10.35Q816-747.3 816-732v540q0 60-42 102T672-48H412Z"/></svg>',label:"Move"},On={id:`${re}upload-picture`,type:"uploadpicture",icon:It,label:"Upload picture"},Bn=2,$n="blue",$e=14,Yn=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],Un=["brush","rect","square","line","polygon","circle","curve","ellipse","picture","text","triangle","group"],Xn="react-paint-canvas-drawcanvas",Gn="react-paint-canvas-selectioncanvas",qn={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,availableTools:[Hn,zn,An,En,Rn,In,Nn,Dn,Nt,Wn],clearCallback:"empty",brushAlgo:"simple",isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:"fixed",canZoom:"never",debug:!1},fi={canvasBackgroundColor:"white",canvasSelectionColor:$n,canvasSelectionWidth:Bn},_n=300,Ot=(e,t)=>{const n={...t};for(const s of e)delete n[s];return n},xe=(e,t,n)=>{const s=Array.isArray(n)?[...n]:{...n},i=Array.isArray(e)?e:typeof e=="string"?e.split("."):[e];return i.reduce((a,r,l)=>(a[r]=Bt(a[r])?{...a[r]}:Array.isArray(a[r])?[...a[r]]:a[r]===void 0||a[r]===null?{}:a[r],l===i.length-1&&(a[r]=t),a[r]),s),s},Bt=e=>typeof e=="object"&&!Array.isArray(e)&&e!==null,Ve=(e,t,n)=>{if(!Bt(t)||!Bt(n))return n;const s={...t};for(const i in n)n.hasOwnProperty(i)&&(s.hasOwnProperty(i)?s[i]=e(s[i],n[i],i)??Ve(e,s[i],n[i]):s[i]=n[i]);return s},Kn=(e,t)=>{if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const i of n)if(!s.includes(i)||!Kn(e[i],t[i]))return!1;return!0},$t={},de=(e="")=>($t[e]||($t[e]=0),`${e}${++$t[e]}`),Ze=(e,t,n)=>Math.max(t,Math.min(e,n)),Jn=()=>typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),es=e=>{e.reset(),e.lineCap="round",e.lineJoin="round"},me=(e,t={})=>{const{lineCap:n="round",fillColor:s="transparent",opacity:i=100,strokeColor:a=$n,lineWidth:r=Bn,lineDash:l=0,shadowColor:o="transparent",shadowBlur:c=0}=t;e.lineCap=n,e.globalAlpha=i/100,e.fillStyle=s,e.strokeStyle=a,e.lineWidth=r,e.setLineDash(l===0?[]:[Vn[l][0]*r,Vn[l][1]*r]),e.shadowColor=o,e.shadowBlur=c},ft=(e,t,n,s)=>{e.save(),e.scale(t.canvasSize.scaleRatio,t.canvasSize.scaleRatio),e.translate(t.canvasOffset[0],t.canvasOffset[1]),n&&s&&(e.translate(s[0],s[1]),e.rotate(n),e.translate(-s[0],-s[1]))},ts=(e,{selectionPadding:t})=>{const n=e.points.flat(),s=Math.min(...n.map(o=>o[0])),i=Math.min(...n.map(o=>o[1])),a=n.map(o=>ke(o,s,i,e.scaleX,e.scaleY)),r=Math.max(...a.map(o=>o[0]))+t,l=Math.max(...a.map(o=>o[1]))+t;return{x:s-t,width:r-s+t,y:i-t,height:l-i+t}},ns=(e,t)=>Te(e,ts,t),tt=(e,t)=>{const n=Si(e,t),s=ns(e,t);return{...e,path:n,selection:nt(n,s,t),computed:s}},vi=tt,Yt=e=>180*e/Math.PI,ss=(e,t)=>{const n=t.x-Math.min(Math.max(t.x,e.x),e.x+e.width),s=t.y-Math.min(Math.max(t.y,e.y),e.y+e.height);return Math.sqrt(n*n+s*s)<=t.radius},ye=({origin:e=[0,0],point:t,rotation:n=0})=>{const s=[t[0]-e[0],t[1]-e[1]],i=s[1]*Math.cos(n)-s[0]*Math.sin(n);return[s[1]*Math.sin(n)+s[0]*Math.cos(n)+e[0],i+e[1]]},is=e=>(e+2*Math.PI)%(2*Math.PI),as=({targetVector:[e,t],radian:n=!0,originVector:s})=>{const i=is(Math.atan2(t[1]-e[1],t[0]-e[0]));if(s){const[a,r]=s,l=Math.atan2(r[1]-a[1],r[0]-a[0]),o=is(i-l);return n?o:Yt(o)}return n?i:Yt(i)},os=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),De=(e,t=2)=>Math.round(e*10**t)/10**t,ke=(e,t,n,s=1,i=1)=>[t+(e[0]-t)*s,n+(e[1]-n)*i],$=(e,t,n=0)=>{if(!t.gridGap)return De(e);const s=e+n,i=s>=0?t.gridGap:-t.gridGap;return s+i/2-(s+i/2)%i-n},mi=(e,t,n)=>t.gridGap||n?e+Math.PI/18/2-(e+Math.PI/18/2)%(Math.PI/18):De(e,3),Re=(e,t)=>t?[Math.abs(e[0])>Math.abs(e[1])?e[0]:0,Math.abs(e[1])>Math.abs(e[0])?e[1]:0]:e,yi=(e,t,n,s,i,a,r)=>Se(G(t).map(l=>{switch(s.mode){case"brush":return((o,c,p)=>{const d={...o,points:xe(o.points.length-1,[...o.points[o.points.length-1],[Math.round(c[0]),Math.round(c[1])]],o.points)};return tt(d,p)})(l,n,i);case"translate":return rn(n,G(s.originalShape).find(o=>o.id===l.id),s.cursorStartPosition,i,a);case"rotate":return Yi(l,n,G(s.originalShape).find(o=>o.id===l.id),s.cursorStartPosition,s.center,i,a);case"resize":return Ui(e,l,n,G(s.originalShape).find(o=>o.id===l.id),s,i,a,r);default:return l}}),i),Ut=e=>{const t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},vt=e=>{const t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},mt=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},Si=(e,{brushAlgo:t})=>{if(e.points.length<1||e.style?.strokeColor==="transparent")return;const n=e.points.flat(),s=n.map(o=>o[0]),i=n.map(o=>o[1]),a=Math.min(...s),r=Math.min(...i),l=new Path2D;for(const o of e.points){if(!o.length)return;if(o.length===1)l.rect(...ke(o[0],a,r,e.scaleX,e.scaleY),1,1);else if(l.moveTo(...ke(o[0],a,r,e.scaleX,e.scaleY)),t==="quadratic"){for(let c=0;c<o.slice(1).length-2;c++){const p=ke(o[c],a,r,e.scaleX,e.scaleY),d=ke(o[c+1],a,r,e.scaleX,e.scaleY),u=(p[0]+d[0])/2,m=(p[1]+d[1])/2;l.quadraticCurveTo(...p,u,m)}l.quadraticCurveTo(...ke(o[o.length-2],a,r,e.scaleX,e.scaleY),...ke(o[o.length-1],a,r,e.scaleX,e.scaleY))}else for(const c of o.slice(1))l.lineTo(...ke(c,a,r,e.scaleX,e.scaleY))}return l},xi=(e,t,n,s)=>{const i=Q=>(1-Q)**3*e[0]+3*(1-Q)**2*Q*t[0]+3*(1-Q)*Q**2*n[0]+Q**3*s[0],a=Q=>(1-Q)**3*e[1]+3*(1-Q)**2*Q*t[1]+3*(1-Q)*Q**2*n[1]+Q**3*s[1],r=(Q,V,A)=>{const H=Q-2*V+A,x=-2*Q+2*V,Z=Q;if(Math.abs(H)<1e-10){if(Math.abs(x)<1e-10)return[];const O=-Z/x;return O>0&&O<1?[O]:[]}const R=x*x-4*H*Z;if(R<0)return[];const I=Math.sqrt(R),T=(-x-I)/(2*H),N=(-x+I)/(2*H),B=[];return T>0&&T<1&&B.push(T),N>0&&N<1&&N!==T&&B.push(N),B},l=e[0],o=t[0],c=n[0],p=s[0],d=e[1],u=t[1],m=n[1],f=s[1],C=r(o-l,c-o,p-c),M=r(u-d,m-u,f-m);let P=Math.min(e[0],s[0]),w=Math.max(e[0],s[0]),y=Math.min(e[1],s[1]),S=Math.max(e[1],s[1]);for(const Q of C){const V=i(Q);P=Math.min(P,V),w=Math.max(w,V)}for(const Q of M){const V=a(Q);y=Math.min(y,V),S=Math.max(S,V)}return{minX:P,maxX:w,minY:y,maxY:S}},Xt=(e,t)=>e.style?.closedPoints===1&&t.length>2?[t[t.length-2],...t,t[0],t[1]]:[t[0],...t,t[t.length-1]],Gt=(e,t,n,s)=>({cp1:[t[0]+(n[0]-e[0])/6,t[1]+(n[1]-e[1])/6],cp2:[n[0]-(s[0]-t[0])/6,n[1]-(s[1]-t[1])/6]}),rs=e=>{const t=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(t.length<2)return;const n=new Path2D;n.moveTo(...t[0]);for(const s of t.slice(1))n.lineTo(...s);return t.length>2&&e.style?.closedPoints===1&&n.lineTo(...t[0]),n},bi=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t.lineTo(...e.points[2]),t.lineTo(...e.points[0]),t},Qi=(e,t)=>({x:e.x-(t?.lineWidth??0)/2,y:e.y-(t?.lineWidth??0)/2,width:e.width+(t?.lineWidth??0),height:e.height+(t?.lineWidth??0)}),Te=(e,t,n,s=Qi)=>{const i=t(e,n),a=s(i,e.style),r=[i.x+i.width/2,i.y+i.height/2],l=((o,c,p=0)=>{if(p===0)return o;const d=[[o.x,o.y],[o.x+o.width,o.y],[o.x+o.width,o.y+o.height],[o.x,o.y+o.height]].map(f=>ye({point:f,origin:c,rotation:p})),u=Math.min(...d.map(f=>f[0])),m=Math.min(...d.map(f=>f[1]));return{x:u,y:m,width:Math.max(...d.map(f=>f[0]))-u,height:Math.max(...d.map(f=>f[1]))-m}})(a,r,e.rotation);return{borders:i,outerBorders:a,center:r,boundingBox:l}},nt=(e,t,n,s=!1)=>{const{borders:i}=t;return{border:Ut(i),shapePath:e,line:s?void 0:mt({points:[[i.x+i.width/2,i.y],[i.x+i.width/2,i.y-23/n.canvasSize.scaleRatio]]}),anchors:s?[]:[vt({x:i.x+i.width/2,y:i.y-23/n.canvasSize.scaleRatio,radius:7/n.canvasSize.scaleRatio}),...Yn.map(a=>vt({x:i.x+i.width*a[0],y:i.y+i.height*a[1],radius:7/n.canvasSize.scaleRatio}))]}},ls=({borderStart:e,borderSize:t,vector:n,settings:s,invertedAxe:i,anchor:a})=>{switch(a){case 0:{if(i){const l=t-2*s.selectionPadding;return[e+l,n-l]}const r=Math.max(2*s.selectionPadding,t-n);return[e+t-r,r]}case .5:return[e,t];case 1:if(i){const r=t+n;return[e+r,2*s.selectionPadding-r]}return[e,Math.max(2*s.selectionPadding,t+n)];default:return[0,0]}},st=(e,t,n,s,i=!1,a=!1)=>{const{center:r,borders:l}=t.computed,o=ye({origin:r,point:e,rotation:t.rotation}),c=n.anchor[0]===0&&o[0]>=l.x+l.width||n.anchor[0]===1&&o[0]<=l.x,p=n.anchor[1]===0&&o[1]>=l.y+l.height||n.anchor[1]===1&&o[1]<=l.y,d=[$(o[0],s,n.anchor[0]===0&&!c||n.anchor[0]===1&&c?s.selectionPadding:-s.selectionPadding),$(o[1],s,n.anchor[1]===0&&!p||n.anchor[1]===1&&p?s.selectionPadding:-s.selectionPadding)],u=s.gridGap?[n.anchor[0]===0?l.x:n.anchor[0]===.5?l.x+l.width/2:l.x+l.width,n.anchor[1]===0?l.y:n.anchor[1]===.5?l.y+l.height/2:l.y+l.height]:ye({origin:r,point:n.cursorStartPosition,rotation:t.rotation}),m=[d[0]-u[0],d[1]-u[1]],[f,C]=ls({borderStart:l.x,borderSize:l.width,vector:m[0],settings:s,invertedAxe:c,anchor:n.anchor[0]}),[M,P]=ls({borderStart:l.y,borderSize:l.height,vector:m[1],settings:s,invertedAxe:p,anchor:n.anchor[1]}),w=i?((y,S,Q,V,A,H,x,Z,R,I)=>{const{selectionPadding:T}=I,N=(S.width-2*T||1)/(S.height-2*T||1),B=(A-2*T)/(x-2*T);let O,Y,g,b;return R.anchor[0]!==.5&&R.anchor[1]!==.5?B<N?(Y=H,b=x,g=(x-2*T)*N+2*T,O=R.anchor[0]===0?S.width-y[0]>T?S.x+(S.width-g):S.x+S.width-2*T:S.width+y[0]>T?S.x:S.x-g+2*T):(O=V,g=A,b=(A-2*T)/N+2*T,Y=R.anchor[1]===0?S.height-y[1]>T?S.y+(S.height-b):S.y+S.height-2*T:S.height+y[1]>T?S.y:S.y-b+2*T):R.anchor[0]!==.5?(O=V,g=A,b=(A-2*T)/N+2*T,Y=S.y+(S.height-b)/2):(Y=H,b=x,g=(x-2*T)*N+2*T,O=S.x+(S.width-g)/2),{borderX:O,borderWidth:g,borderY:Y,borderHeight:b,center:Q,originalShape:Z}})(m,l,r,f,C,M,P,t,n,s):{borderX:f,borderWidth:C,borderY:M,borderHeight:P,center:r,originalShape:t};return(({borderX:y,borderWidth:S,borderY:Q,borderHeight:V,center:A,originalShape:H})=>{const x=[y+S/2-A[0],Q+V/2-A[1]],[Z,R]=ye({point:x,rotation:-(H.rotation??0)});return{borderX:De(y+Z-x[0]),borderWidth:De(S),borderY:De(Q+R-x[1]),borderHeight:De(V)}})(a?((y,S,Q,V)=>{const A=S.x+S.width/2,H=S.y+S.height/2,x=Q?2*y.borderWidth+S.width:Math.abs(S.width+2*(y.borderWidth-S.width)),Z=V?2*y.borderHeight+S.height:Math.abs(S.height+2*(y.borderHeight-S.height));return{...y,borderHeight:Z,borderWidth:x,borderX:A-x/2,borderY:H-Z/2}})(w,l,c,p):w)},cs=(e,t)=>Te(e,qt,t),yt=(e,t,n=!1)=>{const s=Ut(e),i=cs(e,t);return{...e,path:s,computed:i,selection:nt(s,i,t,n)}},Ci=yt,ds=(e,t,n,s=!1,i=0,a=0)=>{const r={toolId:e.id,type:e.type,id:de(`${e.type}_`),x:t[0],y:t[1],width:i,height:a,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}};return yt(r,n,s)},wi=(e,t)=>{e.globalAlpha!==0&&t.path&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},qt=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),us=(e,t,n,[s,i]=[!1,!1])=>{const a=e[0]===.5?n.x+n.width/2:e[0]===0?n.x+(s?0:n.width):n.x+(s?n.width:0),r=e[1]===.5?n.y+n.height/2:e[1]===0?n.y+(i?0:n.height):n.y+(i?n.height:0);return Pi([a,r],n.rotation??0,t)},hs=(e,t,n,s,i,a,r,l)=>{let o=!1;if(i){o=ht(e,i,n,s,!0,a?20:void 0);const p=((d,u,m)=>{if(d.mode==="translate")return{mode:"translate",cursorStartPosition:m,originalShape:u,dateStart:Date.now()};if(d.mode==="rotate"){const{center:f}=u.computed;return{mode:"rotate",cursorStartPosition:m,originalShape:u,center:[f[0],f[1]]}}return d.mode==="resize"?{mode:"resize",cursorStartPosition:m,originalShape:u,anchor:d.anchor}:void 0})(o||{mode:"default"},i,n);if(p?.mode==="resize"||p?.mode==="rotate")return{shape:i,mode:p}}const c=t.find(p=>G(i).find(d=>p.id===d?.id)?o&&l?ht(e,p,n,s,!0,a?20:void 0):!!o:!!ys(e,p,n,s));if(c){if(l){const d=G(i).find(u=>u.id===c?.id)?Se(ki(i,c),s):Se(gs(i,[c]),s);return{shape:d,mode:{mode:"translate",cursorStartPosition:n,dateStart:Date.now(),originalShape:d}}}const p=G(i).find(d=>d.id===c?.id)?i:Se([c],s);return{shape:p,mode:{mode:"translate",cursorStartPosition:n,dateStart:Date.now(),originalShape:p}}}return l?{shape:i,mode:{mode:r?"selectionFrame":"default"}}:{shape:void 0,mode:{mode:r?"selectionFrame":"default"}}},Mi=(e,t,n=!0)=>{const s=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]];if(!n)return s;const i=[e.x+e.width/2,e.y+e.height/2];return s.map(a=>ye({point:[a[0],a[1]],origin:i,rotation:t}))},Se=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];let n=Number.POSITIVE_INFINITY,s=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY,a=Number.NEGATIVE_INFINITY;const r=e.some(p=>p.rotation!==e[0].rotation),l=r?0:e[0]?.rotation??0;for(const p of e){const{borders:d}=p.computed,u=Mi(d,p.rotation??0,r);n=Math.min(u[0][0],u[1][0],u[2][0],u[3][0],n),i=Math.max(u[0][0],u[1][0],u[2][0],u[3][0],i),s=Math.min(u[0][1],u[1][1],u[2][1],u[3][1],s),a=Math.max(u[0][1],u[1][1],u[2][1],u[3][1],a)}const o=ds({id:"test",type:"rect",settings:Tn},[n,s],t,!0,i-n,a-s),c=e.slice(1).reduce((p,d)=>{const u=d.style??{},m={};for(const f in u)p[f]!==void 0&&u[f]!==void 0&&p[f]===u[f]&&(m[f]=p[f]);return m},e[0].style??{});return{id:e.map(p=>p.id).join("-"),type:"group",shapes:e,rotation:l,visible:!0,locked:!1,selection:o.selection,x:o.x,y:o.y,width:o.width,height:o.height,style:c,computed:o.computed}},ps=(e,t)=>n=>{if(!n)return;const s=n.type==="group"?n.shapes.map(i=>e(i,t)):[e(n,t)];return Se(s,t)},G=e=>e?e.type==="group"?e.shapes:[e]:[],gs=(e,t)=>{const n=G(e);return[...new Set([...n,...t])]},ki=(e,t)=>G(e).filter(n=>n.id!==t.id),fs=e=>{const{clientX:t=0,clientY:n=0}="touches"in e&&e.touches[0]?e.touches[0]:"changedTouches"in e&&e.changedTouches[0]?e.changedTouches[0]:"clientX"in e?e:{};return{clientX:t,clientY:n}},vs=(e,t,n)=>{const{clientX:s,clientY:i}=fs(e),a=t.getBoundingClientRect();return[(s-a.left)/n.scaleRatio,(i-a.top)/n.scaleRatio]},it=(e,t,n)=>{const{clientX:s,clientY:i}=fs(e),a=t?.getBoundingClientRect()??{left:0,top:0,width:n.canvasSize.width,height:n.canvasSize.height};return[(s-a.left)*(n.canvasSize.width/a.width)/n.canvasSize.scaleRatio-n.canvasOffset[0],(i-a.top)*(n.canvasSize.height/a.height)/n.canvasSize.scaleRatio-n.canvasOffset[1]]},at=e=>"touches"in e,Pe=(e,t,[n,s])=>ye({origin:[n,s],point:e,rotation:t}),Pi=(e,t,[n,s])=>ye({origin:[n,s],point:e,rotation:-t}),St=(e,t,n)=>n?ss(e,{x:t[0],y:t[1],radius:n}):((s,i)=>i[0]>=s.x&&i[0]<=s.x+s.width&&i[1]>=s.y&&i[1]<=s.y+s.height)(e,t),ht=(e,t,n,s,i=!1,a=0)=>{if(t.locked)return!1;const{canvasSize:{scaleRatio:r}}=s,{borders:l,center:o}=t.computed,c=Pe(n,t.rotation??0,o),p=G(t);if(i){if(p.length!==1||p[0]?.type!=="line"&&p[0]?.type!=="polygon"&&p[0]?.type!=="curve"){if(p.length===1){if(St({x:l.x+l.width/2-7/r,y:l.y-$e/r-16/r,width:$e/r,height:$e/r},c,a))return{mode:"rotate"};for(const d of Yn)if(St({x:l.x+l.width*d[0]-7/r,y:l.y+l.height*d[1]-7/r,width:$e/r,height:$e/r},c,a))return{mode:"resize",anchor:d}}}else for(let d=0;d<p[0].points.length;d++)if(St({x:p[0].points[d][0]-7/r,y:p[0].points[d][1]-7/r,width:$e/r,height:$e/r},c,a))return{mode:"resize",anchor:d}}return(St(l,c,a)||!!(t.type==="curve"&&"path"in t&&t.path&&e.isPointInPath(t.path,c[0],c[1])))&&{mode:"translate"}},ms=(e,t,n,s,i=50)=>{if(t.locked||t.points.length<2)return!1;const{center:a}=t.computed,r=Pe(n,t.rotation??0,a);e.lineWidth=(t.style?.lineWidth??0)+i/s.canvasZoom;const l=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let o=0;o<l.length-1;o++){const c=mt({points:[l[o],l[o+1]]});if(e.isPointInStroke(c,r[0],r[1]))return{lineIndex:o}}return!1},ys=(e,t,n,s)=>{if(t.locked)return!1;const{center:i}=t.computed,a=Pe(n,t.rotation??0,i);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/s.canvasZoom,!!e.isPointInStroke(t.path,a[0],a[1])&&{mode:"translate"}):ht(e,t,n,s,!1)};function _t(e,t){const n=Math.max(e.x,t.x),s=Math.max(e.y,t.y),i=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));if(n<i&&s<a)return{x:n,y:s,width:i-n,height:a-s}}const Ss=({ctx:e,path:t,rect:n,offset:s,checkFill:i})=>{for(let a=0;a<s;a+=s/2)for(let r=0;r<s;r+=s/2)for(let l=a+n.x;l<n.x+n.width;l+=s)for(let o=r+n.y;o<n.y+n.height;o+=s)if(i?e.isPointInPath(t,l,o):e.isPointInStroke(t,l,o))return!0;return!1},Kt=(e,t,n,s)=>({border:Ut(n.borders),shapePath:e,anchors:[...t.points.map(i=>vt({x:i[0],y:i[1],radius:7/s.canvasSize.scaleRatio}))]}),be=[.05,.1,.25,.5,1,2,4,8],Jt=({size:e,zoom:t,newOffset:[n,s],canvasSize:i})=>e==="infinite"?{zoom:t,offset:[n,s]}:t<1?{zoom:t,offset:[-(i.realWidth-i.realWidth/t)/2,-(i.realHeight-i.realHeight/t)/2]}:{zoom:t,offset:[Ze(n,i.realWidth/t-i.realWidth,0),Ze(s,i.realHeight/t-i.realHeight,0)]},en=({size:e,canvasSize:t,currentOffset:n,currentZoom:s,zoom:i,centerPoint:a})=>{const r=e==="fixed"&&i<1?[t.realWidth/2,t.realHeight/2]:a,l=n[0]-(r[0]/s-r[0]/i),o=n[1]-(r[1]/s-r[1]/i);return{offset:e==="infinite"?[l,o]:i<1?[-(t.realWidth-t.realWidth/i)/2,-(t.realHeight-t.realHeight/i)/2]:[Ze(l,t.realWidth/i-t.realWidth,0),Ze(o,t.realHeight/i-t.realHeight,0)],zoom:i}},xs=e=>{const{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:s},canvasZoom:i,canvasOffset:a}=e;return{x:a[0]*i*s,y:a[1]*i*s,width:t*i,height:n*i}},bs=(e,t)=>{const{canvasZoom:n,size:s}=t;if(s!=="fixed"||n>=1)return;const i=xs(t);e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.closePath(),e.clip()},pt=(e,t)=>t.size!=="fixed"||e[0]>0&&e[0]<t.canvasSize.realWidth&&e[1]>0&&e[1]<t.canvasSize.realHeight,ji=(e,t)=>({x:e.x-e.radius-t.selectionPadding,width:2*(e.radius+t.selectionPadding),y:e.y-e.radius-t.selectionPadding,height:2*(e.radius+t.selectionPadding)}),Qs=(e,t)=>Te(e,ji,t),xt=(e,t)=>{const n=vt(e),s=Qs(e,t);return{...e,path:n,selection:nt(n,s,t),computed:s}},Li=xt,Cs=(e,t)=>Te(e,tn,t),ot=(e,t)=>{const n=rs(e),s=Cs(e,t);return{...e,path:n,selection:Kt(n,e,s,t),computed:s}},Vi=ot,tn=(e,t)=>{const n=Math.min(...e.points.map(a=>a[0]))-t.selectionPadding,s=Math.max(...e.points.map(a=>a[0]))+t.selectionPadding,i=Math.min(...e.points.map(a=>a[1]))-t.selectionPadding;return{x:n,width:s-n,y:i,height:Math.max(...e.points.map(a=>a[1]))+t.selectionPadding-i}},Zi=(e,t,n,s)=>{if(t<0||t>e.points.length-1)return e;const i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return ot({...e,points:i},s)},ws=(e,t,n,s=!1)=>{const i=[$(t[0],n),$(t[1],n)],a=Pe(i,e.rotation??0,e.computed.center),r={...e,points:s?e.points:[...e.points,a],tempPoint:s?a:void 0};return ot(r,n)},Ti=(e,t)=>{const n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2){const o=n[0]??[0,0],c=t.selectionPadding;return{x:o[0]-c,y:o[1]-c,width:2*c,height:2*c}}if(n.length<3)return tn({...e,points:n},t);const s=Xt(e,n);let i=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let o=1;o<s.length-2;o++){const c=s[o-1],p=s[o],d=s[o+1],u=s[o+2],{cp1:m,cp2:f}=Gt(c,p,d,u),C=xi(p,m,f,d);i=Math.min(i,C.minX),a=Math.max(a,C.maxX),r=Math.min(r,C.minY),l=Math.max(l,C.maxY)}return qt({x:i,y:r,width:a-i,height:l-r},t)},Ms=(e,t)=>Te(e,Ti,t),rt=(e,t)=>{const n=(i=>{const a=i.tempPoint?[...i.points,i.tempPoint]:i.points;if(a.length<2)return;if(a.length<3)return rs(i);const r=i.style?.closedPoints===1&&a.length>2,l=new Path2D;l.moveTo(...a[0]);const o=Xt(i,a);for(let c=1;c<o.length-2;c++){const p=o[c-1],d=o[c],u=o[c+1],m=o[c+2],{cp1:f,cp2:C}=Gt(p,d,u,m);l.bezierCurveTo(f[0],f[1],C[0],C[1],u[0],u[1])}return r&&l.closePath(),l})(e),s=Ms(e,t);return{...e,path:n,selection:Kt(n,e,s,t),computed:s}},Hi=rt,zi=(e,t,n,s)=>{if(t<0||t>e.points.length-1)return e;const i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return rt({...e,points:i},s)},ks=(e,t,n,s=!1)=>{const i=[$(t[0],n),$(t[1],n)],a=e.computed.center,r=Pe(i,e.rotation??0,a),l={...e,points:s?e.points:[...e.points,r],tempPoint:s?r:void 0};return rt(l,n)},Ai=(e,t)=>({x:e.x-e.radiusX-t.selectionPadding,width:2*(e.radiusX+t.selectionPadding),y:e.y-e.radiusY-t.selectionPadding,height:2*(e.radiusY+t.selectionPadding)}),Ps=(e,t)=>Te(e,Ai,t),bt=(e,t)=>{const n=(i=>{const a=new Path2D;return a.ellipse(i.x,i.y,i.radiusX,i.radiusY,0,0,2*Math.PI),a})(e),s=Ps(e,t);return{...e,path:n,selection:nt(n,s,t),computed:s}},Ei=bt,Ri=(e,t)=>Te(e,tn,t),js=(e,t)=>((n,s)=>({...n,path:bi(n),computed:Ri(n,s)}))({...e,id:de("triangle_"),type:"triangle"},t),Ii=(e,t)=>{e.globalAlpha!==0&&t.path&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},Ni=(e,t)=>({x:Math.min(e.points[0][0],e.points[1][0])-t.selectionPadding,width:Math.abs(e.points[0][0]-e.points[1][0])+2*t.selectionPadding,y:Math.min(e.points[0][1],e.points[1][1])-t.selectionPadding,height:Math.abs(e.points[0][1]-e.points[1][1])+2*t.selectionPadding}),Ls=(e,t)=>Te(e,Ni,t),Qt=(e,t)=>{const n=[];let s;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){const a=Math.PI/2-as({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||n.push(js(Vs(e.points[0],a,e.style),t)),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||n.push(js(Vs(e.points[1],a+Math.PI,e.style),t));const r=(({line:l,size:o,direction:c})=>{const p=Math.PI/2-as({targetVector:[l.points[0],l.points[1]]}),d=[l.points[0][0]+(l.points[1][0]-l.points[0][0])/2,l.points[0][1]+(l.points[1][1]-l.points[0][1])/2];let u,m;if(["start","both"].includes(c)){const f=ye({point:l.points[0],origin:d,rotation:-p});u=ye({point:[f[0],f[1]+o],origin:d,rotation:p})}else u=[...l.points[0]];if(["end","both"].includes(c)){const f=ye({point:l.points[1],origin:d,rotation:-p});m=ye({point:[f[0],f[1]-o],origin:d,rotation:p})}else m=[...l.points[1]];return{points:[u,m]}})({line:e,size:10+2*(e.style?.lineWidth??0),direction:e.style?.lineArrow===1?"start":e.style?.lineArrow===2?"end":"both"});s=mt(r)}else s=mt(e);const i=Ls(e,t);return{...e,path:s,selection:Kt(s,e,i,t),arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"},computed:i}},Di=Qt,Vs=(e,t,n)=>{const s=[ye({point:[0,0],rotation:t}),ye({point:[-(5+(n.lineWidth??0)),10+2*(n.lineWidth??0)],rotation:t}),ye({point:[5+(n.lineWidth??0),10+2*(n.lineWidth??0)],rotation:t})];return{points:[[e[0]+s[0][0],e[1]+s[0][1]],[e[0]+s[1][0],e[1]+s[1][1]],[e[0]+s[2][0],e[1]+s[2][1]]],style:{...n,fillColor:n.strokeColor,strokeColor:"transparent"}}},Zs=(e,t)=>Te(e,qt,t),Ct=(e,t)=>{const n=Zs(e,t);return{...e,selection:nt(void 0,n,t),computed:n}},Wi=Ct,nn=(e,t,n,s,i)=>{const[a,r]=((l,o,c,p,d=!1)=>{if(!(l&&o&&p&&c))return[_n,_n];const u=l/o;if(u>c/p){const f=d?c:Math.min(l,c);return[f,f/u]}const m=d?p:Math.min(o,p);return[m*u,m]})(e.width,e.height,n,s,!0);return Ct({toolId:Nt.id,type:"picture",id:de("picture_"),x:-i.canvasOffset[0]+i.canvasSize.realWidth/i.canvasZoom/2-a/2,y:-i.canvasOffset[1]+i.canvasSize.realHeight/i.canvasZoom/2-r/2,width:a,height:r,src:t,img:e},i)},Fi=(e,t,n,s)=>new Promise((i,a)=>{const r=new Image;r.onerror=()=>{a(new Error("Some images could not be loaded"))},setTimeout(()=>{a(new Error("Timeout while loading images"))},4e3),e instanceof File?((l,o,c,p,d,u)=>{Rs(c)?c.text().then(m=>{const f=Es(m);l.onload=async()=>{URL.revokeObjectURL(l.src);const C=nn(l,m,p,d,u);o(C)},l.src=f}):(l.onload=async()=>{URL.revokeObjectURL(l.src);const m=nn(l,l.src,p,d,u);o(m)},l.src=URL.createObjectURL(c))})(r,i,e,t,n,s):((l,o,c,p,d,u)=>{l.onload=()=>{URL.revokeObjectURL(l.src);const m=nn(l,c,p,d,u);o(m)},Is(c).then(m=>{l.src=m}).catch(()=>{l.src=""})})(r,i,e,t,n,s)}),sn=["Texte"],an=(e,t)=>Te(e,Bi,t),wt=(e,t)=>{const n=an(e,t);return{...e,selection:nt(void 0,n,t),computed:n}},Oi=wt,on=(e,t,n,s,i,a=ut)=>{e.font=`${i?"italic":""} ${s?"bold":""} 1px ${a}`;const r=t.map(l=>n/e.measureText(l).width);return Math.min(...r)||36},Bi=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),$i=(e,t,n,s)=>{const i={...t,value:n},a=((m,f,C,M,P,w=ut)=>{m.font=`${P?"italic":""} ${M?"bold":""} ${C}px ${w}`;const y=f.map(S=>m.measureText(S).width);return Math.max(...y)||20})(e,i.value,i.fontSize,i.style?.fontBold??!1,i.style?.fontItalic??!1,i.style?.fontFamily),r=i.fontSize*i.value.length,l={...i,width:a,height:r},{center:o}=an(l,s),[c,p]=us([1,1],t.computed.center,t),[d,u]=us([1,1],o,l,[!1,!1]);return{...l,x:l.x-(d-c),y:l.y-(u-p)}},Ts=(e,t,n,s)=>{const i=[$(n[0],s),$(n[1],s)];switch(t.type){case"brush":return((a,r,l)=>tt({toolId:a.id,type:a.type,id:de(`${a.type}_`),points:[[r]],scaleX:1,scaleY:1,style:{opacity:a.settings.opacity.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default}},l))(t,i,s);case"line":return((a,r,l)=>{const o={toolId:a.id,type:a.type,id:de(`${a.type}_`),points:[r,r],style:{opacity:a.settings.opacity.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default,lineArrow:a.settings.lineArrow.default}};return Qt(o,l)})(t,i,s);case"polygon":return((a,r,l)=>ot({toolId:a.id,type:a.type,id:de(`${a.type}_`),points:[r],style:{opacity:a.settings.opacity.default,fillColor:a.settings.fillColor.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default,closedPoints:a.settings.closedPoints.default}},l))(t,i,s);case"curve":return((a,r,l)=>rt({toolId:a.id,type:a.type,id:de(`${a.type}_`),points:[r],style:{opacity:a.settings.opacity.default,fillColor:a.settings.fillColor.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default,closedPoints:a.settings.closedPoints.default}},l))(t,i,s);case"rect":case"square":return ds(t,i,s);case"text":return((a,r,l,o)=>{const c=on(a,sn,150,r.settings?.fontBold.default??!1,r.settings?.fontItalic.default??!1,r.settings.fontFamily.default),p=c*(sn.length||1);return wt({toolId:r.id,type:r.type,id:de(`${r.type}_`),x:l[0]-150,y:l[1]-p,value:sn,fontSize:c,width:150,height:p,style:{opacity:r.settings.opacity.default,strokeColor:r.settings.strokeColor.default,fontFamily:r.settings.fontFamily.default,fontItalic:r.settings.fontItalic.default,fontBold:r.settings.fontBold.default}},o)})(e,t,i,s);case"ellipse":return((a,r,l)=>bt({toolId:a.id,type:a.type,id:de(`${a.type}_`),x:r[0],y:r[1],radiusX:0,radiusY:0,style:{opacity:a.settings.opacity.default,fillColor:a.settings.fillColor.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default}},l))(t,i,s);case"circle":return((a,r,l)=>xt({toolId:a.id,type:a.type,id:de(`${a.type}_`),x:r[0],y:r[1],radius:0,style:{opacity:a.settings.opacity.default,fillColor:a.settings.fillColor.default,strokeColor:a.settings.strokeColor.default,lineWidth:a.settings.lineWidth.default,lineDash:a.settings.lineDash.default}},l))(t,i,s)}},Hs=(e,t)=>{switch(t.type){case"brush":((n,s)=>{s.points.length<1||!s.path||n.globalAlpha!==0&&s.style?.strokeColor!=="transparent"&&n.globalAlpha!==0&&n.stroke(s.path)})(e,t);break;case"text":((n,s)=>{if(n.globalAlpha!==0&&s.style?.strokeColor&&s.style.strokeColor!=="transparent"){n.font=`${s.style?.fontItalic?"italic":""} ${s.style?.fontBold?"bold":""} ${s.fontSize}px ${s.style?.fontFamily??ut}`,n.textBaseline="top",n.fillStyle=s.style.strokeColor;for(let i=0;i<s.value.length;i++)n.fillText(s.value[i],s.x,s.y+i*s.fontSize,s.width)}})(e,t);break;case"line":((n,s)=>{if(n.globalAlpha!==0&&s.path){s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path);for(const i of s.arrows??[])me(n,i.style),Ii(n,i)}})(e,t);break;case"polygon":((n,s)=>{s.path&&n.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"curve":((n,s)=>{s.path&&n.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"circle":((n,s)=>{n.globalAlpha!==0&&s.path&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"ellipse":((n,s)=>{n.globalAlpha!==0&&s.path&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"rect":case"square":wi(e,t);break;case"picture":((n,s)=>{n.globalAlpha!==0&&(n.beginPath(),n.drawImage(s.img,s.x,s.y,s.width,s.height))})(e,t)}},zs=(e,t,n)=>{if(t.visible===!1)return;if(((i,a)=>{const r=(l=>{const{canvasSize:{width:o,height:c,scaleRatioWithNoZoom:p},canvasZoom:d,canvasOffset:u}=l;return{x:-u[0],y:-u[1],width:o/d/p,height:c/d/p}})(a);return!!_t(i.computed.boundingBox,r)})(t,n)){if(ft(e,n,t.rotation,t.computed.center),me(e,t.style),e.globalAlpha!==1)return((i,a)=>{const r=document.createElement("canvas"),l=r.getContext("2d");if(!l)throw new Error("No context found for canvas");const{outerBorders:o}=a.computed,c={width:2*o.width,height:2*o.height};r.width=c.width,r.height=c.height,l.translate(c.width/4-o.x,c.height/4-o.y),me(l,{...a.style,opacity:100}),Hs(l,a),i.drawImage(r,o.x-c.width/4,o.y-c.height/4)})(e,t),void e.restore();Hs(e,t),e.restore()}},Yi=(e,t,n,s,i,a,r)=>{const l=i[0]-s[0],o=i[1]-s[1],c=i[0]-t[0],p=i[1]-t[1],d={...e,rotation:mi((n.rotation??0)+Math.atan2(p,c)-Math.atan2(o,l),a,r)};return{...d,computed:Xi(d,a)}},Ui=(e,t,n,s,i,a,r,l)=>{switch(s.type){case"line":return((o,c,p,d)=>{const u=[$(o[0],d),$(o[1],d)],m=Pe(u,c.rotation??0,c.computed.center),f=xe(["points",p.anchor],m,c);return Qt(f,d)})(n,s,i,a);case"polygon":return((o,c,p,d)=>{const u=[$(o[0],d),$(o[1],d)],m=Pe(u,c.rotation??0,c.computed.center),f=xe(["points",p.anchor],m,c);return ot(f,d)})(n,s,i,a);case"curve":return((o,c,p,d)=>{const u=[$(o[0],d),$(o[1],d)],m=c.computed.center,f=Pe(u,c.rotation??0,m),C=xe(["points",p.anchor],f,c);return rt(C,d)})(n,s,i,a);case"brush":return((o,c,p,d,u,m)=>{const f=ts({...c,scaleX:1,scaleY:1},d),C=c.computed.borders,{borderX:M,borderHeight:P,borderY:w,borderWidth:y}=st(o,c,p,d,u,m),S=Math.max(0,f.width-2*d.selectionPadding),Q=Math.max(0,f.height-2*d.selectionPadding),V=Math.max(0,y-2*d.selectionPadding),A=Math.max(0,P-2*d.selectionPadding),H=S?V/S:1,x=Q?A/Q:1;if(!S||!Q)return c;const Z=De(M-C.x),R=De(w-C.y);return tt({...c,points:c.points.map(I=>I.map(([T,N])=>[T+Z,N+R])),scaleX:H,scaleY:x},d)})(n,s,i,a,r,l);case"circle":return((o,c,p,d,u)=>{const{borderX:m,borderHeight:f,borderY:C,borderWidth:M}=st(o,c,p,d,!0,u);return xt({...c,radius:Math.max(0,M/2-d.selectionPadding),x:m+M/2,y:C+f/2},d)})(n,s,i,a,l);case"ellipse":return((o,c,p,d,u=!1,m=!1)=>{const{borderX:f,borderHeight:C,borderY:M,borderWidth:P}=st(o,c,p,d,u,m);return bt({...c,radiusX:Math.max(0,P/2-d.selectionPadding),radiusY:Math.max(0,C/2-d.selectionPadding),x:f+P/2,y:M+C/2},d)})(n,s,i,a,r,l);case"rect":case"square":return((o,c,p,d,u=!1,m=!1)=>{const{borderX:f,borderHeight:C,borderY:M,borderWidth:P}=st(o,c,p,d,u,m);return yt({...c,width:Math.max(0,P-2*d.selectionPadding),height:Math.max(0,C-2*d.selectionPadding),x:f+d.selectionPadding,y:M+d.selectionPadding},d)})(n,s,i,a,t.type==="square"||r,l);case"text":return((o,c,p,d,u,m)=>{const{borderX:f,borderHeight:C,borderY:M,borderWidth:P}=st(c,p,d,u,!0,m),w=wt({...p,width:Math.max(0,P-2*u.selectionPadding),height:Math.max(0,C-2*u.selectionPadding),x:f+u.selectionPadding,y:M+u.selectionPadding},u);return{...w,fontSize:on(o,w.value,w.width,w.style?.fontBold??!1,w.style?.fontItalic??!1,w.style?.fontFamily)}})(e,n,s,i,a,l);case"picture":return((o,c,p,d,u)=>{const{borderX:m,borderHeight:f,borderY:C,borderWidth:M}=st(o,c,p,d,!0,u);return Ct({...c,width:Math.max(0,M-2*d.selectionPadding),height:Math.max(0,f-2*d.selectionPadding),x:m+d.selectionPadding,y:C+d.selectionPadding},d)})(n,s,i,a,l);default:return s}},rn=(e,t,n,s,i)=>{switch(t.type){case"rect":case"square":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return yt({...r,x:$(r.x+p[0],o),y:$(r.y+p[1],o)},o)})(e,t,n,s,i);case"ellipse":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return bt({...r,x:$(r.x+p[0],o),y:$(r.y+p[1],o)},o)})(e,t,n,s,i);case"circle":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return xt({...r,x:$(r.x+p[0],o),y:$(r.y+p[1],o)},o)})(e,t,n,s,i);case"picture":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return Ct({...r,x:$(r.x+p[0],o),y:$(r.y+p[1],o)},o)})(e,t,n,s,i);case"text":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return wt({...r,x:$(r.x+p[0],o),y:$(r.y+p[1],o)},o)})(e,t,n,s,i);case"line":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c);return Qt({...r,points:r.points.map(([d,u])=>[$(d+p[0],o),$(u+p[1],o)])},o)})(e,t,n,s,i);case"polygon":return((a,r,l,o,c)=>{const p=Re([a[0]-l[0],a[1]-l[1]],c),d=r.computed.borders;return ot({...r,points:r.points.map(([u,m])=>o.gridGap?[u+$(d.x+p[0],o)-d.x,m+$(d.y+p[1],o)-d.y]:[$(u+a[0]-l[0],o),$(m+a[1]-l[1],o)])},o)})(e,t,n,s,i);case"curve":return((a,r,l,o,c)=>{const p=r.computed.borders,d=Re([a[0]-l[0],a[1]-l[1]],c);return rt({...r,points:r.points.map(([u,m])=>o.gridGap?[u+$(p.x+d[0],o)-p.x,m+$(p.y+d[1],o)-p.y]:[$(u+d[0],o),$(m+d[1],o)])},o)})(e,t,n,s,i);case"brush":return((a,r,l,o,c)=>{const p=r.computed.borders,d=Re([a[0]-l[0],a[1]-l[1]],c),u=o.gridGap?$(p.x+d[0],o)-p.x:d[0],m=o.gridGap?$(p.y+d[1],o)-p.y:d[1];return tt({...r,points:r.points.map(f=>f.map(([C,M])=>[C+u,M+m]))},o)})(e,t,n,s,i);default:return t}},lt=(e,t)=>{switch(e.type){case"rect":case"square":return Ci(e,t);case"ellipse":return Ei(e,t);case"circle":return Li(e,t);case"picture":return Wi(e,t);case"text":return Oi(e,t);case"line":return Di(e,t);case"polygon":return Vi(e,t);case"curve":return Hi(e,t);case"brush":return vi(e,t);default:return e}},Xi=(e,t)=>{switch(e.type){case"rect":case"square":return cs(e,t);case"ellipse":return Ps(e,t);case"circle":return Qs(e,t);case"picture":return Zs(e,t);case"text":return an(e,t);case"line":return Ls(e,t);case"polygon":return Cs(e,t);case"curve":return Ms(e,t);case"brush":return ns(e,t)}},As=({ctx:e,shape:t,settings:n,selectionWidth:s,selectionColor:i,hoverMode:a,withAnchors:r=!0})=>{const{center:l}=t.computed;switch(n.debug&&((o,c,p,d)=>{c.selection&&d.debug&&(o.save(),o.scale(d.canvasSize.scaleRatio,d.canvasSize.scaleRatio),o.translate(d.canvasOffset[0],d.canvasOffset[1]),me(o,{fillColor:"transparent",strokeColor:"green",lineWidth:p/d.canvasSize.scaleRatio}),o.strokeRect(c.computed.boundingBox.x,c.computed.boundingBox.y,c.computed.boundingBox.width,c.computed.boundingBox.height),o.restore())})(e,t,s,n),ft(e,n,t.rotation,l),t.type){case"rect":case"square":case"circle":case"ellipse":case"picture":case"text":case"brush":((o,c,p,d,u,m)=>{if(c.selection&&(u.debug&&(me(o,{fillColor:"transparent",strokeColor:"red",lineWidth:d/u.canvasSize.scaleRatio}),o.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),me(o,{fillColor:"transparent",strokeColor:p,lineWidth:d/u.canvasSize.scaleRatio}),c.selection.shapePath?o.stroke(c.selection.shapePath):o.stroke(c.selection.border),m&&!c.locked)){c.selection.shapePath&&o.stroke(c.selection.border),c.selection.line&&o.stroke(c.selection.line),me(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/u.canvasSize.scaleRatio,shadowColor:p,shadowBlur:0});for(const f of c.selection.anchors)o.fill(f),o.stroke(f)}})(e,t,i,s,n,r);break;case"group":((o,c,p,d,u,m)=>{if(c.selection){if(u.debug&&(me(o,{fillColor:"transparent",strokeColor:"red",lineWidth:d/u.canvasSize.scaleRatio}),o.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),me(o,{fillColor:"transparent",strokeColor:p,lineWidth:d/u.canvasSize.scaleRatio}),m&&!c.locked){o.stroke(c.selection.border),c.selection.line&&o.stroke(c.selection.line),me(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/u.canvasSize.scaleRatio});for(const f of c.selection.anchors)o.fill(f),o.stroke(f)}c.shapes.forEach(f=>{o.restore(),me(o,{fillColor:"transparent",strokeColor:p,lineWidth:d/u.canvasSize.scaleRatio}),ft(o,u,f.rotation,f.computed.center),f.selection?.shapePath&&o.stroke(f.selection.shapePath)})}})(e,t,i,s,n,r);break;case"polygon":case"line":case"curve":(({ctx:o,shape:c,withAnchors:p,selectionWidth:d,selectionColor:u,hoverMode:m,settings:f})=>{if(c.selection&&(f.debug&&(me(o,{fillColor:"transparent",strokeColor:"red",lineWidth:d/f.canvasSize.scaleRatio}),o.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),me(o,{fillColor:"transparent",strokeColor:u,lineWidth:d/f.canvasSize.scaleRatio}),c.selection.shapePath&&o.stroke(c.selection.shapePath),p&&!c.locked)){me(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/f.canvasSize.scaleRatio,shadowColor:u,shadowBlur:0});for(let C=0;C<c.selection.anchors.length;C++){const M=c.selection.anchors[C];m.mode==="resize"&&m.anchor===C?(o.shadowBlur=10,o.fill(M),o.shadowBlur=0):o.fill(M),o.stroke(M)}}})({ctx:e,shape:t,withAnchors:r,selectionWidth:s,selectionColor:i,hoverMode:a,settings:n})}e.restore()},Gi=({ctx:e,selectionFrame:t,settings:n})=>{ft(e,n),((s,i,a)=>{me(s,{fillColor:"rgba(170,170,170, 0.1)",strokeColor:"rgb(170,170,170)",lineWidth:1/a.canvasSize.scaleRatio}),s.fillRect(i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1]),s.strokeRect(i[0][0],i[0][1],i[1][0]-i[0][0],i[1][1]-i[0][1])})(e,t.frame,n),e.restore()},ln=e=>e.filter(t=>t!=null),Es=e=>{const t=new DOMParser().parseFromString(e,"text/xml").getElementsByTagName("svg")[0];if(!t)return"";const n=t.getAttribute("width"),s=t.getAttribute("height");let i;if(n||s)i=e;else{const r=t.getAttribute("viewBox")??"0 0 300 300",[,,l,o]=r.split(" ");t.setAttribute("width",l??"300"),t.setAttribute("height",o??"300"),i=new XMLSerializer().serializeToString(t)}const a=new Blob([i],{type:"image/svg+xml"});return URL.createObjectURL(a)},Rs=e=>(e instanceof File?e.name:e).includes(".svg"),Is=e=>Rs(e)?fetch(e).then(t=>t.text()).then(t=>Es(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),Ns=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},qi=e=>e.src.includes("<svg")?e.src:(t=>{const n=document.createElement("canvas");n.width=t.width,n.height=t.height;const s=n.getContext("2d");return s?(s.drawImage(t,0,0),n.toDataURL("image/png")):""})(e.img),cn=({shapes:e,settings:t})=>{const n=document.createElement("canvas"),s=n.getContext("2d");if(!s)throw new Error("No context found for canvas");const{realHeight:i,realWidth:a}=t.canvasSize;n.width=a,n.height=i,s.clearRect(0,0,a,i),es(s);for(let r=e.length-1;r>=0;r--)zs(s,e[r],t);return n.toDataURL("image/png")},Ds=({shapes:e,settings:t,view:n})=>{if(n==="fitToShapes"&&!e.length)throw new Error("No image found to export");if(n==="fitToShapes"){const i=Math.min(...e.map(c=>c.computed.boundingBox.x)),a=Math.max(...e.map(c=>c.computed.boundingBox.x+c.computed.boundingBox.width)),r=Math.min(...e.map(c=>c.computed.boundingBox.y)),l=Math.max(...e.map(c=>c.computed.boundingBox.y+c.computed.boundingBox.height)),o={...t,canvasOffset:[-i,-r],canvasZoom:1,canvasSize:{realWidth:a-i,realHeight:l-r,width:a-i,height:l-r,scaleRatio:1,scaleRatioWithNoZoom:1}};return cn({shapes:e,settings:o})}if(n==="defaultView"){const i={...t,canvasOffset:[0,0],canvasZoom:1,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:1,scaleRatioWithNoZoom:1}};return cn({shapes:e,settings:i})}const s={...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}};return cn({shapes:e,settings:s})},_i=(e,t,n)=>{return i=dn(e,t,n),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(i))}`;var i},Ki=e=>{const t=["img","id","selection","path","arrows","tempPoint","computed"];return e.map(n=>n.type!=="picture"||n.src.startsWith("http")?Ot(t,n):Ot(t,{...n,src:qi(n)}))},dn=(e,t,n)=>({shapes:Ki(e),config:{width:t,height:n}}),Ws=(e,t)=>lt({...e,id:de(`${e.type}_`)},t),Ji=(e,t,n,s)=>{const i=v.useRef([]),a=v.useRef({dataChanged:[]}),[r,l]=v.useState(void 0),[o,c]=v.useState(void 0),[p,d]=v.useState(void 0),[u,m]=v.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),f=u.cursor>0,C=u.cursor<u.states.length-1,M=i.current.length>0,P=v.useCallback(()=>{m(g=>Kn(g.states[g.cursor]?.shapes,i.current)?g:{states:[...g.states.slice(0,g.cursor+1),{shapes:i.current,selectedShape:o,source:"user"}],cursor:g.cursor+1})},[o]),w=v.useCallback(g=>{i.current=[...g,...i.current]},[]),y=v.useCallback((g,b,k,L)=>{if(g.target&&"className"in g.target&&![Xn,Gn].includes(g.target.className)||!L)return void d(void 0);const j=i.current.find(E=>!G(o)?.map(W=>W.id).includes(E.id)&&!!ys(b,E,k,e));d(j)},[e,o]),S=v.useCallback(async(g,b=300,k=300)=>{const L=await Fi(g,b,k,e);return w([L]),P(),L},[w,P,e]),Q=v.useCallback((g,b=!1)=>{i.current=i.current.map(k=>g.find(L=>L.id===k.id)??k),c(k=>k&&Se(G(k).map(L=>g.find(j=>j.id===L.id)??L),e)),b&&P()},[P,e]),V=v.useCallback(g=>{const b=g.map(k=>Ot(["chosen"],k));i.current=b,P()},[P]),A=v.useCallback(g=>{const b=new Set(g.map(k=>k.id));c(k=>{const L=G(k).map(j=>j.id);return L&&b.size&&L.find(j=>b.has(j))?void 0:k}),i.current=i.current.filter(k=>!b?.has(k.id)),P()},[P]),H=v.useCallback(g=>{m(b=>{const k=g(b);return i.current=b.states[k]?.shapes??[],c(b.states[k]?.selectedShape),xe("cursor",k,b)})},[]),x=v.useCallback(()=>{H(g=>Math.max(0,g.cursor-1))},[H]),Z=v.useCallback(()=>{H(g=>Math.min(g.states.length-1,g.cursor+1))},[H]),R=v.useCallback((g,b)=>{c(void 0),i.current=g,m(k=>b.clearHistory?{states:[{shapes:g,selectedShape:void 0,source:b.source}],cursor:0}:{states:[...k.states.slice(0,k.cursor+1),{shapes:g,selectedShape:void 0,source:b.source}],cursor:k.cursor+1})},[]),I=v.useCallback((g,b)=>{const k=i.current,L=k.findIndex(z=>z.id===g),j=k.findIndex(z=>z.id===b);var E,W,F;V((E=k,F=j,(W=L)<0||F<0||W>E.length-1||F>E.length-1?E:W<F?[...E.slice(0,W),...E.slice(W+1,F+1),E[W],...E.slice(F+1,E.length)]:[...E.slice(0,F),E[W],...E.slice(F,W),...E.slice(W+1,E.length)]))},[V]),T=v.useCallback(g=>{const b=i.current,k=new Set(g.map(j=>j.id)),L=b.map(j=>k.has(j.id)?xe("visible",j.visible===!1,j):j);c(ps(j=>xe("visible",j.visible===!1,j),e)),V(L)},[V,e]),N=v.useCallback(g=>{const b=i.current,k=new Set(g.map(j=>j.id)),L=b.map(j=>k.has(j.id)?xe("locked",!j.locked,j):j);c(ps(j=>xe("locked",!j.locked,j),e)),V(L)},[V,e]),B=v.useCallback((g,b)=>{a.current.hasOwnProperty(g)&&(a.current[g]=[...a.current[g],b])},[]),O=v.useCallback((g,b)=>{if(a.current.hasOwnProperty(g))if(b){const k=a.current[g].indexOf(b);a.current[g]=[...a.current[g].slice(0,k),...a.current[g].slice(k+1)]}else a.current[g]=[]},[]);v.useEffect(()=>{const g=u.states[u.cursor],b=dn(g.shapes,t,n);for(const k of a.current.dataChanged)k(b,g.source)},[t,n,u]),v.useEffect(()=>{i.current=i.current.map(g=>lt(g,e)),c(g=>g===void 0?void 0:Se(G(g).map(b=>lt(b,e)),e))},[e]);const Y=v.useCallback((g,b)=>{l(k=>{const L=[k?.frame[0]??[b[0],b[1]],[b[0],b[1]]],j=i.current.filter(W=>((F,z,K,se)=>{const{selectionPadding:D}=se,{center:te,borders:U}=z.computed,ie=Pe(K[0],z.rotation??0,te),J=Pe(K[1],z.rotation??0,te),ce=Math.round(Math.min(ie[0],J[0])-D/2),ne=Math.round(Math.max(ie[0],J[0])+D),ue=Math.round(Math.min(ie[1],J[1])-D/2),X={x:ce,y:ue,width:ne-ce,height:Math.round(Math.max(ie[1],J[1])+D)-ue},le=_t(U,X);if(!le)return!1;if(U.width<=1||U.height<=1||!("path"in z)||!z.path)return!0;if(F.lineWidth=(z.style?.lineWidth??0)+10,z.type==="brush"){const He=z.points.flat(),ze=Math.min(...He.map(he=>he[0])),je=Math.min(...He.map(he=>he[1]));for(const he of z.points){if(he.length<1)break;if(he.length<2){const ee=ke(he[0],ze,je,z.scaleX,z.scaleY);if(ss(le,{x:ee[0],y:ee[1],radius:(z.style?.lineWidth??1)/2}))return!0}for(let ee=0;ee<he.length-1;ee++){const Le=ke(he[ee],ze,je,z.scaleX,z.scaleY),Ie=ke(he[ee+1],ze,je,z.scaleX,z.scaleY),Ce=_t({x:Math.min(Le[0],Ie[0]),y:Math.min(Le[1],Ie[1]),width:Math.abs(Le[0]-Ie[0]),height:Math.abs(Le[1]-Ie[1])},X);if(Ce){const Ue=new Path2D;if(Ue.moveTo(...Le),Ue.lineTo(...Ie),Ss({ctx:F,path:Ue,rect:Ce,offset:10,checkFill:!1}))return!0}}}return!1}const ae=!(!z.style?.fillColor||z.style?.fillColor==="transparent");return Ss({ctx:F,path:z.path,rect:le,offset:10,checkFill:ae})})(g,W,L,e)),E=Se(j,e);return c(s?Se(gs(k?.oldSelection,j),e):E),{oldSelection:k?.oldSelection,frame:L}})},[e,s]);return{registerEvent:B,unregisterEvent:O,shapesRef:i,selectedShape:o,hoveredShape:p,selectionFrame:r,setSelectionFrame:l,refreshSelectedShapes:Y,addShapes:w,addPictureShape:S,moveShapes:I,saveShapes:P,setSelectedShape:c,refreshHoveredShape:y,toggleShapeVisibility:T,toggleShapeLock:N,removeShape:A,updateShape:Q,backwardShape:x,forwardShape:Z,clearShapes:R,canGoBackward:f,canGoForward:C,canClear:M}},Fs=e=>{const t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];var s,i;return{diff:os(t,n),center:(i=n,[((s=t)[0]+i[0])/2,(s[1]+i[1])/2])}},ea=({canvasElt:e,canvasTransformation:t,canvasSize:n,size:s,setCanvasTransformation:i})=>{const a=v.useRef([]),[r,l]=v.useState(a.current.length>0),o=v.useRef(null),c=v.useRef(t);c.current=t;const p=v.useCallback(({startDiff:d,startZoom:u,startCenter:m,startOffset:f,currentDiff:C,currentCenter:M,isMoving:P,isZooming:w})=>{if(!e||!C||!d)return;const y=(({canvasBoundingRect:S,canvasSize:Q,size:V,startDiff:A,startZoom:H,startCenter:x,startOffset:Z,currentDiff:R,currentCenter:I,isMoving:T,isZooming:N})=>{const B=N?Ze(R/A*H,be[0],be[be.length-1]):H,O=T?[Z[0]+(I[0]-x[0])*(Q.width/S.width)/Q.scaleRatio/H,Z[1]+(I[1]-x[1])*(Q.height/S.height)/Q.scaleRatio/H]:[Z[0],Z[1]],Y=[(I[0]-S.left)/Q.scaleRatio,(I[1]-S.top)/Q.scaleRatio];return en({size:V,canvasSize:Q,currentOffset:O,currentZoom:H,zoom:B,centerPoint:Y})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:n,size:s,startDiff:d,startZoom:u,startCenter:m,startOffset:f,currentDiff:C,currentCenter:M,isMoving:P,isZooming:w});i(y)},[e,n,s,i]);v.useEffect(()=>{if(!e)return;const d=u=>{if(a.current=[...a.current,u],l(a.current.length>0),a.current.length===2){u.stopPropagation();const{diff:m,center:f}=Fs(a.current);o.current={startDiff:m,startCenter:f,startZoom:c.current.zoom,startOffset:c.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",d),()=>{e.removeEventListener("pointerdown",d)}},[e]),v.useEffect(()=>{if(!r)return;const d=m=>{const f=a.current.findIndex(C=>C.pointerId===m.pointerId);if(f>-1&&(a.current[f]=m),a.current.length===2&&o.current){const{diff:C,center:M}=Fs(a.current),P=o.current.isZooming||((y,S)=>Math.abs(y-S.startDiff)>30)(C,o.current),w=o.current.isMoving||P||((y,S)=>Math.abs(os(y,S.startCenter))>10)(M,o.current);o.current={...o.current,isMoving:w,isZooming:P},p({...o.current,currentDiff:C,currentCenter:M})}},u=m=>{a.current=a.current.filter(f=>f.pointerId!==m.pointerId),l(a.current.length>0)};return document.addEventListener("pointermove",d),document.addEventListener("pointerup",u),document.addEventListener("pointerout",u),document.addEventListener("pointercancel",u),document.addEventListener("pointerleave",u),()=>{document.removeEventListener("pointermove",d),document.removeEventListener("pointerup",u),document.removeEventListener("pointerout",u),document.removeEventListener("pointercancel",u),document.removeEventListener("pointerleave",u)}},[r,p])},Os={offset:[0,0],zoom:1},ta=({canvasSize:e,size:t,zoomEnabled:n,canvasElt:s})=>{const[i,a]=v.useState(Os),r=v.useRef(0),l=v.useCallback(p=>{a(({zoom:d})=>Jt({zoom:d,size:t,canvasSize:e,newOffset:p}))},[e,t]),o=v.useCallback(p=>{a(({offset:d,zoom:u})=>(({size:m,canvasSize:f,currentOffset:C,currentZoom:M,action:P})=>{const w=P==="default"?be[4]:P==="zoom"?be[Ze(be.length-1-be.slice(0).reverse().findIndex(S=>S<=M)+1,0,be.length-1)]:be[Ze(be.findIndex(S=>S>=M)-1,0,be.length-1)],y=[f.realWidth/2,f.realHeight/2];return en({size:m,canvasSize:f,currentOffset:C,currentZoom:M,zoom:w,centerPoint:y})})({size:t,canvasSize:e,currentOffset:d,currentZoom:u,action:p}))},[e,t]);ea({canvasElt:s,canvasTransformation:i,canvasSize:e,size:t,setCanvasTransformation:a});const c=v.useCallback(()=>{a(Os)},[]);return v.useEffect(()=>{if(!n||!s)return;const p=d=>{const u=d.ctrlKey,{deltaX:m,deltaY:f}=((w,y)=>{const S=Math.abs(w.deltaY)<50&&y<50,Q=w.ctrlKey,V=Jn()&&S&&Q;switch(w.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:16*w.deltaX,deltaY:16*w.deltaY};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:w.deltaX*window.innerHeight,deltaY:w.deltaY*window.innerHeight};default:return V?{deltaX:5*w.deltaX,deltaY:5*w.deltaY}:{deltaX:w.deltaX,deltaY:w.deltaY}}})(d,d.timeStamp-r.current);if(r.current=d.timeStamp,u){d.preventDefault();const w=vs(d,s,e);return void a(({offset:y,zoom:S})=>(({size:Q,canvasSize:V,currentOffset:A,currentZoom:H,delta:x,centerPoint:Z})=>{const R=Ze(H*(1-x/1e3),be[0],be[be.length-1]);return en({size:Q,canvasSize:V,currentOffset:A,currentZoom:H,zoom:R,centerPoint:Z})})({size:t,canvasSize:e,currentOffset:y,currentZoom:S,delta:f,centerPoint:w}))}const C=d.shiftKey,[M,P]=C?[f,m]:[m,f];a(({offset:w,zoom:y})=>{const S=[w[0]-M/y,w[1]-P/y],Q=Jt({zoom:y,size:t,canvasSize:e,newOffset:S});return Q.offset[0]===w[0]&&Q.offset[1]===w[1]||d.preventDefault(),Q})};return s.addEventListener("wheel",p,{passive:!1}),()=>{s.removeEventListener("wheel",p)}},[s,t,e,n]),{setCanvasTransformation:a,setCanvasOffset:l,setCanvasZoom:o,resetZoom:c,canvasTransformation:i}},Bs=(e,t=!1)=>{const n=(i,a)=>{if(Array.isArray(i))return a},s=e.map(i=>{if(typeof i!="object")return null;switch(i.type){case"brush":return Ve(n,Hn,i);case"circle":return Ve(n,Nn,i);case"curve":return Ve(n,En,i);case"ellipse":return Ve(n,Dn,i);case"line":return Ve(n,zn,i);case"polygon":return Ve(n,An,i);case"rect":return Ve(n,Rn,i);case"square":return Ve(n,In,i);case"text":return Ve(n,Wn,i)}return null});return ln(t?[...s,Nt]:s)},na=({addShapes:e,drawCanvasRef:t,setActiveTool:n,refreshHoveredShape:s,shapes:i,selectionMode:a,activeTool:r,isInsideComponent:l,setCanvasOffset:o,selectedShape:c,canvasOffsetStartData:p,refreshSelectedShapes:d,setSelectedShape:u,setSelectionFrame:m,setCanvasOffsetStartData:f,updateSingleShape:C,saveShapes:M,setSelectionMode:P,setCanvasMoveAcceleration:w,settings:y,isShiftPressed:S,isAltPressed:Q,withFrameSelection:V,isSpacePressed:A})=>{const[H,x]=v.useState({mode:"default"}),{registerDoubleClickEvent:Z,unRegisterDoubleClickEvent:R}=(()=>{const g=v.useRef(void 0),b=v.useRef(void 0),k=L=>{const j=Date.now();g.current&&j<g.current+300&&b.current?.(L),g.current=Date.now()};return{registerDoubleClickEvent:(L,j)=>{b.current=j,L.addEventListener("click",k),L.addEventListener("touchend",k)},unRegisterDoubleClickEvent:L=>{L.removeEventListener("click",k),L.removeEventListener("touchend",k)}}})(),I=v.useRef(null);I.current=g=>((b,k,L,j,E,W,F,z,K,se,D,te,U,ie,J)=>{if(at(b)&&b.touches.length>1)return;const ce=k.current?.getContext("2d");if(!ce)return;const ne=it(b,k.current,D);if(j.mode==="selectionFrame"){se(ce,ne,D);const X=vs(b,k.current,D.canvasSize);return void J([Math.ceil(Ze(X[0]*D.canvasZoom<50?X[0]*D.canvasZoom-50:X[0]*D.canvasZoom>D.canvasSize.width/D.canvasSize.scaleRatioWithNoZoom-50?X[0]*D.canvasZoom-(D.canvasSize.width/D.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/D.canvasZoom),Math.ceil(Ze(X[1]*D.canvasZoom<50?X[1]*D.canvasZoom-50:X[1]*D.canvasZoom>D.canvasSize.height/D.canvasSize.scaleRatioWithNoZoom-50?X[1]*D.canvasZoom-(D.canvasSize.height/D.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/D.canvasZoom)])}if(E!==void 0)return void K([ne[0]+D.canvasOffset[0]-E.start[0],ne[1]+D.canvasOffset[1]-E.start[1]]);if(j.mode==="preview"){const X=G(L)[0];if(X?.type==="curve"){const le=ks(X,ne,D,!0);return void ie(Se([le],D))}if(X?.type==="polygon"){const le=ws(X,ne,D,!0);return void ie(Se([le],D))}}const ue=pt(ne,D);if(at(b)||F(b,ce,ne,ue),L===void 0||L.locked)W({mode:"default",outOfView:!ue});else if(j.mode==="default"||j.mode==="textedition"){if(!ue)return void W({mode:"default"});W(ht(ce,L,ne,D,!0)||{mode:"default"})}else{const X=k.current?.getContext("2d");if(!X)return;const le=yi(X,L,ne,j,D,te,U);z(G(le))}})(g,t,c,a,p,x,s,C,o,d,y,S,Q,u,w),v.useEffect(()=>{if(l){const g=b=>I.current?.(b);return document.addEventListener("mousemove",g),document.addEventListener("touchmove",g),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("touchmove",g)}}},[l]);const{isBrushShapeDoneOnMouseUp:T}=y,N=v.useRef(null);N.current=g=>{if(at(g)&&g.touches.length>1)return;const b=t.current?.getContext("2d");if(!b)return;if("button"in g&&g.button===2)return u(void 0),n(Ee),P({mode:"default"}),void m(void 0);if(p)return void f(void 0);if(a.mode==="textedition"||a.mode==="preview")return;const k=it(g,t.current,y);if(a.mode==="translate"&&Date.now()-a.dateStart<=500&&k[0]===a.cursorStartPosition[0]&&k[1]===a.cursorStartPosition[1]){if(!(g.ctrlKey||g.shiftKey||g.metaKey)){const{shape:L}=hs(b,i,k,y,void 0,at(g),V,!1);u(L)}return P({mode:"default"}),m(void 0),void M()}a.mode!=="default"&&(a.mode==="brush"&&T&&u(void 0),P({mode:"default"}),m(void 0),M())},v.useEffect(()=>{if(l){const g=b=>N.current?.(b);return document.addEventListener("mouseup",g),document.addEventListener("touchend",g),()=>{document.removeEventListener("mouseup",g),document.removeEventListener("touchend",g)}}},[l]);const B=!y.features.edition&&y.features.zoom,O=!y.features.edition&&!y.features.zoom,Y=v.useRef(null);return Y.current=(g,b,k)=>{if(g.preventDefault(),at(g)&&g.touches.length>1)return;const L=b?.getContext("2d");if(!L)return;b.focus();const j=it(g,t.current,y),E="button"in g&&g.button===1;if(!("button"in g&&g.button===2)){if(E||k||r.type==="move")f({start:j,originalOffset:y.canvasOffset});else if(!B){if(!pt(j,y))return u(void 0),void P({mode:"default"});if(r.type==="selection"){const W=g.ctrlKey||g.shiftKey||g.metaKey,{shape:F,mode:z}=hs(L,i,j,y,c,at(g),V,W);u(F),P(z),z.mode==="selectionFrame"&&m({oldSelection:F,frame:[[j[0],j[1]],[j[0],j[1]]]})}else if(Un.some(W=>W===r.type)){const W=G(c)[0],F=t.current?.getContext("2d");if(!F)return;if(r.type==="brush"){if(W?.type==="brush"){const z=((K,se,D)=>{const te={...K,points:xe(K.points.length,[[Math.round(se[0]),Math.round(se[1])]],K.points)};return tt(te,D)})(W,j,y);C([z])}else{const z=Ts(F,r,j,y);if(!z)return;e([z]),u(Se([z],y))}P({mode:"brush"})}else if(a.mode!=="preview"||W?.type!=="polygon"&&W?.type!=="curve"){if(r.type!=="picture"){const z=Ts(F,r,j,y);if(!z)return;e([z]);const K=Se([z],y);u(K),z.type==="polygon"||z.type==="curve"?P({mode:"preview"}):(n(Ee),P({mode:"resize",cursorStartPosition:[j[0]+y.selectionPadding,j[1]+y.selectionPadding],originalShape:K,anchor:z.type==="line"?0:[1,1]}))}}else{const z=W.type==="polygon"?ws(W,j,y):ks(W,j,y);u(Se([z],y)),C([z],!0)}}}}},v.useEffect(()=>{if(O)return;const g=t.current;if(!g)return;const b=k=>Y.current?.(k,g,A);return g.addEventListener("mousedown",b,{passive:!1}),g.addEventListener("touchstart",b,{passive:!1}),()=>{g.removeEventListener("mousedown",b),g.removeEventListener("touchstart",b)}},[O,t,A]),v.useEffect(()=>{const g=t.current,b=t.current?.getContext("2d");if(!(!g||!b))return l?(Z(g,k=>{if(r.type==="selection"){if(G(c).length!==1)return;const L=G(c)[0];if(L?.type==="text"){const j=it(k,t.current,y);return pt(j,y)?void(ht(b,c,j,y)&&P({mode:"textedition",defaultValue:L.value})):void 0}if(L?.type==="polygon"){const j=it(k,t.current,y);if(!pt(j,y))return;const E=ms(b,L,j,y);return void(E&&C([Zi(L,E.lineIndex,j,y)]))}if(L?.type==="curve"){const j=it(k,t.current,y);if(!pt(j,y))return;const E=((W,F,z,K,se=50)=>{if(F.locked||F.points.length<2)return!1;if(F.points.length<3)return ms(W,F,z,K,se);const{center:D}=F.computed,te=Pe(z,F.rotation??0,D);W.lineWidth=(F.style?.lineWidth??0)+se/K.canvasZoom;const U=Xt(F,F.points),ie=new Path2D;ie.moveTo(...U[0]);for(let J=1;J<U.length-2;J++){const ce=U[J-1],ne=U[J],ue=U[J+1],X=U[J+2],{cp1:le,cp2:ae}=Gt(ce,ne,ue,X);if(ie.bezierCurveTo(le[0],le[1],ae[0],ae[1],ue[0],ue[1]),W.isPointInStroke(ie,te[0],te[1]))return{lineIndex:J-1}}return!1})(b,L,j,y);return void(E&&C([zi(L,E.lineIndex,j,y)]))}}}),()=>{R(g)}):void 0},[C,Z,R,l,t,r,c,P,y]),{hoverMode:H}},$s=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>$s(t)).join(""):e.nodeValue??"",sa=({disabled:e=!1,shape:t,defaultValue:n,updateValue:s,saveShapes:i,settings:a})=>{const r=v.useRef(null),l=v.useRef(i);v.useEffect(()=>{if(!r.current)return;const c=r.current,p=d=>{d.preventDefault();const u=d.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,u)};c.addEventListener("paste",p),c.innerText="";for(const d of n){const u=document.createElement("div");d===""?u.innerHTML="<br/>":u.innerText=d,c.appendChild(u)}return c.focus(),()=>{c.removeEventListener("paste",p)}},[n]),v.useEffect(()=>{const c=l.current;return()=>{c()}},[]);const o=v.useMemo(()=>{const{borders:c,center:p}=t.computed;return ye({point:[c.x,c.y],rotation:-(t.rotation??0),origin:p})},[t]);return h.jsx("div",{className:"react-paint-editor-toolbox-edittextbox",ref:r,"data-fontbold":t.style?.fontBold??!1,"data-fontitalic":t.style?.fontItalic??!1,contentEditable:!e,onInput:c=>{const p=Array.from(c.target.childNodes).map(d=>$s(d));s(p)},style:{"--react-paint-editor-toolbox-edittextbox-transform":`translate3D(${(o[0]+a.canvasOffset[0])*a.canvasSize.scaleRatio}px, ${(o[1]+a.canvasOffset[1])*a.canvasSize.scaleRatio}px, 0) rotate(${Yt(t.rotation??0)}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??ut}})},ia=(e,t,n,s,i)=>{es(e),((a,r)=>{const{canvasZoom:l,size:o,canvasSize:{width:c,height:p}}=r;if(o!=="fixed"||l>=1)return;a.fillStyle="#f5f5f5",a.fillRect(0,0,c,p);const d=xs(r);a.clearRect(d.x,d.y,d.width,d.height),bs(a,r)})(e,n),((a,r)=>{const{canvasSize:{width:l,height:o},gridGap:c,canvasOffset:p,canvasSize:{scaleRatio:d}}=r;if(!c)return;a.strokeStyle="rgb(220,220,220)",a.lineWidth=1,a.save(),a.scale(d,d),a.beginPath();const u=p[0]%c,m=p[1]%c,f=Math.ceil(l/d/c)+2,C=Math.ceil(o/d/c)+2;for(let M=-5;M<f;M++)a.moveTo(u+(M+1)*c,m-c),a.lineTo(u+(M+1)*c,m+o/d+c);for(let M=-5;M<C;M++)a.moveTo(u-c,m+(M+1)*c),a.lineTo(u+l/d+c,m+(M+1)*c);a.stroke(),a.restore()})(e,n);for(let a=s.length-1;a>=0;a--)t.mode==="textedition"&&s[a]===i||zs(e,G(i).find(r=>r.id===s[a].id)??s[a],n)},aa=v.forwardRef(({canGrow:e,shapes:t,addShapes:n,updateSingleShape:s,selectedShape:i,setSelectedShape:a,setSelectionFrame:r,hoveredShape:l,selectionFrame:o,refreshHoveredShape:c,refreshSelectedShapes:p,saveShapes:d,activeTool:u,setActiveTool:m,canvasOffsetStartData:f,setCanvasOffsetStartData:C,setCanvasOffset:M,setCanvasMoveAcceleration:P,isInsideComponent:w,selectionMode:y,setSelectionMode:S,selectionWidth:Q,selectionColor:V,settings:A,isEditMode:H,isShiftPressed:x,isAltPressed:Z,isSpacePressed:R,withFrameSelection:I,withSkeleton:T},N)=>{const B=v.useRef(null),O=v.useRef(null),Y=A.canvasSize,g=H,b=H?0:-1;v.useImperativeHandle(N,()=>B.current);const{hoverMode:k}=na({addShapes:n,drawCanvasRef:B,setActiveTool:m,shapes:t,selectionMode:y,activeTool:u,isInsideComponent:w,setCanvasOffset:M,selectedShape:i,canvasOffsetStartData:f,setCanvasOffsetStartData:C,setSelectedShape:a,setSelectionFrame:r,refreshHoveredShape:c,refreshSelectedShapes:p,updateSingleShape:s,saveShapes:d,setSelectionMode:S,setCanvasMoveAcceleration:P,isShiftPressed:x,isAltPressed:Z,withFrameSelection:I,settings:A,isSpacePressed:R}),L=v.useCallback(E=>{const W=G(i)[0];if(W?.type!=="text")return;const F=B.current?.getContext("2d");if(!F)return;const z=lt($i(F,W,E,A),A);s([z])},[s,i,A]),j=E=>{if(H)return E.preventDefault(),E.stopPropagation(),!1};return v.useEffect(()=>{const E=B.current?.getContext("2d");E&&window.requestAnimationFrame(()=>ia(E,y,A,t,i))},[t,y,i,A]),v.useEffect(()=>{const E=O.current?.getContext("2d");E&&window.requestAnimationFrame(()=>((W,F,z,K,se,D,te,U,ie,J,ce)=>{W.reset(),bs(W,z),ce&&U&&!G(te).find(ne=>ne.id===U.id)&&K.type==="selection"&&F.mode==="default"&&As({ctx:W,shape:U,settings:z,selectionWidth:se,selectionColor:D,hoverMode:ie,withAnchors:!1}),te&&K.type!=="brush"&&As({ctx:W,shape:te,settings:z,selectionWidth:se,selectionColor:D,hoverMode:ie,withAnchors:F.mode!=="textedition"}),J&&Gi({ctx:W,selectionFrame:J,settings:z})})(E,y,A,u,Q,V,i,l,k,o,T))},[l,k,o,y,i,u,A,Q,V,T]),h.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":f?"grabbing":k.outOfView?"default":k.mode==="resize"?"pointer":u.type!=="selection"&&u.type!=="move"?"crosshair":k.mode==="translate"?"move":k.mode==="rotate"||u.type==="move"||R?"grab":"default"},children:h.jsxs("div",{className:"react-paint-canvas-container","data-grow":e,children:[h.jsx("canvas",{className:Xn,ref:B,"data-grow":e,width:Y.width,height:Y.height,onContextMenu:j,tabIndex:b}),g&&h.jsx("canvas",{className:Gn,ref:O,width:Y.width,height:Y.height,"data-grow":e,onContextMenu:j}),H&&y.mode==="textedition"&&G(i)[0]?.type==="text"&&h.jsx(sa,{disabled:!A.features.edition,shape:G(i)[0],defaultValue:y.defaultValue,updateValue:L,saveShapes:d,settings:A})]})})}),Ys="ArrowUp",Us="ArrowDown",Xs="ArrowLeft",Gs="ArrowRight",oa="Delete",ra="Backspace",la="Escape",qs="Shift",_s="Alt",Ks="Option",Mt=" ",ca="z",da="Z",ua="y",ha="Y",pa="+",ga="-",fa="0",Js="copy",ei="paste",va=({isInsideComponent:e,isInsideCanvas:t,selectedShape:n,isEditingText:s,settings:i,setSelectedShape:a,setActiveTool:r,setCanvasZoom:l,resetZoom:o,setSelectionMode:c,setSelectionFrame:p,removeShape:d,pasteShapes:u,updateShapes:m,backwardShape:f,forwardShape:C,setShiftPressed:M,setAltPressed:P,setIsSpacePressed:w})=>{const[y,S]=v.useState(void 0);return v.useEffect(()=>{const Q=x=>{n&&(s||(x.preventDefault(),S({...n})))},V=x=>{y&&(s||(x.preventDefault(),u(((Z,R)=>G(Z).map(I=>({...rn([20,20],I,[0,0],R,!1),id:de(`${I.type}_`)})))(y,i))))},A=x=>{switch(x.key){case qs:M(!1);break;case _s:case Ks:P(!1);break;case Mt:w(!1)}},H=x=>{if(x.metaKey||x.ctrlKey){if(x.key===da||x.key===ca)return x.preventDefault(),x.stopPropagation(),void(x.shiftKey?C():f());if(!Jn()&&(x.key===ha||x.key===ua))return x.preventDefault(),x.stopPropagation(),void C();if(x.key===pa)return x.preventDefault(),x.stopPropagation(),void l("zoom");if(x.key===ga)return x.preventDefault(),x.stopPropagation(),void l("unzoom");if(x.key===fa)return x.preventDefault(),x.stopPropagation(),void o()}if(x.key===qs)return x.preventDefault(),x.stopPropagation(),void M(!0);if(x.key===Mt&&t)return x.preventDefault(),x.stopPropagation(),void w(!0);if(x.key===_s||x.key===Ks)return x.preventDefault(),x.stopPropagation(),void P(!0);if(!n)return;if(x.key===la)return a(void 0),r(Ee),c({mode:"default"}),void p(void 0);if(s)return;const Z={[Xs]:[i.gridGap?-i.gridGap:-1,0],[Gs]:[i.gridGap?i.gridGap:1,0],[Us]:[0,i.gridGap?i.gridGap:1],[Ys]:[0,i.gridGap?-i.gridGap:-1]};switch(x.key){case Xs:case Gs:case Us:case Ys:x.preventDefault(),x.stopPropagation(),m(((R,I,T,N,B)=>G(I).map(O=>rn(R,O,T,N,B)))(Z[x.key],n,[0,0],i,!1));break;case oa:case ra:x.preventDefault(),x.stopPropagation(),d(G(n))}};if(e)return document.addEventListener("keydown",H),document.addEventListener("keyup",A),document.addEventListener(Js,Q),document.addEventListener(ei,V),()=>{document.removeEventListener("keydown",H),document.removeEventListener("keyup",A),document.removeEventListener(Js,Q),document.removeEventListener(ei,V)}},[e,t,y,s,n,i,m,d,a,u,f,C,M,P,r,c,p,l,o,w]),{}},ma=({isLoading:e=!1})=>{const[t,n]=v.useState("hidden");return v.useEffect(()=>{if(!e){n("fadeOut");const s=setTimeout(()=>n("hidden"),300);return()=>{clearTimeout(s)}}n("visible")},[e]),t==="hidden"?null:h.jsx("div",{className:"react-paint-editor-loading","data-loading":t,style:{"--react-paint-editor-loading-zindex":pi,"--react-paint-editor-loading-transition-duration":"300ms"},children:h.jsxs("div",{className:"react-paint-editor-loader",children:[h.jsx("div",{}),h.jsx("div",{}),h.jsx("div",{}),h.jsx("div",{})]})})},ya="infos",Sa=4e3,xa=({type:e,text:t,duration:n})=>{const[s,i]=v.useState(!1);return v.useEffect(()=>{const a=setTimeout(()=>{i(!0)},100),r=setTimeout(()=>{i(!1)},n-500-100);return()=>{clearTimeout(a),clearTimeout(r)}},[n]),h.jsx("div",{className:"react-paint-editor-snackbar","data-is-shown":+s,"data-type":e,style:{"--react-paint-editor-panel-transition-duration":"500ms"},children:t})},ba=({snackbarList:e})=>h.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":gi},children:e.map(t=>h.jsx(xa,{...t},t.id))}),Qa=v.forwardRef((e,t)=>{const{hidden:n=!1,disabled:s=!1,selected:i=!1,icon:a,children:r,className:l="",title:o,onClick:c,...p}=e,d=s?-1:0,u=v.useRef(null);return v.useImperativeHandle(t,()=>u.current),h.jsxs("label",{className:`react-paint-editor-button ${l}`,title:o,onClick:c,"data-disabled":+s,"data-selected":+i,"data-hidden":+n,tabIndex:d,onKeyDown:m=>{m.key===Mt&&(m.preventDefault(),m.stopPropagation())},onKeyUp:m=>{m.preventDefault(),m.stopPropagation(),m.key===Mt&&u.current?.click()},children:[h.jsx("input",{ref:u,disabled:s,...p}),h.jsxs("span",{className:"react-paint-editor-button-content",children:[r&&h.jsx("span",{className:"react-paint-editor-button-children",children:r}),a&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:a}})]})]})}),q=v.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color")return h.jsx(Qa,{...e,ref:t});const{hidden:n=!1,disabled:s=!1,selected:i=!1,icon:a,children:r,type:l="button",className:o="",...c}=e;return h.jsx("button",{className:`react-paint-editor-button ${o}`,ref:t,disabled:s,"data-disabled":+s,"data-selected":+i,"data-hidden":+n,type:l,...c,children:h.jsxs("span",{className:"react-paint-editor-button-content",children:[r&&h.jsx("span",{className:"react-paint-editor-button-children",children:r}),a&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:a}})]})})}),Ye=({children:e,title:t="",className:n="",position:s="bottom",fitContainer:i=!1,alignment:a="center",style:r,...l})=>h.jsxs("div",{className:`react-paint-editor-panel ${n}`,"data-fitcontainer":i,"data-position":s,"data-alignment":a,style:{...r,"--react-paint-editor-panel-zindex":Zn},...l,children:[t&&h.jsx("h3",{className:"react-paint-editor-panel-title",children:t}),e]}),Ca=e=>{switch(e){case"brush":return yn;case"line":return Qn;case"polygon":return Rt;case"curve":return Cn;case"rect":case"square":return At;case"circle":case"ellipse":return Et;case"text":return bn;case"picture":return It;case"group":return'<svg><path d="M3.333 17.5V16.667H7.5V17.5ZM3.333 14.167V13.333H9.167V14.167ZM3.333 10.833V10H10.833V10.833ZM3.333 7.5V6.667H12.5V7.5ZM3.333 4.167V3.333H13.333V4.167ZM3.333 0.833V0H16.667V0.833Z"/></svg>';case"triangle":return""}},wa=({disabled:e=!1,shape:t,selected:n,layoutDragging:s,toggleShapeVisibility:i,toggleShapeLock:a,setLayoutDragging:r,handleRemove:l,handleSelect:o,onMoveShapes:c})=>{const p=v.useRef(null),{isOver:d}=(({disabled:u=!1,ref:m,shape:f,layoutDragging:C,setLayoutDragging:M,handleSelect:P,onMoveShapes:w})=>{const[y,S]=v.useState(!1);return v.useEffect(()=>{C||S(!1)},[C]),v.useEffect(()=>{const Q=m.current;if(!Q)return;const V=()=>{M(void 0)},A=I=>(I.preventDefault&&I.preventDefault(),!1),H=I=>{P([f]),I.dataTransfer&&(I.dataTransfer.effectAllowed="move",I.dataTransfer.setData("draggableShapeId",f.id),M(f.id))},x=()=>{C!==f.id&&S(!0)},Z=()=>{S(!1)},R=I=>(I.stopPropagation(),I.dataTransfer&&w(I.dataTransfer.getData("draggableShapeId"),f.id),!1);return u||(Q.addEventListener("dragstart",H),Q.addEventListener("dragend",V),Q.addEventListener("dragover",A),Q.addEventListener("dragenter",x),Q.addEventListener("dragleave",Z),Q.addEventListener("drop",R)),()=>{u||(Q.removeEventListener("dragstart",H),Q.removeEventListener("dragend",V),Q.removeEventListener("dragover",A),Q.removeEventListener("dragenter",x),Q.removeEventListener("dragleave",Z),Q.removeEventListener("drop",R))}},[u,m,f,M,P,w,C]),{isOver:y}})({disabled:e,ref:p,shape:t,layoutDragging:s,setLayoutDragging:r,handleSelect:o,onMoveShapes:c});return h.jsxs("div",{className:"react-paint-editor-layout","data-disabled":+e,draggable:!e,"data-is-dragging":+(s===t.id),"data-is-over":+d,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),o([t]))},"data-selected":+n,ref:p,tabIndex:-1,children:[h.jsx("span",{dangerouslySetInnerHTML:{__html:Ca(t.type)}}),h.jsx("span",{children:t.id}),h.jsx("div",{className:"react-paint-editor-layouts-separator"}),h.jsx(q,{className:"react-paint-editor-layouts-visible-button",title:t.visible?"Hide":"Show","data-visible":t.visible!==!1,disabled:e,selected:n,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),i([t]))},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>'}),h.jsx(q,{className:"react-paint-editor-layouts-locked-button",title:t.locked?"Locked":"Unlocked","data-locked":!!t.locked,disabled:e,selected:n,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),a([t]))},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>'}),h.jsx(q,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:u=>{e||(u.preventDefault(),u.stopPropagation(),l([t]))},icon:Sn})]})},Ma=({gridFormat:e,setGridFormat:t,settings:n,shapes:s,removeShape:i,toggleShapeVisibility:a,toggleShapeLock:r,selectedShapes:l,moveShapes:o,selectShapes:c,isLayoutPanelShown:p})=>{const[d,u]=v.useState(void 0),m=!n.features.edition;return p?h.jsx(Ye,{alignment:"right",className:"react-paint-editor-layouts-panel",children:h.jsx("div",{className:"react-paint-editor-layouts-panel-content",children:h.jsxs("div",{className:"react-paint-editor-layouts-scrolling-content",children:[h.jsxs("div",{className:"react-paint-editor-layouts-row",children:[h.jsx("span",{className:"react-paint-editor-layouts-subtitle",children:"Grid"}),h.jsx(q,{icon:'<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>',className:"react-paint-editor-layouts-grid-button",selected:e==="none",disabled:m,onClick:()=>t("none")}),["small","medium","large"].map(f=>h.jsx(q,{className:"react-paint-editor-layouts-grid-button",selected:e===f,disabled:m,onClick:()=>t(f),children:f.charAt(0).toUpperCase()},f))]}),h.jsx("hr",{}),h.jsx("div",{className:"react-paint-editor-layouts",children:s.length===0?h.jsx("div",{className:"react-paint-editor-layouts-placeholder",children:"No layer yet"}):s.map(f=>h.jsx(wa,{shape:f,disabled:m,layoutDragging:d,setLayoutDragging:u,selected:G(l).some(C=>C.id===f.id)??!1,handleSelect:c,handleRemove:i,onMoveShapes:o,toggleShapeVisibility:a,toggleShapeLock:r},f.id))})]})})}):null},kt=({children:e,onClose:t,position:n="center",title:s,className:i=""})=>h.jsxs("div",{className:"react-paint-editor-modal","data-position":n,style:{"--react-paint-editor-modal-zindex":Zn},role:"dialog","aria-modal":"true","aria-labelledby":s,children:[h.jsx("div",{className:"react-paint-editor-modal-mask",onClick:t}),h.jsx("div",{className:`react-paint-editor-modal-panel ${i}`,children:e})]}),Pt=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez une couleur",mode:s="fill",disabled:i=!1,values:a,field:r,value:l="",valueChanged:o})=>{const[c]=v.useState(de("settings_")),p=e===c;return a.length?h.jsxs(h.Fragment,{children:[h.jsx(q,{selected:p,title:n,disabled:i,onClick:()=>{t(d=>d===c?void 0:c)},icon:l==="transparent"?s==="fill"?jn:Pn:void 0,children:l!=="transparent"&&h.jsx("div",{className:"react-paint-editor-colorfield-color","data-mode":s,style:{"--react-paint-editor-colorfield-color-value":l}})}),p&&h.jsx(Ye,{title:n,alignment:"left",children:h.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[a.map(d=>h.jsx(q,{title:d,selected:d===l,color:d,icon:d==="transparent"?s==="fill"?jn:Pn:void 0,onClick:()=>{o(r,d)},children:d!=="transparent"&&h.jsx("div",{className:"react-paint-editor-colorfield-color",color:d,"data-mode":s,style:{"--react-paint-editor-colorfield-color-value":d}})},d)),h.jsx(q,{type:"color",title:"Custom color",selected:l!==""&&!a.includes(l),value:l,onChange:d=>{const u=+d.target.value;o(r,Number.isNaN(u)?d.target.value:u)},children:h.jsx("div",{className:"react-paint-editor-colorfield-customcolor",style:{"--react-paint-editor-colorfield-color-value":a.includes(l)?"var(--react-paint-editor-app-font-color)":l},children:h.jsx("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},ka=({disabled:e=!1,selectedShape:t,removeShape:n})=>h.jsx(q,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{n(G(t))},icon:Sn}),jt=({CustomOption:e,selectedSettings:t,setSelectedSettings:n,title:s="Choisissez l'option",disabled:i=!1,field:a,icon:r,values:l,defaultValue:o,valueChanged:c})=>{const[p]=v.useState(de("settings_")),d=t===p;return l.length?h.jsxs(h.Fragment,{children:[h.jsx(q,{selected:d,title:s,icon:r,disabled:i,onClick:()=>{n(u=>u===p?void 0:p)}}),d&&h.jsx(Ye,{title:s,alignment:"left",fitContainer:!0,children:h.jsx("div",{className:"react-paint-editor-selectfield-wrapper",children:l.map(u=>h.jsx(q,{title:`${u}`,onClick:()=>(m=>{c(a,m)})(u),selected:o===u,style:{"--react-paint-editor-button-padding":"16px"},children:h.jsx(e,{children:u})},u))})})]}):null},Pa=({children:e})=>h.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),ti=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:i,valueChanged:a})=>s.length?h.jsx(jt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Pa,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:n,field:"fontFamily",values:s,defaultValue:i,valueChanged:a}):null,ja=({disabled:e,toggleLayoutPanel:t})=>h.jsx(q,{title:"Toggle layers panel",disabled:e,onClick:t,icon:'<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>',className:"react-paint-editor-layout-button"}),La=({children:e})=>h.jsxs("span",{className:"react-paint-editor-linearrow-option","data-type":e,children:[h.jsx("span",{className:"react-paint-editor-linearrow-left"}),h.jsx("span",{className:"react-paint-editor-linearrow-right"})]}),ni=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:i,valueChanged:a})=>s.length?h.jsx(jt,{selectedSettings:e,setSelectedSettings:t,CustomOption:La,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:n,field:"lineArrow",values:s,defaultValue:i,valueChanged:a}):null,Va=({children:e})=>h.jsxs("span",{className:"react-paint-editor-linetype-option","data-type":e,children:[h.jsx("span",{}),h.jsx("span",{}),h.jsx("span",{}),h.jsx("span",{}),h.jsx("span",{}),h.jsx("span",{}),h.jsx("span",{})]}),si=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:i,valueChanged:a})=>s.length?h.jsx(jt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Va,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:n,field:"lineDash",values:s,defaultValue:i,valueChanged:a}):null,Lt=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez l'intervalle",icon:s,disabled:i=!1,field:a,value:r,min:l=1,max:o=20,step:c=1,unity:p="",valueChanged:d})=>{const u=r===void 0,m=u?"N/A":`${Math.round(r)}${p}`,[f]=v.useState(de("settings_")),C=((P,w=500)=>{const y=v.useRef(null),S=v.useCallback((...Q)=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>P(...Q),w)},[P,w]);return v.useEffect(()=>()=>{y.current&&clearTimeout(y.current)},[]),S})(d),M=e===f;return l===o?null:h.jsxs(h.Fragment,{children:[h.jsx(q,{selected:M,title:n,disabled:i,icon:s,onClick:()=>{t(P=>P===f?void 0:f)}}),M&&h.jsx(Ye,{title:n,alignment:"left",fitContainer:!0,children:h.jsx("div",{children:h.jsxs("label",{className:"react-paint-editor-rangefield",children:[h.jsx("input",{type:"range",min:l,max:o,step:c,value:r??(o+l)/2,"data-indeterminate":+u,onChange:P=>{const w=+P.target.value,y=Number.isNaN(w)?P.target.value:w;d(a,y,!1),C(a,y,!0)}}),h.jsx("span",{children:m})]})})})]})},Za=({children:e})=>h.jsx("span",{children:e===0?"Non":"Oui"}),Ta=[0,1],ii=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,defaultValue:s,valueChanged:i})=>h.jsx(jt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Za,title:"Fermer les points",icon:Rt,disabled:n,field:"closedPoints",values:Ta,defaultValue:s,valueChanged:i}),Ha=({disabled:e=!1,className:t,toggleZoomPanel:n})=>h.jsx(q,{title:"Toggle zoom panel",disabled:e,onClick:n,icon:Ln,className:t?` ${t}`:""}),Vt=({setSelectedSettings:e,disabled:t=!1,field:n,icon:s,values:i,value:a=!1,valueChanged:r})=>{const[l]=v.useState(de("settings_"));return i.length!==2?null:h.jsx(q,{onClick:()=>{e(o=>o===l?void 0:l),r(n,!a)},selected:a,disabled:t,icon:s})},un=({activeTool:e,selectedShape:t,selectedShapeTool:n,disabled:s,selectedSettings:i,setSelectedSettings:a,handleShapeStyleChange:r,handleShapeFontFamilyChange:l})=>t?n&&h.jsxs(h.Fragment,{children:["strokeColor"in n.settings&&!n.settings.strokeColor.hidden&&h.jsx(Pt,{selectedSettings:i,setSelectedSettings:a,title:"Couleur du trait",mode:"stroke",disabled:s,field:"strokeColor",value:t.style?.strokeColor,valueChanged:r,values:n.settings.strokeColor.values}),"fillColor"in n.settings&&!n.settings.fillColor.hidden&&h.jsx(Pt,{selectedSettings:i,setSelectedSettings:a,title:"Couleur de fond",disabled:s,field:"fillColor",value:t.style?.fillColor,valueChanged:r,values:n.settings.fillColor.values}),"lineWidth"in n.settings&&!n.settings.lineWidth.hidden&&h.jsx(Lt,{selectedSettings:i,setSelectedSettings:a,title:"Epaisseur du trait",icon:kn,disabled:s,field:"lineWidth",value:t.style?.lineWidth,valueChanged:r,unity:"px",min:n.settings.lineWidth.min,max:n.settings.lineWidth.max,step:n.settings.lineWidth.step}),"lineDash"in n.settings&&!n.settings.lineDash.hidden&&h.jsx(si,{selectedSettings:i,setSelectedSettings:a,disabled:s,defaultValue:t.style?.lineDash,valueChanged:r,values:n.settings.lineDash.values}),"lineArrow"in n.settings&&!n.settings.lineArrow.hidden&&h.jsx(ni,{selectedSettings:i,setSelectedSettings:a,disabled:s,defaultValue:t.style?.lineArrow,valueChanged:r,values:n.settings.lineArrow.values}),"closedPoints"in n.settings&&!n.settings.closedPoints.hidden&&h.jsx(ii,{selectedSettings:i,setSelectedSettings:a,disabled:s,valueChanged:r,defaultValue:t.style?.closedPoints}),"fontFamily"in n.settings&&!n.settings.fontFamily.hidden&&h.jsx(ti,{selectedSettings:i,setSelectedSettings:a,disabled:s,valueChanged:l,values:n.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),"fontBold"in n.settings&&!n.settings.fontBold.hidden&&h.jsx(Vt,{setSelectedSettings:a,disabled:s,field:"fontBold",icon:wn,valueChanged:l,values:n.settings.fontBold.values,value:t.style?.fontBold}),"fontItalic"in n.settings&&!n.settings.fontItalic.hidden&&h.jsx(Vt,{setSelectedSettings:a,disabled:s,field:"fontItalic",icon:Mn,valueChanged:l,values:n.settings.fontItalic.values,value:t.style?.fontItalic}),"opacity"in n.settings&&!n.settings.opacity.hidden&&h.jsx(Lt,{selectedSettings:i,setSelectedSettings:a,title:"Opacité",icon:xn,min:n.settings.opacity.min,max:n.settings.opacity.max,step:n.settings.opacity.step,unity:"%",disabled:s,field:"opacity",value:t.style?.opacity,valueChanged:r})]}):"settings"in e?h.jsxs(h.Fragment,{children:["strokeColor"in e.settings&&!e.settings.strokeColor.hidden&&h.jsx(Pt,{selectedSettings:i,setSelectedSettings:a,title:"Couleur du trait",mode:"stroke",disabled:s,field:"strokeColor",value:e.settings.strokeColor.default,valueChanged:r,values:e.settings.strokeColor.values}),"fillColor"in e.settings&&!e.settings.fillColor.hidden&&h.jsx(Pt,{selectedSettings:i,setSelectedSettings:a,title:"Couleur de fond",disabled:s,field:"fillColor",value:e.settings.fillColor.default,valueChanged:r,values:e.settings.fillColor.values}),"lineWidth"in e.settings&&!e.settings.lineWidth.hidden&&h.jsx(Lt,{selectedSettings:i,setSelectedSettings:a,title:"Epaisseur du trait",disabled:s,field:"lineWidth",icon:kn,value:e.settings.lineWidth.default,valueChanged:r,unity:"px",min:e.settings.lineWidth.min,max:e.settings.lineWidth.max,step:e.settings.lineWidth.step}),"lineDash"in e.settings&&!e.settings.lineDash.hidden&&h.jsx(si,{selectedSettings:i,setSelectedSettings:a,disabled:s,defaultValue:e.settings.lineDash.default,valueChanged:r,values:e.settings.lineDash.values}),"lineArrow"in e.settings&&!e.settings.lineArrow.hidden&&h.jsx(ni,{selectedSettings:i,setSelectedSettings:a,disabled:s,defaultValue:e.settings.lineArrow.default,valueChanged:r,values:e.settings.lineArrow.values}),"closedPoints"in e.settings&&!e.settings.closedPoints.hidden&&h.jsx(ii,{selectedSettings:i,setSelectedSettings:a,disabled:s,valueChanged:r,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&h.jsx(ti,{selectedSettings:i,setSelectedSettings:a,disabled:s,valueChanged:l,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),"fontBold"in e.settings&&!e.settings.fontBold.hidden&&h.jsx(Vt,{setSelectedSettings:a,disabled:s,field:"fontBold",icon:wn,valueChanged:l,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),"fontItalic"in e.settings&&!e.settings.fontItalic.hidden&&h.jsx(Vt,{setSelectedSettings:a,disabled:s,field:"fontItalic",icon:Mn,valueChanged:l,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),"opacity"in e.settings&&!e.settings.opacity.hidden&&h.jsx(Lt,{selectedSettings:i,setSelectedSettings:a,title:"Opacité",icon:xn,min:e.settings.opacity.min,max:e.settings.opacity.max,step:e.settings.opacity.step,unity:"%",disabled:s,field:"opacity",value:e.settings.opacity.default,valueChanged:r})]}):null,za=({width:e,availableTools:t,updateToolSettings:n,layersManipulation:s=!1,toggleLayoutPanel:i,activeTool:a,selectedShape:r,canvas:l,settings:o,updateShape:c,removeShape:p,isZoomPanelShown:d,setIsZoomPanelShown:u})=>{const[m,f]=v.useState(void 0),[C,M]=v.useState(!1),P=o.size==="infinite"||o.features.zoom,w=!o.features.edition,y=()=>{M(x=>!x)},S=((x,Z)=>{const R=G(x).map(T=>Z.find(N=>N.id===T?.toolId)||Z.find(N=>N.type===T?.type)).filter(T=>T!==void 0);if(!R.length)return;if(R.length===1)return R[0];const I=R.slice(1).reduce((T,N)=>{const B={};for(const O in N.settings){if(T[O]===void 0||N.settings[O]?.hidden||T[O]?.hidden)continue;const Y=T[O],g=N.settings[O],b={};"min"in g&&"min"in Y&&g.min===Y.min&&"max"in g&&"max"in Y&&g.max===Y.max&&"step"in g&&"step"in Y&&g.step===Y.step&&(b.min=g.min,b.max=g.max,b.step=g.step),"values"in g&&"values"in Y&&g.values?.join(",")===Y.values?.join(",")&&(b.values=g.values),(Object.keys(b).length>0||O==="closedPoints")&&(B[O]=b)}return B},R[0].settings);return{id:R.map(T=>T.id).join("-"),icon:"",label:"group",type:"group",settings:I}})(r,t),Q=(S?Object.keys(S.settings).length+1:"settings"in a?Object.keys(a.settings).length:0)+ +s+ +P,V=e<40*Q,A=(x,Z,R=!0)=>{if(G(r).length){const I=G(r).map(T=>lt(xe(["style",x],Z,T),o));c(I,R),S&&n(S.id,x,Z)}else n(a.id,x,Z)},H=(x,Z)=>{if(G(r).length){const R=G(r).map(I=>{if(I.type!=="text")return I;const T=l?.getContext("2d");if(!T)return I;const N=xe(["style",x],Z,I),B=on(T,N.value,N.width,N.style?.fontBold??!1,N.style?.fontItalic??!1,N.style?.fontFamily);return lt({...N,fontSize:B,height:B*N.value.length},o)});c(R,!0),S&&n(S.id,x,Z)}else n(a.id,x,Z)};return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"react-paint-editor-settings-bar",children:[h.jsxs("div",{className:"react-paint-editor-settings-shrinkable",children:[P&&h.jsx(Ha,{className:d?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{u(x=>!x)}}),V&&Q>2&&h.jsx(q,{disabled:w,onClick:y,title:"Toggle settings",icon:'<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>'}),r?S&&h.jsxs(h.Fragment,{children:[!V&&h.jsx(un,{activeTool:a,selectedShape:r,selectedShapeTool:S,disabled:w,selectedSettings:m,setSelectedSettings:f,handleShapeStyleChange:A,handleShapeFontFamilyChange:H}),a.type==="selection"&&h.jsx(ka,{disabled:w,selectedShape:r,removeShape:p})]}):!V&&h.jsx(un,{activeTool:a,selectedShape:r,selectedShapeTool:S,disabled:w,selectedSettings:m,setSelectedSettings:f,handleShapeStyleChange:A,handleShapeFontFamilyChange:H})]}),h.jsx("div",{className:"react-paint-editor-settings-separator"}),s&&h.jsx(ja,{disabled:w,toggleLayoutPanel:i})]}),C&&h.jsx(kt,{className:"react-paint-editor-settings-modal",onClose:y,position:"bottom",title:"Settings",children:h.jsx(un,{activeTool:a,selectedShape:r,selectedShapeTool:S,disabled:w,selectedSettings:m,setSelectedSettings:f,handleShapeStyleChange:A,handleShapeFontFamilyChange:H})})]})},ai=({disabled:e=!1,withText:t=!1,loadFile:n,type:s,img:i,accept:a})=>{const r=v.useRef(null);return h.jsx(q,{ref:r,type:"file",onClick:l=>{l.stopPropagation(),r.current&&(r.current.value="")},onChange:l=>{const o=l.target.files?.item(0);o&&n(o)},accept:a,title:s.label??s.type,icon:i,disabled:e,children:t?s.label:void 0})},Qe=({type:e,img:t,isActive:n,withText:s=!1,disabled:i=!1,setActive:a})=>h.jsx(q,{disabled:i,selected:n,onClick:()=>{a(e)},title:e.label??e.type,icon:t,children:s?e.label:void 0}),Aa=({activeTool:e,withActionsInMenu:t,hasActionToUndo:n=!1,hasActionToRedo:s=!1,hasActionToClear:i=!1,undoAction:a,redoAction:r,clearCanvas:l,alignment:o,group:c,vertical:p=!1,disabled:d=!1,withLoadAndSave:u,withExport:m,addPicture:f,loadFile:C,togglePictureUrlModal:M,saveFile:P,toggleExportModal:w,withUploadPicture:y,withUrlPicture:S})=>{const[Q,V]=v.useState(!1),[,A]=v.useTransition(),H=c?.tools?.some(Z=>Z===e.type),x=(H?e.icon:c.img)??c.title;return v.useEffect(()=>{if(!Q)return;const Z=()=>{V(!1)};return document.addEventListener("click",Z),()=>{document.removeEventListener("click",Z)}},[Q]),t||y||S||u||m?h.jsxs("div",{className:"react-paint-editor-toolbox-relative",children:[h.jsx(q,{selected:H,title:c.title,disabled:d,onClick:()=>{A(()=>{V(!0)})},icon:x}),Q&&h.jsx(Ye,{alignment:o,position:"top",children:h.jsxs("div",{className:"react-paint-editor-toolbox-panel-content","data-vertical":+p,children:[t&&h.jsxs(h.Fragment,{children:[h.jsx(Qe,{withText:!0,type:Ke,disabled:d||!n,img:Ke.icon,isActive:e.id===Ke.id,setActive:a}),h.jsx(Qe,{withText:!0,type:Je,disabled:d||!s,img:Je.icon,isActive:e.id===Je.id,setActive:r}),h.jsx(Qe,{withText:!0,type:et,disabled:d||!i,img:et.icon,isActive:e.id===et.id,setActive:l}),(y||S||u)&&h.jsx("hr",{})]}),y&&h.jsx(ai,{withText:!0,type:On,disabled:d,loadFile:async Z=>{V(!1),await f(Z)},img:On.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),S&&h.jsx(q,{disabled:d,selected:!1,onClick:M,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"}),(y||S)&&u&&h.jsx("hr",{}),u&&h.jsxs(h.Fragment,{children:[h.jsx(ai,{withText:!0,type:Fn,disabled:d,loadFile:Z=>{V(!1),C(Z)},img:Fn.icon,accept:"application/JSON"}),h.jsx(Qe,{withText:!0,disabled:d,type:Wt,img:Wt.icon,isActive:e.id===Wt.id,setActive:P})]}),m&&h.jsx(Qe,{withText:!0,disabled:d,type:Dt,img:Dt.icon,isActive:e.id===Dt.id,setActive:w})]})})]}):null},Ea=({togglePictureUrlModal:e,addPicture:t})=>{const n=v.useRef(null);return v.useEffect(()=>{n.current&&n.current.focus()},[]),h.jsx(kt,{className:"react-paint-editor-toolbox-pictureinput-modal",onClose:e,title:"Add picture from URL",children:h.jsxs("form",{onSubmit:async s=>{s.preventDefault();const i=n.current?.value;i&&(await t(i),e())},children:[h.jsxs("label",{children:["URL ",h.jsx("input",{type:"text",ref:n})]}),h.jsx(q,{onClick:e,children:"Annuler"}),h.jsx(q,{type:"submit",selected:!0,children:"Ajouter"})]})})},oi="Choose export settings",Ra=({toggleExportModal:e,exportCanvasInFile:t})=>{const n=async s=>{t(s),e()};return h.jsxs(kt,{className:"react-paint-editor-toolbox-export-modal",onClose:e,title:oi,children:[h.jsx("h3",{children:oi}),h.jsx("hr",{}),h.jsx(q,{onClick:()=>n("currentZoom"),children:"Exporter la vue actuelle"}),h.jsx(q,{onClick:()=>n("defaultView"),children:"Exporter le canevas par défaut"}),h.jsx(q,{onClick:()=>n("fitToShapes"),children:"Exporter le dessin entier"}),h.jsx(q,{selected:!0,onClick:e,children:"Annuler"})]})},Ia=({activeTool:e,alignment:t,group:n,disabled:s=!1,setActiveToolFromId:i})=>{const a=v.useRef(null),[r,l]=v.useState(!1),[,o]=v.useTransition(),[c,p]=v.useState(void 0),d=f=>{p(f),i(f.id)};if(v.useEffect(()=>{if(!r)return;const f=C=>{!((P,w)=>!!(P.target instanceof Node&&w)&&w.contains(P.target))(C,a.current)&&l(!1)};return document.addEventListener("mousedown",f,{passive:!1}),document.addEventListener("touchstart",f,{passive:!1}),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("touchstart",f)}},[r]),"type"in n)return h.jsx(Qe,{disabled:s,type:n,img:n.icon,isActive:e.id===n.id,setActive:d});if(!n.toolsType.length)return null;if(n.toolsType?.length===1)return h.jsx(Qe,{disabled:s,type:n.toolsType[0],img:n.toolsType[0].icon,isActive:e.id===n.toolsType[0].id,setActive:d});const u=n?.toolsType.find(f=>f.type===e.type)!==void 0,m=(c?c.icon:n.toolsType?.[0]?.icon)??n.title;return h.jsxs("div",{className:"react-paint-editor-toolbargroup-relative",children:[h.jsx(q,{selected:u,title:n.title,disabled:s,onClick:()=>{c?i(c.id):n.toolsType?.[0]&&d(n.toolsType[0]),o(()=>{l(!0)})},icon:m}),r&&h.jsx(Ye,{alignment:t,position:"top",children:h.jsx("div",{className:"react-paint-editor-toolbargroup-panel-content","data-vertical":+n.vertical,ref:a,children:n.toolsType.map(f=>h.jsx(Qe,{disabled:s,type:f,img:f.icon,isActive:e.id===f.id,setActive:d},f.id))})})]})},Na=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],Da=({settings:e,width:t,activeTool:n,hasActionToUndo:s=!1,hasActionToRedo:i=!1,hasActionToClear:a=!1,withLoadAndSave:r,withExport:l,clearCanvas:o,setActiveTool:c,undoAction:p,redoAction:d,addPicture:u,loadFile:m,saveFile:f,exportCanvasInFile:C,availableTools:M,withUrlPicture:P,withUploadPicture:w})=>{const y=((g,b)=>{const k=b.flatMap(L=>{if(typeof L!="object")return g.filter(E=>E.type===L);const j=g.filter(E=>L.toolsType.includes(E.type));return j?{...L,toolsType:j}:null});return ln(k)})(M,Na),S=!e.features.edition,Q=t<40*(6+y.length),V=t<40*(3+y.length),[A,H]=v.useState(!1),[x,Z]=v.useState(!1),[R,I]=v.useState(!1),T=()=>{H(g=>!g)},N=()=>{I(g=>!g)},B=g=>{c(g),H(!1)},O=g=>{B(M.find(b=>b.id===g)??n)},Y=M.find(g=>g.type===n.type)!==void 0;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"react-paint-editor-toolbar-toolbox",style:{"--react-paint-editor-toolbar-minwidth":"160px"},children:[h.jsxs("div",{className:"react-paint-editor-toolbar-shrinkable",children:[h.jsx(Qe,{type:Ee,disabled:S,img:Ee.icon,isActive:n.id===Ee.id,setActive:B}),(e.size==="infinite"||e.features.zoom)&&h.jsx(Qe,{type:Ft,disabled:S,img:Ft.icon,isActive:n.id===Ft.id,setActive:B}),V?h.jsx(q,{disabled:S,onClick:T,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:Y}):y.map(g=>h.jsx(Ia,{disabled:S,activeTool:n,group:g,setActiveToolFromId:O},"id"in g?g.id:g.title))]}),!Q&&h.jsxs(h.Fragment,{children:[h.jsx(Qe,{type:Ke,disabled:S||!s,img:Ke.icon,isActive:n.id===Ke.id,setActive:p}),h.jsx(Qe,{type:Je,disabled:S||!i,img:Je.icon,isActive:n.id===Je.id,setActive:d}),h.jsx(Qe,{type:et,disabled:S||!a,img:et.icon,isActive:n.id===et.id,setActive:o})]}),h.jsx(Aa,{withActionsInMenu:Q,disabled:S,vertical:!0,alignment:"right",group:{title:"Menu",img:'<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>'},activeTool:n,addPicture:u,loadFile:m,saveFile:f,togglePictureUrlModal:()=>{Z(!0)},toggleExportModal:N,withUploadPicture:w,withUrlPicture:P,withLoadAndSave:r,withExport:l,hasActionToUndo:s,hasActionToRedo:i,hasActionToClear:a,undoAction:p,redoAction:d,clearCanvas:o})]}),A&&h.jsx(kt,{className:"react-paint-editor-toolbar-modal",onClose:T,title:"Outils",children:M.map(g=>g.type==="picture"?null:h.jsx(Qe,{disabled:S,type:g,img:g.icon,withText:!1,isActive:n.id===g.id,setActive:B},g.id))}),x&&h.jsx(Ea,{togglePictureUrlModal:()=>{Z(g=>!g)},addPicture:u}),R&&h.jsx(Ra,{toggleExportModal:N,exportCanvasInFile:C})]})},Zt={none:0,small:10,medium:20,large:40},Wa={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},Fa=()=>{const e=v.useRef([]),[t,n]=v.useState([]);return v.useEffect(()=>()=>{for(const s of e.current)clearTimeout(s)},[]),{snackbarList:t,addSnackbar:({type:s=ya,duration:i=Sa,text:a})=>{const r={id:de("snackbar_"),duration:i,type:s,text:a};n(l=>[...l,r]),e.current=[...e.current,setTimeout(()=>{return l=r.id,void n(o=>o.filter(c=>c.id!==l));var l},i)]}}};Ae.Canvas=({options:e,className:t,style:n,canvasProps:s})=>{const{shapesRef:i,selectedShape:a,selectionFrame:r,hoveredShape:l,addShape:o,setSelectedShape:c,setSelectionFrame:p,refreshSelectedShapes:d,refreshHoveredShape:u,removeShape:m,updateShape:f,backwardShape:C,forwardShape:M,saveShapes:P,refs:w,width:y,height:S,settings:Q,setCanvasSize:V,setCanvasOffset:A,selectShapes:H,activeTool:x,setActiveTool:Z,isInsideComponent:R,isInsideCanvas:I,isEditMode:T,canvas:{withSkeleton:N,withFrameSelection:B,canGrow:O,canShrink:Y},canvasOffsetStartData:g,setCanvasOffsetStartData:b,selectionMode:k,setSelectionMode:L,setCanvasMoveAcceleration:j,isShiftPressed:E,isAltPressed:W,isSpacePressed:F,setShiftPressed:z,setAltPressed:K,setCanvasZoom:se,resetZoom:D,setIsSpacePressed:te}=s,{canvasBackgroundColor:U,canvasSelectionColor:ie,canvasSelectionWidth:J}={...fi,...e},ce=v.useRef(null),ne=v.useCallback(X=>{o(X),H(X)},[o,H]),ue=v.useCallback(X=>{V({realWidth:y,realHeight:S,width:X,height:S*X/y,scaleRatio:X/y})},[y,S,V]);return va({isInsideComponent:R,isInsideCanvas:I,isEditingText:k.mode==="textedition",settings:Q,selectedShape:a,setSelectedShape:c,removeShape:m,pasteShapes:ne,updateShapes:f,backwardShape:C,forwardShape:M,setShiftPressed:z,setAltPressed:K,setActiveTool:Z,setSelectionMode:L,setSelectionFrame:p,setCanvasZoom:se,resetZoom:D,setIsSpacePressed:te}),(({onResized:X,element:le})=>{v.useEffect(()=>{const ae=le.current;if(!ae)return;const He=new ResizeObserver(ze=>{const je=ze?.[0]?.borderBoxSize?.[0],{width:he,height:ee}=je?{width:je.inlineSize,height:je.blockSize}:ze?.[0]?.contentRect??{};he!==void 0&&ee!==void 0&&X(he,ee)});return He.observe(ae),()=>{He.unobserve(ae)}},[le,X])})({element:ce,onResized:ue}),h.jsx("div",{ref:ce,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":O,"data-shrink":Y,style:{"--react-paint-app-row-width":Q.canvasSize.width,"--react-paint-app-canvaswidth":y,"--react-paint-app-canvasheight":S,"--react-paint-app-row-aspectratio":`calc(${Q.canvasSize.width} / ${Q.canvasSize.height})`,"--react-paint-app-canvas-bg":U,...n},children:h.jsx(aa,{isSpacePressed:F,ref:w.canvas,canGrow:O,isInsideComponent:R,activeTool:x,setActiveTool:Z,canvasOffsetStartData:g,setCanvasOffsetStartData:b,shapes:i.current,addShapes:o,updateSingleShape:f,selectedShape:a,selectionFrame:r,setSelectedShape:c,setSelectionFrame:p,hoveredShape:l,refreshHoveredShape:u,refreshSelectedShapes:d,settings:Q,setCanvasOffset:A,saveShapes:P,selectionMode:k,setSelectionMode:L,setCanvasMoveAcceleration:j,selectionColor:ie,selectionWidth:J,isEditMode:T,isShiftPressed:E,isAltPressed:W,withFrameSelection:B,withSkeleton:N})})},Ae.Editor=({editorProps:e,className:t,style:n,options:s,children:i})=>{const{shapesRef:a,addPictureShape:r,moveShapes:l,toggleShapeVisibility:o,toggleShapeLock:c,canGoBackward:p,canGoForward:d,canClear:u,selectedShape:m,removeShape:f,updateShape:C,backwardShape:M,forwardShape:P,refs:w,width:y,height:S,selectTool:Q,selectShapes:V,activeTool:A,setActiveTool:H,setAvailableTools:x,isEditMode:Z,availableTools:R,gridGap:I,setGridGap:T,loadFile:N,exportPicture:B,exportData:O,clearCanvas:Y,settings:g,setCanvasZoom:b,canvas:{canGrow:k,layersManipulation:L,withExport:j,withLoadAndSave:E,withUploadPicture:W,withUrlPicture:F}}=e,{toolbarBackgroundColor:z,dividerColor:K,fontRadius:se,fontDisabledColor:D,fontDisabledBackgroundColor:te,fontColor:U,fontBackgroundColor:ie,fontSelectedColor:J,fontSelectedBackgroundColor:ce,fontHoverColor:ne,fontHoverBackgroundColor:ue}={...Wa,...s},X=g.size==="infinite"||g.features.zoom,[le,ae]=v.useState(!1),[He,ze]=v.useState(!1),[je,he]=v.useState(X),ee=X&&je,Le=I>=Zt.large?"large":I>=Zt.medium?"medium":I>=Zt.small?"small":"none",{snackbarList:Ie,addSnackbar:Ce}=Fa(),Ue=v.useCallback((pe,ge,gt)=>{x(We=>We.map(ct=>ct.id===pe?xe(["settings",ge,"default"],gt,ct):ct)),H(We=>We.id===pe?xe(["settings",ge,"default"],gt,We):We)},[H,x]),hn=v.useCallback(pe=>{ae(!0);try{B(pe)}catch(ge){ge instanceof Error&&Ce({type:"error",text:`L'export a échoué : ${ge.message}`}),console.warn(ge)}finally{ae(!1)}},[B,Ce]),pn=v.useCallback(()=>{ae(!0);try{O(),ae(!1)}catch(pe){pe instanceof Error&&Ce({type:"error",text:"L'enregistrement a échoué"}),console.warn(pe)}finally{ae(!1)}},[O,Ce]),Xe=v.useCallback(async pe=>{ae(!0);try{await N(pe),Ce({type:"success",text:"Fichier chargé !"})}catch(ge){ge instanceof Error&&Ce({type:"error",text:"Le chargement a échoué"}),console.warn(ge)}finally{ae(!1)}},[N,Ce]),gn=v.useCallback(async pe=>{ae(!0);try{const ge=await r(pe,y,S);V([ge])}catch(ge){ge instanceof Error&&Ce({type:"error",text:"Le chargement a échoué"}),console.warn(ge)}finally{ae(!1)}},[r,V,Ce,y,S]),fn=`${t?`${t} `:""}${He?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return h.jsxs("div",{ref:w.setEditor,className:fn,style:{"--react-paint-editor-app-maxWidth":k?"100%":`${y}px`,"--react-paint-editor-app-toolbar-bg":z,"--react-paint-editor-app-divider-color":K,"--react-paint-editor-app-font-radius":se,"--react-paint-editor-app-font-disabled-color":D,"--react-paint-editor-app-font-disabled-bg":te,"--react-paint-editor-app-font-color":U,"--react-paint-editor-app-font-bg":ie,"--react-paint-editor-app-font-selected-color":J,"--react-paint-editor-app-font-selected-bg":ce,"--react-paint-editor-app-font-hover-color":ne,"--react-paint-editor-app-font-hover-bg":ue,...n},children:[Z&&h.jsx(Da,{settings:g,width:g.canvasSize.width,activeTool:A,clearCanvas:Y,setActiveTool:Q,exportCanvasInFile:hn,saveFile:pn,loadFile:Xe,addPicture:gn,hasActionToUndo:p,hasActionToRedo:d,hasActionToClear:u,undoAction:M,redoAction:P,availableTools:R,withExport:j,withLoadAndSave:E,withUploadPicture:W,withUrlPicture:F}),i,Z&&L&&h.jsx(Ma,{gridFormat:Le,setGridFormat:pe=>{T(Zt[pe])},shapes:a.current,moveShapes:l,selectedShapes:m,removeShape:f,selectShapes:V,toggleShapeVisibility:o,toggleShapeLock:c,isLayoutPanelShown:He,settings:g}),ee&&h.jsxs(Ye,{alignment:"left",className:"react-paint-editor-layouts-panel","data-edit":+Z,children:[h.jsx(q,{className:"react-paint-editor-zoom-button",icon:'<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>',onClick:()=>b("unzoom")}),h.jsxs(q,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>b("default"),children:[Math.round(100*g.canvasZoom),"%"]}),h.jsx(q,{className:"react-paint-editor-zoom-button",icon:Ln,onClick:()=>b("zoom")})]}),Z&&h.jsxs(h.Fragment,{children:[h.jsx(za,{setCanvasZoom:b,width:g.canvasSize.width,activeTool:A,availableTools:R,selectedShape:m,settings:g,removeShape:f,updateShape:C,canvas:w.canvas.current,layersManipulation:L,toggleLayoutPanel:()=>{ze(pe=>!pe)},isZoomPanelShown:ee,setIsZoomPanelShown:he,updateToolSettings:Ue}),h.jsx(ma,{isLoading:le}),h.jsx(ba,{snackbarList:Ie})]})]})},Ae.useReactPaint=({width:e=1e3,height:t=600,shapes:n,mode:s="editor",disabled:i=!1,options:a=qn}={})=>{const{layersManipulation:r,brushAlgo:l,isBrushShapeDoneOnMouseUp:o,debug:c,grid:p,canGrow:d,canShrink:u,withExport:m,withLoadAndSave:f,withUploadPicture:C,withUrlPicture:M,withSkeleton:P,withFrameSelection:w,clearCallback:y,availableTools:S,canvasSelectionPadding:Q,size:V,canZoom:A}={...qn,...a},H=s!=="viewer",x=v.useRef(null),Z=v.useRef(null),R=v.useRef(!1),I=v.useCallback(_=>{x.current=_},[]),[T,N]=v.useState(void 0),[B,O]=v.useState(Ee),[Y,g]=v.useState({mode:"default"}),[b,k]=v.useState(p),[L,j]=v.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),E=A==="always"&&!i,{canvasTransformation:W,setCanvasTransformation:F,setCanvasOffset:z,setCanvasZoom:K,resetZoom:se}=ta({canvasSize:L,size:V,canvasElt:Z.current,zoomEnabled:E}),{offset:D,zoom:te}=W,U=v.useMemo(()=>({brushAlgo:l,isBrushShapeDoneOnMouseUp:o,debug:c,canvasSize:{realWidth:L.realWidth,realHeight:L.realHeight,width:L.width,height:L.height,scaleRatioWithNoZoom:L.scaleRatio,scaleRatio:L.scaleRatio*te},size:V,canvasOffset:D,canvasZoom:te,gridGap:b,selectionPadding:Q,features:{edition:H&&!i,zoom:E}}),[Q,b,l,o,c,te,D,L,V,i,E,H]),[ie,J]=v.useState(Bs(S,C||M)),{isInsideComponent:ce,isInsideCanvas:ne}=(({settings:_,componentRef:oe,canvasRef:we})=>{const[Fe,Oe]=v.useState(!1),[qe,_e]=v.useState(!1),fe=!_.features.edition&&!_.features.zoom;return v.useEffect(()=>{if(!fe){const Me=()=>Oe(!0),Ht=()=>Oe(!1),Be=()=>_e(!0),zt=()=>_e(!1);return oe.current?.addEventListener("focusin",Me),oe.current?.addEventListener("focusout",Ht),we.current?.addEventListener("focusin",Be),we.current?.addEventListener("focusout",zt),()=>{oe.current?.removeEventListener("focusin",Me),oe.current?.removeEventListener("focusout",Ht),we.current?.removeEventListener("focusin",Be),we.current?.removeEventListener("focusout",zt)}}Oe(!1),_e(!1)},[fe,oe,we]),{isInsideComponent:Fe,isInsideCanvas:qe}})({settings:U,componentRef:x,canvasRef:Z}),[ue,X]=v.useState(!1),[le,ae]=v.useState(!1),[He,ze]=v.useState(!1),{registerEvent:je,unregisterEvent:he,shapesRef:ee,selectedShape:Le,selectionFrame:Ie,hoveredShape:Ce,addShapes:Ue,addPictureShape:hn,moveShapes:pn,setSelectedShape:Xe,setSelectionFrame:gn,refreshSelectedShapes:fn,refreshHoveredShape:pe,removeShape:ge,updateShape:gt,backwardShape:We,forwardShape:ct,clearShapes:ri,saveShapes:Oa,toggleShapeVisibility:Ba,toggleShapeLock:$a,canGoBackward:Ya,canGoForward:Ua,canClear:Xa}=Ji(U,e,t,ue),vn=v.useCallback(_=>{Xe(void 0),O(_)},[Xe]),[dt,li]=v.useState([0,0]),ci=Y.mode==="preview";v.useEffect(()=>{if(ci)return()=>g(_=>_.mode==="preview"?{mode:"default"}:_)},[Le?.id,ci]);const di=Y.mode==="selectionFrame";v.useEffect(()=>{if(di)return()=>li([0,0])},[di]),v.useEffect(()=>{if(dt[0]!==0||dt[1]!==0){const _=setInterval(()=>{F(({offset:oe,zoom:we})=>{const Fe=[oe[0]-dt[0],oe[1]-dt[1]];return Jt({zoom:we,size:V,canvasSize:L,newOffset:Fe})})},20);return()=>clearInterval(_)}},[dt[0],dt[1],F,V,L]);const Tt=v.useCallback((_,oe)=>{ri(_,oe),vn(Ee),F({offset:[0,0],zoom:1})},[vn,ri,F]),ui=v.useCallback(_=>{Xe(oe=>(oe?.id!==_.map(we=>we.id).join("-")&&O(Ee),Se(_,U)))},[Xe,U]),Ga=v.useCallback(()=>{const _=_i(ee.current,e,t);if(!_)throw new Error("L'encodage a échoué");Ns(_,"drawing.json")},[ee,e,t]),qa=v.useCallback(_=>{const oe=Ds({shapes:ee.current,settings:U,view:_});Ns(oe,"drawing.png")},[ee,U]),_a=v.useCallback(_=>Ds({shapes:ee.current,settings:U,view:_}),[ee,U]),Ka=v.useCallback(()=>dn(ee.current,e,t),[ee,e,t]),Ge=v.useCallback(async(_,oe)=>{const we=await(async(Fe,Oe)=>{if(!Fe)return[];const qe=[],_e=ln(Fe.map(fe=>{if(!fe||!Un.includes(fe.type))return null;if(fe.type==="picture"){const Me=new Image,Ht=new Promise((Be,zt)=>{Me.onload=()=>{URL.revokeObjectURL(Me.src),Be()},Me.onerror=()=>{zt(new Error("Some images could not be loaded"))}});if(qe.push(Ht),fe.src.startsWith("http"))Is(fe.src).then(Be=>{Me.src=Be}).catch(()=>{Me.src=""});else if(fe.src.includes("<svg")){const Be=new Blob([fe.src],{type:"image/svg+xml"});Me.src=URL.createObjectURL(Be)}else Me.src=fe.src;return Ws({...fe,img:Me},Oe)}return Ws(fe,Oe)}));return await Promise.all(qe),_e})(_,U);Tt(we,oe)},[Tt,U]),mn=v.useRef(Ge);mn.current=Ge;const Ja=v.useCallback((_=[],oe=!0)=>{mn.current?.(_,{clearHistory:oe,source:"remote"})},[]);v.useEffect(()=>{R.current||(R.current=!0,n&&mn.current?.(n,{clearHistory:!0,source:"remote"}))},[n]);const eo=v.useCallback(async _=>{const oe=await(async we=>new Promise((Fe,Oe)=>{const qe=new FileReader;qe.onload=_e=>{const fe=_e.target?.result;if(!fe)return Oe("Impossible de récupérer les données du fichier");const Me=JSON.parse(fe);Fe(Me)},qe.readAsText(we)}))(_);await Ge(oe.shapes??[],{clearHistory:!0,source:"remote"})},[Ge]),to=v.useCallback(()=>{typeof y!="string"?Ge(y(),{clearHistory:!1,source:"user"}):y==="defaultShapes"&&n!==void 0?Ge(n,{clearHistory:!1,source:"user"}):Tt([],{clearHistory:!1,source:"user"})},[Tt,Ge,n,y]);v.useEffect(()=>{J(Bs(S,C||M))},[S,C,M]);const hi={canvas:Z,editor:x,setEditor:I};return{annotationsProps:{style:{userSelect:"none",touchAction:"none",transformOrigin:"left top",transform:"scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))","--react-paint-canvas-zoom":U.canvasZoom,"--react-paint-canvas-offset-x":U.canvasOffset[0],"--react-paint-canvas-offset-y":U.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:ee,addPictureShape:hn,moveShapes:pn,toggleShapeVisibility:Ba,toggleShapeLock:$a,canGoBackward:Ya,canGoForward:Ua,canClear:Xa,selectedShape:Le,removeShape:ge,updateShape:gt,backwardShape:We,forwardShape:ct,refs:hi,width:e,height:t,selectTool:vn,selectShapes:ui,activeTool:B,setActiveTool:O,setAvailableTools:J,isEditMode:H,availableTools:ie,gridGap:b,setGridGap:k,loadFile:eo,exportPicture:qa,exportData:Ga,clearCanvas:to,settings:U,setCanvasZoom:K,resetZoom:se,canvas:{canGrow:d,canShrink:u,layersManipulation:r,withExport:m,withLoadAndSave:f,withUploadPicture:C,withUrlPicture:M}},canvasProps:{shapesRef:ee,selectedShape:Le,selectionFrame:Ie,hoveredShape:Ce,addShape:Ue,setSelectedShape:Xe,setSelectionFrame:gn,refreshSelectedShapes:fn,refreshHoveredShape:pe,removeShape:ge,updateShape:gt,backwardShape:We,forwardShape:ct,saveShapes:Oa,refs:hi,width:e,height:t,settings:U,setCanvasSize:j,setCanvasOffset:z,setCanvasZoom:K,resetZoom:se,selectShapes:ui,activeTool:B,setActiveTool:O,isInsideComponent:ce,isInsideCanvas:ne,isEditMode:H,canvas:{withSkeleton:P,withFrameSelection:w,canGrow:d,canShrink:u},canvasOffsetStartData:T,setCanvasOffsetStartData:N,selectionMode:Y,setSelectionMode:g,setCanvasMoveAcceleration:li,isShiftPressed:ue,isAltPressed:le,isSpacePressed:He,setShiftPressed:X,setAltPressed:ae,setIsSpacePressed:ze},registerEvent:je,unregisterEvent:he,resetCanvas:Ja,resetZoom:se,getCurrentImage:_a,getCurrentData:Ka,setCanvasOffset:z,setCanvasZoom:K}},Object.defineProperty(Ae,Symbol.toStringTag,{value:"Module"})});
|