react-sync-board 1.2.8 → 1.2.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(U,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(U=typeof globalThis<"u"?globalThis:U||self,d(U["React-sync-board"]={},U.React))})(this,function(U,d){"use strict";var
|
|
1
|
+
(function(U,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(U=typeof globalThis<"u"?globalThis:U||self,d(U["React-sync-board"]={},U.React))})(this,function(U,d){"use strict";var io=Object.defineProperty;var ao=(U,d,me)=>d in U?io(U,d,{enumerable:!0,configurable:!0,writable:!0,value:me}):U[d]=me;var lr=(U,d,me)=>(ao(U,typeof d!="symbol"?d+"":d,me),me);function me(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var we={},fr={get exports(){return we},set exports(e){we=e}},Ce={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ht;function dr(){if(ht)return Ce;ht=1;var e=d,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,
|
|
9
|
+
*/var ht;function dr(){if(ht)return Ce;ht=1;var e=d,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,s=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(u,l,m){var f,c={},h=null,S=null;m!==void 0&&(h=""+m),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(S=l.ref);for(f in l)n.call(l,f)&&!o.hasOwnProperty(f)&&(c[f]=l[f]);if(u&&u.defaultProps)for(f in l=u.defaultProps,l)c[f]===void 0&&(c[f]=l[f]);return{$$typeof:t,type:u,key:h,ref:S,props:c,_owner:s.current}}return Ce.Fragment=r,Ce.jsx=a,Ce.jsxs=a,Ce}var xe={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var vt;function mr(){return vt||(vt=1,process.env.NODE_ENV!=="production"&&function(){var e=d,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),
|
|
18
|
-
`+Se+i}}var lt=!1,Ue;{var
|
|
19
|
-
`),te
|
|
20
|
-
`),
|
|
21
|
-
`+
|
|
17
|
+
*/var vt;function mr(){return vt||(vt=1,process.env.NODE_ENV!=="production"&&function(){var e=d,t=Symbol.for("react.element"),r=Symbol.for("react.portal"),n=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),o=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),u=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),c=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),S=Symbol.for("react.offscreen"),v=Symbol.iterator,E="@@iterator";function T(i){if(i===null||typeof i!="object")return null;var _=v&&i[v]||i[E];return typeof _=="function"?_:null}var y=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function C(i){{for(var _=arguments.length,O=new Array(_>1?_-1:0),$=1;$<_;$++)O[$-1]=arguments[$];x("error",i,O)}}function x(i,_,O){{var $=y.ReactDebugCurrentFrame,X=$.getStackAddendum();X!==""&&(_+="%s",O=O.concat([X]));var V=O.map(function(N){return String(N)});V.unshift("Warning: "+_),Function.prototype.apply.call(console[i],console,V)}}var p=!1,b=!1,g=!1,w=!1,I=!1,k;k=Symbol.for("react.module.reference");function D(i){return!!(typeof i=="string"||typeof i=="function"||i===n||i===o||I||i===s||i===m||i===f||w||i===S||p||b||g||typeof i=="object"&&i!==null&&(i.$$typeof===h||i.$$typeof===c||i.$$typeof===a||i.$$typeof===u||i.$$typeof===l||i.$$typeof===k||i.getModuleId!==void 0))}function j(i,_,O){var $=i.displayName;if($)return $;var X=_.displayName||_.name||"";return X!==""?O+"("+X+")":O}function A(i){return i.displayName||"Context"}function Y(i){if(i==null)return null;if(typeof i.tag=="number"&&C("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof i=="function")return i.displayName||i.name||null;if(typeof i=="string")return i;switch(i){case n:return"Fragment";case r:return"Portal";case o:return"Profiler";case s:return"StrictMode";case m:return"Suspense";case f:return"SuspenseList"}if(typeof i=="object")switch(i.$$typeof){case u:var _=i;return A(_)+".Consumer";case a:var O=i;return A(O._context)+".Provider";case l:return j(i,i.render,"ForwardRef");case c:var $=i.displayName||null;return $!==null?$:Y(i.type)||"Memo";case h:{var X=i,V=X._payload,N=X._init;try{return Y(N(V))}catch{return null}}}return null}var W=Object.assign,q=0,M,R,L,F,z,K,G;function re(){}re.__reactDisabledLog=!0;function ee(){{if(q===0){M=console.log,R=console.info,L=console.warn,F=console.error,z=console.group,K=console.groupCollapsed,G=console.groupEnd;var i={configurable:!0,enumerable:!0,value:re,writable:!0};Object.defineProperties(console,{info:i,log:i,warn:i,error:i,group:i,groupCollapsed:i,groupEnd:i})}q++}}function oe(){{if(q--,q===0){var i={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:W({},i,{value:M}),info:W({},i,{value:R}),warn:W({},i,{value:L}),error:W({},i,{value:F}),group:W({},i,{value:z}),groupCollapsed:W({},i,{value:K}),groupEnd:W({},i,{value:G})})}q<0&&C("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var le=y.ReactCurrentDispatcher,Se;function be(i,_,O){{if(Se===void 0)try{throw Error()}catch(X){var $=X.stack.trim().match(/\n( *(at )?)/);Se=$&&$[1]||""}return`
|
|
18
|
+
`+Se+i}}var lt=!1,Ue;{var Ls=typeof WeakMap=="function"?WeakMap:Map;Ue=new Ls}function Gt(i,_){if(!i||lt)return"";{var O=Ue.get(i);if(O!==void 0)return O}var $;lt=!0;var X=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var V;V=le.current,le.current=null,ee();try{if(_){var N=function(){throw Error()};if(Object.defineProperty(N.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(N,[])}catch(fe){$=fe}Reflect.construct(i,[],N)}else{try{N.call()}catch(fe){$=fe}i.call(N.prototype)}}else{try{throw Error()}catch(fe){$=fe}i()}}catch(fe){if(fe&&$&&typeof fe.stack=="string"){for(var B=fe.stack.split(`
|
|
19
|
+
`),te=$.stack.split(`
|
|
20
|
+
`),J=B.length-1,Z=te.length-1;J>=1&&Z>=0&&B[J]!==te[Z];)Z--;for(;J>=1&&Z>=0;J--,Z--)if(B[J]!==te[Z]){if(J!==1||Z!==1)do if(J--,Z--,Z<0||B[J]!==te[Z]){var ne=`
|
|
21
|
+
`+B[J].replace(" at new "," at ");return i.displayName&&ne.includes("<anonymous>")&&(ne=ne.replace("<anonymous>",i.displayName)),typeof i=="function"&&Ue.set(i,ne),ne}while(J>=1&&Z>=0);break}}}finally{lt=!1,le.current=V,oe(),Error.prepareStackTrace=X}var Ee=i?i.displayName||i.name:"",ur=Ee?be(Ee):"";return typeof i=="function"&&Ue.set(i,ur),ur}function zs(i,_,O){return Gt(i,!1)}function Ys(i){var _=i.prototype;return!!(_&&_.isReactComponent)}function We(i,_,O){if(i==null)return"";if(typeof i=="function")return Gt(i,Ys(i));if(typeof i=="string")return be(i);switch(i){case m:return be("Suspense");case f:return be("SuspenseList")}if(typeof i=="object")switch(i.$$typeof){case l:return zs(i.render);case c:return We(i.type,_,O);case h:{var $=i,X=$._payload,V=$._init;try{return We(V(X),_,O)}catch{}}}return""}var Ve=Object.prototype.hasOwnProperty,Jt={},Zt=y.ReactDebugCurrentFrame;function Fe(i){if(i){var _=i._owner,O=We(i.type,i._source,_?_.type:null);Zt.setExtraStackFrame(O)}else Zt.setExtraStackFrame(null)}function Bs(i,_,O,$,X){{var V=Function.call.bind(Ve);for(var N in i)if(V(i,N)){var B=void 0;try{if(typeof i[N]!="function"){var te=Error(($||"React class")+": "+O+" type `"+N+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof i[N]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw te.name="Invariant Violation",te}B=i[N](_,N,$,O,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(J){B=J}B&&!(B instanceof Error)&&(Fe(X),C("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",$||"React class",O,N,typeof B),Fe(null)),B instanceof Error&&!(B.message in Jt)&&(Jt[B.message]=!0,Fe(X),C("Failed %s type: %s",O,B.message),Fe(null))}}}var Ns=Array.isArray;function ft(i){return Ns(i)}function Xs(i){{var _=typeof Symbol=="function"&&Symbol.toStringTag,O=_&&i[Symbol.toStringTag]||i.constructor.name||"Object";return O}}function Us(i){try{return Qt(i),!1}catch{return!0}}function Qt(i){return""+i}function er(i){if(Us(i))return C("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Xs(i)),Qt(i)}var je=y.ReactCurrentOwner,Ws={key:!0,ref:!0,__self:!0,__source:!0},tr,rr,dt;dt={};function Vs(i){if(Ve.call(i,"ref")){var _=Object.getOwnPropertyDescriptor(i,"ref").get;if(_&&_.isReactWarning)return!1}return i.ref!==void 0}function Fs(i){if(Ve.call(i,"key")){var _=Object.getOwnPropertyDescriptor(i,"key").get;if(_&&_.isReactWarning)return!1}return i.key!==void 0}function Ks(i,_){if(typeof i.ref=="string"&&je.current&&_&&je.current.stateNode!==_){var O=Y(je.current.type);dt[O]||(C('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',Y(je.current.type),i.ref),dt[O]=!0)}}function Hs(i,_){{var O=function(){tr||(tr=!0,C("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",_))};O.isReactWarning=!0,Object.defineProperty(i,"key",{get:O,configurable:!0})}}function qs(i,_){{var O=function(){rr||(rr=!0,C("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",_))};O.isReactWarning=!0,Object.defineProperty(i,"ref",{get:O,configurable:!0})}}var Gs=function(i,_,O,$,X,V,N){var B={$$typeof:t,type:i,key:_,ref:O,props:N,_owner:V};return B._store={},Object.defineProperty(B._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(B,"_self",{configurable:!1,enumerable:!1,writable:!1,value:$}),Object.defineProperty(B,"_source",{configurable:!1,enumerable:!1,writable:!1,value:X}),Object.freeze&&(Object.freeze(B.props),Object.freeze(B)),B};function Js(i,_,O,$,X){{var V,N={},B=null,te=null;O!==void 0&&(er(O),B=""+O),Fs(_)&&(er(_.key),B=""+_.key),Vs(_)&&(te=_.ref,Ks(_,X));for(V in _)Ve.call(_,V)&&!Ws.hasOwnProperty(V)&&(N[V]=_[V]);if(i&&i.defaultProps){var J=i.defaultProps;for(V in J)N[V]===void 0&&(N[V]=J[V])}if(B||te){var Z=typeof i=="function"?i.displayName||i.name||"Unknown":i;B&&Hs(N,Z),te&&qs(N,Z)}return Gs(i,B,te,X,$,je.current,N)}}var mt=y.ReactCurrentOwner,nr=y.ReactDebugCurrentFrame;function _e(i){if(i){var _=i._owner,O=We(i.type,i._source,_?_.type:null);nr.setExtraStackFrame(O)}else nr.setExtraStackFrame(null)}var pt;pt=!1;function gt(i){return typeof i=="object"&&i!==null&&i.$$typeof===t}function sr(){{if(mt.current){var i=Y(mt.current.type);if(i)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+i+"`."}return""}}function
|
|
23
|
+
Check the render method of \``+i+"`."}return""}}function Zs(i){{if(i!==void 0){var _=i.fileName.replace(/^.*[\\\/]/,""),O=i.lineNumber;return`
|
|
24
24
|
|
|
25
|
-
Check your code at `+_+":"+O+"."}return""}}var
|
|
25
|
+
Check your code at `+_+":"+O+"."}return""}}var or={};function Qs(i){{var _=sr();if(!_){var O=typeof i=="string"?i:i.displayName||i.name;O&&(_=`
|
|
26
26
|
|
|
27
|
-
Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(!i._store||i._store.validated||i.key!=null)return;i._store.validated=!0;var O=
|
|
27
|
+
Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(!i._store||i._store.validated||i.key!=null)return;i._store.validated=!0;var O=Qs(_);if(or[O])return;or[O]=!0;var $="";i&&i._owner&&i._owner!==mt.current&&($=" It was passed a child from "+Y(i._owner.type)+"."),_e(i),C('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',O,$),_e(null)}}function ar(i,_){{if(typeof i!="object")return;if(ft(i))for(var O=0;O<i.length;O++){var $=i[O];gt($)&&ir($,_)}else if(gt(i))i._store&&(i._store.validated=!0);else if(i){var X=T(i);if(typeof X=="function"&&X!==i.entries)for(var V=X.call(i),N;!(N=V.next()).done;)gt(N.value)&&ir(N.value,_)}}}function eo(i){{var _=i.type;if(_==null||typeof _=="string")return;var O;if(typeof _=="function")O=_.propTypes;else if(typeof _=="object"&&(_.$$typeof===l||_.$$typeof===c))O=_.propTypes;else return;if(O){var $=Y(_);Bs(O,i.props,"prop",$,i)}else if(_.PropTypes!==void 0&&!pt){pt=!0;var X=Y(_);C("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",X||"Unknown")}typeof _.getDefaultProps=="function"&&!_.getDefaultProps.isReactClassApproved&&C("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function to(i){{for(var _=Object.keys(i.props),O=0;O<_.length;O++){var $=_[O];if($!=="children"&&$!=="key"){_e(i),C("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",$),_e(null);break}}i.ref!==null&&(_e(i),C("Invalid attribute `ref` supplied to `React.Fragment`."),_e(null))}}function cr(i,_,O,$,X,V){{var N=D(i);if(!N){var B="";(i===void 0||typeof i=="object"&&i!==null&&Object.keys(i).length===0)&&(B+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var te=Zs(X);te?B+=te:B+=sr();var J;i===null?J="null":ft(i)?J="array":i!==void 0&&i.$$typeof===t?(J="<"+(Y(i.type)||"Unknown")+" />",B=" Did you accidentally export a JSX literal instead of a component?"):J=typeof i,C("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",J,B)}var Z=Js(i,_,O,X,V);if(Z==null)return Z;if(N){var ne=_.children;if(ne!==void 0)if($)if(ft(ne)){for(var Ee=0;Ee<ne.length;Ee++)ar(ne[Ee],i);Object.freeze&&Object.freeze(ne)}else C("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ar(ne,i)}return i===n?to(Z):eo(Z),Z}}function ro(i,_,O){return cr(i,_,O,!0)}function no(i,_,O){return cr(i,_,O,!1)}var so=no,oo=ro;xe.Fragment=n,xe.jsx=so,xe.jsxs=oo}()),xe}(function(e){process.env.NODE_ENV==="production"?e.exports=dr():e.exports=mr()})(fr);const pr=we.Fragment,P=we.jsx,ae=we.jsxs;let gr=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,r)=>(r&=63,r<36?t+=r.toString(36):r<62?t+=(r-26).toString(36).toUpperCase():r>62?t+="-":t+="_",t),"");class hr{constructor(t,r,n=null){this._socket=t,this.userId=n,this.room=r,this.toUnregister=[()=>{this._socket.off(`${this.room}.isMaster`),this._socket.off(`${this.room}.roomJoined`),this._socket.off(`${this.room}._call`)}],this._left=!1,this.registeredRPC={},this._socket.on(`${this.room}._call`,async({callId:s,name:o,params:a})=>{try{const u=await this.registeredRPC[o](a);t.emit(`${this.room}._result.${s}`,{ok:u||null})}catch(u){t.emit(`${this.room}._result.${s}`,{err:`${u.message}`})}})}async _callServerRPC(t,r){const n=gr();return new Promise((s,o)=>{this._socket.once(`${this.room}._result.${n}`,a=>{a.hasOwnProperty("ok")?s(a.ok):o(a.err)}),this._socket.emit(`${this.room}._call`,{callId:n,name:t,params:r})})}leave(){this._left=!0,this.toUnregister.forEach(t=>{t()}),this._socket.emit(`${this.room}.leave`)}publish(t,r,n=!1){this._socket.emit(`${this.room}.publish`,{name:t,params:r,self:n})}subscribe(t,r){this._socket.on(`${this.room}.${t}`,r);const n=()=>{this._socket.off(`${this.room}.${t}`,r)};return this.toUnregister.push(n),n}async register(t,r,{invoke:n="single"}={}){this.registeredRPC[t]=r,await this._callServerRPC("register",{name:t,invoke:n});const s=()=>{if(this.registeredRPC[t]===r)return delete this.registeredRPC[t],this._callServerRPC("unregister",{name:t})};return this.toUnregister.push(s),s}async call(t,r){return await this._callServerRPC("call",{name:t,params:r})}}const vr=({socket:e,room:t,onJoined:r=()=>{},onMaster:n=()=>{},userId:s=null})=>{const o=new hr(e,t,s);return new Promise(a=>{let u=!0;e.on(`${t}.isMaster`,()=>{o._left||n(t)}),e.on(`${t}.roomJoined`,l=>{o._left||(o.userId=l,u=!1,r(o),a(o))}),e.on("connect",()=>{o._left||u||e.emit("joinSuperSocket",{room:t,userId:o.userId})}),e.emit("joinSuperSocket",{room:t,userId:s})})},Ke=d.createContext(),yr=()=>P("div",{style:{position:"absolute",top:"0",bottom:"0",width:"100%",display:"flex",justifyContent:"center",alignItems:"center"},children:P("h2",{children:"🌀 Loading..."})}),yt=({socket:e,room:t,channel:r="default",LoadingComponent:n=yr,children:s})=>{const[o,a]=d.useState(!1),[u,l]=d.useState(!1),[m,f]=d.useState(null),c=d.useRef(null),h=d.useRef(!1),S=d.useContext(Ke),v=d.useRef(!1);return d.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),d.useEffect(()=>{if(!e)return null;const E=()=>{console.log(`Disconnected from ${r}…`),h.current&&(a(!1),l(!1))};return e.on("disconnect",E),()=>{e.off("disconnect",E)}},[r,e]),d.useEffect(()=>e?(e.connected||e.connect(),console.log(`Try to connect to wire ${t} on channel ${r}`),v.current||(v.current=!0,vr({socket:e,room:t,onMaster:()=>{console.log(`Is now master on channel ${r}…`),h.current&&l(!0)},onJoined:E=>{console.log(`Connected on channel ${r}…`),c.current=E,h.current&&(f(E),a(!0))}})),()=>{var E;(E=c.current)==null||E.leave()}):null,[r,t,e]),!o||!m?P(n,{}):P(Ke.Provider,{value:{...S,[r]:{wire:m,joined:o,isMaster:u,room:t}},children:s})},Ie=(e="default")=>(d.useContext(Ke)||{})[e],St=e=>{let t;const r=new Set,n=(l,m)=>{const f=typeof l=="function"?l(t):l;if(!Object.is(f,t)){const c=t;t=m??typeof f!="object"?f:Object.assign({},t,f),r.forEach(h=>h(t,c))}},s=()=>t,u={setState:n,getState:s,subscribe:l=>(r.add(l),()=>r.delete(l)),destroy:()=>{({BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0}&&"production")!=="production"&&console.warn("[DEPRECATED] The destroy method will be unsupported in the future version. You should use unsubscribe function returned by subscribe. Everything will be garbage collected if store is garbage collected."),r.clear()}};return t=e(n,s,u),u},De=e=>e?St(e):St;var He={},Sr={get exports(){return He},set exports(e){He=e}},qe={},Re={},br={get exports(){return Re},set exports(e){Re=e}},Ge={};/**
|
|
28
28
|
* @license React
|
|
29
29
|
* use-sync-external-store-shim.production.min.js
|
|
30
30
|
*
|
|
@@ -32,7 +32,7 @@ Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(
|
|
|
32
32
|
*
|
|
33
33
|
* This source code is licensed under the MIT license found in the
|
|
34
34
|
* LICENSE file in the root directory of this source tree.
|
|
35
|
-
*/var bt;function _r(){if(bt)return Ge;bt=1;var e=d;function t(c,h){return c===h&&(c!==0||1/c===1/h)||c!==c&&h!==h}var r=typeof Object.is=="function"?Object.is:t,n=e.useState,
|
|
35
|
+
*/var bt;function _r(){if(bt)return Ge;bt=1;var e=d;function t(c,h){return c===h&&(c!==0||1/c===1/h)||c!==c&&h!==h}var r=typeof Object.is=="function"?Object.is:t,n=e.useState,s=e.useEffect,o=e.useLayoutEffect,a=e.useDebugValue;function u(c,h){var S=h(),v=n({inst:{value:S,getSnapshot:h}}),E=v[0].inst,T=v[1];return o(function(){E.value=S,E.getSnapshot=h,l(E)&&T({inst:E})},[c,S,h]),s(function(){return l(E)&&T({inst:E}),c(function(){l(E)&&T({inst:E})})},[c]),a(S),S}function l(c){var h=c.getSnapshot;c=c.value;try{var S=h();return!r(c,S)}catch{return!0}}function m(c,h){return h()}var f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?m:u;return Ge.useSyncExternalStore=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:f,Ge}var Je={};/**
|
|
36
36
|
* @license React
|
|
37
37
|
* use-sync-external-store-shim.development.js
|
|
38
38
|
*
|
|
@@ -40,7 +40,7 @@ Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(
|
|
|
40
40
|
*
|
|
41
41
|
* This source code is licensed under the MIT license found in the
|
|
42
42
|
* LICENSE file in the root directory of this source tree.
|
|
43
|
-
*/var _t;function Er(){return _t||(_t=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=d,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function r(x){{for(var p=arguments.length,b=new Array(p>1?p-1:0),g=1;g<p;g++)b[g-1]=arguments[g];n("error",x,b)}}function n(x,p,b){{var g=t.ReactDebugCurrentFrame,w=g.getStackAddendum();w!==""&&(p+="%s",b=b.concat([w]));var I=b.map(function(k){return String(k)});I.unshift("Warning: "+p),Function.prototype.apply.call(console[x],console,I)}}function
|
|
43
|
+
*/var _t;function Er(){return _t||(_t=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=d,t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function r(x){{for(var p=arguments.length,b=new Array(p>1?p-1:0),g=1;g<p;g++)b[g-1]=arguments[g];n("error",x,b)}}function n(x,p,b){{var g=t.ReactDebugCurrentFrame,w=g.getStackAddendum();w!==""&&(p+="%s",b=b.concat([w]));var I=b.map(function(k){return String(k)});I.unshift("Warning: "+p),Function.prototype.apply.call(console[x],console,I)}}function s(x,p){return x===p&&(x!==0||1/x===1/p)||x!==x&&p!==p}var o=typeof Object.is=="function"?Object.is:s,a=e.useState,u=e.useEffect,l=e.useLayoutEffect,m=e.useDebugValue,f=!1,c=!1;function h(x,p,b){f||e.startTransition!==void 0&&(f=!0,r("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var g=p();if(!c){var w=p();o(g,w)||(r("The result of getSnapshot should be cached to avoid an infinite loop"),c=!0)}var I=a({inst:{value:g,getSnapshot:p}}),k=I[0].inst,D=I[1];return l(function(){k.value=g,k.getSnapshot=p,S(k)&&D({inst:k})},[x,g,p]),u(function(){S(k)&&D({inst:k});var j=function(){S(k)&&D({inst:k})};return x(j)},[x]),m(g),g}function S(x){var p=x.getSnapshot,b=x.value;try{var g=p();return!o(b,g)}catch{return!0}}function v(x,p,b){return p()}var E=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",T=!E,y=T?v:h,C=e.useSyncExternalStore!==void 0?e.useSyncExternalStore:y;Je.useSyncExternalStore=C,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Je}var Et;function wt(){return Et||(Et=1,function(e){process.env.NODE_ENV==="production"?e.exports=_r():e.exports=Er()}(br)),Re}/**
|
|
44
44
|
* @license React
|
|
45
45
|
* use-sync-external-store-shim/with-selector.production.min.js
|
|
46
46
|
*
|
|
@@ -48,7 +48,7 @@ Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(
|
|
|
48
48
|
*
|
|
49
49
|
* This source code is licensed under the MIT license found in the
|
|
50
50
|
* LICENSE file in the root directory of this source tree.
|
|
51
|
-
*/var Ct;function wr(){if(Ct)return qe;Ct=1;var e=d,t=wt();function r(m,f){return m===f&&(m!==0||1/m===1/f)||m!==m&&f!==f}var n=typeof Object.is=="function"?Object.is:r,
|
|
51
|
+
*/var Ct;function wr(){if(Ct)return qe;Ct=1;var e=d,t=wt();function r(m,f){return m===f&&(m!==0||1/m===1/f)||m!==m&&f!==f}var n=typeof Object.is=="function"?Object.is:r,s=t.useSyncExternalStore,o=e.useRef,a=e.useEffect,u=e.useMemo,l=e.useDebugValue;return qe.useSyncExternalStoreWithSelector=function(m,f,c,h,S){var v=o(null);if(v.current===null){var E={hasValue:!1,value:null};v.current=E}else E=v.current;v=u(function(){function y(g){if(!C){if(C=!0,x=g,g=h(g),S!==void 0&&E.hasValue){var w=E.value;if(S(w,g))return p=w}return p=g}if(w=p,n(x,g))return w;var I=h(g);return S!==void 0&&S(w,I)?w:(x=g,p=I)}var C=!1,x,p,b=c===void 0?null:c;return[function(){return y(f())},b===null?void 0:function(){return y(b())}]},[f,c,h,S]);var T=s(m,v[0],v[1]);return a(function(){E.hasValue=!0,E.value=T},[T]),l(T),T},qe}var Ze={};/**
|
|
52
52
|
* @license React
|
|
53
53
|
* use-sync-external-store-shim/with-selector.development.js
|
|
54
54
|
*
|
|
@@ -56,7 +56,7 @@ Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(
|
|
|
56
56
|
*
|
|
57
57
|
* This source code is licensed under the MIT license found in the
|
|
58
58
|
* LICENSE file in the root directory of this source tree.
|
|
59
|
-
*/var xt;function Cr(){return xt||(xt=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=d,t=wt();function r(f,c){return f===c&&(f!==0||1/f===1/c)||f!==f&&c!==c}var n=typeof Object.is=="function"?Object.is:r,o=t.useSyncExternalStore,s=e.useRef,a=e.useEffect,u=e.useMemo,l=e.useDebugValue;function m(f,c,h,S,v){var E=s(null),T;E.current===null?(T={hasValue:!1,value:null},E.current=T):T=E.current;var y=u(function(){var b=!1,g,w,I=function(A){if(!b){b=!0,g=A;var Y=S(A);if(v!==void 0&&T.hasValue){var W=T.value;if(v(W,Y))return w=W,W}return w=Y,Y}var J=g,M=w;if(n(J,A))return M;var $=S(A);return v!==void 0&&v(M,$)?M:(g=A,w=$,$)},k=h===void 0?null:h,D=function(){return I(c())},j=k===null?void 0:function(){return I(k())};return[D,j]},[c,h,S,v]),C=y[0],x=y[1],p=o(f,C,x);return a(function(){T.hasValue=!0,T.value=p},[p]),l(p),p}Ze.useSyncExternalStoreWithSelector=m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Ze}(function(e){process.env.NODE_ENV==="production"?e.exports=wr():e.exports=Cr()})(Sr);const xr=me(He),{useSyncExternalStoreWithSelector:Ir}=xr;function $e(e,t=e.getState,r){const n=Ir(e.subscribe,e.getState,e.getServerState||e.getState,t,r);return d.useDebugValue(n),n}const he=(e,t)=>e.classList&&e.classList.contains(t),Oe=(e,t)=>he(e,t)?e:e.parentNode?Oe(e.parentNode,t):!1,Ae=([e,t],[r,n])=>{const o=Math.abs(e-r),s=Math.abs(t-n);return Math.hypot(o,s)},It=(e,t,r)=>{const n=r*Math.PI/180,o=e*Math.cos(n)-t*Math.sin(n),s=e*Math.sin(n)+t*Math.cos(n);return[o,s]},Qe=([e,t],{scale:r,rotate:n,translateX:o,translateY:s})=>{const a=(e-o)/r,u=(t-s)/r;return It(a,u,-n)},Le=([e,t],{scale:r,rotate:n,translateX:o,translateY:s})=>{const[a,u]=It(e,t,n);return[a*r+o,u*r+s]},Ot=(e,t,r,n)=>{const o=e.x,s=e.y,a=t.x,u=t.y,l=r.x,m=r.y,f=a-o,c=u-s,h=o-l,S=s-m,v=f*f+c*c,E=2*(h*f+S*c),T=h*h+S*S-n*n,y=E*E-4*v*T;if(y<0)return[];const C=(-E+Math.sqrt(y))/(2*v),x=(-E-Math.sqrt(y))/(2*v),p=[];return C>=0&&C<=1&&p.push({x:o+C*f,y:s+C*c}),x>=0&&x<=1&&p.push({x:o+x*f,y:s+x*c}),p},et=(e,t)=>e.x>t.left&&e.x<t.left+t.width&&e.y>t.top&&e.y<t.top+t.height,Or=(e,t)=>Array.from(e.querySelectorAll(".corner")).every(n=>{const{top:o,left:s}=n.getBoundingClientRect();return et({x:s,y:o},t)}),Tr=(e,t)=>{const r=t.getBoundingClientRect();return Or(e,r)},ze=(e,t)=>{try{const r=document.getElementById(`${e}__${t}`);return r||console.error(`Missing item ${t}`),r}catch{console.error(`Error while getting item with id ${t} inside wrapper`,e);return}},Te=e=>{var r,n;const t=(r=e==null?void 0:e.dataset)==null?void 0:r.id;return t||console.error("getIdFromElem call fails",e,JSON.stringify(e==null?void 0:e.dataset),(n=e==null?void 0:e.dataset)==null?void 0:n.id),t},kr=(e,t)=>{const r=e.reduce((n,o)=>{const s=ze(t,o);if(!s)return n||null;const{left:a,right:u,top:l,bottom:m}=s.getBoundingClientRect();let f;return n?f=n:f={left:a,top:l,right:u,bottom:m},f.left=Math.min(a,f.left),f.top=Math.min(l,f.top),f.right=Math.max(u,f.right),f.bottom=Math.max(m,f.bottom),f},null);return r&&(r.width=r.right-r.left,r.height=r.bottom-r.top,r)},Tt=(e,t,r=null)=>(r===null&&(r=new Set),!Array.isArray(t)||t.length===0?[]:t.map(n=>r.has(n)?[]:(r.add(n),e[n]?[n,...Tt(e,e[n].linkedItems,r)]:[])).flat()),kt=(e,t,r)=>{const n=new Set(Tt(e,r));return t.filter(o=>n.has(o))},Pr=({x:e,y:t,width:r,height:n},{type:o="grid",size:s=1,offset:a={x:0,y:0}})=>{const[u,l]=[e+r/2-a.x,t+n/2-a.y];let m,f,c,h,S,v,E,T,y,C;const x=s/1.1547;switch(o){case"grid":m=Math.round(u/s)*s,f=Math.round(l/s)*s;break;case"hexH":c=2*x,h=3*s,S=Math.round(u/c)*c,E=Math.round(l/h)*h,v=S>u?S-x:S+x,T=E>l?E-1.5*s:E+1.5*s,y=Math.hypot(S-u,E-l),C=Math.hypot(v-u,T-l),y<C?(m=S,f=E):(m=v,f=T);break;case"hexV":c=3*s,h=2*x,S=Math.round(u/c)*c,E=Math.round(l/h)*h,v=S>u?S-1.5*s:S+1.5*s,T=E>l?E-x:E+x,y=Math.hypot(S-u,E-l),C=Math.hypot(v-u,T-l),y<C?(m=S,f=E):(m=v,f=T);break;default:m=e+r/2,f=t+n/2}return{x:m+a.x-r/2,y:f+a.y-n/2}},Pt=["#037758","#99092a","#067070","#c6650f","#008726","#3d7004","#348402","#057f58","#b58612","#c44c01","#0a7704","#0e910e","#027377","#c99e02","#054160","#157a01","#b10de2","#0d6289","#bc5d03","#ba0cd1","#d39f10","#0c4c7a","#460782","#a51f10","#cecb10","#9b0943","#607f0c","#007a4b","#bf0daa","#af0ad8"],Mt=()=>Pt[Math.floor(Math.random()*Pt.length)],Mr=!1,tt=({wire:e,storeName:t,noSync:r=[],defaultValue:n},o)=>(s,a,u)=>{s({ready:!1});const l=[];(async()=>{try{const S=await e.call(`${t}_getValue`);Mr&&console.log("init from peer with value",S),s(v=>({...v,...S}))}catch{n!==void 0&&s(n)}l.push(await e.register(`${t}_getValue`,()=>Object.fromEntries(Object.entries(a()).filter(([S,v])=>typeof v!="function"&&!r.includes(S))),{invoke:"first"})),l.push(e.subscribe(`${t}_call`,([S,v])=>{c[S](...v)})),s({ready:!0})})();const f=o(s,a,u),c={...f},h=Object.fromEntries(Object.entries(f).map(([S,v])=>typeof v=="function"&&!S.startsWith("get")&&!r.includes(S)?[S,(...T)=>{const y=v(...T);return e.publish(`${t}_call`,[S,T]),y}]:[S,v]));return h.unsub=()=>{l.forEach(S=>S())},h};function Ye(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[n,o]of e)if(!Object.is(o,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(t,r[n])||!Object.is(e[r[n]],t[r[n]]))return!1;return!0}const jt=d.createContext(),jr=(e,t)=>({items:{},getItems:()=>t().items,setItems:r=>e({items:r}),updateItems:(r,n=!1)=>e(o=>n?{items:Object.fromEntries(Object.entries(o.items).map(([a,u])=>r[a]?[a,{...u,...r[a]}]:[a,u]))}:{items:{...o.items,...r}}),moveItems:(r,n)=>e(({items:o})=>{const s={...o};return r.forEach(a=>{const u=o[a];u&&(s[a]={...u,x:(u.x||0)+n.x,y:(u.y||0)+n.y,moving:!0})}),{items:s}})}),Dr=(e,t)=>({itemIds:[],setItemIds:r=>e({itemIds:r}),getItemIds:()=>t().itemIds,insert:(r,n)=>e(o=>{const s=[...o.itemIds];return s.splice(r,0,n),{itemIds:s}}),remove:r=>e(n=>{const o=[...n.itemIds];return o.splice(r,1),{itemIds:o}}),updateItemIds:(r,n)=>e(o=>{const s=[...o.itemIds];return s[r]=n,{items:s}}),updateManyItemIds:r=>e(n=>({items:n.itemIds.map((o,s)=>r[s]!==void 0?r[s]:o)}))}),Rr=(e,t)=>({removeItemsById:r=>e(n=>({itemIds:n.itemIds.filter(o=>!r.includes(o)),items:Object.fromEntries(Object.entries(n.items).filter(([o])=>!r.includes(o)))})),getItemList:()=>{const r=t().items;return t().itemIds.map(n=>r[n])},setItemList:r=>e({items:Object.fromEntries(r.map(n=>[n.id,n])),itemIds:r.map(({id:n})=>n)}),insertItems:(r,n)=>e(o=>{let s;const a=r.map(({id:u})=>u);if(n){const u=o.itemIds.findIndex(l=>l===n);s=[...o.itemIds],s.splice(u,0,...a)}else s=[...o.itemIds,...a];return{items:{...o.items,...Object.fromEntries(r.map(u=>[u.id,u]))},itemIds:s}})}),$r=(e,t)=>({boardConfig:{},getBoardConfig:()=>t().boardConfig,setBoardConfig:r=>e({boardConfig:r}),updateBoardConfig:r=>e(n=>({boardConfig:{...n.boardConfig,...r}}))}),Ar=(e,t)=>({session:{},getSessionInfo:()=>t().session,setSessionInfo:r=>e({session:r}),updateSessionInfo:r=>e(n=>({session:{...n.session,...r}}))}),Dt=({storeName:e,children:t,defaultValue:r})=>{const{wire:n}=Ie("room"),[o,s]=d.useState(!1),[a]=d.useState(()=>De(tt({wire:n,storeName:e,defaultValue:r},(...u)=>({...jr(...u),...Dr(...u),...Rr(...u),...$r(...u),...Ar(...u)}))));return d.useEffect(()=>{const u=a.subscribe(l=>{l.ready&&(u(),s(!0))})},[a]),o?P(jt.Provider,{value:a,children:t}):null},oe=(e,t)=>{const r=d.useContext(jt);return $e(r,e,t||Ye)},Lr=()=>{const[e,t]=oe(n=>[n.itemIds,n.items]);return d.useMemo(()=>e.map(n=>t[n]),[e,t])},zr=()=>{const[e,t,r]=oe(a=>[a.items,a.itemIds,a.getItemList]),[n,o]=d.useState(r()),[,s]=d.useTransition();return d.useEffect(()=>{const a=r();s(()=>{o(a)})},[e,t,r]),n},Rt=5e4,$t=d.createContext(),Yr=(e,t)=>({config:{itemTemplates:{},actions:{},uid:null,itemExtent:{x:0,y:0,radius:0},boardWrapperRect:{},boardSize:Rt},updateConfiguration:r=>e(n=>({config:{...n.config,...r}})),getConfiguration:()=>t().config}),Br=(e,t)=>({boardState:{movingItems:!1,selecting:!1,zooming:!1,panning:!1,translateX:0,translateY:0,scale:1,rotate:0},updateBoardState:r=>e(n=>({boardState:{...n.boardState,...r}})),getBoardState:()=>t().boardState}),Nr=(e,t)=>({interactions:{},getInteractions:()=>t().interactions,register:(r,n)=>e(o=>{const s=[...o.interactions[r]||[]];return s.push(n),{interactions:{...o.interactions,[r]:s}}}),unregister:(r,n)=>e(o=>{const s=(o.interactions[r]||[]).filter(a=>a!==n);return{interactions:{...o.interactions,[r]:s}}}),callInteractions:(r,n)=>{t().interactions[r]&&t().interactions[r].forEach(o=>{setTimeout(()=>o(n),0)})}}),Xr=(e,t)=>({selection:[],setSelection:r=>e(n=>JSON.stringify(n.selection)!==JSON.stringify(r)?{selection:r}:{}),getSelection:()=>t().selection,select:r=>e(n=>({selection:[...n.selection,...r]})),unselect:r=>e(n=>({selection:n.selection.filter(o=>!r.includes(o))})),clear:()=>e(r=>r.selection.length>0?{selection:[]}:{}),reverse:()=>e(r=>{const n=[...r.selection];return n.reverse(),{selection:n}}),selectionBox:null,setSelectionBox:r=>e(n=>{const o=n.selectionBox;return!o||!r||o.top!==r.top||o.left!==r.left||o.width!==r.width||o.height!==r.height?{selectionBox:r}:{}})}),At=({children:e})=>{const[t]=d.useState(()=>De((...r)=>({...Yr(...r),...Br(...r),...Nr(...r),...Xr(...r)})));return P($t.Provider,{value:t,children:e})},Q=(e,t)=>{const r=d.useContext($t);return $e(r,e,t||Ye)},Ur=()=>{const[e]=Q(t=>[t.selection]);return e},Wr=()=>{const[e]=Q(t=>[t.getSelection]);return e};function rt(e){const t=d.useRef(e);return t.current=e,d.useMemo(()=>Object.freeze({get current(){return t.current}}),[])}function Vr(e){const t=rt(e);d.useEffect(()=>()=>{t.current()},[])}function nt(e,t,r,n=0){const o=d.useRef(),s=d.useRef(),a=d.useRef(),u=()=>{o.current&&(clearTimeout(o.current),o.current=void 0),s.current&&(clearTimeout(s.current),s.current=void 0)};return Vr(u),d.useMemo(()=>{const l=()=>{if(!a.current)return;const f=a.current;a.current=void 0,e.apply(f.this,f.args),u()},m=function(...f){o.current&&clearTimeout(o.current),a.current={args:f,this:this},o.current=setTimeout(l,r),n>0&&!s.current&&(s.current=setTimeout(l,n))};return Object.defineProperties(m,{length:{value:e.length},name:{value:`${e.name||"anonymous"}__debounced__${r}`}}),m},[r,n,...t])}const Fr=100,Kr=1e3,Hr=.8;let ot=!1;const qr=({x:e,y:t,scale:r,rotate:n,itemExtent:o,boardWrapperRect:s,boardSize:a})=>{let[u,l]=[e,t];const m=Qe([s.width/2,s.height/2],{translateX:u,translateY:l,scale:r,rotate:n}),f={x:o.x+a/2,y:o.y+a/2},c={x:a/2,y:a/2},h=Ae(m,[f.x,f.y]),S=Math.min(s.width,s.height),v=o.radius+S/2/r-Fr/r;if(h>v){const y=Ot({x:m[0],y:m[1]},f,f,v-1/r)[0],[C,x]=Le([-y.x,-y.y],{translateX:s.width/2,translateY:s.height/2,scale:r,rotate:n});u=C,l=x}const E=Ae(m,[c.x,c.y]),T=a/2-Ae([0,0],[s.width,s.height])/r;if(E>T){const y=Ot({x:m[0],y:m[1]},c,c,T-1/r)[0];if(y){const[C,x]=Le([-y.x,-y.y],{translateX:s.width/2,translateY:s.height/2,scale:r,rotate:n});u=C,l=x}}return[u,l]},ve=()=>{const[e,t,r,n,o]=Q(p=>[p.getBoardState,p.updateBoardState,p.config.itemExtent,p.getConfiguration,p.updateConfiguration]),s=d.useRef([.15,5]),[a]=oe(p=>[p.getItemList]),u=d.useCallback(()=>{const{translateX:p,translateY:b,scale:g,rotate:w}=e();return{translateX:p,translateY:b,scale:g,rotate:w}},[e]),l=d.useCallback((p,b)=>Qe([p,b],e()),[e]),m=d.useCallback((p,b)=>Le([p,b],e()),[e]),f=d.useCallback((p,b)=>{const{scale:g,rotate:w}=e();return Qe([p,b],{translateX:0,translateY:0,rotate:w,scale:g})},[e]),c=d.useCallback(p=>p>s.current[1]?s.current[1]:p<s.current[0]?s.current[0]:p,[]),h=d.useCallback(p=>{const{itemExtent:b,boardWrapperRect:g,boardSize:w}=n(),I=e(),{translateX:k,translateY:D,scale:j,rotate:A}={...I,...p(I)};ot&&console.log("New expected values: ",k,D,j,A);const Y=c(j);let[W,J]=[k,D];(k!==I.translateX||D!==I.translateY)&&([W,J]=qr({x:k,y:D,scale:Y,rotate:A,itemExtent:b,boardWrapperRect:g,boardSize:w})),ot&&console.log("New fixed values: ",W,J,Y,A),t({translateX:W,translateY:J,scale:Y,rotate:A})},[c,e,n,t]),S=d.useCallback(p=>{let b=g=>({...g,...p});typeof p=="function"&&(b=p),h(g=>({...g,...b({translateX:g.translateX,translateY:g.translateY})}))},[h]),v=d.useCallback(({to:p,factor:b})=>{const{boardWrapperRect:g}=n();let w=p;w||(w={x:g.left+g.width/2,y:g.top+g.height/2});const I=e(),k=c(I.scale*b),D=w.x-g.left,j=w.y-g.top,A=D-(D-I.translateX)*k/I.scale,Y=j-(j-I.translateY)*k/I.scale;h(W=>({...W,translateX:A,translateY:Y,scale:k}))},[c,e,n,h]),E=d.useCallback(({x:p,y:b,radius:g})=>{const{rotate:w}=e(),{boardWrapperRect:I,boardSize:k}=n(),D=I.width/(g*2),j=I.height/(g*2),A=c(Math.min(D,j)*Hr),[Y,W]=Le([-k/2-p,-k/2-b],{translateX:I.width/2,translateY:I.height/2,scale:A,rotate:w});h(J=>({...J,translateX:Y,translateY:W,scale:A}))},[c,e,n,h]),T=d.useCallback(()=>{const{boardWrapperRect:p,boardSize:b}=n(),[g,w]=l(p.width/2,p.height/2);return{x:g-b/2,y:w-b/2}},[l,n]),y=d.useCallback(()=>{const p=a(),{boardSize:b,uid:g}=n(),w=p.reduce((k,D)=>{const j=ze(g,D.id);return j&&(k.left=Math.min(D.x,k.left),k.top=Math.min(D.y,k.top),k.right=Math.max(D.x+j.offsetWidth,k.right),k.bottom=Math.max(D.y+j.offsetHeight,k.bottom)),k},{left:b/2,top:b/2,right:-b/2,bottom:-b/2}),I={x:(w.right+w.left)/2,y:(w.bottom+w.top)/2};I.radius=Math.max(Ae([I.x,I.y],[w.left,w.top]),Kr),o({itemExtent:I})},[n,a,o]),C=d.useCallback(p=>{let b=()=>p;typeof p=="function"&&(b=p),h(g=>({...g,rotate:b(g.rotate)})),y(),E(r)},[r,h,y,E]),x=nt(()=>y(),[y],200);return d.useEffect(()=>{window.debugUpdateExtent=()=>y(),window.debugDisplayExtent=()=>console.log(n().itemExtent),window.debugSetDebug=()=>{ot=!0}},[n,y]),{setDim:h,rotateBoard:C,moveBoard:S,getDim:u,zoomTo:v,zoomToCenter:v,zoomToExtent:E,getCenter:T,updateItemExtent:x,vectorFromWrapperToBoard:f,fromWrapperToBoard:l,fromBoardToWrapper:m}},st=e=>{const[t,r,n]=Q(({register:a,unregister:u,callInteractions:l})=>[a,u,l]),o=d.useCallback(a=>(t(e,a),()=>{r(e,a)}),[e,t,r]),s=d.useCallback(a=>{n(e,a)},[n,e]);return{register:o,call:s}},Be=()=>{const{call:e}=st("place"),{call:t}=st("delete"),{getCenter:r,updateItemExtent:n}=ve(),[o,s,a,u]=Q(M=>[M.clear,M.reverse,M.unselect,M.getConfiguration]),{getItems:l,getItemIds:m,setItemIds:f,updateItems:c,moveItems:h,removeItemsById:S,getItemList:v,insertItems:E,setItemList:T}=oe(({getItems:M,getItemIds:$,setItemIds:B,updateItems:F,moveItems:L,removeItemsById:K,getItemList:q,insertItems:re,setItemList:ee})=>({getItems:M,getItemIds:$,setItemIds:B,updateItems:F,moveItems:L,removeItemsById:K,getItemList:q,insertItems:re,setItemList:ee})),y=d.useCallback((M,$,B=!1)=>{let F=$;typeof $=="object"&&(F=()=>$);const L=m().filter(ee=>M.includes(ee)),K=l(),q=L.map(ee=>{const se=K[ee];return B?[ee,F(se)]:[ee,F({...se})]}).filter(([,ee])=>ee);if(q.length===0)return;const re=Object.fromEntries(q);c(re,B),n()},[m,l,n,c]),C=d.useCallback(M=>{T(M),o(),n()},[o,T,n]),x=d.useCallback((M,$,B=!1)=>{y([M],$,B)},[y]),p=d.useCallback((M,$)=>{h(kt(l(),m(),M),$)},[m,l,h]),b=d.useCallback(M=>{const $=m(),B=$.filter(L=>!M.includes(L)),F=$.filter(L=>M.includes(L));f([...B,...F])},[m,f]),g=d.useCallback((M,{type:$,size:B}={})=>{const{uid:F}=u();y(M,L=>{const K=ze(F,L.id);if(!K)return;const q={type:$||"grid",size:B||1,offset:{x:0,y:0},...L.grid};return Pr({x:L.x,y:L.y,width:K.clientWidth,height:K.clientHeight},q)},!0)},[u,y]),w=d.useCallback((M,$)=>{const B=kt(l(),m(),M);b(B),y(B,{moving:!1},!0),g(B,$),e(M),n()},[y,e,m,l,b,g,n]),I=d.useCallback(M=>{f(M)},[f]),k=d.useCallback(M=>{const $=m(),B=$.filter(L=>M.includes(L)),F=$.map(L=>M.includes(L)?B.pop():L);f(F),s()},[m,s,f]),D=d.useCallback((M,$)=>{const B=l(),F=Object.fromEntries($.map((q,re)=>{const ee=B[M[re]];return[q,{x:ee.x,y:ee.y}]}));y(M,q=>F[q.id],!0);const L=Object.fromEntries(M.map((q,re)=>[q,$[re]])),K=m().map(q=>M.includes(q)?L[q]:q);f(K)},[l,y,m,f]),j=d.useCallback((M,$)=>{const B=r(),F=M.map((L,K)=>!L.x||!L.y?{...L,x:B.x+2*K,y:B.y+2*K}:L);E(F,$),w(M.map(({id:L})=>L))},[r,E,w]),A=d.useCallback((M,$)=>{j([M],$)},[j]),Y=d.useCallback(M=>{a(M),S(M),t(M)},[a,S,t]),W=d.useCallback(M=>{const $=l();return M.map(B=>$[B])},[l]),J=d.useCallback(({target:M,clientX:$,clientY:B},{returnLocked:F=!1,passLocked:L=!1}={})=>{if(["INPUT","TEXTAREA"].includes(M.tagName))return null;const K=Oe(M,"item");if(K){if(he(K,"selected"))return K;if(!L&&he(K,"locked")&&!he(M,"passthrough"))return F?K:null;if(he(M,"passthrough")){const q=m(),{uid:re}=u(),ee=q.reduce((se,le)=>{const Se=ze(re,le),be=Se.getBoundingClientRect();return et({x:$,y:B},be)&&se.unshift(Se),se},[]);for(let se=0;se<ee.length;se+=1){const le=ee[se];if(le!==K&&(L||!he(le,"locked")))return le}return null}}return K},[u,m]);return{putItemsOnTop:b,batchUpdateItems:y,updateItemOrder:I,moveItems:p,placeItems:w,updateItem:x,swapItems:D,reverseItemsOrder:k,setItemList:C,pushItem:A,pushItems:j,removeItems:Y,getItemList:v,findElementUnderPointer:J,getItems:W}};var Gr=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var n,o,s;if(Array.isArray(t)){if(n=t.length,n!=r.length)return!1;for(o=n;o--!==0;)if(!e(t[o],r[o]))return!1;return!0}if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(o of t.entries())if(!r.has(o[0]))return!1;for(o of t.entries())if(!e(o[1],r.get(o[0])))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(o of t.entries())if(!r.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(r)){if(n=t.length,n!=r.length)return!1;for(o=n;o--!==0;)if(t[o]!==r[o])return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(s=Object.keys(t),n=s.length,n!==Object.keys(r).length)return!1;for(o=n;o--!==0;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=n;o--!==0;){var a=s[o];if(!e(t[a],r[a]))return!1}return!0}return t!==t&&r!==r};function Jr(e,t,r,n=0){d.useEffect(nt(e,t,r,n),t)}const Zr=(e,t)=>{if(e.type in t){const r=t[e.type].defaultActions;return typeof r=="function"?r(e):r}return[]},Lt=(e,t)=>{const{actions:r=Zr(e,t)}=e;return r.map(n=>typeof n=="string"?{name:n}:n)},Qr=()=>{const[e,t]=oe(c=>[c.items,c.getItems]),[r,n,o]=Q(c=>[c.config.itemTemplates,c.selection,c.getSelection]),[s,a]=d.useState([]),u=d.useRef(!1),[,l]=d.useTransition();d.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const m=d.useCallback(c=>{const h=t();if(c)return[c,c.map(v=>h[v])];const S=o();return[S,S.map(v=>h[v])]},[t,o]),f=d.useCallback(()=>{const[c,h]=m();if(c.length>0){if(!u.current)return;const S=h.reduce((v,E)=>{const T=Lt(E,r);return v.filter(y=>T.some(C=>Gr(y,C)))},Lt(h[0],r));l(()=>{a(S)})}else l(()=>{a([])})},[m,r]);return Jr(()=>f(),[e,n,f],100),{availableActions:s}},en=()=>{const[e]=Q(t=>[t.selectionBox]);return e};let pe=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,r)=>(r&=63,r<36?t+=r.toString(36):r<62?t+=(r-26).toString(36).toUpperCase():r>62?t+="-":t+="_",t),"");const zt=d.createContext(),it=e=>{localStorage.setItem("user",JSON.stringify(e))},tn=()=>{if(localStorage.user){const t={name:"Player",color:Mt(),uid:pe(),...JSON.parse(localStorage.user)};return it(t),t}const e={name:"Player",color:Mt(),uid:pe()};return it(e),e},rn=e=>(t,r)=>({isSpaceMaster:!1,users:{},getUser:()=>r().users[e],getUsers:()=>r().users,getUserList:()=>Object.values(r().users),getLocalUsers:()=>{if(!r().users[e])return[];const{space:n}=r().users[e];return r().getUserList().filter(({space:o})=>o===n)},addUser:n=>t(o=>({users:{...o.users,[n.id]:n}})),updateUser:(n,o)=>t(s=>{if(!s.users[n])return{};const a={...s.users[n],...o,id:n,uid:s.users[n].uid};return a.id===e&&it(a),setTimeout(()=>r().electSpaceMaster(),100),{users:{...s.users,[n]:a}}}),removeUser:n=>t(o=>{const s={...o.users};return delete s[n],setTimeout(()=>r().electSpaceMaster(),100),{users:s}}),updateCurrentUser:n=>r().updateUser(e,n),joinSpace:n=>r().updateUser(e,{space:n,spaceJoinedTimestamp:Date.now()}),electSpaceMaster:()=>{const n=r().getLocalUsers(),o={uid:null,timestamp:Date.now()};Object.values(n).forEach(({spaceJoinedTimestamp:s,id:a})=>{s<o.timestamp&&(o.id=a,o.timestamp=s)}),t({isSpaceMaster:o.id===e})}}),nn=e=>({cursors:{},moveCursor:(t,r)=>e(n=>({cursors:{...n.cursors,[t]:r}})),removeCursor:t=>e(r=>{const n={...r.cursors};return delete n[t],{cursors:n}})}),Yt=({storeName:e,children:t})=>{const{wire:r,isMaster:n}=Ie("room"),[o,s]=d.useState(null),[a,u]=d.useState(!1),l=d.useRef(!1);return d.useEffect(()=>{let m=!0;const f=[];if(!o&&!l.current)return l.current=!0,(()=>{const h=De(tt({wire:r,storeName:e,noSync:["updateCurrentUser","joinSpace","isSpaceMaster","electSpaceMaster"]},(...v)=>({...rn(r.userId)(...v),...nn(...v)}))),S=h.subscribe(v=>{v.ready&&(S(),m&&s(h))})})(),()=>{m=!1,l.current=!1,f.forEach(h=>h())}},[o,e,r,r.userId]),d.useEffect(()=>{if(o)return o.getState().addUser({...tn(),id:r.userId}),u(!0),()=>{o.getState().removeUser(r.userId)}},[n,o,r]),d.useEffect(()=>{if(o){const m=r.subscribe("userLeave",f=>{o.getState().removeUser(f)});return()=>{m()}}},[n,o,r]),d.useEffect(()=>{n&&o&&o.getState().updateCurrentUser({isMaster:n})},[n,o,r]),a?P(zt.Provider,{value:o,children:t}):null},ye=(e,t)=>{const r=d.useContext(zt);return $e(r,e,t||Ye)},on=()=>{const[e,t,r,n,o]=ye(u=>[u.isSpaceMaster,u.getUser(),u.users,u.updateCurrentUser,u.joinSpace]),s=d.useMemo(()=>Object.values(r),[r]),a=d.useMemo(()=>{const{space:u}=t;return s.filter(({space:l})=>l===u)},[t,s]);return{isSpaceMaster:e,currentUser:t,updateCurrentUser:n,users:s,localUsers:a,joinSpace:o}},sn=()=>{const[e,t,r]=oe(o=>[o.boardConfig,o.getBoardConfig,o.setBoardConfig]),n=d.useCallback(o=>{let s=o;typeof o=="object"&&(s=()=>o);const a=t(),u=s(a);r(u)},[t,r]);return[e,n]},an=()=>{const[e]=Q(t=>[t.boardState]);return e},cn=()=>{const[e,t,r,n]=oe(o=>[o.getSessionInfo,o.setSessionInfo,o.updateSessionInfo,o.session]);return{getSessionInfo:e,setSessionInfo:t,sessionInfo:n,updateSessionInfo:r}},Bt=d.createContext(),un=({user:{name:e,uid:t,color:r},content:n})=>({type:"message",user:{name:e,uid:t,color:r},content:n,uid:pe(),timestamp:new Date().toISOString()}),ln=(e,t)=>({messages:[],setMessages:r=>e({messages:r.map(n=>({...n,timestamp:Date.parse(n.timestamp)}))}),addMessage:r=>e(n=>({messages:[...n.messages,{...r,timestamp:Date.parse(r.timestamp)}]})),sendMessage:(r,n)=>{const o=un({user:r,content:n});o&&t().addMessage(o)}}),Nt=({storeName:e,children:t,defaultValue:r=[]})=>{const{wire:n}=Ie("room"),[o]=d.useState(()=>De(tt({wire:n,storeName:e,defaultValue:r,noSync:["sendMessage"]},(...s)=>({...ln(...s)}))));return P(Bt.Provider,{value:o,children:t})},fn=(e,t)=>{const r=d.useContext(Bt);return $e(r,e,t||Ye)},dn=()=>{},mn=(e=dn)=>{const t=ye(a=>a.getUser()),[r,n,o]=fn(a=>[a.messages,a.setMessages,a.sendMessage]);d.useEffect(()=>{r.length&&e()},[r,e]);const s=d.useCallback(a=>{o(t,a)},[t,o]);return{messages:r,setMessages:n,sendMessage:s}},Xt=({children:e,session:t})=>{const r=ye(n=>n.joinSpace);return d.useEffect(()=>(r(t),()=>{r(null)}),[r,t]),e},pn=({socket:e,room:t,session:r,items:n=[],messages:o=[],LoadingComponent:s,...a})=>{const[u]=d.useState(t||pe()),[l]=d.useState(r||pe()),[m]=d.useState(()=>({itemIds:n.map(({id:c})=>c),items:Object.fromEntries(n.map(c=>[c.id,c]))}));return Ie("room")?P(Nt,{storeName:`${l}_messages`,defaultValue:o,children:P(At,{children:P(Dt,{storeName:`${l}_item`,defaultValue:m,children:P(Xt,{...a,session:l})})})}):P(yt,{room:u,channel:"room",socket:e,LoadingComponent:s,children:P(Yt,{storeName:`${u}_users`,children:P(Nt,{storeName:`${l}_messages`,defaultValue:o,children:P(At,{children:P(Dt,{storeName:`${l}_item`,defaultValue:m,children:P(Xt,{...a,session:l})})})})})})},gn=({socket:e,room:t,children:r,LoadingComponent:n})=>{const[o]=d.useState(t||pe());return P(yt,{room:o,channel:"room",socket:e,LoadingComponent:n,children:P(Yt,{storeName:`${o}_users`,children:r})})};let hn={data:""},vn=e=>typeof window=="object"?((e?e.querySelector("#_goober"):window._goober)||Object.assign((e||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:e||hn,yn=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,Sn=/\/\*[^]*?\*\/| +/g,Ut=/\n+/g,de=(e,t)=>{let r="",n="",o="";for(let s in e){let a=e[s];s[0]=="@"?s[1]=="i"?r=s+" "+a+";":n+=s[1]=="f"?de(a,s):s+"{"+de(a,s[1]=="k"?"":t)+"}":typeof a=="object"?n+=de(a,t?t.replace(/([^,])+/g,u=>s.replace(/(^:.*)|([^,])+/g,l=>/&/.test(l)?l.replace(/&/g,u):u?u+" "+l:l)):s):a!=null&&(s=/^--/.test(s)?s:s.replace(/[A-Z]/g,"-$&").toLowerCase(),o+=de.p?de.p(s,a):s+":"+a+";")}return r+(t&&o?t+"{"+o+"}":o)+n},ce={},Wt=e=>{if(typeof e=="object"){let t="";for(let r in e)t+=r+Wt(e[r]);return t}return e},bn=(e,t,r,n,o)=>{let s=Wt(e),a=ce[s]||(ce[s]=(l=>{let m=0,f=11;for(;m<l.length;)f=101*f+l.charCodeAt(m++)>>>0;return"go"+f})(s));if(!ce[a]){let l=s!==e?e:(m=>{let f,c,h=[{}];for(;f=yn.exec(m.replace(Sn,""));)f[4]?h.shift():f[3]?(c=f[3].replace(Ut," ").trim(),h.unshift(h[0][c]=h[0][c]||{})):h[0][f[1]]=f[2].replace(Ut," ").trim();return h[0]})(e);ce[a]=de(o?{["@keyframes "+a]:l}:l,r?"":"."+a)}let u=r&&ce.g?ce.g:null;return r&&(ce.g=ce[a]),((l,m,f,c)=>{c?m.data=m.data.replace(c,l):m.data.indexOf(l)===-1&&(m.data=f?l+m.data:m.data+l)})(ce[a],t,n,u),a},_n=(e,t,r)=>e.reduce((n,o,s)=>{let a=t[s];if(a&&a.call){let u=a(r),l=u&&u.props&&u.props.className||/^go/.test(u)&&u;a=l?"."+l:u&&typeof u=="object"?u.props?"":de(u,""):u===!1?"":u}return n+o+(a??"")},"");function H(e){let t=this||{},r=e.call?e(t.p):e;return bn(r.unshift?r.raw?_n(r,[].slice.call(arguments,1),t.p):r.reduce((n,o)=>Object.assign(n,o&&o.call?o(t.p):o),{}):r,vn(t.target),t.g,t.o,t.k)}H.bind({g:1}),H.bind({k:1});function En(e,t,r,n){de.p=t}var wn=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var n,o,s;if(Array.isArray(t)){if(n=t.length,n!=r.length)return!1;for(o=n;o--!==0;)if(!e(t[o],r[o]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(s=Object.keys(t),n=s.length,n!==Object.keys(r).length)return!1;for(o=n;o--!==0;)if(!Object.prototype.hasOwnProperty.call(r,s[o]))return!1;for(o=n;o--!==0;){var a=s[o];if(!e(t[a],r[a]))return!1}return!0}return t!==t&&r!==r};const at=()=>{const e=navigator.userAgent.toLowerCase();return/mac os ?x 10/.test(e)},Cn=(()=>{const e=document.createElement("iframe");e.src="#",document.body.appendChild(e);const t=e.contentWindow.document;t.open(),t.write("<!DOCTYPE html><html><head></head><body><span>a</span></body></html>"),t.close();const r=t.body.firstElementChild.offsetHeight;return document.body.removeChild(e),r})(),xn=800,Vt=(e,t)=>{const r=Object.keys(e).map(n=>Number(n)).find(n=>n!==t);return e[r]},Ft=([e,t],[r,n])=>{const o=Math.abs(e-r),s=Math.abs(t-n);return Math.hypot(o,s)},ge=()=>{},In=e=>t=>{const{event:r}=t;return r.isPropagationStopped()?null:e(t)},On=e=>async(...t)=>{try{await e(...t)}catch(r){console.error(r)}};class Tn{constructor(){lr(this,"lastPromise",Promise.resolve(!0))}add(t,...r){return new Promise((n,o)=>{this.lastPromise=this.lastPromise.then(()=>In(On(t))(...r)).then(n).catch(o)})}}const ie=new Tn,Ne=({children:e,onDrag:t=ge,onDragStart:r=ge,onDragEnd:n=ge,onPan:o=ge,onTap:s=ge,onLongTap:a=ge,onDoubleTap:u=ge,onZoom:l,mainAction:m="drag"})=>{const f=d.useRef(null),c=d.useRef({moving:!1,pointers:{},mainPointer:void 0}),h=y=>{const{deltaX:C,deltaY:x,clientX:p,clientY:b,deltaMode:g,ctrlKey:w,altKey:I,metaKey:k,target:D}=y;if(!(I||w&&!at()))if(at()&&!w)ie.add(o,{deltaX:-2*C,deltaY:-2*x,button:1,ctrlKey:w,metaKey:k,target:D,event:y});else{if(l===void 0||!x)return;let j=x;switch(g){case 1:j*=Cn;break;case 2:j*=xn;break}at()&&(j*=2),ie.add(l,{scale:j,clientX:p,clientY:b,event:y})}},S=y=>{const{target:C,button:x,clientX:p,clientY:b,pointerId:g,altKey:w,ctrlKey:I,metaKey:k,isPrimary:D}=y;if(c.current.pointers[g]={clientX:p,clientY:b},D&&(c.current.mainPointer=void 0),c.current.mainPointer!==void 0){if(c.current.mainPointer!==g)try{const{clientX:j,clientY:A}=Vt(c.current.pointers,g),Y=(j+p)/2,W=(A+b)/2,J=Ft([j,A],[p,b]);Object.assign(c.current,{pressed:!0,moving:!1,gestureStart:!1,startX:p,startY:b,prevX:Y,prevY:W,startDistance:J,prevDistance:J})}catch(j){console.log("Error while getting other pointer. Ignoring",j),c.current.mainPointer}return}c.current.mainPointer=g,Object.assign(c.current,{pressed:!0,moving:!1,gestureStart:!1,startX:p,startY:b,prevX:p,prevY:b,currentButton:x,pointerDownEvent:y,startDistance:0,prevDistance:0,target:C,timeStart:Date.now(),longTapTimeout:setTimeout(async()=>{c.current.noTap=!0,ie.add(a,{clientX:p,clientY:b,altKey:w,ctrlKey:I,metaKey:k,target:C,event:y})},750)});try{C.setPointerCapture(g)}catch(j){console.log("Fail to capture pointer",j)}},v=y=>{if(c.current.pressed){const{pointerId:C,clientX:x,clientY:p,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,buttons:k}=y;c.current.pointers[C]={clientX:x,clientY:p},c.current.moving=!0;const D=Object.keys(c.current.pointers).length===2;let j,A,Y=0;if(D){const{clientX:$,clientY:B}=Vt(c.current.pointers,C);j=($+x)/2,A=(B+p)/2,Y=Ft([$,B],[x,p])}else j=x,A=p;let W=g||b||w||I||k!==1;m!=="drag"&&(W=!W);const J=!W,M=W;if(J){c.current.gestureStart||(f.current.style.cursor="move",c.current.gestureStart=!0,clearTimeout(c.current.longTapTimeout),ie.add(r,{deltaX:0,deltaY:0,startX:c.current.startX,startY:c.current.startY,clientX:c.current.startX,clientY:c.current.startY,distanceX:0,distanceY:0,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:c.current.target,event:c.current.pointerDownEvent}));const $=j-c.current.prevX,B=A-c.current.prevY,F=j-c.current.startX,L=A-c.current.startY;ie.add(t,{deltaX:$,deltaY:B,startX:c.current.startX,startY:c.current.startY,clientX:j,clientY:A,distanceX:F,distanceY:L,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:c.current.target,event:y})}if(M){c.current.gestureStart||(f.current.style.cursor="move",c.current.gestureStart=!0,clearTimeout(c.current.longTapTimeout));const $=j-c.current.prevX,B=A-c.current.prevY,{target:F}=c.current;if(ie.add(o,{deltaX:$,deltaY:B,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:F,event:y}),Y!==c.current.prevDistance&&l){const L=c.current.prevDistance-Y;Math.abs(L)>0&&(ie.add(l,{scale:L*3,clientX:j,clientY:A,event:y}),c.current.prevDistance=Y)}}c.current.prevX=j,c.current.prevY=A}},E=y=>{const{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,pointerId:k}=y;if(c.current.pointers[k]){if(delete c.current.pointers[k],c.current.mainPointer!==k){const{clientX:D,clientY:j}=c.current.pointers[c.current.mainPointer];Object.assign(c.current,{prevX:D,prevY:j,prevDistance:0,startDistance:0});return}for(;Object.keys(c.current.pointers).length>0;){c.current.mainPointer=Number(Object.keys(c.current.pointers)[0]);try{c.current.target.setPointerCapture(c.current.mainPointer);const{clientX:D,clientY:j}=c.current.pointers[c.current.mainPointer];Object.assign(c.current,{prevX:D,prevY:j,prevDistance:0,startDistance:0});return}catch(D){console.log("Fails to set pointer capture",D),c.current.mainPointer=void 0,delete c.current.pointers[Object.keys(c.current.pointers)[0]]}}if(c.current.mainPointer=void 0,c.current.pressed=!1,clearTimeout(c.current.longTapTimeout),c.current.moving)c.current.moving=!1,ie.add(n,{deltaX:C-c.current.prevX,deltaY:x-c.current.prevY,startX:c.current.startX,startY:c.current.startY,clientX:C,clientY:x,distanceX:C-c.current.startX,distanceY:x-c.current.startY,button:c.current.currentButton,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,event:y}),f.current.style.cursor="auto";else{const D=Date.now();c.current.noTap?c.current.noTap=!1:c.current.timeStart-D<300&&ie.add(s,{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,event:y})}}};return P("div",{onWheel:h,onPointerDown:S,onPointerMove:v,onPointerUp:E,onPointerOut:E,onPointerLeave:E,onPointerCancel:E,onDoubleClick:y=>{const{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I}=y;ie.add(u,{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,event:y})},style:{touchAction:"none"},ref:f,children:e})},ct=({onResize:e,...t})=>{const[r]=Q(o=>[o.getBoardState]);return P(Ne,{onDrag:({deltaX:o,deltaY:s,event:a})=>{a.stopPropagation();const{scale:u}=r();e({width:o/u,height:s/u})},children:P("div",{...t})})},kn=H`
|
|
59
|
+
*/var xt;function Cr(){return xt||(xt=1,process.env.NODE_ENV!=="production"&&function(){typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error);var e=d,t=wt();function r(f,c){return f===c&&(f!==0||1/f===1/c)||f!==f&&c!==c}var n=typeof Object.is=="function"?Object.is:r,s=t.useSyncExternalStore,o=e.useRef,a=e.useEffect,u=e.useMemo,l=e.useDebugValue;function m(f,c,h,S,v){var E=o(null),T;E.current===null?(T={hasValue:!1,value:null},E.current=T):T=E.current;var y=u(function(){var b=!1,g,w,I=function(A){if(!b){b=!0,g=A;var Y=S(A);if(v!==void 0&&T.hasValue){var W=T.value;if(v(W,Y))return w=W,W}return w=Y,Y}var q=g,M=w;if(n(q,A))return M;var R=S(A);return v!==void 0&&v(M,R)?M:(g=A,w=R,R)},k=h===void 0?null:h,D=function(){return I(c())},j=k===null?void 0:function(){return I(k())};return[D,j]},[c,h,S,v]),C=y[0],x=y[1],p=s(f,C,x);return a(function(){T.hasValue=!0,T.value=p},[p]),l(p),p}Ze.useSyncExternalStoreWithSelector=m,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error)}()),Ze}(function(e){process.env.NODE_ENV==="production"?e.exports=wr():e.exports=Cr()})(Sr);const xr=me(He),{useSyncExternalStoreWithSelector:Ir}=xr;function $e(e,t=e.getState,r){const n=Ir(e.subscribe,e.getState,e.getServerState||e.getState,t,r);return d.useDebugValue(n),n}const he=(e,t)=>e.classList&&e.classList.contains(t),Oe=(e,t)=>he(e,t)?e:e.parentNode?Oe(e.parentNode,t):!1,Ae=([e,t],[r,n])=>{const s=Math.abs(e-r),o=Math.abs(t-n);return Math.hypot(s,o)},It=(e,t,r)=>{const n=r*Math.PI/180,s=e*Math.cos(n)-t*Math.sin(n),o=e*Math.sin(n)+t*Math.cos(n);return[s,o]},Qe=([e,t],{scale:r,rotate:n,translateX:s,translateY:o})=>{const a=(e-s)/r,u=(t-o)/r;return It(a,u,-n)},Le=([e,t],{scale:r,rotate:n,translateX:s,translateY:o})=>{const[a,u]=It(e,t,n);return[a*r+s,u*r+o]},Ot=(e,t,r,n)=>{const s=e.x,o=e.y,a=t.x,u=t.y,l=r.x,m=r.y,f=a-s,c=u-o,h=s-l,S=o-m,v=f*f+c*c,E=2*(h*f+S*c),T=h*h+S*S-n*n,y=E*E-4*v*T;if(y<0)return[];const C=(-E+Math.sqrt(y))/(2*v),x=(-E-Math.sqrt(y))/(2*v),p=[];return C>=0&&C<=1&&p.push({x:s+C*f,y:o+C*c}),x>=0&&x<=1&&p.push({x:s+x*f,y:o+x*c}),p},et=(e,t)=>e.x>t.left&&e.x<t.left+t.width&&e.y>t.top&&e.y<t.top+t.height,Or=(e,t)=>Array.from(e.querySelectorAll(".corner")).every(n=>{const{top:s,left:o}=n.getBoundingClientRect();return et({x:o,y:s},t)}),Tr=(e,t)=>{const r=t.getBoundingClientRect();return Or(e,r)},ze=(e,t)=>{try{const r=document.getElementById(`${e}__${t}`);return r||console.error(`Missing item ${t}`),r}catch{console.error(`Error while getting item with id ${t} inside wrapper`,e);return}},Te=e=>{var r,n;const t=(r=e==null?void 0:e.dataset)==null?void 0:r.id;return t||console.error("getIdFromElem call fails",e,JSON.stringify(e==null?void 0:e.dataset),(n=e==null?void 0:e.dataset)==null?void 0:n.id),t},kr=(e,t)=>{const r=e.reduce((n,s)=>{const o=ze(t,s);if(!o)return n||null;const{left:a,right:u,top:l,bottom:m}=o.getBoundingClientRect();let f;return n?f=n:f={left:a,top:l,right:u,bottom:m},f.left=Math.min(a,f.left),f.top=Math.min(l,f.top),f.right=Math.max(u,f.right),f.bottom=Math.max(m,f.bottom),f},null);return r&&(r.width=r.right-r.left,r.height=r.bottom-r.top,r)},Tt=(e,t,r=null)=>(r===null&&(r=new Set),!Array.isArray(t)||t.length===0?[]:t.map(n=>r.has(n)?[]:(r.add(n),e[n]?[n,...Tt(e,e[n].linkedItems,r)]:[])).flat()),kt=(e,t,r)=>{const n=new Set(Tt(e,r));return t.filter(s=>n.has(s))},Pr=({x:e,y:t,width:r,height:n},{type:s="grid",size:o=1,offset:a={x:0,y:0}})=>{const[u,l]=[e+r/2-a.x,t+n/2-a.y];let m,f,c,h,S,v,E,T,y,C;const x=o/1.1547;switch(s){case"grid":m=Math.round(u/o)*o,f=Math.round(l/o)*o;break;case"hexH":c=2*x,h=3*o,S=Math.round(u/c)*c,E=Math.round(l/h)*h,v=S>u?S-x:S+x,T=E>l?E-1.5*o:E+1.5*o,y=Math.hypot(S-u,E-l),C=Math.hypot(v-u,T-l),y<C?(m=S,f=E):(m=v,f=T);break;case"hexV":c=3*o,h=2*x,S=Math.round(u/c)*c,E=Math.round(l/h)*h,v=S>u?S-1.5*o:S+1.5*o,T=E>l?E-x:E+x,y=Math.hypot(S-u,E-l),C=Math.hypot(v-u,T-l),y<C?(m=S,f=E):(m=v,f=T);break;default:m=e+r/2,f=t+n/2}return{x:m+a.x-r/2,y:f+a.y-n/2}},Pt=["#037758","#99092a","#067070","#c6650f","#008726","#3d7004","#348402","#057f58","#b58612","#c44c01","#0a7704","#0e910e","#027377","#c99e02","#054160","#157a01","#b10de2","#0d6289","#bc5d03","#ba0cd1","#d39f10","#0c4c7a","#460782","#a51f10","#cecb10","#9b0943","#607f0c","#007a4b","#bf0daa","#af0ad8"],Mt=()=>Pt[Math.floor(Math.random()*Pt.length)],Mr=!1,tt=({wire:e,storeName:t,noSync:r=[],defaultValue:n},s)=>(o,a,u)=>{o({ready:!1});const l=[];(async()=>{try{const S=await e.call(`${t}_getValue`);Mr&&console.log("init from peer with value",S),o(v=>({...v,...S}))}catch{n!==void 0&&o(n)}l.push(await e.register(`${t}_getValue`,()=>Object.fromEntries(Object.entries(a()).filter(([S,v])=>typeof v!="function"&&!r.includes(S))),{invoke:"first"})),l.push(e.subscribe(`${t}_call`,([S,v])=>{c[S](...v)})),o({ready:!0})})();const f=s(o,a,u),c={...f},h=Object.fromEntries(Object.entries(f).map(([S,v])=>typeof v=="function"&&!S.startsWith("get")&&!r.includes(S)?[S,(...T)=>{const y=v(...T);return e.publish(`${t}_call`,[S,T]),y}]:[S,v]));return h.unsub=()=>{l.forEach(S=>S())},h};function Ye(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[n,s]of e)if(!Object.is(s,t.get(n)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}const r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n=0;n<r.length;n++)if(!Object.prototype.hasOwnProperty.call(t,r[n])||!Object.is(e[r[n]],t[r[n]]))return!1;return!0}const jt=d.createContext(),jr=(e,t)=>({items:{},getItems:()=>t().items,setItems:r=>e({items:r}),updateItems:(r,n=!1)=>e(s=>n?{items:Object.fromEntries(Object.entries(s.items).map(([a,u])=>r[a]?[a,{...u,...r[a]}]:[a,u]))}:{items:{...s.items,...r}}),moveItems:(r,n)=>e(({items:s})=>{const o={...s};return r.forEach(a=>{const u=s[a];u&&(o[a]={...u,x:(u.x||0)+n.x,y:(u.y||0)+n.y,moving:!0})}),{items:o}})}),Dr=(e,t)=>({itemIds:[],setItemIds:r=>e({itemIds:r}),getItemIds:()=>t().itemIds,insert:(r,n)=>e(s=>{const o=[...s.itemIds];return o.splice(r,0,n),{itemIds:o}}),remove:r=>e(n=>{const s=[...n.itemIds];return s.splice(r,1),{itemIds:s}}),updateItemIds:(r,n)=>e(s=>{const o=[...s.itemIds];return o[r]=n,{items:o}}),updateManyItemIds:r=>e(n=>({items:n.itemIds.map((s,o)=>r[o]!==void 0?r[o]:s)}))}),Rr=(e,t)=>({removeItemsById:r=>e(n=>({itemIds:n.itemIds.filter(s=>!r.includes(s)),items:Object.fromEntries(Object.entries(n.items).filter(([s])=>!r.includes(s)))})),getItemList:()=>{const r=t().items;return t().itemIds.map(n=>r[n])},setItemList:r=>e({items:Object.fromEntries(r.map(n=>[n.id,n])),itemIds:r.map(({id:n})=>n)}),insertItems:(r,n)=>e(s=>{let o;const a=r.map(({id:u})=>u);if(n){const u=s.itemIds.findIndex(l=>l===n);o=[...s.itemIds],o.splice(u,0,...a)}else o=[...s.itemIds,...a];return{items:{...s.items,...Object.fromEntries(r.map(u=>[u.id,u]))},itemIds:o}})}),$r=(e,t)=>({boardConfig:{},getBoardConfig:()=>t().boardConfig,setBoardConfig:r=>e({boardConfig:r}),updateBoardConfig:r=>e(n=>({boardConfig:{...n.boardConfig,...r}}))}),Ar=(e,t)=>({session:{},getSessionInfo:()=>t().session,setSessionInfo:r=>e({session:r}),updateSessionInfo:r=>e(n=>({session:{...n.session,...r}}))}),Dt=({storeName:e,children:t,defaultValue:r})=>{const{wire:n}=Ie("room"),[s,o]=d.useState(!1),[a]=d.useState(()=>De(tt({wire:n,storeName:e,defaultValue:r},(...u)=>({...jr(...u),...Dr(...u),...Rr(...u),...$r(...u),...Ar(...u)}))));return d.useEffect(()=>{const u=a.subscribe(l=>{l.ready&&(u(),o(!0))})},[a]),s?P(jt.Provider,{value:a,children:t}):null},se=(e,t)=>{const r=d.useContext(jt);return $e(r,e,t||Ye)},Lr=()=>{const[e,t]=se(n=>[n.itemIds,n.items]);return d.useMemo(()=>e.map(n=>t[n]),[e,t])},zr=()=>{const[e,t,r]=se(a=>[a.items,a.itemIds,a.getItemList]),[n,s]=d.useState(r()),[,o]=d.useTransition();return d.useEffect(()=>{const a=r();o(()=>{s(a)})},[e,t,r]),n},Rt=5e4,$t=d.createContext(),Yr=(e,t)=>({config:{itemTemplates:{},actions:{},uid:null,itemExtent:{x:0,y:0,radius:0},boardWrapperRect:{},boardSize:Rt},updateConfiguration:r=>e(n=>({config:{...n.config,...r}})),getConfiguration:()=>t().config}),Br=(e,t)=>({boardState:{movingItems:!1,selecting:!1,zooming:!1,panning:!1,translateX:0,translateY:0,scale:1,rotate:0},updateBoardState:r=>e(n=>({boardState:{...n.boardState,...r}})),getBoardState:()=>t().boardState}),Nr=(e,t)=>({interactions:{},getInteractions:()=>t().interactions,register:(r,n)=>e(s=>{const o=[...s.interactions[r]||[]];return o.push(n),{interactions:{...s.interactions,[r]:o}}}),unregister:(r,n)=>e(s=>{const o=(s.interactions[r]||[]).filter(a=>a!==n);return{interactions:{...s.interactions,[r]:o}}}),callInteractions:(r,n)=>{t().interactions[r]&&t().interactions[r].forEach(s=>{setTimeout(()=>s(n),0)})}}),Xr=(e,t)=>({selection:[],setSelection:r=>e(n=>JSON.stringify(n.selection)!==JSON.stringify(r)?{selection:r}:{}),getSelection:()=>t().selection,select:r=>e(n=>({selection:[...n.selection,...r]})),unselect:r=>e(n=>({selection:n.selection.filter(s=>!r.includes(s))})),clear:()=>e(r=>r.selection.length>0?{selection:[]}:{}),reverse:()=>e(r=>{const n=[...r.selection];return n.reverse(),{selection:n}}),selectionBox:null,setSelectionBox:r=>e(n=>{const s=n.selectionBox;return!s||!r||s.top!==r.top||s.left!==r.left||s.width!==r.width||s.height!==r.height?{selectionBox:r}:{}})}),At=({children:e})=>{const[t]=d.useState(()=>De((...r)=>({...Yr(...r),...Br(...r),...Nr(...r),...Xr(...r)})));return P($t.Provider,{value:t,children:e})},Q=(e,t)=>{const r=d.useContext($t);return $e(r,e,t||Ye)},Ur=()=>{const[e]=Q(t=>[t.selection]);return e},Wr=()=>{const[e]=Q(t=>[t.getSelection]);return e};function rt(e){const t=d.useRef(e);return t.current=e,d.useMemo(()=>Object.freeze({get current(){return t.current}}),[])}function Vr(e){const t=rt(e);d.useEffect(()=>()=>{t.current()},[])}function nt(e,t,r,n=0){const s=d.useRef(),o=d.useRef(),a=d.useRef(),u=()=>{s.current&&(clearTimeout(s.current),s.current=void 0),o.current&&(clearTimeout(o.current),o.current=void 0)};return Vr(u),d.useMemo(()=>{const l=()=>{if(!a.current)return;const f=a.current;a.current=void 0,e.apply(f.this,f.args),u()},m=function(...f){s.current&&clearTimeout(s.current),a.current={args:f,this:this},s.current=setTimeout(l,r),n>0&&!o.current&&(o.current=setTimeout(l,n))};return Object.defineProperties(m,{length:{value:e.length},name:{value:`${e.name||"anonymous"}__debounced__${r}`}}),m},[r,n,...t])}const Fr=100,Kr=1e3,Hr=.8;let st=!1;const qr=({x:e,y:t,scale:r,rotate:n,itemExtent:s,boardWrapperRect:o,boardSize:a})=>{let[u,l]=[e,t];const m=Qe([o.width/2,o.height/2],{translateX:u,translateY:l,scale:r,rotate:n}),f={x:s.x+a/2,y:s.y+a/2},c={x:a/2,y:a/2},h=Ae(m,[f.x,f.y]),S=Math.min(o.width,o.height),v=s.radius+S/2/r-Fr/r;if(h>v){const y=Ot({x:m[0],y:m[1]},f,f,v-1/r)[0],[C,x]=Le([-y.x,-y.y],{translateX:o.width/2,translateY:o.height/2,scale:r,rotate:n});u=C,l=x}const E=Ae(m,[c.x,c.y]),T=a/2-Ae([0,0],[o.width,o.height])/r;if(E>T){const y=Ot({x:m[0],y:m[1]},c,c,T-1/r)[0];if(y){const[C,x]=Le([-y.x,-y.y],{translateX:o.width/2,translateY:o.height/2,scale:r,rotate:n});u=C,l=x}}return[u,l]},ve=()=>{const[e,t,r,n,s]=Q(p=>[p.getBoardState,p.updateBoardState,p.config.itemExtent,p.getConfiguration,p.updateConfiguration]),o=d.useRef([.15,5]),[a]=se(p=>[p.getItemList]),u=d.useCallback(()=>{const{translateX:p,translateY:b,scale:g,rotate:w}=e();return{translateX:p,translateY:b,scale:g,rotate:w}},[e]),l=d.useCallback((p,b)=>Qe([p,b],e()),[e]),m=d.useCallback((p,b)=>Le([p,b],e()),[e]),f=d.useCallback((p,b)=>{const{scale:g,rotate:w}=e();return Qe([p,b],{translateX:0,translateY:0,rotate:w,scale:g})},[e]),c=d.useCallback(p=>p>o.current[1]?o.current[1]:p<o.current[0]?o.current[0]:p,[]),h=d.useCallback(p=>{const{itemExtent:b,boardWrapperRect:g,boardSize:w}=n(),I=e(),{translateX:k,translateY:D,scale:j,rotate:A}={...I,...p(I)};st&&console.log("New expected values: ",k,D,j,A);const Y=c(j);let[W,q]=[k,D];(k!==I.translateX||D!==I.translateY)&&([W,q]=qr({x:k,y:D,scale:Y,rotate:A,itemExtent:b,boardWrapperRect:g,boardSize:w})),st&&console.log("New fixed values: ",W,q,Y,A),t({translateX:isNaN(W)?0:W,translateY:isNaN(q)?0:q,scale:isNaN(Y)?c(1):Y,rotate:isNaN(A)?0:A})},[c,e,n,t]),S=d.useCallback(p=>{let b=g=>({...g,...p});typeof p=="function"&&(b=p),h(g=>({...g,...b({translateX:g.translateX,translateY:g.translateY})}))},[h]),v=d.useCallback(({to:p,factor:b})=>{const{boardWrapperRect:g}=n();let w=p;w||(w={x:g.left+g.width/2,y:g.top+g.height/2});const I=e(),k=c(I.scale*b),D=w.x-g.left,j=w.y-g.top,A=D-(D-I.translateX)*k/I.scale,Y=j-(j-I.translateY)*k/I.scale;h(W=>({...W,translateX:A,translateY:Y,scale:k}))},[c,e,n,h]),E=d.useCallback(({x:p,y:b,radius:g})=>{const{rotate:w}=e(),{boardWrapperRect:I,boardSize:k}=n(),[D,j,A]=[p||0,b||0,g||2e3],Y=I.width/(A*2),W=I.height/(A*2),q=c(Math.min(Y,W)*Hr),[M,R]=Le([-k/2-D,-k/2-j],{translateX:I.width/2,translateY:I.height/2,scale:q,rotate:w});h(L=>({...L,translateX:M,translateY:R,scale:q}))},[c,e,n,h]),T=d.useCallback(()=>{const{boardWrapperRect:p,boardSize:b}=n(),[g,w]=l(p.width/2,p.height/2);return{x:g-b/2,y:w-b/2}},[l,n]),y=d.useCallback(()=>{const p=a(),{boardSize:b,uid:g}=n(),w=p.reduce((k,D)=>{const j=ze(g,D.id);return j&&(k.left=Math.min(D.x,k.left),k.top=Math.min(D.y,k.top),k.right=Math.max(D.x+j.offsetWidth,k.right),k.bottom=Math.max(D.y+j.offsetHeight,k.bottom)),k},{left:b/2,top:b/2,right:-b/2,bottom:-b/2}),I={x:(w.right+w.left)/2,y:(w.bottom+w.top)/2};I.radius=Math.max(Ae([I.x,I.y],[w.left,w.top]),Kr),s({itemExtent:I})},[n,a,s]),C=d.useCallback(p=>{let b=()=>p;typeof p=="function"&&(b=p),h(g=>({...g,rotate:b(g.rotate)})),y(),E(r)},[r,h,y,E]),x=nt(()=>y(),[y],200);return d.useEffect(()=>{window.debugUpdateExtent=()=>y(),window.debugDisplayExtent=()=>console.log(n().itemExtent),window.debugSetDebug=()=>{st=!0}},[n,y]),{setDim:h,rotateBoard:C,moveBoard:S,getDim:u,zoomTo:v,zoomToCenter:v,zoomToExtent:E,getCenter:T,updateItemExtent:x,vectorFromWrapperToBoard:f,fromWrapperToBoard:l,fromBoardToWrapper:m}},ot=e=>{const[t,r,n]=Q(({register:a,unregister:u,callInteractions:l})=>[a,u,l]),s=d.useCallback(a=>(t(e,a),()=>{r(e,a)}),[e,t,r]),o=d.useCallback(a=>{n(e,a)},[n,e]);return{register:s,call:o}},Be=()=>{const{call:e}=ot("place"),{call:t}=ot("delete"),{getCenter:r,updateItemExtent:n}=ve(),[s,o,a,u]=Q(M=>[M.clear,M.reverse,M.unselect,M.getConfiguration]),{getItems:l,getItemIds:m,setItemIds:f,updateItems:c,moveItems:h,removeItemsById:S,getItemList:v,insertItems:E,setItemList:T}=se(({getItems:M,getItemIds:R,setItemIds:L,updateItems:F,moveItems:z,removeItemsById:K,getItemList:G,insertItems:re,setItemList:ee})=>({getItems:M,getItemIds:R,setItemIds:L,updateItems:F,moveItems:z,removeItemsById:K,getItemList:G,insertItems:re,setItemList:ee})),y=d.useCallback((M,R,L=!1)=>{let F=R;typeof R=="object"&&(F=()=>R);const z=m().filter(ee=>M.includes(ee)),K=l(),G=z.map(ee=>{const oe=K[ee];return L?[ee,F(oe)]:[ee,F({...oe})]}).filter(([,ee])=>ee);if(G.length===0)return;const re=Object.fromEntries(G);c(re,L),n()},[m,l,n,c]),C=d.useCallback(M=>{T(M),s(),n()},[s,T,n]),x=d.useCallback((M,R,L=!1)=>{y([M],R,L)},[y]),p=d.useCallback((M,R)=>{h(kt(l(),m(),M),R)},[m,l,h]),b=d.useCallback(M=>{const R=m(),L=R.filter(z=>!M.includes(z)),F=R.filter(z=>M.includes(z));f([...L,...F])},[m,f]),g=d.useCallback((M,{type:R,size:L}={})=>{const{uid:F}=u();y(M,z=>{const K=ze(F,z.id);if(!K)return;const G={type:R||"grid",size:L||1,offset:{x:0,y:0},...z.grid};return Pr({x:z.x,y:z.y,width:K.clientWidth,height:K.clientHeight},G)},!0)},[u,y]),w=d.useCallback((M,R)=>{const L=kt(l(),m(),M);b(L),y(L,{moving:!1},!0),g(L,R),e(M),n()},[y,e,m,l,b,g,n]),I=d.useCallback(M=>{f(M)},[f]),k=d.useCallback(M=>{const R=m(),L=R.filter(z=>M.includes(z)),F=R.map(z=>M.includes(z)?L.pop():z);f(F),o()},[m,o,f]),D=d.useCallback((M,R)=>{const L=l(),F=Object.fromEntries(R.map((G,re)=>{const ee=L[M[re]];return[G,{x:ee.x,y:ee.y}]}));y(M,G=>F[G.id],!0);const z=Object.fromEntries(M.map((G,re)=>[G,R[re]])),K=m().map(G=>M.includes(G)?z[G]:G);f(K)},[l,y,m,f]),j=d.useCallback((M,R)=>{const L=r(),F=M.map((z,K)=>!z.x||!z.y?{...z,x:L.x+2*K,y:L.y+2*K}:z);E(F,R),w(M.map(({id:z})=>z))},[r,E,w]),A=d.useCallback((M,R)=>{j([M],R)},[j]),Y=d.useCallback(M=>{a(M),S(M),t(M)},[a,S,t]),W=d.useCallback(M=>{const R=l();return M.map(L=>R[L])},[l]),q=d.useCallback(({target:M,clientX:R,clientY:L},{returnLocked:F=!1,passLocked:z=!1}={})=>{if(["INPUT","TEXTAREA"].includes(M.tagName))return null;const K=Oe(M,"item");if(K){if(he(K,"selected"))return K;if(!z&&he(K,"locked")&&!he(M,"passthrough"))return F?K:null;if(he(M,"passthrough")){const G=m(),{uid:re}=u(),ee=G.reduce((oe,le)=>{const Se=ze(re,le),be=Se.getBoundingClientRect();return et({x:R,y:L},be)&&oe.unshift(Se),oe},[]);for(let oe=0;oe<ee.length;oe+=1){const le=ee[oe];if(le!==K&&(z||!he(le,"locked")))return le}return null}}return K},[u,m]);return{putItemsOnTop:b,batchUpdateItems:y,updateItemOrder:I,moveItems:p,placeItems:w,updateItem:x,swapItems:D,reverseItemsOrder:k,setItemList:C,pushItem:A,pushItems:j,removeItems:Y,getItemList:v,findElementUnderPointer:q,getItems:W}};var Gr=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var n,s,o;if(Array.isArray(t)){if(n=t.length,n!=r.length)return!1;for(s=n;s--!==0;)if(!e(t[s],r[s]))return!1;return!0}if(t instanceof Map&&r instanceof Map){if(t.size!==r.size)return!1;for(s of t.entries())if(!r.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],r.get(s[0])))return!1;return!0}if(t instanceof Set&&r instanceof Set){if(t.size!==r.size)return!1;for(s of t.entries())if(!r.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(r)){if(n=t.length,n!=r.length)return!1;for(s=n;s--!==0;)if(t[s]!==r[s])return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(o=Object.keys(t),n=o.length,n!==Object.keys(r).length)return!1;for(s=n;s--!==0;)if(!Object.prototype.hasOwnProperty.call(r,o[s]))return!1;for(s=n;s--!==0;){var a=o[s];if(!e(t[a],r[a]))return!1}return!0}return t!==t&&r!==r};function Jr(e,t,r,n=0){d.useEffect(nt(e,t,r,n),t)}const Zr=(e,t)=>{if(e.type in t){const r=t[e.type].defaultActions;return typeof r=="function"?r(e):r}return[]},Lt=(e,t)=>{const{actions:r=Zr(e,t)}=e;return r.map(n=>typeof n=="string"?{name:n}:n)},Qr=()=>{const[e,t]=se(c=>[c.items,c.getItems]),[r,n,s]=Q(c=>[c.config.itemTemplates,c.selection,c.getSelection]),[o,a]=d.useState([]),u=d.useRef(!1),[,l]=d.useTransition();d.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]);const m=d.useCallback(c=>{const h=t();if(c)return[c,c.map(v=>h[v])];const S=s();return[S,S.map(v=>h[v])]},[t,s]),f=d.useCallback(()=>{const[c,h]=m();if(c.length>0){if(!u.current)return;const S=h.reduce((v,E)=>{const T=Lt(E,r);return v.filter(y=>T.some(C=>Gr(y,C)))},Lt(h[0],r));l(()=>{a(S)})}else l(()=>{a([])})},[m,r]);return Jr(()=>f(),[e,n,f],100),{availableActions:o}},en=()=>{const[e]=Q(t=>[t.selectionBox]);return e};let pe=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,r)=>(r&=63,r<36?t+=r.toString(36):r<62?t+=(r-26).toString(36).toUpperCase():r>62?t+="-":t+="_",t),"");const zt=d.createContext(),it=e=>{localStorage.setItem("user",JSON.stringify(e))},tn=()=>{if(localStorage.user){const t={name:"Player",color:Mt(),uid:pe(),...JSON.parse(localStorage.user)};return it(t),t}const e={name:"Player",color:Mt(),uid:pe()};return it(e),e},rn=e=>(t,r)=>({isSpaceMaster:!1,users:{},getUser:()=>r().users[e],getUsers:()=>r().users,getUserList:()=>Object.values(r().users),getLocalUsers:()=>{if(!r().users[e])return[];const{space:n}=r().users[e];return r().getUserList().filter(({space:s})=>s===n)},addUser:n=>t(s=>({users:{...s.users,[n.id]:n}})),updateUser:(n,s)=>t(o=>{if(!o.users[n])return{};const a={...o.users[n],...s,id:n,uid:o.users[n].uid};return a.id===e&&it(a),setTimeout(()=>r().electSpaceMaster(),100),{users:{...o.users,[n]:a}}}),removeUser:n=>t(s=>{const o={...s.users};return delete o[n],setTimeout(()=>r().electSpaceMaster(),100),{users:o}}),updateCurrentUser:n=>r().updateUser(e,n),joinSpace:n=>r().updateUser(e,{space:n,spaceJoinedTimestamp:Date.now()}),electSpaceMaster:()=>{const n=r().getLocalUsers(),s={uid:null,timestamp:Date.now()};Object.values(n).forEach(({spaceJoinedTimestamp:o,id:a})=>{o<s.timestamp&&(s.id=a,s.timestamp=o)}),t({isSpaceMaster:s.id===e})}}),nn=e=>({cursors:{},moveCursor:(t,r)=>e(n=>({cursors:{...n.cursors,[t]:r}})),removeCursor:t=>e(r=>{const n={...r.cursors};return delete n[t],{cursors:n}})}),Yt=({storeName:e,children:t})=>{const{wire:r,isMaster:n}=Ie("room"),[s,o]=d.useState(null),[a,u]=d.useState(!1),l=d.useRef(!1);return d.useEffect(()=>{let m=!0;const f=[];if(!s&&!l.current)return l.current=!0,(()=>{const h=De(tt({wire:r,storeName:e,noSync:["updateCurrentUser","joinSpace","isSpaceMaster","electSpaceMaster"]},(...v)=>({...rn(r.userId)(...v),...nn(...v)}))),S=h.subscribe(v=>{v.ready&&(S(),m&&o(h))})})(),()=>{m=!1,l.current=!1,f.forEach(h=>h())}},[s,e,r,r.userId]),d.useEffect(()=>{if(s)return s.getState().addUser({...tn(),id:r.userId}),u(!0),()=>{s.getState().removeUser(r.userId)}},[n,s,r]),d.useEffect(()=>{if(s){const m=r.subscribe("userLeave",f=>{s.getState().removeUser(f)});return()=>{m()}}},[n,s,r]),d.useEffect(()=>{n&&s&&s.getState().updateCurrentUser({isMaster:n})},[n,s,r]),a?P(zt.Provider,{value:s,children:t}):null},ye=(e,t)=>{const r=d.useContext(zt);return $e(r,e,t||Ye)},sn=()=>{const[e,t,r,n,s]=ye(u=>[u.isSpaceMaster,u.getUser(),u.users,u.updateCurrentUser,u.joinSpace]),o=d.useMemo(()=>Object.values(r),[r]),a=d.useMemo(()=>{const{space:u}=t;return o.filter(({space:l})=>l===u)},[t,o]);return{isSpaceMaster:e,currentUser:t,updateCurrentUser:n,users:o,localUsers:a,joinSpace:s}},on=()=>{const[e,t,r]=se(s=>[s.boardConfig,s.getBoardConfig,s.setBoardConfig]),n=d.useCallback(s=>{let o=s;typeof s=="object"&&(o=()=>s);const a=t(),u=o(a);r(u)},[t,r]);return[e,n]},an=()=>{const[e]=Q(t=>[t.boardState]);return e},cn=()=>{const[e,t,r,n]=se(s=>[s.getSessionInfo,s.setSessionInfo,s.updateSessionInfo,s.session]);return{getSessionInfo:e,setSessionInfo:t,sessionInfo:n,updateSessionInfo:r}},Bt=d.createContext(),un=({user:{name:e,uid:t,color:r},content:n})=>({type:"message",user:{name:e,uid:t,color:r},content:n,uid:pe(),timestamp:new Date().toISOString()}),ln=(e,t)=>({messages:[],setMessages:r=>e({messages:r.map(n=>({...n,timestamp:Date.parse(n.timestamp)}))}),addMessage:r=>e(n=>({messages:[...n.messages,{...r,timestamp:Date.parse(r.timestamp)}]})),sendMessage:(r,n)=>{const s=un({user:r,content:n});s&&t().addMessage(s)}}),Nt=({storeName:e,children:t,defaultValue:r=[]})=>{const{wire:n}=Ie("room"),[s]=d.useState(()=>De(tt({wire:n,storeName:e,defaultValue:r,noSync:["sendMessage"]},(...o)=>({...ln(...o)}))));return P(Bt.Provider,{value:s,children:t})},fn=(e,t)=>{const r=d.useContext(Bt);return $e(r,e,t||Ye)},dn=()=>{},mn=(e=dn)=>{const t=ye(a=>a.getUser()),[r,n,s]=fn(a=>[a.messages,a.setMessages,a.sendMessage]);d.useEffect(()=>{r.length&&e()},[r,e]);const o=d.useCallback(a=>{s(t,a)},[t,s]);return{messages:r,setMessages:n,sendMessage:o}},Xt=({children:e,session:t})=>{const r=ye(n=>n.joinSpace);return d.useEffect(()=>(r(t),()=>{r(null)}),[r,t]),e},pn=({socket:e,room:t,session:r,items:n=[],messages:s=[],LoadingComponent:o,...a})=>{const[u]=d.useState(t||pe()),[l]=d.useState(r||pe()),[m]=d.useState(()=>({itemIds:n.map(({id:c})=>c),items:Object.fromEntries(n.map(c=>[c.id,c]))}));return Ie("room")?P(Nt,{storeName:`${l}_messages`,defaultValue:s,children:P(At,{children:P(Dt,{storeName:`${l}_item`,defaultValue:m,children:P(Xt,{...a,session:l})})})}):P(yt,{room:u,channel:"room",socket:e,LoadingComponent:o,children:P(Yt,{storeName:`${u}_users`,children:P(Nt,{storeName:`${l}_messages`,defaultValue:s,children:P(At,{children:P(Dt,{storeName:`${l}_item`,defaultValue:m,children:P(Xt,{...a,session:l})})})})})})},gn=({socket:e,room:t,children:r,LoadingComponent:n})=>{const[s]=d.useState(t||pe());return P(yt,{room:s,channel:"room",socket:e,LoadingComponent:n,children:P(Yt,{storeName:`${s}_users`,children:r})})};let hn={data:""},vn=e=>typeof window=="object"?((e?e.querySelector("#_goober"):window._goober)||Object.assign((e||document.head).appendChild(document.createElement("style")),{innerHTML:" ",id:"_goober"})).firstChild:e||hn,yn=/(?:([\u0080-\uFFFF\w-%@]+) *:? *([^{;]+?);|([^;}{]*?) *{)|(}\s*)/g,Sn=/\/\*[^]*?\*\/| +/g,Ut=/\n+/g,de=(e,t)=>{let r="",n="",s="";for(let o in e){let a=e[o];o[0]=="@"?o[1]=="i"?r=o+" "+a+";":n+=o[1]=="f"?de(a,o):o+"{"+de(a,o[1]=="k"?"":t)+"}":typeof a=="object"?n+=de(a,t?t.replace(/([^,])+/g,u=>o.replace(/(^:.*)|([^,])+/g,l=>/&/.test(l)?l.replace(/&/g,u):u?u+" "+l:l)):o):a!=null&&(o=/^--/.test(o)?o:o.replace(/[A-Z]/g,"-$&").toLowerCase(),s+=de.p?de.p(o,a):o+":"+a+";")}return r+(t&&s?t+"{"+s+"}":s)+n},ce={},Wt=e=>{if(typeof e=="object"){let t="";for(let r in e)t+=r+Wt(e[r]);return t}return e},bn=(e,t,r,n,s)=>{let o=Wt(e),a=ce[o]||(ce[o]=(l=>{let m=0,f=11;for(;m<l.length;)f=101*f+l.charCodeAt(m++)>>>0;return"go"+f})(o));if(!ce[a]){let l=o!==e?e:(m=>{let f,c,h=[{}];for(;f=yn.exec(m.replace(Sn,""));)f[4]?h.shift():f[3]?(c=f[3].replace(Ut," ").trim(),h.unshift(h[0][c]=h[0][c]||{})):h[0][f[1]]=f[2].replace(Ut," ").trim();return h[0]})(e);ce[a]=de(s?{["@keyframes "+a]:l}:l,r?"":"."+a)}let u=r&&ce.g?ce.g:null;return r&&(ce.g=ce[a]),((l,m,f,c)=>{c?m.data=m.data.replace(c,l):m.data.indexOf(l)===-1&&(m.data=f?l+m.data:m.data+l)})(ce[a],t,n,u),a},_n=(e,t,r)=>e.reduce((n,s,o)=>{let a=t[o];if(a&&a.call){let u=a(r),l=u&&u.props&&u.props.className||/^go/.test(u)&&u;a=l?"."+l:u&&typeof u=="object"?u.props?"":de(u,""):u===!1?"":u}return n+s+(a??"")},"");function H(e){let t=this||{},r=e.call?e(t.p):e;return bn(r.unshift?r.raw?_n(r,[].slice.call(arguments,1),t.p):r.reduce((n,s)=>Object.assign(n,s&&s.call?s(t.p):s),{}):r,vn(t.target),t.g,t.o,t.k)}H.bind({g:1}),H.bind({k:1});function En(e,t,r,n){de.p=t}var wn=function e(t,r){if(t===r)return!0;if(t&&r&&typeof t=="object"&&typeof r=="object"){if(t.constructor!==r.constructor)return!1;var n,s,o;if(Array.isArray(t)){if(n=t.length,n!=r.length)return!1;for(s=n;s--!==0;)if(!e(t[s],r[s]))return!1;return!0}if(t.constructor===RegExp)return t.source===r.source&&t.flags===r.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===r.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===r.toString();if(o=Object.keys(t),n=o.length,n!==Object.keys(r).length)return!1;for(s=n;s--!==0;)if(!Object.prototype.hasOwnProperty.call(r,o[s]))return!1;for(s=n;s--!==0;){var a=o[s];if(!e(t[a],r[a]))return!1}return!0}return t!==t&&r!==r};const at=()=>{const e=navigator.userAgent.toLowerCase();return/mac os ?x 10/.test(e)},Cn=(()=>{const e=document.createElement("iframe");e.src="#",document.body.appendChild(e);const t=e.contentWindow.document;t.open(),t.write("<!DOCTYPE html><html><head></head><body><span>a</span></body></html>"),t.close();const r=t.body.firstElementChild.offsetHeight;return document.body.removeChild(e),r})(),xn=800,Vt=(e,t)=>{const r=Object.keys(e).map(n=>Number(n)).find(n=>n!==t);return e[r]},Ft=([e,t],[r,n])=>{const s=Math.abs(e-r),o=Math.abs(t-n);return Math.hypot(s,o)},ge=()=>{},In=e=>t=>{const{event:r}=t;return r.isPropagationStopped()?null:e(t)},On=e=>async(...t)=>{try{await e(...t)}catch(r){console.error(r)}};class Tn{constructor(){lr(this,"lastPromise",Promise.resolve(!0))}add(t,...r){return new Promise((n,s)=>{this.lastPromise=this.lastPromise.then(()=>In(On(t))(...r)).then(n).catch(s)})}}const ie=new Tn,Ne=({children:e,onDrag:t=ge,onDragStart:r=ge,onDragEnd:n=ge,onPan:s=ge,onTap:o=ge,onLongTap:a=ge,onDoubleTap:u=ge,onZoom:l,mainAction:m="drag"})=>{const f=d.useRef(null),c=d.useRef({moving:!1,pointers:{},mainPointer:void 0}),h=y=>{const{deltaX:C,deltaY:x,clientX:p,clientY:b,deltaMode:g,ctrlKey:w,altKey:I,metaKey:k,target:D}=y;if(!(I||w&&!at()))if(at()&&!w)ie.add(s,{deltaX:-2*C,deltaY:-2*x,button:1,ctrlKey:w,metaKey:k,target:D,event:y});else{if(l===void 0||!x)return;let j=x;switch(g){case 1:j*=Cn;break;case 2:j*=xn;break}at()&&(j*=2),ie.add(l,{scale:j,clientX:p,clientY:b,event:y})}},S=y=>{const{target:C,button:x,clientX:p,clientY:b,pointerId:g,altKey:w,ctrlKey:I,metaKey:k,isPrimary:D}=y;if(c.current.pointers[g]={clientX:p,clientY:b},D&&(c.current.mainPointer=void 0),c.current.mainPointer!==void 0){if(c.current.mainPointer!==g)try{const{clientX:j,clientY:A}=Vt(c.current.pointers,g),Y=(j+p)/2,W=(A+b)/2,q=Ft([j,A],[p,b]);Object.assign(c.current,{pressed:!0,moving:!1,gestureStart:!1,startX:p,startY:b,prevX:Y,prevY:W,startDistance:q,prevDistance:q})}catch(j){console.log("Error while getting other pointer. Ignoring",j),c.current.mainPointer}return}c.current.mainPointer=g,Object.assign(c.current,{pressed:!0,moving:!1,gestureStart:!1,startX:p,startY:b,prevX:p,prevY:b,currentButton:x,pointerDownEvent:y,startDistance:0,prevDistance:0,target:C,timeStart:Date.now(),longTapTimeout:setTimeout(async()=>{c.current.noTap=!0,ie.add(a,{clientX:p,clientY:b,altKey:w,ctrlKey:I,metaKey:k,target:C,event:y})},750)});try{C.setPointerCapture(g)}catch(j){console.log("Fail to capture pointer",j)}},v=y=>{if(c.current.pressed){const{pointerId:C,clientX:x,clientY:p,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,buttons:k}=y;c.current.pointers[C]={clientX:x,clientY:p},c.current.moving=!0;const D=Object.keys(c.current.pointers).length===2;let j,A,Y=0;if(D){const{clientX:R,clientY:L}=Vt(c.current.pointers,C);j=(R+x)/2,A=(L+p)/2,Y=Ft([R,L],[x,p])}else j=x,A=p;let W=g||b||w||I||k!==1;m!=="drag"&&(W=!W);const q=!W,M=W;if(q){c.current.gestureStart||(f.current.style.cursor="move",c.current.gestureStart=!0,clearTimeout(c.current.longTapTimeout),ie.add(r,{deltaX:0,deltaY:0,startX:c.current.startX,startY:c.current.startY,clientX:c.current.startX,clientY:c.current.startY,distanceX:0,distanceY:0,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:c.current.target,event:c.current.pointerDownEvent}));const R=j-c.current.prevX,L=A-c.current.prevY,F=j-c.current.startX,z=A-c.current.startY;ie.add(t,{deltaX:R,deltaY:L,startX:c.current.startX,startY:c.current.startY,clientX:j,clientY:A,distanceX:F,distanceY:z,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:c.current.target,event:y})}if(M){c.current.gestureStart||(f.current.style.cursor="move",c.current.gestureStart=!0,clearTimeout(c.current.longTapTimeout));const R=j-c.current.prevX,L=A-c.current.prevY,{target:F}=c.current;if(ie.add(s,{deltaX:R,deltaY:L,button:c.current.currentButton,altKey:b,shiftKey:g,ctrlKey:w,metaKey:I,target:F,event:y}),Y!==c.current.prevDistance&&l){const z=c.current.prevDistance-Y;Math.abs(z)>0&&(ie.add(l,{scale:z*3,clientX:j,clientY:A,event:y}),c.current.prevDistance=Y)}}c.current.prevX=j,c.current.prevY=A}},E=y=>{const{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,pointerId:k}=y;if(c.current.pointers[k]){if(delete c.current.pointers[k],c.current.mainPointer!==k){const{clientX:D,clientY:j}=c.current.pointers[c.current.mainPointer];Object.assign(c.current,{prevX:D,prevY:j,prevDistance:0,startDistance:0});return}for(;Object.keys(c.current.pointers).length>0;){c.current.mainPointer=Number(Object.keys(c.current.pointers)[0]);try{c.current.target.setPointerCapture(c.current.mainPointer);const{clientX:D,clientY:j}=c.current.pointers[c.current.mainPointer];Object.assign(c.current,{prevX:D,prevY:j,prevDistance:0,startDistance:0});return}catch(D){console.log("Fails to set pointer capture",D),c.current.mainPointer=void 0,delete c.current.pointers[Object.keys(c.current.pointers)[0]]}}if(c.current.mainPointer=void 0,c.current.pressed=!1,clearTimeout(c.current.longTapTimeout),c.current.moving)c.current.moving=!1,ie.add(n,{deltaX:C-c.current.prevX,deltaY:x-c.current.prevY,startX:c.current.startX,startY:c.current.startY,clientX:C,clientY:x,distanceX:C-c.current.startX,distanceY:x-c.current.startY,button:c.current.currentButton,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,event:y}),f.current.style.cursor="auto";else{const D=Date.now();c.current.noTap?c.current.noTap=!1:c.current.timeStart-D<300&&ie.add(o,{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,event:y})}}};return P("div",{onWheel:h,onPointerDown:S,onPointerMove:v,onPointerUp:E,onPointerOut:E,onPointerLeave:E,onPointerCancel:E,onDoubleClick:y=>{const{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I}=y;ie.add(u,{clientX:C,clientY:x,altKey:p,shiftKey:b,ctrlKey:g,metaKey:w,target:I,event:y})},style:{touchAction:"none"},ref:f,children:e})},ct=({onResize:e,...t})=>{const[r]=Q(s=>[s.getBoardState]);return P(Ne,{onDrag:({deltaX:s,deltaY:o,event:a})=>{a.stopPropagation();const{scale:u}=r();e({width:s/u,height:o/u})},children:P("div",{...t})})},kn=H`
|
|
60
60
|
display: inline-block;
|
|
61
61
|
transition: transform 150ms;
|
|
62
62
|
user-select: none;
|
|
@@ -105,5 +105,5 @@ Check the top-level render call using <`+O+">.")}return _}}function ir(i,_){{if(
|
|
|
105
105
|
cursor: nwse-resize;
|
|
106
106
|
bottom: -6px;
|
|
107
107
|
right: -6px;
|
|
108
|
-
`,Yn=({onReload:e})=>ae("div",{className:`syncboard-error-item ${H({width:"100px",display:"flex",flexDirection:"column",justifyContent:"center",textAlign:"center",color:"red"})}`,children:["Sorry, this item seems broken.",P("button",{onClick:e,children:"Reload it"})]});class Bn extends d.Component{constructor(t){super(t),this.state={hasError:!1,itemId:t.itemId},this.onReload=this.onReload.bind(this)}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error(`Error for item ${this.state.itemId}`,t,this.props.state)}onReload(){this.setState({hasError:!1})}render(){const{ErrorComponent:t}=this.props;return this.state.hasError?P(t,{onReload:this.onReload}):this.props.children}}const Nn=e=>{e.target.className=""},Xn=({width:e,height:t,actualWidth:r,actualHeight:n,prevState:o,keepRatio:s})=>{let{width:a,height:u}=o;if([a,u]=[parseFloat(a),parseFloat(u)],(!a||Number.isNaN(Number(a)))&&(a=r),(!u||Number.isNaN(Number(u)))&&(u=n),s){const l=a/u;return{...o,width:(a+e).toFixed(1),height:(u+t/l).toFixed(1)}}return{...o,width:(a+e).toFixed(1),height:(u+t).toFixed(1)}},Un={w:!0,h:!0,b:!0},Wn=({setState:e,state:{type:t,rotation:r=0,id:n,locked:o,extraClasses:s,...a}={},animate:u="hvr-pop",isSelected:l,itemMap:m,showResizeHandle:f=!0})=>{var w;const c=d.useRef(null),[h]=Q(I=>[I.config.uid]),{component:S=()=>null,resizeDirections:v=Un,resize:E=Xn}=m[t],T=d.useCallback((I,k=!1)=>e(n,I,k),[e,n]);d.useEffect(()=>{c.current.className=u},[u]);const y=["item",n,kn];o&&y.push("locked"),l&&(y.push("selected"),y.push(Pn));const C=y.join(" "),x=({width:I=0,height:k=0,keepRatio:D})=>{T(j=>{const{offsetWidth:A,offsetHeight:Y}=c.current;return E({prevState:j,width:I,height:k,actualHeight:Y,actualWidth:A,keepRatio:D})})},p=({width:I})=>{x({width:I})},b=({height:I})=>{x({height:I})},g=({width:I})=>{x({height:I,width:I,keepRatio:!0})};return P("div",{style:{transform:`rotate(${r}deg`},"data-id":n,id:`${h}__${n}`,className:C,children:ae("div",{style:{display:"flex"},ref:c,onAnimationEnd:Nn,onKeyDown:I=>I.stopPropagation(),onKeyUp:I=>I.stopPropagation(),children:[P(Bn,{itemId:n,state:a,ErrorComponent:((w=m==null?void 0:m.error)==null?void 0:w.component)||Yn,children:P(S,{...a,id:n,setState:T})}),P("div",{className:`corner ${ke} ${Mn}`}),P("div",{className:`corner ${ke} ${jn}`}),P("div",{className:`corner ${ke} ${Rn}`}),P("div",{className:`corner ${ke} ${Dn}`}),P("div",{className:`center ${ke} ${$n}`}),f&&ae(pr,{children:[v.b&&P(ct,{className:`${ut} ${zn}`,onResize:g}),v.h&&P(ct,{className:`${ut} ${Ln}`,onResize:b}),v.w&&P(ct,{className:`${ut} ${An}`,onResize:p})]})]})})},Vn=d.memo(Wn,({state:e,setState:t,isSelected:r,showResizeHandle:n},{state:o,setState:s,isSelected:a,showResizeHandle:u})=>r===a&&n===u&&t===s&&wn(e,o)),Fn=e=>e,Kn=({state:e={},getCurrentUser:t,className:r,...n})=>{if(!n.itemMap[e.type])return null;const{stateHook:o=Fn}=n.itemMap[e.type],{x:s=0,y:a=0,layer:u=0,moving:l,...m}=o(e,{getCurrentUser:t}),f=(u+4)*10+100+(l?5:0);return P("div",{className:r,style:{transform:`translate(${s}px, ${a}px)`,zIndex:f},children:P(Vn,{...n,showResizeHandle:n.isSelected&&n.showResizeHandle,state:m})})},Hn=d.memo(Kn),qn=()=>{const{updateItem:e}=Be(),[t,r]=oe(m=>[m.itemIds,m.items]),[n,o,s,a]=Q(m=>[m.config.boardSize,m.config.showResizeHandle,m.config.itemTemplates,m.selection]),[u]=ye(m=>[m.getUser]),l=H({position:"absolute",top:`${n/2}px`,left:`${n/2}px`,display:"inline-block",lineHeight:0});return t.map(m=>P(Hn,{state:r[m],setState:e,isSelected:a.includes(m),itemMap:s,boardSize:n,getCurrentUser:u,showResizeHandle:o,className:l},m))};function Gn(e=!1){const t=d.useRef(e),r=d.useCallback(()=>t.current,[]);return d.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),r}function Jn(e,...t){e&&e.addEventListener&&e.addEventListener(...t)}function Zn(e,...t){e&&e.removeEventListener&&e.removeEventListener(...t)}const Qn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function ue(e,...t){const r=Gn(),n=rt(t[1]),o=d.useMemo(()=>function(...s){r()&&(typeof n.current=="function"?n.current.apply(this,s):typeof n.current.handleEvent=="function"&&n.current.handleEvent.apply(this,s))},[]);d.useEffect(()=>{const s=e&&Qn(e,"current")?e.current:e;if(!s)return;const a=t.slice(2);return Jn(s,t[0],o,...a),()=>Zn(s,t[0],o,...a)},[e,t[0]])}const eo=H({zIndex:210,position:"absolute",backgroundColor:"hsla(0, 40%, 50%, 10%)",border:"2px solid hsl(0, 55%, 40%)"}),to=(e,t,r=!1)=>{const n=t.getElementsByClassName("selector");if(!n.length)return[];const o=n[0];return Array.from(t.getElementsByClassName("item")).filter(s=>{const a=Te(s),u=e[a];return!u||!r&&u.locked?!1:Tr(s,o)}).map(s=>Te(s))},ro=({children:e,moveFirst:t})=>{const[r,n,o,s,a,u]=Q(g=>[g.getSelection,g.clear,g.setSelection,g.select,g.getConfiguration,g.getBoardState,g.updateBoardState]),{findElementUnderPointer:l}=Be(),[m]=oe(g=>[g.getItems]),[f,c]=d.useState({}),[,h]=d.useTransition(),[S,v]=d.useState(!1),E=d.useRef(null),T=d.useRef({moving:!1});return ue(document,"keydown",g=>{g.key==="l"&&v(!0)}),ue(document,"keyup",g=>{g.key==="l"&&v(!1)}),d.useEffect(()=>(n(),()=>{n()}),[n]),d.useEffect(()=>{if(T.current.moving){const g=m(),{boardWrapper:w}=a(),I=to(g,w,S);h(()=>{o(I)})}},[a,m,f,o,S]),P(Ne,{onDragStart:async g=>{await l(g)||(T.current.moving=!0,h(()=>{u({selecting:!0})}),E.current.style.cursor="crosshair")},onDrag:({distanceY:g,distanceX:w,startX:I,startY:k})=>{if(T.current.moving){const{top:D,left:j}=E.current.getBoundingClientRect(),A=I-j,Y=k-D;w>0?(T.current.left=A,T.current.width=w):(T.current.left=A+w,T.current.width=-w),g>0?(T.current.top=Y,T.current.height=g):(T.current.top=Y+g,T.current.height=-g),c({...T.current,moving:!0})}},onDragEnd:()=>{T.current.moving&&(h(()=>{u({selecting:!1})}),T.current.moving=!1,c({moving:!1}),E.current.style.cursor="auto")},onTap:g=>{const{target:w,ctrlKey:I,metaKey:k}=g,D=l(g);if(!D&&Oe(w,"board"))n();else{const j=Te(D);if(!j){n();return}const A=r();D&&!A.includes(j)&&(I||k?s([j]):o([j]))}},onLongTap:({target:g})=>{const w=Oe(g,"item");if(w){const I=Te(w);o([I])}},mainAction:t?"pan":"drag",children:ae("div",{ref:E,children:[f.moving&&P("div",{style:{transform:`translate(${f.left}px, ${f.top}px)`,height:`${f.height}px`,width:`${f.width}px`},className:`selector ${eo}`}),e]})})},no=({children:e})=>{const{moveItems:t,placeItems:r,findElementUnderPointer:n}=Be(),{vectorFromWrapperToBoard:o}=ve(),[s,a,u,l,m]=Q(y=>[y.select,y.setSelection,y.getSelection,y.getBoardState,y.updateBoardState]),[f]=oe(y=>[y.getBoardConfig]),c=d.useRef({}),h=d.useRef({items:[]}),S=y=>{const{ctrlKey:C,metaKey:x,event:p}=y,b=n(y);if(b){p.stopPropagation();const g=u();h.current.items=g;const w=Te(b);g.includes(w)||(C||x?(h.current.items=[...g,w],s([w])):(h.current.items=[w],a([w]))),Object.assign(c.current,{moving:!0})}},v=({deltaX:y,deltaY:C,event:x})=>{if(c.current.moving){x.stopPropagation();const{movingItems:p}=l(),[b,g]=o(y,C);t(h.current.items,{x:b,y:g},!0),p||m({movingItems:!0})}},E=()=>{if(c.current.moving){const{gridSize:y=1}=f(),C=y||1;c.current={moving:!1},r(h.current.items,{type:"grid",size:C}),m({movingItems:!1})}};return ue(document,"keydown",y=>{if(["INPUT","TEXTAREA"].includes(y.target.tagName))return;const C=u();if(C.length){const{gridSize:x=1}=f();let p=0,b=0;switch(y.key){case"ArrowLeft":p=-10;break;case"ArrowRight":p=10;break;case"ArrowUp":b=-10;break;case"ArrowDown":b=10;break}if(p||b){y.shiftKey&&(p*=5,b*=5),(y.ctrlKey||y.altKey||y.metaKey)&&(p/=10,b/=10);const[g,w]=o(p,b);t(C,{x:g,y:w},!0),r(C,{type:"grid",size:x||1}),y.preventDefault()}}}),P(Ne,{onDragStart:S,onDrag:v,onDragEnd:E,children:e})},oo=e=>{const t=d.useRef({hover:!1,x:0,y:0});return ue(e.current,"mousemove",n=>{const{clientX:o,clientY:s}=n;t.current.x=o,t.current.y=s}),ue(e.current,"mouseenter",()=>{t.current.hover=!0}),ue(e.current,"mouseleave",()=>{t.current.hover=!1}),d.useCallback(()=>t.current,[])},so=[...Array(5).keys()].map(e=>`Digit${e+1}`),io=()=>{const[e,t]=d.useState({}),[r,n]=Q(o=>[o.getBoardState,o.updateBoardState]);return ue(document,"keydown",o=>{if(!["INPUT","TEXTAREA"].includes(o.target.tagName)&&so.includes(o.code)){const s=o.code,{translateX:a,translateY:u,scale:l}=r();o.altKey||o.metaKey||o.ctrlKey||o.shiftKey?t(m=>({...m,[s]:{translateX:a,translateY:u,scale:l}})):e[s]&&n(e[s]),o.preventDefault()}}),null},ao=({children:e,moveFirst:t=!1})=>{const r=d.useRef(null),[n,o,s,a,u]=Q(p=>[{translateX:p.boardState.translateX,translateY:p.boardState.translateY,scale:p.boardState.scale,rotate:p.boardState.rotate},p.config.itemExtent,p.getConfiguration,p.updateBoardState,p.getSelection]),{zoomToCenter:l,zoomToExtent:m,moveBoard:f}=ve(),[c,h]=d.useState(!1),S=d.useRef({}),v=oo(r);io();const E=d.useCallback(()=>{const{itemExtent:p}=s();m(p)},[s,m]);d.useEffect(()=>{!c&&o.radius&&(E(),h(!0))},[E,c,o]);const T=({clientX:p,clientY:b,scale:g})=>{l({to:{x:p,y:b},factor:1-g/500}),clearTimeout(S.current.zoom),S.current.zoom=setTimeout(()=>{a({zooming:!1})},200),a({zooming:!0})},y=({deltaX:p,deltaY:b})=>{f(({translateX:g,translateY:w})=>({translateX:g+p,translateY:w+b})),clearTimeout(S.current.pan),S.current.pan=setTimeout(()=>{a({panning:!1})},200),a({panning:!0})},C=p=>{if(["INPUT","TEXTAREA"].includes(p.target.tagName))return;let b=0,g=0,w=1;switch(p.key){case"ArrowLeft":b=-10;break;case"ArrowRight":b=10;break;case"ArrowUp":g=-10;break;case"ArrowDown":g=10;break;case"PageUp":w=1.2;break;case"PageDown":w=.8;break}if(b||g||w!==1){const I=u();if(w===1&&I.length)return;p.shiftKey&&(b*=5,g*=5),(p.ctrlKey||p.altKey||p.metaKey)&&(b/=5,g/=5),f(({translateX:k,translateY:D})=>({translateX:k+b,translateY:D+g})),l({factor:w}),p.preventDefault()}p.key===" "&&!p.repeat&&v().hover&&l({factor:3,to:v()})},x=p=>{["INPUT","TEXTAREA"].includes(p.target.tagName)||p.key===" "&&v().hover&&l({factor:1/3,to:v()})};return ue(document,"keydown",C),ue(document,"keyup",x),P(Ne,{onPan:y,onZoom:T,mainAction:t?"pan":"drag",children:P("div",{style:{display:"inline-block",transformOrigin:"top left",transform:`translate(${n.translateX}px, ${n.translateY}px) rotate(${n.rotate}deg) scale(${n.scale})`},className:`board-pane${n.scale<.5?" board-pane__far":""}`,ref:r,children:e})})},co=H({position:"absolute",top:0,left:0,zIndex:210,backgroundColor:"hsla(0, 40%, 50%, 0%)",border:"2px dashed hsl(20, 55%, 40%)",pointerEvents:"none"}),uo=()=>{const[e,t,r,n,o,{translateX:s,translateY:a,scale:u}]=Q(c=>[c.selection,c.getSelection,c.selectionBox,c.setSelectionBox,c.getConfiguration,{translateX:c.boardState.translateX,translateY:c.boardState.translateY,scale:c.boardState.scale}]),[l]=oe(c=>[c.items]),m=d.useCallback(()=>{const c=t(),{boardWrapperRect:h,uid:S}=o();if(c.length===0){n(null);return}const v=kr(c,S);if(!v){n(null);return}const{left:E,top:T,width:y,height:C}=v,x={left:E-h.left,top:T-h.top,height:C,width:y};n(x)},[o,t,n]),f=nt(m,[m],300);return d.useEffect(()=>{m(),f()},[e,l,s,a,u,m,f]),!r||e.length<2?null:P("div",{style:{transform:`translate(${r.left}px, ${r.top}px)`,height:`${r.height}px`,width:`${r.width}px`},className:`selection ${co}`})},lo=()=>{const[e]=Q(t=>[t.boardState.movingItems]);return e?null:P(uo,{})},fo=typeof window<"u"&&typeof navigator<"u"&&typeof document<"u";let Xe;function mo(){if(!fo)return;if(Xe)return Xe;const e=new Map,t=new ResizeObserver(r=>{r.forEach(n=>{var o;return(o=e.get(n.target))==null?void 0:o.forEach(s=>setTimeout(()=>s(n),0))})});return Xe={observer:t,subscribe:(r,n)=>{let o=e.get(r);o||(o=new Set,e.set(r,o),t.observe(r)),o.add(n)},unsubscribe:(r,n)=>{const o=e.get(r);o&&(o.delete(n),o.size||(e.delete(r),t.unobserve(r)))}},Xe}function po(e,t,r=!0){const n=r&&mo(),o=rt(t),s=e&&"current"in e?e.current:e;d.useEffect(()=>{const a=e&&"current"in e?e.current:e;if(!n||!a)return;let u=!0;const l=(...m)=>{u&&o.current(...m)};return n.subscribe(a,l),()=>{u=!1,n.unsubscribe(a,l)}},[s,n])}function Kt(e,t,r){return Math.min(Math.max(e,r),t)}class go extends Error{constructor(t){super(`Failed to parse color: "${t}"`)}}var Pe=go;function ho(e){if(typeof e!="string")throw new Pe(e);if(e.trim().toLowerCase()==="transparent")return[0,0,0,0];let t=e.trim();t=Co.test(e)?So(e):e;const r=bo.exec(t);if(r){const a=Array.from(r).slice(1);return[...a.slice(0,3).map(u=>parseInt(Me(u,2),16)),parseInt(Me(a[3]||"f",2),16)/255]}const n=_o.exec(t);if(n){const a=Array.from(n).slice(1);return[...a.slice(0,3).map(u=>parseInt(u,16)),parseInt(a[3]||"ff",16)/255]}const o=Eo.exec(t);if(o){const a=Array.from(o).slice(1);return[...a.slice(0,3).map(u=>parseInt(u,10)),parseFloat(a[3]||"1")]}const s=wo.exec(t);if(s){const[a,u,l,m]=Array.from(s).slice(1).map(parseFloat);if(Kt(0,100,u)!==u)throw new Pe(e);if(Kt(0,100,l)!==l)throw new Pe(e);return[...xo(a,u,l),Number.isNaN(m)?1:m]}throw new Pe(e)}function vo(e){let t=5381,r=e.length;for(;r;)t=t*33^e.charCodeAt(--r);return(t>>>0)%2341}const Ht=e=>parseInt(e.replace(/_/g,""),36),yo="1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((e,t)=>{const r=Ht(t.substring(0,3)),n=Ht(t.substring(3)).toString(16);let o="";for(let s=0;s<6-n.length;s++)o+="0";return e[r]=`${o}${n}`,e},{});function So(e){const t=e.toLowerCase().trim(),r=yo[vo(t)];if(!r)throw new Pe(e);return`#${r}`}const Me=(e,t)=>Array.from(Array(t)).map(()=>e).join(""),bo=new RegExp(`^#${Me("([a-f0-9])",3)}([a-f0-9])?$`,"i"),_o=new RegExp(`^#${Me("([a-f0-9]{2})",3)}([a-f0-9]{2})?$`,"i"),Eo=new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${Me(",\\s*(\\d+)\\s*",2)}(?:,\\s*([\\d.]+))?\\s*\\)$`,"i"),wo=/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i,Co=/^[a-z]+$/i,qt=e=>Math.round(e*255),xo=(e,t,r)=>{let n=r/100;if(t===0)return[n,n,n].map(qt);const o=(e%360+360)%360/60,s=(1-Math.abs(2*n-1))*(t/100),a=s*(1-Math.abs(o%2-1));let u=0,l=0,m=0;o>=0&&o<1?(u=s,l=a):o>=1&&o<2?(u=a,l=s):o>=2&&o<3?(l=s,m=a):o>=3&&o<4?(l=a,m=s):o>=4&&o<5?(u=a,m=s):o>=5&&o<6&&(u=s,m=a);const f=n-s/2,c=u+f,h=l+f,S=m+f;return[c,h,S].map(qt)};function Io(e){if(e==="transparent")return 0;function t(s){const a=s/255;return a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4)}const[r,n,o]=ho(e);return .2126*t(r)+.7152*t(n)+.0722*t(o)}function Oo(e){return Io(e)>.179}const To=H({display:"flex",flexDirection:"row",alignItems:"center",zIndex:210,pointerEvents:"none"}),ko=H({fontWeight:"bold",padding:"0 0.5em",borderRadius:"2px",maxWidth:"5em",overflow:"hidden",textOverflow:"ellipsis",marginLeft:"-0.5em",marginTop:"1.7em",whitespace:"nowrap",pointerEvents:"none"}),Po=({color:e="#666",size:t=40,text:r})=>{const n=Oo(e)?"#222":"#EEE";return ae("div",{className:To,children:[ae("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"1064.7701 445.5539 419.8101 717.0565",width:t,height:t,children:[P("path",{d:"m 1197.1015,869.718 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z",style:{fill:n}}),P("path",{d:"m 1193.0939,861.12419 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z",style:{fill:"white",stroke:"#111",strokeWidth:20}})]}),P("div",{style:{color:n,backgroundColor:e},className:ko,children:r})]})},Mo=d.memo(Po),jo=H({top:0,left:0,zIndex:210,position:"fixed",pointerEvents:"none"}),Do=({pos:e,...t})=>P("div",{className:jo,style:{transform:`translate(${e.x-6}px, ${e.y-15}px)`},children:P(Mo,{...t})}),Ro=({children:e})=>{const[t]=Q(v=>[v.getConfiguration,v.boardState.scale]),{fromWrapperToBoard:r,fromBoardToWrapper:n}=ve(),[o,s,a,u]=ye(v=>[v.getUser(),v.getLocalUsers(),v.cursors,v.users]),[l,m]=ye(v=>[v.moveCursor,v.removeCursor]),{boardWrapperRect:f}=t(),c=({clientX:v,clientY:E})=>{const[T,y]=r(v-f.left,E-f.top);l(o.id,{x:T,y})},h=()=>{m(o.id)},S=s.reduce((v,E)=>(E.id!==o.id&&a[E.id]&&(v[E.id]=a[E.id]),v),{});return ae("div",{onPointerMove:c,onPointerLeave:h,children:[e,Object.entries(S).map(([v,E])=>{const[T,y]=n(E.x,E.y),C={x:T+f.left,y:y+f.top};return et(C,f)?P(Do,{pos:C,text:u[v].name,color:u[v].color},v):null})]})},$o=({children:e})=>e,Ao={overflow:"hidden",position:"absolute",inset:0},Lo=({moveFirst:e=!0,style:t,wrapperStyle:r,itemTemplates:n={},boardSize:o=Rt,children:s,showResizeHandle:a=!1,Wrapper:u=$o})=>{const l=d.useRef(null),[m,f]=Q(v=>[v.config.uid,v.updateConfiguration]),{updateItemExtent:c}=ve(),h={userSelect:"none",width:`${o}px`,height:`${o}px`,backgroundColor:"#333",...t};d.useEffect(()=>{const v=E=>{Oe(E.target,"board")&&E.preventDefault()};return document.body.addEventListener("wheel",v,{passive:!1}),()=>{document.body.removeEventListener("wheel",v)}},[]),d.useEffect(()=>{f({boardWrapper:l.current})},[f]),d.useEffect(()=>{m||f({uid:pe()})},[m,f]),d.useEffect(()=>{f({itemTemplates:n,boardSize:o,showResizeHandle:a})},[n,o,a,f]),d.useEffect(()=>{f({boardWrapperRect:l.current.getBoundingClientRect()}),c(),setTimeout(c,2e3)},[f,c]),po(l,()=>{l.current&&f({boardWrapperRect:l.current.getBoundingClientRect()})});const S=H({...Ao,...r});return ae("div",{ref:l,id:m,className:`sync-board ${S}`,children:[P(Ro,{children:P(ro,{moveFirst:e,children:P(ao,{moveFirst:e,children:P(no,{moveFirst:e,children:P(u,{children:ae("div",{onContextMenu:v=>{v.preventDefault()},style:h,className:"board",children:[P(qn,{}),s]})})})})})}),P(lo,{})]})};En(d.createElement),U.Board=Lo,U.BoardWrapper=pn,U.RoomWrapper=gn,U.useAvailableActions=Qr,U.useBoardConfig=sn,U.useBoardPosition=ve,U.useBoardState=an,U.useDebouncedItems=zr,U.useGetSelectedItems=Wr,U.useItemActions=Be,U.useItemInteraction=st,U.useItems=Lr,U.useMessage=mn,U.useSelectedItems=Ur,U.useSelectionBox=en,U.useSessionInfo=cn,U.useUsers=on,U.useWire=Ie,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
|
|
108
|
+
`,Yn=({onReload:e})=>ae("div",{className:`syncboard-error-item ${H({width:"100px",display:"flex",flexDirection:"column",justifyContent:"center",textAlign:"center",color:"red"})}`,children:["Sorry, this item seems broken.",P("button",{onClick:e,children:"Reload it"})]});class Bn extends d.Component{constructor(t){super(t),this.state={hasError:!1,itemId:t.itemId},this.onReload=this.onReload.bind(this)}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(t){console.error(`Error for item ${this.state.itemId}`,t,this.props.state)}onReload(){this.setState({hasError:!1})}render(){const{ErrorComponent:t}=this.props;return this.state.hasError?P(t,{onReload:this.onReload}):this.props.children}}const Nn=e=>{e.target.className=""},Xn=({width:e,height:t,actualWidth:r,actualHeight:n,prevState:s,keepRatio:o})=>{let{width:a,height:u}=s;if([a,u]=[parseFloat(a),parseFloat(u)],(!a||Number.isNaN(Number(a)))&&(a=r),(!u||Number.isNaN(Number(u)))&&(u=n),o){const l=a/u;return{...s,width:(a+e).toFixed(1),height:(u+t/l).toFixed(1)}}return{...s,width:(a+e).toFixed(1),height:(u+t).toFixed(1)}},Un={w:!0,h:!0,b:!0},Wn=({setState:e,state:{type:t,rotation:r=0,id:n,locked:s,extraClasses:o,...a}={},animate:u="hvr-pop",isSelected:l,itemMap:m,showResizeHandle:f=!0})=>{var w;const c=d.useRef(null),[h]=Q(I=>[I.config.uid]),{component:S=()=>null,resizeDirections:v=Un,resize:E=Xn}=m[t],T=d.useCallback((I,k=!1)=>e(n,I,k),[e,n]);d.useEffect(()=>{c.current.className=u},[u]);const y=["item",n,kn];s&&y.push("locked"),l&&(y.push("selected"),y.push(Pn));const C=y.join(" "),x=({width:I=0,height:k=0,keepRatio:D})=>{T(j=>{const{offsetWidth:A,offsetHeight:Y}=c.current;return E({prevState:j,width:I,height:k,actualHeight:Y,actualWidth:A,keepRatio:D})})},p=({width:I})=>{x({width:I})},b=({height:I})=>{x({height:I})},g=({width:I})=>{x({height:I,width:I,keepRatio:!0})};return P("div",{style:{transform:`rotate(${r}deg`},"data-id":n,id:`${h}__${n}`,className:C,children:ae("div",{style:{display:"flex"},ref:c,onAnimationEnd:Nn,onKeyDown:I=>I.stopPropagation(),onKeyUp:I=>I.stopPropagation(),children:[P(Bn,{itemId:n,state:a,ErrorComponent:((w=m==null?void 0:m.error)==null?void 0:w.component)||Yn,children:P(S,{...a,id:n,setState:T})}),P("div",{className:`corner ${ke} ${Mn}`}),P("div",{className:`corner ${ke} ${jn}`}),P("div",{className:`corner ${ke} ${Rn}`}),P("div",{className:`corner ${ke} ${Dn}`}),P("div",{className:`center ${ke} ${$n}`}),f&&ae(pr,{children:[v.b&&P(ct,{className:`${ut} ${zn}`,onResize:g}),v.h&&P(ct,{className:`${ut} ${Ln}`,onResize:b}),v.w&&P(ct,{className:`${ut} ${An}`,onResize:p})]})]})})},Vn=d.memo(Wn,({state:e,setState:t,isSelected:r,showResizeHandle:n},{state:s,setState:o,isSelected:a,showResizeHandle:u})=>r===a&&n===u&&t===o&&wn(e,s)),Fn=e=>e,Kn=({state:e={},getCurrentUser:t,className:r,...n})=>{if(!n.itemMap[e.type])return null;const{stateHook:s=Fn}=n.itemMap[e.type],{x:o=0,y:a=0,layer:u=0,moving:l,...m}=s(e,{getCurrentUser:t}),f=(u+4)*10+100+(l?5:0);return P("div",{className:r,style:{transform:`translate(${o}px, ${a}px)`,zIndex:f},children:P(Vn,{...n,showResizeHandle:n.isSelected&&n.showResizeHandle,state:m})})},Hn=d.memo(Kn),qn=()=>{const{updateItem:e}=Be(),[t,r]=se(m=>[m.itemIds,m.items]),[n,s,o,a]=Q(m=>[m.config.boardSize,m.config.showResizeHandle,m.config.itemTemplates,m.selection]),[u]=ye(m=>[m.getUser]),l=H({position:"absolute",top:`${n/2}px`,left:`${n/2}px`,display:"inline-block",lineHeight:0});return t.map(m=>P(Hn,{state:r[m],setState:e,isSelected:a.includes(m),itemMap:o,boardSize:n,getCurrentUser:u,showResizeHandle:s,className:l},m))};function Gn(e=!1){const t=d.useRef(e),r=d.useCallback(()=>t.current,[]);return d.useEffect(()=>(t.current=!0,()=>{t.current=!1}),[]),r}function Jn(e,...t){e&&e.addEventListener&&e.addEventListener(...t)}function Zn(e,...t){e&&e.removeEventListener&&e.removeEventListener(...t)}const Qn=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);function ue(e,...t){const r=Gn(),n=rt(t[1]),s=d.useMemo(()=>function(...o){r()&&(typeof n.current=="function"?n.current.apply(this,o):typeof n.current.handleEvent=="function"&&n.current.handleEvent.apply(this,o))},[]);d.useEffect(()=>{const o=e&&Qn(e,"current")?e.current:e;if(!o)return;const a=t.slice(2);return Jn(o,t[0],s,...a),()=>Zn(o,t[0],s,...a)},[e,t[0]])}const es=H({zIndex:210,position:"absolute",backgroundColor:"hsla(0, 40%, 50%, 10%)",border:"2px solid hsl(0, 55%, 40%)"}),ts=(e,t,r=!1)=>{const n=t.getElementsByClassName("selector");if(!n.length)return[];const s=n[0];return Array.from(t.getElementsByClassName("item")).filter(o=>{const a=Te(o),u=e[a];return!u||!r&&u.locked?!1:Tr(o,s)}).map(o=>Te(o))},rs=({children:e,moveFirst:t})=>{const[r,n,s,o,a,u]=Q(g=>[g.getSelection,g.clear,g.setSelection,g.select,g.getConfiguration,g.getBoardState,g.updateBoardState]),{findElementUnderPointer:l}=Be(),[m]=se(g=>[g.getItems]),[f,c]=d.useState({}),[,h]=d.useTransition(),[S,v]=d.useState(!1),E=d.useRef(null),T=d.useRef({moving:!1});return ue(document,"keydown",g=>{g.key==="l"&&v(!0)}),ue(document,"keyup",g=>{g.key==="l"&&v(!1)}),d.useEffect(()=>(n(),()=>{n()}),[n]),d.useEffect(()=>{if(T.current.moving){const g=m(),{boardWrapper:w}=a(),I=ts(g,w,S);h(()=>{s(I)})}},[a,m,f,s,S]),P(Ne,{onDragStart:async g=>{await l(g)||(T.current.moving=!0,h(()=>{u({selecting:!0})}),E.current.style.cursor="crosshair")},onDrag:({distanceY:g,distanceX:w,startX:I,startY:k})=>{if(T.current.moving){const{top:D,left:j}=E.current.getBoundingClientRect(),A=I-j,Y=k-D;w>0?(T.current.left=A,T.current.width=w):(T.current.left=A+w,T.current.width=-w),g>0?(T.current.top=Y,T.current.height=g):(T.current.top=Y+g,T.current.height=-g),c({...T.current,moving:!0})}},onDragEnd:()=>{T.current.moving&&(h(()=>{u({selecting:!1})}),T.current.moving=!1,c({moving:!1}),E.current.style.cursor="auto")},onTap:g=>{const{target:w,ctrlKey:I,metaKey:k}=g,D=l(g);if(!D&&Oe(w,"board"))n();else{const j=Te(D);if(!j){n();return}const A=r();D&&!A.includes(j)&&(I||k?o([j]):s([j]))}},onLongTap:({target:g})=>{const w=Oe(g,"item");if(w){const I=Te(w);s([I])}},mainAction:t?"pan":"drag",children:ae("div",{ref:E,children:[f.moving&&P("div",{style:{transform:`translate(${f.left}px, ${f.top}px)`,height:`${f.height}px`,width:`${f.width}px`},className:`selector ${es}`}),e]})})},ns=({children:e})=>{const{moveItems:t,placeItems:r,findElementUnderPointer:n}=Be(),{vectorFromWrapperToBoard:s}=ve(),[o,a,u,l,m]=Q(y=>[y.select,y.setSelection,y.getSelection,y.getBoardState,y.updateBoardState]),[f]=se(y=>[y.getBoardConfig]),c=d.useRef({}),h=d.useRef({items:[]}),S=y=>{const{ctrlKey:C,metaKey:x,event:p}=y,b=n(y);if(b){p.stopPropagation();const g=u();h.current.items=g;const w=Te(b);g.includes(w)||(C||x?(h.current.items=[...g,w],o([w])):(h.current.items=[w],a([w]))),Object.assign(c.current,{moving:!0})}},v=({deltaX:y,deltaY:C,event:x})=>{if(c.current.moving){x.stopPropagation();const{movingItems:p}=l(),[b,g]=s(y,C);t(h.current.items,{x:b,y:g},!0),p||m({movingItems:!0})}},E=()=>{if(c.current.moving){const{gridSize:y=1}=f(),C=y||1;c.current={moving:!1},r(h.current.items,{type:"grid",size:C}),m({movingItems:!1})}};return ue(document,"keydown",y=>{if(["INPUT","TEXTAREA"].includes(y.target.tagName))return;const C=u();if(C.length){const{gridSize:x=1}=f();let p=0,b=0;switch(y.key){case"ArrowLeft":p=-10;break;case"ArrowRight":p=10;break;case"ArrowUp":b=-10;break;case"ArrowDown":b=10;break}if(p||b){y.shiftKey&&(p*=5,b*=5),(y.ctrlKey||y.altKey||y.metaKey)&&(p/=10,b/=10);const[g,w]=s(p,b);t(C,{x:g,y:w},!0),r(C,{type:"grid",size:x||1}),y.preventDefault()}}}),P(Ne,{onDragStart:S,onDrag:v,onDragEnd:E,children:e})},ss=e=>{const t=d.useRef({hover:!1,x:0,y:0});return ue(e.current,"mousemove",n=>{const{clientX:s,clientY:o}=n;t.current.x=s,t.current.y=o}),ue(e.current,"mouseenter",()=>{t.current.hover=!0}),ue(e.current,"mouseleave",()=>{t.current.hover=!1}),d.useCallback(()=>t.current,[])},os=[...Array(5).keys()].map(e=>`Digit${e+1}`),is=()=>{const[e,t]=d.useState({}),[r,n]=Q(s=>[s.getBoardState,s.updateBoardState]);return ue(document,"keydown",s=>{if(!["INPUT","TEXTAREA"].includes(s.target.tagName)&&os.includes(s.code)){const o=s.code,{translateX:a,translateY:u,scale:l}=r();s.altKey||s.metaKey||s.ctrlKey||s.shiftKey?t(m=>({...m,[o]:{translateX:a,translateY:u,scale:l}})):e[o]&&n(e[o]),s.preventDefault()}}),null},as=({children:e,moveFirst:t=!1})=>{const r=d.useRef(null),[n,s,o,a,u]=Q(p=>[{translateX:p.boardState.translateX,translateY:p.boardState.translateY,scale:p.boardState.scale,rotate:p.boardState.rotate},p.config.itemExtent,p.getConfiguration,p.updateBoardState,p.getSelection]),{zoomToCenter:l,zoomToExtent:m,moveBoard:f}=ve(),[c,h]=d.useState(!1),S=d.useRef({}),v=ss(r);is();const E=d.useCallback(()=>{const{itemExtent:p}=o();m(p)},[o,m]);d.useEffect(()=>{!c&&s.radius&&(E(),h(!0))},[E,c,s]);const T=({clientX:p,clientY:b,scale:g})=>{l({to:{x:p,y:b},factor:1-g/500}),clearTimeout(S.current.zoom),S.current.zoom=setTimeout(()=>{a({zooming:!1})},200),a({zooming:!0})},y=({deltaX:p,deltaY:b})=>{f(({translateX:g,translateY:w})=>({translateX:g+p,translateY:w+b})),clearTimeout(S.current.pan),S.current.pan=setTimeout(()=>{a({panning:!1})},200),a({panning:!0})},C=p=>{if(["INPUT","TEXTAREA"].includes(p.target.tagName))return;let b=0,g=0,w=1;switch(p.key){case"ArrowLeft":b=-10;break;case"ArrowRight":b=10;break;case"ArrowUp":g=-10;break;case"ArrowDown":g=10;break;case"PageUp":w=1.2;break;case"PageDown":w=.8;break}if(b||g||w!==1){const I=u();if(w===1&&I.length)return;p.shiftKey&&(b*=5,g*=5),(p.ctrlKey||p.altKey||p.metaKey)&&(b/=5,g/=5),f(({translateX:k,translateY:D})=>({translateX:k+b,translateY:D+g})),l({factor:w}),p.preventDefault()}p.key===" "&&!p.repeat&&v().hover&&l({factor:3,to:v()})},x=p=>{["INPUT","TEXTAREA"].includes(p.target.tagName)||p.key===" "&&v().hover&&l({factor:1/3,to:v()})};return ue(document,"keydown",C),ue(document,"keyup",x),P(Ne,{onPan:y,onZoom:T,mainAction:t?"pan":"drag",children:P("div",{style:{display:"inline-block",transformOrigin:"top left",transform:`translate(${n.translateX}px, ${n.translateY}px) rotate(${n.rotate}deg) scale(${n.scale})`},className:`board-pane${n.scale<.5?" board-pane__far":""}`,ref:r,children:e})})},cs=H({position:"absolute",top:0,left:0,zIndex:210,backgroundColor:"hsla(0, 40%, 50%, 0%)",border:"2px dashed hsl(20, 55%, 40%)",pointerEvents:"none"}),us=()=>{const[e,t,r,n,s,{translateX:o,translateY:a,scale:u}]=Q(c=>[c.selection,c.getSelection,c.selectionBox,c.setSelectionBox,c.getConfiguration,{translateX:c.boardState.translateX,translateY:c.boardState.translateY,scale:c.boardState.scale}]),[l]=se(c=>[c.items]),m=d.useCallback(()=>{const c=t(),{boardWrapperRect:h,uid:S}=s();if(c.length===0){n(null);return}const v=kr(c,S);if(!v){n(null);return}const{left:E,top:T,width:y,height:C}=v,x={left:E-h.left,top:T-h.top,height:C,width:y};n(x)},[s,t,n]),f=nt(m,[m],300);return d.useEffect(()=>{m(),f()},[e,l,o,a,u,m,f]),!r||e.length<2?null:P("div",{style:{transform:`translate(${r.left}px, ${r.top}px)`,height:`${r.height}px`,width:`${r.width}px`},className:`selection ${cs}`})},ls=()=>{const[e]=Q(t=>[t.boardState.movingItems]);return e?null:P(us,{})},fs=typeof window<"u"&&typeof navigator<"u"&&typeof document<"u";let Xe;function ds(){if(!fs)return;if(Xe)return Xe;const e=new Map,t=new ResizeObserver(r=>{r.forEach(n=>{var s;return(s=e.get(n.target))==null?void 0:s.forEach(o=>setTimeout(()=>o(n),0))})});return Xe={observer:t,subscribe:(r,n)=>{let s=e.get(r);s||(s=new Set,e.set(r,s),t.observe(r)),s.add(n)},unsubscribe:(r,n)=>{const s=e.get(r);s&&(s.delete(n),s.size||(e.delete(r),t.unobserve(r)))}},Xe}function ms(e,t,r=!0){const n=r&&ds(),s=rt(t),o=e&&"current"in e?e.current:e;d.useEffect(()=>{const a=e&&"current"in e?e.current:e;if(!n||!a)return;let u=!0;const l=(...m)=>{u&&s.current(...m)};return n.subscribe(a,l),()=>{u=!1,n.unsubscribe(a,l)}},[o,n])}function Kt(e,t,r){return Math.min(Math.max(e,r),t)}class ps extends Error{constructor(t){super(`Failed to parse color: "${t}"`)}}var Pe=ps;function gs(e){if(typeof e!="string")throw new Pe(e);if(e.trim().toLowerCase()==="transparent")return[0,0,0,0];let t=e.trim();t=ws.test(e)?ys(e):e;const r=Ss.exec(t);if(r){const a=Array.from(r).slice(1);return[...a.slice(0,3).map(u=>parseInt(Me(u,2),16)),parseInt(Me(a[3]||"f",2),16)/255]}const n=bs.exec(t);if(n){const a=Array.from(n).slice(1);return[...a.slice(0,3).map(u=>parseInt(u,16)),parseInt(a[3]||"ff",16)/255]}const s=_s.exec(t);if(s){const a=Array.from(s).slice(1);return[...a.slice(0,3).map(u=>parseInt(u,10)),parseFloat(a[3]||"1")]}const o=Es.exec(t);if(o){const[a,u,l,m]=Array.from(o).slice(1).map(parseFloat);if(Kt(0,100,u)!==u)throw new Pe(e);if(Kt(0,100,l)!==l)throw new Pe(e);return[...Cs(a,u,l),Number.isNaN(m)?1:m]}throw new Pe(e)}function hs(e){let t=5381,r=e.length;for(;r;)t=t*33^e.charCodeAt(--r);return(t>>>0)%2341}const Ht=e=>parseInt(e.replace(/_/g,""),36),vs="1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm".split(" ").reduce((e,t)=>{const r=Ht(t.substring(0,3)),n=Ht(t.substring(3)).toString(16);let s="";for(let o=0;o<6-n.length;o++)s+="0";return e[r]=`${s}${n}`,e},{});function ys(e){const t=e.toLowerCase().trim(),r=vs[hs(t)];if(!r)throw new Pe(e);return`#${r}`}const Me=(e,t)=>Array.from(Array(t)).map(()=>e).join(""),Ss=new RegExp(`^#${Me("([a-f0-9])",3)}([a-f0-9])?$`,"i"),bs=new RegExp(`^#${Me("([a-f0-9]{2})",3)}([a-f0-9]{2})?$`,"i"),_s=new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${Me(",\\s*(\\d+)\\s*",2)}(?:,\\s*([\\d.]+))?\\s*\\)$`,"i"),Es=/^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i,ws=/^[a-z]+$/i,qt=e=>Math.round(e*255),Cs=(e,t,r)=>{let n=r/100;if(t===0)return[n,n,n].map(qt);const s=(e%360+360)%360/60,o=(1-Math.abs(2*n-1))*(t/100),a=o*(1-Math.abs(s%2-1));let u=0,l=0,m=0;s>=0&&s<1?(u=o,l=a):s>=1&&s<2?(u=a,l=o):s>=2&&s<3?(l=o,m=a):s>=3&&s<4?(l=a,m=o):s>=4&&s<5?(u=a,m=o):s>=5&&s<6&&(u=o,m=a);const f=n-o/2,c=u+f,h=l+f,S=m+f;return[c,h,S].map(qt)};function xs(e){if(e==="transparent")return 0;function t(o){const a=o/255;return a<=.03928?a/12.92:Math.pow((a+.055)/1.055,2.4)}const[r,n,s]=gs(e);return .2126*t(r)+.7152*t(n)+.0722*t(s)}function Is(e){return xs(e)>.179}const Os=H({display:"flex",flexDirection:"row",alignItems:"center",zIndex:210,pointerEvents:"none"}),Ts=H({fontWeight:"bold",padding:"0 0.5em",borderRadius:"2px",maxWidth:"5em",overflow:"hidden",textOverflow:"ellipsis",marginLeft:"-0.5em",marginTop:"1.7em",whitespace:"nowrap",pointerEvents:"none"}),ks=({color:e="#666",size:t=40,text:r})=>{const n=Is(e)?"#222":"#EEE";return ae("div",{className:Os,children:[ae("svg",{version:"1.1",xmlns:"http://www.w3.org/2000/svg",viewBox:"1064.7701 445.5539 419.8101 717.0565",width:t,height:t,children:[P("path",{d:"m 1197.1015,869.718 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z",style:{fill:n}}),P("path",{d:"m 1193.0939,861.12419 -62.2719,-154.49286 133.3276,-9.05842 -257.6915,-253.12748 1.2392,356.98609 88.2465,-79.47087 61.702,152.78366 z",style:{fill:"white",stroke:"#111",strokeWidth:20}})]}),P("div",{style:{color:n,backgroundColor:e},className:Ts,children:r})]})},Ps=d.memo(ks),Ms=H({top:0,left:0,zIndex:210,position:"fixed",pointerEvents:"none"}),js=({pos:e,...t})=>P("div",{className:Ms,style:{transform:`translate(${e.x-6}px, ${e.y-15}px)`},children:P(Ps,{...t})}),Ds=({children:e})=>{const[t]=Q(v=>[v.getConfiguration,v.boardState.scale]),{fromWrapperToBoard:r,fromBoardToWrapper:n}=ve(),[s,o,a,u]=ye(v=>[v.getUser(),v.getLocalUsers(),v.cursors,v.users]),[l,m]=ye(v=>[v.moveCursor,v.removeCursor]),{boardWrapperRect:f}=t(),c=({clientX:v,clientY:E})=>{const[T,y]=r(v-f.left,E-f.top);l(s.id,{x:T,y})},h=()=>{m(s.id)},S=o.reduce((v,E)=>(E.id!==s.id&&a[E.id]&&(v[E.id]=a[E.id]),v),{});return ae("div",{onPointerMove:c,onPointerLeave:h,children:[e,Object.entries(S).map(([v,E])=>{const[T,y]=n(E.x,E.y),C={x:T+f.left,y:y+f.top};return et(C,f)?P(js,{pos:C,text:u[v].name,color:u[v].color},v):null})]})},Rs=({children:e})=>e,$s={overflow:"hidden",position:"absolute",inset:0},As=({moveFirst:e=!0,style:t,wrapperStyle:r,itemTemplates:n={},boardSize:s=Rt,children:o,showResizeHandle:a=!1,Wrapper:u=Rs})=>{const l=d.useRef(null),[m,f]=Q(v=>[v.config.uid,v.updateConfiguration]),{updateItemExtent:c}=ve(),h={userSelect:"none",width:`${s}px`,height:`${s}px`,backgroundColor:"#333",...t};d.useEffect(()=>{const v=E=>{Oe(E.target,"board")&&E.preventDefault()};return document.body.addEventListener("wheel",v,{passive:!1}),()=>{document.body.removeEventListener("wheel",v)}},[]),d.useEffect(()=>{f({boardWrapper:l.current})},[f]),d.useEffect(()=>{m||f({uid:pe()})},[m,f]),d.useEffect(()=>{f({itemTemplates:n,boardSize:s,showResizeHandle:a})},[n,s,a,f]),d.useEffect(()=>{f({boardWrapperRect:l.current.getBoundingClientRect()}),c(),setTimeout(c,2e3)},[f,c]),ms(l,()=>{l.current&&f({boardWrapperRect:l.current.getBoundingClientRect()})});const S=H({...$s,...r});return ae("div",{ref:l,id:m,className:`sync-board ${S}`,children:[P(Ds,{children:P(rs,{moveFirst:e,children:P(as,{moveFirst:e,children:P(ns,{moveFirst:e,children:P(u,{children:ae("div",{onContextMenu:v=>{v.preventDefault()},style:h,className:"board",children:[P(qn,{}),o]})})})})})}),P(ls,{})]})};En(d.createElement),U.Board=As,U.BoardWrapper=pn,U.RoomWrapper=gn,U.useAvailableActions=Qr,U.useBoardConfig=on,U.useBoardPosition=ve,U.useBoardState=an,U.useDebouncedItems=zr,U.useGetSelectedItems=Wr,U.useItemActions=Be,U.useItemInteraction=ot,U.useItems=Lr,U.useMessage=mn,U.useSelectedItems=Ur,U.useSelectionBox=en,U.useSessionInfo=cn,U.useUsers=sn,U.useWire=Ie,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
|
|
109
109
|
//# sourceMappingURL=react-sync-board.umd.cjs.map
|