@yorab/react-paint 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) 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/file.d.ts +11 -11
  9. package/dist/canvas/utils/intersect.d.ts +1 -1
  10. package/dist/canvas/utils/selection.d.ts +1 -1
  11. package/dist/canvas/utils/shapes/curve.d.ts +1 -0
  12. package/dist/canvas/utils/shapes/path.d.ts +3 -3
  13. package/dist/canvas/utils/shapes/polygon.d.ts +1 -0
  14. package/dist/common/types/Mode.d.ts +10 -1
  15. package/dist/common/types/Shapes.d.ts +3 -1
  16. package/dist/editor/components/common/Menu.d.ts +10 -0
  17. package/dist/editor/components/common/Panel.d.ts +3 -3
  18. package/dist/editor/components/settings/Layouts.d.ts +2 -2
  19. package/dist/editor/components/toolbox/ContextMenu.d.ts +23 -0
  20. package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -8
  21. package/dist/editor/components/toolbox/ToolbarGroup.d.ts +1 -4
  22. package/dist/editor/constants/icons.d.ts +1 -0
  23. package/dist/editor/hooks/useDrag.d.ts +2 -2
  24. package/dist/editor/hooks/useMenu.d.ts +10 -0
  25. package/dist/react-paint.css +1 -1
  26. package/dist/react-paint.js +1452 -1309
  27. package/dist/react-paint.umd.cjs +1 -1
  28. package/package.json +25 -8
  29. package/dist/canvas/utils/string.d.ts +0 -2
  30. package/dist/editor/components/settings/PointsNumberField.d.ts +0 -13
@@ -1 +1 @@
1
- (function(Re,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((Re=typeof globalThis<"u"?globalThis:Re||self)["react-paint"]={},Re.React,Re.jsxRuntime)})(this,function(Re,y,h){"use strict";const xn='<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>',Dt='<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>',Qn='<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>',bn='<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>',wn='<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>',Cn='<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>',Mn='<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>',kn='<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>',Pn='<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>',Ln='<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>',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.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>',Zn='<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],Hn=[[1,0],[1,2],[4,6]],ut="serif",pa=2,zn=3,ga=4,re="react-paint-",Tn={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}}},An={type:"brush",id:`${re}brush`,icon:xn,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}}},En={type:"line",id:`${re}line`,icon:Cn,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}}},Dn={type:"curve",id:`${re}curve`,icon:Mn,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}}},In={type:"rect",id:`${re}rect`,icon:Dt,label:"Rectangle",settings:Tn},Wn={type:"square",id:`${re}square`,icon:Dt,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}}},Nn={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}}},Fn={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:wn,label:"Texte",settings:{strokeColor:{values:Se,default:"black"},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:["arial","serif","monospace"],default:ut},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}}},De={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"},Ot={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"},Bn={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"},Bt={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"},Yn={id:`${re}upload-picture`,type:"uploadpicture",icon:Nt,label:"Upload picture"},Xn=2,$n="blue",Be=14,Un=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],qn=["brush","rect","square","line","polygon","circle","curve","ellipse","picture","text","triangle","group"],fa=["rect","square","circle","ellipse","picture","text","triangle","brush","group"],va=["square","circle","picture","text"],Gn="react-paint-canvas-drawcanvas",_n="react-paint-canvas-selectioncanvas",Kn={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,availableTools:[An,En,Rn,Dn,In,Wn,Nn,Fn,Ft,On],clearCallback:"empty",brushAlgo:"simple",isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:"fixed",canZoom:"never",debug:!1},ma={canvasBackgroundColor:"white",canvasSelectionColor:$n,canvasSelectionWidth:Xn},Jn=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((i,c,r)=>(i[c]=$t(i[c])?{...i[c]}:Array.isArray(i[c])?[...i[c]]:i[c]===void 0||i[c]===null?{}:i[c],r===a.length-1&&(i[c]=t),i[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},es=(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)||!es(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)),ts=()=>typeof navigator<"u"&&navigator.userAgent.includes("Macintosh"),ns=e=>{e.reset(),e.lineCap="round",e.lineJoin="round"},xe=(e,t={})=>{const{lineCap:n="round",fillColor:s="transparent",opacity:a=100,strokeColor:i=$n,lineWidth:c=Xn,lineDash:r=0,shadowColor:o="transparent",shadowBlur:l=0}=t;e.lineCap=n,e.globalAlpha=a/100,e.fillStyle=s,e.strokeStyle=i,e.lineWidth=c,e.setLineDash(r===0?[]:[Hn[r][0]*c,Hn[r][1]*c]),e.shadowColor=o,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,ss=(e,t)=>{const n=t.x-Math.min(Math.max(t.x,e.x),e.x+e.width),s=t.y-Math.min(Math.max(t.y,e.y),e.y+e.height);return Math.sqrt(n*n+s*s)<=t.radius},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]]},as=e=>(e+2*Math.PI)%(2*Math.PI),is=({targetVector:[e,t],radian:n=!0,originVector:s})=>{const a=as(Math.atan2(t[1]-e[1],t[0]-e[0]));if(s){const[i,c]=s,r=Math.atan2(c[1]-i[1],c[0]-i[0]),o=as(a-r);return n?o:qt(o)}return n?a:qt(a)},os=(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,i=(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-i:i)}},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(o=>o[0])),a=Math.min(...n.map(o=>o[1])),i=n.map(o=>Ve(o,s,a,e.scaleX,e.scaleY)),c=Math.max(...i.map(o=>o[0]))+t,r=Math.max(...i.map(o=>o[1]))+t;return{x:s-t,width:c-s+t,y:a-t,height:r-a+t}},at=(e,t)=>{const n=xa(e,t),s=((a,i)=>Te(a,Gt,i))(e,t);return{...e,path:n,selection:it(n,s,t),computed:s}},ya=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},Sa=(e,t,n,s,a,i,c)=>{if(s.mode==="translate")return ce(zs(n,s.originalShape,s.cursorStartPosition,a,i),a);if(s.mode==="rotate"){const r=s.originalShape.computed.center[0]-s.cursorStartPosition[0],o=s.originalShape.computed.center[1]-s.cursorStartPosition[1],l=s.originalShape.computed.center[0]-n[0],d=s.originalShape.computed.center[1]-n[1],u=((m,v,f)=>v.gridGap||f?m+Math.PI/18/2-(m+Math.PI/18/2)%(Math.PI/18):be(m,3))(Math.atan2(d,l)-Math.atan2(o,r),a,i),p=U(s.originalShape).map(m=>Ee(Xa(m,u,s.originalShape.computed.center),a));return ce(p,a)}return s.mode==="resize"?ce($a(e,n,s.originalShape,s,a,i,c),a):s.mode==="brush"?ce(U(t).map(r=>((o,l,d)=>{const u={...o,points:Qe(o.points.length-1,[...o.points[o.points.length-1],[Math.round(l[0]),Math.round(l[1])]],o.points)};return at(u,d)})(r,n,a)),a):t},ht=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},xa=(e,{brushAlgo:t})=>{if(e.points.length<1||e.style?.strokeColor==="transparent")return;const n=e.points.flat(),s=n.map(o=>o[0]),a=n.map(o=>o[1]),i=Math.min(...s),c=Math.min(...a),r=new Path2D;for(const o of e.points){if(!o.length)return;if(o.length===1)r.rect(...Ve(o[0],i,c,e.scaleX,e.scaleY),1,1);else if(r.moveTo(...Ve(o[0],i,c,e.scaleX,e.scaleY)),t==="quadratic"){for(let l=0;l<o.slice(1).length-2;l++){const d=Ve(o[l],i,c,e.scaleX,e.scaleY),u=Ve(o[l+1],i,c,e.scaleX,e.scaleY),p=(d[0]+u[0])/2,m=(d[1]+u[1])/2;r.quadraticCurveTo(...d,p,m)}r.quadraticCurveTo(...Ve(o[o.length-2],i,c,e.scaleX,e.scaleY),...Ve(o[o.length-1],i,c,e.scaleX,e.scaleY))}else for(const l of o.slice(1))r.lineTo(...Ve(l,i,c,e.scaleX,e.scaleY))}return r},Qa=(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],i=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,L,R)=>{const V=w-2*L+R,C=-2*w+2*L,Z=w;if(Math.abs(V)<1e-10){if(Math.abs(C)<1e-10)return[];const X=-Z/C;return X>0&&X<1?[X]:[]}const A=C*C-4*V*Z;if(A<0)return[];const H=Math.sqrt(A),B=(-C-H)/(2*V),D=(-C+H)/(2*V),I=[];return B>0&&B<1&&I.push(B),D>0&&D<1&&D!==B&&I.push(D),I},r=e[0],o=t[0],l=n[0],d=s[0],u=e[1],p=t[1],m=n[1],v=s[1],f=c(o-r,l-o,d-l),Q=c(p-u,m-p,v-m);let k=Math.min(e[0],s[0]),b=Math.max(e[0],s[0]),x=Math.min(e[1],s[1]),g=Math.max(e[1],s[1]);for(const w of f){const L=a(w);k=Math.min(k,L),b=Math.max(b,L)}for(const w of Q){const L=i(w);x=Math.min(x,L),g=Math.max(g,L)}return{minX:k,maxX:b,minY:x,maxY:g}},_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]}),rs=e=>{const t=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(t.length<2)return;const n=new Path2D;n.moveTo(...t[0]);for(const s of t.slice(1))n.lineTo(...s);return t.length>2&&e.style?.closedPoints===1&&n.lineTo(...t[0]),n},ba=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},wa=(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=wa)=>{const a=t(e,n),i=s(e,a,n),c=[a.x+a.width/2,a.y+a.height/2],r=((o,l,d=0)=>{if(d===0)return o;const u=[[o.x,o.y],[o.x+o.width,o.y],[o.x+o.width,o.y+o.height],[o.x,o.y+o.height]].map(v=>ne({point:v,origin:l,rotation:d})),p=Math.min(...u.map(v=>v[0])),m=Math.min(...u.map(v=>v[1]));return{x:p,y:m,width:Math.max(...u.map(v=>v[0]))-p,height:Math.max(...u.map(v=>v[1]))-m}})(i,c,e.rotation);return{borders:a,outerBorders:i,center:c,boundingBox:r}},it=(e,t,n)=>{const{borders:s}=t;return{border:ht(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}),...Un.map(a=>mt({x:s.x+s.width*a[0],y:s.y+s.height*a[1],radius:7/n.canvasSize.scaleRatio}))]}},ls=({borderStart:e,borderSize:t,vector:n,settings:s,invertedAxe:a,anchor:i})=>{switch(i){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]}},Ca=({borderX:e,borderWidth:t,borderY:n,borderHeight:s,center:a,originalShape:i})=>{const c=[e+t/2-a[0],n+s/2-a[1]],[r,o]=ne({point:c,rotation:-(i.rotation??0)});return{borderX:be(e+r-c[0]),borderWidth:be(t),borderY:be(n+o-c[1]),borderHeight:be(s)}},Ma=(e,t,n,s)=>{const a=t.x+t.width/2,i=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:i-r/2}},$e=(e,t,n,s,a=!1,i=!1)=>{const{center:c,borders:r}=t.computed,o=ne({origin:c,point:e,rotation:t.rotation}),l=n.anchor[0]===0&&o[0]>=r.x+r.width-s.selectionPadding||n.anchor[0]===1&&o[0]<=r.x+s.selectionPadding,d=n.anchor[1]===0&&o[1]>=r.y+r.height-s.selectionPadding||n.anchor[1]===1&&o[1]<=r.y+s.selectionPadding,u=[ge(o[0],s,n.anchor[0]===0&&!l||n.anchor[0]===1&&l?s.selectionPadding:-s.selectionPadding),ge(o[1],s,n.anchor[1]===0&&!d||n.anchor[1]===1&&d?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=[u[0]-p[0],u[1]-p[1]],[v,f]=ls({borderStart:r.x,borderSize:r.width,vector:m[0],settings:s,invertedAxe:l,anchor:n.anchor[0]}),[Q,k]=ls({borderStart:r.y,borderSize:r.height,vector:m[1],settings:s,invertedAxe:d,anchor:n.anchor[1]}),b=a?((x,g,w,L,R,V,C,Z,A,H,B)=>{const{selectionPadding:D}=B,I="ratio"in A&&A.ratio?A.ratio:(x.width-2*D||1)/(x.height-2*D||1),X=(L-2*D)/(V-2*D);let $,z,S,M;return H.anchor[0]!==.5&&H.anchor[1]!==.5?X<I?(z=R,M=V,S=(V-2*D)*I+2*D,$=H.anchor[0]===0?C?x.x+x.width-2*D:x.x+(x.width-S):C?x.x-S+2*D:x.x):($=w,S=L,M=(L-2*D)/I+2*D,z=H.anchor[1]===0?Z?x.y+x.height-2*D:x.y+(x.height-M):Z?x.y-M+2*D:x.y):H.anchor[0]!==.5?($=w,S=L,M=(L-2*D)/I+2*D,z=x.y+(x.height-M)/2):(z=R,M=V,S=(V-2*D)*I+2*D,$=x.x+(x.width-S)/2),{borderX:$,borderWidth:S,borderY:z,borderHeight:M,center:g,originalShape:A}})(r,c,v,f,Q,k,l,d,t,n,s):{borderX:v,borderWidth:f,borderY:Q,borderHeight:k,center:c,originalShape:t};return{...Ca(i?Ma(b,r,l,d):b),isXinverted:l,isYinverted:d}},St=(e,t)=>{const n=ht(e),s=((a,i)=>Te(a,Jt,i))(e,t);return{...e,path:n,computed:s,selection:it(n,s,t)}},ka=St,cs=(e,t,n,s=0,a=0)=>{const i={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(i,n)},Pa=(e,t)=>{e.globalAlpha!==0&&t.path&&(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}),ds=(e,t,n,[s,a]=[!1,!1])=>{const i=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([i,c],n.rotation??0,t)},us=(e,t,n,s,a,i,c,r)=>{let o=!1;if(a){o=lt(e,a,n,s,!0,i?20:void 0);const d=((u,p,m)=>{if(u.mode==="translate")return{mode:"translate",cursorStartPosition:m,originalShape:p,hasBeenDuplicated:!1,dateStart:Date.now()};if(u.mode==="rotate"){const{center:v}=p.computed;return{mode:"rotate",cursorStartPosition:m,originalShape:p,center:[v[0],v[1]]}}return u.mode==="resize"?{mode:"resize",cursorStartPosition:m,originalShape:p,anchor:u.anchor}:void 0})(o||{mode:"default"},a,n);if(d?.mode==="resize"||d?.mode==="rotate")return{shape:a,mode:d}}const l=t.find(d=>U(a).find(u=>d.id===u?.id)?o&&r?lt(e,d,n,s,!0,i?20:void 0):!!o:!!ms(e,d,n,s));if(l){if(r){const u=U(a).find(p=>p.id===l?.id)?ce(ja(a,l),s):ce(ps(a,[l]),s);return{shape:u,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:u}}}const d=U(a).find(u=>u.id===l?.id)?a:ce([l],s);return{shape:d,mode:{mode:"translate",cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:d}}}return r?{shape:a,mode:{mode:c?"selectionFrame":"default"}}:{shape: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,o)=>{const l=c.map(g=>[[g.computed.borders.x+o.selectionPadding,g.computed.borders.y+o.selectionPadding],[g.computed.borders.x-o.selectionPadding+g.computed.borders.width,g.computed.borders.y+o.selectionPadding],[g.computed.borders.x-o.selectionPadding+g.computed.borders.width,g.computed.borders.y-o.selectionPadding+g.computed.borders.height],[g.computed.borders.x+o.selectionPadding,g.computed.borders.y-o.selectionPadding+g.computed.borders.height]].map(w=>{const L=ne({point:[w[0],w[1]],origin:g.computed.center,rotation:-(g.rotation??0)});return ne({point:[L[0],L[1]],origin:[0,0],rotation:r})})),d=Math.min(...l.flatMap(g=>[g[0][0],g[1][0],g[2][0],g[3][0]])),u=Math.min(...l.flatMap(g=>[g[0][1],g[1][1],g[2][1],g[3][1]])),p=Math.max(...l.flatMap(g=>[g[0][0],g[1][0],g[2][0],g[3][0]])),m=Math.max(...l.flatMap(g=>[g[0][1],g[1][1],g[2][1],g[3][1]])),v=[(d+p)/2,(u+m)/2],f=ne({point:v,origin:[0,0],rotation:-r}),Q=[v[0]-f[0],v[1]-f[1]],k=be(d-Q[0]),b=be(p-Q[0]),x=be(u-Q[1]);return{width:b-k,height:be(m-Q[1])-x,x:k,y:x}})(e,n,t),a=cs({id:"group_selection",type:"rect",settings:Tn},[s.x,s.y],t,s.width,s.height),i=e.slice(1).reduce((c,r)=>{const o=r.style??{},l={};for(const d in o)c[d]!==void 0&&o[d]!==void 0&&c[d]===o[d]&&(l[d]=c[d]);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:i,computed:a.computed}},hs=(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)},U=e=>e?e.type==="group"?e.shapes:[e]:[],ps=(e,t)=>{const n=U(e);return[...new Set([...n,...t])]},ja=(e,t)=>U(e).filter(n=>n.id!==t.id),gs=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}},fs=(e,t,n)=>{const{clientX:s,clientY:a}=gs(e),i=t.getBoundingClientRect();return[(s-i.left)/n.scaleRatio,(a-i.top)/n.scaleRatio]},ot=(e,t,n)=>{const{clientX:s,clientY:a}=gs(e),i=t?.getBoundingClientRect()??{left:0,top:0,width:n.canvasSize.width,height:n.canvasSize.height};return[(s-i.left)*(n.canvasSize.width/i.width)/n.canvasSize.scaleRatio-n.canvasOffset[0],(a-i.top)*(n.canvasSize.height/i.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?ss(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),lt=(e,t,n,s,a=!1,i=0)=>{if(t.locked)return!1;const{canvasSize:{scaleRatio:c}}=s,{borders:r,center:o}=t.computed,l=Ae(n,t.rotation??0,o),d=U(t).length>1?t:U(t)[0];if(d&&a)if(d.type==="line"||d.type==="polygon"||d.type==="curve"){for(let u=0;u<d.points.length;u++)if(xt({x:d.points[u][0]-7/c,y:d.points[u][1]-7/c,width:Be/c,height:Be/c},l,i))return{mode:"resize",anchor:u}}else{if(xt({x:r.x+r.width/2-7/c,y:r.y-Be/c-16/c,width:Be/c,height:Be/c},l,i))return{mode:"rotate"};for(const u of Un)if(xt({x:r.x+r.width*u[0]-7/c,y:r.y+r.height*u[1]-7/c,width:Be/c,height:Be/c},l,i))return{mode:"resize",anchor:u}}return(xt(r,l,i)||!(t.type!=="curve"||!t.path||!e.isPointInPath(t.path,l[0],l[1])))&&{mode:"translate"}},vs=(e,t,n,s,a=50)=>{if(t.locked||t.points.length<2)return!1;const{center:i}=t.computed,c=Ae(n,t.rotation??0,i);e.lineWidth=(t.style?.lineWidth??0)+a/s.canvasZoom;const r=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let o=0;o<r.length-1;o++){const l=yt({points:[r[o],r[o+1]]});if(e.isPointInStroke(l,c[0],c[1]))return{lineIndex:o}}return!1},ms=(e,t,n,s)=>{if(t.locked)return!1;const{center:a}=t.computed,i=Ae(n,t.rotation??0,a);return t.path?t.style?.fillColor&&t.style?.fillColor!=="transparent"||["picture","text"].includes(t.type)?!!e.isPointInPath(t.path,i[0],i[1])&&{mode:"translate"}:(e.lineWidth=(t.style?.lineWidth??0)+15/s.canvasZoom,!!e.isPointInStroke(t.path,i[0],i[1])&&{mode:"translate"}):lt(e,t,n,s,!1)};function tn(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)),i=Math.min(e.y+(e.height||1),t.y+(t.height||1));if(n<a&&s<i)return{x:n,y:s,width:a-n,height:i-s}}const ys=({ctx:e,path:t,rect:n,offset:s,center:a,rotation:i=0,checkFill:c})=>{for(let r=0;r<s;r+=s/2)for(let o=0;o<s;o+=s/2)for(let l=r+n.x;l<n.x+n.width;l+=s)for(let d=o+n.y;d<n.y+n.height;d+=s){const u=Ae([l,d],i,a);if(c?e.isPointInPath(t,u[0],u[1]):e.isPointInStroke(t,u[0],u[1]))return!0}return!1},nn=(e,t,n,s)=>({border:ht(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],sn=({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)]},an=({size:e,canvasSize:t,currentOffset:n,currentZoom:s,zoom:a,centerPoint:i})=>{const c=e==="fixed"&&a<1?[t.realWidth/2,t.realHeight/2]:i,r=n[0]-(c[0]/s-c[0]/a),o=n[1]-(c[1]/s-c[1]/a);return{offset:e==="infinite"?[r,o]:a<1?[-(t.realWidth-t.realWidth/a)/2,-(t.realHeight-t.realHeight/a)/2]:[ze(r,t.realWidth/a-t.realWidth,0),ze(o,t.realHeight/a-t.realHeight,0)],zoom:a}},Ss=e=>{const{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:s},canvasZoom:a,canvasOffset:i}=e;return{x:i[0]*a*s,y:i[1]*a*s,width:t*a,height:n*a}},xs=(e,t)=>{const{canvasZoom:n,size:s}=t;if(s!=="fixed"||n>=1)return;const a=Ss(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,La=(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,i)=>Te(a,La,i))(e,t);return{...e,path:n,selection:it(n,s,t),computed:s}},Va=Qt,gt=(e,t)=>{const n=rs(e),s=((a,i)=>Te(a,bt,i))(e,t);return{...e,path:n,selection:nn(n,e,s,t),computed:s}},Qs=gt,bt=(e,t)=>{const n=Math.min(...e.points.map(i=>i[0]))-t.selectionPadding,s=Math.max(...e.points.map(i=>i[0]))+t.selectionPadding,a=Math.min(...e.points.map(i=>i[1]))-t.selectionPadding;return{x:n,width:s-n,y:a,height:Math.max(...e.points.map(i=>i[1]))+t.selectionPadding-a}},Za=(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)},bs=(e,t,n,s=!1)=>{const a=[ge(t[0],n),ge(t[1],n)],i=Ae(a,e.rotation??0,e.computed.center),c={...e,points:s?e.points:[...e.points,i],tempPoint:s?i:void 0};return gt(c,n)},Ha=(e,t,n)=>{const s=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(s.length<2){const l=s[0]??[0,0],d=n.selectionPadding;return{x:l[0]-d,y:l[1]-d,width:2*d,height:2*d}}if(s.length<3)return bt({...e,points:s},n);const a=_t(e,s);let i=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY,r=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY;for(let l=1;l<a.length-2;l++){const d=a[l-1],u=a[l],p=a[l+1],m=a[l+2],{cp1:v,cp2:f}=Kt(d,u,p,m),Q=Qa(u,v,f,p);i=Math.min(i,Q.minX),c=Math.max(c,Q.maxX),r=Math.min(r,Q.minY),o=Math.max(o,Q.maxY)}return Jt({x:i,y:r,width:c-i,height:o-r},n)},ft=(e,t)=>{const n=(a=>{const i=a.tempPoint?[...a.points,a.tempPoint]:a.points;if(i.length<2)return;if(i.length<3)return rs(a);const c=a.style?.closedPoints===1&&i.length>2,r=new Path2D;r.moveTo(...i[0]);const o=_t(a,i);for(let l=1;l<o.length-2;l++){const d=o[l-1],u=o[l],p=o[l+1],m=o[l+2],{cp1:v,cp2:f}=Kt(d,u,p,m);r.bezierCurveTo(v[0],v[1],f[0],f[1],p[0],p[1])}return c&&r.closePath(),r})(e),s=((a,i)=>Te(a,bt,i,Ha))(e,t);return{...e,path:n,selection:nn(n,e,s,t),computed:s}},ws=ft,za=(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)},Cs=(e,t,n,s=!1)=>{const a=[ge(t[0],n),ge(t[1],n)],i=e.computed.center,c=Ae(a,e.rotation??0,i),r={...e,points:s?e.points:[...e.points,c],tempPoint:s?c:void 0};return ft(r,n)},Ta=(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 i=new Path2D;return i.ellipse(a.x,a.y,a.radiusX,a.radiusY,0,0,2*Math.PI),i})(e),s=((a,i)=>Te(a,Ta,i))(e,t);return{...e,path:n,selection:it(n,s,t),computed:s}},Aa=wt,Ea=(e,t)=>Te(e,bt,t),Ms=(e,t)=>((n,s)=>({...n,path:ba(n),computed:Ea(n,s)}))({...e,id:le("triangle_"),type:"triangle"},t),Ra=(e,t)=>{e.globalAlpha!==0&&t.path&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},Da=(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 i=Math.PI/2-is({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||n.push(Ms(ks(e.points[0],i,e.style),t)),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||n.push(Ms(ks(e.points[1],i+Math.PI,e.style),t));const c=(({line:r,size:o,direction:l})=>{const d=Math.PI/2-is({targetVector:[r.points[0],r.points[1]]}),u=[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:u,rotation:-d});p=ne({point:[v[0],v[1]+o],origin:u,rotation:d})}else p=[...r.points[0]];if(["end","both"].includes(l)){const v=ne({point:r.points[1],origin:u,rotation:-d});m=ne({point:[v[0],v[1]-o],origin:u,rotation:d})}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=((i,c)=>Te(i,Da,c))(e,t);return{...e,path:s,selection:nn(s,e,a,t),arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"},computed:a}},Ia=Ct,ks=(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"}}},Wa=(e,t,n)=>{const{isXinverted:s,isYinverted:a,settings:i,widthMultiplier:c,heightMultiplier:r}=n,o=e.computed.borders.width-2*i.selectionPadding,l=e.computed.borders.height-2*i.selectionPadding,d=o*c,u=l*r,p=Ye(e,t,n),m=Xe(n,p.x,p.y,d,u),v=e.computed.center[0]-o/2,f=e.computed.center[1]-l/2,Q=m[0]-d/2,k=m[1]-u/2;return((b,x)=>b.type==="line"?Ct(b,x):b.type==="polygon"?Qs(b,x):ws(b,x))({...e,points:e.points.map(([b,x])=>[Q+(s?d-(b-v)*c:(b-v)*c),k+(a?u-(x-f)*r:(x-f)*r)])},n.settings)},Mt=(e,t)=>{const n=((a,i)=>Te(a,Jt,i))(e,t),s=ht(e);return{...e,path:s,selection:it(void 0,n,t),computed:n}},Na=Mt,on=(e,t,n,s,a)=>{const[i,c]=((r,o,l,d,u=!1)=>{if(!(r&&o&&d&&l))return[Jn,Jn];const p=r/o;if(p>l/d){const v=u?l:Math.min(r,l);return[v,v/p]}const m=u?d:Math.min(o,d);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-i/2,y:-a.canvasOffset[1]+a.canvasSize.realHeight/a.canvasZoom/2-c/2,width:i,height:c,ratio:i/c,src:t,img:e},a)},Fa=(e,t,n,s)=>new Promise((a,i)=>{const c=new Image;c.onerror=()=>{i(new Error("Some images could not be loaded"))},setTimeout(()=>{i(new Error("Timeout while loading images"))},4e3),e instanceof File?((r,o,l,d,u,p)=>{Es(l)?l.text().then(m=>{const v=As(m);r.onload=async()=>{URL.revokeObjectURL(r.src);const f=on(r,m,d,u,p);o(f)},r.src=v}):(r.onload=async()=>{URL.revokeObjectURL(r.src);const m=on(r,r.src,d,u,p);o(m)},r.src=URL.createObjectURL(l))})(c,a,e,t,n,s):((r,o,l,d,u,p)=>{r.onload=()=>{URL.revokeObjectURL(r.src);const m=on(r,l,d,u,p);o(m)},Rs(l).then(m=>{r.src=m}).catch(()=>{r.src=""})})(c,a,e,t,n,s)}),rn=["Texte"],Ps=(e,t)=>Te(e,Ba,t),kt=(e,t)=>{const n=Ps(e,t),s=ht(e);return{...e,path:s,selection:it(void 0,n,t),computed:n}},Oa=kt,Pt=(e,t,n,s,a,i=ut)=>{e.font=`${a?"italic":""} ${s?"bold":""} 1px ${i}`;const c=t.map(r=>n/e.measureText(r).width);return Math.min(...c)||36},Ba=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),Ya=(e,t,n,s)=>{const a={...t,value:n},i=((v,f,Q,k,b,x=ut)=>{v.font=`${b?"italic":""} ${k?"bold":""} ${Q}px ${x}`;const g=f.map(w=>v.measureText(w).width);return Math.max(...g)||20})(e,a.value,a.fontSize,a.style?.fontBold??!1,a.style?.fontItalic??!1,a.style?.fontFamily),c=a.fontSize*a.value.length,r=i/c,o={...a,width:i,height:c,ratio:r},{center:l}=Ps(o,s),[d,u]=ds([1,1],t.computed.center,t),[p,m]=ds([1,1],l,o,[!1,!1]);return{...o,x:o.x-(p-d),y:o.y-(m-u)}},js=(e,t,n,s)=>{const a=[ge(n[0],s),ge(n[1],s)];switch(t.type){case"brush":return((i,c,r)=>at({toolId:i.id,type:i.type,id:le(`${i.type}_`),points:[[c]],scaleX:1,scaleY:1,style:{opacity:i.settings.opacity.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default}},r))(t,a,s);case"line":return((i,c,r)=>{const o={toolId:i.id,type:i.type,id:le(`${i.type}_`),points:[c,c],style:{opacity:i.settings.opacity.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default,lineArrow:i.settings.lineArrow.default}};return Ct(o,r)})(t,a,s);case"polygon":return((i,c,r)=>gt({toolId:i.id,type:i.type,id:le(`${i.type}_`),points:[c],style:{opacity:i.settings.opacity.default,fillColor:i.settings.fillColor.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default,closedPoints:i.settings.closedPoints.default}},r))(t,a,s);case"curve":return((i,c,r)=>ft({toolId:i.id,type:i.type,id:le(`${i.type}_`),points:[c],style:{opacity:i.settings.opacity.default,fillColor:i.settings.fillColor.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default,closedPoints:i.settings.closedPoints.default}},r))(t,a,s);case"rect":case"square":return cs(t,a,s);case"text":return((i,c,r,o)=>{const l=Pt(i,rn,150,c.settings?.fontBold.default??!1,c.settings?.fontItalic.default??!1,c.settings.fontFamily.default),d=l*(rn.length||1);return kt({toolId:c.id,type:c.type,id:le(`${c.type}_`),x:r[0]-150,y:r[1]-d,value:rn,fontSize:l,width:150,height:d,ratio:150/d,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}},o)})(e,t,a,s);case"ellipse":return((i,c,r)=>wt({toolId:i.id,type:i.type,id:le(`${i.type}_`),x:c[0],y:c[1],radiusX:0,radiusY:0,style:{opacity:i.settings.opacity.default,fillColor:i.settings.fillColor.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default}},r))(t,a,s);case"circle":return((i,c,r)=>Qt({toolId:i.id,type:i.type,id:le(`${i.type}_`),x:c[0],y:c[1],radius:0,style:{opacity:i.settings.opacity.default,fillColor:i.settings.fillColor.default,strokeColor:i.settings.strokeColor.default,lineWidth:i.settings.lineWidth.default,lineDash:i.settings.lineDash.default}},r))(t,a,s)}},Ls=(e,t)=>{switch(t.type){case"brush":((n,s)=>{s.points.length<1||!s.path||n.globalAlpha!==0&&s.style?.strokeColor!=="transparent"&&n.globalAlpha!==0&&n.stroke(s.path)})(e,t);break;case"text":((n,s)=>{if(n.globalAlpha!==0&&s.style?.strokeColor&&s.style.strokeColor!=="transparent"){n.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??ut}`,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.path){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)=>{s.path&&n.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"curve":((n,s)=>{s.path&&n.globalAlpha!==0&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"circle":((n,s)=>{n.globalAlpha!==0&&s.path&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"ellipse":((n,s)=>{n.globalAlpha!==0&&s.path&&(s.style?.fillColor!=="transparent"&&n.fill(s.path),s.style?.strokeColor!=="transparent"&&n.stroke(s.path))})(e,t);break;case"rect":case"square":Pa(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)}},Vs=(e,t,n)=>{if(t.visible===!1)return;if(((a,i)=>{const c=(r=>{const{canvasSize:{width:o,height:l,scaleRatioWithNoZoom:d},canvasZoom:u,canvasOffset:p}=r;return{x:-p[0],y:-p[1],width:o/u/d,height:l/u/d}})(i);return!!tn(a.computed.boundingBox,c)})(t,n)){if(st(e,n,t.rotation,t.computed.center),xe(e,t.style),e.globalAlpha!==1)return((a,i)=>{const{outerBorders:c}=i.computed,r={width:2*c.width,height:2*c.height};if(r.width===0||r.height===0)return;const o=document.createElement("canvas"),l=o.getContext("2d");if(!l)throw new Error("No context found for canvas");o.width=r.width,o.height=r.height,l.translate(r.width/4-c.x,r.height/4-c.y),xe(l,{...i.style,opacity:100}),Ls(l,i),a.drawImage(o,c.x-r.width/4,c.y-r.height/4)})(e,t),void e.restore();Ls(e,t),e.restore()}},Xa=(e,t,n)=>{const s=ne({origin:n,point:e.computed.center,rotation:-t});if("points"in e){if(e.type==="brush"){const i=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:i,rotation:(e.rotation??0)+t}}const a=e.points.map(i=>ne({origin:n,point:i,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}},Zs=(e,t,n,s,a,i,c)=>{switch(n.type){case"line":return((r,o,l,d)=>{const u=[ge(r[0],d),ge(r[1],d)],p=Ae(u,o.rotation??0,o.computed.center),m=Qe(["points",l.anchor],p,o);return Ct(m,d)})(t,n,s,a);case"polygon":return((r,o,l,d)=>{const u=[ge(r[0],d),ge(r[1],d)],p=Ae(u,o.rotation??0,o.computed.center),m=Qe(["points",l.anchor],p,o);return gt(m,d)})(t,n,s,a);case"curve":return((r,o,l,d)=>{const u=[ge(r[0],d),ge(r[1],d)],p=o.computed.center,m=Ae(u,o.rotation??0,p),v=Qe(["points",l.anchor],m,o);return ft(v,d)})(t,n,s,a);case"brush":return((r,o,l,d,u,p)=>{const m=Gt({...o,scaleX:1,scaleY:1},d),v=o.computed.borders,{borderX:f,borderHeight:Q,borderY:k,borderWidth:b,isXinverted:x,isYinverted:g}=$e(r,o,l,d,u,p),w=Math.max(0,m.width-2*d.selectionPadding),L=Math.max(0,m.height-2*d.selectionPadding),R=Math.max(0,b-2*d.selectionPadding),V=Math.max(0,Q-2*d.selectionPadding),C=w?R/w:1,Z=L?V/L:1;if(!w||!L)return o;const A=be(f-v.x)+(x?2*v.x+m.width:0),H=be(k-v.y)+(g?2*v.y+m.height:0);return at({...o,points:o.points.map(B=>B.map(([D,I])=>[x?-D+A:D+A,g?-I+H:I+H])),scaleX:C,scaleY:Z},d)})(t,n,s,a,i,c);case"circle":return((r,o,l,d,u)=>{const{borderX:p,borderHeight:m,borderY:v,borderWidth:f}=$e(r,o,l,d,!0,u);return Qt({...o,radius:Math.max(0,f/2-d.selectionPadding),x:p+f/2,y:v+m/2},d)})(t,n,s,a,c);case"ellipse":return((r,o,l,d,u=!1,p=!1)=>{const{borderX:m,borderHeight:v,borderY:f,borderWidth:Q}=$e(r,o,l,d,u,p);return wt({...o,radiusX:Math.max(0,Q/2-d.selectionPadding),radiusY:Math.max(0,v/2-d.selectionPadding),x:m+Q/2,y:f+v/2},d)})(t,n,s,a,i,c);case"rect":case"square":return((r,o,l,d,u=!1,p=!1)=>{const{borderX:m,borderHeight:v,borderY:f,borderWidth:Q}=$e(r,o,l,d,u,p);return St({...o,width:Math.max(0,Q-2*d.selectionPadding),height:Math.max(0,v-2*d.selectionPadding),x:m+d.selectionPadding,y:f+d.selectionPadding},d)})(t,n,s,a,n.type==="square"||i,c);case"text":return((r,o,l,d,u,p)=>{const{borderX:m,borderHeight:v,borderY:f,borderWidth:Q,isXinverted:k,isYinverted:b}=$e(o,l,d,u,!0,p),x=Math.max(0,Q-2*u.selectionPadding),g=Math.max(0,v-2*u.selectionPadding),w=kt({...l,width:x,height:g,x:m+u.selectionPadding,y:f+u.selectionPadding,flipX:k?!l.flipX:!!l.flipX,flipY:b?!l.flipY:!!l.flipY},u);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,o,l,d,u)=>{const{borderX:p,borderHeight:m,borderY:v,borderWidth:f,isXinverted:Q,isYinverted:k}=$e(r,o,l,d,!0,u),b=Math.max(0,f-2*d.selectionPadding),x=Math.max(0,m-2*d.selectionPadding);return Mt({...o,width:b,height:x,x:p+d.selectionPadding,y:v+d.selectionPadding,flipX:Q?!o.flipX:!!o.flipX,flipY:k?!o.flipY:!!o.flipY},d)})(t,n,s,a,c);default:return n}},$a=(e,t,n,s,a,i,c)=>{if(n.type!=="group")return U(n).map(v=>Zs(e,t,v,s,a,i,c));const r=n,o=U(r),l=o.filter(v=>fa.includes(v.type)),d=!l.some(v=>(v.rotation??0)!==(l[0]?.rotation??0)),u=(l[0]?.rotation??0)!==0&&l.length!==o.length,p=o.some(v=>va.includes(v.type)),m=((v,f,Q,k,b,x)=>{const{borders:g}=f.computed,{borderX:w,borderHeight:L,borderY:R,borderWidth:V,isXinverted:C,isYinverted:Z}=$e(v,f,Q,k,b,x);return{newBorderX:w,newBorderY:R,newBorderWidth:V,newBorderHeight:L,widthMultiplier:(V-2*k.selectionPadding)/(g.width-2*k.selectionPadding||1),heightMultiplier:(L-2*k.selectionPadding)/(g.height-2*k.selectionPadding||1),isXinverted:C,isYinverted:Z,groupCenter:[w+V/2,R+L/2],rotation:f.rotation??0,settings:k,originalBorders:g}})(t,r,s,a,i||!d||p||u,c);return o.map(v=>{switch(v.type){case"rect":case"square":return((f,Q,k)=>{const{isXinverted:b,isYinverted:x,settings:g,widthMultiplier:w,heightMultiplier:L}=k,R=(b||x)&&!(b&&x)&&(f.rotation??0)!==0&&Q.rotation!==f.rotation,V=Ye(f,Q,k),C=(f.width||1)*w,Z=(f.height||1)*L,A=Xe(k,V.x,V.y,C,Z);return St({...f,width:C,height:Z,x:A[0]-C/2,y:A[1]-Z/2,rotation:R?-(f.rotation??0):f.rotation??0},g)})(v,r,m);case"picture":return((f,Q,k)=>{const{isXinverted:b,isYinverted:x,settings:g,widthMultiplier:w,heightMultiplier:L}=k,R=Ye(f,Q,k),V=(f.width===0||f.height===0?f.ratio??1:f.width)*w,C=(f.width===0||f.height===0?f.ratio??1:f.height)*L,Z=Xe(k,R.x,R.y,V,C),A=(b||x)&&!(b&&x)&&(f.rotation??0)!==0&&Q.rotation!==f.rotation;return Mt({...f,width:V,height:C,x:Z[0]-V/2,y:Z[1]-C/2,flipX:b?!f.flipX:!!f.flipX,flipY:x?!f.flipY:!!f.flipY,rotation:A?-(f.rotation??0):f.rotation??0},g)})(v,r,m);case"text":return((f,Q,k,b)=>{const{isXinverted:x,isYinverted:g,settings:w,widthMultiplier:L,heightMultiplier:R}=b,V=(x||g)&&!(x&&g)&&(Q.rotation??0)!==0&&k.rotation!==Q.rotation,C=Ye(Q,k,b),Z=(Q.width===0||Q.height===0?Q.ratio??1:Q.width)*L,A=(Q.width===0||Q.height===0?Q.ratio??1:Q.height)*R,H=Xe(b,C.x,C.y,Z,A),B=kt({...Q,width:Z,height:A,x:H[0]-Z/2,y:H[1]-A/2,flipX:x?!Q.flipX:!!Q.flipX,flipY:g?!Q.flipY:!!Q.flipY,rotation:V?-(Q.rotation??0):Q.rotation??0},w);return{...B,fontSize:Pt(f,B.value,B.width,B.style?.fontBold??!1,B.style?.fontItalic??!1,B.style?.fontFamily)}})(e,v,r,m);case"ellipse":return((f,Q,k)=>{const{isXinverted:b,isYinverted:x,settings:g,widthMultiplier:w,heightMultiplier:L}=k,R=(b||x)&&!(b&&x)&&(f.rotation??0)!==0&&Q.rotation!==f.rotation,V=Ye(f,Q,k),C=(f.radiusX||.5)*w,Z=(f.radiusY||.5)*L,A=Xe(k,V.x,V.y,2*C,2*Z);return wt({...f,radiusX:C,radiusY:Z,x:A[0],y:A[1],rotation:R?-(f.rotation??0):f.rotation??0},g)})(v,r,m);case"circle":return((f,Q,k)=>{const b=Ye(f,Q,k),x=(f.radius||.5)*k.widthMultiplier,g=Xe(k,b.x,b.y,2*x,2*x);return Qt({...f,radius:x,x:g[0],y:g[1]},k.settings)})(v,r,m);case"brush":return((f,Q,k)=>{const{isXinverted:b,isYinverted:x,settings:g,widthMultiplier:w,heightMultiplier:L}=k,R=Gt({...f,scaleX:1,scaleY:1},g),V=R.width-2*g.selectionPadding,C=R.height-2*g.selectionPadding,Z=f.scaleX??1?(f.scaleX??1)*w:w/V,A=f.scaleY??1?(f.scaleY??1)*L:L/C,H=V*Z,B=C*A,D=Ye(f,Q,k),I=Xe(k,D.x,D.y,H,B),X=be(I[0]-H/2-f.computed.borders.x-g.selectionPadding)+(b?2*f.computed.borders.x+R.width:0),$=be(I[1]-B/2-f.computed.borders.y-g.selectionPadding)+(x?2*f.computed.borders.y+R.height:0),z=(b||x)&&!(b&&x)&&(f.rotation??0)!==0&&Q.rotation!==f.rotation;return at({...f,points:f.points.map(S=>S.map(([M,P])=>[b?-M+X:M+X,x?-P+$:P+$])),scaleX:Z,scaleY:A,rotation:z?-(f.rotation??0):f.rotation??0},k.settings)})(v,r,m);case"line":case"polygon":case"curve":return Wa(v,r,m);default:return Zs(e,t,v,s,a,i,c)}})},Hs=(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,i])=>[a+t,i+n])},s);case"brush":return Ee({...e,points:e.points.map(a=>a.map(([i,c])=>[i+t,c+n]))},s);default:return e}},zs=(e,t,n,s,a)=>{const i=t.computed.borders,c=((l,d)=>d?[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(i.x+s.selectionPadding+c[0],s)-(i.x+s.selectionPadding),o=c[1]===0?0:ge(i.y+s.selectionPadding+c[1],s)-(i.y+s.selectionPadding);return U(t).map(l=>Hs(l,r,o,s))},Ee=(e,t)=>{switch(e.type){case"rect":case"square":return ka(e,t);case"ellipse":return Aa(e,t);case"circle":return Va(e,t);case"picture":return Na(e,t);case"text":return Oa(e,t);case"line":return Ia(e,t);case"polygon":return Qs(e,t);case"curve":return ws(e,t);case"brush":return ya(e,t);default:return e}},Ts=({ctx:e,shape:t,settings:n,selectionWidth:s,selectionColor:a,hoverMode:i,selectionMode:c,withAnchors:r=!0})=>{switch(n.debug&&((o,l,d,u)=>{l.selection&&u.debug&&(o.save(),o.scale(u.canvasSize.scaleRatio,u.canvasSize.scaleRatio),o.translate(u.canvasOffset[0],u.canvasOffset[1]),xe(o,{fillColor:"transparent",strokeColor:"green",lineWidth:d/u.canvasSize.scaleRatio}),o.strokeRect(l.computed.boundingBox.x,l.computed.boundingBox.y,l.computed.boundingBox.width,l.computed.boundingBox.height),o.restore())})(e,t,s,n),t.type){case"rect":case"square":case"circle":case"ellipse":case"picture":case"text":case"brush":((o,l,d,u,p,m)=>{if(l.selection&&(st(o,p,l.rotation,l.computed.center),p.debug&&(xe(o,{fillColor:"transparent",strokeColor:"red",lineWidth:u/p.canvasSize.scaleRatio}),o.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(o,{fillColor:"transparent",strokeColor:d,lineWidth:u/p.canvasSize.scaleRatio}),l.selection.shapePath?o.stroke(l.selection.shapePath):o.stroke(l.selection.border),m&&!l.locked)){l.selection.shapePath&&o.stroke(l.selection.border),l.selection.line&&o.stroke(l.selection.line),xe(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/p.canvasSize.scaleRatio,shadowColor:d,shadowBlur:0});for(const v of l.selection.anchors)o.fill(v),o.stroke(v)}})(e,t,a,s,n,r);break;case"group":((o,l,d,u,p,m,v)=>{if(l.selection&&(l.shapes.forEach(f=>{xe(o,{fillColor:"transparent",strokeColor:d,lineWidth:u/m.canvasSize.scaleRatio}),st(o,m,f.rotation,f.computed.center),f.selection?.shapePath&&o.stroke(f.selection.shapePath),o.restore()}),p.mode!=="rotate"&&(st(o,m,l.rotation,l.computed.center),m.debug&&(xe(o,{fillColor:"transparent",strokeColor:"red",lineWidth:u/m.canvasSize.scaleRatio}),o.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(o,{fillColor:"transparent",strokeColor:d,lineWidth:u/m.canvasSize.scaleRatio}),v&&!l.locked))){o.stroke(l.selection.border),l.selection.line&&o.stroke(l.selection.line),xe(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/m.canvasSize.scaleRatio});for(const f of l.selection.anchors)o.fill(f),o.stroke(f)}})(e,t,a,s,c,n,r);break;case"polygon":case"line":case"curve":(({ctx:o,shape:l,withAnchors:d,selectionWidth:u,selectionColor:p,hoverMode:m,settings:v})=>{if(l.selection&&(st(o,v,l.rotation,l.computed.center),v.debug&&(xe(o,{fillColor:"transparent",strokeColor:"red",lineWidth:u/v.canvasSize.scaleRatio}),o.strokeRect(l.computed.outerBorders.x,l.computed.outerBorders.y,l.computed.outerBorders.width,l.computed.outerBorders.height)),xe(o,{fillColor:"transparent",strokeColor:p,lineWidth:u/v.canvasSize.scaleRatio}),l.selection.shapePath&&o.stroke(l.selection.shapePath),d&&!l.locked)){xe(o,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/v.canvasSize.scaleRatio,shadowColor:p,shadowBlur:0});for(let f=0;f<l.selection.anchors.length;f++){const Q=l.selection.anchors[f];m.mode==="resize"&&m.anchor===f?(o.shadowBlur=10,o.fill(Q),o.shadowBlur=0):o.fill(Q),o.stroke(Q)}}})({ctx:e,shape:t,withAnchors:r,selectionWidth:s,selectionColor:a,hoverMode:i,settings:n})}e.restore()},Ua=({ctx:e,selectionFrame:t,settings:n})=>{st(e,n),((s,a,i)=>{xe(s,{fillColor:"rgba(170,170,170, 0.1)",strokeColor:"rgb(170,170,170)",lineWidth:1/i.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()},ln=e=>e.filter(t=>t!=null),As=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,o]=c.split(" ");t.setAttribute("width",r??"300"),t.setAttribute("height",o??"300"),a=new XMLSerializer().serializeToString(t)}const i=new Blob([a],{type:"image/svg+xml"});return URL.createObjectURL(i)},Es=e=>(e instanceof File?e.name:e).includes(".svg"),Rs=e=>Es(e)?fetch(e).then(t=>t.text()).then(t=>As(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),Ds=(e,t)=>{const n=document.createElement("a");n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},qa=e=>e.src.includes("<svg")?e.src:(t=>{const n=document.createElement("canvas");n.width=t.width,n.height=t.height;const s=n.getContext("2d");return s?(s.drawImage(t,0,0),n.toDataURL("image/png")):""})(e.img),cn=({shapes:e,settings:t})=>{const n=document.createElement("canvas"),s=n.getContext("2d");if(!s)throw new Error("No context found for canvas");const{realHeight:a,realWidth:i}=t.canvasSize;n.width=i,n.height=a,s.clearRect(0,0,i,a),ns(s);for(let c=e.length-1;c>=0;c--)Vs(s,e[c],t);return n.toDataURL("image/png")},Is=({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)),i=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)),o={...t,canvasOffset:[-a,-c],canvasZoom:1,canvasSize:{realWidth:i-a,realHeight:r-c,width:i-a,height:r-c,scaleRatio:1,scaleRatioWithNoZoom:1}};return cn({shapes:e,settings:o})}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 cn({shapes:e,settings:a})}const s={...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}};return cn({shapes:e,settings:s})},Ga=(e,t,n)=>{return a=dn(e,t,n),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(a))}`;var a},_a=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:qa(n)}))},dn=(e,t,n)=>({shapes:_a(e),config:{width:t,height:n}}),Ws=(e,t)=>Ee({...e,id:le(`${e.type}_`)},t),Ka=(e,t,n,s)=>{const a=y.useRef([]),i=y.useRef({dataChanged:[]}),[c,r]=y.useState(void 0),[o,l]=y.useState(void 0),[d,u]=y.useState(void 0),[p,m]=y.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),v=p.cursor>0,f=p.cursor<p.states.length-1,Q=a.current.length>0,k=y.useCallback(()=>{m(S=>es(S.states[S.cursor]?.shapes,a.current)?S:{states:[...S.states.slice(0,S.cursor+1),{shapes:a.current,selectedShape:o,source:"user"}],cursor:S.cursor+1})},[o]),b=y.useCallback(S=>{a.current=[...S,...a.current]},[]),x=y.useCallback(S=>{a.current=a.current.flatMap(M=>{const P=S.find(T=>T.id===M.id);return P?[{...P,id:le(`${M.type}_`)},M]:M})},[]),g=y.useCallback((S,M,P,T)=>{if(S.target&&"className"in S.target&&![Gn,_n].includes(S.target.className)||!T)return void u(void 0);const j=a.current.find(O=>U(o)?.map(W=>W.id).includes(O.id)?!!lt(M,O,P,e):!!ms(M,O,P,e));u(j)},[e,o]),w=y.useCallback(async(S,M=300,P=300)=>{const T=await Fa(S,M,P,e);return b([T]),k(),T},[b,k,e]),L=y.useCallback((S,M=!1)=>{a.current=a.current.map(P=>S.find(T=>T.id===P.id)??P),l(P=>P&&ce(U(P).map(T=>S.find(j=>j.id===T.id)??T),e)),M&&k()},[k,e]),R=y.useCallback(S=>{const M=S.map(P=>Xt(["chosen"],P));a.current=M,k()},[k]),V=y.useCallback(S=>{const M=new Set(S.map(P=>P.id));l(P=>{const T=U(P).map(j=>j.id);return T&&M.size&&T.find(j=>M.has(j))?void 0:P}),a.current=a.current.filter(P=>!M?.has(P.id)),k()},[k]),C=y.useCallback(S=>{m(M=>{const P=S(M);return a.current=M.states[P]?.shapes??[],l(M.states[P]?.selectedShape),Qe("cursor",P,M)})},[]),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,M)=>{l(void 0),a.current=S,m(P=>M.clearHistory?{states:[{shapes:S,selectedShape:void 0,source:M.source}],cursor:0}:{states:[...P.states.slice(0,P.cursor+1),{shapes:S,selectedShape:void 0,source:M.source}],cursor:P.cursor+1})},[]),B=y.useCallback((S,M)=>{const P=a.current,T=P.findIndex(E=>E.id===S),j=P.findIndex(E=>E.id===M);var O,W,F;R((O=P,F=j,(W=T)<0||F<0||W>O.length-1||F>O.length-1?O:W<F?[...O.slice(0,W),...O.slice(W+1,F+1),O[W],...O.slice(F+1,O.length)]:[...O.slice(0,F),O[W],...O.slice(F,W),...O.slice(W+1,O.length)]))},[R]),D=y.useCallback(S=>{const M=a.current,P=new Set(S.map(j=>j.id)),T=M.map(j=>P.has(j.id)?Qe("visible",j.visible===!1,j):j);l(hs(j=>Qe("visible",j.visible===!1,j),e)),R(T)},[R,e]),I=y.useCallback(S=>{const M=a.current,P=new Set(S.map(j=>j.id)),T=M.map(j=>P.has(j.id)?Qe("locked",!j.locked,j):j);l(hs(j=>Qe("locked",!j.locked,j),e)),R(T)},[R,e]),X=y.useCallback((S,M)=>{i.current.hasOwnProperty(S)&&(i.current[S]=[...i.current[S],M])},[]),$=y.useCallback((S,M)=>{if(i.current.hasOwnProperty(S))if(M){const P=i.current[S].indexOf(M);i.current[S]=[...i.current[S].slice(0,P),...i.current[S].slice(P+1)]}else i.current[S]=[]},[]);y.useEffect(()=>{const S=p.states[p.cursor],M=dn(S.shapes,t,n);for(const P of i.current.dataChanged)P(M,S.source)},[t,n,p]),y.useEffect(()=>{a.current=a.current.map(S=>Ee(S,e)),l(S=>S===void 0?void 0:ce(U(S).map(M=>Ee(M,e)),e))},[e]);const z=y.useCallback((S,M)=>{r(P=>{const T=[P?.frame[0]??[M[0],M[1]],[M[0],M[1]]],j=a.current.filter(W=>((F,E,_)=>{const{borders:ie,center:se,boundingBox:q}=E.computed,N=Math.min(_[0][0],_[1][0]),de=Math.max(_[0][0],_[1][0]),te=Math.min(_[0][1],_[1][1]),fe={x:N,y:te,width:de-N,height:Math.max(_[0][1],_[1][1])-te},ve=tn(q,fe);if(!ve)return!1;if(ie.width<=1||ie.height<=1||!E.path)return!0;if(F.lineWidth=(E.style?.lineWidth??0)+10,E.type==="brush"){const K=E.points.flat(),ue=Math.min(...K.map(ee=>ee[0])),Y=Math.min(...K.map(ee=>ee[1]));for(const ee of E.points){if(ee.length<1)break;if(ee.length<2){const Me=Ve(ee[0],ue,Y,E.scaleX,E.scaleY);if(ss(ve,{x:Me[0],y:Me[1],radius:(E.style?.lineWidth??1)/2}))return!0}for(let Me=0;Me<ee.length-1;Me++){const ke=en(Ve(ee[Me],ue,Y,E.scaleX,E.scaleY),E.rotation??0,se),ae=en(Ve(ee[Me+1],ue,Y,E.scaleX,E.scaleY),E.rotation??0,se),Le=tn({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(Le){const qe=new Path2D;if(qe.moveTo(...ke),qe.lineTo(...ae),ys({ctx:F,path:qe,rect:Le,offset:10,center:se,checkFill:!1}))return!0}}}return!1}const me=E.style?.fillColor&&E.style?.fillColor!=="transparent"||["picture","text"].includes(E.type);return ys({ctx:F,path:E.path,rect:ve,offset:10,center:se,rotation:E.rotation??0,checkFill:me})})(S,W,T)),O=ce(j,e);return l(s?ce(ps(P?.oldSelection,j),e):O),{oldSelection:P?.oldSelection,frame:T}})},[e,s]);return{registerEvent:X,unregisterEvent:$,shapesRef:a,selectedShape:o,hoveredShape:d,selectionFrame:c,setSelectionFrame:r,refreshSelectedShapes:z,addShapes:b,duplicateShapes:x,addPictureShape:w,moveShapes:B,saveShapes:k,setSelectedShape:l,refreshHoveredShape:g,toggleShapeVisibility:D,toggleShapeLock:I,removeShape:V,updateShape:L,backwardShape:Z,forwardShape:A,clearShapes:H,canGoBackward:v,canGoForward:f,canClear:Q}},Ns=e=>{const t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];var s,a;return{diff:os(t,n),center:(a=n,[((s=t)[0]+a[0])/2,(s[1]+a[1])/2])}},Ja=({canvasElt:e,canvasTransformation:t,canvasSize:n,size:s,setCanvasTransformation:a})=>{const i=y.useRef([]),[c,r]=y.useState(i.current.length>0),o=y.useRef(null),l=y.useRef(t);l.current=t;const d=y.useCallback(({startDiff:u,startZoom:p,startCenter:m,startOffset:v,currentDiff:f,currentCenter:Q,isMoving:k,isZooming:b})=>{if(!e||!f||!u)return;const x=(({canvasBoundingRect:g,canvasSize:w,size:L,startDiff:R,startZoom:V,startCenter:C,startOffset:Z,currentDiff:A,currentCenter:H,isMoving:B,isZooming:D})=>{const I=D?ze(A/R*V,we[0],we[we.length-1]):V,X=B?[Z[0]+(H[0]-C[0])*(w.width/g.width)/w.scaleRatio/V,Z[1]+(H[1]-C[1])*(w.height/g.height)/w.scaleRatio/V]:[Z[0],Z[1]],$=[(H[0]-g.left)/w.scaleRatio,(H[1]-g.top)/w.scaleRatio];return an({size:L,canvasSize:w,currentOffset:X,currentZoom:V,zoom:I,centerPoint:$})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:n,size:s,startDiff:u,startZoom:p,startCenter:m,startOffset:v,currentDiff:f,currentCenter:Q,isMoving:k,isZooming:b});a(x)},[e,n,s,a]);y.useEffect(()=>{if(!e)return;const u=p=>{if(i.current=[...i.current,p],r(i.current.length>0),i.current.length===2){p.stopPropagation();const{diff:m,center:v}=Ns(i.current);o.current={startDiff:m,startCenter:v,startZoom:l.current.zoom,startOffset:l.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",u),()=>{e.removeEventListener("pointerdown",u)}},[e]),y.useEffect(()=>{if(!c)return;const u=m=>{const v=i.current.findIndex(f=>f.pointerId===m.pointerId);if(v>-1&&(i.current[v]=m),i.current.length===2&&o.current){const{diff:f,center:Q}=Ns(i.current),k=o.current.isZooming||((x,g)=>Math.abs(x-g.startDiff)>30)(f,o.current),b=o.current.isMoving||k||((x,g)=>Math.abs(os(x,g.startCenter))>10)(Q,o.current);o.current={...o.current,isMoving:b,isZooming:k},d({...o.current,currentDiff:f,currentCenter:Q})}},p=m=>{i.current=i.current.filter(v=>v.pointerId!==m.pointerId),r(i.current.length>0)};return document.addEventListener("pointermove",u),document.addEventListener("pointerup",p),document.addEventListener("pointerout",p),document.addEventListener("pointercancel",p),document.addEventListener("pointerleave",p),()=>{document.removeEventListener("pointermove",u),document.removeEventListener("pointerup",p),document.removeEventListener("pointerout",p),document.removeEventListener("pointercancel",p),document.removeEventListener("pointerleave",p)}},[c,d])},Fs={offset:[0,0],zoom:1},ei=({canvasSize:e,size:t,zoomEnabled:n,canvasElt:s})=>{const[a,i]=y.useState(Fs),c=y.useRef(0),r=y.useCallback(d=>{i(({zoom:u})=>sn({zoom:u,size:t,canvasSize:e,newOffset:d}))},[e,t]),o=y.useCallback(d=>{i(({offset:u,zoom:p})=>(({size:m,canvasSize:v,currentOffset:f,currentZoom:Q,action:k})=>{const b=k==="default"?we[4]:k==="zoom"?we[ze(we.length-1-we.slice(0).reverse().findIndex(g=>g<=Q)+1,0,we.length-1)]:we[ze(we.findIndex(g=>g>=Q)-1,0,we.length-1)],x=[v.realWidth/2,v.realHeight/2];return an({size:m,canvasSize:v,currentOffset:f,currentZoom:Q,zoom:b,centerPoint:x})})({size:t,canvasSize:e,currentOffset:u,currentZoom:p,action:d}))},[e,t]);Ja({canvasElt:s,canvasTransformation:a,canvasSize:e,size:t,setCanvasTransformation:i});const l=y.useCallback(()=>{i(Fs)},[]);return y.useEffect(()=>{if(!n||!s)return;const d=u=>{const p=u.ctrlKey,{deltaX:m,deltaY:v}=((b,x)=>{const g=Math.abs(b.deltaY)<50&&x<50,w=b.ctrlKey,L=ts()&&g&&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 L?{deltaX:5*b.deltaX,deltaY:5*b.deltaY}:{deltaX:b.deltaX,deltaY:b.deltaY}}})(u,u.timeStamp-c.current);if(c.current=u.timeStamp,p){u.preventDefault();const b=fs(u,s,e);return void i(({offset:x,zoom:g})=>(({size:w,canvasSize:L,currentOffset:R,currentZoom:V,delta:C,centerPoint:Z})=>{const A=ze(V*(1-C/1e3),we[0],we[we.length-1]);return an({size:w,canvasSize:L,currentOffset:R,currentZoom:V,zoom:A,centerPoint:Z})})({size:t,canvasSize:e,currentOffset:x,currentZoom:g,delta:v,centerPoint:b}))}const f=u.shiftKey,[Q,k]=f?[v,m]:[m,v];i(({offset:b,zoom:x})=>{const g=[b[0]-Q/x,b[1]-k/x],w=sn({zoom:x,size:t,canvasSize:e,newOffset:g});return w.offset[0]===b[0]&&w.offset[1]===b[1]||u.preventDefault(),w})};return s.addEventListener("wheel",d,{passive:!1}),()=>{s.removeEventListener("wheel",d)}},[s,t,e,n]),{setCanvasTransformation:i,setCanvasOffset:r,setCanvasZoom:o,resetZoom:l,canvasTransformation:a}},Os=(e,t=!1)=>{const n=(a,i)=>{if(Array.isArray(a))return i},s=e.map(a=>{if(typeof a!="object")return null;switch(a.type){case"brush":return He(n,An,a);case"circle":return He(n,Nn,a);case"curve":return He(n,Dn,a);case"ellipse":return He(n,Fn,a);case"line":return He(n,En,a);case"polygon":return He(n,Rn,a);case"rect":return He(n,In,a);case"square":return He(n,Wn,a);case"text":return He(n,On,a)}return null});return ln(t?[...s,Ft]:s)},ti=({addShapes:e,drawCanvasRef:t,setActiveTool:n,refreshHoveredShape:s,shapes:a,selectionMode:i,activeTool:c,isInsideComponent:r,setCanvasOffset:o,selectedShape:l,canvasOffsetStartData:d,refreshSelectedShapes:u,setSelectedShape:p,setSelectionFrame:m,setCanvasOffsetStartData:v,updateSingleShape:f,duplicateShapes:Q,saveShapes:k,setSelectionMode:b,setCanvasMoveAcceleration:x,settings:g,isShiftPressed:w,isAltPressed:L,withFrameSelection:R,isSpacePressed:V})=>{const[C,Z]=y.useState({mode:"default"}),{registerDoubleClickEvent:A,unRegisterDoubleClickEvent:H}=(()=>{const S=y.useRef(void 0),M=y.useRef(void 0),P=T=>{const j=Date.now();S.current&&j<S.current+300&&M.current?.(T),S.current=Date.now()};return{registerDoubleClickEvent:(T,j)=>{M.current=j,T.addEventListener("click",P),T.addEventListener("touchend",P)},unRegisterDoubleClickEvent:T=>{T.removeEventListener("click",P),T.removeEventListener("touchend",P)}}})(),B=y.useRef(null);B.current=S=>((M,P,T,j,O,W,F,E,_,ie,se,q,N,de,te,fe,ve)=>{if(rt(M)&&M.touches.length>1)return;const me=P.current?.getContext("2d");if(!me)return;const K=ot(M,P.current,N);if(j.mode==="selectionFrame"){q(me,K,N);const Y=fs(M,P.current,N.canvasSize);return void ve([Math.ceil(ze(Y[0]*N.canvasZoom<50?Y[0]*N.canvasZoom-50:Y[0]*N.canvasZoom>N.canvasSize.width/N.canvasSize.scaleRatioWithNoZoom-50?Y[0]*N.canvasZoom-(N.canvasSize.width/N.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/N.canvasZoom),Math.ceil(ze(Y[1]*N.canvasZoom<50?Y[1]*N.canvasZoom-50:Y[1]*N.canvasZoom>N.canvasSize.height/N.canvasSize.scaleRatioWithNoZoom-50?Y[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(j.mode==="preview"){const Y=U(T)[0];if(Y?.type==="curve"){const ee=Cs(Y,K,N,!0);return void fe(ce([ee],N))}if(Y?.type==="polygon"){const ee=bs(Y,K,N,!0);return void fe(ce([ee],N))}}const ue=pt(K,N);if(rt(M)||E(M,me,K,ue),T===void 0||T.locked)F({mode:"default",outOfView:!ue});else{if(j.mode==="default"||j.mode==="textedition"){if(!ue)return void F({mode:"default"});F(lt(me,T,K,N,!0)||{mode:"default"})}else{const Y=P.current?.getContext("2d");if(!Y)return;const ee=Sa(Y,T,K,j,N,de,te);_(U(ee))}j.mode==="translate"&&te&&!j.hasBeenDuplicated&&(O({...j,hasBeenDuplicated:!0}),ie(U(j.originalShape)))}})(S,t,l,i,b,d,Z,s,f,Q,o,u,g,w,L,p,x),y.useEffect(()=>{if(r){const S=M=>B.current?.(M);return document.addEventListener("mousemove",S),document.addEventListener("touchmove",S),()=>{document.removeEventListener("mousemove",S),document.removeEventListener("touchmove",S)}}},[r]);const{isBrushShapeDoneOnMouseUp:D}=g,I=y.useRef(null);I.current=S=>{if(rt(S)&&S.touches.length>1)return;const M=t.current?.getContext("2d");if(!M)return;if("button"in S&&S.button===2)return p(void 0),n(De),b({mode:"default"}),void m(void 0);if(d)return void v(void 0);if(i.mode==="textedition"||i.mode==="preview")return;const P=ot(S,t.current,g);if(i.mode==="translate"&&Date.now()-i.dateStart<=500&&P[0]===i.cursorStartPosition[0]&&P[1]===i.cursorStartPosition[1]){if(!(S.ctrlKey||S.shiftKey||S.metaKey)){const{shape:T}=us(M,a,P,g,void 0,rt(S),R,!1);p(T)}return b({mode:"default"}),m(void 0),void k()}i.mode!=="default"&&(i.mode==="brush"&&D&&p(void 0),b({mode:"default"}),m(void 0),k())},y.useEffect(()=>{if(r){const S=M=>I.current?.(M);return document.addEventListener("mouseup",S),document.addEventListener("touchend",S),()=>{document.removeEventListener("mouseup",S),document.removeEventListener("touchend",S)}}},[r]);const X=!g.features.edition&&g.features.zoom,$=!g.features.edition&&!g.features.zoom,z=y.useRef(null);return z.current=(S,M,P)=>{if(S.preventDefault(),rt(S)&&S.touches.length>1)return;const T=M?.getContext("2d");if(!T)return;M.focus();const j=ot(S,t.current,g),O="button"in S&&S.button===1;if(!("button"in S&&S.button===2)){if(O||P||c.type==="move")v({start:j,originalOffset:g.canvasOffset});else if(!X){if(!pt(j,g))return p(void 0),void b({mode:"default"});if(c.type==="selection"){const W=S.ctrlKey||S.shiftKey||S.metaKey,{shape:F,mode:E}=us(T,a,j,g,l,rt(S),R,W);p(F),b(E),E.mode==="selectionFrame"&&m({oldSelection:F,frame:[[j[0],j[1]],[j[0],j[1]]]})}else if(qn.some(W=>W===c.type)){const W=U(l)[0],F=t.current?.getContext("2d");if(!F)return;if(c.type==="brush"){if(W?.type==="brush"){const E=((_,ie,se)=>{const q={..._,points:Qe(_.points.length,[[Math.round(ie[0]),Math.round(ie[1])]],_.points)};return at(q,se)})(W,j,g);f([E])}else{const E=js(F,c,j,g);if(!E)return;e([E]),p(ce([E],g))}b({mode:"brush"})}else if(i.mode!=="preview"||W?.type!=="polygon"&&W?.type!=="curve"){if(c.type!=="picture"){const E=js(F,c,j,g);if(!E)return;e([E]);const _=ce([E],g);p(_),E.type==="polygon"||E.type==="curve"?b({mode:"preview"}):(n(De),b({mode:"resize",cursorStartPosition:[j[0]+g.selectionPadding,j[1]+g.selectionPadding],originalShape:_,anchor:E.type==="line"?0:[1,1]}))}}else{const E=W.type==="polygon"?bs(W,j,g):Cs(W,j,g);p(ce([E],g)),f([E],!0)}}}}},y.useEffect(()=>{if($)return;const S=t.current;if(!S)return;const M=P=>z.current?.(P,S,V);return S.addEventListener("mousedown",M,{passive:!1}),S.addEventListener("touchstart",M,{passive:!1}),()=>{S.removeEventListener("mousedown",M),S.removeEventListener("touchstart",M)}},[$,t,V]),y.useEffect(()=>{const S=t.current,M=t.current?.getContext("2d");if(!(!S||!M))return r?(A(S,P=>{if(c.type==="selection"){if(U(l).length!==1)return;const T=U(l)[0];if(T?.type==="text"){const j=ot(P,t.current,g);return pt(j,g)?void(lt(M,l,j,g)&&b({mode:"textedition",defaultValue:T.value})):void 0}if(T?.type==="polygon"){const j=ot(P,t.current,g);if(!pt(j,g))return;const O=vs(M,T,j,g);return void(O&&f([Za(T,O.lineIndex,j,g)]))}if(T?.type==="curve"){const j=ot(P,t.current,g);if(!pt(j,g))return;const O=((W,F,E,_,ie=50)=>{if(F.locked||F.points.length<2)return!1;if(F.points.length<3)return vs(W,F,E,_,ie);const{center:se}=F.computed,q=Ae(E,F.rotation??0,se);W.lineWidth=(F.style?.lineWidth??0)+ie/_.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:Y}=Kt(fe,ve,me,K);if(de.bezierCurveTo(ue[0],ue[1],Y[0],Y[1],me[0],me[1]),W.isPointInStroke(de,q[0],q[1]))return{lineIndex:te-1}}return!1})(M,T,j,g);return void(O&&f([za(T,O.lineIndex,j,g)]))}}}),()=>{H(S)}):void 0},[f,A,H,r,t,c,l,b,g]),{hoverMode:C}},Bs=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>Bs(t)).join(""):e.nodeValue??"",ni=({disabled:e=!1,shape:t,defaultValue:n,updateValue:s,saveShapes:a,settings:i})=>{const c=y.useRef(null),r=y.useRef(a);y.useEffect(()=>{if(!c.current)return;const d=c.current,u=p=>{p.preventDefault();const m=p.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,m)};d.addEventListener("paste",u),d.innerText="";for(const p of n){const m=document.createElement("div");p===""?m.innerHTML="<br/>":m.innerText=p,d.appendChild(m)}return d.focus(),()=>{d.removeEventListener("paste",u)}},[n]),y.useEffect(()=>{const d=r.current;return()=>{d()}},[]);const o=y.useMemo(()=>{const{borders:d,center:u}=t.computed;return ne({point:[d.x,d.y],rotation:-(t.rotation??0),origin:u})},[t]),l=[`translate3D(${(o[0]+i.canvasOffset[0])*i.canvasSize.scaleRatio}px, ${(o[1]+i.canvasOffset[1])*i.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:d=>{const u=Array.from(d.target.childNodes).map(p=>Bs(p));s(u)},style:{"--react-paint-editor-toolbox-edittextbox-transform":l,"--react-paint-editor-toolbox-edittextbox-fontsize":t.fontSize*i.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-padding":i.selectionPadding*i.canvasSize.scaleRatio+"px","--react-paint-editor-toolbox-edittextbox-color":t.style?.strokeColor??"inherit","--react-paint-editor-toolbox-edittextbox-opacity":(t.style?.opacity??100)/100,"--react-paint-editor-toolbox-edittextbox-fontfamily":t.style?.fontFamily??ut}})},si=(e,t,n,s,a)=>{ns(e),((i,c)=>{const{canvasZoom:r,size:o,canvasSize:{width:l,height:d}}=c;if(o!=="fixed"||r>=1)return;i.fillStyle="#f5f5f5",i.fillRect(0,0,l,d);const u=Ss(c);i.clearRect(u.x,u.y,u.width,u.height),xs(i,c)})(e,n),((i,c)=>{const{canvasSize:{width:r,height:o},gridGap:l,canvasOffset:d,canvasSize:{scaleRatio:u}}=c;if(!l)return;i.strokeStyle="rgb(220,220,220)",i.lineWidth=1,i.save(),i.scale(u,u),i.beginPath();const p=d[0]%l,m=d[1]%l,v=Math.ceil(r/u/l)+2,f=Math.ceil(o/u/l)+2;for(let Q=-5;Q<v;Q++)i.moveTo(p+(Q+1)*l,m-l),i.lineTo(p+(Q+1)*l,m+o/u+l);for(let Q=-5;Q<f;Q++)i.moveTo(p-l,m+(Q+1)*l),i.lineTo(p+r/u+l,m+(Q+1)*l);i.stroke(),i.restore()})(e,n);for(let i=s.length-1;i>=0;i--)t.mode==="textedition"&&s[i]===a||Vs(e,U(a).find(c=>c.id===s[i].id)??s[i],n)},ai=y.forwardRef(({canGrow:e,shapes:t,duplicateShapes:n,addShapes:s,updateSingleShape:a,selectedShape:i,setSelectedShape:c,setSelectionFrame:r,hoveredShape:o,selectionFrame:l,refreshHoveredShape:d,refreshSelectedShapes:u,saveShapes:p,activeTool:m,setActiveTool:v,canvasOffsetStartData:f,setCanvasOffsetStartData:Q,setCanvasOffset:k,setCanvasMoveAcceleration:b,isInsideComponent:x,selectionMode:g,setSelectionMode:w,selectionWidth:L,selectionColor:R,settings:V,isEditMode:C,isShiftPressed:Z,isAltPressed:A,isSpacePressed:H,withFrameSelection:B,withSkeleton:D},I)=>{const X=y.useRef(null),$=y.useRef(null),z=V.canvasSize,S=C,M=C?0:-1;y.useImperativeHandle(I,()=>X.current);const{hoverMode:P}=ti({addShapes:s,drawCanvasRef:X,setActiveTool:v,shapes:t,selectionMode:g,activeTool:m,isInsideComponent:x,setCanvasOffset:k,selectedShape:i,canvasOffsetStartData:f,setCanvasOffsetStartData:Q,setSelectedShape:c,setSelectionFrame:r,refreshHoveredShape:d,refreshSelectedShapes:u,updateSingleShape:a,duplicateShapes:n,saveShapes:p,setSelectionMode:w,setCanvasMoveAcceleration:b,isShiftPressed:Z,isAltPressed:A,withFrameSelection:B,settings:V,isSpacePressed:H}),T=y.useCallback(O=>{const W=U(i)[0];if(W?.type!=="text")return;const F=X.current?.getContext("2d");if(!F)return;const E=Ee(Ya(F,W,O,V),V);a([E])},[a,i,V]),j=O=>{if(C)return O.preventDefault(),O.stopPropagation(),!1};return y.useEffect(()=>{const O=X.current?.getContext("2d");O&&window.requestAnimationFrame(()=>si(O,g,V,t,i))},[t,g,i,V]),y.useEffect(()=>{const O=$.current?.getContext("2d");O&&window.requestAnimationFrame(()=>((W,F,E,_,ie,se,q,N,de,te,fe)=>{W.reset(),xs(W,E),fe&&N&&!U(q).find(ve=>ve.id===N.id)&&_.type==="selection"&&F.mode==="default"&&Ts({ctx:W,shape:N,settings:E,selectionWidth:ie,selectionColor:se,hoverMode:de,selectionMode:F,withAnchors:!1}),q&&_.type!=="brush"&&Ts({ctx:W,shape:q,settings:E,selectionWidth:ie,selectionColor:se,hoverMode:de,selectionMode:F,withAnchors:F.mode!=="textedition"}),te&&Ua({ctx:W,selectionFrame:te,settings:E})})(O,g,V,m,L,R,i,o,P,l,D))},[o,P,l,g,i,m,V,L,R,D]),h.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":f?"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:Gn,ref:X,"data-grow":e,width:z.width,height:z.height,onContextMenu:j,tabIndex:M}),S&&h.jsx("canvas",{className:_n,ref:$,width:z.width,height:z.height,"data-grow":e,onContextMenu:j}),C&&g.mode==="textedition"&&U(i)[0]?.type==="text"&&h.jsx(ni,{disabled:!V.features.edition,shape:U(i)[0],defaultValue:g.defaultValue,updateValue:T,saveShapes:p,settings:V})]})})}),Ys="ArrowUp",Xs="ArrowDown",$s="ArrowLeft",Us="ArrowRight",ii="Delete",oi="Backspace",ri="Escape",qs="Shift",Gs="Alt",_s="Option",jt=" ",li="z",ci="Z",di="y",ui="Y",hi="+",pi="-",gi="0",Ks="copy",Js="paste",fi=({isInsideComponent:e,isInsideCanvas:t,selectedShape:n,isEditingText:s,settings:a,setSelectedShape:i,setActiveTool:c,setCanvasZoom:r,resetZoom:o,setSelectionMode:l,setSelectionFrame:d,removeShape:u,pasteShapes:p,updateShapes:m,backwardShape:v,forwardShape:f,setShiftPressed:Q,setAltPressed:k,setIsSpacePressed:b})=>{const[x,g]=y.useState(void 0);return y.useEffect(()=>{const w=C=>{n&&(s||(C.preventDefault(),g({...n})))},L=C=>{x&&(s||(C.preventDefault(),p(((Z,A)=>U(Z).map(H=>({...Hs(H,20,20,A),id:le(`${H.type}_`)})))(x,a))))},R=C=>{switch(C.key){case qs:Q(!1);break;case Gs:case _s:k(!1);break;case jt:b(!1)}},V=C=>{if(C.metaKey||C.ctrlKey){if(C.key===ci||C.key===li)return C.preventDefault(),C.stopPropagation(),void(C.shiftKey?f():v());if(!ts()&&(C.key===ui||C.key===di))return C.preventDefault(),C.stopPropagation(),void f();if(C.key===hi)return C.preventDefault(),C.stopPropagation(),void r("zoom");if(C.key===pi)return C.preventDefault(),C.stopPropagation(),void r("unzoom");if(C.key===gi)return C.preventDefault(),C.stopPropagation(),void o()}if(C.key===qs)return C.preventDefault(),C.stopPropagation(),void Q(!0);if(C.key===jt&&t)return C.preventDefault(),C.stopPropagation(),void b(!0);if(C.key===Gs||C.key===_s)return C.preventDefault(),C.stopPropagation(),void k(!0);if(!n)return;if(C.key===ri)return i(void 0),c(De),l({mode:"default"}),void d(void 0);if(s)return;const Z={[$s]:[a.gridGap?-a.gridGap:-1,0],[Us]:[a.gridGap?a.gridGap:1,0],[Xs]:[0,a.gridGap?a.gridGap:1],[Ys]:[0,a.gridGap?-a.gridGap:-1]};switch(C.key){case $s:case Us:case Xs:case Ys:C.preventDefault(),C.stopPropagation(),m(zs(Z[C.key],n,[0,0],a,!0));break;case ii:case oi:C.preventDefault(),C.stopPropagation(),u(U(n))}};if(e)return document.addEventListener("keydown",V),document.addEventListener("keyup",R),document.addEventListener(Ks,w),document.addEventListener(Js,L),()=>{document.removeEventListener("keydown",V),document.removeEventListener("keyup",R),document.removeEventListener(Ks,w),document.removeEventListener(Js,L)}},[e,t,x,s,n,a,m,u,i,p,v,f,Q,k,c,l,d,r,o,b]),{}},vi=({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":pa,"--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",{})]})})},mi="infos",yi=4e3,Si=({type:e,text:t,duration:n})=>{const[s,a]=y.useState(!1);return y.useEffect(()=>{const i=setTimeout(()=>{a(!0)},100),c=setTimeout(()=>{a(!1)},n-500-100);return()=>{clearTimeout(i),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})},xi=({snackbarList:e})=>h.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":ga},children:e.map(t=>h.jsx(Si,{...t},t.id))}),Qi=y.forwardRef((e,t)=>{const{hidden:n=!1,disabled:s=!1,selected:a=!1,icon:i,children:c,className:r="",title:o,onClick:l,...d}=e,u=s?-1:0,p=y.useRef(null);return y.useImperativeHandle(t,()=>p.current),h.jsxs("label",{className:`react-paint-editor-button ${r}`,title:o,onClick:l,"data-disabled":+s,"data-selected":+a,"data-hidden":+n,tabIndex:u,onKeyDown:m=>{m.key===jt&&(m.preventDefault(),m.stopPropagation())},onKeyUp:m=>{m.preventDefault(),m.stopPropagation(),m.key===jt&&p.current?.click()},children:[h.jsx("input",{ref:p,disabled:s,...d}),h.jsxs("span",{className:"react-paint-editor-button-content",children:[c&&h.jsx("span",{className:"react-paint-editor-button-children",children:c}),i&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:i}})]})]})}),G=y.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color")return h.jsx(Qi,{...e,ref:t});const{hidden:n=!1,disabled:s=!1,selected:a=!1,icon:i,children:c,type:r="button",className:o="",...l}=e;return h.jsx("button",{className:`react-paint-editor-button ${o}`,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}),i&&h.jsx("span",{className:"react-paint-editor-button-icon",dangerouslySetInnerHTML:{__html:i}})]})})}),Ue=({children:e,title:t="",className:n="",position:s="bottom",fitContainer:a=!1,alignment:i="center",style:c,...r})=>h.jsxs("div",{className:`react-paint-editor-panel ${n}`,"data-fitcontainer":a,"data-position":s,"data-alignment":i,style:{...c,"--react-paint-editor-panel-zindex":zn},...r,children:[t&&h.jsx("h3",{className:"react-paint-editor-panel-title",children:t}),e]}),bi=e=>{switch(e){case"brush":return xn;case"line":return Cn;case"polygon":return Wt;case"curve":return Mn;case"rect":case"square":return Dt;case"circle":case"ellipse":return It;case"text":return wn;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""}},wi=({disabled:e=!1,shape:t,selected:n,layoutDragging:s,toggleShapeVisibility:a,toggleShapeLock:i,setLayoutDragging:c,handleRemove:r,handleSelect:o,onMoveShapes:l})=>{const d=y.useRef(null),{isOver:u}=(({disabled:p=!1,ref:m,shape:v,layoutDragging:f,setLayoutDragging:Q,handleSelect:k,onMoveShapes:b})=>{const[x,g]=y.useState(!1);return y.useEffect(()=>{f||g(!1)},[f]),y.useEffect(()=>{const w=m.current;if(!w)return;const L=()=>{Q(void 0)},R=H=>(H.preventDefault&&H.preventDefault(),!1),V=H=>{k([v]),H.dataTransfer&&(H.dataTransfer.effectAllowed="move",H.dataTransfer.setData("draggableShapeId",v.id),Q(v.id))},C=()=>{f!==v.id&&g(!0)},Z=()=>{g(!1)},A=H=>(H.stopPropagation(),H.dataTransfer&&b(H.dataTransfer.getData("draggableShapeId"),v.id),!1);return p||(w.addEventListener("dragstart",V),w.addEventListener("dragend",L),w.addEventListener("dragover",R),w.addEventListener("dragenter",C),w.addEventListener("dragleave",Z),w.addEventListener("drop",A)),()=>{p||(w.removeEventListener("dragstart",V),w.removeEventListener("dragend",L),w.removeEventListener("dragover",R),w.removeEventListener("dragenter",C),w.removeEventListener("dragleave",Z),w.removeEventListener("drop",A))}},[p,m,v,Q,k,b,f]),{isOver:x}})({disabled:e,ref:d,shape:t,layoutDragging:s,setLayoutDragging:c,handleSelect:o,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":+u,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),o([t]))},"data-selected":+n,ref:d,tabIndex:-1,children:[h.jsx("span",{dangerouslySetInnerHTML:{__html:bi(t.type)}}),h.jsx("span",{children:t.id}),h.jsx("div",{className:"react-paint-editor-layouts-separator"}),h.jsx(G,{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(G,{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(),i([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(G,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:p=>{e||(p.preventDefault(),p.stopPropagation(),r([t]))},icon:Qn})]})},Ci=({gridFormat:e,setGridFormat:t,settings:n,shapes:s,removeShape:a,toggleShapeVisibility:i,toggleShapeLock:c,selectedShapes:r,moveShapes:o,selectShapes:l,isLayoutPanelShown:d})=>{const[u,p]=y.useState(void 0),m=!n.features.edition;return d?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(G,{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(G,{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(wi,{shape:v,disabled:m,layoutDragging:u,setLayoutDragging:p,selected:U(r).some(f=>f.id===v.id)??!1,handleSelect:l,handleRemove:a,onMoveShapes:o,toggleShapeVisibility:i,toggleShapeLock:c},v.id))})]})})}):null},Lt=({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":zn},role:"dialog","aria-modal":"true","aria-labelledby":s,children:[h.jsx("div",{className:"react-paint-editor-modal-mask",onClick:t}),h.jsx("div",{className:`react-paint-editor-modal-panel ${a}`,children:e})]}),Vt=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez une couleur",mode:s="fill",disabled:a=!1,values:i,field:c,value:r="",valueChanged:o})=>{const[l]=y.useState(le("settings_")),d=e===l;return i.length?h.jsxs(h.Fragment,{children:[h.jsx(G,{selected:d,title:n,disabled:a,onClick:()=>{t(u=>u===l?void 0:l)},icon:r==="transparent"?s==="fill"?Vn:Ln: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}})}),d&&h.jsx(Ue,{title:n,alignment:"left",children:h.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[i.map(u=>h.jsx(G,{title:u,selected:u===r,color:u,icon:u==="transparent"?s==="fill"?Vn:Ln:void 0,onClick:()=>{o(c,u)},children:u!=="transparent"&&h.jsx("div",{className:"react-paint-editor-colorfield-color",color:u,"data-mode":s,style:{"--react-paint-editor-colorfield-color-value":u}})},u)),h.jsx(G,{type:"color",title:"Custom color",selected:r!==""&&!i.includes(r),value:r,onChange:u=>{const p=+u.target.value;o(c,Number.isNaN(p)?u.target.value:p)},children:h.jsx("div",{className:"react-paint-editor-colorfield-customcolor",style:{"--react-paint-editor-colorfield-color-value":i.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},Mi=({disabled:e=!1,selectedShape:t,removeShape:n})=>h.jsx(G,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{n(U(t))},icon:Qn}),Zt=({CustomOption:e,selectedSettings:t,setSelectedSettings:n,title:s="Choisissez l'option",disabled:a=!1,field:i,icon:c,values:r,defaultValue:o,valueChanged:l})=>{const[d]=y.useState(le("settings_")),u=t===d;return r.length?h.jsxs(h.Fragment,{children:[h.jsx(G,{selected:u,title:s,icon:c,disabled:a,onClick:()=>{n(p=>p===d?void 0:d)}}),u&&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(G,{title:`${p}`,onClick:()=>(m=>{l(i,m)})(p),selected:o===p,style:{"--react-paint-editor-button-padding":"16px"},children:h.jsx(e,{children:p})},p))})})]}):null},ki=({children:e})=>h.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),ea=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:i})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ki,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:i}):null,Pi=({disabled:e,toggleLayoutPanel:t})=>h.jsx(G,{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"}),ji=({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"})]}),ta=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:i})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:ji,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:i}):null,Li=({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",{})]}),na=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,values:s,defaultValue:a,valueChanged:i})=>s.length?h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Li,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:i}):null,Ht=({selectedSettings:e,setSelectedSettings:t,title:n="Choisissez l'intervalle",icon:s,disabled:a=!1,field:i,value:c,min:r=1,max:o=20,step:l=1,unity:d="",valueChanged:u,saveShapes:p})=>{const m=c===void 0,v=m?"N/A":`${Math.round(c)}${d}`,[f]=y.useState(le("settings_")),Q=((b,x=500)=>{const g=y.useRef(null),w=y.useCallback((...L)=>{g.current&&clearTimeout(g.current),g.current=setTimeout(()=>b(...L),x)},[b,x]);return y.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]),w})(p),k=e===f;return r===o?null:h.jsxs(h.Fragment,{children:[h.jsx(G,{selected:k,title:n,disabled:a,icon:s,onClick:()=>{t(b=>b===f?void 0:f)}}),k&&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:o,step:l,value:c??(o+r)/2,"data-indeterminate":+m,onChange:b=>{const x=+b.target.value,g=Number.isNaN(x)?b.target.value:x;u(i,g,!1),Q()}}),h.jsx("span",{children:v})]})})})]})},Vi=({children:e})=>h.jsx("span",{children:e===0?"Non":"Oui"}),Zi=[0,1],sa=({selectedSettings:e,setSelectedSettings:t,disabled:n=!1,defaultValue:s,valueChanged:a})=>h.jsx(Zt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Vi,title:"Fermer les points",icon:Wt,disabled:n,field:"closedPoints",values:Zi,defaultValue:s,valueChanged:a}),Hi=({disabled:e=!1,className:t,toggleZoomPanel:n})=>h.jsx(G,{title:"Toggle zoom panel",disabled:e,onClick:n,icon:Zn,className:t?` ${t}`:""}),zt=({setSelectedSettings:e,disabled:t=!1,field:n,icon:s,values:a,value:i=!1,valueChanged:c})=>{const[r]=y.useState(le("settings_"));return a.length!==2?null:h.jsx(G,{onClick:()=>{e(o=>o===r?void 0:r),c(n,!i)},selected:i,disabled:t,icon:s})},un=({activeTool:e,selectedShape:t,selectedShapeTool:n,disabled:s,selectedSettings:a,setSelectedSettings:i,saveShapes:c,handleShapeStyleChange:r,handleShapeFontFamilyChange:o})=>t?n&&h.jsxs(h.Fragment,{children:["strokeColor"in n.settings&&!n.settings.strokeColor.hidden&&h.jsx(Vt,{selectedSettings:a,setSelectedSettings:i,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:i,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:i,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(na,{selectedSettings:a,setSelectedSettings:i,disabled:s,defaultValue:t.style?.lineDash,valueChanged:r,values:n.settings.lineDash.values}),"lineArrow"in n.settings&&!n.settings.lineArrow.hidden&&h.jsx(ta,{selectedSettings:a,setSelectedSettings:i,disabled:s,defaultValue:t.style?.lineArrow,valueChanged:r,values:n.settings.lineArrow.values}),"closedPoints"in n.settings&&!n.settings.closedPoints.hidden&&h.jsx(sa,{selectedSettings:a,setSelectedSettings:i,disabled:s,valueChanged:r,defaultValue:t.style?.closedPoints}),"fontFamily"in n.settings&&!n.settings.fontFamily.hidden&&h.jsx(ea,{selectedSettings:a,setSelectedSettings:i,disabled:s,valueChanged:o,values:n.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),"fontBold"in n.settings&&!n.settings.fontBold.hidden&&h.jsx(zt,{setSelectedSettings:i,disabled:s,field:"fontBold",icon:kn,valueChanged:o,values:n.settings.fontBold.values,value:t.style?.fontBold}),"fontItalic"in n.settings&&!n.settings.fontItalic.hidden&&h.jsx(zt,{setSelectedSettings:i,disabled:s,field:"fontItalic",icon:Pn,valueChanged:o,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:i,title:"Opacité",icon:bn,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:i,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:i,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:i,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(na,{selectedSettings:a,setSelectedSettings:i,disabled:s,defaultValue:e.settings.lineDash.default,valueChanged:r,values:e.settings.lineDash.values}),"lineArrow"in e.settings&&!e.settings.lineArrow.hidden&&h.jsx(ta,{selectedSettings:a,setSelectedSettings:i,disabled:s,defaultValue:e.settings.lineArrow.default,valueChanged:r,values:e.settings.lineArrow.values}),"closedPoints"in e.settings&&!e.settings.closedPoints.hidden&&h.jsx(sa,{selectedSettings:a,setSelectedSettings:i,disabled:s,valueChanged:r,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&h.jsx(ea,{selectedSettings:a,setSelectedSettings:i,disabled:s,valueChanged:o,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),"fontBold"in e.settings&&!e.settings.fontBold.hidden&&h.jsx(zt,{setSelectedSettings:i,disabled:s,field:"fontBold",icon:kn,valueChanged:o,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),"fontItalic"in e.settings&&!e.settings.fontItalic.hidden&&h.jsx(zt,{setSelectedSettings:i,disabled:s,field:"fontItalic",icon:Pn,valueChanged:o,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:i,title:"Opacité",icon:bn,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,zi=({width:e,availableTools:t,updateToolSettings:n,layersManipulation:s=!1,toggleLayoutPanel:a,activeTool:i,saveShapes:c,selectedShape:r,canvas:o,settings:l,updateShape:d,removeShape:u,isZoomPanelShown:p,setIsZoomPanelShown:m})=>{const[v,f]=y.useState(void 0),[Q,k]=y.useState(!1),b=l.size==="infinite"||l.features.zoom,x=!l.features.edition,g=()=>{k(Z=>!Z)},w=((Z,A)=>{const H=U(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 B=H.slice(1).reduce((D,I)=>{const X={};for(const $ in I.settings){if(D[$]===void 0||I.settings[$]?.hidden||D[$]?.hidden)continue;const z=D[$],S=I.settings[$],M={};"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&&(M.min=S.min,M.max=S.max,M.step=S.step),"values"in S&&"values"in z&&S.values?.join(",")===z.values?.join(",")&&(M.values=S.values),(Object.keys(M).length>0||$==="closedPoints")&&(X[$]=M)}return X},H[0].settings);return{id:H.map(D=>D.id).join("-"),icon:"",label:"group",type:"group",settings:B}})(r,t),L=(w?Object.keys(w.settings).length+1:"settings"in i?Object.keys(i.settings).length:0)+ +s+ +b,R=e<40*L,V=(Z,A,H=!0)=>{if(U(r).length){const B=U(r).map(D=>Ee(Qe(["style",Z],A,D),l));d(B,H),w&&n(w.id,Z,A)}else n(i.id,Z,A)},C=(Z,A)=>{if(U(r).length){const H=U(r).map(B=>{if(B.type!=="text")return B;const D=o?.getContext("2d");if(!D)return B;const I=Qe(["style",Z],A,B),X=Pt(D,I.value,I.width,I.style?.fontBold??!1,I.style?.fontItalic??!1,I.style?.fontFamily);return Ee({...I,fontSize:X,height:X*I.value.length},l)});d(H,!0),w&&n(w.id,Z,A)}else n(i.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(Hi,{className:p?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{m(Z=>!Z)}}),R&&L>2&&h.jsx(G,{disabled:x,onClick:g,title:"Toggle settings",icon:'<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>'}),r?w&&h.jsxs(h.Fragment,{children:[!R&&h.jsx(un,{saveShapes:c,activeTool:i,selectedShape:r,selectedShapeTool:w,disabled:x,selectedSettings:v,setSelectedSettings:f,handleShapeStyleChange:V,handleShapeFontFamilyChange:C}),i.type==="selection"&&h.jsx(Mi,{disabled:x,selectedShape:r,removeShape:u})]}):!R&&h.jsx(un,{saveShapes:c,activeTool:i,selectedShape:r,selectedShapeTool:w,disabled:x,selectedSettings:v,setSelectedSettings:f,handleShapeStyleChange:V,handleShapeFontFamilyChange:C})]}),h.jsx("div",{className:"react-paint-editor-settings-separator"}),s&&h.jsx(Pi,{disabled:x,toggleLayoutPanel:a})]}),Q&&h.jsx(Lt,{className:"react-paint-editor-settings-modal",onClose:g,position:"bottom",title:"Settings",children:h.jsx(un,{saveShapes:c,activeTool:i,selectedShape:r,selectedShapeTool:w,disabled:x,selectedSettings:v,setSelectedSettings:f,handleShapeStyleChange:V,handleShapeFontFamilyChange:C})})]})},aa=({disabled:e=!1,withText:t=!1,loadFile:n,type:s,img:a,accept:i})=>{const c=y.useRef(null);return h.jsx(G,{ref:c,type:"file",onClick:r=>{r.stopPropagation(),c.current&&(c.current.value="")},onChange:r=>{const o=r.target.files?.item(0);o&&n(o)},accept:i,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:i})=>h.jsx(G,{disabled:a,selected:n,onClick:()=>{i(e)},title:e.label??e.type,icon:t,children:s?e.label:void 0}),Ti=({activeTool:e,withActionsInMenu:t,hasActionToUndo:n=!1,hasActionToRedo:s=!1,hasActionToClear:a=!1,undoAction:i,redoAction:c,clearCanvas:r,alignment:o,group:l,vertical:d=!1,disabled:u=!1,withLoadAndSave:p,withExport:m,addPicture:v,loadFile:f,togglePictureUrlModal:Q,saveFile:k,toggleExportModal:b,withUploadPicture:x,withUrlPicture:g})=>{const[w,L]=y.useState(!1),[,R]=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=()=>{L(!1)};return document.addEventListener("click",Z),()=>{document.removeEventListener("click",Z)}},[w]),t||x||g||p||m?h.jsxs("div",{className:"react-paint-editor-toolbox-relative",children:[h.jsx(G,{selected:V,title:l.title,disabled:u,onClick:()=>{R(()=>{L(!0)})},icon:C}),w&&h.jsx(Ue,{alignment:o,position:"top",children:h.jsxs("div",{className:"react-paint-editor-toolbox-panel-content","data-vertical":+d,children:[t&&h.jsxs(h.Fragment,{children:[h.jsx(Ce,{withText:!0,type:et,disabled:u||!n,img:et.icon,isActive:e.id===et.id,setActive:i}),h.jsx(Ce,{withText:!0,type:tt,disabled:u||!s,img:tt.icon,isActive:e.id===tt.id,setActive:c}),h.jsx(Ce,{withText:!0,type:nt,disabled:u||!a,img:nt.icon,isActive:e.id===nt.id,setActive:r}),(x||g||p)&&h.jsx("hr",{})]}),x&&h.jsx(aa,{withText:!0,type:Yn,disabled:u,loadFile:async Z=>{L(!1),await v(Z)},img:Yn.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),g&&h.jsx(G,{disabled:u,selected:!1,onClick:Q,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"}),(x||g)&&p&&h.jsx("hr",{}),p&&h.jsxs(h.Fragment,{children:[h.jsx(aa,{withText:!0,type:Bn,disabled:u,loadFile:Z=>{L(!1),f(Z)},img:Bn.icon,accept:"application/JSON"}),h.jsx(Ce,{withText:!0,disabled:u,type:Bt,img:Bt.icon,isActive:e.id===Bt.id,setActive:k})]}),m&&h.jsx(Ce,{withText:!0,disabled:u,type:Ot,img:Ot.icon,isActive:e.id===Ot.id,setActive:b})]})})]}):null},Ai=({togglePictureUrlModal:e,addPicture:t})=>{const n=y.useRef(null);return y.useEffect(()=>{n.current&&n.current.focus()},[]),h.jsx(Lt,{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(G,{onClick:e,children:"Annuler"}),h.jsx(G,{type:"submit",selected:!0,children:"Ajouter"})]})})},ia="Choose export settings",Ei=({toggleExportModal:e,exportCanvasInFile:t})=>{const n=async s=>{t(s),e()};return h.jsxs(Lt,{className:"react-paint-editor-toolbox-export-modal",onClose:e,title:ia,children:[h.jsx("h3",{children:ia}),h.jsx("hr",{}),h.jsx(G,{onClick:()=>n("currentZoom"),children:"Exporter la vue actuelle"}),h.jsx(G,{onClick:()=>n("defaultView"),children:"Exporter le canevas par défaut"}),h.jsx(G,{onClick:()=>n("fitToShapes"),children:"Exporter le dessin entier"}),h.jsx(G,{selected:!0,onClick:e,children:"Annuler"})]})},Ri=({activeTool:e,alignment:t,group:n,disabled:s=!1,setActiveToolFromId:a})=>{const i=y.useRef(null),[c,r]=y.useState(!1),[,o]=y.useTransition(),[l,d]=y.useState(void 0),u=v=>{d(v),a(v.id)};if(y.useEffect(()=>{if(!c)return;const v=f=>{!((k,b)=>!!(k.target instanceof Node&&b)&&b.contains(k.target))(f,i.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:u});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:u});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(G,{selected:p,title:n.title,disabled:s,onClick:()=>{l?a(l.id):n.toolsType?.[0]&&u(n.toolsType[0]),o(()=>{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:i,children:n.toolsType.map(v=>h.jsx(Ce,{disabled:s,type:v,img:v.icon,isActive:e.id===v.id,setActive:u},v.id))})})]})},Di=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],Ii=({settings:e,width:t,activeTool:n,hasActionToUndo:s=!1,hasActionToRedo:a=!1,hasActionToClear:i=!1,withLoadAndSave:c,withExport:r,clearCanvas:o,setActiveTool:l,undoAction:d,redoAction:u,addPicture:p,loadFile:m,saveFile:v,exportCanvasInFile:f,availableTools:Q,withUrlPicture:k,withUploadPicture:b})=>{const x=((z,S)=>{const M=S.flatMap(P=>{if(typeof P!="object")return z.filter(j=>j.type===P);const T=z.filter(j=>P.toolsType.includes(j.type));return T?{...P,toolsType:T}:null});return ln(M)})(Q,Di),g=!e.features.edition,w=t<40*(6+x.length),L=t<40*(3+x.length),[R,V]=y.useState(!1),[C,Z]=y.useState(!1),[A,H]=y.useState(!1),B=()=>{V(z=>!z)},D=()=>{H(z=>!z)},I=z=>{l(z),V(!1)},X=z=>{I(Q.find(S=>S.id===z)??n)},$=Q.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:De,disabled:g,img:De.icon,isActive:n.id===De.id,setActive:I}),(e.size==="infinite"||e.features.zoom)&&h.jsx(Ce,{type:Yt,disabled:g,img:Yt.icon,isActive:n.id===Yt.id,setActive:I}),L?h.jsx(G,{disabled:g,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:$}):x.map(z=>h.jsx(Ri,{disabled:g,activeTool:n,group:z,setActiveToolFromId:X},"id"in z?z.id:z.title))]}),!w&&h.jsxs(h.Fragment,{children:[h.jsx(Ce,{type:et,disabled:g||!s,img:et.icon,isActive:n.id===et.id,setActive:d}),h.jsx(Ce,{type:tt,disabled:g||!a,img:tt.icon,isActive:n.id===tt.id,setActive:u}),h.jsx(Ce,{type:nt,disabled:g||!i,img:nt.icon,isActive:n.id===nt.id,setActive:o})]}),h.jsx(Ti,{withActionsInMenu:w,disabled:g,vertical:!0,alignment:"right",group:{title:"Menu",img:'<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>'},activeTool:n,addPicture:p,loadFile:m,saveFile:v,togglePictureUrlModal:()=>{Z(!0)},toggleExportModal:D,withUploadPicture:b,withUrlPicture:k,withLoadAndSave:c,withExport:r,hasActionToUndo:s,hasActionToRedo:a,hasActionToClear:i,undoAction:d,redoAction:u,clearCanvas:o})]}),R&&h.jsx(Lt,{className:"react-paint-editor-toolbar-modal",onClose:B,title:"Outils",children:Q.map(z=>z.type==="picture"?null:h.jsx(Ce,{disabled:g,type:z,img:z.icon,withText:!1,isActive:n.id===z.id,setActive:I},z.id))}),C&&h.jsx(Ai,{togglePictureUrlModal:()=>{Z(z=>!z)},addPicture:p}),A&&h.jsx(Ei,{toggleExportModal:D,exportCanvasInFile:f})]})},Tt={none:0,small:10,medium:20,large:40},Wi={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},Ni=()=>{const e=y.useRef([]),[t,n]=y.useState([]);return y.useEffect(()=>()=>{for(const s of e.current)clearTimeout(s)},[]),{snackbarList:t,addSnackbar:({type:s=mi,duration:a=yi,text:i})=>{const c={id:le("snackbar_"),duration:a,type:s,text:i};n(r=>[...r,c]),e.current=[...e.current,setTimeout(()=>{return r=c.id,void n(o=>o.filter(l=>l.id!==r));var r},a)]}}};Re.Canvas=({options:e,className:t,style:n,canvasProps:s})=>{const{shapesRef:a,selectedShape:i,selectionFrame:c,hoveredShape:r,addShape:o,setSelectedShape:l,setSelectionFrame:d,refreshSelectedShapes:u,refreshHoveredShape:p,duplicateShapes:m,removeShape:v,updateShape:f,backwardShape:Q,forwardShape:k,saveShapes:b,refs:x,width:g,height:w,settings:L,setCanvasSize:R,setCanvasOffset:V,selectShapes:C,activeTool:Z,setActiveTool:A,isInsideComponent:H,isInsideCanvas:B,isEditMode:D,canvas:{withSkeleton:I,withFrameSelection:X,canGrow:$,canShrink:z},canvasOffsetStartData:S,setCanvasOffsetStartData:M,selectionMode:P,setSelectionMode:T,setCanvasMoveAcceleration:j,isShiftPressed:O,isAltPressed:W,isSpacePressed:F,setShiftPressed:E,setAltPressed:_,setCanvasZoom:ie,resetZoom:se,setIsSpacePressed:q}=s,{canvasBackgroundColor:N,canvasSelectionColor:de,canvasSelectionWidth:te}={...ma,...e},fe=y.useRef(null),ve=y.useCallback(K=>{o(K),C(K)},[o,C]),me=y.useCallback(K=>{R({realWidth:g,realHeight:w,width:K,height:w*K/g,scaleRatio:K/g})},[g,w,R]);return fi({isInsideComponent:H,isInsideCanvas:B,isEditingText:P.mode==="textedition",settings:L,selectedShape:i,setSelectedShape:l,removeShape:v,pasteShapes:ve,updateShapes:f,backwardShape:Q,forwardShape:k,setShiftPressed:E,setAltPressed:_,setActiveTool:A,setSelectionMode:T,setSelectionFrame:d,setCanvasZoom:ie,resetZoom:se,setIsSpacePressed:q}),(({onResized:K,element:ue})=>{y.useEffect(()=>{const Y=ue.current;if(!Y)return;const ee=new ResizeObserver(Me=>{const ke=Me?.[0]?.borderBoxSize?.[0],{width:ae,height:Le}=ke?{width:ke.inlineSize,height:ke.blockSize}:Me?.[0]?.contentRect??{};ae!==void 0&&Le!==void 0&&K(ae,Le)});return ee.observe(Y),()=>{ee.unobserve(Y)}},[ue,K])})({element:fe,onResized:me}),h.jsx("div",{ref:fe,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":$,"data-shrink":z,style:{"--react-paint-app-row-width":L.canvasSize.width,"--react-paint-app-canvaswidth":g,"--react-paint-app-canvasheight":w,"--react-paint-app-row-aspectratio":`calc(${L.canvasSize.width} / ${L.canvasSize.height})`,"--react-paint-app-canvas-bg":N,...n},children:h.jsx(ai,{duplicateShapes:m,isSpacePressed:F,ref:x.canvas,canGrow:$,isInsideComponent:H,activeTool:Z,setActiveTool:A,canvasOffsetStartData:S,setCanvasOffsetStartData:M,shapes:a.current,addShapes:o,updateSingleShape:f,selectedShape:i,selectionFrame:c,setSelectedShape:l,setSelectionFrame:d,hoveredShape:r,refreshHoveredShape:p,refreshSelectedShapes:u,settings:L,setCanvasOffset:V,saveShapes:b,selectionMode:P,setSelectionMode:T,setCanvasMoveAcceleration:j,selectionColor:de,selectionWidth:te,isEditMode:D,isShiftPressed:O,isAltPressed:W,withFrameSelection:X,withSkeleton:I})})},Re.Editor=({editorProps:e,className:t,style:n,options:s,children:a})=>{const{shapesRef:i,addPictureShape:c,moveShapes:r,toggleShapeVisibility:o,toggleShapeLock:l,canGoBackward:d,canGoForward:u,canClear:p,selectedShape:m,removeShape:v,updateShape:f,backwardShape:Q,forwardShape:k,refs:b,width:x,height:g,selectTool:w,selectShapes:L,activeTool:R,setActiveTool:V,setAvailableTools:C,isEditMode:Z,availableTools:A,gridGap:H,setGridGap:B,loadFile:D,exportPicture:I,exportData:X,clearCanvas:$,settings:z,setCanvasZoom:S,saveShapes:M,canvas:{canGrow:P,layersManipulation:T,withExport:j,withLoadAndSave:O,withUploadPicture:W,withUrlPicture:F}}=e,{toolbarBackgroundColor:E,dividerColor:_,fontRadius:ie,fontDisabledColor:se,fontDisabledBackgroundColor:q,fontColor:N,fontBackgroundColor:de,fontSelectedColor:te,fontSelectedBackgroundColor:fe,fontHoverColor:ve,fontHoverBackgroundColor:me}={...Wi,...s},K=z.size==="infinite"||z.features.zoom,[ue,Y]=y.useState(!1),[ee,Me]=y.useState(!1),[ke,ae]=y.useState(K),Le=K&&ke,qe=H>=Tt.large?"large":H>=Tt.medium?"medium":H>=Tt.small?"small":"none",{snackbarList:hn,addSnackbar:Ze}=Ni(),pn=y.useCallback((he,pe,vt)=>{C(We=>We.map(ct=>ct.id===he?Qe(["settings",pe,"default"],vt,ct):ct)),V(We=>We.id===he?Qe(["settings",pe,"default"],vt,We):We)},[V,C]),gn=y.useCallback(he=>{Y(!0);try{I(he)}catch(pe){pe instanceof Error&&Ze({type:"error",text:`L'export a échoué : ${pe.message}`}),console.warn(pe)}finally{Y(!1)}},[I,Ze]),Ge=y.useCallback(()=>{Y(!0);try{X(),Y(!1)}catch(he){he instanceof Error&&Ze({type:"error",text:"L'enregistrement a échoué"}),console.warn(he)}finally{Y(!1)}},[X,Ze]),fn=y.useCallback(async he=>{Y(!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{Y(!1)}},[D,Ze]),vn=y.useCallback(async he=>{Y(!0);try{const pe=await c(he,x,g);L([pe])}catch(pe){pe instanceof Error&&Ze({type:"error",text:"Le chargement a échoué"}),console.warn(pe)}finally{Y(!1)}},[c,L,Ze,x,g]),mn=`${t?`${t} `:""}${ee?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return h.jsxs("div",{ref:b.setEditor,className:mn,style:{"--react-paint-editor-app-maxWidth":P?"100%":`${x}px`,"--react-paint-editor-app-toolbar-bg":E,"--react-paint-editor-app-divider-color":_,"--react-paint-editor-app-font-radius":ie,"--react-paint-editor-app-font-disabled-color":se,"--react-paint-editor-app-font-disabled-bg":q,"--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(Ii,{settings:z,width:z.canvasSize.width,activeTool:R,clearCanvas:$,setActiveTool:w,exportCanvasInFile:gn,saveFile:Ge,loadFile:fn,addPicture:vn,hasActionToUndo:d,hasActionToRedo:u,hasActionToClear:p,undoAction:Q,redoAction:k,availableTools:A,withExport:j,withLoadAndSave:O,withUploadPicture:W,withUrlPicture:F}),a,Z&&T&&h.jsx(Ci,{gridFormat:qe,setGridFormat:he=>{B(Tt[he])},shapes:i.current,moveShapes:r,selectedShapes:m,removeShape:v,selectShapes:L,toggleShapeVisibility:o,toggleShapeLock:l,isLayoutPanelShown:ee,settings:z}),Le&&h.jsxs(Ue,{alignment:"left",className:"react-paint-editor-layouts-panel","data-edit":+Z,children:[h.jsx(G,{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(G,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>S("default"),children:[Math.round(100*z.canvasZoom),"%"]}),h.jsx(G,{className:"react-paint-editor-zoom-button",icon:Zn,onClick:()=>S("zoom")})]}),Z&&h.jsxs(h.Fragment,{children:[h.jsx(zi,{saveShapes:M,setCanvasZoom:S,width:z.canvasSize.width,activeTool:R,availableTools:A,selectedShape:m,settings:z,removeShape:v,updateShape:f,canvas:b.canvas.current,layersManipulation:T,toggleLayoutPanel:()=>{Me(he=>!he)},isZoomPanelShown:Le,setIsZoomPanelShown:ae,updateToolSettings:pn}),h.jsx(vi,{isLoading:ue}),h.jsx(xi,{snackbarList:hn})]})]})},Re.useReactPaint=({width:e=1e3,height:t=600,shapes:n,mode:s="editor",disabled:a=!1,options:i=Kn}={})=>{const{layersManipulation:c,brushAlgo:r,isBrushShapeDoneOnMouseUp:o,debug:l,grid:d,canGrow:u,canShrink:p,withExport:m,withLoadAndSave:v,withUploadPicture:f,withUrlPicture:Q,withSkeleton:k,withFrameSelection:b,clearCallback:x,availableTools:g,canvasSelectionPadding:w,size:L,canZoom:R}={...Kn,...i},V=s!=="viewer",C=y.useRef(null),Z=y.useRef(null),A=y.useRef(!1),H=y.useCallback(J=>{C.current=J},[]),[B,D]=y.useState(void 0),[I,X]=y.useState(De),[$,z]=y.useState({mode:"default"}),[S,M]=y.useState(d),[P,T]=y.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),j=R==="always"&&!a,{canvasTransformation:O,setCanvasTransformation:W,setCanvasOffset:F,setCanvasZoom:E,resetZoom:_}=ei({canvasSize:P,size:L,canvasElt:Z.current,zoomEnabled:j}),{offset:ie,zoom:se}=O,q=y.useMemo(()=>({brushAlgo:r,isBrushShapeDoneOnMouseUp:o,debug:l,canvasSize:{realWidth:P.realWidth,realHeight:P.realHeight,width:P.width,height:P.height,scaleRatioWithNoZoom:P.scaleRatio,scaleRatio:P.scaleRatio*se},size:L,canvasOffset:ie,canvasZoom:se,gridGap:S,selectionPadding:w,features:{edition:V&&!a,zoom:j}}),[w,S,r,o,l,se,ie,P,L,a,j,V]),[N,de]=y.useState(Os(g,f||Q)),{isInsideComponent:te,isInsideCanvas:fe}=(({settings:J,componentRef:oe,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 je=()=>Fe(!0),Et=()=>Fe(!1),Oe=()=>Je(!0),Rt=()=>Je(!1);return oe.current?.addEventListener("focusin",je),oe.current?.addEventListener("focusout",Et),Pe.current?.addEventListener("focusin",Oe),Pe.current?.addEventListener("focusout",Rt),()=>{oe.current?.removeEventListener("focusin",je),oe.current?.removeEventListener("focusout",Et),Pe.current?.removeEventListener("focusin",Oe),Pe.current?.removeEventListener("focusout",Rt)}}Fe(!1),Je(!1)},[ye,oe,Pe]),{isInsideComponent:Ne,isInsideCanvas:Ke}})({settings:q,componentRef:C,canvasRef:Z}),[ve,me]=y.useState(!1),[K,ue]=y.useState(!1),[Y,ee]=y.useState(!1),{registerEvent:Me,unregisterEvent:ke,shapesRef:ae,selectedShape:Le,selectionFrame:qe,hoveredShape:hn,addShapes:Ze,addPictureShape:pn,moveShapes:gn,setSelectedShape:Ge,setSelectionFrame:fn,refreshSelectedShapes:vn,refreshHoveredShape:mn,duplicateShapes:he,removeShape:pe,updateShape:vt,backwardShape:We,forwardShape:ct,clearShapes:oa,saveShapes:ra,toggleShapeVisibility:Fi,toggleShapeLock:Oi,canGoBackward:Bi,canGoForward:Yi,canClear:Xi}=Ka(q,e,t,ve),yn=y.useCallback(J=>{Ge(void 0),X(J)},[Ge]),[dt,la]=y.useState([0,0]),ca=$.mode==="preview";y.useEffect(()=>{if(ca)return()=>z(J=>J.mode==="preview"?{mode:"default"}:J)},[Le?.id,ca]);const da=$.mode==="selectionFrame";y.useEffect(()=>{if(da)return()=>la([0,0])},[da]),y.useEffect(()=>{if(dt[0]!==0||dt[1]!==0){const J=setInterval(()=>{W(({offset:oe,zoom:Pe})=>{const Ne=[oe[0]-dt[0],oe[1]-dt[1]];return sn({zoom:Pe,size:L,canvasSize:P,newOffset:Ne})})},20);return()=>clearInterval(J)}},[dt[0],dt[1],W,L,P]);const At=y.useCallback((J,oe)=>{oa(J,oe),yn(De),W({offset:[0,0],zoom:1})},[yn,oa,W]),ua=y.useCallback(J=>{Ge(oe=>(oe?.id!==J.map(Pe=>Pe.id).join("-")&&X(De),ce(J,q)))},[Ge,q]),$i=y.useCallback(()=>{const J=Ga(ae.current,e,t);if(!J)throw new Error("L'encodage a échoué");Ds(J,"drawing.json")},[ae,e,t]),Ui=y.useCallback(J=>{const oe=Is({shapes:ae.current,settings:q,view:J});Ds(oe,"drawing.png")},[ae,q]),qi=y.useCallback(J=>Is({shapes:ae.current,settings:q,view:J}),[ae,q]),Gi=y.useCallback(()=>dn(ae.current,e,t),[ae,e,t]),_e=y.useCallback(async(J,oe)=>{const Pe=await(async(Ne,Fe)=>{if(!Ne)return[];const Ke=[],Je=ln(Ne.map(ye=>{if(!ye||!qn.includes(ye.type))return null;if(ye.type==="picture"){const je=new Image,Et=new Promise((Oe,Rt)=>{je.onload=()=>{URL.revokeObjectURL(je.src),Oe()},je.onerror=()=>{Rt(new Error("Some images could not be loaded"))}});if(Ke.push(Et),ye.src.startsWith("http"))Rs(ye.src).then(Oe=>{je.src=Oe}).catch(()=>{je.src=""});else if(ye.src.includes("<svg")){const Oe=new Blob([ye.src],{type:"image/svg+xml"});je.src=URL.createObjectURL(Oe)}else je.src=ye.src;return Ws({...ye,img:je},Fe)}return Ws(ye,Fe)}));return await Promise.all(Ke),Je})(J,q);At(Pe,oe)},[At,q]),Sn=y.useRef(_e);Sn.current=_e;const _i=y.useCallback((J=[],oe=!0)=>{Sn.current?.(J,{clearHistory:oe,source:"remote"})},[]);y.useEffect(()=>{A.current||(A.current=!0,n&&Sn.current?.(n,{clearHistory:!0,source:"remote"}))},[n]);const Ki=y.useCallback(async J=>{const oe=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 je=JSON.parse(ye);Ne(je)},Ke.readAsText(Pe)}))(J);await _e(oe.shapes??[],{clearHistory:!0,source:"remote"})},[_e]),Ji=y.useCallback(()=>{typeof x!="string"?_e(x(),{clearHistory:!1,source:"user"}):x==="defaultShapes"&&n!==void 0?_e(n,{clearHistory:!1,source:"user"}):At([],{clearHistory:!1,source:"user"})},[At,_e,n,x]);y.useEffect(()=>{de(Os(g,f||Q))},[g,f,Q]);const ha={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":q.canvasZoom,"--react-paint-canvas-offset-x":q.canvasOffset[0],"--react-paint-canvas-offset-y":q.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:ae,addPictureShape:pn,moveShapes:gn,toggleShapeVisibility:Fi,toggleShapeLock:Oi,canGoBackward:Bi,canGoForward:Yi,canClear:Xi,selectedShape:Le,saveShapes:ra,removeShape:pe,updateShape:vt,backwardShape:We,forwardShape:ct,refs:ha,width:e,height:t,selectTool:yn,selectShapes:ua,activeTool:I,setActiveTool:X,setAvailableTools:de,isEditMode:V,availableTools:N,gridGap:S,setGridGap:M,loadFile:Ki,exportPicture:Ui,exportData:$i,clearCanvas:Ji,settings:q,setCanvasZoom:E,resetZoom:_,canvas:{canGrow:u,canShrink:p,layersManipulation:c,withExport:m,withLoadAndSave:v,withUploadPicture:f,withUrlPicture:Q}},canvasProps:{shapesRef:ae,selectedShape:Le,selectionFrame:qe,hoveredShape:hn,addShape:Ze,setSelectedShape:Ge,setSelectionFrame:fn,refreshSelectedShapes:vn,refreshHoveredShape:mn,removeShape:pe,updateShape:vt,duplicateShapes:he,backwardShape:We,forwardShape:ct,saveShapes:ra,refs:ha,width:e,height:t,settings:q,setCanvasSize:T,setCanvasOffset:F,setCanvasZoom:E,resetZoom:_,selectShapes:ua,activeTool:I,setActiveTool:X,isInsideComponent:te,isInsideCanvas:fe,isEditMode:V,canvas:{withSkeleton:k,withFrameSelection:b,canGrow:u,canShrink:p},canvasOffsetStartData:B,setCanvasOffsetStartData:D,selectionMode:$,setSelectionMode:z,setCanvasMoveAcceleration:la,isShiftPressed:ve,isAltPressed:K,isSpacePressed:Y,setShiftPressed:me,setAltPressed:ue,setIsSpacePressed:ee},registerEvent:Me,unregisterEvent:ke,resetCanvas:_i,resetZoom:_,getCurrentImage:qi,getCurrentData:Gi,setCanvasOffset:F,setCanvasZoom:E}},Object.defineProperty(Re,Symbol.toStringTag,{value:"Module"})});
1
+ (function(Ke,S){typeof exports=="object"&&typeof module<"u"?S(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],S):S((Ke=typeof globalThis<"u"?globalThis:Ke||self)["react-paint"]={},Ke.React,Ke.jsxRuntime)})(this,function(Ke,S,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>',Fa='<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>',Oa='<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>',Ba='<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>',Pe=["transparent","black","white","red","green","blue","yellow"],tt=[0,1,2],Ga=[[1,0],[1,2],[4,6]],Vt="serif",Hn=2,_a=3,zn=4,fe="react-paint-",Ka={strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}picture`,icon:ra,label:"Image",settings:{opacity:{min:0,max:100,step:1,default:100}}},Ja={type:"brush",id:`${fe}brush`,icon:Ra,label:"Brosse",settings:{strokeColor:{values:Pe,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:`${fe}line`,icon:Na,label:"Ligne",settings:{strokeColor:{values:Pe,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:`${fe}polygon`,icon:ia,label:"Polygone",settings:{strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}curve`,icon:Oa,label:"Courbe",settings:{strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}rect`,icon:na,label:"Rectangle",settings:Ka},ns={type:"square",id:`${fe}square`,icon:na,label:"Carré",settings:{strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}circle`,icon:oa,label:"Cercle",settings:{strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}ellipse`,icon:oa,label:"Ellipse",settings:{strokeColor:{values:Pe,default:"black"},fillColor:{values:Pe,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:`${fe}text`,icon:Wa,label:"Texte",settings:{strokeColor:{values:Pe,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:`${fe}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:`${fe}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:`${fe}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:`${fe}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:`${fe}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:`${fe}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:`${fe}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"},ua={id:`${fe}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:`${fe}upload-picture`,type:"uploadpicture",icon:ra,label:"Upload picture"},ds=2,us="blue",ot=14,hs=[[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"],Tn=["rect","square","circle","ellipse","picture","text","triangle","brush","group"],An=["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},En={canvasBackgroundColor:"white",canvasSelectionColor:us,canvasSelectionWidth:ds},ms=300,ha=(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},Ie=(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={},Se=(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"},je=(e,t={})=>{const{lineCap:a="round",fillColor:s="transparent",opacity:n=100,strokeColor:o=us,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},he=({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]]},Qs=e=>(e+2*Math.PI)%(2*Math.PI),ws=({targetVector:[e,t],radian:a=!0,originVector:s})=>{const n=Qs(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=Qs(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=he({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)=>he({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=In(e,t),s=((n,o)=>qe(n,va,o))(e,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},Rn=xt,He=(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],Me=(e,t,a=0)=>{if(!t.gridGap)return He(e);const s=e+a,n=s>=0?t.gridGap:-t.gridGap;return s+n/2-(s+n/2)%n-a},Dn=(e,t,a,s,n,o,r)=>{if(s.mode==="translate")return oe(Gs(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],h=s.originalShape.computed.center[1]-a[1],u=((p,m,g)=>m.gridGap||g?p+Math.PI/18/2-(p+Math.PI/18/2)%(Math.PI/18):He(p,3))(Math.atan2(h,c)-Math.atan2(i,l),n,o),v=X(s.originalShape).map(p=>Fe($s(p,u,s.originalShape.computed.center),n));return oe(v,n)}return s.mode==="resize"?oe(ho(e,a,s.originalShape,s,n,o,r),n):s.mode==="brush"?oe(X(t).map(l=>((i,c,h)=>{const u={...i,points:Ie(i.points.length-1,[...i.points[i.points.length-1],[Math.round(c[0]),Math.round(c[1])]],i.points)};return xt(u,h)})(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},In=(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 h=Ne(i[c],r,l,e.scaleX,e.scaleY),u=Ne(i[c+1],r,l,e.scaleX,e.scaleY),v=(h[0]+u[0])/2,p=(h[1]+u[1])/2;a.quadraticCurveTo(...h,v,p)}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},Wn=(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,P,H)=>{const E=f-2*P+H,z=-2*f+2*P,T=f;if(Math.abs(E)<1e-10){if(Math.abs(z)<1e-10)return[];const ae=-T/z;return ae>0&&ae<1?[ae]:[]}const Z=z*z-4*E*T;if(Z<0)return[];const R=Math.sqrt(Z),B=(-z-R)/(2*E),W=(-z+R)/(2*E),D=[];return B>0&&B<1&&D.push(B),W>0&&W<1&&W!==B&&D.push(W),D},l=e[0],i=t[0],c=a[0],h=s[0],u=e[1],v=t[1],p=a[1],m=s[1],g=r(i-l,c-i,h-c),y=r(v-u,p-v,m-p);let w=Math.min(e[0],s[0]),C=Math.max(e[0],s[0]),b=Math.min(e[1],s[1]),x=Math.max(e[1],s[1]);for(const f of g){const P=n(f);w=Math.min(w,P),C=Math.max(C,P)}for(const f of y){const P=o(f);b=Math.min(b,P),x=Math.max(x,P)}return{minX:w,maxX:C,minY:b,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]}),Ms=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},Nn=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},Fn=(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=Fn)=>{const n=t(e,a),o=s(e,n,a),r=[n.x+n.width/2,n.y+n.height/2],l=((i,c,h=0)=>{if(h===0)return i;const u=[[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(m=>he({point:m,origin:c,rotation:h})),v=Math.min(...u.map(m=>m[0])),p=Math.min(...u.map(m=>m[1]));return{x:v,y:p,width:Math.max(...u.map(m=>m[0]))-v,height:Math.max(...u.map(m=>m[1]))-p}})(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}),...hs.map(n=>At({x:s.x+s.width*n[0],y:s.y+s.height*n[1],radius:7/a.canvasSize.scaleRatio}))]}},ks=({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]}},On=({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]=he({point:r,rotation:-(o.rotation??0)});return{borderX:He(e+l-r[0]),borderWidth:He(t),borderY:He(a+i-r[1]),borderHeight:He(s)}},Bn=(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=he({origin:r,point:e,rotation:t.rotation}),c=a.anchor[0]===0&&i[0]>=l.x+l.width-s.selectionPadding||a.anchor[0]===1&&i[0]<=l.x+s.selectionPadding,h=a.anchor[1]===0&&i[1]>=l.y+l.height-s.selectionPadding||a.anchor[1]===1&&i[1]<=l.y+s.selectionPadding,u=[Me(i[0],s,a.anchor[0]===0&&!c||a.anchor[0]===1&&c?s.selectionPadding:-s.selectionPadding),Me(i[1],s,a.anchor[1]===0&&!h||a.anchor[1]===1&&h?s.selectionPadding:-s.selectionPadding)],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]:he({origin:r,point:a.cursorStartPosition,rotation:t.rotation}),p=[u[0]-v[0],u[1]-v[1]],[m,g]=ks({borderStart:l.x,borderSize:l.width,vector:p[0],settings:s,invertedAxe:c,anchor:a.anchor[0]}),[y,w]=ks({borderStart:l.y,borderSize:l.height,vector:p[1],settings:s,invertedAxe:h,anchor:a.anchor[1]}),C=n?((b,x,f,P,H,E,z,T,Z,R,B)=>{const{selectionPadding:W}=B,D="ratio"in Z&&Z.ratio?Z.ratio:(b.width-2*W||1)/(b.height-2*W||1),ae=(P-2*W)/(E-2*W);let J,I,$,G;return R.anchor[0]!==.5&&R.anchor[1]!==.5?ae<D?(I=H,G=E,$=(E-2*W)*D+2*W,J=R.anchor[0]===0?z?b.x+b.width-2*W:b.x+(b.width-$):z?b.x-$+2*W:b.x):(J=f,$=P,G=(P-2*W)/D+2*W,I=R.anchor[1]===0?T?b.y+b.height-2*W:b.y+(b.height-G):T?b.y-G+2*W:b.y):R.anchor[0]!==.5?(J=f,$=P,G=(P-2*W)/D+2*W,I=b.y+(b.height-G)/2):(I=H,G=E,$=(E-2*W)*D+2*W,J=b.x+(b.width-$)/2),{borderX:J,borderWidth:$,borderY:I,borderHeight:G,center:x,originalShape:Z}})(l,r,m,g,y,w,c,h,t,a,s):{borderX:m,borderWidth:g,borderY:y,borderHeight:w,center:r,originalShape:t};return{...On(o?Bn(C,l,c,h):C),isXinverted:c,isYinverted:h}},Rt=(e,t)=>{const a=Zt(e),s=((n,o)=>qe(n,ya,o))(e,t);return{...e,path:a,computed:s,selection:bt(a,s,t)}},Yn=Rt,Ps=(e,t,a,s=0,n=0)=>{const o={toolId:e.id,type:e.type,id:Se(`${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)},Xn=(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}),js=(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)},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 h=((u,v,p)=>{if(u.mode==="translate")return{mode:"translate",cursorStartPosition:p,originalShape:v,hasBeenDuplicated:!1,dateStart:Date.now(),selectedShapesLengthAtMouseDown:X(v).length};if(u.mode==="rotate"){const{center:m}=v.computed;return{mode:"rotate",cursorStartPosition:p,originalShape:v,center:[m[0],m[1]],selectedShapesLengthAtMouseDown:X(v).length}}return u.mode==="resize"?{mode:"resize",cursorStartPosition:p,originalShape:v,anchor:u.anchor,selectedShapesLengthAtMouseDown:X(v).length}:void 0})(i||{mode:"default"},n,a);if(h?.mode==="resize"||h?.mode==="rotate")return{shape:n,mode:h}}const c=t.find(h=>X(n).find(u=>h.id===u?.id)?i&&Ht(e,h,a,s,!0,o?20:void 0):!!zs(e,h,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:X(n).length}};if(c){if(l==="add"){const u=oe(Ls(n,[c]),s);return{shape:u,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:u,selectedShapesLengthAtMouseDown:X(n).length}}}if(l==="remove"){const u=oe($n(n,c),s);return{shape:u,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:u,selectedShapesLengthAtMouseDown:X(n).length}}}const h=X(n).find(u=>u.id===c?.id)?n:oe([c],s);return{shape:h,mode:{mode:"translate",cursorStartPosition:a,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:h,selectedShapesLengthAtMouseDown:X(n).length}}}return{shape:l!=="replace"?n:void 0,mode:{mode:r?"selectionFrame":"default"}}},oe=(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 P=he({point:[f[0],f[1]],origin:x.computed.center,rotation:-(x.rotation??0)});return he({point:[P[0],P[1]],origin:[0,0],rotation:l})})),h=Math.min(...c.flatMap(x=>[x[0][0],x[1][0],x[2][0],x[3][0]])),u=Math.min(...c.flatMap(x=>[x[0][1],x[1][1],x[2][1],x[3][1]])),v=Math.max(...c.flatMap(x=>[x[0][0],x[1][0],x[2][0],x[3][0]])),p=Math.max(...c.flatMap(x=>[x[0][1],x[1][1],x[2][1],x[3][1]])),m=[(h+v)/2,(u+p)/2],g=he({point:m,origin:[0,0],rotation:-l}),y=[m[0]-g[0],m[1]-g[1]],w=He(h-y[0]),C=He(v-y[0]),b=He(u-y[1]);return{width:C-w,height:He(p-y[1])-b,x:w,y:b}})(e,a,t),n=Ps({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 h in i)r[h]!==void 0&&i[h]!==void 0&&r[h]===i[h]&&(c[h]=r[h]);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}},X=e=>e?e.type==="group"?e.shapes:[e]:[],Ls=(e,t)=>{const a=X(e);return[...new Set([...a,...t])]},$n=(e,t)=>X(e).filter(a=>a.id!==t.id),Vs=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}},Zs=(e,t,a)=>{const{clientX:s,clientY:n}=Vs(e),o=t.getBoundingClientRect();return[(s-o.left)/a.scaleRatio,(n-o.top)/a.scaleRatio]},ct=(e,t,a)=>{const{clientX:s,clientY:n}=Vs(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])=>he({origin:[a,s],point:e,rotation:t}),xa=(e,t,[a,s])=>he({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=X(t).length>1?t:X(t)[0];if(!r||r.locked)return!1;const{borders:l,center:i}=r.computed,c=Ge(a,r.rotation??0,i);if(n){const h=((u,v,p,m=0)=>{const{canvasSize:{scaleRatio:g}}=p,{borders:y}=u.computed;if(u.type==="line"||u.type==="polygon"||u.type==="curve"){for(let w=0;w<u.points.length;w++)if(It({x:u.points[w][0]-7/g,y:u.points[w][1]-7/g,width:ot/g,height:ot/g},v,m))return{mode:"resize",anchor:w}}else{if(It({x:y.x+y.width/2-7/g,y:y.y-ot/g-16/g,width:ot/g,height:ot/g},v,m))return{mode:"rotate"};for(const w of hs)if(It({x:y.x+y.width*w[0]-7/g,y:y.y+y.height*w[1]-7/g,width:ot/g,height:ot/g},v,m))return{mode:"resize",anchor:w}}return!1})(r,c,s,o);if(h)return h}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"}},Hs=(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),zs=(e,t,a,s)=>{if(t.locked)return!1;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 Qa(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 Ts=({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 h=i+a.y;h<a.y+a.height;h+=s){const u=Ge([c,h],o,n);if(r?e.isPointInPath(t,u[0],u[1]):e.isPointInStroke(t,u[0],u[1]))return!0}return!1},wa=(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}))]}),ze=[.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}},As=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}},Es=(e,t)=>{const{canvasZoom:a,size:s}=t;if(s!=="fixed"||a>=1)return;const n=As(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,Un=(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=((n,o)=>qe(n,Un,o))(e,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},qn=Wt,Qt=(e,t)=>{const a=Ms(e),s=((n,o)=>qe(n,Nt,o))(e,t);return{...e,path:a,selection:wa(a,e,s,t),computed:s}},Rs=Qt,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}},Gn=(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)},Ds=(e,t,a,s=!1)=>{const n=[Me(t[0],a),Me(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 Qt(r,a)},_n=(e,t,a)=>{const s=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(s.length<2){const c=s[0]??[0,0],h=a.selectionPadding;return{x:c[0]-h,y:c[1]-h,width:2*h,height:2*h}}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 h=n[c-1],u=n[c],v=n[c+1],p=n[c+2],{cp1:m,cp2:g}=Sa(h,u,v,p),y=Wn(u,m,g,v);o=Math.min(o,y.minX),r=Math.max(r,y.maxX),l=Math.min(l,y.minY),i=Math.max(i,y.maxY)}return ya({x:o,y:l,width:r-o,height:i-l},a)},wt=(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 Ms(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 h=i[c-1],u=i[c],v=i[c+1],p=i[c+2],{cp1:m,cp2:g}=Sa(h,u,v,p);o.bezierCurveTo(m[0],m[1],g[0],g[1],v[0],v[1])}return l&&o.closePath(),o})(e),s=((n,o)=>qe(n,Nt,o,_n))(e,t);return{...e,path:a,selection:wa(a,e,s,t),computed:s}},Is=wt,Kn=(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)},Ws=(e,t,a,s=!1)=>{const n=[Me(t[0],a),Me(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 wt(l,a)},Jn=(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)}),Ft=(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=((n,o)=>qe(n,Jn,o))(e,t);return{...e,path:a,selection:bt(a,s,t),computed:s}},eo=Ft,to=(e,t)=>qe(e,Nt,t),Ns=(e,t)=>((a,s)=>({...a,path:Nn(a),computed:to(a,s)}))({...e,id:Se("triangle_"),type:"triangle"},t),ao=(e,t)=>{e.globalAlpha!==0&&(t.style?.fillColor!=="transparent"&&e.fill(t.path),t.style?.strokeColor!=="transparent"&&e.stroke(t.path))},so=(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}),Ot=(e,t)=>{const a=[];let s;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){const o=Math.PI/2-ws({targetVector:[e.points[0],e.points[1]]});e.style?.lineArrow!==1&&e.style?.lineArrow!==3||a.push(Ns(Fs(e.points[0],o,e.style),t)),e.style?.lineArrow!==2&&e.style?.lineArrow!==3||a.push(Ns(Fs(e.points[1],o+Math.PI,e.style),t));const r=(({line:l,size:i,direction:c})=>{const h=Math.PI/2-ws({targetVector:[l.points[0],l.points[1]]}),u=[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 v,p;if(["start","both"].includes(c)){const m=he({point:l.points[0],origin:u,rotation:-h});v=he({point:[m[0],m[1]+i],origin:u,rotation:h})}else v=[...l.points[0]];if(["end","both"].includes(c)){const m=he({point:l.points[1],origin:u,rotation:-h});p=he({point:[m[0],m[1]-i],origin:u,rotation:h})}else p=[...l.points[1]];return{points:[v,p]}})({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=((o,r)=>qe(o,so,r))(e,t);return{...e,path:s,selection:wa(s,e,n,t),arrows:a,style:{...e.style,lineCap:e.style?.lineArrow?"butt":"round"},computed:n}},no=Ot,Fs=(e,t,a)=>{const s=[he({point:[0,0],rotation:t}),he({point:[-(5+(a.lineWidth??0)),10+2*(a.lineWidth??0)],rotation:t}),he({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"}}},oo=(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,h=i*r,u=c*l,v=it(e,t,a),p=rt(a,v.x,v.y,h,u),m=e.computed.center[0]-i/2,g=e.computed.center[1]-c/2,y=p[0]-h/2,w=p[1]-u/2;return((C,b)=>C.type==="line"?Ot(C,b):C.type==="polygon"?Rs(C,b):Is(C,b))({...e,points:e.points.map(([C,b])=>[y+(s?h-(C-m)*r:(C-m)*r),w+(n?u-(b-g)*l:(b-g)*l)])},a.settings)},Bt=(e,t)=>{const a=((n,o)=>qe(n,ya,o))(e,t),s=Zt(e);return{...e,path:s,selection:bt(void 0,a,t),computed:a}},io=Bt,ka=(e,t,a,s,n)=>{const[o,r]=((l,i,c,h,u=!1)=>{if(!(l&&i&&h&&c))return[ms,ms];const v=l/i;if(v>c/h){const m=u?c:Math.min(l,c);return[m,m/v]}const p=u?h:Math.min(i,h);return[p*v,p]})(e.width,e.height,a,s,!0);return Bt({toolId:la.id,type:"picture",id:Se("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)},ro=(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,h,u,v)=>{Js(c)?c.text().then(p=>{const m=Ks(p);l.onload=async()=>{URL.revokeObjectURL(l.src);const g=ka(l,p,h,u,v);i(g)},l.src=m}):(l.onload=async()=>{URL.revokeObjectURL(l.src);const p=ka(l,l.src,h,u,v);i(p)},l.src=URL.createObjectURL(c))})(r,n,e,t,a,s):((l,i,c,h,u,v)=>{l.onload=()=>{URL.revokeObjectURL(l.src);const p=ka(l,c,h,u,v);i(p)},en(c).then(p=>{l.src=p}).catch(()=>{l.src=""})})(r,n,e,t,a,s)}),Pa=["Texte"],Os=(e,t)=>qe(e,co,t),Yt=(e,t)=>{const a=Os(e,t),s=Zt(e);return{...e,path:s,selection:bt(void 0,a,t),computed:a}},lo=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},co=(e,t)=>({x:e.x-t.selectionPadding,width:e.width+2*t.selectionPadding,y:e.y-t.selectionPadding,height:e.height+2*t.selectionPadding}),uo=(e,t,a,s)=>{const n={...t,value:a},o=((m,g,y,w,C,b=Vt)=>{m.font=`${C?"italic":""} ${w?"bold":""} ${y}px ${b}`;const x=g.map(f=>m.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}=Os(i,s),[h,u]=js([1,1],t.computed.center,t),[v,p]=js([1,1],c,i,[!1,!1]);return{...i,x:i.x-(v-h),y:i.y-(p-u)}},Bs=(e,t,a,s)=>{const n=[Me(a[0],s),Me(a[1],s)];switch(t.type){case"brush":return((o,r,l)=>xt({toolId:o.id,type:o.type,id:Se(`${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:Se(`${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 Ot(i,l)})(t,n,s);case"polygon":return((o,r,l)=>Qt({toolId:o.id,type:o.type,id:Se(`${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)=>wt({toolId:o.id,type:o.type,id:Se(`${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 Ps(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),h=c*(Pa.length||1);return Yt({toolId:r.id,type:r.type,id:Se(`${r.type}_`),x:l[0]-150,y:l[1]-h,value:Pa,fontSize:c,width:150,height:h,ratio:150/h,style:{opacity:r.settings.opacity.default,strokeColor:r.settings.strokeColor.default,fontFamily:r.settings.fontFamily.default,fontItalic:r.settings.fontItalic.default,fontBold:r.settings.fontBold.default}},i)})(e,t,n,s);case"ellipse":return((o,r,l)=>Ft({toolId:o.id,type:o.type,id:Se(`${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:Se(`${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)}},Ys=(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??[])je(a,n.style),ao(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":Xn(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)}},Xs=(e,t,a)=>{if(t.visible===!1)return;if(((n,o)=>{const r=(l=>{const{canvasSize:{width:i,height:c,scaleRatioWithNoZoom:h},canvasZoom:u,canvasOffset:v}=l;return{x:-v[0],y:-v[1],width:i/u/h,height:c/u/h}})(o);return!!Qa(n.computed.boundingBox,r)})(t,a)){if(yt(e,a,t.rotation,t.computed.center),je(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),je(c,{...o.style,opacity:100}),Ys(c,o),n.drawImage(i,r.x-l.width/4,r.y-l.height/4)})(e,t),void e.restore();Ys(e,t),e.restore()}},$s=(e,t,a)=>{const s=he({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=>he({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}},Us=(e,t,a,s,n,o,r)=>{switch(a.type){case"line":return((l,i,c,h)=>{const u=[Me(l[0],h),Me(l[1],h)],v=Ge(u,i.rotation??0,i.computed.center),p=Ie(["points",c.anchor],v,i);return Ot(p,h)})(t,a,s,n);case"polygon":return((l,i,c,h)=>{const u=[Me(l[0],h),Me(l[1],h)],v=Ge(u,i.rotation??0,i.computed.center),p=Ie(["points",c.anchor],v,i);return Qt(p,h)})(t,a,s,n);case"curve":return((l,i,c,h)=>{const u=[Me(l[0],h),Me(l[1],h)],v=i.computed.center,p=Ge(u,i.rotation??0,v),m=Ie(["points",c.anchor],p,i);return wt(m,h)})(t,a,s,n);case"brush":return((l,i,c,h,u,v)=>{const p=va({...i,scaleX:1,scaleY:1},h),m=i.computed.borders,{borderX:g,borderHeight:y,borderY:w,borderWidth:C,isXinverted:b,isYinverted:x}=lt(l,i,c,h,u,v),f=Math.max(0,p.width-2*h.selectionPadding),P=Math.max(0,p.height-2*h.selectionPadding),H=Math.max(0,C-2*h.selectionPadding),E=Math.max(0,y-2*h.selectionPadding),z=f?H/f:1,T=P?E/P:1;if(!f||!P)return i;const Z=He(g-m.x)+(b?2*m.x+p.width:0),R=He(w-m.y)+(x?2*m.y+p.height:0);return xt({...i,points:i.points.map(B=>B.map(([W,D])=>[b?-W+Z:W+Z,x?-D+R:D+R])),scaleX:z,scaleY:T},h)})(t,a,s,n,o,r);case"circle":return((l,i,c,h,u)=>{const{borderX:v,borderHeight:p,borderY:m,borderWidth:g}=lt(l,i,c,h,!0,u);return Wt({...i,radius:Math.max(0,g/2-h.selectionPadding),x:v+g/2,y:m+p/2},h)})(t,a,s,n,r);case"ellipse":return((l,i,c,h,u=!1,v=!1)=>{const{borderX:p,borderHeight:m,borderY:g,borderWidth:y}=lt(l,i,c,h,u,v);return Ft({...i,radiusX:Math.max(0,y/2-h.selectionPadding),radiusY:Math.max(0,m/2-h.selectionPadding),x:p+y/2,y:g+m/2},h)})(t,a,s,n,o,r);case"rect":case"square":return((l,i,c,h,u=!1,v=!1)=>{const{borderX:p,borderHeight:m,borderY:g,borderWidth:y}=lt(l,i,c,h,u,v);return Rt({...i,width:Math.max(0,y-2*h.selectionPadding),height:Math.max(0,m-2*h.selectionPadding),x:p+h.selectionPadding,y:g+h.selectionPadding},h)})(t,a,s,n,a.type==="square"||o,r);case"text":return((l,i,c,h,u,v)=>{const{borderX:p,borderHeight:m,borderY:g,borderWidth:y,isXinverted:w,isYinverted:C}=lt(i,c,h,u,!0,v),b=Math.max(0,y-2*u.selectionPadding),x=Math.max(0,m-2*u.selectionPadding),f=Yt({...c,width:b,height:x,x:p+u.selectionPadding,y:g+u.selectionPadding,flipX:w?!c.flipX:!!c.flipX,flipY:C?!c.flipY:!!c.flipY},u);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,h,u)=>{const{borderX:v,borderHeight:p,borderY:m,borderWidth:g,isXinverted:y,isYinverted:w}=lt(l,i,c,h,!0,u),C=Math.max(0,g-2*h.selectionPadding),b=Math.max(0,p-2*h.selectionPadding);return Bt({...i,width:C,height:b,x:v+h.selectionPadding,y:m+h.selectionPadding,flipX:y?!i.flipX:!!i.flipX,flipY:w?!i.flipY:!!i.flipY},h)})(t,a,s,n,r);default:return a}},ho=(e,t,a,s,n,o,r)=>{if(a.type!=="group")return X(a).map(m=>Us(e,t,m,s,n,o,r));const l=a,i=X(l),c=i.filter(m=>Tn.includes(m.type)),h=!c.some(m=>(m.rotation??0)!==(c[0]?.rotation??0)),u=(c[0]?.rotation??0)!==0&&c.length!==i.length,v=i.some(m=>An.includes(m.type)),p=((m,g,y,w,C,b)=>{const{borders:x}=g.computed,{borderX:f,borderHeight:P,borderY:H,borderWidth:E,isXinverted:z,isYinverted:T}=lt(m,g,y,w,C,b);return{newBorderX:f,newBorderY:H,newBorderWidth:E,newBorderHeight:P,widthMultiplier:(E-2*w.selectionPadding)/(x.width-2*w.selectionPadding||1),heightMultiplier:(P-2*w.selectionPadding)/(x.height-2*w.selectionPadding||1),isXinverted:z,isYinverted:T,groupCenter:[f+E/2,H+P/2],rotation:g.rotation??0,settings:w,originalBorders:x}})(t,l,s,n,o||!h||v||u,r);return i.map(m=>{switch(m.type){case"rect":case"square":return((g,y,w)=>{const{isXinverted:C,isYinverted:b,settings:x,widthMultiplier:f,heightMultiplier:P}=w,H=(C||b)&&!(C&&b)&&(g.rotation??0)!==0&&y.rotation!==g.rotation,E=it(g,y,w),z=(g.width||1)*f,T=(g.height||1)*P,Z=rt(w,E.x,E.y,z,T);return Rt({...g,width:z,height:T,x:Z[0]-z/2,y:Z[1]-T/2,rotation:H?-(g.rotation??0):g.rotation??0},x)})(m,l,p);case"picture":return((g,y,w)=>{const{isXinverted:C,isYinverted:b,settings:x,widthMultiplier:f,heightMultiplier:P}=w,H=it(g,y,w),E=(g.width===0||g.height===0?g.ratio??1:g.width)*f,z=(g.width===0||g.height===0?g.ratio??1:g.height)*P,T=rt(w,H.x,H.y,E,z),Z=(C||b)&&!(C&&b)&&(g.rotation??0)!==0&&y.rotation!==g.rotation;return Bt({...g,width:E,height:z,x:T[0]-E/2,y:T[1]-z/2,flipX:C?!g.flipX:!!g.flipX,flipY:b?!g.flipY:!!g.flipY,rotation:Z?-(g.rotation??0):g.rotation??0},x)})(m,l,p);case"text":return((g,y,w,C)=>{const{isXinverted:b,isYinverted:x,settings:f,widthMultiplier:P,heightMultiplier:H}=C,E=(b||x)&&!(b&&x)&&(y.rotation??0)!==0&&w.rotation!==y.rotation,z=it(y,w,C),T=(y.width===0||y.height===0?y.ratio??1:y.width)*P,Z=(y.width===0||y.height===0?y.ratio??1:y.height)*H,R=rt(C,z.x,z.y,T,Z),B=Yt({...y,width:T,height:Z,x:R[0]-T/2,y:R[1]-Z/2,flipX:b?!y.flipX:!!y.flipX,flipY:x?!y.flipY:!!y.flipY,rotation:E?-(y.rotation??0):y.rotation??0},f);return{...B,fontSize:Xt(g,B.value,B.width,B.style?.fontBold??!1,B.style?.fontItalic??!1,B.style?.fontFamily)}})(e,m,l,p);case"ellipse":return((g,y,w)=>{const{isXinverted:C,isYinverted:b,settings:x,widthMultiplier:f,heightMultiplier:P}=w,H=(C||b)&&!(C&&b)&&(g.rotation??0)!==0&&y.rotation!==g.rotation,E=it(g,y,w),z=(g.radiusX||.5)*f,T=(g.radiusY||.5)*P,Z=rt(w,E.x,E.y,2*z,2*T);return Ft({...g,radiusX:z,radiusY:T,x:Z[0],y:Z[1],rotation:H?-(g.rotation??0):g.rotation??0},x)})(m,l,p);case"circle":return((g,y,w)=>{const C=it(g,y,w),b=(g.radius||.5)*w.widthMultiplier,x=rt(w,C.x,C.y,2*b,2*b);return Wt({...g,radius:b,x:x[0],y:x[1]},w.settings)})(m,l,p);case"brush":return((g,y,w)=>{const{isXinverted:C,isYinverted:b,settings:x,widthMultiplier:f,heightMultiplier:P}=w,H=va({...g,scaleX:1,scaleY:1},x),E=H.width-2*x.selectionPadding,z=H.height-2*x.selectionPadding,T=g.scaleX??1?(g.scaleX??1)*f:f/E,Z=g.scaleY??1?(g.scaleY??1)*P:P/z,R=E*T,B=z*Z,W=it(g,y,w),D=rt(w,W.x,W.y,R,B),ae=He(D[0]-R/2-g.computed.borders.x-x.selectionPadding)+(C?2*g.computed.borders.x+H.width:0),J=He(D[1]-B/2-g.computed.borders.y-x.selectionPadding)+(b?2*g.computed.borders.y+H.height:0),I=(C||b)&&!(C&&b)&&(g.rotation??0)!==0&&y.rotation!==g.rotation;return xt({...g,points:g.points.map($=>$.map(([G,ie])=>[C?-G+ae:G+ae,b?-ie+J:ie+J])),scaleX:T,scaleY:Z,rotation:I?-(g.rotation??0):g.rotation??0},w.settings)})(m,l,p);case"line":case"polygon":case"curve":return oo(m,l,p);default:return Us(e,t,m,s,n,o,r)}})},qs=(e,t,a,s)=>{switch(e.type){case"rect":case"square":case"ellipse":case"circle":case"picture":case"text":return Fe({...e,x:e.x+t,y:e.y+a},s);case"line":case"polygon":case"curve":return Fe({...e,points:e.points.map(([n,o])=>[n+t,o+a])},s);case"brush":return Fe({...e,points:e.points.map(n=>n.map(([o,r])=>[o+t,r+a]))},s);default:return e}},Gs=(e,t,a,s,n)=>{const o=t.computed.borders,r=((c,h)=>h?[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:Me(o.x+s.selectionPadding+r[0],s)-(o.x+s.selectionPadding),i=r[1]===0?0:Me(o.y+s.selectionPadding+r[1],s)-(o.y+s.selectionPadding);return X(t).map(c=>qs(c,l,i,s))},Fe=(e,t)=>{switch(e.type){case"rect":case"square":return Yn(e,t);case"ellipse":return eo(e,t);case"circle":return qn(e,t);case"picture":return io(e,t);case"text":return lo(e,t);case"line":return no(e,t);case"polygon":return Rs(e,t);case"curve":return Is(e,t);case"brush":return Rn(e,t);default:return e}},_s=({ctx:e,shape:t,settings:a,selectionWidth:s,selectionColor:n,hoverMode:o,selectionMode:r,withAnchors:l=!0})=>{switch(a.debug&&((i,c,h,u)=>{c.selection&&u.debug&&(i.save(),i.scale(u.canvasSize.scaleRatio,u.canvasSize.scaleRatio),i.translate(u.canvasOffset[0],u.canvasOffset[1]),je(i,{fillColor:"transparent",strokeColor:"green",lineWidth:h/u.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,h,u,v,p)=>{if(c.selection&&(yt(i,v,c.rotation,c.computed.center),v.debug&&(je(i,{fillColor:"transparent",strokeColor:"red",lineWidth:u/v.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),je(i,{fillColor:"transparent",strokeColor:h,lineWidth:u/v.canvasSize.scaleRatio}),c.selection.shapePath?i.stroke(c.selection.shapePath):i.stroke(c.selection.border),p&&!c.locked)){c.selection.shapePath&&i.stroke(c.selection.border),c.selection.line&&i.stroke(c.selection.line),je(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/v.canvasSize.scaleRatio,shadowColor:h,shadowBlur:0});for(const m of c.selection.anchors)i.fill(m),i.stroke(m)}})(e,t,n,s,a,l);break;case"group":((i,c,h,u,v,p,m)=>{if(c.selection&&(c.shapes.forEach(g=>{je(i,{fillColor:"transparent",strokeColor:h,lineWidth:u/p.canvasSize.scaleRatio}),yt(i,p,g.rotation,g.computed.center),g.selection?.shapePath&&i.stroke(g.selection.shapePath),i.restore()}),v.mode!=="rotate"&&(yt(i,p,c.rotation,c.computed.center),p.debug&&(je(i,{fillColor:"transparent",strokeColor:"red",lineWidth:u/p.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),je(i,{fillColor:"transparent",strokeColor:h,lineWidth:u/p.canvasSize.scaleRatio}),m&&!c.locked))){i.stroke(c.selection.border),c.selection.line&&i.stroke(c.selection.line),je(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/p.canvasSize.scaleRatio});for(const g of c.selection.anchors)i.fill(g),i.stroke(g)}})(e,t,n,s,r,a,l);break;case"polygon":case"line":case"curve":(({ctx:i,shape:c,withAnchors:h,selectionWidth:u,selectionColor:v,hoverMode:p,settings:m})=>{if(c.selection&&(yt(i,m,c.rotation,c.computed.center),m.debug&&(je(i,{fillColor:"transparent",strokeColor:"red",lineWidth:u/m.canvasSize.scaleRatio}),i.strokeRect(c.computed.outerBorders.x,c.computed.outerBorders.y,c.computed.outerBorders.width,c.computed.outerBorders.height)),je(i,{fillColor:"transparent",strokeColor:v,lineWidth:u/m.canvasSize.scaleRatio}),c.selection.shapePath&&i.stroke(c.selection.shapePath),h&&!c.locked)){je(i,{fillColor:"rgb(255,255,255)",strokeColor:"rgb(150,150,150)",lineWidth:2/m.canvasSize.scaleRatio,shadowColor:v,shadowBlur:0});for(let g=0;g<c.selection.anchors.length;g++){const y=c.selection.anchors[g];p.mode==="resize"&&p.anchor===g?(i.shadowBlur=10,i.fill(y),i.shadowBlur=0):i.fill(y),i.stroke(y)}}})({ctx:e,shape:t,withAnchors:l,selectionWidth:s,selectionColor:n,hoverMode:o,settings:a})}e.restore()},po=({ctx:e,selectionFrame:t,settings:a})=>{yt(e,a),((s,n,o)=>{je(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)=>X(e).map(a=>({...qs(a,20,20,t),id:Se(`${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)],Ks=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)},Js=e=>(e instanceof File?e.name:e).includes(".svg"),en=e=>Js(e)?fetch(e).then(t=>t.text()).then(t=>Ks(t)):fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(t)),tn=(e,t)=>{const a=document.createElement("a");a.href=e,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a)},go=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--)Xs(s,e[r],t);return a.toDataURL("image/png")},an=({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})},fo=(e,t,a)=>{return n=Ha(e,t,a),`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(n))}`;var n},vo=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")?ha(t,a):ha(t,{...a,src:go(a)}))},Ha=(e,t,a)=>({shapes:vo(e),config:{width:t,height:a}}),sn=(e,t)=>Fe({...e,id:Se(`${e.type}_`)},t),mo=(e,t,a,s)=>{const n=S.useRef([]),o=S.useRef(void 0),r=S.useRef({dataChanged:[]}),[l,i]=S.useState(void 0),[c,h]=S.useState(void 0),[u,v]=S.useState(void 0),[p,m]=S.useState(void 0),[g,y]=S.useState({states:[{shapes:[],selectedShape:void 0,source:"remote"}],cursor:0}),w=S.useCallback(M=>{o.current=typeof M=="function"?M(o.current):M,h(o.current)},[]),C=g.cursor>0,b=g.cursor<g.states.length-1,x=n.current.length>0,f=S.useCallback(()=>{y(M=>Ss(M.states[M.cursor]?.shapes,n.current)?M:{states:[...M.states.slice(0,M.cursor+1),{shapes:n.current,selectedShape:o.current,source:"user"}],cursor:M.cursor+1})},[]),P=S.useCallback(M=>{n.current=[...M,...n.current]},[]),H=S.useCallback((M,k=!1,Q=!1)=>{const V=[];n.current=n.current.flatMap(N=>{const j=M.find(_=>_.id===N.id);if(j){const _=k?ja(oe([j],e),e)[0]:{...j,id:Se(`${N.type}_`)};return V.push(_),[_,N]}return N}),Q&&w(oe(V,e))},[e,w]),E=S.useCallback((M,k,Q,V)=>{if(M.target&&"className"in M.target&&![gs,fs].includes(M.target.className)||!V)return void v(void 0);const N=n.current.find(j=>X(c)?.map(_=>_.id).includes(j.id)?!!Ht(k,j,Q,e):!!zs(k,j,Q,e));v(N)},[e,c]),z=S.useCallback(async(M,k=300,Q=300)=>{const V=await ro(M,k,Q,e);return P([V]),f(),V},[P,f,e]),T=S.useCallback((M,k=!1)=>{n.current=n.current.map(Q=>M.find(V=>V.id===Q.id)??Q),w(Q=>Q&&oe(X(Q).map(V=>M.find(N=>N.id===V.id)??V),e)),k&&f()},[f,w,e]),Z=S.useCallback(M=>{const k=M.map(Q=>ha(["chosen"],Q));n.current=k,f()},[f]),R=S.useCallback(M=>{const k=new Set(M.map(Q=>Q.id));w(Q=>{const V=X(Q).map(N=>N.id);return V&&k.size&&V.find(N=>k.has(N))?void 0:Q}),n.current=n.current.filter(Q=>!k?.has(Q.id)),f()},[f,w]),B=S.useCallback(M=>{y(k=>{const Q=M(k);return n.current=k.states[Q]?.shapes??[],w(k.states[Q]?.selectedShape),Ie("cursor",Q,k)})},[w]),W=S.useCallback(()=>{B(M=>Math.max(0,M.cursor-1))},[B]),D=S.useCallback(()=>{B(M=>Math.min(M.states.length-1,M.cursor+1))},[B]),ae=S.useCallback((M,k)=>{w(void 0),n.current=M,y(Q=>k.clearHistory?{states:[{shapes:M,selectedShape:void 0,source:k.source}],cursor:0}:{states:[...Q.states.slice(0,Q.cursor+1),{shapes:M,selectedShape:void 0,source:k.source}],cursor:Q.cursor+1})},[w]),J=S.useCallback((M,k)=>{const Q=n.current,V=Q.findIndex(j=>j.id===M),N=Q.findIndex(j=>j.id===k);Z(Va(Q,V,N))},[Z]),I=S.useCallback((M,k)=>{const Q=[...n.current],V=new Set(M.map(j=>j.id)),N=Q.map((j,_)=>V.has(j.id)?_:-1).filter(j=>j>=0);if(N.length!==0)switch(k){case"first":case"last":{const j=N.map(F=>Q[F]).filter(Boolean),_=Q.filter((F,A)=>!N.includes(A));Z(k==="first"?[...j,..._]:[..._,...j]);break}case"backward":{let j=[...Q];const _=N.sort((F,A)=>A-F).map(F=>Q[F].id);for(const F of _){const A=j.findIndex(te=>te.id===F);if(A<j.length-1){const te=A+1;V.has(j[te].id)||(j=Va(j,A,te))}}Z(j);break}case"forward":{let j=[...Q];const _=N.sort((F,A)=>F-A).map(F=>Q[F].id);for(const F of _){const A=j.findIndex(te=>te.id===F);if(A>0){const te=A-1;V.has(j[te].id)||(j=Va(j,A,te))}}Z(j);break}}},[Z]),$=S.useCallback((M,k,Q)=>{const V=new Set(M.map(j=>j.id)),N=n.current.map(j=>V.has(j.id)?Fe($s(j,Q==="rotateClockwise"?Math.PI/2:-Math.PI/2,k),e):j);w(oe(N.filter(j=>V.has(j.id)),e)),Z(N)},[e,Z,w]),G=S.useCallback(M=>{const k=new Set(M.map(V=>V.id)),Q=n.current.map(V=>k.has(V.id)?Ie("visible",V.visible===!1,V):V);w(V=>oe(Q.filter(N=>X(V)?.map(j=>j.id).includes(N.id)),e)),Z(Q)},[Z,e,w]),ie=S.useCallback(M=>{const k=new Set(M.map(V=>V.id)),Q=n.current.map(V=>k.has(V.id)?Ie("locked",!V.locked,V):V);w(V=>oe(Q.filter(N=>X(V)?.map(j=>j.id).includes(N.id)),e)),Z(Q)},[Z,e,w]),Qe=S.useCallback((M,k)=>{r.current.hasOwnProperty(M)&&(r.current[M]=[...r.current[M],k])},[]),L=S.useCallback((M,k)=>{if(r.current.hasOwnProperty(M))if(k){const Q=r.current[M].indexOf(k);r.current[M]=[...r.current[M].slice(0,Q),...r.current[M].slice(Q+1)]}else r.current[M]=[]},[]);S.useEffect(()=>{const M=g.states[g.cursor],k=Ha(M.shapes,t,a);for(const Q of r.current.dataChanged)Q(k,M.source)},[t,a,g]),S.useEffect(()=>{n.current=n.current.map(M=>Fe(M,e)),w(M=>M===void 0?void 0:oe(X(M).map(k=>Fe(k,e)),e))},[e,w]);const q=S.useCallback((M,k)=>{i(Q=>{const V=[Q?.frame[0]??[k[0],k[1]],[k[0],k[1]]],N=n.current.filter(_=>((F,A,te)=>{const{borders:ve,center:Y,boundingBox:Le}=A.computed,de=Math.min(te[0][0],te[1][0]),Ee=Math.max(te[0][0],te[1][0]),We=Math.min(te[0][1],te[1][1]),re={x:de,y:We,width:Ee-de,height:Math.max(te[0][1],te[1][1])-We},ge=Qa(Le,re);if(!ge)return!1;if(ve.width<=1||ve.height<=1)return!0;if(F.lineWidth=(A.style?.lineWidth??0)+10,A.type==="brush"){const ue=A.points.flat(),K=Math.min(...ue.map(le=>le[0])),ne=Math.min(...ue.map(le=>le[1]));for(const le of A.points){if(le.length<1)break;if(le.length<2){const we=Ne(le[0],K,ne,A.scaleX,A.scaleY);if(bs(ge,{x:we[0],y:we[1],radius:(A.style?.lineWidth??1)/2}))return!0}for(let we=0;we<le.length-1;we++){const Re=xa(Ne(le[we],K,ne,A.scaleX,A.scaleY),A.rotation??0,Y),Ae=xa(Ne(le[we+1],K,ne,A.scaleX,A.scaleY),A.rotation??0,Y),ye=Qa({x:Math.min(Re[0],Ae[0]),y:Math.min(Re[1],Ae[1]),width:Math.abs(Re[0]-Ae[0]),height:Math.abs(Re[1]-Ae[1])},re);if(ye){const De=new Path2D;if(De.moveTo(...Re),De.lineTo(...Ae),Ts({ctx:F,path:De,rect:ye,offset:10,center:Y,checkFill:!1}))return!0}}}return!1}const se=ba(A);return Ts({ctx:F,path:A.path,rect:ge,offset:10,center:Y,rotation:A.rotation??0,checkFill:se})})(M,_,V)),j=oe(N,e);return w(s?oe(Ls(Q?.oldSelection,N),e):j),{oldSelection:Q?.oldSelection,frame:V}})},[e,s,w]);return{registerEvent:Qe,unregisterEvent:L,shapesRef:n,selectedShape:c,hoveredShape:u,selectionFrame:l,setSelectionFrame:i,copiedShape:p,setCopiedShape:m,refreshSelectedShapes:q,addShapes:P,duplicateShapes:H,addPictureShape:z,moveShapes:I,swapShapes:J,saveShapes:f,setSelectedShape:w,refreshHoveredShape:E,toggleShapeVisibility:G,toggleShapeLock:ie,removeShape:R,updateShape:T,transformShape:$,backwardShape:W,forwardShape:D,clearShapes:ae,canGoBackward:C,canGoForward:b,canClear:x}},nn=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])}},So=({canvasElt:e,canvasTransformation:t,canvasSize:a,size:s,setCanvasTransformation:n})=>{const o=S.useRef([]),[r,l]=S.useState(o.current.length>0),i=S.useRef(null),c=S.useRef(t);c.current=t;const h=S.useCallback(({startDiff:u,startZoom:v,startCenter:p,startOffset:m,currentDiff:g,currentCenter:y,isMoving:w,isZooming:C})=>{if(!e||!g||!u)return;const b=(({canvasBoundingRect:x,canvasSize:f,size:P,startDiff:H,startZoom:E,startCenter:z,startOffset:T,currentDiff:Z,currentCenter:R,isMoving:B,isZooming:W})=>{const D=W?Ue(Z/H*E,ze[0],ze[ze.length-1]):E,ae=B?[T[0]+(R[0]-z[0])*(f.width/x.width)/f.scaleRatio/E,T[1]+(R[1]-z[1])*(f.height/x.height)/f.scaleRatio/E]:[T[0],T[1]],J=[(R[0]-x.left)/f.scaleRatio,(R[1]-x.top)/f.scaleRatio];return Ma({size:P,canvasSize:f,currentOffset:ae,currentZoom:E,zoom:D,centerPoint:J})})({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:a,size:s,startDiff:u,startZoom:v,startCenter:p,startOffset:m,currentDiff:g,currentCenter:y,isMoving:w,isZooming:C});n(b)},[e,a,s,n]);S.useEffect(()=>{if(!e)return;const u=v=>{if(o.current=[...o.current,v],l(o.current.length>0),o.current.length===2){v.stopPropagation();const{diff:p,center:m}=nn(o.current);i.current={startDiff:p,startCenter:m,startZoom:c.current.zoom,startOffset:c.current.offset,isMoving:!1,isZooming:!1}}};return e.addEventListener("pointerdown",u),()=>{e.removeEventListener("pointerdown",u)}},[e]),S.useEffect(()=>{if(!r)return;const u=p=>{const m=o.current.findIndex(g=>g.pointerId===p.pointerId);if(m>-1&&(o.current[m]=p),o.current.length===2&&i.current){const{diff:g,center:y}=nn(o.current),w=i.current.isZooming||((b,x)=>Math.abs(b-x.startDiff)>30)(g,i.current),C=i.current.isMoving||w||((b,x)=>Math.abs(Cs(b,x.startCenter))>10)(y,i.current);i.current={...i.current,isMoving:C,isZooming:w},h({...i.current,currentDiff:g,currentCenter:y})}},v=p=>{o.current=o.current.filter(m=>m.pointerId!==p.pointerId),l(o.current.length>0)};return document.addEventListener("pointermove",u),document.addEventListener("pointerup",v),document.addEventListener("pointerout",v),document.addEventListener("pointercancel",v),document.addEventListener("pointerleave",v),()=>{document.removeEventListener("pointermove",u),document.removeEventListener("pointerup",v),document.removeEventListener("pointerout",v),document.removeEventListener("pointercancel",v),document.removeEventListener("pointerleave",v)}},[r,h])},on={offset:[0,0],zoom:1},yo=({canvasSize:e,size:t,zoomEnabled:a,canvasElt:s})=>{const[n,o]=S.useState(on),r=S.useRef(0),l=S.useCallback(h=>{o(({zoom:u})=>Ca({zoom:u,size:t,canvasSize:e,newOffset:h}))},[e,t]),i=S.useCallback(h=>{o(({offset:u,zoom:v})=>(({size:p,canvasSize:m,currentOffset:g,currentZoom:y,action:w})=>{const C=w==="default"?ze[4]:w==="zoom"?ze[Ue(ze.length-1-ze.slice(0).reverse().findIndex(x=>x<=y)+1,0,ze.length-1)]:ze[Ue(ze.findIndex(x=>x>=y)-1,0,ze.length-1)],b=[m.realWidth/2,m.realHeight/2];return Ma({size:p,canvasSize:m,currentOffset:g,currentZoom:y,zoom:C,centerPoint:b})})({size:t,canvasSize:e,currentOffset:u,currentZoom:v,action:h}))},[e,t]);So({canvasElt:s,canvasTransformation:n,canvasSize:e,size:t,setCanvasTransformation:o});const c=S.useCallback(()=>{o(on)},[]);return S.useEffect(()=>{if(!a||!s)return;const h=u=>{const v=u.ctrlKey,{deltaX:p,deltaY:m}=((C,b)=>{const x=Math.abs(C.deltaY)<50&&b<50,f=C.ctrlKey,P=ys()&&x&&f;switch(C.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:16*C.deltaX,deltaY:16*C.deltaY};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:C.deltaX*window.innerHeight,deltaY:C.deltaY*window.innerHeight};default:return P?{deltaX:5*C.deltaX,deltaY:5*C.deltaY}:{deltaX:C.deltaX,deltaY:C.deltaY}}})(u,u.timeStamp-r.current);if(r.current=u.timeStamp,v){u.preventDefault();const C=Zs(u,s,e);return void o(({offset:b,zoom:x})=>(({size:f,canvasSize:P,currentOffset:H,currentZoom:E,delta:z,centerPoint:T})=>{const Z=Ue(E*(1-z/1e3),ze[0],ze[ze.length-1]);return Ma({size:f,canvasSize:P,currentOffset:H,currentZoom:E,zoom:Z,centerPoint:T})})({size:t,canvasSize:e,currentOffset:b,currentZoom:x,delta:m,centerPoint:C}))}const g=u.shiftKey,[y,w]=g?[m,p]:[p,m];o(({offset:C,zoom:b})=>{const x=[C[0]-y/b,C[1]-w/b],f=Ca({zoom:b,size:t,canvasSize:e,newOffset:x});return f.offset[0]===C[0]&&f.offset[1]===C[1]||u.preventDefault(),f})};return s.addEventListener("wheel",h,{passive:!1}),()=>{s.removeEventListener("wheel",h)}},[s,t,e,a]),{setCanvasTransformation:o,setCanvasOffset:l,setCanvasZoom:i,resetZoom:c,canvasTransformation:n}},rn=(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)},xo=({addShapes:e,drawCanvasRef:t,setActiveTool:a,refreshHoveredShape:s,shapes:n,selectionMode:o,activeTool:r,isInsideComponent:l,isInsideCanvas:i,setCanvasOffset:c,selectedShape:h,canvasOffsetStartData:u,refreshSelectedShapes:v,setSelectedShape:p,setSelectionFrame:m,setCanvasOffsetStartData:g,updateSingleShape:y,duplicateShapes:w,saveShapes:C,setSelectionMode:b,setCanvasMoveAcceleration:x,settings:f,isShiftPressed:P,isAltPressed:H,withFrameSelection:E,withContextMenu:z,isSpacePressed:T})=>{const Z=S.useRef(null),[R,B]=S.useState({mode:"default"}),{registerDoubleClickEvent:W,unRegisterDoubleClickEvent:D}=(()=>{const L=S.useRef(void 0),q=S.useRef(void 0),M=k=>{const Q=Date.now();L.current&&Q<L.current+300&&q.current?.(k),L.current=Date.now()};return{registerDoubleClickEvent:(k,Q)=>{q.current=Q,k.addEventListener("click",M),k.addEventListener("touchend",M)},unRegisterDoubleClickEvent:k=>{k.removeEventListener("click",M),k.removeEventListener("touchend",M)}}})(),ae=(L,q)=>{const M=q?.getContext("2d");if(M){if(r===Xe&&z){const k=ct(L,t.current,f),{shape:Q,mode:V}=Dt(M,n,k,f,h,Je(L),!1);p(Q),b({mode:"contextMenu",cursorStartPosition:k,originalShape:Q,anchor:"anchor"in V?V.anchor:void 0})}else p(void 0),b({mode:"default"});a(Xe),m(void 0)}},J=S.useRef(null);J.current=L=>((q,M,k,Q,V,N,j,_,F,A,te,ve,Y,Le,de,Ee,We,re)=>{if(re&&clearTimeout(re),Je(q)&&q.touches.length>1)return;const ge=M.current?.getContext("2d");if(!ge)return;const se=ct(q,M.current,Y);if(Q.mode==="selectionFrame"){ve(ge,se,Y);const K=Zs(q,M.current,Y.canvasSize);return void We([Math.ceil(Ue(K[0]*Y.canvasZoom<50?K[0]*Y.canvasZoom-50:K[0]*Y.canvasZoom>Y.canvasSize.width/Y.canvasSize.scaleRatioWithNoZoom-50?K[0]*Y.canvasZoom-(Y.canvasSize.width/Y.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/Y.canvasZoom),Math.ceil(Ue(K[1]*Y.canvasZoom<50?K[1]*Y.canvasZoom-50:K[1]*Y.canvasZoom>Y.canvasSize.height/Y.canvasSize.scaleRatioWithNoZoom-50?K[1]*Y.canvasZoom-(Y.canvasSize.height/Y.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/Y.canvasZoom)])}if(N!==void 0)return void te([se[0]+Y.canvasOffset[0]-N.start[0],se[1]+Y.canvasOffset[1]-N.start[1]]);if(Q.mode==="preview"){const K=X(k)[0];if(K?.type==="curve"){const ne=Ws(K,se,Y,!0);return void Ee(oe([ne],Y))}if(K?.type==="polygon"){const ne=Ds(K,se,Y,!0);return void Ee(oe([ne],Y))}}const ue=zt(se,Y);if(Je(q)||_(q,ge,se,ue),k===void 0||k.locked)j({mode:"default",outOfView:!ue});else{if(Q.mode==="default"||Q.mode==="textedition"||Q.mode==="contextMenu"){if(!ue)return void j({mode:"default"});j(Ht(ge,k,se,Y,!0)||{mode:"default"})}else{const K=M.current?.getContext("2d");if(!K)return;const ne=Dn(K,k,se,Q,Y,Le,de);F(X(ne))}Q.mode==="translate"&&de&&!Q.hasBeenDuplicated&&(V({...Q,hasBeenDuplicated:!0}),A(X(Q.originalShape)))}})(L,t,h,o,b,u,B,s,y,w,c,v,f,P,H,p,x,Z.current),S.useEffect(()=>{if(l){const L=q=>J.current?.(q);return document.addEventListener("mousemove",L),document.addEventListener("touchmove",L),()=>{document.removeEventListener("mousemove",L),document.removeEventListener("touchmove",L)}}},[l]);const{isBrushShapeDoneOnMouseUp:I}=f,$=S.useRef(null);$.current=L=>{if(Z.current&&clearTimeout(Z.current),Je(L)&&L.touches.length>1)return;const q=t.current?.getContext("2d");if(!q)return;if("button"in L&&L.button===2)return void ae(L,t.current);if(u)return void g(void 0);if(o.mode==="contextMenu"||o.mode==="textedition"||o.mode==="preview")return;const M=ct(L,t.current,f);if(o.mode==="translate"&&Date.now()-o.dateStart<=500&&M[0]===o.cursorStartPosition[0]&&M[1]===o.cursorStartPosition[1]){if(L.ctrlKey||L.shiftKey||L.metaKey){const{shape:k}=Dt(q,n,M,f,h,Je(L),E,"remove");X(k).length!==o.selectedShapesLengthAtMouseDown&&p(k)}return b({mode:"default"}),m(void 0),void C()}o.mode!=="default"&&(o.mode==="brush"&&I&&p(void 0),b({mode:"default"}),m(void 0),C())},S.useEffect(()=>{if(i){const L=q=>$.current?.(q);return document.addEventListener("mouseup",L),document.addEventListener("touchend",L),()=>{document.removeEventListener("mouseup",L),document.removeEventListener("touchend",L)}}},[i]);const G=!f.features.edition&&f.features.zoom,ie=!f.features.edition&&!f.features.zoom,Qe=S.useRef(null);return Qe.current=(L,q,M)=>{if(L.preventDefault(),Je(L)&&L.touches.length>1)return;const k=q?.getContext("2d");if(!k)return;q.focus();const Q=ct(L,t.current,f),V="button"in L&&L.button===1,N="button"in L&&L.button===2;if(V||M||r.type==="move"&&!N)g({start:Q,originalOffset:f.canvasOffset});else if(!G){if(!zt(Q,f))return p(void 0),void b({mode:"default"});if(N){if(r.type==="selection"){const{shape:j}=Dt(k,n,Q,f,h,Je(L),!1);p(j),b({mode:"default"})}}else if(Je(L)&&(Z.current&&clearTimeout(Z.current),Z.current=setTimeout(()=>{ae(L,t.current)},500)),r.type==="selection"){const j=L.ctrlKey||L.shiftKey||L.metaKey?"add":"replace",{shape:_,mode:F}=Dt(k,n,Q,f,h,Je(L),E,j);p(_),b(F),F.mode==="selectionFrame"&&m({oldSelection:_,frame:[[Q[0],Q[1]],[Q[0],Q[1]]]})}else if(ps.some(j=>j===r.type)){const j=X(h)[0],_=t.current?.getContext("2d");if(!_)return;if(r.type==="brush"){if(j?.type==="brush"){const F=((A,te,ve)=>{const Y={...A,points:Ie(A.points.length,[[Math.round(te[0]),Math.round(te[1])]],A.points)};return xt(Y,ve)})(j,Q,f);y([F])}else{const F=Bs(_,r,Q,f);if(!F)return;e([F]),p(oe([F],f))}b({mode:"brush"})}else if(o.mode!=="preview"||j?.type!=="polygon"&&j?.type!=="curve"){if(r.type!=="picture"){const F=Bs(_,r,Q,f);if(!F)return;e([F]);const A=oe([F],f);p(A),F.type==="polygon"||F.type==="curve"?b({mode:"preview"}):(a(Xe),b({mode:"resize",cursorStartPosition:[Q[0]+f.selectionPadding,Q[1]+f.selectionPadding],originalShape:A,anchor:F.type==="line"?0:[1,1],selectedShapesLengthAtMouseDown:X(A).length}))}}else{const F=j.type==="polygon"?Ds(j,Q,f):Ws(j,Q,f);p(oe([F],f)),y([F],!0)}}}},S.useEffect(()=>{if(ie)return;const L=t.current;if(!L)return;const q=M=>Qe.current?.(M,L,T);return L.addEventListener("mousedown",q,{passive:!1}),L.addEventListener("touchstart",q,{passive:!1}),()=>{L.removeEventListener("mousedown",q),L.removeEventListener("touchstart",q)}},[ie,t,T]),S.useEffect(()=>{const L=t.current,q=t.current?.getContext("2d");if(!(!L||!q))return i?(W(L,M=>{if(r.type==="selection"){if(X(h).length!==1)return;const k=X(h)[0];if(k?.type==="text"){const Q=ct(M,t.current,f);return zt(Q,f)?void(Ht(q,h,Q,f)&&b({mode:"textedition",defaultValue:k.value})):void 0}if(k?.type==="polygon"){const Q=ct(M,t.current,f);if(!zt(Q,f))return;const V=Hs(q,k,Q,f);return void(V&&y([Gn(k,V.lineIndex,Q,f)]))}if(k?.type==="curve"){const Q=ct(M,t.current,f);if(!zt(Q,f))return;const V=((N,j,_,F,A=50)=>{if(j.locked||j.points.length<2)return!1;if(j.points.length<3)return Hs(N,j,_,F,A);const{center:te}=j.computed,ve=Ge(_,j.rotation??0,te);N.lineWidth=(j.style?.lineWidth??0)+A/F.canvasZoom;const Y=ma(j,j.points),Le=new Path2D;Le.moveTo(...Y[0]);for(let de=1;de<Y.length-2;de++){const Ee=Y[de-1],We=Y[de],re=Y[de+1],ge=Y[de+2],{cp1:se,cp2:ue}=Sa(Ee,We,re,ge);if(Le.bezierCurveTo(se[0],se[1],ue[0],ue[1],re[0],re[1]),N.isPointInStroke(Le,ve[0],ve[1]))return{lineIndex:de-1}}return!1})(q,k,Q,f);return void(V&&y([Kn(k,V.lineIndex,Q,f)]))}}}),()=>{D(L)}):void 0},[y,W,D,i,t,r,h,b,f]),{hoverMode:R}},ln=e=>e.childNodes.length?Array.from(e.childNodes).map(t=>ln(t)).join(""):e.nodeValue??"",bo=({disabled:e=!1,shape:t,defaultValue:a,updateValue:s,saveShapes:n,settings:o})=>{const r=S.useRef(null),l=S.useRef(n);S.useEffect(()=>{if(!r.current)return;const u=r.current,v=p=>{p.preventDefault();const m=p.clipboardData?.getData("text/plain");document.execCommand("insertText",!1,m)};u.addEventListener("paste",v),u.innerText="";for(const p of a){const m=document.createElement("div");p===""?m.innerHTML="<br/>":m.innerText=p,u.appendChild(m)}return u.focus(),()=>{u.removeEventListener("paste",v)}},[a]),S.useEffect(()=>{const u=l.current;return()=>{u()}},[]);const i=S.useMemo(()=>{const{borders:u,center:v}=t.computed;return he({point:[u.x,u.y],rotation:-(t.rotation??0),origin:v})},[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(" "),h=!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:h,role:"textbox",tabIndex:h?0:void 0,onInput:u=>{const v=Array.from(u.target.childNodes).map(p=>ln(p));s(v)},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}})},Qo=(e,t,a,s,n)=>{xs(e),((o,r)=>{const{canvasZoom:l,size:i,canvasSize:{width:c,height:h}}=r;if(i!=="fixed"||l>=1)return;o.fillStyle="#f5f5f5",o.fillRect(0,0,c,h);const u=As(r);o.clearRect(u.x,u.y,u.width,u.height),Es(o,r)})(e,a),((o,r)=>{const{canvasSize:{width:l,height:i},gridGap:c,canvasOffset:h,canvasSize:{scaleRatio:u}}=r;if(!c)return;o.strokeStyle="rgb(220,220,220)",o.lineWidth=1,o.save(),o.scale(u,u),o.beginPath();const v=h[0]%c,p=h[1]%c,m=Math.ceil(l/u/c)+2,g=Math.ceil(i/u/c)+2;for(let y=-5;y<m;y++)o.moveTo(v+(y+1)*c,p-c),o.lineTo(v+(y+1)*c,p+i/u+c);for(let y=-5;y<g;y++)o.moveTo(v-c,p+(y+1)*c),o.lineTo(v+l/u+c,p+(y+1)*c);o.stroke(),o.restore()})(e,a);for(let o=s.length-1;o>=0;o--)t.mode==="textedition"&&s[o]===n||Xs(e,X(n).find(r=>r.id===s[o].id)??s[o],a)},wo=S.forwardRef(({canGrow:e,shapes:t,duplicateShapes:a,addShapes:s,updateSingleShape:n,selectedShape:o,setSelectedShape:r,setSelectionFrame:l,hoveredShape:i,selectionFrame:c,refreshHoveredShape:h,refreshSelectedShapes:u,saveShapes:v,activeTool:p,setActiveTool:m,canvasOffsetStartData:g,setCanvasOffsetStartData:y,setCanvasOffset:w,setCanvasMoveAcceleration:C,isInsideComponent:b,isInsideCanvas:x,selectionMode:f,setSelectionMode:P,selectionWidth:H,selectionColor:E,settings:z,isEditMode:T,isShiftPressed:Z,isAltPressed:R,isSpacePressed:B,withFrameSelection:W,withSkeleton:D,withContextMenu:ae},J)=>{const I=S.useRef(null),$=S.useRef(null),G=z.canvasSize,ie=T,Qe=T?0:-1;S.useImperativeHandle(J,()=>I.current);const{hoverMode:L}=xo({addShapes:s,drawCanvasRef:I,setActiveTool:m,shapes:t,selectionMode:f,activeTool:p,isInsideComponent:b,isInsideCanvas:x,setCanvasOffset:w,selectedShape:o,canvasOffsetStartData:g,setCanvasOffsetStartData:y,setSelectedShape:r,setSelectionFrame:l,refreshHoveredShape:h,refreshSelectedShapes:u,updateSingleShape:n,duplicateShapes:a,saveShapes:v,setSelectionMode:P,setCanvasMoveAcceleration:C,isShiftPressed:Z,isAltPressed:R,withFrameSelection:W,settings:z,isSpacePressed:B,withContextMenu:ae}),q=S.useCallback(k=>{const Q=X(o)[0];if(Q?.type!=="text")return;const V=I.current?.getContext("2d");if(!V)return;const N=Fe(uo(V,Q,k,z),z);n([N])},[n,o,z]),M=k=>{if(T)return k.preventDefault(),k.stopPropagation(),!1};return S.useEffect(()=>{const k=I.current?.getContext("2d");k&&window.requestAnimationFrame(()=>Qo(k,f,z,t,o))},[t,f,o,z]),S.useEffect(()=>{const k=$.current?.getContext("2d");k&&window.requestAnimationFrame(()=>((Q,V,N,j,_,F,A,te,ve,Y,Le)=>{Q.reset(),Es(Q,N),Le&&te&&!X(A).find(de=>de.id===te.id)&&j.type==="selection"&&(V.mode==="default"||V.mode==="contextMenu"||V.mode==="textedition")&&_s({ctx:Q,shape:te,settings:N,selectionWidth:_,selectionColor:F,hoverMode:ve,selectionMode:V,withAnchors:!1}),A&&j.type!=="brush"&&_s({ctx:Q,shape:A,settings:N,selectionWidth:_,selectionColor:F,hoverMode:ve,selectionMode:V,withAnchors:V.mode!=="textedition"}),Y&&po({ctx:Q,selectionFrame:Y,settings:N})})(k,f,z,p,H,E,o,i,L,c,D))},[i,L,c,f,o,p,z,H,E,D]),d.jsx("div",{className:"react-paint-canvas-box",style:{"--react-paint-canvas-cursor":g?"grabbing":L.outOfView?"default":L.mode==="resize"?"pointer":p.type!=="selection"&&p.type!=="move"?"crosshair":L.mode==="translate"?"move":L.mode==="rotate"||p.type==="move"||B?"grab":"default"},children:d.jsxs("div",{className:"react-paint-canvas-container","data-grow":e,children:[d.jsx("canvas",{className:gs,ref:I,"data-grow":e,width:G.width,height:G.height,onContextMenu:M,tabIndex:Qe}),ie&&d.jsx("canvas",{className:fs,ref:$,width:G.width,height:G.height,"data-grow":e,onContextMenu:M}),T&&f.mode==="textedition"&&X(o)[0]?.type==="text"&&d.jsx(bo,{disabled:!z.features.edition,shape:X(o)[0],defaultValue:f.defaultValue,updateValue:q,saveShapes:v,settings:z})]})})}),cn="ArrowUp",dn="ArrowDown",un="ArrowLeft",hn="ArrowRight",Co="Delete",Mo="Backspace",ko="Escape",pn="Shift",gn="Alt",fn="Option",$t=" ",Po="A",jo="a",Lo="z",Vo="Z",Zo="y",Ho="Y",zo="+",To="-",Ao="0",vn="cut",mn="copy",Sn="paste",Eo=({isLoading:e=!1})=>{const[t,a]=S.useState("hidden");return S.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":Hn,"--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",{})]})})},Ro="infos",Do=4e3,Io=({type:e,text:t,duration:a})=>{const[s,n]=S.useState(!1);return S.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})},Wo=({snackbarList:e})=>d.jsx("div",{className:"react-paint-editor-snackbar-container",style:{"--react-paint-editor-snackbar-zindex":zn},children:e.map(t=>d.jsx(Io,{...t},t.id))}),No=S.forwardRef((e,t)=>{const{hidden:a=!1,disabled:s=!1,selected:n=!1,icon:o,children:r,className:l="",title:i,onClick:c,...h}=e,u=s?-1:0,v=S.useRef(null);return S.useImperativeHandle(t,()=>v.current),d.jsxs("label",{className:`react-paint-editor-button ${l}`,title:i,onClick:c,"data-disabled":+s,"data-selected":+n,"data-hidden":+a,tabIndex:u,onKeyDown:p=>{p.key===$t&&(p.preventDefault(),p.stopPropagation())},onKeyUp:p=>{p.preventDefault(),p.stopPropagation(),p.key===$t&&v.current?.click()},children:[d.jsx("input",{ref:v,disabled:s,...h}),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}})]})]})}),U=S.forwardRef((e,t)=>{if(e.type==="file"||e.type==="color")return d.jsx(No,{...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]}),Fo=e=>{switch(e){case"brush":return Ra;case"line":return Na;case"polygon":return ia;case"curve":return Oa;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""}},Oo=({disabled:e=!1,shape:t,selected:a,layoutDragging:s,toggleShapeVisibility:n,toggleShapeLock:o,setLayoutDragging:r,handleRemove:l,handleSelect:i,onSwapShapes:c})=>{const h=S.useRef(null),{isOver:u}=(({disabled:v=!1,ref:p,shape:m,layoutDragging:g,setLayoutDragging:y,handleSelect:w,onSwapShapes:C})=>{const[b,x]=S.useState(!1);return S.useEffect(()=>{g||x(!1)},[g]),S.useEffect(()=>{const f=p.current;if(!f)return;const P=()=>{y(void 0)},H=R=>(R.preventDefault&&R.preventDefault(),!1),E=R=>{w([m]),R.dataTransfer&&(R.dataTransfer.effectAllowed="move",R.dataTransfer.setData("draggableShapeId",m.id),y(m.id))},z=()=>{g!==m.id&&x(!0)},T=()=>{x(!1)},Z=R=>(R.stopPropagation(),R.dataTransfer&&C(R.dataTransfer.getData("draggableShapeId"),m.id),!1);return v||(f.addEventListener("dragstart",E),f.addEventListener("dragend",P),f.addEventListener("dragover",H),f.addEventListener("dragenter",z),f.addEventListener("dragleave",T),f.addEventListener("drop",Z)),()=>{v||(f.removeEventListener("dragstart",E),f.removeEventListener("dragend",P),f.removeEventListener("dragover",H),f.removeEventListener("dragenter",z),f.removeEventListener("dragleave",T),f.removeEventListener("drop",Z))}},[v,p,m,y,w,C,g]),{isOver:b}})({disabled:e,ref:h,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":+u,onClick:v=>{e||(v.preventDefault(),i([t]))},"data-selected":+a,ref:h,tabIndex:-1,children:[d.jsx("span",{dangerouslySetInnerHTML:{__html:Fo(t.type)}}),d.jsx("span",{children:t.id}),d.jsx("div",{className:"react-paint-editor-layouts-separator"}),d.jsx(U,{className:"react-paint-editor-layouts-visible-button",title:t.visible?"Hide":"Show","data-visible":t.visible!==!1,disabled:e,selected:a,onClick:v=>{e||(v.preventDefault(),v.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(U,{className:"react-paint-editor-layouts-locked-button",title:t.locked?"Locked":"Unlocked","data-locked":!!t.locked,disabled:e,selected:a,onClick:v=>{e||(v.preventDefault(),v.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(U,{className:"react-paint-editor-layouts-remove-button",title:"Remove",disabled:e,onClick:v=>{e||(v.preventDefault(),v.stopPropagation(),l([t]))},icon:Da})]})},Bo=({gridFormat:e,setGridFormat:t,settings:a,shapes:s,removeShape:n,toggleShapeVisibility:o,toggleShapeLock:r,selectedShapes:l,swapShapes:i,selectShapes:c,isLayoutPanelShown:h})=>{const[u,v]=S.useState(void 0),p=!a.features.edition;return h?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(U,{icon:'<svg><path d="M18.333 15.854 16.583 14.104V13.354H15.833L14.083 11.604H16.583V8.375H13.375V10.896L11.625 9.146V8.375H10.875L9.125 6.625H11.625V3.417H8.396V5.896L6.646 4.146V3.417H5.896L4.146 1.667H16.583Q17.312 1.667 17.823 2.177Q18.333 2.688 18.333 3.417ZM13.375 6.625H16.583V3.417Q16.583 3.417 16.583 3.417Q16.583 3.417 16.583 3.417H13.375ZM16.771 19.229 15.854 18.333H3.417Q2.688 18.333 2.177 17.823Q1.667 17.312 1.667 16.583V4.125L0.812 3.271L2.042 2.021L18 18ZM13.375 16.583H14.104L13.375 15.833ZM8.396 11.604H9.125L8.396 10.854ZM8.396 16.583H11.625V14.083L10.875 13.354H8.396ZM3.417 6.625H4.167L3.417 5.875ZM3.417 11.604H6.646V9.104L5.917 8.375H3.417ZM6.646 16.583V13.354H3.417V16.583Q3.417 16.583 3.417 16.583Q3.417 16.583 3.417 16.583Z"/></svg>',className:"react-paint-editor-layouts-grid-button",selected:e==="none",disabled:p,onClick:()=>t("none")}),["small","medium","large"].map(m=>d.jsx(U,{className:"react-paint-editor-layouts-grid-button",selected:e===m,disabled:p,onClick:()=>t(m),children:m.charAt(0).toUpperCase()},m))]}),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(m=>d.jsx(Oo,{shape:m,disabled:p,layoutDragging:u,setLayoutDragging:v,selected:X(l).some(g=>g.id===m.id)??!1,handleSelect:c,handleRemove:n,onSwapShapes:i,toggleShapeVisibility:o,toggleShapeLock:r},m.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]=S.useState(Se("settings_")),h=e===c;return o.length?d.jsxs(d.Fragment,{children:[d.jsx(U,{selected:h,title:a,disabled:n,onClick:()=>{t(u=>u===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}})}),h&&d.jsx(dt,{title:a,alignment:"left",position:"bottom",children:d.jsxs("div",{className:"react-paint-editor-colorfield-wrapper",children:[o.map(u=>d.jsx(U,{title:u,selected:u===l,color:u,icon:u==="transparent"?s==="fill"?Ua:$a:void 0,onClick:()=>{i(r,u)},children:u!=="transparent"&&d.jsx("div",{className:"react-paint-editor-colorfield-color",color:u,"data-mode":s,style:{"--react-paint-editor-colorfield-color-value":u}})},u)),d.jsx(U,{type:"color",title:"Custom color",selected:l!==""&&!o.includes(l),value:l,onChange:u=>{const v=+u.target.value;i(r,Number.isNaN(v)?u.target.value:v)},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},Yo=({disabled:e=!1,selectedShape:t,removeShape:a})=>d.jsx(U,{title:"Delete",disabled:e,"data-disabled":+e,onClick:()=>{a(X(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[h]=S.useState(Se("settings_")),u=t===h;return l.length?d.jsxs(d.Fragment,{children:[d.jsx(U,{selected:u,title:s,icon:r,disabled:n,onClick:()=>{a(v=>v===h?void 0:h)}}),u&&d.jsx(dt,{title:s,alignment:"left",fitContainer:!0,position:"bottom",children:d.jsx("div",{className:"react-paint-editor-selectfield-wrapper",children:l.map(v=>d.jsx(U,{title:`${v}`,onClick:()=>(p=>{c(o,p)})(v),selected:i===v,style:{"--react-paint-editor-button-padding":"16px"},children:d.jsx(e,{children:v})},v))})})]}):null},Xo=({children:e})=>d.jsx("span",{className:"react-paint-editor-fontfamily-option",style:{"--react-paint-editor-fontfamily-family":e},children:e}),yn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Xo,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,$o=({disabled:e,toggleLayoutPanel:t})=>d.jsx(U,{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"}),Uo=({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"})]}),xn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Uo,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,qo=({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",{})]}),bn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,values:s,defaultValue:n,valueChanged:o})=>s.length?d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:qo,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:h="",valueChanged:u,saveShapes:v})=>{const p=r===void 0,m=p?"N/A":`${Math.round(r)}${h}`,[g]=S.useState(Se("settings_")),y=((C,b=500)=>{const x=S.useRef(null),f=S.useCallback((...P)=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>C(...P),b)},[C,b]);return S.useEffect(()=>()=>{x.current&&clearTimeout(x.current)},[]),f})(v),w=e===g;return l===i?null:d.jsxs(d.Fragment,{children:[d.jsx(U,{selected:w,title:a,disabled:n,icon:s,onClick:()=>{t(C=>C===g?void 0:g)}}),w&&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":+p,onChange:C=>{const b=+C.target.value,x=Number.isNaN(b)?C.target.value:b;u(o,x,!1),y()}}),d.jsx("span",{children:m})]})})})]})},Go=({children:e})=>d.jsx("span",{children:e===0?"Non":"Oui"}),_o=[0,1],Qn=({selectedSettings:e,setSelectedSettings:t,disabled:a=!1,defaultValue:s,valueChanged:n})=>d.jsx(Gt,{selectedSettings:e,setSelectedSettings:t,CustomOption:Go,title:"Fermer les points",icon:ia,disabled:a,field:"closedPoints",values:_o,defaultValue:s,valueChanged:n}),Ko=({disabled:e=!1,className:t,toggleZoomPanel:a})=>d.jsx(U,{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]=S.useState(Se("settings_"));return n.length!==2?null:d.jsx(U,{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(bn,{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(xn,{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(Qn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:l,defaultValue:t.style?.closedPoints}),"fontFamily"in a.settings&&!a.settings.fontFamily.hidden&&d.jsx(yn,{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:Ba,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(bn,{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(xn,{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(Qn,{selectedSettings:n,setSelectedSettings:o,disabled:s,valueChanged:l,defaultValue:e.settings?.closedPoints.default}),"fontFamily"in e.settings&&!e.settings.fontFamily.hidden&&d.jsx(yn,{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:Ba,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,Jo=({width:e,availableTools:t,updateToolSettings:a,layersManipulation:s=!1,toggleLayoutPanel:n,activeTool:o,saveShapes:r,selectedShape:l,canvas:i,settings:c,updateShape:h,removeShape:u,isZoomPanelShown:v,setIsZoomPanelShown:p})=>{const[m,g]=S.useState(void 0),[y,w]=S.useState(!1),C=c.size==="infinite"||c.features.zoom,b=!c.features.edition,x=()=>{w(T=>!T)},f=((T,Z)=>{const R=X(T).map(W=>Z.find(D=>D.id===W?.toolId)||Z.find(D=>D.type===W?.type)).filter(W=>W!==void 0);if(!R.length)return;if(R.length===1)return R[0];const B=R.slice(1).reduce((W,D)=>{const ae={};for(const J in D.settings){if(W[J]===void 0||D.settings[J]?.hidden||W[J]?.hidden)continue;const I=W[J],$=D.settings[J],G={};"min"in $&&"min"in I&&$.min===I.min&&"max"in $&&"max"in I&&$.max===I.max&&"step"in $&&"step"in I&&$.step===I.step&&(G.min=$.min,G.max=$.max,G.step=$.step),"values"in $&&"values"in I&&$.values?.join(",")===I.values?.join(",")&&(G.values=$.values),(Object.keys(G).length>0||J==="closedPoints")&&(ae[J]=G)}return ae},R[0].settings);return{id:R.map(W=>W.id).join("-"),icon:"",label:"group",type:"group",settings:B}})(l,t),P=(f?Object.keys(f.settings).length+1:"settings"in o?Object.keys(o.settings).length:0)+ +s+ +C,H=e<40*P,E=(T,Z,R=!0)=>{if(X(l).length){const B=X(l).map(W=>Fe(Ie(["style",T],Z,W),c));h(B,R),f&&a(f.id,T,Z)}else a(o.id,T,Z)},z=(T,Z)=>{if(X(l).length){const R=X(l).map(B=>{if(B.type!=="text")return B;const W=i?.getContext("2d");if(!W)return B;const D=Ie(["style",T],Z,B),ae=Xt(W,D.value,D.width,D.style?.fontBold??!1,D.style?.fontItalic??!1,D.style?.fontFamily);return Fe({...D,fontSize:ae,height:ae*D.value.length},c)});h(R,!0),f&&a(f.id,T,Z)}else a(o.id,T,Z)};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:[C&&d.jsx(Ko,{className:v?"react-paint-editor-bar-zoom-button-opened":void 0,toggleZoomPanel:()=>{p(T=>!T)}}),H&&P>2&&d.jsx(U,{disabled:b,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:[!H&&d.jsx(za,{saveShapes:r,activeTool:o,selectedShape:l,selectedShapeTool:f,disabled:b,selectedSettings:m,setSelectedSettings:g,handleShapeStyleChange:E,handleShapeFontFamilyChange:z}),o.type==="selection"&&d.jsx(Yo,{disabled:b,selectedShape:l,removeShape:u})]}):!H&&d.jsx(za,{saveShapes:r,activeTool:o,selectedShape:l,selectedShapeTool:f,disabled:b,selectedSettings:m,setSelectedSettings:g,handleShapeStyleChange:E,handleShapeFontFamilyChange:z})]}),d.jsx("div",{className:"react-paint-editor-settings-separator"}),s&&d.jsx($o,{disabled:b,toggleLayoutPanel:n})]}),y&&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:b,selectedSettings:m,setSelectedSettings:g,handleShapeStyleChange:E,handleShapeFontFamilyChange:z})})]})},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})}),wn=({disabled:e=!1,withText:t=!1,loadFile:a,type:s,img:n,accept:o})=>{const r=S.useRef(null);return d.jsx(U,{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})},Te=({type:e,img:t,isActive:a,withText:s=!1,disabled:n=!1,setActive:o})=>d.jsx(U,{disabled:n,selected:a,onClick:()=>{o(e)},title:e.label??e.type,icon:t,children:s?e.label:void 0}),Cn=(e,t)=>!!(e.target instanceof Node&&t)&&t.contains(e.target),Ta=({trigger:e="click",buttonElt:t})=>{const[a,s]=S.useState(!1),[,n]=S.useTransition(),o=S.useCallback(()=>{n(()=>{s(!1)})},[]);return S.useEffect(()=>{if(!t)return;if(a){const l=c=>{Cn(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}},ei=({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:h,addPicture:u,loadFile:v,togglePictureUrlModal:p,saveFile:m,toggleExportModal:g,withUploadPicture:y,withUrlPicture:w})=>{const C=S.useRef(null),{isOpen:b,closeMenu:x}=Ta({buttonElt:C.current}),f=P=>async(...H)=>{await P(...H),x()};return t||y||w||c||h?d.jsx("div",{className:"react-paint-editor-toolbox-relative",children:d.jsxs("div",{ref:C,children:[d.jsx(U,{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>'}),b&&d.jsxs(Jt,{alignment:"right",position:"top",children:[t&&d.jsxs(d.Fragment,{children:[d.jsx(Te,{withText:!0,type:vt,disabled:i||!a,img:vt.icon,isActive:e.id===vt.id,setActive:f(o)}),d.jsx(Te,{withText:!0,type:mt,disabled:i||!s,img:mt.icon,isActive:e.id===mt.id,setActive:f(r)}),d.jsx(Te,{withText:!0,type:St,disabled:i||!n,img:St.icon,isActive:e.id===St.id,setActive:f(l)}),(y||w||c)&&d.jsx("hr",{})]}),y&&d.jsx(wn,{withText:!0,type:cs,disabled:i,loadFile:f(u),img:cs.icon,accept:"image/png, image/gif, image/jpeg, image/svg+xml, image/webp"}),w&&d.jsx(U,{disabled:i,selected:!1,onClick:f(p),title:"Add picture from URL",icon:'<svg><path d="M9.188 16.542V14.938Q8.5 14.938 8.021 14.458Q7.542 13.979 7.542 13.292V12.458L3.583 8.5Q3.5 8.875 3.458 9.25Q3.417 9.625 3.417 10Q3.417 12.5 5.062 14.365Q6.708 16.229 9.188 16.542ZM14.854 14.438Q15.708 13.521 16.146 12.385Q16.583 11.25 16.583 10Q16.583 7.979 15.469 6.313Q14.354 4.646 12.479 3.917V4.229Q12.479 4.917 12 5.396Q11.521 5.875 10.833 5.875H9.188V7.521Q9.188 7.875 8.948 8.115Q8.708 8.354 8.354 8.354H6.708V10H11.646Q12 10 12.24 10.229Q12.479 10.458 12.479 10.812V13.292H13.292Q13.833 13.292 14.26 13.604Q14.688 13.917 14.854 14.438ZM10 18.333Q8.271 18.333 6.75 17.677Q5.229 17.021 4.104 15.896Q2.979 14.771 2.323 13.25Q1.667 11.729 1.667 10Q1.667 8.271 2.323 6.75Q2.979 5.229 4.104 4.104Q5.229 2.979 6.75 2.323Q8.271 1.667 10 1.667Q11.729 1.667 13.25 2.323Q14.771 2.979 15.896 4.104Q17.021 5.229 17.677 6.75Q18.333 8.271 18.333 10Q18.333 11.729 17.677 13.25Q17.021 14.771 15.896 15.896Q14.771 17.021 13.25 17.677Q11.729 18.333 10 18.333Z"/></svg>',children:"Add picture from URL"}),(y||w)&&c&&d.jsx("hr",{}),c&&d.jsxs(d.Fragment,{children:[d.jsx(wn,{withText:!0,type:ls,disabled:i,loadFile:f(v),img:ls.icon,accept:"application/JSON"}),d.jsx(Te,{withText:!0,disabled:i,type:da,img:da.icon,isActive:e.id===da.id,setActive:f(m)})]}),h&&d.jsx(Te,{withText:!0,disabled:i,type:ca,img:ca.icon,isActive:e.id===ca.id,setActive:f(g)})]})]})}):null},ti=({togglePictureUrlModal:e,addPicture:t})=>{const a=S.useRef(null);return S.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(U,{onClick:e,children:"Annuler"}),d.jsx(U,{type:"submit",selected:!0,children:"Ajouter"})]})})},Mn="Choose export settings",ai=({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:Mn,children:[d.jsx("h3",{children:Mn}),d.jsx("hr",{}),d.jsx(U,{onClick:()=>a("currentZoom"),children:"Exporter la vue actuelle"}),d.jsx(U,{onClick:()=>a("defaultView"),children:"Exporter le canevas par défaut"}),d.jsx(U,{onClick:()=>a("fitToShapes"),children:"Exporter le dessin entier"}),d.jsx(U,{selected:!0,onClick:e,children:"Annuler"})]})},si=({activeTool:e,group:t,disabled:a=!1,setActiveToolFromId:s})=>{const n=S.useRef(null),[o,r]=S.useState(!1),[,l]=S.useTransition(),[i,c]=S.useState(void 0),h=p=>{c(p),s(p.id)};if(S.useEffect(()=>{if(!o)return;const p=m=>{!Cn(m,n.current)&&r(!1)};return document.addEventListener("mousedown",p,{passive:!1}),document.addEventListener("touchstart",p,{passive:!1}),()=>{document.removeEventListener("mousedown",p),document.removeEventListener("touchstart",p)}},[o]),"type"in t)return d.jsx(Te,{disabled:a,type:t,img:t.icon,isActive:e.id===t.id,setActive:h});if(!t.toolsType.length)return null;if(t.toolsType?.length===1)return d.jsx(Te,{disabled:a,type:t.toolsType[0],img:t.toolsType[0].icon,isActive:e.id===t.toolsType[0].id,setActive:h});const u=t?.toolsType.find(p=>p.type===e.type)!==void 0,v=(i?i.icon:t.toolsType?.[0]?.icon)??t.title;return d.jsxs("div",{className:"react-paint-editor-toolbargroup-relative",children:[d.jsx(U,{selected:u,title:t.title,disabled:a,onClick:()=>{i?s(i.id):t.toolsType?.[0]&&h(t.toolsType[0]),l(()=>{r(!0)})},icon:v}),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(p=>d.jsx(Te,{disabled:a,type:p,img:p.icon,isActive:e.id===p.id,setActive:h},p.id))})})]})},ni=[{title:"brush",toolsType:["brush"],vertical:!1},{title:"lines",toolsType:["line","curve","polygon"],vertical:!1},{title:"shapes",toolsType:["rect","square","circle","ellipse"],vertical:!1},"text"],oi=({settings:e,width:t,activeTool:a,hasActionToUndo:s=!1,hasActionToRedo:n=!1,hasActionToClear:o=!1,withLoadAndSave:r,withExport:l,clearCanvas:i,setActiveTool:c,undoAction:h,redoAction:u,addPicture:v,loadFile:p,saveFile:m,exportCanvasInFile:g,availableTools:y,withUrlPicture:w,withUploadPicture:C})=>{const b=((I,$)=>{const G=$.flatMap(ie=>{if(typeof ie!="object")return I.filter(L=>L.type===ie);const Qe=I.filter(L=>ie.toolsType.includes(L.type));return Qe?{...ie,toolsType:Qe}:null});return La(G)})(y,ni),x=!e.features.edition,f=t<40*(6+b.length),P=t<40*(3+b.length),[H,E]=S.useState(!1),[z,T]=S.useState(!1),[Z,R]=S.useState(!1),B=()=>{E(I=>!I)},W=()=>{R(I=>!I)},D=I=>{c(I),E(!1)},ae=I=>{D(y.find($=>$.id===I)??a)},J=y.find(I=>I.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(Te,{type:Xe,disabled:x,img:Xe.icon,isActive:a.id===Xe.id,setActive:D}),(e.size==="infinite"||e.features.zoom)&&d.jsx(Te,{type:ua,disabled:x,img:ua.icon,isActive:a.id===ua.id,setActive:D}),P?d.jsx(U,{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:J}):b.map(I=>d.jsx(si,{disabled:x,activeTool:a,group:I,setActiveToolFromId:ae},"id"in I?I.id:I.title))]}),!f&&d.jsxs(d.Fragment,{children:[d.jsx(Te,{type:vt,disabled:x||!s,img:vt.icon,isActive:a.id===vt.id,setActive:h}),d.jsx(Te,{type:mt,disabled:x||!n,img:mt.icon,isActive:a.id===mt.id,setActive:u}),d.jsx(Te,{type:St,disabled:x||!o,img:St.icon,isActive:a.id===St.id,setActive:i})]}),d.jsx(ei,{withActionsInMenu:f,disabled:x,activeTool:a,addPicture:v,loadFile:p,saveFile:m,togglePictureUrlModal:()=>{T(!0)},toggleExportModal:W,withUploadPicture:C,withUrlPicture:w,withLoadAndSave:r,withExport:l,hasActionToUndo:s,hasActionToRedo:n,hasActionToClear:o,undoAction:h,redoAction:u,clearCanvas:i})]}),H&&d.jsx(Ut,{className:"react-paint-editor-toolbar-modal",onClose:B,title:"Outils",children:y.map(I=>I.type==="picture"?null:d.jsx(Te,{disabled:x,type:I,img:I.icon,withText:!1,isActive:a.id===I.id,setActive:D},I.id))}),z&&d.jsx(ti,{togglePictureUrlModal:()=>{T(I=>!I)},addPicture:v}),Z&&d.jsx(ai,{toggleExportModal:W,exportCanvasInFile:g})]})},ea={none:0,small:10,medium:20,large:40},ii={toolbarBackgroundColor:"white",dividerColor:"#36418129",fontRadius:8,fontDisabledColor:"#3641812b",fontDisabledBackgroundColor:"transparent",fontColor:"#364181",fontBackgroundColor:"transparent",fontSelectedColor:"white",fontSelectedBackgroundColor:"#364181",fontHoverColor:"#364181",fontHoverBackgroundColor:"#afd8d8"},ri=()=>{const e=S.useRef([]),[t,a]=S.useState([]);return S.useEffect(()=>()=>{for(const s of e.current)clearTimeout(s)},[]),{snackbarList:t,addSnackbar:({type:s=Ro,duration:n=Do,text:o})=>{const r={id:Se("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)]}}},li=({moveShapes:e,selectAllShapes:t,selectionMode:a,transformShape:s,settings:n,canvasRef:o,closeContextMenu:r,toggleShapeVisibility:l,toggleShapeLock:i,removeShape:c,duplicateShapes:h,copiedShape:u,setCopiedShape:v,pasteShapes:p,removeShapePoint:m})=>{const g=S.useRef(null),y=S.useRef(null),{isOpen:w}=Ta({trigger:"hover",buttonElt:g.current}),{isOpen:C}=Ta({trigger:"hover",buttonElt:y.current}),{originalShape:b,cursorStartPosition:x,anchor:f}=a,P=X(b),H=P.length>0,E=P.length===1&&(P[0]?.type==="polygon"||P[0]?.type==="curve")&&f!==void 0&&P[0]?.points?.length>2,z=!P.some(D=>D.visible===!1);P.some(D=>D.locked);const T=16+36*(2+(H?8:0)+(E?1:0))+16*(H?3:1),[Z]=S.useState(()=>[(x[0]+n.canvasOffset[0])*n.canvasSize.scaleRatio,36+(x[1]+n.canvasOffset[1])*n.canvasSize.scaleRatio]),[R,B]=S.useState();S.useEffect(()=>{const D=o?.current?.getBoundingClientRect();if(!D)return;const ae=D.left+Z[0],J=D.top+Z[1],I=Math.max(0,Math.min(ae,window.innerWidth-176))-D.left,$=Math.max(0,Math.min(J,window.innerHeight-T))-D.top,G=I>window.innerWidth-176-Math.min(I,200)?"left":"right";B({x:I,y:$,subMenuPosition:G})},[o,Z,T]);const W=R?{"--react-paint-editor-toolbox-contextmenu-transform":`translate3D(${R.x}px, ${R.y}px, 0)`}:{display:"none"};return d.jsxs(Jt,{className:"react-paint-editor-toolbox-contextmenu",style:W,children:[H&&d.jsxs(d.Fragment,{children:[E&&d.jsx(U,{onClick:()=>{E&&m(P[0],f),r()},children:"Delete point"}),d.jsxs("div",{className:"react-paint-editor-toolbox-contextmenu-group",ref:g,children:[d.jsx(U,{icon:Fa,children:"Organize"}),w&&d.jsxs(Jt,{position:R?.subMenuPosition,children:[d.jsx(U,{onClick:()=>{H&&e(P,"forward"),r()},children:"Move forward"}),d.jsx(U,{onClick:()=>{H&&e(P,"first"),r()},children:"Put on first"}),d.jsx(U,{onClick:()=>{H&&e(P,"backward"),r()},children:"Move backward"}),d.jsx(U,{onClick:()=>{H&&e(P,"last"),r()},children:"Put on last"})]})]}),d.jsxs("div",{className:"react-paint-editor-toolbox-contextmenu-group",ref:y,children:[d.jsx(U,{icon:Fa,children:"Transform"}),C&&d.jsxs(Jt,{position:R?.subMenuPosition,children:[d.jsx(U,{onClick:()=>{H&&s(P,b.computed.center,"rotateClockwise"),r()},children:"Rotate clockwise"}),d.jsx(U,{onClick:()=>{H&&s(P,b.computed.center,"rotateCounterclockwise"),r()},children:"Rotate counterclockwise"})]})]}),d.jsx("hr",{}),d.jsx(U,{onClick:()=>{H&&(v(oe(P,n)),c(P)),r()},children:"Cut"}),d.jsx(U,{onClick:()=>{H&&v(oe(P,n)),r()},children:"Copy"})]}),d.jsx(U,{onClick:()=>{u&&p(ja(u,n)),r()},disabled:!u,children:"Paste"}),d.jsx("hr",{}),H&&d.jsxs(d.Fragment,{children:[d.jsx(U,{onClick:()=>{H&&h(P,!0,!0),r()},children:"Duplicate"}),d.jsx(U,{onClick:()=>{H&&l(P.filter(D=>z?D.visible!==!1:D.visible===!1)),r()},children:z?"Hide":"Show"}),d.jsx(U,{onClick:()=>{H&&c(P),r()},children:"Delete"}),d.jsx("hr",{})]}),d.jsx(U,{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:h,setSelectionFrame:u,refreshSelectedShapes:v,refreshHoveredShape:p,duplicateShapes:m,removeShape:g,updateShape:y,backwardShape:w,forwardShape:C,saveShapes:b,refs:x,width:f,height:P,settings:H,setCanvasSize:E,setCanvasOffset:z,pasteShapes:T,activeTool:Z,setActiveTool:R,isInsideComponent:B,isInsideCanvas:W,isEditMode:D,canvas:{withSkeleton:ae,withFrameSelection:J,withContextMenu:I,canGrow:$,canShrink:G},canvasOffsetStartData:ie,setCanvasOffsetStartData:Qe,selectionMode:L,setSelectionMode:q,setCanvasMoveAcceleration:M,isShiftPressed:k,isAltPressed:Q,isSpacePressed:V,copiedShape:N,setCopiedShape:j,setShiftPressed:_,setAltPressed:F,setCanvasZoom:A,resetZoom:te,setIsSpacePressed:ve}=s,{canvasBackgroundColor:Y,canvasSelectionColor:Le,canvasSelectionWidth:de}={...En,...e},Ee=S.useRef(null),We=S.useCallback(re=>{E({realWidth:f,realHeight:P,width:re,height:P*re/f,scaleRatio:re/f})},[f,P,E]);return(({isInsideComponent:re,isInsideCanvas:ge,selectedShape:se,isEditingText:ue,settings:K,copiedShape:ne,setCopiedShape:le,setSelectedShape:we,setActiveTool:Re,setCanvasZoom:Ae,resetZoom:ye,setSelectionMode:De,setSelectionFrame:Ct,selectAllShapes:Mt,removeShape:ut,pasteShapes:Oe,updateShapes:kt,backwardShape:Pt,forwardShape:Ve,setShiftPressed:at,setAltPressed:st,setIsSpacePressed:_e})=>{S.useEffect(()=>{const ht=O=>{se&&(ue||(O.preventDefault(),le({...se})))},pt=O=>{se&&(ue||(O.preventDefault(),le({...se}),ut(X(se))))},gt=O=>{ne&&(ue||(O.preventDefault(),Oe(ja(ne,K))))},pe=O=>{switch(O.key){case pn:at(!1);break;case gn:case fn:st(!1);break;case $t:_e(!1)}},me=O=>{if(O.metaKey||O.ctrlKey){if(O.key===Vo||O.key===Lo)return O.preventDefault(),O.stopPropagation(),void(O.shiftKey?Ve():Pt());if(!ys()&&(O.key===Ho||O.key===Zo))return O.preventDefault(),O.stopPropagation(),void Ve();if(O.key===Po||O.key===jo)return O.preventDefault(),O.stopPropagation(),void Mt();if(O.key===zo)return O.preventDefault(),O.stopPropagation(),void Ae("zoom");if(O.key===To)return O.preventDefault(),O.stopPropagation(),void Ae("unzoom");if(O.key===Ao)return O.preventDefault(),O.stopPropagation(),void ye()}if(O.key===pn)return O.preventDefault(),O.stopPropagation(),void at(!0);if(O.key===$t&&ge)return O.preventDefault(),O.stopPropagation(),void _e(!0);if(O.key===gn||O.key===fn)return O.preventDefault(),O.stopPropagation(),void st(!0);if(!se)return;if(O.key===ko)return we(void 0),Re(Xe),De({mode:"default"}),void Ct(void 0);if(ue)return;const et={[un]:[K.gridGap?-K.gridGap:-1,0],[hn]:[K.gridGap?K.gridGap:1,0],[dn]:[0,K.gridGap?K.gridGap:1],[cn]:[0,K.gridGap?-K.gridGap:-1]};switch(O.key){case un:case hn:case dn:case cn:O.preventDefault(),O.stopPropagation(),kt(Gs(et[O.key],se,[0,0],K,!0));break;case Co:case Mo:O.preventDefault(),O.stopPropagation(),ut(X(se))}};if(re)return document.addEventListener("keydown",me),document.addEventListener("keyup",pe),document.addEventListener(mn,ht),document.addEventListener(Sn,gt),document.addEventListener(vn,pt),()=>{document.removeEventListener("keydown",me),document.removeEventListener("keyup",pe),document.removeEventListener(mn,ht),document.removeEventListener(Sn,gt),document.removeEventListener(vn,pt)}},[re,ge,ne,ue,se,K,kt,ut,we,Oe,Pt,Ve,at,st,Re,De,Ct,le,Ae,ye,_e,Mt])})({isInsideComponent:B,isInsideCanvas:W,isEditingText:L.mode==="textedition",settings:H,selectedShape:o,copiedShape:N,setCopiedShape:j,selectAllShapes:h,setSelectedShape:c,removeShape:g,pasteShapes:T,updateShapes:y,backwardShape:w,forwardShape:C,setShiftPressed:_,setAltPressed:F,setActiveTool:R,setSelectionMode:q,setSelectionFrame:u,setCanvasZoom:A,resetZoom:te,setIsSpacePressed:ve}),(({onResized:re,element:ge})=>{S.useEffect(()=>{const se=ge.current;if(!se)return;const ue=new ResizeObserver(K=>{const ne=K?.[0]?.borderBoxSize?.[0],{width:le,height:we}=ne?{width:ne.inlineSize,height:ne.blockSize}:K?.[0]?.contentRect??{};le!==void 0&&we!==void 0&&re(le,we)});return ue.observe(se),()=>{ue.unobserve(se)}},[ge,re])})({element:Ee,onResized:We}),d.jsx("div",{ref:Ee,className:"react-paint-app-row"+(t?` ${t}`:""),"data-grow":$,"data-shrink":G,style:{"--react-paint-app-row-width":H.canvasSize.width,"--react-paint-app-canvaswidth":f,"--react-paint-app-canvasheight":P,"--react-paint-app-row-aspectratio":`calc(${H.canvasSize.width} / ${H.canvasSize.height})`,"--react-paint-app-canvas-bg":Y,...a},children:d.jsx(wo,{duplicateShapes:m,isSpacePressed:V,withContextMenu:I,ref:x.canvas,canGrow:$,isInsideComponent:B,isInsideCanvas:W,activeTool:Z,setActiveTool:R,canvasOffsetStartData:ie,setCanvasOffsetStartData:Qe,shapes:n.current,addShapes:i,updateSingleShape:y,selectedShape:o,selectionFrame:r,setSelectedShape:c,setSelectionFrame:u,hoveredShape:l,refreshHoveredShape:p,refreshSelectedShapes:v,settings:H,setCanvasOffset:z,saveShapes:b,selectionMode:L,setSelectionMode:q,setCanvasMoveAcceleration:M,selectionColor:Le,selectionWidth:de,isEditMode:D,isShiftPressed:k,isAltPressed:Q,withFrameSelection:J,withSkeleton:ae})})},Ke.Editor=({editorProps:e,className:t,style:a,options:s,children:n})=>{const{selectionMode:o,setSelectionMode:r,shapesRef:l,addPictureShape:i,moveShapes:c,swapShapes:h,toggleShapeVisibility:u,toggleShapeLock:v,canGoBackward:p,canGoForward:m,canClear:g,selectedShape:y,copiedShape:w,setCopiedShape:C,pasteShapes:b,removeShape:x,duplicateShapes:f,updateShape:P,backwardShape:H,forwardShape:E,removeShapePoint:z,transformShape:T,refs:Z,width:R,height:B,selectTool:W,selectShapes:D,selectAllShapes:ae,activeTool:J,setActiveTool:I,setAvailableTools:$,isEditMode:G,availableTools:ie,gridGap:Qe,setGridGap:L,loadFile:q,exportPicture:M,exportData:k,clearCanvas:Q,settings:V,setCanvasZoom:N,saveShapes:j,canvas:{canGrow:_,layersManipulation:F,withExport:A,withLoadAndSave:te,withUploadPicture:ve,withUrlPicture:Y,withContextMenu:Le}}=e,{toolbarBackgroundColor:de,dividerColor:Ee,fontRadius:We,fontDisabledColor:re,fontDisabledBackgroundColor:ge,fontColor:se,fontBackgroundColor:ue,fontSelectedColor:K,fontSelectedBackgroundColor:ne,fontHoverColor:le,fontHoverBackgroundColor:we}={...ii,...s},Re=V.size==="infinite"||V.features.zoom,[Ae,ye]=S.useState(!1),[De,Ct]=S.useState(!1),[Mt,ut]=S.useState(Re),Oe=Re&&Mt,kt=Qe>=ea.large?"large":Qe>=ea.medium?"medium":Qe>=ea.small?"small":"none",{snackbarList:Pt,addSnackbar:Ve}=ri(),at=S.useCallback((pe,me,O)=>{$(et=>et.map(Tt=>Tt.id===pe?Ie(["settings",me,"default"],O,Tt):Tt)),I(et=>et.id===pe?Ie(["settings",me,"default"],O,et):et)},[I,$]),st=S.useCallback(pe=>{ye(!0);try{M(pe)}catch(me){me instanceof Error&&Ve({type:"error",text:`L'export a échoué : ${me.message}`}),console.warn(me)}finally{ye(!1)}},[M,Ve]),_e=S.useCallback(()=>{ye(!0);try{k(),ye(!1)}catch(pe){pe instanceof Error&&Ve({type:"error",text:"L'enregistrement a échoué"}),console.warn(pe)}finally{ye(!1)}},[k,Ve]),ht=S.useCallback(async pe=>{ye(!0);try{await q(pe),Ve({type:"success",text:"Fichier chargé !"})}catch(me){me instanceof Error&&Ve({type:"error",text:"Le chargement a échoué"}),console.warn(me)}finally{ye(!1)}},[q,Ve]),pt=S.useCallback(async pe=>{ye(!0);try{const me=await i(pe,R,B);D([me])}catch(me){me instanceof Error&&Ve({type:"error",text:"Le chargement a échoué"}),console.warn(me)}finally{ye(!1)}},[i,D,Ve,R,B]),gt=`${t?`${t} `:""}${De?"react-paint-editor-layout-opened ":""}react-paint-editor-app`;return d.jsxs("div",{ref:Z.setEditor,className:gt,style:{"--react-paint-editor-app-maxWidth":_?"100%":`${R}px`,"--react-paint-editor-app-toolbar-bg":de,"--react-paint-editor-app-divider-color":Ee,"--react-paint-editor-app-font-radius":`${We}px`,"--react-paint-editor-app-font-disabled-color":re,"--react-paint-editor-app-font-disabled-bg":ge,"--react-paint-editor-app-font-color":se,"--react-paint-editor-app-font-bg":ue,"--react-paint-editor-app-font-selected-color":K,"--react-paint-editor-app-font-selected-bg":ne,"--react-paint-editor-app-font-hover-color":le,"--react-paint-editor-app-font-hover-bg":we,...a},children:[G&&d.jsx(oi,{settings:V,width:V.canvasSize.width,activeTool:J,clearCanvas:Q,setActiveTool:W,exportCanvasInFile:st,saveFile:_e,loadFile:ht,addPicture:pt,hasActionToUndo:p,hasActionToRedo:m,hasActionToClear:g,undoAction:H,redoAction:E,availableTools:ie,withExport:A,withLoadAndSave:te,withUploadPicture:ve,withUrlPicture:Y}),n,G&&F&&d.jsx(Bo,{gridFormat:kt,setGridFormat:pe=>{L(ea[pe])},shapes:l.current,swapShapes:h,selectedShapes:y,removeShape:x,selectShapes:D,toggleShapeVisibility:u,toggleShapeLock:v,isLayoutPanelShown:De,settings:V}),Oe&&d.jsxs(dt,{alignment:"left",position:"bottom",className:"react-paint-editor-layouts-panel","data-edit":+G,children:[d.jsx(U,{className:"react-paint-editor-zoom-button",icon:'<svg viewBox="0 -960 960 960" width="24px"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400ZM280-540v-80h200v80H280Z"/></svg>',onClick:()=>N("unzoom")}),d.jsxs(U,{className:"react-paint-editor-zoom-button react-paint-editor-zoom-button-value",onClick:()=>N("default"),children:[Math.round(100*V.canvasZoom),"%"]}),d.jsx(U,{className:"react-paint-editor-zoom-button",icon:qa,onClick:()=>N("zoom")})]}),G&&d.jsxs(d.Fragment,{children:[d.jsx(Jo,{saveShapes:j,setCanvasZoom:N,width:V.canvasSize.width,activeTool:J,availableTools:ie,selectedShape:y,settings:V,removeShape:x,updateShape:P,canvas:Z.canvas.current,layersManipulation:F,toggleLayoutPanel:()=>{Ct(pe=>!pe)},isZoomPanelShown:Oe,setIsZoomPanelShown:ut,updateToolSettings:at}),d.jsx(Eo,{isLoading:Ae}),d.jsx(Wo,{snackbarList:Pt})]}),o.mode==="contextMenu"&&Le&&d.jsx(li,{selectionMode:o,settings:V,canvasRef:Z.canvas,closeContextMenu:()=>{r({mode:"default"}),Z.canvas.current?.focus()},selectAllShapes:ae,removeShape:x,moveShapes:c,duplicateShapes:f,toggleShapeLock:v,toggleShapeVisibility:u,setCopiedShape:C,copiedShape:w,pasteShapes:b,removeShapePoint:z,transformShape:T})]})},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:h,canGrow:u,canShrink:v,withExport:p,withLoadAndSave:m,withUploadPicture:g,withUrlPicture:y,withSkeleton:w,withFrameSelection:C,withContextMenu:b,clearCallback:x,availableTools:f,canvasSelectionPadding:P,size:H,canZoom:E}={...vs,...o},z=s!=="viewer",T=b&&z&&!n,Z=S.useRef(null),R=S.useRef(null),B=S.useRef(!1),W=S.useCallback(ee=>{Z.current=ee},[]),[D,ae]=S.useState(void 0),[J,I]=S.useState(Xe),[$,G]=S.useState({mode:"default"}),[ie,Qe]=S.useState(h),[L,q]=S.useState({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),M=E==="always"&&!n,{canvasTransformation:k,setCanvasTransformation:Q,setCanvasOffset:V,setCanvasZoom:N,resetZoom:j}=yo({canvasSize:L,size:H,canvasElt:R.current,zoomEnabled:M}),{offset:_,zoom:F}=k,A=S.useMemo(()=>({brushAlgo:l,isBrushShapeDoneOnMouseUp:i,debug:c,canvasSize:{realWidth:L.realWidth,realHeight:L.realHeight,width:L.width,height:L.height,scaleRatioWithNoZoom:L.scaleRatio,scaleRatio:L.scaleRatio*F},size:H,canvasOffset:_,canvasZoom:F,gridGap:ie,selectionPadding:P,features:{edition:z&&!n,zoom:M}}),[P,ie,l,i,c,F,_,L,H,n,M,z]),[te,ve]=S.useState(rn(f,g||y)),{isInsideComponent:Y,isInsideCanvas:Le}=(({settings:ee,componentRef:ce,canvasRef:Ze})=>{const[xe,ke]=S.useState(!1),[Be,Ye]=S.useState(!1),be=!ee.features.edition&&!ee.features.zoom;return S.useEffect(()=>{if(!be){const Ce=()=>ke(!0),aa=()=>ke(!1),nt=()=>Ye(!0),sa=()=>Ye(!1);return ce.current?.addEventListener("focusin",Ce),ce.current?.addEventListener("focusout",aa),Ze.current?.addEventListener("focusin",nt),Ze.current?.addEventListener("focusout",sa),()=>{ce.current?.removeEventListener("focusin",Ce),ce.current?.removeEventListener("focusout",aa),Ze.current?.removeEventListener("focusin",nt),Ze.current?.removeEventListener("focusout",sa)}}ke(!1),Ye(!1)},[be,ce,Ze]),{isInsideComponent:xe,isInsideCanvas:Be}})({settings:A,componentRef:Z,canvasRef:R}),[de,Ee]=S.useState(!1),[We,re]=S.useState(!1),[ge,se]=S.useState(!1),{registerEvent:ue,unregisterEvent:K,shapesRef:ne,selectedShape:le,selectionFrame:we,hoveredShape:Re,copiedShape:Ae,setCopiedShape:ye,addShapes:De,addPictureShape:Ct,moveShapes:Mt,swapShapes:ut,setSelectedShape:Oe,setSelectionFrame:kt,refreshSelectedShapes:Pt,refreshHoveredShape:Ve,duplicateShapes:at,removeShape:st,updateShape:_e,backwardShape:ht,forwardShape:pt,clearShapes:gt,saveShapes:pe,toggleShapeVisibility:me,toggleShapeLock:O,transformShape:et,canGoBackward:Tt,canGoForward:ci,canClear:di}=mo(A,e,t,de),Aa=S.useCallback(ee=>{Oe(void 0),I(ee)},[Oe]),[jt,kn]=S.useState([0,0]),Pn=$.mode==="preview";S.useEffect(()=>{if(Pn)return()=>G(ee=>ee.mode==="preview"?{mode:"default"}:ee)},[le?.id,Pn]);const jn=$.mode==="selectionFrame";S.useEffect(()=>{if(jn)return()=>kn([0,0])},[jn]),S.useEffect(()=>{if(jt[0]!==0||jt[1]!==0){const ee=setInterval(()=>{Q(({offset:ce,zoom:Ze})=>{const xe=[ce[0]-jt[0],ce[1]-jt[1]];return Ca({zoom:Ze,size:H,canvasSize:L,newOffset:xe})})},20);return()=>clearInterval(ee)}},[jt[0],jt[1],Q,H,L]);const ta=S.useCallback((ee,ce)=>{gt(ee,ce),Aa(Xe),Q({offset:[0,0],zoom:1})},[Aa,gt,Q]),Lt=S.useCallback(ee=>{Oe(ce=>(ce?.id!==ee.map(Ze=>Ze.id).join("-")&&I(Xe),oe(ee,A)))},[Oe,A]),Ln=S.useCallback(ee=>{De(ee),Lt(ee)},[De,Lt]),Vn=S.useCallback(()=>{Lt(ne.current)},[Lt,ne]),ui=S.useCallback(()=>{const ee=fo(ne.current,e,t);if(!ee)throw new Error("L'encodage a échoué");tn(ee,"drawing.json")},[ne,e,t]),hi=S.useCallback(ee=>{const ce=an({shapes:ne.current,settings:A,view:ee});tn(ce,"drawing.png")},[ne,A]),pi=S.useCallback(ee=>an({shapes:ne.current,settings:A,view:ee}),[ne,A]),gi=S.useCallback(()=>Ha(ne.current,e,t),[ne,e,t]),ft=S.useCallback(async(ee,ce)=>{const Ze=await(async(xe,ke)=>{if(!xe)return[];const Be=[],Ye=La(xe.map(be=>{if(!be||!ps.includes(be.type))return null;if(be.type==="picture"){const Ce=new Image,aa=new Promise((nt,sa)=>{Ce.onload=()=>{URL.revokeObjectURL(Ce.src),nt()},Ce.onerror=()=>{sa(new Error("Some images could not be loaded"))}});if(Be.push(aa),be.src.startsWith("http"))en(be.src).then(nt=>{Ce.src=nt}).catch(()=>{Ce.src=""});else if(be.src.includes("<svg")){const nt=new Blob([be.src],{type:"image/svg+xml"});Ce.src=URL.createObjectURL(nt)}else Ce.src=be.src;return sn({...be,img:Ce},ke)}return sn(be,ke)}));return await Promise.all(Be),Ye})(ee,A);ta(Ze,ce)},[ta,A]),Ea=S.useRef(ft);Ea.current=ft;const fi=S.useCallback((ee=[],ce=!0)=>{Ea.current?.(ee,{clearHistory:ce,source:"remote"})},[]);S.useEffect(()=>{B.current||(B.current=!0,a&&Ea.current?.(a,{clearHistory:!0,source:"remote"}))},[a]);const vi=S.useCallback(async ee=>{const ce=await(async Ze=>new Promise((xe,ke)=>{const Be=new FileReader;Be.onload=Ye=>{const be=Ye.target?.result;if(!be)return ke("Impossible de récupérer les données du fichier");const Ce=JSON.parse(be);xe(Ce)},Be.readAsText(Ze)}))(ee);await ft(ce.shapes??[],{clearHistory:!0,source:"remote"})},[ft]),mi=S.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]),Si=S.useCallback((ee,ce)=>{const Ze=ee.type==="curve"?((xe,ke,Be)=>{if(ke<0||ke>xe.points.length-1)return xe;const Ye={...xe,points:xe.points.filter((be,Ce)=>Ce!==ke)};return wt(Ye,Be)})(ee,ce,A):((xe,ke,Be)=>{if(ke<0||ke>xe.points.length-1)return xe;const Ye={...xe,points:xe.points.filter((be,Ce)=>Ce!==ke)};return Qt(Ye,Be)})(ee,ce,A);_e([Ze],!0)},[A,_e]);S.useEffect(()=>{ve(rn(f,g||y))},[f,g,y]);const Zn={canvas:R,editor:Z,setEditor:W};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":A.canvasZoom,"--react-paint-canvas-offset-x":A.canvasOffset[0],"--react-paint-canvas-offset-y":A.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":t}},editorProps:{shapesRef:ne,addPictureShape:Ct,moveShapes:Mt,swapShapes:ut,toggleShapeVisibility:me,toggleShapeLock:O,duplicateShapes:at,canGoBackward:Tt,canGoForward:ci,canClear:di,selectedShape:le,copiedShape:Ae,setCopiedShape:ye,pasteShapes:Ln,saveShapes:pe,removeShape:st,updateShape:_e,backwardShape:ht,forwardShape:pt,removeShapePoint:Si,transformShape:et,refs:Zn,width:e,height:t,selectTool:Aa,selectShapes:Lt,selectAllShapes:Vn,activeTool:J,setActiveTool:I,setAvailableTools:ve,isEditMode:z,availableTools:te,gridGap:ie,setGridGap:Qe,loadFile:vi,exportPicture:hi,exportData:ui,clearCanvas:mi,selectionMode:$,setSelectionMode:G,settings:A,setCanvasZoom:N,resetZoom:j,canvas:{canGrow:u,canShrink:v,layersManipulation:r,withExport:p,withLoadAndSave:m,withUploadPicture:g,withUrlPicture:y,withContextMenu:T}},canvasProps:{shapesRef:ne,selectedShape:le,selectionFrame:we,hoveredShape:Re,copiedShape:Ae,pasteShapes:Ln,setCopiedShape:ye,addShape:De,setSelectedShape:Oe,setSelectionFrame:kt,refreshSelectedShapes:Pt,refreshHoveredShape:Ve,removeShape:st,updateShape:_e,duplicateShapes:at,backwardShape:ht,forwardShape:pt,saveShapes:pe,refs:Zn,width:e,height:t,settings:A,setCanvasSize:q,setCanvasOffset:V,setCanvasZoom:N,resetZoom:j,selectShapes:Lt,selectAllShapes:Vn,activeTool:J,setActiveTool:I,isInsideComponent:Y,isInsideCanvas:Le,isEditMode:z,canvas:{withSkeleton:w,withFrameSelection:C,withContextMenu:T,canGrow:u,canShrink:v},canvasOffsetStartData:D,setCanvasOffsetStartData:ae,selectionMode:$,setSelectionMode:G,setCanvasMoveAcceleration:kn,isShiftPressed:de,isAltPressed:We,isSpacePressed:ge,setShiftPressed:Ee,setAltPressed:re,setIsSpacePressed:se},registerEvent:ue,unregisterEvent:K,resetCanvas:fi,resetZoom:j,getCurrentImage:pi,getCurrentData:gi,setCanvasOffset:V,setCanvasZoom:N}},Object.defineProperty(Ke,Symbol.toStringTag,{value:"Module"})});