claw-machine-js
Version:
A physics based claw-machine simulation
1,131 lines (1,128 loc) • 37.1 kB
JavaScript
import He, { memo as Rr, forwardRef as Er, useRef as re, useEffect as ce, useImperativeHandle as Tr } from "react";
var Me = { exports: {} }, de = {};
/**
* @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 Je;
function _r() {
if (Je) return de;
Je = 1;
var e = He, 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 de.Fragment = t, de.jsx = v, de.jsxs = v, de;
}
var ye = {};
/**
* @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 Ke;
function Cr() {
return Ke || (Ke = 1, process.env.NODE_ENV !== "production" && function() {
var e = He, 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, B = "@@iterator";
function X(r) {
if (r === null || typeof r != "object")
return null;
var u = E && r[E] || r[B];
return typeof u == "function" ? u : null;
}
var D = 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];
ne("error", r, o);
}
}
function ne(r, u, o) {
{
var g = D.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 te = !1, Q = !1, z = !1, ae = !1, ue = !1, P;
P = Symbol.for("react.module.reference");
function q(r) {
return !!(typeof r == "string" || typeof r == "function" || r === a || r === y || ue || r === s || r === d || r === T || ae || r === C || te || Q || z || typeof r == "object" && r !== null && (r.$$typeof === m || r.$$typeof === h || r.$$typeof === v || r.$$typeof === f || r.$$typeof === i || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
r.$$typeof === P || r.getModuleId !== void 0));
}
function N(r, u, o) {
var g = r.displayName;
if (g)
return g;
var p = u.displayName || u.name || "";
return p !== "" ? o + "(" + p + ")" : o;
}
function V(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 V(u) + ".Consumer";
case v:
var o = r;
return V(o._context) + ".Provider";
case i:
return N(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 k = Object.assign, J = 0, ve, ge, le, ie, xe, pe, me;
function Y() {
}
Y.__reactDisabledLog = !0;
function he() {
{
if (J === 0) {
ve = console.log, ge = console.info, le = console.warn, ie = console.error, xe = console.group, pe = console.groupCollapsed, me = console.groupEnd;
var r = {
configurable: !0,
enumerable: !0,
value: Y,
writable: !0
};
Object.defineProperties(console, {
info: r,
log: r,
warn: r,
error: r,
group: r,
groupCollapsed: r,
groupEnd: r
});
}
J++;
}
}
function b() {
{
if (J--, J === 0) {
var r = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: k({}, r, {
value: ve
}),
info: k({}, r, {
value: ge
}),
warn: k({}, r, {
value: le
}),
error: k({}, r, {
value: ie
}),
group: k({}, r, {
value: xe
}),
groupCollapsed: k({}, r, {
value: pe
}),
groupEnd: k({}, r, {
value: me
})
});
}
J < 0 && _("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var A = D.ReactCurrentDispatcher, U;
function K(r, u, o) {
{
if (U === void 0)
try {
throw Error();
} catch (p) {
var g = p.stack.trim().match(/\n( *(at )?)/);
U = g && g[1] || "";
}
return `
` + U + r;
}
}
var G = !1, $;
{
var Re = typeof WeakMap == "function" ? WeakMap : Map;
$ = new Re();
}
function oe(r, u) {
if (!r || G)
return "";
{
var o = $.get(r);
if (o !== void 0)
return o;
}
var g;
G = !0;
var p = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var R;
R = A.current, A.current = null, he();
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 (j) {
g = j;
}
Reflect.construct(r, [], x);
} else {
try {
x.call();
} catch (j) {
g = j;
}
r.call(x.prototype);
}
} else {
try {
throw Error();
} catch (j) {
g = j;
}
r();
}
} catch (j) {
if (j && g && typeof j.stack == "string") {
for (var l = j.stack.split(`
`), L = g.stack.split(`
`), I = l.length - 1, O = L.length - 1; I >= 1 && O >= 0 && l[I] !== L[O]; )
O--;
for (; I >= 1 && O >= 0; I--, O--)
if (l[I] !== L[O]) {
if (I !== 1 || O !== 1)
do
if (I--, O--, O < 0 || l[I] !== L[O]) {
var F = `
` + l[I].replace(" at new ", " at ");
return r.displayName && F.includes("<anonymous>") && (F = F.replace("<anonymous>", r.displayName)), typeof r == "function" && $.set(r, F), F;
}
while (I >= 1 && O >= 0);
break;
}
}
} finally {
G = !1, A.current = R, b(), Error.prepareStackTrace = p;
}
var ee = r ? r.displayName || r.name : "", H = ee ? K(ee) : "";
return typeof r == "function" && $.set(r, H), H;
}
function Ee(r, u, o) {
return oe(r, !1);
}
function Z(r) {
var u = r.prototype;
return !!(u && u.isReactComponent);
}
function Te(r, u, o) {
if (r == null)
return "";
if (typeof r == "function")
return oe(r, Z(r));
if (typeof r == "string")
return K(r);
switch (r) {
case d:
return K("Suspense");
case T:
return K("SuspenseList");
}
if (typeof r == "object")
switch (r.$$typeof) {
case i:
return Ee(r.render);
case h:
return Te(r.type, u, o);
case m: {
var g = r, p = g._payload, R = g._init;
try {
return Te(R(p), u, o);
} catch {
}
}
}
return "";
}
var se = Object.prototype.hasOwnProperty, be = {}, De = D.ReactDebugCurrentFrame;
function _e(r) {
if (r) {
var u = r._owner, o = Te(r.type, r._source, u ? u.type : null);
De.setExtraStackFrame(o);
} else
De.setExtraStackFrame(null);
}
function ze(r, u, o, g, p) {
{
var R = Function.call.bind(se);
for (var x in r)
if (R(r, x)) {
var l = void 0;
try {
if (typeof r[x] != "function") {
var L = 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 L.name = "Invariant Violation", L;
}
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) && (_e(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), _e(null)), l instanceof Error && !(l.message in be) && (be[l.message] = !0, _e(p), _("Failed %s type: %s", o, l.message), _e(null));
}
}
}
var we = Array.isArray;
function Ie(r) {
return we(r);
}
function er(r) {
{
var u = typeof Symbol == "function" && Symbol.toStringTag, o = u && r[Symbol.toStringTag] || r.constructor.name || "Object";
return o;
}
}
function rr(r) {
try {
return Fe(r), !1;
} catch {
return !0;
}
}
function Fe(r) {
return "" + r;
}
function We(r) {
if (rr(r))
return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", er(r)), Fe(r);
}
var fe = D.ReactCurrentOwner, nr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Be, Ye, Oe;
Oe = {};
function tr(r) {
if (se.call(r, "ref")) {
var u = Object.getOwnPropertyDescriptor(r, "ref").get;
if (u && u.isReactWarning)
return !1;
}
return r.ref !== void 0;
}
function ar(r) {
if (se.call(r, "key")) {
var u = Object.getOwnPropertyDescriptor(r, "key").get;
if (u && u.isReactWarning)
return !1;
}
return r.key !== void 0;
}
function ur(r, u) {
if (typeof r.ref == "string" && fe.current && u && fe.current.stateNode !== u) {
var o = c(fe.current.type);
Oe[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(fe.current.type), r.ref), Oe[o] = !0);
}
}
function ir(r, u) {
{
var o = function() {
Be || (Be = !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 or(r, u) {
{
var o = function() {
Ye || (Ye = !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 sr = function(r, u, o, g, p, R, x) {
var l = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: n,
// Built-in properties that belong on the element
type: r,
key: u,
ref: o,
props: x,
// Record the component responsible for creating this element.
_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 fr(r, u, o, g, p) {
{
var R, x = {}, l = null, L = null;
o !== void 0 && (We(o), l = "" + o), ar(u) && (We(u.key), l = "" + u.key), tr(u) && (L = u.ref, ur(u, p));
for (R in u)
se.call(u, R) && !nr.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 || L) {
var O = typeof r == "function" ? r.displayName || r.name || "Unknown" : r;
l && ir(x, O), L && or(x, O);
}
return sr(r, l, L, p, g, fe.current, x);
}
}
var Le = D.ReactCurrentOwner, $e = D.ReactDebugCurrentFrame;
function w(r) {
if (r) {
var u = r._owner, o = Te(r.type, r._source, u ? u.type : null);
$e.setExtraStackFrame(o);
} else
$e.setExtraStackFrame(null);
}
var ke;
ke = !1;
function Ae(r) {
return typeof r == "object" && r !== null && r.$$typeof === n;
}
function Xe() {
{
if (Le.current) {
var r = c(Le.current.type);
if (r)
return `
Check the render method of \`` + r + "`.";
}
return "";
}
}
function cr(r) {
return "";
}
var Ue = {};
function dr(r) {
{
var u = Xe();
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 Ne(r, u) {
{
if (!r._store || r._store.validated || r.key != null)
return;
r._store.validated = !0;
var o = dr(u);
if (Ue[o])
return;
Ue[o] = !0;
var g = "";
r && r._owner && r._owner !== Le.current && (g = " It was passed a child from " + c(r._owner.type) + "."), w(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), w(null);
}
}
function Pe(r, u) {
{
if (typeof r != "object")
return;
if (Ie(r))
for (var o = 0; o < r.length; o++) {
var g = r[o];
Ae(g) && Ne(g, u);
}
else if (Ae(r))
r._store && (r._store.validated = !0);
else if (r) {
var p = X(r);
if (typeof p == "function" && p !== r.entries)
for (var R = p.call(r), x; !(x = R.next()).done; )
Ae(x.value) && Ne(x.value, u);
}
}
}
function yr(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 || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
u.$$typeof === h))
o = u.propTypes;
else
return;
if (o) {
var g = c(u);
ze(o, r.props, "prop", g, r);
} else if (u.PropTypes !== void 0 && !ke) {
ke = !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 vr(r) {
{
for (var u = Object.keys(r.props), o = 0; o < u.length; o++) {
var g = u[o];
if (g !== "children" && g !== "key") {
w(r), _("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", g), w(null);
break;
}
}
r.ref !== null && (w(r), _("Invalid attribute `ref` supplied to `React.Fragment`."), w(null));
}
}
var qe = {};
function Ve(r, u, o, g, p, R) {
{
var x = q(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 L = cr();
L ? l += L : l += Xe();
var I;
r === null ? I = "null" : Ie(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 O = fr(r, u, o, p, R);
if (O == null)
return O;
if (x) {
var F = u.children;
if (F !== void 0)
if (g)
if (Ie(F)) {
for (var ee = 0; ee < F.length; ee++)
Pe(F[ee], r);
Object.freeze && Object.freeze(F);
} 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
Pe(F, r);
}
if (se.call(u, "key")) {
var H = c(r), j = Object.keys(u).filter(function(hr) {
return hr !== "key";
}), je = j.length > 0 ? "{key: someKey, " + j.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!qe[H + je]) {
var mr = j.length > 0 ? "{" + j.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} />`, je, H, mr, H), qe[H + je] = !0;
}
}
return r === a ? vr(O) : yr(O), O;
}
}
function gr(r, u, o) {
return Ve(r, u, o, !0);
}
function lr(r, u, o) {
return Ve(r, u, o, !1);
}
var xr = lr, pr = gr;
ye.Fragment = a, ye.jsx = xr, ye.jsxs = pr;
}()), ye;
}
process.env.NODE_ENV === "production" ? Me.exports = _r() : Me.exports = Cr();
var Ge = Me.exports;
function Ir(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 Or(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 Se = {};
function Lr(e) {
return new Promise((n) => {
const t = new Image();
t.src = e, t.onload = () => n(t);
});
}
async function kr(e) {
for (const n of e)
n.icon && !Se[n.icon] && (Se[n.icon] = await Lr(n.icon));
}
function Ar(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 = Se[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 W = (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 };
}, Qe = (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 B = e - C, X = n - E;
return Math.sqrt(B * B + X * X);
}, Ce = (e) => Math.sqrt(e ^ 2 + e ^ 2);
function Ze(e, n) {
return e > n ? n : e < 0 ? 0 : e;
}
const M = (e, n, t, a, s) => Qe(e.x, e.y, n, t, a, s) < e.radius, jr = (e, n, t) => {
e.x += n.x * t, e.y += n.y * t;
}, S = (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 = Qe(e.x, e.y, n.x, n.y, t.x, t.y), i = e.radius - f;
jr(e, v, i);
const d = e.dx * v.x + e.dy * v.y;
e.dx -= 0.5 * d * v.x, e.dy -= 0.5 * d * v.y;
};
function Mr(e, n, t, a, s, y, v) {
const f = M(
e,
n.x,
n.y,
t.x,
t.y
), i = M(
e,
a.x,
a.y,
t.x,
t.y
), d = M(
e,
s.x,
s.y,
a.x,
a.y
);
(f || i || d) && (y && v(), f && S(e, t, n), i && S(e, a, t), d && S(e, s, a));
}
function Sr(e, n, t, a, s, y, v) {
const f = M(
e,
n.x,
n.y,
t.x,
t.y
), i = M(
e,
t.x,
t.y,
a.x,
a.y
), d = M(
e,
a.x,
a.y,
s.x,
s.y
);
(f || i || d) && (y && v(), f && S(e, n, t), i && S(e, t, a), d && S(e, a, s));
}
function br(e, n, t, a, s) {
const y = M(
e,
n.x,
n.y,
t.x,
t.y
), v = M(
e,
t.x,
t.y,
a.x,
a.y
), f = M(
e,
a.x,
a.y,
s.x,
s.y
);
(y || v || f) && (y && S(e, t, n), v && S(e, a, t), f && S(e, s, a));
}
function Dr(e, n, t, a, s) {
const y = M(
e,
n.x,
n.y,
t.x,
t.y
), v = M(
e,
t.x,
t.y,
a.x,
a.y
), f = M(
e,
a.x,
a.y,
s.x,
s.y
);
(y || v || f) && (y && S(e, n, t), v && S(e, t, a), f && S(e, a, s));
}
function Fr(e, n, t, a, s) {
const y = M(
e,
n.x,
n.y,
t.x,
t.y
), v = M(
e,
a.x,
a.y,
s.x,
s.y
);
(y || v) && (y && S(e, n, t), v && S(e, s, a));
}
function Wr(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) < 0.1 && (e.dy = 0), Math.abs(e.dx) < 0.1 && (e.dx = 0)) : e.y - e.radius < 0 && (e.dy = -e.dy * a, e.y = e.radius);
}
function Br(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 }, B = C.x;
C.x = E.x, E.x = B, a.dx = 0.5 * C.x * m - C.y * h, a.dy = 0.5 * C.y * m + C.x * h, s.dx = 0.5 * E.x * m - E.y * h, s.dy = 0.5 * E.y * m + E.x * h;
}
}
}
const Yr = (e, n) => e ? e < 0 ? n : e : n, $r = (e, n, t) => e && e > 0 && e < n ? e : Math.random() * n - t - 50, Xr = (e, n) => e && e > 0 && e < n ? e : n - Math.random() * n / 2 + 50, Ur = (e) => e || (Math.random() - 0.5) * 4, Nr = (e) => e || (Math.random() - 0.5) * 4, Pr = (e, n, t, a, s, y, v, f) => {
const i = { x: e.x, y: e.y }, d = W(
{ x: e.x + n, y: e.y + n },
i,
-e.angle
), T = W(
{ x: e.x + n, y: e.y + n + n },
i,
-e.angle
), h = W(
{ x: e.x, y: e.y + n + n + n },
i,
-e.angle
), m = W(
{ x: e.x - n, y: e.y + n },
i,
e.angle
), C = W(
{ x: e.x - n, y: e.y + n + n },
i,
e.angle
), E = W(
{ x: e.x, y: e.y + n + n + n },
i,
e.angle
), B = { x: e.x, y: e.y - t }, X = W(
{ x: e.x + n + t, y: e.y + n - Ce(t) },
i,
-e.angle
), D = W(
{ x: e.x + n + t, y: e.y + n + n + Ce(t) },
i,
-e.angle
), _ = W(
{ x: e.x, y: e.y + n + n + n + t },
i,
-e.angle
), ne = W(
{ x: e.x - n - t, y: e.y + n - Ce(t) },
i,
e.angle
), te = W(
{ x: e.x - n - t, y: e.y + n + n + Ce(t) },
i,
e.angle
), Q = W(
{ x: e.x, y: e.y + n + n + n + t },
i,
e.angle
), z = {
x: a - y - v,
y: f
}, ae = { x: a - y - v, y: s }, ue = { x: a - y, y: f }, P = { x: a - y, y: s };
return {
innerLineStart: i,
rightInnerLineMiddle1: d,
rightInnerLineMiddle2: T,
rightInnerLineEnd: h,
leftInnerLineMiddle1: m,
leftInnerLineMiddle2: C,
leftInnerLineEnd: E,
outerLineStart: B,
rightOuterLineMiddle1: X,
rightOuterLineMiddle2: D,
rightOuterLineEnd: _,
leftOuterLineMiddle1: ne,
leftOuterLineMiddle2: te,
leftOuterLineEnd: Q,
dividerLineLeftStart: z,
dividerLineLeftEnd: ae,
dividerLineRightStart: ue,
dividerLineRightEnd: P
};
}, qr = (e, n, t, a, s, y, v, f, i) => e.map((d) => (d.dy += n, d.x += d.dx, d.y += d.dy, Wr(d, t, a, s, y), Mr(
d,
i.innerLineStart,
i.leftInnerLineMiddle1,
i.leftInnerLineMiddle2,
i.leftInnerLineEnd,
f.returnOnContact,
v
), Sr(
d,
i.innerLineStart,
i.rightInnerLineMiddle1,
i.rightInnerLineMiddle2,
i.rightInnerLineEnd,
f.returnOnContact,
v
), br(
d,
i.outerLineStart,
i.rightOuterLineMiddle1,
i.rightOuterLineMiddle2,
i.rightOuterLineEnd
), Dr(
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)), Vr = (e, n) => e.filter((t) => t.y <= n).length > 0, Jr = (e, n) => {
e.y <= e.targetY ? e.y += e.dy : (e.y -= e.dy, e.targetY = n, e.y <= n && (e.y = n));
}, Kr = (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);
}, Gr = (e) => {
e.angle > e.targetAngle ? e.angle -= e.dAngle : e.angle += e.dAngle;
}, Zr = (e, n, t, a, s, y) => {
const v = [];
return e.filter(
(f) => !n.find((i) => i.text === f.text)
).forEach((f) => {
v.push({
x: $r(f.startX, t, y),
y: Xr(f.startY, a),
radius: Yr(f.radius, s),
dx: Ur(f.startXMomentum),
dy: Nr(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;
}, Qr = Rr(
Er(
({
ballData: e,
width: n = 600,
height: t = 400,
gravity: a = 0.2,
friction: s = 0.99,
groundFriction: y = 0.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: B = 0,
clawSpeedX: X = 2,
clawSpeedY: D = 1.1,
clawOpenSpeed: _ = 1,
clawColor: ne = "gray",
clawBoltColor: te = "black",
ballRadius: Q = 20,
alreadyDroppedBalls: z,
addToDroppedBalls: ae
}, ue) => {
const P = re(null), q = re(null), N = re([]), V = re({ x: 0, y: 0 }), c = re({
x: C,
y: E,
angle: B,
targetY: E,
targetX: C,
targetAngle: B,
dx: X,
dy: D,
dAngle: _,
returnOnContact: !1
}), k = re(!0);
ce(() => {
N.current && (N.current = Zr(
e,
z,
n,
t,
Q,
f
), kr(N.current));
}, [e, Q, n, t, f]), ce(() => {
c.current.dx && (c.current.dx = X);
}, [X]), ce(() => {
c.current.dy && (c.current.dy = D);
}, [D]), ce(() => {
c.current.dAngle && (c.current.dAngle = _);
}, [_]);
function J() {
Jr(c.current, E);
}
function ve() {
Kr(c.current, n);
}
function ge() {
Gr(c.current);
}
ce(() => {
const b = P.current;
if (!b)
return;
const A = b.getContext("2d");
if (!A)
return;
const U = () => {
c.current.targetAngle = 0, c.current.targetY = c.current.y;
}, G = setInterval(() => {
A.clearRect(0, 0, n, t);
const $ = Pr(
c.current,
v,
m,
n,
t,
f,
d,
i
), Re = qr(
N.current,
a,
n,
t,
s,
y,
U,
c.current,
$
), oe = Re.filter((Z) => Z.isInDropZone), Ee = Re.filter((Z) => !Z.isInDropZone);
oe.length > 0 && ae(oe), Br(N.current), Ee.forEach((Z) => {
Ar(A, Z);
}), Or(
A,
d,
t - i,
$,
T,
h
), N.current = Ee, c.current.targetY !== c.current.y && J(), c.current.targetX !== c.current.x && ve(), c.current.angle !== c.current.targetAngle && ge(), Ir(m, A, $, ne, te);
}, 1e3 / 60);
return () => clearInterval(G);
}, [
V.current,
c.current,
e,
z,
n,
t,
f,
d,
m,
v
]);
const le = (b) => {
if (!k.current)
return;
const A = P.current;
if (!A)
return;
const U = A.getBoundingClientRect();
V.current = {
x: b.clientX - U.left,
y: b.clientY - U.top
}, Math.abs(c.current.x - V.current.x) > 20 && (c.current.targetX = Math.round(V.current.x / 2) * 2);
}, ie = async (b) => {
await Y(c.current.x + b, c.current.y, c.current.angle, !1);
}, xe = () => {
q.current !== null && (clearInterval(q.current), q.current = null);
}, pe = () => {
k.current && (q.current = setInterval(() => {
ie(c.current.dx);
}, 5));
}, me = () => {
k.current && (q.current = setInterval(() => {
ie(-c.current.dx);
}, 5));
}, Y = (b, A, U, K = !1) => new Promise((G) => {
k.current = !1, c.current.returnOnContact = K, c.current.targetX = Ze(b, n), c.current.targetY = Ze(A, t), c.current.targetAngle = U;
const $ = () => {
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 ? (k.current = !0, G()) : requestAnimationFrame($);
};
requestAnimationFrame($);
}), he = async (b) => {
k.current && (await Y(c.current.x, t - 50, 40, !0), await Y(c.current.x, c.current.y, 0), await Y(c.current.x, E, 0), Vr(N.current, i) && (await Y(n - 30, E, 0), await Y(n - 30, E, 40).then(() => {
setTimeout(
() => Y(Math.round(n / 4) * 2, E, 0),
b || 500
);
})));
};
return Tr(ue, () => ({
moveClaw: Y,
moveClawRight: pe,
moveClawLeft: me,
stopMoving: xe,
moveClawDown: he
})), /* @__PURE__ */ Ge.jsx("div", { children: /* @__PURE__ */ Ge.jsx(
"canvas",
{
ref: P,
width: n,
height: t,
style: { border: "1px solid black", width: "100%" },
onMouseMove: le,
onMouseDown: () => he()
}
) });
}
)
);
export {
Qr as ClawMachine
};