@yorab/react-paint 0.18.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/README.md +270 -22
  2. package/dist/_chunks/canvas-CDYlr833.js +1 -0
  3. package/dist/_chunks/editor-BARYd5Od.js +1 -0
  4. package/dist/canvas/components/Canvas.d.ts +15 -3
  5. package/dist/canvas/components/EditTextBox.d.ts +4 -4
  6. package/dist/canvas/constants/app.d.ts +32 -17
  7. package/dist/canvas/constants/grid.d.ts +7 -0
  8. package/dist/canvas/constants/picture.d.ts +8 -0
  9. package/dist/canvas/constants/shapes.d.ts +2 -2
  10. package/dist/canvas/constants/tools.d.ts +12 -2
  11. package/dist/canvas/constants/zoom.d.ts +4 -2
  12. package/dist/canvas/context/PaintContext.d.ts +9 -0
  13. package/dist/canvas/hooks/useAnnotationsStyle.d.ts +5 -0
  14. package/dist/canvas/hooks/useAutoScroll.d.ts +4 -0
  15. package/dist/canvas/hooks/useCanvasRenderer.d.ts +17 -0
  16. package/dist/canvas/hooks/useDrawableCanvas.d.ts +8 -5
  17. package/dist/canvas/hooks/useDropPicture.d.ts +7 -0
  18. package/dist/canvas/hooks/useKeyboard.d.ts +6 -32
  19. package/dist/canvas/hooks/usePaintState.d.ts +9 -0
  20. package/dist/canvas/hooks/usePinchZoomAndMove.d.ts +3 -13
  21. package/dist/canvas/hooks/useReactPaint.d.ts +11 -163
  22. package/dist/canvas/hooks/useResizeObserver.d.ts +1 -0
  23. package/dist/canvas/hooks/useShapeEvents.d.ts +7 -0
  24. package/dist/canvas/hooks/useZoom.d.ts +4 -17
  25. package/dist/canvas/index.d.ts +24 -17
  26. package/dist/canvas/index.js +1 -1
  27. package/dist/canvas/store/createStore.d.ts +14 -0
  28. package/dist/canvas/store/eventEmitter.d.ts +11 -0
  29. package/dist/canvas/store/internal.d.ts +5 -0
  30. package/dist/canvas/store/paintStore.d.ts +898 -0
  31. package/dist/canvas/store/selectors.d.ts +855 -0
  32. package/dist/canvas/store/shapesReducer.d.ts +66 -0
  33. package/dist/canvas/store/types.d.ts +72 -0
  34. package/dist/canvas/types/Canvas.d.ts +19 -0
  35. package/dist/{common → canvas}/types/Mode.d.ts +8 -15
  36. package/dist/{common → canvas}/types/Settings.d.ts +6 -1
  37. package/dist/{common → canvas}/types/Shapes.d.ts +27 -21
  38. package/dist/canvas/types/editor.d.ts +388 -0
  39. package/dist/{common → canvas}/types/tools.d.ts +10 -6
  40. package/dist/{common → canvas}/utils/array.d.ts +2 -0
  41. package/dist/canvas/utils/canvas.d.ts +18 -2
  42. package/dist/canvas/utils/click.d.ts +17 -0
  43. package/dist/canvas/utils/data.d.ts +6 -5
  44. package/dist/canvas/utils/equality.d.ts +5 -0
  45. package/dist/canvas/utils/file.d.ts +36 -266
  46. package/dist/canvas/utils/grid.d.ts +1 -1
  47. package/dist/canvas/utils/intersect.d.ts +24 -14
  48. package/dist/canvas/utils/object.d.ts +11 -0
  49. package/dist/{common/utils/selection.d.ts → canvas/utils/selectedShapes.d.ts} +2 -2
  50. package/dist/canvas/utils/selection/anchors.d.ts +16 -0
  51. package/dist/canvas/utils/selection/groupSelection.d.ts +3 -3
  52. package/dist/canvas/utils/selection/lineSelection.d.ts +3 -10
  53. package/dist/canvas/utils/selection/rectSelection.d.ts +6 -11
  54. package/dist/canvas/utils/selection/selectionFrame.d.ts +2 -2
  55. package/dist/canvas/utils/selection.d.ts +7 -5
  56. package/dist/canvas/utils/shapeInput.d.ts +45 -0
  57. package/dist/canvas/utils/shapePatch.d.ts +10 -0
  58. package/dist/canvas/utils/shapes/brush.d.ts +6 -6
  59. package/dist/canvas/utils/shapes/circle.d.ts +5 -5
  60. package/dist/canvas/utils/shapes/curve.d.ts +4 -4
  61. package/dist/canvas/utils/shapes/ellipse.d.ts +5 -5
  62. package/dist/canvas/utils/shapes/group.d.ts +9 -3
  63. package/dist/canvas/utils/shapes/index.d.ts +31 -5
  64. package/dist/canvas/utils/shapes/line.d.ts +5 -5
  65. package/dist/canvas/utils/shapes/path.d.ts +16 -8
  66. package/dist/canvas/utils/shapes/picture.d.ts +7 -5
  67. package/dist/canvas/utils/shapes/polygon.d.ts +4 -4
  68. package/dist/canvas/utils/shapes/rectangle.d.ts +5 -5
  69. package/dist/canvas/utils/shapes/text.d.ts +12 -6
  70. package/dist/canvas/utils/shapes/triangle.d.ts +2 -2
  71. package/dist/canvas/utils/tools.d.ts +12 -3
  72. package/dist/canvas/utils/transform.d.ts +5 -4
  73. package/dist/canvas/utils/trigo.d.ts +17 -1
  74. package/dist/canvas/utils/util.d.ts +14 -0
  75. package/dist/canvas/utils/zoom.d.ts +29 -15
  76. package/dist/editor/components/common/Button.d.ts +0 -1
  77. package/dist/editor/components/common/FileInput.d.ts +0 -1
  78. package/dist/editor/components/common/Loading.d.ts +1 -2
  79. package/dist/editor/components/common/Menu.d.ts +3 -2
  80. package/dist/editor/components/common/Modal.d.ts +1 -2
  81. package/dist/editor/components/common/Panel.d.ts +1 -2
  82. package/dist/editor/components/common/Snackbar.d.ts +2 -3
  83. package/dist/editor/components/settings/ClosedPointsField.d.ts +1 -1
  84. package/dist/editor/components/settings/ColorField.d.ts +1 -2
  85. package/dist/editor/components/settings/DeleteButton.d.ts +3 -4
  86. package/dist/editor/components/settings/FontFamilyField.d.ts +1 -2
  87. package/dist/editor/components/settings/LayoutButton.d.ts +1 -2
  88. package/dist/editor/components/settings/Layouts.d.ts +4 -15
  89. package/dist/editor/components/settings/LineArrowField.d.ts +1 -2
  90. package/dist/editor/components/settings/LineTypeField.d.ts +2 -3
  91. package/dist/editor/components/settings/RangeField.d.ts +1 -2
  92. package/dist/editor/components/settings/SelectField.d.ts +1 -2
  93. package/dist/editor/components/settings/SettingsBar.d.ts +3 -18
  94. package/dist/editor/components/settings/ToggleField.d.ts +2 -1
  95. package/dist/editor/components/settings/ZoomButton.d.ts +1 -2
  96. package/dist/editor/components/settings/ZoomPanel.d.ts +4 -0
  97. package/dist/editor/components/toolbox/ActionButton.d.ts +9 -0
  98. package/dist/editor/components/toolbox/ContextMenu.d.ts +5 -24
  99. package/dist/editor/components/toolbox/ExportModal.d.ts +1 -2
  100. package/dist/editor/components/toolbox/LoadFileTool.d.ts +4 -4
  101. package/dist/editor/components/toolbox/MenuGroup.d.ts +1 -7
  102. package/dist/editor/components/toolbox/PictureUrlInput.d.ts +2 -2
  103. package/dist/editor/components/toolbox/Tool.d.ts +3 -3
  104. package/dist/editor/components/toolbox/Toolbar.d.ts +5 -16
  105. package/dist/editor/components/toolbox/ToolbarGroup.d.ts +2 -3
  106. package/dist/editor/constants/options.d.ts +11 -1
  107. package/dist/editor/constants/snackbar.d.ts +1 -1
  108. package/dist/editor/constants/style.d.ts +0 -9
  109. package/dist/editor/constants/tools.d.ts +12 -32
  110. package/dist/editor/editor.css +1 -0
  111. package/dist/editor/hooks/useDrag.d.ts +3 -3
  112. package/dist/editor/hooks/useMenu.d.ts +3 -2
  113. package/dist/editor/hooks/usePressOutside.d.ts +7 -0
  114. package/dist/editor/hooks/useSnackbar.d.ts +1 -1
  115. package/dist/editor/index.d.ts +12 -22
  116. package/dist/editor/index.js +1 -1
  117. package/dist/editor/types/tools.d.ts +7 -0
  118. package/dist/editor/utils/dom.d.ts +1 -0
  119. package/dist/editor/utils/style.d.ts +7 -1
  120. package/dist/editor/utils/toolbar.d.ts +1 -2
  121. package/dist/editor/utils/util.d.ts +5 -0
  122. package/dist/index.d.ts +2 -5
  123. package/dist/react-paint.css +1 -1
  124. package/dist/react-paint.js +1 -1
  125. package/dist/react-paint.umd.cjs +1 -1
  126. package/package.json +41 -28
  127. package/dist/_chunks/array-DuJem3vg.js +0 -1
  128. package/dist/_chunks/canvas-OCtokhMt.js +0 -1
  129. package/dist/_chunks/editor-CNTO8aYs.js +0 -1
  130. package/dist/canvas/context/CanvasContext.d.ts +0 -55
  131. package/dist/canvas/hooks/useComponent.d.ts +0 -12
  132. package/dist/canvas/hooks/useDoubleClick.d.ts +0 -5
  133. package/dist/canvas/hooks/useEventListener.d.ts +0 -2
  134. package/dist/canvas/hooks/useShapes.d.ts +0 -44
  135. package/dist/common/hooks/useDebounce.d.ts +0 -2
  136. package/dist/common/types/Canvas.d.ts +0 -8
  137. package/dist/common/types/react.d.ts +0 -6
  138. package/dist/common/utils/dom.d.ts +0 -1
  139. package/dist/common/utils/object.d.ts +0 -4
  140. package/dist/common/utils/util.d.ts +0 -3
  141. package/dist/editor/constants/grid.d.ts +0 -7
  142. /package/dist/{common → canvas}/types/utils.d.ts +0 -0
  143. /package/dist/{canvas → editor}/hooks/useDebounce.d.ts +0 -0
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactPaint={},e.React,e.ReactJSXRuntime))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t);var u=`blue`,d=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],f=[`brush`,`rect`,`square`,`line`,`polygon`,`circle`,`curve`,`ellipse`,`picture`,`text`,`triangle`,`group`],p=[`rect`,`square`,`circle`,`ellipse`,`picture`,`text`,`triangle`,`brush`,`group`],m=[`square`,`circle`,`picture`,`text`],h=`react-paint-canvas-drawcanvas`,g={layersManipulation:!0,grid:0,canGrow:!1,canShrink:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1,withContextMenu:!0,availableTools:[],clearCallback:`empty`,brushAlgo:`simple`,isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:`fixed`,canZoom:`never`,debug:!1},_={canvasBackgroundColor:`white`,canvasSelectionColor:u,canvasSelectionWidth:2},v=(0,t.createContext)(void 0),y=()=>{let e=(0,t.useContext)(v);if(!e)throw Error(`useCanvasContext must be used within a CanvasContext.Provider`);return e},b={id:`react-paint-selection`,type:`selection`,icon:``,label:``},x=`react-paint-picture`,S={strokeColor:{values:[],default:`black`},fillColor:{values:[],default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:[],default:0}},C=300,w=()=>{let e=(0,t.useRef)(void 0),n=(0,t.useRef)(void 0),r=t=>{let r=Date.now();e.current&&r<e.current+C&&n.current?.(t),e.current=Date.now()};return{registerDoubleClickEvent:(e,t)=>{n.current=t,e.addEventListener(`click`,r),e.addEventListener(`touchend`,r)},unRegisterDoubleClickEvent:e=>{e.removeEventListener(`click`,r),e.removeEventListener(`touchend`,r)}}},T=(e,n,r)=>{let i=(0,t.useRef)(r);i.current=r,(0,t.useEffect)(()=>{if(!e)return;let t=e=>i.current(e);return e.addEventListener(n,t),()=>{e.removeEventListener(n,t)}},[e,n])},E=[[1,0],[1,2],[4,6]],D=`serif`,O=e=>{e.reset(),e.lineCap=`round`,e.lineJoin=`round`},k=(e,t={})=>{let{lineCap:n=`round`,fillColor:r=`transparent`,opacity:i=100,strokeColor:a=u,lineWidth:o=2,lineDash:s=0,shadowColor:c=`transparent`,shadowBlur:l=0}=t;e.lineCap=n,e.globalAlpha=i/100,e.fillStyle=r,e.strokeStyle=a,e.lineWidth=o,e.setLineDash(s===0?[]:[E[s][0]*o,E[s][1]*o]),e.shadowColor=c,e.shadowBlur=l},A=(e,t,n,r)=>{e.save(),e.scale(t.canvasSize.scaleRatio,t.canvasSize.scaleRatio),e.translate(t.canvasOffset[0],t.canvasOffset[1]),n&&r&&(e.translate(r[0],r[1]),e.rotate(n),e.translate(-r[0],-r[1]))},j=(e,t,n)=>{e.globalAlpha!==0&&(n?.fillColor!==`transparent`&&e.fill(t),n?.strokeColor!==`transparent`&&e.stroke(t))},M=e=>e*180/Math.PI,N=(e,t)=>t[0]>=e.x&&t[0]<=e.x+e.width&&t[1]>=e.y&&t[1]<=e.y+e.height,ee=(e,t)=>{let n=t.x-Math.min(Math.max(t.x,e.x),e.x+e.width),r=t.y-Math.min(Math.max(t.y,e.y),e.y+e.height);return Math.sqrt(n*n+r*r)<=t.radius},P=({origin:e=[0,0],point:t,rotation:n=0})=>{if(n===0)return t;let r=[t[0]-e[0],t[1]-e[1]],i=r[1]*Math.cos(n)-r[0]*Math.sin(n);return[r[1]*Math.sin(n)+r[0]*Math.cos(n)+e[0],i+e[1]]},F=e=>(e+2*Math.PI)%(2*Math.PI),I=({targetVector:[e,t],radian:n=!0,originVector:r})=>{let i=F(Math.atan2(t[1]-e[1],t[0]-e[0]));if(r){let[e,t]=r,a=F(i-Math.atan2(t[1]-e[1],t[0]-e[0]));return n?a:M(a)}return n?i:M(i)},L=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),te=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],R=(e,t,n)=>{let{borders:r}=t;return{type:`rect`,border:Qn(r),shapePath:e,line:tr({points:[[r.x+r.width/2,r.y],[r.x+r.width/2,r.y-23/n.canvasSize.scaleRatio]]}),anchors:[$n({x:r.x+r.width/2,y:r.y-23/n.canvasSize.scaleRatio,radius:14/2/n.canvasSize.scaleRatio}),...d.map(e=>$n({x:r.x+r.width*e[0],y:r.y+r.height*e[1],radius:14/2/n.canvasSize.scaleRatio}))]}},ne=(e,t,n,r)=>{t.selection&&r.debug&&(e.save(),e.scale(r.canvasSize.scaleRatio,r.canvasSize.scaleRatio),e.translate(r.canvasOffset[0],r.canvasOffset[1]),k(e,{fillColor:`transparent`,strokeColor:`green`,lineWidth:n/r.canvasSize.scaleRatio}),e.strokeRect(t.computed.boundingBox.x,t.computed.boundingBox.y,t.computed.boundingBox.width,t.computed.boundingBox.height),e.restore())},z=(e,t,n,r,i,a)=>{if(t.selection&&(A(e,i,t.rotation,t.computed.center),i.debug&&(k(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/i.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),k(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/i.canvasSize.scaleRatio}),t.selection.shapePath?e.stroke(t.selection.shapePath):e.stroke(t.selection.border),!(!a||t.locked))){t.selection.shapePath&&e.stroke(t.selection.border),t.selection.line&&e.stroke(t.selection.line),k(e,{fillColor:`rgb(255,255,255)`,strokeColor:`rgb(150,150,150)`,lineWidth:2/i.canvasSize.scaleRatio,shadowColor:n,shadowBlur:0});for(let n of t.selection.anchors)e.fill(n),e.stroke(n)}},re=({borderStart:e,borderSize:t,vector:n,settings:r,invertedAxe:i,anchor:a})=>{switch(a){case 0:{if(i){let i=Math.max(0,n-t)+2*r.selectionPadding;return[e+t-2*r.selectionPadding,i]}let a=Math.max(2*r.selectionPadding,t-n);return[e+t-a,a]}case .5:return[e,t];case 1:if(i){let i=Math.min(e,e+t+n);return[i,e-i+2*r.selectionPadding]}return[e,Math.max(2*r.selectionPadding,t+n)];default:return[0,0]}},ie=(e,t,n,r,i,a,o,s,c,l,u)=>{let{selectionPadding:d}=u,f=`ratio`in c&&c.ratio?c.ratio:(e.width-d*2||1)/(e.height-d*2||1),p=(r-d*2)/(a-d*2),m,h,g,_;return l.anchor[0]!==.5&&l.anchor[1]!==.5?p<f?(h=i,_=a,g=(a-d*2)*f+2*d,m=l.anchor[0]===0?o?e.x+e.width-2*d:e.x+(e.width-g):o?e.x-g+2*d:e.x):(m=n,g=r,_=(r-d*2)/f+2*d,h=l.anchor[1]===0?s?e.y+e.height-2*d:e.y+(e.height-_):s?e.y-_+2*d:e.y):l.anchor[0]===.5?(h=i,_=a,g=(a-d*2)*f+2*d,m=e.x+(e.width-g)/2):(m=n,g=r,_=(r-d*2)/f+2*d,h=e.y+(e.height-_)/2),{borderX:m,borderWidth:g,borderY:h,borderHeight:_,center:t,originalShape:c}},ae=({borderX:e,borderWidth:t,borderY:n,borderHeight:r,center:i,originalShape:a})=>{let o=[e+t/2-i[0],n+r/2-i[1]],[s,c]=P({point:o,rotation:-(a.rotation??0)});return{borderX:q(e+s-o[0]),borderWidth:q(t),borderY:q(n+c-o[1]),borderHeight:q(r)}},B=(e,t,n,r)=>{let i=t.x+t.width/2,a=t.y+t.height/2,o=n?e.borderWidth*2+t.width:Math.abs(t.width+(e.borderWidth-t.width)*2),s=r?e.borderHeight*2+t.height:Math.abs(t.height+(e.borderHeight-t.height)*2);return{...e,borderHeight:s,borderWidth:o,borderX:i-o/2,borderY:a-s/2}},oe=({roundCursorPosition:e,borders:t,center:n,selectionMode:r,originalShape:i,settings:a})=>{let{selectionPadding:o}=a,s=Math.max(1,t.width-o*2),c=Math.max(1,t.height-o*2),l=`ratio`in i&&i.ratio?i.ratio:s/c,u=t.x+t.width/2,d=t.y+t.height/2,f=1;if(r.anchor[0]!==.5&&r.anchor[1]!==.5){let t=[(r.anchor[0]-.5)*s,(r.anchor[1]-.5)*c],n=[e[0]-u,e[1]-d],i=Math.hypot(t[0],t[1])||1;f=Math.hypot(n[0],n[1])/i}else if(r.anchor[0]===.5){let t=(r.anchor[1]-.5)*c,n=e[1]-d;f=Math.abs(n)/(Math.abs(t)||1)}else{let t=(r.anchor[0]-.5)*s,n=e[0]-u;f=Math.abs(n)/(Math.abs(t)||1)}let p=2*o/(s+2*o),m=s*Math.max(f,p),h=m/l,g=m+o*2,_=h+o*2;return{borderX:u-g/2,borderY:d-_/2,borderWidth:g,borderHeight:_,center:n,originalShape:i}},se=(e,t,n,r,i=!1,a=!1)=>{let{center:o,borders:s}=t.computed,c=P({origin:o,point:e,rotation:t.rotation}),l=a&&i?[s.x+s.width/2,s.x+s.width/2]:[s.x+s.width-r.selectionPadding,s.x+r.selectionPadding],u=a&&i?[s.y+s.height/2,s.y+s.height/2]:[s.y+s.height-r.selectionPadding,s.y+r.selectionPadding],d=n.anchor[0]===0&&c[0]>=l[0]||n.anchor[0]===1&&c[0]<=l[1],f=n.anchor[1]===0&&c[1]>=u[0]||n.anchor[1]===1&&c[1]<=u[1],p=[J(c[0],r,n.anchor[0]===0&&!d||n.anchor[0]===1&&d?r.selectionPadding:-r.selectionPadding),J(c[1],r,n.anchor[1]===0&&!f||n.anchor[1]===1&&f?r.selectionPadding:-r.selectionPadding)];if(i&&a)return{...ae(oe({roundCursorPosition:p,borders:s,center:o,selectionMode:n,originalShape:t,settings:r})),isXinverted:d,isYinverted:f};let m=r.gridGap?[n.anchor[0]===0?s.x:n.anchor[0]===.5?s.x+s.width/2:s.x+s.width,n.anchor[1]===0?s.y:n.anchor[1]===.5?s.y+s.height/2:s.y+s.height]:P({origin:o,point:n.cursorStartPosition,rotation:t.rotation}),h=[p[0]-m[0],p[1]-m[1]],[g,_]=re({borderStart:s.x,borderSize:s.width,vector:h[0],settings:r,invertedAxe:d,anchor:n.anchor[0]}),[v,y]=re({borderStart:s.y,borderSize:s.height,vector:h[1],settings:r,invertedAxe:f,anchor:n.anchor[1]}),b=i?ie(s,o,g,_,v,y,d,f,t,n,r):{borderX:g,borderWidth:_,borderY:v,borderHeight:y,center:o,originalShape:t};return{...ae(a?B(b,s,d,f):b),isXinverted:d,isYinverted:f}},ce={},V=(e=``)=>(ce[e]||(ce[e]=0),`${e}${++ce[e]}`),le=(e,t,n)=>Math.max(t,Math.min(e,n)),H=()=>typeof navigator>`u`?!1:navigator.userAgent.includes(`Macintosh`),ue=(e,t,n,r,i,a)=>{let{borders:o}=t.computed,{borderX:s,borderHeight:c,borderY:l,borderWidth:u,isXinverted:d,isYinverted:f}=se(e,t,n,r,i,a);return{newBorderX:s,newBorderY:l,newBorderWidth:u,newBorderHeight:c,widthMultiplier:(u-2*r.selectionPadding)/(o.width-2*r.selectionPadding||1),heightMultiplier:(c-2*r.selectionPadding)/(o.height-2*r.selectionPadding||1),isXinverted:d,isYinverted:f,groupCenter:[s+u/2,l+c/2],rotation:t.rotation??0,settings:r,originalBorders:o}},de=(e,t,n)=>{let r=P({origin:t.computed.center,point:e.computed.center,rotation:t.rotation??0}),i=(r[0]-(e.computed.borders.width/2-n.settings.selectionPadding)-(n.originalBorders.x+n.settings.selectionPadding))*n.widthMultiplier,a=(r[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-i:i),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-a:a)}},fe=(e,t,n,r,i)=>P({origin:e.groupCenter,point:[t+r/2,n+i/2],rotation:-e.rotation}),pe=(e,t)=>{let n=Qn(e),r=fr(e,_e,t);return{...e,path:n,computed:r,selection:R(n,r,t)}},me=pe,he=(e,t,n,r=0,i=0)=>pe({toolId:e.id,type:e.type,id:V(`${e.type}_`),x:t[0],y:t[1],width:r,height:i,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}},n),ge=(e,t)=>{j(e,t.path,t.style)},_e=(e,t)=>lr(e,t.selectionPadding),ve=(e,t,n,[r,i]=[!1,!1])=>vr([e[0]===.5?n.x+n.width/2:e[0]===0?n.x+(r?0:n.width):n.x+(r?n.width:0),e[1]===.5?n.y+n.height/2:e[1]===0?n.y+(i?0:n.height):n.y+(i?n.height:0)],n.rotation??0,t),ye=(e,t,n,r,i=!1,a=!1)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l}=se(e,t,n,r,i,a);return pe({...t,width:Math.max(0,l-2*r.selectionPadding),height:Math.max(0,s-2*r.selectionPadding),x:o+r.selectionPadding,y:c+r.selectionPadding},r)},be=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation,l=de(e,t,n),u=(e.width||1)*o,d=(e.height||1)*s,f=fe(n,l.x,l.y,u,d);return pe({...e,width:u,height:d,x:f[0]-u/2,y:f[1]-d/2,rotation:c?-(e.rotation??0):e.rotation??0},a)},U=e=>e?e.type===`group`?e.shapes:[e]:[],xe=(e,t)=>{let n=U(e).map(e=>t.find(t=>t.id===e?.toolId)||t.find(t=>t.type===e?.type)).filter(e=>e!==void 0);if(!n.length)return;if(n.length===1)return n[0];let r=n.slice(1).reduce((e,t)=>{let n={};for(let r in t.settings){if(e[r]===void 0)continue;let i=e[r],a=t.settings[r];if(i.hidden||a?.hidden)continue;let o={};`min`in a&&`min`in i&&a.min===i.min&&`max`in a&&`max`in i&&a.max===i.max&&`step`in a&&`step`in i&&a.step===i.step&&(o.min=a.min,o.max=a.max,o.step=a.step),`values`in a&&`values`in i&&a.values?.join(`,`)===i.values?.join(`,`)&&(o.values=a.values),(Object.keys(o).length>0||r===`closedPoints`)&&(n[r]=o)}return n},n[0].settings);return{id:n.map(e=>e.id).join(`-`),icon:``,label:`group`,type:`group`,settings:r}},Se=(e,t,n)=>{if(e.mode===`translate`)return{mode:`translate`,cursorStartPosition:n,originalShape:t,hasBeenDuplicated:!1,dateStart:Date.now(),selectedShapesLengthAtMouseDown:U(t).length};if(e.mode===`rotate`){let{center:e}=t.computed;return{mode:`rotate`,cursorStartPosition:n,originalShape:t,center:[e[0],e[1]],selectedShapesLengthAtMouseDown:U(t).length}}if(e.mode===`resize`)return{mode:`resize`,cursorStartPosition:n,originalShape:t,anchor:e.anchor,selectedShapesLengthAtMouseDown:U(t).length}},Ce=(e,t,n,r,i,a,o,s=`replace`)=>{let c=!1;if(i){c=xr(e,i,n,r,!0,a?20:void 0);let t=Se(c||{mode:`default`},i,n);if(t?.mode===`resize`||t?.mode===`rotate`)return{shape:i,mode:t}}let l=t.find(t=>U(i).find(e=>t.id===e?.id)?c&&xr(e,t,n,r,!0,a?20:void 0):!!Tr(e,t,n,r))??(c?i:void 0);if(i&&i?.id===l?.id)return{shape:i,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:i,selectedShapesLengthAtMouseDown:U(i).length}};if(l?.locked&&s===`add`)return{shape:i,mode:{mode:o?`selectionFrame`:`default`}};if(l&&s===`add`&&i?.locked){let e=W([l],r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:U(i).length}}}if(l){if(s===`add`){let e=W(Te(i,[l]),r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:U(i).length}}}if(s===`remove`){let e=W(Ee(i,l),r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:U(i).length}}}let e=U(i).find(e=>e.id===l?.id)?i:W([l],r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:U(i).length}}}return{shape:s===`replace`?void 0:i,mode:{mode:o?`selectionFrame`:`default`}}},we=(e,t,n)=>{let r=e.map(e=>[[e.computed.borders.x+n.selectionPadding,e.computed.borders.y+n.selectionPadding],[e.computed.borders.x-n.selectionPadding+e.computed.borders.width,e.computed.borders.y+n.selectionPadding],[e.computed.borders.x-n.selectionPadding+e.computed.borders.width,e.computed.borders.y-n.selectionPadding+e.computed.borders.height],[e.computed.borders.x+n.selectionPadding,e.computed.borders.y-n.selectionPadding+e.computed.borders.height]].map(n=>{let r=P({point:[n[0],n[1]],origin:e.computed.center,rotation:-(e.rotation??0)});return P({point:[r[0],r[1]],origin:[0,0],rotation:t})})),i=Math.min(...r.flatMap(e=>[e[0][0],e[1][0],e[2][0],e[3][0]])),a=Math.min(...r.flatMap(e=>[e[0][1],e[1][1],e[2][1],e[3][1]])),o=Math.max(...r.flatMap(e=>[e[0][0],e[1][0],e[2][0],e[3][0]])),s=Math.max(...r.flatMap(e=>[e[0][1],e[1][1],e[2][1],e[3][1]])),c=[(i+o)/2,(a+s)/2],l=P({point:c,origin:[0,0],rotation:-t}),u=[c[0]-l[0],c[1]-l[1]],d=q(i-u[0]),f=q(o-u[0]),p=q(a-u[1]),m=q(s-u[1]);return{width:f-d,height:m-p,x:d,y:p}},W=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];let n=e.some(t=>t.rotation!==e[0].rotation)?0:e[0]?.rotation??0,r=we(e,n,t),i=he({id:`group_selection`,type:`rect`,settings:S},[r.x,r.y],t,r.width,r.height),a=e.slice(1).reduce((e,t)=>{let n=t.style??{},r={};for(let t in n)e[t]!==void 0&&n[t]!==void 0&&e[t]===n[t]&&(r[t]=e[t]);return r},e[0].style??{});return{id:e.map(e=>e.id).join(`-`),type:`group`,shapes:e,rotation:n,visible:!0,locked:!1,selection:i.selection,x:i.x,y:i.y,width:i.width,height:i.height,style:a,computed:i.computed,path:i.path}},Te=(e,t)=>{let n=U(e);return[...new Set([...n,...t])]},Ee=(e,t)=>U(e).filter(e=>e.id!==t.id),De=(e,t,n,r,i,a,o)=>{if(t.selection&&(t.shapes.forEach(t=>{k(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/a.canvasSize.scaleRatio}),A(e,a,t.rotation,t.computed.center),t.selection?.shapePath&&e.stroke(t.selection.shapePath),e.restore()}),i.mode!==`rotate`&&(A(e,a,t.rotation,t.computed.center),a.debug&&(k(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/a.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),k(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/a.canvasSize.scaleRatio}),o&&!t.locked))){e.stroke(t.selection.border),t.selection.line&&e.stroke(t.selection.line),k(e,{fillColor:`rgb(255,255,255)`,strokeColor:`rgb(150,150,150)`,lineWidth:2/a.canvasSize.scaleRatio});for(let n of t.selection.anchors)e.fill(n),e.stroke(n)}},G=(e,t,n,r)=>({type:`line`,border:Qn(n.borders),shapePath:e,anchors:[...t.points.map(e=>$n({x:e[0],y:e[1],radius:14/2/r.canvasSize.scaleRatio}))]}),Oe=({ctx:e,shape:t,withAnchors:n,selectionWidth:r,selectionColor:i,hoverMode:a,settings:o})=>{if(t.selection&&(A(e,o,t.rotation,t.computed.center),o.debug&&(k(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/o.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),k(e,{fillColor:`transparent`,strokeColor:i,lineWidth:r/o.canvasSize.scaleRatio}),t.selection.shapePath&&e.stroke(t.selection.shapePath),!(!n||t.locked))){k(e,{fillColor:`rgb(255,255,255)`,strokeColor:`rgb(150,150,150)`,lineWidth:2/o.canvasSize.scaleRatio,shadowColor:i,shadowBlur:0});for(let n=0;n<t.selection.anchors.length;n++){let r=t.selection.anchors[n];a.mode===`resize`&&a.anchor===n?(e.shadowBlur=10,e.fill(r),e.shadowBlur=0):e.fill(r),e.stroke(r)}}},ke=(e,t,n)=>{k(e,{fillColor:`rgba(170,170,170, 0.1)`,strokeColor:`rgb(170,170,170)`,lineWidth:1/n.canvasSize.scaleRatio}),e.fillRect(t[0][0],t[0][1],t[1][0]-t[0][0],t[1][1]-t[0][1]),e.strokeRect(t[0][0],t[0][1],t[1][0]-t[0][0],t[1][1]-t[0][1])},K=[.05,.1,.25,.5,1,2,4,8],Ae=`#f5f5f5`,je=({size:e,zoom:t,newOffset:[n,r],canvasSize:i})=>e===`infinite`?{zoom:t,offset:[n,r]}:t<1?{zoom:t,offset:[-(i.realWidth-i.realWidth/t)/2,-(i.realHeight-i.realHeight/t)/2]}:{zoom:t,offset:[le(n,i.realWidth/t-i.realWidth,0),le(r,i.realHeight/t-i.realHeight,0)]},Me=({size:e,canvasSize:t,currentOffset:n,currentZoom:r,zoom:i,centerPoint:a})=>{let o=e===`fixed`&&i<1?[t.realWidth/2,t.realHeight/2]:a,{offset:s}=je({size:e,zoom:i,newOffset:[n[0]-(o[0]/r-o[0]/i),n[1]-(o[1]/r-o[1]/i)],canvasSize:t});return{offset:s,zoom:i}},Ne=({size:e,canvasSize:t,currentOffset:n,currentZoom:r,action:i})=>Me({size:e,canvasSize:t,currentOffset:n,currentZoom:r,zoom:i===`default`?K[4]:i===`zoom`?K[le(K.length-1-K.slice(0).reverse().findIndex(e=>e<=r)+1,0,K.length-1)]:K[le(K.findIndex(e=>e>=r)-1,0,K.length-1)],centerPoint:[t.realWidth/2,t.realHeight/2]}),Pe=({size:e,canvasSize:t,currentOffset:n,currentZoom:r,delta:i,centerPoint:a})=>Me({size:e,canvasSize:t,currentOffset:n,currentZoom:r,zoom:le(r*(1-i/1e3),K[0],K[K.length-1]),centerPoint:a}),Fe=e=>{let{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:r},canvasZoom:i,canvasOffset:a}=e;return{x:-a[0],y:-a[1],width:t/i/r,height:n/i/r}},Ie=e=>{let{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:r},canvasZoom:i,canvasOffset:a}=e;return{x:a[0]*i*r,y:a[1]*i*r,width:t*i,height:n*i}},Le=(e,t)=>{let{canvasZoom:n,size:r}=t;if(r!==`fixed`||n>=1)return;let i=Ie(t);e.beginPath(),e.rect(i.x,i.y,i.width,i.height),e.closePath(),e.clip()},Re=(e,t)=>{let{canvasZoom:n,size:r,canvasSize:{width:i,height:a}}=t;if(r!==`fixed`||n>=1)return;e.fillStyle=Ae,e.fillRect(0,0,i,a);let o=Ie(t);e.clearRect(o.x,o.y,o.width,o.height),Le(e,t)},ze=(e,t)=>t.size!==`fixed`||e[0]>0&&e[0]<t.canvasSize.realWidth&&e[1]>0&&e[1]<t.canvasSize.realHeight,Be=(e,t)=>{let n=Math.abs(e.deltaY)<50&&t<50,r=e.ctrlKey,i=H()&&n&&r;switch(e.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:e.deltaX*16,deltaY:e.deltaY*16};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:e.deltaX*window.innerHeight,deltaY:e.deltaY*window.innerHeight};default:return i?{deltaX:e.deltaX*5,deltaY:e.deltaY*5}:{deltaX:e.deltaX,deltaY:e.deltaY}}},Ve=(e,t)=>{let n={...t};for(let t of e)Array.isArray(t)?t[1].includes(n[t[0]])&&delete n[t[0]]:delete n[t];return n},He=(e,t,n)=>{let r=Array.isArray(n)?[...n]:{...n},i=Array.isArray(e)?e:typeof e==`string`?e.split(`.`):[e];return i.reduce((e,n,r)=>(e[n]=Ue(e[n])?{...e[n]}:Array.isArray(e[n])?[...e[n]]:e[n]===void 0||e[n]===null?{}:e[n],r===i.length-1&&(e[n]=t),e[n]),r),r},Ue=e=>typeof e==`object`&&!Array.isArray(e)&&e!==null,We=(e,t,n)=>{if(!Ue(t)||!Ue(n))return n;let r={...t};for(let t in n)n.hasOwnProperty(t)&&(r.hasOwnProperty(t)?r[t]=e(r[t],n[t],t)??We(e,r[t],n[t]):r[t]=n[t]);return r},Ge=(e,t)=>{if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let i of n)if(!r.includes(i)||!Ge(e[i],t[i]))return!1;return!0},Ke=(e,{selectionPadding:t})=>{let n=e.points.flat(),r=Math.min(...n.map(e=>e[0])),i=Math.min(...n.map(e=>e[1])),a=n.map(t=>Kn(t,r,i,e.scaleX,e.scaleY)),o=Math.max(...a.map(e=>e[0])),s=Math.max(...a.map(e=>e[1]));return lr({x:r,y:i,width:o-r,height:s-i},t)},qe=(e,t)=>{let n=nr(e,t),r=fr(e,Ke,t);return{...e,path:n,selection:R(n,r,t),computed:r}},Je=qe,Ye=(e,t,n)=>qe({toolId:e.id,type:e.type,id:V(`${e.type}_`),points:[[t]],scaleX:1,scaleY:1,style:{opacity:e.settings.opacity.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),Xe=(e,t)=>{t.points.length<1||e.globalAlpha!==0&&(t.style?.strokeColor===`transparent`||e.globalAlpha===0||e.stroke(t.path))},Ze=(e,t,n,r,i,a)=>{let o=Ke({...t,scaleX:1,scaleY:1},r),s=t.computed.borders,{borderX:c,borderHeight:l,borderY:u,borderWidth:d,isXinverted:f,isYinverted:p}=se(e,t,n,r,i,a),m=Math.max(0,o.width-2*r.selectionPadding),h=Math.max(0,o.height-2*r.selectionPadding),g=Math.max(0,d-2*r.selectionPadding),_=Math.max(0,l-2*r.selectionPadding),v=m?g/m:1,y=h?_/h:1;if(!m||!h)return t;let b=q(c-s.x)+(f?2*s.x+o.width:0),x=q(u-s.y)+(p?2*s.y+o.height:0);return qe({...t,points:t.points.map(e=>e.map(([e,t])=>[f?-e+b:e+b,p?-t+x:t+x])),scaleX:v,scaleY:y},r)},Qe=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=Ke({...e,scaleX:1,scaleY:1},a),l=c.width-2*a.selectionPadding,u=c.height-2*a.selectionPadding,d=e.scaleX??1?(e.scaleX??1)*o:o/l,f=e.scaleY??1?(e.scaleY??1)*s:s/u,p=l*d,m=u*f,h=de(e,t,n),g=fe(n,h.x,h.y,p,m),_=q(g[0]-p/2-e.computed.borders.x-a.selectionPadding)+(r?2*e.computed.borders.x+c.width:0),v=q(g[1]-m/2-e.computed.borders.y-a.selectionPadding)+(i?2*e.computed.borders.y+c.height:0),y=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation;return qe({...e,points:e.points.map(e=>e.map(([e,t])=>[r?-e+_:e+_,i?-t+v:t+v])),scaleX:d,scaleY:f,rotation:y?-(e.rotation??0):e.rotation??0},n.settings)},$e=(e,t,n)=>qe({...e,points:He(e.points.length-1,[...e.points[e.points.length-1],[Math.round(t[0]),Math.round(t[1])]],e.points)},n),et=(e,t,n)=>qe({...e,points:He(e.points.length,[[Math.round(t[0]),Math.round(t[1])]],e.points)},n),tt=(e,t)=>lr({x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2},t.selectionPadding),nt=(e,t)=>{let n=$n(e),r=fr(e,tt,t);return{...e,path:n,selection:R(n,r,t),computed:r}},rt=nt,it=(e,t,n)=>nt({toolId:e.id,type:e.type,id:V(`${e.type}_`),x:t[0],y:t[1],radius:0,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),at=(e,t)=>{j(e,t.path,t.style)},ot=(e,t,n,r,i)=>{let{borderX:a,borderHeight:o,borderY:s,borderWidth:c}=se(e,t,n,r,!0,i);return nt({...t,radius:Math.max(0,c/2-r.selectionPadding),x:a+c/2,y:s+o/2},r)},st=(e,t,n)=>{let r=de(e,t,n),i=(e.radius||.5)*n.widthMultiplier,a=fe(n,r.x,r.y,i*2,i*2);return nt({...e,radius:i,x:a[0],y:a[1]},n.settings)},ct=(e,t)=>{let n=sr(e),r=fr(e,ft,t);return{...e,path:n,selection:G(n,e,r,t),computed:r}},lt=ct,ut=(e,t,n)=>ct({toolId:e.id,type:e.type,id:V(`${e.type}_`),points:[t],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,closedPoints:e.settings.closedPoints.default}},n),dt=(e,t)=>{j(e,t.path,t.style)},ft=(e,t)=>{let n=Math.min(...e.points.map(e=>e[0])),r=Math.max(...e.points.map(e=>e[0])),i=Math.min(...e.points.map(e=>e[1])),a=Math.max(...e.points.map(e=>e[1]));return lr({x:n,width:r-n,y:i,height:a-i},t.selectionPadding)},pt=(e,t,n,r)=>{let i=_r([J(e[0],r),J(e[1],r)],t.rotation??0,t.computed.center);return ct(He([`points`,n.anchor],i,t),r)},mt=(e,t,n,r)=>{if(t<0||t>e.points.length-1)return e;let i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return ct({...e,points:i},r)},ht=(e,t,n,r=!1)=>{let i=_r([J(t[0],n),J(t[1],n)],e.rotation??0,e.computed.center);return ct({...e,points:r?e.points:[...e.points,i],tempPoint:r?i:void 0},n)},gt=(e,t,n)=>t<0||t>e.points.length-1?e:ct({...e,points:e.points.filter((e,n)=>n!==t)},n),_t=(e,t,n)=>{let r=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(r.length<2){let e=r[0]??[0,0],t=n.selectionPadding;return{x:e[0]-t,y:e[1]-t,width:2*t,height:2*t}}if(r.length<3)return ft({...e,points:r},n);let i=ir(e,r),a=1/0,o=-1/0,s=1/0,c=-1/0;for(let e=1;e<i.length-2;e++){let t=i[e-1],n=i[e],r=i[e+1],l=i[e+2],{cp1:u,cp2:d}=ar(t,n,r,l),f=rr(n,u,d,r);a=Math.min(a,f.minX),o=Math.max(o,f.maxX),s=Math.min(s,f.minY),c=Math.max(c,f.maxY)}return _e({x:a,y:s,width:o-a,height:c-s},n)},vt=(e,t)=>{let n=or(e),r=fr(e,ft,t,_t);return{...e,path:n,selection:G(n,e,r,t),computed:r}},yt=vt,bt=(e,t,n)=>vt({toolId:e.id,type:e.type,id:V(`${e.type}_`),points:[t],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,closedPoints:e.settings.closedPoints.default}},n),xt=(e,t,n,r)=>{let i=[J(e[0],r),J(e[1],r)],a=t.computed.center,o=_r(i,t.rotation??0,a);return vt(He([`points`,n.anchor],o,t),r)},St=(e,t)=>{j(e,t.path,t.style)},Ct=(e,t,n,r)=>{if(t<0||t>e.points.length-1)return e;let i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return vt({...e,points:i},r)},wt=(e,t,n,r=!1)=>{let i=[J(t[0],n),J(t[1],n)],a=e.computed.center,o=_r(i,e.rotation??0,a);return vt({...e,points:r?e.points:[...e.points,o],tempPoint:r?o:void 0},n)},Tt=(e,t,n)=>t<0||t>e.points.length-1?e:vt({...e,points:e.points.filter((e,n)=>n!==t)},n),Et=(e,t)=>lr({x:e.x-e.radiusX,y:e.y-e.radiusY,width:e.radiusX*2,height:e.radiusY*2},t.selectionPadding),Dt=(e,t)=>{let n=er(e),r=fr(e,Et,t);return{...e,path:n,selection:R(n,r,t),computed:r}},Ot=Dt,kt=(e,t,n)=>Dt({toolId:e.id,type:e.type,id:V(`${e.type}_`),x:t[0],y:t[1],radiusX:0,radiusY:0,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),At=(e,t)=>{j(e,t.path,t.style)},jt=(e,t,n,r,i=!1,a=!1)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l}=se(e,t,n,r,i,a);return Dt({...t,radiusX:Math.max(0,l/2-r.selectionPadding),radiusY:Math.max(0,s/2-r.selectionPadding),x:o+l/2,y:c+s/2},r)},Mt=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation,l=de(e,t,n),u=(e.radiusX||.5)*o,d=(e.radiusY||.5)*s,f=fe(n,l.x,l.y,u*2,d*2);return Dt({...e,radiusX:u,radiusY:d,x:f[0],y:f[1],rotation:c?-(e.rotation??0):e.rotation??0},a)},Nt=(e,t)=>({...e,path:cr(e),computed:fr(e,ft,t)}),Pt=(e,t)=>Nt({...e,id:V(`triangle_`),type:`triangle`},t),Ft=(e,t)=>{j(e,t.path,t.style)},It=(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])+t.selectionPadding*2,y:Math.min(e.points[0][1],e.points[1][1])-t.selectionPadding,height:Math.abs(e.points[0][1]-e.points[1][1])+t.selectionPadding*2}),Lt=(e,t)=>{let n=[],r;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){let i=Math.PI/2-I({targetVector:[e.points[0],e.points[1]]});(e.style?.lineArrow===1||e.style?.lineArrow===3)&&n.push(Pt(Bt(e.points[0],i,e.style),t)),(e.style?.lineArrow===2||e.style?.lineArrow===3)&&n.push(Pt(Bt(e.points[1],i+Math.PI,e.style),t)),r=tr(Zn({line:e,size:10+(e.style?.lineWidth??0)*2,direction:e.style?.lineArrow===1?`start`:e.style?.lineArrow===2?`end`:`both`}))}else r=tr(e);let i=fr(e,It,t);return{...e,path:r,selection:G(r,e,i,t),arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?`butt`:`round`},computed:i}},Rt=Lt,zt=(e,t,n)=>Lt({toolId:e.id,type:e.type,id:V(`${e.type}_`),points:[t,t],style:{opacity:e.settings.opacity.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default,lineArrow:e.settings.lineArrow.default}},n),Bt=(e,t,n)=>{let r=[P({point:[0,0],rotation:t}),P({point:[-(5+(n.lineWidth??0)),10+(n.lineWidth??0)*2],rotation:t}),P({point:[5+(n.lineWidth??0),10+(n.lineWidth??0)*2],rotation:t})];return{points:[[e[0]+r[0][0],e[1]+r[0][1]],[e[0]+r[1][0],e[1]+r[1][1]],[e[0]+r[2][0],e[1]+r[2][1]]],style:{...n,fillColor:n.strokeColor,strokeColor:`transparent`}}},Vt=(e,t)=>{j(e,t.path,t.style);for(let n of t.arrows??[])k(e,n.style),Ft(e,n)},Ht=(e,t,n,r)=>{let i=_r([J(e[0],r),J(e[1],r)],t.rotation??0,t.computed.center);return Lt(He([`points`,n.anchor],i,t),r)},Ut=(e,t)=>e.type===`line`?Lt(e,t):e.type===`polygon`?lt(e,t):yt(e,t),Wt=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=e.computed.borders.width-2*a.selectionPadding,l=e.computed.borders.height-2*a.selectionPadding,u=c*o,d=l*s,f=de(e,t,n),p=fe(n,f.x,f.y,u,d),m=e.computed.center[0]-c/2,h=e.computed.center[1]-l/2,g=p[0]-u/2,_=p[1]-d/2;return Ut({...e,points:e.points.map(([e,t])=>[g+(r?u-(e-m)*o:(e-m)*o),_+(i?d-(t-h)*s:(t-h)*s)])},n.settings)},Gt=e=>{let t=[`img`,`id`,`selection`,`path`,`arrows`,`tempPoint`,`computed`,[`flipX`,[void 0,!1]],[`flipY`,[void 0,!1]]];return e.map(e=>e.type===`picture`&&!e.src.startsWith(`http`)?Ve(t,{...e,src:tn(e)}):Ve(t,e))},Kt=(e,t,n)=>({shapes:Gt(e),config:{width:t,height:n}}),qt=(e,t)=>Hn({...e,id:V(`${e.type}_`)},t),Jt=e=>e.filter(e=>e!=null),Yt=(e,t,n)=>t<0||n<0||t>e.length-1||n>e.length-1?e:t<n?[...e.slice(0,t),...e.slice(t+1,n+1),e[t],...e.slice(n+1,e.length)]:[...e.slice(0,n),e[t],...e.slice(n,t),...e.slice(t+1,e.length)],Xt=e=>{let t=new DOMParser().parseFromString(e,`text/xml`).getElementsByTagName(`svg`)[0];if(!t)return``;let n=t.getAttribute(`width`),r=t.getAttribute(`height`),i;if(n||r)i=e;else{let[,,e,n]=(t.getAttribute(`viewBox`)??`0 0 300 300`).split(` `);t.setAttribute(`width`,e??`300`),t.setAttribute(`height`,n??`300`),i=new XMLSerializer().serializeToString(t)}let a=new Blob([i],{type:`image/svg+xml`});return URL.createObjectURL(a)},Zt=e=>(e instanceof File?e.name:e).includes(`.svg`),Qt=e=>Zt(e)?fetch(e).then(e=>e.text()).then(e=>Xt(e)):fetch(e).then(e=>e.blob()).then(e=>URL.createObjectURL(e)),$t=(e,t)=>{let n=document.createElement(`a`);n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},en=e=>{let t=document.createElement(`canvas`);t.width=e.width,t.height=e.height;let n=t.getContext(`2d`);return n?(n.drawImage(e,0,0),t.toDataURL(`image/png`)):``},tn=e=>e.src.includes(`<svg`)?e.src:en(e.img),nn=e=>`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(e))}`,rn=({shapes:e,settings:t})=>{let n=document.createElement(`canvas`),r=n.getContext(`2d`);if(!r)throw Error(`No context found for canvas`);let{realHeight:i,realWidth:a}=t.canvasSize;n.width=a,n.height=i,r.clearRect(0,0,a,i),O(r);for(let n=e.length-1;n>=0;n--)Fn(r,e[n],t);return n.toDataURL(`image/png`)},an=({shapes:e,settings:t,view:n})=>{if(n===`fitToShapes`&&!e.length)throw Error(`No image found to export`);if(n===`fitToShapes`){let n=Math.min(...e.map(e=>e.computed.boundingBox.x)),r=Math.max(...e.map(e=>e.computed.boundingBox.x+e.computed.boundingBox.width)),i=Math.min(...e.map(e=>e.computed.boundingBox.y)),a=Math.max(...e.map(e=>e.computed.boundingBox.y+e.computed.boundingBox.height));return rn({shapes:e,settings:{...t,canvasOffset:[-n,-i],canvasZoom:1,canvasSize:{realWidth:r-n,realHeight:a-i,width:r-n,height:a-i,scaleRatio:1,scaleRatioWithNoZoom:1}}})}return rn(n===`defaultView`?{shapes:e,settings:{...t,canvasOffset:[0,0],canvasZoom:1,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:1,scaleRatioWithNoZoom:1}}}:{shapes:e,settings:{...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}}})},on=(e,t,n)=>nn(Kt(e,t,n)),sn=async e=>new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{let r=e.target?.result;if(!r)return n(Error(`Impossible de récupérer les données du fichier`));try{t(JSON.parse(r))}catch{n(Error(`Invalid JSON file`))}},r.onerror=()=>n(Error(`Failed to read file`)),r.readAsText(e)}),cn=async(e,t)=>{if(!e)return[];let n=[],r=Jt(e.map(e=>{if(!e||!f.includes(e.type))return null;if(e.type===`picture`){let r=new Image,i=new Promise((e,t)=>{r.onload=()=>{URL.revokeObjectURL(r.src),e()},r.onerror=()=>{t(Error(`Some images could not be loaded`))}});if(n.push(i),e.src.startsWith(`http`))Qt(e.src).then(e=>{r.src=e}).catch(()=>{r.src=``});else if(e.src.includes(`<svg`)){let t=new Blob([e.src],{type:`image/svg+xml`});r.src=URL.createObjectURL(t)}else r.src=e.src;return qt({...e,img:r},t)}return qt(e,t)}));return await Promise.all(n),r},ln=(e,t)=>{let n=fr(e,_e,t),r=Qn(e);return{...e,path:r,selection:R(void 0,n,t),computed:n}},un=ln,dn=(e,t,n,r,i)=>{let[a,o]=Xn(e.width,e.height,n,r,!0);return ln({toolId:x,type:`picture`,id:V(`picture_`),x:-i.canvasOffset[0]+i.canvasSize.realWidth/i.canvasZoom/2-a/2,y:-i.canvasOffset[1]+i.canvasSize.realHeight/i.canvasZoom/2-o/2,width:a,height:o,ratio:o===0?1:a/o,src:t,img:e},i)},fn=(e,t,n,r,i,a)=>{Zt(n)?n.text().then(n=>{let o=Xt(n);e.onload=async()=>{URL.revokeObjectURL(e.src),t(dn(e,n,r,i,a))},e.src=o}):(e.onload=async()=>{URL.revokeObjectURL(e.src),t(dn(e,e.src,r,i,a))},e.src=URL.createObjectURL(n))},pn=(e,t,n,r,i,a)=>{e.onload=()=>{URL.revokeObjectURL(e.src),t(dn(e,n,r,i,a))},Qt(n).then(t=>{e.src=t}).catch(()=>{e.src=``})},mn=(e,t,n,r)=>new Promise((i,a)=>{let o=new Image,s=setTimeout(()=>{a(Error(`Timeout while loading images`))},4e3),c=e=>{clearTimeout(s),i(e)};o.onerror=()=>{clearTimeout(s),a(Error(`Some images could not be loaded`))},e instanceof File?fn(o,c,e,t,n,r):pn(o,c,e,t,n,r)}),hn=(e,t)=>{e.globalAlpha!==0&&(e.beginPath(),e.scale(t.flipX?-1:1,t.flipY?-1:1),e.drawImage(t.img,t.flipX?-t.x-t.width:t.x,t.flipY?-t.y-t.height:t.y,t.width,t.height))},gn=(e,t,n,r,i)=>{let{borderX:a,borderHeight:o,borderY:s,borderWidth:c,isXinverted:l,isYinverted:u}=se(e,t,n,r,!0,i),d=Math.max(0,c-2*r.selectionPadding),f=Math.max(0,o-2*r.selectionPadding);return ln({...t,width:d,height:f,x:a+r.selectionPadding,y:s+r.selectionPadding,flipX:l?!t.flipX:!!t.flipX,flipY:u?!t.flipY:!!t.flipY},r)},_n=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=de(e,t,n),l=(e.width===0||e.height===0?e.ratio??1:e.width)*o,u=(e.width===0||e.height===0?e.ratio??1:e.height)*s,d=fe(n,c.x,c.y,l,u),f=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation;return ln({...e,width:l,height:u,x:d[0]-l/2,y:d[1]-u/2,flipX:r?!e.flipX:!!e.flipX,flipY:i?!e.flipY:!!e.flipY,rotation:f?-(e.rotation??0):e.rotation??0},a)},vn=[`Texte`],yn=150,bn=(e,t)=>fr(e,En,t),xn=(e,t)=>{let n=bn(e,t),r=Qn(e);return{...e,path:r,selection:R(void 0,n,t),computed:n}},Sn=xn,Cn=(e,t,n,r,i,a=D)=>{e.font=`${i?`italic`:``} ${r?`bold`:``} 1px ${a}`;let o=t.map(t=>n/e.measureText(t).width);return Math.min(...o)||36},wn=(e,t,n,r)=>{let i=Cn(e,vn,yn,t.settings?.fontBold.default??!1,t.settings?.fontItalic.default??!1,t.settings.fontFamily.default),a=yn,o=i*(vn.length||1);return xn({toolId:t.id,type:t.type,id:V(`${t.type}_`),x:n[0]-a,y:n[1]-o,value:vn,fontSize:i,width:a,height:o,ratio:a/o,style:{opacity:t.settings.opacity.default,strokeColor:t.settings.strokeColor.default,fontFamily:t.settings.fontFamily.default,fontItalic:t.settings.fontItalic.default,fontBold:t.settings.fontBold.default}},r)},Tn=(e,t)=>{if(!(e.globalAlpha===0||!t.style?.strokeColor||t.style.strokeColor===`transparent`)){e.scale(t.flipX?-1:1,t.flipY?-1:1),e.font=`${t.style?.fontItalic?`italic`:``} ${t.style?.fontBold?`bold`:``} ${t.fontSize}px ${t.style?.fontFamily??`serif`}`,e.textBaseline=`top`,e.fillStyle=t.style.strokeColor;for(let n=0;n<t.value.length;n++)e.fillText(t.value[n],t.flipX?-t.x-t.width:t.x,(t.flipY?-t.y-t.height:t.y)+n*t.fontSize,t.width)}},En=(e,t)=>lr({x:e.x,y:e.y,width:e.width,height:e.height},t.selectionPadding),Dn=(e,t,n,r,i,a)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l,isXinverted:u,isYinverted:d}=se(t,n,r,i,!0,a),f=Math.max(0,l-2*i.selectionPadding),p=Math.max(0,s-2*i.selectionPadding),m=xn({...n,width:f,height:p,x:o+i.selectionPadding,y:c+i.selectionPadding,flipX:u?!n.flipX:!!n.flipX,flipY:d?!n.flipY:!!n.flipY},i);return{...m,fontSize:Cn(e,m.value,m.width,m.style?.fontBold??!1,m.style?.fontItalic??!1,m.style?.fontFamily)}},On=(e,t,n,r)=>{let{isXinverted:i,isYinverted:a,settings:o,widthMultiplier:s,heightMultiplier:c}=r,l=(i||a)&&!(i&&a)&&(t.rotation??0)!==0&&r.rotation!==t.rotation,u=de(t,n,r),d=(t.width===0||t.height===0?t.ratio??1:t.width)*s,f=(t.width===0||t.height===0?t.ratio??1:t.height)*c,p=fe(r,u.x,u.y,d,f),m=xn({...t,width:d,height:f,x:p[0]-d/2,y:p[1]-f/2,flipX:i?!t.flipX:!!t.flipX,flipY:a?!t.flipY:!!t.flipY,rotation:l?-(t.rotation??0):t.rotation??0},o);return{...m,fontSize:Cn(e,m.value,m.width,m.style?.fontBold??!1,m.style?.fontItalic??!1,m.style?.fontFamily)}},kn=(e,t,n,r,i,a=D)=>{e.font=`${i?`italic`:``} ${r?`bold`:``} ${n}px ${a}`;let o=t.map(t=>e.measureText(t).width);return Math.max(...o)||20},An=(e,t,n,r)=>{let i={...t,value:n},a=kn(e,i.value,i.fontSize,i.style?.fontBold??!1,i.style?.fontItalic??!1,i.style?.fontFamily),o=i.fontSize*i.value.length,s=a/o,c={...i,width:a,height:o,ratio:s},{center:l}=bn(c,r),[u,d]=ve([1,1],t.computed.center,t),[f,p]=ve([1,1],l,c,[!1,!1]);return{...c,x:c.x-(f-u),y:c.y-(p-d)}},jn=(e,t,n,r)=>{let i=[J(n[0],r),J(n[1],r)];switch(t.type){case`brush`:return Ye(t,i,r);case`line`:return zt(t,i,r);case`polygon`:return ut(t,i,r);case`curve`:return bt(t,i,r);case`rect`:case`square`:return he(t,i,r);case`text`:return wn(e,t,i,r);case`ellipse`:return kt(t,i,r);case`circle`:return it(t,i,r)}},Mn=(e,t)=>{switch(t.type){case`brush`:Xe(e,t);break;case`text`:Tn(e,t);break;case`line`:Vt(e,t);break;case`polygon`:dt(e,t);break;case`curve`:St(e,t);break;case`circle`:at(e,t);break;case`ellipse`:At(e,t);break;case`rect`:ge(e,t);break;case`square`:ge(e,t);break;case`picture`:hn(e,t);break}},Nn=(e,t)=>{let{outerBorders:n}=t.computed,r={width:n.width*2,height:n.height*2};if(r.width===0||r.height===0)return;let i=document.createElement(`canvas`),a=i.getContext(`2d`);if(!a)throw Error(`No context found for canvas`);i.width=r.width,i.height=r.height,a.translate(r.width/4-n.x,r.height/4-n.y),k(a,{...t.style,opacity:100}),Mn(a,t),e.drawImage(i,n.x-r.width/4,n.y-r.height/4)},Pn=(e,t,n)=>!!Er(e.computed.boundingBox,n??Fe(t)),Fn=(e,t,n,r)=>{if(t.visible!==!1&&Pn(t,n,r)){if(A(e,n,t.rotation,t.computed.center),k(e,t.style),e.globalAlpha!==1){Nn(e,t),e.restore();return}Mn(e,t),e.restore()}},In=(e,t,n)=>{if(e.locked)return e;let r=P({origin:n,point:e.computed.center,rotation:-t});if(`points`in e){if(e.type===`brush`){let n=e.points.map(t=>t.map(t=>[t[0]+r[0]-e.computed.center[0],t[1]+r[1]-e.computed.center[1]]));return{...e,points:n,rotation:(e.rotation??0)+t}}let i=e.points.map(e=>P({origin:n,point:e,rotation:-t}));return{...e,points:i}}return{...e,x:e.x+r[0]-e.computed.center[0],y:e.y+r[1]-e.computed.center[1],rotation:(e.rotation??0)+t}},Ln=(e,t,n,r,i,a,o)=>{if(n.locked)return n;switch(n.type){case`line`:return Ht(t,n,r,i);case`polygon`:return pt(t,n,r,i);case`curve`:return xt(t,n,r,i);case`brush`:return Ze(t,n,r,i,a,o);case`circle`:return ot(t,n,r,i,o);case`ellipse`:return jt(t,n,r,i,a,o);case`rect`:case`square`:return ye(t,n,r,i,n.type===`square`||a,o);case`text`:return Dn(e,t,n,r,i,o);case`picture`:return gn(t,n,r,i,o);default:return n}},Rn=(e,t,n,r,i,a,o)=>{if(n.type!==`group`)return U(n).map(n=>Ln(e,t,n,r,i,a,o));let s=n,c=U(s),l=c.filter(e=>p.includes(e.type)),u=!l.some(e=>(e.rotation??0)!==(l[0]?.rotation??0)),d=(l[0]?.rotation??0)!==0&&l.length!==c.length,f=c.some(e=>m.includes(e.type)),h=ue(t,s,r,i,a||!u||f||d,o);return c.map(n=>{if(n.locked)return n;switch(n.type){case`rect`:case`square`:return be(n,s,h);case`picture`:return _n(n,s,h);case`text`:return On(e,n,s,h);case`ellipse`:return Mt(n,s,h);case`circle`:return st(n,s,h);case`brush`:return Qe(n,s,h);case`line`:case`polygon`:case`curve`:return Wt(n,s,h);default:return Ln(e,t,n,r,i,a,o)}})},zn=(e,t,n,r,i,a)=>{if(n.length===0)return t;let o=W(n,a),s=o.computed.borders,c={newBorderX:s.x,newBorderY:s.y,newBorderWidth:s.width,newBorderHeight:s.height,widthMultiplier:1,heightMultiplier:1,isXinverted:i===`flipHorizontally`,isYinverted:i===`flipVertically`,groupCenter:r,rotation:0,settings:a,originalBorders:s},l=new Set(n.map(e=>e.id));return t.map(t=>{if(t.locked||!l.has(t.id))return t;switch(t.type){case`rect`:case`square`:return be(t,o,c);case`picture`:return _n(t,o,c);case`text`:return On(e,t,o,c);case`ellipse`:return Mt(t,o,c);case`circle`:return st(t,o,c);case`brush`:return Qe(t,o,c);case`line`:case`polygon`:case`curve`:return Wt(t,o,c);default:return t}})},Bn=(e,t,n,r)=>{if(e.locked)return e;switch(e.type){case`rect`:case`square`:case`ellipse`:case`circle`:case`picture`:case`text`:return Hn({...e,x:e.x+t,y:e.y+n},r);case`line`:case`polygon`:case`curve`:return Hn({...e,points:e.points.map(([e,r])=>[e+t,r+n])},r);case`brush`:return Hn({...e,points:e.points.map(e=>e.map(([e,r])=>[e+t,r+n]))},r);default:return e}},Vn=(e,t,n,r,i)=>{let a=t.computed.borders,o=Jn([e[0]-n[0],e[1]-n[1]],i),s=o[0]===0?0:J(a.x+r.selectionPadding+o[0],r)-(a.x+r.selectionPadding),c=o[1]===0?0:J(a.y+r.selectionPadding+o[1],r)-(a.y+r.selectionPadding);return U(t).map(e=>Bn(e,s,c,r))},Hn=(e,t)=>{switch(e.type){case`rect`:case`square`:return me(e,t);case`ellipse`:return Ot(e,t);case`circle`:return rt(e,t);case`picture`:return un(e,t);case`text`:return Sn(e,t);case`line`:return Rt(e,t);case`polygon`:return lt(e,t);case`curve`:return yt(e,t);case`brush`:return Je(e,t);default:return e}},Un=({ctx:e,shape:t,settings:n,selectionWidth:r,selectionColor:i,hoverMode:a,selectionMode:o,withAnchors:s=!0})=>{switch(n.debug&&ne(e,t,r,n),t.type){case`rect`:case`square`:case`circle`:case`ellipse`:case`picture`:case`text`:case`brush`:z(e,t,i,r,n,s);break;case`group`:De(e,t,i,r,o,n,s);break;case`polygon`:case`line`:case`curve`:Oe({ctx:e,shape:t,withAnchors:s,selectionWidth:r,selectionColor:i,hoverMode:a,settings:n});break}e.restore()},Wn=({ctx:e,selectionFrame:t,settings:n})=>{A(e,n),ke(e,t.frame,n),e.restore()},Gn=(e,t)=>U(e).map(e=>({...Bn(e,20,20,t),id:V(`${e.type}_`)})),q=(e,t=2)=>Math.round(e*10**t)/10**t,Kn=(e,t,n,r=1,i=1)=>[t+(e[0]-t)*r,n+(e[1]-n)*i],J=(e,t,n=0)=>{if(!t.gridGap)return q(e);let r=e+n,i=r>=0?t.gridGap:-t.gridGap;return r+i/2-(r+i/2)%i-n},qn=(e,t,n)=>!t.gridGap&&!n?q(e,3):e+Math.PI/18/2-(e+Math.PI/18/2)%(Math.PI/18),Jn=(e,t)=>t?[Math.abs(e[0])>Math.abs(e[1])?e[0]:0,Math.abs(e[1])>Math.abs(e[0])?e[1]:0]:e,Yn=(e,t,n,r,i,a,o)=>{if(r.mode===`translate`)return W(Vn(n,r.originalShape,r.cursorStartPosition,i,a),i);if(r.mode===`rotate`){let{originalShape:e,cursorStartPosition:t}=r,o=e.computed.center,[s,c]=o,l=qn(Math.atan2(c-n[1],s-n[0])-Math.atan2(c-t[1],s-t[0]),i,a);return W(U(e).map(e=>Hn(In(e,l,o),i)),i)}return r.mode===`resize`?W(Rn(e,n,r.originalShape,r,i,a,o),i):r.mode===`brush`?W(U(t).map(e=>$e(e,n,i)),i):t},Xn=(e,t,n,r,i=!1)=>{if(!e||!t||!r||!n)return[300,300];let a=e/t;if(a>n/r){let t=i?n:Math.min(e,n);return[t,t/a]}let o=i?r:Math.min(t,r);return[o*a,o]},Zn=({line:e,size:t,direction:n})=>{let r=Math.PI/2-I({targetVector:[e.points[0],e.points[1]]}),i=[e.points[0][0]+(e.points[1][0]-e.points[0][0])/2,e.points[0][1]+(e.points[1][1]-e.points[0][1])/2],a;if([`start`,`both`].includes(n)){let n=P({point:e.points[0],origin:i,rotation:-r});a=P({point:[n[0],n[1]+t],origin:i,rotation:r})}else a=[...e.points[0]];let o;if([`end`,`both`].includes(n)){let n=P({point:e.points[1],origin:i,rotation:-r});o=P({point:[n[0],n[1]-t],origin:i,rotation:r})}else o=[...e.points[1]];return{points:[a,o]}},Qn=e=>{let t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},$n=e=>{let t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},er=e=>{let t=new Path2D;return t.ellipse(e.x,e.y,e.radiusX,e.radiusY,0,0,2*Math.PI),t},tr=e=>{let t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},nr=(e,{brushAlgo:t})=>{let n=new Path2D;if(e.points.length<1)return n;let r=e.points.flat(),i=r.map(e=>e[0]),a=r.map(e=>e[1]),o=Math.min(...i),s=Math.min(...a);for(let r of e.points)if(r.length)if(r.length===1)n.rect(...Kn(r[0],o,s,e.scaleX,e.scaleY),1,1);else switch(n.moveTo(...Kn(r[0],o,s,e.scaleX,e.scaleY)),t){case`quadratic`:for(let t=0;t<r.slice(1).length-2;t++){let i=Kn(r[t],o,s,e.scaleX,e.scaleY),a=Kn(r[t+1],o,s,e.scaleX,e.scaleY),c=(i[0]+a[0])/2,l=(i[1]+a[1])/2;n.quadraticCurveTo(...i,c,l)}n.quadraticCurveTo(...Kn(r[r.length-2],o,s,e.scaleX,e.scaleY),...Kn(r[r.length-1],o,s,e.scaleX,e.scaleY));break;default:for(let t of r.slice(1))n.lineTo(...Kn(t,o,s,e.scaleX,e.scaleY));break}return n},rr=(e,t,n,r)=>{let i=i=>(1-i)**3*e[0]+3*(1-i)**2*i*t[0]+3*(1-i)*i**2*n[0]+i**3*r[0],a=i=>(1-i)**3*e[1]+3*(1-i)**2*i*t[1]+3*(1-i)*i**2*n[1]+i**3*r[1],o=(e,t,n)=>{let r=e-2*t+n,i=-2*e+2*t,a=e;if(Math.abs(r)<1e-10){if(Math.abs(i)<1e-10)return[];let e=-a/i;return e>0&&e<1?[e]:[]}let o=i*i-4*r*a;if(o<0)return[];let s=Math.sqrt(o),c=(-i-s)/(2*r),l=(-i+s)/(2*r),u=[];return c>0&&c<1&&u.push(c),l>0&&l<1&&l!==c&&u.push(l),u},s=e[0],c=t[0],l=n[0],u=r[0],d=e[1],f=t[1],p=n[1],m=r[1],h=o(c-s,l-c,u-l),g=o(f-d,p-f,m-p),_=Math.min(e[0],r[0]),v=Math.max(e[0],r[0]),y=Math.min(e[1],r[1]),b=Math.max(e[1],r[1]);for(let e of h){let t=i(e);_=Math.min(_,t),v=Math.max(v,t)}for(let e of g){let t=a(e);y=Math.min(y,t),b=Math.max(b,t)}return{minX:_,maxX:v,minY:y,maxY:b}},ir=(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]],ar=(e,t,n,r)=>({cp1:[t[0]+(n[0]-e[0])/6,t[1]+(n[1]-e[1])/6],cp2:[n[0]-(r[0]-t[0])/6,n[1]-(r[1]-t[1])/6]}),or=e=>{let t=new Path2D,n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2)return t;if(n.length<3)return sr(e);let r=e.style?.closedPoints===1&&n.length>2;t.moveTo(...n[0]);let i=ir(e,n);for(let e=1;e<i.length-2;e++){let n=i[e-1],r=i[e],a=i[e+1],o=i[e+2],{cp1:s,cp2:c}=ar(n,r,a,o);t.bezierCurveTo(s[0],s[1],c[0],c[1],a[0],a[1])}return r&&t.closePath(),t},sr=e=>{let t=new Path2D,n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2)return t;t.moveTo(...n[0]);for(let e of n.slice(1))t.lineTo(...e);return n.length>2&&e.style?.closedPoints===1&&t.lineTo(...n[0]),t},cr=e=>{let 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},lr=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}),ur=(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)}),dr=(e,t,n=0)=>{if(n===0)return e;let r=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]].map(e=>P({point:e,origin:t,rotation:n})),i=Math.min(...r.map(e=>e[0])),a=Math.min(...r.map(e=>e[1])),o=Math.max(...r.map(e=>e[0])),s=Math.max(...r.map(e=>e[1]));return{x:i,y:a,width:o-i,height:s-a}},fr=(e,t,n,r=ur)=>{let i=t(e,n),a=r(e,i,n),o=[i.x+i.width/2,i.y+i.height/2];return{borders:i,outerBorders:a,center:o,boundingBox:dr(a,o,e.rotation)}},pr=e=>{let{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}},mr=(e,t,n)=>{let{clientX:r,clientY:i}=pr(e),a=t.getBoundingClientRect();return[(r-a.left)/n.scaleRatio,(i-a.top)/n.scaleRatio]},hr=(e,t,n)=>{let{clientX:r,clientY:i}=pr(e),a=t?.getBoundingClientRect()??{left:0,top:0,width:n.canvasSize.width,height:n.canvasSize.height};return[(r-a.left)*(n.canvasSize.width/a.width)/n.canvasSize.scaleRatio-n.canvasOffset[0],(i-a.top)*(n.canvasSize.height/a.height)/n.canvasSize.scaleRatio-n.canvasOffset[1]]},gr=e=>`touches`in e,_r=(e,t,[n,r])=>P({origin:[n,r],point:e,rotation:t}),vr=(e,t,[n,r])=>P({origin:[n,r],point:e,rotation:-t}),yr=(e,t,n)=>n?ee(e,{x:t[0],y:t[1],radius:n}):N(e,t),br=(e,t,n,r=0)=>{let{canvasSize:{scaleRatio:i}}=n,{borders:a}=e.computed;if(e.type===`line`||e.type===`polygon`||e.type===`curve`){for(let n=0;n<e.points.length;n++)if(yr({x:e.points[n][0]-14/2/i,y:e.points[n][1]-14/2/i,width:14/i,height:14/i},t,r))return{mode:`resize`,anchor:n}}else{if(yr({x:a.x+a.width/2-14/2/i,y:a.y-14/i-16/i,width:14/i,height:14/i},t,r))return{mode:`rotate`};for(let e of d)if(yr({x:a.x+a.width*e[0]-14/2/i,y:a.y+a.height*e[1]-14/2/i,width:14/i,height:14/i},t,r))return{mode:`resize`,anchor:e}}return!1},xr=(e,t,n,r,i=!1,a=0)=>{let o=U(t).length>1?t:U(t)[0];if(!o)return!1;let{borders:s,center:c}=o.computed,l=_r(n,o.rotation??0,c);if(i){let e=br(o,l,r,a);if(e)return e}return o.selection?.type===`line`?(e.lineWidth=(o.style?.lineWidth??0)+15/r.canvasZoom,(wr(o,!0)?e.isPointInPath(o.path,l[0],l[1]):e.isPointInStroke(o.path,l[0],l[1]))?{mode:`translate`}:!1):yr(s,l,(15+a)/r.canvasZoom)?{mode:`translate`}:!1},Sr=(e,t,n,r,i=50)=>{if(t.locked||t.points.length<2)return!1;let{center:a}=t.computed,o=_r(n,t.rotation??0,a);e.lineWidth=(t.style?.lineWidth??0)+i/r.canvasZoom;let s=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let t=0;t<s.length-1;t++){let n=tr({points:[s[t],s[t+1]]});if(e.isPointInStroke(n,o[0],o[1]))return{lineIndex:t}}return!1},Cr=(e,t,n,r,i=50)=>{if(t.locked||t.points.length<2)return!1;if(t.points.length<3)return Sr(e,t,n,r,i);let{center:a}=t.computed,o=_r(n,t.rotation??0,a);e.lineWidth=(t.style?.lineWidth??0)+i/r.canvasZoom;let s=ir(t,t.points),c=new Path2D;c.moveTo(...s[0]);for(let t=1;t<s.length-2;t++){let n=s[t-1],r=s[t],i=s[t+1],a=s[t+2],{cp1:l,cp2:u}=ar(n,r,i,a);if(c.bezierCurveTo(l[0],l[1],u[0],u[1],i[0],i[1]),e.isPointInStroke(c,o[0],o[1]))return{lineIndex:t-1}}return!1},wr=(e,t=!1)=>t&&[`curve`,`polygon`].includes(e.type)?!0:e.style?.fillColor&&e.style?.fillColor!==`transparent`||[`picture`,`text`].includes(e.type),Tr=(e,t,n,r)=>{let{center:i}=t.computed,a=_r(n,t.rotation??0,i);return e.lineWidth=(t.style?.lineWidth??0)+15/r.canvasZoom,(wr(t)?e.isPointInPath(t.path,a[0],a[1]):e.isPointInStroke(t.path,a[0],a[1]))?{mode:`translate`}:!1};function Er(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+(e.width||1),t.x+(t.width||1)),a=Math.min(e.y+(e.height||1),t.y+(t.height||1));if(n<i&&r<a)return{x:n,y:r,width:i-n,height:a-r}}var Dr=({ctx:e,path:t,rect:n,offset:r,center:i,rotation:a=0,checkFill:o})=>{for(let s=0;s<r;s+=r/2)for(let c=0;c<r;c+=r/2)for(let l=s+n.x;l<n.x+n.width;l+=r)for(let s=c+n.y;s<n.y+n.height;s+=r){let n=_r([l,s],a,i);if(o?e.isPointInPath(t,n[0],n[1]):e.isPointInStroke(t,n[0],n[1]))return!0}return!1},Or=10,kr=(e,t,n)=>{let{borders:r,center:i,boundingBox:a}=t.computed,o=Math.min(n[0][0],n[1][0]),s=Math.max(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1]),l=Math.max(n[0][1],n[1][1]),u={x:o,y:c,width:s-o,height:l-c},d=Er(a,u);if(!d)return!1;if(r.width<=1||r.height<=1)return!0;if(e.lineWidth=(t.style?.lineWidth??0)+Or,t.type===`brush`){let n=t.points.flat(),r=Math.min(...n.map(e=>e[0])),a=Math.min(...n.map(e=>e[1]));for(let n of t.points){if(n.length<1)break;if(n.length<2){let e=Kn(n[0],r,a,t.scaleX,t.scaleY);if(ee(d,{x:e[0],y:e[1],radius:(t.style?.lineWidth??1)/2}))return!0}for(let o=0;o<n.length-1;o++){let s=vr(Kn(n[o],r,a,t.scaleX,t.scaleY),t.rotation??0,i),c=vr(Kn(n[o+1],r,a,t.scaleX,t.scaleY),t.rotation??0,i),l=Er({x:Math.min(s[0],c[0]),y:Math.min(s[1],c[1]),width:Math.abs(s[0]-c[0]),height:Math.abs(s[1]-c[1])},u);if(l){let t=new Path2D;if(t.moveTo(...s),t.lineTo(...c),Dr({ctx:e,path:t,rect:l,offset:Or,center:i,checkFill:!1}))return!0}}}return!1}let f=wr(t);return Dr({ctx:e,path:t.path,rect:d,offset:Or,center:i,rotation:t.rotation??0,checkFill:f})},Ar=5,jr=(e,t)=>{if(!gr(e))return!0;let{clientX:n,clientY:r}=pr(e),i=n-t.clientX,a=r-t.clientY;return i*i+a*a>Ar*Ar},Mr=(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)=>{if(_&&jr(e,_.startPosition)&&clearTimeout(_.timeout),gr(e)&&e.touches.length>1)return;let v=t.current?.getContext(`2d`);if(!v)return;let y=hr(e,t.current,f);if(r.mode===`selectionFrame`){d(v,y,f);let n=mr(e,t.current,f.canvasSize);g([Math.ceil(le(n[0]*f.canvasZoom<50?n[0]*f.canvasZoom-50:n[0]*f.canvasZoom>f.canvasSize.width/f.canvasSize.scaleRatioWithNoZoom-50?n[0]*f.canvasZoom-(f.canvasSize.width/f.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/f.canvasZoom),Math.ceil(le(n[1]*f.canvasZoom<50?n[1]*f.canvasZoom-50:n[1]*f.canvasZoom>f.canvasSize.height/f.canvasSize.scaleRatioWithNoZoom-50?n[1]*f.canvasZoom-(f.canvasSize.height/f.canvasSize.scaleRatioWithNoZoom-50):0,-100,100)/5/f.canvasZoom)]);return}if(a!==void 0){u([y[0]+f.canvasOffset[0]-a.start[0],y[1]+f.canvasOffset[1]-a.start[1]]);return}if(r.mode===`preview`){let e=U(n)[0];if(e?.type===`curve`){h(W([wt(e,y,f,!0)],f));return}if(e?.type===`polygon`){h(W([ht(e,y,f,!0)],f));return}}let b=ze(y,f);if(gr(e)||s(e,v,y,b),n===void 0||n.locked){o({mode:`default`,outOfView:!b});return}if(r.mode===`default`||r.mode===`textedition`||r.mode===`contextMenu`){if(!b){o({mode:`default`});return}o(xr(v,n,y,f,!0)||{mode:`default`})}else{let e=t.current?.getContext(`2d`);if(!e)return;c(U(Yn(e,n,y,r,f,p,m)))}r.mode===`translate`&&m&&!r.hasBeenDuplicated&&(i({...r,hasBeenDuplicated:!0}),l(U(r.originalShape)))},Nr=e=>{let{shapes:n,settings:r,selectedShape:i,selectionMode:a,activeTool:o,canvasOffsetStartData:s,isInsideComponent:c,isInsideCanvas:l,isShiftPressed:u,isAltPressed:d,isSpacePressed:p,withFrameSelection:m,withContextMenu:h,setSelectedShape:g,setSelectionFrame:_,setSelectionMode:v,setActiveTool:x,setCanvasOffsetStartData:S,setCanvasOffset:C,setCanvasMoveAcceleration:E,addShapes:D,updateSingleShape:O,duplicateShapes:k,saveShapes:A,refreshHoveredShape:j,refreshSelectedShapes:M}=y(),N=(0,t.useRef)(null),[ee,P]=(0,t.useState)({mode:`default`});(0,t.useEffect)(()=>()=>{N.current&&clearTimeout(N.current.timeout)},[]);let{registerDoubleClickEvent:F,unRegisterDoubleClickEvent:I}=w(),L=(t,a)=>{let s=a?.getContext(`2d`);if(s){if(o!==b||!h)g(void 0),v({mode:`default`});else{let a=hr(t,e.current,r),{shape:o,mode:c}=Ce(s,n,a,r,i,gr(t),!1);g(o),v({mode:`contextMenu`,cursorStartPosition:a,originalShape:o,anchor:`anchor`in c?c.anchor:void 0})}x(b),_(void 0)}},te=(0,t.useRef)(null);te.current=t=>Mr(t,e,i,a,v,s,P,j,O,k,C,M,r,u,d,g,E,N.current);let R=c?document:null;T(R,`mousemove`,e=>te.current?.(e)),T(R,`touchmove`,e=>te.current?.(e));let{isBrushShapeDoneOnMouseUp:ne}=r,z=(0,t.useRef)(null);z.current=t=>{if(N.current&&clearTimeout(N.current.timeout),gr(t)&&t.touches.length>1)return;let o=e.current?.getContext(`2d`);if(!o)return;if(`button`in t&&t.button===2){L(t,e.current);return}if(s){S(void 0);return}if(a.mode===`contextMenu`||a.mode===`textedition`||a.mode===`preview`)return;let c=hr(t,e.current,r);if(a.mode===`translate`&&Date.now()-a.dateStart<=500&&c[0]===a.cursorStartPosition[0]&&c[1]===a.cursorStartPosition[1]){if(t.ctrlKey||t.shiftKey||t.metaKey){let{shape:e}=Ce(o,n,c,r,i,gr(t),m,`remove`);U(e).length!==a.selectedShapesLengthAtMouseDown&&g(e)}v({mode:`default`}),_(void 0),A();return}a.mode!==`default`&&(a.mode===`brush`&&ne&&g(void 0),v({mode:`default`}),_(void 0),A())};let re=l?document:null;T(re,`mouseup`,e=>z.current?.(e)),T(re,`touchend`,e=>z.current?.(e));let ie=!r.features.edition&&r.features.zoom,ae=!r.features.edition&&!r.features.zoom,B=(0,t.useRef)(null);return B.current=(t,s,c)=>{if(t.preventDefault(),gr(t)&&t.touches.length>1)return;let l=s?.getContext(`2d`);if(!l)return;s.focus();let u=hr(t,e.current,r),d=`button`in t&&t.button===1,p=`button`in t&&t.button===2;if(d||c||o.type===`move`&&!p){S({start:u,originalOffset:r.canvasOffset});return}if(!ie){if(!ze(u,r)){g(void 0),v({mode:`default`});return}if(p){if(o.type===`selection`){let{shape:e}=Ce(l,n,u,r,i,gr(t),!1);g(e),v({mode:`default`})}return}if(gr(t)&&(N.current&&clearTimeout(N.current.timeout),N.current={timeout:setTimeout(()=>{L(t,e.current)},500),startPosition:pr(t)}),o.type===`selection`){let e=t.ctrlKey||t.shiftKey||t.metaKey?`add`:`replace`,{shape:a,mode:o}=Ce(l,n,u,r,i,gr(t),m,e);g(a),v(o),o.mode===`selectionFrame`&&_({oldSelection:a,frame:[[u[0],u[1]],[u[0],u[1]]]})}else if(f.some(e=>e===o.type)){let t=U(i)[0],n=e.current?.getContext(`2d`);if(!n)return;if(o.type===`brush`){if(t?.type===`brush`)O([et(t,u,r)]);else{let e=jn(n,o,u,r);if(!e)return;D([e]),g(W([e],r))}v({mode:`brush`})}else if(a.mode===`preview`&&(t?.type===`polygon`||t?.type===`curve`)){let e=t.type===`polygon`?ht(t,u,r):wt(t,u,r);g(W([e],r)),O([e],!0)}else if(o.type!==`picture`){let e=jn(n,o,u,r);if(!e)return;D([e]);let t=W([e],r);g(t),e.type===`polygon`||e.type===`curve`?v({mode:`preview`}):(x(b),v({mode:`resize`,cursorStartPosition:[u[0]+r.selectionPadding,u[1]+r.selectionPadding],originalShape:t,anchor:e.type===`line`?0:[1,1],selectedShapesLengthAtMouseDown:U(t).length}))}}}},(0,t.useEffect)(()=>{if(ae)return;let t=e.current;if(!t)return;let n=e=>B.current?.(e,t,p);return t.addEventListener(`mousedown`,n,{passive:!1}),t.addEventListener(`touchstart`,n,{passive:!1}),()=>{t.removeEventListener(`mousedown`,n),t.removeEventListener(`touchstart`,n)}},[ae,e,p]),(0,t.useEffect)(()=>{let t=e.current,n=e.current?.getContext(`2d`);if(!t||!n)return;let a=t=>{if(o.type!==`selection`)return;let a=U(i);if(a.length!==1)return;let s=a[0];if(s?.locked)return;let c=hr(t,e.current,r);if(ze(c,r)){if(s?.type===`text`){xr(n,i,c,r)&&v({mode:`textedition`,defaultValue:s.value});return}if(s?.type===`polygon`){let e=Sr(n,s,c,r);e&&O([mt(s,e.lineIndex,c,r)]);return}if(s?.type===`curve`){let e=Cr(n,s,c,r);e&&O([Ct(s,e.lineIndex,c,r)]);return}}};if(l)return F(t,a),()=>{I(t)}},[O,F,I,l,e,o,i,v,r]),{hoverMode:ee}},Pr=(e,t)=>{let{canvasSize:{width:n,height:r},gridGap:i,canvasOffset:a,canvasSize:{scaleRatio:o}}=t;if(!i)return;e.strokeStyle=`rgb(220,220,220)`,e.lineWidth=1,e.save(),e.scale(o,o),e.beginPath();let s=a[0]%i,c=a[1]%i,l=Math.ceil(n/o/i)+2,u=Math.ceil(r/o/i)+2;for(let t=-5;t<l;t++)e.moveTo(s+(t+1)*i,c-i),e.lineTo(s+(t+1)*i,c+r/o+i);for(let t=-5;t<u;t++)e.moveTo(s-i,c+(t+1)*i),e.lineTo(s+n/o+i,c+(t+1)*i);e.stroke(),e.restore()},Fr=e=>e.childNodes.length?Array.from(e.childNodes).map(e=>Fr(e)).join(``):e.nodeValue??``,Ir=({disabled:e=!1,shape:r,defaultValue:i,updateValue:a,saveShapes:o,settings:s})=>{let c=(0,t.useRef)(null),l=(0,t.useRef)(o),u=e=>{a(Array.from(e.target.childNodes).map(e=>Fr(e)))};(0,t.useEffect)(()=>{if(!c.current)return;let e=c.current,t=t=>{t.preventDefault();let n=t.clipboardData?.getData(`text/plain`);if(!n)return;let r=window.getSelection();if(!r||r.rangeCount===0)return;r.deleteFromDocument();let i=r.getRangeAt(0);i.insertNode(document.createTextNode(n)),i.collapse(!1),r.removeAllRanges(),r.addRange(i),e.dispatchEvent(new Event(`input`,{bubbles:!0}))};e.addEventListener(`paste`,t),e.innerText=``;for(let t of i){let n=document.createElement(`div`);t===``?n.innerHTML=`<br/>`:n.innerText=t,e.appendChild(n)}return e.focus(),()=>{e.removeEventListener(`paste`,t)}},[i]),(0,t.useEffect)(()=>{let e=l.current;return()=>{e()}},[]);let d=(0,t.useMemo)(()=>{let{borders:e,center:t}=r.computed;return P({point:[e.x,e.y],rotation:-(r.rotation??0),origin:t})},[r]),f=[`translate3D(${(d[0]+s.canvasOffset[0])*s.canvasSize.scaleRatio}px, ${(d[1]+s.canvasOffset[1])*s.canvasSize.scaleRatio}px, 0)`,`rotate(${M(r.rotation??0)}deg)`,r.flipX||r.flipY?`scale(${r.flipX?-1:1}, ${r.flipY?-1:1})`:void 0,r.flipX||r.flipY?`translate3D(${r.flipX?-100:0}%,${r.flipY?-100:0}%,0)`:void 0].filter(Boolean).join(` `),p=!e;return(0,n.jsx)(`div`,{className:`react-paint-editor-toolbox-edittextbox`,ref:c,"data-fontbold":r.style?.fontBold??!1,"data-fontitalic":r.style?.fontItalic??!1,contentEditable:p,role:`textbox`,tabIndex:p?0:void 0,onInput:u,style:{"--react-paint-editor-toolbox-edittextbox-transform":f,"--react-paint-editor-toolbox-edittextbox-fontsize":`${r.fontSize*s.canvasSize.scaleRatio}px`,"--react-paint-editor-toolbox-edittextbox-padding":`${s.selectionPadding*s.canvasSize.scaleRatio}px`,"--react-paint-editor-toolbox-edittextbox-color":r.style?.strokeColor??`inherit`,"--react-paint-editor-toolbox-edittextbox-opacity":(r.style?.opacity??100)/100,"--react-paint-editor-toolbox-edittextbox-fontfamily":r.style?.fontFamily??`serif`}})},Lr=(e,t,n,r,i)=>{O(e),Re(e,n),Pr(e,n);let a=Fe(n);for(let o=r.length-1;o>=0;o--)t.mode===`textedition`&&r[o]===i||Fn(e,U(i).find(e=>e.id===r[o].id)??r[o],n,a)},Rr=(e,t,n,r,i,a,o,s,c,l,u)=>{e.reset(),Le(e,n),u&&s&&!U(o).find(e=>e.id===s.id)&&r.type===`selection`&&(t.mode===`default`||t.mode===`contextMenu`||t.mode===`textedition`)&&Un({ctx:e,shape:s,settings:n,selectionWidth:i,selectionColor:a,hoverMode:c,selectionMode:t,withAnchors:!1}),o&&r.type!==`brush`&&Un({ctx:e,shape:o,settings:n,selectionWidth:i,selectionColor:a,hoverMode:c,selectionMode:t,withAnchors:t.mode!==`textedition`}),l&&Wn({ctx:e,selectionFrame:l,settings:n})},zr=t.default.forwardRef((e,r)=>{let{shapes:i,settings:a,selectedShape:o,hoveredShape:s,selectionFrame:c,selectionMode:l,activeTool:u,canvasOffsetStartData:d,isSpacePressed:f,selectionColor:p,selectionWidth:m,isEditMode:g,canGrow:_,withSkeleton:v,updateSingleShape:b,saveShapes:x}=y(),S=(0,t.useRef)(null),C=(0,t.useRef)(null),w=a.canvasSize,T=g,E=g?0:-1;(0,t.useImperativeHandle)(r,()=>S.current);let{hoverMode:D}=Nr(S),O=(0,t.useCallback)(e=>{let t=U(o)[0];if(t?.type!==`text`)return;let n=S.current?.getContext(`2d`);n&&b([Hn(An(n,t,e,a),a)])},[b,o,a]),k=e=>{if(g)return e.preventDefault(),e.stopPropagation(),!1};return(0,t.useEffect)(()=>{let e=S.current?.getContext(`2d`);e&&window.requestAnimationFrame(()=>Lr(e,l,a,i,o))},[i,l,o,a]),(0,t.useEffect)(()=>{let e=C.current?.getContext(`2d`);e&&window.requestAnimationFrame(()=>Rr(e,l,a,u,m,p,o,s,D,c,v))},[s,D,c,l,o,u,a,m,p,v]),(0,n.jsx)(`div`,{className:`react-paint-canvas-box`,style:{"--react-paint-canvas-cursor":d?`grabbing`:D.outOfView?`default`:D.mode===`resize`?`pointer`:u.type!==`selection`&&u.type!==`move`?`crosshair`:D.mode===`translate`?`move`:D.mode===`rotate`||u.type===`move`||f?`grab`:`default`},children:(0,n.jsxs)(`div`,{className:`react-paint-canvas-container`,"data-grow":_,children:[(0,n.jsx)(`canvas`,{className:h,ref:S,"data-grow":_,width:w.width,height:w.height,onContextMenu:k,tabIndex:E}),T&&(0,n.jsx)(`canvas`,{className:`react-paint-canvas-selectioncanvas`,ref:C,width:w.width,height:w.height,"data-grow":_,onContextMenu:k}),g&&l.mode===`textedition`&&U(o)[0]?.type===`text`&&(0,n.jsx)(Ir,{disabled:!a.features.edition,shape:U(o)[0],defaultValue:l.defaultValue,updateValue:O,saveShapes:x,settings:a})]})})}),Y={ArrowUp:`ArrowUp`,ArrowDown:`ArrowDown`,ArrowLeft:`ArrowLeft`,ArrowRight:`ArrowRight`,Delete:`Delete`,Backspace:`Backspace`,Escape:`Escape`,Shift:`Shift`,Alt:`Alt`,Option:`Option`,Space:` `,A:`A`,a:`a`,z:`z`,Z:`Z`,y:`y`,Y:`Y`,Plus:`+`,Minus:`-`,Zero:`0`},Br={Cut:`cut`,Copy:`copy`,Paste:`paste`},Vr=({isInsideComponent:e,isInsideCanvas:n,selectedShape:r,isEditingText:i,settings:a,copiedShape:o,setCopiedShape:s,setSelectedShape:c,setActiveTool:l,setCanvasZoom:u,resetZoom:d,setSelectionMode:f,setSelectionFrame:p,selectAllShapes:m,removeShape:h,pasteShapes:g,updateShapes:_,backwardShape:v,forwardShape:y,setShiftPressed:x,setAltPressed:S,setIsSpacePressed:C})=>((0,t.useEffect)(()=>{let t=e=>{r&&(i||(e.preventDefault(),s({...r})))},w=e=>{r&&(i||(e.preventDefault(),s({...r}),h(U(r))))},T=e=>{o&&(i||(e.preventDefault(),g(Gn(o,a))))},E=e=>{switch(e.key){case Y.Shift:x(!1);break;case Y.Alt:case Y.Option:S(!1);break;case Y.Space:C(!1);break}},D=e=>{if(e.metaKey||e.ctrlKey){if(e.key===Y.Z||e.key===Y.z){e.preventDefault(),e.stopPropagation(),e.shiftKey?y():v();return}if(!H()&&(e.key===Y.Y||e.key===Y.y)){e.preventDefault(),e.stopPropagation(),y();return}if(e.key===Y.A||e.key===Y.a){e.preventDefault(),e.stopPropagation(),m();return}if(e.key===Y.Plus){e.preventDefault(),e.stopPropagation(),u(`zoom`);return}if(e.key===Y.Minus){e.preventDefault(),e.stopPropagation(),u(`unzoom`);return}if(e.key===Y.Zero){e.preventDefault(),e.stopPropagation(),d();return}}if(e.key===Y.Shift){e.preventDefault(),e.stopPropagation(),x(!0);return}if(e.key===Y.Space&&n){e.preventDefault(),e.stopPropagation(),C(!0);return}if(e.key===Y.Alt||e.key===Y.Option){e.preventDefault(),e.stopPropagation(),S(!0);return}if(!r)return;if(e.key===Y.Escape){c(void 0),l(b),f({mode:`default`}),p(void 0);return}if(i)return;let t={[Y.ArrowLeft]:[a.gridGap?-a.gridGap:-1,0],[Y.ArrowRight]:[a.gridGap?a.gridGap:1,0],[Y.ArrowDown]:[0,a.gridGap?a.gridGap:1],[Y.ArrowUp]:[0,a.gridGap?-a.gridGap:-1]};switch(e.key){case Y.ArrowLeft:case Y.ArrowRight:case Y.ArrowDown:case Y.ArrowUp:e.preventDefault(),e.stopPropagation(),_(Vn(t[e.key],r,[0,0],a,!0));break;case Y.Delete:case Y.Backspace:e.preventDefault(),e.stopPropagation(),h(U(r));break}};if(e)return document.addEventListener(`keydown`,D),document.addEventListener(`keyup`,E),document.addEventListener(Br.Copy,t),document.addEventListener(Br.Paste,T),document.addEventListener(Br.Cut,w),()=>{document.removeEventListener(`keydown`,D),document.removeEventListener(`keyup`,E),document.removeEventListener(Br.Copy,t),document.removeEventListener(Br.Paste,T),document.removeEventListener(Br.Cut,w)}},[e,n,o,i,r,a,_,h,c,g,v,y,x,S,l,f,p,s,u,d,C,m]),{}),Hr=({onResized:e,element:n})=>{(0,t.useEffect)(()=>{let t=n.current;if(!t)return;let r=new ResizeObserver(t=>{let n=t?.[0]?.borderBoxSize?.[0],{width:r,height:i}=n?{width:n.inlineSize,height:n.blockSize}:t?.[0]?.contentRect??{};r!==void 0&&i!==void 0&&e(r,i)});return r.observe(t),()=>{r.unobserve(t)}},[n,e])},Ur=({settings:e,componentRef:n,canvasRef:r})=>{let[i,a]=(0,t.useState)(!1),[o,s]=(0,t.useState)(!1),c=!e.features.edition&&!e.features.zoom;return(0,t.useEffect)(()=>{if(c)a(!1),s(!1);else{let e=()=>a(!0),t=()=>a(!1),i=()=>s(!0),o=()=>s(!1);return n.current?.addEventListener(`focusin`,e),n.current?.addEventListener(`focusout`,t),r.current?.addEventListener(`focusin`,i),r.current?.addEventListener(`focusout`,o),()=>{n.current?.removeEventListener(`focusin`,e),n.current?.removeEventListener(`focusout`,t),r.current?.removeEventListener(`focusin`,i),r.current?.removeEventListener(`focusout`,o)}}},[c,n,r]),{isInsideComponent:i,isInsideCanvas:o}},Wr=(e,t,n,r)=>Ge(e.states[e.cursor]?.shapes,t)?e:{states:[...e.states.slice(0,e.cursor+1),{shapes:t,selectedShape:n,source:r}],cursor:e.cursor+1},Gr=(e,t)=>{switch(t.type){case`ADD`:return{...e,shapes:[...t.newShapes,...e.shapes]};case`UPDATE`:{let n=new Map(t.updatedShapes.map(e=>[e.id,e])),r=e.shapes.map(e=>n.get(e.id)??e),i={...e,shapes:r,selectedShape:t.newSelectedShape};return t.save?{...i,history:Wr(i.history,r,t.newSelectedShape,`user`)}:i}case`REMOVE`:{let n=e.shapes.filter(e=>!t.ids.has(e.id));return{...e,shapes:n,selectedShape:t.newSelectedShape,history:Wr(e.history,n,t.newSelectedShape,`user`)}}case`DUPLICATE`:{let n=e.shapes.flatMap(e=>{let n=t.newShapesMap.get(e.id);return n?[n,e]:[e]});return{...e,shapes:n,selectedShape:t.newSelectedShape??e.selectedShape}}case`RESET_AND_SAVE`:{let n=t.shapes.map(e=>Ve([`chosen`],e));return{...e,shapes:n,selectedShape:t.newSelectedShape,history:Wr(e.history,n,t.newSelectedShape,`user`)}}case`SET_SELECTION`:return{...e,selectedShape:t.newSelectedShape};case`SAVE`:return{...e,history:Wr(e.history,e.shapes,e.selectedShape,`user`)};case`UNDO`:{if(e.history.cursor<=0)return e;let t=e.history.cursor-1,{shapes:n,selectedShape:r}=e.history.states[t];return{...e,shapes:n,selectedShape:r,history:{...e.history,cursor:t}}}case`REDO`:{if(e.history.cursor>=e.history.states.length-1)return e;let t=e.history.cursor+1,{shapes:n,selectedShape:r}=e.history.states[t];return{...e,shapes:n,selectedShape:r,history:{...e.history,cursor:t}}}case`CLEAR`:return t.clearHistory?{shapes:t.shapes,selectedShape:void 0,history:{states:[{shapes:t.shapes,selectedShape:void 0,source:t.source}],cursor:0}}:{...e,shapes:t.shapes,selectedShape:void 0,history:Wr(e.history,t.shapes,void 0,t.source)};case`REFRESH_ALL`:return{...e,shapes:t.shapes,selectedShape:t.newSelectedShape};default:return e}},Kr=(e,n,r,i)=>{let[a,o]=(0,t.useReducer)(Gr,{shapes:[],selectedShape:void 0,history:{states:[{shapes:[],selectedShape:void 0,source:`remote`}],cursor:0}}),s=(0,t.useRef)([]),c=(0,t.useRef)(void 0),l=(0,t.useRef)({dataChanged:[]});(0,t.useLayoutEffect)(()=>{s.current=a.shapes,c.current=a.selectedShape},[a.shapes,a.selectedShape]);let[u,d]=(0,t.useState)(void 0),[f,p]=(0,t.useState)(void 0),[m,h]=(0,t.useState)(void 0),g=(0,t.useCallback)(e=>{o({type:`SET_SELECTION`,newSelectedShape:typeof e==`function`?e(c.current):e})},[]),_=a.history.cursor>0,v=a.history.cursor<a.history.states.length-1,y=a.shapes.length>0,b=(0,t.useCallback)(()=>{o({type:`SAVE`})},[]),x=(0,t.useCallback)(e=>{o({type:`ADD`,newShapes:e})},[]),S=(0,t.useCallback)((t,n=!1,r=!1)=>{let i=new Map,a=[];for(let r of s.current){let o=t.find(e=>e.id===r.id);if(o){let t=n?Gn(W([o],e),e)[0]:{...o,id:V(`${r.type}_`)};i.set(r.id,t),a.push(t)}}o({type:`DUPLICATE`,newShapesMap:i,newSelectedShape:r?W(a,e):c.current})},[e]),C=(0,t.useCallback)((t,n,r,i)=>{if(t.target&&`className`in t.target&&![`react-paint-canvas-drawcanvas`,`react-paint-canvas-selectioncanvas`].includes(t.target.className)||!i){p(void 0);return}p(s.current.filter(e=>!e.locked&&N(e.computed.boundingBox,r)).find(t=>U(a.selectedShape)?.map(e=>e.id).includes(t.id)?!!xr(n,t,r,e):!!Tr(n,t,r,e)))},[e,a.selectedShape]),w=(0,t.useCallback)(async(t,n=300,r=300)=>{let i=await mn(t,n,r,e);return o({type:`ADD`,newShapes:[i]}),o({type:`SAVE`}),i},[e]),T=(0,t.useCallback)((t,n=!1)=>{let r=new Map(t.map(e=>[e.id,e])),i=c.current;o({type:`UPDATE`,updatedShapes:t,newSelectedShape:i&&W(U(i).map(e=>r.get(e.id)??e),e),save:n})},[e]),E=(0,t.useCallback)((e,t=c.current)=>{o({type:`RESET_AND_SAVE`,shapes:e,newSelectedShape:t})},[]),D=(0,t.useCallback)(e=>{let t=new Set(e.map(e=>e.id)),n=c.current;o({type:`REMOVE`,ids:t,newSelectedShape:U(n).map(e=>e.id).find(e=>t.has(e))?void 0:n})},[]),O=(0,t.useCallback)(()=>{o({type:`UNDO`})},[]),k=(0,t.useCallback)(()=>{o({type:`REDO`})},[]),A=(0,t.useCallback)((e,t)=>{o({type:`CLEAR`,shapes:e,clearHistory:t.clearHistory,source:t.source})},[]),j=(0,t.useCallback)((e,t)=>{let n=s.current;E(Yt(n,n.findIndex(t=>t.id===e),n.findIndex(e=>e.id===t)))},[E]),M=(0,t.useCallback)((e,t)=>{let n=[...s.current],r=new Set(e.map(e=>e.id)),i=n.map((e,t)=>r.has(e.id)?t:-1).filter(e=>e>=0);if(i.length!==0)switch(t){case`first`:case`last`:{let e=i.map(e=>n[e]).filter(Boolean),r=n.filter((e,t)=>!i.includes(t));E(t===`first`?[...e,...r]:[...r,...e]);break}case`backward`:{let e=[...n],t=i.sort((e,t)=>t-e).map(e=>n[e].id);for(let n of t){let t=e.findIndex(e=>e.id===n);if(t<e.length-1){let n=t+1;r.has(e[n].id)||(e=Yt(e,t,n))}}E(e);break}case`forward`:{let e=[...n],t=i.sort((e,t)=>e-t).map(e=>n[e].id);for(let n of t){let t=e.findIndex(e=>e.id===n);if(t>0){let n=t-1;r.has(e[n].id)||(e=Yt(e,t,n))}}E(e);break}}},[E]),ee=(0,t.useCallback)((t,n,r,i)=>{let a=new Set(n.map(e=>e.id)),o=i===`rotateClockwise`||i===`rotateCounterclockwise`?s.current.map(t=>a.has(t.id)?Hn(In(t,i===`rotateClockwise`?Math.PI/2:-Math.PI/2,r),e):t):zn(t,s.current,n,r,i,e);E(o,W(o.filter(e=>a.has(e.id)),e))},[e,E]),P=(0,t.useCallback)(t=>{let n=new Set(t.map(e=>e.id)),r=s.current.map(e=>n.has(e.id)?He(`visible`,e.visible===!1,e):e);E(r,W(r.filter(e=>U(c.current)?.map(e=>e.id).includes(e.id)),e))},[E,e]),F=(0,t.useCallback)(t=>{let n=new Set(t.map(e=>e.id)),r=s.current.map(e=>n.has(e.id)?He(`locked`,!e.locked,e):e);E(r,W(r.filter(e=>U(c.current)?.map(e=>e.id).includes(e.id)),e))},[E,e]),I=(0,t.useCallback)((e,t)=>{l.current.hasOwnProperty(e)&&(l.current[e]=[...l.current[e],t])},[]),L=(0,t.useCallback)((e,t)=>{if(l.current.hasOwnProperty(e))if(t){let n=l.current[e].indexOf(t);l.current[e]=[...l.current[e].slice(0,n),...l.current[e].slice(n+1)]}else l.current[e]=[]},[]);(0,t.useEffect)(()=>{let e=a.history.states[a.history.cursor],t=Kt(e.shapes,n,r);for(let n of l.current.dataChanged)n(t,e.source)},[n,r,a.history]),(0,t.useEffect)(()=>{let t=s.current.map(t=>Hn(t,e)),n=c.current;o({type:`REFRESH_ALL`,shapes:t,newSelectedShape:n===void 0?void 0:W(U(n).map(t=>Hn(t,e)),e)})},[e]);let te=(0,t.useCallback)((t,n)=>{d(r=>{let a=[r?.frame[0]??[n[0],n[1]],[n[0],n[1]]],o=s.current.filter(e=>e.locked?!1:kr(t,e,a)),c=W(o,e);return g(i?W(Te(r?.oldSelection,o),e):c),{oldSelection:r?.oldSelection,frame:a}})},[e,i,g]);return{registerEvent:I,unregisterEvent:L,shapes:a.shapes,shapesRef:s,selectedShape:a.selectedShape,hoveredShape:f,selectionFrame:u,setSelectionFrame:d,copiedShape:m,setCopiedShape:h,refreshSelectedShapes:te,addShapes:x,duplicateShapes:S,addPictureShape:w,moveShapes:M,swapShapes:j,saveShapes:b,setSelectedShape:g,refreshHoveredShape:C,toggleShapeVisibility:P,toggleShapeLock:F,removeShape:D,updateShape:T,transformShape:ee,backwardShape:O,forwardShape:k,clearShapes:A,canGoBackward:_,canGoForward:v,canClear:y}},qr=(e,t)=>Math.abs(e-t.startDiff)>30,Jr=(e,t)=>Math.abs(L(e,t.startCenter))>10,Yr=e=>{let t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];return{diff:L(t,n),center:te(t,n)}},Xr=({canvasBoundingRect:e,canvasSize:t,size:n,startDiff:r,startZoom:i,startCenter:a,startOffset:o,currentDiff:s,currentCenter:c,isMoving:l,isZooming:u})=>{let d=u?le(s/r*i,K[0],K[K.length-1]):i;return Me({size:n,canvasSize:t,currentOffset:l?[o[0]+(c[0]-a[0])*(t.width/e.width)/t.scaleRatio/i,o[1]+(c[1]-a[1])*(t.height/e.height)/t.scaleRatio/i]:[o[0],o[1]],currentZoom:i,zoom:d,centerPoint:[(c[0]-e.left)/t.scaleRatio,(c[1]-e.top)/t.scaleRatio]})},Zr=({canvasElt:e,canvasTransformation:n,canvasSize:r,size:i,setCanvasTransformation:a})=>{let o=(0,t.useRef)([]),[s,c]=(0,t.useState)(o.current.length>0),l=(0,t.useRef)(null),u=(0,t.useRef)(n);u.current=n;let d=(0,t.useCallback)(({startDiff:t,startZoom:n,startCenter:o,startOffset:s,currentDiff:c,currentCenter:l,isMoving:u,isZooming:d})=>{!e||!c||!t||a(Xr({canvasBoundingRect:e.getBoundingClientRect(),canvasSize:r,size:i,startDiff:t,startZoom:n,startCenter:o,startOffset:s,currentDiff:c,currentCenter:l,isMoving:u,isZooming:d}))},[e,r,i,a]),f=e=>{if(o.current=[...o.current,e],c(o.current.length>0),o.current.length===2){e.stopPropagation();let{diff:t,center:n}=Yr(o.current);l.current={startDiff:t,startCenter:n,startZoom:u.current.zoom,startOffset:u.current.offset,isMoving:!1,isZooming:!1}}},p=e=>{let t=o.current.findIndex(t=>t.pointerId===e.pointerId);if(t>-1&&(o.current[t]=e),o.current.length===2&&l.current){let{diff:e,center:t}=Yr(o.current),n=l.current.isZooming||qr(e,l.current),r=l.current.isMoving||n||Jr(t,l.current);l.current={...l.current,isMoving:r,isZooming:n},d({...l.current,currentDiff:e,currentCenter:t})}},m=e=>{o.current=o.current.filter(t=>t.pointerId!==e.pointerId),c(o.current.length>0)};T(e,`pointerdown`,f);let h=s?document:null;T(h,`pointermove`,p),T(h,`pointerup`,m),T(h,`pointerout`,m),T(h,`pointercancel`,m),T(h,`pointerleave`,m)},Qr={offset:[0,0],zoom:1},$r=({canvasSize:e,size:n,zoomEnabled:r,canvasElt:i})=>{let[a,o]=(0,t.useState)(Qr),s=(0,t.useRef)(0),c=(0,t.useCallback)(t=>{o(({zoom:r})=>je({zoom:r,size:n,canvasSize:e,newOffset:t}))},[e,n]),l=(0,t.useCallback)(t=>{o(({offset:r,zoom:i})=>Ne({size:n,canvasSize:e,currentOffset:r,currentZoom:i,action:t}))},[e,n]);Zr({canvasElt:i,canvasTransformation:a,canvasSize:e,size:n,setCanvasTransformation:o});let u=(0,t.useCallback)(()=>{o(Qr)},[]);return(0,t.useEffect)(()=>{if(!r||!i)return;let t=t=>{let r=t.ctrlKey,{deltaX:a,deltaY:c}=Be(t,t.timeStamp-s.current);if(s.current=t.timeStamp,r){t.preventDefault();let r=mr(t,i,e);o(({offset:t,zoom:i})=>Pe({size:n,canvasSize:e,currentOffset:t,currentZoom:i,delta:c,centerPoint:r}));return}let[l,u]=t.shiftKey?[c,a]:[a,c];o(({offset:r,zoom:i})=>{let a=je({zoom:i,size:n,canvasSize:e,newOffset:[r[0]-l/i,r[1]-u/i]});return(a.offset[0]!==r[0]||a.offset[1]!==r[1])&&t.preventDefault(),a})};return i.addEventListener(`wheel`,t,{passive:!1}),()=>{i.removeEventListener(`wheel`,t)}},[i,n,e,r]),{setCanvasTransformation:o,setCanvasOffset:c,setCanvasZoom:l,resetZoom:u,canvasTransformation:a}},ei=({width:e=1e3,height:n=600,shapes:r,mode:i=`editor`,disabled:a=!1,options:o=g}={})=>{let{layersManipulation:s,brushAlgo:c,isBrushShapeDoneOnMouseUp:l,debug:u,grid:d,canGrow:f,canShrink:p,withExport:m,withLoadAndSave:h,withUploadPicture:_,withUrlPicture:v,withSkeleton:y,withFrameSelection:x,withContextMenu:S,clearCallback:C,availableTools:w,canvasSelectionPadding:T,size:E,canZoom:D}={...g,...o},O=i!==`viewer`,k=S&&O&&!a,A=(0,t.useRef)(null),j=(0,t.useRef)(null),M=(0,t.useRef)(!1),N=(0,t.useCallback)(e=>{A.current=e},[]),[ee,P]=(0,t.useState)(void 0),[F,I]=(0,t.useState)(b),[L,te]=(0,t.useState)({mode:`default`}),[R,ne]=(0,t.useState)(d),[z,re]=(0,t.useState)({realWidth:e,realHeight:n,width:e,height:n,scaleRatio:1}),ie=D===`always`&&!a,{canvasTransformation:ae,setCanvasTransformation:B,setCanvasOffset:oe,setCanvasZoom:se,resetZoom:ce}=$r({canvasSize:z,size:E,canvasElt:j.current,zoomEnabled:ie}),{offset:V,zoom:le}=ae,H=(0,t.useMemo)(()=>({brushAlgo:c,isBrushShapeDoneOnMouseUp:l,debug:u,canvasSize:{realWidth:z.realWidth,realHeight:z.realHeight,width:z.width,height:z.height,scaleRatioWithNoZoom:z.scaleRatio,scaleRatio:z.scaleRatio*le},size:E,canvasOffset:V,canvasZoom:le,gridGap:R,selectionPadding:T,features:{edition:O&&!a,zoom:ie}}),[T,R,c,l,u,le,V,z,E,a,ie,O]),[ue,de]=(0,t.useState)(w),{isInsideComponent:fe,isInsideCanvas:pe}=Ur({settings:H,componentRef:A,canvasRef:j}),[me,he]=(0,t.useState)(!1),[ge,_e]=(0,t.useState)(!1),[ve,ye]=(0,t.useState)(!1),{registerEvent:be,unregisterEvent:U,shapes:xe,shapesRef:Se,selectedShape:Ce,selectionFrame:we,hoveredShape:Te,copiedShape:Ee,setCopiedShape:De,addShapes:G,addPictureShape:Oe,moveShapes:ke,swapShapes:K,setSelectedShape:Ae,setSelectionFrame:Me,refreshSelectedShapes:Ne,refreshHoveredShape:Pe,duplicateShapes:Fe,removeShape:Ie,updateShape:Le,backwardShape:Re,forwardShape:ze,clearShapes:Be,saveShapes:Ve,toggleShapeVisibility:He,toggleShapeLock:Ue,transformShape:We,canGoBackward:Ge,canGoForward:Ke,canClear:qe}=Kr(H,e,n,me),Je=(0,t.useCallback)(e=>{Ae(void 0),I(e)},[Ae]),[Ye,Xe]=(0,t.useState)([0,0]),Ze=L.mode===`preview`;(0,t.useEffect)(()=>{if(Ze)return()=>te(e=>e.mode===`preview`?{mode:`default`}:e)},[Ce?.id,Ze]);let Qe=L.mode===`selectionFrame`;(0,t.useEffect)(()=>{if(Qe)return()=>Xe([0,0])},[Qe]),(0,t.useEffect)(()=>{if(Ye[0]!==0||Ye[1]!==0){let e=setInterval(()=>{B(({offset:e,zoom:t})=>je({zoom:t,size:E,canvasSize:z,newOffset:[e[0]-Ye[0],e[1]-Ye[1]]}))},20);return()=>clearInterval(e)}},[Ye[0],Ye[1],B,E,z]);let $e=(0,t.useCallback)((e,t)=>{Be(e,t),Je(b),B({offset:[0,0],zoom:1})},[Je,Be,B]),et=(0,t.useCallback)(e=>{Ae(t=>(t?.id!==e.map(e=>e.id).join(`-`)&&I(b),W(e,H)))},[Ae,H]),tt=(0,t.useCallback)(e=>{G(e),et(e)},[G,et]),nt=(0,t.useCallback)(()=>{et(Se.current.filter(e=>!e.locked))},[et,Se]),rt=(0,t.useCallback)(e=>W(e,H),[H]),it=(0,t.useCallback)(e=>Gn(e,H),[H]),at=(0,t.useCallback)(e=>Hn(e,H),[H]),ot=(0,t.useCallback)(()=>{let t=on(Se.current,e,n);if(!t)throw Error(`L'encodage a échoué`);$t(t,`drawing.json`)},[Se,e,n]),st=(0,t.useCallback)(e=>{$t(an({shapes:Se.current,settings:H,view:e}),`drawing.png`)},[Se,H]),ct=(0,t.useCallback)(e=>an({shapes:Se.current,settings:H,view:e}),[Se,H]),lt=(0,t.useCallback)(()=>Kt(Se.current,e,n),[Se,e,n]),ut=(0,t.useCallback)(async(e,t)=>{$e(await cn(e,H),t)},[$e,H]),dt=(0,t.useRef)(ut);dt.current=ut;let ft=(0,t.useCallback)((e=[],t=!0)=>{dt.current?.(e,{clearHistory:t,source:`remote`})},[]);(0,t.useEffect)(()=>{M.current||(M.current=!0,r&&dt.current?.(r,{clearHistory:!0,source:`remote`}))},[r]);let pt=(0,t.useCallback)(async e=>{await ut((await sn(e)).shapes??[],{clearHistory:!0,source:`remote`})},[ut]),mt=(0,t.useCallback)(()=>{typeof C==`string`?C===`defaultShapes`&&r!==void 0?ut(r,{clearHistory:!1,source:`user`}):$e([],{clearHistory:!1,source:`user`}):ut(C(),{clearHistory:!1,source:`user`})},[$e,ut,r,C]),ht=(0,t.useCallback)((e,t)=>{Le([e.type===`curve`?Tt(e,t,H):gt(e,t,H)],!0)},[H,Le]);(0,t.useEffect)(()=>{de(w)},[w]);let _t={canvas:j,editor:A,setEditor:N};return{annotationsProps:{style:{userSelect:`none`,touchAction:`none`,transformOrigin:`left top`,transform:`scale(var(--react-paint-canvas-zoom)) translate(calc(var(--react-paint-canvas-offset-x) * 100% / var(--react-paint-app-canvaswidth)), calc(var(--react-paint-canvas-offset-y) * 100% / var(--react-paint-app-canvasheight)))`,"--react-paint-canvas-zoom":H.canvasZoom,"--react-paint-canvas-offset-x":H.canvasOffset[0],"--react-paint-canvas-offset-y":H.canvasOffset[1],"--react-paint-app-canvaswidth":e,"--react-paint-app-canvasheight":n}},editorProps:{shapes:xe,addPictureShape:Oe,moveShapes:ke,swapShapes:K,toggleShapeVisibility:He,toggleShapeLock:Ue,duplicateShapes:Fe,canGoBackward:Ge,canGoForward:Ke,canClear:qe,selectedShape:Ce,copiedShape:Ee,setCopiedShape:De,pasteShapes:tt,saveShapes:Ve,removeShape:Ie,updateShape:Le,backwardShape:Re,forwardShape:ze,removeShapePoint:ht,transformShape:We,refs:_t,width:e,height:n,selectTool:Je,selectShapes:et,selectAllShapes:nt,activeTool:F,setActiveTool:I,setAvailableTools:de,isEditMode:O,availableTools:ue,gridGap:R,setGridGap:ne,loadFile:pt,exportPicture:st,exportData:ot,clearCanvas:mt,selectionMode:L,setSelectionMode:te,settings:H,setCanvasZoom:se,resetZoom:ce,buildShapesGroup:rt,copyShapes:it,refreshShape:at,calculateTextFontSize:Cn,canvas:{canGrow:f,canShrink:p,layersManipulation:s,withExport:m,withLoadAndSave:h,withUploadPicture:_,withUrlPicture:v,withContextMenu:k}},canvasProps:{shapes:xe,selectedShape:Ce,selectionFrame:we,hoveredShape:Te,copiedShape:Ee,pasteShapes:tt,setCopiedShape:De,addShape:G,setSelectedShape:Ae,setSelectionFrame:Me,refreshSelectedShapes:Ne,refreshHoveredShape:Pe,removeShape:Ie,updateShape:Le,duplicateShapes:Fe,backwardShape:Re,forwardShape:ze,saveShapes:Ve,refs:_t,width:e,height:n,settings:H,setCanvasSize:re,setCanvasOffset:oe,setCanvasZoom:se,resetZoom:ce,selectShapes:et,selectAllShapes:nt,activeTool:F,setActiveTool:I,isInsideComponent:fe,isInsideCanvas:pe,isEditMode:O,canvas:{withSkeleton:y,withFrameSelection:x,withContextMenu:k,canGrow:f,canShrink:p},canvasOffsetStartData:ee,setCanvasOffsetStartData:P,selectionMode:L,setSelectionMode:te,setCanvasMoveAcceleration:Xe,isShiftPressed:me,isAltPressed:ge,isSpacePressed:ve,setShiftPressed:he,setAltPressed:_e,setIsSpacePressed:ye},registerEvent:be,unregisterEvent:U,resetCanvas:ft,resetZoom:ce,getCurrentImage:ct,getCurrentData:lt,setCanvasOffset:oe,setCanvasZoom:se}},ti=({options:e,className:r,style:i,canvasProps:a})=>{let{shapes:o,selectedShape:s,selectionFrame:c,hoveredShape:l,addShape:u,setSelectedShape:d,selectAllShapes:f,setSelectionFrame:p,refreshSelectedShapes:m,refreshHoveredShape:h,duplicateShapes:g,removeShape:y,updateShape:b,backwardShape:x,forwardShape:S,saveShapes:C,refs:w,width:T,height:E,settings:D,setCanvasSize:O,setCanvasOffset:k,pasteShapes:A,activeTool:j,setActiveTool:M,isInsideComponent:N,isInsideCanvas:ee,isEditMode:P,canvas:{withSkeleton:F,withFrameSelection:I,withContextMenu:L,canGrow:te,canShrink:R},canvasOffsetStartData:ne,setCanvasOffsetStartData:z,selectionMode:re,setSelectionMode:ie,setCanvasMoveAcceleration:ae,isShiftPressed:B,isAltPressed:oe,isSpacePressed:se,copiedShape:ce,setCopiedShape:V,setShiftPressed:le,setAltPressed:H,setCanvasZoom:ue,resetZoom:de,setIsSpacePressed:fe}=a,{canvasBackgroundColor:pe,canvasSelectionColor:me,canvasSelectionWidth:he}={..._,...e},ge=(0,t.useRef)(null),_e=(0,t.useCallback)(e=>{O({realWidth:T,realHeight:E,width:e,height:E*e/T,scaleRatio:e/T})},[T,E,O]);Vr({isInsideComponent:N,isInsideCanvas:ee,isEditingText:re.mode===`textedition`,settings:D,selectedShape:s,copiedShape:ce,setCopiedShape:V,selectAllShapes:f,setSelectedShape:d,removeShape:y,pasteShapes:A,updateShapes:b,backwardShape:x,forwardShape:S,setShiftPressed:le,setAltPressed:H,setActiveTool:M,setSelectionMode:ie,setSelectionFrame:p,setCanvasZoom:ue,resetZoom:de,setIsSpacePressed:fe}),Hr({element:ge,onResized:_e});let ve=(0,t.useMemo)(()=>({shapes:o,settings:D,selectedShape:s,hoveredShape:l,selectionFrame:c,selectionMode:re,activeTool:j,canvasOffsetStartData:ne,isInsideComponent:N,isInsideCanvas:ee,isShiftPressed:B,isAltPressed:oe,isSpacePressed:se,selectionColor:me,selectionWidth:he,isEditMode:P,canGrow:te,withFrameSelection:I,withSkeleton:F,withContextMenu:L,setSelectedShape:d,setSelectionFrame:p,setSelectionMode:ie,setActiveTool:M,setCanvasOffsetStartData:z,setCanvasOffset:k,setCanvasMoveAcceleration:ae,addShapes:u,updateSingleShape:b,duplicateShapes:g,saveShapes:C,refreshHoveredShape:h,refreshSelectedShapes:m}),[o,D,s,l,c,re,j,ne,N,ee,B,oe,se,me,he,P,te,I,F,L,d,p,ie,M,z,k,ae,u,b,g,C,h,m]);return(0,n.jsx)(`div`,{ref:ge,className:`react-paint-app-row${r?` ${r}`:``}`,"data-grow":te,"data-shrink":R,style:{"--react-paint-app-row-width":D.canvasSize.width,"--react-paint-app-canvaswidth":T,"--react-paint-app-canvasheight":E,"--react-paint-app-row-aspectratio":`calc(${D.canvasSize.width} / ${D.canvasSize.height})`,"--react-paint-app-canvas-bg":pe,...i},children:(0,n.jsx)(v.Provider,{value:ve,children:(0,n.jsx)(zr,{ref:w.canvas})})})},X=[`transparent`,`black`,`white`,`red`,`green`,`blue`,`yellow`],ni=[0,1,2],ri=[0,1,2,3],ii=[`arial`,`serif`,`monospace`],ai=`serif`,oi={LOADING:2,PANEL:3,SNACKBAR:4},si=({isLoading:e=!1})=>{let[r,i]=(0,t.useState)(`hidden`);return(0,t.useEffect)(()=>{if(e)i(`visible`);else{i(`fadeOut`);let e=setTimeout(()=>i(`hidden`),300);return()=>{clearTimeout(e)}}},[e]),r===`hidden`?null:(0,n.jsx)(`div`,{className:`react-paint-editor-loading`,"data-loading":r,style:{"--react-paint-editor-loading-zindex":oi.LOADING,"--react-paint-editor-loading-transition-duration":`300ms`},children:(0,n.jsxs)(`div`,{className:`react-paint-editor-loader`,children:[(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{})]})})},ci={type:`infos`,duration:4e3},li=({type:e,text:r,duration:i})=>{let[a,o]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{let e=setTimeout(()=>{o(!0)},100),t=setTimeout(()=>{o(!1)},i-500-100);return()=>{clearTimeout(e),clearTimeout(t)}},[i]),(0,n.jsx)(`div`,{className:`react-paint-editor-snackbar`,"data-is-shown":+a,"data-type":e,style:{"--react-paint-editor-panel-transition-duration":`500ms`},children:r})},ui=({snackbarList:e})=>(0,n.jsx)(`div`,{className:`react-paint-editor-snackbar-container`,style:{"--react-paint-editor-snackbar-zindex":oi.SNACKBAR},children:e.map(e=>(0,n.jsx)(li,{...e},e.id))}),di=t.default.forwardRef((e,r)=>{let{hidden:i=!1,disabled:a=!1,selected:o=!1,icon:s,children:c,className:l=``,title:u,onClick:d,...f}=e,p=a?-1:0,m=(0,t.useRef)(null);(0,t.useImperativeHandle)(r,()=>m.current);let h=e=>{e.key===` `&&(e.preventDefault(),e.stopPropagation())},g=e=>{e.preventDefault(),e.stopPropagation(),e.key===` `&&m.current?.click()};return(0,n.jsxs)(`label`,{className:`react-paint-editor-button ${l}`,title:u,onClick:d,"data-disabled":+a,"data-selected":+o,"data-hidden":+i,tabIndex:p,onKeyDown:h,onKeyUp:g,children:[(0,n.jsx)(`input`,{ref:m,disabled:a,...f}),(0,n.jsxs)(`span`,{className:`react-paint-editor-button-content`,children:[c&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-children`,children:c}),s&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-icon`,dangerouslySetInnerHTML:{__html:s}})]})]})}),Z=t.default.forwardRef((e,t)=>{if(e.type===`file`||e.type===`color`)return(0,n.jsx)(di,{...e,ref:t});let{hidden:r=!1,disabled:i=!1,selected:a=!1,icon:o,children:s,type:c=`button`,className:l=``,...u}=e;return(0,n.jsx)(`button`,{className:`react-paint-editor-button ${l}`,ref:t,disabled:i,"data-disabled":+i,"data-selected":+a,"data-hidden":+r,type:c,...u,children:(0,n.jsxs)(`span`,{className:`react-paint-editor-button-content`,children:[s&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-children`,children:s}),o&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-icon`,dangerouslySetInnerHTML:{__html:o}})]})})}),fi=({children:e,title:t=``,className:r=``,position:i,fitContainer:a=!1,alignment:o,style:s,...c})=>(0,n.jsxs)(`div`,{className:`react-paint-editor-panel ${r}`,"data-fitcontainer":a,"data-position":i??`unset`,"data-alignment":o??`unset`,style:{...s,"--react-paint-editor-panel-zindex":oi.PANEL},...c,children:[t&&(0,n.jsx)(`h3`,{className:`react-paint-editor-panel-title`,children:t}),e]}),pi=`<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>`,mi=`<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>`,hi=`<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>`,gi=`<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>`,_i=`<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>`,vi=`<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>`,yi=`<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>`,bi=`<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>`,xi=`<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>`,Si=`<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>`,Ci=`<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>`,wi=`<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>`,Ti=`<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>`,Ei=`<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>`,Di=`<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>`,Oi=`<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>`,ki=`<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>`,Ai=`<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>`,ji=`<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>`,Mi=`<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>`,Ni=`<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>`,Pi=`<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>`,Fi=`<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>`,Ii=`<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>`,Li=`<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>`,Ri=`<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>`,zi=`<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>`,Bi=`<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>`,Vi=`<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>`,Hi=`<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>`,Ui=`<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>`,Wi=`<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>`,Gi=({disabled:e=!1,ref:n,shape:r,layoutDragging:i,setLayoutDragging:a,handleSelect:o,onSwapShapes:s})=>{let[c,l]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{i||l(!1)},[i]),(0,t.useEffect)(()=>{let t=n.current;if(!t)return;let c=()=>{a(void 0)},u=e=>(e.preventDefault&&e.preventDefault(),!1),d=e=>{o([r]),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`draggableShapeId`,r.id),a(r.id))},f=()=>{i!==r.id&&l(!0)},p=()=>{l(!1)},m=e=>(e.stopPropagation(),e.dataTransfer&&s(e.dataTransfer.getData(`draggableShapeId`),r.id),!1);return e||(t.addEventListener(`dragstart`,d),t.addEventListener(`dragend`,c),t.addEventListener(`dragover`,u),t.addEventListener(`dragenter`,f),t.addEventListener(`dragleave`,p),t.addEventListener(`drop`,m)),()=>{e||(t.removeEventListener(`dragstart`,d),t.removeEventListener(`dragend`,c),t.removeEventListener(`dragover`,u),t.removeEventListener(`dragenter`,f),t.removeEventListener(`dragleave`,p),t.removeEventListener(`drop`,m))}},[e,n,r,a,o,s,i]),{isOver:c}},Ki=e=>{switch(e){case`brush`:return pi;case`line`:return Oi;case`polygon`:return _i;case`curve`:return Li;case`rect`:return mi;case`square`:return mi;case`circle`:return gi;case`ellipse`:return gi;case`text`:return Di;case`picture`:return Ei;case`group`:return Wi;case`triangle`:return``}},qi=({disabled:e=!1,shape:r,selected:i,layoutDragging:a,toggleShapeVisibility:o,toggleShapeLock:s,setLayoutDragging:c,handleRemove:l,handleSelect:u,onSwapShapes:d})=>{let f=(0,t.useRef)(null),p=t=>{e||(t.preventDefault(),t.stopPropagation(),l([r]))},m=t=>{e||(t.preventDefault(),u([r]))},h=t=>{e||(t.preventDefault(),t.stopPropagation(),o([r]))},g=t=>{e||(t.preventDefault(),t.stopPropagation(),s([r]))},{isOver:_}=Gi({disabled:e,ref:f,shape:r,layoutDragging:a,setLayoutDragging:c,handleSelect:u,onSwapShapes:d});return(0,n.jsxs)(`div`,{className:`react-paint-editor-layout`,"data-disabled":+e,draggable:!e,"data-is-dragging":+(a===r.id),"data-is-over":+_,onClick:m,"data-selected":+i,ref:f,tabIndex:-1,children:[(0,n.jsx)(`span`,{dangerouslySetInnerHTML:{__html:Ki(r.type)}}),(0,n.jsx)(`span`,{children:r.id}),(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-separator`}),(0,n.jsx)(Z,{className:`react-paint-editor-layouts-visible-button`,title:r.visible?`Hide`:`Show`,"data-visible":r.visible!==!1,disabled:e,selected:i,onClick:h,icon:r.visible===!1?Ni:Mi}),(0,n.jsx)(Z,{className:`react-paint-editor-layouts-locked-button`,title:r.locked?`Locked`:`Unlocked`,"data-locked":!!r.locked,disabled:e,selected:i,onClick:g,icon:r.locked?Pi:Fi}),(0,n.jsx)(Z,{className:`react-paint-editor-layouts-remove-button`,title:`Remove`,disabled:e,onClick:p,icon:vi})]})},Ji=({gridFormat:e,setGridFormat:r,settings:i,shapes:a,removeShape:o,toggleShapeVisibility:s,toggleShapeLock:c,selectedShapes:l,swapShapes:u,selectShapes:d,isLayoutPanelShown:f})=>{let[p,m]=(0,t.useState)(void 0),h=!i.features.edition;return f?(0,n.jsx)(fi,{alignment:`right`,className:`react-paint-editor-layouts-panel`,position:`bottom`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-panel-content`,children:(0,n.jsxs)(`div`,{className:`react-paint-editor-layouts-scrolling-content`,children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-layouts-row`,children:[(0,n.jsx)(`span`,{className:`react-paint-editor-layouts-subtitle`,children:`Grid`}),(0,n.jsx)(Z,{icon:Ii,className:`react-paint-editor-layouts-grid-button`,selected:e===`none`,disabled:h,onClick:()=>r(`none`)}),[`small`,`medium`,`large`].map(t=>(0,n.jsx)(Z,{className:`react-paint-editor-layouts-grid-button`,selected:e===t,disabled:h,onClick:()=>r(t),children:t.charAt(0).toUpperCase()},t))]}),(0,n.jsx)(`hr`,{}),(0,n.jsx)(`div`,{className:`react-paint-editor-layouts`,children:a.length===0?(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-placeholder`,children:`No layer yet`}):a.map(e=>(0,n.jsx)(qi,{shape:e,disabled:h,layoutDragging:p,setLayoutDragging:m,selected:U(l).some(t=>t.id===e.id)??!1,handleSelect:d,handleRemove:o,onSwapShapes:u,toggleShapeVisibility:s,toggleShapeLock:c},e.id))})]})})}):null},Yi=({children:e,onClose:t,position:r=`center`,title:i,className:a=``})=>(0,n.jsxs)(`div`,{className:`react-paint-editor-modal`,"data-position":r,style:{"--react-paint-editor-modal-zindex":oi.PANEL},role:`dialog`,"aria-modal":`true`,"aria-labelledby":i,children:[(0,n.jsx)(`div`,{className:`react-paint-editor-modal-mask`,onClick:t}),(0,n.jsx)(`div`,{className:`react-paint-editor-modal-panel ${a}`,children:e})]}),Xi=({selectedSettings:e,setSelectedSettings:r,title:i=`Choisissez une couleur`,mode:a=`fill`,disabled:o=!1,values:s,field:c,value:l=``,valueChanged:u})=>{let[d]=(0,t.useState)(V(`settings_`)),f=e=>{let t=+e.target.value;u(c,Number.isNaN(t)?e.target.value:t)},p=e=>{u(c,e)},m=()=>{r(e=>e===d?void 0:d)},h=e===d;return s.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Z,{selected:h,title:i,disabled:o,onClick:m,icon:l===`transparent`?a===`fill`?Hi:Vi:void 0,children:l!==`transparent`&&(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-color`,"data-mode":a,style:{"--react-paint-editor-colorfield-color-value":l}})}),h&&(0,n.jsx)(fi,{title:i,alignment:`left`,position:`bottom`,children:(0,n.jsxs)(`div`,{className:`react-paint-editor-colorfield-wrapper`,children:[s.map(e=>(0,n.jsx)(Z,{title:e,selected:e===l,color:e,icon:e===`transparent`?a===`fill`?`<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>`:`<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>`:void 0,onClick:()=>p(e),children:e!==`transparent`&&(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-color`,color:e,"data-mode":a,style:{"--react-paint-editor-colorfield-color-value":e}})},e)),(0,n.jsx)(Z,{type:`color`,title:`Custom color`,selected:l!==``&&!s.includes(l),value:l,onChange:f,children:(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-customcolor`,style:{"--react-paint-editor-colorfield-color-value":s.includes(l)?`var(--react-paint-editor-app-font-color)`:l},children:(0,n.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},Zi=({disabled:e=!1,selectedShape:t,removeShape:r})=>{let i=()=>{r(U(t))};return(0,n.jsx)(Z,{title:`Delete`,disabled:e,"data-disabled":+e,onClick:i,icon:vi})},Qi=({CustomOption:e,selectedSettings:r,setSelectedSettings:i,title:a=`Choisissez l'option`,disabled:o=!1,field:s,icon:c,values:l,defaultValue:u,valueChanged:d})=>{let[f]=(0,t.useState)(V(`settings_`)),p=e=>{d(s,e)},m=()=>{i(e=>e===f?void 0:f)},h=r===f;return l.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Z,{selected:h,title:a,icon:c,disabled:o,onClick:m}),h&&(0,n.jsx)(fi,{title:a,alignment:`left`,fitContainer:!0,position:`bottom`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-selectfield-wrapper`,children:l.map(t=>(0,n.jsx)(Z,{title:`${t}`,onClick:()=>p(t),selected:u===t,style:{"--react-paint-editor-button-padding":`16px`},children:(0,n.jsx)(e,{children:t})},t))})})]}):null},$i=({children:e})=>(0,n.jsx)(`span`,{className:`react-paint-editor-fontfamily-option`,style:{"--react-paint-editor-fontfamily-family":e},children:e}),ea=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(Qi,{selectedSettings:e,setSelectedSettings:t,CustomOption:$i,title:`Police`,icon:zi,disabled:r,field:`fontFamily`,values:i,defaultValue:a,valueChanged:o}):null,ta=({disabled:e,toggleLayoutPanel:t})=>(0,n.jsx)(Z,{title:`Toggle layers panel`,disabled:e,onClick:t,icon:xi,className:`react-paint-editor-layout-button`}),na=({children:e})=>(0,n.jsxs)(`span`,{className:`react-paint-editor-linearrow-option`,"data-type":e,children:[(0,n.jsx)(`span`,{className:`react-paint-editor-linearrow-left`}),(0,n.jsx)(`span`,{className:`react-paint-editor-linearrow-right`})]}),ra=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(Qi,{selectedSettings:e,setSelectedSettings:t,CustomOption:na,title:`Flèches`,icon:Bi,disabled:r,field:`lineArrow`,values:i,defaultValue:a,valueChanged:o}):null,ia=({children:e})=>(0,n.jsxs)(`span`,{className:`react-paint-editor-linetype-option`,"data-type":e,children:[(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{})]}),aa=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(Qi,{selectedSettings:e,setSelectedSettings:t,CustomOption:ia,icon:Ri,title:`Type de traits`,disabled:r,field:`lineDash`,values:i,defaultValue:a,valueChanged:o}):null,oa=(e,n=500)=>{let r=(0,t.useRef)(null),i=(0,t.useCallback)((...t)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>e(...t),n)},[e,n]);return(0,t.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]),i},sa=({selectedSettings:e,setSelectedSettings:r,title:i=`Choisissez l'intervalle`,icon:a,disabled:o=!1,field:s,value:c,min:l=1,max:u=20,step:d=1,unity:f=``,valueChanged:p,saveShapes:m})=>{let h=c===void 0,g=h?`N/A`:`${Math.round(c)}${f}`,[_]=(0,t.useState)(V(`settings_`)),v=oa(m),y=e=>{let t=+e.target.value;p(s,Number.isNaN(t)?e.target.value:t,!1),v()},b=()=>{r(e=>e===_?void 0:_)},x=e===_;return l===u?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Z,{selected:x,title:i,disabled:o,icon:a,onClick:b}),x&&(0,n.jsx)(fi,{title:i,alignment:`left`,fitContainer:!0,position:`bottom`,children:(0,n.jsx)(`div`,{children:(0,n.jsxs)(`label`,{className:`react-paint-editor-rangefield`,children:[(0,n.jsx)(`input`,{type:`range`,min:l,max:u,step:d,value:c??(u+l)/2,"data-indeterminate":+h,onChange:y}),(0,n.jsx)(`span`,{children:g})]})})})]})},ca=({children:e})=>(0,n.jsx)(`span`,{children:e===0?`Non`:`Oui`}),la=[0,1],ua=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,defaultValue:i,valueChanged:a})=>(0,n.jsx)(Qi,{selectedSettings:e,setSelectedSettings:t,CustomOption:ca,title:`Fermer les points`,icon:_i,disabled:r,field:`closedPoints`,values:la,defaultValue:i,valueChanged:a}),da=({disabled:e=!1,className:t,toggleZoomPanel:r})=>(0,n.jsx)(Z,{title:`Toggle zoom panel`,disabled:e,onClick:r,icon:Ui,className:`${t?` ${t}`:``}`}),fa=({setSelectedSettings:e,disabled:r=!1,field:i,icon:a,values:o,value:s=!1,valueChanged:c})=>{let[l]=(0,t.useState)(V(`settings_`));return o.length===2?(0,n.jsx)(Z,{onClick:()=>{e(e=>e===l?void 0:l),c(i,!s)},selected:s,disabled:r,icon:a}):null},pa=40,ma=({activeTool:e,selectedShape:t,selectedShapeTool:r,disabled:i,selectedSettings:a,setSelectedSettings:o,saveShapes:s,handleShapeStyleChange:c,handleShapeFontFamilyChange:l})=>t?r&&(0,n.jsxs)(n.Fragment,{children:[`strokeColor`in r.settings&&!r.settings.strokeColor.hidden&&(0,n.jsx)(Xi,{selectedSettings:a,setSelectedSettings:o,title:`Couleur du trait`,mode:`stroke`,disabled:i,field:`strokeColor`,value:t.style?.strokeColor,valueChanged:c,values:r.settings.strokeColor.values}),`fillColor`in r.settings&&!r.settings.fillColor.hidden&&(0,n.jsx)(Xi,{selectedSettings:a,setSelectedSettings:o,title:`Couleur de fond`,disabled:i,field:`fillColor`,value:t.style?.fillColor,valueChanged:c,values:r.settings.fillColor.values}),`lineWidth`in r.settings&&!r.settings.lineWidth.hidden&&(0,n.jsx)(sa,{saveShapes:s,selectedSettings:a,setSelectedSettings:o,title:`Epaisseur du trait`,icon:`<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>`,disabled:i,field:`lineWidth`,value:t.style?.lineWidth,valueChanged:c,unity:`px`,min:r.settings.lineWidth.min,max:r.settings.lineWidth.max,step:r.settings.lineWidth.step}),`lineDash`in r.settings&&!r.settings.lineDash.hidden&&(0,n.jsx)(aa,{selectedSettings:a,setSelectedSettings:o,disabled:i,defaultValue:t.style?.lineDash,valueChanged:c,values:r.settings.lineDash.values}),`lineArrow`in r.settings&&!r.settings.lineArrow.hidden&&(0,n.jsx)(ra,{selectedSettings:a,setSelectedSettings:o,disabled:i,defaultValue:t.style?.lineArrow,valueChanged:c,values:r.settings.lineArrow.values}),`closedPoints`in r.settings&&!r.settings.closedPoints.hidden&&(0,n.jsx)(ua,{selectedSettings:a,setSelectedSettings:o,disabled:i,valueChanged:c,defaultValue:t.style?.closedPoints}),`fontFamily`in r.settings&&!r.settings.fontFamily.hidden&&(0,n.jsx)(ea,{selectedSettings:a,setSelectedSettings:o,disabled:i,valueChanged:l,values:r.settings.fontFamily.values,defaultValue:t.style?.fontFamily}),`fontBold`in r.settings&&!r.settings.fontBold.hidden&&(0,n.jsx)(fa,{setSelectedSettings:o,disabled:i,field:`fontBold`,icon:`<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>`,valueChanged:l,values:r.settings.fontBold.values,value:t.style?.fontBold}),`fontItalic`in r.settings&&!r.settings.fontItalic.hidden&&(0,n.jsx)(fa,{setSelectedSettings:o,disabled:i,field:`fontItalic`,icon:`<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>`,valueChanged:l,values:r.settings.fontItalic.values,value:t.style?.fontItalic}),`opacity`in r.settings&&!r.settings.opacity.hidden&&(0,n.jsx)(sa,{saveShapes:s,selectedSettings:a,setSelectedSettings:o,title:`Opacité`,icon:`<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>`,min:r.settings.opacity.min,max:r.settings.opacity.max,step:r.settings.opacity.step,unity:`%`,disabled:i,field:`opacity`,value:t.style?.opacity,valueChanged:c})]}):`settings`in e?(0,n.jsxs)(n.Fragment,{children:[`strokeColor`in e.settings&&!e.settings.strokeColor.hidden&&(0,n.jsx)(Xi,{selectedSettings:a,setSelectedSettings:o,title:`Couleur du trait`,mode:`stroke`,disabled:i,field:`strokeColor`,value:e.settings.strokeColor.default,valueChanged:c,values:e.settings.strokeColor.values}),`fillColor`in e.settings&&!e.settings.fillColor.hidden&&(0,n.jsx)(Xi,{selectedSettings:a,setSelectedSettings:o,title:`Couleur de fond`,disabled:i,field:`fillColor`,value:e.settings.fillColor.default,valueChanged:c,values:e.settings.fillColor.values}),`lineWidth`in e.settings&&!e.settings.lineWidth.hidden&&(0,n.jsx)(sa,{saveShapes:s,selectedSettings:a,setSelectedSettings:o,title:`Epaisseur du trait`,disabled:i,field:`lineWidth`,icon:`<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>`,value:e.settings.lineWidth.default,valueChanged:c,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&&(0,n.jsx)(aa,{selectedSettings:a,setSelectedSettings:o,disabled:i,defaultValue:e.settings.lineDash.default,valueChanged:c,values:e.settings.lineDash.values}),`lineArrow`in e.settings&&!e.settings.lineArrow.hidden&&(0,n.jsx)(ra,{selectedSettings:a,setSelectedSettings:o,disabled:i,defaultValue:e.settings.lineArrow.default,valueChanged:c,values:e.settings.lineArrow.values}),`closedPoints`in e.settings&&!e.settings.closedPoints.hidden&&(0,n.jsx)(ua,{selectedSettings:a,setSelectedSettings:o,disabled:i,valueChanged:c,defaultValue:e.settings?.closedPoints.default}),`fontFamily`in e.settings&&!e.settings.fontFamily.hidden&&(0,n.jsx)(ea,{selectedSettings:a,setSelectedSettings:o,disabled:i,valueChanged:l,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),`fontBold`in e.settings&&!e.settings.fontBold.hidden&&(0,n.jsx)(fa,{setSelectedSettings:o,disabled:i,field:`fontBold`,icon:`<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>`,valueChanged:l,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),`fontItalic`in e.settings&&!e.settings.fontItalic.hidden&&(0,n.jsx)(fa,{setSelectedSettings:o,disabled:i,field:`fontItalic`,icon:`<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>`,valueChanged:l,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),`opacity`in e.settings&&!e.settings.opacity.hidden&&(0,n.jsx)(sa,{saveShapes:s,selectedSettings:a,setSelectedSettings:o,title:`Opacité`,icon:`<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>`,min:e.settings.opacity.min,max:e.settings.opacity.max,step:e.settings.opacity.step,unity:`%`,disabled:i,field:`opacity`,value:e.settings.opacity.default,valueChanged:c})]}):null,ha=({width:e,availableTools:r,updateToolSettings:i,layersManipulation:a=!1,toggleLayoutPanel:o,activeTool:s,saveShapes:c,selectedShape:l,canvas:u,settings:d,updateShape:f,removeShape:p,isZoomPanelShown:m,setIsZoomPanelShown:h,refreshShape:g,calculateTextFontSize:_})=>{let[v,y]=(0,t.useState)(void 0),[b,x]=(0,t.useState)(!1),S=d.size===`infinite`||d.features.zoom,C=!d.features.edition,w=()=>{x(e=>!e)},T=()=>{h(e=>!e)},E=xe(l,r),D=(E?Object.keys(E.settings).length+1:`settings`in s?Object.keys(s.settings).length:0)+ +a+ +S,O=e<D*pa,k=(e,t,n=!0)=>{U(l).length?(f(U(l).map(n=>g(He([`style`,e],t,n))),n),E&&i(E.id,e,t)):i(s.id,e,t)},A=(e,t)=>{U(l).length?(f(U(l).map(n=>{if(n.type!==`text`)return n;let r=u?.getContext(`2d`);if(!r)return n;let i=He([`style`,e],t,n),a=_(r,i.value,i.width,i.style?.fontBold??!1,i.style?.fontItalic??!1,i.style?.fontFamily);return g({...i,fontSize:a,height:a*i.value.length})}),!0),E&&i(E.id,e,t)):i(s.id,e,t)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-settings-bar`,children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-settings-shrinkable`,children:[S&&(0,n.jsx)(da,{className:m?`react-paint-editor-bar-zoom-button-opened`:void 0,toggleZoomPanel:T}),O&&D>2&&(0,n.jsx)(Z,{disabled:C,onClick:w,title:`Toggle settings`,icon:`<svg><path d="M2.5 15.833V14.083H7.667V15.833ZM2.5 5.917V4.167H10.771V5.917ZM9.208 17.5V12.438H10.958V14.083H17.5V15.833H10.958V17.5ZM5.917 12.542V10.875H2.5V9.125H5.917V7.479H7.667V12.542ZM9.208 10.875V9.125H17.5V10.875ZM12.333 7.562V2.5H14.083V4.167H17.5V5.917H14.083V7.562Z"/></svg>`}),l?E&&(0,n.jsxs)(n.Fragment,{children:[!O&&(0,n.jsx)(ma,{saveShapes:c,activeTool:s,selectedShape:l,selectedShapeTool:E,disabled:C,selectedSettings:v,setSelectedSettings:y,handleShapeStyleChange:k,handleShapeFontFamilyChange:A}),s.type===`selection`&&(0,n.jsx)(Zi,{disabled:C,selectedShape:l,removeShape:p})]}):!O&&(0,n.jsx)(ma,{saveShapes:c,activeTool:s,selectedShape:l,selectedShapeTool:E,disabled:C,selectedSettings:v,setSelectedSettings:y,handleShapeStyleChange:k,handleShapeFontFamilyChange:A})]}),(0,n.jsx)(`div`,{className:`react-paint-editor-settings-separator`}),a&&(0,n.jsx)(ta,{disabled:C,toggleLayoutPanel:o})]}),b&&(0,n.jsx)(Yi,{className:`react-paint-editor-settings-modal`,onClose:w,position:`bottom`,title:`Settings`,children:(0,n.jsx)(ma,{saveShapes:c,activeTool:s,selectedShape:l,selectedShapeTool:E,disabled:C,selectedSettings:v,setSelectedSettings:y,handleShapeStyleChange:k,handleShapeFontFamilyChange:A})})]})},Q=`react-paint-`,ga={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0}},_a={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0}},va={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0}},ya={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0}},ba={opacity:{min:0,max:100,step:1,default:100}},xa={strokeColor:{values:X,default:`black`},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:ii,default:ai},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}},Sa={strokeColor:{values:X,default:`black`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:ni,default:0}},Ca={strokeColor:{values:X,default:`black`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0},lineArrow:{values:ri,default:0}},wa={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0},closedPoints:{default:0}},Ta={strokeColor:{values:X,default:`black`},fillColor:{values:X,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:ni,default:0},closedPoints:{default:0}},Ea={type:`picture`,id:`${Q}picture`,icon:Ei,label:`Image`,settings:ba},Da=[{type:`brush`,id:`${Q}brush`,icon:pi,label:`Brosse`,settings:Sa},{type:`line`,id:`${Q}line`,icon:Oi,label:`Ligne`,settings:Ca},{type:`polygon`,id:`${Q}polygon`,icon:_i,label:`Polygone`,settings:wa},{type:`curve`,id:`${Q}curve`,icon:Li,label:`Courbe`,settings:Ta},{type:`rect`,id:`${Q}rect`,icon:mi,label:`Rectangle`,settings:ga},{type:`square`,id:`${Q}square`,icon:mi,label:`Carré`,settings:_a},{type:`circle`,id:`${Q}circle`,icon:gi,label:`Cercle`,settings:va},{type:`ellipse`,id:`${Q}ellipse`,icon:gi,label:`Ellipse`,settings:ya},Ea,{type:`text`,id:`${Q}text`,icon:Di,label:`Texte`,settings:xa}],Oa={id:`${Q}selection`,type:`selection`,icon:ki,label:`Sélection`},ka={id:`${Q}undo`,type:`undo`,icon:yi,label:`Undo`},Aa={id:`${Q}redo`,type:`redo`,icon:bi,label:`Redo`},ja={id:`${Q}clear`,type:`clear`,icon:Si,label:`Clear`},Ma={id:`${Q}export`,type:`export`,icon:wi,label:`Export PNG`},Na={id:`${Q}load`,type:`loadfile`,icon:Ti,label:`Load project`},Pa={id:`${Q}save`,type:`savefile`,icon:Ci,label:`Save project`},Fa={id:`${Q}move`,type:`move`,icon:Ai,label:`Move`},Ia={id:`${Q}upload-picture`,type:`uploadpicture`,icon:Ei,label:`Upload picture`};`${Q}`;var La=(e,t)=>Jt(t.flatMap(t=>{if(typeof t!=`object`)return e.filter(e=>e.type===t);let n=e.filter(e=>t.toolsType.includes(e.type));return n?{...t,toolsType:n}:null})),Ra=({alignment:e,children:t,className:r,style:i,position:a})=>(0,n.jsx)(fi,{alignment:e,position:a,className:r,style:i,children:(0,n.jsx)(`div`,{className:`react-paint-editor-menu`,role:`menu`,children:t})}),za=({disabled:e=!1,withText:r=!1,loadFile:i,type:a,img:o,accept:s})=>{let c=(0,t.useRef)(null);return(0,n.jsx)(Z,{ref:c,type:`file`,onClick:()=>{c.current&&(c.current.value=``)},onChange:e=>{let t=e.target.files?.item(0);t&&i(t)},accept:s,title:a.label??a.type,icon:o,disabled:e,children:r?a.label:void 0})},Ba=(e,t)=>!(e.target instanceof Node)||!t?!1:t.contains(e.target),Va=({trigger:e=`click`,disabled:n=!1,buttonElt:r})=>{let[i,a]=(0,t.useState)(!1),[,o]=(0,t.useTransition)(),s=(0,t.useCallback)(()=>{o(()=>{a(!1)})},[]);return(0,t.useEffect)(()=>{if(!r||n)return;if(i){let t=e=>{Ba(e,r)||o(()=>{a(!1)})},n=()=>{o(()=>{a(!1)})};return e===`hover`?(r.addEventListener(`mouseleave`,n),()=>{r.removeEventListener(`mouseleave`,n)}):(document.addEventListener(`click`,t),()=>{document.removeEventListener(`click`,t)})}let t=()=>{o(()=>{a(!0)})};return e===`hover`?(r.addEventListener(`mouseenter`,t),()=>{r.removeEventListener(`mouseenter`,t)}):(r.addEventListener(`click`,t),()=>{r.removeEventListener(`click`,t)})},[r,i,n,e]),{isOpen:i,trigger:e,closeMenu:s}},$=({type:e,img:t,isActive:r,withText:i=!1,disabled:a=!1,setActive:o})=>(0,n.jsx)(Z,{disabled:a,selected:r,onClick:()=>{o(e)},title:e.label??e.type,icon:t,children:i?e.label:void 0}),Ha=({activeTool:e,withActionsInMenu:r,hasActionToUndo:i=!1,hasActionToRedo:a=!1,hasActionToClear:o=!1,undoAction:s,redoAction:c,clearCanvas:l,disabled:u=!1,withLoadAndSave:d,withExport:f,addPicture:p,loadFile:m,togglePictureUrlModal:h,saveFile:g,toggleExportModal:_,withUploadPicture:v,withUrlPicture:y})=>{let b=(0,t.useRef)(null),{isOpen:x,closeMenu:S}=Va({buttonElt:b.current}),C=e=>async(...t)=>{await e(...t),S()};return r||v||y||d||f?(0,n.jsx)(`div`,{className:`react-paint-editor-toolbox-relative`,children:(0,n.jsxs)(`div`,{ref:b,children:[(0,n.jsx)(Z,{title:`Menu`,disabled:u,icon:ji}),x&&(0,n.jsxs)(Ra,{alignment:`right`,position:`top`,children:[r&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{withText:!0,type:ka,disabled:u||!i,img:ka.icon,isActive:e.id===ka.id,setActive:C(s)}),(0,n.jsx)($,{withText:!0,type:Aa,disabled:u||!a,img:Aa.icon,isActive:e.id===Aa.id,setActive:C(c)}),(0,n.jsx)($,{withText:!0,type:ja,disabled:u||!o,img:ja.icon,isActive:e.id===ja.id,setActive:C(l)}),(v||y||d)&&(0,n.jsx)(`hr`,{})]}),v&&(0,n.jsx)(za,{withText:!0,type:Ia,disabled:u,loadFile:C(p),img:Ia.icon,accept:`image/png, image/gif, image/jpeg, image/svg+xml, image/webp`}),y&&(0,n.jsx)(Z,{disabled:u,selected:!1,onClick:C(h),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`}),(v||y)&&d&&(0,n.jsx)(`hr`,{}),d&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(za,{withText:!0,type:Na,disabled:u,loadFile:C(m),img:Na.icon,accept:`application/JSON`}),(0,n.jsx)($,{withText:!0,disabled:u,type:Pa,img:Pa.icon,isActive:e.id===Pa.id,setActive:C(g)})]}),f&&(0,n.jsx)($,{withText:!0,disabled:u,type:Ma,img:Ma.icon,isActive:e.id===Ma.id,setActive:C(_)})]})]})}):null},Ua=({togglePictureUrlModal:e,addPicture:r})=>{let i=(0,t.useRef)(null);return(0,t.useEffect)(()=>{i.current&&i.current.focus()},[]),(0,n.jsx)(Yi,{className:`react-paint-editor-toolbox-pictureinput-modal`,onClose:e,title:`Add picture from URL`,children:(0,n.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let n=i.current?.value;n&&(await r(n),e())},children:[(0,n.jsxs)(`label`,{children:[`URL\xA0`,(0,n.jsx)(`input`,{type:`text`,ref:i})]}),(0,n.jsx)(Z,{onClick:e,children:`Annuler`}),(0,n.jsx)(Z,{type:`submit`,selected:!0,children:`Ajouter`})]})})},Wa=`Choose export settings`,Ga=({toggleExportModal:e,exportCanvasInFile:t})=>{let r=async n=>{t(n),e()};return(0,n.jsxs)(Yi,{className:`react-paint-editor-toolbox-export-modal`,onClose:e,title:Wa,children:[(0,n.jsx)(`h3`,{children:Wa}),(0,n.jsx)(`hr`,{}),(0,n.jsx)(Z,{onClick:()=>r(`currentZoom`),children:`Exporter la vue actuelle`}),(0,n.jsx)(Z,{onClick:()=>r(`defaultView`),children:`Exporter le canevas par défaut`}),(0,n.jsx)(Z,{onClick:()=>r(`fitToShapes`),children:`Exporter le dessin entier`}),(0,n.jsx)(Z,{selected:!0,onClick:e,children:`Annuler`})]})},Ka=({activeTool:e,group:r,disabled:i=!1,setActiveToolFromId:a})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),[,l]=(0,t.useTransition)(),[u,d]=(0,t.useState)(void 0),f=e=>{d(e),a(e.id)};if((0,t.useEffect)(()=>{if(!s)return;let e=e=>{!Ba(e,o.current)&&c(!1)};return document.addEventListener(`mousedown`,e,{passive:!1}),document.addEventListener(`touchstart`,e,{passive:!1}),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`touchstart`,e)}},[s]),`type`in r)return(0,n.jsx)($,{disabled:i,type:r,img:r.icon,isActive:e.id===r.id,setActive:f});if(!r.toolsType.length)return null;if(r.toolsType?.length===1)return(0,n.jsx)($,{disabled:i,type:r.toolsType[0],img:r.toolsType[0].icon,isActive:e.id===r.toolsType[0].id,setActive:f});let p=r?.toolsType.find(t=>t.type===e.type)!==void 0,m=(u?u.icon:r.toolsType?.[0]?.icon)??r.title;return(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbargroup-relative`,children:[(0,n.jsx)(Z,{selected:p,title:r.title,disabled:i,onClick:()=>{u?a(u.id):r.toolsType?.[0]&&f(r.toolsType[0]),l(()=>{c(!0)})},icon:m}),s&&(0,n.jsx)(fi,{alignment:`center`,position:`top`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-toolbargroup-panel-content`,"data-vertical":+r.vertical,ref:o,children:r.toolsType.map(t=>(0,n.jsx)($,{disabled:i,type:t,img:t.icon,isActive:e.id===t.id,setActive:f},t.id))})})]})},qa=40,Ja=[{title:`brush`,toolsType:[`brush`],vertical:!1},{title:`lines`,toolsType:[`line`,`curve`,`polygon`],vertical:!1},{title:`shapes`,toolsType:[`rect`,`square`,`circle`,`ellipse`],vertical:!1},`text`],Ya=({settings:e,width:r,activeTool:i,hasActionToUndo:a=!1,hasActionToRedo:o=!1,hasActionToClear:s=!1,withLoadAndSave:c,withExport:l,clearCanvas:u,setActiveTool:d,undoAction:f,redoAction:p,addPicture:m,loadFile:h,saveFile:g,exportCanvasInFile:_,availableTools:v,withUrlPicture:y,withUploadPicture:b})=>{let x=La(v,Ja),S=!e.features.edition,C=r<(6+x.length)*qa,w=r<(3+x.length)*qa,T=4*qa,[E,D]=(0,t.useState)(!1),[O,k]=(0,t.useState)(!1),[A,j]=(0,t.useState)(!1),M=()=>{D(e=>!e)},N=()=>{k(!0)},ee=()=>{k(e=>!e)},P=()=>{j(e=>!e)},F=e=>{d(e),D(!1)},I=e=>{F(v.find(t=>t.id===e)??i)},L=v.find(e=>e.type===i.type)!==void 0;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbar-toolbox`,style:{"--react-paint-editor-toolbar-minwidth":`${T}px`},children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbar-shrinkable`,children:[(0,n.jsx)($,{type:Oa,disabled:S,img:Oa.icon,isActive:i.id===Oa.id,setActive:F}),(e.size===`infinite`||e.features.zoom)&&(0,n.jsx)($,{type:Fa,disabled:S,img:Fa.icon,isActive:i.id===Fa.id,setActive:F}),w?(0,n.jsx)(Z,{disabled:S,onClick:M,title:`Toggle tools`,icon:hi,selected:L}):x.map(e=>(0,n.jsx)(Ka,{disabled:S,activeTool:i,group:e,setActiveToolFromId:I},`id`in e?e.id:e.title))]}),!C&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{type:ka,disabled:S||!a,img:ka.icon,isActive:i.id===ka.id,setActive:f}),(0,n.jsx)($,{type:Aa,disabled:S||!o,img:Aa.icon,isActive:i.id===Aa.id,setActive:p}),(0,n.jsx)($,{type:ja,disabled:S||!s,img:ja.icon,isActive:i.id===ja.id,setActive:u})]}),(0,n.jsx)(Ha,{withActionsInMenu:C,disabled:S,activeTool:i,addPicture:m,loadFile:h,saveFile:g,togglePictureUrlModal:N,toggleExportModal:P,withUploadPicture:b,withUrlPicture:y,withLoadAndSave:c,withExport:l,hasActionToUndo:a,hasActionToRedo:o,hasActionToClear:s,undoAction:f,redoAction:p,clearCanvas:u})]}),E&&(0,n.jsx)(Yi,{className:`react-paint-editor-toolbar-modal`,onClose:M,title:`Outils`,children:v.map(e=>e.type===`picture`?null:(0,n.jsx)($,{disabled:S,type:e,img:e.icon,withText:!1,isActive:i.id===e.id,setActive:F},e.id))}),O&&(0,n.jsx)(Ua,{togglePictureUrlModal:ee,addPicture:m}),A&&(0,n.jsx)(Ga,{toggleExportModal:P,exportCanvasInFile:_})]})},Xa={none:0,small:10,medium:20,large:40},Za={toolbarBackgroundColor:`white`,dividerColor:`#36418129`,fontRadius:8,fontDisabledColor:`#3641812b`,fontDisabledBackgroundColor:`transparent`,fontColor:`#364181`,fontBackgroundColor:`transparent`,fontSelectedColor:`white`,fontSelectedBackgroundColor:`#364181`,fontHoverColor:`#364181`,fontHoverBackgroundColor:`#afd8d8`},Qa=()=>{let e=(0,t.useRef)([]),[n,r]=(0,t.useState)([]),i=e=>{r(t=>t.filter(t=>t.id!==e))};return(0,t.useEffect)(()=>()=>{for(let t of e.current)clearTimeout(t)},[]),{snackbarList:n,addSnackbar:({type:t=ci.type,duration:n=ci.duration,text:a})=>{let o={id:V(`snackbar_`),duration:n,type:t,text:a};r(e=>[...e,o]);let s=setTimeout(()=>{i(o.id),e.current=e.current.filter(e=>e!==s)},n);e.current=[...e.current,s]}}},$a=36,eo=36,to=16,no=8,ro=176,io=200,ao=({moveShapes:e,selectAllShapes:r,selectionMode:i,transformShape:a,settings:o,canvasRef:s,closeContextMenu:c,toggleShapeVisibility:l,toggleShapeLock:u,removeShape:d,duplicateShapes:f,copiedShape:p,setCopiedShape:m,pasteShapes:h,removeShapePoint:g,buildShapesGroup:_,copyShapes:v})=>{let y=(0,t.useRef)(null),b=(0,t.useRef)(null),{originalShape:x,cursorStartPosition:S,anchor:C}=i,w=U(x),T=w.length>0,E=w.length===1&&(w[0]?.type===`polygon`||w[0]?.type===`curve`)&&C!==void 0&&w[0]?.points?.length>2,D=!w.some(e=>e.visible===!1),O=w.some(e=>e.locked),{isOpen:k}=Va({trigger:`hover`,buttonElt:y.current}),{isOpen:A}=Va({trigger:`hover`,buttonElt:b.current,disabled:O}),j=no*2+eo*(2+(T?8:0)+(E?1:0))+to*(T?3:1),[M]=(0,t.useState)(()=>[(S[0]+o.canvasOffset[0])*o.canvasSize.scaleRatio,$a+(S[1]+o.canvasOffset[1])*o.canvasSize.scaleRatio]),[N,ee]=(0,t.useState)();(0,t.useEffect)(()=>{let e=s?.current?.getBoundingClientRect();if(!e)return;let t=e.left+M[0],n=e.top+M[1],r=Math.max(0,Math.min(t,window.innerWidth-ro))-e.left;ee({x:r,y:Math.max(0,Math.min(n,window.innerHeight-j))-e.top,subMenuPosition:r>window.innerWidth-ro-Math.min(r,io)?`left`:`right`})},[s,M,j]);let P=N?{"--react-paint-editor-toolbox-contextmenu-transform":`translate3D(${N.x}px, ${N.y}px, 0)`}:{display:`none`};return(0,n.jsxs)(Ra,{className:`react-paint-editor-toolbox-contextmenu`,style:P,children:[T&&(0,n.jsxs)(n.Fragment,{children:[E&&(0,n.jsx)(Z,{onClick:()=>{E&&g(w[0],C),c()},children:`Delete point`}),(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbox-contextmenu-group`,ref:y,children:[(0,n.jsx)(Z,{icon:`<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>`,children:`Organize`}),k&&(0,n.jsxs)(Ra,{position:N?.subMenuPosition,children:[(0,n.jsx)(Z,{onClick:()=>{T&&e(w,`forward`),c()},children:`Move forward`}),(0,n.jsx)(Z,{onClick:()=>{T&&e(w,`first`),c()},children:`Put on first`}),(0,n.jsx)(Z,{onClick:()=>{T&&e(w,`backward`),c()},children:`Move backward`}),(0,n.jsx)(Z,{onClick:()=>{T&&e(w,`last`),c()},children:`Put on last`})]})]}),(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbox-contextmenu-group`,ref:b,children:[(0,n.jsx)(Z,{icon:`<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>`,disabled:O,children:`Transform`}),A&&(0,n.jsxs)(Ra,{position:N?.subMenuPosition,children:[(0,n.jsx)(Z,{onClick:()=>{let e=s?.current?.getContext(`2d`);e&&T&&a(e,w,x.computed.center,`flipHorizontally`),c()},children:`Flip horizontally`}),(0,n.jsx)(Z,{onClick:()=>{let e=s?.current?.getContext(`2d`);e&&T&&a(e,w,x.computed.center,`flipVertically`),c()},children:`Flip vertically`}),(0,n.jsx)(Z,{onClick:()=>{let e=s?.current?.getContext(`2d`);e&&T&&a(e,w,x.computed.center,`rotateClockwise`),c()},children:`Rotate clockwise`}),(0,n.jsx)(Z,{onClick:()=>{let e=s?.current?.getContext(`2d`);e&&T&&a(e,w,x.computed.center,`rotateCounterclockwise`),c()},children:`Rotate counterclockwise`})]})]}),(0,n.jsx)(`hr`,{}),(0,n.jsx)(Z,{onClick:()=>{T&&(m(_(w)),d(w)),c()},children:`Cut`}),(0,n.jsx)(Z,{onClick:()=>{T&&m(_(w)),c()},children:`Copy`})]}),(0,n.jsx)(Z,{onClick:()=>{p&&h(v(p)),c()},disabled:!p,children:`Paste`}),(0,n.jsx)(`hr`,{}),T&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Z,{onClick:()=>{T&&f(w,!0,!0),c()},children:`Duplicate`}),(0,n.jsx)(Z,{onClick:()=>{T&&l(w.filter(e=>D?e.visible!==!1:e.visible===!1)),c()},children:D?`Hide`:`Show`}),(0,n.jsx)(Z,{onClick:()=>{T&&u(w.filter(e=>O?e.locked:!e.locked)),c()},children:O?`Unlock`:`Lock`}),(0,n.jsx)(Z,{onClick:()=>{T&&d(w),c()},children:`Delete`}),(0,n.jsx)(`hr`,{})]}),(0,n.jsx)(Z,{onClick:()=>{r(),c()},children:`Select all`})]})},oo=({editorProps:e,className:r,style:i,options:a,children:o})=>{let{selectionMode:s,setSelectionMode:c,shapes:l,addPictureShape:u,moveShapes:d,swapShapes:f,toggleShapeVisibility:p,toggleShapeLock:m,canGoBackward:h,canGoForward:g,canClear:_,selectedShape:v,copiedShape:y,setCopiedShape:b,pasteShapes:x,removeShape:S,duplicateShapes:C,updateShape:w,backwardShape:T,forwardShape:E,removeShapePoint:D,transformShape:O,refs:k,width:A,height:j,selectTool:M,selectShapes:N,selectAllShapes:ee,activeTool:P,setActiveTool:F,setAvailableTools:I,isEditMode:L,availableTools:te,gridGap:R,setGridGap:ne,loadFile:z,exportPicture:re,exportData:ie,clearCanvas:ae,settings:B,setCanvasZoom:oe,saveShapes:se,buildShapesGroup:ce,copyShapes:V,refreshShape:le,calculateTextFontSize:H,canvas:{canGrow:ue,layersManipulation:de,withExport:fe,withLoadAndSave:pe,withUploadPicture:me,withUrlPicture:he,withContextMenu:ge}}=e,{toolbarBackgroundColor:_e,dividerColor:ve,fontRadius:ye,fontDisabledColor:be,fontDisabledBackgroundColor:U,fontColor:xe,fontBackgroundColor:Se,fontSelectedColor:Ce,fontSelectedBackgroundColor:we,fontHoverColor:W,fontHoverBackgroundColor:Te}={...Za,...a},Ee=B.size===`infinite`||B.features.zoom,[De,G]=(0,t.useState)(!1),[Oe,ke]=(0,t.useState)(!1),[K,Ae]=(0,t.useState)(Ee),je=Ee&&K,Me=R>=Xa.large?`large`:R>=Xa.medium?`medium`:R>=Xa.small?`small`:`none`,Ne=e=>{ne(Xa[e])},{snackbarList:Pe,addSnackbar:Fe}=Qa(),Ie=(0,t.useCallback)((e,t,n)=>{I(r=>r.map(r=>r.id===e?He([`settings`,t,`default`],n,r):r)),F(r=>r.id===e?He([`settings`,t,`default`],n,r):r)},[F,I]),Le=(0,t.useCallback)(e=>{G(!0);try{re(e)}catch(e){e instanceof Error&&Fe({type:`error`,text:`L'export a échoué : ${e.message}`}),console.warn(e)}finally{G(!1)}},[re,Fe]),Re=(0,t.useCallback)(()=>{G(!0);try{ie(),G(!1)}catch(e){e instanceof Error&&Fe({type:`error`,text:`L'enregistrement a échoué`}),console.warn(e)}finally{G(!1)}},[ie,Fe]),ze=(0,t.useCallback)(async e=>{G(!0);try{await z(e),Fe({type:`success`,text:`Fichier chargé !`})}catch(e){e instanceof Error&&Fe({type:`error`,text:`Le chargement a échoué`}),console.warn(e)}finally{G(!1)}},[z,Fe]),Be=(0,t.useCallback)(async e=>{G(!0);try{N([await u(e,A,j)])}catch(e){e instanceof Error&&Fe({type:`error`,text:`Le chargement a échoué`}),console.warn(e)}finally{G(!1)}},[u,N,Fe,A,j]),Ve=`${r?`${r} `:``}${Oe?`react-paint-editor-layout-opened `:``}react-paint-editor-app`,Ue=()=>{c({mode:`default`}),k.canvas.current?.focus()};return(0,n.jsxs)(`div`,{ref:k.setEditor,className:Ve,style:{"--react-paint-editor-app-maxWidth":ue?`100%`:`${A}px`,"--react-paint-editor-app-toolbar-bg":_e,"--react-paint-editor-app-divider-color":ve,"--react-paint-editor-app-font-radius":`${ye}px`,"--react-paint-editor-app-font-disabled-color":be,"--react-paint-editor-app-font-disabled-bg":U,"--react-paint-editor-app-font-color":xe,"--react-paint-editor-app-font-bg":Se,"--react-paint-editor-app-font-selected-color":Ce,"--react-paint-editor-app-font-selected-bg":we,"--react-paint-editor-app-font-hover-color":W,"--react-paint-editor-app-font-hover-bg":Te,...i},children:[L&&(0,n.jsx)(Ya,{settings:B,width:B.canvasSize.width,activeTool:P,clearCanvas:ae,setActiveTool:M,exportCanvasInFile:Le,saveFile:Re,loadFile:ze,addPicture:Be,hasActionToUndo:h,hasActionToRedo:g,hasActionToClear:_,undoAction:T,redoAction:E,availableTools:te,withExport:fe,withLoadAndSave:pe,withUploadPicture:me,withUrlPicture:he}),o,L&&de&&(0,n.jsx)(Ji,{gridFormat:Me,setGridFormat:Ne,shapes:l,swapShapes:f,selectedShapes:v,removeShape:S,selectShapes:N,toggleShapeVisibility:p,toggleShapeLock:m,isLayoutPanelShown:Oe,settings:B}),je&&(0,n.jsxs)(fi,{alignment:`left`,position:`bottom`,className:`react-paint-editor-layouts-panel`,"data-edit":+L,children:[(0,n.jsx)(Z,{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:()=>oe(`unzoom`)}),(0,n.jsxs)(Z,{className:`react-paint-editor-zoom-button react-paint-editor-zoom-button-value`,onClick:()=>oe(`default`),children:[Math.round(B.canvasZoom*100),`%`]}),(0,n.jsx)(Z,{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-400Zm-40-60v-80h-80v-80h80v-80h80v80h80v80h-80v80h-80Z"/></svg>`,onClick:()=>oe(`zoom`)})]}),L&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(ha,{saveShapes:se,setCanvasZoom:oe,width:B.canvasSize.width,activeTool:P,availableTools:te,selectedShape:v,settings:B,removeShape:S,updateShape:w,canvas:k.canvas.current,layersManipulation:de,toggleLayoutPanel:()=>{ke(e=>!e)},isZoomPanelShown:je,setIsZoomPanelShown:Ae,updateToolSettings:Ie,refreshShape:le,calculateTextFontSize:H}),(0,n.jsx)(si,{isLoading:De}),(0,n.jsx)(ui,{snackbarList:Pe})]}),s.mode===`contextMenu`&&ge&&(0,n.jsx)(ao,{selectionMode:s,settings:B,canvasRef:k.canvas,closeContextMenu:Ue,selectAllShapes:ee,removeShape:S,moveShapes:d,duplicateShapes:C,toggleShapeLock:m,toggleShapeVisibility:p,setCopiedShape:b,copiedShape:y,pasteShapes:x,removeShapePoint:D,transformShape:O,buildShapesGroup:ce,copyShapes:V})]})},so=(e,t)=>{if(Array.isArray(e))return t},co=e=>Jt(e.map(e=>{if(typeof e!=`object`||!e.type)return null;let t=Da.find(t=>t.type===e.type);return t?We(so,t,e):e}));e.Canvas=ti,e.Editor=oo,e.useReactPaint=({options:e,...n}={})=>{let r=e?.availableTools,i=(e?.withUploadPicture??g.withUploadPicture)||(e?.withUrlPicture??g.withUrlPicture),a=(0,t.useMemo)(()=>{let e=r?co(r):Da;return i?e:e.filter(e=>e.type!==`picture`)},[r,i]);return ei({...n,options:{...e,availableTools:a}})}});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ReactPaint={},e.React,e.ReactJSXRuntime))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};t=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule||!c.call(e,`default`)?i(n,`default`,{value:e,enumerable:!0}):n,e)))(t,1);var u=`blue`,d=[[0,0],[.5,0],[1,0],[1,.5],[1,1],[.5,1],[0,1],[0,.5]],f=[`rect`,`square`,`circle`,`ellipse`,`picture`,`text`,`triangle`,`brush`,`group`],p=[`square`,`circle`,`picture`,`text`],m=[`brush`,`rect`,`square`,`line`,`polygon`,`circle`,`curve`,`ellipse`,`picture`,`text`,`triangle`,`group`],h=[[1,0],[1,2],[4,6]],g=`serif`,_=`react-paint-`,v={id:`${_}selection`,type:`selection`},y={id:`${_}move`,type:`move`},b=`${_}picture`,x=[`transparent`,`black`,`white`,`red`,`green`,`blue`,`yellow`],S=[0,1,2],C=[0,1,2,3],w=[`arial`,`serif`,`monospace`],T={strokeColor:{values:x,default:`black`},fillColor:{values:x,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:S,default:0}},E={opacity:{min:0,max:100,step:1,default:100}},D={strokeColor:{values:x,default:`black`},opacity:{min:0,max:100,step:1,default:100},fontFamily:{values:w,default:g},fontBold:{values:[!1,!0],default:!1},fontItalic:{values:[!1,!0],default:!1}},ee={strokeColor:{values:x,default:`black`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:6,max:20,step:2,default:10},lineDash:{values:S,default:0}},te={strokeColor:{values:x,default:`black`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:S,default:0},lineArrow:{values:C,default:0}},O={strokeColor:{values:x,default:`black`},fillColor:{values:x,default:`transparent`},opacity:{min:0,max:100,step:1,default:100},lineWidth:{min:1,max:20,step:1,default:1},lineDash:{values:S,default:0},closedPoints:{default:0}},k=[{type:`brush`,id:`${_}brush`,settings:ee},{type:`line`,id:`${_}line`,settings:te},{type:`polygon`,id:`${_}polygon`,settings:O},{type:`curve`,id:`${_}curve`,settings:O},{type:`rect`,id:`${_}rect`,settings:T},{type:`square`,id:`${_}square`,settings:T},{type:`circle`,id:`${_}circle`,settings:T},{type:`ellipse`,id:`${_}ellipse`,settings:T},{type:`picture`,id:b,settings:E},{type:`text`,id:`${_}text`,settings:D}],A=`react-paint-canvas-drawcanvas`,ne=104857600,re={grid:0,withContextMenu:!0,withDropPicture:!0,availableTools:k,clearCallback:`empty`,resolvePictureSrc:void 0,brushAlgo:`simple`,isBrushShapeDoneOnMouseUp:!0,withFrameSelection:!0,withSkeleton:!0,canvasSelectionPadding:0,size:`fixed`,resize:`scaleDown`,canZoom:`never`,debug:!1},j={canvasBackgroundColor:`white`,canvasSelectionColor:u,canvasSelectionWidth:2},M=(e,t)=>{if(Object.is(e,t))return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null)return!1;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.prototype.hasOwnProperty.call(t,n)&&Object.is(e[n],t[n]))},ie={},ae=(e=``)=>(ie[e]||(ie[e]=0),`${e}${++ie[e]}`),oe=0,N=e=>`${e}_${typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():`${Date.now().toString(36)}${Math.random().toString(36).slice(2,10)}${++oe}`}`,se=(e,t,n)=>Math.max(t,Math.min(e,n)),ce=()=>typeof navigator>`u`?!1:navigator.userAgent.includes(`Macintosh`),P=(e,t)=>t===void 0?`var(${e})`:`var(${e}, ${t})`,le=e=>e.filter(e=>e!=null),ue=(e,t,...n)=>{let r=se(Math.round(t),0,e.length);return[...e.slice(0,r),...n,...e.slice(r)]},de=(e,t,n)=>t<0||n<0||t>e.length-1||n>e.length-1?e:t<n?[...e.slice(0,t),...e.slice(t+1,n+1),e[t],...e.slice(n+1,e.length)]:[...e.slice(0,n),e[t],...e.slice(n,t),...e.slice(t+1,e.length)],fe=(e,t)=>{let n={...t};for(let t of e)delete n[t];return n},pe=(e,t,n)=>{let r=Array.isArray(n)?[...n]:{...n},i=Array.isArray(e)?e:typeof e==`string`?e.split(`.`):[e];return i.reduce((e,n,r)=>(e[n]=F(e[n])?{...e[n]}:Array.isArray(e[n])?[...e[n]]:e[n]===void 0||e[n]===null?{}:e[n],r===i.length-1&&(e[n]=t),e[n]),r),r},me=e=>Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0)),he=(e,t)=>({...e,...me(t??{})}),F=e=>typeof e==`object`&&!Array.isArray(e)&&e!==null,ge=(e,t)=>Array.isArray(e)?t:void 0,_e=(e,t,n)=>{if(!F(t)||!F(n))return n;let r={...t};for(let t in n)n.hasOwnProperty(t)&&(r[t]=r.hasOwnProperty(t)?e(r[t],n[t],t)??_e(e,r[t],n[t]):n[t]);return r},ve=(e,t)=>{if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null)return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;let r=e,i=t;for(let e of n)if(!Object.prototype.hasOwnProperty.call(i,e)||!ve(r[e],i[e]))return!1;return!0},ye=e=>e?le(e.map(e=>{if(!F(e)||!e.type)return null;let t=k.find(t=>t.type===e.type);return t?_e(ge,t,e):e})):k,be=(e,t)=>e.find(e=>e.id===t.toolId)??e.find(e=>e.type===t.type),xe=e=>{let t={};for(let[n,r]of Object.entries(e?.settings??{}))F(r)&&r.default!==void 0&&(t[n]=r.default);return t},I=e=>e?e.type===`group`?e.shapes:[e]:[],Se=(e,t)=>{let n=le(I(e).map(e=>be(t,e)));if(!n.length)return;if(n.length===1)return n[0];let r=n.slice(1).reduce((e,t)=>{let n={};for(let r in t.settings){if(e[r]===void 0)continue;let i=e[r],a=t.settings[r];if(i.hidden||a?.hidden)continue;let o={};`min`in a&&`min`in i&&a.min===i.min&&`max`in a&&`max`in i&&a.max===i.max&&`step`in a&&`step`in i&&a.step===i.step&&(o.min=a.min,o.max=a.max,o.step=a.step),`values`in a&&`values`in i&&a.values?.join(`,`)===i.values?.join(`,`)&&(o.values=a.values),(Object.keys(o).length>0||r===`closedPoints`)&&(n[r]=o)}return n},n[0].settings);return{id:n.map(e=>e.id).join(`-`),icon:``,label:`group`,type:`group`,settings:r}},Ce=e=>{e.reset(),e.lineCap=`round`,e.lineJoin=`round`},L=(e,t={})=>{let{lineCap:n=`round`,fillColor:r=`transparent`,opacity:i=100,strokeColor:a=u,lineWidth:o=2,lineDash:s=0,shadowColor:c=`transparent`,shadowBlur:l=0}=t;e.lineCap=n,e.globalAlpha=i/100,e.fillStyle=r,e.strokeStyle=a,e.lineWidth=o,e.setLineDash(s===0?[]:[h[s][0]*o,h[s][1]*o]),e.shadowColor=c,e.shadowBlur=l},we=(e,t,n,r)=>{e.save(),e.scale(t.canvasSize.scaleRatio,t.canvasSize.scaleRatio),e.translate(t.canvasOffset[0],t.canvasOffset[1]),n&&r&&(e.translate(r[0],r[1]),e.rotate(n),e.translate(-r[0],-r[1]))},Te=(e,t,n)=>{e.globalAlpha!==0&&(n?.fillColor!==`transparent`&&e.fill(t),n?.strokeColor!==`transparent`&&e.stroke(t))},Ee=(e,t,n)=>({realWidth:t,realHeight:n,width:e,height:n*e/t,scaleRatio:e/t}),De=(e,t)=>({realWidth:e,realHeight:t,width:e,height:t,scaleRatio:1}),Oe=e=>e===`scale`||e===`scaleUp`,ke=e=>e===`scale`||e===`scaleDown`,Ae=()=>{if(typeof document>`u`)return null;try{return document.createElement(`canvas`).getContext(`2d`)}catch{return null}},je=()=>{let e={font:`10px sans-serif`,measureText:t=>({width:t.length*Number.parseFloat(/([\d.]+)px/.exec(e.font)?.[1]??`10`)*.6})};return e},Me=e=>e.type===`line`||e.type===`polygon`||e.type===`curve`,Ne=e=>7/e.canvasSize.scaleRatio,Pe=(e,t)=>[e.x+e.width/2,e.y-23/t.canvasSize.scaleRatio],Fe=(e,[t,n])=>[e.x+e.width*t,e.y+e.height*n],Ie=(e,{x:t,y:n,width:r,height:i})=>{e.beginPath(),e.rect(t,n,r,i),e.stroke()},Le=(e,t)=>L(e,{fillColor:`rgb(255,255,255)`,strokeColor:`rgb(150,150,150)`,lineWidth:2/t.canvasSize.scaleRatio}),Re=(e,[t,n],r,i)=>{e.beginPath(),e.arc(t,n,Ne(r),0,2*Math.PI),i&&(e.shadowColor=i,e.shadowBlur=10),e.fill(),e.shadowBlur=0,e.stroke()},ze=(e,t,n)=>{let r=Pe(t,n);e.beginPath(),e.moveTo(r[0],t.y),e.lineTo(r[0],r[1]),e.stroke(),Le(e,n),Re(e,r,n);for(let r of d)Re(e,Fe(t,r),n)},Be={none:0,small:10,medium:20,large:40},Ve=4e3,He=16384,Ue=[`image/png`,`image/gif`,`image/jpeg`,`image/svg+xml`,`image/webp`],We=e=>e*180/Math.PI,Ge=(e,t)=>t[0]>=e.x&&t[0]<=e.x+e.width&&t[1]>=e.y&&t[1]<=e.y+e.height,Ke=e=>{let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)for(let[e,o]of a)e<t&&(t=e),e>r&&(r=e),o<n&&(n=o),o>i&&(i=o);return{minX:t,minY:n,maxX:r,maxY:i}},qe=({x:e,y:t,width:n,height:r})=>[[e,t],[e+n,t],[e+n,t+r],[e,t+r]],Je=e=>{let t=1/0,n=1/0,r=-1/0,i=-1/0;for(let a of e)t=Math.min(t,a.x),n=Math.min(n,a.y),r=Math.max(r,a.x+a.width),i=Math.max(i,a.y+a.height);return{x:t,y:n,width:r-t,height:i-n}},Ye=(e,t)=>{let n=t.x-Math.min(Math.max(t.x,e.x),e.x+e.width),r=t.y-Math.min(Math.max(t.y,e.y),e.y+e.height);return Math.sqrt(n*n+r*r)<=t.radius},R=({origin:e=[0,0],point:t,rotation:n=0})=>{if(n===0)return t;let r=[t[0]-e[0],t[1]-e[1]],i=r[1]*Math.cos(n)-r[0]*Math.sin(n);return[r[1]*Math.sin(n)+r[0]*Math.cos(n)+e[0],i+e[1]]},Xe=e=>(e+2*Math.PI)%(2*Math.PI),Ze=({targetVector:[e,t],radian:n=!0,originVector:r})=>{let i=Xe(Math.atan2(t[1]-e[1],t[0]-e[0]));if(r){let[e,t]=r,a=Xe(i-Math.atan2(t[1]-e[1],t[0]-e[0]));return n?a:We(a)}return n?i:We(i)},Qe=(e,t)=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),$e=(e,t)=>[(e[0]+t[0])/2,(e[1]+t[1])/2],et=e=>e.type===`picture`||e.type===`text`?void 0:e.path,tt=(e,t,n,r)=>{r.debug&&(e.save(),e.scale(r.canvasSize.scaleRatio,r.canvasSize.scaleRatio),e.translate(r.canvasOffset[0],r.canvasOffset[1]),L(e,{fillColor:`transparent`,strokeColor:`green`,lineWidth:n/r.canvasSize.scaleRatio}),e.strokeRect(t.computed.boundingBox.x,t.computed.boundingBox.y,t.computed.boundingBox.width,t.computed.boundingBox.height),e.restore())},nt=(e,t,n,r,i,a)=>{we(e,i,t.rotation,t.computed.center),i.debug&&(L(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/i.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),L(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/i.canvasSize.scaleRatio});let{borders:o}=t.computed,s=et(t);s?e.stroke(s):Ie(e,o),a&&!t.locked&&(s&&Ie(e,o),ze(e,o,i))},rt=({borderStart:e,borderSize:t,vector:n,settings:r,invertedAxe:i,anchor:a})=>{switch(a){case 0:{if(i){let i=Math.max(0,n-t)+2*r.selectionPadding;return[e+t-2*r.selectionPadding,i]}let a=Math.max(2*r.selectionPadding,t-n);return[e+t-a,a]}case .5:return[e,t];case 1:if(i){let i=Math.min(e,e+t+n);return[i,e-i+2*r.selectionPadding]}return[e,Math.max(2*r.selectionPadding,t+n)];default:return[0,0]}},it=(e,t,n,r,i,a,o,s,c,l,u)=>{let{selectionPadding:d}=u,f=`ratio`in c&&c.ratio?c.ratio:(e.width-d*2||1)/(e.height-d*2||1),p=(r-d*2)/(a-d*2),m,h,g,_;return l.anchor[0]!==.5&&l.anchor[1]!==.5?p<f?(h=i,_=a,g=(a-d*2)*f+2*d,m=l.anchor[0]===0?o?e.x+e.width-2*d:e.x+(e.width-g):o?e.x-g+2*d:e.x):(m=n,g=r,_=(r-d*2)/f+2*d,h=l.anchor[1]===0?s?e.y+e.height-2*d:e.y+(e.height-_):s?e.y-_+2*d:e.y):l.anchor[0]===.5?(h=i,_=a,g=(a-d*2)*f+2*d,m=e.x+(e.width-g)/2):(m=n,g=r,_=(r-d*2)/f+2*d,h=e.y+(e.height-_)/2),{borderX:m,borderWidth:g,borderY:h,borderHeight:_,center:t,originalShape:c}},at=({borderX:e,borderWidth:t,borderY:n,borderHeight:r,center:i,originalShape:a})=>{let o=[e+t/2-i[0],n+r/2-i[1]],[s,c]=R({point:o,rotation:-(a.rotation??0)});return{borderX:U(e+s-o[0]),borderWidth:U(t),borderY:U(n+c-o[1]),borderHeight:U(r)}},ot=(e,t)=>Math.max(0,Math.abs(e)-t),st=({roundCursorPosition:e,borders:t,center:n,selectionMode:r,originalShape:i,settings:a})=>{let o=(t,i,o)=>{if(r.anchor[t]===.5)return[i,o];let s=2*Math.max(a.selectionPadding,Math.abs(e[t]-n[t]));return[n[t]-s/2,s]},[s,c]=o(0,t.x,t.width),[l,u]=o(1,t.y,t.height);return{borderX:s,borderWidth:c,borderY:l,borderHeight:u,center:n,originalShape:i}},ct=({roundCursorPosition:e,borders:t,center:n,selectionMode:r,originalShape:i,settings:a})=>{let{selectionPadding:o}=a,s=Math.max(1,t.width-o*2),c=Math.max(1,t.height-o*2),l=`ratio`in i&&i.ratio?i.ratio:s/c,[u,d]=n,[f,p]=r.anchor,m=Math.hypot((f-.5)*s,(p-.5)*c)||1,h=Math.hypot(f===.5?0:ot(e[0]-u,o),p===.5?0:ot(e[1]-d,o))/m,g=2*o/(s+2*o),_=s*Math.max(h,g),v=_/l,y=_+o*2,b=v+o*2;return{borderX:u-y/2,borderY:d-b/2,borderWidth:y,borderHeight:b,center:n,originalShape:i}},lt=(e,t,n,r,i=!1,a=!1)=>{let{center:o,borders:s}=t.computed,c=R({origin:o,point:e,rotation:t.rotation}),l=a?[o[0],o[0]]:[s.x+s.width-r.selectionPadding,s.x+r.selectionPadding],u=a?[o[1],o[1]]:[s.y+s.height-r.selectionPadding,s.y+r.selectionPadding],d=n.anchor[0]===0&&c[0]>=l[0]||n.anchor[0]===1&&c[0]<=l[1],f=n.anchor[1]===0&&c[1]>=u[0]||n.anchor[1]===1&&c[1]<=u[1],p=[W(c[0],r,n.anchor[0]===0&&!d||n.anchor[0]===1&&d?r.selectionPadding:-r.selectionPadding),W(c[1],r,n.anchor[1]===0&&!f||n.anchor[1]===1&&f?r.selectionPadding:-r.selectionPadding)];if(a){let e={roundCursorPosition:p,borders:s,center:o,selectionMode:n,originalShape:t,settings:r};return{...at(i?ct(e):st(e)),isXinverted:d,isYinverted:f}}let m=r.gridGap?[n.anchor[0]===0?s.x:n.anchor[0]===.5?s.x+s.width/2:s.x+s.width,n.anchor[1]===0?s.y:n.anchor[1]===.5?s.y+s.height/2:s.y+s.height]:R({origin:o,point:n.cursorStartPosition,rotation:t.rotation}),h=[p[0]-m[0],p[1]-m[1]],[g,_]=rt({borderStart:s.x,borderSize:s.width,vector:h[0],settings:r,invertedAxe:d,anchor:n.anchor[0]}),[v,y]=rt({borderStart:s.y,borderSize:s.height,vector:h[1],settings:r,invertedAxe:f,anchor:n.anchor[1]});return{...at(i?it(s,o,g,_,v,y,d,f,t,n,r):{borderX:g,borderWidth:_,borderY:v,borderHeight:y,center:o,originalShape:t}),isXinverted:d,isYinverted:f}},ut=(e,t,n,r,i,a,o)=>{t.shapes.forEach(t=>{L(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/a.canvasSize.scaleRatio}),we(e,a,t.rotation,t.computed.center);let i=et(t);i&&e.stroke(i),e.restore()}),i.mode!==`rotate`&&(we(e,a,t.rotation,t.computed.center),a.debug&&(L(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/a.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),L(e,{fillColor:`transparent`,strokeColor:n,lineWidth:r/a.canvasSize.scaleRatio}),o&&!t.locked&&(Ie(e,t.computed.borders),ze(e,t.computed.borders,a)))},dt=({ctx:e,shape:t,withAnchors:n,selectionWidth:r,selectionColor:i,hoverMode:a,settings:o})=>{we(e,o,t.rotation,t.computed.center),o.debug&&(L(e,{fillColor:`transparent`,strokeColor:`red`,lineWidth:r/o.canvasSize.scaleRatio}),e.strokeRect(t.computed.outerBorders.x,t.computed.outerBorders.y,t.computed.outerBorders.width,t.computed.outerBorders.height)),L(e,{fillColor:`transparent`,strokeColor:i,lineWidth:r/o.canvasSize.scaleRatio}),e.stroke(t.path),n&&!t.locked&&(Le(e,o),t.points.forEach((t,n)=>{Re(e,t,o,a.mode===`resize`&&a.anchor===n?i:void 0)}))},ft=(e,t,n)=>{L(e,{fillColor:`rgba(170,170,170, 0.1)`,strokeColor:`rgb(170,170,170)`,lineWidth:1/n.canvasSize.scaleRatio}),e.fillRect(t[0][0],t[0][1],t[1][0]-t[0][0],t[1][1]-t[0][1]),e.strokeRect(t[0][0],t[0][1],t[1][0]-t[0][0],t[1][1]-t[0][1])},z=[.05,.1,.25,.5,1,2,4,8],pt=`#f5f5f5`,mt=e=>se(e,z[0],z[z.length-1]),ht=(e,t,n,r)=>r*t<=n?n/t/2-r/2:se(e,n/t-r,0),gt=({size:e,zoom:t,newOffset:[n,r],canvasSize:i,drawingSize:a})=>e===`infinite`?{zoom:t,offset:[n,r]}:{zoom:t,offset:[ht(n,t,i.realWidth,a.width),ht(r,t,i.realHeight,a.height)]},_t=({currentOffset:e,currentZoom:t,zoom:n,centerPoint:r,...i})=>{let a=e[0]-(r[0]/t-r[0]/n),o=e[1]-(r[1]/t-r[1]/n),{offset:s}=gt({...i,zoom:n,newOffset:[a,o]});return{offset:s,zoom:n}},vt=({currentOffset:e,currentZoom:t,action:n,...r})=>{let i=n==="default"?z[4]:n===`zoom`?z[se(z.length-1-z.slice(0).reverse().findIndex(e=>e<=t)+1,0,z.length-1)]:z[se(z.findIndex(e=>e>=t)-1,0,z.length-1)],a=[r.canvasSize.realWidth/2,r.canvasSize.realHeight/2];return _t({...r,currentOffset:e,currentZoom:t,zoom:i,centerPoint:a})},yt=({currentOffset:e,currentZoom:t,delta:n,centerPoint:r,...i})=>{let a=mt(t*(1-n/1e3));return _t({...i,currentOffset:e,currentZoom:t,zoom:a,centerPoint:r})},bt=({box:e,padding:t,...n})=>{let{canvasSize:r}=n,i=2*t/r.scaleRatio,a=mt(Math.min((r.realWidth-i)/Math.max(e.width,1),(r.realHeight-i)/Math.max(e.height,1))),o=[r.realWidth/2/a-(e.x+e.width/2),r.realHeight/2/a-(e.y+e.height/2)];return gt({...n,zoom:a,newOffset:o})},xt=e=>{let{canvasSize:{width:t,height:n,scaleRatioWithNoZoom:r},canvasZoom:i,canvasOffset:a}=e;return{x:0-a[0],y:0-a[1],width:t/i/r,height:n/i/r}},St=e=>{let{canvasSize:{scaleRatio:t},drawingSize:n,canvasOffset:r}=e;return{x:r[0]*t,y:r[1]*t,width:n.width*t,height:n.height*t}},Ct=({size:e,canvasZoom:t,canvasSize:n,drawingSize:r})=>e===`fixed`&&(r.width*t<n.realWidth||r.height*t<n.realHeight),wt=(e,t)=>{if(!Ct(t))return;let n=St(t);e.beginPath(),e.rect(n.x,n.y,n.width,n.height),e.closePath(),e.clip()},Tt=(e,t)=>{let{canvasSize:{width:n,height:r}}=t;if(!Ct(t))return;e.fillStyle=pt,e.fillRect(0,0,n,r);let i=St(t);e.clearRect(i.x,i.y,i.width,i.height),wt(e,t)},Et=(e,t)=>t.size!==`fixed`||e[0]>0&&e[0]<t.drawingSize.width&&e[1]>0&&e[1]<t.drawingSize.height,Dt=(e,t)=>{let n=Math.abs(e.deltaY)<50&&t<50,r=e.ctrlKey,i=ce()&&n&&r;switch(e.deltaMode){case WheelEvent.DOM_DELTA_LINE:return{deltaX:e.deltaX*16,deltaY:e.deltaY*16};case WheelEvent.DOM_DELTA_PAGE:return{deltaX:e.deltaX*window.innerHeight,deltaY:e.deltaY*window.innerHeight};default:return i?{deltaX:e.deltaX*5,deltaY:e.deltaY*5}:{deltaX:e.deltaX,deltaY:e.deltaY}}},Ot=(e,t,n,{isXinverted:r=!1,isYinverted:i=!1,rotation:a=e.rotation??0}={})=>{let{borders:o}=e.computed,s=(t.width-2*n.selectionPadding)/(o.width-2*n.selectionPadding||1),c=(t.height-2*n.selectionPadding)/(o.height-2*n.selectionPadding||1);return{newBorderX:t.x,newBorderY:t.y,newBorderWidth:t.width,newBorderHeight:t.height,widthMultiplier:s,heightMultiplier:c,isXinverted:r,isYinverted:i,groupCenter:[t.x+t.width/2,t.y+t.height/2],rotation:a,settings:n,originalBorders:o}},kt=(e,t,n,r,i,a)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l,isXinverted:u,isYinverted:d}=lt(e,t,n,r,i,a);return Ot(t,{x:o,y:c,width:l,height:s},r,{isXinverted:u,isYinverted:d})},B=(e,t,n)=>{let r=R({origin:t.computed.center,point:e.computed.center,rotation:t.rotation??0}),i=(r[0]-(e.computed.borders.width/2-n.settings.selectionPadding)-(n.originalBorders.x+n.settings.selectionPadding))*n.widthMultiplier,a=(r[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-i:i),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-a:a)}},V=(e,t,n,r,i)=>R({origin:e.groupCenter,point:[t+r/2,n+i/2],rotation:-e.rotation}),At=(e,{selectionPadding:t})=>{let n=ki(e.points),{minX:r,minY:i}=n,[a,o]=_i([n.maxX,n.maxY],r,i,e.scaleX,e.scaleY),s=Math.max(r,a),c=Math.max(i,o);return Hi({x:r,y:i,width:s-r,height:c-i},t)},jt=(e,t,n=Fi(e,t))=>{let r=G(e,At,t);return{...e,path:n,computed:r}},Mt=jt,Nt=(e,t,n)=>jt({toolId:e.id,type:e.type,id:N(e.type),points:[[t]],scaleX:1,scaleY:1,style:{opacity:e.settings.opacity.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),Pt=(e,t)=>{t.points.length<1||e.globalAlpha!==0&&t.style?.strokeColor!==`transparent`&&e.globalAlpha!==0&&e.stroke(t.path)},Ft=(e,t,n,r,i,a)=>{let o=At({...t,scaleX:1,scaleY:1},r),s=t.computed.borders,{borderX:c,borderHeight:l,borderY:u,borderWidth:d,isXinverted:f,isYinverted:p}=lt(e,t,n,r,i,a),m=Math.max(0,o.width-2*r.selectionPadding),h=Math.max(0,o.height-2*r.selectionPadding),g=Math.max(0,d-2*r.selectionPadding),_=Math.max(0,l-2*r.selectionPadding),v=m?g/m:1,y=h?_/h:1;if(!m||!h)return t;let b=U(c-s.x)+(f?2*s.x+o.width:0),x=U(u-s.y)+(p?2*s.y+o.height:0);return jt({...t,points:t.points.map(e=>e.map(([e,t])=>[f?-e+b:e+b,p?-t+x:t+x])),scaleX:v,scaleY:y},r)},It=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=At({...e,scaleX:1,scaleY:1},a),l=c.width-2*a.selectionPadding,u=c.height-2*a.selectionPadding,d=e.scaleX??1?(e.scaleX??1)*o:o/l,f=e.scaleY??1?(e.scaleY??1)*s:s/u,p=l*d,m=u*f,h=B(e,t,n),g=V(n,h.x,h.y,p,m),_=U(g[0]-p/2-e.computed.borders.x-a.selectionPadding)+(r?2*e.computed.borders.x+c.width:0),v=U(g[1]-m/2-e.computed.borders.y-a.selectionPadding)+(i?2*e.computed.borders.y+c.height:0),y=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation;return jt({...e,points:e.points.map(e=>e.map(([e,t])=>[r?-e+_:e+_,i?-t+v:t+v])),scaleX:d,scaleY:f,rotation:y?-(e.rotation??0):e.rotation??0},n.settings)},Lt=([e,t])=>[Math.round(e),Math.round(t)],Rt=(e,t,n)=>{let r=Lt(t);return jt({...e,points:Ai(e.points,e.points.length-1,r)},n,Pi(e,r,n))},zt=(e,t,n)=>jt({...e,points:Ai(e.points,e.points.length,Lt(t))},n),Bt=(e,t)=>Hi({x:e.x-e.radius,y:e.y-e.radius,width:e.radius*2,height:e.radius*2},t.selectionPadding),Vt=(e,t)=>{let n=Ti(e),r=G(e,Bt,t);return{...e,path:n,computed:r}},Ht=Vt,Ut=(e,t,n)=>Vt({toolId:e.id,type:e.type,id:N(e.type),x:t[0],y:t[1],radius:0,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),Wt=(e,t)=>{Te(e,t.path,t.style)},Gt=(e,t,n,r,i)=>{let{borderX:a,borderHeight:o,borderY:s,borderWidth:c}=lt(e,t,n,r,!0,i);return Vt({...t,radius:Math.max(0,c/2-r.selectionPadding),x:a+c/2,y:s+o/2},r)},Kt=(e,t,n)=>{let r=B(e,t,n),i=(e.radius||.5)*n.widthMultiplier,a=V(n,r.x,r.y,i*2,i*2);return Vt({...e,radius:i,x:a[0],y:a[1]},n.settings)},qt=(e,t)=>{let n=Bi(e),r=G(e,Zt,t);return{...e,path:n,computed:r}},Jt=qt,Yt=(e,t,n)=>qt({toolId:e.id,type:e.type,id:N(e.type),points:[t],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,closedPoints:e.settings.closedPoints.default}},n),Xt=(e,t)=>{Te(e,t.path,t.style)},Zt=(e,t)=>{let{minX:n,minY:r,maxX:i,maxY:a}=Ke([e.points]);return Hi({x:n,width:i-n,y:r,height:a-r},t.selectionPadding)},Qt=(e,t,n,r)=>{let i=K([W(e[0],r),W(e[1],r)],t.rotation??0,t.computed.center);return qt(pe([`points`,n.anchor],i,t),r)},$t=(e,t,n,r)=>{if(t<0||t>e.points.length-1)return e;let i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return qt({...e,points:i},r)},en=(e,t,n,r=!1)=>{let i=K([W(t[0],n),W(t[1],n)],e.rotation??0,e.computed.center);return qt({...e,points:r?e.points:[...e.points,i],tempPoint:r?i:void 0},n)},tn=(e,t,n)=>t<0||t>e.points.length-1?e:qt({...e,points:e.points.filter((e,n)=>n!==t)},n),nn=(e,t,n)=>{let r=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(r.length<2){let e=r[0]??[0,0],t=n.selectionPadding;return{x:e[0]-t,y:e[1]-t,width:2*t,height:2*t}}if(r.length<3)return Zt({...e,points:r},n);let i=Li(e,r),a=1/0,o=-1/0,s=1/0,c=-1/0;for(let e=1;e<i.length-2;e++){let t=i[e-1],n=i[e],r=i[e+1],l=i[e+2],{cp1:u,cp2:d}=Ri(t,n,r,l),f=Ii(n,u,d,r);a=Math.min(a,f.minX),o=Math.max(o,f.maxX),s=Math.min(s,f.minY),c=Math.max(c,f.maxY)}return xa({x:a,y:s,width:o-a,height:c-s},n)},rn=(e,t)=>{let n=zi(e),r=G(e,Zt,t,nn);return{...e,path:n,computed:r}},an=rn,on=(e,t,n)=>rn({toolId:e.id,type:e.type,id:N(e.type),points:[t],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,closedPoints:e.settings.closedPoints.default}},n),sn=(e,t,n,r)=>{let i=[W(e[0],r),W(e[1],r)],a=t.computed.center,o=K(i,t.rotation??0,a);return rn(pe([`points`,n.anchor],o,t),r)},cn=(e,t)=>{Te(e,t.path,t.style)},ln=(e,t,n,r)=>{if(t<0||t>e.points.length-1)return e;let i=[...e.points.slice(0,t+1),n,...e.points.slice(t+1)];return rn({...e,points:i},r)},un=(e,t,n,r=!1)=>{let i=[W(t[0],n),W(t[1],n)],a=e.computed.center,o=K(i,e.rotation??0,a);return rn({...e,points:r?e.points:[...e.points,o],tempPoint:r?o:void 0},n)},dn=(e,t,n)=>t<0||t>e.points.length-1?e:rn({...e,points:e.points.filter((e,n)=>n!==t)},n),fn=(e,t)=>Hi({x:e.x-e.radiusX,y:e.y-e.radiusY,width:e.radiusX*2,height:e.radiusY*2},t.selectionPadding),pn=(e,t)=>{let n=Ei(e),r=G(e,fn,t);return{...e,path:n,computed:r}},mn=pn,hn=(e,t,n)=>pn({toolId:e.id,type:e.type,id:N(e.type),x:t[0],y:t[1],radiusX:0,radiusY:0,style:{opacity:e.settings.opacity.default,fillColor:e.settings.fillColor.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default}},n),gn=(e,t)=>{Te(e,t.path,t.style)},_n=(e,t,n,r,i=!1,a=!1)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l}=lt(e,t,n,r,i,a);return pn({...t,radiusX:Math.max(0,l/2-r.selectionPadding),radiusY:Math.max(0,s/2-r.selectionPadding),x:o+l/2,y:c+s/2},r)},vn=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation,l=B(e,t,n),u=(e.radiusX||.5)*o,d=(e.radiusY||.5)*s,f=V(n,l.x,l.y,u*2,d*2);return pn({...e,radiusX:u,radiusY:d,x:f[0],y:f[1],rotation:c?-(e.rotation??0):e.rotation??0},a)},yn=(e,t)=>({...e,path:Vi(e),computed:G(e,Zt,t)}),bn=(e,t)=>yn({...e,id:ae(`triangle_`),type:`triangle`},t),xn=(e,t)=>{Te(e,t.path,t.style)},Sn=(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])+t.selectionPadding*2,y:Math.min(e.points[0][1],e.points[1][1])-t.selectionPadding,height:Math.abs(e.points[0][1]-e.points[1][1])+t.selectionPadding*2}),Cn=(e,t)=>{let n=[],r;if(e.style?.lineArrow===1||e.style?.lineArrow===2||e.style?.lineArrow===3){let i=Math.PI/2-Ze({targetVector:[e.points[0],e.points[1]]});(e.style?.lineArrow===1||e.style?.lineArrow===3)&&n.push(bn(En(e.points[0],i,e.style),t)),(e.style?.lineArrow===2||e.style?.lineArrow===3)&&n.push(bn(En(e.points[1],i+Math.PI,e.style),t)),r=Di(Ci({line:e,size:10+(e.style?.lineWidth??0)*2,direction:e.style?.lineArrow===1?`start`:e.style?.lineArrow===2?`end`:`both`}))}else r=Di(e);let i=G(e,Sn,t);return{...e,path:r,arrows:n,style:{...e.style,lineCap:e.style?.lineArrow?`butt`:`round`},computed:i}},wn=Cn,Tn=(e,t,n)=>Cn({toolId:e.id,type:e.type,id:N(e.type),points:[t,t],style:{opacity:e.settings.opacity.default,strokeColor:e.settings.strokeColor.default,lineWidth:e.settings.lineWidth.default,lineDash:e.settings.lineDash.default,lineArrow:e.settings.lineArrow.default}},n),En=(e,t,n)=>{let r=[R({point:[0,0],rotation:t}),R({point:[-(5+(n.lineWidth??0)),10+(n.lineWidth??0)*2],rotation:t}),R({point:[5+(n.lineWidth??0),10+(n.lineWidth??0)*2],rotation:t})];return{points:[[e[0]+r[0][0],e[1]+r[0][1]],[e[0]+r[1][0],e[1]+r[1][1]],[e[0]+r[2][0],e[1]+r[2][1]]],style:{...n,fillColor:n.strokeColor,strokeColor:`transparent`}}},Dn=(e,t)=>{Te(e,t.path,t.style);for(let n of t.arrows??[])L(e,{...n.style,opacity:100}),xn(e,n)},On=(e,t,n,r)=>{let i=K([W(e[0],r),W(e[1],r)],t.rotation??0,t.computed.center);return Cn(pe([`points`,n.anchor],i,t),r)},kn=(e,t)=>e.type===`line`?Cn(e,t):e.type===`polygon`?Jt(e,t):an(e,t),An=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=e.computed.borders.width-2*a.selectionPadding,l=e.computed.borders.height-2*a.selectionPadding,u=c*o,d=l*s,f=B(e,t,n),p=V(n,f.x,f.y,u,d),m=e.computed.center[0]-c/2,h=e.computed.center[1]-l/2,g=p[0]-u/2,_=p[1]-d/2;return kn({...e,points:e.points.map(([e,t])=>[g+(r?u-(e-m)*o:(e-m)*o),_+(i?d-(t-h)*s:(t-h)*s)])},n.settings)},jn=new Set([`img`,`path`,`arrows`,`tempPoint`,`computed`]),Mn=new Set([`flipX`,`flipY`]),Nn=3,Pn=6,Fn=new Map([[`x`,Nn],[`y`,Nn],[`width`,Nn],[`height`,Nn],[`radius`,Nn],[`radiusX`,Nn],[`radiusY`,Nn],[`fontSize`,Nn],[`rotation`,Pn],[`scaleX`,Pn],[`scaleY`,Pn],[`ratio`,Pn]]),In=new WeakMap,Ln=e=>{if(typeof e==`number`)return U(e,Nn);if(!Array.isArray(e))return e;let t=Array.isArray(e[0]),n=t?In.get(e):void 0;if(n)return n;let r=e.map(Ln),i=r.some((t,n)=>t!==e[n])?r:e;return t&&In.set(e,i),i},Rn=(e,t)=>{if(e===`points`)return Ln(t);let n=Fn.get(e);return n!==void 0&&typeof t==`number`?U(t,n):t},zn=e=>{let t={};for(let n of Object.keys(e)){let r=e[n];jn.has(n)||Mn.has(n)&&(r===void 0||r===!1)||(t[n]=Rn(n,r))}return t},Bn=new WeakMap,Vn=e=>{let t=Bn.get(e);if(t)return t;let n=zn(e);return Bn.set(e,n),n},Hn=e=>{let t=Vn(e);return e.type===`picture`&&nr(e.src)?{...t,src:tr(e.img)??e.src}:t},Un=e=>({...Hn(e)}),Wn=e=>e.map(Un),Gn=(e,t,n)=>({shapes:Wn(e),config:{width:t,height:n}}),Kn=(e,t,n)=>{let r=new Map(e.map(e=>[e.id,e])),i=new Set(t.map(e=>e.id)),a=[],o=[];t.forEach((e,t)=>{let i=r.get(e.id),s=n[t];if(!i)a.push(s);else if(i!==e){let e=Hn(i);ve(e,s)||o.push({shape:s,previous:{...e}})}});let s=t.filter(e=>r.has(e.id)).map(e=>e.id),c=e.filter(e=>i.has(e.id)).map(e=>e.id);return{added:a,updated:o,removed:Wn(e.filter(e=>!i.has(e.id))),reordered:!M(s,c)}},qn=e=>{let t=new DOMParser().parseFromString(e,`text/xml`).getElementsByTagName(`svg`)[0];if(!t)throw Error(`The SVG of the picture is invalid`);let n=t.getAttribute(`width`),r=t.getAttribute(`height`),i;if(n||r)i=e;else{let[,,e,n]=(t.getAttribute(`viewBox`)??`0 0 300 300`).split(` `);t.setAttribute(`width`,e??`300`),t.setAttribute(`height`,n??`300`),i=new XMLSerializer().serializeToString(t)}let a=new Blob([i],{type:`image/svg+xml`});return URL.createObjectURL(a)},Jn=e=>(e instanceof File?e.name:e).includes(`.svg`),Yn=e=>{if(/^data:/i.test(e))return/^data:image\//i.test(e)?{kind:`direct`}:{kind:`refused`};if(/^blob:/i.test(e))return{kind:`direct`};if(e.includes(`<svg`))return{kind:`svg`};if(!e||typeof document>`u`)return{kind:`refused`};try{let t=new URL(e,document.baseURI);return t.protocol===`http:`||t.protocol===`https:`?{kind:`remote`,url:t.href}:{kind:`refused`}}catch{return{kind:`refused`}}},Xn=async(e,t)=>{let n=await fetch(e,{credentials:`omit`,referrerPolicy:`no-referrer`,signal:t});if(!n.ok)throw Error(`The picture could not be fetched (${n.status})`);let r=(n.headers.get(`content-type`)??``).split(`;`)[0].trim().toLowerCase(),i=r.startsWith(`image/`);return r===`image/svg+xml`||!i&&Jn(e)?qn(await n.text()):URL.createObjectURL(new Blob([await n.blob()],{type:i?r:`application/octet-stream`}))},Zn=async(e,t,n)=>{let r=Yn(e);switch(r.kind){case`direct`:return e;case`svg`:return URL.createObjectURL(new Blob([e],{type:`image/svg+xml`}));case`refused`:throw Error(`The source of the picture is not supported`);case`remote`:{let e=t?await t(r.url):r.url;if(typeof e!=`string`)throw Error(`The source of the picture is refused`);let i=Yn(e);if(i.kind!==`remote`)throw Error(`The resolved source of the picture must be an http(s) URL`);return Xn(i.url,n)}}},Qn=e=>{e?.startsWith(`blob:`)&&URL.revokeObjectURL(e)},$n=(e,t)=>{let n=document.createElement(`a`);n.href=e,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n)},er=new WeakMap,tr=e=>{if(!e.complete||e.width===0)return;let t=er.get(e);if(t!==void 0)return t;let n=Ae();if(n){n.canvas.width=e.width,n.canvas.height=e.height;try{n.drawImage(e,0,0);let t=n.canvas.toDataURL(`image/png`);return er.set(e,t),t}catch{return}}},nr=e=>/^blob:/i.test(e),rr=(e,t,n)=>{let r=new AbortController,i,a;return new Promise((o,s)=>{a=setTimeout(()=>s(Error(`Timeout while loading images`)),Ve),e.onload=()=>{e.naturalWidth>16384||e.naturalHeight>16384?s(Error(`The picture is larger than ${He} pixels`)):o()},e.onerror=()=>s(Error(`Some images could not be loaded`)),Zn(t,n,r.signal).then(t=>{r.signal.aborted?Qn(t):(i=t,e.src=t)},s)}).finally(()=>{r.abort(),clearTimeout(a),e.onload=null,e.onerror=null,Qn(i)})},ir=e=>`data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(e))}`,ar={png:`image/png`,jpeg:`image/jpeg`,webp:`image/webp`},or=({shapes:e,settings:t,options:n})=>{let r=document.createElement(`canvas`),i=r.getContext(`2d`);if(!i)throw Error(`No context found for canvas`);let{realHeight:a,realWidth:o}=t.canvasSize;r.width=o,r.height=a,i.clearRect(0,0,o,a),Ce(i);let s=n.format??`png`,c=n.backgroundColor??(s===`jpeg`?`white`:void 0);c&&(i.fillStyle=c,i.fillRect(0,0,o,a)),n.backgroundImage&&(we(i,t),i.drawImage(n.backgroundImage,0,0,t.drawingSize.width,t.drawingSize.height),i.restore());for(let n=e.length-1;n>=0;n--)ei(i,e[n],t);return r.toDataURL(ar[s],n.quality)},sr=(e,t,{width:n,height:r})=>({...e,canvasOffset:t,canvasZoom:1,canvasSize:{...De(n,r),scaleRatioWithNoZoom:1}}),cr=({shapes:e,settings:t,options:n={}})=>{let{view:r=`defaultView`,...i}=n;if(r===`fitToShapes`&&!e.length)throw Error(`No image found to export`);if(r===`fitToShapes`){let n=Je(e.map(e=>e.computed.boundingBox));return or({shapes:e,settings:sr(t,[-n.x,-n.y],n),options:i})}return or(r===`defaultView`?{shapes:e,settings:sr(t,[0,0],t.drawingSize),options:i}:{shapes:e,settings:{...t,canvasSize:{...t.canvasSize,width:t.canvasSize.realWidth,height:t.canvasSize.realHeight,scaleRatio:t.canvasZoom,scaleRatioWithNoZoom:1}},options:i})},lr=(e,t,n)=>ir(Gn(e,t,n)),ur=e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(r.result),r.onerror=()=>n(r.error??Error(`Failed to read file`)),r.readAsDataURL(e)}),dr=async e=>{if(e.size>104857600)throw Error(`The file is larger than ${ne/1024/1024} MB`);return new Promise((t,n)=>{let r=new FileReader;r.onload=e=>{let r=e.target?.result;if(!r)return n(Error(`Impossible de récupérer les données du fichier`));try{t(JSON.parse(r))}catch{n(Error(`Invalid JSON file`))}},r.onerror=()=>n(Error(`Failed to read file`)),r.readAsText(e)})},fr=(e,t)=>{let n=G(e,xa,t),r=wi(e);return{...e,path:r,computed:n}},pr=fr,mr=(e,t,n,r,i,a)=>{let[o,s]=Si(e.width,e.height,n,r,!0),[c,l]=a??[-i.canvasOffset[0]+i.canvasSize.realWidth/i.canvasZoom/2,-i.canvasOffset[1]+i.canvasSize.realHeight/i.canvasZoom/2];return fr({toolId:b,type:`picture`,id:N(`picture`),x:c-o/2,y:l-s/2,width:o,height:s,ratio:s===0?1:o/s,src:t,img:e,style:{opacity:100}},i)},hr=async(e,t,n)=>{if(!(t instanceof File))return await rr(e,t,n),t;if(Jn(t)){let n=await t.text();return await rr(e,qn(n)),n}let[r]=await Promise.all([ur(t),rr(e,URL.createObjectURL(t))]);return r},gr=async(e,t,n,r,i,a)=>{let o=new Image;return mr(o,await hr(o,e,i),t,n,r,a)},_r=new WeakMap,vr=(e,t)=>{let{naturalWidth:n,naturalHeight:r}=t.img,{a:i,b:a,c:o,d:s}=e.getTransform(),c=t.width*Math.hypot(i,a),l=t.height*Math.hypot(o,s);return!n||!r||c<=0||l<=0?0:Math.max(0,Math.floor(Math.log2(Math.min(n/c,r/l))))},yr=(e,t)=>{if(t===0)return e;let n=_r.get(e)??new Map,r=n.get(t);if(r)return r;let i=Ae();return i?(i.canvas.width=Math.ceil(e.naturalWidth/2**t),i.canvas.height=Math.ceil(e.naturalHeight/2**t),i.imageSmoothingQuality=`high`,i.drawImage(e,0,0,i.canvas.width,i.canvas.height),i.canvas.addEventListener(`contextlost`,()=>n.delete(t)),n.set(t,i.canvas),_r.set(e,n),i.canvas):e},br=(e,t)=>{if(e.globalAlpha===0)return;let n=yr(t.img,vr(e,t));e.beginPath(),e.scale(t.flipX?-1:1,t.flipY?-1:1),e.drawImage(n,t.flipX?-t.x-t.width:t.x,t.flipY?-t.y-t.height:t.y,t.width,t.height)},xr=(e,t,n,r,i)=>{let{borderX:a,borderHeight:o,borderY:s,borderWidth:c,isXinverted:l,isYinverted:u}=lt(e,t,n,r,!0,i),d=Math.max(0,c-2*r.selectionPadding),f=Math.max(0,o-2*r.selectionPadding);return fr({...t,width:d,height:f,x:a+r.selectionPadding,y:s+r.selectionPadding,flipX:l?!t.flipX:!!t.flipX,flipY:u?!t.flipY:!!t.flipY},r)},Sr=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=B(e,t,n),l=(e.width===0||e.height===0?e.ratio??1:e.width)*o,u=(e.width===0||e.height===0?e.ratio??1:e.height)*s,d=V(n,c.x,c.y,l,u),f=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation;return fr({...e,width:l,height:u,x:d[0]-l/2,y:d[1]-u/2,flipX:r?!e.flipX:!!e.flipX,flipY:i?!e.flipY:!!e.flipY,rotation:f?-(e.rotation??0):e.rotation??0},a)},Cr=[`Texte`],wr=150,Tr=(e,t)=>G(e,Lr,t),Er=(e,t)=>{let n=Tr(e,t),r=wi(e);return{...e,path:r,computed:n}},Dr=Er,Or=e=>e.length||1,kr=(e,t,n,r,i,a=g)=>(e.font=`${i?`italic`:``} ${r?`bold`:``} ${n}px ${a}`,Math.max(0,...t.map(t=>e.measureText(t).width))),Ar=(e,t,n,r,i,a)=>{let o=n/kr(e,t,1,r,i,a);return Number.isFinite(o)&&o!==0?o:36},jr=[`fontFamily`,`fontBold`,`fontItalic`],Mr=e=>jr.includes(e),Nr=(e,t)=>{let n=Ar(e,t.value,t.width,t.style?.fontBold??!1,t.style?.fontItalic??!1,t.style?.fontFamily),r=n*Or(t.value);return{...t,fontSize:n,height:r,ratio:t.width/r}},Pr=(e,t)=>{if(t.width!==void 0&&t.height!==void 0&&t.fontSize!==void 0)return t;if(t.width!==void 0&&t.fontSize===void 0)return Nr(e,t);let{fontBold:n=!1,fontItalic:r=!1,fontFamily:i}=t.style??{},a=Or(t.value),o=t.fontSize??(t.height===void 0?36:t.height/a),s=t.width??Br(e,t.value,o,n,r,i),c=t.height??o*a;return{...t,fontSize:o,width:s,height:c,ratio:s/c}},Fr=(e,t,n,r)=>{let i=Ar(e,Cr,wr,t.settings?.fontBold.default??!1,t.settings?.fontItalic.default??!1,t.settings.fontFamily.default),a=wr,o=i*Cr.length;return Er({toolId:t.id,type:t.type,id:N(t.type),x:n[0]-a,y:n[1]-o,value:Cr,fontSize:i,width:a,height:o,ratio:a/o,style:{opacity:t.settings.opacity.default,strokeColor:t.settings.strokeColor.default,fontFamily:t.settings.fontFamily.default,fontItalic:t.settings.fontItalic.default,fontBold:t.settings.fontBold.default}},r)},Ir=(e,t)=>{if(e.globalAlpha!==0&&t.style?.strokeColor&&t.style.strokeColor!==`transparent`){e.scale(t.flipX?-1:1,t.flipY?-1:1),e.font=`${t.style?.fontItalic?`italic`:``} ${t.style?.fontBold?`bold`:``} ${t.fontSize}px ${t.style?.fontFamily??`serif`}`,e.textBaseline=`top`,e.fillStyle=t.style.strokeColor;for(let n=0;n<t.value.length;n++)e.fillText(t.value[n],t.flipX?-t.x-t.width:t.x,(t.flipY?-t.y-t.height:t.y)+n*t.fontSize,t.width)}},Lr=(e,t)=>Hi({x:e.x,y:e.y,width:e.width,height:e.height},t.selectionPadding),Rr=(e,t,n,r,i,a)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l,isXinverted:u,isYinverted:d}=lt(t,n,r,i,!0,a),f=Math.max(0,l-2*i.selectionPadding),p=Math.max(0,s-2*i.selectionPadding),m=Er({...n,width:f,height:p,x:o+i.selectionPadding,y:c+i.selectionPadding,flipX:u?!n.flipX:!!n.flipX,flipY:d?!n.flipY:!!n.flipY},i);return{...m,fontSize:Ar(e,m.value,m.width,m.style?.fontBold??!1,m.style?.fontItalic??!1,m.style?.fontFamily)}},zr=(e,t,n,r)=>{let{isXinverted:i,isYinverted:a,settings:o,widthMultiplier:s,heightMultiplier:c}=r,l=(i||a)&&!(i&&a)&&(t.rotation??0)!==0&&r.rotation!==t.rotation,u=B(t,n,r),d=(t.width===0||t.height===0?t.ratio??1:t.width)*s,f=(t.width===0||t.height===0?t.ratio??1:t.height)*c,p=V(r,u.x,u.y,d,f),m=Er({...t,width:d,height:f,x:p[0]-d/2,y:p[1]-f/2,flipX:i?!t.flipX:!!t.flipX,flipY:a?!t.flipY:!!t.flipY,rotation:l?-(t.rotation??0):t.rotation??0},o);return{...m,fontSize:Ar(e,m.value,m.width,m.style?.fontBold??!1,m.style?.fontItalic??!1,m.style?.fontFamily)}},Br=(e,t,n,r,i,a)=>kr(e,t,n,r,i,a)||20,Vr=(e,t,n,r)=>{let i={...t,value:n},a=Br(e,i.value,i.fontSize,i.style?.fontBold??!1,i.style?.fontItalic??!1,i.style?.fontFamily),o=i.fontSize*Or(i.value),s=a/o,c={...i,width:a,height:o,ratio:s},{center:l}=Tr(c,r),[u,d]=Sa([1,1],t.computed.center,t),[f,p]=Sa([1,1],l,c,[!1,!1]);return{...c,x:c.x-(f-u),y:c.y-(p-d)}},Hr=(e,t,n,r)=>{let i=[W(n[0],r),W(n[1],r)];switch(t.type){case`brush`:return Nt(t,i,r);case`line`:return Tn(t,i,r);case`polygon`:return Yt(t,i,r);case`curve`:return on(t,i,r);case`rect`:case`square`:return ya(t,i,r);case`text`:return Fr(e,t,i,r);case`ellipse`:return hn(t,i,r);case`circle`:return Ut(t,i,r)}},Ur=(e,t)=>{switch(t.type){case`brush`:Pt(e,t);break;case`text`:Ir(e,t);break;case`line`:Dn(e,t);break;case`polygon`:Xt(e,t);break;case`curve`:cn(e,t);break;case`circle`:Wt(e,t);break;case`ellipse`:gn(e,t);break;case`rect`:ba(e,t);break;case`square`:ba(e,t);break;case`picture`:br(e,t)}},Wr=e=>e!==void 0&&e!==`transparent`,Gr=(e,t)=>{if(e.type===`picture`)return!1;if(e.type===`text`)return e.value.length>1;let n=e.style?.strokeColor!==`transparent`;return n&&(e.style?.lineWidth??2)*t<=1?!0:e.type===`line`?!!e.arrows?.length:e.type!==`brush`&&n&&Wr(e.style?.fillColor)},Kr=new WeakMap,qr=(e,t)=>Math.min(t,Math.max(32,2**Math.ceil(Math.log2(e)))),Jr=(e,t,n)=>{let r=Kr.get(n);(r?.width!==n.width||r.height!==n.height)&&(r={width:n.width,height:n.height,layers:new Map},Kr.set(n,r));let i=qr(e,n.width),a=qr(t,n.height),o=i*65536+a,s=r.layers.get(o);return s===void 0&&(s=Ae(),s&&(s.canvas.width=i,s.canvas.height=a,Ce(s)),r.layers.set(o,s)),s},Yr=e=>{if(e.type===`text`)return e.fontSize/4;let t=e.style?.lineWidth??2;return e.type===`line`?10+t*2:t/2},Xr=2,Zr=(e,t,n)=>{let{minX:r,minY:i,maxX:a,maxY:o}=Ke([qe(n).map(([e,n])=>[t.a*e+t.c*n+t.e,t.b*e+t.d*n+t.f])]),s=Math.max(0,Math.floor(r)-Xr),c=Math.max(0,Math.floor(i)-Xr);return{x:s,y:c,width:Math.min(e.width,Math.ceil(a)+Xr)-s,height:Math.min(e.height,Math.ceil(o)+Xr)-c}},Qr=(e,t)=>{let n=e.getTransform(),r=Zr(e.canvas,n,Hi(t.computed.outerBorders,Yr(t)));if(r.width<=0||r.height<=0)return;let i=Jr(r.width,r.height,e.canvas);i&&(i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,r.width,r.height),i.setTransform(n.a,n.b,n.c,n.d,n.e-r.x,n.f-r.y),L(i,{...t.style,opacity:100}),Ur(i,t),e.save(),e.setTransform(1,0,0,1,0,0),e.drawImage(i.canvas,0,0,r.width,r.height,r.x,r.y,r.width,r.height),e.restore())},$r=(e,t,n)=>!!ia(e.computed.boundingBox,n??xt(t)),ei=(e,t,n,r)=>{t.visible!==!1&&$r(t,n,r)&&(we(e,n,t.rotation,t.computed.center),L(e,t.style),e.globalAlpha<1&&Gr(t,n.canvasSize.scaleRatio)?Qr(e,t):e.globalAlpha>0&&Ur(e,t),e.restore())},ti=(e,t,n)=>{if(e.locked)return e;let r=R({origin:n,point:e.computed.center,rotation:-t});if(`points`in e){if(e.type===`brush`){let n=e.points.map(t=>t.map(t=>[t[0]+r[0]-e.computed.center[0],t[1]+r[1]-e.computed.center[1]]));return{...e,points:n,rotation:(e.rotation??0)+t}}let i=e.points.map(e=>R({origin:n,point:e,rotation:-t}));return{...e,points:i}}return{...e,x:e.x+r[0]-e.computed.center[0],y:e.y+r[1]-e.computed.center[1],rotation:(e.rotation??0)+t}},ni=(e,t,n,r,i,a,o)=>{if(n.locked)return n;switch(n.type){case`line`:return On(t,n,r,i);case`polygon`:return Qt(t,n,r,i);case`curve`:return sn(t,n,r,i);case`brush`:return Ft(t,n,r,i,a,o);case`circle`:return Gt(t,n,r,i,o);case`ellipse`:return _n(t,n,r,i,a,o);case`rect`:case`square`:return Ca(t,n,r,i,n.type===`square`||a,o);case`text`:return Rr(e,t,n,r,i,o);case`picture`:return xr(t,n,r,i,o);default:return n}},ri=e=>{let t=e.filter(e=>f.includes(e.type)),n=!t.some(e=>(e.rotation??0)!==(t[0]?.rotation??0)),r=(t[0]?.rotation??0)!==0&&t.length!==e.length,i=e.some(e=>p.includes(e.type));return!n||i||r},ii=(e,t,n,r)=>{if(t.locked)return t;let i=n;switch(t.type){case`rect`:case`square`:return wa(t,i,r);case`picture`:return Sr(t,i,r);case`text`:return zr(e,t,i,r);case`ellipse`:return vn(t,i,r);case`circle`:return Kt(t,i,r);case`brush`:return It(t,i,r);case`line`:case`polygon`:case`curve`:return An(t,i,r);default:return t}},ai=(e,t,n,r,i,a,o)=>{if(n.type!==`group`)return I(n).map(n=>ni(e,t,n,r,i,a,o));let s=n,c=I(s),l=kt(t,s,r,i,a||ri(c),o);return c.map(n=>n.type===`group`?ni(e,t,n,r,i,a,o):ii(e,n,s,l))},oi=(e,t)=>{let{borders:n}=e.computed,r=t.selectionPadding;return{x:n.x+r,y:n.y+r,width:n.width-2*r,height:n.height-2*r}},si=(e,t,n,r)=>{let i=q(t,r);if(!i)return t;let a=oi(i,r),{width:o,height:s}=n;if(ri(t)&&a.width>0&&a.height>0){let e=Math.min(o/a.width,s/a.height);o=a.width*e,s=a.height*e}let c=r.selectionPadding,l=Ot(i,{x:n.x-c,y:n.y-c,width:o+2*c,height:s+2*c},r);return t.map(t=>ii(e,t,i,l))},ci=(e,t,n,r)=>{let i=q(t,r);if(!i)return[];let a={...Ot(i,i.computed.borders,r,{isXinverted:n===`flipHorizontally`,isYinverted:n===`flipVertically`,rotation:0}),widthMultiplier:1,heightMultiplier:1,groupCenter:i.computed.center};return t.map(t=>ii(e,t,i,a))},li=(e,t,n,r)=>{if(e.locked)return e;switch(e.type){case`rect`:case`square`:case`ellipse`:case`circle`:case`picture`:case`text`:return H({...e,x:e.x+t,y:e.y+n},r);case`line`:case`polygon`:case`curve`:return H({...e,points:e.points.map(([e,r])=>[e+t,r+n])},r);case`brush`:return H({...e,points:e.points.map(e=>e.map(([e,r])=>[e+t,r+n]))},r);default:return e}},ui=(e,t,n,r,i)=>{let a=t.computed.borders,o=bi([e[0]-n[0],e[1]-n[1]],i),s=o[0]===0?0:W(a.x+r.selectionPadding+o[0],r)-(a.x+r.selectionPadding),c=o[1]===0?0:W(a.y+r.selectionPadding+o[1],r)-(a.y+r.selectionPadding);return I(t).map(e=>li(e,s,c,r))},H=(e,t)=>{switch(e.type){case`rect`:case`square`:return va(e,t);case`ellipse`:return mn(e,t);case`circle`:return Ht(e,t);case`picture`:return pr(e,t);case`text`:return Dr(e,t);case`line`:return wn(e,t);case`polygon`:return Jt(e,t);case`curve`:return an(e,t);case`brush`:return Mt(e,t);default:return e}},di=(e,t)=>(e?.type===`polygon`||e?.type===`curve`)&&t!==void 0&&t>=0&&t<e.points.length&&e.points.length>2,fi=(e,t,n,r)=>{let i=Object.keys(n).filter(e=>t.type===`text`||!Mr(e));if(!i.length)return t;let a={...t,style:{...t.style,...Object.fromEntries(i.map(e=>[e,n[e]]))}};return a.type===`text`&&i.some(Mr)?H(Nr(e,a),r):H(a,r)},pi=({ctx:e,shape:t,settings:n,selectionWidth:r,selectionColor:i,hoverMode:a,selectionMode:o,withAnchors:s=!0})=>{switch(n.debug&&tt(e,t,r,n),t.type){case`rect`:case`square`:case`circle`:case`ellipse`:case`picture`:case`text`:case`brush`:nt(e,t,i,r,n,s);break;case`group`:ut(e,t,i,r,o,n,s);break;case`polygon`:case`line`:case`curve`:dt({ctx:e,shape:t,withAnchors:s,selectionWidth:r,selectionColor:i,hoverMode:a,settings:n})}e.restore()},mi=({ctx:e,selectionFrame:t,settings:n})=>{we(e,n),ft(e,t.frame,n),e.restore()},hi=e=>({...e,id:N(e.type),...e.data?{data:structuredClone(e.data)}:{}}),gi=(e,t)=>I(e).map(e=>hi(li(e,20,20,t))),U=(e,t=2)=>{let n=10**t;return Math.round(e*n)/n},_i=(e,t,n,r=1,i=1)=>[t+(e[0]-t)*r,n+(e[1]-n)*i],vi=(e,t)=>{let n=e>=0?t:-t;return e+n/2-(e+n/2)%n},W=(e,t,n=0)=>t.gridGap?vi(e+n,t.gridGap)-n:U(e),yi=(e,t,n)=>!t.gridGap&&!n?U(e,3):vi(e,Math.PI/18),bi=(e,t)=>t?[Math.abs(e[0])>Math.abs(e[1])?e[0]:0,Math.abs(e[1])>Math.abs(e[0])?e[1]:0]:e,xi=(e,t,n,r,i,a,o)=>{if(r.mode===`translate`)return ui(n,r.originalShape,r.cursorStartPosition,i,a);if(r.mode===`rotate`){let{originalShape:e,cursorStartPosition:t}=r,o=e.computed.center,[s,c]=o,l=yi(Math.atan2(c-n[1],s-n[0])-Math.atan2(c-t[1],s-t[0]),i,a);return I(e).map(e=>H(ti(e,l,o),i))}return r.mode===`resize`?ai(e,n,r.originalShape,r,i,a,o):r.mode===`brush`?I(t).map(e=>Rt(e,n,i)):I(t)},Si=(e,t,n,r,i=!1)=>{if(!e||!t||!r||!n)return[300,300];let a=e/t;if(a>n/r){let t=i?n:Math.min(e,n);return[t,t/a]}let o=i?r:Math.min(t,r);return[o*a,o]},Ci=({line:e,size:t,direction:n})=>{let r=Math.PI/2-Ze({targetVector:[e.points[0],e.points[1]]}),i=[e.points[0][0]+(e.points[1][0]-e.points[0][0])/2,e.points[0][1]+(e.points[1][1]-e.points[0][1])/2],a;if([`start`,`both`].includes(n)){let n=R({point:e.points[0],origin:i,rotation:-r});a=R({point:[n[0],n[1]+t],origin:i,rotation:r})}else a=[...e.points[0]];let o;if([`end`,`both`].includes(n)){let n=R({point:e.points[1],origin:i,rotation:-r});o=R({point:[n[0],n[1]-t],origin:i,rotation:r})}else o=[...e.points[1]];return{points:[a,o]}},wi=e=>{let t=new Path2D;return t.rect(e.x,e.y,e.width,e.height),t},Ti=e=>{let t=new Path2D;return t.arc(e.x,e.y,e.radius,0,2*Math.PI),t},Ei=e=>{let t=new Path2D;return t.ellipse(e.x,e.y,e.radiusX,e.radiusY,0,0,2*Math.PI),t},Di=e=>{let t=new Path2D;return t.moveTo(...e.points[0]),t.lineTo(...e.points[1]),t},Oi=new WeakMap,ki=e=>Oi.get(e)??Ke(e),Ai=(e,t,n)=>{let r=[...e];r[t]=[...e[t]??[],n];let{minX:i,minY:a,maxX:o,maxY:s}=ki(e);return Oi.set(r,{minX:Math.min(i,n[0]),minY:Math.min(a,n[1]),maxX:Math.max(o,n[0]),maxY:Math.max(s,n[1])}),r},ji=e=>(e.scaleX??1)===1&&(e.scaleY??1)===1,Mi=e=>e,Ni=e=>{if(ji(e))return Mi;let{minX:t,minY:n}=ki(e.points);return r=>_i(r,t,n,e.scaleX,e.scaleY)},Pi=(e,t,{brushAlgo:n})=>{if(!ji(e)||n===`quadratic`||e.points[e.points.length-1].length<2)return;let r=new Path2D(e.path);return r.lineTo(...t),r},Fi=(e,{brushAlgo:t})=>{let n=new Path2D;if(e.points.length<1)return n;let r=Ni(e);for(let i of e.points)if(i.length){if(i.length===1)n.rect(...r(i[0]),1,1);else switch(n.moveTo(...r(i[0])),t){case`quadratic`:{let e=r(i[1]);for(let t=1;t<i.length-2;t++){let a=r(i[t+1]),o=(e[0]+a[0])/2,s=(e[1]+a[1])/2;n.quadraticCurveTo(...e,o,s),e=a}n.quadraticCurveTo(...r(i[i.length-2]),...r(i[i.length-1]));break}default:for(let e=1;e<i.length;e++)n.lineTo(...r(i[e]))}}return n},Ii=(e,t,n,r)=>{let i=i=>(1-i)**3*e[0]+3*(1-i)**2*i*t[0]+3*(1-i)*i**2*n[0]+i**3*r[0],a=i=>(1-i)**3*e[1]+3*(1-i)**2*i*t[1]+3*(1-i)*i**2*n[1]+i**3*r[1],o=(e,t,n)=>{let r=e-2*t+n,i=-2*e+2*t,a=e;if(Math.abs(r)<1e-10){if(Math.abs(i)<1e-10)return[];let e=-a/i;return e>0&&e<1?[e]:[]}let o=i*i-4*r*a;if(o<0)return[];let s=Math.sqrt(o),c=(-i-s)/(2*r),l=(-i+s)/(2*r),u=[];return c>0&&c<1&&u.push(c),l>0&&l<1&&l!==c&&u.push(l),u},s=e[0],c=t[0],l=n[0],u=r[0],d=e[1],f=t[1],p=n[1],m=r[1],h=o(c-s,l-c,u-l),g=o(f-d,p-f,m-p),_=Math.min(e[0],r[0]),v=Math.max(e[0],r[0]),y=Math.min(e[1],r[1]),b=Math.max(e[1],r[1]);for(let e of h){let t=i(e);_=Math.min(_,t),v=Math.max(v,t)}for(let e of g){let t=a(e);y=Math.min(y,t),b=Math.max(b,t)}return{minX:_,maxX:v,minY:y,maxY:b}},Li=(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]],Ri=(e,t,n,r)=>({cp1:[t[0]+(n[0]-e[0])/6,t[1]+(n[1]-e[1])/6],cp2:[n[0]-(r[0]-t[0])/6,n[1]-(r[1]-t[1])/6]}),zi=e=>{let t=new Path2D,n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2)return t;if(n.length<3)return Bi(e);let r=e.style?.closedPoints===1&&n.length>2;t.moveTo(...n[0]);let i=Li(e,n);for(let e=1;e<i.length-2;e++){let n=i[e-1],r=i[e],a=i[e+1],o=i[e+2],{cp1:s,cp2:c}=Ri(n,r,a,o);t.bezierCurveTo(s[0],s[1],c[0],c[1],a[0],a[1])}return r&&t.closePath(),t},Bi=e=>{let t=new Path2D,n=e.tempPoint?[...e.points,e.tempPoint]:e.points;if(n.length<2)return t;t.moveTo(...n[0]);for(let e of n.slice(1))t.lineTo(...e);return n.length>2&&e.style?.closedPoints===1&&t.lineTo(...n[0]),t},Vi=e=>{let 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},Hi=(e,t)=>({x:e.x-t,y:e.y-t,width:e.width+t*2,height:e.height+t*2}),Ui=(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)}),Wi=(e,t,n=0)=>{if(n===0)return e;let{minX:r,minY:i,maxX:a,maxY:o}=Ke([qe(e).map(e=>R({point:e,origin:t,rotation:n}))]);return{x:r,y:i,width:a-r,height:o-i}},G=(e,t,n,r=Ui)=>{let i=t(e,n),a=r(e,i,n),o=[i.x+i.width/2,i.y+i.height/2];return{borders:i,outerBorders:a,center:o,boundingBox:Wi(a,o,e.rotation)}},Gi=(e,t,n)=>{let{clientX:r,clientY:i}=e,a=t.getBoundingClientRect();return[(r-a.left)/n.scaleRatio,(i-a.top)/n.scaleRatio]},Ki=({clientX:e,clientY:t},{left:n,top:r,width:i,height:a},{canvasSize:o,canvasOffset:s})=>[(e-n)*(o.width/i)/o.scaleRatio-s[0],(t-r)*(o.height/a)/o.scaleRatio-s[1]],qi=(e,{left:t,top:n,width:r,height:i},{canvasSize:a,canvasOffset:o})=>({x:t+(e[0]+o[0])*a.scaleRatio*r/a.width,y:n+(e[1]+o[1])*a.scaleRatio*i/a.height}),Ji=(e,t,n)=>Ki(e,t.getBoundingClientRect(),n),Yi=e=>e.pointerType===`touch`,K=(e,t,[n,r])=>R({origin:[n,r],point:e,rotation:t}),Xi=(e,t,[n,r])=>R({origin:[n,r],point:e,rotation:-t}),Zi=(e,t,n)=>n?Ye(e,{x:t[0],y:t[1],radius:n}):Ge(e,t),Qi=(e,t,n,r=0)=>{let i=Ne(n),a=([e,n])=>Zi({x:e-i,y:n-i,width:i*2,height:i*2},t,r);if(Me(e)){let t=e.points.findIndex(e=>a(e));return t>-1&&{mode:`resize`,anchor:t}}let{borders:o}=e.computed;if(a(Pe(o,n)))return{mode:`rotate`};let s=d.find(e=>a(Fe(o,e)));return s?{mode:`resize`,anchor:s}:!1},$i=(e,t,n,r,i=!1,a=0)=>{let o=I(t).length>1?t:I(t)[0];if(!o)return!1;let{borders:s,center:c}=o.computed,l=K(n,o.rotation??0,c);if(i){let e=Qi(o,l,r,a);if(e)return e}return Me(o)?(e.lineWidth=(o.style?.lineWidth??0)+15/r.canvasZoom,(na(o,!0)?e.isPointInPath(o.path,l[0],l[1]):e.isPointInStroke(o.path,l[0],l[1]))?{mode:`translate`}:!1):Zi(s,l,(15+a)/r.canvasZoom)?{mode:`translate`}:!1},ea=(e,t,n,r,i=50)=>{if(t.locked||t.points.length<2)return!1;let{center:a}=t.computed,o=K(n,t.rotation??0,a);e.lineWidth=(t.style?.lineWidth??0)+i/r.canvasZoom;let s=t.style?.closedPoints?[...t.points,t.points[0]]:t.points;for(let t=0;t<s.length-1;t++){let n=Di({points:[s[t],s[t+1]]});if(e.isPointInStroke(n,o[0],o[1]))return{lineIndex:t}}return!1},ta=(e,t,n,r,i=50)=>{if(t.locked||t.points.length<2)return!1;if(t.points.length<3)return ea(e,t,n,r,i);let{center:a}=t.computed,o=K(n,t.rotation??0,a);e.lineWidth=(t.style?.lineWidth??0)+i/r.canvasZoom;let s=Li(t,t.points),c=new Path2D;c.moveTo(...s[0]);for(let t=1;t<s.length-2;t++){let n=s[t-1],r=s[t],i=s[t+1],a=s[t+2],{cp1:l,cp2:u}=Ri(n,r,i,a);if(c.bezierCurveTo(l[0],l[1],u[0],u[1],i[0],i[1]),e.isPointInStroke(c,o[0],o[1]))return{lineIndex:t-1}}return!1},na=(e,t=!1)=>t&&[`curve`,`polygon`].includes(e.type)?!0:e.style?.fillColor&&e.style?.fillColor!==`transparent`||[`picture`,`text`].includes(e.type),ra=(e,t,n,r)=>{let{center:i}=t.computed,a=K(n,t.rotation??0,i);return e.lineWidth=(t.style?.lineWidth??0)+15/r.canvasZoom,(na(t)?e.isPointInPath(t.path,a[0],a[1]):e.isPointInStroke(t.path,a[0],a[1]))?{mode:`translate`}:!1};function ia(e,t){let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+(e.width||1),t.x+(t.width||1)),a=Math.min(e.y+(e.height||1),t.y+(t.height||1));if(n<i&&r<a)return{x:n,y:r,width:i-n,height:a-r}}var aa=({ctx:e,path:t,rect:n,offset:r,center:i,rotation:a=0,checkFill:o})=>{for(let s=0;s<r;s+=r/2)for(let c=0;c<r;c+=r/2)for(let l=s+n.x;l<n.x+n.width;l+=r)for(let s=c+n.y;s<n.y+n.height;s+=r){let n=K([l,s],a,i);if(o?e.isPointInPath(t,n[0],n[1]):e.isPointInStroke(t,n[0],n[1]))return!0}return!1},oa=10,sa=1,ca=(e,t)=>{switch(e.type){case`rect`:case`square`:{let n=Hi(e,-t);return e=>Ge(n,e)}case`circle`:case`ellipse`:{let n=Math.abs(e.type===`circle`?e.radius:e.radiusX),r=Math.abs(e.type===`circle`?e.radius:e.radiusY),i=1-t/Math.min(n,r);return i<=0?void 0:([t,a])=>((t-e.x)/n)**2+((a-e.y)/r)**2<i**2}default:return}},la=(e,t,n)=>{let r=ca(e,n+sa);if(!r)return!1;let{center:i}=e.computed;return qe(t).every(t=>r(K(t,e.rotation??0,i)))},ua=(e,t,n)=>{let{borders:r,center:i,boundingBox:a}=t.computed,o=Math.min(n[0][0],n[1][0]),s=Math.max(n[0][0],n[1][0]),c=Math.min(n[0][1],n[1][1]),l=Math.max(n[0][1],n[1][1]),u={x:o,y:c,width:s-o,height:l-c},d=ia(a,u);if(!d)return!1;if(r.width<=1||r.height<=1||a.x>=o&&a.y>=c&&a.x+a.width<=s&&a.y+a.height<=l)return!0;let f=(t.style?.lineWidth??0)+oa;if(e.lineWidth=f,t.type===`brush`){let n=Ni(t);for(let r of t.points){if(r.length<1)break;if(r.length<2){let e=n(r[0]);if(Ye(d,{x:e[0],y:e[1],radius:(t.style?.lineWidth??1)/2}))return!0}for(let a=0;a<r.length-1;a++){let o=Xi(n(r[a]),t.rotation??0,i),s=Xi(n(r[a+1]),t.rotation??0,i),c=ia({x:Math.min(o[0],s[0]),y:Math.min(o[1],s[1]),width:Math.abs(o[0]-s[0]),height:Math.abs(o[1]-s[1])},u);if(c){let t=new Path2D;if(t.moveTo(...o),t.lineTo(...s),aa({ctx:e,path:t,rect:c,offset:oa,center:i,checkFill:!1}))return!0}}}return!1}let p=na(t);return!p&&la(t,d,f/2)?!1:aa({ctx:e,path:t.path,rect:d,offset:oa,center:i,rotation:t.rotation??0,checkFill:p})},da=5,fa=(e,t,n=da)=>{let r=e.clientX-t.clientX,i=e.clientY-t.clientY;return r*r+i*i>n*n},pa=(e,t)=>!Yi(e)||fa(e,t),ma=(e,t,n,r)=>t.visible!==!1&&Ge(t.computed.boundingBox,n)&&!!ra(e,t,n,r),ha=(e,t,n,r)=>t.filter(t=>ma(e,t,n,r)),ga=(e,t,n,r)=>t.find(t=>ma(e,t,n,r)),_a=(e,t)=>{let n=wi(e),r=G(e,xa,t);return{...e,path:n,computed:r}},va=_a,ya=(e,t,n,r=0,i=0)=>_a({toolId:e.id,type:e.type,id:N(e.type),x:t[0],y:t[1],width:r,height:i,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}},n),ba=(e,t)=>{Te(e,t.path,t.style)},xa=(e,t)=>Hi(e,t.selectionPadding),Sa=(e,t,n,[r,i]=[!1,!1])=>Xi([e[0]===.5?n.x+n.width/2:e[0]===0?n.x+(r?0:n.width):n.x+(r?n.width:0),e[1]===.5?n.y+n.height/2:e[1]===0?n.y+(i?0:n.height):n.y+(i?n.height:0)],n.rotation??0,t),Ca=(e,t,n,r,i=!1,a=!1)=>{let{borderX:o,borderHeight:s,borderY:c,borderWidth:l}=lt(e,t,n,r,i,a);return _a({...t,width:Math.max(0,l-2*r.selectionPadding),height:Math.max(0,s-2*r.selectionPadding),x:o+r.selectionPadding,y:c+r.selectionPadding},r)},wa=(e,t,n)=>{let{isXinverted:r,isYinverted:i,settings:a,widthMultiplier:o,heightMultiplier:s}=n,c=(r||i)&&!(r&&i)&&(e.rotation??0)!==0&&n.rotation!==e.rotation,l=B(e,t,n),u=(e.width||1)*o,d=(e.height||1)*s,f=V(n,l.x,l.y,u,d);return _a({...e,width:u,height:d,x:f[0]-u/2,y:f[1]-d/2,rotation:c?-(e.rotation??0):e.rotation??0},a)},Ta=({mode:e})=>e==="default"||e===`contextMenu`||e===`textedition`,Ea=(e,t,n)=>{if(e.mode===`translate`)return{mode:`translate`,cursorStartPosition:n,originalShape:t,hasBeenDuplicated:!1,dateStart:Date.now(),selectedShapesLengthAtMouseDown:I(t).length};if(e.mode===`rotate`){let{center:e}=t.computed;return{mode:`rotate`,cursorStartPosition:n,originalShape:t,center:[e[0],e[1]],selectedShapesLengthAtMouseDown:I(t).length}}if(e.mode===`resize`)return{mode:`resize`,cursorStartPosition:n,originalShape:t,anchor:e.anchor,selectedShapesLengthAtMouseDown:I(t).length}},Da=(e,t,n,r,i,a,o,s=`replace`,c=!0)=>{let l=a?20:void 0,u=!1;if(i){u=$i(e,i,n,r,!0,l);let t=Ea(u||{mode:`default`},i,n);if(t?.mode===`resize`||t?.mode===`rotate`)return{shape:i,mode:t}}let d=new Set(I(i).map(e=>e.id)),f=t=>d.has(t.id)?u&&$i(e,t,n,r,!0,l):ra(e,t,n,r),p=c&&t.find(e=>d.has(e.id)&&f(e))||t.find(f)||(u?i:void 0),m=s===`toggle`?p&&d.has(p.id)?`remove`:`add`:s;if(i&&i?.id===p?.id)return{shape:i,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:i,selectedShapesLengthAtMouseDown:I(i).length}};if(p?.locked&&m===`add`)return{shape:i,mode:{mode:o?`selectionFrame`:`default`}};if(p&&m===`add`&&i?.locked){let e=q([p],r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:I(i).length}}}if(p){if(m===`add`){let e=q(ka(i,[p]),r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:I(i).length}}}if(m===`remove`){let e=q(Aa(i,[p]),r);return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:I(i).length}}}let e=d.has(p.id)?i:p;return{shape:e,mode:{mode:`translate`,cursorStartPosition:n,hasBeenDuplicated:!1,dateStart:Date.now(),originalShape:e,selectedShapesLengthAtMouseDown:I(i).length}}}return{shape:s===`replace`?void 0:i,mode:{mode:o?`selectionFrame`:`default`}}},Oa=(e,t,n)=>{let{minX:r,minY:i,maxX:a,maxY:o}=Ke(e.map(e=>[[e.computed.borders.x+n.selectionPadding,e.computed.borders.y+n.selectionPadding],[e.computed.borders.x-n.selectionPadding+e.computed.borders.width,e.computed.borders.y+n.selectionPadding],[e.computed.borders.x-n.selectionPadding+e.computed.borders.width,e.computed.borders.y-n.selectionPadding+e.computed.borders.height],[e.computed.borders.x+n.selectionPadding,e.computed.borders.y-n.selectionPadding+e.computed.borders.height]].map(n=>{let r=R({point:[n[0],n[1]],origin:e.computed.center,rotation:-(e.rotation??0)});return R({point:[r[0],r[1]],origin:[0,0],rotation:t})}))),s=[(r+a)/2,(i+o)/2],c=R({point:s,origin:[0,0],rotation:-t}),l=[s[0]-c[0],s[1]-c[1]],u=U(r-l[0]),d=U(a-l[0]),f=U(i-l[1]),p=U(o-l[1]);return{width:d-u,height:p-f,x:u,y:f}},q=(e,t)=>{if(!e.length)return;if(e.length===1)return e[0];let n=e.some(t=>t.rotation!==e[0].rotation)?0:e[0]?.rotation??0,r=Oa(e,n,t),i=ya({id:`group_selection`,type:`rect`,settings:T},[r.x,r.y],t,r.width,r.height),a=e.slice(1).reduce((e,t)=>{let n=t.style??{},r={};for(let t in n)e[t]!==void 0&&n[t]!==void 0&&e[t]===n[t]&&(r[t]=e[t]);return r},e[0].style??{});return{id:e.map(e=>e.id).join(`-`),type:`group`,shapes:e,rotation:n,visible:!0,locked:!1,x:i.x,y:i.y,width:i.width,height:i.height,style:a,computed:i.computed,path:i.path}},ka=(e,t)=>{let n=I(e);return[...new Set([...n,...t])]},Aa=(e,t)=>{let n=new Set(t.map(e=>e.id));return I(e).filter(e=>!n.has(e.id))},J=e=>{let t,n;return(...r)=>(M(t,r)||(t=r,n=e(...r)),n)},Y=()=>{let e;return t=>((e===void 0||!M(e,t))&&(e=t),e)},ja=(e,t)=>[v,y,...e].find(e=>e.id===t),Ma=()=>{let e=J((e,t,n)=>({edition:e&&!t,zoom:n===`always`&&!t})),t=({config:t})=>e(t.mode!==`viewer`,t.disabled,t.options.canZoom),n=e=>{let{edition:n,zoom:r}=t(e);return n||r},r=J((e,t,n,r,i,a,o,s,c,l,u,d)=>({brushAlgo:e,isBrushShapeDoneOnMouseUp:t,debug:n,canvasSize:{realWidth:a.realWidth,realHeight:a.realHeight,width:a.width,height:a.height,scaleRatioWithNoZoom:a.scaleRatio,scaleRatio:a.scaleRatio*l},drawingSize:{width:o,height:s},size:r,canvasOffset:c,canvasZoom:l,gridGap:u,selectionPadding:i,features:d})),i=J(e=>{let{options:n,width:i,height:a}=e.config,{canvasSize:o,transformation:s,gridGap:c}=e.view;return r(n.brushAlgo,n.isBrushShapeDoneOnMouseUp,n.debug,n.size,n.canvasSelectionPadding,o,i,a,s.offset,s.zoom,c,t(e))}),a=J((e,t)=>ja(e,t)??v),o=({tools:e})=>a(e.available,e.activeToolId),s=J(I),c=Y(),l=J(e=>c(e.map(e=>e.id))),u=J((e,t)=>t===void 0?void 0:e.find(e=>e.id===t)),d=({document:e,interaction:t})=>u(e.shapes,t.hoveredShapeId),f=({config:e})=>e.options.withContextMenu&&e.mode!==`viewer`&&!e.disabled,p=e=>e.config.options.withDropPicture&&t(e).edition&&e.tools.available.some(e=>e.type===`picture`),m=Y(),h=Y(),g=Y(),_=Y(),y=Y(),b=Y(),x=Y(),S=J((e,t)=>{if(!e||t.mode!==`contextMenu`)return;let n=I(t.originalShape),r=typeof t.anchor==`number`?t.anchor:void 0;return{shapes:n,anchorIndex:r,canRemoveAnchor:n.length===1&&di(n[0],r),canvasPosition:t.cursorStartPosition,clientPosition:t.clientPosition}}),C=({interaction:e})=>e.hoverMode.mode==="default"||!Ta(e.selectionMode)?void 0:e.hoverMode,w=J(e=>{let{config:n,document:r,view:a,interaction:c}=e,{history:u}=r,{zoom:v,offset:w}=a.transformation,T=f(e),E=s(r.selectedShape);return x({mode:n.mode,disabled:n.disabled,features:t(e),width:n.width,height:n.height,layout:m({size:n.options.size,resize:n.options.resize}),view:g({zoom:v,offset:w,displayWidth:a.canvasSize.width,displayHeight:a.canvasSize.height,scaleRatio:a.canvasSize.scaleRatio*v,visibleArea:h(xt(i(e)))}),options:n.options,gridGap:a.gridGap,shapes:r.shapes,selection:r.selectedShape,selectedShapes:E,selectedShapeIds:l(E),activeTool:o(e),tools:e.tools.available,history:_({canUndo:u.cursor>0,canRedo:u.cursor<u.states.length-1,canClear:r.shapes.length>0}),clipboard:y({hasContent:e.clipboard!==void 0}),withContextMenu:T,withDropPicture:p(e),interaction:b({mode:c.selectionMode.mode,hoveredShape:d(e),selectionHover:C(e),selectionFrame:c.selectionFrame?.frame,modifiers:c.modifiers,isPanning:c.panStart!==void 0,focus:c.focus}),contextMenu:S(T,c.selectionMode)})}),T=J((e,t,n)=>{if(e.mode!==`textedition`)return;let r=I(t)[0];return r?.type===`text`?{shape:r,defaultValue:e.defaultValue,settings:n}:void 0}),E=Y();return{selectFeatures:t,selectIsInteractive:n,selectSettings:i,selectActiveTool:o,selectSelectedShapes:s,selectHoveredShape:d,selectWithContextMenu:f,selectWithDropPicture:p,selectEditorState:w,selectCanvasView:J(e=>{let{config:n,view:r,document:a,interaction:o}=e;return E({width:n.width,height:n.height,canvasSize:r.canvasSize,resize:n.options.resize,isEditMode:n.mode!==`viewer`,features:t(e),textEdition:T(o.selectionMode,a.selectedShape,i(e))})}),selectCursor:e=>{let{panStart:t,hoverMode:n,modifiers:r}=e.interaction,i=o(e);return t?`grabbing`:n.outOfView?`default`:n.mode===`resize`?`pointer`:i.type!==`selection`&&i.type!==`move`?`crosshair`:n.mode===`translate`?`move`:n.mode===`rotate`||i.type===`move`||r.space?`grab`:`default`}}},Na=(e,t)=>{let{canvasSize:{width:n,height:r},gridGap:i,canvasOffset:a,canvasSize:{scaleRatio:o}}=t;if(!i)return;e.strokeStyle=`rgb(220,220,220)`,e.lineWidth=1,e.save(),e.scale(o,o),e.beginPath();let s=a[0]%i,c=a[1]%i,l=Math.ceil(n/o/i)+2,u=Math.ceil(r/o/i)+2;for(let t=-5;t<l;t++)e.moveTo(s+(t+1)*i,c-i),e.lineTo(s+(t+1)*i,c+r/o+i);for(let t=-5;t<u;t++)e.moveTo(s-i,c+(t+1)*i),e.lineTo(s+n/o+i,c+(t+1)*i);e.stroke(),e.restore()},Pa=(e,t,n)=>{let r=I(t);if(!r.length)return e;let i=new Map(r.map(e=>[e.id,e])),a=[];for(let r of e)n&&r===t||a.push(i.get(r.id)??r);return a},Fa=(e,t,n)=>{Ce(e),Tt(e,n),Na(e,n);let r=xt(n);for(let i=t.length-1;i>=0;i--)ei(e,t[i],n,r)},Ia=(e,t,n,r,i,a,o)=>{let{selectedShape:s}=t.document,{selectionMode:c,hoverMode:l,selectionFrame:u}=t.interaction;e.reset(),wt(e,n),t.config.options.withSkeleton&&i&&!I(s).find(e=>e.id===i.id)&&r.type===`selection`&&Ta(c)&&pi({ctx:e,shape:i,settings:n,selectionWidth:a,selectionColor:o,hoverMode:l,selectionMode:c,withAnchors:!1}),s&&r.type!==`brush`&&pi({ctx:e,shape:s,settings:n,selectionWidth:a,selectionColor:o,hoverMode:l,selectionMode:c,withAnchors:c.mode!==`textedition`}),u&&mi({ctx:e,selectionFrame:u,settings:n})},La=({store:e,drawCanvas:n,selectionCanvasRef:r,selectionColor:i,selectionWidth:a,canvasSize:o})=>{let s=(0,t.useRef)([]);(0,t.useEffect)(()=>{let t=(t,n)=>{let r=0,i=()=>{cancelAnimationFrame(r),r=0,n(e.getState())},a=()=>{r||(r=requestAnimationFrame(i))};a();let o=e.watch(t,a,M);return{drawNow:i,stop:()=>{o(),cancelAnimationFrame(r)}}},o=Y(),c=J((e,t,n)=>o(Pa(e,t,n))),l=e=>c(e.document.shapes,e.document.selectedShape,e.interaction.selectionMode.mode===`textedition`),u=t(t=>[l(t),e.getSettings(t)],t=>{let r=n?.getContext(`2d`);r&&Fa(r,l(t),e.getSettings(t))}),d=t(t=>[t.document.selectedShape,e.getSettings(t),t.interaction.selectionMode,e.selectors.selectHoveredShape(t),t.interaction.hoverMode,t.interaction.selectionFrame,e.selectors.selectActiveTool(t),t.config.options.withSkeleton],t=>{let n=r.current?.getContext(`2d`);n&&Ia(n,t,e.getSettings(t),e.selectors.selectActiveTool(t),e.selectors.selectHoveredShape(t),a,i)});return s.current=[u,d],()=>{u.stop(),d.stop()}},[e,n,r,i,a]),(0,t.useLayoutEffect)(()=>{for(let e of s.current)e.drawNow()},[o.width,o.height])},Ra=()=>{let e,t,n=()=>{e=void 0,t=void 0};return{press:t=>{e=t.button===0?t:void 0},reset:n,release:r=>{let i=e;if(!i||i.pointerId!==r.pointerId||fa(r,i)||r.timeStamp-i.timeStamp>=500){n();return}e=void 0;let a=!!t&&r.timeStamp-t.timeStamp<300&&!fa(r,t,Yi(r)?20:void 0);return t=a?void 0:r,a?`doubleClick`:`click`}}},za=500,Ba=(e,t,n)=>{let r=e*n.canvasZoom,i=r<50?r-50:r>t-50?r-(t-50):0;return Math.ceil(se(i,-100,100)/5/n.canvasZoom)},Va=(e,t,n)=>{let[r,i]=Gi(e,t,n.canvasSize),{width:a,height:o,scaleRatioWithNoZoom:s}=n.canvasSize;return[Ba(r,a/s,n),Ba(i,o/s,n)]},Ha=(e,t)=>Ge(t.getBoundingClientRect(),[e.clientX,e.clientY]),Ua=(e,n)=>{(0,t.useEffect)(()=>{if(!n)return;let t=null,r=Ra(),i=new Set,a,o=()=>{let t=e.getState();return{state:t,settings:e.getSettings(t),activeTool:e.selectors.selectActiveTool(t),ctx:n.getContext(`2d`)}},s=t=>{let{state:r,settings:i,activeTool:a,ctx:s}=o();s&&e.batch(()=>{if(a.id!==v.id||!e.selectors.selectWithContextMenu(r)){e.setSelectedShape(void 0),e.setSelectionMode({mode:`default`}),e.setActiveTool(v),e.setSelectionFrame(void 0);return}let o=Ji(t,n,i),{shape:c,mode:l}=Da(s,r.document.shapes,o,i,r.document.selectedShape,Yi(t),!1);e.showContextMenu({cursorStartPosition:o,clientPosition:{x:t.clientX,y:t.clientY},originalShape:c,anchor:`anchor`in l?l.anchor:void 0})})},c=r=>{if(a!==void 0&&r.pointerId!==a||(t&&pa(r,t.startPosition)&&clearTimeout(t.timeout),i.size>1||!e.selectors.selectIsInteractive(e.getState())))return;let{state:s,settings:c,ctx:l}=o();if(!l)return;let{selectionMode:u,panStart:d,modifiers:f}=s.interaction,{selectedShape:p}=s.document,m=Ji(r,n,c);if(u.mode===`selectionFrame`){e.batch(()=>{e.refreshSelectedShapes(l,m),e.setMoveAcceleration(Va(r,n,c))});return}if(d!==void 0){e.actions.setOffset([m[0]+c.canvasOffset[0]-d.start[0],m[1]+c.canvasOffset[1]-d.start[1]]);return}if(u.mode===`preview`){let t=I(p)[0];if(t?.type===`curve`){e.setSelectedShape(q([un(t,m,c,!0)],c));return}if(t?.type===`polygon`){e.setSelectedShape(q([en(t,m,c,!0)],c));return}}let h=Et(m,c),g=!Ta(u);e.batch(()=>{if(!Yi(r)){let t=!g&&(a===void 0||Ha(r,n));e.refreshHoveredShape(t,l,m,h)}if(p===void 0||p.locked)e.setHoverMode({mode:`default`,outOfView:!h});else{if(g)e.updateShapes(xi(l,p,m,u,c,f.shift,f.alt));else{if(!h){e.setHoverMode({mode:`default`});return}e.setHoverMode($i(l,p,m,c,!0)||{mode:`default`})}u.mode===`translate`&&f.alt&&!u.hasBeenDuplicated&&(e.setSelectionMode({...u,hasBeenDuplicated:!0}),e.duplicateShapes(I(u.originalShape)))}})},l=r=>{t&&clearTimeout(t.timeout);let{state:i,settings:a,ctx:c}=o();if(!c)return;if(r.button===2){s(r);return}if(i.interaction.panStart){e.setPanStart(void 0);return}let{selectionMode:l}=i.interaction;if(l.mode===`contextMenu`||l.mode===`textedition`||l.mode===`preview`)return;let u=Ji(r,n,a);if(l.mode===`translate`&&Date.now()-l.dateStart<=500&&u[0]===l.cursorStartPosition[0]&&u[1]===l.cursorStartPosition[1]){let t=r.ctrlKey||r.shiftKey||r.metaKey,{shape:n}=Da(c,i.document.shapes,u,a,i.document.selectedShape,Yi(r),i.config.options.withFrameSelection,t?`toggle`:`replace`,!1),o=t&&I(n).length===l.selectedShapesLengthAtMouseDown;e.batch(()=>{o||e.setSelectedShape(n),e.setSelectionMode({mode:`default`}),e.setSelectionFrame(void 0),e.actions.saveShapes()})}else l.mode!=="default"&&e.batch(()=>{l.mode===`brush`&&a.isBrushShapeDoneOnMouseUp&&e.setSelectedShape(void 0),e.setSelectionMode({mode:`default`}),e.setSelectionFrame(void 0),e.actions.saveShapes()})},u=c=>{let{state:l,settings:u,activeTool:d,ctx:f}=o(),{features:p}=u;if(!e.selectors.selectIsInteractive(l))return;if(c.preventDefault(),i.add(c.pointerId),i.size>1){t&&clearTimeout(t.timeout),r.reset();return}a=c.pointerId,r.press(c);try{n.setPointerCapture(c.pointerId)}catch{}if(n.focus(),!f)return;let{selectedShape:h,shapes:g}=l.document,{selectionMode:_}=l.interaction,y=Ji(c,n,u),b=c.button===1,x=c.button===2;if(b||l.interaction.modifiers.space||d.type===`move`&&!x)e.setPanStart({start:y,originalOffset:u.canvasOffset});else if(p.edition){if(!Et(y,u))e.batch(()=>{e.setSelectedShape(void 0),e.setSelectionMode({mode:`default`})});else if(x){if(d.type===`selection`){let{shape:t}=Da(f,g,y,u,h,Yi(c),!1);e.batch(()=>{e.setSelectedShape(t),e.setSelectionMode({mode:`default`})})}}else if(Yi(c)&&(t&&clearTimeout(t.timeout),t={timeout:setTimeout(()=>s(c),za),startPosition:{clientX:c.clientX,clientY:c.clientY}}),d.type===`selection`){let t=c.ctrlKey||c.shiftKey||c.metaKey?`add`:`replace`,{withFrameSelection:n}=l.config.options,{shape:r,mode:i}=Da(f,g,y,u,h,Yi(c),n,t);e.batch(()=>{e.setSelectedShape(r),e.setSelectionMode(i),i.mode===`selectionFrame`&&e.setSelectionFrame({oldSelection:r,frame:[[y[0],y[1]],[y[0],y[1]]]})})}else if(m.some(e=>e===d.type)){let t=I(h)[0];if(d.type===`brush`)e.batch(()=>{if(t?.type===`brush`)e.updateShapes([zt(t,y,u)]);else{let t=Hr(f,d,y,u);if(!t)return;e.addShapes([t]),e.setSelectedShape(q([t],u))}e.setSelectionMode({mode:`brush`})});else if(_.mode===`preview`&&(t?.type===`polygon`||t?.type===`curve`)){let n=t.type===`polygon`?en(t,y,u):un(t,y,u);e.batch(()=>{e.setSelectedShape(q([n],u)),e.updateShapes([n],!0)})}else if(d.type!==`picture`){let t=Hr(f,d,y,u);if(!t)return;let n=q([t],u);e.batch(()=>{e.addShapes([t]),e.setSelectedShape(n),t.type===`polygon`||t.type===`curve`?e.setSelectionMode({mode:`preview`}):(e.setActiveTool(v),e.setSelectionMode({mode:`resize`,cursorStartPosition:[y[0]+u.selectionPadding,y[1]+u.selectionPadding],originalShape:n,anchor:t.type===`line`?0:[1,1],selectedShapesLengthAtMouseDown:I(n).length}))})}}}},d=t=>{let{state:r,settings:i,activeTool:a,ctx:s}=o();if(a.type!==`selection`||!s)return;let{selectedShape:c}=r.document,l=I(c);if(l.length!==1)return;let u=l[0];if(u?.locked)return;let d=Ji(t,n,i);if(Et(d,i)){if(u?.type===`text`)$i(s,c,d,i)&&e.setSelectionMode({mode:`textedition`,defaultValue:u.value});else if(u?.type===`polygon`){let t=ea(s,u,d,i);t&&e.updateShapes([$t(u,t.lineIndex,d,i)])}else if(u?.type===`curve`){let t=ta(s,u,d,i);t&&e.updateShapes([ln(u,t.lineIndex,d,i)])}}},f=e=>{if(i.delete(e.pointerId),e.pointerId!==a)return;a=void 0;let t=e.type===`pointerup`&&e.button===0&&Ha(e,n);l(e),t?r.release(e)===`doubleClick`&&d(e):r.reset()},p=()=>{a===void 0&&e.clearHover()};return n.addEventListener(`pointerdown`,u,{passive:!1}),n.addEventListener(`pointermove`,c),n.addEventListener(`pointerup`,f),n.addEventListener(`pointercancel`,f),n.addEventListener(`lostpointercapture`,f),n.addEventListener(`pointerleave`,p),()=>{t&&clearTimeout(t.timeout),n.removeEventListener(`pointerdown`,u),n.removeEventListener(`pointermove`,c),n.removeEventListener(`pointerup`,f),n.removeEventListener(`pointercancel`,f),n.removeEventListener(`lostpointercapture`,f),n.removeEventListener(`pointerleave`,p)}},[e,n])},Wa=e=>e.dataTransfer?.types.includes(`Files`)??!1,Ga=(e,n)=>{(0,t.useEffect)(()=>{if(!n)return;let t=t=>Wa(t)&&e.selectors.selectWithDropPicture(e.getState()),r=e=>{e.dataTransfer&&t(e)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},i=async r=>{if(!t(r))return;r.preventDefault();let i=Array.from(r.dataTransfer?.files??[]),a=i.filter(e=>Ue.includes(e.type));for(let t of i)a.includes(t)||e.emit(`pictureDropFailed`,t,Error(`Unsupported file type: ${t.type||t.name}`));let[o,s]=Ji(r,n,e.getSettings());for(let[t,n]of a.entries())try{await e.actions.addPicture(n,{position:[o+t*20,s+t*20]})}catch(t){console.warn(t),e.emit(`pictureDropFailed`,n,t)}};return n.addEventListener(`dragover`,r),n.addEventListener(`drop`,i),()=>{n.removeEventListener(`dragover`,r),n.removeEventListener(`drop`,i)}},[e,n])},Ka=[`shapeClicked`,`canvasClicked`,`canvasDoubleClicked`],qa=(e,n)=>{(0,t.useEffect)(()=>{if(!n)return;let t=Ra(),r,i=t=>({canvasPosition:Ji(t,n,e.getSettings()),clientPosition:{x:t.clientX,y:t.clientY},originalEvent:t}),a=t=>Et(t.canvasPosition,e.getSettings()),o=t=>a(t)?e.getShapeAt(t.canvasPosition):void 0,s=()=>e.hasListeners(`shapeClicked`)&&!e.selectors.selectFeatures(e.getState()).edition,c=(t,i,a)=>{n.style.cursor=t&&a?`pointer`:``,t?.id!==r&&(r=t?.id,e.emit(`shapeHovered`,t,i))},l=e=>{(r!==void 0||n.style.cursor)&&c(void 0,i(e),!1)},u={pointerdown:t.press,pointerup:n=>{let r=t.release(n);if(!r||!Ka.some(t=>e.hasListeners(t)))return;let o=i(n);if(!a(o)){t.reset();return}let s=e.getShapeAt(o.canvasPosition);s&&e.emit(`shapeClicked`,s,o),e.emit(`canvasClicked`,s,o),r===`doubleClick`&&e.emit(`canvasDoubleClicked`,s,o)},pointermove:t=>{let n=s();if(!n&&!e.hasListeners(`shapeHovered`)){l(t);return}let r=i(t);c(o(r),r,n)},pointerleave:l};for(let[e,t]of Object.entries(u))n.addEventListener(e,t);return()=>{for(let[e,t]of Object.entries(u))n.removeEventListener(e,t);n.style.cursor=``}},[e,n])},Ja=(e,t)=>Math.abs(e-t.startDiff)>30,Ya=(e,t)=>Math.abs(Qe(e,t.startCenter))>10,Xa=e=>{let t=[e[0].clientX,e[0].clientY],n=[e[1].clientX,e[1].clientY];return{diff:Qe(t,n),center:$e(t,n)}},Za=({canvasBoundingRect:e,startDiff:t,startZoom:n,startCenter:r,startOffset:i,currentDiff:a,currentCenter:o,isMoving:s,isZooming:c,...l})=>{let{canvasSize:u}=l,d=c?mt(a/t*n):n,f=s?[i[0]+(o[0]-r[0])*(u.width/e.width)/u.scaleRatio/n,i[1]+(o[1]-r[1])*(u.height/e.height)/u.scaleRatio/n]:[i[0],i[1]],p=[(o[0]-e.left)/u.scaleRatio,(o[1]-e.top)/u.scaleRatio];return _t({...l,currentOffset:f,currentZoom:n,zoom:d,centerPoint:p})},Qa=[`pointerup`,`pointerout`,`pointercancel`,`pointerleave`],$a=({store:e,canvasElt:n})=>{(0,t.useEffect)(()=>{if(!n)return;let t=[],r,i=i=>{let a=t.findIndex(e=>e.pointerId===i.pointerId);if(a>-1&&(t[a]=i),t.length!==2||!r)return;let{diff:o,center:s}=Xa(t),c=r.isZooming||Ja(o,r),l=r.isMoving||c||Ya(s,r);r={...r,isMoving:l,isZooming:c},o&&r.startDiff&&e.setTransformation(Za({...r,...e.getViewBounds(),canvasBoundingRect:n.getBoundingClientRect(),currentDiff:o,currentCenter:s}))},a=e=>{if(e){document.addEventListener(`pointermove`,i);for(let e of Qa)document.addEventListener(e,s)}else{document.removeEventListener(`pointermove`,i);for(let e of Qa)document.removeEventListener(e,s)}},o=n=>{if(t=[...t,n],t.length===1&&a(!0),t.length===2){n.stopPropagation();let{diff:i,center:a}=Xa(t),{transformation:o}=e.getState().view;r={startDiff:i,startCenter:a,startZoom:o.zoom,startOffset:o.offset,isMoving:!1,isZooming:!1}}},s=e=>{t=t.filter(t=>t.pointerId!==e.pointerId),t.length||a(!1)};return n.addEventListener(`pointerdown`,o),()=>{n.removeEventListener(`pointerdown`,o),a(!1)}},[n,e])},eo=({store:e,zoomEnabled:n,canvasElt:r})=>{let i=(0,t.useRef)(0);$a({store:e,canvasElt:r}),(0,t.useEffect)(()=>{if(!n||!r)return;let t=t=>{let n=t.ctrlKey,{deltaX:a,deltaY:o}=Dt(t,t.timeStamp-i.current);if(i.current=t.timeStamp,n){t.preventDefault();let n=Gi(t,r,e.getState().view.canvasSize);e.zoomBy(o,n);return}let s=t.shiftKey;e.scrollBy(s?[o,a]:[a,o])&&t.preventDefault()};return r.addEventListener(`wheel`,t,{passive:!1}),()=>{r.removeEventListener(`wheel`,t)}},[r,n,e])},to=[`id`,`type`,`rotation`,`toolId`,`visible`,`locked`,`style`,`data`],no={rect:[`x`,`y`,`width`,`height`],square:[`x`,`y`,`width`,`height`],picture:[`x`,`y`,`width`,`height`,`src`,`flipX`,`flipY`,`ratio`],text:[`x`,`y`,`width`,`height`,`value`,`fontSize`,`flipX`,`flipY`,`ratio`],circle:[`x`,`y`,`radius`],ellipse:[`x`,`y`,`radiusX`,`radiusY`],line:[`points`],polygon:[`points`],curve:[`points`],brush:[`points`,`scaleX`,`scaleY`]},ro=Object.keys(no),io=e=>ro.includes(e),ao=e=>typeof e==`number`&&Number.isFinite(e),oo=e=>Array.isArray(e)&&e.length===2&&ao(e[0])&&ao(e[1]),so=(e,t)=>Array.isArray(e)&&e.length>=t&&e.every(oo),co=(e,t)=>{let n=Object.keys(e).find(e=>!to.includes(e)&&!no[t].includes(e));return n===void 0?void 0:`unknown field "${n}" for a ${t}`},lo=e=>{if(e.rotation!==void 0&&!ao(e.rotation))return`"rotation" must be a finite number`;if(e.style!==void 0&&!F(e.style))return`"style" must be an object`;if(e.data!==void 0&&!F(e.data))return`"data" must be an object`;if(e.visible!==void 0&&typeof e.visible!=`boolean`)return`"visible" must be a boolean`;if(e.locked!==void 0&&typeof e.locked!=`boolean`)return`"locked" must be a boolean`},uo=(e,t)=>{let n=(...t)=>t.find(t=>!ao(e[t]));switch(t){case`rect`:case`square`:case`picture`:{let r=n(`x`,`y`,`width`,`height`);return r?`"${r}" must be a finite number`:t===`picture`&&(typeof e.src!=`string`||!e.src)?`"src" must be a non empty string`:void 0}case`text`:{let t=n(`x`,`y`)??[`width`,`height`,`fontSize`].find(t=>e[t]!==void 0&&!ao(e[t]));if(t)return`"${t}" must be a finite number`;let{value:r}=e;return!Array.isArray(r)||!r.length||r.some(e=>typeof e!=`string`)?`"value" must be a non empty array of strings`:void 0}case`circle`:{let e=n(`x`,`y`,`radius`);return e&&`"${e}" must be a finite number`}case`ellipse`:{let e=n(`x`,`y`,`radiusX`,`radiusY`);return e&&`"${e}" must be a finite number`}case`line`:return so(e.points,2)&&e.points.length===2?void 0:`"points" must hold exactly 2 points`;case`polygon`:case`curve`:return so(e.points,2)?void 0:`"points" must hold at least 2 points`;case`brush`:return Array.isArray(e.points)&&e.points.length>0&&e.points.every(e=>so(e,1))?void 0:`"points" must be a non empty array of non empty point lists`}},fo=e=>{if(!F(e))return`a shape must be an object`;let{type:t}=e;return io(t)?e.id!==void 0&&(typeof e.id!=`string`||!e.id)?`"id" must be a non empty string`:co(e,t)??lo(e)??uo(e,t):`unknown shape type "${String(t)}"`},po=(e,t)=>{e.forEach((e,n)=>{let r=fo(e);if(r)throw Error(`react-paint ${t}: invalid shape at index ${n}, ${r}`)})},mo=(e,{ctx:t,settings:n,tools:r,usedIds:i,completeStyle:a})=>{let o=typeof e.id==`string`&&e.id&&!i.has(e.id)?e.id:N(e.type);i.add(o);let s=a?{...xe(be(r,e)),...e.style}:e.style,c={...e,id:o,...s?{style:s}:{}};switch(c.type){case`text`:return H(Pr(t,c),n);case`picture`:return H({...c,img:new Image},n);default:return H(c,n)}},ho=async(e,{resolvePictureSrc:t,...n})=>{if(!e)return{shapes:[],failedPictures:[]};let r=le(e.map(e=>e&&io(e.type)?mo(e,{...n,completeStyle:!1}):null)),i=r.filter(e=>e.type===`picture`),a=await Promise.allSettled(i.map(e=>rr(e.img,e.src,t))),o=[];a.forEach((e,t)=>{if(e.status===`fulfilled`)return;let n=i[t];o.push({shape:n,error:e.reason}),console.warn(`react-paint: the picture ${n.id} is left out, it could not be loaded`,e.reason)});let s=new Set(o.map(({shape:e})=>e));return{shapes:r.filter(e=>!s.has(e)),failedPictures:o}},go=(e,t)=>{if(!e)return;let{type:n}=e;return io(n)?t.type!==void 0&&t.type!==n?`the type of a shape cannot change`:co(t,n)??lo(t)??uo({...e,...t},n):`a ${n} cannot be updated`},_o=(e,t)=>{e.forEach((e,n)=>{let r=F(e)&&typeof e.id==`string`?go(t.get(e.id),e):`"id" must be a string`;if(r)throw Error(`react-paint updateShapes: invalid patch at index ${n}, ${r}`)})},vo=(e,t,n,r)=>{let{id:i,type:a,...o}=n,s=o.style?{...t.style,...o.style}:t.style,c={...t,...o,style:s};if(c.type===`square`&&(`width`in o||`height`in o)){let e=`width`in o?c.width:c.height;return H({...c,width:e,height:e},r)}if(c.type===`text`){let t=`value`in o||`fontSize`in o||`height`in o,n=Object.keys(o.style??{}).some(e=>Mr(e));if(`width`in o||n&&!t)return H(Nr(e,c),r);if(t){let t=`fontSize`in o?c.fontSize:`height`in o?c.height/Or(c.value):c.fontSize;return H(Vr(e,{...c,fontSize:t,computed:Tr(c,r)},c.value,r),r)}}return H(c,r)},yo={position:`absolute`,outline:`none`,left:0,top:0,transformOrigin:`left top`,boxSizing:`border-box`,lineHeight:1,width:`max-content`,background:`none`},bo=e=>e.childNodes.length?Array.from(e.childNodes).map(e=>bo(e)).join(``):e.nodeValue??``,xo=({disabled:e=!1,shape:r,defaultValue:i,updateValue:a,saveShapes:o,settings:s})=>{let c=(0,t.useRef)(null),l=(0,t.useRef)(o),u=e=>{a(Array.from(e.target.childNodes).map(e=>bo(e)))};(0,t.useEffect)(()=>{if(!c.current)return;let e=c.current,t=t=>{t.preventDefault();let n=t.clipboardData?.getData(`text/plain`);if(!n)return;let r=window.getSelection();if(!r||r.rangeCount===0)return;r.deleteFromDocument();let i=r.getRangeAt(0);i.insertNode(document.createTextNode(n)),i.collapse(!1),r.removeAllRanges(),r.addRange(i),e.dispatchEvent(new Event(`input`,{bubbles:!0}))};e.addEventListener(`paste`,t),e.innerText=``;for(let t of i){let n=document.createElement(`div`);t===``?n.innerHTML=`<br/>`:n.innerText=t,e.appendChild(n)}return e.focus(),()=>{e.removeEventListener(`paste`,t)}},[i]),(0,t.useEffect)(()=>{let e=l.current;return()=>{e()}},[]);let d=(0,t.useMemo)(()=>{let{borders:e,center:t}=r.computed;return R({point:[e.x,e.y],rotation:-(r.rotation??0),origin:t})},[r]),f=[`translate3D(${(d[0]+s.canvasOffset[0])*s.canvasSize.scaleRatio}px, ${(d[1]+s.canvasOffset[1])*s.canvasSize.scaleRatio}px, 0)`,`rotate(${We(r.rotation??0)}deg)`,r.flipX||r.flipY?`scale(${r.flipX?-1:1}, ${r.flipY?-1:1})`:void 0,r.flipX||r.flipY?`translate3D(${r.flipX?-100:0}%,${r.flipY?-100:0}%,0)`:void 0].filter(Boolean).join(` `),p=!e;return(0,n.jsx)(`div`,{className:`react-paint-canvas-edittextbox`,ref:c,"aria-label":`Text content`,contentEditable:p,role:`textbox`,tabIndex:p?0:void 0,onInput:u,style:{...yo,transform:P(`--react-paint-canvas-edittextbox-transform`,f),fontSize:P(`--react-paint-canvas-edittextbox-fontsize`,`${r.fontSize*s.canvasSize.scaleRatio}px`),padding:P(`--react-paint-canvas-edittextbox-padding`,`${s.selectionPadding*s.canvasSize.scaleRatio}px`),color:P(`--react-paint-canvas-edittextbox-color`,r.style?.strokeColor),opacity:P(`--react-paint-canvas-edittextbox-opacity`,(r.style?.opacity??100)/100),fontFamily:P(`--react-paint-canvas-edittextbox-fontfamily`,r.style?.fontFamily??`serif`),fontWeight:r.style?.fontBold?`bold`:void 0,fontStyle:r.style?.fontItalic?`italic`:void 0}})},So={flex:1,display:`flex`,alignItems:`center`,justifyContent:`center`},Co={position:`relative`,backgroundSize:`16px`,overflow:`hidden`,display:`grid`},wo={userSelect:`none`,touchAction:`none`},To={box:So,container:{...Co,width:`100%`,height:`100%`},canvas:{...wo,position:`relative`,width:`100%`,gridArea:`1 / 1`}},Eo={box:{position:`absolute`,inset:0},container:{...Co,position:`absolute`,inset:0},canvas:{...wo,position:`absolute`,left:0,top:0}},Do=({store:e,view:r,backgroundColor:i,selectionColor:a,selectionWidth:o})=>{let{canvasSize:s,resize:c,isEditMode:l,features:u,textEdition:d}=r,f=(0,t.useRef)(null),p=(0,t.useRef)(null),m=l,h=l?0:-1,g=c===`extend`?Eo:To,[_,v]=(0,t.useState)(null),y=(0,t.useCallback)(t=>{e.setCanvasElement(t),v(t)},[e]);Ua(e,_),qa(e,_),Ga(e,_),eo({store:e,canvasElt:_,zoomEnabled:u.zoom}),La({store:e,drawCanvas:_,selectionCanvasRef:p,selectionColor:a,selectionWidth:o,canvasSize:s}),(0,t.useEffect)(()=>{let t=f.current;if(!t)return;let n=e=>{t.style.cursor=P(`--react-paint-canvas-cursor`,e)};return n(e.selectors.selectCursor(e.getState())),e.watch(e.selectors.selectCursor,n)},[e]);let b=(0,t.useCallback)(t=>{let n=e.getState(),r=I(n.document.selectedShape)[0];if(r?.type!==`text`)return;let i=_?.getContext(`2d`);i&&e.updateShapes([vo(i,r,{id:r.id,value:t},e.getSettings(n))])},[e,_]),x=e=>{if(l)return e.preventDefault(),e.stopPropagation(),!1};return(0,n.jsx)(`div`,{className:`react-paint-canvas-box`,style:g.box,children:(0,n.jsxs)(`div`,{className:`react-paint-canvas-container`,ref:f,style:{...g.container,backgroundColor:P(`--react-paint-app-canvas-bg`,i)},children:[(0,n.jsx)(`canvas`,{className:A,ref:y,style:g.canvas,"data-testid":`draw-canvas`,width:s.width,height:s.height,onContextMenu:x,tabIndex:h}),m&&(0,n.jsx)(`canvas`,{className:`react-paint-canvas-selectioncanvas`,ref:p,style:{...g.canvas,pointerEvents:`none`},width:s.width,height:s.height,onContextMenu:x}),l&&d&&(0,n.jsx)(xo,{disabled:!u.edition,shape:d.shape,defaultValue:d.defaultValue,updateValue:b,saveShapes:e.actions.saveShapes,settings:d.settings})]})})},Oo=20,ko=e=>{(0,t.useEffect)(()=>{let t=0,n=0,r=i=>{let a=Math.min(Math.max(i-n,0),100);e.applyMoveAcceleration(a/Oo),n=i,t=requestAnimationFrame(r)},i=e=>{cancelAnimationFrame(t),t=0,e&&(n=performance.now(),t=requestAnimationFrame(r))},a=e=>{let[t,n]=e.interaction.moveAcceleration;return t!==0||n!==0};i(a(e.getState()));let o=e.watch(a,i);return()=>{o(),cancelAnimationFrame(t)}},[e])},X={ArrowUp:`ArrowUp`,ArrowDown:`ArrowDown`,ArrowLeft:`ArrowLeft`,ArrowRight:`ArrowRight`,Delete:`Delete`,Backspace:`Backspace`,Escape:`Escape`,Shift:`Shift`,Alt:`Alt`,Option:`Option`,Space:` `,A:`A`,a:`a`,z:`z`,Z:`Z`,y:`y`,Y:`Y`,Plus:`+`,Minus:`-`,Zero:`0`},Ao={Cut:`cut`,Copy:`copy`,Paste:`paste`},jo=e=>{(0,t.useEffect)(()=>{let t=()=>e.selectors.selectIsInteractive(e.getState()),n=()=>e.getState().interaction.selectionMode.mode===`textedition`,r=()=>e.getState().document.selectedShape!==void 0,i=new Set,a=i=>{t()&&r()&&!n()&&(i.preventDefault(),e.actions.copy())},o=i=>{t()&&r()&&!n()&&(i.preventDefault(),e.actions.cut())},s=r=>{t()&&e.getState().clipboard!==void 0&&!n()&&(r.preventDefault(),e.actions.paste())};return e.listenScope({keydown:r=>{if(!t())return;if(r.metaKey||r.ctrlKey){if(r.key===X.Z||r.key===X.z){r.preventDefault(),r.stopPropagation(),r.shiftKey?e.actions.redo():e.actions.undo();return}if(!ce()&&(r.key===X.Y||r.key===X.y)){r.preventDefault(),r.stopPropagation(),e.actions.redo();return}if(r.key===X.A||r.key===X.a){r.preventDefault(),r.stopPropagation(),e.actions.selectAllShapes();return}if(r.key===X.Plus){r.preventDefault(),r.stopPropagation(),e.actions.setZoom(`zoom`);return}if(r.key===X.Minus){r.preventDefault(),r.stopPropagation(),e.actions.setZoom(`unzoom`);return}if(r.key===X.Zero){r.preventDefault(),r.stopPropagation(),e.actions.resetZoom();return}}if(r.key===X.Shift){r.preventDefault(),r.stopPropagation(),e.setModifiers({shift:!0});return}if(r.key===X.Space&&e.getState().interaction.focus.canvas){r.preventDefault(),r.stopPropagation(),e.setModifiers({space:!0});return}if(r.key===X.Alt||r.key===X.Option){r.preventDefault(),r.stopPropagation(),e.setModifiers({alt:!0});return}let{selectedShape:a}=e.getState().document;if(!a)return;if(r.key===X.Escape){e.batch(()=>{e.setSelectedShape(void 0),e.setActiveTool(v),e.setSelectionMode({mode:`default`}),e.setSelectionFrame(void 0)});return}if(n())return;let{gridGap:o}=e.getSettings(),s={[X.ArrowLeft]:[o?-o:-1,0],[X.ArrowRight]:[o||1,0],[X.ArrowDown]:[0,o||1],[X.ArrowUp]:[0,o?-o:-1]};switch(r.key){case X.ArrowLeft:case X.ArrowRight:case X.ArrowDown:case X.ArrowUp:r.preventDefault(),r.stopPropagation(),i.add(r.key),e.updateShapes(ui(s[r.key],a,[0,0],e.getSettings(),!0));break;case X.Delete:case X.Backspace:r.preventDefault(),r.stopPropagation(),e.removeShapes(I(a))}},keyup:n=>{if(i.delete(n.key)&&!i.size&&e.actions.saveShapes(),t())switch(n.key){case X.Shift:e.setModifiers({shift:!1});break;case X.Alt:case X.Option:e.setModifiers({alt:!1});break;case X.Space:e.setModifiers({space:!1})}},focusout:t=>{!i.size||t.relatedTarget&&t.currentTarget.contains(t.relatedTarget)||(i.clear(),e.actions.saveShapes())},[Ao.Copy]:a,[Ao.Paste]:s,[Ao.Cut]:o})},[e])},Mo=({onResized:e,element:n})=>{(0,t.useLayoutEffect)(()=>{let t=n.current;if(!t)return;let r=new ResizeObserver(t=>{let n=t?.[0]?.borderBoxSize?.[0],{width:r,height:i}=n?{width:n.inlineSize,height:n.blockSize}:t?.[0]?.contentRect??{};r!==void 0&&i!==void 0&&e(r,i)});return r.observe(t),()=>{r.unobserve(t)}},[n,e])},No=Symbol.for(`@yorab/react-paint/store`),Po=e=>({actions:e.actions,getState:e.getEditorState,subscribe:e.subscribe,registerEvent:e.registerEvent,unregisterEvent:e.unregisterEvent,batch:e.transaction,getShape:e.getShape,getBounds:e.getBounds,getShapesAt:e.getShapesAt,toCanvasPosition:e.toCanvasPosition,toClientPosition:e.toClientPosition,resetCanvas:(t,n)=>void e.resetCanvas(t,n),getCurrentImage:e.getCurrentImage,getCurrentData:e.getCurrentData,scopeRef:e.setScopeElement,[No]:e}),Fo=e=>{let t=e[No];if(!t)throw Error(`The paint prop must be the value returned by useReactPaint`);return t},Io=(0,t.createContext)(void 0),Lo=({paint:e,children:t})=>(0,n.jsx)(Io.Provider,{value:e,children:t}),Ro=()=>{let e=(0,t.useContext)(Io);if(!e)throw Error(`usePaint must be used inside a PaintProvider or an Editor`);return e},zo=e=>e,Bo=()=>typeof process<`u`&&process.env.NODE_ENV!==`production`;function Z(e,n,r=Object.is){let i=n??zo,a=(0,t.useRef)(null),o=(0,t.useRef)(!1),s=(0,t.useMemo)(()=>{let t;return()=>{let n=e.getState();if(t&&Object.is(t.state,n))return t.selection;let s=i(n);Bo()&&!o.current&&(o.current=!0,r(s,i(n))||console.warn(`usePaintState: the selector returns a new value on each call, so the component renders on each change of the state. Return an existing value, or give an equality function like shallowEqual.`));let c=t??(a.current?{selection:a.current.value}:void 0);return t={state:n,selection:c&&r(c.selection,s)?c.selection:s},t.selection}},[e,i,r]),c=(0,t.useSyncExternalStore)(e.subscribe,s,s);return(0,t.useEffect)(()=>{a.current={value:c}},[c]),c}var Vo=e=>{let{zoom:n,offset:r}=Z(e,e=>e.view),i=Z(e,e=>e.width),a=Z(e,e=>e.height);return(0,t.useMemo)(()=>({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":n,"--react-paint-canvas-offset-x":r[0],"--react-paint-canvas-offset-y":r[1],"--react-paint-app-canvaswidth":i,"--react-paint-app-canvasheight":a}),[n,r,i,a])},Ho=e=>{let t=e,n=[],r=0,i=!1,a=()=>{if(r>0)i=!0;else for(let e of n)e()},o=e=>(n=[...n,e],()=>{let t=n.indexOf(e);t!==-1&&(n=[...n.slice(0,t),...n.slice(t+1)])});return{getState:()=>t,setState:e=>{let n=typeof e==`function`?e(t):e;Object.is(n,t)||(t=n,a())},subscribe:o,watch:(e,n,r=Object.is)=>{let i=e(t);return o(()=>{let a=e(t);if(r(i,a))return;let o=i;i=a,n(a,o)})},batch:e=>{r++;try{return e()}finally{r--,r===0&&i&&(i=!1,a())}}}},Uo=()=>{let e={dataChanged:[],selectionChanged:[],toolChanged:[],shapeClicked:[],shapeHovered:[],canvasClicked:[],canvasDoubleClicked:[],pictureDropFailed:[],pictureLoaded:[],pictureLoadFailed:[]},t=(t,n)=>{if(e.hasOwnProperty(t)){if(n){let r=e[t].indexOf(n);r!==-1&&e[t].splice(r,1)}else e[t].length=0}};return{registerEvent:(n,r)=>(e.hasOwnProperty(n)&&e[n].push(r),()=>t(n,r)),unregisterEvent:t,emit:(t,...n)=>{for(let r of[...e[t]])r(...n)},hasListeners:t=>e[t].length>0}},Wo={shapes:[],selectedShape:void 0,history:{states:[{shapes:[],selectedShape:void 0,source:`remote`}],cursor:0}},Go=(e,t,n,r=`user`)=>ve(e.states[e.cursor]?.shapes,t)?e:{states:[...e.states.slice(0,e.cursor+1),{shapes:t,selectedShape:n,source:r}],cursor:e.cursor+1},Ko=(e,t)=>{switch(t.type){case`ADD`:return{...e,shapes:ue(e.shapes,t.index??0,...t.newShapes)};case`UPDATE`:{let n=new Map(t.updatedShapes.map(e=>[e.id,e])),r=e.shapes.map(e=>n.get(e.id)??e),i={...e,shapes:r,selectedShape:t.newSelectedShape};return t.save?{...i,history:Go(i.history,r,t.newSelectedShape,t.source)}:i}case`REMOVE`:{let n=e.shapes.filter(e=>!t.ids.has(e.id));return{...e,shapes:n,selectedShape:t.newSelectedShape,history:Go(e.history,n,t.newSelectedShape,t.source)}}case`DUPLICATE`:{let n=e.shapes.flatMap(e=>{let n=t.newShapesMap.get(e.id);return n?[n,e]:[e]});return{...e,shapes:n,selectedShape:t.newSelectedShape??e.selectedShape}}case`RESET_AND_SAVE`:{let n=t.shapes.map(e=>`chosen`in e?fe([`chosen`],e):e);return{...e,shapes:n,selectedShape:t.newSelectedShape,history:Go(e.history,n,t.newSelectedShape)}}case`SET_SELECTION`:return{...e,selectedShape:t.newSelectedShape};case`SAVE`:return{...e,history:Go(e.history,e.shapes,e.selectedShape,t.source)};case`UNDO`:{if(e.history.cursor<=0)return e;let t=e.history.cursor-1,{shapes:n,selectedShape:r}=e.history.states[t];return{...e,shapes:n,selectedShape:r,history:{...e.history,cursor:t}}}case`REDO`:{if(e.history.cursor>=e.history.states.length-1)return e;let t=e.history.cursor+1,{shapes:n,selectedShape:r}=e.history.states[t];return{...e,shapes:n,selectedShape:r,history:{...e.history,cursor:t}}}case`CLEAR`:return t.clearHistory?{shapes:t.shapes,selectedShape:void 0,history:{states:[{shapes:t.shapes,selectedShape:void 0,source:t.source}],cursor:0}}:{...e,shapes:t.shapes,selectedShape:void 0,history:Go(e.history,t.shapes,void 0,t.source)};case`REFRESH_ALL`:return{...e,shapes:t.shapes,selectedShape:t.newSelectedShape};case`SQUASH_HISTORY`:{let{states:n,cursor:r}=e.history;return r<=t.from+1?e:{...e,history:{states:[...n.slice(0,t.from+1),n[r]],cursor:t.from+1}}}default:return e}},qo={offset:[0,0],zoom:1},Jo=({width:e=1e3,height:t=600,mode:n=`editor`,disabled:r=!1,options:i},a)=>{let{clearCallback:o,resolvePictureSrc:s,...c}=he(re,_e(ge,i??{},a));return c.size===`infinite`&&(c.canZoom=`always`),{config:{width:e,height:t,mode:n,disabled:r,options:c},clearCallback:o,resolvePictureSrc:s}},Yo=e=>({config:e,document:Wo,clipboard:void 0,tools:{available:ye(e.options.availableTools),activeToolId:v.id},view:{canvasSize:De(e.width,e.height),transformation:qo,gridGap:e.options.grid},interaction:{selectionMode:{mode:`default`},hoveredShapeId:void 0,hoverMode:{mode:`default`},selectionFrame:void 0,modifiers:{shift:!1,alt:!1,space:!1},panStart:void 0,moveAcceleration:[0,0],focus:{component:!1,canvas:!1}}}),Xo=(e,t)=>e[0]===t[0]&&e[1]===t[1],Zo=(e,t)=>e.zoom===t.zoom&&Xo(e.offset,t.offset),Qo=(e,t)=>e.config.options.canvasSelectionPadding!==t.config.options.canvasSelectionPadding||e.config.options.brushAlgo!==t.config.options.brushAlgo,$o=(e,t)=>e.view.canvasSize!==t.view.canvasSize||e.view.transformation!==t.view.transformation||e.config.width!==t.config.width||e.config.height!==t.config.height||e.config.options.size!==t.config.options.size,es=(e,t)=>e.mode!==t.mode||e.outOfView!==t.outOfView?!1:e.mode!==`resize`||t.mode!==`resize`?!0:typeof e.anchor==`number`||typeof t.anchor==`number`?e.anchor===t.anchor:Xo(e.anchor,t.anchor),ts=(e,t)=>Object.keys(t).every(n=>Object.is(t[n],e[n]))?e:{...e,...t},Q=(e,t)=>{let n=ts(e.interaction,t);return n===e.interaction?e:{...e,interaction:n}},ns=(e,t)=>Zo(t,e.view.transformation)?e:{...e,view:{...e.view,transformation:t}},rs=(e,t,n)=>{let r=!1,i=e.tools.available.map(e=>e.id===t?Object.entries(n).reduce((e,[t,n])=>{let i=e.settings[t];return!i||n===void 0||Object.is(i.default,n)?e:(r=!0,pe([`settings`,t,`default`],n,e))},e):e);return r?{...e,tools:{...e.tools,available:i}}:e},is=(e=`png`)=>`drawing.${e===`jpeg`?`jpg`:e}`,as=(e,t,n,r)=>{let i=n??q(e,r)?.computed.center;return i?e.map(e=>H(ti(e,t,i),r)):[]},os=(e,t)=>new Map([...e,...I(t)].map(e=>[e.id,e])),ss=(e={})=>{let t={props:e,overrides:{}},n=Ho(Yo(Jo(e,t.overrides).config)),r=Ma(),{registerEvent:i,unregisterEvent:a,emit:o,hasListeners:s}=Uo(),{getState:c,batch:l}=n,u=null,d=null,f=null,p=null,m=!1,h=(e=c())=>r.selectSettings(e),g=(e=c())=>({size:e.config.options.size,canvasSize:e.view.canvasSize,drawingSize:{width:e.config.width,height:e.config.height}}),_,y,b=()=>u?.getContext(`2d`)||(_===void 0&&(_=Ae()),_),x=()=>b()||(y??(y=je()),y),S=(e,t)=>{let n=e.document.shapes.map(e=>H(e,t)),r=new Map(e.document.shapes.map((e,t)=>[e,n[t]])),i=e.document.selectedShape,a=i===void 0?void 0:q(I(i).map(e=>r.get(e)??H(e,t)),t);return{...e,document:Ko(e.document,{type:`REFRESH_ALL`,shapes:n,newSelectedShape:a})}},C=(e,t)=>{if(t===e)return t;let n=t,i=e.interaction.selectionMode.mode,a=n.interaction.selectionMode.mode;i===`preview`&&a===`preview`&&e.document.selectedShape?.id!==n.document.selectedShape?.id&&(n=Q(n,{selectionMode:{mode:`default`}})),i===`selectionFrame`&&a!==`selectionFrame`&&!Xo(n.interaction.moveAcceleration,[0,0])&&(n=Q(n,{moveAcceleration:[0,0]}));let{selectedShape:o}=n.document;return(o===void 0||o.locked)&&n.interaction.hoverMode.mode!=="default"&&(n=Q(n,{hoverMode:{mode:`default`}})),!r.selectIsInteractive(n)&&(n.interaction.focus.component||n.interaction.focus.canvas)&&(n=Q(n,{focus:{component:!1,canvas:!1}})),Qo(e,n)&&(n=S(n,h(n))),n.config.options.size===`fixed`&&$o(e,n)&&(n=w(n)),n},w=e=>{let{transformation:t}=e.view;return ns(e,gt({...g(e),zoom:t.zoom,newOffset:t.offset}))},T=e=>n.setState(t=>C(t,e(t))),E=e=>T(t=>{let n=Ko(t.document,typeof e==`function`?e(t):e);return n===t.document?t:{...t,document:n}}),D=(e,t)=>T(n=>Q(n,{[e]:t})),ee=!1,te=e=>ee?e():l(()=>{let t=c().document.history.cursor;ee=!0;try{return e()}finally{ee=!1,E({type:`SQUASH_HISTORY`,from:t})}});n.watch(({document:e,config:t})=>[e.history,t.width,t.height],([e,t,n],[r])=>{if(!s(`dataChanged`))return;let{shapes:i,source:a}=e.states[e.cursor],c=Gn(i,t,n);o(`dataChanged`,c,a,Kn(r.states[r.cursor].shapes,i,c.shapes))},M),n.watch(e=>e.document.selectedShape?.id,()=>o(`selectionChanged`,r.selectSelectedShapes(c().document.selectedShape))),n.watch(r.selectActiveTool,e=>o(`toolChanged`,e),(e,t)=>e.id===t.id);let O=()=>{let{config:e}=Jo(t.props,t.overrides);T(t=>{let n=t.config,r=!ve(n.options,e.options);if(!r&&n.width===e.width&&n.height===e.height&&n.mode===e.mode&&n.disabled===e.disabled)return t;let i=r?e.options:n.options,a=r&&!ve(n.options.availableTools,i.availableTools),o=i.grid!==n.options.grid,s=i.resize!==`extend`&&(n.options.resize===`extend`||n.width!==e.width||n.height!==e.height),{view:c}=t;return o&&(c={...c,gridGap:i.grid}),s&&(c={...c,canvasSize:Ee(c.canvasSize.width,e.width,e.height)}),{...t,config:{...e,options:i},tools:a?{...t.tools,available:ye(i.availableTools)}:t.tools,view:c}})},k=e=>{t.props=e,O()},A=e=>T(t=>e===t.document.selectedShape?t:{...t,document:Ko(t.document,{type:`SET_SELECTION`,newSelectedShape:e})}),ne=(e,t)=>E({type:`ADD`,newShapes:e,index:t}),re=e=>E({type:`SAVE`,source:e}),j=()=>E({type:`UNDO`}),ie=()=>E({type:`REDO`}),ae=(e,{clearHistory:t,source:n})=>E({type:`CLEAR`,shapes:e,clearHistory:t,source:n}),oe=(e,t=!1,n=!1)=>E(r=>{let i=h(r),a=new Map,o=[];for(let n of r.document.shapes){let r=e.find(e=>e.id===n.id);if(r){let e=hi(t?li(r,20,20,i):r);a.set(n.id,e),o.push(e)}}return{type:`DUPLICATE`,newShapesMap:a,newSelectedShape:n?q(o,i):r.document.selectedShape}}),N=(e,t,n,r)=>{if(!e||!r){D(`hoveredShapeId`,void 0);return}let i=c(),a=h(i),o=I(i.document.selectedShape).map(e=>e.id),s=i.document.shapes.filter(e=>!e.locked&&Ge(e.computed.boundingBox,n)).find(e=>o.includes(e.id)?!!$i(t,e,n,a):!!ra(t,e,n,a));D(`hoveredShapeId`,s?.id)},ce=()=>l(()=>{D(`hoveredShapeId`,void 0),Fe({mode:`default`})}),P=(e,t=!1,n)=>E(r=>{let i=new Map(e.map(e=>[e.id,e])),a=r.document.selectedShape;return{type:`UPDATE`,updatedShapes:e,newSelectedShape:a&&q(I(a).map(e=>i.get(e.id)??e),h(r)),save:t,source:n}}),fe=(e,{save:t=!0,source:n}={})=>{e.length&&P(e,t,n)},he=(e,t=`current`)=>E(n=>({type:`RESET_AND_SAVE`,shapes:e,newSelectedShape:t===`current`?n.document.selectedShape:t})),xe=(e,t)=>E(n=>{let r=new Set(e.map(e=>e.id)),i=n.document.selectedShape;return{type:`REMOVE`,ids:r,newSelectedShape:I(i).map(e=>e.id).find(e=>r.has(e))?void 0:i,source:t}}),Se=(e,t)=>{let{shapes:n}=c().document,r=n.findIndex(t=>t.id===e),i=n.findIndex(e=>e.id===t);he(de(n,r,i))},Ce=(e,t)=>{let n=[...c().document.shapes],r=new Set(e.map(e=>e.id)),i=n.map((e,t)=>r.has(e.id)?t:-1).filter(e=>e>=0);if(i.length!==0)switch(t){case`first`:case`last`:{let e=i.map(e=>n[e]).filter(Boolean),r=n.filter((e,t)=>!i.includes(t));he(t===`first`?[...e,...r]:[...r,...e]);break}case`backward`:{let e=[...n],t=i.sort((e,t)=>t-e).map(e=>n[e].id);for(let n of t){let t=e.findIndex(e=>e.id===n);if(t<e.length-1){let n=t+1;r.has(e[n].id)||(e=de(e,t,n))}}he(e);break}case`forward`:{let e=[...n],t=i.sort((e,t)=>e-t).map(e=>n[e].id);for(let n of t){let t=e.findIndex(e=>e.id===n);if(t>0){let n=t-1;r.has(e[n].id)||(e=de(e,t,n))}}he(e);break}}},L=e=>{M(e,c().document.shapes)||he(e)},we=(e,t)=>{let n=h(),{shapes:r,selectedShape:i}=c().document,a=new Set(e.map(e=>e.id)),o=r.map(e=>a.has(e.id)?t===`visible`?pe(`visible`,e.visible===!1,e):pe(`locked`,!e.locked,e):e),s=I(i).map(e=>e.id),l=q(o.filter(e=>s.includes(e.id)),n);he(o,l)},Te=e=>we(e,`visible`),De=e=>we(e,`locked`),Oe=(e,t)=>T(n=>{let r=n.interaction.selectionFrame,i=[r?.frame[0]??[t[0],t[1]],[t[0],t[1]]],a=n.document.shapes.filter(t=>!t.locked&&ua(e,t,i)),o=n.interaction.modifiers.shift?ka(r?.oldSelection,a):a,{selectedShape:s}=n.document,c=M(o,I(s));return{...Q(n,{selectionFrame:{oldSelection:r?.oldSelection,frame:i}}),document:c?n.document:Ko(n.document,{type:`SET_SELECTION`,newSelectedShape:q(o,h(n))})}}),ke=e=>D(`selectionFrame`,e),Me=e=>T(t=>t.tools.activeToolId===e.id?t:{...t,tools:{...t.tools,activeToolId:e.id}}),Ne=e=>l(()=>{A(void 0),Me(e)}),Pe=e=>D(`selectionMode`,e),Fe=e=>T(t=>es(e,t.interaction.hoverMode)?t:Q(t,{hoverMode:e})),Ie=e=>D(`panStart`,e),Le=e=>T(t=>Xo(e,t.interaction.moveAcceleration)?t:Q(t,{moveAcceleration:e})),Re=e=>T(t=>Q(t,{modifiers:ts(t.interaction.modifiers,e)})),ze=e=>T(t=>Q(t,{focus:ts(t.interaction.focus,e)})),Be=e=>T(t=>ve(e,t.view.canvasSize)?t:{...t,view:{...t.view,canvasSize:e}}),Ve=e=>T(t=>ns(t,e(t.view.transformation,t))),He=e=>Ve(()=>e),Ue=e=>Ve((t,n)=>gt({...g(n),zoom:t.zoom,newOffset:e(t,n)})),We=e=>Ue(()=>e),Ke=e=>Ve(({offset:t,zoom:n},r)=>vt({...g(r),currentOffset:t,currentZoom:n,action:e})),qe=(e,t)=>Ve(({offset:n,zoom:r},i)=>{let{canvasSize:a}=i.view,o=t?[(t[0]+n[0])*r,(t[1]+n[1])*r]:[a.realWidth/2,a.realHeight/2];return _t({...g(i),currentOffset:n,currentZoom:r,zoom:mt(e),centerPoint:o})}),Ye=(e,t)=>{if(!e.length)return;let n=Je(e.map(e=>e.computed.boundingBox));Ve((e,r)=>bt({...g(r),box:n,padding:t}))},R=()=>Ve((e,t)=>gt({...g(t),zoom:1,newOffset:[0,0]})),Xe=(e,t)=>Ve(({offset:n,zoom:r},i)=>yt({...g(i),currentOffset:n,currentZoom:r,delta:e,centerPoint:t})),Ze=([e,t])=>{let n=c().view.transformation;return Ue(({offset:n,zoom:r})=>[n[0]-e/r,n[1]-t/r]),c().view.transformation!==n},Qe=(e=1)=>Ue(({offset:t},{interaction:{moveAcceleration:n}})=>[t[0]-n[0]*e,t[1]-n[1]*e]),$e=e=>T(t=>t.view.gridGap===e?t:{...t,view:{...t.view,gridGap:e}}),et=e=>T(t=>{let n=q(e,h(t)),r=t.document.selectedShape?.id!==e.map(e=>e.id).join(`-`);return{...t,document:Ko(t.document,{type:`SET_SELECTION`,newSelectedShape:n}),tools:r&&t.tools.activeToolId!==v.id?{...t.tools,activeToolId:v.id}:t.tools}}),tt=e=>l(()=>{ne(e),et(e)}),nt=(e,{index:t=0,save:n=!0,source:r,select:i=!1}={})=>l(()=>{ne(e,t),n&&re(r),i&&et(e)}),rt=()=>et(c().document.shapes.filter(e=>!e.locked)),it=(e,t)=>l(()=>{ae(e,t),Ne(v),R()}),at=()=>Jo(t.props,t.overrides).resolvePictureSrc,ot=async(e,t)=>{let n=c(),{shapes:r,failedPictures:i}=await ho(e,{ctx:x(),settings:h(n),tools:n.tools.available,usedIds:new Set,resolvePictureSrc:at()});it(r,t);for(let{shape:e,error:t}of i)o(`pictureLoadFailed`,e,t)},st=()=>{m||(m=!0,t.props.shapes&&ot(t.props.shapes,{clearHistory:!0,source:`remote`}))},ct=e=>cr({shapes:c().document.shapes,settings:h(),options:e}),lt=()=>{let{document:e,config:t}=c();return Gn(e.shapes,t.width,t.height)},ut=(e,t,n)=>{for(let[r,i]of Object.entries(n))e?.removeEventListener(r,i),t?.addEventListener(r,i)},dt=e=>({focusin:()=>r.selectIsInteractive(c())&&ze({[e]:!0}),focusout:()=>r.selectIsInteractive(c())&&ze({[e]:!1})}),ft={focusin:()=>r.selectIsInteractive(c())&&ze({component:!0}),focusout:e=>{e.relatedTarget&&p?.contains(e.relatedTarget)||l(()=>{Re({shift:!1,alt:!1,space:!1}),ze({component:!1})})}},z=dt(`canvas`),pt=new Set([ft]),ht=()=>{let e=f??d;if(e!==p){for(let t of pt)ut(p,e,t);p=e}},xt=e=>(pt.add(e),ut(null,p,e),()=>{pt.delete(e),ut(p,null,e)}),St=e=>{f=e,ht()},Ct=e=>{d=e,ht()},wt=e=>{e!==u&&(ut(u,e,z),u=e)},Tt=()=>{let e=u?.getBoundingClientRect();return e?.width&&e.height?e:void 0},Et=({x:e,y:t})=>{let n=Tt();return n?Ki({clientX:e,clientY:t},n,h()):void 0},Dt=e=>{let t=Tt();return t?qi(e,t,h()):void 0},Ot=J(os),kt=()=>{let{shapes:e,selectedShape:t}=c().document;return Ot(e,t)},B=e=>{let t=kt();return le(e.map(e=>t.get(e)))},V=(e,t,n)=>{let r=B(e);r.length&&fe(t(r,h()),n)},At=e=>l(()=>{A(e.originalShape),Me(v),ke(void 0),Pe({mode:`contextMenu`,...e})}),jt=e=>{let t=e?B(e):I(c().document.selectedShape);if(t.length){let e=q(t,h());T(t=>({...t,clipboard:e}))}return t},Mt=e=>{if(e.type!==`picture`)return;let t=()=>{let t=c().document.shapes.find(t=>t.id===e.id);return t?.type===`picture`&&t.img===e.img?t:void 0};rr(e.img,e.src,at()).then(()=>{let e=t();if(!e)return;let n={...e};P([n]),o(`pictureLoaded`,n)},n=>{console.warn(`react-paint: the picture ${e.id} could not be loaded`,n);let r=t();r&&o(`pictureLoadFailed`,r,n)})},Nt=(e,t)=>{po(e,`addShapes`);let n=c(),r=new Set(n.document.shapes.map(e=>e.id)),i={ctx:x(),settings:h(n),tools:n.tools.available,usedIds:r,completeStyle:!0},a=e.map(e=>mo(e,i));if(!a.length)return[];nt(a,t);for(let e of a)Mt(e);return a.map(e=>e.id)},Pt=(e,t)=>{let n=kt();_o(e,n);let r=x(),i=h(),a=new Map,o=[];for(let t of e){let e=a.get(t.id)??n.get(t.id);if(!e)continue;let s=vo(r,e,t,i);s.type===`picture`&&e.type===`picture`&&s.src!==e.src&&(s={...s,img:new Image},o.push(s)),a.set(t.id,s)}fe([...a.values()],t);for(let e of o)Mt(e)},Ft=(e,t)=>{let n=B([e])[0];return n&&t.includes(n.type)&&`points`in n&&n.type!==`brush`?n:void 0},It={selectTool:e=>{let t=ja(c().tools.available,typeof e==`string`?e:e.id);t&&Ne(t)},updateToolSettings:(e,t,n)=>T(r=>rs(r,e,{[t]:n})),setToolStyle:(e,t)=>T(n=>rs(n,e,t)),selectShapes:(e,{mode:t=`replace`}={})=>{let n=B(e),{selectedShape:r}=c().document;et(t===`add`?ka(r,n):t===`remove`?Aa(r,n):n)},selectAllShapes:rt,clearSelection:()=>A(void 0),addShapes:Nt,updateShapes:Pt,removeShapes:(e,{source:t}={})=>xe(B(e),t),duplicateShapes:(e,{translate:t=!1,select:n=!1}={})=>oe(B(e),t,n),translateShapes:(e,[t,n],r)=>V(e,(e,r)=>e.map(e=>li(e,t,n,r)),r),rotateShapes:(e,t,{center:n,...r}={})=>V(e,(e,r)=>as(e,t,n,r),r),resizeShapes:(e,t,n)=>V(e,(e,n)=>si(x(),e,t,n),n),transformShapes:(e,t)=>V(e,(e,n)=>t===`rotateClockwise`||t===`rotateCounterclockwise`?as(e,t===`rotateClockwise`?Math.PI/2:-Math.PI/2,void 0,n):ci(x(),e,t,n)),setShapesStyle:(e,t,{updateTool:n=!1,...r}={})=>l(()=>{let i=x();if(V(e,(e,n)=>e.map(e=>fi(i,e,t,n)),r),!n)return;let{available:a}=c().tools,o=new Set(le(B(e).map(e=>be(a,e)?.id)));T(e=>[...o].reduce((e,n)=>rs(e,n,t),e))}),updateShapesStyle:(e,t,n,{save:r=!0}={})=>It.setShapesStyle(e,{[t]:n},{save:r}),moveShapes:(e,t)=>Ce(B(e),t),swapShapes:Se,setShapeIndex:(e,t)=>{let{shapes:n}=c().document,r=n.findIndex(t=>t.id===e);r!==-1&&L(de(n,r,se(Math.round(t),0,n.length-1)))},reorderShapes:e=>{let{shapes:t}=c().document,n=new Map(t.map(e=>[e.id,e])),r=le([...new Set(e)].map(e=>n.get(e))),i=new Set(r);L([...r,...t.filter(e=>!i.has(e))])},toggleShapesVisibility:e=>Te(B(e)),toggleShapesLock:e=>De(B(e)),setShapesVisibility:(e,t)=>{let n=B(e).filter(e=>e.visible!==!1!==t);n.length&&Te(n)},setShapesLocked:(e,t)=>{let n=B(e).filter(e=>!!e.locked!==t);n.length&&De(n)},insertShapePoint:(e,t,n)=>{let r=Ft(e,[`polygon`,`curve`]);r&&Pt([{id:e,points:ue(r.points,t,n)}])},moveShapePoint:(e,t,n)=>{let r=Ft(e,[`line`,`polygon`,`curve`]);!r||t<0||t>=r.points.length||Pt([{id:e,points:r.points.map((e,r)=>r===t?n:e)}])},removeShapePoint:(e,t)=>{let n=B([e])[0];if(!di(n,t))return;let r=h();P([n.type===`curve`?dn(n,t,r):tn(n,t,r)],!0)},editText:e=>{let t=B([e])[0];t?.type===`text`&&u&&l(()=>{et([t]),Pe({mode:`textedition`,defaultValue:t.value})})},addPicture:async(e,{maxWidth:t=c().config.width,maxHeight:n=c().config.height,select:r=!0,position:i}={})=>{let a=await gr(e,t,n,h(),at(),i);return nt([a],{select:r}),a},copy:e=>{jt(e)},cut:e=>{let t=jt(e);t.length&&xe(t)},paste:()=>{let{clipboard:e}=c();e&&tt(gi(e,h()))},undo:j,redo:ie,saveShapes:()=>re(),clearCanvas:()=>{let{clearCallback:e}=Jo(t.props,t.overrides),n=t.props.shapes;typeof e==`string`?e===`defaultShapes`&&n!==void 0?ot(n,{clearHistory:!1,source:`user`}):it([],{clearHistory:!1,source:`user`}):ot(e(),{clearHistory:!1,source:`user`})},loadFile:async e=>It.loadData(await dr(e)),loadData:async(e,{clearHistory:t=!0}={})=>{let n=typeof e==`string`?JSON.parse(e):e,r=F(n)&&Array.isArray(n.shapes)?n.shapes:[];await ot(r,{clearHistory:t,source:`remote`})},exportPicture:({fileName:e,...t}={})=>$n(ct(t),e??is(t.format)),exportData:({fileName:e=`drawing.json`}={})=>{let{document:t,config:n}=c(),r=lr(t.shapes,n.width,n.height);if(!r)throw Error(`L'encodage a échoué`);$n(r,e)},setZoom:Ke,zoomTo:(e,{center:t}={})=>qe(e,t),zoomToShapes:(e,{padding:t=0}={})=>Ye(e?B(e):c().document.shapes.filter(e=>e.visible!==!1),t),resetZoom:R,setOffset:We,panBy:([e,t])=>Ue(({offset:n})=>[n[0]-e,n[1]-t]),setGridGap:$e,openContextMenu:({clientPosition:e,canvasPosition:t,ids:n})=>{let i=c();if(!r.selectWithContextMenu(i))return;let a=h(i);At({cursorStartPosition:t??Et(e)??[0,0],clientPosition:e,originalShape:q(n?B(n):I(i.document.selectedShape),a),anchor:void 0})},closeContextMenu:()=>{c().interaction.selectionMode.mode===`contextMenu`&&(Pe({mode:`default`}),u?.focus())},setOptions:e=>{t.overrides=me(_e(ge,t.overrides,e)),O()},resetOptions:()=>{t.overrides={},O()},resetSettings:()=>T(e=>{let{tools:t,view:n}=Yo(e.config);return{...e,tools:t,view:{...e.view,transformation:n.transformation,gridGap:n.gridGap}}})};return{getState:c,subscribe:n.subscribe,watch:n.watch,batch:l,transaction:te,selectors:r,getSettings:h,getEditorState:()=>r.selectEditorState(c()),actions:It,registerEvent:i,unregisterEvent:a,emit:o,hasListeners:s,setConfig:k,init:st,resetCanvas:(e=[],t=!0)=>ot(e,{clearHistory:t,source:`remote`}),getCurrentImage:ct,getCurrentData:lt,getShape:e=>kt().get(e),getBounds:e=>{let t=h(),n=q(B(e),t);if(n)return{...oi(n,t),rotation:n.rotation??0,center:n.computed.center}},getShapesAt:e=>{let t=b();return t?ha(t,c().document.shapes,e,h()):[]},getShapeAt:e=>{let t=b();return t?ga(t,c().document.shapes,e,h()):void 0},toCanvasPosition:Et,toClientPosition:Dt,setScopeElement:St,setCanvasRootElement:Ct,setCanvasElement:wt,listenScope:xt,setSelectedShape:A,addShapes:ne,duplicateShapes:oe,refreshHoveredShape:N,clearHover:ce,updateShapes:P,removeShapes:xe,refreshSelectedShapes:Oe,setSelectionFrame:ke,setActiveTool:Me,setSelectionMode:Pe,showContextMenu:At,setHoverMode:Fe,setPanStart:Ie,setMoveAcceleration:Le,setModifiers:Re,setCanvasSize:Be,setTransformation:He,getViewBounds:g,zoomBy:Xe,scrollBy:Ze,applyMoveAcceleration:Qe}},cs=(e={})=>{let[n]=(0,t.useState)(()=>Po(ss(e))),r=Fo(n);return(0,t.useLayoutEffect)(()=>{r.setConfig(e)}),(0,t.useEffect)(()=>{r.init()},[r]),n},ls={position:`relative`,width:`100%`,height:`100%`,flex:`1 1 0`,minWidth:0,minHeight:0,overflow:`hidden`},us=({paint:e,options:r,className:i,style:a})=>{let o=Fo(e),s=(0,t.useCallback)(()=>o.selectors.selectCanvasView(o.getState()),[o]),c=(0,t.useSyncExternalStore)(o.subscribe,s,s),{width:l,canvasSize:u,resize:d}=c,{canvasBackgroundColor:f,canvasSelectionColor:p,canvasSelectionWidth:m}=he(j,r),h=(0,t.useRef)(null),g=(0,t.useCallback)(e=>{h.current=e,o.setCanvasRootElement(e)},[o]),_=(0,t.useRef)(0);(0,t.useEffect)(()=>()=>cancelAnimationFrame(_.current),[]);let v=(0,t.useCallback)((e,t)=>{if(cancelAnimationFrame(_.current),d===`extend`){let n=Math.round(e),r=Math.round(t);n&&r&&o.setCanvasSize(De(n,r))}else _.current=requestAnimationFrame(()=>{let{config:t}=o.getState();o.setCanvasSize(Ee(e,t.width,t.height))})},[d,o]);ko(o),jo(o),Mo({element:h,onResized:v});let y=`calc(${P(`--react-paint-app-canvaswidth`,l)} * 1px)`,b=d===`extend`?ls:{position:`relative`,width:`100%`,maxWidth:Oe(d)?`100%`:y,minWidth:ke(d)?void 0:y,aspectRatio:P(`--react-paint-app-row-aspectratio`,`${u.width} / ${u.height}`)};return(0,n.jsx)(`div`,{ref:g,className:`react-paint-app-row${i?` ${i}`:``}`,style:{...b,...a},children:(0,n.jsx)(Do,{store:o,view:c,backgroundColor:f,selectionColor:p,selectionWidth:m})})},ds={LOADING:2,PANEL:3,SNACKBAR:4},fs=({isLoading:e=!1})=>{let[r,i]=(0,t.useState)(`hidden`);return(0,t.useEffect)(()=>{if(e)i(`visible`);else{i(`fadeOut`);let e=setTimeout(()=>i(`hidden`),300);return()=>{clearTimeout(e)}}},[e]),r===`hidden`?null:(0,n.jsx)(`div`,{className:`react-paint-editor-loading`,"data-loading":r,style:{"--react-paint-editor-loading-zindex":ds.LOADING,"--react-paint-editor-loading-transition-duration":`300ms`},children:(0,n.jsxs)(`div`,{className:`react-paint-editor-loader`,children:[(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{}),(0,n.jsx)(`div`,{})]})})},ps={type:`infos`,duration:4e3},ms=({type:e,text:r,duration:i})=>{let[a,o]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{let e=setTimeout(()=>{o(!0)},100),t=setTimeout(()=>{o(!1)},i-500-100);return()=>{clearTimeout(e),clearTimeout(t)}},[i]),(0,n.jsx)(`div`,{className:`react-paint-editor-snackbar`,"data-is-shown":+a,"data-type":e,style:{"--react-paint-editor-panel-transition-duration":`500ms`},children:r})},hs=({snackbarList:e})=>(0,n.jsx)(`div`,{className:`react-paint-editor-snackbar-container`,style:{"--react-paint-editor-snackbar-zindex":ds.SNACKBAR},children:e.map(e=>(0,n.jsx)(ms,{...e},e.id))}),gs=t.default.forwardRef((e,r)=>{let{hidden:i=!1,disabled:a=!1,selected:o=!1,icon:s,children:c,className:l=``,title:u,onClick:d,...f}=e,p=a?-1:0,m=(0,t.useRef)(null);return(0,t.useImperativeHandle)(r,()=>m.current),(0,n.jsxs)(`label`,{className:`react-paint-editor-button ${l}`,title:u,onClick:d,"data-disabled":+a,"data-selected":+o,"data-hidden":+i,tabIndex:p,onKeyDown:e=>{e.key===` `&&(e.preventDefault(),e.stopPropagation())},onKeyUp:e=>{e.preventDefault(),e.stopPropagation(),e.key===` `&&m.current?.click()},children:[(0,n.jsx)(`input`,{ref:m,disabled:a,...f}),(0,n.jsxs)(`span`,{className:`react-paint-editor-button-content`,children:[c&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-children`,children:c}),s&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-icon`,dangerouslySetInnerHTML:{__html:s}})]})]})}),$=t.default.forwardRef((e,t)=>{if(e.type===`file`||e.type===`color`)return(0,n.jsx)(gs,{...e,ref:t});let{hidden:r=!1,disabled:i=!1,selected:a=!1,icon:o,children:s,type:c=`button`,className:l=``,...u}=e;return(0,n.jsx)(`button`,{className:`react-paint-editor-button ${l}`,ref:t,disabled:i,"data-disabled":+i,"data-selected":+a,"data-hidden":+r,type:c,...u,children:(0,n.jsxs)(`span`,{className:`react-paint-editor-button-content`,children:[s&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-children`,children:s}),o&&(0,n.jsx)(`span`,{className:`react-paint-editor-button-icon`,dangerouslySetInnerHTML:{__html:o}})]})})}),_s=({children:e,title:t=``,className:r=``,position:i,fitContainer:a=!1,alignment:o,style:s,...c})=>(0,n.jsxs)(`div`,{className:`react-paint-editor-panel ${r}`,"data-fitcontainer":a,"data-position":i??`unset`,"data-alignment":o??`unset`,style:{...s,"--react-paint-editor-panel-zindex":ds.PANEL},...c,children:[t&&(0,n.jsx)(`h3`,{className:`react-paint-editor-panel-title`,children:t}),e]}),vs=`<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>`,ys=`<svg><path d="M2.5 17.5V2.5H17.5V17.5ZM4.25 15.75H15.75V4.25H4.25ZM4.25 15.75V4.25V15.75Z"/></svg>`,bs=`<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>`,xs=`<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>`,Ss=`<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>`,Cs=`<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>`,ws=`<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>`,Ts=`<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>`,Es=`<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>`,Ds=`<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>`,Os=`<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>`,ks=`<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>`,As=`<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>`,js=`<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>`,Ms=`<svg><path d="M8.708 16.667V5.917H4.167V3.333H15.833V5.917H11.292V16.667Z"/></svg>`,Ns=`<svg><path d="M7.5 15.833V14.083H12.833L3.333 4.583L4.583 3.333L14.083 12.833V7.5H15.833V15.833Z"/></svg>`,Ps=`<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>`,Fs=`<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>`,Is=`<svg><path d="M2.5 15V13.25H17.5V15ZM2.5 10.875V9.125H17.5V10.875ZM2.5 6.75V5H17.5V6.75Z"/></svg>`,Ls=`<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>`,Rs=`<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>`,zs=`<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>`,Bs=`<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>`,Vs=`<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>`,Hs=`<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>`,Us=`<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>`,Ws=`<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>`,Gs=`<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>`,Ks=`<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>`,qs=`<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>`,Js=`<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>`,Ys=`<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>`,Xs=`<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>`,Zs=({disabled:e=!1,ref:n,shape:r,layoutDragging:i,setLayoutDragging:a,handleSelect:o,onSwapShapes:s})=>{let[c,l]=(0,t.useState)(!1);return(0,t.useEffect)(()=>{i||l(!1)},[i]),(0,t.useEffect)(()=>{let t=n.current;if(!t)return;let c=()=>{a(void 0)},u=e=>(e.preventDefault&&e.preventDefault(),!1),d=e=>{o([r.id]),e.dataTransfer&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`draggableShapeId`,r.id),a(r.id))},f=()=>{i!==r.id&&l(!0)},p=()=>{l(!1)},m=e=>(e.stopPropagation(),e.dataTransfer&&s(e.dataTransfer.getData(`draggableShapeId`),r.id),!1);return e||(t.addEventListener(`dragstart`,d),t.addEventListener(`dragend`,c),t.addEventListener(`dragover`,u),t.addEventListener(`dragenter`,f),t.addEventListener(`dragleave`,p),t.addEventListener(`drop`,m)),()=>{e||(t.removeEventListener(`dragstart`,d),t.removeEventListener(`dragend`,c),t.removeEventListener(`dragover`,u),t.removeEventListener(`dragenter`,f),t.removeEventListener(`dragleave`,p),t.removeEventListener(`drop`,m))}},[e,n,r,a,o,s,i]),{isOver:c}},Qs={brush:`Brosse`,line:`Ligne`,polygon:`Polygone`,curve:`Courbe`,rect:`Rectangle`,square:`Carré`,circle:`Cercle`,ellipse:`Ellipse`,picture:`Image`,text:`Texte`,triangle:`Triangle`,group:`Groupe`},$s={...v,icon:Ps,label:`Sélection`},ec={...y,icon:Fs,label:`Move`},tc={type:`undo`,icon:ws,label:`Undo`},nc={type:`redo`,icon:Ts,label:`Redo`},rc={type:`clear`,icon:Ds,label:`Clear`},ic={type:`export`,icon:ks,label:`Export PNG`},ac={type:`loadfile`,icon:As,label:`Load project`},oc={type:`savefile`,icon:Os,label:`Save project`},sc={type:`uploadpicture`,icon:js,label:`Upload picture`},cc=e=>{switch(e){case`brush`:return vs;case`line`:return Ns;case`polygon`:return Ss;case`curve`:return Hs;case`rect`:return ys;case`square`:return ys;case`circle`:return xs;case`ellipse`:return xs;case`text`:return Ms;case`picture`:return js;case`group`:return Xs;case`triangle`:return``}},lc=e=>({...e,icon:e.icon??cc(e.type),label:e.label??Qs[e.type]}),uc=(0,t.memo)(function({disabled:e=!1,shape:r,selected:i,layoutDragging:a,toggleShapeVisibility:o,toggleShapeLock:s,setLayoutDragging:c,handleRemove:l,handleSelect:u,onSwapShapes:d}){let f=(0,t.useRef)(null),p=t=>{e||(t.preventDefault(),t.stopPropagation(),l([r.id]))},m=t=>{e||(t.preventDefault(),u([r.id]))},h=t=>{e||(t.preventDefault(),t.stopPropagation(),o([r.id]))},g=t=>{e||(t.preventDefault(),t.stopPropagation(),s([r.id]))},{isOver:_}=Zs({disabled:e,ref:f,shape:r,layoutDragging:a,setLayoutDragging:c,handleSelect:u,onSwapShapes:d});return(0,n.jsxs)(`div`,{className:`react-paint-editor-layout`,"data-disabled":+e,draggable:!e,"data-is-dragging":+(a===r.id),"data-is-over":+_,onClick:m,"data-selected":+i,ref:f,tabIndex:-1,children:[(0,n.jsx)(`span`,{dangerouslySetInnerHTML:{__html:cc(r.type)}}),(0,n.jsx)(`span`,{children:r.id}),(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-separator`}),(0,n.jsx)($,{className:`react-paint-editor-layouts-visible-button`,title:r.visible?`Hide`:`Show`,"data-visible":r.visible!==!1,disabled:e,selected:i,onClick:h,icon:r.visible===!1?Rs:Ls}),(0,n.jsx)($,{className:`react-paint-editor-layouts-locked-button`,title:r.locked?`Locked`:`Unlocked`,"data-locked":!!r.locked,disabled:e,selected:i,onClick:g,icon:r.locked?zs:Bs}),(0,n.jsx)($,{className:`react-paint-editor-layouts-remove-button`,title:`Remove`,disabled:e,onClick:p,icon:Cs})]})}),dc=e=>e>=Be.large?`large`:e>=Be.medium?`medium`:e>=Be.small?`small`:`none`,fc=()=>{let e,t=[],n=new Map;return({shapes:r})=>{if(r===e)return t;let i=new Map,a=r.map(({id:e,type:t,visible:r,locked:a})=>{let o=n.get(e),s=o?.type===t&&o.visible===r&&o.locked===a?o:{id:e,type:t,visible:r,locked:a};return i.set(e,s),s});return n=i,e=r,t=a,a}},pc=e=>e.selectedShapeIds,mc=({disabled:e})=>{let r=Ro(),{actions:i}=r,[a]=(0,t.useState)(fc),o=Z(r,a,M),s=Z(r,pc),c=dc(Z(r,e=>e.gridGap)),[l,u]=(0,t.useState)(void 0),d=(0,t.useMemo)(()=>new Set(s),[s]),f=e=>i.setGridGap(Be[e]);return(0,n.jsx)(_s,{alignment:`right`,className:`react-paint-editor-layouts-panel`,position:`bottom`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-panel-content`,children:(0,n.jsxs)(`div`,{className:`react-paint-editor-layouts-scrolling-content`,children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-layouts-row`,children:[(0,n.jsx)(`span`,{className:`react-paint-editor-layouts-subtitle`,children:`Grid`}),(0,n.jsx)($,{"aria-label":`No grid`,icon:Vs,className:`react-paint-editor-layouts-grid-button`,selected:c===`none`,disabled:e,onClick:()=>f(`none`)}),[`small`,`medium`,`large`].map(t=>(0,n.jsx)($,{className:`react-paint-editor-layouts-grid-button`,selected:c===t,disabled:e,onClick:()=>f(t),children:t.charAt(0).toUpperCase()},t))]}),(0,n.jsx)(`hr`,{}),(0,n.jsx)(`div`,{className:`react-paint-editor-layouts`,children:o.length===0?(0,n.jsx)(`div`,{className:`react-paint-editor-layouts-placeholder`,children:`No layer yet`}):o.map(t=>(0,n.jsx)(uc,{shape:t,disabled:e,layoutDragging:l,setLayoutDragging:u,selected:d.has(t.id),handleSelect:i.selectShapes,handleRemove:i.removeShapes,onSwapShapes:i.swapShapes,toggleShapeVisibility:i.toggleShapesVisibility,toggleShapeLock:i.toggleShapesLock},t.id))})]})})})},hc=({disabled:e,isLayoutPanelShown:t})=>t?(0,n.jsx)(mc,{disabled:e}):null,gc=({children:e,onClose:t,position:r=`center`,title:i,className:a=``})=>(0,n.jsxs)(`div`,{className:`react-paint-editor-modal`,"data-position":r,style:{"--react-paint-editor-modal-zindex":ds.PANEL},role:`dialog`,"aria-modal":`true`,"aria-labelledby":i,children:[(0,n.jsx)(`div`,{className:`react-paint-editor-modal-mask`,onClick:t}),(0,n.jsx)(`div`,{className:`react-paint-editor-modal-panel ${a}`,children:e})]}),_c={},vc=(e=``)=>(_c[e]||(_c[e]=0),`${e}${++_c[e]}`),yc=(e,t,n)=>Math.max(t,Math.min(e,n)),bc=e=>e.filter(e=>e!=null),xc=(e,t)=>({...e,...Object.fromEntries(Object.entries(t??{}).filter(([,e])=>e!==void 0))}),Sc=({selectedSettings:e,setSelectedSettings:r,title:i=`Choisissez une couleur`,mode:a=`fill`,disabled:o=!1,values:s,field:c,value:l=``,valueChanged:u})=>{let[d]=(0,t.useState)(vc(`settings_`)),f=e=>{let t=+e.target.value;u(c,Number.isNaN(t)?e.target.value:t)},p=e=>{u(c,e)},m=()=>{r(e=>e===d?void 0:d)},h=e===d;return s.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selected:h,title:i,disabled:o,onClick:m,icon:l===`transparent`?a===`fill`?qs:Ks:void 0,children:l!==`transparent`&&(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-color`,"data-mode":a,style:{"--react-paint-editor-colorfield-color-value":l}})}),h&&(0,n.jsx)(_s,{title:i,alignment:`left`,position:`bottom`,children:(0,n.jsxs)(`div`,{className:`react-paint-editor-colorfield-wrapper`,children:[s.map(e=>(0,n.jsx)($,{title:e,selected:e===l,color:e,icon:e===`transparent`?a===`fill`?`<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>`:`<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>`:void 0,onClick:()=>p(e),children:e!==`transparent`&&(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-color`,color:e,"data-mode":a,style:{"--react-paint-editor-colorfield-color-value":e}})},e)),(0,n.jsx)($,{type:`color`,title:`Custom color`,selected:l!==``&&!s.includes(l),value:l,onChange:f,children:(0,n.jsx)(`div`,{className:`react-paint-editor-colorfield-customcolor`,style:{"--react-paint-editor-colorfield-color-value":s.includes(l)?`var(--react-paint-editor-app-font-color)`:l},children:(0,n.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},Cc=({disabled:e=!1,selectedShapeIds:t,removeShapes:r})=>(0,n.jsx)($,{title:`Delete`,disabled:e,"data-disabled":+e,onClick:()=>{r(t)},icon:Cs}),wc=({CustomOption:e,selectedSettings:r,setSelectedSettings:i,title:a=`Choisissez l'option`,disabled:o=!1,field:s,icon:c,values:l,defaultValue:u,valueChanged:d})=>{let[f]=(0,t.useState)(vc(`settings_`)),p=e=>{d(s,e)},m=()=>{i(e=>e===f?void 0:f)},h=r===f;return l.length?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selected:h,title:a,icon:c,disabled:o,onClick:m}),h&&(0,n.jsx)(_s,{title:a,alignment:`left`,fitContainer:!0,position:`bottom`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-selectfield-wrapper`,children:l.map(t=>(0,n.jsx)($,{title:`${t}`,onClick:()=>p(t),selected:u===t,style:{"--react-paint-editor-button-padding":`16px`},children:(0,n.jsx)(e,{children:t})},t))})})]}):null},Tc=({children:e})=>(0,n.jsx)(`span`,{className:`react-paint-editor-fontfamily-option`,style:{"--react-paint-editor-fontfamily-family":e},children:e}),Ec=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(wc,{selectedSettings:e,setSelectedSettings:t,CustomOption:Tc,title:`Police`,icon:Ws,disabled:r,field:`fontFamily`,values:i,defaultValue:a,valueChanged:o}):null,Dc=({disabled:e,toggleLayoutPanel:t})=>(0,n.jsx)($,{title:`Toggle layers panel`,disabled:e,onClick:t,icon:Es,className:`react-paint-editor-layout-button`}),Oc=({children:e})=>(0,n.jsxs)(`span`,{className:`react-paint-editor-linearrow-option`,"data-type":e,children:[(0,n.jsx)(`span`,{className:`react-paint-editor-linearrow-left`}),(0,n.jsx)(`span`,{className:`react-paint-editor-linearrow-right`})]}),kc=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(wc,{selectedSettings:e,setSelectedSettings:t,CustomOption:Oc,title:`Flèches`,icon:Gs,disabled:r,field:`lineArrow`,values:i,defaultValue:a,valueChanged:o}):null,Ac=({children:e})=>(0,n.jsxs)(`span`,{className:`react-paint-editor-linetype-option`,"data-type":e,children:[(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{}),(0,n.jsx)(`span`,{})]}),jc=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,values:i,defaultValue:a,valueChanged:o})=>i.length?(0,n.jsx)(wc,{selectedSettings:e,setSelectedSettings:t,CustomOption:Ac,icon:Us,title:`Type de traits`,disabled:r,field:`lineDash`,values:i,defaultValue:a,valueChanged:o}):null,Mc=(e,n=500)=>{let r=(0,t.useRef)(null),i=(0,t.useCallback)((...t)=>{r.current&&clearTimeout(r.current),r.current=setTimeout(()=>e(...t),n)},[e,n]);return(0,t.useEffect)(()=>()=>{r.current&&clearTimeout(r.current)},[]),i},Nc=({selectedSettings:e,setSelectedSettings:r,title:i=`Choisissez l'intervalle`,icon:a,disabled:o=!1,field:s,value:c,min:l=1,max:u=20,step:d=1,unity:f=``,valueChanged:p,saveShapes:m})=>{let h=c===void 0,g=h?`N/A`:`${Math.round(c)}${f}`,[_]=(0,t.useState)(vc(`settings_`)),v=Mc(m),y=e=>{let t=+e.target.value;p(s,Number.isNaN(t)?e.target.value:t,!1),v()},b=()=>{r(e=>e===_?void 0:_)},x=e===_;return l===u?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{selected:x,title:i,disabled:o,icon:a,onClick:b}),x&&(0,n.jsx)(_s,{title:i,alignment:`left`,fitContainer:!0,position:`bottom`,children:(0,n.jsx)(`div`,{children:(0,n.jsxs)(`label`,{className:`react-paint-editor-rangefield`,children:[(0,n.jsx)(`input`,{type:`range`,min:l,max:u,step:d,value:c??(u+l)/2,"data-indeterminate":+h,onChange:y}),(0,n.jsx)(`span`,{children:g})]})})})]})},Pc=({children:e})=>(0,n.jsx)(`span`,{children:e===0?`Non`:`Oui`}),Fc=[0,1],Ic=({selectedSettings:e,setSelectedSettings:t,disabled:r=!1,defaultValue:i,valueChanged:a})=>(0,n.jsx)(wc,{selectedSettings:e,setSelectedSettings:t,CustomOption:Pc,title:`Fermer les points`,icon:Ss,disabled:r,field:`closedPoints`,values:Fc,defaultValue:i,valueChanged:a}),Lc=({disabled:e=!1,className:t,toggleZoomPanel:r})=>(0,n.jsx)($,{title:`Toggle zoom panel`,disabled:e,onClick:r,icon:Js,className:`${t?` ${t}`:``}`}),Rc=({setSelectedSettings:e,disabled:r=!1,field:i,icon:a,title:o,values:s,value:c=!1,valueChanged:l})=>{let[u]=(0,t.useState)(vc(`settings_`));return s.length===2?(0,n.jsx)($,{onClick:()=>{e(e=>e===u?void 0:u),l(i,!c)},selected:c,disabled:r,icon:a,title:o}):null},zc=40,Bc=({activeTool:e,hasSelection:t,selectedStyle:r,selectedShapeTool:i,disabled:a,selectedSettings:o,setSelectedSettings:s,saveShapes:c,handleShapeStyleChange:l})=>t?i&&(0,n.jsxs)(n.Fragment,{children:[`strokeColor`in i.settings&&!i.settings.strokeColor.hidden&&(0,n.jsx)(Sc,{selectedSettings:o,setSelectedSettings:s,title:`Couleur du trait`,mode:`stroke`,disabled:a,field:`strokeColor`,value:r?.strokeColor,valueChanged:l,values:i.settings.strokeColor.values}),`fillColor`in i.settings&&!i.settings.fillColor.hidden&&(0,n.jsx)(Sc,{selectedSettings:o,setSelectedSettings:s,title:`Couleur de fond`,disabled:a,field:`fillColor`,value:r?.fillColor,valueChanged:l,values:i.settings.fillColor.values}),`lineWidth`in i.settings&&!i.settings.lineWidth.hidden&&(0,n.jsx)(Nc,{saveShapes:c,selectedSettings:o,setSelectedSettings:s,title:`Epaisseur du trait`,icon:`<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>`,disabled:a,field:`lineWidth`,value:r?.lineWidth,valueChanged:l,unity:`px`,min:i.settings.lineWidth.min,max:i.settings.lineWidth.max,step:i.settings.lineWidth.step}),`lineDash`in i.settings&&!i.settings.lineDash.hidden&&(0,n.jsx)(jc,{selectedSettings:o,setSelectedSettings:s,disabled:a,defaultValue:r?.lineDash,valueChanged:l,values:i.settings.lineDash.values}),`lineArrow`in i.settings&&!i.settings.lineArrow.hidden&&(0,n.jsx)(kc,{selectedSettings:o,setSelectedSettings:s,disabled:a,defaultValue:r?.lineArrow,valueChanged:l,values:i.settings.lineArrow.values}),`closedPoints`in i.settings&&!i.settings.closedPoints.hidden&&(0,n.jsx)(Ic,{selectedSettings:o,setSelectedSettings:s,disabled:a,valueChanged:l,defaultValue:r?.closedPoints}),`fontFamily`in i.settings&&!i.settings.fontFamily.hidden&&(0,n.jsx)(Ec,{selectedSettings:o,setSelectedSettings:s,disabled:a,valueChanged:l,values:i.settings.fontFamily.values,defaultValue:r?.fontFamily}),`fontBold`in i.settings&&!i.settings.fontBold.hidden&&(0,n.jsx)(Rc,{setSelectedSettings:s,disabled:a,field:`fontBold`,icon:`<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>`,title:`Gras`,valueChanged:l,values:i.settings.fontBold.values,value:r?.fontBold}),`fontItalic`in i.settings&&!i.settings.fontItalic.hidden&&(0,n.jsx)(Rc,{setSelectedSettings:s,disabled:a,field:`fontItalic`,icon:`<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>`,title:`Italique`,valueChanged:l,values:i.settings.fontItalic.values,value:r?.fontItalic}),`opacity`in i.settings&&!i.settings.opacity.hidden&&(0,n.jsx)(Nc,{saveShapes:c,selectedSettings:o,setSelectedSettings:s,title:`Opacité`,icon:`<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>`,min:i.settings.opacity.min,max:i.settings.opacity.max,step:i.settings.opacity.step,unity:`%`,disabled:a,field:`opacity`,value:r?.opacity,valueChanged:l})]}):`settings`in e?(0,n.jsxs)(n.Fragment,{children:[`strokeColor`in e.settings&&!e.settings.strokeColor.hidden&&(0,n.jsx)(Sc,{selectedSettings:o,setSelectedSettings:s,title:`Couleur du trait`,mode:`stroke`,disabled:a,field:`strokeColor`,value:e.settings.strokeColor.default,valueChanged:l,values:e.settings.strokeColor.values}),`fillColor`in e.settings&&!e.settings.fillColor.hidden&&(0,n.jsx)(Sc,{selectedSettings:o,setSelectedSettings:s,title:`Couleur de fond`,disabled:a,field:`fillColor`,value:e.settings.fillColor.default,valueChanged:l,values:e.settings.fillColor.values}),`lineWidth`in e.settings&&!e.settings.lineWidth.hidden&&(0,n.jsx)(Nc,{saveShapes:c,selectedSettings:o,setSelectedSettings:s,title:`Epaisseur du trait`,disabled:a,field:`lineWidth`,icon:`<svg><path d="M3.021 16V15H17V16ZM3.021 13.5V12H17V13.5ZM3 10.5V8.5H16.979V10.5ZM3.021 7V4H17V7Z"/></svg>`,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&&(0,n.jsx)(jc,{selectedSettings:o,setSelectedSettings:s,disabled:a,defaultValue:e.settings.lineDash.default,valueChanged:l,values:e.settings.lineDash.values}),`lineArrow`in e.settings&&!e.settings.lineArrow.hidden&&(0,n.jsx)(kc,{selectedSettings:o,setSelectedSettings:s,disabled:a,defaultValue:e.settings.lineArrow.default,valueChanged:l,values:e.settings.lineArrow.values}),`closedPoints`in e.settings&&!e.settings.closedPoints.hidden&&(0,n.jsx)(Ic,{selectedSettings:o,setSelectedSettings:s,disabled:a,valueChanged:l,defaultValue:e.settings?.closedPoints.default}),`fontFamily`in e.settings&&!e.settings.fontFamily.hidden&&(0,n.jsx)(Ec,{selectedSettings:o,setSelectedSettings:s,disabled:a,valueChanged:l,values:e.settings.fontFamily.values,defaultValue:e.settings.fontFamily.default}),`fontBold`in e.settings&&!e.settings.fontBold.hidden&&(0,n.jsx)(Rc,{setSelectedSettings:s,disabled:a,field:`fontBold`,icon:`<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>`,title:`Gras`,valueChanged:l,values:e.settings.fontBold.values,value:e.settings.fontBold.default}),`fontItalic`in e.settings&&!e.settings.fontItalic.hidden&&(0,n.jsx)(Rc,{setSelectedSettings:s,disabled:a,field:`fontItalic`,icon:`<svg><path d="M4.167 16.667V14.083H6.979L10.229 5.917H7.5V3.333H15.833V5.917H13.021L9.771 14.083H12.5V16.667Z"/></svg>`,title:`Italique`,valueChanged:l,values:e.settings.fontItalic.values,value:e.settings.fontItalic.default}),`opacity`in e.settings&&!e.settings.opacity.hidden&&(0,n.jsx)(Nc,{saveShapes:c,selectedSettings:o,setSelectedSettings:s,title:`Opacité`,icon:`<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>`,min:e.settings.opacity.min,max:e.settings.opacity.max,step:e.settings.opacity.step,unity:`%`,disabled:a,field:`opacity`,value:e.settings.opacity.default,valueChanged:l})]}):null,Vc=()=>{let e;return t=>((e?.ids!==t.selectedShapeIds||e.tools!==t.tools)&&(e={ids:t.selectedShapeIds,tools:t.tools,tool:Se(t.selection,t.tools)}),{width:t.view.displayWidth,activeTool:t.activeTool,selectedStyle:t.selection?.style,selectedShapeIds:t.selectedShapeIds,selectedShapeTool:e.tool})},Hc=(e,t)=>e.width===t.width&&e.activeTool===t.activeTool&&e.selectedShapeIds===t.selectedShapeIds&&e.selectedShapeTool===t.selectedShapeTool&&M(e.selectedStyle,t.selectedStyle),Uc=({disabled:e,withZoom:r,layersManipulation:i=!1,toggleLayoutPanel:a,isZoomPanelShown:o,setIsZoomPanelShown:s})=>{let c=Ro(),{actions:l}=c,[u]=(0,t.useState)(Vc),{width:d,activeTool:f,selectedStyle:p,selectedShapeIds:m,selectedShapeTool:h}=Z(c,u,Hc),g=m.length>0,[_,v]=(0,t.useState)(void 0),[y,b]=(0,t.useState)(!1),x=()=>{b(e=>!e)},S=()=>{s(e=>!e)},C=(h?Object.keys(h.settings).length+1:`settings`in f?Object.keys(f.settings).length:0)+ +i+ +r,w=d<C*zc,T=(e,t,n=!0)=>{m.length?l.setShapesStyle(m,{[e]:t},{save:n,updateTool:!0}):l.updateToolSettings(f.id,e,t)};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-settings-bar`,children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-settings-shrinkable`,children:[r&&(0,n.jsx)(Lc,{className:o?`react-paint-editor-bar-zoom-button-opened`:void 0,toggleZoomPanel:S}),w&&C>2&&(0,n.jsx)($,{disabled:e,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>`}),g?h&&(0,n.jsxs)(n.Fragment,{children:[!w&&(0,n.jsx)(Bc,{saveShapes:l.saveShapes,activeTool:f,hasSelection:g,selectedStyle:p,selectedShapeTool:h,disabled:e,selectedSettings:_,setSelectedSettings:v,handleShapeStyleChange:T}),f.type===`selection`&&(0,n.jsx)(Cc,{disabled:e,selectedShapeIds:m,removeShapes:l.removeShapes})]}):!w&&(0,n.jsx)(Bc,{saveShapes:l.saveShapes,activeTool:f,hasSelection:g,selectedStyle:p,selectedShapeTool:h,disabled:e,selectedSettings:_,setSelectedSettings:v,handleShapeStyleChange:T})]}),(0,n.jsx)(`div`,{className:`react-paint-editor-settings-separator`}),i&&(0,n.jsx)(Dc,{disabled:e,toggleLayoutPanel:a})]}),y&&(0,n.jsx)(gc,{className:`react-paint-editor-settings-modal`,onClose:x,position:`bottom`,title:`Settings`,children:(0,n.jsx)(Bc,{saveShapes:l.saveShapes,activeTool:f,hasSelection:g,selectedStyle:p,selectedShapeTool:h,disabled:e,selectedSettings:_,setSelectedSettings:v,handleShapeStyleChange:T})})]})},Wc=({isEditMode:e})=>{let t=Ro(),{actions:r}=t,i=Z(t,e=>e.view.zoom);return(0,n.jsxs)(_s,{alignment:`left`,position:`bottom`,className:`react-paint-editor-layouts-panel`,"data-edit":+e,children:[(0,n.jsx)($,{"aria-label":`Zoom out`,className:`react-paint-editor-zoom-button`,icon:Ys,disabled:i<=z[0],onClick:()=>r.setZoom(`unzoom`)}),(0,n.jsxs)($,{className:`react-paint-editor-zoom-button react-paint-editor-zoom-button-value`,onClick:()=>r.setZoom(`default`),children:[Math.round(i*100),`%`]}),(0,n.jsx)($,{"aria-label":`Zoom in`,className:`react-paint-editor-zoom-button`,icon:Js,disabled:i>=z[z.length-1],onClick:()=>r.setZoom(`zoom`)})]})},Gc=(e,t)=>bc(t.flatMap(t=>{if(typeof t!=`object`)return e.filter(e=>e.type===t);let n=e.filter(e=>t.toolsType.includes(e.type));return n?{...t,toolsType:n}:null})),Kc=({alignment:e,children:t,className:r,style:i,position:a,menuRef:o})=>(0,n.jsx)(_s,{alignment:e,position:a,className:r,style:i,children:(0,n.jsx)(`div`,{className:`react-paint-editor-menu`,role:`menu`,ref:o,children:t})}),qc=({disabled:e=!1,withText:r=!1,loadFile:i,type:a,accept:o})=>{let s=(0,t.useRef)(null);return(0,n.jsx)($,{ref:s,type:`file`,onClick:()=>{s.current&&(s.current.value=``)},onChange:e=>{let t=e.target.files?.item(0);t&&i(t)},accept:o,title:a.label,icon:a.icon,disabled:e,children:r?a.label:void 0})},Jc=(e,t)=>!(e.target instanceof Node)||!t?!1:t.contains(e.target),Yc=({trigger:e=`click`,disabled:n=!1}={})=>{let[r,i]=(0,t.useState)(null),[a,o]=(0,t.useState)(!1),[,s]=(0,t.useTransition)(),c=(0,t.useCallback)(()=>{s(()=>{o(!1)})},[]);return(0,t.useEffect)(()=>{if(!r||n)return;if(a){let t=e=>{Jc(e,r)||s(()=>{o(!1)})},n=()=>{s(()=>{o(!1)})};return e===`hover`?(r.addEventListener(`mouseleave`,n),()=>{r.removeEventListener(`mouseleave`,n)}):(document.addEventListener(`click`,t),()=>{document.removeEventListener(`click`,t)})}let t=()=>{s(()=>{o(!0)})};return e===`hover`?(r.addEventListener(`mouseenter`,t),()=>{r.removeEventListener(`mouseenter`,t)}):(r.addEventListener(`click`,t),()=>{r.removeEventListener(`click`,t)})},[r,a,n,e]),{ref:i,isOpen:a,trigger:e,closeMenu:c}},Xc=({type:e,withText:t=!1,disabled:r=!1,onClick:i})=>(0,n.jsx)($,{disabled:r,onClick:()=>{i()},title:e.label,icon:e.icon,"data-testid":`tool-${e.type}`,children:t?e.label:void 0}),Zc=({withActionsInMenu:e,hasActionToUndo:t=!1,hasActionToRedo:r=!1,hasActionToClear:i=!1,undoAction:a,redoAction:o,clearCanvas:s,disabled:c=!1,withLoadAndSave:l,withExport:u,addPicture:d,loadFile:f,togglePictureUrlModal:p,saveFile:m,toggleExportModal:h,withUploadPicture:g,withUrlPicture:_})=>{let{ref:v,isOpen:y,closeMenu:b}=Yc(),x=e=>async(...t)=>{await e(...t),b()};return e||g||_||l||u?(0,n.jsx)(`div`,{className:`react-paint-editor-toolbox-relative`,children:(0,n.jsxs)(`div`,{ref:v,children:[(0,n.jsx)($,{title:`Menu`,disabled:c,icon:Is}),y&&(0,n.jsxs)(Kc,{alignment:`right`,position:`top`,children:[e&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Xc,{withText:!0,type:tc,disabled:c||!t,onClick:x(a)}),(0,n.jsx)(Xc,{withText:!0,type:nc,disabled:c||!r,onClick:x(o)}),(0,n.jsx)(Xc,{withText:!0,type:rc,disabled:c||!i,onClick:x(s)}),(g||_||l)&&(0,n.jsx)(`hr`,{})]}),g&&(0,n.jsx)(qc,{withText:!0,type:sc,disabled:c,loadFile:x(d),accept:`image/png, image/gif, image/jpeg, image/svg+xml, image/webp`}),_&&(0,n.jsx)($,{disabled:c,selected:!1,onClick:x(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`}),(g||_)&&l&&(0,n.jsx)(`hr`,{}),l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(qc,{withText:!0,type:ac,disabled:c,loadFile:x(f),accept:`application/JSON`}),(0,n.jsx)(Xc,{withText:!0,disabled:c,type:oc,onClick:x(m)})]}),u&&(0,n.jsx)(Xc,{withText:!0,disabled:c,type:ic,onClick:x(h)})]})]})}):null},Qc=({togglePictureUrlModal:e,addPicture:r})=>{let i=(0,t.useRef)(null);return(0,t.useEffect)(()=>{i.current&&i.current.focus()},[]),(0,n.jsx)(gc,{className:`react-paint-editor-toolbox-pictureinput-modal`,onClose:e,title:`Add picture from URL`,children:(0,n.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault();let n=i.current?.value;n&&(await r(n),e())},children:[(0,n.jsxs)(`label`,{children:[`URL\xA0`,(0,n.jsx)(`input`,{type:`text`,ref:i})]}),(0,n.jsx)($,{onClick:e,children:`Annuler`}),(0,n.jsx)($,{type:`submit`,selected:!0,children:`Ajouter`})]})})},$c=({type:e,img:t,isActive:r,withText:i=!1,disabled:a=!1,setActive:o})=>(0,n.jsx)($,{disabled:a,selected:r,onClick:()=>{o(e)},title:e.label??e.type,icon:t,"data-testid":`tool-${e.type}`,children:i?e.label:void 0}),el=`Choose export settings`,tl=({toggleExportModal:e,exportCanvasInFile:t})=>{let r=async n=>{t(n),e()};return(0,n.jsxs)(gc,{className:`react-paint-editor-toolbox-export-modal`,onClose:e,title:el,children:[(0,n.jsx)(`h3`,{children:el}),(0,n.jsx)(`hr`,{}),(0,n.jsx)($,{onClick:()=>r(`currentZoom`),children:`Exporter la vue actuelle`}),(0,n.jsx)($,{onClick:()=>r(`defaultView`),children:`Exporter le canevas par défaut`}),(0,n.jsx)($,{onClick:()=>r(`fitToShapes`),children:`Exporter le dessin entier`}),(0,n.jsx)($,{selected:!0,onClick:e,children:`Annuler`})]})},nl=(e,n,r=!0)=>{(0,t.useEffect)(()=>{if(!r)return;let t=t=>{Jc(t,e.current)||n()};return document.addEventListener(`pointerdown`,t),()=>document.removeEventListener(`pointerdown`,t)},[e,n,r])},rl=({activeTool:e,group:r,disabled:i=!1,setActiveToolFromId:a})=>{let o=(0,t.useRef)(null),[s,c]=(0,t.useState)(!1),[,l]=(0,t.useTransition)(),[u,d]=(0,t.useState)(void 0),f=e=>{d(e),a(e.id)};if(nl(o,(0,t.useCallback)(()=>c(!1),[]),s),`type`in r)return(0,n.jsx)($c,{disabled:i,type:r,img:r.icon,isActive:e.id===r.id,setActive:f});if(!r.toolsType.length)return null;if(r.toolsType?.length===1)return(0,n.jsx)($c,{disabled:i,type:r.toolsType[0],img:r.toolsType[0].icon,isActive:e.id===r.toolsType[0].id,setActive:f});let p=r?.toolsType.find(t=>t.type===e.type)!==void 0,m=u?u.icon:r.toolsType?.[0]?.icon;return(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbargroup-relative`,children:[(0,n.jsx)($,{selected:p,title:r.title,disabled:i,onClick:()=>{u?a(u.id):r.toolsType?.[0]&&f(r.toolsType[0]),l(()=>{c(!0)})},icon:m,children:m===void 0?r.title:void 0}),s&&(0,n.jsx)(_s,{alignment:`center`,position:`top`,children:(0,n.jsx)(`div`,{className:`react-paint-editor-toolbargroup-panel-content`,"data-vertical":+r.vertical,ref:o,children:r.toolsType.map(t=>(0,n.jsx)($c,{disabled:i,type:t,img:t.icon,isActive:e.id===t.id,setActive:f},t.id))})})]})},il=40,al=[{title:`brush`,toolsType:[`brush`],vertical:!1},{title:`lines`,toolsType:[`line`,`curve`,`polygon`],vertical:!1},{title:`shapes`,toolsType:[`rect`,`square`,`circle`,`ellipse`],vertical:!1},`text`],ol=e=>({activeTool:e.activeTool,tools:e.tools,history:e.history,width:e.view.displayWidth}),sl=({disabled:e,withMoveTool:r,withLoadAndSave:i,withExport:a,addPicture:o,loadFile:s,saveFile:c,exportCanvasInFile:l,withUrlPicture:u,withUploadPicture:d})=>{let f=Ro(),{actions:p}=f,{activeTool:m,tools:h,history:g,width:_}=Z(f,ol,M),v=(0,t.useMemo)(()=>h.map(lc),[h]),{canUndo:y,canRedo:b,canClear:x}=g,{undo:S,redo:C,clearCanvas:w}=p,T=Gc(v,al),E=_<(6+T.length)*il,D=_<(3+T.length)*il,[ee,te]=(0,t.useState)(!1),[O,k]=(0,t.useState)(!1),[A,ne]=(0,t.useState)(!1),re=()=>{te(e=>!e)},j=()=>{k(!0)},ie=()=>{k(e=>!e)},ae=()=>{ne(e=>!e)},oe=e=>{p.selectTool(e),te(!1)},N=v.find(e=>e.type===m.type)!==void 0;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbar-toolbox`,style:{"--react-paint-editor-toolbar-minwidth":`160px`},children:[(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbar-shrinkable`,children:[(0,n.jsx)($c,{type:$s,disabled:e,img:$s.icon,isActive:m.id===$s.id,setActive:()=>oe($s.id)}),r&&(0,n.jsx)($c,{type:ec,disabled:e,img:ec.icon,isActive:m.id===ec.id,setActive:()=>oe(ec.id)}),D?(0,n.jsx)($,{disabled:e,onClick:re,title:`Toggle tools`,icon:bs,selected:N}):T.map(t=>(0,n.jsx)(rl,{disabled:e,activeTool:m,group:t,setActiveToolFromId:oe},`id`in t?t.id:t.title))]}),!E&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Xc,{type:tc,disabled:e||!y,onClick:S}),(0,n.jsx)(Xc,{type:nc,disabled:e||!b,onClick:C}),(0,n.jsx)(Xc,{type:rc,disabled:e||!x,onClick:w})]}),(0,n.jsx)(Zc,{withActionsInMenu:E,disabled:e,addPicture:o,loadFile:s,saveFile:c,togglePictureUrlModal:j,toggleExportModal:ae,withUploadPicture:d,withUrlPicture:u,withLoadAndSave:i,withExport:a,hasActionToUndo:y,hasActionToRedo:b,hasActionToClear:x,undoAction:S,redoAction:C,clearCanvas:w})]}),ee&&(0,n.jsx)(gc,{className:`react-paint-editor-toolbar-modal`,onClose:re,title:`Outils`,children:v.map(t=>t.type===`picture`?null:(0,n.jsx)($c,{disabled:e,type:t,img:t.icon,withText:!1,isActive:m.id===t.id,setActive:()=>oe(t.id)},t.id))}),O&&(0,n.jsx)(Qc,{togglePictureUrlModal:ie,addPicture:o}),A&&(0,n.jsx)(tl,{toggleExportModal:ae,exportCanvasInFile:l})]})},cl={toolbarBackgroundColor:`white`,dividerColor:`#36418129`,fontRadius:8,fontDisabledColor:`#3641812b`,fontDisabledBackgroundColor:`transparent`,fontColor:`#364181`,fontBackgroundColor:`transparent`,fontSelectedColor:`white`,fontSelectedBackgroundColor:`#364181`,fontHoverColor:`#364181`,fontHoverBackgroundColor:`#afd8d8`,layersManipulation:!0,withExport:!0,withLoadAndSave:!0,withUploadPicture:!0,withUrlPicture:!1},ll=()=>{let e=(0,t.useRef)([]),[n,r]=(0,t.useState)([]),i=(0,t.useCallback)(e=>{r(t=>t.filter(t=>t.id!==e))},[]),a=(0,t.useCallback)(({type:t=ps.type,duration:n=ps.duration,text:a})=>{let o={id:vc(`snackbar_`),duration:n,type:t,text:a};r(e=>[...e,o]);let s=setTimeout(()=>{i(o.id),e.current=e.current.filter(e=>e!==s)},n);e.current=[...e.current,s]},[i]);return(0,t.useEffect)(()=>()=>{for(let t of e.current)clearTimeout(t)},[]),{snackbarList:n,addSnackbar:a}},ul=36,dl=16,fl=176,pl=200,ml=({contextMenu:e,containerRef:r,hasCopiedShapes:i,actions:a})=>{let{shapes:o,anchorIndex:s,canRemoveAnchor:c,clientPosition:l}=e,u=o.map(e=>e.id),d=o.length>0,f=o[0],p=!o.some(e=>e.visible===!1),m=o.some(e=>e.locked),{ref:h,isOpen:g}=Yc({trigger:`hover`}),{ref:_,isOpen:v}=Yc({trigger:`hover`,disabled:m}),y=16+ul*(2+(d?8:0)+ +!!c)+dl*(d?3:1),[b,x]=(0,t.useState)();(0,t.useEffect)(()=>{let e=r.current?.getBoundingClientRect();if(!e)return;let t=yc(l.x,0,window.innerWidth-fl),n=yc(l.y,0,window.innerHeight-y),i=t+fl+pl>window.innerWidth?`left`:`right`;x({x:t-e.left,y:n-e.top,subMenuPosition:i})},[r,l.x,l.y,y]);let S=b?{"--react-paint-editor-toolbox-contextmenu-transform":`translate3D(${b.x}px, ${b.y}px, 0)`}:{display:`none`},C=(0,t.useRef)(null);nl(C,a.closeContextMenu);let w=e=>()=>{e(),a.closeContextMenu()},T=w(()=>{f&&s!==void 0&&a.removeShapePoint(f.id,s)}),E=w(()=>a.removeShapes(u)),D=w(a.selectAllShapes),ee=w(()=>a.duplicateShapes(u,{translate:!0,select:!0})),te=w(()=>a.cut(u)),O=w(()=>a.copy(u)),k=w(a.paste),A=e=>w(()=>a.moveShapes(u,e)),ne=e=>w(()=>a.transformShapes(u,e)),re=w(()=>a.setShapesVisibility(u,!p)),j=w(()=>a.setShapesLocked(u,!m));return(0,n.jsxs)(Kc,{className:`react-paint-editor-toolbox-contextmenu`,style:S,menuRef:C,children:[d&&(0,n.jsxs)(n.Fragment,{children:[c&&(0,n.jsx)($,{onClick:T,children:`Delete point`}),(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbox-contextmenu-group`,ref:h,children:[(0,n.jsx)($,{icon:`<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>`,children:`Organize`}),g&&(0,n.jsxs)(Kc,{position:b?.subMenuPosition,children:[(0,n.jsx)($,{onClick:A(`forward`),children:`Move forward`}),(0,n.jsx)($,{onClick:A(`first`),children:`Put on first`}),(0,n.jsx)($,{onClick:A(`backward`),children:`Move backward`}),(0,n.jsx)($,{onClick:A(`last`),children:`Put on last`})]})]}),(0,n.jsxs)(`div`,{className:`react-paint-editor-toolbox-contextmenu-group`,ref:_,children:[(0,n.jsx)($,{icon:`<svg viewBox="0 -960 960 960"><path d="M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z"/></svg>`,disabled:m,children:`Transform`}),v&&(0,n.jsxs)(Kc,{position:b?.subMenuPosition,children:[(0,n.jsx)($,{onClick:ne(`flipHorizontally`),children:`Flip horizontally`}),(0,n.jsx)($,{onClick:ne(`flipVertically`),children:`Flip vertically`}),(0,n.jsx)($,{onClick:ne(`rotateClockwise`),children:`Rotate clockwise`}),(0,n.jsx)($,{onClick:ne(`rotateCounterclockwise`),children:`Rotate counterclockwise`})]})]}),(0,n.jsx)(`hr`,{}),(0,n.jsx)($,{onClick:te,children:`Cut`}),(0,n.jsx)($,{onClick:O,children:`Copy`})]}),(0,n.jsx)($,{onClick:k,disabled:!i,children:`Paste`}),(0,n.jsx)(`hr`,{}),d&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)($,{onClick:ee,children:`Duplicate`}),(0,n.jsx)($,{onClick:re,children:p?`Hide`:`Show`}),(0,n.jsx)($,{onClick:j,children:m?`Unlock`:`Lock`}),(0,n.jsx)($,{onClick:E,children:`Delete`}),(0,n.jsx)(`hr`,{})]}),(0,n.jsx)($,{onClick:D,children:`Select all`})]})},hl=({containerRef:e})=>{let t=Ro(),r=Z(t,e=>e.contextMenu),i=Z(t,e=>e.clipboard.hasContent);return r?(0,n.jsx)(ml,{contextMenu:r,containerRef:e,hasCopiedShapes:i,actions:t.actions}):null},gl=e=>({mode:e.mode,features:e.features,layout:e.layout,width:e.width});e.Canvas=us,e.DEFAULT_EDITOR_OPTIONS=cl,e.DEFAULT_OPTIONS=re,e.DEFAULT_TOOLS=k,e.Editor=({paint:e,className:r,style:i,options:a,children:o})=>{let{actions:s,scopeRef:c}=e,{mode:l,features:u,layout:d,width:f}=Z(e,gl,M),{toolbarBackgroundColor:p,dividerColor:m,fontRadius:h,fontDisabledColor:g,fontDisabledBackgroundColor:_,fontColor:v,fontBackgroundColor:y,fontSelectedColor:b,fontSelectedBackgroundColor:x,fontHoverColor:S,fontHoverBackgroundColor:C,layersManipulation:w,withExport:T,withLoadAndSave:E,withUploadPicture:D,withUrlPicture:ee}=xc(cl,a),te=l!==`viewer`,O=!u.edition,k=d.size===`infinite`||u.zoom,A=(0,t.useRef)(null),ne=(0,t.useCallback)(e=>{A.current=e,c(e)},[c]),[re,j]=(0,t.useState)(!1),[ie,ae]=(0,t.useState)(!1),[oe,N]=(0,t.useState)(k),se=k&&oe,{snackbarList:ce,addSnackbar:P}=ll(),le=(0,t.useCallback)(e=>{j(!0);try{s.exportPicture({view:e})}catch(e){e instanceof Error&&P({type:`error`,text:`L'export a échoué : ${e.message}`}),console.warn(e)}finally{j(!1)}},[s,P]),ue=(0,t.useCallback)(()=>{j(!0);try{s.exportData(),j(!1)}catch(e){e instanceof Error&&P({type:`error`,text:`L'enregistrement a échoué`}),console.warn(e)}finally{j(!1)}},[s,P]),de=(0,t.useCallback)(async e=>{j(!0);try{await s.loadFile(e),P({type:`success`,text:`Fichier chargé !`})}catch(e){e instanceof Error&&P({type:`error`,text:`Le chargement a échoué`}),console.warn(e)}finally{j(!1)}},[s,P]),fe=(0,t.useCallback)(async e=>{j(!0);try{await s.addPicture(e)}catch(e){e instanceof Error&&P({type:`error`,text:`Le chargement a échoué`}),console.warn(e)}finally{j(!1)}},[s,P]);(0,t.useEffect)(()=>e.registerEvent(`pictureDropFailed`,()=>P({type:`error`,text:`Le chargement a échoué`})),[e,P]);let pe=Mc((0,t.useCallback)(()=>P({type:`error`,text:`Certaines images n'ont pas pu être chargées`}),[P]),0);(0,t.useEffect)(()=>e.registerEvent(`pictureLoadFailed`,pe),[e,pe]),(0,t.useEffect)(()=>{if(!D)return s.setOptions({withDropPicture:!1}),()=>s.setOptions({withDropPicture:void 0})},[s,D]);let me=`${r?`${r} `:``}${ie?`react-paint-editor-layout-opened `:``}react-paint-editor-app`;return(0,n.jsx)(`div`,{ref:ne,className:me,"data-resize":d.resize,style:{"--react-paint-editor-app-canvasWidth":`calc(var(--react-paint-app-canvaswidth, ${f}) * 1px)`,"--react-paint-editor-app-toolbar-bg":p,"--react-paint-editor-app-divider-color":m,"--react-paint-editor-app-font-radius":`${h}px`,"--react-paint-editor-app-font-disabled-color":g,"--react-paint-editor-app-font-disabled-bg":_,"--react-paint-editor-app-font-color":v,"--react-paint-editor-app-font-bg":y,"--react-paint-editor-app-font-selected-color":b,"--react-paint-editor-app-font-selected-bg":x,"--react-paint-editor-app-font-hover-color":S,"--react-paint-editor-app-font-hover-bg":C,...i},children:(0,n.jsxs)(Lo,{paint:e,children:[te&&(0,n.jsx)(sl,{disabled:O,withMoveTool:k,exportCanvasInFile:le,saveFile:ue,loadFile:de,addPicture:fe,withExport:T,withLoadAndSave:E,withUploadPicture:D,withUrlPicture:ee}),o,te&&w&&(0,n.jsx)(hc,{isLayoutPanelShown:ie,disabled:O}),se&&(0,n.jsx)(Wc,{isEditMode:te}),te&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Uc,{disabled:O,withZoom:k,layersManipulation:w,toggleLayoutPanel:()=>{ae(e=>!e)},isZoomPanelShown:se,setIsZoomPanelShown:N}),(0,n.jsx)(fs,{isLoading:re}),(0,n.jsx)(hs,{snackbarList:ce})]}),(0,n.jsx)(hl,{containerRef:A})]})})},e.GRID_PRESETS=Be,e.MOVE_TOOL=y,e.PaintProvider=Lo,e.SELECTION_TOOL=v,e.ZOOM_LEVELS=z,e.getSelectedShapes=I,e.getSelectedShapesTools=Se,e.shallowEqual=M,e.useAnnotationsStyle=Vo,e.usePaint=Ro,e.usePaintState=Z,e.useReactPaint=cs});