@yorab/react-paint 0.16.3 → 0.17.1

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.
Files changed (32) hide show
  1. package/dist/canvas/components/Canvas.d.ts +2 -0
  2. package/dist/canvas/constants/app.d.ts +1 -0
  3. package/dist/canvas/constants/keyboard.d.ts +3 -0
  4. package/dist/canvas/hooks/useDrawableCanvas.d.ts +3 -1
  5. package/dist/canvas/hooks/useKeyboard.d.ts +4 -1
  6. package/dist/canvas/hooks/useReactPaint.d.ts +18 -2
  7. package/dist/canvas/hooks/useShapes.d.ts +6 -2
  8. package/dist/canvas/utils/shapes/brush.d.ts +0 -6
  9. package/dist/canvas/utils/shapes/circle.d.ts +1 -7
  10. package/dist/canvas/utils/shapes/curve.d.ts +2 -7
  11. package/dist/canvas/utils/shapes/ellipse.d.ts +1 -7
  12. package/dist/canvas/utils/shapes/index.d.ts +1 -6
  13. package/dist/canvas/utils/shapes/line.d.ts +1 -7
  14. package/dist/canvas/utils/shapes/picture.d.ts +0 -6
  15. package/dist/canvas/utils/shapes/polygon.d.ts +1 -6
  16. package/dist/canvas/utils/shapes/rectangle.d.ts +0 -6
  17. package/dist/common/types/Mode.d.ts +7 -1
  18. package/dist/editor/components/common/Menu.d.ts +10 -0
  19. package/dist/editor/components/common/Panel.d.ts +3 -3
  20. package/dist/editor/components/settings/Layouts.d.ts +2 -2
  21. package/dist/editor/components/toolbox/ContextMenu.d.ts +23 -0
  22. package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -8
  23. package/dist/editor/components/toolbox/ToolbarGroup.d.ts +1 -4
  24. package/dist/editor/constants/icons.d.ts +1 -0
  25. package/dist/editor/hooks/useDrag.d.ts +2 -2
  26. package/dist/editor/hooks/useMenu.d.ts +10 -0
  27. package/dist/react-paint.css +1 -1
  28. package/dist/react-paint.js +1421 -1229
  29. package/dist/react-paint.umd.cjs +1 -1
  30. package/package.json +1 -1
  31. package/dist/canvas/utils/string.d.ts +0 -2
  32. package/dist/editor/components/settings/PointsNumberField.d.ts +0 -13
@@ -1 +1 @@
1
- (function(De,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],y):y((De=typeof globalThis<"u"?globalThis:De||self)["react-paint"]={},De.React,De.jsxRuntime)})(this,function(De,y,h){"use strict";const Qn='<svg><path d="M5.146 17.5Q4.146 17.5 3.208 17Q2.271 16.5 1.667 15.708Q2.208 15.75 2.802 15.344Q3.396 14.938 3.396 14.104Q3.396 13.042 4.135 12.292Q4.875 11.542 5.958 11.542Q7.021 11.542 7.76 12.292Q8.5 13.042 8.5 14.104Q8.5 15.5 7.51 16.5Q6.521 17.5 5.146 17.5ZM9.917 12.5 7.562 10.146 14.917 2.729Q15.146 2.5 15.469 2.5Q15.792 2.5 16.021 2.729L17.271 3.958Q17.5 4.188 17.5 4.531Q17.5 4.875 17.271 5.125Z"/></svg>',Rt='<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>',It='<svg><path d="M10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333ZM10 16.583Q12.75 16.583 14.667 14.667Q16.583 12.75 16.583 10Q16.583 7.25 14.667 5.333Q12.75 3.417 10 3.417Q7.25 3.417 5.333 5.333Q3.417 7.25 3.417 10Q3.417 12.75 5.333 14.667Q7.25 16.583 10 16.583ZM10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Q10 10 10 10Z"/></svg>',Wt='<svg><path d="M12.25 18.333V16.167L6.833 13.458H2.5V8.208H6.25L8.25 5.917V1.667H13.5V6.917H9.708L7.75 9.146V11.958L12.25 14.208V13.083H17.5V18.333Z"/></svg>',bn='<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>',wn='<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>',Nt='<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>',Cn='<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>',Mn='<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>',kn='<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>',Pn='<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>',Ln='<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>',jn='<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>',Vn='<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>',Zn='<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>',Hn='<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>',Se=["transparent","black","white","red","green","blue","yellow"],Ie=[0,1,2],zn=[[1,0],[1,2],[4,6]],dt="serif",ga=2,Tn=3,fa=4,re="react-paint-",An={strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0}},Ft={type:"picture",id:`${re}picture`,icon:Nt,label:"Image",settings:{opacity:{min:0,max:100,step:1,default:100}}},En={type:"brush",id:`${re}brush`,icon:Qn,label:"Brosse",settings:{strokeColor:{values:Se,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:Ie,default:0}}},Dn={type:"line",id:`${re}line`,icon:Mn,label:"Ligne",settings:{strokeColor:{values:Se,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0},lineArrow:{values:[0,1,2,3],default:0}}},Rn={type:"polygon",id:`${re}polygon`,icon:Wt,label:"Polygone",settings:{strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0},closedPoints:{default:0}}},In={type:"curve",id:`${re}curve`,icon:kn,label:"Courbe",settings:{strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0},closedPoints:{default:0}}},Wn={type:"rect",id:`${re}rect`,icon:Rt,label:"Rectangle",settings:An},Nn={type:"square",id:`${re}square`,icon:Rt,label:"Carré",settings:{strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0}}},Fn={type:"circle",id:`${re}circle`,icon:It,label:"Cercle",settings:{strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0}}},Bn={type:"ellipse",id:`${re}ellipse`,icon:It,label:"Ellipse",settings:{strokeColor:{values:Se,default:"black"},fillColor:{values:Se,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:Ie,default:0}}},On={type:"text",id:`${re}text`,icon:Cn,label:"Texte",settings:{strokeColor:{values:Se,default:"black"},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:["arial","serif","monospace"],default:dt},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}}},Re={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"},et={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"},tt={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"},nt={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"},Bt={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"},Yn={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"},Ot={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"},Yt={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"},Xn={id:`${re}upload-picture`,type:"uploadpicture",icon:Nt,label:"Upload picture"},$n=2,Un="blue",Oe=14,qn=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],Gn=["brush","rect","square","line","polygon","circle","curve","ellipse","picture","text","triangle","group"],va=["rect","square","circle","ellipse","picture","text","triangle","brush","group"],ma=["square","circle","picture","text"],_n="react-paint-canvas-drawcanvas",Kn="react-paint-canvas-selectioncanvas",Jn={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,availableTools:[En,Dn,Rn,In,Wn,Nn,Fn,Bn,Ft,On],clearCallback:"empty",brushAlgo:"simple",isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:"fixed",canZoom:"never",debug:!1},ya={canvasBackgroundColor:"white",canvasSelectionColor:Un,canvasSelectionWidth:$n},es=300,Xt=(e,t)=>{const n={...t};for(const s of e)Array.isArray(s)?s[1].includes(n[s[0]])&&delete n[s[0]]:delete n[s];return n},Qe=(e,t,n)=>{const s=Array.isArray(n)?[...n]:{...n},a=Array.isArray(e)?e:typeof e=="string"?e.split("."):[e];return a.reduce((o,c,r)=>(o[c]=$t(o[c])?{...o[c]}:Array.isArray(o[c])?[...o[c]]:o[c]===void 0||o[c]===null?{}:o[c],r===a.length-1&&(o[c]=t),o[c]),s),s},$t=e=>typeof e=="object"&&!Array.isArray(e)&&e!==null,He=(e,t,n)=>{if(!$t(t)||!$t(n))return n;const s={...t};for(const a in n)n.hasOwnProperty(a)&&(s.hasOwnProperty(a)?s[a]=e(s[a],n[a],a)??He(e,s[a],n[a]):s[a]=n[a]);return s},ts=(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 a of n)if(!s.includes(a)||!ts(e[a],t[a]))return!1;return!0},Ut={},le=(e="")=>(Ut[e]||(Ut[e]=0),`${e}${++Ut[e]}`),ze=(e,t,n)=>Math.max(t,Math.min(e,n)),ns=()=>typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),ss=e=>{e.reset(),e.lineCap="round",e.lineJoin="round"},xe=(e,t={})=>{const{lineCap:n="round",fillColor:s="transparent",opacity:a=100,strokeColor:o=Un,lineWidth:c=$n,lineDash:r=0,shadowColor:i="transparent",shadowBlur:l=0}=t;e.lineCap=n,e.globalAlpha=a/100,e.fillStyle=s,e.strokeStyle=o,e.lineWidth=c,e.setLineDash(r===0?[]:[zn[r][0]*c,zn[r][1]*c]),e.shadowColor=i,e.shadowBlur=l},st=(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]))},qt=e=>180*e/Math.PI,as=(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},ne=({origin:e=[0,0],point:t,rotation:n=0})=>{if(n===0)return t;const s=[t[0]-e[0],t[1]-e[1]],a=s[1]*Math.cos(n)-s[0]*Math.sin(n);return[s[1]*Math.sin(n)+s[0]*Math.cos(n)+e[0],a+e[1]]},os=e=>(e+2*Math.PI)%(2*Math.PI),is=({targetVector:[e,t],radian:n=!0,originVector:s})=>{const a=os(Math.atan2(t[1]-e[1],t[0]-e[0]));if(s){const[o,c]=s,r=Math.atan2(c[1]-o[1],c[0]-o[0]),i=os(a-r);return n?i:qt(i)}return n?a:qt(a)},rs=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),Ye=(e,t,n)=>{const s=ne({origin:t.computed.center,point:e.computed.center,rotation:t.rotation??0}),a=(s[0]-(e.computed.borders.width/2-n.settings.selectionPadding)-(n.originalBorders.x+n.settings.selectionPadding))*n.widthMultiplier,o=(s[1]-(e.computed.borders.height/2-n.settings.selectionPadding)-(n.originalBorders.y+n.settings.selectionPadding))*n.heightMultiplier;return{x:n.newBorderX+n.settings.selectionPadding+(n.isXinverted?n.newBorderWidth-2*n.settings.selectionPadding-(e.computed.borders.width-2*n.settings.selectionPadding||1)*n.widthMultiplier-a:a),y:n.newBorderY+n.settings.selectionPadding+(n.isYinverted?n.newBorderHeight-2*n.settings.selectionPadding-(e.computed.borders.height-2*n.settings.selectionPadding||1)*n.heightMultiplier-o:o)}},Xe=(e,t,n,s,a)=>ne({origin:e.groupCenter,point:[t+s/2,n+a/2],rotation:-e.rotation}),Gt=(e,{selectionPadding:t})=>{const n=e.points.flat(),s=Math.min(...n.map(i=>i[0])),a=Math.min(...n.map(i=>i[1])),o=n.map(i=>Ve(i,s,a,e.scaleX,e.scaleY)),c=Math.max(...o.map(i=>i[0]))+t,r=Math.max(...o.map(i=>i[1]))+t;return{x:s-t,width:c-s+t,y:a-t,height:r-a+t}},at=(e,t)=>{const n=Qa(e,t),s=((a,o)=>Te(a,Gt,o))(e,t);return{...e,path:n,selection:ot(n,s,t),computed:s}},Sa=at,be=(e,t=2)=>Math.round(e*10**t)/10**t,Ve=(e,t,n,s=1,a=1)=>[t+(e[0]-t)*s,n+(e[1]-n)*a],ge=(e,t,n=0)=>{if(!t.gridGap)return be(e);const s=e+n,a=s>=0?t.gridGap:-t.gridGap;return s+a/2-(s+a/2)%a-n},xa=(e,t,n,s,a,o,c)=>{if(s.mode==="translate")return ce(Ts(n,s.originalShape,s.cursorStartPosition,a,o),a);if(s.mode==="rotate"){const r=s.originalShape.computed.center[0]-s.cursorStartPosition[0],i=s.originalShape.computed.center[1]-s.cursorStartPosition[1],l=s.originalShape.computed.center[0]-n[0],u=s.originalShape.computed.center[1]-n[1],d=((m,v,g)=>v.gridGap||g?m+Math.PI/18/2-(m+Math.PI/18/2)%(Math.PI/18):be(m,3))(Math.atan2(u,l)-Math.atan2(i,r),a,o),p=Y(s.originalShape).map(m=>Ee($a(m,d,s.originalShape.computed.center),a));return ce(p,a)}return s.mode==="resize"?ce(Ua(e,n,s.originalShape,s,a,o,c),a):s.mode==="brush"?ce(Y(t).map(r=>((i,l,u)=>{const d={...i,points:Qe(i.points.length-1,[...i.points[i.points.length-1],[Math.round(l[0]),Math.round(l[1])]],i.points)};return at(d,u)})(r,n,a)),a):t},ut=e=>{const t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},mt=e=>{const t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},yt=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},Qa=(e,{brushAlgo:t})=>{const n=new Path2D;if(e.points.length<1)return n;const s=e.points.flat(),a=s.map(i=>i[0]),o=s.map(i=>i[1]),c=Math.min(...a),r=Math.min(...o);for(const i of e.points)if(i.length)if(i.length===1)n.rect(...Ve(i[0],c,r,e.scaleX,e.scaleY),1,1);else if(n.moveTo(...Ve(i[0],c,r,e.scaleX,e.scaleY)),t==="quadratic"){for(let l=0;l<i.slice(1).length-2;l++){const u=Ve(i[l],c,r,e.scaleX,e.scaleY),d=Ve(i[l+1],c,r,e.scaleX,e.scaleY),p=(u[0]+d[0])/2,m=(u[1]+d[1])/2;n.quadraticCurveTo(...u,p,m)}n.quadraticCurveTo(...Ve(i[i.length-2],c,r,e.scaleX,e.scaleY),...Ve(i[i.length-1],c,r,e.scaleX,e.scaleY))}else for(const l of i.slice(1))n.lineTo(...Ve(l,c,r,e.scaleX,e.scaleY));return n},ba=(e,t,n,s)=>{const a=w=>(1-w)**3*e[0]+3*(1-w)**2*w*t[0]+3*(1-w)*w**2*n[0]+w**3*s[0],o=w=>(1-w)**3*e[1]+3*(1-w)**2*w*t[1]+3*(1-w)*w**2*n[1]+w**3*s[1],c=(w,j,E)=>{const V=w-2*j+E,C=-2*w+2*j,Z=w;if(Math.abs(V)<1e-10){if(Math.abs(C)<1e-10)return[];const $=-Z/C;return $>0&&$<1?[$]:[]}const A=C*C-4*V*Z;if(A<0)return[];const H=Math.sqrt(A),O=(-C-H)/(2*V),D=(-C+H)/(2*V),I=[];return O>0&&O<1&&I.push(O),D>0&&D<1&&D!==O&&I.push(D),I},r=e[0],i=t[0],l=n[0],u=s[0],d=e[1],p=t[1],m=n[1],v=s[1],g=c(i-r,l-i,u-l),x=c(p-d,m-p,v-m);let M=Math.min(e[0],s[0]),b=Math.max(e[0],s[0]),Q=Math.min(e[1],s[1]),f=Math.max(e[1],s[1]);for(const w of g){const j=a(w);M=Math.min(M,j),b=Math.max(b,j)}for(const w of x){const j=o(w);Q=Math.min(Q,j),f=Math.max(f,j)}return{minX:M,maxX:b,minY:Q,maxY:f}},_t=(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]],Kt=(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]}),ls=e=>{const t=new Path2D,n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2)return t;t.moveTo(...n[0]);for(const s of n.slice(1))t.lineTo(...s);return n.length>2&&e.style?.closedPoints===1&&t.lineTo(...n[0]),t},wa=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},Ca=(e,t)=>({x:t.x-(e.style?.lineWidth??0)/2,y:t.y-(e.style?.lineWidth??0)/2,width:t.width+(e.style?.lineWidth??0),height:t.height+(e.style?.lineWidth??0)}),Te=(e,t,n,s=Ca)=>{const a=t(e,n),o=s(e,a,n),c=[a.x+a.width/2,a.y+a.height/2],r=((i,l,u=0)=>{if(u===0)return i;const d=[[i.x,i.y],[i.x+i.width,i.y],[i.x+i.width,i.y+i.height],[i.x,i.y+i.height]].map(v=>ne({point:v,origin:l,rotation:u})),p=Math.min(...d.map(v=>v[0])),m=Math.min(...d.map(v=>v[1]));return{x:p,y:m,width:Math.max(...d.map(v=>v[0]))-p,height:Math.max(...d.map(v=>v[1]))-m}})(o,c,e.rotation);return{borders:a,outerBorders:o,center:c,boundingBox:r}},ot=(e,t,n)=>{const{borders:s}=t;return{type:"rect",border:ut(s),shapePath:e,line:yt({points:[[s.x+s.width/2,s.y],[s.x+s.width/2,s.y-23/n.canvasSize.scaleRatio]]}),anchors:[mt({x:s.x+s.width/2,y:s.y-23/n.canvasSize.scaleRatio,radius:7/n.canvasSize.scaleRatio}),...qn.map(a=>mt({x:s.x+s.width*a[0],y:s.y+s.height*a[1],radius:7/n.canvasSize.scaleRatio}))]}},cs=({borderStart:e,borderSize:t,vector:n,settings:s,invertedAxe:a,anchor:o})=>{switch(o){case 0:{if(a){const r=Math.max(0,n-t)+2*s.selectionPadding;return[e+t-2*s.selectionPadding,r]}const c=Math.max(2*s.selectionPadding,t-n);return[e+t-c,c]}case .5:return[e,t];case 1:if(a){const c=Math.min(e,e+t+n);return[c,e-c+2*s.selectionPadding]}return[e,Math.max(2*s.selectionPadding,t+n)];default:return[0,0]}},Ma=({borderX:e,borderWidth:t,borderY:n,borderHeight:s,center:a,originalShape:o})=>{const c=[e+t/2-a[0],n+s/2-a[1]],[r,i]=ne({point:c,rotation:-(o.rotation??0)});return{borderX:be(e+r-c[0]),borderWidth:be(t),borderY:be(n+i-c[1]),borderHeight:be(s)}},ka=(e,t,n,s)=>{const a=t.x+t.width/2,o=t.y+t.height/2,c=n?2*e.borderWidth+t.width:Math.abs(t.width+2*(e.borderWidth-t.width)),r=s?2*e.borderHeight+t.height:Math.abs(t.height+2*(e.borderHeight-t.height));return{...e,borderHeight:r,borderWidth:c,borderX:a-c/2,borderY:o-r/2}},$e=(e,t,n,s,a=!1,o=!1)=>{const{center:c,borders:r}=t.computed,i=ne({origin:c,point:e,rotation:t.rotation}),l=n.anchor[0]===0&&i[0]>=r.x+r.width-s.selectionPadding||n.anchor[0]===1&&i[0]<=r.x+s.selectionPadding,u=n.anchor[1]===0&&i[1]>=r.y+r.height-s.selectionPadding||n.anchor[1]===1&&i[1]<=r.y+s.selectionPadding,d=[ge(i[0],s,n.anchor[0]===0&&!l||n.anchor[0]===1&&l?s.selectionPadding:-s.selectionPadding),ge(i[1],s,n.anchor[1]===0&&!u||n.anchor[1]===1&&u?s.selectionPadding:-s.selectionPadding)],p=s.gridGap?[n.anchor[0]===0?r.x:n.anchor[0]===.5?r.x+r.width/2:r.x+r.width,n.anchor[1]===0?r.y:n.anchor[1]===.5?r.y+r.height/2:r.y+r.height]:ne({origin:c,point:n.cursorStartPosition,rotation:t.rotation}),m=[d[0]-p[0],d[1]-p[1]],[v,g]=cs({borderStart:r.x,borderSize:r.width,vector:m[0],settings:s,invertedAxe:l,anchor:n.anchor[0]}),[x,M]=cs({borderStart:r.y,borderSize:r.height,vector:m[1],settings:s,invertedAxe:u,anchor:n.anchor[1]}),b=a?((Q,f,w,j,E,V,C,Z,A,H,O)=>{const{selectionPadding:D}=O,I="ratio"in A&&A.ratio?A.ratio:(Q.width-2*D||1)/(Q.height-2*D||1),$=(j-2*D)/(V-2*D);let U,z,S,k;return H.anchor[0]!==.5&&H.anchor[1]!==.5?$<I?(z=E,k=V,S=(V-2*D)*I+2*D,U=H.anchor[0]===0?C?Q.x+Q.width-2*D:Q.x+(Q.width-S):C?Q.x-S+2*D:Q.x):(U=w,S=j,k=(j-2*D)/I+2*D,z=H.anchor[1]===0?Z?Q.y+Q.height-2*D:Q.y+(Q.height-k):Z?Q.y-k+2*D:Q.y):H.anchor[0]!==.5?(U=w,S=j,k=(j-2*D)/I+2*D,z=Q.y+(Q.height-k)/2):(z=E,k=V,S=(V-2*D)*I+2*D,U=Q.x+(Q.width-S)/2),{borderX:U,borderWidth:S,borderY:z,borderHeight:k,center:f,originalShape:A}})(r,c,v,g,x,M,l,u,t,n,s):{borderX:v,borderWidth:g,borderY:x,borderHeight:M,center:c,originalShape:t};return{...Ma(o?ka(b,r,l,u):b),isXinverted:l,isYinverted:u}},St=(e,t)=>{const n=ut(e),s=((a,o)=>Te(a,Jt,o))(e,t);return{...e,path:n,computed:s,selection:ot(n,s,t)}},Pa=St,ds=(e,t,n,s=0,a=0)=>{const o={toolId:e.id,type:e.type,id:le(`${e.type}_`),x:t[0],y:t[1],width:s,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 St(o,n)},La=(e,t)=>{e.globalAlpha!==0&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},Jt=(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,a]=[!1,!1])=>{const o=e[0]===.5?n.x+n.width/2:e[0]===0?n.x+(s?0:n.width):n.x+(s?n.width:0),c=e[1]===.5?n.y+n.height/2:e[1]===0?n.y+(a?0:n.height):n.y+(a?n.height:0);return en([o,c],n.rotation??0,t)},hs=(e,t,n,s,a,o,c,r="replace")=>{let i=!1;if(a){i=ht(e,a,n,s,!0,o?20:void 0);const u=((d,p,m)=>{if(d.mode==="translate")return{mode:"translate",cursorStartPosition:m,originalShape:p,hasBeenDuplicated:!1,dateStart:Date.now(),selectedShapesLengthAtMouseDown:Y(p).length};if(d.mode==="rotate"){const{center:v}=p.computed;return{mode:"rotate",cursorStartPosition:m,originalShape:p,center:[v[0],v[1]],selectedShapesLengthAtMouseDown:Y(p).length}}return d.mode==="resize"?{mode:"resize",cursorStartPosition:m,originalShape:p,anchor:d.anchor,selectedShapesLengthAtMouseDown:Y(p).length}:void 0})(i||{mode:"default"},a,n);if(u?.mode==="resize"||u?.mode==="rotate")return{shape:a,mode:u}}const l=t.find(u=>Y(a).find(d=>u.id===d?.id)?i&&ht(e,u,n,s,!0,o?20:void 0):!!ys(e,u,n,s))??(i?a:void 0);if(a&&a?.id===l?.id)return{shape:a,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:a,selectedShapesLengthAtMouseDown:Y(a).length}};if(l){if(r==="add"){const d=ce(gs(a,[l]),s);return{shape:d,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:d,selectedShapesLengthAtMouseDown:Y(a).length}}}if(r==="remove"){const d=ce(ja(a,l),s);return{shape:d,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:d,selectedShapesLengthAtMouseDown:Y(a).length}}}const u=Y(a).find(d=>d.id===l?.id)?a:ce([l],s);return{shape:u,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:u,selectedShapesLengthAtMouseDown:Y(a).length}}}return{shape:r!=="replace"?a:void 0,mode:{mode:c?"selectionFrame":"default"}}},ce=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];const n=e.some(c=>c.rotation!==e[0].rotation)?0:e[0]?.rotation??0,s=((c,r,i)=>{const l=c.map(f=>[[f.computed.borders.x+i.selectionPadding,f.computed.borders.y+i.selectionPadding],[f.computed.borders.x-i.selectionPadding+f.computed.borders.width,f.computed.borders.y+i.selectionPadding],[f.computed.borders.x-i.selectionPadding+f.computed.borders.width,f.computed.borders.y-i.selectionPadding+f.computed.borders.height],[f.computed.borders.x+i.selectionPadding,f.computed.borders.y-i.selectionPadding+f.computed.borders.height]].map(w=>{const j=ne({point:[w[0],w[1]],origin:f.computed.center,rotation:-(f.rotation??0)});return ne({point:[j[0],j[1]],origin:[0,0],rotation:r})})),u=Math.min(...l.flatMap(f=>[f[0][0],f[1][0],f[2][0],f[3][0]])),d=Math.min(...l.flatMap(f=>[f[0][1],f[1][1],f[2][1],f[3][1]])),p=Math.max(...l.flatMap(f=>[f[0][0],f[1][0],f[2][0],f[3][0]])),m=Math.max(...l.flatMap(f=>[f[0][1],f[1][1],f[2][1],f[3][1]])),v=[(u+p)/2,(d+m)/2],g=ne({point:v,origin:[0,0],rotation:-r}),x=[v[0]-g[0],v[1]-g[1]],M=be(u-x[0]),b=be(p-x[0]),Q=be(d-x[1]);return{width:b-M,height:be(m-x[1])-Q,x:M,y:Q}})(e,n,t),a=ds({id:"group_selection",type:"rect",settings:An},[s.x,s.y],t,s.width,s.height),o=e.slice(1).reduce((c,r)=>{const i=r.style??{},l={};for(const u in i)c[u]!==void 0&&i[u]!==void 0&&c[u]===i[u]&&(l[u]=c[u]);return l},e[0].style??{});return{id:e.map(c=>c.id).join("-"),type:"group",shapes:e,rotation:n,visible:!0,locked:!1,selection:a.selection,x:a.x,y:a.y,width:a.width,height:a.height,style:o,computed:a.computed,path:a.path}},ps=(e,t)=>n=>{if(!n)return;const s=n.type==="group"?n.shapes.map(a=>e(a,t)):[e(n,t)];return ce(s,t)},Y=e=>e?e.type==="group"?e.shapes:[e]:[],gs=(e,t)=>{const n=Y(e);return[...new Set([...n,...t])]},ja=(e,t)=>Y(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:a}=fs(e),o=t.getBoundingClientRect();return[(s-o.left)/n.scaleRatio,(a-o.top)/n.scaleRatio]},it=(e,t,n)=>{const{clientX:s,clientY:a}=fs(e),o=t?.getBoundingClientRect()??{left:0,top:0,width:n.canvasSize.width,height:n.canvasSize.height};return[(s-o.left)*(n.canvasSize.width/o.width)/n.canvasSize.scaleRatio-n.canvasOffset[0],(a-o.top)*(n.canvasSize.height/o.height)/n.canvasSize.scaleRatio-n.canvasOffset[1]]},rt=e=>"touches"in e,Ae=(e,t,[n,s])=>ne({origin:[n,s],point:e,rotation:t}),en=(e,t,[n,s])=>ne({origin:[n,s],point:e,rotation:-t}),xt=(e,t,n)=>n?as(e,{x:t[0],y:t[1],radius:n}):((s,a)=>a[0]>=s.x&&a[0]<=s.x+s.width&&a[1]>=s.y&&a[1]<=s.y+s.height)(e,t),ht=(e,t,n,s,a=!1,o=0)=>{const c=Y(t).length>1?t:Y(t)[0];if(!c||c.locked)return!1;const{borders:r,center:i}=c.computed,l=Ae(n,c.rotation??0,i);if(a){const u=((d,p,m,v=0)=>{const{canvasSize:{scaleRatio:g}}=m,{borders:x}=d.computed;if(d.type==="line"||d.type==="polygon"||d.type==="curve"){for(let M=0;M<d.points.length;M++)if(xt({x:d.points[M][0]-7/g,y:d.points[M][1]-7/g,width:Oe/g,height:Oe/g},p,v))return{mode:"resize",anchor:M}}else{if(xt({x:x.x+x.width/2-7/g,y:x.y-Oe/g-16/g,width:Oe/g,height:Oe/g},p,v))return{mode:"rotate"};for(const M of qn)if(xt({x:x.x+x.width*M[0]-7/g,y:x.y+x.height*M[1]-7/g,width:Oe/g,height:Oe/g},p,v))return{mode:"resize",anchor:M}}return!1})(c,l,s,o);if(u)return u}return c.selection?.type==="line"?(e.lineWidth=(c.style?.lineWidth??0)+15/s.canvasZoom,!!(tn(c,!0)?e.isPointInPath(c.path,l[0],l[1]):e.isPointInStroke(c.path,l[0],l[1]))&&{mode:"translate"}):!!xt(r,l,15+o)&&{mode:"translate"}},ms=(e,t,n,s,a=50)=>{if(t.locked||t.points.length<2)return!1;const{center:o}=t.computed,c=Ae(n,t.rotation??0,o);e.lineWidth=(t.style?.lineWidth??0)+a/s.canvasZoom;const r=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let i=0;i<r.length-1;i++){const l=yt({points:[r[i],r[i+1]]});if(e.isPointInStroke(l,c[0],c[1]))return{lineIndex:i}}return!1},tn=(e,t=!1)=>!(!t||!["curve","polygon"].includes(e.type))||e.style?.fillColor&&e.style?.fillColor!=="transparent"||["picture","text"].includes(e.type),ys=(e,t,n,s)=>{if(t.locked)return!1;const{center:a}=t.computed,o=Ae(n,t.rotation??0,a);return e.lineWidth=(t.style?.lineWidth??0)+15/s.canvasZoom,!!(tn(t)?e.isPointInPath(t.path,o[0],o[1]):e.isPointInStroke(t.path,o[0],o[1]))&&{mode:"translate"}};function nn(e,t){const n=Math.max(e.x,t.x),s=Math.max(e.y,t.y),a=Math.min(e.x+(e.width||1),t.x+(t.width||1)),o=Math.min(e.y+(e.height||1),t.y+(t.height||1));if(n<a&&s<o)return{x:n,y:s,width:a-n,height:o-s}}const Ss=({ctx:e,path:t,rect:n,offset:s,center:a,rotation:o=0,checkFill:c})=>{for(let r=0;r<s;r+=s/2)for(let i=0;i<s;i+=s/2)for(let l=r+n.x;l<n.x+n.width;l+=s)for(let u=i+n.y;u<n.y+n.height;u+=s){const d=Ae([l,u],o,a);if(c?e.isPointInPath(t,d[0],d[1]):e.isPointInStroke(t,d[0],d[1]))return!0}return!1},sn=(e,t,n,s)=>({type:"line",border:ut(n.borders),shapePath:e,anchors:[...t.points.map(a=>mt({x:a[0],y:a[1],radius:7/s.canvasSize.scaleRatio}))]}),we=[.05,.1,.25,.5,1,2,4,8],an=({size:e,zoom:t,newOffset:[n,s],canvasSize:a})=>e==="infinite"?{zoom:t,offset:[n,s]}:t<1?{zoom:t,offset:[-(a.realWidth-a.realWidth/t)/2,-(a.realHeight-a.realHeight/t)/2]}:{zoom:t,offset:[ze(n,a.realWidth/t-a.realWidth,0),ze(s,a.realHeight/t-a.realHeight,0)]},on=({size:e,canvasSize:t,currentOffset:n,currentZoom:s,zoom:a,centerPoint:o})=>{const c=e==="fixed"&&a<1?[t.realWidth/2,t.realHeight/2]:o,r=n[0]-(c[0]/s-c[0]/a),i=n[1]-(c[1]/s-c[1]/a);return{offset:e==="infinite"?[r,i]:a<1?[-(t.realWidth-t.realWidth/a)/2,-(t.realHeight-t.realHeight/a)/2]:[ze(r,t.realWidth/a-t.realWidth,0),ze(i,t.realHeight/a-t.realHeight,0)],zoom:a}},xs=e=>{const{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:s},canvasZoom:a,canvasOffset:o}=e;return{x:o[0]*a*s,y:o[1]*a*s,width:t*a,height:n*a}},Qs=(e,t)=>{const{canvasZoom:n,size:s}=t;if(s!=="fixed"||n>=1)return;const a=xs(t);e.beginPath(),e.rect(a.x,a.y,a.width,a.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,Va=(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)}),Qt=(e,t)=>{const n=mt(e),s=((a,o)=>Te(a,Va,o))(e,t);return{...e,path:n,selection:ot(n,s,t),computed:s}},Za=Qt,gt=(e,t)=>{const n=ls(e),s=((a,o)=>Te(a,bt,o))(e,t);return{...e,path:n,selection:sn(n,e,s,t),computed:s}},bs=gt,bt=(e,t)=>{const n=Math.min(...e.points.map(o=>o[0]))-t.selectionPadding,s=Math.max(...e.points.map(o=>o[0]))+t.selectionPadding,a=Math.min(...e.points.map(o=>o[1]))-t.selectionPadding;return{x:n,width:s-n,y:a,height:Math.max(...e.points.map(o=>o[1]))+t.selectionPadding-a}},Ha=(e,t,n,s)=>{if(t<0||t>e.points.length-1)return e;const a=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return gt({...e,points:a},s)},ws=(e,t,n,s=!1)=>{const a=[ge(t[0],n),ge(t[1],n)],o=Ae(a,e.rotation??0,e.computed.center),c={...e,points:s?e.points:[...e.points,o],tempPoint:s?o:void 0};return gt(c,n)},za=(e,t,n)=>{const s=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(s.length<2){const l=s[0]??[0,0],u=n.selectionPadding;return{x:l[0]-u,y:l[1]-u,width:2*u,height:2*u}}if(s.length<3)return bt({...e,points:s},n);const a=_t(e,s);let o=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let l=1;l<a.length-2;l++){const u=a[l-1],d=a[l],p=a[l+1],m=a[l+2],{cp1:v,cp2:g}=Kt(u,d,p,m),x=ba(d,v,g,p);o=Math.min(o,x.minX),c=Math.max(c,x.maxX),r=Math.min(r,x.minY),i=Math.max(i,x.maxY)}return Jt({x:o,y:r,width:c-o,height:i-r},n)},ft=(e,t)=>{const n=(a=>{const o=new Path2D,c=a.tempPoint?[...a.points,a.tempPoint]:a.points;if(c.length<2)return o;if(c.length<3)return ls(a);const r=a.style?.closedPoints===1&&c.length>2;o.moveTo(...c[0]);const i=_t(a,c);for(let l=1;l<i.length-2;l++){const u=i[l-1],d=i[l],p=i[l+1],m=i[l+2],{cp1:v,cp2:g}=Kt(u,d,p,m);o.bezierCurveTo(v[0],v[1],g[0],g[1],p[0],p[1])}return r&&o.closePath(),o})(e),s=((a,o)=>Te(a,bt,o,za))(e,t);return{...e,path:n,selection:sn(n,e,s,t),computed:s}},Cs=ft,Ta=(e,t,n,s)=>{if(t<0||t>e.points.length-1)return e;const a=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return ft({...e,points:a},s)},Ms=(e,t,n,s=!1)=>{const a=[ge(t[0],n),ge(t[1],n)],o=e.computed.center,c=Ae(a,e.rotation??0,o),r={...e,points:s?e.points:[...e.points,c],tempPoint:s?c:void 0};return ft(r,n)},Aa=(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)}),wt=(e,t)=>{const n=(a=>{const o=new Path2D;return o.ellipse(a.x,a.y,a.radiusX,a.radiusY,0,0,2*Math.PI),o})(e),s=((a,o)=>Te(a,Aa,o))(e,t);return{...e,path:n,selection:ot(n,s,t),computed:s}},Ea=wt,Da=(e,t)=>Te(e,bt,t),ks=(e,t)=>((n,s)=>({...n,path:wa(n),computed:Da(n,s)}))({...e,id:le("triangle_"),type:"triangle"},t),Ra=(e,t)=>{e.globalAlpha!==0&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},Ia=(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}),Ct=(e,t)=>{const n=[];let s;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){const o=Math.PI/2-is({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||n.push(ks(Ps(e.points[0],o,e.style),t)),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||n.push(ks(Ps(e.points[1],o+Math.PI,e.style),t));const c=(({line:r,size:i,direction:l})=>{const u=Math.PI/2-is({targetVector:[r.points[0],r.points[1]]}),d=[r.points[0][0]+(r.points[1][0]-r.points[0][0])/2,r.points[0][1]+(r.points[1][1]-r.points[0][1])/2];let p,m;if(["start","both"].includes(l)){const v=ne({point:r.points[0],origin:d,rotation:-u});p=ne({point:[v[0],v[1]+i],origin:d,rotation:u})}else p=[...r.points[0]];if(["end","both"].includes(l)){const v=ne({point:r.points[1],origin:d,rotation:-u});m=ne({point:[v[0],v[1]-i],origin:d,rotation:u})}else m=[...r.points[1]];return{points:[p,m]}})({line:e,size:10+2*(e.style?.lineWidth??0),direction:e.style?.lineArrow===1?"start":e.style?.lineArrow===2?"end":"both"});s=yt(c)}else s=yt(e);const a=((o,c)=>Te(o,Ia,c))(e,t);return{...e,path:s,selection:sn(s,e,a,t),arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"},computed:a}},Wa=Ct,Ps=(e,t,n)=>{const s=[ne({point:[0,0],rotation:t}),ne({point:[-(5+(n.lineWidth??0)),10+2*(n.lineWidth??0)],rotation:t}),ne({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"}}},Na=(e,t,n)=>{const{isXinverted:s,isYinverted:a,settings:o,widthMultiplier:c,heightMultiplier:r}=n,i=e.computed.borders.width-2*o.selectionPadding,l=e.computed.borders.height-2*o.selectionPadding,u=i*c,d=l*r,p=Ye(e,t,n),m=Xe(n,p.x,p.y,u,d),v=e.computed.center[0]-i/2,g=e.computed.center[1]-l/2,x=m[0]-u/2,M=m[1]-d/2;return((b,Q)=>b.type==="line"?Ct(b,Q):b.type==="polygon"?bs(b,Q):Cs(b,Q))({...e,points:e.points.map(([b,Q])=>[x+(s?u-(b-v)*c:(b-v)*c),M+(a?d-(Q-g)*r:(Q-g)*r)])},n.settings)},Mt=(e,t)=>{const n=((a,o)=>Te(a,Jt,o))(e,t),s=ut(e);return{...e,path:s,selection:ot(void 0,n,t),computed:n}},Fa=Mt,rn=(e,t,n,s,a)=>{const[o,c]=((r,i,l,u,d=!1)=>{if(!(r&&i&&u&&l))return[es,es];const p=r/i;if(p>l/u){const v=d?l:Math.min(r,l);return[v,v/p]}const m=d?u:Math.min(i,u);return[m*p,m]})(e.width,e.height,n,s,!0);return Mt({toolId:Ft.id,type:"picture",id:le("picture_"),x:-a.canvasOffset[0]+a.canvasSize.realWidth/a.canvasZoom/2-o/2,y:-a.canvasOffset[1]+a.canvasSize.realHeight/a.canvasZoom/2-c/2,width:o,height:c,ratio:o/c,src:t,img:e},a)},Ba=(e,t,n,s)=>new Promise((a,o)=>{const c=new Image;c.onerror=()=>{o(new Error("Some images could not be loaded"))},setTimeout(()=>{o(new Error("Timeout while loading images"))},4e3),e instanceof File?((r,i,l,u,d,p)=>{Ds(l)?l.text().then(m=>{const v=Es(m);r.onload=async()=>{URL.revokeObjectURL(r.src);const g=rn(r,m,u,d,p);i(g)},r.src=v}):(r.onload=async()=>{URL.revokeObjectURL(r.src);const m=rn(r,r.src,u,d,p);i(m)},r.src=URL.createObjectURL(l))})(c,a,e,t,n,s):((r,i,l,u,d,p)=>{r.onload=()=>{URL.revokeObjectURL(r.src);const m=rn(r,l,u,d,p);i(m)},Rs(l).then(m=>{r.src=m}).catch(()=>{r.src=""})})(c,a,e,t,n,s)}),ln=["Texte"],Ls=(e,t)=>Te(e,Ya,t),kt=(e,t)=>{const n=Ls(e,t),s=ut(e);return{...e,path:s,selection:ot(void 0,n,t),computed:n}},Oa=kt,Pt=(e,t,n,s,a,o=dt)=>{e.font=`${a?"italic":""} ${s?"bold":""} 1px ${o}`;const c=t.map(r=>n/e.measureText(r).width);return Math.min(...c)||36},Ya=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),Xa=(e,t,n,s)=>{const a={...t,value:n},o=((v,g,x,M,b,Q=dt)=>{v.font=`${b?"italic":""} ${M?"bold":""} ${x}px ${Q}`;const f=g.map(w=>v.measureText(w).width);return Math.max(...f)||20})(e,a.value,a.fontSize,a.style?.fontBold??!1,a.style?.fontItalic??!1,a.style?.fontFamily),c=a.fontSize*a.value.length,r=o/c,i={...a,width:o,height:c,ratio:r},{center:l}=Ls(i,s),[u,d]=us([1,1],t.computed.center,t),[p,m]=us([1,1],l,i,[!1,!1]);return{...i,x:i.x-(p-u),y:i.y-(m-d)}},js=(e,t,n,s)=>{const a=[ge(n[0],s),ge(n[1],s)];switch(t.type){case"brush":return((o,c,r)=>at({toolId:o.id,type:o.type,id:le(`${o.type}_`),points:[[c]],scaleX:1,scaleY:1,style:{opacity:o.settings.opacity.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},r))(t,a,s);case"line":return((o,c,r)=>{const i={toolId:o.id,type:o.type,id:le(`${o.type}_`),points:[c,c],style:{opacity:o.settings.opacity.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,lineArrow:o.settings.lineArrow.default}};return Ct(i,r)})(t,a,s);case"polygon":return((o,c,r)=>gt({toolId:o.id,type:o.type,id:le(`${o.type}_`),points:[c],style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,closedPoints:o.settings.closedPoints.default}},r))(t,a,s);case"curve":return((o,c,r)=>ft({toolId:o.id,type:o.type,id:le(`${o.type}_`),points:[c],style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,closedPoints:o.settings.closedPoints.default}},r))(t,a,s);case"rect":case"square":return ds(t,a,s);case"text":return((o,c,r,i)=>{const l=Pt(o,ln,150,c.settings?.fontBold.default??!1,c.settings?.fontItalic.default??!1,c.settings.fontFamily.default),u=l*(ln.length||1);return kt({toolId:c.id,type:c.type,id:le(`${c.type}_`),x:r[0]-150,y:r[1]-u,value:ln,fontSize:l,width:150,height:u,ratio:150/u,style:{opacity:c.settings.opacity.default,strokeColor:c.settings.strokeColor.default,fontFamily:c.settings.fontFamily.default,fontItalic:c.settings.fontItalic.default,fontBold:c.settings.fontBold.default}},i)})(e,t,a,s);case"ellipse":return((o,c,r)=>wt({toolId:o.id,type:o.type,id:le(`${o.type}_`),x:c[0],y:c[1],radiusX:0,radiusY:0,style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},r))(t,a,s);case"circle":return((o,c,r)=>Qt({toolId:o.id,type:o.type,id:le(`${o.type}_`),x:c[0],y:c[1],radius:0,style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},r))(t,a,s)}},Vs=(e,t)=>{switch(t.type){case"brush":((n,s)=>{s.points.length<1||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.scale(s.flipX?-1:1,s.flipY?-1:1),n.font=`${s.style?.fontItalic?"italic":""} ${s.style?.fontBold?"bold":""} ${s.fontSize}px ${s.style?.fontFamily??dt}`,n.textBaseline="top",n.fillStyle=s.style.strokeColor;for(let a=0;a<s.value.length;a++)n.fillText(s.value[a],s.flipX?-s.x-s.width:s.x,(s.flipY?-s.y-s.height:s.y)+a*s.fontSize,s.width)}})(e,t);break;case"line":((n,s)=>{if(n.globalAlpha!==0){s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path);for(const a of s.arrows??[])xe(n,a.style),Ra(n,a)}})(e,t);break;case"polygon":((n,s)=>{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)=>{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.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.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"rect":case"square":La(e,t);break;case"picture":((n,s)=>{n.globalAlpha!==0&&(n.beginPath(),n.scale(s.flipX?-1:1,s.flipY?-1:1),n.drawImage(s.img,s.flipX?-s.x-s.width:s.x,s.flipY?-s.y-s.height:s.y,s.width,s.height))})(e,t)}},Zs=(e,t,n)=>{if(t.visible===!1)return;if(((a,o)=>{const c=(r=>{const{canvasSize:{width:i,height:l,scaleRatioWithNoZoom:u},canvasZoom:d,canvasOffset:p}=r;return{x:-p[0],y:-p[1],width:i/d/u,height:l/d/u}})(o);return!!nn(a.computed.boundingBox,c)})(t,n)){if(st(e,n,t.rotation,t.computed.center),xe(e,t.style),e.globalAlpha!==1)return((a,o)=>{const{outerBorders:c}=o.computed,r={width:2*c.width,height:2*c.height};if(r.width===0||r.height===0)return;const i=document.createElement("canvas"),l=i.getContext("2d");if(!l)throw new Error("No context found for canvas");i.width=r.width,i.height=r.height,l.translate(r.width/4-c.x,r.height/4-c.y),xe(l,{...o.style,opacity:100}),Vs(l,o),a.drawImage(i,c.x-r.width/4,c.y-r.height/4)})(e,t),void e.restore();Vs(e,t),e.restore()}},$a=(e,t,n)=>{const s=ne({origin:n,point:e.computed.center,rotation:-t});if("points"in e){if(e.type==="brush"){const o=e.points.map(c=>c.map(r=>[r[0]+s[0]-e.computed.center[0],r[1]+s[1]-e.computed.center[1]]));return{...e,points:o,rotation:(e.rotation??0)+t}}const a=e.points.map(o=>ne({origin:n,point:o,rotation:-t}));return{...e,points:a}}return{...e,x:e.x+s[0]-e.computed.center[0],y:e.y+s[1]-e.computed.center[1],rotation:(e.rotation??0)+t}},Hs=(e,t,n,s,a,o,c)=>{switch(n.type){case"line":return((r,i,l,u)=>{const d=[ge(r[0],u),ge(r[1],u)],p=Ae(d,i.rotation??0,i.computed.center),m=Qe(["points",l.anchor],p,i);return Ct(m,u)})(t,n,s,a);case"polygon":return((r,i,l,u)=>{const d=[ge(r[0],u),ge(r[1],u)],p=Ae(d,i.rotation??0,i.computed.center),m=Qe(["points",l.anchor],p,i);return gt(m,u)})(t,n,s,a);case"curve":return((r,i,l,u)=>{const d=[ge(r[0],u),ge(r[1],u)],p=i.computed.center,m=Ae(d,i.rotation??0,p),v=Qe(["points",l.anchor],m,i);return ft(v,u)})(t,n,s,a);case"brush":return((r,i,l,u,d,p)=>{const m=Gt({...i,scaleX:1,scaleY:1},u),v=i.computed.borders,{borderX:g,borderHeight:x,borderY:M,borderWidth:b,isXinverted:Q,isYinverted:f}=$e(r,i,l,u,d,p),w=Math.max(0,m.width-2*u.selectionPadding),j=Math.max(0,m.height-2*u.selectionPadding),E=Math.max(0,b-2*u.selectionPadding),V=Math.max(0,x-2*u.selectionPadding),C=w?E/w:1,Z=j?V/j:1;if(!w||!j)return i;const A=be(g-v.x)+(Q?2*v.x+m.width:0),H=be(M-v.y)+(f?2*v.y+m.height:0);return at({...i,points:i.points.map(O=>O.map(([D,I])=>[Q?-D+A:D+A,f?-I+H:I+H])),scaleX:C,scaleY:Z},u)})(t,n,s,a,o,c);case"circle":return((r,i,l,u,d)=>{const{borderX:p,borderHeight:m,borderY:v,borderWidth:g}=$e(r,i,l,u,!0,d);return Qt({...i,radius:Math.max(0,g/2-u.selectionPadding),x:p+g/2,y:v+m/2},u)})(t,n,s,a,c);case"ellipse":return((r,i,l,u,d=!1,p=!1)=>{const{borderX:m,borderHeight:v,borderY:g,borderWidth:x}=$e(r,i,l,u,d,p);return wt({...i,radiusX:Math.max(0,x/2-u.selectionPadding),radiusY:Math.max(0,v/2-u.selectionPadding),x:m+x/2,y:g+v/2},u)})(t,n,s,a,o,c);case"rect":case"square":return((r,i,l,u,d=!1,p=!1)=>{const{borderX:m,borderHeight:v,borderY:g,borderWidth:x}=$e(r,i,l,u,d,p);return St({...i,width:Math.max(0,x-2*u.selectionPadding),height:Math.max(0,v-2*u.selectionPadding),x:m+u.selectionPadding,y:g+u.selectionPadding},u)})(t,n,s,a,n.type==="square"||o,c);case"text":return((r,i,l,u,d,p)=>{const{borderX:m,borderHeight:v,borderY:g,borderWidth:x,isXinverted:M,isYinverted:b}=$e(i,l,u,d,!0,p),Q=Math.max(0,x-2*d.selectionPadding),f=Math.max(0,v-2*d.selectionPadding),w=kt({...l,width:Q,height:f,x:m+d.selectionPadding,y:g+d.selectionPadding,flipX:M?!l.flipX:!!l.flipX,flipY:b?!l.flipY:!!l.flipY},d);return{...w,fontSize:Pt(r,w.value,w.width,w.style?.fontBold??!1,w.style?.fontItalic??!1,w.style?.fontFamily)}})(e,t,n,s,a,c);case"picture":return((r,i,l,u,d)=>{const{borderX:p,borderHeight:m,borderY:v,borderWidth:g,isXinverted:x,isYinverted:M}=$e(r,i,l,u,!0,d),b=Math.max(0,g-2*u.selectionPadding),Q=Math.max(0,m-2*u.selectionPadding);return Mt({...i,width:b,height:Q,x:p+u.selectionPadding,y:v+u.selectionPadding,flipX:x?!i.flipX:!!i.flipX,flipY:M?!i.flipY:!!i.flipY},u)})(t,n,s,a,c);default:return n}},Ua=(e,t,n,s,a,o,c)=>{if(n.type!=="group")return Y(n).map(v=>Hs(e,t,v,s,a,o,c));const r=n,i=Y(r),l=i.filter(v=>va.includes(v.type)),u=!l.some(v=>(v.rotation??0)!==(l[0]?.rotation??0)),d=(l[0]?.rotation??0)!==0&&l.length!==i.length,p=i.some(v=>ma.includes(v.type)),m=((v,g,x,M,b,Q)=>{const{borders:f}=g.computed,{borderX:w,borderHeight:j,borderY:E,borderWidth:V,isXinverted:C,isYinverted:Z}=$e(v,g,x,M,b,Q);return{newBorderX:w,newBorderY:E,newBorderWidth:V,newBorderHeight:j,widthMultiplier:(V-2*M.selectionPadding)/(f.width-2*M.selectionPadding||1),heightMultiplier:(j-2*M.selectionPadding)/(f.height-2*M.selectionPadding||1),isXinverted:C,isYinverted:Z,groupCenter:[w+V/2,E+j/2],rotation:g.rotation??0,settings:M,originalBorders:f}})(t,r,s,a,o||!u||p||d,c);return i.map(v=>{switch(v.type){case"rect":case"square":return((g,x,M)=>{const{isXinverted:b,isYinverted:Q,settings:f,widthMultiplier:w,heightMultiplier:j}=M,E=(b||Q)&&!(b&&Q)&&(g.rotation??0)!==0&&x.rotation!==g.rotation,V=Ye(g,x,M),C=(g.width||1)*w,Z=(g.height||1)*j,A=Xe(M,V.x,V.y,C,Z);return St({...g,width:C,height:Z,x:A[0]-C/2,y:A[1]-Z/2,rotation:E?-(g.rotation??0):g.rotation??0},f)})(v,r,m);case"picture":return((g,x,M)=>{const{isXinverted:b,isYinverted:Q,settings:f,widthMultiplier:w,heightMultiplier:j}=M,E=Ye(g,x,M),V=(g.width===0||g.height===0?g.ratio??1:g.width)*w,C=(g.width===0||g.height===0?g.ratio??1:g.height)*j,Z=Xe(M,E.x,E.y,V,C),A=(b||Q)&&!(b&&Q)&&(g.rotation??0)!==0&&x.rotation!==g.rotation;return Mt({...g,width:V,height:C,x:Z[0]-V/2,y:Z[1]-C/2,flipX:b?!g.flipX:!!g.flipX,flipY:Q?!g.flipY:!!g.flipY,rotation:A?-(g.rotation??0):g.rotation??0},f)})(v,r,m);case"text":return((g,x,M,b)=>{const{isXinverted:Q,isYinverted:f,settings:w,widthMultiplier:j,heightMultiplier:E}=b,V=(Q||f)&&!(Q&&f)&&(x.rotation??0)!==0&&M.rotation!==x.rotation,C=Ye(x,M,b),Z=(x.width===0||x.height===0?x.ratio??1:x.width)*j,A=(x.width===0||x.height===0?x.ratio??1:x.height)*E,H=Xe(b,C.x,C.y,Z,A),O=kt({...x,width:Z,height:A,x:H[0]-Z/2,y:H[1]-A/2,flipX:Q?!x.flipX:!!x.flipX,flipY:f?!x.flipY:!!x.flipY,rotation:V?-(x.rotation??0):x.rotation??0},w);return{...O,fontSize:Pt(g,O.value,O.width,O.style?.fontBold??!1,O.style?.fontItalic??!1,O.style?.fontFamily)}})(e,v,r,m);case"ellipse":return((g,x,M)=>{const{isXinverted:b,isYinverted:Q,settings:f,widthMultiplier:w,heightMultiplier:j}=M,E=(b||Q)&&!(b&&Q)&&(g.rotation??0)!==0&&x.rotation!==g.rotation,V=Ye(g,x,M),C=(g.radiusX||.5)*w,Z=(g.radiusY||.5)*j,A=Xe(M,V.x,V.y,2*C,2*Z);return wt({...g,radiusX:C,radiusY:Z,x:A[0],y:A[1],rotation:E?-(g.rotation??0):g.rotation??0},f)})(v,r,m);case"circle":return((g,x,M)=>{const b=Ye(g,x,M),Q=(g.radius||.5)*M.widthMultiplier,f=Xe(M,b.x,b.y,2*Q,2*Q);return Qt({...g,radius:Q,x:f[0],y:f[1]},M.settings)})(v,r,m);case"brush":return((g,x,M)=>{const{isXinverted:b,isYinverted:Q,settings:f,widthMultiplier:w,heightMultiplier:j}=M,E=Gt({...g,scaleX:1,scaleY:1},f),V=E.width-2*f.selectionPadding,C=E.height-2*f.selectionPadding,Z=g.scaleX??1?(g.scaleX??1)*w:w/V,A=g.scaleY??1?(g.scaleY??1)*j:j/C,H=V*Z,O=C*A,D=Ye(g,x,M),I=Xe(M,D.x,D.y,H,O),$=be(I[0]-H/2-g.computed.borders.x-f.selectionPadding)+(b?2*g.computed.borders.x+E.width:0),U=be(I[1]-O/2-g.computed.borders.y-f.selectionPadding)+(Q?2*g.computed.borders.y+E.height:0),z=(b||Q)&&!(b&&Q)&&(g.rotation??0)!==0&&x.rotation!==g.rotation;return at({...g,points:g.points.map(S=>S.map(([k,P])=>[b?-k+$:k+$,Q?-P+U:P+U])),scaleX:Z,scaleY:A,rotation:z?-(g.rotation??0):g.rotation??0},M.settings)})(v,r,m);case"line":case"polygon":case"curve":return Na(v,r,m);default:return Hs(e,t,v,s,a,o,c)}})},zs=(e,t,n,s)=>{switch(e.type){case"rect":case"square":case"ellipse":case"circle":case"picture":case"text":return Ee({...e,x:e.x+t,y:e.y+n},s);case"line":case"polygon":case"curve":return Ee({...e,points:e.points.map(([a,o])=>[a+t,o+n])},s);case"brush":return Ee({...e,points:e.points.map(a=>a.map(([o,c])=>[o+t,c+n]))},s);default:return e}},Ts=(e,t,n,s,a)=>{const o=t.computed.borders,c=((l,u)=>u?[Math.abs(l[0])>Math.abs(l[1])?l[0]:0,Math.abs(l[1])>Math.abs(l[0])?l[1]:0]:l)([e[0]-n[0],e[1]-n[1]],a),r=c[0]===0?0:ge(o.x+s.selectionPadding+c[0],s)-(o.x+s.selectionPadding),i=c[1]===0?0:ge(o.y+s.selectionPadding+c[1],s)-(o.y+s.selectionPadding);return Y(t).map(l=>zs(l,r,i,s))},Ee=(e,t)=>{switch(e.type){case"rect":case"square":return Pa(e,t);case"ellipse":return Ea(e,t);case"circle":return Za(e,t);case"picture":return Fa(e,t);case"text":return Oa(e,t);case"line":return Wa(e,t);case"polygon":return bs(e,t);case"curve":return Cs(e,t);case"brush":return Sa(e,t);default:return e}},As=({ctx:e,shape:t,settings:n,selectionWidth:s,selectionColor:a,hoverMode:o,selectionMode:c,withAnchors:r=!0})=>{switch(n.debug&&((i,l,u,d)=>{l.selection&&d.debug&&(i.save(),i.scale(d.canvasSize.scaleRatio,d.canvasSize.scaleRatio),i.translate(d.canvasOffset[0],d.canvasOffset[1]),xe(i,{fillColor:"transparent",strokeColor:"green",lineWidth:u/d.canvasSize.scaleRatio}),i.strokeRect(l.computed.boundingBox.x,l.computed.boundingBox.y,l.computed.boundingBox.width,l.computed.boundingBox.height),i.restore())})(e,t,s,n),t.type){case"rect":case"square":case"circle":case"ellipse":case"picture":case"text":case"brush":((i,l,u,d,p,m)=>{if(l.selection&&(st(i,p,l.rotation,l.computed.center),p.debug&&(xe(i,{fillColor:"transparent",strokeColor:"red",lineWidth:d/p.canvasSize.scaleRatio}),i.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(i,{fillColor:"transparent",strokeColor:u,lineWidth:d/p.canvasSize.scaleRatio}),l.selection.shapePath?i.stroke(l.selection.shapePath):i.stroke(l.selection.border),m&&!l.locked)){l.selection.shapePath&&i.stroke(l.selection.border),l.selection.line&&i.stroke(l.selection.line),xe(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/p.canvasSize.scaleRatio,shadowColor:u,shadowBlur:0});for(const v of l.selection.anchors)i.fill(v),i.stroke(v)}})(e,t,a,s,n,r);break;case"group":((i,l,u,d,p,m,v)=>{if(l.selection&&(l.shapes.forEach(g=>{xe(i,{fillColor:"transparent",strokeColor:u,lineWidth:d/m.canvasSize.scaleRatio}),st(i,m,g.rotation,g.computed.center),g.selection?.shapePath&&i.stroke(g.selection.shapePath),i.restore()}),p.mode!=="rotate"&&(st(i,m,l.rotation,l.computed.center),m.debug&&(xe(i,{fillColor:"transparent",strokeColor:"red",lineWidth:d/m.canvasSize.scaleRatio}),i.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(i,{fillColor:"transparent",strokeColor:u,lineWidth:d/m.canvasSize.scaleRatio}),v&&!l.locked))){i.stroke(l.selection.border),l.selection.line&&i.stroke(l.selection.line),xe(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/m.canvasSize.scaleRatio});for(const g of l.selection.anchors)i.fill(g),i.stroke(g)}})(e,t,a,s,c,n,r);break;case"polygon":case"line":case"curve":(({ctx:i,shape:l,withAnchors:u,selectionWidth:d,selectionColor:p,hoverMode:m,settings:v})=>{if(l.selection&&(st(i,v,l.rotation,l.computed.center),v.debug&&(xe(i,{fillColor:"transparent",strokeColor:"red",lineWidth:d/v.canvasSize.scaleRatio}),i.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(i,{fillColor:"transparent",strokeColor:p,lineWidth:d/v.canvasSize.scaleRatio}),l.selection.shapePath&&i.stroke(l.selection.shapePath),u&&!l.locked)){xe(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/v.canvasSize.scaleRatio,shadowColor:p,shadowBlur:0});for(let g=0;g<l.selection.anchors.length;g++){const x=l.selection.anchors[g];m.mode==="resize"&&m.anchor===g?(i.shadowBlur=10,i.fill(x),i.shadowBlur=0):i.fill(x),i.stroke(x)}}})({ctx:e,shape:t,withAnchors:r,selectionWidth:s,selectionColor:a,hoverMode:o,settings:n})}e.restore()},qa=({ctx:e,selectionFrame:t,settings:n})=>{st(e,n),((s,a,o)=>{xe(s,{fillColor:"rgba(170,170,170, 0.1)",strokeColor:"rgb(170,170,170)",lineWidth:1/o.canvasSize.scaleRatio}),s.fillRect(a[0][0],a[0][1],a[1][0]-a[0][0],a[1][1]-a[0][1]),s.strokeRect(a[0][0],a[0][1],a[1][0]-a[0][0],a[1][1]-a[0][1])})(e,t.frame,n),e.restore()},cn=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 a;if(n||s)a=e;else{const c=t.getAttribute("viewBox")??"0 0 300 300",[,,r,i]=c.split(" ");t.setAttribute("width",r??"300"),t.setAttribute("height",i??"300"),a=new XMLSerializer().serializeToString(t)}const o=new Blob([a],{type:"image/svg+xml"});return URL.createObjectURL(o)},Ds=e=>(e instanceof File?e.name:e).includes(".svg"),Rs=e=>Ds(e)?fetch(e).then(t=>t.text()).then(t=>Es(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),Is=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},Ga=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),dn=({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:a,realWidth:o}=t.canvasSize;n.width=o,n.height=a,s.clearRect(0,0,o,a),ss(s);for(let c=e.length-1;c>=0;c--)Zs(s,e[c],t);return n.toDataURL("image/png")},Ws=({shapes:e,settings:t,view:n})=>{if(n==="fitToShapes"&&!e.length)throw new Error("No image found to export");if(n==="fitToShapes"){const a=Math.min(...e.map(l=>l.computed.boundingBox.x)),o=Math.max(...e.map(l=>l.computed.boundingBox.x+l.computed.boundingBox.width)),c=Math.min(...e.map(l=>l.computed.boundingBox.y)),r=Math.max(...e.map(l=>l.computed.boundingBox.y+l.computed.boundingBox.height)),i={...t,canvasOffset:[-a,-c],canvasZoom:1,canvasSize:{realWidth:o-a,realHeight:r-c,width:o-a,height:r-c,scaleRatio:1,scaleRatioWithNoZoom:1}};return dn({shapes:e,settings:i})}if(n==="defaultView"){const a={...t,canvasOffset:[0,0],canvasZoom:1,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:1,scaleRatioWithNoZoom:1}};return dn({shapes:e,settings:a})}const s={...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}};return dn({shapes:e,settings:s})},_a=(e,t,n)=>{return a=un(e,t,n),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;var a},Ka=e=>{const t=["img","id","selection","path","arrows","tempPoint","computed",["flipX",[void 0,!1]],["flipY",[void 0,!1]]];return e.map(n=>n.type!=="picture"||n.src.startsWith("http")?Xt(t,n):Xt(t,{...n,src:Ga(n)}))},un=(e,t,n)=>({shapes:Ka(e),config:{width:t,height:n}}),Ns=(e,t)=>Ee({...e,id:le(`${e.type}_`)},t),Ja=(e,t,n,s)=>{const a=y.useRef([]),o=y.useRef({dataChanged:[]}),[c,r]=y.useState(void 0),[i,l]=y.useState(void 0),[u,d]=y.useState(void 0),[p,m]=y.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),v=p.cursor>0,g=p.cursor<p.states.length-1,x=a.current.length>0,M=y.useCallback(()=>{m(S=>ts(S.states[S.cursor]?.shapes,a.current)?S:{states:[...S.states.slice(0,S.cursor+1),{shapes:a.current,selectedShape:i,source:"user"}],cursor:S.cursor+1})},[i]),b=y.useCallback(S=>{a.current=[...S,...a.current]},[]),Q=y.useCallback(S=>{a.current=a.current.flatMap(k=>{const P=S.find(T=>T.id===k.id);return P?[{...P,id:le(`${k.type}_`)},k]:k})},[]),f=y.useCallback((S,k,P,T)=>{if(S.target&&"className"in S.target&&![_n,Kn].includes(S.target.className)||!T)return void d(void 0);const L=a.current.find(B=>Y(i)?.map(W=>W.id).includes(B.id)?!!ht(k,B,P,e):!!ys(k,B,P,e));d(L)},[e,i]),w=y.useCallback(async(S,k=300,P=300)=>{const T=await Ba(S,k,P,e);return b([T]),M(),T},[b,M,e]),j=y.useCallback((S,k=!1)=>{a.current=a.current.map(P=>S.find(T=>T.id===P.id)??P),l(P=>P&&ce(Y(P).map(T=>S.find(L=>L.id===T.id)??T),e)),k&&M()},[M,e]),E=y.useCallback(S=>{const k=S.map(P=>Xt(["chosen"],P));a.current=k,M()},[M]),V=y.useCallback(S=>{const k=new Set(S.map(P=>P.id));l(P=>{const T=Y(P).map(L=>L.id);return T&&k.size&&T.find(L=>k.has(L))?void 0:P}),a.current=a.current.filter(P=>!k?.has(P.id)),M()},[M]),C=y.useCallback(S=>{m(k=>{const P=S(k);return a.current=k.states[P]?.shapes??[],l(k.states[P]?.selectedShape),Qe("cursor",P,k)})},[]),Z=y.useCallback(()=>{C(S=>Math.max(0,S.cursor-1))},[C]),A=y.useCallback(()=>{C(S=>Math.min(S.states.length-1,S.cursor+1))},[C]),H=y.useCallback((S,k)=>{l(void 0),a.current=S,m(P=>k.clearHistory?{states:[{shapes:S,selectedShape:void 0,source:k.source}],cursor:0}:{states:[...P.states.slice(0,P.cursor+1),{shapes:S,selectedShape:void 0,source:k.source}],cursor:P.cursor+1})},[]),O=y.useCallback((S,k)=>{const P=a.current,T=P.findIndex(R=>R.id===S),L=P.findIndex(R=>R.id===k);var B,W,F;E((B=P,F=L,(W=T)<0||F<0||W>B.length-1||F>B.length-1?B:W<F?[...B.slice(0,W),...B.slice(W+1,F+1),B[W],...B.slice(F+1,B.length)]:[...B.slice(0,F),B[W],...B.slice(F,W),...B.slice(W+1,B.length)]))},[E]),D=y.useCallback(S=>{const k=a.current,P=new Set(S.map(L=>L.id)),T=k.map(L=>P.has(L.id)?Qe("visible",L.visible===!1,L):L);l(ps(L=>Qe("visible",L.visible===!1,L),e)),E(T)},[E,e]),I=y.useCallback(S=>{const k=a.current,P=new Set(S.map(L=>L.id)),T=k.map(L=>P.has(L.id)?Qe("locked",!L.locked,L):L);l(ps(L=>Qe("locked",!L.locked,L),e)),E(T)},[E,e]),$=y.useCallback((S,k)=>{o.current.hasOwnProperty(S)&&(o.current[S]=[...o.current[S],k])},[]),U=y.useCallback((S,k)=>{if(o.current.hasOwnProperty(S))if(k){const P=o.current[S].indexOf(k);o.current[S]=[...o.current[S].slice(0,P),...o.current[S].slice(P+1)]}else o.current[S]=[]},[]);y.useEffect(()=>{const S=p.states[p.cursor],k=un(S.shapes,t,n);for(const P of o.current.dataChanged)P(k,S.source)},[t,n,p]),y.useEffect(()=>{a.current=a.current.map(S=>Ee(S,e)),l(S=>S===void 0?void 0:ce(Y(S).map(k=>Ee(k,e)),e))},[e]);const z=y.useCallback((S,k)=>{r(P=>{const T=[P?.frame[0]??[k[0],k[1]],[k[0],k[1]]],L=a.current.filter(W=>((F,R,q)=>{const{borders:oe,center:se,boundingBox:G}=R.computed,N=Math.min(q[0][0],q[1][0]),de=Math.max(q[0][0],q[1][0]),te=Math.min(q[0][1],q[1][1]),fe={x:N,y:te,width:de-N,height:Math.max(q[0][1],q[1][1])-te},ve=nn(G,fe);if(!ve)return!1;if(oe.width<=1||oe.height<=1)return!0;if(F.lineWidth=(R.style?.lineWidth??0)+10,R.type==="brush"){const K=R.points.flat(),ue=Math.min(...K.map(ee=>ee[0])),X=Math.min(...K.map(ee=>ee[1]));for(const ee of R.points){if(ee.length<1)break;if(ee.length<2){const Me=Ve(ee[0],ue,X,R.scaleX,R.scaleY);if(as(ve,{x:Me[0],y:Me[1],radius:(R.style?.lineWidth??1)/2}))return!0}for(let Me=0;Me<ee.length-1;Me++){const ke=en(Ve(ee[Me],ue,X,R.scaleX,R.scaleY),R.rotation??0,se),ae=en(Ve(ee[Me+1],ue,X,R.scaleX,R.scaleY),R.rotation??0,se),je=nn({x:Math.min(ke[0],ae[0]),y:Math.min(ke[1],ae[1]),width:Math.abs(ke[0]-ae[0]),height:Math.abs(ke[1]-ae[1])},fe);if(je){const qe=new Path2D;if(qe.moveTo(...ke),qe.lineTo(...ae),Ss({ctx:F,path:qe,rect:je,offset:10,center:se,checkFill:!1}))return!0}}}return!1}const me=tn(R);return Ss({ctx:F,path:R.path,rect:ve,offset:10,center:se,rotation:R.rotation??0,checkFill:me})})(S,W,T)),B=ce(L,e);return l(s?ce(gs(P?.oldSelection,L),e):B),{oldSelection:P?.oldSelection,frame:T}})},[e,s]);return{registerEvent:$,unregisterEvent:U,shapesRef:a,selectedShape:i,hoveredShape:u,selectionFrame:c,setSelectionFrame:r,refreshSelectedShapes:z,addShapes:b,duplicateShapes:Q,addPictureShape:w,moveShapes:O,saveShapes:M,setSelectedShape:l,refreshHoveredShape:f,toggleShapeVisibility:D,toggleShapeLock:I,removeShape:V,updateShape:j,backwardShape:Z,forwardShape:A,clearShapes:H,canGoBackward:v,canGoForward:g,canClear:x}},Fs=e=>{const t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];var s,a;return{diff:rs(t,n),center:(a=n,[((s=t)[0]+a[0])/2,(s[1]+a[1])/2])}},eo=({canvasElt:e,canvasTransformation:t,canvasSize:n,size:s,setCanvasTransformation:a})=>{const o=y.useRef([]),[c,r]=y.useState(o.current.length>0),i=y.useRef(null),l=y.useRef(t);l.current=t;const u=y.useCallback(({startDiff:d,startZoom:p,startCenter:m,startOffset:v,currentDiff:g,currentCenter:x,isMoving:M,isZooming:b})=>{if(!e||!g||!d)return;const Q=(({canvasBoundingRect:f,canvasSize:w,size:j,startDiff:E,startZoom:V,startCenter:C,startOffset:Z,currentDiff:A,currentCenter:H,isMoving:O,isZooming:D})=>{const I=D?ze(A/E*V,we[0],we[we.length-1]):V,$=O?[Z[0]+(H[0]-C[0])*(w.width/f.width)/w.scaleRatio/V,Z[1]+(H[1]-C[1])*(w.height/f.height)/w.scaleRatio/V]:[Z[0],Z[1]],U=[(H[0]-f.left)/w.scaleRatio,(H[1]-f.top)/w.scaleRatio];return on({size:j,canvasSize:w,currentOffset:$,currentZoom:V,zoom:I,centerPoint:U})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:n,size:s,startDiff:d,startZoom:p,startCenter:m,startOffset:v,currentDiff:g,currentCenter:x,isMoving:M,isZooming:b});a(Q)},[e,n,s,a]);y.useEffect(()=>{if(!e)return;const d=p=>{if(o.current=[...o.current,p],r(o.current.length>0),o.current.length===2){p.stopPropagation();const{diff:m,center:v}=Fs(o.current);i.current={startDiff:m,startCenter:v,startZoom:l.current.zoom,startOffset:l.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",d),()=>{e.removeEventListener("pointerdown",d)}},[e]),y.useEffect(()=>{if(!c)return;const d=m=>{const v=o.current.findIndex(g=>g.pointerId===m.pointerId);if(v>-1&&(o.current[v]=m),o.current.length===2&&i.current){const{diff:g,center:x}=Fs(o.current),M=i.current.isZooming||((Q,f)=>Math.abs(Q-f.startDiff)>30)(g,i.current),b=i.current.isMoving||M||((Q,f)=>Math.abs(rs(Q,f.startCenter))>10)(x,i.current);i.current={...i.current,isMoving:b,isZooming:M},u({...i.current,currentDiff:g,currentCenter:x})}},p=m=>{o.current=o.current.filter(v=>v.pointerId!==m.pointerId),r(o.current.length>0)};return document.addEventListener("pointermove",d),document.addEventListener("pointerup",p),document.addEventListener("pointerout",p),document.addEventListener("pointercancel",p),document.addEventListener("pointerleave",p),()=>{document.removeEventListener("pointermove",d),document.removeEventListener("pointerup",p),document.removeEventListener("pointerout",p),document.removeEventListener("pointercancel",p),document.removeEventListener("pointerleave",p)}},[c,u])},Bs={offset:[0,0],zoom:1},to=({canvasSize:e,size:t,zoomEnabled:n,canvasElt:s})=>{const[a,o]=y.useState(Bs),c=y.useRef(0),r=y.useCallback(u=>{o(({zoom:d})=>an({zoom:d,size:t,canvasSize:e,newOffset:u}))},[e,t]),i=y.useCallback(u=>{o(({offset:d,zoom:p})=>(({size:m,canvasSize:v,currentOffset:g,currentZoom:x,action:M})=>{const b=M==="default"?we[4]:M==="zoom"?we[ze(we.length-1-we.slice(0).reverse().findIndex(f=>f<=x)+1,0,we.length-1)]:we[ze(we.findIndex(f=>f>=x)-1,0,we.length-1)],Q=[v.realWidth/2,v.realHeight/2];return on({size:m,canvasSize:v,currentOffset:g,currentZoom:x,zoom:b,centerPoint:Q})})({size:t,canvasSize:e,currentOffset:d,currentZoom:p,action:u}))},[e,t]);eo({canvasElt:s,canvasTransformation:a,canvasSize:e,size:t,setCanvasTransformation:o});const l=y.useCallback(()=>{o(Bs)},[]);return y.useEffect(()=>{if(!n||!s)return;const u=d=>{const p=d.ctrlKey,{deltaX:m,deltaY:v}=((b,Q)=>{const f=Math.abs(b.deltaY)<50&&Q<50,w=b.ctrlKey,j=ns()&&f&&w;switch(b.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:16*b.deltaX,deltaY:16*b.deltaY};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:b.deltaX*window.innerHeight,deltaY:b.deltaY*window.innerHeight};default:return j?{deltaX:5*b.deltaX,deltaY:5*b.deltaY}:{deltaX:b.deltaX,deltaY:b.deltaY}}})(d,d.timeStamp-c.current);if(c.current=d.timeStamp,p){d.preventDefault();const b=vs(d,s,e);return void o(({offset:Q,zoom:f})=>(({size:w,canvasSize:j,currentOffset:E,currentZoom:V,delta:C,centerPoint:Z})=>{const A=ze(V*(1-C/1e3),we[0],we[we.length-1]);return on({size:w,canvasSize:j,currentOffset:E,currentZoom:V,zoom:A,centerPoint:Z})})({size:t,canvasSize:e,currentOffset:Q,currentZoom:f,delta:v,centerPoint:b}))}const g=d.shiftKey,[x,M]=g?[v,m]:[m,v];o(({offset:b,zoom:Q})=>{const f=[b[0]-x/Q,b[1]-M/Q],w=an({zoom:Q,size:t,canvasSize:e,newOffset:f});return w.offset[0]===b[0]&&w.offset[1]===b[1]||d.preventDefault(),w})};return s.addEventListener("wheel",u,{passive:!1}),()=>{s.removeEventListener("wheel",u)}},[s,t,e,n]),{setCanvasTransformation:o,setCanvasOffset:r,setCanvasZoom:i,resetZoom:l,canvasTransformation:a}},Os=(e,t=!1)=>{const n=(a,o)=>{if(Array.isArray(a))return o},s=e.map(a=>{if(typeof a!="object")return null;switch(a.type){case"brush":return He(n,En,a);case"circle":return He(n,Fn,a);case"curve":return He(n,In,a);case"ellipse":return He(n,Bn,a);case"line":return He(n,Dn,a);case"polygon":return He(n,Rn,a);case"rect":return He(n,Wn,a);case"square":return He(n,Nn,a);case"text":return He(n,On,a)}return null});return cn(t?[...s,Ft]:s)},no=({addShapes:e,drawCanvasRef:t,setActiveTool:n,refreshHoveredShape:s,shapes:a,selectionMode:o,activeTool:c,isInsideComponent:r,setCanvasOffset:i,selectedShape:l,canvasOffsetStartData:u,refreshSelectedShapes:d,setSelectedShape:p,setSelectionFrame:m,setCanvasOffsetStartData:v,updateSingleShape:g,duplicateShapes:x,saveShapes:M,setSelectionMode:b,setCanvasMoveAcceleration:Q,settings:f,isShiftPressed:w,isAltPressed:j,withFrameSelection:E,isSpacePressed:V})=>{const[C,Z]=y.useState({mode:"default"}),{registerDoubleClickEvent:A,unRegisterDoubleClickEvent:H}=(()=>{const S=y.useRef(void 0),k=y.useRef(void 0),P=T=>{const L=Date.now();S.current&&L<S.current+300&&k.current?.(T),S.current=Date.now()};return{registerDoubleClickEvent:(T,L)=>{k.current=L,T.addEventListener("click",P),T.addEventListener("touchend",P)},unRegisterDoubleClickEvent:T=>{T.removeEventListener("click",P),T.removeEventListener("touchend",P)}}})(),O=y.useRef(null);O.current=S=>((k,P,T,L,B,W,F,R,q,oe,se,G,N,de,te,fe,ve)=>{if(rt(k)&&k.touches.length>1)return;const me=P.current?.getContext("2d");if(!me)return;const K=it(k,P.current,N);if(L.mode==="selectionFrame"){G(me,K,N);const X=vs(k,P.current,N.canvasSize);return void ve([Math.ceil(ze(X[0]*N.canvasZoom<50?X[0]*N.canvasZoom-50:X[0]*N.canvasZoom>N.canvasSize.width/N.canvasSize.scaleRatioWithNoZoom-50?X[0]*N.canvasZoom-(N.canvasSize.width/N.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/N.canvasZoom),Math.ceil(ze(X[1]*N.canvasZoom<50?X[1]*N.canvasZoom-50:X[1]*N.canvasZoom>N.canvasSize.height/N.canvasSize.scaleRatioWithNoZoom-50?X[1]*N.canvasZoom-(N.canvasSize.height/N.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/N.canvasZoom)])}if(W!==void 0)return void se([K[0]+N.canvasOffset[0]-W.start[0],K[1]+N.canvasOffset[1]-W.start[1]]);if(L.mode==="preview"){const X=Y(T)[0];if(X?.type==="curve"){const ee=Ms(X,K,N,!0);return void fe(ce([ee],N))}if(X?.type==="polygon"){const ee=ws(X,K,N,!0);return void fe(ce([ee],N))}}const ue=pt(K,N);if(rt(k)||R(k,me,K,ue),T===void 0||T.locked)F({mode:"default",outOfView:!ue});else{if(L.mode==="default"||L.mode==="textedition"){if(!ue)return void F({mode:"default"});F(ht(me,T,K,N,!0)||{mode:"default"})}else{const X=P.current?.getContext("2d");if(!X)return;const ee=xa(X,T,K,L,N,de,te);q(Y(ee))}L.mode==="translate"&&te&&!L.hasBeenDuplicated&&(B({...L,hasBeenDuplicated:!0}),oe(Y(L.originalShape)))}})(S,t,l,o,b,u,Z,s,g,x,i,d,f,w,j,p,Q),y.useEffect(()=>{if(r){const S=k=>O.current?.(k);return document.addEventListener("mousemove",S),document.addEventListener("touchmove",S),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("touchmove",S)}}},[r]);const{isBrushShapeDoneOnMouseUp:D}=f,I=y.useRef(null);I.current=S=>{if(rt(S)&&S.touches.length>1)return;const k=t.current?.getContext("2d");if(!k)return;if("button"in S&&S.button===2)return p(void 0),n(Re),b({mode:"default"}),void m(void 0);if(u)return void v(void 0);if(o.mode==="textedition"||o.mode==="preview")return;const P=it(S,t.current,f);if(o.mode==="translate"&&Date.now()-o.dateStart<=500&&P[0]===o.cursorStartPosition[0]&&P[1]===o.cursorStartPosition[1]){if(S.ctrlKey||S.shiftKey||S.metaKey){const{shape:T}=hs(k,a,P,f,l,rt(S),E,"remove");Y(T).length!==o.selectedShapesLengthAtMouseDown&&p(T)}return b({mode:"default"}),m(void 0),void M()}o.mode!=="default"&&(o.mode==="brush"&&D&&p(void 0),b({mode:"default"}),m(void 0),M())},y.useEffect(()=>{if(r){const S=k=>I.current?.(k);return document.addEventListener("mouseup",S),document.addEventListener("touchend",S),()=>{document.removeEventListener("mouseup",S),document.removeEventListener("touchend",S)}}},[r]);const $=!f.features.edition&&f.features.zoom,U=!f.features.edition&&!f.features.zoom,z=y.useRef(null);return z.current=(S,k,P)=>{if(S.preventDefault(),rt(S)&&S.touches.length>1)return;const T=k?.getContext("2d");if(!T)return;k.focus();const L=it(S,t.current,f),B="button"in S&&S.button===1;if(!("button"in S&&S.button===2)){if(B||P||c.type==="move")v({start:L,originalOffset:f.canvasOffset});else if(!$){if(!pt(L,f))return p(void 0),void b({mode:"default"});if(c.type==="selection"){const W=S.ctrlKey||S.shiftKey||S.metaKey?"add":"replace",{shape:F,mode:R}=hs(T,a,L,f,l,rt(S),E,W);p(F),b(R),R.mode==="selectionFrame"&&m({oldSelection:F,frame:[[L[0],L[1]],[L[0],L[1]]]})}else if(Gn.some(W=>W===c.type)){const W=Y(l)[0],F=t.current?.getContext("2d");if(!F)return;if(c.type==="brush"){if(W?.type==="brush"){const R=((q,oe,se)=>{const G={...q,points:Qe(q.points.length,[[Math.round(oe[0]),Math.round(oe[1])]],q.points)};return at(G,se)})(W,L,f);g([R])}else{const R=js(F,c,L,f);if(!R)return;e([R]),p(ce([R],f))}b({mode:"brush"})}else if(o.mode!=="preview"||W?.type!=="polygon"&&W?.type!=="curve"){if(c.type!=="picture"){const R=js(F,c,L,f);if(!R)return;e([R]);const q=ce([R],f);p(q),R.type==="polygon"||R.type==="curve"?b({mode:"preview"}):(n(Re),b({mode:"resize",cursorStartPosition:[L[0]+f.selectionPadding,L[1]+f.selectionPadding],originalShape:q,anchor:R.type==="line"?0:[1,1],selectedShapesLengthAtMouseDown:Y(q).length}))}}else{const R=W.type==="polygon"?ws(W,L,f):Ms(W,L,f);p(ce([R],f)),g([R],!0)}}}}},y.useEffect(()=>{if(U)return;const S=t.current;if(!S)return;const k=P=>z.current?.(P,S,V);return S.addEventListener("mousedown",k,{passive:!1}),S.addEventListener("touchstart",k,{passive:!1}),()=>{S.removeEventListener("mousedown",k),S.removeEventListener("touchstart",k)}},[U,t,V]),y.useEffect(()=>{const S=t.current,k=t.current?.getContext("2d");if(!(!S||!k))return r?(A(S,P=>{if(c.type==="selection"){if(Y(l).length!==1)return;const T=Y(l)[0];if(T?.type==="text"){const L=it(P,t.current,f);return pt(L,f)?void(ht(k,l,L,f)&&b({mode:"textedition",defaultValue:T.value})):void 0}if(T?.type==="polygon"){const L=it(P,t.current,f);if(!pt(L,f))return;const B=ms(k,T,L,f);return void(B&&g([Ha(T,B.lineIndex,L,f)]))}if(T?.type==="curve"){const L=it(P,t.current,f);if(!pt(L,f))return;const B=((W,F,R,q,oe=50)=>{if(F.locked||F.points.length<2)return!1;if(F.points.length<3)return ms(W,F,R,q,oe);const{center:se}=F.computed,G=Ae(R,F.rotation??0,se);W.lineWidth=(F.style?.lineWidth??0)+oe/q.canvasZoom;const N=_t(F,F.points),de=new Path2D;de.moveTo(...N[0]);for(let te=1;te<N.length-2;te++){const fe=N[te-1],ve=N[te],me=N[te+1],K=N[te+2],{cp1:ue,cp2:X}=Kt(fe,ve,me,K);if(de.bezierCurveTo(ue[0],ue[1],X[0],X[1],me[0],me[1]),W.isPointInStroke(de,G[0],G[1]))return{lineIndex:te-1}}return!1})(k,T,L,f);return void(B&&g([Ta(T,B.lineIndex,L,f)]))}}}),()=>{H(S)}):void 0},[g,A,H,r,t,c,l,b,f]),{hoverMode:C}},Ys=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>Ys(t)).join(""):e.nodeValue??"",so=({disabled:e=!1,shape:t,defaultValue:n,updateValue:s,saveShapes:a,settings:o})=>{const c=y.useRef(null),r=y.useRef(a);y.useEffect(()=>{if(!c.current)return;const u=c.current,d=p=>{p.preventDefault();const m=p.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,m)};u.addEventListener("paste",d),u.innerText="";for(const p of n){const m=document.createElement("div");p===""?m.innerHTML="<br/>":m.innerText=p,u.appendChild(m)}return u.focus(),()=>{u.removeEventListener("paste",d)}},[n]),y.useEffect(()=>{const u=r.current;return()=>{u()}},[]);const i=y.useMemo(()=>{const{borders:u,center:d}=t.computed;return ne({point:[u.x,u.y],rotation:-(t.rotation??0),origin:d})},[t]),l=[`translate3D(${(i[0]+o.canvasOffset[0])*o.canvasSize.scaleRatio}px, ${(i[1]+o.canvasOffset[1])*o.canvasSize.scaleRatio}px, 0)`,`rotate(${qt(t.rotation??0)}deg)`,t.flipX||t.flipY?`scale(${t.flipX?-1:1}, ${t.flipY?-1:1})`:void 0,t.flipX||t.flipY?`translate3D(${t.flipX?-100:0}%,${t.flipY?-100:0}%,0)`:void 0].filter(Boolean).join(" ");return h.jsx("div",{className:"react-paint-editor-toolbox-edittextbox",ref:c,"data-fontbold":t.style?.fontBold??!1,"data-fontitalic":t.style?.fontItalic??!1,contentEditable:!e,onInput:u=>{const d=Array.from(u.target.childNodes).map(p=>Ys(p));s(d)},style:{"--react-paint-editor-toolbox-edittextbox-transform":l,"--react-paint-editor-toolbox-edittextbox-fontsize":t.fontSize*o.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-padding":o.selectionPadding*o.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-color":t.style?.strokeColor??"inherit","--react-paint-editor-toolbox-edittextbox-opacity":(t.style?.opacity??100)/100,"--react-paint-editor-toolbox-edittextbox-fontfamily":t.style?.fontFamily??dt}})},ao=(e,t,n,s,a)=>{ss(e),((o,c)=>{const{canvasZoom:r,size:i,canvasSize:{width:l,height:u}}=c;if(i!=="fixed"||r>=1)return;o.fillStyle="#f5f5f5",o.fillRect(0,0,l,u);const d=xs(c);o.clearRect(d.x,d.y,d.width,d.height),Qs(o,c)})(e,n),((o,c)=>{const{canvasSize:{width:r,height:i},gridGap:l,canvasOffset:u,canvasSize:{scaleRatio:d}}=c;if(!l)return;o.strokeStyle="rgb(220,220,220)",o.lineWidth=1,o.save(),o.scale(d,d),o.beginPath();const p=u[0]%l,m=u[1]%l,v=Math.ceil(r/d/l)+2,g=Math.ceil(i/d/l)+2;for(let x=-5;x<v;x++)o.moveTo(p+(x+1)*l,m-l),o.lineTo(p+(x+1)*l,m+i/d+l);for(let x=-5;x<g;x++)o.moveTo(p-l,m+(x+1)*l),o.lineTo(p+r/d+l,m+(x+1)*l);o.stroke(),o.restore()})(e,n);for(let o=s.length-1;o>=0;o--)t.mode==="textedition"&&s[o]===a||Zs(e,Y(a).find(c=>c.id===s[o].id)??s[o],n)},oo=y.forwardRef(({canGrow:e,shapes:t,duplicateShapes:n,addShapes:s,updateSingleShape:a,selectedShape:o,setSelectedShape:c,setSelectionFrame:r,hoveredShape:i,selectionFrame:l,refreshHoveredShape:u,refreshSelectedShapes:d,saveShapes:p,activeTool:m,setActiveTool:v,canvasOffsetStartData:g,setCanvasOffsetStartData:x,setCanvasOffset:M,setCanvasMoveAcceleration:b,isInsideComponent:Q,selectionMode:f,setSelectionMode:w,selectionWidth:j,selectionColor:E,settings:V,isEditMode:C,isShiftPressed:Z,isAltPressed:A,isSpacePressed:H,withFrameSelection:O,withSkeleton:D},I)=>{const $=y.useRef(null),U=y.useRef(null),z=V.canvasSize,S=C,k=C?0:-1;y.useImperativeHandle(I,()=>$.current);const{hoverMode:P}=no({addShapes:s,drawCanvasRef:$,setActiveTool:v,shapes:t,selectionMode:f,activeTool:m,isInsideComponent:Q,setCanvasOffset:M,selectedShape:o,canvasOffsetStartData:g,setCanvasOffsetStartData:x,setSelectedShape:c,setSelectionFrame:r,refreshHoveredShape:u,refreshSelectedShapes:d,updateSingleShape:a,duplicateShapes:n,saveShapes:p,setSelectionMode:w,setCanvasMoveAcceleration:b,isShiftPressed:Z,isAltPressed:A,withFrameSelection:O,settings:V,isSpacePressed:H}),T=y.useCallback(B=>{const W=Y(o)[0];if(W?.type!=="text")return;const F=$.current?.getContext("2d");if(!F)return;const R=Ee(Xa(F,W,B,V),V);a([R])},[a,o,V]),L=B=>{if(C)return B.preventDefault(),B.stopPropagation(),!1};return y.useEffect(()=>{const B=$.current?.getContext("2d");B&&window.requestAnimationFrame(()=>ao(B,f,V,t,o))},[t,f,o,V]),y.useEffect(()=>{const B=U.current?.getContext("2d");B&&window.requestAnimationFrame(()=>((W,F,R,q,oe,se,G,N,de,te,fe)=>{W.reset(),Qs(W,R),fe&&N&&!Y(G).find(ve=>ve.id===N.id)&&q.type==="selection"&&F.mode==="default"&&As({ctx:W,shape:N,settings:R,selectionWidth:oe,selectionColor:se,hoverMode:de,selectionMode:F,withAnchors:!1}),G&&q.type!=="brush"&&As({ctx:W,shape:G,settings:R,selectionWidth:oe,selectionColor:se,hoverMode:de,selectionMode:F,withAnchors:F.mode!=="textedition"}),te&&qa({ctx:W,selectionFrame:te,settings:R})})(B,f,V,m,j,E,o,i,P,l,D))},[i,P,l,f,o,m,V,j,E,D]),h.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":g?"grabbing":P.outOfView?"default":P.mode==="resize"?"pointer":m.type!=="selection"&&m.type!=="move"?"crosshair":P.mode==="translate"?"move":P.mode==="rotate"||m.type==="move"||H?"grab":"default"},children:h.jsxs("div",{className:"react-paint-canvas-container","data-grow":e,children:[h.jsx("canvas",{className:_n,ref:$,"data-grow":e,width:z.width,height:z.height,onContextMenu:L,tabIndex:k}),S&&h.jsx("canvas",{className:Kn,ref:U,width:z.width,height:z.height,"data-grow":e,onContextMenu:L}),C&&f.mode==="textedition"&&Y(o)[0]?.type==="text"&&h.jsx(so,{disabled:!V.features.edition,shape:Y(o)[0],defaultValue:f.defaultValue,updateValue:T,saveShapes:p,settings:V})]})})}),Xs="ArrowUp",$s="ArrowDown",Us="ArrowLeft",qs="ArrowRight",io="Delete",ro="Backspace",lo="Escape",Gs="Shift",_s="Alt",Ks="Option",Lt=" ",co="z",uo="Z",ho="y",po="Y",go="+",fo="-",vo="0",Js="copy",ea="paste",mo=({isInsideComponent:e,isInsideCanvas:t,selectedShape:n,isEditingText:s,settings:a,setSelectedShape:o,setActiveTool:c,setCanvasZoom:r,resetZoom:i,setSelectionMode:l,setSelectionFrame:u,removeShape:d,pasteShapes:p,updateShapes:m,backwardShape:v,forwardShape:g,setShiftPressed:x,setAltPressed:M,setIsSpacePressed:b})=>{const[Q,f]=y.useState(void 0);return y.useEffect(()=>{const w=C=>{n&&(s||(C.preventDefault(),f({...n})))},j=C=>{Q&&(s||(C.preventDefault(),p(((Z,A)=>Y(Z).map(H=>({...zs(H,20,20,A),id:le(`${H.type}_`)})))(Q,a))))},E=C=>{switch(C.key){case Gs:x(!1);break;case _s:case Ks:M(!1);break;case Lt:b(!1)}},V=C=>{if(C.metaKey||C.ctrlKey){if(C.key===uo||C.key===co)return C.preventDefault(),C.stopPropagation(),void(C.shiftKey?g():v());if(!ns()&&(C.key===po||C.key===ho))return C.preventDefault(),C.stopPropagation(),void g();if(C.key===go)return C.preventDefault(),C.stopPropagation(),void r("zoom");if(C.key===fo)return C.preventDefault(),C.stopPropagation(),void r("unzoom");if(C.key===vo)return C.preventDefault(),C.stopPropagation(),void i()}if(C.key===Gs)return C.preventDefault(),C.stopPropagation(),void x(!0);if(C.key===Lt&&t)return C.preventDefault(),C.stopPropagation(),void b(!0);if(C.key===_s||C.key===Ks)return C.preventDefault(),C.stopPropagation(),void M(!0);if(!n)return;if(C.key===lo)return o(void 0),c(Re),l({mode:"default"}),void u(void 0);if(s)return;const Z={[Us]:[a.gridGap?-a.gridGap:-1,0],[qs]:[a.gridGap?a.gridGap:1,0],[$s]:[0,a.gridGap?a.gridGap:1],[Xs]:[0,a.gridGap?-a.gridGap:-1]};switch(C.key){case Us:case qs:case $s:case Xs:C.preventDefault(),C.stopPropagation(),m(Ts(Z[C.key],n,[0,0],a,!0));break;case io:case ro:C.preventDefault(),C.stopPropagation(),d(Y(n))}};if(e)return document.addEventListener("keydown",V),document.addEventListener("keyup",E),document.addEventListener(Js,w),document.addEventListener(ea,j),()=>{document.removeEventListener("keydown",V),document.removeEventListener("keyup",E),document.removeEventListener(Js,w),document.removeEventListener(ea,j)}},[e,t,Q,s,n,a,m,d,o,p,v,g,x,M,c,l,u,r,i,b]),{}},yo=({isLoading:e=!1})=>{const[t,n]=y.useState("hidden");return y.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":ga,"--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",{})]})})},So="infos",xo=4e3,Qo=({type:e,text:t,duration:n})=>{const[s,a]=y.useState(!1);return y.useEffect(()=>{const o=setTimeout(()=>{a(!0)},100),c=setTimeout(()=>{a(!1)},n-500-100);return()=>{clearTimeout(o),clearTimeout(c)}},[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})},bo=({snackbarList:e})=>h.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":fa},children:e.map(t=>h.jsx(Qo,{...t},t.id))}),wo=y.forwardRef((e,t)=>{const{hidden:n=!1,disabled:s=!1,selected:a=!1,icon:o,children:c,className:r="",title:i,onClick:l,...u}=e,d=s?-1:0,p=y.useRef(null);return y.useImperativeHandle(t,()=>p.current),h.jsxs("label",{className:`react-paint-editor-button ${r}`,title:i,onClick:l,"data-disabled":+s,"data-selected":+a,"data-hidden":+n,tabIndex:d,onKeyDown:m=>{m.key===Lt&&(m.preventDefault(),m.stopPropagation())},onKeyUp:m=>{m.preventDefault(),m.stopPropagation(),m.key===Lt&&p.current?.click()},children:[h.jsx("input",{ref:p,disabled:s,...u}),h.jsxs("span",{className:"react-paint-editor-button-content",children:[c&&h.jsx("span",{className:"react-paint-editor-button-children",children:c}),o&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:o}})]})]})}),_=y.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color")return h.jsx(wo,{...e,ref:t});const{hidden:n=!1,disabled:s=!1,selected:a=!1,icon:o,children:c,type:r="button",className:i="",...l}=e;return h.jsx("button",{className:`react-paint-editor-button ${i}`,ref:t,disabled:s,"data-disabled":+s,"data-selected":+a,"data-hidden":+n,type:r,...l,children:h.jsxs("span",{className:"react-paint-editor-button-content",children:[c&&h.jsx("span",{className:"react-paint-editor-button-children",children:c}),o&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:o}})]})})}),Ue=({children:e,title:t="",className:n="",position:s="bottom",fitContainer:a=!1,alignment:o="center",style:c,...r})=>h.jsxs("div",{className:`react-paint-editor-panel ${n}`,"data-fitcontainer":a,"data-position":s,"data-alignment":o,style:{...c,"--react-paint-editor-panel-zindex":Tn},...r,children:[t&&h.jsx("h3",{className:"react-paint-editor-panel-title",children:t}),e]}),Co=e=>{switch(e){case"brush":return Qn;case"line":return Mn;case"polygon":return Wt;case"curve":return kn;case"rect":case"square":return Rt;case"circle":case"ellipse":return It;case"text":return Cn;case"picture":return Nt;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""}},Mo=({disabled:e=!1,shape:t,selected:n,layoutDragging:s,toggleShapeVisibility:a,toggleShapeLock:o,setLayoutDragging:c,handleRemove:r,handleSelect:i,onMoveShapes:l})=>{const u=y.useRef(null),{isOver:d}=(({disabled:p=!1,ref:m,shape:v,layoutDragging:g,setLayoutDragging:x,handleSelect:M,onMoveShapes:b})=>{const[Q,f]=y.useState(!1);return y.useEffect(()=>{g||f(!1)},[g]),y.useEffect(()=>{const w=m.current;if(!w)return;const j=()=>{x(void 0)},E=H=>(H.preventDefault&&H.preventDefault(),!1),V=H=>{M([v]),H.dataTransfer&&(H.dataTransfer.effectAllowed="move",H.dataTransfer.setData("draggableShapeId",v.id),x(v.id))},C=()=>{g!==v.id&&f(!0)},Z=()=>{f(!1)},A=H=>(H.stopPropagation(),H.dataTransfer&&b(H.dataTransfer.getData("draggableShapeId"),v.id),!1);return p||(w.addEventListener("dragstart",V),w.addEventListener("dragend",j),w.addEventListener("dragover",E),w.addEventListener("dragenter",C),w.addEventListener("dragleave",Z),w.addEventListener("drop",A)),()=>{p||(w.removeEventListener("dragstart",V),w.removeEventListener("dragend",j),w.removeEventListener("dragover",E),w.removeEventListener("dragenter",C),w.removeEventListener("dragleave",Z),w.removeEventListener("drop",A))}},[p,m,v,x,M,b,g]),{isOver:Q}})({disabled:e,ref:u,shape:t,layoutDragging:s,setLayoutDragging:c,handleSelect:i,onMoveShapes:l});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:p=>{e||(p.preventDefault(),p.stopPropagation(),i([t]))},"data-selected":+n,ref:u,tabIndex:-1,children:[h.jsx("span",{dangerouslySetInnerHTML:{__html:Co(t.type)}}),h.jsx("span",{children:t.id}),h.jsx("div",{className:"react-paint-editor-layouts-separator"}),h.jsx(_,{className:"react-paint-editor-layouts-visible-button",title:t.visible?"Hide":"Show","data-visible":t.visible!==!1,disabled:e,selected:n,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),a([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(_,{className:"react-paint-editor-layouts-locked-button",title:t.locked?"Locked":"Unlocked","data-locked":!!t.locked,disabled:e,selected:n,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),o([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(_,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),r([t]))},icon:bn})]})},ko=({gridFormat:e,setGridFormat:t,settings:n,shapes:s,removeShape:a,toggleShapeVisibility:o,toggleShapeLock:c,selectedShapes:r,moveShapes:i,selectShapes:l,isLayoutPanelShown:u})=>{const[d,p]=y.useState(void 0),m=!n.features.edition;return u?h.jsx(Ue,{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(_,{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=>h.jsx(_,{className:"react-paint-editor-layouts-grid-button",selected:e===v,disabled:m,onClick:()=>t(v),children:v.charAt(0).toUpperCase()},v))]}),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(v=>h.jsx(Mo,{shape:v,disabled:m,layoutDragging:d,setLayoutDragging:p,selected:Y(r).some(g=>g.id===v.id)??!1,handleSelect:l,handleRemove:a,onMoveShapes:i,toggleShapeVisibility:o,toggleShapeLock:c},v.id))})]})})}):null},jt=({children:e,onClose:t,position:n="center",title:s,className:a=""})=>h.jsxs("div",{className:"react-paint-editor-modal","data-position":n,style:{"--react-paint-editor-modal-zindex":Tn},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 ${a}`,children:e})]}),Vt=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez une couleur",mode:s="fill",disabled:a=!1,values:o,field:c,value:r="",valueChanged:i})=>{const[l]=y.useState(le("settings_")),u=e===l;return o.length?h.jsxs(h.Fragment,{children:[h.jsx(_,{selected:u,title:n,disabled:a,onClick:()=>{t(d=>d===l?void 0:l)},icon:r==="transparent"?s==="fill"?Zn:Vn:void 0,children:r!=="transparent"&&h.jsx("div",{className:"react-paint-editor-colorfield-color","data-mode":s,style:{"--react-paint-editor-colorfield-color-value":r}})}),u&&h.jsx(Ue,{title:n,alignment:"left",children:h.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[o.map(d=>h.jsx(_,{title:d,selected:d===r,color:d,icon:d==="transparent"?s==="fill"?Zn:Vn:void 0,onClick:()=>{i(c,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(_,{type:"color",title:"Custom color",selected:r!==""&&!o.includes(r),value:r,onChange:d=>{const p=+d.target.value;i(c,Number.isNaN(p)?d.target.value:p)},children:h.jsx("div",{className:"react-paint-editor-colorfield-customcolor",style:{"--react-paint-editor-colorfield-color-value":o.includes(r)?"var(--react-paint-editor-app-font-color)":r},children: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},Po=({disabled:e=!1,selectedShape:t,removeShape:n})=>h.jsx(_,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{n(Y(t))},icon:bn}),Zt=({CustomOption:e,selectedSettings:t,setSelectedSettings:n,title:s="Choisissez l'option",disabled:a=!1,field:o,icon:c,values:r,defaultValue:i,valueChanged:l})=>{const[u]=y.useState(le("settings_")),d=t===u;return r.length?h.jsxs(h.Fragment,{children:[h.jsx(_,{selected:d,title:s,icon:c,disabled:a,onClick:()=>{n(p=>p===u?void 0:u)}}),d&&h.jsx(Ue,{title:s,alignment:"left",fitContainer:!0,children:h.jsx("div",{className:"react-paint-editor-selectfield-wrapper",children:r.map(p=>h.jsx(_,{title:`${p}`,onClick:()=>(m=>{l(o,m)})(p),selected:i===p,style:{"--react-paint-editor-button-padding":"16px"},children:h.jsx(e,{children:p})},p))})})]}):null},Lo=({children:e})=>h.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),ta=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:o})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Lo,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:a,valueChanged:o}):null,jo=({disabled:e,toggleLayoutPanel:t})=>h.jsx(_,{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"}),Vo=({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"})]}),na=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:o})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Vo,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:a,valueChanged:o}):null,Zo=({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",{})]}),sa=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:o})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Zo,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:a,valueChanged:o}):null,Ht=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez l'intervalle",icon:s,disabled:a=!1,field:o,value:c,min:r=1,max:i=20,step:l=1,unity:u="",valueChanged:d,saveShapes:p})=>{const m=c===void 0,v=m?"N/A":`${Math.round(c)}${u}`,[g]=y.useState(le("settings_")),x=((b,Q=500)=>{const f=y.useRef(null),w=y.useCallback((...j)=>{f.current&&clearTimeout(f.current),f.current=setTimeout(()=>b(...j),Q)},[b,Q]);return y.useEffect(()=>()=>{f.current&&clearTimeout(f.current)},[]),w})(p),M=e===g;return r===i?null:h.jsxs(h.Fragment,{children:[h.jsx(_,{selected:M,title:n,disabled:a,icon:s,onClick:()=>{t(b=>b===g?void 0:g)}}),M&&h.jsx(Ue,{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:r,max:i,step:l,value:c??(i+r)/2,"data-indeterminate":+m,onChange:b=>{const Q=+b.target.value,f=Number.isNaN(Q)?b.target.value:Q;d(o,f,!1),x()}}),h.jsx("span",{children:v})]})})})]})},Ho=({children:e})=>h.jsx("span",{children:e===0?"Non":"Oui"}),zo=[0,1],aa=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,defaultValue:s,valueChanged:a})=>h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Ho,title:"Fermer les points",icon:Wt,disabled:n,field:"closedPoints",values:zo,defaultValue:s,valueChanged:a}),To=({disabled:e=!1,className:t,toggleZoomPanel:n})=>h.jsx(_,{title:"Toggle zoom panel",disabled:e,onClick:n,icon:Hn,className:t?` ${t}`:""}),zt=({setSelectedSettings:e,disabled:t=!1,field:n,icon:s,values:a,value:o=!1,valueChanged:c})=>{const[r]=y.useState(le("settings_"));return a.length!==2?null:h.jsx(_,{onClick:()=>{e(i=>i===r?void 0:r),c(n,!o)},selected:o,disabled:t,icon:s})},hn=({activeTool:e,selectedShape:t,selectedShapeTool:n,disabled:s,selectedSettings:a,setSelectedSettings:o,saveShapes:c,handleShapeStyleChange:r,handleShapeFontFamilyChange:i})=>t?n&&h.jsxs(h.Fragment,{children:["strokeColor"in n.settings&&!n.settings.strokeColor.hidden&&h.jsx(Vt,{selectedSettings:a,setSelectedSettings:o,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(Vt,{selectedSettings:a,setSelectedSettings:o,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(Ht,{saveShapes:c,selectedSettings:a,setSelectedSettings:o,title:"Epaisseur du trait",icon:jn,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(sa,{selectedSettings:a,setSelectedSettings:o,disabled:s,defaultValue:t.style?.lineDash,valueChanged:r,values:n.settings.lineDash.values}),"lineArrow"in n.settings&&!n.settings.lineArrow.hidden&&h.jsx(na,{selectedSettings:a,setSelectedSettings:o,disabled:s,defaultValue:t.style?.lineArrow,valueChanged:r,values:n.settings.lineArrow.values}),"closedPoints"in n.settings&&!n.settings.closedPoints.hidden&&h.jsx(aa,{selectedSettings:a,setSelectedSettings:o,disabled:s,valueChanged:r,defaultValue:t.style?.closedPoints}),"fontFamily"in n.settings&&!n.settings.fontFamily.hidden&&h.jsx(ta,{selectedSettings:a,setSelectedSettings:o,disabled:s,valueChanged:i,values:n.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),"fontBold"in n.settings&&!n.settings.fontBold.hidden&&h.jsx(zt,{setSelectedSettings:o,disabled:s,field:"fontBold",icon:Pn,valueChanged:i,values:n.settings.fontBold.values,value:t.style?.fontBold}),"fontItalic"in n.settings&&!n.settings.fontItalic.hidden&&h.jsx(zt,{setSelectedSettings:o,disabled:s,field:"fontItalic",icon:Ln,valueChanged:i,values:n.settings.fontItalic.values,value:t.style?.fontItalic}),"opacity"in n.settings&&!n.settings.opacity.hidden&&h.jsx(Ht,{saveShapes:c,selectedSettings:a,setSelectedSettings:o,title:"Opacité",icon:wn,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(Vt,{selectedSettings:a,setSelectedSettings:o,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(Vt,{selectedSettings:a,setSelectedSettings:o,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(Ht,{saveShapes:c,selectedSettings:a,setSelectedSettings:o,title:"Epaisseur du trait",disabled:s,field:"lineWidth",icon:jn,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(sa,{selectedSettings:a,setSelectedSettings:o,disabled:s,defaultValue:e.settings.lineDash.default,valueChanged:r,values:e.settings.lineDash.values}),"lineArrow"in e.settings&&!e.settings.lineArrow.hidden&&h.jsx(na,{selectedSettings:a,setSelectedSettings:o,disabled:s,defaultValue:e.settings.lineArrow.default,valueChanged:r,values:e.settings.lineArrow.values}),"closedPoints"in e.settings&&!e.settings.closedPoints.hidden&&h.jsx(aa,{selectedSettings:a,setSelectedSettings:o,disabled:s,valueChanged:r,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&h.jsx(ta,{selectedSettings:a,setSelectedSettings:o,disabled:s,valueChanged:i,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),"fontBold"in e.settings&&!e.settings.fontBold.hidden&&h.jsx(zt,{setSelectedSettings:o,disabled:s,field:"fontBold",icon:Pn,valueChanged:i,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),"fontItalic"in e.settings&&!e.settings.fontItalic.hidden&&h.jsx(zt,{setSelectedSettings:o,disabled:s,field:"fontItalic",icon:Ln,valueChanged:i,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),"opacity"in e.settings&&!e.settings.opacity.hidden&&h.jsx(Ht,{saveShapes:c,selectedSettings:a,setSelectedSettings:o,title:"Opacité",icon:wn,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,Ao=({width:e,availableTools:t,updateToolSettings:n,layersManipulation:s=!1,toggleLayoutPanel:a,activeTool:o,saveShapes:c,selectedShape:r,canvas:i,settings:l,updateShape:u,removeShape:d,isZoomPanelShown:p,setIsZoomPanelShown:m})=>{const[v,g]=y.useState(void 0),[x,M]=y.useState(!1),b=l.size==="infinite"||l.features.zoom,Q=!l.features.edition,f=()=>{M(Z=>!Z)},w=((Z,A)=>{const H=Y(Z).map(D=>A.find(I=>I.id===D?.toolId)||A.find(I=>I.type===D?.type)).filter(D=>D!==void 0);if(!H.length)return;if(H.length===1)return H[0];const O=H.slice(1).reduce((D,I)=>{const $={};for(const U in I.settings){if(D[U]===void 0||I.settings[U]?.hidden||D[U]?.hidden)continue;const z=D[U],S=I.settings[U],k={};"min"in S&&"min"in z&&S.min===z.min&&"max"in S&&"max"in z&&S.max===z.max&&"step"in S&&"step"in z&&S.step===z.step&&(k.min=S.min,k.max=S.max,k.step=S.step),"values"in S&&"values"in z&&S.values?.join(",")===z.values?.join(",")&&(k.values=S.values),(Object.keys(k).length>0||U==="closedPoints")&&($[U]=k)}return $},H[0].settings);return{id:H.map(D=>D.id).join("-"),icon:"",label:"group",type:"group",settings:O}})(r,t),j=(w?Object.keys(w.settings).length+1:"settings"in o?Object.keys(o.settings).length:0)+ +s+ +b,E=e<40*j,V=(Z,A,H=!0)=>{if(Y(r).length){const O=Y(r).map(D=>Ee(Qe(["style",Z],A,D),l));u(O,H),w&&n(w.id,Z,A)}else n(o.id,Z,A)},C=(Z,A)=>{if(Y(r).length){const H=Y(r).map(O=>{if(O.type!=="text")return O;const D=i?.getContext("2d");if(!D)return O;const I=Qe(["style",Z],A,O),$=Pt(D,I.value,I.width,I.style?.fontBold??!1,I.style?.fontItalic??!1,I.style?.fontFamily);return Ee({...I,fontSize:$,height:$*I.value.length},l)});u(H,!0),w&&n(w.id,Z,A)}else n(o.id,Z,A)};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:[b&&h.jsx(To,{className:p?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{m(Z=>!Z)}}),E&&j>2&&h.jsx(_,{disabled:Q,onClick:f,title:"Toggle settings",icon:'<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>'}),r?w&&h.jsxs(h.Fragment,{children:[!E&&h.jsx(hn,{saveShapes:c,activeTool:o,selectedShape:r,selectedShapeTool:w,disabled:Q,selectedSettings:v,setSelectedSettings:g,handleShapeStyleChange:V,handleShapeFontFamilyChange:C}),o.type==="selection"&&h.jsx(Po,{disabled:Q,selectedShape:r,removeShape:d})]}):!E&&h.jsx(hn,{saveShapes:c,activeTool:o,selectedShape:r,selectedShapeTool:w,disabled:Q,selectedSettings:v,setSelectedSettings:g,handleShapeStyleChange:V,handleShapeFontFamilyChange:C})]}),h.jsx("div",{className:"react-paint-editor-settings-separator"}),s&&h.jsx(jo,{disabled:Q,toggleLayoutPanel:a})]}),x&&h.jsx(jt,{className:"react-paint-editor-settings-modal",onClose:f,position:"bottom",title:"Settings",children:h.jsx(hn,{saveShapes:c,activeTool:o,selectedShape:r,selectedShapeTool:w,disabled:Q,selectedSettings:v,setSelectedSettings:g,handleShapeStyleChange:V,handleShapeFontFamilyChange:C})})]})},oa=({disabled:e=!1,withText:t=!1,loadFile:n,type:s,img:a,accept:o})=>{const c=y.useRef(null);return h.jsx(_,{ref:c,type:"file",onClick:r=>{r.stopPropagation(),c.current&&(c.current.value="")},onChange:r=>{const i=r.target.files?.item(0);i&&n(i)},accept:o,title:s.label??s.type,icon:a,disabled:e,children:t?s.label:void 0})},Ce=({type:e,img:t,isActive:n,withText:s=!1,disabled:a=!1,setActive:o})=>h.jsx(_,{disabled:a,selected:n,onClick:()=>{o(e)},title:e.label??e.type,icon:t,children:s?e.label:void 0}),Eo=({activeTool:e,withActionsInMenu:t,hasActionToUndo:n=!1,hasActionToRedo:s=!1,hasActionToClear:a=!1,undoAction:o,redoAction:c,clearCanvas:r,alignment:i,group:l,vertical:u=!1,disabled:d=!1,withLoadAndSave:p,withExport:m,addPicture:v,loadFile:g,togglePictureUrlModal:x,saveFile:M,toggleExportModal:b,withUploadPicture:Q,withUrlPicture:f})=>{const[w,j]=y.useState(!1),[,E]=y.useTransition(),V=l?.tools?.some(Z=>Z===e.type),C=(V?e.icon:l.img)??l.title;return y.useEffect(()=>{if(!w)return;const Z=()=>{j(!1)};return document.addEventListener("click",Z),()=>{document.removeEventListener("click",Z)}},[w]),t||Q||f||p||m?h.jsxs("div",{className:"react-paint-editor-toolbox-relative",children:[h.jsx(_,{selected:V,title:l.title,disabled:d,onClick:()=>{E(()=>{j(!0)})},icon:C}),w&&h.jsx(Ue,{alignment:i,position:"top",children:h.jsxs("div",{className:"react-paint-editor-toolbox-panel-content","data-vertical":+u,children:[t&&h.jsxs(h.Fragment,{children:[h.jsx(Ce,{withText:!0,type:et,disabled:d||!n,img:et.icon,isActive:e.id===et.id,setActive:o}),h.jsx(Ce,{withText:!0,type:tt,disabled:d||!s,img:tt.icon,isActive:e.id===tt.id,setActive:c}),h.jsx(Ce,{withText:!0,type:nt,disabled:d||!a,img:nt.icon,isActive:e.id===nt.id,setActive:r}),(Q||f||p)&&h.jsx("hr",{})]}),Q&&h.jsx(oa,{withText:!0,type:Xn,disabled:d,loadFile:async Z=>{j(!1),await v(Z)},img:Xn.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),f&&h.jsx(_,{disabled:d,selected:!1,onClick:x,title:"Add picture from URL",icon:'<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>',children:"Add picture from URL"}),(Q||f)&&p&&h.jsx("hr",{}),p&&h.jsxs(h.Fragment,{children:[h.jsx(oa,{withText:!0,type:Yn,disabled:d,loadFile:Z=>{j(!1),g(Z)},img:Yn.icon,accept:"application/JSON"}),h.jsx(Ce,{withText:!0,disabled:d,type:Ot,img:Ot.icon,isActive:e.id===Ot.id,setActive:M})]}),m&&h.jsx(Ce,{withText:!0,disabled:d,type:Bt,img:Bt.icon,isActive:e.id===Bt.id,setActive:b})]})})]}):null},Do=({togglePictureUrlModal:e,addPicture:t})=>{const n=y.useRef(null);return y.useEffect(()=>{n.current&&n.current.focus()},[]),h.jsx(jt,{className:"react-paint-editor-toolbox-pictureinput-modal",onClose:e,title:"Add picture from URL",children:h.jsxs("form",{onSubmit:async s=>{s.preventDefault();const a=n.current?.value;a&&(await t(a),e())},children:[h.jsxs("label",{children:["URL ",h.jsx("input",{type:"text",ref:n})]}),h.jsx(_,{onClick:e,children:"Annuler"}),h.jsx(_,{type:"submit",selected:!0,children:"Ajouter"})]})})},ia="Choose export settings",Ro=({toggleExportModal:e,exportCanvasInFile:t})=>{const n=async s=>{t(s),e()};return h.jsxs(jt,{className:"react-paint-editor-toolbox-export-modal",onClose:e,title:ia,children:[h.jsx("h3",{children:ia}),h.jsx("hr",{}),h.jsx(_,{onClick:()=>n("currentZoom"),children:"Exporter la vue actuelle"}),h.jsx(_,{onClick:()=>n("defaultView"),children:"Exporter le canevas par défaut"}),h.jsx(_,{onClick:()=>n("fitToShapes"),children:"Exporter le dessin entier"}),h.jsx(_,{selected:!0,onClick:e,children:"Annuler"})]})},Io=({activeTool:e,alignment:t,group:n,disabled:s=!1,setActiveToolFromId:a})=>{const o=y.useRef(null),[c,r]=y.useState(!1),[,i]=y.useTransition(),[l,u]=y.useState(void 0),d=v=>{u(v),a(v.id)};if(y.useEffect(()=>{if(!c)return;const v=g=>{!((M,b)=>!!(M.target instanceof Node&&b)&&b.contains(M.target))(g,o.current)&&r(!1)};return document.addEventListener("mousedown",v,{passive:!1}),document.addEventListener("touchstart",v,{passive:!1}),()=>{document.removeEventListener("mousedown",v),document.removeEventListener("touchstart",v)}},[c]),"type"in n)return h.jsx(Ce,{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(Ce,{disabled:s,type:n.toolsType[0],img:n.toolsType[0].icon,isActive:e.id===n.toolsType[0].id,setActive:d});const p=n?.toolsType.find(v=>v.type===e.type)!==void 0,m=(l?l.icon:n.toolsType?.[0]?.icon)??n.title;return h.jsxs("div",{className:"react-paint-editor-toolbargroup-relative",children:[h.jsx(_,{selected:p,title:n.title,disabled:s,onClick:()=>{l?a(l.id):n.toolsType?.[0]&&d(n.toolsType[0]),i(()=>{r(!0)})},icon:m}),c&&h.jsx(Ue,{alignment:t,position:"top",children:h.jsx("div",{className:"react-paint-editor-toolbargroup-panel-content","data-vertical":+n.vertical,ref:o,children:n.toolsType.map(v=>h.jsx(Ce,{disabled:s,type:v,img:v.icon,isActive:e.id===v.id,setActive:d},v.id))})})]})},Wo=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],No=({settings:e,width:t,activeTool:n,hasActionToUndo:s=!1,hasActionToRedo:a=!1,hasActionToClear:o=!1,withLoadAndSave:c,withExport:r,clearCanvas:i,setActiveTool:l,undoAction:u,redoAction:d,addPicture:p,loadFile:m,saveFile:v,exportCanvasInFile:g,availableTools:x,withUrlPicture:M,withUploadPicture:b})=>{const Q=((z,S)=>{const k=S.flatMap(P=>{if(typeof P!="object")return z.filter(L=>L.type===P);const T=z.filter(L=>P.toolsType.includes(L.type));return T?{...P,toolsType:T}:null});return cn(k)})(x,Wo),f=!e.features.edition,w=t<40*(6+Q.length),j=t<40*(3+Q.length),[E,V]=y.useState(!1),[C,Z]=y.useState(!1),[A,H]=y.useState(!1),O=()=>{V(z=>!z)},D=()=>{H(z=>!z)},I=z=>{l(z),V(!1)},$=z=>{I(x.find(S=>S.id===z)??n)},U=x.find(z=>z.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(Ce,{type:Re,disabled:f,img:Re.icon,isActive:n.id===Re.id,setActive:I}),(e.size==="infinite"||e.features.zoom)&&h.jsx(Ce,{type:Yt,disabled:f,img:Yt.icon,isActive:n.id===Yt.id,setActive:I}),j?h.jsx(_,{disabled:f,onClick:O,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:U}):Q.map(z=>h.jsx(Io,{disabled:f,activeTool:n,group:z,setActiveToolFromId:$},"id"in z?z.id:z.title))]}),!w&&h.jsxs(h.Fragment,{children:[h.jsx(Ce,{type:et,disabled:f||!s,img:et.icon,isActive:n.id===et.id,setActive:u}),h.jsx(Ce,{type:tt,disabled:f||!a,img:tt.icon,isActive:n.id===tt.id,setActive:d}),h.jsx(Ce,{type:nt,disabled:f||!o,img:nt.icon,isActive:n.id===nt.id,setActive:i})]}),h.jsx(Eo,{withActionsInMenu:w,disabled:f,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:p,loadFile:m,saveFile:v,togglePictureUrlModal:()=>{Z(!0)},toggleExportModal:D,withUploadPicture:b,withUrlPicture:M,withLoadAndSave:c,withExport:r,hasActionToUndo:s,hasActionToRedo:a,hasActionToClear:o,undoAction:u,redoAction:d,clearCanvas:i})]}),E&&h.jsx(jt,{className:"react-paint-editor-toolbar-modal",onClose:O,title:"Outils",children:x.map(z=>z.type==="picture"?null:h.jsx(Ce,{disabled:f,type:z,img:z.icon,withText:!1,isActive:n.id===z.id,setActive:I},z.id))}),C&&h.jsx(Do,{togglePictureUrlModal:()=>{Z(z=>!z)},addPicture:p}),A&&h.jsx(Ro,{toggleExportModal:D,exportCanvasInFile:g})]})},Tt={none:0,small:10,medium:20,large:40},Fo={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},Bo=()=>{const e=y.useRef([]),[t,n]=y.useState([]);return y.useEffect(()=>()=>{for(const s of e.current)clearTimeout(s)},[]),{snackbarList:t,addSnackbar:({type:s=So,duration:a=xo,text:o})=>{const c={id:le("snackbar_"),duration:a,type:s,text:o};n(r=>[...r,c]),e.current=[...e.current,setTimeout(()=>{return r=c.id,void n(i=>i.filter(l=>l.id!==r));var r},a)]}}};De.Canvas=({options:e,className:t,style:n,canvasProps:s})=>{const{shapesRef:a,selectedShape:o,selectionFrame:c,hoveredShape:r,addShape:i,setSelectedShape:l,setSelectionFrame:u,refreshSelectedShapes:d,refreshHoveredShape:p,duplicateShapes:m,removeShape:v,updateShape:g,backwardShape:x,forwardShape:M,saveShapes:b,refs:Q,width:f,height:w,settings:j,setCanvasSize:E,setCanvasOffset:V,selectShapes:C,activeTool:Z,setActiveTool:A,isInsideComponent:H,isInsideCanvas:O,isEditMode:D,canvas:{withSkeleton:I,withFrameSelection:$,canGrow:U,canShrink:z},canvasOffsetStartData:S,setCanvasOffsetStartData:k,selectionMode:P,setSelectionMode:T,setCanvasMoveAcceleration:L,isShiftPressed:B,isAltPressed:W,isSpacePressed:F,setShiftPressed:R,setAltPressed:q,setCanvasZoom:oe,resetZoom:se,setIsSpacePressed:G}=s,{canvasBackgroundColor:N,canvasSelectionColor:de,canvasSelectionWidth:te}={...ya,...e},fe=y.useRef(null),ve=y.useCallback(K=>{i(K),C(K)},[i,C]),me=y.useCallback(K=>{E({realWidth:f,realHeight:w,width:K,height:w*K/f,scaleRatio:K/f})},[f,w,E]);return mo({isInsideComponent:H,isInsideCanvas:O,isEditingText:P.mode==="textedition",settings:j,selectedShape:o,setSelectedShape:l,removeShape:v,pasteShapes:ve,updateShapes:g,backwardShape:x,forwardShape:M,setShiftPressed:R,setAltPressed:q,setActiveTool:A,setSelectionMode:T,setSelectionFrame:u,setCanvasZoom:oe,resetZoom:se,setIsSpacePressed:G}),(({onResized:K,element:ue})=>{y.useEffect(()=>{const X=ue.current;if(!X)return;const ee=new ResizeObserver(Me=>{const ke=Me?.[0]?.borderBoxSize?.[0],{width:ae,height:je}=ke?{width:ke.inlineSize,height:ke.blockSize}:Me?.[0]?.contentRect??{};ae!==void 0&&je!==void 0&&K(ae,je)});return ee.observe(X),()=>{ee.unobserve(X)}},[ue,K])})({element:fe,onResized:me}),h.jsx("div",{ref:fe,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":U,"data-shrink":z,style:{"--react-paint-app-row-width":j.canvasSize.width,"--react-paint-app-canvaswidth":f,"--react-paint-app-canvasheight":w,"--react-paint-app-row-aspectratio":`calc(${j.canvasSize.width} / ${j.canvasSize.height})`,"--react-paint-app-canvas-bg":N,...n},children:h.jsx(oo,{duplicateShapes:m,isSpacePressed:F,ref:Q.canvas,canGrow:U,isInsideComponent:H,activeTool:Z,setActiveTool:A,canvasOffsetStartData:S,setCanvasOffsetStartData:k,shapes:a.current,addShapes:i,updateSingleShape:g,selectedShape:o,selectionFrame:c,setSelectedShape:l,setSelectionFrame:u,hoveredShape:r,refreshHoveredShape:p,refreshSelectedShapes:d,settings:j,setCanvasOffset:V,saveShapes:b,selectionMode:P,setSelectionMode:T,setCanvasMoveAcceleration:L,selectionColor:de,selectionWidth:te,isEditMode:D,isShiftPressed:B,isAltPressed:W,withFrameSelection:$,withSkeleton:I})})},De.Editor=({editorProps:e,className:t,style:n,options:s,children:a})=>{const{shapesRef:o,addPictureShape:c,moveShapes:r,toggleShapeVisibility:i,toggleShapeLock:l,canGoBackward:u,canGoForward:d,canClear:p,selectedShape:m,removeShape:v,updateShape:g,backwardShape:x,forwardShape:M,refs:b,width:Q,height:f,selectTool:w,selectShapes:j,activeTool:E,setActiveTool:V,setAvailableTools:C,isEditMode:Z,availableTools:A,gridGap:H,setGridGap:O,loadFile:D,exportPicture:I,exportData:$,clearCanvas:U,settings:z,setCanvasZoom:S,saveShapes:k,canvas:{canGrow:P,layersManipulation:T,withExport:L,withLoadAndSave:B,withUploadPicture:W,withUrlPicture:F}}=e,{toolbarBackgroundColor:R,dividerColor:q,fontRadius:oe,fontDisabledColor:se,fontDisabledBackgroundColor:G,fontColor:N,fontBackgroundColor:de,fontSelectedColor:te,fontSelectedBackgroundColor:fe,fontHoverColor:ve,fontHoverBackgroundColor:me}={...Fo,...s},K=z.size==="infinite"||z.features.zoom,[ue,X]=y.useState(!1),[ee,Me]=y.useState(!1),[ke,ae]=y.useState(K),je=K&&ke,qe=H>=Tt.large?"large":H>=Tt.medium?"medium":H>=Tt.small?"small":"none",{snackbarList:pn,addSnackbar:Ze}=Bo(),gn=y.useCallback((he,pe,vt)=>{C(We=>We.map(lt=>lt.id===he?Qe(["settings",pe,"default"],vt,lt):lt)),V(We=>We.id===he?Qe(["settings",pe,"default"],vt,We):We)},[V,C]),fn=y.useCallback(he=>{X(!0);try{I(he)}catch(pe){pe instanceof Error&&Ze({type:"error",text:`L'export a échoué : ${pe.message}`}),console.warn(pe)}finally{X(!1)}},[I,Ze]),Ge=y.useCallback(()=>{X(!0);try{$(),X(!1)}catch(he){he instanceof Error&&Ze({type:"error",text:"L'enregistrement a échoué"}),console.warn(he)}finally{X(!1)}},[$,Ze]),vn=y.useCallback(async he=>{X(!0);try{await D(he),Ze({type:"success",text:"Fichier chargé !"})}catch(pe){pe instanceof Error&&Ze({type:"error",text:"Le chargement a échoué"}),console.warn(pe)}finally{X(!1)}},[D,Ze]),mn=y.useCallback(async he=>{X(!0);try{const pe=await c(he,Q,f);j([pe])}catch(pe){pe instanceof Error&&Ze({type:"error",text:"Le chargement a échoué"}),console.warn(pe)}finally{X(!1)}},[c,j,Ze,Q,f]),yn=`${t?`${t} `:""}${ee?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return h.jsxs("div",{ref:b.setEditor,className:yn,style:{"--react-paint-editor-app-maxWidth":P?"100%":`${Q}px`,"--react-paint-editor-app-toolbar-bg":R,"--react-paint-editor-app-divider-color":q,"--react-paint-editor-app-font-radius":oe,"--react-paint-editor-app-font-disabled-color":se,"--react-paint-editor-app-font-disabled-bg":G,"--react-paint-editor-app-font-color":N,"--react-paint-editor-app-font-bg":de,"--react-paint-editor-app-font-selected-color":te,"--react-paint-editor-app-font-selected-bg":fe,"--react-paint-editor-app-font-hover-color":ve,"--react-paint-editor-app-font-hover-bg":me,...n},children:[Z&&h.jsx(No,{settings:z,width:z.canvasSize.width,activeTool:E,clearCanvas:U,setActiveTool:w,exportCanvasInFile:fn,saveFile:Ge,loadFile:vn,addPicture:mn,hasActionToUndo:u,hasActionToRedo:d,hasActionToClear:p,undoAction:x,redoAction:M,availableTools:A,withExport:L,withLoadAndSave:B,withUploadPicture:W,withUrlPicture:F}),a,Z&&T&&h.jsx(ko,{gridFormat:qe,setGridFormat:he=>{O(Tt[he])},shapes:o.current,moveShapes:r,selectedShapes:m,removeShape:v,selectShapes:j,toggleShapeVisibility:i,toggleShapeLock:l,isLayoutPanelShown:ee,settings:z}),je&&h.jsxs(Ue,{alignment:"left",className:"react-paint-editor-layouts-panel","data-edit":+Z,children:[h.jsx(_,{className:"react-paint-editor-zoom-button",icon:'<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>',onClick:()=>S("unzoom")}),h.jsxs(_,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>S("default"),children:[Math.round(100*z.canvasZoom),"%"]}),h.jsx(_,{className:"react-paint-editor-zoom-button",icon:Hn,onClick:()=>S("zoom")})]}),Z&&h.jsxs(h.Fragment,{children:[h.jsx(Ao,{saveShapes:k,setCanvasZoom:S,width:z.canvasSize.width,activeTool:E,availableTools:A,selectedShape:m,settings:z,removeShape:v,updateShape:g,canvas:b.canvas.current,layersManipulation:T,toggleLayoutPanel:()=>{Me(he=>!he)},isZoomPanelShown:je,setIsZoomPanelShown:ae,updateToolSettings:gn}),h.jsx(yo,{isLoading:ue}),h.jsx(bo,{snackbarList:pn})]})]})},De.useReactPaint=({width:e=1e3,height:t=600,shapes:n,mode:s="editor",disabled:a=!1,options:o=Jn}={})=>{const{layersManipulation:c,brushAlgo:r,isBrushShapeDoneOnMouseUp:i,debug:l,grid:u,canGrow:d,canShrink:p,withExport:m,withLoadAndSave:v,withUploadPicture:g,withUrlPicture:x,withSkeleton:M,withFrameSelection:b,clearCallback:Q,availableTools:f,canvasSelectionPadding:w,size:j,canZoom:E}={...Jn,...o},V=s!=="viewer",C=y.useRef(null),Z=y.useRef(null),A=y.useRef(!1),H=y.useCallback(J=>{C.current=J},[]),[O,D]=y.useState(void 0),[I,$]=y.useState(Re),[U,z]=y.useState({mode:"default"}),[S,k]=y.useState(u),[P,T]=y.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),L=E==="always"&&!a,{canvasTransformation:B,setCanvasTransformation:W,setCanvasOffset:F,setCanvasZoom:R,resetZoom:q}=to({canvasSize:P,size:j,canvasElt:Z.current,zoomEnabled:L}),{offset:oe,zoom:se}=B,G=y.useMemo(()=>({brushAlgo:r,isBrushShapeDoneOnMouseUp:i,debug:l,canvasSize:{realWidth:P.realWidth,realHeight:P.realHeight,width:P.width,height:P.height,scaleRatioWithNoZoom:P.scaleRatio,scaleRatio:P.scaleRatio*se},size:j,canvasOffset:oe,canvasZoom:se,gridGap:S,selectionPadding:w,features:{edition:V&&!a,zoom:L}}),[w,S,r,i,l,se,oe,P,j,a,L,V]),[N,de]=y.useState(Os(f,g||x)),{isInsideComponent:te,isInsideCanvas:fe}=(({settings:J,componentRef:ie,canvasRef:Pe})=>{const[Ne,Fe]=y.useState(!1),[Ke,Je]=y.useState(!1),ye=!J.features.edition&&!J.features.zoom;return y.useEffect(()=>{if(!ye){const Le=()=>Fe(!0),Et=()=>Fe(!1),Be=()=>Je(!0),Dt=()=>Je(!1);return ie.current?.addEventListener("focusin",Le),ie.current?.addEventListener("focusout",Et),Pe.current?.addEventListener("focusin",Be),Pe.current?.addEventListener("focusout",Dt),()=>{ie.current?.removeEventListener("focusin",Le),ie.current?.removeEventListener("focusout",Et),Pe.current?.removeEventListener("focusin",Be),Pe.current?.removeEventListener("focusout",Dt)}}Fe(!1),Je(!1)},[ye,ie,Pe]),{isInsideComponent:Ne,isInsideCanvas:Ke}})({settings:G,componentRef:C,canvasRef:Z}),[ve,me]=y.useState(!1),[K,ue]=y.useState(!1),[X,ee]=y.useState(!1),{registerEvent:Me,unregisterEvent:ke,shapesRef:ae,selectedShape:je,selectionFrame:qe,hoveredShape:pn,addShapes:Ze,addPictureShape:gn,moveShapes:fn,setSelectedShape:Ge,setSelectionFrame:vn,refreshSelectedShapes:mn,refreshHoveredShape:yn,duplicateShapes:he,removeShape:pe,updateShape:vt,backwardShape:We,forwardShape:lt,clearShapes:ra,saveShapes:la,toggleShapeVisibility:Oo,toggleShapeLock:Yo,canGoBackward:Xo,canGoForward:$o,canClear:Uo}=Ja(G,e,t,ve),Sn=y.useCallback(J=>{Ge(void 0),$(J)},[Ge]),[ct,ca]=y.useState([0,0]),da=U.mode==="preview";y.useEffect(()=>{if(da)return()=>z(J=>J.mode==="preview"?{mode:"default"}:J)},[je?.id,da]);const ua=U.mode==="selectionFrame";y.useEffect(()=>{if(ua)return()=>ca([0,0])},[ua]),y.useEffect(()=>{if(ct[0]!==0||ct[1]!==0){const J=setInterval(()=>{W(({offset:ie,zoom:Pe})=>{const Ne=[ie[0]-ct[0],ie[1]-ct[1]];return an({zoom:Pe,size:j,canvasSize:P,newOffset:Ne})})},20);return()=>clearInterval(J)}},[ct[0],ct[1],W,j,P]);const At=y.useCallback((J,ie)=>{ra(J,ie),Sn(Re),W({offset:[0,0],zoom:1})},[Sn,ra,W]),ha=y.useCallback(J=>{Ge(ie=>(ie?.id!==J.map(Pe=>Pe.id).join("-")&&$(Re),ce(J,G)))},[Ge,G]),qo=y.useCallback(()=>{const J=_a(ae.current,e,t);if(!J)throw new Error("L'encodage a échoué");Is(J,"drawing.json")},[ae,e,t]),Go=y.useCallback(J=>{const ie=Ws({shapes:ae.current,settings:G,view:J});Is(ie,"drawing.png")},[ae,G]),_o=y.useCallback(J=>Ws({shapes:ae.current,settings:G,view:J}),[ae,G]),Ko=y.useCallback(()=>un(ae.current,e,t),[ae,e,t]),_e=y.useCallback(async(J,ie)=>{const Pe=await(async(Ne,Fe)=>{if(!Ne)return[];const Ke=[],Je=cn(Ne.map(ye=>{if(!ye||!Gn.includes(ye.type))return null;if(ye.type==="picture"){const Le=new Image,Et=new Promise((Be,Dt)=>{Le.onload=()=>{URL.revokeObjectURL(Le.src),Be()},Le.onerror=()=>{Dt(new Error("Some images could not be loaded"))}});if(Ke.push(Et),ye.src.startsWith("http"))Rs(ye.src).then(Be=>{Le.src=Be}).catch(()=>{Le.src=""});else if(ye.src.includes("<svg")){const Be=new Blob([ye.src],{type:"image/svg+xml"});Le.src=URL.createObjectURL(Be)}else Le.src=ye.src;return Ns({...ye,img:Le},Fe)}return Ns(ye,Fe)}));return await Promise.all(Ke),Je})(J,G);At(Pe,ie)},[At,G]),xn=y.useRef(_e);xn.current=_e;const Jo=y.useCallback((J=[],ie=!0)=>{xn.current?.(J,{clearHistory:ie,source:"remote"})},[]);y.useEffect(()=>{A.current||(A.current=!0,n&&xn.current?.(n,{clearHistory:!0,source:"remote"}))},[n]);const ei=y.useCallback(async J=>{const ie=await(async Pe=>new Promise((Ne,Fe)=>{const Ke=new FileReader;Ke.onload=Je=>{const ye=Je.target?.result;if(!ye)return Fe("Impossible de récupérer les données du fichier");const Le=JSON.parse(ye);Ne(Le)},Ke.readAsText(Pe)}))(J);await _e(ie.shapes??[],{clearHistory:!0,source:"remote"})},[_e]),ti=y.useCallback(()=>{typeof Q!="string"?_e(Q(),{clearHistory:!1,source:"user"}):Q==="defaultShapes"&&n!==void 0?_e(n,{clearHistory:!1,source:"user"}):At([],{clearHistory:!1,source:"user"})},[At,_e,n,Q]);y.useEffect(()=>{de(Os(f,g||x))},[f,g,x]);const pa={canvas:Z,editor:C,setEditor:H};return{annotationsProps:{style:{userSelect:"none",touchAction:"none",transformOrigin:"left top",transform:"scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))","--react-paint-canvas-zoom":G.canvasZoom,"--react-paint-canvas-offset-x":G.canvasOffset[0],"--react-paint-canvas-offset-y":G.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:ae,addPictureShape:gn,moveShapes:fn,toggleShapeVisibility:Oo,toggleShapeLock:Yo,canGoBackward:Xo,canGoForward:$o,canClear:Uo,selectedShape:je,saveShapes:la,removeShape:pe,updateShape:vt,backwardShape:We,forwardShape:lt,refs:pa,width:e,height:t,selectTool:Sn,selectShapes:ha,activeTool:I,setActiveTool:$,setAvailableTools:de,isEditMode:V,availableTools:N,gridGap:S,setGridGap:k,loadFile:ei,exportPicture:Go,exportData:qo,clearCanvas:ti,settings:G,setCanvasZoom:R,resetZoom:q,canvas:{canGrow:d,canShrink:p,layersManipulation:c,withExport:m,withLoadAndSave:v,withUploadPicture:g,withUrlPicture:x}},canvasProps:{shapesRef:ae,selectedShape:je,selectionFrame:qe,hoveredShape:pn,addShape:Ze,setSelectedShape:Ge,setSelectionFrame:vn,refreshSelectedShapes:mn,refreshHoveredShape:yn,removeShape:pe,updateShape:vt,duplicateShapes:he,backwardShape:We,forwardShape:lt,saveShapes:la,refs:pa,width:e,height:t,settings:G,setCanvasSize:T,setCanvasOffset:F,setCanvasZoom:R,resetZoom:q,selectShapes:ha,activeTool:I,setActiveTool:$,isInsideComponent:te,isInsideCanvas:fe,isEditMode:V,canvas:{withSkeleton:M,withFrameSelection:b,canGrow:d,canShrink:p},canvasOffsetStartData:O,setCanvasOffsetStartData:D,selectionMode:U,setSelectionMode:z,setCanvasMoveAcceleration:ca,isShiftPressed:ve,isAltPressed:K,isSpacePressed:X,setShiftPressed:me,setAltPressed:ue,setIsSpacePressed:ee},registerEvent:Me,unregisterEvent:ke,resetCanvas:Jo,resetZoom:q,getCurrentImage:_o,getCurrentData:Ko,setCanvasOffset:F,setCanvasZoom:R}},Object.defineProperty(De,Symbol.toStringTag,{value:"Module"})});
1
+ (function(Ke,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],m):m((Ke=typeof globalThis<"u"?globalThis:Ke||self)["react-paint"]={},Ke.React,Ke.jsxRuntime)})(this,function(Ke,m,d){"use strict";const Ra='<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>',na='<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>',oa='<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>',ia='<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>',Da='<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>',Ia='<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>',ra='<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>',Wa='<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>',Na='<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>',Ba='<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>',Fa='<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>',Oa='<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>',Ya='<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>',Xa='<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>',$a='<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>',Ua='<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>',qa='<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>',Le=["transparent","black","white","red","green","blue","yellow"],tt=[0,1,2],Ga=[[1,0],[1,2],[4,6]],Vt="serif",Wn=2,_a=3,Nn=4,ye="react-paint-",Ka={strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0}},la={type:"picture",id:`${ye}picture`,icon:ra,label:"Image",settings:{opacity:{min:0,max:100,step:1,default:100}}},Ja={type:"brush",id:`${ye}brush`,icon:Ra,label:"Brosse",settings:{strokeColor:{values:Le,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:tt,default:0}}},es={type:"line",id:`${ye}line`,icon:Na,label:"Ligne",settings:{strokeColor:{values:Le,default:"black"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0},lineArrow:{values:[0,1,2,3],default:0}}},ts={type:"polygon",id:`${ye}polygon`,icon:ia,label:"Polygone",settings:{strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0},closedPoints:{default:0}}},as={type:"curve",id:`${ye}curve`,icon:Fa,label:"Courbe",settings:{strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0},closedPoints:{default:0}}},ss={type:"rect",id:`${ye}rect`,icon:na,label:"Rectangle",settings:Ka},ns={type:"square",id:`${ye}square`,icon:na,label:"Carré",settings:{strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0}}},os={type:"circle",id:`${ye}circle`,icon:oa,label:"Cercle",settings:{strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0}}},is={type:"ellipse",id:`${ye}ellipse`,icon:oa,label:"Ellipse",settings:{strokeColor:{values:Le,default:"black"},fillColor:{values:Le,default:"transparent"},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:tt,default:0}}},rs={type:"text",id:`${ye}text`,icon:Wa,label:"Texte",settings:{strokeColor:{values:Le,default:"black"},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:["arial","serif","monospace"],default:Vt},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}}},Xe={id:`${ye}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"},vt={id:`${ye}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"},mt={id:`${ye}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"},St={id:`${ye}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"},ca={id:`${ye}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"},ls={id:`${ye}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"},da={id:`${ye}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"},ha={id:`${ye}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"},cs={id:`${ye}upload-picture`,type:"uploadpicture",icon:ra,label:"Upload picture"},ds=2,hs="blue",ot=14,us=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],ps=["brush","rect","square","line","polygon","circle","curve","ellipse","picture","text","triangle","group"],Bn=["rect","square","circle","ellipse","picture","text","triangle","brush","group"],Fn=["square","circle","picture","text"],gs="react-paint-canvas-drawcanvas",fs="react-paint-canvas-selectioncanvas",vs={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,withContextMenu:!0,availableTools:[Ja,es,ts,as,ss,ns,os,is,la,rs],clearCallback:"empty",brushAlgo:"simple",isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:"fixed",canZoom:"never",debug:!1},On={canvasBackgroundColor:"white",canvasSelectionColor:hs,canvasSelectionWidth:ds},ms=300,ua=(e,t)=>{const a={...t};for(const s of e)Array.isArray(s)?s[1].includes(a[s[0]])&&delete a[s[0]]:delete a[s];return a},We=(e,t,a)=>{const s=Array.isArray(a)?[...a]:{...a},n=Array.isArray(e)?e:typeof e=="string"?e.split("."):[e];return n.reduce((o,r,l)=>(o[r]=pa(o[r])?{...o[r]}:Array.isArray(o[r])?[...o[r]]:o[r]===void 0||o[r]===null?{}:o[r],l===n.length-1&&(o[r]=t),o[r]),s),s},pa=e=>typeof e=="object"&&!Array.isArray(e)&&e!==null,$e=(e,t,a)=>{if(!pa(t)||!pa(a))return a;const s={...t};for(const n in a)a.hasOwnProperty(n)&&(s.hasOwnProperty(n)?s[n]=e(s[n],a[n],n)??$e(e,s[n],a[n]):s[n]=a[n]);return s},Ss=(e,t)=>{if(e===t)return!0;if(typeof e!="object"||typeof t!="object"||e===null||t===null)return!1;const a=Object.keys(e),s=Object.keys(t);if(a.length!==s.length)return!1;for(const n of a)if(!s.includes(n)||!Ss(e[n],t[n]))return!1;return!0},ga={},be=(e="")=>(ga[e]||(ga[e]=0),`${e}${++ga[e]}`),Ue=(e,t,a)=>Math.max(t,Math.min(e,a)),ys=()=>typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),xs=e=>{e.reset(),e.lineCap="round",e.lineJoin="round"},Ve=(e,t={})=>{const{lineCap:a="round",fillColor:s="transparent",opacity:n=100,strokeColor:o=hs,lineWidth:r=ds,lineDash:l=0,shadowColor:i="transparent",shadowBlur:c=0}=t;e.lineCap=a,e.globalAlpha=n/100,e.fillStyle=s,e.strokeStyle=o,e.lineWidth=r,e.setLineDash(l===0?[]:[Ga[l][0]*r,Ga[l][1]*r]),e.shadowColor=i,e.shadowBlur=c},yt=(e,t,a,s)=>{e.save(),e.scale(t.canvasSize.scaleRatio,t.canvasSize.scaleRatio),e.translate(t.canvasOffset[0],t.canvasOffset[1]),a&&s&&(e.translate(s[0],s[1]),e.rotate(a),e.translate(-s[0],-s[1]))},fa=e=>180*e/Math.PI,bs=(e,t)=>{const a=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(a*a+s*s)<=t.radius},fe=({origin:e=[0,0],point:t,rotation:a=0})=>{if(a===0)return t;const s=[t[0]-e[0],t[1]-e[1]],n=s[1]*Math.cos(a)-s[0]*Math.sin(a);return[s[1]*Math.sin(a)+s[0]*Math.cos(a)+e[0],n+e[1]]},ws=e=>(e+2*Math.PI)%(2*Math.PI),Qs=({targetVector:[e,t],radian:a=!0,originVector:s})=>{const n=ws(Math.atan2(t[1]-e[1],t[0]-e[0]));if(s){const[o,r]=s,l=Math.atan2(r[1]-o[1],r[0]-o[0]),i=ws(n-l);return a?i:fa(i)}return a?n:fa(n)},Cs=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),it=(e,t,a)=>{const s=fe({origin:t.computed.center,point:e.computed.center,rotation:t.rotation??0}),n=(s[0]-(e.computed.borders.width/2-a.settings.selectionPadding)-(a.originalBorders.x+a.settings.selectionPadding))*a.widthMultiplier,o=(s[1]-(e.computed.borders.height/2-a.settings.selectionPadding)-(a.originalBorders.y+a.settings.selectionPadding))*a.heightMultiplier;return{x:a.newBorderX+a.settings.selectionPadding+(a.isXinverted?a.newBorderWidth-2*a.settings.selectionPadding-(e.computed.borders.width-2*a.settings.selectionPadding||1)*a.widthMultiplier-n:n),y:a.newBorderY+a.settings.selectionPadding+(a.isYinverted?a.newBorderHeight-2*a.settings.selectionPadding-(e.computed.borders.height-2*a.settings.selectionPadding||1)*a.heightMultiplier-o:o)}},rt=(e,t,a,s,n)=>fe({origin:e.groupCenter,point:[t+s/2,a+n/2],rotation:-e.rotation}),va=(e,{selectionPadding:t})=>{const a=e.points.flat(),s=Math.min(...a.map(i=>i[0])),n=Math.min(...a.map(i=>i[1])),o=a.map(i=>Ne(i,s,n,e.scaleX,e.scaleY)),r=Math.max(...o.map(i=>i[0]))+t,l=Math.max(...o.map(i=>i[1]))+t;return{x:s-t,width:r-s+t,y:n-t,height:l-n+t}},xt=(e,t)=>{const a=$n(e,t),s=qe(e,va,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},Yn=xt,Ms=(e,t,a)=>{const{isXinverted:s,isYinverted:n,settings:o,widthMultiplier:r,heightMultiplier:l}=a,i=va({...e,scaleX:1,scaleY:1},o),c=i.width-2*o.selectionPadding,u=i.height-2*o.selectionPadding,h=e.scaleX??1?(e.scaleX??1)*r:r/c,p=e.scaleY??1?(e.scaleY??1)*l:l/u,g=c*h,v=u*p,S=it(e,t,a),b=rt(a,S.x,S.y,g,v),C=ze(b[0]-g/2-e.computed.borders.x-o.selectionPadding)+(s?2*e.computed.borders.x+i.width:0),P=ze(b[1]-v/2-e.computed.borders.y-o.selectionPadding)+(n?2*e.computed.borders.y+i.height:0),M=(s||n)&&!(s&&n)&&(e.rotation??0)!==0&&a.rotation!==e.rotation;return xt({...e,points:e.points.map(x=>x.map(([f,j])=>[s?-f+C:f+C,n?-j+P:j+P])),scaleX:h,scaleY:p,rotation:M?-(e.rotation??0):e.rotation??0},a.settings)},ze=(e,t=2)=>Math.round(e*10**t)/10**t,Ne=(e,t,a,s=1,n=1)=>[t+(e[0]-t)*s,a+(e[1]-a)*n],Pe=(e,t,a=0)=>{if(!t.gridGap)return ze(e);const s=e+a,n=s>=0?t.gridGap:-t.gridGap;return s+n/2-(s+n/2)%n-a},Xn=(e,t,a,s,n,o,r)=>{if(s.mode==="translate")return ce(nn(a,s.originalShape,s.cursorStartPosition,n,o),n);if(s.mode==="rotate"){const l=s.originalShape.computed.center[0]-s.cursorStartPosition[0],i=s.originalShape.computed.center[1]-s.cursorStartPosition[1],c=s.originalShape.computed.center[0]-a[0],u=s.originalShape.computed.center[1]-a[1],h=((g,v,S)=>v.gridGap||S?g+Math.PI/18/2-(g+Math.PI/18/2)%(Math.PI/18):ze(g,3))(Math.atan2(u,c)-Math.atan2(i,l),n,o),p=G(s.originalShape).map(g=>Be(tn(g,h,s.originalShape.computed.center),n));return ce(p,n)}return s.mode==="resize"?ce(mo(e,a,s.originalShape,s,n,o,r),n):s.mode==="brush"?ce(G(t).map(l=>((i,c,u)=>{const h={...i,points:We(i.points.length-1,[...i.points[i.points.length-1],[Math.round(c[0]),Math.round(c[1])]],i.points)};return xt(h,u)})(l,a,n)),n):t},Zt=e=>{const t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},At=e=>{const t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},Et=e=>{const t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},$n=(e,{brushAlgo:t})=>{const a=new Path2D;if(e.points.length<1)return a;const s=e.points.flat(),n=s.map(i=>i[0]),o=s.map(i=>i[1]),r=Math.min(...n),l=Math.min(...o);for(const i of e.points)if(i.length)if(i.length===1)a.rect(...Ne(i[0],r,l,e.scaleX,e.scaleY),1,1);else if(a.moveTo(...Ne(i[0],r,l,e.scaleX,e.scaleY)),t==="quadratic"){for(let c=0;c<i.slice(1).length-2;c++){const u=Ne(i[c],r,l,e.scaleX,e.scaleY),h=Ne(i[c+1],r,l,e.scaleX,e.scaleY),p=(u[0]+h[0])/2,g=(u[1]+h[1])/2;a.quadraticCurveTo(...u,p,g)}a.quadraticCurveTo(...Ne(i[i.length-2],r,l,e.scaleX,e.scaleY),...Ne(i[i.length-1],r,l,e.scaleX,e.scaleY))}else for(const c of i.slice(1))a.lineTo(...Ne(c,r,l,e.scaleX,e.scaleY));return a},Un=(e,t,a,s)=>{const n=f=>(1-f)**3*e[0]+3*(1-f)**2*f*t[0]+3*(1-f)*f**2*a[0]+f**3*s[0],o=f=>(1-f)**3*e[1]+3*(1-f)**2*f*t[1]+3*(1-f)*f**2*a[1]+f**3*s[1],r=(f,j,z)=>{const N=f-2*j+z,E=-2*f+2*j,R=f;if(Math.abs(N)<1e-10){if(Math.abs(E)<1e-10)return[];const Z=-R/E;return Z>0&&Z<1?[Z]:[]}const T=E*E-4*N*R;if(T<0)return[];const A=Math.sqrt(T),B=(-E-A)/(2*N),O=(-E+A)/(2*N),X=[];return B>0&&B<1&&X.push(B),O>0&&O<1&&O!==B&&X.push(O),X},l=e[0],i=t[0],c=a[0],u=s[0],h=e[1],p=t[1],g=a[1],v=s[1],S=r(i-l,c-i,u-c),b=r(p-h,g-p,v-g);let C=Math.min(e[0],s[0]),P=Math.max(e[0],s[0]),M=Math.min(e[1],s[1]),x=Math.max(e[1],s[1]);for(const f of S){const j=n(f);C=Math.min(C,j),P=Math.max(P,j)}for(const f of b){const j=o(f);M=Math.min(M,j),x=Math.max(x,j)}return{minX:C,maxX:P,minY:M,maxY:x}},ma=(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]],Sa=(e,t,a,s)=>({cp1:[t[0]+(a[0]-e[0])/6,t[1]+(a[1]-e[1])/6],cp2:[a[0]-(s[0]-t[0])/6,a[1]-(s[1]-t[1])/6]}),ks=e=>{const t=new Path2D,a=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(a.length<2)return t;t.moveTo(...a[0]);for(const s of a.slice(1))t.lineTo(...s);return a.length>2&&e.style?.closedPoints===1&&t.lineTo(...a[0]),t},qn=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},Gn=(e,t)=>({x:t.x-(e.style?.lineWidth??0)/2,y:t.y-(e.style?.lineWidth??0)/2,width:t.width+(e.style?.lineWidth??0),height:t.height+(e.style?.lineWidth??0)}),qe=(e,t,a,s=Gn)=>{const n=t(e,a),o=s(e,n,a),r=[n.x+n.width/2,n.y+n.height/2],l=((i,c,u=0)=>{if(u===0)return i;const h=[[i.x,i.y],[i.x+i.width,i.y],[i.x+i.width,i.y+i.height],[i.x,i.y+i.height]].map(v=>fe({point:v,origin:c,rotation:u})),p=Math.min(...h.map(v=>v[0])),g=Math.min(...h.map(v=>v[1]));return{x:p,y:g,width:Math.max(...h.map(v=>v[0]))-p,height:Math.max(...h.map(v=>v[1]))-g}})(o,r,e.rotation);return{borders:n,outerBorders:o,center:r,boundingBox:l}},bt=(e,t,a)=>{const{borders:s}=t;return{type:"rect",border:Zt(s),shapePath:e,line:Et({points:[[s.x+s.width/2,s.y],[s.x+s.width/2,s.y-23/a.canvasSize.scaleRatio]]}),anchors:[At({x:s.x+s.width/2,y:s.y-23/a.canvasSize.scaleRatio,radius:7/a.canvasSize.scaleRatio}),...us.map(n=>At({x:s.x+s.width*n[0],y:s.y+s.height*n[1],radius:7/a.canvasSize.scaleRatio}))]}},Ps=({borderStart:e,borderSize:t,vector:a,settings:s,invertedAxe:n,anchor:o})=>{switch(o){case 0:{if(n){const l=Math.max(0,a-t)+2*s.selectionPadding;return[e+t-2*s.selectionPadding,l]}const r=Math.max(2*s.selectionPadding,t-a);return[e+t-r,r]}case .5:return[e,t];case 1:if(n){const r=Math.min(e,e+t+a);return[r,e-r+2*s.selectionPadding]}return[e,Math.max(2*s.selectionPadding,t+a)];default:return[0,0]}},js=({borderX:e,borderWidth:t,borderY:a,borderHeight:s,center:n,originalShape:o})=>{const r=[e+t/2-n[0],a+s/2-n[1]],[l,i]=fe({point:r,rotation:-(o.rotation??0)});return{borderX:ze(e+l-r[0]),borderWidth:ze(t),borderY:ze(a+i-r[1]),borderHeight:ze(s)}},_n=(e,t,a,s)=>{const n=t.x+t.width/2,o=t.y+t.height/2,r=a?2*e.borderWidth+t.width:Math.abs(t.width+2*(e.borderWidth-t.width)),l=s?2*e.borderHeight+t.height:Math.abs(t.height+2*(e.borderHeight-t.height));return{...e,borderHeight:l,borderWidth:r,borderX:n-r/2,borderY:o-l/2}},lt=(e,t,a,s,n=!1,o=!1)=>{const{center:r,borders:l}=t.computed,i=fe({origin:r,point:e,rotation:t.rotation}),c=o&&n?[l.x+l.width/2,l.x+l.width/2]:[l.x+l.width-s.selectionPadding,l.x+s.selectionPadding],u=o&&n?[l.y+l.height/2,l.y+l.height/2]:[l.y+l.height-s.selectionPadding,l.y+s.selectionPadding],h=a.anchor[0]===0&&i[0]>=c[0]||a.anchor[0]===1&&i[0]<=c[1],p=a.anchor[1]===0&&i[1]>=u[0]||a.anchor[1]===1&&i[1]<=u[1],g=[Pe(i[0],s,a.anchor[0]===0&&!h||a.anchor[0]===1&&h?s.selectionPadding:-s.selectionPadding),Pe(i[1],s,a.anchor[1]===0&&!p||a.anchor[1]===1&&p?s.selectionPadding:-s.selectionPadding)];if(n&&o){const f=(({roundCursorPosition:j,borders:z,center:N,selectionMode:E,originalShape:R,settings:T})=>{const{selectionPadding:A}=T,B=Math.max(1,z.width-2*A),O=Math.max(1,z.height-2*A),X="ratio"in R&&R.ratio?R.ratio:B/O,Z=z.x+z.width/2,te=z.y+z.height/2;let D=1;if(E.anchor[0]!==.5&&E.anchor[1]!==.5){const k=[(E.anchor[0]-.5)*B,(E.anchor[1]-.5)*O],U=[j[0]-Z,j[1]-te],w=Math.hypot(k[0],k[1])||1;D=Math.hypot(U[0],U[1])/w}else if(E.anchor[0]===.5){const k=(E.anchor[1]-.5)*O,U=j[1]-te,w=Math.abs(k)||1;D=Math.abs(U)/w}else{const k=(E.anchor[0]-.5)*B,U=j[0]-Z,w=Math.abs(k)||1;D=Math.abs(U)/w}const _=2*A/(B+2*A),K=B*Math.max(D,_),ne=K+2*A,re=K/X+2*A;return{borderX:Z-ne/2,borderY:te-re/2,borderWidth:ne,borderHeight:re,center:N,originalShape:R}})({roundCursorPosition:g,borders:l,center:r,selectionMode:a,originalShape:t,settings:s});return{...js(f),isXinverted:h,isYinverted:p}}const v=s.gridGap?[a.anchor[0]===0?l.x:a.anchor[0]===.5?l.x+l.width/2:l.x+l.width,a.anchor[1]===0?l.y:a.anchor[1]===.5?l.y+l.height/2:l.y+l.height]:fe({origin:r,point:a.cursorStartPosition,rotation:t.rotation}),S=[g[0]-v[0],g[1]-v[1]],[b,C]=Ps({borderStart:l.x,borderSize:l.width,vector:S[0],settings:s,invertedAxe:h,anchor:a.anchor[0]}),[P,M]=Ps({borderStart:l.y,borderSize:l.height,vector:S[1],settings:s,invertedAxe:p,anchor:a.anchor[1]}),x=n?((f,j,z,N,E,R,T,A,B,O,X)=>{const{selectionPadding:Z}=X,te="ratio"in B&&B.ratio?B.ratio:(f.width-2*Z||1)/(f.height-2*Z||1),D=(N-2*Z)/(R-2*Z);let _,K,ne,re;return O.anchor[0]!==.5&&O.anchor[1]!==.5?D<te?(K=E,re=R,ne=(R-2*Z)*te+2*Z,_=O.anchor[0]===0?T?f.x+f.width-2*Z:f.x+(f.width-ne):T?f.x-ne+2*Z:f.x):(_=z,ne=N,re=(N-2*Z)/te+2*Z,K=O.anchor[1]===0?A?f.y+f.height-2*Z:f.y+(f.height-re):A?f.y-re+2*Z:f.y):O.anchor[0]!==.5?(_=z,ne=N,re=(N-2*Z)/te+2*Z,K=f.y+(f.height-re)/2):(K=E,re=R,ne=(R-2*Z)*te+2*Z,_=f.x+(f.width-ne)/2),{borderX:_,borderWidth:ne,borderY:K,borderHeight:re,center:j,originalShape:B}})(l,r,b,C,P,M,h,p,t,a,s):{borderX:b,borderWidth:C,borderY:P,borderHeight:M,center:r,originalShape:t};return{...js(o?_n(x,l,h,p):x),isXinverted:h,isYinverted:p}},Rt=(e,t)=>{const a=Zt(e),s=qe(e,ya,t);return{...e,path:a,computed:s,selection:bt(a,s,t)}},Kn=Rt,Ls=(e,t,a,s=0,n=0)=>{const o={toolId:e.id,type:e.type,id:be(`${e.type}_`),x:t[0],y:t[1],width:s,height:n,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 Rt(o,a)},Jn=(e,t)=>{e.globalAlpha!==0&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},ya=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),Vs=(e,t,a,[s,n]=[!1,!1])=>{const o=e[0]===.5?a.x+a.width/2:e[0]===0?a.x+(s?0:a.width):a.x+(s?a.width:0),r=e[1]===.5?a.y+a.height/2:e[1]===0?a.y+(n?0:a.height):a.y+(n?a.height:0);return xa([o,r],a.rotation??0,t)},Zs=(e,t,a)=>{const{isXinverted:s,isYinverted:n,settings:o,widthMultiplier:r,heightMultiplier:l}=a,i=(s||n)&&!(s&&n)&&(e.rotation??0)!==0&&a.rotation!==e.rotation,c=it(e,t,a),u=(e.width||1)*r,h=(e.height||1)*l,p=rt(a,c.x,c.y,u,h);return Rt({...e,width:u,height:h,x:p[0]-u/2,y:p[1]-h/2,rotation:i?-(e.rotation??0):e.rotation??0},o)},Dt=(e,t,a,s,n,o,r,l="replace")=>{let i=!1;if(n){i=Ht(e,n,a,s,!0,o?20:void 0);const u=((h,p,g)=>{if(h.mode==="translate")return{mode:"translate",cursorStartPosition:g,originalShape:p,hasBeenDuplicated:!1,dateStart:Date.now(),selectedShapesLengthAtMouseDown:G(p).length};if(h.mode==="rotate"){const{center:v}=p.computed;return{mode:"rotate",cursorStartPosition:g,originalShape:p,center:[v[0],v[1]],selectedShapesLengthAtMouseDown:G(p).length}}return h.mode==="resize"?{mode:"resize",cursorStartPosition:g,originalShape:p,anchor:h.anchor,selectedShapesLengthAtMouseDown:G(p).length}:void 0})(i||{mode:"default"},n,a);if(u?.mode==="resize"||u?.mode==="rotate")return{shape:n,mode:u}}const c=t.find(u=>G(n).find(h=>u.id===h?.id)?i&&Ht(e,u,a,s,!0,o?20:void 0):!!Es(e,u,a,s))??(i?n:void 0);if(n&&n?.id===c?.id)return{shape:n,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:n,selectedShapesLengthAtMouseDown:G(n).length}};if(c){if(l==="add"){const h=ce(Hs(n,[c]),s);return{shape:h,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:h,selectedShapesLengthAtMouseDown:G(n).length}}}if(l==="remove"){const h=ce(eo(n,c),s);return{shape:h,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:h,selectedShapesLengthAtMouseDown:G(n).length}}}const u=G(n).find(h=>h.id===c?.id)?n:ce([c],s);return{shape:u,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:u,selectedShapesLengthAtMouseDown:G(n).length}}}return{shape:l!=="replace"?n:void 0,mode:{mode:r?"selectionFrame":"default"}}},ce=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];const a=e.some(r=>r.rotation!==e[0].rotation)?0:e[0]?.rotation??0,s=((r,l,i)=>{const c=r.map(x=>[[x.computed.borders.x+i.selectionPadding,x.computed.borders.y+i.selectionPadding],[x.computed.borders.x-i.selectionPadding+x.computed.borders.width,x.computed.borders.y+i.selectionPadding],[x.computed.borders.x-i.selectionPadding+x.computed.borders.width,x.computed.borders.y-i.selectionPadding+x.computed.borders.height],[x.computed.borders.x+i.selectionPadding,x.computed.borders.y-i.selectionPadding+x.computed.borders.height]].map(f=>{const j=fe({point:[f[0],f[1]],origin:x.computed.center,rotation:-(x.rotation??0)});return fe({point:[j[0],j[1]],origin:[0,0],rotation:l})})),u=Math.min(...c.flatMap(x=>[x[0][0],x[1][0],x[2][0],x[3][0]])),h=Math.min(...c.flatMap(x=>[x[0][1],x[1][1],x[2][1],x[3][1]])),p=Math.max(...c.flatMap(x=>[x[0][0],x[1][0],x[2][0],x[3][0]])),g=Math.max(...c.flatMap(x=>[x[0][1],x[1][1],x[2][1],x[3][1]])),v=[(u+p)/2,(h+g)/2],S=fe({point:v,origin:[0,0],rotation:-l}),b=[v[0]-S[0],v[1]-S[1]],C=ze(u-b[0]),P=ze(p-b[0]),M=ze(h-b[1]);return{width:P-C,height:ze(g-b[1])-M,x:C,y:M}})(e,a,t),n=Ls({id:"group_selection",type:"rect",settings:Ka},[s.x,s.y],t,s.width,s.height),o=e.slice(1).reduce((r,l)=>{const i=l.style??{},c={};for(const u in i)r[u]!==void 0&&i[u]!==void 0&&r[u]===i[u]&&(c[u]=r[u]);return c},e[0].style??{});return{id:e.map(r=>r.id).join("-"),type:"group",shapes:e,rotation:a,visible:!0,locked:!1,selection:n.selection,x:n.x,y:n.y,width:n.width,height:n.height,style:o,computed:n.computed,path:n.path}},G=e=>e?e.type==="group"?e.shapes:[e]:[],Hs=(e,t)=>{const a=G(e);return[...new Set([...a,...t])]},eo=(e,t)=>G(e).filter(a=>a.id!==t.id),zs=e=>{const{clientX:t=0,clientY:a=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:a}},Ts=(e,t,a)=>{const{clientX:s,clientY:n}=zs(e),o=t.getBoundingClientRect();return[(s-o.left)/a.scaleRatio,(n-o.top)/a.scaleRatio]},ct=(e,t,a)=>{const{clientX:s,clientY:n}=zs(e),o=t?.getBoundingClientRect()??{left:0,top:0,width:a.canvasSize.width,height:a.canvasSize.height};return[(s-o.left)*(a.canvasSize.width/o.width)/a.canvasSize.scaleRatio-a.canvasOffset[0],(n-o.top)*(a.canvasSize.height/o.height)/a.canvasSize.scaleRatio-a.canvasOffset[1]]},Je=e=>"touches"in e,Ge=(e,t,[a,s])=>fe({origin:[a,s],point:e,rotation:t}),xa=(e,t,[a,s])=>fe({origin:[a,s],point:e,rotation:-t}),It=(e,t,a)=>a?bs(e,{x:t[0],y:t[1],radius:a}):((s,n)=>n[0]>=s.x&&n[0]<=s.x+s.width&&n[1]>=s.y&&n[1]<=s.y+s.height)(e,t),Ht=(e,t,a,s,n=!1,o=0)=>{const r=G(t).length>1?t:G(t)[0];if(!r)return!1;const{borders:l,center:i}=r.computed,c=Ge(a,r.rotation??0,i);if(n){const u=((h,p,g,v=0)=>{const{canvasSize:{scaleRatio:S}}=g,{borders:b}=h.computed;if(h.type==="line"||h.type==="polygon"||h.type==="curve"){for(let C=0;C<h.points.length;C++)if(It({x:h.points[C][0]-7/S,y:h.points[C][1]-7/S,width:ot/S,height:ot/S},p,v))return{mode:"resize",anchor:C}}else{if(It({x:b.x+b.width/2-7/S,y:b.y-ot/S-16/S,width:ot/S,height:ot/S},p,v))return{mode:"rotate"};for(const C of us)if(It({x:b.x+b.width*C[0]-7/S,y:b.y+b.height*C[1]-7/S,width:ot/S,height:ot/S},p,v))return{mode:"resize",anchor:C}}return!1})(r,c,s,o);if(u)return u}return r.selection?.type==="line"?(e.lineWidth=(r.style?.lineWidth??0)+15/s.canvasZoom,!!(ba(r,!0)?e.isPointInPath(r.path,c[0],c[1]):e.isPointInStroke(r.path,c[0],c[1]))&&{mode:"translate"}):!!It(l,c,15+o)&&{mode:"translate"}},As=(e,t,a,s,n=50)=>{if(t.locked||t.points.length<2)return!1;const{center:o}=t.computed,r=Ge(a,t.rotation??0,o);e.lineWidth=(t.style?.lineWidth??0)+n/s.canvasZoom;const l=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let i=0;i<l.length-1;i++){const c=Et({points:[l[i],l[i+1]]});if(e.isPointInStroke(c,r[0],r[1]))return{lineIndex:i}}return!1},ba=(e,t=!1)=>!(!t||!["curve","polygon"].includes(e.type))||e.style?.fillColor&&e.style?.fillColor!=="transparent"||["picture","text"].includes(e.type),Es=(e,t,a,s)=>{const{center:n}=t.computed,o=Ge(a,t.rotation??0,n);return e.lineWidth=(t.style?.lineWidth??0)+15/s.canvasZoom,!!(ba(t)?e.isPointInPath(t.path,o[0],o[1]):e.isPointInStroke(t.path,o[0],o[1]))&&{mode:"translate"}};function wa(e,t){const a=Math.max(e.x,t.x),s=Math.max(e.y,t.y),n=Math.min(e.x+(e.width||1),t.x+(t.width||1)),o=Math.min(e.y+(e.height||1),t.y+(t.height||1));if(a<n&&s<o)return{x:a,y:s,width:n-a,height:o-s}}const Rs=({ctx:e,path:t,rect:a,offset:s,center:n,rotation:o=0,checkFill:r})=>{for(let l=0;l<s;l+=s/2)for(let i=0;i<s;i+=s/2)for(let c=l+a.x;c<a.x+a.width;c+=s)for(let u=i+a.y;u<a.y+a.height;u+=s){const h=Ge([c,u],o,n);if(r?e.isPointInPath(t,h[0],h[1]):e.isPointInStroke(t,h[0],h[1]))return!0}return!1},Qa=(e,t,a,s)=>({type:"line",border:Zt(a.borders),shapePath:e,anchors:[...t.points.map(n=>At({x:n[0],y:n[1],radius:7/s.canvasSize.scaleRatio}))]}),Te=[.05,.1,.25,.5,1,2,4,8],Ca=({size:e,zoom:t,newOffset:[a,s],canvasSize:n})=>e==="infinite"?{zoom:t,offset:[a,s]}:t<1?{zoom:t,offset:[-(n.realWidth-n.realWidth/t)/2,-(n.realHeight-n.realHeight/t)/2]}:{zoom:t,offset:[Ue(a,n.realWidth/t-n.realWidth,0),Ue(s,n.realHeight/t-n.realHeight,0)]},Ma=({size:e,canvasSize:t,currentOffset:a,currentZoom:s,zoom:n,centerPoint:o})=>{const r=e==="fixed"&&n<1?[t.realWidth/2,t.realHeight/2]:o,l=a[0]-(r[0]/s-r[0]/n),i=a[1]-(r[1]/s-r[1]/n);return{offset:e==="infinite"?[l,i]:n<1?[-(t.realWidth-t.realWidth/n)/2,-(t.realHeight-t.realHeight/n)/2]:[Ue(l,t.realWidth/n-t.realWidth,0),Ue(i,t.realHeight/n-t.realHeight,0)],zoom:n}},Ds=e=>{const{canvasSize:{width:t,height:a,scaleRatioWithNoZoom:s},canvasZoom:n,canvasOffset:o}=e;return{x:o[0]*n*s,y:o[1]*n*s,width:t*n,height:a*n}},Is=(e,t)=>{const{canvasZoom:a,size:s}=t;if(s!=="fixed"||a>=1)return;const n=Ds(t);e.beginPath(),e.rect(n.x,n.y,n.width,n.height),e.closePath(),e.clip()},zt=(e,t)=>t.size!=="fixed"||e[0]>0&&e[0]<t.canvasSize.realWidth&&e[1]>0&&e[1]<t.canvasSize.realHeight,to=(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)}),Wt=(e,t)=>{const a=At(e),s=qe(e,to,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},ao=Wt,Ws=(e,t,a)=>{const s=it(e,t,a),n=(e.radius||.5)*a.widthMultiplier,o=rt(a,s.x,s.y,2*n,2*n);return Wt({...e,radius:n,x:o[0],y:o[1]},a.settings)},wt=(e,t)=>{const a=ks(e),s=qe(e,Nt,t);return{...e,path:a,selection:Qa(a,e,s,t),computed:s}},Ns=wt,Nt=(e,t)=>{const a=Math.min(...e.points.map(o=>o[0]))-t.selectionPadding,s=Math.max(...e.points.map(o=>o[0]))+t.selectionPadding,n=Math.min(...e.points.map(o=>o[1]))-t.selectionPadding;return{x:a,width:s-a,y:n,height:Math.max(...e.points.map(o=>o[1]))+t.selectionPadding-n}},so=(e,t,a,s)=>{if(t<0||t>e.points.length-1)return e;const n=[...e.points.slice(0,t+1),a,...e.points.slice(t+1)];return wt({...e,points:n},s)},Bs=(e,t,a,s=!1)=>{const n=[Pe(t[0],a),Pe(t[1],a)],o=Ge(n,e.rotation??0,e.computed.center),r={...e,points:s?e.points:[...e.points,o],tempPoint:s?o:void 0};return wt(r,a)},no=(e,t,a)=>{const s=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(s.length<2){const c=s[0]??[0,0],u=a.selectionPadding;return{x:c[0]-u,y:c[1]-u,width:2*u,height:2*u}}if(s.length<3)return Nt({...e,points:s},a);const n=ma(e,s);let o=Number.POSITIVE_INFINITY,r=Number.NEGATIVE_INFINITY,l=Number.POSITIVE_INFINITY,i=Number.NEGATIVE_INFINITY;for(let c=1;c<n.length-2;c++){const u=n[c-1],h=n[c],p=n[c+1],g=n[c+2],{cp1:v,cp2:S}=Sa(u,h,p,g),b=Un(h,v,S,p);o=Math.min(o,b.minX),r=Math.max(r,b.maxX),l=Math.min(l,b.minY),i=Math.max(i,b.maxY)}return ya({x:o,y:l,width:r-o,height:i-l},a)},Qt=(e,t)=>{const a=(n=>{const o=new Path2D,r=n.tempPoint?[...n.points,n.tempPoint]:n.points;if(r.length<2)return o;if(r.length<3)return ks(n);const l=n.style?.closedPoints===1&&r.length>2;o.moveTo(...r[0]);const i=ma(n,r);for(let c=1;c<i.length-2;c++){const u=i[c-1],h=i[c],p=i[c+1],g=i[c+2],{cp1:v,cp2:S}=Sa(u,h,p,g);o.bezierCurveTo(v[0],v[1],S[0],S[1],p[0],p[1])}return l&&o.closePath(),o})(e),s=qe(e,Nt,t,no);return{...e,path:a,selection:Qa(a,e,s,t),computed:s}},Fs=Qt,oo=(e,t,a,s)=>{if(t<0||t>e.points.length-1)return e;const n=[...e.points.slice(0,t+1),a,...e.points.slice(t+1)];return Qt({...e,points:n},s)},Os=(e,t,a,s=!1)=>{const n=[Pe(t[0],a),Pe(t[1],a)],o=e.computed.center,r=Ge(n,e.rotation??0,o),l={...e,points:s?e.points:[...e.points,r],tempPoint:s?r:void 0};return Qt(l,a)},io=(e,t)=>({x:e.x-e.radiusX-t.selectionPadding,width:2*(e.radiusX+t.selectionPadding),y:e.y-e.radiusY-t.selectionPadding,height:2*(e.radiusY+t.selectionPadding)}),Bt=(e,t)=>{const a=(n=>{const o=new Path2D;return o.ellipse(n.x,n.y,n.radiusX,n.radiusY,0,0,2*Math.PI),o})(e),s=qe(e,io,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},ro=Bt,Ys=(e,t,a)=>{const{isXinverted:s,isYinverted:n,settings:o,widthMultiplier:r,heightMultiplier:l}=a,i=(s||n)&&!(s&&n)&&(e.rotation??0)!==0&&a.rotation!==e.rotation,c=it(e,t,a),u=(e.radiusX||.5)*r,h=(e.radiusY||.5)*l,p=rt(a,c.x,c.y,2*u,2*h);return Bt({...e,radiusX:u,radiusY:h,x:p[0],y:p[1],rotation:i?-(e.rotation??0):e.rotation??0},o)},Xs=(e,t)=>((a,s)=>({...a,path:qn(a),computed:qe(a,Nt,s)}))({...e,id:be("triangle_"),type:"triangle"},t),lo=(e,t)=>{e.globalAlpha!==0&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},co=(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}),Ft=(e,t)=>{const a=[];let s;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){const o=Math.PI/2-Qs({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||a.push(Xs($s(e.points[0],o,e.style),t)),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||a.push(Xs($s(e.points[1],o+Math.PI,e.style),t));const r=(({line:l,size:i,direction:c})=>{const u=Math.PI/2-Qs({targetVector:[l.points[0],l.points[1]]}),h=[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 p,g;if(["start","both"].includes(c)){const v=fe({point:l.points[0],origin:h,rotation:-u});p=fe({point:[v[0],v[1]+i],origin:h,rotation:u})}else p=[...l.points[0]];if(["end","both"].includes(c)){const v=fe({point:l.points[1],origin:h,rotation:-u});g=fe({point:[v[0],v[1]-i],origin:h,rotation:u})}else g=[...l.points[1]];return{points:[p,g]}})({line:e,size:10+2*(e.style?.lineWidth??0),direction:e.style?.lineArrow===1?"start":e.style?.lineArrow===2?"end":"both"});s=Et(r)}else s=Et(e);const n=qe(e,co,t);return{...e,path:s,selection:Qa(s,e,n,t),arrows:a,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"},computed:n}},ho=Ft,$s=(e,t,a)=>{const s=[fe({point:[0,0],rotation:t}),fe({point:[-(5+(a.lineWidth??0)),10+2*(a.lineWidth??0)],rotation:t}),fe({point:[5+(a.lineWidth??0),10+2*(a.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:{...a,fillColor:a.strokeColor,strokeColor:"transparent"}}},Us=(e,t,a)=>{const{isXinverted:s,isYinverted:n,settings:o,widthMultiplier:r,heightMultiplier:l}=a,i=e.computed.borders.width-2*o.selectionPadding,c=e.computed.borders.height-2*o.selectionPadding,u=i*r,h=c*l,p=it(e,t,a),g=rt(a,p.x,p.y,u,h),v=e.computed.center[0]-i/2,S=e.computed.center[1]-c/2,b=g[0]-u/2,C=g[1]-h/2;return((P,M)=>P.type==="line"?Ft(P,M):P.type==="polygon"?Ns(P,M):Fs(P,M))({...e,points:e.points.map(([P,M])=>[b+(s?u-(P-v)*r:(P-v)*r),C+(n?h-(M-S)*l:(M-S)*l)])},a.settings)},Ot=(e,t)=>{const a=qe(e,ya,t),s=Zt(e);return{...e,path:s,selection:bt(void 0,a,t),computed:a}},uo=Ot,ka=(e,t,a,s,n)=>{const[o,r]=((l,i,c,u,h=!1)=>{if(!(l&&i&&u&&c))return[ms,ms];const p=l/i;if(p>c/u){const v=h?c:Math.min(l,c);return[v,v/p]}const g=h?u:Math.min(i,u);return[g*p,g]})(e.width,e.height,a,s,!0);return Ot({toolId:la.id,type:"picture",id:be("picture_"),x:-n.canvasOffset[0]+n.canvasSize.realWidth/n.canvasZoom/2-o/2,y:-n.canvasOffset[1]+n.canvasSize.realHeight/n.canvasZoom/2-r/2,width:o,height:r,ratio:o/r,src:t,img:e},n)},po=(e,t,a,s)=>new Promise((n,o)=>{const r=new Image;r.onerror=()=>{o(new Error("Some images could not be loaded"))},setTimeout(()=>{o(new Error("Timeout while loading images"))},4e3),e instanceof File?((l,i,c,u,h,p)=>{ln(c)?c.text().then(g=>{const v=rn(g);l.onload=async()=>{URL.revokeObjectURL(l.src);const S=ka(l,g,u,h,p);i(S)},l.src=v}):(l.onload=async()=>{URL.revokeObjectURL(l.src);const g=ka(l,l.src,u,h,p);i(g)},l.src=URL.createObjectURL(c))})(r,n,e,t,a,s):((l,i,c,u,h,p)=>{l.onload=()=>{URL.revokeObjectURL(l.src);const g=ka(l,c,u,h,p);i(g)},cn(c).then(g=>{l.src=g}).catch(()=>{l.src=""})})(r,n,e,t,a,s)}),qs=(e,t,a)=>{const{isXinverted:s,isYinverted:n,settings:o,widthMultiplier:r,heightMultiplier:l}=a,i=it(e,t,a),c=(e.width===0||e.height===0?e.ratio??1:e.width)*r,u=(e.width===0||e.height===0?e.ratio??1:e.height)*l,h=rt(a,i.x,i.y,c,u),p=(s||n)&&!(s&&n)&&(e.rotation??0)!==0&&a.rotation!==e.rotation;return Ot({...e,width:c,height:u,x:h[0]-c/2,y:h[1]-u/2,flipX:s?!e.flipX:!!e.flipX,flipY:n?!e.flipY:!!e.flipY,rotation:p?-(e.rotation??0):e.rotation??0},o)},Pa=["Texte"],Gs=(e,t)=>qe(e,fo,t),Yt=(e,t)=>{const a=Gs(e,t),s=Zt(e);return{...e,path:s,selection:bt(void 0,a,t),computed:a}},go=Yt,Xt=(e,t,a,s,n,o=Vt)=>{e.font=`${n?"italic":""} ${s?"bold":""} 1px ${o}`;const r=t.map(l=>a/e.measureText(l).width);return Math.min(...r)||36},fo=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),_s=(e,t,a,s)=>{const{isXinverted:n,isYinverted:o,settings:r,widthMultiplier:l,heightMultiplier:i}=s,c=(n||o)&&!(n&&o)&&(t.rotation??0)!==0&&s.rotation!==t.rotation,u=it(t,a,s),h=(t.width===0||t.height===0?t.ratio??1:t.width)*l,p=(t.width===0||t.height===0?t.ratio??1:t.height)*i,g=rt(s,u.x,u.y,h,p),v=Yt({...t,width:h,height:p,x:g[0]-h/2,y:g[1]-p/2,flipX:n?!t.flipX:!!t.flipX,flipY:o?!t.flipY:!!t.flipY,rotation:c?-(t.rotation??0):t.rotation??0},r);return{...v,fontSize:Xt(e,v.value,v.width,v.style?.fontBold??!1,v.style?.fontItalic??!1,v.style?.fontFamily)}},vo=(e,t,a,s)=>{const n={...t,value:a},o=((v,S,b,C,P,M=Vt)=>{v.font=`${P?"italic":""} ${C?"bold":""} ${b}px ${M}`;const x=S.map(f=>v.measureText(f).width);return Math.max(...x)||20})(e,n.value,n.fontSize,n.style?.fontBold??!1,n.style?.fontItalic??!1,n.style?.fontFamily),r=n.fontSize*n.value.length,l=o/r,i={...n,width:o,height:r,ratio:l},{center:c}=Gs(i,s),[u,h]=Vs([1,1],t.computed.center,t),[p,g]=Vs([1,1],c,i,[!1,!1]);return{...i,x:i.x-(p-u),y:i.y-(g-h)}},Ks=(e,t,a,s)=>{const n=[Pe(a[0],s),Pe(a[1],s)];switch(t.type){case"brush":return((o,r,l)=>xt({toolId:o.id,type:o.type,id:be(`${o.type}_`),points:[[r]],scaleX:1,scaleY:1,style:{opacity:o.settings.opacity.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},l))(t,n,s);case"line":return((o,r,l)=>{const i={toolId:o.id,type:o.type,id:be(`${o.type}_`),points:[r,r],style:{opacity:o.settings.opacity.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,lineArrow:o.settings.lineArrow.default}};return Ft(i,l)})(t,n,s);case"polygon":return((o,r,l)=>wt({toolId:o.id,type:o.type,id:be(`${o.type}_`),points:[r],style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,closedPoints:o.settings.closedPoints.default}},l))(t,n,s);case"curve":return((o,r,l)=>Qt({toolId:o.id,type:o.type,id:be(`${o.type}_`),points:[r],style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default,closedPoints:o.settings.closedPoints.default}},l))(t,n,s);case"rect":case"square":return Ls(t,n,s);case"text":return((o,r,l,i)=>{const c=Xt(o,Pa,150,r.settings?.fontBold.default??!1,r.settings?.fontItalic.default??!1,r.settings.fontFamily.default),u=c*(Pa.length||1);return Yt({toolId:r.id,type:r.type,id:be(`${r.type}_`),x:l[0]-150,y:l[1]-u,value:Pa,fontSize:c,width:150,height:u,ratio:150/u,style:{opacity:r.settings.opacity.default,strokeColor:r.settings.strokeColor.default,fontFamily:r.settings.fontFamily.default,fontItalic:r.settings.fontItalic.default,fontBold:r.settings.fontBold.default}},i)})(e,t,n,s);case"ellipse":return((o,r,l)=>Bt({toolId:o.id,type:o.type,id:be(`${o.type}_`),x:r[0],y:r[1],radiusX:0,radiusY:0,style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},l))(t,n,s);case"circle":return((o,r,l)=>Wt({toolId:o.id,type:o.type,id:be(`${o.type}_`),x:r[0],y:r[1],radius:0,style:{opacity:o.settings.opacity.default,fillColor:o.settings.fillColor.default,strokeColor:o.settings.strokeColor.default,lineWidth:o.settings.lineWidth.default,lineDash:o.settings.lineDash.default}},l))(t,n,s)}},Js=(e,t)=>{switch(t.type){case"brush":((a,s)=>{s.points.length<1||a.globalAlpha!==0&&s.style?.strokeColor!=="transparent"&&a.globalAlpha!==0&&a.stroke(s.path)})(e,t);break;case"text":((a,s)=>{if(a.globalAlpha!==0&&s.style?.strokeColor&&s.style.strokeColor!=="transparent"){a.scale(s.flipX?-1:1,s.flipY?-1:1),a.font=`${s.style?.fontItalic?"italic":""} ${s.style?.fontBold?"bold":""} ${s.fontSize}px ${s.style?.fontFamily??Vt}`,a.textBaseline="top",a.fillStyle=s.style.strokeColor;for(let n=0;n<s.value.length;n++)a.fillText(s.value[n],s.flipX?-s.x-s.width:s.x,(s.flipY?-s.y-s.height:s.y)+n*s.fontSize,s.width)}})(e,t);break;case"line":((a,s)=>{if(a.globalAlpha!==0){s.style?.fillColor!=="transparent"&&a.fill(s.path),s.style?.strokeColor!=="transparent"&&a.stroke(s.path);for(const n of s.arrows??[])Ve(a,n.style),lo(a,n)}})(e,t);break;case"polygon":((a,s)=>{a.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&a.fill(s.path),s.style?.strokeColor!=="transparent"&&a.stroke(s.path))})(e,t);break;case"curve":((a,s)=>{a.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&a.fill(s.path),s.style?.strokeColor!=="transparent"&&a.stroke(s.path))})(e,t);break;case"circle":((a,s)=>{a.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&a.fill(s.path),s.style?.strokeColor!=="transparent"&&a.stroke(s.path))})(e,t);break;case"ellipse":((a,s)=>{a.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&a.fill(s.path),s.style?.strokeColor!=="transparent"&&a.stroke(s.path))})(e,t);break;case"rect":case"square":Jn(e,t);break;case"picture":((a,s)=>{a.globalAlpha!==0&&(a.beginPath(),a.scale(s.flipX?-1:1,s.flipY?-1:1),a.drawImage(s.img,s.flipX?-s.x-s.width:s.x,s.flipY?-s.y-s.height:s.y,s.width,s.height))})(e,t)}},en=(e,t,a)=>{if(t.visible===!1)return;if(((n,o)=>{const r=(l=>{const{canvasSize:{width:i,height:c,scaleRatioWithNoZoom:u},canvasZoom:h,canvasOffset:p}=l;return{x:-p[0],y:-p[1],width:i/h/u,height:c/h/u}})(o);return!!wa(n.computed.boundingBox,r)})(t,a)){if(yt(e,a,t.rotation,t.computed.center),Ve(e,t.style),e.globalAlpha!==1)return((n,o)=>{const{outerBorders:r}=o.computed,l={width:2*r.width,height:2*r.height};if(l.width===0||l.height===0)return;const i=document.createElement("canvas"),c=i.getContext("2d");if(!c)throw new Error("No context found for canvas");i.width=l.width,i.height=l.height,c.translate(l.width/4-r.x,l.height/4-r.y),Ve(c,{...o.style,opacity:100}),Js(c,o),n.drawImage(i,r.x-l.width/4,r.y-l.height/4)})(e,t),void e.restore();Js(e,t),e.restore()}},tn=(e,t,a)=>{if(e.locked)return e;const s=fe({origin:a,point:e.computed.center,rotation:-t});if("points"in e){if(e.type==="brush"){const o=e.points.map(r=>r.map(l=>[l[0]+s[0]-e.computed.center[0],l[1]+s[1]-e.computed.center[1]]));return{...e,points:o,rotation:(e.rotation??0)+t}}const n=e.points.map(o=>fe({origin:a,point:o,rotation:-t}));return{...e,points:n}}return{...e,x:e.x+s[0]-e.computed.center[0],y:e.y+s[1]-e.computed.center[1],rotation:(e.rotation??0)+t}},an=(e,t,a,s,n,o,r)=>{if(a.locked)return a;switch(a.type){case"line":return((l,i,c,u)=>{const h=[Pe(l[0],u),Pe(l[1],u)],p=Ge(h,i.rotation??0,i.computed.center),g=We(["points",c.anchor],p,i);return Ft(g,u)})(t,a,s,n);case"polygon":return((l,i,c,u)=>{const h=[Pe(l[0],u),Pe(l[1],u)],p=Ge(h,i.rotation??0,i.computed.center),g=We(["points",c.anchor],p,i);return wt(g,u)})(t,a,s,n);case"curve":return((l,i,c,u)=>{const h=[Pe(l[0],u),Pe(l[1],u)],p=i.computed.center,g=Ge(h,i.rotation??0,p),v=We(["points",c.anchor],g,i);return Qt(v,u)})(t,a,s,n);case"brush":return((l,i,c,u,h,p)=>{const g=va({...i,scaleX:1,scaleY:1},u),v=i.computed.borders,{borderX:S,borderHeight:b,borderY:C,borderWidth:P,isXinverted:M,isYinverted:x}=lt(l,i,c,u,h,p),f=Math.max(0,g.width-2*u.selectionPadding),j=Math.max(0,g.height-2*u.selectionPadding),z=Math.max(0,P-2*u.selectionPadding),N=Math.max(0,b-2*u.selectionPadding),E=f?z/f:1,R=j?N/j:1;if(!f||!j)return i;const T=ze(S-v.x)+(M?2*v.x+g.width:0),A=ze(C-v.y)+(x?2*v.y+g.height:0);return xt({...i,points:i.points.map(B=>B.map(([O,X])=>[M?-O+T:O+T,x?-X+A:X+A])),scaleX:E,scaleY:R},u)})(t,a,s,n,o,r);case"circle":return((l,i,c,u,h)=>{const{borderX:p,borderHeight:g,borderY:v,borderWidth:S}=lt(l,i,c,u,!0,h);return Wt({...i,radius:Math.max(0,S/2-u.selectionPadding),x:p+S/2,y:v+g/2},u)})(t,a,s,n,r);case"ellipse":return((l,i,c,u,h=!1,p=!1)=>{const{borderX:g,borderHeight:v,borderY:S,borderWidth:b}=lt(l,i,c,u,h,p);return Bt({...i,radiusX:Math.max(0,b/2-u.selectionPadding),radiusY:Math.max(0,v/2-u.selectionPadding),x:g+b/2,y:S+v/2},u)})(t,a,s,n,o,r);case"rect":case"square":return((l,i,c,u,h=!1,p=!1)=>{const{borderX:g,borderHeight:v,borderY:S,borderWidth:b}=lt(l,i,c,u,h,p);return Rt({...i,width:Math.max(0,b-2*u.selectionPadding),height:Math.max(0,v-2*u.selectionPadding),x:g+u.selectionPadding,y:S+u.selectionPadding},u)})(t,a,s,n,a.type==="square"||o,r);case"text":return((l,i,c,u,h,p)=>{const{borderX:g,borderHeight:v,borderY:S,borderWidth:b,isXinverted:C,isYinverted:P}=lt(i,c,u,h,!0,p),M=Math.max(0,b-2*h.selectionPadding),x=Math.max(0,v-2*h.selectionPadding),f=Yt({...c,width:M,height:x,x:g+h.selectionPadding,y:S+h.selectionPadding,flipX:C?!c.flipX:!!c.flipX,flipY:P?!c.flipY:!!c.flipY},h);return{...f,fontSize:Xt(l,f.value,f.width,f.style?.fontBold??!1,f.style?.fontItalic??!1,f.style?.fontFamily)}})(e,t,a,s,n,r);case"picture":return((l,i,c,u,h)=>{const{borderX:p,borderHeight:g,borderY:v,borderWidth:S,isXinverted:b,isYinverted:C}=lt(l,i,c,u,!0,h),P=Math.max(0,S-2*u.selectionPadding),M=Math.max(0,g-2*u.selectionPadding);return Ot({...i,width:P,height:M,x:p+u.selectionPadding,y:v+u.selectionPadding,flipX:b?!i.flipX:!!i.flipX,flipY:C?!i.flipY:!!i.flipY},u)})(t,a,s,n,r);default:return a}},mo=(e,t,a,s,n,o,r)=>{if(a.type!=="group")return G(a).map(v=>an(e,t,v,s,n,o,r));const l=a,i=G(l),c=i.filter(v=>Bn.includes(v.type)),u=!c.some(v=>(v.rotation??0)!==(c[0]?.rotation??0)),h=(c[0]?.rotation??0)!==0&&c.length!==i.length,p=i.some(v=>Fn.includes(v.type)),g=((v,S,b,C,P,M)=>{const{borders:x}=S.computed,{borderX:f,borderHeight:j,borderY:z,borderWidth:N,isXinverted:E,isYinverted:R}=lt(v,S,b,C,P,M);return{newBorderX:f,newBorderY:z,newBorderWidth:N,newBorderHeight:j,widthMultiplier:(N-2*C.selectionPadding)/(x.width-2*C.selectionPadding||1),heightMultiplier:(j-2*C.selectionPadding)/(x.height-2*C.selectionPadding||1),isXinverted:E,isYinverted:R,groupCenter:[f+N/2,z+j/2],rotation:S.rotation??0,settings:C,originalBorders:x}})(t,l,s,n,o||!u||p||h,r);return i.map(v=>{if(v.locked)return v;switch(v.type){case"rect":case"square":return Zs(v,l,g);case"picture":return qs(v,l,g);case"text":return _s(e,v,l,g);case"ellipse":return Ys(v,l,g);case"circle":return Ws(v,l,g);case"brush":return Ms(v,l,g);case"line":case"polygon":case"curve":return Us(v,l,g);default:return an(e,t,v,s,n,o,r)}})},sn=(e,t,a,s)=>{if(e.locked)return e;switch(e.type){case"rect":case"square":case"ellipse":case"circle":case"picture":case"text":return Be({...e,x:e.x+t,y:e.y+a},s);case"line":case"polygon":case"curve":return Be({...e,points:e.points.map(([n,o])=>[n+t,o+a])},s);case"brush":return Be({...e,points:e.points.map(n=>n.map(([o,r])=>[o+t,r+a]))},s);default:return e}},nn=(e,t,a,s,n)=>{const o=t.computed.borders,r=((c,u)=>u?[Math.abs(c[0])>Math.abs(c[1])?c[0]:0,Math.abs(c[1])>Math.abs(c[0])?c[1]:0]:c)([e[0]-a[0],e[1]-a[1]],n),l=r[0]===0?0:Pe(o.x+s.selectionPadding+r[0],s)-(o.x+s.selectionPadding),i=r[1]===0?0:Pe(o.y+s.selectionPadding+r[1],s)-(o.y+s.selectionPadding);return G(t).map(c=>sn(c,l,i,s))},Be=(e,t)=>{switch(e.type){case"rect":case"square":return Kn(e,t);case"ellipse":return ro(e,t);case"circle":return ao(e,t);case"picture":return uo(e,t);case"text":return go(e,t);case"line":return ho(e,t);case"polygon":return Ns(e,t);case"curve":return Fs(e,t);case"brush":return Yn(e,t);default:return e}},on=({ctx:e,shape:t,settings:a,selectionWidth:s,selectionColor:n,hoverMode:o,selectionMode:r,withAnchors:l=!0})=>{switch(a.debug&&((i,c,u,h)=>{c.selection&&h.debug&&(i.save(),i.scale(h.canvasSize.scaleRatio,h.canvasSize.scaleRatio),i.translate(h.canvasOffset[0],h.canvasOffset[1]),Ve(i,{fillColor:"transparent",strokeColor:"green",lineWidth:u/h.canvasSize.scaleRatio}),i.strokeRect(c.computed.boundingBox.x,c.computed.boundingBox.y,c.computed.boundingBox.width,c.computed.boundingBox.height),i.restore())})(e,t,s,a),t.type){case"rect":case"square":case"circle":case"ellipse":case"picture":case"text":case"brush":((i,c,u,h,p,g)=>{if(c.selection&&(yt(i,p,c.rotation,c.computed.center),p.debug&&(Ve(i,{fillColor:"transparent",strokeColor:"red",lineWidth:h/p.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),Ve(i,{fillColor:"transparent",strokeColor:u,lineWidth:h/p.canvasSize.scaleRatio}),c.selection.shapePath?i.stroke(c.selection.shapePath):i.stroke(c.selection.border),g&&!c.locked)){c.selection.shapePath&&i.stroke(c.selection.border),c.selection.line&&i.stroke(c.selection.line),Ve(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/p.canvasSize.scaleRatio,shadowColor:u,shadowBlur:0});for(const v of c.selection.anchors)i.fill(v),i.stroke(v)}})(e,t,n,s,a,l);break;case"group":((i,c,u,h,p,g,v)=>{if(c.selection&&(c.shapes.forEach(S=>{Ve(i,{fillColor:"transparent",strokeColor:u,lineWidth:h/g.canvasSize.scaleRatio}),yt(i,g,S.rotation,S.computed.center),S.selection?.shapePath&&i.stroke(S.selection.shapePath),i.restore()}),p.mode!=="rotate"&&(yt(i,g,c.rotation,c.computed.center),g.debug&&(Ve(i,{fillColor:"transparent",strokeColor:"red",lineWidth:h/g.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),Ve(i,{fillColor:"transparent",strokeColor:u,lineWidth:h/g.canvasSize.scaleRatio}),v&&!c.locked))){i.stroke(c.selection.border),c.selection.line&&i.stroke(c.selection.line),Ve(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/g.canvasSize.scaleRatio});for(const S of c.selection.anchors)i.fill(S),i.stroke(S)}})(e,t,n,s,r,a,l);break;case"polygon":case"line":case"curve":(({ctx:i,shape:c,withAnchors:u,selectionWidth:h,selectionColor:p,hoverMode:g,settings:v})=>{if(c.selection&&(yt(i,v,c.rotation,c.computed.center),v.debug&&(Ve(i,{fillColor:"transparent",strokeColor:"red",lineWidth:h/v.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),Ve(i,{fillColor:"transparent",strokeColor:p,lineWidth:h/v.canvasSize.scaleRatio}),c.selection.shapePath&&i.stroke(c.selection.shapePath),u&&!c.locked)){Ve(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/v.canvasSize.scaleRatio,shadowColor:p,shadowBlur:0});for(let S=0;S<c.selection.anchors.length;S++){const b=c.selection.anchors[S];g.mode==="resize"&&g.anchor===S?(i.shadowBlur=10,i.fill(b),i.shadowBlur=0):i.fill(b),i.stroke(b)}}})({ctx:e,shape:t,withAnchors:l,selectionWidth:s,selectionColor:n,hoverMode:o,settings:a})}e.restore()},So=({ctx:e,selectionFrame:t,settings:a})=>{yt(e,a),((s,n,o)=>{Ve(s,{fillColor:"rgba(170,170,170, 0.1)",strokeColor:"rgb(170,170,170)",lineWidth:1/o.canvasSize.scaleRatio}),s.fillRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1]),s.strokeRect(n[0][0],n[0][1],n[1][0]-n[0][0],n[1][1]-n[0][1])})(e,t.frame,a),e.restore()},ja=(e,t)=>G(e).map(a=>({...sn(a,20,20,t),id:be(`${a.type}_`)})),La=e=>e.filter(t=>t!=null),Va=(e,t,a)=>t<0||a<0||t>e.length-1||a>e.length-1?e:t<a?[...e.slice(0,t),...e.slice(t+1,a+1),e[t],...e.slice(a+1,e.length)]:[...e.slice(0,a),e[t],...e.slice(a,t),...e.slice(t+1,e.length)],rn=e=>{const t=new DOMParser().parseFromString(e,"text/xml").getElementsByTagName("svg")[0];if(!t)return"";const a=t.getAttribute("width"),s=t.getAttribute("height");let n;if(a||s)n=e;else{const r=t.getAttribute("viewBox")??"0 0 300 300",[,,l,i]=r.split(" ");t.setAttribute("width",l??"300"),t.setAttribute("height",i??"300"),n=new XMLSerializer().serializeToString(t)}const o=new Blob([n],{type:"image/svg+xml"});return URL.createObjectURL(o)},ln=e=>(e instanceof File?e.name:e).includes(".svg"),cn=e=>ln(e)?fetch(e).then(t=>t.text()).then(t=>rn(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),dn=(e,t)=>{const a=document.createElement("a");a.href=e,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a)},yo=e=>e.src.includes("<svg")?e.src:(t=>{const a=document.createElement("canvas");a.width=t.width,a.height=t.height;const s=a.getContext("2d");return s?(s.drawImage(t,0,0),a.toDataURL("image/png")):""})(e.img),Za=({shapes:e,settings:t})=>{const a=document.createElement("canvas"),s=a.getContext("2d");if(!s)throw new Error("No context found for canvas");const{realHeight:n,realWidth:o}=t.canvasSize;a.width=o,a.height=n,s.clearRect(0,0,o,n),xs(s);for(let r=e.length-1;r>=0;r--)en(s,e[r],t);return a.toDataURL("image/png")},hn=({shapes:e,settings:t,view:a})=>{if(a==="fitToShapes"&&!e.length)throw new Error("No image found to export");if(a==="fitToShapes"){const n=Math.min(...e.map(c=>c.computed.boundingBox.x)),o=Math.max(...e.map(c=>c.computed.boundingBox.x+c.computed.boundingBox.width)),r=Math.min(...e.map(c=>c.computed.boundingBox.y)),l=Math.max(...e.map(c=>c.computed.boundingBox.y+c.computed.boundingBox.height)),i={...t,canvasOffset:[-n,-r],canvasZoom:1,canvasSize:{realWidth:o-n,realHeight:l-r,width:o-n,height:l-r,scaleRatio:1,scaleRatioWithNoZoom:1}};return Za({shapes:e,settings:i})}if(a==="defaultView"){const n={...t,canvasOffset:[0,0],canvasZoom:1,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:1,scaleRatioWithNoZoom:1}};return Za({shapes:e,settings:n})}const s={...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}};return Za({shapes:e,settings:s})},xo=(e,t,a)=>{return n=Ha(e,t,a),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(n))}`;var n},bo=e=>{const t=["img","id","selection","path","arrows","tempPoint","computed",["flipX",[void 0,!1]],["flipY",[void 0,!1]]];return e.map(a=>a.type!=="picture"||a.src.startsWith("http")?ua(t,a):ua(t,{...a,src:yo(a)}))},Ha=(e,t,a)=>({shapes:bo(e),config:{width:t,height:a}}),un=(e,t)=>Be({...e,id:be(`${e.type}_`)},t),wo=(e,t,a,s)=>{const n=m.useRef([]),o=m.useRef(void 0),r=m.useRef({dataChanged:[]}),[l,i]=m.useState(void 0),[c,u]=m.useState(void 0),[h,p]=m.useState(void 0),[g,v]=m.useState(void 0),[S,b]=m.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),C=m.useCallback(w=>{o.current=typeof w=="function"?w(o.current):w,u(o.current)},[]),P=S.cursor>0,M=S.cursor<S.states.length-1,x=n.current.length>0,f=m.useCallback(()=>{b(w=>Ss(w.states[w.cursor]?.shapes,n.current)?w:{states:[...w.states.slice(0,w.cursor+1),{shapes:n.current,selectedShape:o.current,source:"user"}],cursor:w.cursor+1})},[]),j=m.useCallback(w=>{n.current=[...w,...n.current]},[]),z=m.useCallback((w,Q=!1,y=!1)=>{const L=[];n.current=n.current.flatMap(I=>{const V=w.find(q=>q.id===I.id);if(V){const q=Q?ja(ce([V],e),e)[0]:{...V,id:be(`${I.type}_`)};return L.push(q),[q,I]}return I}),y&&C(ce(L,e))},[e,C]),N=m.useCallback((w,Q,y,L)=>{if(w.target&&"className"in w.target&&![gs,fs].includes(w.target.className)||!L)return void p(void 0);const I=n.current.find(V=>!V.locked&&(G(c)?.map(q=>q.id).includes(V.id)?!!Ht(Q,V,y,e):!!Es(Q,V,y,e)));p(I)},[e,c]),E=m.useCallback(async(w,Q=300,y=300)=>{const L=await po(w,Q,y,e);return j([L]),f(),L},[j,f,e]),R=m.useCallback((w,Q=!1)=>{n.current=n.current.map(y=>w.find(L=>L.id===y.id)??y),C(y=>y&&ce(G(y).map(L=>w.find(I=>I.id===L.id)??L),e)),Q&&f()},[f,C,e]),T=m.useCallback(w=>{const Q=w.map(y=>ua(["chosen"],y));n.current=Q,f()},[f]),A=m.useCallback(w=>{const Q=new Set(w.map(y=>y.id));C(y=>{const L=G(y).map(I=>I.id);return L&&Q.size&&L.find(I=>Q.has(I))?void 0:y}),n.current=n.current.filter(y=>!Q?.has(y.id)),f()},[f,C]),B=m.useCallback(w=>{b(Q=>{const y=w(Q);return n.current=Q.states[y]?.shapes??[],C(Q.states[y]?.selectedShape),We("cursor",y,Q)})},[C]),O=m.useCallback(()=>{B(w=>Math.max(0,w.cursor-1))},[B]),X=m.useCallback(()=>{B(w=>Math.min(w.states.length-1,w.cursor+1))},[B]),Z=m.useCallback((w,Q)=>{C(void 0),n.current=w,b(y=>Q.clearHistory?{states:[{shapes:w,selectedShape:void 0,source:Q.source}],cursor:0}:{states:[...y.states.slice(0,y.cursor+1),{shapes:w,selectedShape:void 0,source:Q.source}],cursor:y.cursor+1})},[C]),te=m.useCallback((w,Q)=>{const y=n.current,L=y.findIndex(V=>V.id===w),I=y.findIndex(V=>V.id===Q);T(Va(y,L,I))},[T]),D=m.useCallback((w,Q)=>{const y=[...n.current],L=new Set(w.map(V=>V.id)),I=y.map((V,q)=>L.has(V.id)?q:-1).filter(V=>V>=0);if(I.length!==0)switch(Q){case"first":case"last":{const V=I.map(W=>y[W]).filter(Boolean),q=y.filter((W,H)=>!I.includes(H));T(Q==="first"?[...V,...q]:[...q,...V]);break}case"backward":{let V=[...y];const q=I.sort((W,H)=>H-W).map(W=>y[W].id);for(const W of q){const H=V.findIndex(ae=>ae.id===W);if(H<V.length-1){const ae=H+1;L.has(V[ae].id)||(V=Va(V,H,ae))}}T(V);break}case"forward":{let V=[...y];const q=I.sort((W,H)=>W-H).map(W=>y[W].id);for(const W of q){const H=V.findIndex(ae=>ae.id===W);if(H>0){const ae=H-1;L.has(V[ae].id)||(V=Va(V,H,ae))}}T(V);break}}},[T]),_=m.useCallback((w,Q,y,L)=>{const I=new Set(Q.map(q=>q.id)),V=L==="rotateClockwise"||L==="rotateCounterclockwise"?n.current.map(q=>I.has(q.id)?Be(tn(q,L==="rotateClockwise"?Math.PI/2:-Math.PI/2,y),e):q):((q,W,H,ae,pe,F)=>{if(H.length===0)return W;const de=ce(H,F),le=de.computed.borders,ve={newBorderX:le.x,newBorderY:le.y,newBorderWidth:le.width,newBorderHeight:le.height,widthMultiplier:1,heightMultiplier:1,isXinverted:pe==="flipHorizontally",isYinverted:pe==="flipVertically",groupCenter:ae,rotation:0,settings:F,originalBorders:le},Ee=new Set(H.map(J=>J.id));return W.map(J=>{if(J.locked||!Ee.has(J.id))return J;switch(J.type){case"rect":case"square":return Zs(J,de,ve);case"picture":return qs(J,de,ve);case"text":return _s(q,J,de,ve);case"ellipse":return Ys(J,de,ve);case"circle":return Ws(J,de,ve);case"brush":return Ms(J,de,ve);case"line":case"polygon":case"curve":return Us(J,de,ve);default:return J}})})(w,n.current,Q,y,L,e);C(ce(V.filter(q=>I.has(q.id)),e)),T(V)},[e,T,C]),K=m.useCallback(w=>{const Q=new Set(w.map(L=>L.id)),y=n.current.map(L=>Q.has(L.id)?We("visible",L.visible===!1,L):L);C(L=>ce(y.filter(I=>G(L)?.map(V=>V.id).includes(I.id)),e)),T(y)},[T,e,C]),ne=m.useCallback(w=>{const Q=new Set(w.map(L=>L.id)),y=n.current.map(L=>Q.has(L.id)?We("locked",!L.locked,L):L);C(L=>ce(y.filter(I=>G(L)?.map(V=>V.id).includes(I.id)),e)),T(y)},[T,e,C]),re=m.useCallback((w,Q)=>{r.current.hasOwnProperty(w)&&(r.current[w]=[...r.current[w],Q])},[]),k=m.useCallback((w,Q)=>{if(r.current.hasOwnProperty(w))if(Q){const y=r.current[w].indexOf(Q);r.current[w]=[...r.current[w].slice(0,y),...r.current[w].slice(y+1)]}else r.current[w]=[]},[]);m.useEffect(()=>{const w=S.states[S.cursor],Q=Ha(w.shapes,t,a);for(const y of r.current.dataChanged)y(Q,w.source)},[t,a,S]),m.useEffect(()=>{n.current=n.current.map(w=>Be(w,e)),C(w=>w===void 0?void 0:ce(G(w).map(Q=>Be(Q,e)),e))},[e,C]);const U=m.useCallback((w,Q)=>{i(y=>{const L=[y?.frame[0]??[Q[0],Q[1]],[Q[0],Q[1]]],I=n.current.filter(q=>!q.locked&&((W,H,ae)=>{const{borders:pe,center:F,boundingBox:de}=H.computed,le=Math.min(ae[0][0],ae[1][0]),ve=Math.max(ae[0][0],ae[1][0]),Ee=Math.min(ae[0][1],ae[1][1]),J={x:le,y:Ee,width:ve-le,height:Math.max(ae[0][1],ae[1][1])-Ee},Se=wa(de,J);if(!Se)return!1;if(pe.width<=1||pe.height<=1)return!0;if(W.lineWidth=(H.style?.lineWidth??0)+10,H.type==="brush"){const ge=H.points.flat(),ee=Math.min(...ge.map(he=>he[0])),ie=Math.min(...ge.map(he=>he[1]));for(const he of H.points){if(he.length<1)break;if(he.length<2){const Me=Ne(he[0],ee,ie,H.scaleX,H.scaleY);if(bs(Se,{x:Me[0],y:Me[1],radius:(H.style?.lineWidth??1)/2}))return!0}for(let Me=0;Me<he.length-1;Me++){const De=xa(Ne(he[Me],ee,ie,H.scaleX,H.scaleY),H.rotation??0,F),Re=xa(Ne(he[Me+1],ee,ie,H.scaleX,H.scaleY),H.rotation??0,F),we=wa({x:Math.min(De[0],Re[0]),y:Math.min(De[1],Re[1]),width:Math.abs(De[0]-Re[0]),height:Math.abs(De[1]-Re[1])},J);if(we){const Ie=new Path2D;if(Ie.moveTo(...De),Ie.lineTo(...Re),Rs({ctx:W,path:Ie,rect:we,offset:10,center:F,checkFill:!1}))return!0}}}return!1}const oe=ba(H);return Rs({ctx:W,path:H.path,rect:Se,offset:10,center:F,rotation:H.rotation??0,checkFill:oe})})(w,q,L)),V=ce(I,e);return C(s?ce(Hs(y?.oldSelection,I),e):V),{oldSelection:y?.oldSelection,frame:L}})},[e,s,C]);return{registerEvent:re,unregisterEvent:k,shapesRef:n,selectedShape:c,hoveredShape:h,selectionFrame:l,setSelectionFrame:i,copiedShape:g,setCopiedShape:v,refreshSelectedShapes:U,addShapes:j,duplicateShapes:z,addPictureShape:E,moveShapes:D,swapShapes:te,saveShapes:f,setSelectedShape:C,refreshHoveredShape:N,toggleShapeVisibility:K,toggleShapeLock:ne,removeShape:A,updateShape:R,transformShape:_,backwardShape:O,forwardShape:X,clearShapes:Z,canGoBackward:P,canGoForward:M,canClear:x}},pn=e=>{const t=[e[0].clientX,e[0].clientY],a=[e[1].clientX,e[1].clientY];var s,n;return{diff:Cs(t,a),center:(n=a,[((s=t)[0]+n[0])/2,(s[1]+n[1])/2])}},Qo=({canvasElt:e,canvasTransformation:t,canvasSize:a,size:s,setCanvasTransformation:n})=>{const o=m.useRef([]),[r,l]=m.useState(o.current.length>0),i=m.useRef(null),c=m.useRef(t);c.current=t;const u=m.useCallback(({startDiff:h,startZoom:p,startCenter:g,startOffset:v,currentDiff:S,currentCenter:b,isMoving:C,isZooming:P})=>{if(!e||!S||!h)return;const M=(({canvasBoundingRect:x,canvasSize:f,size:j,startDiff:z,startZoom:N,startCenter:E,startOffset:R,currentDiff:T,currentCenter:A,isMoving:B,isZooming:O})=>{const X=O?Ue(T/z*N,Te[0],Te[Te.length-1]):N,Z=B?[R[0]+(A[0]-E[0])*(f.width/x.width)/f.scaleRatio/N,R[1]+(A[1]-E[1])*(f.height/x.height)/f.scaleRatio/N]:[R[0],R[1]],te=[(A[0]-x.left)/f.scaleRatio,(A[1]-x.top)/f.scaleRatio];return Ma({size:j,canvasSize:f,currentOffset:Z,currentZoom:N,zoom:X,centerPoint:te})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:a,size:s,startDiff:h,startZoom:p,startCenter:g,startOffset:v,currentDiff:S,currentCenter:b,isMoving:C,isZooming:P});n(M)},[e,a,s,n]);m.useEffect(()=>{if(!e)return;const h=p=>{if(o.current=[...o.current,p],l(o.current.length>0),o.current.length===2){p.stopPropagation();const{diff:g,center:v}=pn(o.current);i.current={startDiff:g,startCenter:v,startZoom:c.current.zoom,startOffset:c.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",h),()=>{e.removeEventListener("pointerdown",h)}},[e]),m.useEffect(()=>{if(!r)return;const h=g=>{const v=o.current.findIndex(S=>S.pointerId===g.pointerId);if(v>-1&&(o.current[v]=g),o.current.length===2&&i.current){const{diff:S,center:b}=pn(o.current),C=i.current.isZooming||((M,x)=>Math.abs(M-x.startDiff)>30)(S,i.current),P=i.current.isMoving||C||((M,x)=>Math.abs(Cs(M,x.startCenter))>10)(b,i.current);i.current={...i.current,isMoving:P,isZooming:C},u({...i.current,currentDiff:S,currentCenter:b})}},p=g=>{o.current=o.current.filter(v=>v.pointerId!==g.pointerId),l(o.current.length>0)};return document.addEventListener("pointermove",h),document.addEventListener("pointerup",p),document.addEventListener("pointerout",p),document.addEventListener("pointercancel",p),document.addEventListener("pointerleave",p),()=>{document.removeEventListener("pointermove",h),document.removeEventListener("pointerup",p),document.removeEventListener("pointerout",p),document.removeEventListener("pointercancel",p),document.removeEventListener("pointerleave",p)}},[r,u])},gn={offset:[0,0],zoom:1},Co=({canvasSize:e,size:t,zoomEnabled:a,canvasElt:s})=>{const[n,o]=m.useState(gn),r=m.useRef(0),l=m.useCallback(u=>{o(({zoom:h})=>Ca({zoom:h,size:t,canvasSize:e,newOffset:u}))},[e,t]),i=m.useCallback(u=>{o(({offset:h,zoom:p})=>(({size:g,canvasSize:v,currentOffset:S,currentZoom:b,action:C})=>{const P=C==="default"?Te[4]:C==="zoom"?Te[Ue(Te.length-1-Te.slice(0).reverse().findIndex(x=>x<=b)+1,0,Te.length-1)]:Te[Ue(Te.findIndex(x=>x>=b)-1,0,Te.length-1)],M=[v.realWidth/2,v.realHeight/2];return Ma({size:g,canvasSize:v,currentOffset:S,currentZoom:b,zoom:P,centerPoint:M})})({size:t,canvasSize:e,currentOffset:h,currentZoom:p,action:u}))},[e,t]);Qo({canvasElt:s,canvasTransformation:n,canvasSize:e,size:t,setCanvasTransformation:o});const c=m.useCallback(()=>{o(gn)},[]);return m.useEffect(()=>{if(!a||!s)return;const u=h=>{const p=h.ctrlKey,{deltaX:g,deltaY:v}=((P,M)=>{const x=Math.abs(P.deltaY)<50&&M<50,f=P.ctrlKey,j=ys()&&x&&f;switch(P.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:16*P.deltaX,deltaY:16*P.deltaY};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:P.deltaX*window.innerHeight,deltaY:P.deltaY*window.innerHeight};default:return j?{deltaX:5*P.deltaX,deltaY:5*P.deltaY}:{deltaX:P.deltaX,deltaY:P.deltaY}}})(h,h.timeStamp-r.current);if(r.current=h.timeStamp,p){h.preventDefault();const P=Ts(h,s,e);return void o(({offset:M,zoom:x})=>(({size:f,canvasSize:j,currentOffset:z,currentZoom:N,delta:E,centerPoint:R})=>{const T=Ue(N*(1-E/1e3),Te[0],Te[Te.length-1]);return Ma({size:f,canvasSize:j,currentOffset:z,currentZoom:N,zoom:T,centerPoint:R})})({size:t,canvasSize:e,currentOffset:M,currentZoom:x,delta:v,centerPoint:P}))}const S=h.shiftKey,[b,C]=S?[v,g]:[g,v];o(({offset:P,zoom:M})=>{const x=[P[0]-b/M,P[1]-C/M],f=Ca({zoom:M,size:t,canvasSize:e,newOffset:x});return f.offset[0]===P[0]&&f.offset[1]===P[1]||h.preventDefault(),f})};return s.addEventListener("wheel",u,{passive:!1}),()=>{s.removeEventListener("wheel",u)}},[s,t,e,a]),{setCanvasTransformation:o,setCanvasOffset:l,setCanvasZoom:i,resetZoom:c,canvasTransformation:n}},fn=(e,t=!1)=>{const a=(n,o)=>{if(Array.isArray(n))return o},s=e.map(n=>{if(typeof n!="object")return null;switch(n.type){case"brush":return $e(a,Ja,n);case"circle":return $e(a,os,n);case"curve":return $e(a,as,n);case"ellipse":return $e(a,is,n);case"line":return $e(a,es,n);case"polygon":return $e(a,ts,n);case"rect":return $e(a,ss,n);case"square":return $e(a,ns,n);case"text":return $e(a,rs,n)}return null});return La(t?[...s,la]:s)},Mo=({addShapes:e,drawCanvasRef:t,setActiveTool:a,refreshHoveredShape:s,shapes:n,selectionMode:o,activeTool:r,isInsideComponent:l,isInsideCanvas:i,setCanvasOffset:c,selectedShape:u,canvasOffsetStartData:h,refreshSelectedShapes:p,setSelectedShape:g,setSelectionFrame:v,setCanvasOffsetStartData:S,updateSingleShape:b,duplicateShapes:C,saveShapes:P,setSelectionMode:M,setCanvasMoveAcceleration:x,settings:f,isShiftPressed:j,isAltPressed:z,withFrameSelection:N,withContextMenu:E,isSpacePressed:R})=>{const T=m.useRef(null),[A,B]=m.useState({mode:"default"}),{registerDoubleClickEvent:O,unRegisterDoubleClickEvent:X}=(()=>{const k=m.useRef(void 0),U=m.useRef(void 0),w=Q=>{const y=Date.now();k.current&&y<k.current+300&&U.current?.(Q),k.current=Date.now()};return{registerDoubleClickEvent:(Q,y)=>{U.current=y,Q.addEventListener("click",w),Q.addEventListener("touchend",w)},unRegisterDoubleClickEvent:Q=>{Q.removeEventListener("click",w),Q.removeEventListener("touchend",w)}}})(),Z=(k,U)=>{const w=U?.getContext("2d");if(w){if(r===Xe&&E){const Q=ct(k,t.current,f),{shape:y,mode:L}=Dt(w,n,Q,f,u,Je(k),!1);g(y),M({mode:"contextMenu",cursorStartPosition:Q,originalShape:y,anchor:"anchor"in L?L.anchor:void 0})}else g(void 0),M({mode:"default"});a(Xe),v(void 0)}},te=m.useRef(null);te.current=k=>((U,w,Q,y,L,I,V,q,W,H,ae,pe,F,de,le,ve,Ee,J)=>{if(J&&clearTimeout(J),Je(U)&&U.touches.length>1)return;const Se=w.current?.getContext("2d");if(!Se)return;const oe=ct(U,w.current,F);if(y.mode==="selectionFrame"){pe(Se,oe,F);const ee=Ts(U,w.current,F.canvasSize);return void Ee([Math.ceil(Ue(ee[0]*F.canvasZoom<50?ee[0]*F.canvasZoom-50:ee[0]*F.canvasZoom>F.canvasSize.width/F.canvasSize.scaleRatioWithNoZoom-50?ee[0]*F.canvasZoom-(F.canvasSize.width/F.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/F.canvasZoom),Math.ceil(Ue(ee[1]*F.canvasZoom<50?ee[1]*F.canvasZoom-50:ee[1]*F.canvasZoom>F.canvasSize.height/F.canvasSize.scaleRatioWithNoZoom-50?ee[1]*F.canvasZoom-(F.canvasSize.height/F.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/F.canvasZoom)])}if(I!==void 0)return void ae([oe[0]+F.canvasOffset[0]-I.start[0],oe[1]+F.canvasOffset[1]-I.start[1]]);if(y.mode==="preview"){const ee=G(Q)[0];if(ee?.type==="curve"){const ie=Os(ee,oe,F,!0);return void ve(ce([ie],F))}if(ee?.type==="polygon"){const ie=Bs(ee,oe,F,!0);return void ve(ce([ie],F))}}const ge=zt(oe,F);if(Je(U)||q(U,Se,oe,ge),Q===void 0||Q.locked)V({mode:"default",outOfView:!ge});else{if(y.mode==="default"||y.mode==="textedition"||y.mode==="contextMenu"){if(!ge)return void V({mode:"default"});V(Ht(Se,Q,oe,F,!0)||{mode:"default"})}else{const ee=w.current?.getContext("2d");if(!ee)return;const ie=Xn(ee,Q,oe,y,F,de,le);W(G(ie))}y.mode==="translate"&&le&&!y.hasBeenDuplicated&&(L({...y,hasBeenDuplicated:!0}),H(G(y.originalShape)))}})(k,t,u,o,M,h,B,s,b,C,c,p,f,j,z,g,x,T.current),m.useEffect(()=>{if(l){const k=U=>te.current?.(U);return document.addEventListener("mousemove",k),document.addEventListener("touchmove",k),()=>{document.removeEventListener("mousemove",k),document.removeEventListener("touchmove",k)}}},[l]);const{isBrushShapeDoneOnMouseUp:D}=f,_=m.useRef(null);_.current=k=>{if(T.current&&clearTimeout(T.current),Je(k)&&k.touches.length>1)return;const U=t.current?.getContext("2d");if(!U)return;if("button"in k&&k.button===2)return void Z(k,t.current);if(h)return void S(void 0);if(o.mode==="contextMenu"||o.mode==="textedition"||o.mode==="preview")return;const w=ct(k,t.current,f);if(o.mode==="translate"&&Date.now()-o.dateStart<=500&&w[0]===o.cursorStartPosition[0]&&w[1]===o.cursorStartPosition[1]){if(k.ctrlKey||k.shiftKey||k.metaKey){const{shape:Q}=Dt(U,n,w,f,u,Je(k),N,"remove");G(Q).length!==o.selectedShapesLengthAtMouseDown&&g(Q)}return M({mode:"default"}),v(void 0),void P()}o.mode!=="default"&&(o.mode==="brush"&&D&&g(void 0),M({mode:"default"}),v(void 0),P())},m.useEffect(()=>{if(i){const k=U=>_.current?.(U);return document.addEventListener("mouseup",k),document.addEventListener("touchend",k),()=>{document.removeEventListener("mouseup",k),document.removeEventListener("touchend",k)}}},[i]);const K=!f.features.edition&&f.features.zoom,ne=!f.features.edition&&!f.features.zoom,re=m.useRef(null);return re.current=(k,U,w)=>{if(k.preventDefault(),Je(k)&&k.touches.length>1)return;const Q=U?.getContext("2d");if(!Q)return;U.focus();const y=ct(k,t.current,f),L="button"in k&&k.button===1,I="button"in k&&k.button===2;if(L||w||r.type==="move"&&!I)S({start:y,originalOffset:f.canvasOffset});else if(!K){if(!zt(y,f))return g(void 0),void M({mode:"default"});if(I){if(r.type==="selection"){const{shape:V}=Dt(Q,n,y,f,u,Je(k),!1);g(V),M({mode:"default"})}}else if(Je(k)&&(T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{Z(k,t.current)},500)),r.type==="selection"){const V=k.ctrlKey||k.shiftKey||k.metaKey?"add":"replace",{shape:q,mode:W}=Dt(Q,n,y,f,u,Je(k),N,V);g(q),M(W),W.mode==="selectionFrame"&&v({oldSelection:q,frame:[[y[0],y[1]],[y[0],y[1]]]})}else if(ps.some(V=>V===r.type)){const V=G(u)[0],q=t.current?.getContext("2d");if(!q)return;if(r.type==="brush"){if(V?.type==="brush"){const W=((H,ae,pe)=>{const F={...H,points:We(H.points.length,[[Math.round(ae[0]),Math.round(ae[1])]],H.points)};return xt(F,pe)})(V,y,f);b([W])}else{const W=Ks(q,r,y,f);if(!W)return;e([W]),g(ce([W],f))}M({mode:"brush"})}else if(o.mode!=="preview"||V?.type!=="polygon"&&V?.type!=="curve"){if(r.type!=="picture"){const W=Ks(q,r,y,f);if(!W)return;e([W]);const H=ce([W],f);g(H),W.type==="polygon"||W.type==="curve"?M({mode:"preview"}):(a(Xe),M({mode:"resize",cursorStartPosition:[y[0]+f.selectionPadding,y[1]+f.selectionPadding],originalShape:H,anchor:W.type==="line"?0:[1,1],selectedShapesLengthAtMouseDown:G(H).length}))}}else{const W=V.type==="polygon"?Bs(V,y,f):Os(V,y,f);g(ce([W],f)),b([W],!0)}}}},m.useEffect(()=>{if(ne)return;const k=t.current;if(!k)return;const U=w=>re.current?.(w,k,R);return k.addEventListener("mousedown",U,{passive:!1}),k.addEventListener("touchstart",U,{passive:!1}),()=>{k.removeEventListener("mousedown",U),k.removeEventListener("touchstart",U)}},[ne,t,R]),m.useEffect(()=>{const k=t.current,U=t.current?.getContext("2d");if(!(!k||!U))return i?(O(k,w=>{if(r.type==="selection"){if(G(u).length!==1)return;const Q=G(u)[0];if(Q?.locked)return;if(Q?.type==="text"){const y=ct(w,t.current,f);return zt(y,f)?void(Ht(U,u,y,f)&&M({mode:"textedition",defaultValue:Q.value})):void 0}if(Q?.type==="polygon"){const y=ct(w,t.current,f);if(!zt(y,f))return;const L=As(U,Q,y,f);return void(L&&b([so(Q,L.lineIndex,y,f)]))}if(Q?.type==="curve"){const y=ct(w,t.current,f);if(!zt(y,f))return;const L=((I,V,q,W,H=50)=>{if(V.locked||V.points.length<2)return!1;if(V.points.length<3)return As(I,V,q,W,H);const{center:ae}=V.computed,pe=Ge(q,V.rotation??0,ae);I.lineWidth=(V.style?.lineWidth??0)+H/W.canvasZoom;const F=ma(V,V.points),de=new Path2D;de.moveTo(...F[0]);for(let le=1;le<F.length-2;le++){const ve=F[le-1],Ee=F[le],J=F[le+1],Se=F[le+2],{cp1:oe,cp2:ge}=Sa(ve,Ee,J,Se);if(de.bezierCurveTo(oe[0],oe[1],ge[0],ge[1],J[0],J[1]),I.isPointInStroke(de,pe[0],pe[1]))return{lineIndex:le-1}}return!1})(U,Q,y,f);return void(L&&b([oo(Q,L.lineIndex,y,f)]))}}}),()=>{X(k)}):void 0},[b,O,X,i,t,r,u,M,f]),{hoverMode:A}},vn=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>vn(t)).join(""):e.nodeValue??"",ko=({disabled:e=!1,shape:t,defaultValue:a,updateValue:s,saveShapes:n,settings:o})=>{const r=m.useRef(null),l=m.useRef(n);m.useEffect(()=>{if(!r.current)return;const h=r.current,p=g=>{g.preventDefault();const v=g.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,v)};h.addEventListener("paste",p),h.innerText="";for(const g of a){const v=document.createElement("div");g===""?v.innerHTML="<br/>":v.innerText=g,h.appendChild(v)}return h.focus(),()=>{h.removeEventListener("paste",p)}},[a]),m.useEffect(()=>{const h=l.current;return()=>{h()}},[]);const i=m.useMemo(()=>{const{borders:h,center:p}=t.computed;return fe({point:[h.x,h.y],rotation:-(t.rotation??0),origin:p})},[t]),c=[`translate3D(${(i[0]+o.canvasOffset[0])*o.canvasSize.scaleRatio}px, ${(i[1]+o.canvasOffset[1])*o.canvasSize.scaleRatio}px, 0)`,`rotate(${fa(t.rotation??0)}deg)`,t.flipX||t.flipY?`scale(${t.flipX?-1:1}, ${t.flipY?-1:1})`:void 0,t.flipX||t.flipY?`translate3D(${t.flipX?-100:0}%,${t.flipY?-100:0}%,0)`:void 0].filter(Boolean).join(" "),u=!e;return d.jsx("div",{className:"react-paint-editor-toolbox-edittextbox",ref:r,"data-fontbold":t.style?.fontBold??!1,"data-fontitalic":t.style?.fontItalic??!1,contentEditable:u,role:"textbox",tabIndex:u?0:void 0,onInput:h=>{const p=Array.from(h.target.childNodes).map(g=>vn(g));s(p)},style:{"--react-paint-editor-toolbox-edittextbox-transform":c,"--react-paint-editor-toolbox-edittextbox-fontsize":t.fontSize*o.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-padding":o.selectionPadding*o.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-color":t.style?.strokeColor??"inherit","--react-paint-editor-toolbox-edittextbox-opacity":(t.style?.opacity??100)/100,"--react-paint-editor-toolbox-edittextbox-fontfamily":t.style?.fontFamily??Vt}})},Po=(e,t,a,s,n)=>{xs(e),((o,r)=>{const{canvasZoom:l,size:i,canvasSize:{width:c,height:u}}=r;if(i!=="fixed"||l>=1)return;o.fillStyle="#f5f5f5",o.fillRect(0,0,c,u);const h=Ds(r);o.clearRect(h.x,h.y,h.width,h.height),Is(o,r)})(e,a),((o,r)=>{const{canvasSize:{width:l,height:i},gridGap:c,canvasOffset:u,canvasSize:{scaleRatio:h}}=r;if(!c)return;o.strokeStyle="rgb(220,220,220)",o.lineWidth=1,o.save(),o.scale(h,h),o.beginPath();const p=u[0]%c,g=u[1]%c,v=Math.ceil(l/h/c)+2,S=Math.ceil(i/h/c)+2;for(let b=-5;b<v;b++)o.moveTo(p+(b+1)*c,g-c),o.lineTo(p+(b+1)*c,g+i/h+c);for(let b=-5;b<S;b++)o.moveTo(p-c,g+(b+1)*c),o.lineTo(p+l/h+c,g+(b+1)*c);o.stroke(),o.restore()})(e,a);for(let o=s.length-1;o>=0;o--)t.mode==="textedition"&&s[o]===n||en(e,G(n).find(r=>r.id===s[o].id)??s[o],a)},jo=m.forwardRef(({canGrow:e,shapes:t,duplicateShapes:a,addShapes:s,updateSingleShape:n,selectedShape:o,setSelectedShape:r,setSelectionFrame:l,hoveredShape:i,selectionFrame:c,refreshHoveredShape:u,refreshSelectedShapes:h,saveShapes:p,activeTool:g,setActiveTool:v,canvasOffsetStartData:S,setCanvasOffsetStartData:b,setCanvasOffset:C,setCanvasMoveAcceleration:P,isInsideComponent:M,isInsideCanvas:x,selectionMode:f,setSelectionMode:j,selectionWidth:z,selectionColor:N,settings:E,isEditMode:R,isShiftPressed:T,isAltPressed:A,isSpacePressed:B,withFrameSelection:O,withSkeleton:X,withContextMenu:Z},te)=>{const D=m.useRef(null),_=m.useRef(null),K=E.canvasSize,ne=R,re=R?0:-1;m.useImperativeHandle(te,()=>D.current);const{hoverMode:k}=Mo({addShapes:s,drawCanvasRef:D,setActiveTool:v,shapes:t,selectionMode:f,activeTool:g,isInsideComponent:M,isInsideCanvas:x,setCanvasOffset:C,selectedShape:o,canvasOffsetStartData:S,setCanvasOffsetStartData:b,setSelectedShape:r,setSelectionFrame:l,refreshHoveredShape:u,refreshSelectedShapes:h,updateSingleShape:n,duplicateShapes:a,saveShapes:p,setSelectionMode:j,setCanvasMoveAcceleration:P,isShiftPressed:T,isAltPressed:A,withFrameSelection:O,settings:E,isSpacePressed:B,withContextMenu:Z}),U=m.useCallback(Q=>{const y=G(o)[0];if(y?.type!=="text")return;const L=D.current?.getContext("2d");if(!L)return;const I=Be(vo(L,y,Q,E),E);n([I])},[n,o,E]),w=Q=>{if(R)return Q.preventDefault(),Q.stopPropagation(),!1};return m.useEffect(()=>{const Q=D.current?.getContext("2d");Q&&window.requestAnimationFrame(()=>Po(Q,f,E,t,o))},[t,f,o,E]),m.useEffect(()=>{const Q=_.current?.getContext("2d");Q&&window.requestAnimationFrame(()=>((y,L,I,V,q,W,H,ae,pe,F,de)=>{y.reset(),Is(y,I),de&&ae&&!G(H).find(le=>le.id===ae.id)&&V.type==="selection"&&(L.mode==="default"||L.mode==="contextMenu"||L.mode==="textedition")&&on({ctx:y,shape:ae,settings:I,selectionWidth:q,selectionColor:W,hoverMode:pe,selectionMode:L,withAnchors:!1}),H&&V.type!=="brush"&&on({ctx:y,shape:H,settings:I,selectionWidth:q,selectionColor:W,hoverMode:pe,selectionMode:L,withAnchors:L.mode!=="textedition"}),F&&So({ctx:y,selectionFrame:F,settings:I})})(Q,f,E,g,z,N,o,i,k,c,X))},[i,k,c,f,o,g,E,z,N,X]),d.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":S?"grabbing":k.outOfView?"default":k.mode==="resize"?"pointer":g.type!=="selection"&&g.type!=="move"?"crosshair":k.mode==="translate"?"move":k.mode==="rotate"||g.type==="move"||B?"grab":"default"},children:d.jsxs("div",{className:"react-paint-canvas-container","data-grow":e,children:[d.jsx("canvas",{className:gs,ref:D,"data-grow":e,width:K.width,height:K.height,onContextMenu:w,tabIndex:re}),ne&&d.jsx("canvas",{className:fs,ref:_,width:K.width,height:K.height,"data-grow":e,onContextMenu:w}),R&&f.mode==="textedition"&&G(o)[0]?.type==="text"&&d.jsx(ko,{disabled:!E.features.edition,shape:G(o)[0],defaultValue:f.defaultValue,updateValue:U,saveShapes:p,settings:E})]})})}),mn="ArrowUp",Sn="ArrowDown",yn="ArrowLeft",xn="ArrowRight",Lo="Delete",Vo="Backspace",Zo="Escape",bn="Shift",wn="Alt",Qn="Option",$t=" ",Ho="A",zo="a",To="z",Ao="Z",Eo="y",Ro="Y",Do="+",Io="-",Wo="0",Cn="cut",Mn="copy",kn="paste",No=({isLoading:e=!1})=>{const[t,a]=m.useState("hidden");return m.useEffect(()=>{if(!e){a("fadeOut");const s=setTimeout(()=>a("hidden"),300);return()=>{clearTimeout(s)}}a("visible")},[e]),t==="hidden"?null:d.jsx("div",{className:"react-paint-editor-loading","data-loading":t,style:{"--react-paint-editor-loading-zindex":Wn,"--react-paint-editor-loading-transition-duration":"300ms"},children:d.jsxs("div",{className:"react-paint-editor-loader",children:[d.jsx("div",{}),d.jsx("div",{}),d.jsx("div",{}),d.jsx("div",{})]})})},Bo="infos",Fo=4e3,Oo=({type:e,text:t,duration:a})=>{const[s,n]=m.useState(!1);return m.useEffect(()=>{const o=setTimeout(()=>{n(!0)},100),r=setTimeout(()=>{n(!1)},a-500-100);return()=>{clearTimeout(o),clearTimeout(r)}},[a]),d.jsx("div",{className:"react-paint-editor-snackbar","data-is-shown":+s,"data-type":e,style:{"--react-paint-editor-panel-transition-duration":"500ms"},children:t})},Yo=({snackbarList:e})=>d.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":Nn},children:e.map(t=>d.jsx(Oo,{...t},t.id))}),Xo=m.forwardRef((e,t)=>{const{hidden:a=!1,disabled:s=!1,selected:n=!1,icon:o,children:r,className:l="",title:i,onClick:c,...u}=e,h=s?-1:0,p=m.useRef(null);return m.useImperativeHandle(t,()=>p.current),d.jsxs("label",{className:`react-paint-editor-button ${l}`,title:i,onClick:c,"data-disabled":+s,"data-selected":+n,"data-hidden":+a,tabIndex:h,onKeyDown:g=>{g.key===$t&&(g.preventDefault(),g.stopPropagation())},onKeyUp:g=>{g.preventDefault(),g.stopPropagation(),g.key===$t&&p.current?.click()},children:[d.jsx("input",{ref:p,disabled:s,...u}),d.jsxs("span",{className:"react-paint-editor-button-content",children:[r&&d.jsx("span",{className:"react-paint-editor-button-children",children:r}),o&&d.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:o}})]})]})}),$=m.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color")return d.jsx(Xo,{...e,ref:t});const{hidden:a=!1,disabled:s=!1,selected:n=!1,icon:o,children:r,type:l="button",className:i="",...c}=e;return d.jsx("button",{className:`react-paint-editor-button ${i}`,ref:t,disabled:s,"data-disabled":+s,"data-selected":+n,"data-hidden":+a,type:l,...c,children:d.jsxs("span",{className:"react-paint-editor-button-content",children:[r&&d.jsx("span",{className:"react-paint-editor-button-children",children:r}),o&&d.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:o}})]})})}),dt=({children:e,title:t="",className:a="",position:s,fitContainer:n=!1,alignment:o,style:r,...l})=>d.jsxs("div",{className:`react-paint-editor-panel ${a}`,"data-fitcontainer":n,"data-position":s??"unset","data-alignment":o??"unset",style:{...r,"--react-paint-editor-panel-zindex":_a},...l,children:[t&&d.jsx("h3",{className:"react-paint-editor-panel-title",children:t}),e]}),$o=e=>{switch(e){case"brush":return Ra;case"line":return Na;case"polygon":return ia;case"curve":return Fa;case"rect":case"square":return na;case"circle":case"ellipse":return oa;case"text":return Wa;case"picture":return ra;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""}},Uo=({disabled:e=!1,shape:t,selected:a,layoutDragging:s,toggleShapeVisibility:n,toggleShapeLock:o,setLayoutDragging:r,handleRemove:l,handleSelect:i,onSwapShapes:c})=>{const u=m.useRef(null),{isOver:h}=(({disabled:p=!1,ref:g,shape:v,layoutDragging:S,setLayoutDragging:b,handleSelect:C,onSwapShapes:P})=>{const[M,x]=m.useState(!1);return m.useEffect(()=>{S||x(!1)},[S]),m.useEffect(()=>{const f=g.current;if(!f)return;const j=()=>{b(void 0)},z=A=>(A.preventDefault&&A.preventDefault(),!1),N=A=>{C([v]),A.dataTransfer&&(A.dataTransfer.effectAllowed="move",A.dataTransfer.setData("draggableShapeId",v.id),b(v.id))},E=()=>{S!==v.id&&x(!0)},R=()=>{x(!1)},T=A=>(A.stopPropagation(),A.dataTransfer&&P(A.dataTransfer.getData("draggableShapeId"),v.id),!1);return p||(f.addEventListener("dragstart",N),f.addEventListener("dragend",j),f.addEventListener("dragover",z),f.addEventListener("dragenter",E),f.addEventListener("dragleave",R),f.addEventListener("drop",T)),()=>{p||(f.removeEventListener("dragstart",N),f.removeEventListener("dragend",j),f.removeEventListener("dragover",z),f.removeEventListener("dragenter",E),f.removeEventListener("dragleave",R),f.removeEventListener("drop",T))}},[p,g,v,b,C,P,S]),{isOver:M}})({disabled:e,ref:u,shape:t,layoutDragging:s,setLayoutDragging:r,handleSelect:i,onSwapShapes:c});return d.jsxs("div",{className:"react-paint-editor-layout","data-disabled":+e,draggable:!e,"data-is-dragging":+(s===t.id),"data-is-over":+h,onClick:p=>{e||(p.preventDefault(),i([t]))},"data-selected":+a,ref:u,tabIndex:-1,children:[d.jsx("span",{dangerouslySetInnerHTML:{__html:$o(t.type)}}),d.jsx("span",{children:t.id}),d.jsx("div",{className:"react-paint-editor-layouts-separator"}),d.jsx($,{className:"react-paint-editor-layouts-visible-button",title:t.visible?"Hide":"Show","data-visible":t.visible!==!1,disabled:e,selected:a,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),n([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>'}),d.jsx($,{className:"react-paint-editor-layouts-locked-button",title:t.locked?"Locked":"Unlocked","data-locked":!!t.locked,disabled:e,selected:a,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),o([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>'}),d.jsx($,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),l([t]))},icon:Da})]})},qo=({gridFormat:e,setGridFormat:t,settings:a,shapes:s,removeShape:n,toggleShapeVisibility:o,toggleShapeLock:r,selectedShapes:l,swapShapes:i,selectShapes:c,isLayoutPanelShown:u})=>{const[h,p]=m.useState(void 0),g=!a.features.edition;return u?d.jsx(dt,{alignment:"right",className:"react-paint-editor-layouts-panel",position:"bottom",children:d.jsx("div",{className:"react-paint-editor-layouts-panel-content",children:d.jsxs("div",{className:"react-paint-editor-layouts-scrolling-content",children:[d.jsxs("div",{className:"react-paint-editor-layouts-row",children:[d.jsx("span",{className:"react-paint-editor-layouts-subtitle",children:"Grid"}),d.jsx($,{icon:'<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>',className:"react-paint-editor-layouts-grid-button",selected:e==="none",disabled:g,onClick:()=>t("none")}),["small","medium","large"].map(v=>d.jsx($,{className:"react-paint-editor-layouts-grid-button",selected:e===v,disabled:g,onClick:()=>t(v),children:v.charAt(0).toUpperCase()},v))]}),d.jsx("hr",{}),d.jsx("div",{className:"react-paint-editor-layouts",children:s.length===0?d.jsx("div",{className:"react-paint-editor-layouts-placeholder",children:"No layer yet"}):s.map(v=>d.jsx(Uo,{shape:v,disabled:g,layoutDragging:h,setLayoutDragging:p,selected:G(l).some(S=>S.id===v.id)??!1,handleSelect:c,handleRemove:n,onSwapShapes:i,toggleShapeVisibility:o,toggleShapeLock:r},v.id))})]})})}):null},Ut=({children:e,onClose:t,position:a="center",title:s,className:n=""})=>d.jsxs("div",{className:"react-paint-editor-modal","data-position":a,style:{"--react-paint-editor-modal-zindex":_a},role:"dialog","aria-modal":"true","aria-labelledby":s,children:[d.jsx("div",{className:"react-paint-editor-modal-mask",onClick:t}),d.jsx("div",{className:`react-paint-editor-modal-panel ${n}`,children:e})]}),qt=({selectedSettings:e,setSelectedSettings:t,title:a="Choisissez une couleur",mode:s="fill",disabled:n=!1,values:o,field:r,value:l="",valueChanged:i})=>{const[c]=m.useState(be("settings_")),u=e===c;return o.length?d.jsxs(d.Fragment,{children:[d.jsx($,{selected:u,title:a,disabled:n,onClick:()=>{t(h=>h===c?void 0:c)},icon:l==="transparent"?s==="fill"?Ua:$a:void 0,children:l!=="transparent"&&d.jsx("div",{className:"react-paint-editor-colorfield-color","data-mode":s,style:{"--react-paint-editor-colorfield-color-value":l}})}),u&&d.jsx(dt,{title:a,alignment:"left",position:"bottom",children:d.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[o.map(h=>d.jsx($,{title:h,selected:h===l,color:h,icon:h==="transparent"?s==="fill"?Ua:$a:void 0,onClick:()=>{i(r,h)},children:h!=="transparent"&&d.jsx("div",{className:"react-paint-editor-colorfield-color",color:h,"data-mode":s,style:{"--react-paint-editor-colorfield-color-value":h}})},h)),d.jsx($,{type:"color",title:"Custom color",selected:l!==""&&!o.includes(l),value:l,onChange:h=>{const p=+h.target.value;i(r,Number.isNaN(p)?h.target.value:p)},children:d.jsx("div",{className:"react-paint-editor-colorfield-customcolor",style:{"--react-paint-editor-colorfield-color-value":o.includes(l)?"var(--react-paint-editor-app-font-color)":l},children:d.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},Go=({disabled:e=!1,selectedShape:t,removeShape:a})=>d.jsx($,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{a(G(t))},icon:Da}),Gt=({CustomOption:e,selectedSettings:t,setSelectedSettings:a,title:s="Choisissez l'option",disabled:n=!1,field:o,icon:r,values:l,defaultValue:i,valueChanged:c})=>{const[u]=m.useState(be("settings_")),h=t===u;return l.length?d.jsxs(d.Fragment,{children:[d.jsx($,{selected:h,title:s,icon:r,disabled:n,onClick:()=>{a(p=>p===u?void 0:u)}}),h&&d.jsx(dt,{title:s,alignment:"left",fitContainer:!0,position:"bottom",children:d.jsx("div",{className:"react-paint-editor-selectfield-wrapper",children:l.map(p=>d.jsx($,{title:`${p}`,onClick:()=>(g=>{c(o,g)})(p),selected:i===p,style:{"--react-paint-editor-button-padding":"16px"},children:d.jsx(e,{children:p})},p))})})]}):null},_o=({children:e})=>d.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),Pn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:_o,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:a,field:"fontFamily",values:s,defaultValue:n,valueChanged:o}):null,Ko=({disabled:e,toggleLayoutPanel:t})=>d.jsx($,{title:"Toggle layers panel",disabled:e,onClick:t,icon:'<svg><path d="M10 17.646 2.438 11.75 3.875 10.646 10 15.396 16.125 10.646 17.562 11.75ZM10 13.188 2.5 7.354 10 1.521 17.5 7.354Z"/></svg>',className:"react-paint-editor-layout-button"}),Jo=({children:e})=>d.jsxs("span",{className:"react-paint-editor-linearrow-option","data-type":e,children:[d.jsx("span",{className:"react-paint-editor-linearrow-left"}),d.jsx("span",{className:"react-paint-editor-linearrow-right"})]}),jn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Jo,title:"Flèches",icon:'<svg><path d="M6 17 2 13 6 9 7.062 10.062 4.875 12.25H17V13.75H4.875L7.062 15.938ZM14 11 12.938 9.938 15.125 7.75H3V6.25H15.125L12.938 4.062L14 3L18 7Z"/></svg>',disabled:a,field:"lineArrow",values:s,defaultValue:n,valueChanged:o}):null,ei=({children:e})=>d.jsxs("span",{className:"react-paint-editor-linetype-option","data-type":e,children:[d.jsx("span",{}),d.jsx("span",{}),d.jsx("span",{}),d.jsx("span",{}),d.jsx("span",{}),d.jsx("span",{}),d.jsx("span",{})]}),Ln=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ei,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:a,field:"lineDash",values:s,defaultValue:n,valueChanged:o}):null,_t=({selectedSettings:e,setSelectedSettings:t,title:a="Choisissez l'intervalle",icon:s,disabled:n=!1,field:o,value:r,min:l=1,max:i=20,step:c=1,unity:u="",valueChanged:h,saveShapes:p})=>{const g=r===void 0,v=g?"N/A":`${Math.round(r)}${u}`,[S]=m.useState(be("settings_")),b=((P,M=500)=>{const x=m.useRef(null),f=m.useCallback((...j)=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>P(...j),M)},[P,M]);return m.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),f})(p),C=e===S;return l===i?null:d.jsxs(d.Fragment,{children:[d.jsx($,{selected:C,title:a,disabled:n,icon:s,onClick:()=>{t(P=>P===S?void 0:S)}}),C&&d.jsx(dt,{title:a,alignment:"left",fitContainer:!0,position:"bottom",children:d.jsx("div",{children:d.jsxs("label",{className:"react-paint-editor-rangefield",children:[d.jsx("input",{type:"range",min:l,max:i,step:c,value:r??(i+l)/2,"data-indeterminate":+g,onChange:P=>{const M=+P.target.value,x=Number.isNaN(M)?P.target.value:M;h(o,x,!1),b()}}),d.jsx("span",{children:v})]})})})]})},ti=({children:e})=>d.jsx("span",{children:e===0?"Non":"Oui"}),ai=[0,1],Vn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,defaultValue:s,valueChanged:n})=>d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ti,title:"Fermer les points",icon:ia,disabled:a,field:"closedPoints",values:ai,defaultValue:s,valueChanged:n}),si=({disabled:e=!1,className:t,toggleZoomPanel:a})=>d.jsx($,{title:"Toggle zoom panel",disabled:e,onClick:a,icon:qa,className:t?` ${t}`:""}),Kt=({setSelectedSettings:e,disabled:t=!1,field:a,icon:s,values:n,value:o=!1,valueChanged:r})=>{const[l]=m.useState(be("settings_"));return n.length!==2?null:d.jsx($,{onClick:()=>{e(i=>i===l?void 0:l),r(a,!o)},selected:o,disabled:t,icon:s})},za=({activeTool:e,selectedShape:t,selectedShapeTool:a,disabled:s,selectedSettings:n,setSelectedSettings:o,saveShapes:r,handleShapeStyleChange:l,handleShapeFontFamilyChange:i})=>t?a&&d.jsxs(d.Fragment,{children:["strokeColor"in a.settings&&!a.settings.strokeColor.hidden&&d.jsx(qt,{selectedSettings:n,setSelectedSettings:o,title:"Couleur du trait",mode:"stroke",disabled:s,field:"strokeColor",value:t.style?.strokeColor,valueChanged:l,values:a.settings.strokeColor.values}),"fillColor"in a.settings&&!a.settings.fillColor.hidden&&d.jsx(qt,{selectedSettings:n,setSelectedSettings:o,title:"Couleur de fond",disabled:s,field:"fillColor",value:t.style?.fillColor,valueChanged:l,values:a.settings.fillColor.values}),"lineWidth"in a.settings&&!a.settings.lineWidth.hidden&&d.jsx(_t,{saveShapes:r,selectedSettings:n,setSelectedSettings:o,title:"Epaisseur du trait",icon:Xa,disabled:s,field:"lineWidth",value:t.style?.lineWidth,valueChanged:l,unity:"px",min:a.settings.lineWidth.min,max:a.settings.lineWidth.max,step:a.settings.lineWidth.step}),"lineDash"in a.settings&&!a.settings.lineDash.hidden&&d.jsx(Ln,{selectedSettings:n,setSelectedSettings:o,disabled:s,defaultValue:t.style?.lineDash,valueChanged:l,values:a.settings.lineDash.values}),"lineArrow"in a.settings&&!a.settings.lineArrow.hidden&&d.jsx(jn,{selectedSettings:n,setSelectedSettings:o,disabled:s,defaultValue:t.style?.lineArrow,valueChanged:l,values:a.settings.lineArrow.values}),"closedPoints"in a.settings&&!a.settings.closedPoints.hidden&&d.jsx(Vn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:l,defaultValue:t.style?.closedPoints}),"fontFamily"in a.settings&&!a.settings.fontFamily.hidden&&d.jsx(Pn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:i,values:a.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),"fontBold"in a.settings&&!a.settings.fontBold.hidden&&d.jsx(Kt,{setSelectedSettings:o,disabled:s,field:"fontBold",icon:Oa,valueChanged:i,values:a.settings.fontBold.values,value:t.style?.fontBold}),"fontItalic"in a.settings&&!a.settings.fontItalic.hidden&&d.jsx(Kt,{setSelectedSettings:o,disabled:s,field:"fontItalic",icon:Ya,valueChanged:i,values:a.settings.fontItalic.values,value:t.style?.fontItalic}),"opacity"in a.settings&&!a.settings.opacity.hidden&&d.jsx(_t,{saveShapes:r,selectedSettings:n,setSelectedSettings:o,title:"Opacité",icon:Ia,min:a.settings.opacity.min,max:a.settings.opacity.max,step:a.settings.opacity.step,unity:"%",disabled:s,field:"opacity",value:t.style?.opacity,valueChanged:l})]}):"settings"in e?d.jsxs(d.Fragment,{children:["strokeColor"in e.settings&&!e.settings.strokeColor.hidden&&d.jsx(qt,{selectedSettings:n,setSelectedSettings:o,title:"Couleur du trait",mode:"stroke",disabled:s,field:"strokeColor",value:e.settings.strokeColor.default,valueChanged:l,values:e.settings.strokeColor.values}),"fillColor"in e.settings&&!e.settings.fillColor.hidden&&d.jsx(qt,{selectedSettings:n,setSelectedSettings:o,title:"Couleur de fond",disabled:s,field:"fillColor",value:e.settings.fillColor.default,valueChanged:l,values:e.settings.fillColor.values}),"lineWidth"in e.settings&&!e.settings.lineWidth.hidden&&d.jsx(_t,{saveShapes:r,selectedSettings:n,setSelectedSettings:o,title:"Epaisseur du trait",disabled:s,field:"lineWidth",icon:Xa,value:e.settings.lineWidth.default,valueChanged:l,unity:"px",min:e.settings.lineWidth.min,max:e.settings.lineWidth.max,step:e.settings.lineWidth.step}),"lineDash"in e.settings&&!e.settings.lineDash.hidden&&d.jsx(Ln,{selectedSettings:n,setSelectedSettings:o,disabled:s,defaultValue:e.settings.lineDash.default,valueChanged:l,values:e.settings.lineDash.values}),"lineArrow"in e.settings&&!e.settings.lineArrow.hidden&&d.jsx(jn,{selectedSettings:n,setSelectedSettings:o,disabled:s,defaultValue:e.settings.lineArrow.default,valueChanged:l,values:e.settings.lineArrow.values}),"closedPoints"in e.settings&&!e.settings.closedPoints.hidden&&d.jsx(Vn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:l,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&d.jsx(Pn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:i,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),"fontBold"in e.settings&&!e.settings.fontBold.hidden&&d.jsx(Kt,{setSelectedSettings:o,disabled:s,field:"fontBold",icon:Oa,valueChanged:i,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),"fontItalic"in e.settings&&!e.settings.fontItalic.hidden&&d.jsx(Kt,{setSelectedSettings:o,disabled:s,field:"fontItalic",icon:Ya,valueChanged:i,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),"opacity"in e.settings&&!e.settings.opacity.hidden&&d.jsx(_t,{saveShapes:r,selectedSettings:n,setSelectedSettings:o,title:"Opacité",icon:Ia,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:l})]}):null,ni=({width:e,availableTools:t,updateToolSettings:a,layersManipulation:s=!1,toggleLayoutPanel:n,activeTool:o,saveShapes:r,selectedShape:l,canvas:i,settings:c,updateShape:u,removeShape:h,isZoomPanelShown:p,setIsZoomPanelShown:g})=>{const[v,S]=m.useState(void 0),[b,C]=m.useState(!1),P=c.size==="infinite"||c.features.zoom,M=!c.features.edition,x=()=>{C(R=>!R)},f=((R,T)=>{const A=G(R).map(O=>T.find(X=>X.id===O?.toolId)||T.find(X=>X.type===O?.type)).filter(O=>O!==void 0);if(!A.length)return;if(A.length===1)return A[0];const B=A.slice(1).reduce((O,X)=>{const Z={};for(const te in X.settings){if(O[te]===void 0||X.settings[te]?.hidden||O[te]?.hidden)continue;const D=O[te],_=X.settings[te],K={};"min"in _&&"min"in D&&_.min===D.min&&"max"in _&&"max"in D&&_.max===D.max&&"step"in _&&"step"in D&&_.step===D.step&&(K.min=_.min,K.max=_.max,K.step=_.step),"values"in _&&"values"in D&&_.values?.join(",")===D.values?.join(",")&&(K.values=_.values),(Object.keys(K).length>0||te==="closedPoints")&&(Z[te]=K)}return Z},A[0].settings);return{id:A.map(O=>O.id).join("-"),icon:"",label:"group",type:"group",settings:B}})(l,t),j=(f?Object.keys(f.settings).length+1:"settings"in o?Object.keys(o.settings).length:0)+ +s+ +P,z=e<40*j,N=(R,T,A=!0)=>{if(G(l).length){const B=G(l).map(O=>Be(We(["style",R],T,O),c));u(B,A),f&&a(f.id,R,T)}else a(o.id,R,T)},E=(R,T)=>{if(G(l).length){const A=G(l).map(B=>{if(B.type!=="text")return B;const O=i?.getContext("2d");if(!O)return B;const X=We(["style",R],T,B),Z=Xt(O,X.value,X.width,X.style?.fontBold??!1,X.style?.fontItalic??!1,X.style?.fontFamily);return Be({...X,fontSize:Z,height:Z*X.value.length},c)});u(A,!0),f&&a(f.id,R,T)}else a(o.id,R,T)};return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"react-paint-editor-settings-bar",children:[d.jsxs("div",{className:"react-paint-editor-settings-shrinkable",children:[P&&d.jsx(si,{className:p?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{g(R=>!R)}}),z&&j>2&&d.jsx($,{disabled:M,onClick:x,title:"Toggle settings",icon:'<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>'}),l?f&&d.jsxs(d.Fragment,{children:[!z&&d.jsx(za,{saveShapes:r,activeTool:o,selectedShape:l,selectedShapeTool:f,disabled:M,selectedSettings:v,setSelectedSettings:S,handleShapeStyleChange:N,handleShapeFontFamilyChange:E}),o.type==="selection"&&d.jsx(Go,{disabled:M,selectedShape:l,removeShape:h})]}):!z&&d.jsx(za,{saveShapes:r,activeTool:o,selectedShape:l,selectedShapeTool:f,disabled:M,selectedSettings:v,setSelectedSettings:S,handleShapeStyleChange:N,handleShapeFontFamilyChange:E})]}),d.jsx("div",{className:"react-paint-editor-settings-separator"}),s&&d.jsx(Ko,{disabled:M,toggleLayoutPanel:n})]}),b&&d.jsx(Ut,{className:"react-paint-editor-settings-modal",onClose:x,position:"bottom",title:"Settings",children:d.jsx(za,{saveShapes:r,activeTool:o,selectedShape:l,selectedShapeTool:f,disabled:M,selectedSettings:v,setSelectedSettings:S,handleShapeStyleChange:N,handleShapeFontFamilyChange:E})})]})},Jt=({alignment:e,children:t,className:a,style:s,position:n})=>d.jsx(dt,{alignment:e,position:n,className:a,style:s,children:d.jsx("div",{className:"react-paint-editor-menu",role:"menu",children:t})}),Zn=({disabled:e=!1,withText:t=!1,loadFile:a,type:s,img:n,accept:o})=>{const r=m.useRef(null);return d.jsx($,{ref:r,type:"file",onClick:()=>{r.current&&(r.current.value="")},onChange:l=>{const i=l.target.files?.item(0);i&&a(i)},accept:o,title:s.label??s.type,icon:n,disabled:e,children:t?s.label:void 0})},Ae=({type:e,img:t,isActive:a,withText:s=!1,disabled:n=!1,setActive:o})=>d.jsx($,{disabled:n,selected:a,onClick:()=>{o(e)},title:e.label??e.type,icon:t,children:s?e.label:void 0}),Hn=(e,t)=>!!(e.target instanceof Node&&t)&&t.contains(e.target),Ta=({trigger:e="click",buttonElt:t})=>{const[a,s]=m.useState(!1),[,n]=m.useTransition(),o=m.useCallback(()=>{n(()=>{s(!1)})},[]);return m.useEffect(()=>{if(!t)return;if(a){const l=c=>{Hn(c,t)||n(()=>{s(!1)})},i=()=>{n(()=>{s(!1)})};return e==="hover"?(t.addEventListener("mouseleave",i),()=>{t.removeEventListener("mouseleave",i)}):(document.addEventListener("click",l),()=>{document.removeEventListener("click",l)})}const r=()=>{n(()=>{s(!0)})};return e==="hover"?(t.addEventListener("mouseenter",r),()=>{t.removeEventListener("mouseenter",r)}):(t.addEventListener("click",r),()=>{t.removeEventListener("click",r)})},[t,a,e]),{isOpen:a,trigger:e,closeMenu:o}},oi=({activeTool:e,withActionsInMenu:t,hasActionToUndo:a=!1,hasActionToRedo:s=!1,hasActionToClear:n=!1,undoAction:o,redoAction:r,clearCanvas:l,disabled:i=!1,withLoadAndSave:c,withExport:u,addPicture:h,loadFile:p,togglePictureUrlModal:g,saveFile:v,toggleExportModal:S,withUploadPicture:b,withUrlPicture:C})=>{const P=m.useRef(null),{isOpen:M,closeMenu:x}=Ta({buttonElt:P.current}),f=j=>async(...z)=>{await j(...z),x()};return t||b||C||c||u?d.jsx("div",{className:"react-paint-editor-toolbox-relative",children:d.jsxs("div",{ref:P,children:[d.jsx($,{title:"Menu",disabled:i,icon:'<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>'}),M&&d.jsxs(Jt,{alignment:"right",position:"top",children:[t&&d.jsxs(d.Fragment,{children:[d.jsx(Ae,{withText:!0,type:vt,disabled:i||!a,img:vt.icon,isActive:e.id===vt.id,setActive:f(o)}),d.jsx(Ae,{withText:!0,type:mt,disabled:i||!s,img:mt.icon,isActive:e.id===mt.id,setActive:f(r)}),d.jsx(Ae,{withText:!0,type:St,disabled:i||!n,img:St.icon,isActive:e.id===St.id,setActive:f(l)}),(b||C||c)&&d.jsx("hr",{})]}),b&&d.jsx(Zn,{withText:!0,type:cs,disabled:i,loadFile:f(h),img:cs.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),C&&d.jsx($,{disabled:i,selected:!1,onClick:f(g),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"}),(b||C)&&c&&d.jsx("hr",{}),c&&d.jsxs(d.Fragment,{children:[d.jsx(Zn,{withText:!0,type:ls,disabled:i,loadFile:f(p),img:ls.icon,accept:"application/JSON"}),d.jsx(Ae,{withText:!0,disabled:i,type:da,img:da.icon,isActive:e.id===da.id,setActive:f(v)})]}),u&&d.jsx(Ae,{withText:!0,disabled:i,type:ca,img:ca.icon,isActive:e.id===ca.id,setActive:f(S)})]})]})}):null},ii=({togglePictureUrlModal:e,addPicture:t})=>{const a=m.useRef(null);return m.useEffect(()=>{a.current&&a.current.focus()},[]),d.jsx(Ut,{className:"react-paint-editor-toolbox-pictureinput-modal",onClose:e,title:"Add picture from URL",children:d.jsxs("form",{onSubmit:async s=>{s.preventDefault();const n=a.current?.value;n&&(await t(n),e())},children:[d.jsxs("label",{children:["URL ",d.jsx("input",{type:"text",ref:a})]}),d.jsx($,{onClick:e,children:"Annuler"}),d.jsx($,{type:"submit",selected:!0,children:"Ajouter"})]})})},zn="Choose export settings",ri=({toggleExportModal:e,exportCanvasInFile:t})=>{const a=async s=>{t(s),e()};return d.jsxs(Ut,{className:"react-paint-editor-toolbox-export-modal",onClose:e,title:zn,children:[d.jsx("h3",{children:zn}),d.jsx("hr",{}),d.jsx($,{onClick:()=>a("currentZoom"),children:"Exporter la vue actuelle"}),d.jsx($,{onClick:()=>a("defaultView"),children:"Exporter le canevas par défaut"}),d.jsx($,{onClick:()=>a("fitToShapes"),children:"Exporter le dessin entier"}),d.jsx($,{selected:!0,onClick:e,children:"Annuler"})]})},li=({activeTool:e,group:t,disabled:a=!1,setActiveToolFromId:s})=>{const n=m.useRef(null),[o,r]=m.useState(!1),[,l]=m.useTransition(),[i,c]=m.useState(void 0),u=g=>{c(g),s(g.id)};if(m.useEffect(()=>{if(!o)return;const g=v=>{!Hn(v,n.current)&&r(!1)};return document.addEventListener("mousedown",g,{passive:!1}),document.addEventListener("touchstart",g,{passive:!1}),()=>{document.removeEventListener("mousedown",g),document.removeEventListener("touchstart",g)}},[o]),"type"in t)return d.jsx(Ae,{disabled:a,type:t,img:t.icon,isActive:e.id===t.id,setActive:u});if(!t.toolsType.length)return null;if(t.toolsType?.length===1)return d.jsx(Ae,{disabled:a,type:t.toolsType[0],img:t.toolsType[0].icon,isActive:e.id===t.toolsType[0].id,setActive:u});const h=t?.toolsType.find(g=>g.type===e.type)!==void 0,p=(i?i.icon:t.toolsType?.[0]?.icon)??t.title;return d.jsxs("div",{className:"react-paint-editor-toolbargroup-relative",children:[d.jsx($,{selected:h,title:t.title,disabled:a,onClick:()=>{i?s(i.id):t.toolsType?.[0]&&u(t.toolsType[0]),l(()=>{r(!0)})},icon:p}),o&&d.jsx(dt,{alignment:"center",position:"top",children:d.jsx("div",{className:"react-paint-editor-toolbargroup-panel-content","data-vertical":+t.vertical,ref:n,children:t.toolsType.map(g=>d.jsx(Ae,{disabled:a,type:g,img:g.icon,isActive:e.id===g.id,setActive:u},g.id))})})]})},ci=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],di=({settings:e,width:t,activeTool:a,hasActionToUndo:s=!1,hasActionToRedo:n=!1,hasActionToClear:o=!1,withLoadAndSave:r,withExport:l,clearCanvas:i,setActiveTool:c,undoAction:u,redoAction:h,addPicture:p,loadFile:g,saveFile:v,exportCanvasInFile:S,availableTools:b,withUrlPicture:C,withUploadPicture:P})=>{const M=((D,_)=>{const K=_.flatMap(ne=>{if(typeof ne!="object")return D.filter(k=>k.type===ne);const re=D.filter(k=>ne.toolsType.includes(k.type));return re?{...ne,toolsType:re}:null});return La(K)})(b,ci),x=!e.features.edition,f=t<40*(6+M.length),j=t<40*(3+M.length),[z,N]=m.useState(!1),[E,R]=m.useState(!1),[T,A]=m.useState(!1),B=()=>{N(D=>!D)},O=()=>{A(D=>!D)},X=D=>{c(D),N(!1)},Z=D=>{X(b.find(_=>_.id===D)??a)},te=b.find(D=>D.type===a.type)!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"react-paint-editor-toolbar-toolbox",style:{"--react-paint-editor-toolbar-minwidth":"160px"},children:[d.jsxs("div",{className:"react-paint-editor-toolbar-shrinkable",children:[d.jsx(Ae,{type:Xe,disabled:x,img:Xe.icon,isActive:a.id===Xe.id,setActive:X}),(e.size==="infinite"||e.features.zoom)&&d.jsx(Ae,{type:ha,disabled:x,img:ha.icon,isActive:a.id===ha.id,setActive:X}),j?d.jsx($,{disabled:x,onClick:B,title:"Toggle tools",icon:'<svg><path d="M5.333 9.292 10.021 1.646 14.708 9.292ZM14.562 18.333Q13 18.333 11.896 17.229Q10.792 16.125 10.792 14.562Q10.792 13 11.896 11.896Q13 10.792 14.562 10.792Q16.125 10.792 17.229 11.896Q18.333 13 18.333 14.562Q18.333 16.125 17.229 17.229Q16.125 18.333 14.562 18.333ZM2.5 17.917V11.188H9.229V17.917ZM14.562 16.583Q15.438 16.583 16.01 16.01Q16.583 15.438 16.583 14.562Q16.583 13.688 16.01 13.115Q15.438 12.542 14.562 12.542Q13.688 12.542 13.115 13.115Q12.542 13.688 12.542 14.562Q12.542 15.438 13.115 16.01Q13.688 16.583 14.562 16.583ZM4.25 16.167H7.479V12.938H4.25ZM8.458 7.542H11.583L10.021 5ZM10.021 7.542ZM7.479 12.938ZM14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Q14.562 14.562 14.562 14.562Z"/></svg>',selected:te}):M.map(D=>d.jsx(li,{disabled:x,activeTool:a,group:D,setActiveToolFromId:Z},"id"in D?D.id:D.title))]}),!f&&d.jsxs(d.Fragment,{children:[d.jsx(Ae,{type:vt,disabled:x||!s,img:vt.icon,isActive:a.id===vt.id,setActive:u}),d.jsx(Ae,{type:mt,disabled:x||!n,img:mt.icon,isActive:a.id===mt.id,setActive:h}),d.jsx(Ae,{type:St,disabled:x||!o,img:St.icon,isActive:a.id===St.id,setActive:i})]}),d.jsx(oi,{withActionsInMenu:f,disabled:x,activeTool:a,addPicture:p,loadFile:g,saveFile:v,togglePictureUrlModal:()=>{R(!0)},toggleExportModal:O,withUploadPicture:P,withUrlPicture:C,withLoadAndSave:r,withExport:l,hasActionToUndo:s,hasActionToRedo:n,hasActionToClear:o,undoAction:u,redoAction:h,clearCanvas:i})]}),z&&d.jsx(Ut,{className:"react-paint-editor-toolbar-modal",onClose:B,title:"Outils",children:b.map(D=>D.type==="picture"?null:d.jsx(Ae,{disabled:x,type:D,img:D.icon,withText:!1,isActive:a.id===D.id,setActive:X},D.id))}),E&&d.jsx(ii,{togglePictureUrlModal:()=>{R(D=>!D)},addPicture:p}),T&&d.jsx(ri,{toggleExportModal:O,exportCanvasInFile:S})]})},ea={none:0,small:10,medium:20,large:40},hi={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},ui=()=>{const e=m.useRef([]),[t,a]=m.useState([]);return m.useEffect(()=>()=>{for(const s of e.current)clearTimeout(s)},[]),{snackbarList:t,addSnackbar:({type:s=Bo,duration:n=Fo,text:o})=>{const r={id:be("snackbar_"),duration:n,type:s,text:o};a(l=>[...l,r]),e.current=[...e.current,setTimeout(()=>{return l=r.id,void a(i=>i.filter(c=>c.id!==l));var l},n)]}}},pi=({moveShapes:e,selectAllShapes:t,selectionMode:a,transformShape:s,settings:n,canvasRef:o,closeContextMenu:r,toggleShapeVisibility:l,toggleShapeLock:i,removeShape:c,duplicateShapes:u,copiedShape:h,setCopiedShape:p,pasteShapes:g,removeShapePoint:v})=>{const S=m.useRef(null),b=m.useRef(null),{isOpen:C}=Ta({trigger:"hover",buttonElt:S.current}),{isOpen:P}=Ta({trigger:"hover",buttonElt:b.current}),{originalShape:M,cursorStartPosition:x,anchor:f}=a,j=G(M),z=j.length>0,N=j.length===1&&(j[0]?.type==="polygon"||j[0]?.type==="curve")&&f!==void 0&&j[0]?.points?.length>2,E=!j.some(Z=>Z.visible===!1),R=j.some(Z=>Z.locked),T=16+36*(2+(z?8:0)+(N?1:0))+16*(z?3:1),[A]=m.useState(()=>[(x[0]+n.canvasOffset[0])*n.canvasSize.scaleRatio,36+(x[1]+n.canvasOffset[1])*n.canvasSize.scaleRatio]),[B,O]=m.useState();m.useEffect(()=>{const Z=o?.current?.getBoundingClientRect();if(!Z)return;const te=Z.left+A[0],D=Z.top+A[1],_=Math.max(0,Math.min(te,window.innerWidth-176))-Z.left,K=Math.max(0,Math.min(D,window.innerHeight-T))-Z.top,ne=_>window.innerWidth-176-Math.min(_,200)?"left":"right";O({x:_,y:K,subMenuPosition:ne})},[o,A,T]);const X=B?{"--react-paint-editor-toolbox-contextmenu-transform":`translate3D(${B.x}px, ${B.y}px, 0)`}:{display:"none"};return d.jsxs(Jt,{className:"react-paint-editor-toolbox-contextmenu",style:X,children:[z&&d.jsxs(d.Fragment,{children:[N&&d.jsx($,{onClick:()=>{N&&v(j[0],f),r()},children:"Delete point"}),d.jsxs("div",{className:"react-paint-editor-toolbox-contextmenu-group",ref:S,children:[d.jsx($,{icon:Ba,children:"Organize"}),C&&d.jsxs(Jt,{position:B?.subMenuPosition,children:[d.jsx($,{onClick:()=>{z&&e(j,"forward"),r()},children:"Move forward"}),d.jsx($,{onClick:()=>{z&&e(j,"first"),r()},children:"Put on first"}),d.jsx($,{onClick:()=>{z&&e(j,"backward"),r()},children:"Move backward"}),d.jsx($,{onClick:()=>{z&&e(j,"last"),r()},children:"Put on last"})]})]}),d.jsxs("div",{className:"react-paint-editor-toolbox-contextmenu-group",ref:b,children:[d.jsx($,{icon:Ba,children:"Transform"}),P&&d.jsxs(Jt,{position:B?.subMenuPosition,children:[d.jsx($,{onClick:()=>{const Z=o?.current?.getContext("2d");Z&&z&&s(Z,j,M.computed.center,"flipHorizontally"),r()},children:"Flip horizontally"}),d.jsx($,{onClick:()=>{const Z=o?.current?.getContext("2d");Z&&z&&s(Z,j,M.computed.center,"flipVertically"),r()},children:"Flip vertically"}),d.jsx($,{onClick:()=>{const Z=o?.current?.getContext("2d");Z&&z&&s(Z,j,M.computed.center,"rotateClockwise"),r()},children:"Rotate clockwise"}),d.jsx($,{onClick:()=>{const Z=o?.current?.getContext("2d");Z&&z&&s(Z,j,M.computed.center,"rotateCounterclockwise"),r()},children:"Rotate counterclockwise"})]})]}),d.jsx("hr",{}),d.jsx($,{onClick:()=>{z&&(p(ce(j,n)),c(j)),r()},children:"Cut"}),d.jsx($,{onClick:()=>{z&&p(ce(j,n)),r()},children:"Copy"})]}),d.jsx($,{onClick:()=>{h&&g(ja(h,n)),r()},disabled:!h,children:"Paste"}),d.jsx("hr",{}),z&&d.jsxs(d.Fragment,{children:[d.jsx($,{onClick:()=>{z&&u(j,!0,!0),r()},children:"Duplicate"}),d.jsx($,{onClick:()=>{z&&l(j.filter(Z=>E?Z.visible!==!1:Z.visible===!1)),r()},children:E?"Hide":"Show"}),d.jsx($,{onClick:()=>{z&&i(j.filter(Z=>R?Z.locked:!Z.locked)),r()},children:R?"Unlock":"Lock"}),d.jsx($,{onClick:()=>{z&&c(j),r()},children:"Delete"}),d.jsx("hr",{})]}),d.jsx($,{onClick:()=>{t(),r()},children:"Select all"})]})};Ke.Canvas=({options:e,className:t,style:a,canvasProps:s})=>{const{shapesRef:n,selectedShape:o,selectionFrame:r,hoveredShape:l,addShape:i,setSelectedShape:c,selectAllShapes:u,setSelectionFrame:h,refreshSelectedShapes:p,refreshHoveredShape:g,duplicateShapes:v,removeShape:S,updateShape:b,backwardShape:C,forwardShape:P,saveShapes:M,refs:x,width:f,height:j,settings:z,setCanvasSize:N,setCanvasOffset:E,pasteShapes:R,activeTool:T,setActiveTool:A,isInsideComponent:B,isInsideCanvas:O,isEditMode:X,canvas:{withSkeleton:Z,withFrameSelection:te,withContextMenu:D,canGrow:_,canShrink:K},canvasOffsetStartData:ne,setCanvasOffsetStartData:re,selectionMode:k,setSelectionMode:U,setCanvasMoveAcceleration:w,isShiftPressed:Q,isAltPressed:y,isSpacePressed:L,copiedShape:I,setCopiedShape:V,setShiftPressed:q,setAltPressed:W,setCanvasZoom:H,resetZoom:ae,setIsSpacePressed:pe}=s,{canvasBackgroundColor:F,canvasSelectionColor:de,canvasSelectionWidth:le}={...On,...e},ve=m.useRef(null),Ee=m.useCallback(J=>{N({realWidth:f,realHeight:j,width:J,height:j*J/f,scaleRatio:J/f})},[f,j,N]);return(({isInsideComponent:J,isInsideCanvas:Se,selectedShape:oe,isEditingText:ge,settings:ee,copiedShape:ie,setCopiedShape:he,setSelectedShape:Me,setActiveTool:De,setCanvasZoom:Re,resetZoom:we,setSelectionMode:Ie,setSelectionFrame:Ct,selectAllShapes:Mt,removeShape:ht,pasteShapes:Fe,updateShapes:kt,backwardShape:Pt,forwardShape:Ze,setShiftPressed:at,setAltPressed:st,setIsSpacePressed:_e})=>{m.useEffect(()=>{const ut=Y=>{oe&&(ge||(Y.preventDefault(),he({...oe})))},pt=Y=>{oe&&(ge||(Y.preventDefault(),he({...oe}),ht(G(oe))))},gt=Y=>{ie&&(ge||(Y.preventDefault(),Fe(ja(ie,ee))))},me=Y=>{switch(Y.key){case bn:at(!1);break;case wn:case Qn:st(!1);break;case $t:_e(!1)}},xe=Y=>{if(Y.metaKey||Y.ctrlKey){if(Y.key===Ao||Y.key===To)return Y.preventDefault(),Y.stopPropagation(),void(Y.shiftKey?Ze():Pt());if(!ys()&&(Y.key===Ro||Y.key===Eo))return Y.preventDefault(),Y.stopPropagation(),void Ze();if(Y.key===Ho||Y.key===zo)return Y.preventDefault(),Y.stopPropagation(),void Mt();if(Y.key===Do)return Y.preventDefault(),Y.stopPropagation(),void Re("zoom");if(Y.key===Io)return Y.preventDefault(),Y.stopPropagation(),void Re("unzoom");if(Y.key===Wo)return Y.preventDefault(),Y.stopPropagation(),void we()}if(Y.key===bn)return Y.preventDefault(),Y.stopPropagation(),void at(!0);if(Y.key===$t&&Se)return Y.preventDefault(),Y.stopPropagation(),void _e(!0);if(Y.key===wn||Y.key===Qn)return Y.preventDefault(),Y.stopPropagation(),void st(!0);if(!oe)return;if(Y.key===Zo)return Me(void 0),De(Xe),Ie({mode:"default"}),void Ct(void 0);if(ge)return;const et={[yn]:[ee.gridGap?-ee.gridGap:-1,0],[xn]:[ee.gridGap?ee.gridGap:1,0],[Sn]:[0,ee.gridGap?ee.gridGap:1],[mn]:[0,ee.gridGap?-ee.gridGap:-1]};switch(Y.key){case yn:case xn:case Sn:case mn:Y.preventDefault(),Y.stopPropagation(),kt(nn(et[Y.key],oe,[0,0],ee,!0));break;case Lo:case Vo:Y.preventDefault(),Y.stopPropagation(),ht(G(oe))}};if(J)return document.addEventListener("keydown",xe),document.addEventListener("keyup",me),document.addEventListener(Mn,ut),document.addEventListener(kn,gt),document.addEventListener(Cn,pt),()=>{document.removeEventListener("keydown",xe),document.removeEventListener("keyup",me),document.removeEventListener(Mn,ut),document.removeEventListener(kn,gt),document.removeEventListener(Cn,pt)}},[J,Se,ie,ge,oe,ee,kt,ht,Me,Fe,Pt,Ze,at,st,De,Ie,Ct,he,Re,we,_e,Mt])})({isInsideComponent:B,isInsideCanvas:O,isEditingText:k.mode==="textedition",settings:z,selectedShape:o,copiedShape:I,setCopiedShape:V,selectAllShapes:u,setSelectedShape:c,removeShape:S,pasteShapes:R,updateShapes:b,backwardShape:C,forwardShape:P,setShiftPressed:q,setAltPressed:W,setActiveTool:A,setSelectionMode:U,setSelectionFrame:h,setCanvasZoom:H,resetZoom:ae,setIsSpacePressed:pe}),(({onResized:J,element:Se})=>{m.useEffect(()=>{const oe=Se.current;if(!oe)return;const ge=new ResizeObserver(ee=>{const ie=ee?.[0]?.borderBoxSize?.[0],{width:he,height:Me}=ie?{width:ie.inlineSize,height:ie.blockSize}:ee?.[0]?.contentRect??{};he!==void 0&&Me!==void 0&&J(he,Me)});return ge.observe(oe),()=>{ge.unobserve(oe)}},[Se,J])})({element:ve,onResized:Ee}),d.jsx("div",{ref:ve,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":_,"data-shrink":K,style:{"--react-paint-app-row-width":z.canvasSize.width,"--react-paint-app-canvaswidth":f,"--react-paint-app-canvasheight":j,"--react-paint-app-row-aspectratio":`calc(${z.canvasSize.width} / ${z.canvasSize.height})`,"--react-paint-app-canvas-bg":F,...a},children:d.jsx(jo,{duplicateShapes:v,isSpacePressed:L,withContextMenu:D,ref:x.canvas,canGrow:_,isInsideComponent:B,isInsideCanvas:O,activeTool:T,setActiveTool:A,canvasOffsetStartData:ne,setCanvasOffsetStartData:re,shapes:n.current,addShapes:i,updateSingleShape:b,selectedShape:o,selectionFrame:r,setSelectedShape:c,setSelectionFrame:h,hoveredShape:l,refreshHoveredShape:g,refreshSelectedShapes:p,settings:z,setCanvasOffset:E,saveShapes:M,selectionMode:k,setSelectionMode:U,setCanvasMoveAcceleration:w,selectionColor:de,selectionWidth:le,isEditMode:X,isShiftPressed:Q,isAltPressed:y,withFrameSelection:te,withSkeleton:Z})})},Ke.Editor=({editorProps:e,className:t,style:a,options:s,children:n})=>{const{selectionMode:o,setSelectionMode:r,shapesRef:l,addPictureShape:i,moveShapes:c,swapShapes:u,toggleShapeVisibility:h,toggleShapeLock:p,canGoBackward:g,canGoForward:v,canClear:S,selectedShape:b,copiedShape:C,setCopiedShape:P,pasteShapes:M,removeShape:x,duplicateShapes:f,updateShape:j,backwardShape:z,forwardShape:N,removeShapePoint:E,transformShape:R,refs:T,width:A,height:B,selectTool:O,selectShapes:X,selectAllShapes:Z,activeTool:te,setActiveTool:D,setAvailableTools:_,isEditMode:K,availableTools:ne,gridGap:re,setGridGap:k,loadFile:U,exportPicture:w,exportData:Q,clearCanvas:y,settings:L,setCanvasZoom:I,saveShapes:V,canvas:{canGrow:q,layersManipulation:W,withExport:H,withLoadAndSave:ae,withUploadPicture:pe,withUrlPicture:F,withContextMenu:de}}=e,{toolbarBackgroundColor:le,dividerColor:ve,fontRadius:Ee,fontDisabledColor:J,fontDisabledBackgroundColor:Se,fontColor:oe,fontBackgroundColor:ge,fontSelectedColor:ee,fontSelectedBackgroundColor:ie,fontHoverColor:he,fontHoverBackgroundColor:Me}={...hi,...s},De=L.size==="infinite"||L.features.zoom,[Re,we]=m.useState(!1),[Ie,Ct]=m.useState(!1),[Mt,ht]=m.useState(De),Fe=De&&Mt,kt=re>=ea.large?"large":re>=ea.medium?"medium":re>=ea.small?"small":"none",{snackbarList:Pt,addSnackbar:Ze}=ui(),at=m.useCallback((me,xe,Y)=>{_(et=>et.map(Tt=>Tt.id===me?We(["settings",xe,"default"],Y,Tt):Tt)),D(et=>et.id===me?We(["settings",xe,"default"],Y,et):et)},[D,_]),st=m.useCallback(me=>{we(!0);try{w(me)}catch(xe){xe instanceof Error&&Ze({type:"error",text:`L'export a échoué : ${xe.message}`}),console.warn(xe)}finally{we(!1)}},[w,Ze]),_e=m.useCallback(()=>{we(!0);try{Q(),we(!1)}catch(me){me instanceof Error&&Ze({type:"error",text:"L'enregistrement a échoué"}),console.warn(me)}finally{we(!1)}},[Q,Ze]),ut=m.useCallback(async me=>{we(!0);try{await U(me),Ze({type:"success",text:"Fichier chargé !"})}catch(xe){xe instanceof Error&&Ze({type:"error",text:"Le chargement a échoué"}),console.warn(xe)}finally{we(!1)}},[U,Ze]),pt=m.useCallback(async me=>{we(!0);try{const xe=await i(me,A,B);X([xe])}catch(xe){xe instanceof Error&&Ze({type:"error",text:"Le chargement a échoué"}),console.warn(xe)}finally{we(!1)}},[i,X,Ze,A,B]),gt=`${t?`${t} `:""}${Ie?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return d.jsxs("div",{ref:T.setEditor,className:gt,style:{"--react-paint-editor-app-maxWidth":q?"100%":`${A}px`,"--react-paint-editor-app-toolbar-bg":le,"--react-paint-editor-app-divider-color":ve,"--react-paint-editor-app-font-radius":`${Ee}px`,"--react-paint-editor-app-font-disabled-color":J,"--react-paint-editor-app-font-disabled-bg":Se,"--react-paint-editor-app-font-color":oe,"--react-paint-editor-app-font-bg":ge,"--react-paint-editor-app-font-selected-color":ee,"--react-paint-editor-app-font-selected-bg":ie,"--react-paint-editor-app-font-hover-color":he,"--react-paint-editor-app-font-hover-bg":Me,...a},children:[K&&d.jsx(di,{settings:L,width:L.canvasSize.width,activeTool:te,clearCanvas:y,setActiveTool:O,exportCanvasInFile:st,saveFile:_e,loadFile:ut,addPicture:pt,hasActionToUndo:g,hasActionToRedo:v,hasActionToClear:S,undoAction:z,redoAction:N,availableTools:ne,withExport:H,withLoadAndSave:ae,withUploadPicture:pe,withUrlPicture:F}),n,K&&W&&d.jsx(qo,{gridFormat:kt,setGridFormat:me=>{k(ea[me])},shapes:l.current,swapShapes:u,selectedShapes:b,removeShape:x,selectShapes:X,toggleShapeVisibility:h,toggleShapeLock:p,isLayoutPanelShown:Ie,settings:L}),Fe&&d.jsxs(dt,{alignment:"left",position:"bottom",className:"react-paint-editor-layouts-panel","data-edit":+K,children:[d.jsx($,{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:()=>I("unzoom")}),d.jsxs($,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>I("default"),children:[Math.round(100*L.canvasZoom),"%"]}),d.jsx($,{className:"react-paint-editor-zoom-button",icon:qa,onClick:()=>I("zoom")})]}),K&&d.jsxs(d.Fragment,{children:[d.jsx(ni,{saveShapes:V,setCanvasZoom:I,width:L.canvasSize.width,activeTool:te,availableTools:ne,selectedShape:b,settings:L,removeShape:x,updateShape:j,canvas:T.canvas.current,layersManipulation:W,toggleLayoutPanel:()=>{Ct(me=>!me)},isZoomPanelShown:Fe,setIsZoomPanelShown:ht,updateToolSettings:at}),d.jsx(No,{isLoading:Re}),d.jsx(Yo,{snackbarList:Pt})]}),o.mode==="contextMenu"&&de&&d.jsx(pi,{selectionMode:o,settings:L,canvasRef:T.canvas,closeContextMenu:()=>{r({mode:"default"}),T.canvas.current?.focus()},selectAllShapes:Z,removeShape:x,moveShapes:c,duplicateShapes:f,toggleShapeLock:p,toggleShapeVisibility:h,setCopiedShape:P,copiedShape:C,pasteShapes:M,removeShapePoint:E,transformShape:R})]})},Ke.useReactPaint=({width:e=1e3,height:t=600,shapes:a,mode:s="editor",disabled:n=!1,options:o=vs}={})=>{const{layersManipulation:r,brushAlgo:l,isBrushShapeDoneOnMouseUp:i,debug:c,grid:u,canGrow:h,canShrink:p,withExport:g,withLoadAndSave:v,withUploadPicture:S,withUrlPicture:b,withSkeleton:C,withFrameSelection:P,withContextMenu:M,clearCallback:x,availableTools:f,canvasSelectionPadding:j,size:z,canZoom:N}={...vs,...o},E=s!=="viewer",R=M&&E&&!n,T=m.useRef(null),A=m.useRef(null),B=m.useRef(!1),O=m.useCallback(se=>{T.current=se},[]),[X,Z]=m.useState(void 0),[te,D]=m.useState(Xe),[_,K]=m.useState({mode:"default"}),[ne,re]=m.useState(u),[k,U]=m.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),w=N==="always"&&!n,{canvasTransformation:Q,setCanvasTransformation:y,setCanvasOffset:L,setCanvasZoom:I,resetZoom:V}=Co({canvasSize:k,size:z,canvasElt:A.current,zoomEnabled:w}),{offset:q,zoom:W}=Q,H=m.useMemo(()=>({brushAlgo:l,isBrushShapeDoneOnMouseUp:i,debug:c,canvasSize:{realWidth:k.realWidth,realHeight:k.realHeight,width:k.width,height:k.height,scaleRatioWithNoZoom:k.scaleRatio,scaleRatio:k.scaleRatio*W},size:z,canvasOffset:q,canvasZoom:W,gridGap:ne,selectionPadding:j,features:{edition:E&&!n,zoom:w}}),[j,ne,l,i,c,W,q,k,z,n,w,E]),[ae,pe]=m.useState(fn(f,S||b)),{isInsideComponent:F,isInsideCanvas:de}=(({settings:se,componentRef:ue,canvasRef:He})=>{const[Qe,je]=m.useState(!1),[Oe,Ye]=m.useState(!1),Ce=!se.features.edition&&!se.features.zoom;return m.useEffect(()=>{if(!Ce){const ke=()=>je(!0),aa=()=>je(!1),nt=()=>Ye(!0),sa=()=>Ye(!1);return ue.current?.addEventListener("focusin",ke),ue.current?.addEventListener("focusout",aa),He.current?.addEventListener("focusin",nt),He.current?.addEventListener("focusout",sa),()=>{ue.current?.removeEventListener("focusin",ke),ue.current?.removeEventListener("focusout",aa),He.current?.removeEventListener("focusin",nt),He.current?.removeEventListener("focusout",sa)}}je(!1),Ye(!1)},[Ce,ue,He]),{isInsideComponent:Qe,isInsideCanvas:Oe}})({settings:H,componentRef:T,canvasRef:A}),[le,ve]=m.useState(!1),[Ee,J]=m.useState(!1),[Se,oe]=m.useState(!1),{registerEvent:ge,unregisterEvent:ee,shapesRef:ie,selectedShape:he,selectionFrame:Me,hoveredShape:De,copiedShape:Re,setCopiedShape:we,addShapes:Ie,addPictureShape:Ct,moveShapes:Mt,swapShapes:ht,setSelectedShape:Fe,setSelectionFrame:kt,refreshSelectedShapes:Pt,refreshHoveredShape:Ze,duplicateShapes:at,removeShape:st,updateShape:_e,backwardShape:ut,forwardShape:pt,clearShapes:gt,saveShapes:me,toggleShapeVisibility:xe,toggleShapeLock:Y,transformShape:et,canGoBackward:Tt,canGoForward:gi,canClear:fi}=wo(H,e,t,le),Aa=m.useCallback(se=>{Fe(void 0),D(se)},[Fe]),[jt,Tn]=m.useState([0,0]),An=_.mode==="preview";m.useEffect(()=>{if(An)return()=>K(se=>se.mode==="preview"?{mode:"default"}:se)},[he?.id,An]);const En=_.mode==="selectionFrame";m.useEffect(()=>{if(En)return()=>Tn([0,0])},[En]),m.useEffect(()=>{if(jt[0]!==0||jt[1]!==0){const se=setInterval(()=>{y(({offset:ue,zoom:He})=>{const Qe=[ue[0]-jt[0],ue[1]-jt[1]];return Ca({zoom:He,size:z,canvasSize:k,newOffset:Qe})})},20);return()=>clearInterval(se)}},[jt[0],jt[1],y,z,k]);const ta=m.useCallback((se,ue)=>{gt(se,ue),Aa(Xe),y({offset:[0,0],zoom:1})},[Aa,gt,y]),Lt=m.useCallback(se=>{Fe(ue=>(ue?.id!==se.map(He=>He.id).join("-")&&D(Xe),ce(se,H)))},[Fe,H]),Rn=m.useCallback(se=>{Ie(se),Lt(se)},[Ie,Lt]),Dn=m.useCallback(()=>{Lt(ie.current)},[Lt,ie]),vi=m.useCallback(()=>{const se=xo(ie.current,e,t);if(!se)throw new Error("L'encodage a échoué");dn(se,"drawing.json")},[ie,e,t]),mi=m.useCallback(se=>{const ue=hn({shapes:ie.current,settings:H,view:se});dn(ue,"drawing.png")},[ie,H]),Si=m.useCallback(se=>hn({shapes:ie.current,settings:H,view:se}),[ie,H]),yi=m.useCallback(()=>Ha(ie.current,e,t),[ie,e,t]),ft=m.useCallback(async(se,ue)=>{const He=await(async(Qe,je)=>{if(!Qe)return[];const Oe=[],Ye=La(Qe.map(Ce=>{if(!Ce||!ps.includes(Ce.type))return null;if(Ce.type==="picture"){const ke=new Image,aa=new Promise((nt,sa)=>{ke.onload=()=>{URL.revokeObjectURL(ke.src),nt()},ke.onerror=()=>{sa(new Error("Some images could not be loaded"))}});if(Oe.push(aa),Ce.src.startsWith("http"))cn(Ce.src).then(nt=>{ke.src=nt}).catch(()=>{ke.src=""});else if(Ce.src.includes("<svg")){const nt=new Blob([Ce.src],{type:"image/svg+xml"});ke.src=URL.createObjectURL(nt)}else ke.src=Ce.src;return un({...Ce,img:ke},je)}return un(Ce,je)}));return await Promise.all(Oe),Ye})(se,H);ta(He,ue)},[ta,H]),Ea=m.useRef(ft);Ea.current=ft;const xi=m.useCallback((se=[],ue=!0)=>{Ea.current?.(se,{clearHistory:ue,source:"remote"})},[]);m.useEffect(()=>{B.current||(B.current=!0,a&&Ea.current?.(a,{clearHistory:!0,source:"remote"}))},[a]);const bi=m.useCallback(async se=>{const ue=await(async He=>new Promise((Qe,je)=>{const Oe=new FileReader;Oe.onload=Ye=>{const Ce=Ye.target?.result;if(!Ce)return je("Impossible de récupérer les données du fichier");const ke=JSON.parse(Ce);Qe(ke)},Oe.readAsText(He)}))(se);await ft(ue.shapes??[],{clearHistory:!0,source:"remote"})},[ft]),wi=m.useCallback(()=>{typeof x!="string"?ft(x(),{clearHistory:!1,source:"user"}):x==="defaultShapes"&&a!==void 0?ft(a,{clearHistory:!1,source:"user"}):ta([],{clearHistory:!1,source:"user"})},[ta,ft,a,x]),Qi=m.useCallback((se,ue)=>{const He=se.type==="curve"?((Qe,je,Oe)=>{if(je<0||je>Qe.points.length-1)return Qe;const Ye={...Qe,points:Qe.points.filter((Ce,ke)=>ke!==je)};return Qt(Ye,Oe)})(se,ue,H):((Qe,je,Oe)=>{if(je<0||je>Qe.points.length-1)return Qe;const Ye={...Qe,points:Qe.points.filter((Ce,ke)=>ke!==je)};return wt(Ye,Oe)})(se,ue,H);_e([He],!0)},[H,_e]);m.useEffect(()=>{pe(fn(f,S||b))},[f,S,b]);const In={canvas:A,editor:T,setEditor:O};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":H.canvasZoom,"--react-paint-canvas-offset-x":H.canvasOffset[0],"--react-paint-canvas-offset-y":H.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:ie,addPictureShape:Ct,moveShapes:Mt,swapShapes:ht,toggleShapeVisibility:xe,toggleShapeLock:Y,duplicateShapes:at,canGoBackward:Tt,canGoForward:gi,canClear:fi,selectedShape:he,copiedShape:Re,setCopiedShape:we,pasteShapes:Rn,saveShapes:me,removeShape:st,updateShape:_e,backwardShape:ut,forwardShape:pt,removeShapePoint:Qi,transformShape:et,refs:In,width:e,height:t,selectTool:Aa,selectShapes:Lt,selectAllShapes:Dn,activeTool:te,setActiveTool:D,setAvailableTools:pe,isEditMode:E,availableTools:ae,gridGap:ne,setGridGap:re,loadFile:bi,exportPicture:mi,exportData:vi,clearCanvas:wi,selectionMode:_,setSelectionMode:K,settings:H,setCanvasZoom:I,resetZoom:V,canvas:{canGrow:h,canShrink:p,layersManipulation:r,withExport:g,withLoadAndSave:v,withUploadPicture:S,withUrlPicture:b,withContextMenu:R}},canvasProps:{shapesRef:ie,selectedShape:he,selectionFrame:Me,hoveredShape:De,copiedShape:Re,pasteShapes:Rn,setCopiedShape:we,addShape:Ie,setSelectedShape:Fe,setSelectionFrame:kt,refreshSelectedShapes:Pt,refreshHoveredShape:Ze,removeShape:st,updateShape:_e,duplicateShapes:at,backwardShape:ut,forwardShape:pt,saveShapes:me,refs:In,width:e,height:t,settings:H,setCanvasSize:U,setCanvasOffset:L,setCanvasZoom:I,resetZoom:V,selectShapes:Lt,selectAllShapes:Dn,activeTool:te,setActiveTool:D,isInsideComponent:F,isInsideCanvas:de,isEditMode:E,canvas:{withSkeleton:C,withFrameSelection:P,withContextMenu:R,canGrow:h,canShrink:p},canvasOffsetStartData:X,setCanvasOffsetStartData:Z,selectionMode:_,setSelectionMode:K,setCanvasMoveAcceleration:Tn,isShiftPressed:le,isAltPressed:Ee,isSpacePressed:Se,setShiftPressed:ve,setAltPressed:J,setIsSpacePressed:oe},registerEvent:ge,unregisterEvent:ee,resetCanvas:xi,resetZoom:V,getCurrentImage:Si,getCurrentData:yi,setCanvasOffset:L,setCanvasZoom:I}},Object.defineProperty(Ke,Symbol.toStringTag,{value:"Module"})});