claw-machine-js
Version:
A physics based claw-machine simulation
31 lines (28 loc) • 24.9 kB
JavaScript
(function(G,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],O):(G=typeof globalThis<"u"?globalThis:G||self,O(G.clawjs={},G.React))})(this,function(G,O){"use strict";var Ie={exports:{}},te={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var be;function $e(){if(be)return te;be=1;var e=O,n=Symbol.for("react.element"),t=Symbol.for("react.fragment"),a=Object.prototype.hasOwnProperty,s=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,y={key:!0,ref:!0,__self:!0,__source:!0};function v(f,i,d){var T,h={},m=null,C=null;d!==void 0&&(m=""+d),i.key!==void 0&&(m=""+i.key),i.ref!==void 0&&(C=i.ref);for(T in i)a.call(i,T)&&!y.hasOwnProperty(T)&&(h[T]=i[T]);if(f&&f.defaultProps)for(T in i=f.defaultProps,i)h[T]===void 0&&(h[T]=i[T]);return{$$typeof:n,type:f,key:m,ref:C,props:h,_owner:s.current}}return te.Fragment=t,te.jsx=v,te.jsxs=v,te}var ae={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var De;function ze(){return De||(De=1,process.env.NODE_ENV!=="production"&&function(){var e=O,n=Symbol.for("react.element"),t=Symbol.for("react.portal"),a=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),y=Symbol.for("react.profiler"),v=Symbol.for("react.provider"),f=Symbol.for("react.context"),i=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),T=Symbol.for("react.suspense_list"),h=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),C=Symbol.for("react.offscreen"),E=Symbol.iterator,Y="@@iterator";function N(r){if(r===null||typeof r!="object")return null;var u=E&&r[E]||r[Y];return typeof u=="function"?u:null}var W=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function _(r){{for(var u=arguments.length,o=new Array(u>1?u-1:0),g=1;g<u;g++)o[g-1]=arguments[g];ue("error",r,o)}}function ue(r,u,o){{var g=W.ReactDebugCurrentFrame,p=g.getStackAddendum();p!==""&&(u+="%s",o=o.concat([p]));var R=o.map(function(x){return String(x)});R.unshift("Warning: "+u),Function.prototype.apply.call(console[r],console,R)}}var ie=!1,w=!1,ee=!1,oe=!1,se=!1,J;J=Symbol.for("react.module.reference");function K(r){return!!(typeof r=="string"||typeof r=="function"||r===a||r===y||se||r===s||r===d||r===T||oe||r===C||ie||w||ee||typeof r=="object"&&r!==null&&(r.$$typeof===m||r.$$typeof===h||r.$$typeof===v||r.$$typeof===f||r.$$typeof===i||r.$$typeof===J||r.getModuleId!==void 0))}function V(r,u,o){var g=r.displayName;if(g)return g;var p=u.displayName||u.name||"";return p!==""?o+"("+p+")":o}function Z(r){return r.displayName||"Context"}function c(r){if(r==null)return null;if(typeof r.tag=="number"&&_("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof r=="function")return r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case a:return"Fragment";case t:return"Portal";case y:return"Profiler";case s:return"StrictMode";case d:return"Suspense";case T:return"SuspenseList"}if(typeof r=="object")switch(r.$$typeof){case f:var u=r;return Z(u)+".Consumer";case v:var o=r;return Z(o._context)+".Provider";case i:return V(r,r.render,"ForwardRef");case h:var g=r.displayName||null;return g!==null?g:c(r.type)||"Memo";case m:{var p=r,R=p._payload,x=p._init;try{return c(x(R))}catch{return null}}}return null}var M=Object.assign,H=0,ge,le,xe,fe,pe,me,he;function X(){}X.__reactDisabledLog=!0;function Re(){{if(H===0){ge=console.log,le=console.info,xe=console.warn,fe=console.error,pe=console.group,me=console.groupCollapsed,he=console.groupEnd;var r={configurable:!0,enumerable:!0,value:X,writable:!0};Object.defineProperties(console,{info:r,log:r,warn:r,error:r,group:r,groupCollapsed:r,groupEnd:r})}H++}}function D(){{if(H--,H===0){var r={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},r,{value:ge}),info:M({},r,{value:le}),warn:M({},r,{value:xe}),error:M({},r,{value:fe}),group:M({},r,{value:pe}),groupCollapsed:M({},r,{value:me}),groupEnd:M({},r,{value:he})})}H<0&&_("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var S=W.ReactCurrentDispatcher,P;function q(r,u,o){{if(P===void 0)try{throw Error()}catch(p){var g=p.stack.trim().match(/\n( *(at )?)/);P=g&&g[1]||""}return`
`+P+r}}var Q=!1,U;{var Ee=typeof WeakMap=="function"?WeakMap:Map;U=new Ee}function ce(r,u){if(!r||Q)return"";{var o=U.get(r);if(o!==void 0)return o}var g;Q=!0;var p=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var R;R=S.current,S.current=null,Re();try{if(u){var x=function(){throw Error()};if(Object.defineProperty(x.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(x,[])}catch(b){g=b}Reflect.construct(r,[],x)}else{try{x.call()}catch(b){g=b}r.call(x.prototype)}}else{try{throw Error()}catch(b){g=b}r()}}catch(b){if(b&&g&&typeof b.stack=="string"){for(var l=b.stack.split(`
`),k=g.stack.split(`
`),I=l.length-1,L=k.length-1;I>=1&&L>=0&&l[I]!==k[L];)L--;for(;I>=1&&L>=0;I--,L--)if(l[I]!==k[L]){if(I!==1||L!==1)do if(I--,L--,L<0||l[I]!==k[L]){var B=`
`+l[I].replace(" at new "," at ");return r.displayName&&B.includes("<anonymous>")&&(B=B.replace("<anonymous>",r.displayName)),typeof r=="function"&&U.set(r,B),B}while(I>=1&&L>=0);break}}}finally{Q=!1,S.current=R,D(),Error.prepareStackTrace=p}var ne=r?r.displayName||r.name:"",z=ne?q(ne):"";return typeof r=="function"&&U.set(r,z),z}function Te(r,u,o){return ce(r,!1)}function $(r){var u=r.prototype;return!!(u&&u.isReactComponent)}function _e(r,u,o){if(r==null)return"";if(typeof r=="function")return ce(r,$(r));if(typeof r=="string")return q(r);switch(r){case d:return q("Suspense");case T:return q("SuspenseList")}if(typeof r=="object")switch(r.$$typeof){case i:return Te(r.render);case h:return _e(r.type,u,o);case m:{var g=r,p=g._payload,R=g._init;try{return _e(R(p),u,o)}catch{}}}return""}var de=Object.prototype.hasOwnProperty,Ye={},Xe=W.ReactDebugCurrentFrame;function Ce(r){if(r){var u=r._owner,o=_e(r.type,r._source,u?u.type:null);Xe.setExtraStackFrame(o)}else Xe.setExtraStackFrame(null)}function Ir(r,u,o,g,p){{var R=Function.call.bind(de);for(var x in r)if(R(r,x)){var l=void 0;try{if(typeof r[x]!="function"){var k=Error((g||"React class")+": "+o+" type `"+x+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof r[x]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw k.name="Invariant Violation",k}l=r[x](u,x,g,o,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(I){l=I}l&&!(l instanceof Error)&&(Ce(p),_("%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).",g||"React class",o,x,typeof l),Ce(null)),l instanceof Error&&!(l.message in Ye)&&(Ye[l.message]=!0,Ce(p),_("Failed %s type: %s",o,l.message),Ce(null))}}}var Or=Array.isArray;function Le(r){return Or(r)}function Lr(r){{var u=typeof Symbol=="function"&&Symbol.toStringTag,o=u&&r[Symbol.toStringTag]||r.constructor.name||"Object";return o}}function kr(r){try{return Ue(r),!1}catch{return!0}}function Ue(r){return""+r}function Ne(r){if(kr(r))return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Lr(r)),Ue(r)}var ye=W.ReactCurrentOwner,jr={key:!0,ref:!0,__self:!0,__source:!0},Pe,Ve,ke;ke={};function Ar(r){if(de.call(r,"ref")){var u=Object.getOwnPropertyDescriptor(r,"ref").get;if(u&&u.isReactWarning)return!1}return r.ref!==void 0}function Mr(r){if(de.call(r,"key")){var u=Object.getOwnPropertyDescriptor(r,"key").get;if(u&&u.isReactWarning)return!1}return r.key!==void 0}function Sr(r,u){if(typeof r.ref=="string"&&ye.current&&u&&ye.current.stateNode!==u){var o=c(ye.current.type);ke[o]||(_('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',c(ye.current.type),r.ref),ke[o]=!0)}}function br(r,u){{var o=function(){Pe||(Pe=!0,_("%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)",u))};o.isReactWarning=!0,Object.defineProperty(r,"key",{get:o,configurable:!0})}}function Dr(r,u){{var o=function(){Ve||(Ve=!0,_("%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)",u))};o.isReactWarning=!0,Object.defineProperty(r,"ref",{get:o,configurable:!0})}}var Fr=function(r,u,o,g,p,R,x){var l={$$typeof:n,type:r,key:u,ref:o,props:x,_owner:R};return l._store={},Object.defineProperty(l._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(l,"_self",{configurable:!1,enumerable:!1,writable:!1,value:g}),Object.defineProperty(l,"_source",{configurable:!1,enumerable:!1,writable:!1,value:p}),Object.freeze&&(Object.freeze(l.props),Object.freeze(l)),l};function Wr(r,u,o,g,p){{var R,x={},l=null,k=null;o!==void 0&&(Ne(o),l=""+o),Mr(u)&&(Ne(u.key),l=""+u.key),Ar(u)&&(k=u.ref,Sr(u,p));for(R in u)de.call(u,R)&&!jr.hasOwnProperty(R)&&(x[R]=u[R]);if(r&&r.defaultProps){var I=r.defaultProps;for(R in I)x[R]===void 0&&(x[R]=I[R])}if(l||k){var L=typeof r=="function"?r.displayName||r.name||"Unknown":r;l&&br(x,L),k&&Dr(x,L)}return Fr(r,l,k,p,g,ye.current,x)}}var je=W.ReactCurrentOwner,Je=W.ReactDebugCurrentFrame;function re(r){if(r){var u=r._owner,o=_e(r.type,r._source,u?u.type:null);Je.setExtraStackFrame(o)}else Je.setExtraStackFrame(null)}var Ae;Ae=!1;function Me(r){return typeof r=="object"&&r!==null&&r.$$typeof===n}function Ke(){{if(je.current){var r=c(je.current.type);if(r)return`
Check the render method of \``+r+"`."}return""}}function Br(r){return""}var Ge={};function Yr(r){{var u=Ke();if(!u){var o=typeof r=="string"?r:r.displayName||r.name;o&&(u=`
Check the top-level render call using <`+o+">.")}return u}}function Ze(r,u){{if(!r._store||r._store.validated||r.key!=null)return;r._store.validated=!0;var o=Yr(u);if(Ge[o])return;Ge[o]=!0;var g="";r&&r._owner&&r._owner!==je.current&&(g=" It was passed a child from "+c(r._owner.type)+"."),re(r),_('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',o,g),re(null)}}function He(r,u){{if(typeof r!="object")return;if(Le(r))for(var o=0;o<r.length;o++){var g=r[o];Me(g)&&Ze(g,u)}else if(Me(r))r._store&&(r._store.validated=!0);else if(r){var p=N(r);if(typeof p=="function"&&p!==r.entries)for(var R=p.call(r),x;!(x=R.next()).done;)Me(x.value)&&Ze(x.value,u)}}}function Xr(r){{var u=r.type;if(u==null||typeof u=="string")return;var o;if(typeof u=="function")o=u.propTypes;else if(typeof u=="object"&&(u.$$typeof===i||u.$$typeof===h))o=u.propTypes;else return;if(o){var g=c(u);Ir(o,r.props,"prop",g,r)}else if(u.PropTypes!==void 0&&!Ae){Ae=!0;var p=c(u);_("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",p||"Unknown")}typeof u.getDefaultProps=="function"&&!u.getDefaultProps.isReactClassApproved&&_("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ur(r){{for(var u=Object.keys(r.props),o=0;o<u.length;o++){var g=u[o];if(g!=="children"&&g!=="key"){re(r),_("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",g),re(null);break}}r.ref!==null&&(re(r),_("Invalid attribute `ref` supplied to `React.Fragment`."),re(null))}}var qe={};function Qe(r,u,o,g,p,R){{var x=K(r);if(!x){var l="";(r===void 0||typeof r=="object"&&r!==null&&Object.keys(r).length===0)&&(l+=" 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 k=Br();k?l+=k:l+=Ke();var I;r===null?I="null":Le(r)?I="array":r!==void 0&&r.$$typeof===n?(I="<"+(c(r.type)||"Unknown")+" />",l=" Did you accidentally export a JSX literal instead of a component?"):I=typeof r,_("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",I,l)}var L=Wr(r,u,o,p,R);if(L==null)return L;if(x){var B=u.children;if(B!==void 0)if(g)if(Le(B)){for(var ne=0;ne<B.length;ne++)He(B[ne],r);Object.freeze&&Object.freeze(B)}else _("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 He(B,r)}if(de.call(u,"key")){var z=c(r),b=Object.keys(u).filter(function(Gr){return Gr!=="key"}),Se=b.length>0?"{key: someKey, "+b.join(": ..., ")+": ...}":"{key: someKey}";if(!qe[z+Se]){var Kr=b.length>0?"{"+b.join(": ..., ")+": ...}":"{}";_(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,Se,z,Kr,z),qe[z+Se]=!0}}return r===a?Ur(L):Xr(L),L}}function Nr(r,u,o){return Qe(r,u,o,!0)}function Pr(r,u,o){return Qe(r,u,o,!1)}var Vr=Pr,Jr=Nr;ae.Fragment=a,ae.jsx=Vr,ae.jsxs=Jr}()),ae}process.env.NODE_ENV==="production"?Ie.exports=$e():Ie.exports=ze();var Fe=Ie.exports;function we(e,n,t,a,s){n.beginPath(),n.moveTo(t.innerLineStart.x,t.innerLineStart.y),n.lineTo(t.innerLineStart.x,0),n.strokeStyle=a,n.lineWidth=e/2,n.stroke(),n.closePath(),n.beginPath(),n.moveTo(t.innerLineStart.x,t.innerLineStart.y),n.lineTo(t.rightInnerLineMiddle1.x,t.rightInnerLineMiddle1.y),n.lineTo(t.rightInnerLineMiddle2.x,t.rightInnerLineMiddle2.y),n.lineTo(t.rightInnerLineEnd.x,t.rightInnerLineEnd.y),n.strokeStyle=a,n.lineWidth=e,n.stroke(),n.closePath(),n.beginPath(),n.moveTo(t.outerLineStart.x,t.outerLineStart.y),n.lineTo(t.rightOuterLineMiddle1.x,t.rightOuterLineMiddle1.y),n.lineTo(t.rightOuterLineMiddle2.x,t.rightOuterLineMiddle2.y),n.lineTo(t.rightOuterLineEnd.x,t.rightOuterLineEnd.y),n.strokeStyle=a,n.lineWidth=e,n.stroke(),n.closePath(),n.beginPath(),n.moveTo(t.innerLineStart.x,t.innerLineStart.y),n.lineTo(t.leftInnerLineMiddle1.x,t.leftInnerLineMiddle1.y),n.lineTo(t.leftInnerLineMiddle2.x,t.leftInnerLineMiddle2.y),n.lineTo(t.leftInnerLineEnd.x,t.leftInnerLineEnd.y),n.strokeStyle=a,n.lineWidth=e,n.stroke(),n.closePath(),n.beginPath(),n.moveTo(t.outerLineStart.x,t.outerLineStart.y),n.lineTo(t.leftOuterLineMiddle1.x,t.leftOuterLineMiddle1.y),n.lineTo(t.leftOuterLineMiddle2.x,t.leftOuterLineMiddle2.y),n.lineTo(t.leftOuterLineEnd.x,t.leftOuterLineEnd.y),n.strokeStyle=a,n.lineWidth=e,n.stroke(),n.closePath(),n.beginPath(),n.arc(t.outerLineStart.x,t.outerLineStart.y+e/1.5,e/2,0,Math.PI*2,!1),n.fillStyle=s,n.fill(),n.closePath()}function er(e,n,t,a,s,y){e.beginPath(),e.moveTo(a.dividerLineLeftStart.x,a.dividerLineLeftStart.y),e.lineTo(a.dividerLineLeftEnd.x,a.dividerLineLeftEnd.y),e.strokeStyle=y,e.lineWidth=1,e.stroke(),e.closePath(),e.beginPath(),e.moveTo(a.dividerLineRightStart.x,a.dividerLineRightStart.y),e.lineTo(a.dividerLineRightEnd.x,a.dividerLineRightEnd.y),e.strokeStyle=y,e.lineWidth=1,e.stroke(),e.closePath(),e.beginPath(),e.moveTo(a.dividerLineRightStart.x,a.dividerLineRightStart.y),e.lineTo(a.dividerLineLeftStart.x,a.dividerLineLeftStart.y),e.strokeStyle=y,e.lineWidth=1,e.stroke(),e.closePath(),e.fillStyle=s,e.fillRect(a.dividerLineLeftStart.x,a.dividerLineLeftStart.y,n,t)}const Oe={};function rr(e){return new Promise(n=>{const t=new Image;t.src=e,t.onload=()=>n(t)})}async function nr(e){for(const n of e)n.icon&&!Oe[n.icon]&&(Oe[n.icon]=await rr(n.icon))}function tr(e,n){const t=n.radius/2,a="white",s="center",y="middle",v="red";if(e.beginPath(),e.arc(n.x,n.y,n.radius,0,Math.PI*2,!1),e.fillStyle=n.ballColor||v,e.fill(),e.closePath(),n.icon){const f=Oe[n.icon];f&&e.drawImage(f,n.x-(n.imageWidth||n.radius*1.4)/2,n.y-(n.imageHeight||n.radius*1.4)/2,n.imageWidth||n.radius*1.4,n.imageHeight||n.radius*1.4)}else e.font=`${n.ballTextFontSize||t}px Arial`,e.fillStyle=n.ballTextColor||a,e.textAlign=n.ballTextAlign||s,e.textBaseline=n.ballTextBaseline||y,e.fillText(n.text,n.x,n.y)}const F=(e,n,t)=>{const a=t*(Math.PI/180),s=Math.cos(a),y=Math.sin(a),v=e.x-n.x,f=e.y-n.y,i=v*s-f*y+n.x,d=v*y+f*s+n.y;return{x:i,y:d}},We=(e,n,t,a,s,y)=>{const v=e-t,f=n-a,i=s-t,d=y-a,T=v*i+f*d,h=i*i+d*d,m=h!==0?T/h:-1;let C,E;m<0?(C=t,E=a):m>1?(C=s,E=y):(C=t+m*i,E=a+m*d);const Y=e-C,N=n-E;return Math.sqrt(Y*Y+N*N)},ve=e=>Math.sqrt(e^2+e^2);function Be(e,n){return e>n?n:e<0?0:e}const j=(e,n,t,a,s)=>We(e.x,e.y,n,t,a,s)<e.radius,ar=(e,n,t)=>{e.x+=n.x*t,e.y+=n.y*t},A=(e,n,t)=>{const a=t.x-n.x,s=t.y-n.y,y=Math.sqrt(a*a+s*s),v={x:-s/y,y:a/y},f=We(e.x,e.y,n.x,n.y,t.x,t.y),i=e.radius-f;ar(e,v,i);const d=e.dx*v.x+e.dy*v.y;e.dx-=.5*d*v.x,e.dy-=.5*d*v.y};function ur(e,n,t,a,s,y,v){const f=j(e,n.x,n.y,t.x,t.y),i=j(e,a.x,a.y,t.x,t.y),d=j(e,s.x,s.y,a.x,a.y);(f||i||d)&&(y&&v(),f&&A(e,t,n),i&&A(e,a,t),d&&A(e,s,a))}function ir(e,n,t,a,s,y,v){const f=j(e,n.x,n.y,t.x,t.y),i=j(e,t.x,t.y,a.x,a.y),d=j(e,a.x,a.y,s.x,s.y);(f||i||d)&&(y&&v(),f&&A(e,n,t),i&&A(e,t,a),d&&A(e,a,s))}function or(e,n,t,a,s){const y=j(e,n.x,n.y,t.x,t.y),v=j(e,t.x,t.y,a.x,a.y),f=j(e,a.x,a.y,s.x,s.y);(y||v||f)&&(y&&A(e,t,n),v&&A(e,a,t),f&&A(e,s,a))}function sr(e,n,t,a,s){const y=j(e,n.x,n.y,t.x,t.y),v=j(e,t.x,t.y,a.x,a.y),f=j(e,a.x,a.y,s.x,s.y);(y||v||f)&&(y&&A(e,n,t),v&&A(e,t,a),f&&A(e,a,s))}function fr(e,n,t,a,s){const y=j(e,n.x,n.y,t.x,t.y),v=j(e,a.x,a.y,s.x,s.y);(y||v)&&(y&&A(e,n,t),v&&A(e,s,a))}function cr(e,n,t,a,s){e.x+e.radius>n?(e.dx=-e.dx*a,e.x=n-e.radius):e.x-e.radius<0&&(e.dx=-e.dx*a,e.x=e.radius),e.y+e.radius>t?(e.dy=-e.dy*s,e.y=t-e.radius,e.dx*=s,Math.abs(e.dy)<.1&&(e.dy=0),Math.abs(e.dx)<.1&&(e.dx=0)):e.y-e.radius<0&&(e.dy=-e.dy*a,e.y=e.radius)}function dr(e){for(let n=0;n<e.length;n++)for(let t=n+1;t<e.length;t++){const a=e[n],s=e[t],y=s.x-a.x,v=s.y-a.y,f=Math.sqrt(y*y+v*v),i=a.radius+s.radius;if(f<i){const d=(i-f)/2,T=Math.atan2(v,y),h=Math.sin(T),m=Math.cos(T);a.x-=d*m,a.y-=d*h,s.x+=d*m,s.y+=d*h;const C={x:a.dx*m+a.dy*h,y:a.dy*m-a.dx*h},E={x:s.dx*m+s.dy*h,y:s.dy*m-s.dx*h},Y=C.x;C.x=E.x,E.x=Y,a.dx=.5*C.x*m-C.y*h,a.dy=.5*C.y*m+C.x*h,s.dx=.5*E.x*m-E.y*h,s.dy=.5*E.y*m+E.x*h}}}const yr=(e,n)=>e?e<0?n:e:n,vr=(e,n,t)=>e&&e>0&&e<n?e:Math.random()*n-t-50,gr=(e,n)=>e&&e>0&&e<n?e:n-Math.random()*n/2+50,lr=e=>e||(Math.random()-.5)*4,xr=e=>e||(Math.random()-.5)*4,pr=(e,n,t,a,s,y,v,f)=>{const i={x:e.x,y:e.y},d=F({x:e.x+n,y:e.y+n},i,-e.angle),T=F({x:e.x+n,y:e.y+n+n},i,-e.angle),h=F({x:e.x,y:e.y+n+n+n},i,-e.angle),m=F({x:e.x-n,y:e.y+n},i,e.angle),C=F({x:e.x-n,y:e.y+n+n},i,e.angle),E=F({x:e.x,y:e.y+n+n+n},i,e.angle),Y={x:e.x,y:e.y-t},N=F({x:e.x+n+t,y:e.y+n-ve(t)},i,-e.angle),W=F({x:e.x+n+t,y:e.y+n+n+ve(t)},i,-e.angle),_=F({x:e.x,y:e.y+n+n+n+t},i,-e.angle),ue=F({x:e.x-n-t,y:e.y+n-ve(t)},i,e.angle),ie=F({x:e.x-n-t,y:e.y+n+n+ve(t)},i,e.angle),w=F({x:e.x,y:e.y+n+n+n+t},i,e.angle),ee={x:a-y-v,y:f},oe={x:a-y-v,y:s},se={x:a-y,y:f},J={x:a-y,y:s};return{innerLineStart:i,rightInnerLineMiddle1:d,rightInnerLineMiddle2:T,rightInnerLineEnd:h,leftInnerLineMiddle1:m,leftInnerLineMiddle2:C,leftInnerLineEnd:E,outerLineStart:Y,rightOuterLineMiddle1:N,rightOuterLineMiddle2:W,rightOuterLineEnd:_,leftOuterLineMiddle1:ue,leftOuterLineMiddle2:ie,leftOuterLineEnd:w,dividerLineLeftStart:ee,dividerLineLeftEnd:oe,dividerLineRightStart:se,dividerLineRightEnd:J}},mr=(e,n,t,a,s,y,v,f,i)=>e.map(d=>(d.dy+=n,d.x+=d.dx,d.y+=d.dy,cr(d,t,a,s,y),ur(d,i.innerLineStart,i.leftInnerLineMiddle1,i.leftInnerLineMiddle2,i.leftInnerLineEnd,f.returnOnContact,v),ir(d,i.innerLineStart,i.rightInnerLineMiddle1,i.rightInnerLineMiddle2,i.rightInnerLineEnd,f.returnOnContact,v),or(d,i.outerLineStart,i.rightOuterLineMiddle1,i.rightOuterLineMiddle2,i.rightOuterLineEnd),sr(d,i.outerLineStart,i.leftOuterLineMiddle1,i.leftOuterLineMiddle2,i.leftOuterLineEnd),fr(d,i.dividerLineLeftStart,i.dividerLineLeftEnd,i.dividerLineRightStart,i.dividerLineRightEnd),d.x>=i.dividerLineRightEnd.x&&d.y>=a-50&&(d.isInDropZone=!0),d)),hr=(e,n)=>e.filter(t=>t.y<=n).length>0,Rr=(e,n)=>{e.y<=e.targetY?e.y+=e.dy:(e.y-=e.dy,e.targetY=n,e.y<=n&&(e.y=n))},Er=(e,n)=>{e.x>e.targetX&&e.targetX>0?e.x-e.dx<e.targetX?e.x=e.targetX:e.x-=e.dx:e.x<e.targetX&&e.targetX<n&&(e.x+e.dx>e.targetX?e.x=e.targetX:e.x+=e.dx)},Tr=e=>{e.angle>e.targetAngle?e.angle-=e.dAngle:e.angle+=e.dAngle},_r=(e,n,t,a,s,y)=>{const v=[];return e.filter(f=>!n.find(i=>i.text===f.text)).forEach(f=>{v.push({x:vr(f.startX,t,y),y:gr(f.startY,a),radius:yr(f.radius,s),dx:lr(f.startXMomentum),dy:xr(f.startYMomentum),isInDropZone:!1,text:f.text,icon:f.icon,ballColor:f.ballColor,ballTextFontSize:f.ballTextFontSize,ballTextAlign:f.ballTextAlign,ballTextBaseline:f.ballTextBaseline,ballTextColor:f.ballTextColor,imageHeight:f.imageHeight,imageWidth:f.imageWidth})}),v},Cr=O.memo(O.forwardRef(({ballData:e,width:n=600,height:t=400,gravity:a=.2,friction:s=.99,groundFriction:y=.8,clawSize:v=30,dividerLineWidth:f=70,dividerLineHeight:i=140,dividerLineThickness:d=20,dividerLineFillColor:T="gray",dividerLineBorderColor:h="gray",clawWidth:m=10,clawStartPositionX:C=200,clawStartPositionY:E=40,clawStartOpenAngle:Y=0,clawSpeedX:N=2,clawSpeedY:W=1.1,clawOpenSpeed:_=1,clawColor:ue="gray",clawBoltColor:ie="black",ballRadius:w=20,alreadyDroppedBalls:ee,addToDroppedBalls:oe},se)=>{const J=O.useRef(null),K=O.useRef(null),V=O.useRef([]),Z=O.useRef({x:0,y:0}),c=O.useRef({x:C,y:E,angle:Y,targetY:E,targetX:C,targetAngle:Y,dx:N,dy:W,dAngle:_,returnOnContact:!1}),M=O.useRef(!0);O.useEffect(()=>{V.current&&(V.current=_r(e,ee,n,t,w,f),nr(V.current))},[e,w,n,t,f]),O.useEffect(()=>{c.current.dx&&(c.current.dx=N)},[N]),O.useEffect(()=>{c.current.dy&&(c.current.dy=W)},[W]),O.useEffect(()=>{c.current.dAngle&&(c.current.dAngle=_)},[_]);function H(){Rr(c.current,E)}function ge(){Er(c.current,n)}function le(){Tr(c.current)}O.useEffect(()=>{const D=J.current;if(!D)return;const S=D.getContext("2d");if(!S)return;const P=()=>{c.current.targetAngle=0,c.current.targetY=c.current.y},Q=setInterval(()=>{S.clearRect(0,0,n,t);const U=pr(c.current,v,m,n,t,f,d,i),Ee=mr(V.current,a,n,t,s,y,P,c.current,U),ce=Ee.filter($=>$.isInDropZone),Te=Ee.filter($=>!$.isInDropZone);ce.length>0&&oe(ce),dr(V.current),Te.forEach($=>{tr(S,$)}),er(S,d,t-i,U,T,h),V.current=Te,c.current.targetY!==c.current.y&&H(),c.current.targetX!==c.current.x&&ge(),c.current.angle!==c.current.targetAngle&&le(),we(m,S,U,ue,ie)},1e3/60);return()=>clearInterval(Q)},[Z.current,c.current,e,ee,n,t,f,d,m,v]);const xe=D=>{if(!M.current)return;const S=J.current;if(!S)return;const P=S.getBoundingClientRect();Z.current={x:D.clientX-P.left,y:D.clientY-P.top},Math.abs(c.current.x-Z.current.x)>20&&(c.current.targetX=Math.round(Z.current.x/2)*2)},fe=async D=>{await X(c.current.x+D,c.current.y,c.current.angle,!1)},pe=()=>{K.current!==null&&(clearInterval(K.current),K.current=null)},me=()=>{M.current&&(K.current=setInterval(()=>{fe(c.current.dx)},5))},he=()=>{M.current&&(K.current=setInterval(()=>{fe(-c.current.dx)},5))},X=(D,S,P,q=!1)=>new Promise(Q=>{M.current=!1,c.current.returnOnContact=q,c.current.targetX=Be(D,n),c.current.targetY=Be(S,t),c.current.targetAngle=P;const U=()=>{Math.abs(c.current.x-c.current.targetX)<=c.current.dx&&Math.abs(c.current.y-c.current.targetY)<=c.current.dy&&Math.abs(c.current.angle-c.current.targetAngle)<=c.current.dAngle?(M.current=!0,Q()):requestAnimationFrame(U)};requestAnimationFrame(U)}),Re=async D=>{M.current&&(await X(c.current.x,t-50,40,!0),await X(c.current.x,c.current.y,0),await X(c.current.x,E,0),hr(V.current,i)&&(await X(n-30,E,0),await X(n-30,E,40).then(()=>{setTimeout(()=>X(Math.round(n/4)*2,E,0),D||500)})))};return O.useImperativeHandle(se,()=>({moveClaw:X,moveClawRight:me,moveClawLeft:he,stopMoving:pe,moveClawDown:Re})),Fe.jsx("div",{children:Fe.jsx("canvas",{ref:J,width:n,height:t,style:{border:"1px solid black",width:"100%"},onMouseMove:xe,onMouseDown:()=>Re()})})}));G.ClawMachine=Cr,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});