@ninesstudios/whiteboard 0.1.8 β†’ 0.1.9

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.
@@ -96,5 +96,5 @@ Take a look at the logic that dispatched this action: `,x,`
96
96
  (See https://redux.js.org/faq/actions#why-should-type-be-a-string-or-at-least-serializable-why-should-my-action-types-be-constants)`,`
97
97
  (To allow non-serializable values see: https://redux-toolkit.js.org/usage/usage-guide#working-with-non-serializable-data)`)}}),S||(F.measureTime(function(){var j=k.getState(),X=Ar(j,"",r,n,c,O);if(X){var M=X.keyPath,oe=X.value;console.error("A non-serializable value was detected in the state, in the path: `"+M+"`. Value:",oe,`
98
98
  Take a look at the reducer(s) handling this action type: `+x.type+`.
99
- (See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)`)}}),F.warnIfExceeded()),D}}}}function Jt(e){return typeof e=="boolean"}function Vi(){return function(t){return $i(t)}}function $i(e){e===void 0&&(e={});var t=e.thunk,r=t===void 0?!0:t,n=e.immutableCheck,i=n===void 0?!0:n,a=e.serializableCheck,l=a===void 0?!0:a,u=e.actionCreatorCheck,p=u===void 0?!0:u,c=new Ri;if(r&&(Jt(r)?c.push(Mr):c.push(Mr.withExtraArgument(r.extraArgument))),process.env.NODE_ENV!=="production"){if(i){var v={};Jt(i)||(v=i),c.unshift(Wi(v))}if(l){var b={};Jt(l)||(b=l),c.push(Yi(b))}if(p){var s={};Jt(p)||(s=p),c.unshift(Mi(s))}}return c}var Ir=process.env.NODE_ENV==="production";function Fi(e){var t=Vi(),r=e||{},n=r.reducer,i=n===void 0?void 0:n,a=r.middleware,l=a===void 0?t():a,u=r.devTools,p=u===void 0?!0:u,c=r.preloadedState,v=c===void 0?void 0:c,b=r.enhancers,s=b===void 0?void 0:b,S;if(typeof i=="function")S=i;else if(Bn(i))S=gi(i);else throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');var m=l;if(typeof m=="function"&&(m=m(t),!Ir&&!Array.isArray(m)))throw new Error("when using a middleware builder function, an array of middleware must be returned");if(!Ir&&m.some(function(I){return typeof I!="function"}))throw new Error("each middleware provided to configureStore must be a function");var y=bi.apply(void 0,m),E=Kt;p&&(E=ji(et({trace:!Ir},typeof p=="object"&&p)));var C=new Ni(y),O=C;Array.isArray(s)?O=wt([y],s):typeof s=="function"&&(O=s(C));var k=E.apply(void 0,O);return Wn(S,v,k)}function Qn(e){var t={},r=[],n,i={addCase:function(a,l){if(process.env.NODE_ENV!=="production"){if(r.length>0)throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");if(n)throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`")}var u=typeof a=="string"?a:a.type;if(!u)throw new Error("`builder.addCase` cannot be called with an empty action type");if(u in t)throw new Error("`builder.addCase` cannot be called with two reducers for the same action type");return t[u]=l,i},addMatcher:function(a,l){if(process.env.NODE_ENV!=="production"&&n)throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");return r.push({matcher:a,reducer:l}),i},addDefaultCase:function(a){if(process.env.NODE_ENV!=="production"&&n)throw new Error("`builder.addDefaultCase` can only be called once");return n=a,i}};return e(i),[t,r,n]}function Xi(e){return typeof e=="function"}var eo=!1;function Bi(e,t,r,n){r===void 0&&(r=[]),process.env.NODE_ENV!=="production"&&typeof t=="object"&&(eo||(eo=!0,console.warn("The object notation for `createReducer` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer")));var i=typeof t=="function"?Qn(t):[t,r,n],a=i[0],l=i[1],u=i[2],p;if(Xi(e))p=function(){return Nr(e())};else{var c=Nr(e);p=function(){return c}}function v(b,s){b===void 0&&(b=p());var S=wt([a[s.type]],l.filter(function(m){var y=m.matcher;return y(s)}).map(function(m){var y=m.reducer;return y}));return S.filter(function(m){return!!m}).length===0&&(S=[u]),S.reduce(function(m,y){if(y)if(Je(m)){var E=m,C=y(E,s);return C===void 0?m:C}else{if(Ue(m))return An(m,function(O){return y(O,s)});var C=y(m,s);if(C===void 0){if(m===null)return m;throw Error("A case reducer on a non-draftable value must not return undefined")}return C}return m},b)}return v.getInitialState=p,v}var to=!1;function Ui(e,t){return e+"/"+t}function Hi(e){var t=e.name;typeof process<"u"&&process.env.NODE_ENV==="development"&&e.initialState===void 0&&console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");var r=typeof e.initialState=="function"?e.initialState:Nr(e.initialState),n=e.reducers||{},i=Object.keys(n),a={},l={},u={};i.forEach(function(v){var b=n[v],s=Ui(t,v),S,m;"reducer"in b?(S=b.reducer,m=b.prepare):S=b,a[v]=S,l[s]=S,u[v]=m?tt(s,m):tt(s)});function p(){process.env.NODE_ENV!=="production"&&typeof e.extraReducers=="object"&&(to||(to=!0,console.warn("The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice")));var v=typeof e.extraReducers=="function"?Qn(e.extraReducers):[e.extraReducers],b=v[0],s=b===void 0?{}:b,S=v[1],m=S===void 0?[]:S,y=v[2],E=y===void 0?void 0:y,C=et(et({},s),l);return Bi(r,function(O){for(var k in C)O.addCase(k,C[k]);for(var I=0,x=m;I<x.length;I++){var D=x[I];O.addMatcher(D.matcher,D.reducer)}E&&O.addDefaultCase(E)})}var c;return{name:t,reducer:function(v,b){return c||(c=p()),c(v,b)},actions:u,caseReducers:a,getInitialState:function(){return c||(c=p()),c.getInitialState()}}}var qi="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",Gi=function(e){e===void 0&&(e=21);for(var t="",r=e;r--;)t+=qi[Math.random()*64|0];return t},Ki=["name","message","stack","code"],Dr=(function(){function e(t,r){this.payload=t,this.meta=r}return e})(),ro=(function(){function e(t,r){this.payload=t,this.meta=r}return e})(),Ji=function(e){if(typeof e=="object"&&e!==null){for(var t={},r=0,n=Ki;r<n.length;r++){var i=n[r];typeof e[i]=="string"&&(t[i]=e[i])}return t}return{message:String(e)}};(function(){function e(t,r,n){var i=tt(t+"/fulfilled",function(v,b,s,S){return{payload:v,meta:Rr(et({},S||{}),{arg:s,requestId:b,requestStatus:"fulfilled"})}}),a=tt(t+"/pending",function(v,b,s){return{payload:void 0,meta:Rr(et({},s||{}),{arg:b,requestId:v,requestStatus:"pending"})}}),l=tt(t+"/rejected",function(v,b,s,S,m){return{payload:S,error:(n&&n.serializeError||Ji)(v||"Rejected"),meta:Rr(et({},m||{}),{arg:s,requestId:b,rejectedWithValue:!!S,requestStatus:"rejected",aborted:(v==null?void 0:v.name)==="AbortError",condition:(v==null?void 0:v.name)==="ConditionError"})}}),u=!1,p=typeof AbortController<"u"?AbortController:(function(){function v(){this.signal={aborted:!1,addEventListener:function(){},dispatchEvent:function(){return!1},onabort:function(){},removeEventListener:function(){},reason:void 0,throwIfAborted:function(){}}}return v.prototype.abort=function(){process.env.NODE_ENV!=="production"&&(u||(u=!0,console.info("This platform does not implement AbortController. \nIf you want to use the AbortController to react to `abort` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.")))},v})();function c(v){return function(b,s,S){var m=n!=null&&n.idGenerator?n.idGenerator(v):Gi(),y=new p,E;function C(k){E=k,y.abort()}var O=(function(){return Oi(this,null,function(){var k,I,x,D,F,j,X;return wi(this,function(M){switch(M.label){case 0:return M.trys.push([0,4,,5]),D=(k=n==null?void 0:n.condition)==null?void 0:k.call(n,v,{getState:s,extra:S}),Qi(D)?[4,D]:[3,2];case 1:D=M.sent(),M.label=2;case 2:if(D===!1||y.signal.aborted)throw{name:"ConditionError",message:"Aborted due to condition callback returning false."};return F=new Promise(function(oe,ue){return y.signal.addEventListener("abort",function(){return ue({name:"AbortError",message:E||"Aborted"})})}),b(a(m,v,(I=n==null?void 0:n.getPendingMeta)==null?void 0:I.call(n,{requestId:m,arg:v},{getState:s,extra:S}))),[4,Promise.race([F,Promise.resolve(r(v,{dispatch:b,getState:s,extra:S,requestId:m,signal:y.signal,abort:C,rejectWithValue:function(oe,ue){return new Dr(oe,ue)},fulfillWithValue:function(oe,ue){return new ro(oe,ue)}})).then(function(oe){if(oe instanceof Dr)throw oe;return oe instanceof ro?i(oe.payload,m,v,oe.meta):i(oe,m,v)})])];case 3:return x=M.sent(),[3,5];case 4:return j=M.sent(),x=j instanceof Dr?l(null,m,v,j.payload,j.meta):l(j,m,v),[3,5];case 5:return X=n&&!n.dispatchConditionRejection&&l.match(x)&&x.meta.condition,X||b(x),[2,x]}})})})();return Object.assign(O,{abort:C,requestId:m,arg:v,unwrap:function(){return O.then(Zi)}})}}return Object.assign(c,{pending:a,rejected:l,fulfilled:i,typePrefix:t})}return e.withTypes=function(){return e},e})();function Zi(e){if(e.meta&&e.meta.rejectedWithValue)throw e.payload;if(e.error)throw e.error;return e.payload}function Qi(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}var zr="listenerMiddleware";tt(zr+"/add"),tt(zr+"/removeAll"),tt(zr+"/remove");var no;typeof queueMicrotask=="function"&&queueMicrotask.bind(typeof window<"u"?window:typeof global<"u"?global:globalThis),ni();const ea={grid:{size:20,color:"#ccc",enabled:!0},toolbar:{selectedTool:"pointer"},toolProperties:{pencil:{strokeColor:"#000000",lineWidth:4},rectangle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},circle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},triangle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},diamond:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},star:{strokeColor:"#000000",fillColor:"#ffff00",lineWidth:2},heart:{strokeColor:"#000000",fillColor:"#ff6b6b",lineWidth:2},hexagon:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},octagon:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},arrow:{strokeColor:"#000000",fillColor:"#000000",lineWidth:2},text:{fontSize:16,fontColor:"#000000"}},elements:[],selectedElementIds:[],viewport:{panX:0,panY:0,zoom:1},watermark:{text:"Nines Studios",url:"https://github.com/huzeyfecoskun",visible:!0},lock:{isLocked:!1,text:"Whiteboard drawing is only for moderator"}};function ta(e){const t=[],r=new Set;for(const n of e){const i=n==null?void 0:n.id;if(i==null){t.push(n);continue}r.has(i)||(r.add(i),t.push(n))}return t}const Lr=Hi({name:"whiteboard",initialState:ea,reducers:{toggleGrid(e){e.grid.enabled=!e.grid.enabled},setGridSize(e,t){e.grid.size=t.payload},setGridColor(e,t){e.grid.color=t.payload},setSelectedTool(e,t){e.toolbar.selectedTool=t.payload},setToolProperty(e,t){const{tool:r,property:n,value:i}=t.payload;e.toolProperties[r]&&(e.toolProperties[r][n]=i)},addElement(e,t){const r=t.payload,n=r==null?void 0:r.id;n!=null&&e.elements.some(a=>(a==null?void 0:a.id)===n)||e.elements.push(r)},updateElement(e,t){const{id:r,updates:n}=t.payload,i=e.elements.findIndex(a=>a.id===r);i!==-1&&(e.elements[i]={...e.elements[i],...n})},updateElements(e,t){t.payload.forEach(({id:n,updates:i})=>{const a=e.elements.findIndex(l=>l.id===n);a!==-1&&(e.elements[a]={...e.elements[a],...i})})},removeElement(e,t){const r=t.payload;e.elements=e.elements.filter(n=>n.id!==r),e.selectedElementIds=e.selectedElementIds.filter(n=>n!==r)},setSelectedElements(e,t){e.selectedElementIds=t.payload},clearElements(e){e.elements=[],e.selectedElementIds=[]},setElements(e,t){const r=Array.isArray(t.payload)?t.payload:[];e.elements=ta(r),e.selectedElementIds=[]},setPan(e,t){e.viewport.panX=t.payload.x,e.viewport.panY=t.payload.y},setZoom(e,t){e.viewport.zoom=Math.max(.1,Math.min(5,t.payload))},resetViewport(e){e.viewport.panX=0,e.viewport.panY=0,e.viewport.zoom=1},bringToFront(e,t){const r=t.payload,n=e.elements.findIndex(i=>i.id===r);if(n!==-1&&n<e.elements.length-1){const[i]=e.elements.splice(n,1);e.elements.push(i)}},sendToBack(e,t){const r=t.payload,n=e.elements.findIndex(i=>i.id===r);if(n>0){const[i]=e.elements.splice(n,1);e.elements.unshift(i)}},fitToView(e,t){const{canvasWidth:r,canvasHeight:n,padding:i=50}=t.payload,a=e.elements;if(a.length===0){e.viewport.panX=0,e.viewport.panY=0,e.viewport.zoom=1;return}let l=1/0,u=1/0,p=-1/0,c=-1/0;if(a.forEach(x=>{const D=F=>F??0;if(x.type==="rectangle"){const F=D(x.x),j=D(x.y),X=D(x.width),M=D(x.height);l=Math.min(l,F),u=Math.min(u,j),p=Math.max(p,F+X),c=Math.max(c,j+M)}else if(x.type==="circle"){const F=D(x.centerX),j=D(x.centerY),X=D(x.radius);l=Math.min(l,F-X),u=Math.min(u,j-X),p=Math.max(p,F+X),c=Math.max(c,j+X)}else if(x.type==="pencil"&&x.points&&x.points.length>0)x.points.forEach(F=>{l=Math.min(l,F.x),u=Math.min(u,F.y),p=Math.max(p,F.x),c=Math.max(c,F.y)});else if(x.type==="triangle"||x.type==="diamond"||x.type==="hexagon"||x.type==="octagon"){const F=D(x.x),j=D(x.y),X=D(x.width),M=D(x.height);l=Math.min(l,F),u=Math.min(u,j),p=Math.max(p,F+X),c=Math.max(c,j+M)}else if(x.type==="star"||x.type==="heart"){const F=D(x.centerX),j=D(x.centerY),X=D(x.size);l=Math.min(l,F-X),u=Math.min(u,j-X),p=Math.max(p,F+X),c=Math.max(c,j+X)}else if(x.type==="arrow"){const F=D(x.startX),j=D(x.startY),X=D(x.endX),M=D(x.endY);l=Math.min(l,F,X),u=Math.min(u,j,M),p=Math.max(p,F,X),c=Math.max(c,j,M)}}),l===1/0)return;const v=p-l,b=c-u;if(v<=0||b<=0)return;const s=r-i*2,S=n-i*2,m=s/v,y=S/b,E=Math.min(m,y,5),C=(l+p)/2,O=(u+c)/2,k=r/2-C*E,I=n/2-O*E;e.viewport.zoom=Math.max(.1,E),e.viewport.panX=k,e.viewport.panY=I},setLocked(e,t){e.lock.isLocked=t.payload,t.payload&&(e.toolbar.selectedTool="pointer",e.selectedElementIds=[])},setWatermarkEnabled(e,t){e.watermark.visible=t.payload},setWatermarkText(e,t){e.watermark.text=t.payload}}}),{toggleGrid:ra,setGridSize:cs,setGridColor:ls,setSelectedTool:Me,setToolProperty:na,addElement:Se,updateElement:Zt,updateElements:oo,removeElement:oa,setSelectedElements:He,clearElements:Wr,setElements:Yr,setPan:ia,setZoom:aa,resetViewport:us,fitToView:sa,bringToFront:ca,sendToBack:la,setLocked:io,setWatermarkEnabled:ua,setWatermarkText:fa}=Lr.actions,da=Lr.actions,ao=Lr.reducer,ha=new Set(["rectangle","circle","pencil","triangle","diamond","star","heart","hexagon","octagon","arrow","text"]),pa=new Set(["strokeColor","fillColor","lineWidth","fontSize","fontColor","textColor"]),va=e=>{var t,r;if(!e||typeof e.type!="string"||e.type.startsWith("@@redux/"))return!1;if(e.type==="whiteboard/addElement"){const n=(t=e==null?void 0:e.payload)==null?void 0:t.type;return typeof n=="string"&&ha.has(n)}if(e.type==="whiteboard/removeElement"||e.type==="whiteboard/clearElements"||e.type==="whiteboard/bringToFront"||e.type==="whiteboard/sendToBack")return!0;if(e.type==="whiteboard/setToolProperty"){const{tool:n,property:i}=(e==null?void 0:e.payload)??{};return typeof n!="string"||typeof i!="string"?!1:pa.has(i)}if(e.type==="whiteboard/updateElement")return so((r=e==null?void 0:e.payload)==null?void 0:r.updates);if(e.type==="whiteboard/updateElements"){const n=e==null?void 0:e.payload;return Array.isArray(n)?n.some(i=>so(i.updates)):!1}return!1},so=e=>{if(!e||typeof e!="object")return!1;const t=r=>Object.prototype.hasOwnProperty.call(e,r);return!!(t("text")||t("fontSize")||t("fontColor")||t("textColor")||t("strokeColor")||t("fillColor")||t("lineWidth")||t("x")||t("y")||t("width")||t("height")||t("centerX")||t("centerY")||t("radius")||t("size")||t("startX")||t("startY")||t("endX")||t("endY")||t("points"))},ya=e=>t=>r=>n=>{var a;const i=r(n);return!((a=n.meta)!=null&&a.fromRemote)&&e&&e.current&&va(n)&&e.current(n,t.getState()),i},Vr=({preloadedState:e,actionHandlerRef:t}={})=>Fi({reducer:{whiteboard:ao},middleware:r=>r().concat(ya(t)),preloadedState:e}),ma=Vr(),ga=()=>{const e=xe(t=>t.whiteboard.watermark);return h.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:h.jsx("div",{className:"wb-watermark",children:e.text})})};var co={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},lo=P.createContext&&P.createContext(co),ba=["attr","size","title"];function wa(e,t){if(e==null)return{};var r=xa(e,t),n,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)n=a[i],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function xa(e,t){if(e==null)return{};var r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){if(t.indexOf(n)>=0)continue;r[n]=e[n]}return r}function Qt(){return Qt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Qt.apply(this,arguments)}function uo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function er(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?uo(Object(r),!0).forEach(function(n){Ea(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):uo(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ea(e,t,r){return t=Sa(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Sa(e){var t=Ca(e,"string");return typeof t=="symbol"?t:t+""}function Ca(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function fo(e){return e&&e.map((t,r)=>P.createElement(t.tag,er({key:r},t.attr),fo(t.child)))}function fe(e){return t=>P.createElement(_a,Qt({attr:er({},e.attr)},t),fo(e.child))}function _a(e){var t=r=>{var{attr:n,size:i,title:a}=e,l=wa(e,ba),u=i||r.size||"1em",p;return r.className&&(p=r.className),e.className&&(p=(p?p+" ":"")+e.className),P.createElement("svg",Qt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,n,l,{className:p,style:er(er({color:e.color||r.color},r.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),a&&P.createElement("title",null,a),e.children)};return lo!==void 0?P.createElement(lo.Consumer,null,r=>t(r)):t(co)}function Oa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M416 32H32A32 32 0 0 0 0 64v384a32 32 0 0 0 32 32h384a32 32 0 0 0 32-32V64a32 32 0 0 0-32-32zm-32 64v128H256V96zm-192 0v128H64V96zM64 416V288h128v128zm192 0V288h128v128z"},child:[]}]})(e)}function ja(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"},child:[]}]})(e)}function Ta(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M497.941 273.941c18.745-18.745 18.745-49.137 0-67.882l-160-160c-18.745-18.745-49.136-18.746-67.883 0l-256 256c-18.745 18.745-18.745 49.137 0 67.882l96 96A48.004 48.004 0 0 0 144 480h356c6.627 0 12-5.373 12-12v-40c0-6.627-5.373-12-12-12H355.883l142.058-142.059zm-302.627-62.627l137.373 137.373L265.373 416H150.628l-80-80 124.686-124.686z"},child:[]}]})(e)}function Pa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M0 180V56c0-13.3 10.7-24 24-24h124c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H64v84c0 6.6-5.4 12-12 12H12c-6.6 0-12-5.4-12-12zM288 44v40c0 6.6 5.4 12 12 12h84v84c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12V56c0-13.3-10.7-24-24-24H300c-6.6 0-12 5.4-12 12zm148 276h-40c-6.6 0-12 5.4-12 12v84h-84c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h124c13.3 0 24-10.7 24-24V332c0-6.6-5.4-12-12-12zM160 468v-40c0-6.6-5.4-12-12-12H64v-84c0-6.6-5.4-12-12-12H12c-6.6 0-12 5.4-12 12v124c0 13.3 10.7 24 24 24h124c6.6 0 12-5.4 12-12z"},child:[]}]})(e)}function ka(e){return fe({attr:{viewBox:"0 0 496 512"},child:[{tag:"path",attr:{d:"M336.5 160C322 70.7 287.8 8 248 8s-74 62.7-88.5 152h177zM152 256c0 22.2 1.2 43.5 3.3 64h185.3c2.1-20.5 3.3-41.8 3.3-64s-1.2-43.5-3.3-64H155.3c-2.1 20.5-3.3 41.8-3.3 64zm324.7-96c-28.6-67.9-86.5-120.4-158-141.6 24.4 33.8 41.2 84.7 50 141.6h108zM177.2 18.4C105.8 39.6 47.8 92.1 19.3 160h108c8.7-56.9 25.5-107.8 49.9-141.6zM487.4 192H372.7c2.1 21 3.3 42.5 3.3 64s-1.2 43-3.3 64h114.6c5.5-20.5 8.6-41.8 8.6-64s-3.1-43.5-8.5-64zM120 256c0-21.5 1.2-43 3.3-64H8.6C3.2 212.5 0 233.8 0 256s3.2 43.5 8.6 64h114.6c-2-21-3.2-42.5-3.2-64zm39.5 96c14.5 89.3 48.7 152 88.5 152s74-62.7 88.5-152h-177zm159.3 141.6c71.4-21.2 129.4-73.7 158-141.6h-108c-8.8 56.9-25.6 107.8-50 141.6zM19.3 352c28.6 67.9 86.5 120.4 158 141.6-24.4-33.8-41.2-84.7-50-141.6h-108z"},child:[]}]})(e)}function Ma(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"},child:[]}]})(e)}function Ra(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"},child:[]}]})(e)}function Na(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"},child:[]}]})(e)}function Aa(e){return fe({attr:{viewBox:"0 0 320 512"},child:[{tag:"path",attr:{d:"M302.189 329.126H196.105l55.831 135.993c3.889 9.428-.555 19.999-9.444 23.999l-49.165 21.427c-9.165 4-19.443-.571-23.332-9.714l-53.053-129.136-86.664 89.138C18.729 472.71 0 463.554 0 447.977V18.299C0 1.899 19.921-6.096 30.277 5.443l284.412 292.542c11.472 11.179 3.007 31.141-12.5 31.141z"},child:[]}]})(e)}function Ia(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M497.9 142.1l-46.1 46.1c-4.7 4.7-12.3 4.7-17 0l-111-111c-4.7-4.7-4.7-12.3 0-17l46.1-46.1c18.7-18.7 49.1-18.7 67.9 0l60.1 60.1c18.8 18.7 18.8 49.1 0 67.9zM284.2 99.8L21.6 362.4.4 483.9c-2.9 16.4 11.4 30.6 27.8 27.8l121.5-21.3 262.6-262.6c4.7-4.7 4.7-12.3 0-17l-111-111c-4.8-4.7-12.4-4.7-17.1 0zM124.1 339.9c-5.5-5.5-5.5-14.3 0-19.8l154-154c5.5-5.5 14.3-5.5 19.8 0s5.5 14.3 0 19.8l-154 154c-5.5 5.5-14.3 5.5-19.8 0zM88 424h48v36.3l-64.5 11.3-31.1-31.1L51.7 376H88v48z"},child:[]}]})(e)}function Da(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"},child:[]}]})(e)}function za(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM224 416c-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64s64 28.654 64 64c0 35.346-28.654 64-64 64zm96-304.52V212c0 6.627-5.373 12-12 12H76c-6.627 0-12-5.373-12-12V108c0-6.627 5.373-12 12-12h228.52c3.183 0 6.235 1.264 8.485 3.515l3.48 3.48A11.996 11.996 0 0 1 320 111.48z"},child:[]}]})(e)}function La(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z"},child:[]}]})(e)}function Wa(e){return fe({attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"},child:[]}]})(e)}function Ya(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z"},child:[]}]})(e)}const Va=({text:e,shifted:t})=>h.jsxs("div",{className:`wb-lock-indicator ${t?"wb-shifted":""}`,children:[h.jsx(Na,{}),h.jsx("span",{children:e||"Locked"})]});function $a(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"},child:[]}]})(e)}function Fa(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M284.3 11.7c-15.6-15.6-40.9-15.6-56.6 0l-216 216c-15.6 15.6-15.6 40.9 0 56.6l216 216c15.6 15.6 40.9 15.6 56.6 0l216-216c15.6-15.6 15.6-40.9 0-56.6l-216-216z"},child:[]}]})(e)}function Xa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M8 256a56 56 0 1 1 112 0A56 56 0 1 1 8 256zm160 0a56 56 0 1 1 112 0 56 56 0 1 1 -112 0zm216-56a56 56 0 1 1 0 112 56 56 0 1 1 0-112z"},child:[]}]})(e)}function Ba(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 144l0 48 160 0 0-48c0-44.2-35.8-80-80-80s-80 35.8-80 80zM80 192l0-48C80 64.5 144.5 0 224 0s144 64.5 144 144l0 48 16 0c35.3 0 64 28.7 64 64l0 192c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 256c0-35.3 28.7-64 64-64l16 0z"},child:[]}]})(e)}function Ua(e){return fe({attr:{viewBox:"0 0 384 512"},child:[{tag:"path",attr:{d:"M32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l128 0 0 352c0 17.7 14.3 32 32 32s32-14.3 32-32l0-352 128 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L192 32 32 32z"},child:[]}]})(e)}function Ha(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 144c0-44.2 35.8-80 80-80c31.9 0 59.4 18.6 72.3 45.7c7.6 16 26.7 22.8 42.6 15.2s22.8-26.7 15.2-42.6C331 33.7 281.5 0 224 0C144.5 0 80 64.5 80 144l0 48-16 0c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-192c0-35.3-28.7-64-64-64l-240 0 0-48z"},child:[]}]})(e)}function qa(e){return fe({attr:{fill:"currentColor",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{fillRule:"evenodd",d:"M8.5.134a1 1 0 0 0-1 0l-6 3.577a1 1 0 0 0-.5.866v6.846a1 1 0 0 0 .5.866l6 3.577a1 1 0 0 0 1 0l6-3.577a1 1 0 0 0 .5-.866V4.577a1 1 0 0 0-.5-.866z"},child:[]}]})(e)}function Ga(e){return fe({attr:{fill:"currentColor",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{d:"M11.107 0a.5.5 0 0 1 .353.146l4.394 4.394a.5.5 0 0 1 .146.353v6.214a.5.5 0 0 1-.146.353l-4.394 4.394a.5.5 0 0 1-.353.146H4.893a.5.5 0 0 1-.353-.146L.146 11.46A.5.5 0 0 1 0 11.107V4.893a.5.5 0 0 1 .146-.353L4.54.146A.5.5 0 0 1 4.893 0z"},child:[]}]})(e)}const Ka=({onClose:e,onConfirm:t})=>{const{t:r}=Ut(),[n,i]=P.useState(!1),a=()=>{i(!0),setTimeout(e,300)},l=()=>{i(!0),setTimeout(t,300)};return Hr.createPortal(h.jsx("div",{className:`wb-confirm-popup-overlay ${n?"wb-closing":""}`,children:h.jsxs("div",{className:"wb-confirm-popup",children:[h.jsx("p",{children:r("confirmClear")}),h.jsxs("div",{className:"wb-actions",children:[h.jsx("button",{onClick:a,children:r("cancel")}),h.jsx("button",{onClick:l,children:r("clear")})]})]})}),document.body)},Ja=({mode:e="user",onImageUpload:t})=>{const r=vr(),{t:n,language:i,changeLanguage:a}=Ut(),l=xe(X=>X.whiteboard.toolbar.selectedTool),u=xe(X=>X.whiteboard.lock.isLocked),[p,c]=P.useState(!1),[v,b]=P.useState(!1),[s,S]=P.useState(!1),m=P.useRef(null),y=P.useRef(null),E=P.useRef(null),C=P.useRef(null),O=P.useRef(null),k=async X=>{var oe;const M=(oe=X.target.files)==null?void 0:oe[0];if(M){if(t)try{const ue=URL.createObjectURL(M),he=new Image;he.onload=async()=>{const pe=he.width,we=he.height;URL.revokeObjectURL(ue);try{const Te=await t(M),Pe=Date.now().toString();r(Se({id:Pe,type:"image",x:100,y:100,width:pe,height:we,src:Te})),r(Me("pointer")),r(He([Pe]))}catch(Te){console.error("Image upload failed:",Te)}},he.src=ue}catch(ue){console.error("Error processing image:",ue)}else{const ue=URL.createObjectURL(M),he=new Image;he.onload=()=>{const pe=Date.now().toString();r(Se({id:pe,type:"image",x:100,y:100,width:he.width,height:he.height,src:ue})),r(Me("pointer")),r(He([pe]))},he.src=ue}X.target.value=""}};P.useEffect(()=>{const X=M=>{const oe=M.target;m.current&&!m.current.contains(oe)&&y.current&&!y.current.contains(oe)&&c(!1),C.current&&!C.current.contains(oe)&&E.current&&!E.current.contains(oe)&&b(!1)};return document.addEventListener("mousedown",X),()=>document.removeEventListener("mousedown",X)},[]);const I=()=>{S(!0)},x=()=>{r(Me("pointer")),r(He([])),r(Wr()),S(!1)},D=[{name:"triangle",icon:h.jsx(Da,{style:{transform:"rotate(-30deg)"}})},{name:"diamond",icon:h.jsx(Fa,{})},{name:"star",icon:h.jsx(Wa,{})},{name:"heart",icon:h.jsx(Ma,{})},{name:"hexagon",icon:h.jsx(qa,{})},{name:"octagon",icon:h.jsx(Ga,{})},{name:"arrow",icon:h.jsx($a,{})}],F=X=>{r(Me(X)),c(!1)},j=X=>{a(X),b(!1)};return h.jsxs("div",{className:"wb-toolbar",children:[h.jsx("button",{className:l==="pointer"?"wb-active":"",onClick:()=>r(Me("pointer")),title:n("pointer"),disabled:u,children:h.jsx(Aa,{})}),h.jsx("button",{className:l==="text"?"wb-active":"",onClick:()=>r(Me("text")),title:n("text"),disabled:u,children:h.jsx(Ua,{})}),h.jsx("button",{onClick:()=>{var X;return(X=O.current)==null?void 0:X.click()},title:n("image"),disabled:u,children:h.jsx(Ra,{})}),h.jsx("input",{type:"file",ref:O,style:{display:"none"},accept:"image/*",onChange:k}),h.jsx("button",{className:l==="pencil"?"wb-active":"",onClick:()=>r(Me("pencil")),title:n("pencil"),disabled:u,children:h.jsx(Ia,{})}),h.jsx("button",{className:l==="rectangle"?"wb-active":"",onClick:()=>r(Me("rectangle")),title:n("rectangle"),disabled:u,children:h.jsx(La,{})}),h.jsx("button",{className:l==="circle"?"wb-active":"",onClick:()=>r(Me("circle")),title:n("circle"),disabled:u,children:h.jsx(ja,{})}),h.jsxs("div",{className:"wb-ellipsis-container",children:[h.jsx("button",{ref:y,className:D.some(X=>X.name===l)?"wb-active":"",onClick:()=>c(!p),title:n("moreShapes"),disabled:u,children:h.jsx(Xa,{})}),p&&h.jsxs("div",{className:"wb-shapes-popup",ref:m,children:[h.jsx("div",{className:"wb-shapes-popup-header",children:n("moreShapes")}),h.jsx("div",{className:"wb-shapes-popup-grid",children:D.map(X=>h.jsx("button",{className:l===X.name?"wb-active":"",onClick:()=>F(X.name),title:n(X.name),children:X.icon},X.name))})]})]}),h.jsx("button",{className:l==="eraser"?"wb-active":"",onClick:()=>r(Me("eraser")),title:n("eraser"),disabled:u,children:h.jsx(Ta,{})}),h.jsx("button",{onClick:I,title:n("trash"),disabled:u,children:h.jsx(Ya,{})}),h.jsxs("div",{className:"wb-language-container",children:[h.jsx("button",{ref:E,onClick:()=>b(!v),title:n("language"),children:h.jsx(ka,{})}),v&&h.jsxs("div",{className:"wb-language-popup",ref:C,children:[h.jsx("div",{className:"wb-language-popup-header",children:n("language")}),h.jsxs("div",{className:"wb-language-options",children:[h.jsxs("button",{className:i==="en"?"wb-active":"",onClick:()=>j("en"),children:["πŸ‡ΊπŸ‡Έ ",n("english")]}),h.jsxs("button",{className:i==="tr"?"wb-active":"",onClick:()=>j("tr"),children:["πŸ‡ΉπŸ‡· ",n("turkish")]})]})]})]}),e==="moderator"&&h.jsx("button",{onClick:()=>r(io(!u)),title:u?"Unlock":"Lock",style:{color:u?"red":"inherit"},children:u?h.jsx(Ba,{}):h.jsx(Ha,{})}),s&&h.jsx(Ka,{onConfirm:x,onClose:()=>S(!1)})]})},Za=({shifted:e})=>{const t=vr(),{t:r}=Ut(),n=xe(s=>s.whiteboard.toolbar.selectedTool),i=xe(s=>s.whiteboard.toolProperties),a=xe(s=>s.whiteboard.selectedElementIds||[]),l=xe(s=>s.whiteboard.elements),u=a.length>0?l.find(s=>s.id===a[0]):null,p=(s,S,m)=>{t(na({tool:s,property:S,value:m}))},c=(s,S)=>{if(a.length>0){const m=a.map(y=>({id:y,updates:{[s]:S}}));t(oo(m))}},v=()=>{a.forEach(s=>{t(ca(s))})},b=()=>{[...a].reverse().forEach(s=>{t(la(s))})};if(n==="pointer"&&u&&u.type==="text")return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontSize")}),h.jsxs("select",{className:"font-size-selector",value:u.fontSize||16,onChange:s=>c("fontSize",parseInt(s.target.value)),children:[h.jsx("option",{value:"12",children:"12 px"}),h.jsx("option",{value:"14",children:"14 px"}),h.jsx("option",{value:"16",children:"16 px"}),h.jsx("option",{value:"18",children:"18 px"}),h.jsx("option",{value:"24",children:"24 px"}),h.jsx("option",{value:"32",children:"32 px"}),h.jsx("option",{value:"48",children:"48 px"}),h.jsx("option",{value:"64",children:"64 px"}),h.jsx("option",{value:"72",children:"72 px"})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontColor")}),h.jsx("input",{type:"color",value:u.fontColor||"#000000",onChange:s=>c("fontColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("layerOrder")}),h.jsxs("div",{className:"wb-layer-buttons",children:[h.jsx("button",{onClick:v,title:r("bringToFront"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"white"})]})}),h.jsx("button",{onClick:b,title:r("sendToBack"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"white"})]})})]})]})]});if(n==="pointer"&&u){const s=["rectangle","circle","triangle","diamond","star","heart","hexagon","octagon","arrow"].includes(u.type),S=u.type==="pencil";return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[s&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeColor")}),h.jsx("input",{type:"color",value:u.strokeColor,onChange:m=>c("strokeColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fillColor")}),h.jsx("input",{type:"color",value:u.fillColor,onChange:m=>c("fillColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeWidth")}),h.jsxs("select",{className:"stroke-width-selector",value:u.lineWidth,onChange:m=>c("lineWidth",parseInt(m.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"})]})]})]}),S&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushColor")}),h.jsx("input",{type:"color",value:u.strokeColor,onChange:m=>c("strokeColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushSize")}),h.jsxs("select",{className:"brush-size-selector",value:u.lineWidth,onChange:m=>c("lineWidth",parseInt(m.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"}),h.jsx("option",{value:"16",children:"16 px"})]})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("layerOrder")}),h.jsxs("div",{className:"wb-layer-buttons",children:[h.jsx("button",{onClick:v,title:r("bringToFront"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"white"})]})}),h.jsx("button",{onClick:b,title:r("sendToBack"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"white"})]})})]})]})]})}return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[n==="text"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontSize")}),h.jsxs("select",{className:"font-size-selector",value:i.text.fontSize,onChange:s=>p("text","fontSize",parseInt(s.target.value)),children:[h.jsx("option",{value:"12",children:"12 px"}),h.jsx("option",{value:"14",children:"14 px"}),h.jsx("option",{value:"16",children:"16 px"}),h.jsx("option",{value:"18",children:"18 px"}),h.jsx("option",{value:"24",children:"24 px"}),h.jsx("option",{value:"32",children:"32 px"}),h.jsx("option",{value:"48",children:"48 px"}),h.jsx("option",{value:"64",children:"64 px"}),h.jsx("option",{value:"72",children:"72 px"})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontColor")}),h.jsx("input",{type:"color",value:i.text.fontColor,onChange:s=>p("text","fontColor",s.target.value)})]})]}),n==="pencil"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushColor")}),h.jsx("input",{type:"color",value:i.pencil.strokeColor,onChange:s=>p("pencil","strokeColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushSize")}),h.jsxs("select",{className:"brush-size-selector",value:i.pencil.lineWidth,onChange:s=>p("pencil","lineWidth",parseInt(s.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"}),h.jsx("option",{value:"16",children:"16 px"})]})]})]}),(n==="rectangle"||n==="circle"||n==="triangle"||n==="diamond"||n==="star"||n==="heart"||n==="hexagon"||n==="octagon"||n==="arrow")&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeColor")}),h.jsx("input",{type:"color",value:i[n].strokeColor,onChange:s=>p(n,"strokeColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fillColor")}),h.jsx("input",{type:"color",value:i[n].fillColor,onChange:s=>p(n,"fillColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeWidth")}),h.jsxs("select",{className:"stroke-width-selector",value:i[n].lineWidth,onChange:s=>p(n,"lineWidth",parseInt(s.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"})]})]})]})]})},Qa=({onFitToView:e,onExport:t,onToggleGrid:r})=>{const{t:n}=Ut();return h.jsxs("div",{className:"wb-canvas-tools",children:[h.jsx("button",{onClick:r,title:n("toggleGrid"),children:h.jsx(Oa,{})}),h.jsx("button",{onClick:e,title:n("fitToView"),children:h.jsx(Pa,{})}),h.jsx("button",{onClick:t,title:n("exportAsPng"),children:h.jsx(za,{})})]})},$r=P.forwardRef(({watermark:e,isLocked:t,lockText:r,onLockChange:n,isWatermarkEnabled:i,watermarkText:a,mode:l,initialElements:u,onAfterMount:p,onImageUpload:c},v)=>{var mo;const b=P.useRef(null),s=vr(),S=wn(),m=xe(o=>o.whiteboard.grid),y=xe(o=>o.whiteboard.toolbar.selectedTool),E=xe(o=>o.whiteboard.elements),C=xe(o=>o.whiteboard.viewport),O=xe(o=>o.whiteboard.toolProperties),k=xe(o=>o.whiteboard.selectedElementIds||[]),I=xe(o=>o.whiteboard.lock),x=I.isLocked,[D,F]=P.useState(!1),[j,X]=P.useState({x:0,y:0}),[M,oe]=P.useState({x:0,y:0}),[ue,he]=P.useState([]),[pe,we]=P.useState(!1),[Te,Pe]=P.useState({}),[ke,Ve]=P.useState(!1),[Re,Ne]=P.useState(!1),[$e,Fe]=P.useState(!1),[rt,lt]=P.useState({x:0,y:0}),[Xe,qe]=P.useState({y:0,initialZoom:1}),[Ae,Oe]=P.useState(!1),[Ie,nt]=P.useState({x:0,y:0}),[V,Ee]=P.useState(""),[$,ge]=P.useState(null),je=P.useRef(null),De=P.useRef(null),[xt,tr]=P.useState(!1),[me,Et]=P.useState(null),[Nt,At]=P.useState(null),[It,rr]=P.useState(null),[St,nr]=P.useState(!1),[se,Dt]=P.useState(null),Fr=P.useCallback(o=>{$&&o.trim()&&(je.current&&clearTimeout(je.current),je.current=setTimeout(()=>{$&&o!==De.current&&(De.current=o,s(Zt({id:$,updates:{text:o}})))},150))},[s,$]);P.useEffect(()=>()=>{je.current&&clearTimeout(je.current)},[]),P.useImperativeHandle(v,()=>({canvas:b.current,applyAction:o=>{s({...o,meta:{...o.meta,fromRemote:!0}})},getElems:()=>S.getState().whiteboard.elements,getElements:()=>S.getState().whiteboard.elements,setElems:o=>{s({...Yr(o),meta:{fromRemote:!0}})},setElements:o=>{s({...Yr(o),meta:{fromRemote:!0}})},clearElems:()=>{s({...Wr(),meta:{fromRemote:!0}})},clearElements:()=>{s({...Wr(),meta:{fromRemote:!0}})}})),P.useEffect(()=>{t!==void 0&&s(io(t))},[t,s]),P.useEffect(()=>{n&&n(x)},[x,n]);const ut=xe(o=>o.whiteboard.watermark);P.useEffect(()=>{i!==void 0&&i!==ut.visible&&s(ua(i))},[i,ut.visible,s]),P.useEffect(()=>{a!==void 0&&a!==ut.text&&s(fa(a))},[a,ut.text,s]),P.useEffect(()=>{u&&u.length>0&&s(Yr(u))},[s]),P.useEffect(()=>{p&&setTimeout(()=>{p()},0)},[]);const Ct=P.useCallback((o,f,g)=>{const w=o.canvas,_=w.width,T=w.height,N=Math.floor(-C.panX/C.zoom/f)*f,A=Math.floor(-C.panY/C.zoom/f)*f,z=Math.ceil((_/C.zoom-C.panX/C.zoom)/f)*f,B=Math.ceil((T/C.zoom-C.panY/C.zoom)/f)*f;o.strokeStyle=g,o.lineWidth=.5/C.zoom;for(let Y=N;Y<=z;Y+=f)o.beginPath(),o.moveTo(Y,A),o.lineTo(Y,B),o.stroke();for(let Y=A;Y<=B;Y+=f)o.beginPath(),o.moveTo(N,Y),o.lineTo(z,Y),o.stroke()},[C]),zt=P.useCallback((o,f,g)=>{const w=Math.min(f.x,g.x),_=Math.min(f.y,g.y),T=Math.abs(g.x-f.x),N=Math.abs(g.y-f.y);o.strokeStyle="#0066cc",o.lineWidth=1,o.setLineDash([5,5]),o.strokeRect(w,_,T,N),o.fillStyle="rgba(0, 102, 204, 0.1)",o.fillRect(w,_,T,N),o.setLineDash([])},[]),ze=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#000",strokeColor:A="#000",lineWidth:z=2}=f;o.fillStyle=N,o.fillRect(g,w,_,T),o.strokeStyle=A,o.lineWidth=z,o.strokeRect(g,w,_,T)},[]),ot=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,radius:_=0,fillColor:T="#000",strokeColor:N="#000",lineWidth:A=2}=f;o.beginPath(),o.arc(g,w,_,0,Math.PI*2),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),it=P.useCallback((o,f)=>{const{points:g=[],strokeColor:w="#000",lineWidth:_=2}=f;if(!(g.length<2)){o.strokeStyle=w,o.lineWidth=_,o.lineCap="round",o.lineJoin="round",o.beginPath(),o.moveTo(g[0].x,g[0].y);for(let T=1;T<g.length;T++)g[T]&&o.lineTo(g[T].x,g[T].y);o.stroke()}},[]),Lt=P.useCallback((o,f)=>{const{x:g=0,y:w=0,text:_="",fontSize:T=16,fontColor:N="#000"}=f;o.font=`${T}px sans-serif`,o.fillStyle=N,o.textBaseline="top",o.fillText(_,g,w)},[]),_t=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f;o.beginPath(),o.moveTo(g+_/2,w),o.lineTo(g+_,w+T),o.lineTo(g,w+T),o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),ft=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f;o.beginPath(),o.moveTo(g+_/2,w),o.lineTo(g+_,w+T/2),o.lineTo(g+_/2,w+T),o.lineTo(g,w+T/2),o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),Ot=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,size:_=0,fillColor:T="#ffff00",strokeColor:N="#000",lineWidth:A=2}=f,z=5,B=_,Y=_/2;o.beginPath();for(let L=0;L<z*2;L++){const H=L%2===0?B:Y,q=Math.PI/z*L-Math.PI/2,K=g+Math.cos(q)*H,ie=w+Math.sin(q)*H;L===0?o.moveTo(K,ie):o.lineTo(K,ie)}o.closePath(),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),dt=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,size:_=0,fillColor:T="#ff6b6b",strokeColor:N="#000",lineWidth:A=2}=f;o.beginPath();const z=w-_/2;o.moveTo(g,z+_/4),o.bezierCurveTo(g-_/2,z,g-_,z+_/2,g,w+_/2),o.bezierCurveTo(g+_,z+_/2,g+_/2,z,g,z+_/4),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),ht=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f,B=g+_/2,Y=w+T/2,L=_/2,H=T/2;o.beginPath();for(let q=0;q<6;q++){const K=Math.PI/3*q-Math.PI/2,ie=B+Math.cos(K)*L,ve=Y+Math.sin(K)*H;q===0?o.moveTo(ie,ve):o.lineTo(ie,ve)}o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),jt=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f,B=g+_/2,Y=w+T/2,L=_/2,H=T/2;o.beginPath();for(let q=0;q<8;q++){const K=Math.PI/4*q-Math.PI/2,ie=B+Math.cos(K)*L,ve=Y+Math.sin(K)*H;q===0?o.moveTo(ie,ve):o.lineTo(ie,ve)}o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),Tt=P.useCallback((o,f)=>{const{startX:g=0,startY:w=0,endX:_=0,endY:T=0,fillColor:N="#000",strokeColor:A="#000",lineWidth:z=2}=f,B=15,Y=Math.atan2(T-w,_-g);o.beginPath(),o.moveTo(g,w),o.lineTo(_,T),o.strokeStyle=A,o.lineWidth=z,o.stroke(),o.beginPath(),o.moveTo(_,T),o.lineTo(_-B*Math.cos(Y-Math.PI/6),T-B*Math.sin(Y-Math.PI/6)),o.lineTo(_-B*Math.cos(Y+Math.PI/6),T-B*Math.sin(Y+Math.PI/6)),o.closePath(),o.fillStyle=N,o.fill()},[]),pt=P.useRef({}),Wt=P.useRef(null),or=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,src:N=""}=f;if(pt.current[N]){const A=pt.current[N];A.complete&&o.drawImage(A,g,w,_,T)}else{const A=new Image;A.onload=()=>{pt.current[N]=A,Wt.current&&Wt.current()},A.src=N,pt.current[N]=A}},[]),Pt=P.useCallback((o,f)=>{switch(f.type){case"rectangle":ze(o,f);break;case"circle":ot(o,f);break;case"pencil":it(o,f);break;case"text":Lt(o,f);break;case"triangle":_t(o,f);break;case"diamond":ft(o,f);break;case"star":Ot(o,f);break;case"heart":dt(o,f);break;case"hexagon":ht(o,f);break;case"octagon":jt(o,f);break;case"arrow":Tt(o,f);break;case"image":or(o,f);break}},[ze,ot,it,Lt,_t,ft,Ot,dt,ht,jt,Tt,or]),Xr=P.useCallback(()=>{const o=b.current;if(!o)return;const f=document.createElement("canvas");f.width=o.width,f.height=o.height;const g=f.getContext("2d");if(!g)return;g.fillStyle="#ffffff",g.fillRect(0,0,f.width,f.height),g.save(),g.translate(C.panX,C.panY),g.scale(C.zoom,C.zoom),E.forEach(T=>{Pt(g,T)}),g.restore();const w=f.toDataURL("image/png"),_=document.createElement("a");_.download=`whiteboard-${Date.now()}.png`,_.href=w,_.click()},[C,E,Pt]),d=P.useCallback(()=>{const o=b.current;o&&s(sa({canvasWidth:o.width,canvasHeight:o.height,padding:50}))},[s]),R=P.useCallback(()=>{s(ra())},[s]),W=(o,f,g,w,_,T)=>{const N=o-g,A=f-w,z=_-g,B=T-w,Y=N*z+A*B,L=z*z+B*B;let H=-1;L!==0&&(H=Y/L);let q,K;H<0?(q=g,K=w):H>1?(q=_,K=T):(q=g+H*z,K=w+H*B);const ie=o-q,ve=f-K;return Math.sqrt(ie*ie+ve*ve)},U=P.useCallback((o,f)=>{for(let g=E.length-1;g>=0;g--){const w=E[g],_=w.x??0,T=w.y??0,N=w.width??0,A=w.height??0,z=w.centerX??0,B=w.centerY??0,Y=w.radius??0;if(w.type==="rectangle"){if(o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}else if(w.type==="circle"){if(Math.sqrt(Math.pow(o-z,2)+Math.pow(f-B,2))<=Y)return w}else if(w.type==="pencil"){const H=w.points??[];for(let q=1;q<H.length;q++){const K=H[q-1],ie=H[q];if(!K||!ie)continue;if(W(o,f,K.x,K.y,ie.x,ie.y)<=5)return w}}else if(w.type==="text"){const L=w.fontSize||16,q=(w.text||"").length*L*.6,K=L;if(o>=_&&o<=_+q&&f>=T&&f<=T+K)return w}else if(w.type==="triangle"||w.type==="diamond"||w.type==="hexagon"||w.type==="octagon"){if(o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}else if(w.type==="star"||w.type==="heart"){const L=Math.sqrt(Math.pow(o-z,2)+Math.pow(f-B,2)),H=w.size??0;if(L<=H)return w}else if(w.type==="arrow"){const H=w.startX??0,q=w.startY??0,K=w.endX??0,ie=w.endY??0;if(W(o,f,H,q,K,ie)<=10)return w}else if(w.type==="image"&&o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}return null},[E]),Z=P.useCallback(o=>{let f=0,g=0,w=0,_=0;if(o.type==="rectangle"||o.type==="image"||o.type==="text"||o.type==="triangle"||o.type==="diamond"||o.type==="hexagon"||o.type==="octagon")if(f=o.x??0,g=o.y??0,o.type==="text"){const T=o.fontSize||16;w=(o.text||"").length*T*.6,_=T}else w=o.width??0,_=o.height??0;else if(o.type==="circle"){const T=o.radius??0;f=(o.centerX??0)-T,g=(o.centerY??0)-T,w=T*2,_=T*2}else if(o.type==="star"||o.type==="heart"){const T=o.size??0;f=(o.centerX??0)-T,g=(o.centerY??0)-T,w=T*2,_=T*2}else if(o.type==="pencil"&&o.points&&o.points.length>0){const T=Math.min(...o.points.map(B=>B.x)),N=Math.max(...o.points.map(B=>B.x)),A=Math.min(...o.points.map(B=>B.y)),z=Math.max(...o.points.map(B=>B.y));f=T,g=A,w=N-T,_=z-A}else if(o.type==="arrow")return null;return{x:f,y:g,w,h:_}},[]),Q=P.useCallback(o=>{const f=[];if(o.type==="arrow")return f.push({type:"start",x:o.startX??0,y:o.startY??0}),f.push({type:"end",x:o.endX??0,y:o.endY??0}),f;const g=Z(o);if(!g)return[];const{x:w,y:_,w:T,h:N}=g;return f.push({type:"nw",x:w,y:_}),f.push({type:"ne",x:w+T,y:_}),f.push({type:"se",x:w+T,y:_+N}),f.push({type:"sw",x:w,y:_+N}),f.push({type:"n",x:w+T/2,y:_}),f.push({type:"s",x:w+T/2,y:_+N}),f.push({type:"e",x:w+T,y:_+N/2}),f.push({type:"w",x:w,y:_+N/2}),f},[Z]),J=P.useCallback((o,f,g,w)=>{const _=Q(g),T=10/w;for(const N of _)if(Math.abs(o-N.x)<=T&&Math.abs(f-N.y)<=T)return N.type;return null},[Q]),G=P.useCallback((o,f)=>{o.strokeStyle="#0066cc",o.lineWidth=1/C.zoom,o.setLineDash([5/C.zoom,5/C.zoom]);const g=Z(f);g?o.strokeRect(g.x-4/C.zoom,g.y-4/C.zoom,g.w+8/C.zoom,g.h+8/C.zoom):f.type,o.setLineDash([]);const w=Q(f),_=8/C.zoom;o.fillStyle="#ffffff",o.strokeStyle="#0066cc",o.lineWidth=1/C.zoom;for(const T of w)o.fillRect(T.x-_/2,T.y-_/2,_,_),o.strokeRect(T.x-_/2,T.y-_/2,_,_)},[C.zoom,Z,Q]),ce=P.useCallback(()=>{const o=b.current;if(!o)return;const f=o.getContext("2d");f&&(f.clearRect(0,0,o.width,o.height),f.save(),f.translate(C.panX,C.panY),f.scale(C.zoom,C.zoom),m.enabled&&Ct(f,m.size,m.color),E.forEach(g=>{Pt(f,g),k.includes(g.id)&&G(f,g)}),St&&se&&(f.fillStyle="rgba(0, 102, 204, 0.1)",f.strokeStyle="#0066cc",f.lineWidth=1/C.zoom,f.fillRect(se.startX,se.startY,se.width,se.height),f.strokeRect(se.startX,se.startY,se.width,se.height)),f.restore())},[m,Ct,E,Pt,k,G,C,St,se]);P.useEffect(()=>{Wt.current=ce},[ce]),P.useEffect(()=>{const o=b.current;if(!o)return;const f=o.parentElement;if(!f)return;const g=()=>{const _=f.getBoundingClientRect();o.width=_.width,o.height=_.height,ce()};g();const w=new ResizeObserver(()=>{g()});return w.observe(f),()=>{w.disconnect()}},[ce]),P.useEffect(()=>{ce()},[ce]),P.useEffect(()=>{const o=g=>{g.target.tagName==="INPUT"||g.target.tagName==="TEXTAREA"||g.code==="Space"&&!g.repeat&&(g.preventDefault(),Ve(!0))},f=g=>{g.target.tagName==="INPUT"||g.target.tagName==="TEXTAREA"||g.code==="Space"&&(g.preventDefault(),Ve(!1),Ne(!1),Fe(!1))};return window.addEventListener("keydown",o),window.addEventListener("keyup",f),()=>{window.removeEventListener("keydown",o),window.removeEventListener("keyup",f)}},[]);const ae=P.useCallback((o,f)=>({x:(o-C.panX)/C.zoom,y:(f-C.panY)/C.zoom}),[C]);P.useEffect(()=>{const o=b.current;if(!o||!D)return;const f=o.getContext("2d");if(f){if(ce(),f.save(),f.translate(C.panX,C.panY),f.scale(C.zoom,C.zoom),y==="pointer")zt(f,j,M);else if(y==="rectangle"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ze(f,{id:"preview",type:"rectangle",x:g,y:w,width:_,height:T,fillColor:O.rectangle.fillColor,lineWidth:O.rectangle.lineWidth})}else if(y==="circle"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));ot(f,{id:"preview",type:"circle",centerX:g,centerY:w,radius:_,strokeColor:O.circle.strokeColor,fillColor:O.circle.fillColor,lineWidth:O.circle.lineWidth})}else if(y==="pencil")it(f,{id:"preview",type:"pencil",points:ue,strokeColor:O.pencil.strokeColor,lineWidth:O.pencil.lineWidth});else if(y==="triangle"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);_t(f,{id:"preview",type:"triangle",x:g,y:w,width:_,height:T,fillColor:O.triangle.fillColor,lineWidth:O.triangle.lineWidth})}else if(y==="diamond"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ft(f,{id:"preview",type:"diamond",x:g,y:w,width:_,height:T,fillColor:O.diamond.fillColor,lineWidth:O.diamond.lineWidth})}else if(y==="star"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));Ot(f,{id:"preview",type:"star",centerX:g,centerY:w,size:_,fillColor:O.star.fillColor,lineWidth:O.star.lineWidth})}else if(y==="heart"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));dt(f,{id:"preview",type:"heart",centerX:g,centerY:w,size:_,fillColor:O.heart.fillColor,lineWidth:O.heart.lineWidth})}else if(y==="hexagon"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ht(f,{id:"preview",type:"hexagon",x:g,y:w,width:_,height:T,fillColor:O.hexagon.fillColor,lineWidth:O.hexagon.lineWidth})}else if(y==="octagon"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);jt(f,{id:"preview",type:"octagon",x:g,y:w,width:_,height:T,fillColor:O.octagon.fillColor,lineWidth:O.octagon.lineWidth})}else y==="arrow"&&Tt(f,{id:"preview",type:"arrow",startX:j.x,startY:j.y,endX:M.x,endY:M.y,fillColor:O.arrow.fillColor,lineWidth:O.arrow.lineWidth});f.restore()}},[D,y,j,M,ue,ce,zt,ze,ot,it,_t,ft,Ot,dt,ht,jt,Tt,C,O]);const de=o=>{const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top;if(Ae)return;if(ke){o.preventDefault(),o.button===0?(Ne(!0),lt({x:w-C.panX,y:_-C.panY})):o.button===2&&(Fe(!0),qe({y:_,initialZoom:C.zoom}));return}if(x)return;const{x:T,y:N}=ae(w,_);if(y==="pointer"){const A=U(T,N);let z=null;if(k.length===1){const B=k[0],Y=E.find(L=>L.id===B);if(Y){const L=J(T,N,Y,C.zoom);L&&(z={element:Y,handle:L})}}if(z){tr(!0),Et(z.handle),At({x:T,y:N}),rr(JSON.parse(JSON.stringify(z.element)));return}if(A){const B=k.includes(A.id);let Y=k;if(o.shiftKey?(B?Y=k.filter(L=>L!==A.id):Y=[...k,A.id],s(He(Y))):B||(Y=[A.id],s(He(Y))),Y.length>0){we(!0),X({x:T,y:N});const L={};Y.forEach(H=>{const q=E.find(K=>K.id===H);q&&(L[H]={...q})}),Pe(L)}}else{o.shiftKey||s(He([])),nr(!0);const{x:B,y:Y}=ae(w,_);Dt({startX:B,startY:Y,width:0,height:0})}}else if(y==="text"){const A=Date.now().toString();s(Se({id:A,type:"text",x:T,y:N,text:"Text",fontSize:O.text.fontSize,fontColor:O.text.fontColor})),s(Me("pointer")),s(He([A])),ge(A),Ee("Text"),nt({x:T,y:N}),Oe(!0)}else if(y==="eraser"){const A=U(T,N);A&&s(oa(A.id))}else s(He([])),F(!0),X({x:T,y:N}),oe({x:T,y:N}),y==="pencil"&&he([{x:T,y:N}])},Le=o=>{const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top;if(Re){s(ia({x:w-rt.x,y:_-rt.y}));return}if($e){const A=Xe.y-_,B=Xe.initialZoom*(1+A*.005);s(aa(B));return}if(x)return;const{x:T,y:N}=ae(w,_);if(St&&se){const A=T-se.startX,z=N-se.startY;Dt({...se,width:A,height:z});return}if(pe&&k.length>0){const A=T-j.x,z=N-j.y,B=[];k.forEach(Y=>{const L=Te[Y];if(!L)return;let H={};if(L.type==="rectangle")H={x:(L.x??0)+A,y:(L.y??0)+z};else if(L.type==="circle")H={centerX:(L.centerX??0)+A,centerY:(L.centerY??0)+z};else if(L.type==="pencil"){const q=L.points||[];if(q.length===0)return;H={points:q.map(K=>({x:K.x+A,y:K.y+z}))}}else L.type==="text"?H={x:(L.x??0)+A,y:(L.y??0)+z}:L.type==="triangle"||L.type==="diamond"||L.type==="hexagon"||L.type==="octagon"?H={x:(L.x??0)+A,y:(L.y??0)+z}:L.type==="star"||L.type==="heart"?H={centerX:(L.centerX??0)+A,centerY:(L.centerY??0)+z}:L.type==="arrow"?H={startX:(L.startX??0)+A,startY:(L.startY??0)+z,endX:(L.endX??0)+A,endY:(L.endY??0)+z}:L.type==="image"&&(H={x:(L.x??0)+A,y:(L.y??0)+z});B.push({id:Y,updates:H})}),B.length>0&&s(oo(B));return}if(xt&&It&&Nt&&me){let A={};const z=T-Nt.x,B=N-Nt.y,Y=It;if(Y.type==="arrow")me==="start"?A={startX:(Y.startX??0)+z,startY:(Y.startY??0)+B}:me==="end"&&(A={endX:(Y.endX??0)+z,endY:(Y.endY??0)+B});else if(Y.type==="circle"||Y.type==="star"||Y.type==="heart"){const L=Y.radius||Y.size||0,H=me.includes("e"),q=me.includes("s"),K=me.includes("w"),ie=me.includes("n");let ve=0;H&&(ve+=z),K&&(ve-=z),q&&(ve+=B),ie&&(ve-=B);const Yt=Math.max(5,L+ve);Y.type==="circle"?A={radius:Yt}:A={size:Yt}}else if(Y.type==="pencil"&&Y.points){const L=Z(Y);if(L){const{x:H,y:q,w:K,h:ie}=L;let ve=H,Yt=q,Br=K,Ur=ie;me.includes("e")&&(Br=Math.max(5,K+z)),me.includes("w")&&(Br=Math.max(5,K-z),ve=H+z),me.includes("s")&&(Ur=Math.max(5,ie+B)),me.includes("n")&&(Ur=Math.max(5,ie-B),Yt=q+B);const os=Br/K,is=Ur/ie;A={points:Y.points.map(go=>({x:ve+(go.x-H)*os,y:Yt+(go.y-q)*is}))}}}else{let L=Y.x??0,H=Y.y??0,q=Y.width??0,K=Y.height??0;if(me.includes("e")&&(q=Math.max(5,(Y.width??0)+z)),me.includes("w")){const ie=(Y.width??0)-z;ie>5&&(q=ie,L=(Y.x??0)+z)}if(me.includes("s")&&(K=Math.max(5,(Y.height??0)+B)),me.includes("n")){const ie=(Y.height??0)-B;ie>5&&(K=ie,H=(Y.y??0)+B)}A={x:L,y:H,width:q,height:K}}Object.keys(A).length>0&&s(Zt({id:Y.id,updates:A}));return}D&&(oe({x:T,y:N}),y==="pencil"&&he(A=>[...A,{x:T,y:N}]))},Ge=()=>{if(Re||$e){Ne(!1),Fe(!1);return}if(x){we(!1),F(!1);return}if(pe&&we(!1),St&&se){const o=se.width>0?se.startX:se.startX+se.width,f=se.height>0?se.startY:se.startY+se.height,g=Math.abs(se.width),w=Math.abs(se.height),_=[];E.forEach(T=>{const N=Z(T);N&&N.x<o+g&&N.x+N.w>o&&N.y<f+w&&N.y+N.h>f&&_.push(T.id)}),_.length>0&&s(He(_))}if(F(!1),we(!1),tr(!1),nr(!1),Dt(null),Et(null),rr(null),he([]),X({x:0,y:0}),Pe({}),At(null),Ne(!1),!!D){if(y==="pointer")ce();else if(y==="rectangle"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"rectangle",x:o,y:f,width:g,height:w,strokeColor:O.rectangle.strokeColor,fillColor:O.rectangle.fillColor,lineWidth:O.rectangle.lineWidth}))}else if(y==="circle"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"circle",centerX:o,centerY:f,radius:g,strokeColor:O.circle.strokeColor,fillColor:O.circle.fillColor,lineWidth:O.circle.lineWidth}))}else if(y==="pencil")ue.length>1&&s(Se({id:Date.now().toString(),type:"pencil",points:[...ue],strokeColor:O.pencil.strokeColor,lineWidth:O.pencil.lineWidth})),he([]);else if(y==="triangle"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"triangle",x:o,y:f,width:g,height:w,strokeColor:O.triangle.strokeColor,fillColor:O.triangle.fillColor,lineWidth:O.triangle.lineWidth}))}else if(y==="diamond"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"diamond",x:o,y:f,width:g,height:w,strokeColor:O.diamond.strokeColor,fillColor:O.diamond.fillColor,lineWidth:O.diamond.lineWidth}))}else if(y==="star"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"star",centerX:o,centerY:f,size:g,strokeColor:O.star.strokeColor,fillColor:O.star.fillColor,lineWidth:O.star.lineWidth}))}else if(y==="heart"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"heart",centerX:o,centerY:f,size:g,strokeColor:O.heart.strokeColor,fillColor:O.heart.fillColor,lineWidth:O.heart.lineWidth}))}else if(y==="hexagon"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"hexagon",x:o,y:f,width:g,height:w,strokeColor:O.hexagon.strokeColor,fillColor:O.hexagon.fillColor,lineWidth:O.hexagon.lineWidth}))}else if(y==="octagon"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"octagon",x:o,y:f,width:g,height:w,strokeColor:O.octagon.strokeColor,fillColor:O.octagon.fillColor,lineWidth:O.octagon.lineWidth}))}else if(y==="arrow"){const o=M.x-j.x,f=M.y-j.y;Math.sqrt(o*o+f*f)>5&&s(Se({id:Date.now().toString(),type:"arrow",startX:j.x,startY:j.y,endX:M.x,endY:M.y,strokeColor:O.arrow.strokeColor,fillColor:O.arrow.fillColor,lineWidth:O.arrow.lineWidth}))}F(!1)}},ir=o=>{ke&&o.preventDefault()},We=(o,f,g)=>{ge(o.id),Ee(o.text||""),nt({x:o.x||f,y:o.y||g}),De.current=o.text||"",Oe(!0)},ts=()=>{if(ke)return Re?"grabbing":$e?"ns-resize":"grab";if(x)return"default";if(k.length===1&&!D&&y==="pointer"){const o=E.find(f=>f.id===k[0]);if(o){const f=J(M.x,M.y,o,C.zoom);if(f)return f==="n"||f==="s"?"ns-resize":f==="e"||f==="w"?"ew-resize":f==="ne"||f==="sw"?"nesw-resize":f==="nw"||f==="se"?"nwse-resize":"pointer"}}return"default"},[po,vo]=P.useState({propTools:!1,lockIndicator:!1});P.useEffect(()=>{const o=()=>{if(window.innerWidth<=768){vo({propTools:!1,lockIndicator:!1});return}const f=document.getElementById("wb-canvas-container");if(!f)return;const g=f.querySelector(".wb-toolbar"),w=f.querySelector(".wb-prop-tools"),_=f.querySelector(".wb-lock-indicator");let T=!1,N=!1;if(g){const A=g.getBoundingClientRect();if(w){const z=w.getBoundingClientRect();A.bottom>z.top-10&&(T=!0)}if(_){const z=_.getBoundingClientRect();A.top<z.bottom+10&&(N=!0)}}vo({propTools:T,lockIndicator:N})};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[y,x,k]);const yo=async(o,f,g)=>{try{let w="";c?w=await c(o):w=URL.createObjectURL(o);const _=new Image;_.onload=()=>{const T=_.width/_.height,N=200,A=N/T;s(Se({id:Date.now().toString(),type:"image",x:f-N/2,y:g-A/2,width:N,height:A,src:w}))},_.src=w}catch(w){console.error("Failed to upload image:",w)}};P.useEffect(()=>{const o=f=>{if(!(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")&&!x&&f.clipboardData&&f.clipboardData.files.length>0){const g=f.clipboardData.files[0];if(g.type.startsWith("image/")){f.preventDefault();const w=b.current;if(w){const _=w.getBoundingClientRect(),T=_.width/2,N=_.height/2,{x:A,y:z}=ae(T,N);yo(g,A,z)}}}};return window.addEventListener("paste",o),()=>window.removeEventListener("paste",o)},[x,ae,c,s]);const rs=o=>{o.preventDefault()},ns=o=>{if(o.preventDefault(),!x&&o.dataTransfer.files&&o.dataTransfer.files.length>0){const f=o.dataTransfer.files[0];if(f.type.startsWith("image/")){const g=b.current;if(g){const w=g.getBoundingClientRect(),_=o.clientX-w.left,T=o.clientY-w.top,{x:N,y:A}=ae(_,T);yo(f,N,A)}}}};return h.jsxs("div",{id:"wb-canvas-container",style:{backgroundColor:"#fff",position:"relative",width:"100%",height:"100%"},onDragOver:rs,onDrop:ns,children:[h.jsx("canvas",{ref:b,onMouseDown:de,onMouseMove:Le,onMouseUp:Ge,onMouseLeave:Ge,onDoubleClick:o=>{if(x)return;const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top,{x:T,y:N}=ae(w,_),A=U(T,N);A&&A.type==="text"&&We(A,T,N)},onContextMenu:ir,style:{cursor:ts()}}),x&&h.jsx(Va,{text:r||e&&((mo=e.lock)==null?void 0:mo.text)||I.text,shifted:po.lockIndicator}),Ae&&h.jsx("input",{type:"text",value:V,onChange:o=>{const f=o.target.value;Ee(f),Fr(f)},onKeyDown:o=>{o.key==="Enter"&&V.trim()?($&&(s(Zt({id:$,updates:{text:V}})),De.current=V),Oe(!1),Ee(""),ge(null)):o.key==="Escape"&&(Oe(!1),Ee(""),ge(null))},onBlur:()=>{V.trim()&&$&&(s(Zt({id:$,updates:{text:V}})),De.current=V),Oe(!1),Ee(""),ge(null)},onMouseDown:o=>o.stopPropagation(),autoFocus:!0,style:{position:"absolute",left:Ie.x*C.zoom+C.panX,top:Ie.y*C.zoom+C.panY,fontSize:O.text.fontSize*C.zoom,color:O.text.fontColor,background:"white",border:"2px solid #0066cc",outline:"none",fontFamily:"sans-serif",minWidth:"150px",padding:"4px 8px",zIndex:1e3,boxShadow:"0 2px 8px rgba(0,0,0,0.2)"}}),h.jsx(Qa,{onFitToView:d,onExport:Xr,onToggleGrid:R}),h.jsx(Ja,{mode:l,onImageUpload:c}),h.jsx(Za,{shifted:po.propTools}),ut.visible&&h.jsx(ga,{})]})});$r.displayName="InternalWhiteboard";class es extends P.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(t){return{hasError:!0}}componentDidCatch(t,r){console.error("Whiteboard Error:",t,r)}render(){return this.state.hasError?h.jsxs("div",{style:{padding:"20px",textAlign:"center",background:"#fff1f0",border:"1px solid #ffa39e",borderRadius:"4px",height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"},children:[h.jsx("h3",{children:"Something went wrong in Whiteboard"}),h.jsx("button",{onClick:()=>this.setState({hasError:!1}),style:{marginTop:"10px",padding:"8px 16px",cursor:"pointer",background:"#fff",border:"1px solid #d9d9d9",borderRadius:"2px"},children:"Try Again"})]}):this.props.children}}const ho=P.forwardRef((e,t)=>{const{store:r,onAction:n,...i}=e,a=P.useRef(n);P.useEffect(()=>{a.current=n},[n]);const l=P.useMemo(()=>r??Vr({actionHandlerRef:a}),[r]);return h.jsx(es,{children:h.jsx(Uo,{store:l,children:h.jsx(Jo,{children:h.jsx($r,{ref:t,...i})})})})});ho.displayName="Whiteboard",Ce.WhiteboardComponent=$r,Ce.createWhiteboardStore=Vr,Ce.default=ho,Ce.store=ma,Ce.whiteboardActions=da,Ce.whiteboardReducer=ao,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
99
+ (See https://redux.js.org/faq/organizing-state#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)`)}}),F.warnIfExceeded()),D}}}}function Jt(e){return typeof e=="boolean"}function Vi(){return function(t){return $i(t)}}function $i(e){e===void 0&&(e={});var t=e.thunk,r=t===void 0?!0:t,n=e.immutableCheck,i=n===void 0?!0:n,a=e.serializableCheck,l=a===void 0?!0:a,u=e.actionCreatorCheck,p=u===void 0?!0:u,c=new Ri;if(r&&(Jt(r)?c.push(Mr):c.push(Mr.withExtraArgument(r.extraArgument))),process.env.NODE_ENV!=="production"){if(i){var v={};Jt(i)||(v=i),c.unshift(Wi(v))}if(l){var b={};Jt(l)||(b=l),c.push(Yi(b))}if(p){var s={};Jt(p)||(s=p),c.unshift(Mi(s))}}return c}var Ir=process.env.NODE_ENV==="production";function Fi(e){var t=Vi(),r=e||{},n=r.reducer,i=n===void 0?void 0:n,a=r.middleware,l=a===void 0?t():a,u=r.devTools,p=u===void 0?!0:u,c=r.preloadedState,v=c===void 0?void 0:c,b=r.enhancers,s=b===void 0?void 0:b,S;if(typeof i=="function")S=i;else if(Bn(i))S=gi(i);else throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');var m=l;if(typeof m=="function"&&(m=m(t),!Ir&&!Array.isArray(m)))throw new Error("when using a middleware builder function, an array of middleware must be returned");if(!Ir&&m.some(function(I){return typeof I!="function"}))throw new Error("each middleware provided to configureStore must be a function");var y=bi.apply(void 0,m),E=Kt;p&&(E=ji(et({trace:!Ir},typeof p=="object"&&p)));var C=new Ni(y),O=C;Array.isArray(s)?O=wt([y],s):typeof s=="function"&&(O=s(C));var k=E.apply(void 0,O);return Wn(S,v,k)}function Qn(e){var t={},r=[],n,i={addCase:function(a,l){if(process.env.NODE_ENV!=="production"){if(r.length>0)throw new Error("`builder.addCase` should only be called before calling `builder.addMatcher`");if(n)throw new Error("`builder.addCase` should only be called before calling `builder.addDefaultCase`")}var u=typeof a=="string"?a:a.type;if(!u)throw new Error("`builder.addCase` cannot be called with an empty action type");if(u in t)throw new Error("`builder.addCase` cannot be called with two reducers for the same action type");return t[u]=l,i},addMatcher:function(a,l){if(process.env.NODE_ENV!=="production"&&n)throw new Error("`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");return r.push({matcher:a,reducer:l}),i},addDefaultCase:function(a){if(process.env.NODE_ENV!=="production"&&n)throw new Error("`builder.addDefaultCase` can only be called once");return n=a,i}};return e(i),[t,r,n]}function Xi(e){return typeof e=="function"}var eo=!1;function Bi(e,t,r,n){r===void 0&&(r=[]),process.env.NODE_ENV!=="production"&&typeof t=="object"&&(eo||(eo=!0,console.warn("The object notation for `createReducer` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer")));var i=typeof t=="function"?Qn(t):[t,r,n],a=i[0],l=i[1],u=i[2],p;if(Xi(e))p=function(){return Nr(e())};else{var c=Nr(e);p=function(){return c}}function v(b,s){b===void 0&&(b=p());var S=wt([a[s.type]],l.filter(function(m){var y=m.matcher;return y(s)}).map(function(m){var y=m.reducer;return y}));return S.filter(function(m){return!!m}).length===0&&(S=[u]),S.reduce(function(m,y){if(y)if(Je(m)){var E=m,C=y(E,s);return C===void 0?m:C}else{if(Ue(m))return An(m,function(O){return y(O,s)});var C=y(m,s);if(C===void 0){if(m===null)return m;throw Error("A case reducer on a non-draftable value must not return undefined")}return C}return m},b)}return v.getInitialState=p,v}var to=!1;function Ui(e,t){return e+"/"+t}function Hi(e){var t=e.name;typeof process<"u"&&process.env.NODE_ENV==="development"&&e.initialState===void 0&&console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");var r=typeof e.initialState=="function"?e.initialState:Nr(e.initialState),n=e.reducers||{},i=Object.keys(n),a={},l={},u={};i.forEach(function(v){var b=n[v],s=Ui(t,v),S,m;"reducer"in b?(S=b.reducer,m=b.prepare):S=b,a[v]=S,l[s]=S,u[v]=m?tt(s,m):tt(s)});function p(){process.env.NODE_ENV!=="production"&&typeof e.extraReducers=="object"&&(to||(to=!0,console.warn("The object notation for `createSlice.extraReducers` is deprecated, and will be removed in RTK 2.0. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice")));var v=typeof e.extraReducers=="function"?Qn(e.extraReducers):[e.extraReducers],b=v[0],s=b===void 0?{}:b,S=v[1],m=S===void 0?[]:S,y=v[2],E=y===void 0?void 0:y,C=et(et({},s),l);return Bi(r,function(O){for(var k in C)O.addCase(k,C[k]);for(var I=0,x=m;I<x.length;I++){var D=x[I];O.addMatcher(D.matcher,D.reducer)}E&&O.addDefaultCase(E)})}var c;return{name:t,reducer:function(v,b){return c||(c=p()),c(v,b)},actions:u,caseReducers:a,getInitialState:function(){return c||(c=p()),c.getInitialState()}}}var qi="ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW",Gi=function(e){e===void 0&&(e=21);for(var t="",r=e;r--;)t+=qi[Math.random()*64|0];return t},Ki=["name","message","stack","code"],Dr=(function(){function e(t,r){this.payload=t,this.meta=r}return e})(),ro=(function(){function e(t,r){this.payload=t,this.meta=r}return e})(),Ji=function(e){if(typeof e=="object"&&e!==null){for(var t={},r=0,n=Ki;r<n.length;r++){var i=n[r];typeof e[i]=="string"&&(t[i]=e[i])}return t}return{message:String(e)}};(function(){function e(t,r,n){var i=tt(t+"/fulfilled",function(v,b,s,S){return{payload:v,meta:Rr(et({},S||{}),{arg:s,requestId:b,requestStatus:"fulfilled"})}}),a=tt(t+"/pending",function(v,b,s){return{payload:void 0,meta:Rr(et({},s||{}),{arg:b,requestId:v,requestStatus:"pending"})}}),l=tt(t+"/rejected",function(v,b,s,S,m){return{payload:S,error:(n&&n.serializeError||Ji)(v||"Rejected"),meta:Rr(et({},m||{}),{arg:s,requestId:b,rejectedWithValue:!!S,requestStatus:"rejected",aborted:(v==null?void 0:v.name)==="AbortError",condition:(v==null?void 0:v.name)==="ConditionError"})}}),u=!1,p=typeof AbortController<"u"?AbortController:(function(){function v(){this.signal={aborted:!1,addEventListener:function(){},dispatchEvent:function(){return!1},onabort:function(){},removeEventListener:function(){},reason:void 0,throwIfAborted:function(){}}}return v.prototype.abort=function(){process.env.NODE_ENV!=="production"&&(u||(u=!0,console.info("This platform does not implement AbortController. \nIf you want to use the AbortController to react to `abort` events, please consider importing a polyfill like 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'.")))},v})();function c(v){return function(b,s,S){var m=n!=null&&n.idGenerator?n.idGenerator(v):Gi(),y=new p,E;function C(k){E=k,y.abort()}var O=(function(){return Oi(this,null,function(){var k,I,x,D,F,j,X;return wi(this,function(M){switch(M.label){case 0:return M.trys.push([0,4,,5]),D=(k=n==null?void 0:n.condition)==null?void 0:k.call(n,v,{getState:s,extra:S}),Qi(D)?[4,D]:[3,2];case 1:D=M.sent(),M.label=2;case 2:if(D===!1||y.signal.aborted)throw{name:"ConditionError",message:"Aborted due to condition callback returning false."};return F=new Promise(function(oe,ue){return y.signal.addEventListener("abort",function(){return ue({name:"AbortError",message:E||"Aborted"})})}),b(a(m,v,(I=n==null?void 0:n.getPendingMeta)==null?void 0:I.call(n,{requestId:m,arg:v},{getState:s,extra:S}))),[4,Promise.race([F,Promise.resolve(r(v,{dispatch:b,getState:s,extra:S,requestId:m,signal:y.signal,abort:C,rejectWithValue:function(oe,ue){return new Dr(oe,ue)},fulfillWithValue:function(oe,ue){return new ro(oe,ue)}})).then(function(oe){if(oe instanceof Dr)throw oe;return oe instanceof ro?i(oe.payload,m,v,oe.meta):i(oe,m,v)})])];case 3:return x=M.sent(),[3,5];case 4:return j=M.sent(),x=j instanceof Dr?l(null,m,v,j.payload,j.meta):l(j,m,v),[3,5];case 5:return X=n&&!n.dispatchConditionRejection&&l.match(x)&&x.meta.condition,X||b(x),[2,x]}})})})();return Object.assign(O,{abort:C,requestId:m,arg:v,unwrap:function(){return O.then(Zi)}})}}return Object.assign(c,{pending:a,rejected:l,fulfilled:i,typePrefix:t})}return e.withTypes=function(){return e},e})();function Zi(e){if(e.meta&&e.meta.rejectedWithValue)throw e.payload;if(e.error)throw e.error;return e.payload}function Qi(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}var zr="listenerMiddleware";tt(zr+"/add"),tt(zr+"/removeAll"),tt(zr+"/remove");var no;typeof queueMicrotask=="function"&&queueMicrotask.bind(typeof window<"u"?window:typeof global<"u"?global:globalThis),ni();const ea={grid:{size:20,color:"#ccc",enabled:!0},toolbar:{selectedTool:"pointer"},toolProperties:{pencil:{strokeColor:"#000000",lineWidth:4},rectangle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},circle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},triangle:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},diamond:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},star:{strokeColor:"#000000",fillColor:"#ffff00",lineWidth:2},heart:{strokeColor:"#000000",fillColor:"#ff6b6b",lineWidth:2},hexagon:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},octagon:{strokeColor:"#000000",fillColor:"#ffffff",lineWidth:2},arrow:{strokeColor:"#000000",fillColor:"#000000",lineWidth:2},text:{fontSize:16,fontColor:"#000000"}},elements:[],selectedElementIds:[],viewport:{panX:0,panY:0,zoom:1},watermark:{text:"Nines Studios",url:"https://github.com/huzeyfecoskun",visible:!0},lock:{isLocked:!1,text:"Whiteboard drawing is only for moderator"}};function ta(e){const t=[],r=new Set;for(const n of e){const i=n==null?void 0:n.id;if(i==null){t.push(n);continue}r.has(i)||(r.add(i),t.push(n))}return t}const Lr=Hi({name:"whiteboard",initialState:ea,reducers:{toggleGrid(e){e.grid.enabled=!e.grid.enabled},setGridSize(e,t){e.grid.size=t.payload},setGridColor(e,t){e.grid.color=t.payload},setSelectedTool(e,t){e.toolbar.selectedTool=t.payload},setToolProperty(e,t){const{tool:r,property:n,value:i}=t.payload;e.toolProperties[r]&&(e.toolProperties[r][n]=i)},addElement(e,t){const r=t.payload,n=r==null?void 0:r.id;n!=null&&e.elements.some(a=>(a==null?void 0:a.id)===n)||e.elements.push(r)},updateElement(e,t){const{id:r,updates:n}=t.payload,i=e.elements.findIndex(a=>a.id===r);i!==-1&&(e.elements[i]={...e.elements[i],...n})},updateElements(e,t){t.payload.forEach(({id:n,updates:i})=>{const a=e.elements.findIndex(l=>l.id===n);a!==-1&&(e.elements[a]={...e.elements[a],...i})})},removeElement(e,t){const r=t.payload;e.elements=e.elements.filter(n=>n.id!==r),e.selectedElementIds=e.selectedElementIds.filter(n=>n!==r)},setSelectedElements(e,t){e.selectedElementIds=t.payload},clearElements(e){e.elements=[],e.selectedElementIds=[]},setElements(e,t){const r=Array.isArray(t.payload)?t.payload:[];e.elements=ta(r),e.selectedElementIds=[]},setPan(e,t){e.viewport.panX=t.payload.x,e.viewport.panY=t.payload.y},setZoom(e,t){e.viewport.zoom=Math.max(.1,Math.min(5,t.payload))},resetViewport(e){e.viewport.panX=0,e.viewport.panY=0,e.viewport.zoom=1},bringToFront(e,t){const r=t.payload,n=e.elements.findIndex(i=>i.id===r);if(n!==-1&&n<e.elements.length-1){const[i]=e.elements.splice(n,1);e.elements.push(i)}},sendToBack(e,t){const r=t.payload,n=e.elements.findIndex(i=>i.id===r);if(n>0){const[i]=e.elements.splice(n,1);e.elements.unshift(i)}},fitToView(e,t){const{canvasWidth:r,canvasHeight:n,padding:i=50}=t.payload,a=e.elements;if(a.length===0){e.viewport.panX=0,e.viewport.panY=0,e.viewport.zoom=1;return}let l=1/0,u=1/0,p=-1/0,c=-1/0;if(a.forEach(x=>{const D=F=>F??0;if(x.type==="rectangle"){const F=D(x.x),j=D(x.y),X=D(x.width),M=D(x.height);l=Math.min(l,F),u=Math.min(u,j),p=Math.max(p,F+X),c=Math.max(c,j+M)}else if(x.type==="circle"){const F=D(x.centerX),j=D(x.centerY),X=D(x.radius);l=Math.min(l,F-X),u=Math.min(u,j-X),p=Math.max(p,F+X),c=Math.max(c,j+X)}else if(x.type==="pencil"&&x.points&&x.points.length>0)x.points.forEach(F=>{l=Math.min(l,F.x),u=Math.min(u,F.y),p=Math.max(p,F.x),c=Math.max(c,F.y)});else if(x.type==="triangle"||x.type==="diamond"||x.type==="hexagon"||x.type==="octagon"){const F=D(x.x),j=D(x.y),X=D(x.width),M=D(x.height);l=Math.min(l,F),u=Math.min(u,j),p=Math.max(p,F+X),c=Math.max(c,j+M)}else if(x.type==="star"||x.type==="heart"){const F=D(x.centerX),j=D(x.centerY),X=D(x.size);l=Math.min(l,F-X),u=Math.min(u,j-X),p=Math.max(p,F+X),c=Math.max(c,j+X)}else if(x.type==="arrow"){const F=D(x.startX),j=D(x.startY),X=D(x.endX),M=D(x.endY);l=Math.min(l,F,X),u=Math.min(u,j,M),p=Math.max(p,F,X),c=Math.max(c,j,M)}}),l===1/0)return;const v=p-l,b=c-u;if(v<=0||b<=0)return;const s=r-i*2,S=n-i*2,m=s/v,y=S/b,E=Math.min(m,y,5),C=(l+p)/2,O=(u+c)/2,k=r/2-C*E,I=n/2-O*E;e.viewport.zoom=Math.max(.1,E),e.viewport.panX=k,e.viewport.panY=I},setLocked(e,t){e.lock.isLocked=t.payload,t.payload&&(e.toolbar.selectedTool="pointer",e.selectedElementIds=[])},setWatermarkEnabled(e,t){e.watermark.visible=t.payload},setWatermarkText(e,t){e.watermark.text=t.payload}}}),{toggleGrid:ra,setGridSize:cs,setGridColor:ls,setSelectedTool:Me,setToolProperty:na,addElement:Se,updateElement:Zt,updateElements:oo,removeElement:oa,setSelectedElements:He,clearElements:Wr,setElements:Yr,setPan:ia,setZoom:aa,resetViewport:us,fitToView:sa,bringToFront:ca,sendToBack:la,setLocked:io,setWatermarkEnabled:ua,setWatermarkText:fa}=Lr.actions,da=Lr.actions,ao=Lr.reducer,ha=new Set(["rectangle","circle","pencil","triangle","diamond","star","heart","hexagon","octagon","arrow","image","text"]),pa=new Set(["strokeColor","fillColor","lineWidth","fontSize","fontColor","textColor"]),va=e=>{var t,r;if(!e||typeof e.type!="string"||e.type.startsWith("@@redux/"))return!1;if(e.type==="whiteboard/addElement"){const n=(t=e==null?void 0:e.payload)==null?void 0:t.type;return typeof n=="string"&&ha.has(n)}if(e.type==="whiteboard/removeElement"||e.type==="whiteboard/clearElements"||e.type==="whiteboard/bringToFront"||e.type==="whiteboard/sendToBack")return!0;if(e.type==="whiteboard/setToolProperty"){const{tool:n,property:i}=(e==null?void 0:e.payload)??{};return typeof n!="string"||typeof i!="string"?!1:pa.has(i)}if(e.type==="whiteboard/updateElement")return so((r=e==null?void 0:e.payload)==null?void 0:r.updates);if(e.type==="whiteboard/updateElements"){const n=e==null?void 0:e.payload;return Array.isArray(n)?n.some(i=>so(i.updates)):!1}return!1},so=e=>{if(!e||typeof e!="object")return!1;const t=r=>Object.prototype.hasOwnProperty.call(e,r);return!!(t("text")||t("fontSize")||t("fontColor")||t("textColor")||t("strokeColor")||t("fillColor")||t("lineWidth")||t("x")||t("y")||t("width")||t("height")||t("centerX")||t("centerY")||t("radius")||t("size")||t("startX")||t("startY")||t("endX")||t("endY")||t("points")||t("src"))},ya=e=>t=>r=>n=>{var a;const i=r(n);return!((a=n.meta)!=null&&a.fromRemote)&&e&&e.current&&va(n)&&e.current(n,t.getState()),i},Vr=({preloadedState:e,actionHandlerRef:t}={})=>Fi({reducer:{whiteboard:ao},middleware:r=>r().concat(ya(t)),preloadedState:e}),ma=Vr(),ga=()=>{const e=xe(t=>t.whiteboard.watermark);return h.jsx("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",children:h.jsx("div",{className:"wb-watermark",children:e.text})})};var co={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},lo=P.createContext&&P.createContext(co),ba=["attr","size","title"];function wa(e,t){if(e==null)return{};var r=xa(e,t),n,i;if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(i=0;i<a.length;i++)n=a[i],!(t.indexOf(n)>=0)&&Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n])}return r}function xa(e,t){if(e==null)return{};var r={};for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){if(t.indexOf(n)>=0)continue;r[n]=e[n]}return r}function Qt(){return Qt=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Qt.apply(this,arguments)}function uo(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),r.push.apply(r,n)}return r}function er(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?uo(Object(r),!0).forEach(function(n){Ea(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):uo(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function Ea(e,t,r){return t=Sa(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Sa(e){var t=Ca(e,"string");return typeof t=="symbol"?t:t+""}function Ca(e,t){if(typeof e!="object"||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var n=r.call(e,t);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function fo(e){return e&&e.map((t,r)=>P.createElement(t.tag,er({key:r},t.attr),fo(t.child)))}function fe(e){return t=>P.createElement(_a,Qt({attr:er({},e.attr)},t),fo(e.child))}function _a(e){var t=r=>{var{attr:n,size:i,title:a}=e,l=wa(e,ba),u=i||r.size||"1em",p;return r.className&&(p=r.className),e.className&&(p=(p?p+" ":"")+e.className),P.createElement("svg",Qt({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,n,l,{className:p,style:er(er({color:e.color||r.color},r.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),a&&P.createElement("title",null,a),e.children)};return lo!==void 0?P.createElement(lo.Consumer,null,r=>t(r)):t(co)}function Oa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M416 32H32A32 32 0 0 0 0 64v384a32 32 0 0 0 32 32h384a32 32 0 0 0 32-32V64a32 32 0 0 0-32-32zm-32 64v128H256V96zm-192 0v128H64V96zM64 416V288h128v128zm192 0V288h128v128z"},child:[]}]})(e)}function ja(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8z"},child:[]}]})(e)}function Ta(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M497.941 273.941c18.745-18.745 18.745-49.137 0-67.882l-160-160c-18.745-18.745-49.136-18.746-67.883 0l-256 256c-18.745 18.745-18.745 49.137 0 67.882l96 96A48.004 48.004 0 0 0 144 480h356c6.627 0 12-5.373 12-12v-40c0-6.627-5.373-12-12-12H355.883l142.058-142.059zm-302.627-62.627l137.373 137.373L265.373 416H150.628l-80-80 124.686-124.686z"},child:[]}]})(e)}function Pa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M0 180V56c0-13.3 10.7-24 24-24h124c6.6 0 12 5.4 12 12v40c0 6.6-5.4 12-12 12H64v84c0 6.6-5.4 12-12 12H12c-6.6 0-12-5.4-12-12zM288 44v40c0 6.6 5.4 12 12 12h84v84c0 6.6 5.4 12 12 12h40c6.6 0 12-5.4 12-12V56c0-13.3-10.7-24-24-24H300c-6.6 0-12 5.4-12 12zm148 276h-40c-6.6 0-12 5.4-12 12v84h-84c-6.6 0-12 5.4-12 12v40c0 6.6 5.4 12 12 12h124c13.3 0 24-10.7 24-24V332c0-6.6-5.4-12-12-12zM160 468v-40c0-6.6-5.4-12-12-12H64v-84c0-6.6-5.4-12-12-12H12c-6.6 0-12 5.4-12 12v124c0 13.3 10.7 24 24 24h124c6.6 0 12-5.4 12-12z"},child:[]}]})(e)}function ka(e){return fe({attr:{viewBox:"0 0 496 512"},child:[{tag:"path",attr:{d:"M336.5 160C322 70.7 287.8 8 248 8s-74 62.7-88.5 152h177zM152 256c0 22.2 1.2 43.5 3.3 64h185.3c2.1-20.5 3.3-41.8 3.3-64s-1.2-43.5-3.3-64H155.3c-2.1 20.5-3.3 41.8-3.3 64zm324.7-96c-28.6-67.9-86.5-120.4-158-141.6 24.4 33.8 41.2 84.7 50 141.6h108zM177.2 18.4C105.8 39.6 47.8 92.1 19.3 160h108c8.7-56.9 25.5-107.8 49.9-141.6zM487.4 192H372.7c2.1 21 3.3 42.5 3.3 64s-1.2 43-3.3 64h114.6c5.5-20.5 8.6-41.8 8.6-64s-3.1-43.5-8.5-64zM120 256c0-21.5 1.2-43 3.3-64H8.6C3.2 212.5 0 233.8 0 256s3.2 43.5 8.6 64h114.6c-2-21-3.2-42.5-3.2-64zm39.5 96c14.5 89.3 48.7 152 88.5 152s74-62.7 88.5-152h-177zm159.3 141.6c71.4-21.2 129.4-73.7 158-141.6h-108c-8.8 56.9-25.6 107.8-50 141.6zM19.3 352c28.6 67.9 86.5 120.4 158 141.6-24.4-33.8-41.2-84.7-50-141.6h-108z"},child:[]}]})(e)}function Ma(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"},child:[]}]})(e)}function Ra(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"},child:[]}]})(e)}function Na(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M400 224h-24v-72C376 68.2 307.8 0 224 0S72 68.2 72 152v72H48c-26.5 0-48 21.5-48 48v192c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V272c0-26.5-21.5-48-48-48zm-104 0H152v-72c0-39.7 32.3-72 72-72s72 32.3 72 72v72z"},child:[]}]})(e)}function Aa(e){return fe({attr:{viewBox:"0 0 320 512"},child:[{tag:"path",attr:{d:"M302.189 329.126H196.105l55.831 135.993c3.889 9.428-.555 19.999-9.444 23.999l-49.165 21.427c-9.165 4-19.443-.571-23.332-9.714l-53.053-129.136-86.664 89.138C18.729 472.71 0 463.554 0 447.977V18.299C0 1.899 19.921-6.096 30.277 5.443l284.412 292.542c11.472 11.179 3.007 31.141-12.5 31.141z"},child:[]}]})(e)}function Ia(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M497.9 142.1l-46.1 46.1c-4.7 4.7-12.3 4.7-17 0l-111-111c-4.7-4.7-4.7-12.3 0-17l46.1-46.1c18.7-18.7 49.1-18.7 67.9 0l60.1 60.1c18.8 18.7 18.8 49.1 0 67.9zM284.2 99.8L21.6 362.4.4 483.9c-2.9 16.4 11.4 30.6 27.8 27.8l121.5-21.3 262.6-262.6c4.7-4.7 4.7-12.3 0-17l-111-111c-4.8-4.7-12.4-4.7-17.1 0zM124.1 339.9c-5.5-5.5-5.5-14.3 0-19.8l154-154c5.5-5.5 14.3-5.5 19.8 0s5.5 14.3 0 19.8l-154 154c-5.5 5.5-14.3 5.5-19.8 0zM88 424h48v36.3l-64.5 11.3-31.1-31.1L51.7 376H88v48z"},child:[]}]})(e)}function Da(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"},child:[]}]})(e)}function za(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M433.941 129.941l-83.882-83.882A48 48 0 0 0 316.118 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V163.882a48 48 0 0 0-14.059-33.941zM224 416c-35.346 0-64-28.654-64-64 0-35.346 28.654-64 64-64s64 28.654 64 64c0 35.346-28.654 64-64 64zm96-304.52V212c0 6.627-5.373 12-12 12H76c-6.627 0-12-5.373-12-12V108c0-6.627 5.373-12 12-12h228.52c3.183 0 6.235 1.264 8.485 3.515l3.48 3.48A11.996 11.996 0 0 1 320 111.48z"},child:[]}]})(e)}function La(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48z"},child:[]}]})(e)}function Wa(e){return fe({attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M259.3 17.8L194 150.2 47.9 171.5c-26.2 3.8-36.7 36.1-17.7 54.6l105.7 103-25 145.5c-4.5 26.3 23.2 46 46.4 33.7L288 439.6l130.7 68.7c23.2 12.2 50.9-7.4 46.4-33.7l-25-145.5 105.7-103c19-18.5 8.5-50.8-17.7-54.6L382 150.2 316.7 17.8c-11.7-23.6-45.6-23.9-57.4 0z"},child:[]}]})(e)}function Ya(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z"},child:[]}]})(e)}const Va=({text:e,shifted:t})=>h.jsxs("div",{className:`wb-lock-indicator ${t?"wb-shifted":""}`,children:[h.jsx(Na,{}),h.jsx("span",{children:e||"Locked"})]});function $a(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z"},child:[]}]})(e)}function Fa(e){return fe({attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M284.3 11.7c-15.6-15.6-40.9-15.6-56.6 0l-216 216c-15.6 15.6-15.6 40.9 0 56.6l216 216c15.6 15.6 40.9 15.6 56.6 0l216-216c15.6-15.6 15.6-40.9 0-56.6l-216-216z"},child:[]}]})(e)}function Xa(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M8 256a56 56 0 1 1 112 0A56 56 0 1 1 8 256zm160 0a56 56 0 1 1 112 0 56 56 0 1 1 -112 0zm216-56a56 56 0 1 1 0 112 56 56 0 1 1 0-112z"},child:[]}]})(e)}function Ba(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 144l0 48 160 0 0-48c0-44.2-35.8-80-80-80s-80 35.8-80 80zM80 192l0-48C80 64.5 144.5 0 224 0s144 64.5 144 144l0 48 16 0c35.3 0 64 28.7 64 64l0 192c0 35.3-28.7 64-64 64L64 512c-35.3 0-64-28.7-64-64L0 256c0-35.3 28.7-64 64-64l16 0z"},child:[]}]})(e)}function Ua(e){return fe({attr:{viewBox:"0 0 384 512"},child:[{tag:"path",attr:{d:"M32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l128 0 0 352c0 17.7 14.3 32 32 32s32-14.3 32-32l0-352 128 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L192 32 32 32z"},child:[]}]})(e)}function Ha(e){return fe({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 144c0-44.2 35.8-80 80-80c31.9 0 59.4 18.6 72.3 45.7c7.6 16 26.7 22.8 42.6 15.2s22.8-26.7 15.2-42.6C331 33.7 281.5 0 224 0C144.5 0 80 64.5 80 144l0 48-16 0c-35.3 0-64 28.7-64 64L0 448c0 35.3 28.7 64 64 64l320 0c35.3 0 64-28.7 64-64l0-192c0-35.3-28.7-64-64-64l-240 0 0-48z"},child:[]}]})(e)}function qa(e){return fe({attr:{fill:"currentColor",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{fillRule:"evenodd",d:"M8.5.134a1 1 0 0 0-1 0l-6 3.577a1 1 0 0 0-.5.866v6.846a1 1 0 0 0 .5.866l6 3.577a1 1 0 0 0 1 0l6-3.577a1 1 0 0 0 .5-.866V4.577a1 1 0 0 0-.5-.866z"},child:[]}]})(e)}function Ga(e){return fe({attr:{fill:"currentColor",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{d:"M11.107 0a.5.5 0 0 1 .353.146l4.394 4.394a.5.5 0 0 1 .146.353v6.214a.5.5 0 0 1-.146.353l-4.394 4.394a.5.5 0 0 1-.353.146H4.893a.5.5 0 0 1-.353-.146L.146 11.46A.5.5 0 0 1 0 11.107V4.893a.5.5 0 0 1 .146-.353L4.54.146A.5.5 0 0 1 4.893 0z"},child:[]}]})(e)}const Ka=({onClose:e,onConfirm:t})=>{const{t:r}=Ut(),[n,i]=P.useState(!1),a=()=>{i(!0),setTimeout(e,300)},l=()=>{i(!0),setTimeout(t,300)};return Hr.createPortal(h.jsx("div",{className:`wb-confirm-popup-overlay ${n?"wb-closing":""}`,children:h.jsxs("div",{className:"wb-confirm-popup",children:[h.jsx("p",{children:r("confirmClear")}),h.jsxs("div",{className:"wb-actions",children:[h.jsx("button",{onClick:a,children:r("cancel")}),h.jsx("button",{onClick:l,children:r("clear")})]})]})}),document.body)},Ja=({mode:e="user",onImageUpload:t})=>{const r=vr(),{t:n,language:i,changeLanguage:a}=Ut(),l=xe(X=>X.whiteboard.toolbar.selectedTool),u=xe(X=>X.whiteboard.lock.isLocked),[p,c]=P.useState(!1),[v,b]=P.useState(!1),[s,S]=P.useState(!1),m=P.useRef(null),y=P.useRef(null),E=P.useRef(null),C=P.useRef(null),O=P.useRef(null),k=async X=>{var oe;const M=(oe=X.target.files)==null?void 0:oe[0];if(M){if(t)try{const ue=URL.createObjectURL(M),he=new Image;he.onload=async()=>{const pe=he.width,we=he.height;URL.revokeObjectURL(ue);try{const Te=await t(M),Pe=Date.now().toString();r(Se({id:Pe,type:"image",x:100,y:100,width:pe,height:we,src:Te})),r(Me("pointer")),r(He([Pe]))}catch(Te){console.error("Image upload failed:",Te)}},he.src=ue}catch(ue){console.error("Error processing image:",ue)}else{const ue=URL.createObjectURL(M),he=new Image;he.onload=()=>{const pe=Date.now().toString();r(Se({id:pe,type:"image",x:100,y:100,width:he.width,height:he.height,src:ue})),r(Me("pointer")),r(He([pe]))},he.src=ue}X.target.value=""}};P.useEffect(()=>{const X=M=>{const oe=M.target;m.current&&!m.current.contains(oe)&&y.current&&!y.current.contains(oe)&&c(!1),C.current&&!C.current.contains(oe)&&E.current&&!E.current.contains(oe)&&b(!1)};return document.addEventListener("mousedown",X),()=>document.removeEventListener("mousedown",X)},[]);const I=()=>{S(!0)},x=()=>{r(Me("pointer")),r(He([])),r(Wr()),S(!1)},D=[{name:"triangle",icon:h.jsx(Da,{style:{transform:"rotate(-30deg)"}})},{name:"diamond",icon:h.jsx(Fa,{})},{name:"star",icon:h.jsx(Wa,{})},{name:"heart",icon:h.jsx(Ma,{})},{name:"hexagon",icon:h.jsx(qa,{})},{name:"octagon",icon:h.jsx(Ga,{})},{name:"arrow",icon:h.jsx($a,{})}],F=X=>{r(Me(X)),c(!1)},j=X=>{a(X),b(!1)};return h.jsxs("div",{className:"wb-toolbar",children:[h.jsx("button",{className:l==="pointer"?"wb-active":"",onClick:()=>r(Me("pointer")),title:n("pointer"),disabled:u,children:h.jsx(Aa,{})}),h.jsx("button",{className:l==="text"?"wb-active":"",onClick:()=>r(Me("text")),title:n("text"),disabled:u,children:h.jsx(Ua,{})}),h.jsx("button",{onClick:()=>{var X;return(X=O.current)==null?void 0:X.click()},title:n("image"),disabled:u,children:h.jsx(Ra,{})}),h.jsx("input",{type:"file",ref:O,style:{display:"none"},accept:"image/*",onChange:k}),h.jsx("button",{className:l==="pencil"?"wb-active":"",onClick:()=>r(Me("pencil")),title:n("pencil"),disabled:u,children:h.jsx(Ia,{})}),h.jsx("button",{className:l==="rectangle"?"wb-active":"",onClick:()=>r(Me("rectangle")),title:n("rectangle"),disabled:u,children:h.jsx(La,{})}),h.jsx("button",{className:l==="circle"?"wb-active":"",onClick:()=>r(Me("circle")),title:n("circle"),disabled:u,children:h.jsx(ja,{})}),h.jsxs("div",{className:"wb-ellipsis-container",children:[h.jsx("button",{ref:y,className:D.some(X=>X.name===l)?"wb-active":"",onClick:()=>c(!p),title:n("moreShapes"),disabled:u,children:h.jsx(Xa,{})}),p&&h.jsxs("div",{className:"wb-shapes-popup",ref:m,children:[h.jsx("div",{className:"wb-shapes-popup-header",children:n("moreShapes")}),h.jsx("div",{className:"wb-shapes-popup-grid",children:D.map(X=>h.jsx("button",{className:l===X.name?"wb-active":"",onClick:()=>F(X.name),title:n(X.name),children:X.icon},X.name))})]})]}),h.jsx("button",{className:l==="eraser"?"wb-active":"",onClick:()=>r(Me("eraser")),title:n("eraser"),disabled:u,children:h.jsx(Ta,{})}),h.jsx("button",{onClick:I,title:n("trash"),disabled:u,children:h.jsx(Ya,{})}),h.jsxs("div",{className:"wb-language-container",children:[h.jsx("button",{ref:E,onClick:()=>b(!v),title:n("language"),children:h.jsx(ka,{})}),v&&h.jsxs("div",{className:"wb-language-popup",ref:C,children:[h.jsx("div",{className:"wb-language-popup-header",children:n("language")}),h.jsxs("div",{className:"wb-language-options",children:[h.jsxs("button",{className:i==="en"?"wb-active":"",onClick:()=>j("en"),children:["πŸ‡ΊπŸ‡Έ ",n("english")]}),h.jsxs("button",{className:i==="tr"?"wb-active":"",onClick:()=>j("tr"),children:["πŸ‡ΉπŸ‡· ",n("turkish")]})]})]})]}),e==="moderator"&&h.jsx("button",{onClick:()=>r(io(!u)),title:u?"Unlock":"Lock",style:{color:u?"red":"inherit"},children:u?h.jsx(Ba,{}):h.jsx(Ha,{})}),s&&h.jsx(Ka,{onConfirm:x,onClose:()=>S(!1)})]})},Za=({shifted:e})=>{const t=vr(),{t:r}=Ut(),n=xe(s=>s.whiteboard.toolbar.selectedTool),i=xe(s=>s.whiteboard.toolProperties),a=xe(s=>s.whiteboard.selectedElementIds||[]),l=xe(s=>s.whiteboard.elements),u=a.length>0?l.find(s=>s.id===a[0]):null,p=(s,S,m)=>{t(na({tool:s,property:S,value:m}))},c=(s,S)=>{if(a.length>0){const m=a.map(y=>({id:y,updates:{[s]:S}}));t(oo(m))}},v=()=>{a.forEach(s=>{t(ca(s))})},b=()=>{[...a].reverse().forEach(s=>{t(la(s))})};if(n==="pointer"&&u&&u.type==="text")return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontSize")}),h.jsxs("select",{className:"font-size-selector",value:u.fontSize||16,onChange:s=>c("fontSize",parseInt(s.target.value)),children:[h.jsx("option",{value:"12",children:"12 px"}),h.jsx("option",{value:"14",children:"14 px"}),h.jsx("option",{value:"16",children:"16 px"}),h.jsx("option",{value:"18",children:"18 px"}),h.jsx("option",{value:"24",children:"24 px"}),h.jsx("option",{value:"32",children:"32 px"}),h.jsx("option",{value:"48",children:"48 px"}),h.jsx("option",{value:"64",children:"64 px"}),h.jsx("option",{value:"72",children:"72 px"})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontColor")}),h.jsx("input",{type:"color",value:u.fontColor||"#000000",onChange:s=>c("fontColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("layerOrder")}),h.jsxs("div",{className:"wb-layer-buttons",children:[h.jsx("button",{onClick:v,title:r("bringToFront"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"white"})]})}),h.jsx("button",{onClick:b,title:r("sendToBack"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"white"})]})})]})]})]});if(n==="pointer"&&u){const s=["rectangle","circle","triangle","diamond","star","heart","hexagon","octagon","arrow"].includes(u.type),S=u.type==="pencil";return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[s&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeColor")}),h.jsx("input",{type:"color",value:u.strokeColor,onChange:m=>c("strokeColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fillColor")}),h.jsx("input",{type:"color",value:u.fillColor,onChange:m=>c("fillColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeWidth")}),h.jsxs("select",{className:"stroke-width-selector",value:u.lineWidth,onChange:m=>c("lineWidth",parseInt(m.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"})]})]})]}),S&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushColor")}),h.jsx("input",{type:"color",value:u.strokeColor,onChange:m=>c("strokeColor",m.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushSize")}),h.jsxs("select",{className:"brush-size-selector",value:u.lineWidth,onChange:m=>c("lineWidth",parseInt(m.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"}),h.jsx("option",{value:"16",children:"16 px"})]})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("layerOrder")}),h.jsxs("div",{className:"wb-layer-buttons",children:[h.jsx("button",{onClick:v,title:r("bringToFront"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"white"})]})}),h.jsx("button",{onClick:b,title:r("sendToBack"),children:h.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[h.jsx("rect",{x:"4",y:"4",width:"12",height:"12",rx:"1",fill:"#0066cc",stroke:"#0066cc"}),h.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"1",fill:"white"})]})})]})]})]})}return h.jsxs("div",{className:`wb-prop-tools ${e?"wb-shifted":""}`,children:[n==="text"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontSize")}),h.jsxs("select",{className:"font-size-selector",value:i.text.fontSize,onChange:s=>p("text","fontSize",parseInt(s.target.value)),children:[h.jsx("option",{value:"12",children:"12 px"}),h.jsx("option",{value:"14",children:"14 px"}),h.jsx("option",{value:"16",children:"16 px"}),h.jsx("option",{value:"18",children:"18 px"}),h.jsx("option",{value:"24",children:"24 px"}),h.jsx("option",{value:"32",children:"32 px"}),h.jsx("option",{value:"48",children:"48 px"}),h.jsx("option",{value:"64",children:"64 px"}),h.jsx("option",{value:"72",children:"72 px"})]})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fontColor")}),h.jsx("input",{type:"color",value:i.text.fontColor,onChange:s=>p("text","fontColor",s.target.value)})]})]}),n==="pencil"&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushColor")}),h.jsx("input",{type:"color",value:i.pencil.strokeColor,onChange:s=>p("pencil","strokeColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("brushSize")}),h.jsxs("select",{className:"brush-size-selector",value:i.pencil.lineWidth,onChange:s=>p("pencil","lineWidth",parseInt(s.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"}),h.jsx("option",{value:"16",children:"16 px"})]})]})]}),(n==="rectangle"||n==="circle"||n==="triangle"||n==="diamond"||n==="star"||n==="heart"||n==="hexagon"||n==="octagon"||n==="arrow")&&h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeColor")}),h.jsx("input",{type:"color",value:i[n].strokeColor,onChange:s=>p(n,"strokeColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("fillColor")}),h.jsx("input",{type:"color",value:i[n].fillColor,onChange:s=>p(n,"fillColor",s.target.value)})]}),h.jsxs("div",{className:"wb-prop-tool-item",children:[h.jsx("span",{children:r("strokeWidth")}),h.jsxs("select",{className:"stroke-width-selector",value:i[n].lineWidth,onChange:s=>p(n,"lineWidth",parseInt(s.target.value)),children:[h.jsx("option",{value:"1",children:"1 px"}),h.jsx("option",{value:"2",children:"2 px"}),h.jsx("option",{value:"4",children:"4 px"}),h.jsx("option",{value:"8",children:"8 px"})]})]})]})]})},Qa=({onFitToView:e,onExport:t,onToggleGrid:r})=>{const{t:n}=Ut();return h.jsxs("div",{className:"wb-canvas-tools",children:[h.jsx("button",{onClick:r,title:n("toggleGrid"),children:h.jsx(Oa,{})}),h.jsx("button",{onClick:e,title:n("fitToView"),children:h.jsx(Pa,{})}),h.jsx("button",{onClick:t,title:n("exportAsPng"),children:h.jsx(za,{})})]})},$r=P.forwardRef(({watermark:e,isLocked:t,lockText:r,onLockChange:n,isWatermarkEnabled:i,watermarkText:a,mode:l,initialElements:u,onAfterMount:p,onImageUpload:c},v)=>{var mo;const b=P.useRef(null),s=vr(),S=wn(),m=xe(o=>o.whiteboard.grid),y=xe(o=>o.whiteboard.toolbar.selectedTool),E=xe(o=>o.whiteboard.elements),C=xe(o=>o.whiteboard.viewport),O=xe(o=>o.whiteboard.toolProperties),k=xe(o=>o.whiteboard.selectedElementIds||[]),I=xe(o=>o.whiteboard.lock),x=I.isLocked,[D,F]=P.useState(!1),[j,X]=P.useState({x:0,y:0}),[M,oe]=P.useState({x:0,y:0}),[ue,he]=P.useState([]),[pe,we]=P.useState(!1),[Te,Pe]=P.useState({}),[ke,Ve]=P.useState(!1),[Re,Ne]=P.useState(!1),[$e,Fe]=P.useState(!1),[rt,lt]=P.useState({x:0,y:0}),[Xe,qe]=P.useState({y:0,initialZoom:1}),[Ae,Oe]=P.useState(!1),[Ie,nt]=P.useState({x:0,y:0}),[V,Ee]=P.useState(""),[$,ge]=P.useState(null),je=P.useRef(null),De=P.useRef(null),[xt,tr]=P.useState(!1),[me,Et]=P.useState(null),[Nt,At]=P.useState(null),[It,rr]=P.useState(null),[St,nr]=P.useState(!1),[se,Dt]=P.useState(null),Fr=P.useCallback(o=>{$&&o.trim()&&(je.current&&clearTimeout(je.current),je.current=setTimeout(()=>{$&&o!==De.current&&(De.current=o,s(Zt({id:$,updates:{text:o}})))},150))},[s,$]);P.useEffect(()=>()=>{je.current&&clearTimeout(je.current)},[]),P.useImperativeHandle(v,()=>({canvas:b.current,applyAction:o=>{s({...o,meta:{...o.meta,fromRemote:!0}})},getElems:()=>S.getState().whiteboard.elements,getElements:()=>S.getState().whiteboard.elements,setElems:o=>{s({...Yr(o),meta:{fromRemote:!0}})},setElements:o=>{s({...Yr(o),meta:{fromRemote:!0}})},clearElems:()=>{s({...Wr(),meta:{fromRemote:!0}})},clearElements:()=>{s({...Wr(),meta:{fromRemote:!0}})}})),P.useEffect(()=>{t!==void 0&&s(io(t))},[t,s]),P.useEffect(()=>{n&&n(x)},[x,n]);const ut=xe(o=>o.whiteboard.watermark);P.useEffect(()=>{i!==void 0&&i!==ut.visible&&s(ua(i))},[i,ut.visible,s]),P.useEffect(()=>{a!==void 0&&a!==ut.text&&s(fa(a))},[a,ut.text,s]),P.useEffect(()=>{u&&u.length>0&&s(Yr(u))},[s]),P.useEffect(()=>{p&&setTimeout(()=>{p()},0)},[]);const Ct=P.useCallback((o,f,g)=>{const w=o.canvas,_=w.width,T=w.height,N=Math.floor(-C.panX/C.zoom/f)*f,A=Math.floor(-C.panY/C.zoom/f)*f,z=Math.ceil((_/C.zoom-C.panX/C.zoom)/f)*f,B=Math.ceil((T/C.zoom-C.panY/C.zoom)/f)*f;o.strokeStyle=g,o.lineWidth=.5/C.zoom;for(let Y=N;Y<=z;Y+=f)o.beginPath(),o.moveTo(Y,A),o.lineTo(Y,B),o.stroke();for(let Y=A;Y<=B;Y+=f)o.beginPath(),o.moveTo(N,Y),o.lineTo(z,Y),o.stroke()},[C]),zt=P.useCallback((o,f,g)=>{const w=Math.min(f.x,g.x),_=Math.min(f.y,g.y),T=Math.abs(g.x-f.x),N=Math.abs(g.y-f.y);o.strokeStyle="#0066cc",o.lineWidth=1,o.setLineDash([5,5]),o.strokeRect(w,_,T,N),o.fillStyle="rgba(0, 102, 204, 0.1)",o.fillRect(w,_,T,N),o.setLineDash([])},[]),ze=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#000",strokeColor:A="#000",lineWidth:z=2}=f;o.fillStyle=N,o.fillRect(g,w,_,T),o.strokeStyle=A,o.lineWidth=z,o.strokeRect(g,w,_,T)},[]),ot=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,radius:_=0,fillColor:T="#000",strokeColor:N="#000",lineWidth:A=2}=f;o.beginPath(),o.arc(g,w,_,0,Math.PI*2),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),it=P.useCallback((o,f)=>{const{points:g=[],strokeColor:w="#000",lineWidth:_=2}=f;if(!(g.length<2)){o.strokeStyle=w,o.lineWidth=_,o.lineCap="round",o.lineJoin="round",o.beginPath(),o.moveTo(g[0].x,g[0].y);for(let T=1;T<g.length;T++)g[T]&&o.lineTo(g[T].x,g[T].y);o.stroke()}},[]),Lt=P.useCallback((o,f)=>{const{x:g=0,y:w=0,text:_="",fontSize:T=16,fontColor:N="#000"}=f;o.font=`${T}px sans-serif`,o.fillStyle=N,o.textBaseline="top",o.fillText(_,g,w)},[]),_t=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f;o.beginPath(),o.moveTo(g+_/2,w),o.lineTo(g+_,w+T),o.lineTo(g,w+T),o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),ft=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f;o.beginPath(),o.moveTo(g+_/2,w),o.lineTo(g+_,w+T/2),o.lineTo(g+_/2,w+T),o.lineTo(g,w+T/2),o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),Ot=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,size:_=0,fillColor:T="#ffff00",strokeColor:N="#000",lineWidth:A=2}=f,z=5,B=_,Y=_/2;o.beginPath();for(let L=0;L<z*2;L++){const H=L%2===0?B:Y,q=Math.PI/z*L-Math.PI/2,K=g+Math.cos(q)*H,ie=w+Math.sin(q)*H;L===0?o.moveTo(K,ie):o.lineTo(K,ie)}o.closePath(),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),dt=P.useCallback((o,f)=>{const{centerX:g=0,centerY:w=0,size:_=0,fillColor:T="#ff6b6b",strokeColor:N="#000",lineWidth:A=2}=f;o.beginPath();const z=w-_/2;o.moveTo(g,z+_/4),o.bezierCurveTo(g-_/2,z,g-_,z+_/2,g,w+_/2),o.bezierCurveTo(g+_,z+_/2,g+_/2,z,g,z+_/4),o.fillStyle=T,o.fill(),o.strokeStyle=N,o.lineWidth=A,o.stroke()},[]),ht=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f,B=g+_/2,Y=w+T/2,L=_/2,H=T/2;o.beginPath();for(let q=0;q<6;q++){const K=Math.PI/3*q-Math.PI/2,ie=B+Math.cos(K)*L,ve=Y+Math.sin(K)*H;q===0?o.moveTo(ie,ve):o.lineTo(ie,ve)}o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),jt=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,fillColor:N="#fff",strokeColor:A="#000",lineWidth:z=2}=f,B=g+_/2,Y=w+T/2,L=_/2,H=T/2;o.beginPath();for(let q=0;q<8;q++){const K=Math.PI/4*q-Math.PI/2,ie=B+Math.cos(K)*L,ve=Y+Math.sin(K)*H;q===0?o.moveTo(ie,ve):o.lineTo(ie,ve)}o.closePath(),o.fillStyle=N,o.fill(),o.strokeStyle=A,o.lineWidth=z,o.stroke()},[]),Tt=P.useCallback((o,f)=>{const{startX:g=0,startY:w=0,endX:_=0,endY:T=0,fillColor:N="#000",strokeColor:A="#000",lineWidth:z=2}=f,B=15,Y=Math.atan2(T-w,_-g);o.beginPath(),o.moveTo(g,w),o.lineTo(_,T),o.strokeStyle=A,o.lineWidth=z,o.stroke(),o.beginPath(),o.moveTo(_,T),o.lineTo(_-B*Math.cos(Y-Math.PI/6),T-B*Math.sin(Y-Math.PI/6)),o.lineTo(_-B*Math.cos(Y+Math.PI/6),T-B*Math.sin(Y+Math.PI/6)),o.closePath(),o.fillStyle=N,o.fill()},[]),pt=P.useRef({}),Wt=P.useRef(null),or=P.useCallback((o,f)=>{const{x:g=0,y:w=0,width:_=0,height:T=0,src:N=""}=f;if(pt.current[N]){const A=pt.current[N];A.complete&&o.drawImage(A,g,w,_,T)}else{const A=new Image;A.onload=()=>{pt.current[N]=A,Wt.current&&Wt.current()},A.src=N,pt.current[N]=A}},[]),Pt=P.useCallback((o,f)=>{switch(f.type){case"rectangle":ze(o,f);break;case"circle":ot(o,f);break;case"pencil":it(o,f);break;case"text":Lt(o,f);break;case"triangle":_t(o,f);break;case"diamond":ft(o,f);break;case"star":Ot(o,f);break;case"heart":dt(o,f);break;case"hexagon":ht(o,f);break;case"octagon":jt(o,f);break;case"arrow":Tt(o,f);break;case"image":or(o,f);break}},[ze,ot,it,Lt,_t,ft,Ot,dt,ht,jt,Tt,or]),Xr=P.useCallback(()=>{const o=b.current;if(!o)return;const f=document.createElement("canvas");f.width=o.width,f.height=o.height;const g=f.getContext("2d");if(!g)return;g.fillStyle="#ffffff",g.fillRect(0,0,f.width,f.height),g.save(),g.translate(C.panX,C.panY),g.scale(C.zoom,C.zoom),E.forEach(T=>{Pt(g,T)}),g.restore();const w=f.toDataURL("image/png"),_=document.createElement("a");_.download=`whiteboard-${Date.now()}.png`,_.href=w,_.click()},[C,E,Pt]),d=P.useCallback(()=>{const o=b.current;o&&s(sa({canvasWidth:o.width,canvasHeight:o.height,padding:50}))},[s]),R=P.useCallback(()=>{s(ra())},[s]),W=(o,f,g,w,_,T)=>{const N=o-g,A=f-w,z=_-g,B=T-w,Y=N*z+A*B,L=z*z+B*B;let H=-1;L!==0&&(H=Y/L);let q,K;H<0?(q=g,K=w):H>1?(q=_,K=T):(q=g+H*z,K=w+H*B);const ie=o-q,ve=f-K;return Math.sqrt(ie*ie+ve*ve)},U=P.useCallback((o,f)=>{for(let g=E.length-1;g>=0;g--){const w=E[g],_=w.x??0,T=w.y??0,N=w.width??0,A=w.height??0,z=w.centerX??0,B=w.centerY??0,Y=w.radius??0;if(w.type==="rectangle"){if(o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}else if(w.type==="circle"){if(Math.sqrt(Math.pow(o-z,2)+Math.pow(f-B,2))<=Y)return w}else if(w.type==="pencil"){const H=w.points??[];for(let q=1;q<H.length;q++){const K=H[q-1],ie=H[q];if(!K||!ie)continue;if(W(o,f,K.x,K.y,ie.x,ie.y)<=5)return w}}else if(w.type==="text"){const L=w.fontSize||16,q=(w.text||"").length*L*.6,K=L;if(o>=_&&o<=_+q&&f>=T&&f<=T+K)return w}else if(w.type==="triangle"||w.type==="diamond"||w.type==="hexagon"||w.type==="octagon"){if(o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}else if(w.type==="star"||w.type==="heart"){const L=Math.sqrt(Math.pow(o-z,2)+Math.pow(f-B,2)),H=w.size??0;if(L<=H)return w}else if(w.type==="arrow"){const H=w.startX??0,q=w.startY??0,K=w.endX??0,ie=w.endY??0;if(W(o,f,H,q,K,ie)<=10)return w}else if(w.type==="image"&&o>=_&&o<=_+N&&f>=T&&f<=T+A)return w}return null},[E]),Z=P.useCallback(o=>{let f=0,g=0,w=0,_=0;if(o.type==="rectangle"||o.type==="image"||o.type==="text"||o.type==="triangle"||o.type==="diamond"||o.type==="hexagon"||o.type==="octagon")if(f=o.x??0,g=o.y??0,o.type==="text"){const T=o.fontSize||16;w=(o.text||"").length*T*.6,_=T}else w=o.width??0,_=o.height??0;else if(o.type==="circle"){const T=o.radius??0;f=(o.centerX??0)-T,g=(o.centerY??0)-T,w=T*2,_=T*2}else if(o.type==="star"||o.type==="heart"){const T=o.size??0;f=(o.centerX??0)-T,g=(o.centerY??0)-T,w=T*2,_=T*2}else if(o.type==="pencil"&&o.points&&o.points.length>0){const T=Math.min(...o.points.map(B=>B.x)),N=Math.max(...o.points.map(B=>B.x)),A=Math.min(...o.points.map(B=>B.y)),z=Math.max(...o.points.map(B=>B.y));f=T,g=A,w=N-T,_=z-A}else if(o.type==="arrow")return null;return{x:f,y:g,w,h:_}},[]),Q=P.useCallback(o=>{const f=[];if(o.type==="arrow")return f.push({type:"start",x:o.startX??0,y:o.startY??0}),f.push({type:"end",x:o.endX??0,y:o.endY??0}),f;const g=Z(o);if(!g)return[];const{x:w,y:_,w:T,h:N}=g;return f.push({type:"nw",x:w,y:_}),f.push({type:"ne",x:w+T,y:_}),f.push({type:"se",x:w+T,y:_+N}),f.push({type:"sw",x:w,y:_+N}),f.push({type:"n",x:w+T/2,y:_}),f.push({type:"s",x:w+T/2,y:_+N}),f.push({type:"e",x:w+T,y:_+N/2}),f.push({type:"w",x:w,y:_+N/2}),f},[Z]),J=P.useCallback((o,f,g,w)=>{const _=Q(g),T=10/w;for(const N of _)if(Math.abs(o-N.x)<=T&&Math.abs(f-N.y)<=T)return N.type;return null},[Q]),G=P.useCallback((o,f)=>{o.strokeStyle="#0066cc",o.lineWidth=1/C.zoom,o.setLineDash([5/C.zoom,5/C.zoom]);const g=Z(f);g?o.strokeRect(g.x-4/C.zoom,g.y-4/C.zoom,g.w+8/C.zoom,g.h+8/C.zoom):f.type,o.setLineDash([]);const w=Q(f),_=8/C.zoom;o.fillStyle="#ffffff",o.strokeStyle="#0066cc",o.lineWidth=1/C.zoom;for(const T of w)o.fillRect(T.x-_/2,T.y-_/2,_,_),o.strokeRect(T.x-_/2,T.y-_/2,_,_)},[C.zoom,Z,Q]),ce=P.useCallback(()=>{const o=b.current;if(!o)return;const f=o.getContext("2d");f&&(f.clearRect(0,0,o.width,o.height),f.save(),f.translate(C.panX,C.panY),f.scale(C.zoom,C.zoom),m.enabled&&Ct(f,m.size,m.color),E.forEach(g=>{Pt(f,g),k.includes(g.id)&&G(f,g)}),St&&se&&(f.fillStyle="rgba(0, 102, 204, 0.1)",f.strokeStyle="#0066cc",f.lineWidth=1/C.zoom,f.fillRect(se.startX,se.startY,se.width,se.height),f.strokeRect(se.startX,se.startY,se.width,se.height)),f.restore())},[m,Ct,E,Pt,k,G,C,St,se]);P.useEffect(()=>{Wt.current=ce},[ce]),P.useEffect(()=>{const o=b.current;if(!o)return;const f=o.parentElement;if(!f)return;const g=()=>{const _=f.getBoundingClientRect();o.width=_.width,o.height=_.height,ce()};g();const w=new ResizeObserver(()=>{g()});return w.observe(f),()=>{w.disconnect()}},[ce]),P.useEffect(()=>{ce()},[ce]),P.useEffect(()=>{const o=g=>{g.target.tagName==="INPUT"||g.target.tagName==="TEXTAREA"||g.code==="Space"&&!g.repeat&&(g.preventDefault(),Ve(!0))},f=g=>{g.target.tagName==="INPUT"||g.target.tagName==="TEXTAREA"||g.code==="Space"&&(g.preventDefault(),Ve(!1),Ne(!1),Fe(!1))};return window.addEventListener("keydown",o),window.addEventListener("keyup",f),()=>{window.removeEventListener("keydown",o),window.removeEventListener("keyup",f)}},[]);const ae=P.useCallback((o,f)=>({x:(o-C.panX)/C.zoom,y:(f-C.panY)/C.zoom}),[C]);P.useEffect(()=>{const o=b.current;if(!o||!D)return;const f=o.getContext("2d");if(f){if(ce(),f.save(),f.translate(C.panX,C.panY),f.scale(C.zoom,C.zoom),y==="pointer")zt(f,j,M);else if(y==="rectangle"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ze(f,{id:"preview",type:"rectangle",x:g,y:w,width:_,height:T,fillColor:O.rectangle.fillColor,lineWidth:O.rectangle.lineWidth})}else if(y==="circle"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));ot(f,{id:"preview",type:"circle",centerX:g,centerY:w,radius:_,strokeColor:O.circle.strokeColor,fillColor:O.circle.fillColor,lineWidth:O.circle.lineWidth})}else if(y==="pencil")it(f,{id:"preview",type:"pencil",points:ue,strokeColor:O.pencil.strokeColor,lineWidth:O.pencil.lineWidth});else if(y==="triangle"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);_t(f,{id:"preview",type:"triangle",x:g,y:w,width:_,height:T,fillColor:O.triangle.fillColor,lineWidth:O.triangle.lineWidth})}else if(y==="diamond"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ft(f,{id:"preview",type:"diamond",x:g,y:w,width:_,height:T,fillColor:O.diamond.fillColor,lineWidth:O.diamond.lineWidth})}else if(y==="star"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));Ot(f,{id:"preview",type:"star",centerX:g,centerY:w,size:_,fillColor:O.star.fillColor,lineWidth:O.star.lineWidth})}else if(y==="heart"){const g=j.x,w=j.y,_=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));dt(f,{id:"preview",type:"heart",centerX:g,centerY:w,size:_,fillColor:O.heart.fillColor,lineWidth:O.heart.lineWidth})}else if(y==="hexagon"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);ht(f,{id:"preview",type:"hexagon",x:g,y:w,width:_,height:T,fillColor:O.hexagon.fillColor,lineWidth:O.hexagon.lineWidth})}else if(y==="octagon"){const g=Math.min(j.x,M.x),w=Math.min(j.y,M.y),_=Math.abs(M.x-j.x),T=Math.abs(M.y-j.y);jt(f,{id:"preview",type:"octagon",x:g,y:w,width:_,height:T,fillColor:O.octagon.fillColor,lineWidth:O.octagon.lineWidth})}else y==="arrow"&&Tt(f,{id:"preview",type:"arrow",startX:j.x,startY:j.y,endX:M.x,endY:M.y,fillColor:O.arrow.fillColor,lineWidth:O.arrow.lineWidth});f.restore()}},[D,y,j,M,ue,ce,zt,ze,ot,it,_t,ft,Ot,dt,ht,jt,Tt,C,O]);const de=o=>{const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top;if(Ae)return;if(ke){o.preventDefault(),o.button===0?(Ne(!0),lt({x:w-C.panX,y:_-C.panY})):o.button===2&&(Fe(!0),qe({y:_,initialZoom:C.zoom}));return}if(x)return;const{x:T,y:N}=ae(w,_);if(y==="pointer"){const A=U(T,N);let z=null;if(k.length===1){const B=k[0],Y=E.find(L=>L.id===B);if(Y){const L=J(T,N,Y,C.zoom);L&&(z={element:Y,handle:L})}}if(z){tr(!0),Et(z.handle),At({x:T,y:N}),rr(JSON.parse(JSON.stringify(z.element)));return}if(A){const B=k.includes(A.id);let Y=k;if(o.shiftKey?(B?Y=k.filter(L=>L!==A.id):Y=[...k,A.id],s(He(Y))):B||(Y=[A.id],s(He(Y))),Y.length>0){we(!0),X({x:T,y:N});const L={};Y.forEach(H=>{const q=E.find(K=>K.id===H);q&&(L[H]={...q})}),Pe(L)}}else{o.shiftKey||s(He([])),nr(!0);const{x:B,y:Y}=ae(w,_);Dt({startX:B,startY:Y,width:0,height:0})}}else if(y==="text"){const A=Date.now().toString();s(Se({id:A,type:"text",x:T,y:N,text:"Text",fontSize:O.text.fontSize,fontColor:O.text.fontColor})),s(Me("pointer")),s(He([A])),ge(A),Ee("Text"),nt({x:T,y:N}),Oe(!0)}else if(y==="eraser"){const A=U(T,N);A&&s(oa(A.id))}else s(He([])),F(!0),X({x:T,y:N}),oe({x:T,y:N}),y==="pencil"&&he([{x:T,y:N}])},Le=o=>{const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top;if(Re){s(ia({x:w-rt.x,y:_-rt.y}));return}if($e){const A=Xe.y-_,B=Xe.initialZoom*(1+A*.005);s(aa(B));return}if(x)return;const{x:T,y:N}=ae(w,_);if(St&&se){const A=T-se.startX,z=N-se.startY;Dt({...se,width:A,height:z});return}if(pe&&k.length>0){const A=T-j.x,z=N-j.y,B=[];k.forEach(Y=>{const L=Te[Y];if(!L)return;let H={};if(L.type==="rectangle")H={x:(L.x??0)+A,y:(L.y??0)+z};else if(L.type==="circle")H={centerX:(L.centerX??0)+A,centerY:(L.centerY??0)+z};else if(L.type==="pencil"){const q=L.points||[];if(q.length===0)return;H={points:q.map(K=>({x:K.x+A,y:K.y+z}))}}else L.type==="text"?H={x:(L.x??0)+A,y:(L.y??0)+z}:L.type==="triangle"||L.type==="diamond"||L.type==="hexagon"||L.type==="octagon"?H={x:(L.x??0)+A,y:(L.y??0)+z}:L.type==="star"||L.type==="heart"?H={centerX:(L.centerX??0)+A,centerY:(L.centerY??0)+z}:L.type==="arrow"?H={startX:(L.startX??0)+A,startY:(L.startY??0)+z,endX:(L.endX??0)+A,endY:(L.endY??0)+z}:L.type==="image"&&(H={x:(L.x??0)+A,y:(L.y??0)+z});B.push({id:Y,updates:H})}),B.length>0&&s(oo(B));return}if(xt&&It&&Nt&&me){let A={};const z=T-Nt.x,B=N-Nt.y,Y=It;if(Y.type==="arrow")me==="start"?A={startX:(Y.startX??0)+z,startY:(Y.startY??0)+B}:me==="end"&&(A={endX:(Y.endX??0)+z,endY:(Y.endY??0)+B});else if(Y.type==="circle"||Y.type==="star"||Y.type==="heart"){const L=Y.radius||Y.size||0,H=me.includes("e"),q=me.includes("s"),K=me.includes("w"),ie=me.includes("n");let ve=0;H&&(ve+=z),K&&(ve-=z),q&&(ve+=B),ie&&(ve-=B);const Yt=Math.max(5,L+ve);Y.type==="circle"?A={radius:Yt}:A={size:Yt}}else if(Y.type==="pencil"&&Y.points){const L=Z(Y);if(L){const{x:H,y:q,w:K,h:ie}=L;let ve=H,Yt=q,Br=K,Ur=ie;me.includes("e")&&(Br=Math.max(5,K+z)),me.includes("w")&&(Br=Math.max(5,K-z),ve=H+z),me.includes("s")&&(Ur=Math.max(5,ie+B)),me.includes("n")&&(Ur=Math.max(5,ie-B),Yt=q+B);const os=Br/K,is=Ur/ie;A={points:Y.points.map(go=>({x:ve+(go.x-H)*os,y:Yt+(go.y-q)*is}))}}}else{let L=Y.x??0,H=Y.y??0,q=Y.width??0,K=Y.height??0;if(me.includes("e")&&(q=Math.max(5,(Y.width??0)+z)),me.includes("w")){const ie=(Y.width??0)-z;ie>5&&(q=ie,L=(Y.x??0)+z)}if(me.includes("s")&&(K=Math.max(5,(Y.height??0)+B)),me.includes("n")){const ie=(Y.height??0)-B;ie>5&&(K=ie,H=(Y.y??0)+B)}A={x:L,y:H,width:q,height:K}}Object.keys(A).length>0&&s(Zt({id:Y.id,updates:A}));return}D&&(oe({x:T,y:N}),y==="pencil"&&he(A=>[...A,{x:T,y:N}]))},Ge=()=>{if(Re||$e){Ne(!1),Fe(!1);return}if(x){we(!1),F(!1);return}if(pe&&we(!1),St&&se){const o=se.width>0?se.startX:se.startX+se.width,f=se.height>0?se.startY:se.startY+se.height,g=Math.abs(se.width),w=Math.abs(se.height),_=[];E.forEach(T=>{const N=Z(T);N&&N.x<o+g&&N.x+N.w>o&&N.y<f+w&&N.y+N.h>f&&_.push(T.id)}),_.length>0&&s(He(_))}if(F(!1),we(!1),tr(!1),nr(!1),Dt(null),Et(null),rr(null),he([]),X({x:0,y:0}),Pe({}),At(null),Ne(!1),!!D){if(y==="pointer")ce();else if(y==="rectangle"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"rectangle",x:o,y:f,width:g,height:w,strokeColor:O.rectangle.strokeColor,fillColor:O.rectangle.fillColor,lineWidth:O.rectangle.lineWidth}))}else if(y==="circle"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"circle",centerX:o,centerY:f,radius:g,strokeColor:O.circle.strokeColor,fillColor:O.circle.fillColor,lineWidth:O.circle.lineWidth}))}else if(y==="pencil")ue.length>1&&s(Se({id:Date.now().toString(),type:"pencil",points:[...ue],strokeColor:O.pencil.strokeColor,lineWidth:O.pencil.lineWidth})),he([]);else if(y==="triangle"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"triangle",x:o,y:f,width:g,height:w,strokeColor:O.triangle.strokeColor,fillColor:O.triangle.fillColor,lineWidth:O.triangle.lineWidth}))}else if(y==="diamond"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"diamond",x:o,y:f,width:g,height:w,strokeColor:O.diamond.strokeColor,fillColor:O.diamond.fillColor,lineWidth:O.diamond.lineWidth}))}else if(y==="star"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"star",centerX:o,centerY:f,size:g,strokeColor:O.star.strokeColor,fillColor:O.star.fillColor,lineWidth:O.star.lineWidth}))}else if(y==="heart"){const o=j.x,f=j.y,g=Math.sqrt(Math.pow(M.x-j.x,2)+Math.pow(M.y-j.y,2));g>0&&s(Se({id:Date.now().toString(),type:"heart",centerX:o,centerY:f,size:g,strokeColor:O.heart.strokeColor,fillColor:O.heart.fillColor,lineWidth:O.heart.lineWidth}))}else if(y==="hexagon"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"hexagon",x:o,y:f,width:g,height:w,strokeColor:O.hexagon.strokeColor,fillColor:O.hexagon.fillColor,lineWidth:O.hexagon.lineWidth}))}else if(y==="octagon"){const o=Math.min(j.x,M.x),f=Math.min(j.y,M.y),g=Math.abs(M.x-j.x),w=Math.abs(M.y-j.y);g>0&&w>0&&s(Se({id:Date.now().toString(),type:"octagon",x:o,y:f,width:g,height:w,strokeColor:O.octagon.strokeColor,fillColor:O.octagon.fillColor,lineWidth:O.octagon.lineWidth}))}else if(y==="arrow"){const o=M.x-j.x,f=M.y-j.y;Math.sqrt(o*o+f*f)>5&&s(Se({id:Date.now().toString(),type:"arrow",startX:j.x,startY:j.y,endX:M.x,endY:M.y,strokeColor:O.arrow.strokeColor,fillColor:O.arrow.fillColor,lineWidth:O.arrow.lineWidth}))}F(!1)}},ir=o=>{ke&&o.preventDefault()},We=(o,f,g)=>{ge(o.id),Ee(o.text||""),nt({x:o.x||f,y:o.y||g}),De.current=o.text||"",Oe(!0)},ts=()=>{if(ke)return Re?"grabbing":$e?"ns-resize":"grab";if(x)return"default";if(k.length===1&&!D&&y==="pointer"){const o=E.find(f=>f.id===k[0]);if(o){const f=J(M.x,M.y,o,C.zoom);if(f)return f==="n"||f==="s"?"ns-resize":f==="e"||f==="w"?"ew-resize":f==="ne"||f==="sw"?"nesw-resize":f==="nw"||f==="se"?"nwse-resize":"pointer"}}return"default"},[po,vo]=P.useState({propTools:!1,lockIndicator:!1});P.useEffect(()=>{const o=()=>{if(window.innerWidth<=768){vo({propTools:!1,lockIndicator:!1});return}const f=document.getElementById("wb-canvas-container");if(!f)return;const g=f.querySelector(".wb-toolbar"),w=f.querySelector(".wb-prop-tools"),_=f.querySelector(".wb-lock-indicator");let T=!1,N=!1;if(g){const A=g.getBoundingClientRect();if(w){const z=w.getBoundingClientRect();A.bottom>z.top-10&&(T=!0)}if(_){const z=_.getBoundingClientRect();A.top<z.bottom+10&&(N=!0)}}vo({propTools:T,lockIndicator:N})};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[y,x,k]);const yo=async(o,f,g)=>{try{let w="";c?w=await c(o):w=URL.createObjectURL(o);const _=new Image;_.onload=()=>{const T=_.width/_.height,N=200,A=N/T;s(Se({id:Date.now().toString(),type:"image",x:f-N/2,y:g-A/2,width:N,height:A,src:w}))},_.src=w}catch(w){console.error("Failed to upload image:",w)}};P.useEffect(()=>{const o=f=>{if(!(f.target.tagName==="INPUT"||f.target.tagName==="TEXTAREA")&&!x&&f.clipboardData&&f.clipboardData.files.length>0){const g=f.clipboardData.files[0];if(g.type.startsWith("image/")){f.preventDefault();const w=b.current;if(w){const _=w.getBoundingClientRect(),T=_.width/2,N=_.height/2,{x:A,y:z}=ae(T,N);yo(g,A,z)}}}};return window.addEventListener("paste",o),()=>window.removeEventListener("paste",o)},[x,ae,c,s]);const rs=o=>{o.preventDefault()},ns=o=>{if(o.preventDefault(),!x&&o.dataTransfer.files&&o.dataTransfer.files.length>0){const f=o.dataTransfer.files[0];if(f.type.startsWith("image/")){const g=b.current;if(g){const w=g.getBoundingClientRect(),_=o.clientX-w.left,T=o.clientY-w.top,{x:N,y:A}=ae(_,T);yo(f,N,A)}}}};return h.jsxs("div",{id:"wb-canvas-container",style:{backgroundColor:"#fff",position:"relative",width:"100%",height:"100%"},onDragOver:rs,onDrop:ns,children:[h.jsx("canvas",{ref:b,onMouseDown:de,onMouseMove:Le,onMouseUp:Ge,onMouseLeave:Ge,onDoubleClick:o=>{if(x)return;const f=b.current;if(!f)return;const g=f.getBoundingClientRect(),w=o.clientX-g.left,_=o.clientY-g.top,{x:T,y:N}=ae(w,_),A=U(T,N);A&&A.type==="text"&&We(A,T,N)},onContextMenu:ir,style:{cursor:ts()}}),x&&h.jsx(Va,{text:r||e&&((mo=e.lock)==null?void 0:mo.text)||I.text,shifted:po.lockIndicator}),Ae&&h.jsx("input",{type:"text",value:V,onChange:o=>{const f=o.target.value;Ee(f),Fr(f)},onKeyDown:o=>{o.key==="Enter"&&V.trim()?($&&(s(Zt({id:$,updates:{text:V}})),De.current=V),Oe(!1),Ee(""),ge(null)):o.key==="Escape"&&(Oe(!1),Ee(""),ge(null))},onBlur:()=>{V.trim()&&$&&(s(Zt({id:$,updates:{text:V}})),De.current=V),Oe(!1),Ee(""),ge(null)},onMouseDown:o=>o.stopPropagation(),autoFocus:!0,style:{position:"absolute",left:Ie.x*C.zoom+C.panX,top:Ie.y*C.zoom+C.panY,fontSize:O.text.fontSize*C.zoom,color:O.text.fontColor,background:"white",border:"2px solid #0066cc",outline:"none",fontFamily:"sans-serif",minWidth:"150px",padding:"4px 8px",zIndex:1e3,boxShadow:"0 2px 8px rgba(0,0,0,0.2)"}}),h.jsx(Qa,{onFitToView:d,onExport:Xr,onToggleGrid:R}),h.jsx(Ja,{mode:l,onImageUpload:c}),h.jsx(Za,{shifted:po.propTools}),ut.visible&&h.jsx(ga,{})]})});$r.displayName="InternalWhiteboard";class es extends P.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(t){return{hasError:!0}}componentDidCatch(t,r){console.error("Whiteboard Error:",t,r)}render(){return this.state.hasError?h.jsxs("div",{style:{padding:"20px",textAlign:"center",background:"#fff1f0",border:"1px solid #ffa39e",borderRadius:"4px",height:"100%",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"},children:[h.jsx("h3",{children:"Something went wrong in Whiteboard"}),h.jsx("button",{onClick:()=>this.setState({hasError:!1}),style:{marginTop:"10px",padding:"8px 16px",cursor:"pointer",background:"#fff",border:"1px solid #d9d9d9",borderRadius:"2px"},children:"Try Again"})]}):this.props.children}}const ho=P.forwardRef((e,t)=>{const{store:r,onAction:n,...i}=e,a=P.useRef(n);P.useEffect(()=>{a.current=n},[n]);const l=P.useMemo(()=>r??Vr({actionHandlerRef:a}),[r]);return h.jsx(es,{children:h.jsx(Uo,{store:l,children:h.jsx(Jo,{children:h.jsx($r,{ref:t,...i})})})})});ho.displayName="Whiteboard",Ce.WhiteboardComponent=$r,Ce.createWhiteboardStore=Vr,Ce.default=ho,Ce.store=ma,Ce.whiteboardActions=da,Ce.whiteboardReducer=ao,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
100
100
  //# sourceMappingURL=whiteboard.umd.js.map