@alexium216/react-pong 1.1.2 → 1.1.3

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,760 +1,132 @@
1
- import $e, { useState as dr, useRef as B, useEffect as Fe } from "react";
2
- var oe = { exports: {} }, Q = {};
3
- /**
4
- * @license React
5
- * react-jsx-runtime.production.min.js
6
- *
7
- * Copyright (c) Facebook, Inc. and its affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var Ie;
13
- function vr() {
14
- if (Ie) return Q;
15
- Ie = 1;
16
- var _ = $e, c = Symbol.for("react.element"), E = Symbol.for("react.fragment"), x = Object.prototype.hasOwnProperty, o = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, f = { key: !0, ref: !0, __self: !0, __source: !0 };
17
- function b(m, h, p) {
18
- var s, a = {}, O = null, S = null;
19
- p !== void 0 && (O = "" + p), h.key !== void 0 && (O = "" + h.key), h.ref !== void 0 && (S = h.ref);
20
- for (s in h) x.call(h, s) && !f.hasOwnProperty(s) && (a[s] = h[s]);
21
- if (m && m.defaultProps) for (s in h = m.defaultProps, h) a[s] === void 0 && (a[s] = h[s]);
22
- return { $$typeof: c, type: m, key: O, ref: S, props: a, _owner: o.current };
23
- }
24
- return Q.Fragment = E, Q.jsx = b, Q.jsxs = b, Q;
25
- }
26
- var ee = {};
27
- /**
28
- * @license React
29
- * react-jsx-runtime.development.js
30
- *
31
- * Copyright (c) Facebook, Inc. and its affiliates.
32
- *
33
- * This source code is licensed under the MIT license found in the
34
- * LICENSE file in the root directory of this source tree.
35
- */
36
- var We;
37
- function pr() {
38
- return We || (We = 1, process.env.NODE_ENV !== "production" && (function() {
39
- var _ = $e, c = Symbol.for("react.element"), E = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), f = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), m = Symbol.for("react.context"), h = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), s = Symbol.for("react.suspense_list"), a = Symbol.for("react.memo"), O = Symbol.for("react.lazy"), S = Symbol.for("react.offscreen"), N = Symbol.iterator, L = "@@iterator";
40
- function C(e) {
41
- if (e === null || typeof e != "object")
42
- return null;
43
- var r = N && e[N] || e[L];
44
- return typeof r == "function" ? r : null;
45
- }
46
- var k = _.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
47
- function d(e) {
48
- {
49
- for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
50
- t[n - 1] = arguments[n];
51
- D("error", e, t);
52
- }
53
- }
54
- function D(e, r, t) {
55
- {
56
- var n = k.ReactDebugCurrentFrame, u = n.getStackAddendum();
57
- u !== "" && (r += "%s", t = t.concat([u]));
58
- var v = t.map(function(l) {
59
- return String(l);
60
- });
61
- v.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, v);
62
- }
63
- }
64
- var U = !1, z = !1, F = !1, w = !1, J = !1, K;
65
- K = Symbol.for("react.module.reference");
66
- function ie(e) {
67
- return !!(typeof e == "string" || typeof e == "function" || e === x || e === f || J || e === o || e === p || e === s || w || e === S || U || z || F || typeof e == "object" && e !== null && (e.$$typeof === O || e.$$typeof === a || e.$$typeof === b || e.$$typeof === m || e.$$typeof === h || // This needs to include all possible module reference object
68
- // types supported by any Flight configuration anywhere since
69
- // we don't know which Flight build this will end up being used
70
- // with.
71
- e.$$typeof === K || e.getModuleId !== void 0));
72
- }
73
- function le(e, r, t) {
74
- var n = e.displayName;
75
- if (n)
76
- return n;
77
- var u = r.displayName || r.name || "";
78
- return u !== "" ? t + "(" + u + ")" : t;
79
- }
80
- function X(e) {
81
- return e.displayName || "Context";
82
- }
83
- function I(e) {
84
- if (e == null)
85
- return null;
86
- if (typeof e.tag == "number" && d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
87
- return e.displayName || e.name || null;
88
- if (typeof e == "string")
89
- return e;
90
- switch (e) {
91
- case x:
92
- return "Fragment";
93
- case E:
94
- return "Portal";
95
- case f:
96
- return "Profiler";
97
- case o:
98
- return "StrictMode";
99
- case p:
100
- return "Suspense";
101
- case s:
102
- return "SuspenseList";
103
- }
104
- if (typeof e == "object")
105
- switch (e.$$typeof) {
106
- case m:
107
- var r = e;
108
- return X(r) + ".Consumer";
109
- case b:
110
- var t = e;
111
- return X(t._context) + ".Provider";
112
- case h:
113
- return le(e, e.render, "ForwardRef");
114
- case a:
115
- var n = e.displayName || null;
116
- return n !== null ? n : I(e.type) || "Memo";
117
- case O: {
118
- var u = e, v = u._payload, l = u._init;
119
- try {
120
- return I(l(v));
121
- } catch {
122
- return null;
123
- }
124
- }
125
- }
126
- return null;
127
- }
128
- var M = Object.assign, y = 0, j, Y, W, V, $, he, be;
129
- function ge() {
130
- }
131
- ge.__reactDisabledLog = !0;
132
- function Ye() {
133
- {
134
- if (y === 0) {
135
- j = console.log, Y = console.info, W = console.warn, V = console.error, $ = console.group, he = console.groupCollapsed, be = console.groupEnd;
136
- var e = {
137
- configurable: !0,
138
- enumerable: !0,
139
- value: ge,
140
- writable: !0
141
- };
142
- Object.defineProperties(console, {
143
- info: e,
144
- log: e,
145
- warn: e,
146
- error: e,
147
- group: e,
148
- groupCollapsed: e,
149
- groupEnd: e
150
- });
151
- }
152
- y++;
153
- }
154
- }
155
- function Le() {
156
- {
157
- if (y--, y === 0) {
158
- var e = {
159
- configurable: !0,
160
- enumerable: !0,
161
- writable: !0
162
- };
163
- Object.defineProperties(console, {
164
- log: M({}, e, {
165
- value: j
166
- }),
167
- info: M({}, e, {
168
- value: Y
169
- }),
170
- warn: M({}, e, {
171
- value: W
172
- }),
173
- error: M({}, e, {
174
- value: V
175
- }),
176
- group: M({}, e, {
177
- value: $
178
- }),
179
- groupCollapsed: M({}, e, {
180
- value: he
181
- }),
182
- groupEnd: M({}, e, {
183
- value: be
184
- })
185
- });
186
- }
187
- y < 0 && d("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
188
- }
189
- }
190
- var se = k.ReactCurrentDispatcher, ue;
191
- function re(e, r, t) {
192
- {
193
- if (ue === void 0)
194
- try {
195
- throw Error();
196
- } catch (u) {
197
- var n = u.stack.trim().match(/\n( *(at )?)/);
198
- ue = n && n[1] || "";
199
- }
200
- return `
201
- ` + ue + e;
202
- }
203
- }
204
- var ce = !1, te;
205
- {
206
- var Ue = typeof WeakMap == "function" ? WeakMap : Map;
207
- te = new Ue();
208
- }
209
- function me(e, r) {
210
- if (!e || ce)
211
- return "";
212
- {
213
- var t = te.get(e);
214
- if (t !== void 0)
215
- return t;
216
- }
217
- var n;
218
- ce = !0;
219
- var u = Error.prepareStackTrace;
220
- Error.prepareStackTrace = void 0;
221
- var v;
222
- v = se.current, se.current = null, Ye();
223
- try {
224
- if (r) {
225
- var l = function() {
226
- throw Error();
227
- };
228
- if (Object.defineProperty(l.prototype, "props", {
229
- set: function() {
230
- throw Error();
231
- }
232
- }), typeof Reflect == "object" && Reflect.construct) {
233
- try {
234
- Reflect.construct(l, []);
235
- } catch (P) {
236
- n = P;
237
- }
238
- Reflect.construct(e, [], l);
239
- } else {
240
- try {
241
- l.call();
242
- } catch (P) {
243
- n = P;
244
- }
245
- e.call(l.prototype);
246
- }
247
- } else {
248
- try {
249
- throw Error();
250
- } catch (P) {
251
- n = P;
252
- }
253
- e();
254
- }
255
- } catch (P) {
256
- if (P && n && typeof P.stack == "string") {
257
- for (var i = P.stack.split(`
258
- `), T = n.stack.split(`
259
- `), g = i.length - 1, R = T.length - 1; g >= 1 && R >= 0 && i[g] !== T[R]; )
260
- R--;
261
- for (; g >= 1 && R >= 0; g--, R--)
262
- if (i[g] !== T[R]) {
263
- if (g !== 1 || R !== 1)
264
- do
265
- if (g--, R--, R < 0 || i[g] !== T[R]) {
266
- var A = `
267
- ` + i[g].replace(" at new ", " at ");
268
- return e.displayName && A.includes("<anonymous>") && (A = A.replace("<anonymous>", e.displayName)), typeof e == "function" && te.set(e, A), A;
269
- }
270
- while (g >= 1 && R >= 0);
271
- break;
272
- }
273
- }
274
- } finally {
275
- ce = !1, se.current = v, Le(), Error.prepareStackTrace = u;
276
- }
277
- var H = e ? e.displayName || e.name : "", q = H ? re(H) : "";
278
- return typeof e == "function" && te.set(e, q), q;
279
- }
280
- function ze(e, r, t) {
281
- return me(e, !1);
282
- }
283
- function Ve(e) {
284
- var r = e.prototype;
285
- return !!(r && r.isReactComponent);
286
- }
287
- function ne(e, r, t) {
288
- if (e == null)
289
- return "";
290
- if (typeof e == "function")
291
- return me(e, Ve(e));
292
- if (typeof e == "string")
293
- return re(e);
294
- switch (e) {
295
- case p:
296
- return re("Suspense");
297
- case s:
298
- return re("SuspenseList");
299
- }
300
- if (typeof e == "object")
301
- switch (e.$$typeof) {
302
- case h:
303
- return ze(e.render);
304
- case a:
305
- return ne(e.type, r, t);
306
- case O: {
307
- var n = e, u = n._payload, v = n._init;
308
- try {
309
- return ne(v(u), r, t);
310
- } catch {
311
- }
312
- }
313
- }
314
- return "";
315
- }
316
- var Z = Object.prototype.hasOwnProperty, Re = {}, _e = k.ReactDebugCurrentFrame;
317
- function ae(e) {
318
- if (e) {
319
- var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
320
- _e.setExtraStackFrame(t);
321
- } else
322
- _e.setExtraStackFrame(null);
323
- }
324
- function Be(e, r, t, n, u) {
325
- {
326
- var v = Function.call.bind(Z);
327
- for (var l in e)
328
- if (v(e, l)) {
329
- var i = void 0;
330
- try {
331
- if (typeof e[l] != "function") {
332
- var T = Error((n || "React class") + ": " + t + " type `" + l + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[l] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
333
- throw T.name = "Invariant Violation", T;
334
- }
335
- i = e[l](r, l, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
336
- } catch (g) {
337
- i = g;
338
- }
339
- i && !(i instanceof Error) && (ae(u), d("%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).", n || "React class", t, l, typeof i), ae(null)), i instanceof Error && !(i.message in Re) && (Re[i.message] = !0, ae(u), d("Failed %s type: %s", t, i.message), ae(null));
340
- }
341
- }
342
- }
343
- var Ne = Array.isArray;
344
- function fe(e) {
345
- return Ne(e);
346
- }
347
- function Je(e) {
348
- {
349
- var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
350
- return t;
351
- }
352
- }
353
- function Ke(e) {
354
- try {
355
- return Ee(e), !1;
356
- } catch {
357
- return !0;
358
- }
359
- }
360
- function Ee(e) {
361
- return "" + e;
362
- }
363
- function xe(e) {
364
- if (Ke(e))
365
- return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Je(e)), Ee(e);
366
- }
367
- var Se = k.ReactCurrentOwner, qe = {
368
- key: !0,
369
- ref: !0,
370
- __self: !0,
371
- __source: !0
372
- }, Te, we;
373
- function Ge(e) {
374
- if (Z.call(e, "ref")) {
375
- var r = Object.getOwnPropertyDescriptor(e, "ref").get;
376
- if (r && r.isReactWarning)
377
- return !1;
378
- }
379
- return e.ref !== void 0;
380
- }
381
- function He(e) {
382
- if (Z.call(e, "key")) {
383
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
384
- if (r && r.isReactWarning)
385
- return !1;
386
- }
387
- return e.key !== void 0;
388
- }
389
- function Xe(e, r) {
390
- typeof e.ref == "string" && Se.current;
391
- }
392
- function Ze(e, r) {
393
- {
394
- var t = function() {
395
- Te || (Te = !0, d("%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)", r));
396
- };
397
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
398
- get: t,
399
- configurable: !0
400
- });
401
- }
402
- }
403
- function Qe(e, r) {
404
- {
405
- var t = function() {
406
- we || (we = !0, d("%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)", r));
407
- };
408
- t.isReactWarning = !0, Object.defineProperty(e, "ref", {
409
- get: t,
410
- configurable: !0
411
- });
412
- }
413
- }
414
- var er = function(e, r, t, n, u, v, l) {
415
- var i = {
416
- // This tag allows us to uniquely identify this as a React Element
417
- $$typeof: c,
418
- // Built-in properties that belong on the element
419
- type: e,
420
- key: r,
421
- ref: t,
422
- props: l,
423
- // Record the component responsible for creating this element.
424
- _owner: v
425
- };
426
- return i._store = {}, Object.defineProperty(i._store, "validated", {
427
- configurable: !1,
428
- enumerable: !1,
429
- writable: !0,
430
- value: !1
431
- }), Object.defineProperty(i, "_self", {
432
- configurable: !1,
433
- enumerable: !1,
434
- writable: !1,
435
- value: n
436
- }), Object.defineProperty(i, "_source", {
437
- configurable: !1,
438
- enumerable: !1,
439
- writable: !1,
440
- value: u
441
- }), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
442
- };
443
- function rr(e, r, t, n, u) {
444
- {
445
- var v, l = {}, i = null, T = null;
446
- t !== void 0 && (xe(t), i = "" + t), He(r) && (xe(r.key), i = "" + r.key), Ge(r) && (T = r.ref, Xe(r, u));
447
- for (v in r)
448
- Z.call(r, v) && !qe.hasOwnProperty(v) && (l[v] = r[v]);
449
- if (e && e.defaultProps) {
450
- var g = e.defaultProps;
451
- for (v in g)
452
- l[v] === void 0 && (l[v] = g[v]);
453
- }
454
- if (i || T) {
455
- var R = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
456
- i && Ze(l, R), T && Qe(l, R);
457
- }
458
- return er(e, i, T, u, n, Se.current, l);
459
- }
460
- }
461
- var de = k.ReactCurrentOwner, Pe = k.ReactDebugCurrentFrame;
462
- function G(e) {
463
- if (e) {
464
- var r = e._owner, t = ne(e.type, e._source, r ? r.type : null);
465
- Pe.setExtraStackFrame(t);
466
- } else
467
- Pe.setExtraStackFrame(null);
468
- }
469
- var ve;
470
- ve = !1;
471
- function pe(e) {
472
- return typeof e == "object" && e !== null && e.$$typeof === c;
473
- }
474
- function Ce() {
475
- {
476
- if (de.current) {
477
- var e = I(de.current.type);
478
- if (e)
479
- return `
480
-
481
- Check the render method of \`` + e + "`.";
482
- }
483
- return "";
484
- }
485
- }
486
- function tr(e) {
487
- return "";
488
- }
489
- var Oe = {};
490
- function nr(e) {
491
- {
492
- var r = Ce();
493
- if (!r) {
494
- var t = typeof e == "string" ? e : e.displayName || e.name;
495
- t && (r = `
496
-
497
- Check the top-level render call using <` + t + ">.");
498
- }
499
- return r;
500
- }
501
- }
502
- function ke(e, r) {
503
- {
504
- if (!e._store || e._store.validated || e.key != null)
505
- return;
506
- e._store.validated = !0;
507
- var t = nr(r);
508
- if (Oe[t])
509
- return;
510
- Oe[t] = !0;
511
- var n = "";
512
- e && e._owner && e._owner !== de.current && (n = " It was passed a child from " + I(e._owner.type) + "."), G(e), d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), G(null);
513
- }
514
- }
515
- function je(e, r) {
516
- {
517
- if (typeof e != "object")
518
- return;
519
- if (fe(e))
520
- for (var t = 0; t < e.length; t++) {
521
- var n = e[t];
522
- pe(n) && ke(n, r);
523
- }
524
- else if (pe(e))
525
- e._store && (e._store.validated = !0);
526
- else if (e) {
527
- var u = C(e);
528
- if (typeof u == "function" && u !== e.entries)
529
- for (var v = u.call(e), l; !(l = v.next()).done; )
530
- pe(l.value) && ke(l.value, r);
531
- }
532
- }
533
- }
534
- function ar(e) {
535
- {
536
- var r = e.type;
537
- if (r == null || typeof r == "string")
538
- return;
539
- var t;
540
- if (typeof r == "function")
541
- t = r.propTypes;
542
- else if (typeof r == "object" && (r.$$typeof === h || // Note: Memo only checks outer props here.
543
- // Inner props are checked in the reconciler.
544
- r.$$typeof === a))
545
- t = r.propTypes;
546
- else
547
- return;
548
- if (t) {
549
- var n = I(r);
550
- Be(t, e.props, "prop", n, e);
551
- } else if (r.PropTypes !== void 0 && !ve) {
552
- ve = !0;
553
- var u = I(r);
554
- d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
555
- }
556
- typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
557
- }
558
- }
559
- function or(e) {
560
- {
561
- for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
562
- var n = r[t];
563
- if (n !== "children" && n !== "key") {
564
- G(e), d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), G(null);
565
- break;
566
- }
567
- }
568
- e.ref !== null && (G(e), d("Invalid attribute `ref` supplied to `React.Fragment`."), G(null));
569
- }
570
- }
571
- var Ae = {};
572
- function De(e, r, t, n, u, v) {
573
- {
574
- var l = ie(e);
575
- if (!l) {
576
- var i = "";
577
- (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (i += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
578
- var T = tr();
579
- T ? i += T : i += Ce();
580
- var g;
581
- e === null ? g = "null" : fe(e) ? g = "array" : e !== void 0 && e.$$typeof === c ? (g = "<" + (I(e.type) || "Unknown") + " />", i = " Did you accidentally export a JSX literal instead of a component?") : g = typeof e, d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", g, i);
582
- }
583
- var R = rr(e, r, t, u, v);
584
- if (R == null)
585
- return R;
586
- if (l) {
587
- var A = r.children;
588
- if (A !== void 0)
589
- if (n)
590
- if (fe(A)) {
591
- for (var H = 0; H < A.length; H++)
592
- je(A[H], e);
593
- Object.freeze && Object.freeze(A);
594
- } else
595
- d("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
596
- else
597
- je(A, e);
598
- }
599
- if (Z.call(r, "key")) {
600
- var q = I(e), P = Object.keys(r).filter(function(fr) {
601
- return fr !== "key";
602
- }), ye = P.length > 0 ? "{key: someKey, " + P.join(": ..., ") + ": ...}" : "{key: someKey}";
603
- if (!Ae[q + ye]) {
604
- var cr = P.length > 0 ? "{" + P.join(": ..., ") + ": ...}" : "{}";
605
- d(`A props object containing a "key" prop is being spread into JSX:
606
- let props = %s;
607
- <%s {...props} />
608
- React keys must be passed directly to JSX without using spread:
609
- let props = %s;
610
- <%s key={someKey} {...props} />`, ye, q, cr, q), Ae[q + ye] = !0;
611
- }
612
- }
613
- return e === x ? or(R) : ar(R), R;
614
- }
615
- }
616
- function ir(e, r, t) {
617
- return De(e, r, t, !0);
618
- }
619
- function lr(e, r, t) {
620
- return De(e, r, t, !1);
621
- }
622
- var sr = lr, ur = ir;
623
- ee.Fragment = x, ee.jsx = sr, ee.jsxs = ur;
624
- })()), ee;
625
- }
626
- var Me;
627
- function yr() {
628
- return Me || (Me = 1, process.env.NODE_ENV === "production" ? oe.exports = vr() : oe.exports = pr()), oe.exports;
629
- }
630
- var hr = yr();
631
- function br(_, c) {
632
- const E = Math.PI, x = () => this._context, o = this.props, f = this._score, b = () => this.state, m = (p) => {
633
- this.setState(p);
1
+ import { jsx as G } from "react/jsx-runtime";
2
+ import { useState as K, useRef as g, useEffect as H } from "react";
3
+ function U(s, r) {
4
+ const i = Math.PI, x = () => this._context, t = this.props, n = this._score, o = () => this.state, u = (a) => {
5
+ this.setState(a);
634
6
  }, h = Math.random();
635
7
  return {
636
- serve(p) {
637
- const s = 0.1 * E * (1 - 2 * h);
638
- m((a) => ({
639
- ...a,
640
- ballx: p === 1 ? a.playerx + o.paddleWidth : a.aix - o.ballSize,
641
- bally: (o.height - o.ballSize) * h,
642
- velx: a.ballSpeed * Math.cos(s) * p,
643
- vely: a.ballSpeed * Math.sin(s)
8
+ serve(a) {
9
+ const c = 0.1 * i * (1 - 2 * h);
10
+ u((e) => ({
11
+ ...e,
12
+ ballx: a === 1 ? e.playerx + t.paddleWidth : e.aix - t.ballSize,
13
+ bally: (t.height - t.ballSize) * h,
14
+ velx: e.ballSpeed * Math.cos(c) * a,
15
+ vely: e.ballSpeed * Math.sin(c)
644
16
  }));
645
17
  },
646
18
  update() {
647
- const p = _(), s = c(), a = b(), O = a.ballx, S = a.bally, N = a.velx, L = a.vely;
648
- if (m((d) => ({
19
+ const a = s(), c = r(), e = o(), P = e.ballx, f = e.bally, _ = e.velx, T = e.vely;
20
+ if (u((d) => ({
649
21
  ...d,
650
- ballx: O + N,
651
- bally: S + L
652
- })), 0 > S || S + o.ballSize > o.height) {
653
- const d = a.vely < 0 ? 0 - a.bally : o.height - (a.bally + o.ballSize);
654
- m((D) => ({
655
- ...D,
656
- bally: S + 2 * d,
657
- vely: L * -1
22
+ ballx: P + _,
23
+ bally: f + T
24
+ })), 0 > f || f + t.ballSize > t.height) {
25
+ const d = e.vely < 0 ? 0 - e.bally : t.height - (e.bally + t.ballSize);
26
+ u((S) => ({
27
+ ...S,
28
+ bally: f + 2 * d,
29
+ vely: T * -1
658
30
  }));
659
31
  }
660
- const C = a.velx < 0 ? p : s;
661
- if (((d, D, U, z, F, w, J, K) => d < F + J && D < w + K && F < d + U && w < D + z)(
662
- C.position().x,
663
- C.position().y,
664
- o.paddleWidth,
665
- o.paddleHeight,
666
- a.ballx,
667
- a.bally,
668
- o.ballSize,
669
- o.ballSize
32
+ const y = e.velx < 0 ? a : c;
33
+ if (((d, S, R, z, b, p, k, I) => d < b + k && S < p + I && b < d + R && p < S + z)(
34
+ y.position().x,
35
+ y.position().y,
36
+ t.paddleWidth,
37
+ t.paddleHeight,
38
+ e.ballx,
39
+ e.bally,
40
+ t.ballSize,
41
+ t.ballSize
670
42
  )) {
671
- const d = a.velx < 0 ? 1 : -1, D = (a.bally + o.ballSize - C.position().y) / (o.paddleHeight + o.ballSize), U = (D > 0.5 ? -1 : 1) * d, z = 0.25 * E * (2 * D + d) + h, F = Math.abs(z) > 0.2 * E ? 1.1 : 1;
672
- m((w) => ({
673
- ...w,
674
- ballx: C === p ? w.playerx + o.paddleWidth : w.aix - o.ballSize,
675
- velx: F * -1 * w.velx,
676
- vely: F * U * w.velx * Math.sin(z)
43
+ const d = e.velx < 0 ? 1 : -1, S = (e.bally + t.ballSize - y.position().y) / (t.paddleHeight + t.ballSize), R = (S > 0.5 ? -1 : 1) * d, z = 0.25 * i * (2 * S + d) + h, b = Math.abs(z) > 0.2 * i ? 1.1 : 1;
44
+ u((p) => ({
45
+ ...p,
46
+ ballx: y === a ? p.playerx + t.paddleWidth : p.aix - t.ballSize,
47
+ velx: b * -1 * p.velx,
48
+ vely: b * R * p.velx * Math.sin(z)
677
49
  }));
678
50
  }
679
- (0 > a.ballx + o.ballSize || a.ballx > o.width) && (f(C.name()), this.serve(C.name() === p.name() ? 1 : -1));
51
+ (0 > e.ballx + t.ballSize || e.ballx > t.width) && (n(y.name()), this.serve(y.name() === a.name() ? 1 : -1));
680
52
  },
681
53
  draw() {
682
- const p = x();
683
- if (!p) return;
684
- const s = b();
685
- p.beginPath(), p.arc(s.ballx, s.bally, o.ballSize, 0, 2 * Math.PI), p.fill(), p.lineWidth = 0, p.strokeStyle = "#fff", p.stroke();
54
+ const a = x();
55
+ if (!a) return;
56
+ const c = o();
57
+ a.beginPath(), a.arc(c.ballx, c.bally, t.ballSize, 0, 2 * Math.PI), a.fill(), a.lineWidth = 0, a.strokeStyle = "#fff", a.stroke();
686
58
  }
687
59
  };
688
60
  }
689
- function gr() {
690
- const _ = () => this._context, c = this.props, E = this._keystate, x = () => this.state, o = (f) => {
691
- this.setState(f);
61
+ function j() {
62
+ const s = () => this._context, r = this.props, i = this._keystate, x = () => this.state, t = (n) => {
63
+ this.setState(n);
692
64
  };
693
65
  return {
694
66
  update() {
695
- const f = x();
696
- let b = f.playery;
697
- E[c.upArrow] && (b = f.playery - c.paddleSpeed), E[c.downArrow] && (b = f.playery + c.paddleSpeed), b = Math.max(Math.min(b, c.height - c.paddleHeight), 0), o((m) => ({ ...m, playery: b }));
67
+ const n = x();
68
+ let o = n.playery;
69
+ i[r.upArrow] && (o = n.playery - r.paddleSpeed), i[r.downArrow] && (o = n.playery + r.paddleSpeed), o = Math.max(Math.min(o, r.height - r.paddleHeight), 0), t((u) => ({ ...u, playery: o }));
698
70
  },
699
71
  draw() {
700
- const f = _();
701
- if (!f) return;
702
- const b = x();
703
- f.fillRect(b.playerx, b.playery, c.paddleWidth, c.paddleHeight);
72
+ const n = s();
73
+ if (!n) return;
74
+ const o = x();
75
+ n.fillRect(o.playerx, o.playery, r.paddleWidth, r.paddleHeight);
704
76
  },
705
77
  name() {
706
78
  return "player";
707
79
  },
708
- position(f) {
709
- f !== void 0 && o((m) => ({ ...m, playery: f }));
710
- const b = x();
80
+ position(n) {
81
+ n !== void 0 && t((u) => ({ ...u, playery: n }));
82
+ const o = x();
711
83
  return {
712
- x: b.playerx,
713
- y: b.playery
84
+ x: o.playerx,
85
+ y: o.playery
714
86
  };
715
87
  }
716
88
  };
717
89
  }
718
- function mr() {
719
- const _ = () => this._context, c = this.props, E = () => this.state, x = (o) => {
720
- this.setState(o);
90
+ function q() {
91
+ const s = () => this._context, r = this.props, i = () => this.state, x = (t) => {
92
+ this.setState(t);
721
93
  };
722
94
  return {
723
95
  update() {
724
- const o = E();
725
- let f = o.aiy;
726
- const b = o.bally - (c.paddleHeight - c.ballSize) * 0.5;
727
- f = f + (b - f) * 0.1, x((m) => ({ ...m, aiy: f }));
96
+ const t = i();
97
+ let n = t.aiy;
98
+ const o = t.bally - (r.paddleHeight - r.ballSize) * 0.5;
99
+ n = n + (o - n) * 0.1, x((u) => ({ ...u, aiy: n }));
728
100
  },
729
101
  draw() {
730
- const o = _();
731
- if (!o) return;
732
- const f = E();
733
- o.fillRect(f.aix, f.aiy, c.paddleWidth, c.paddleHeight);
102
+ const t = s();
103
+ if (!t) return;
104
+ const n = i();
105
+ t.fillRect(n.aix, n.aiy, r.paddleWidth, r.paddleHeight);
734
106
  },
735
107
  name() {
736
108
  return "ai";
737
109
  },
738
110
  position() {
739
- const o = E();
111
+ const t = i();
740
112
  return {
741
- x: o.aix,
742
- y: o.aiy
113
+ x: t.aix,
114
+ y: t.aiy
743
115
  };
744
116
  }
745
117
  };
746
118
  }
747
- const _r = ({
748
- height: _ = 600,
749
- width: c = 700,
750
- upArrow: E = "ArrowUp",
119
+ const N = ({
120
+ height: s = 600,
121
+ width: r = 700,
122
+ upArrow: i = "ArrowUp",
751
123
  downArrow: x = "ArrowDown",
752
- paddleHeight: o = 100,
753
- paddleWidth: f = 20,
754
- paddleSpeed: b = 5,
755
- ballSize: m = 10
124
+ paddleHeight: t = 100,
125
+ paddleWidth: n = 20,
126
+ paddleSpeed: o = 5,
127
+ ballSize: u = 10
756
128
  }) => {
757
- const [h, p] = dr({
129
+ const [h, a] = K({
758
130
  ballx: 100,
759
131
  bally: 100,
760
132
  ballSpeed: 2,
@@ -766,9 +138,9 @@ const _r = ({
766
138
  playery: 100,
767
139
  playerScore: 0,
768
140
  aiScore: 0
769
- }), s = B(null), a = B(null), O = B({}), S = B(null), N = B(h), L = B(null), C = B(null), k = B(null);
770
- Fe(() => {
771
- N.current = h;
141
+ }), c = g(null), e = g(null), P = g({}), f = g(null), _ = g(h), T = g(null), y = g(null), M = g(null);
142
+ H(() => {
143
+ _.current = h;
772
144
  }, [h]);
773
145
  const d = {
774
146
  display: "block",
@@ -778,97 +150,97 @@ const _r = ({
778
150
  bottom: "0",
779
151
  left: "0",
780
152
  right: "0"
781
- }, D = { height: _, width: c, upArrow: E, downArrow: x, paddleHeight: o, paddleWidth: f, paddleSpeed: b, ballSize: m }, U = () => {
782
- s.current && (a.current = s.current.getContext("2d"));
783
- }, z = (y) => {
784
- const j = y === "player" ? "ai" : "player", Y = j + "Score";
785
- p((W) => ({
786
- ...W,
787
- [Y]: W[Y] + 1
788
- })), X(), setTimeout(() => {
789
- a.current && (a.current.font = "30px Arial", a.current.fillStyle = "#fff", a.current.fillText(
790
- j + " score!",
791
- c / 2,
792
- _ / 2
793
- ), a.current.restore());
153
+ }, S = { height: s, width: r, upArrow: i, downArrow: x, paddleHeight: t, paddleWidth: n, paddleSpeed: o, ballSize: u }, R = () => {
154
+ c.current && (e.current = c.current.getContext("2d"));
155
+ }, z = (l) => {
156
+ const m = l === "player" ? "ai" : "player", A = m + "Score";
157
+ a((v) => ({
158
+ ...v,
159
+ [A]: v[A] + 1
160
+ })), W(), setTimeout(() => {
161
+ e.current && (e.current.font = "30px Arial", e.current.fillStyle = "#fff", e.current.fillText(
162
+ m + " score!",
163
+ r / 2,
164
+ s / 2
165
+ ), e.current.restore());
794
166
  }, 0), setTimeout(() => {
795
- U(), I();
167
+ R(), B();
796
168
  }, 1e3);
797
- }, F = () => ({
169
+ }, b = () => ({
798
170
  get _context() {
799
- return a.current;
171
+ return e.current;
800
172
  },
801
173
  get state() {
802
- return N.current;
174
+ return _.current;
803
175
  },
804
- props: D,
805
- _keystate: O.current,
806
- setState: (y) => {
807
- p(y);
176
+ props: S,
177
+ _keystate: P.current,
178
+ setState: (l) => {
179
+ a(l);
808
180
  },
809
181
  _score: z
810
182
  });
811
- C.current || (C.current = gr.call(F())), k.current || (k.current = mr.call(F())), L.current || (L.current = br.call(
812
- F(),
813
- () => C.current,
814
- () => k.current
183
+ y.current || (y.current = j.call(b())), M.current || (M.current = q.call(b())), T.current || (T.current = U.call(
184
+ b(),
185
+ () => y.current,
186
+ () => M.current
815
187
  ));
816
- const w = L.current, J = C.current, K = k.current, ie = () => {
817
- if (!a.current) return;
818
- const y = a.current;
819
- y.fillStyle = "#000", y.fillRect(0, 0, c, _), y.save(), y.fillStyle = "#fff", y.font = "10px Arial", y.fillText("Player: " + String(h.playerScore), 10, 10), y.fillText("CPU: " + String(h.aiScore), 500, 10), w.draw(), J.draw(), K.draw();
820
- const j = 4, Y = (c - j) * 0.5;
821
- let W = 0;
822
- const V = _ / 20;
823
- for (; W < _; )
824
- y.fillRect(Y, W + V * 0.25, j, V * 0.5), W += V;
825
- y.restore();
826
- }, le = () => {
827
- J.update(), K.update(), w.update();
828
- }, X = () => {
829
- S.current !== null && (clearInterval(S.current), S.current = null), setTimeout(() => {
830
- a.current && s.current && a.current.clearRect(0, 0, s.current.width, s.current.height);
188
+ const p = T.current, k = y.current, I = M.current, D = () => {
189
+ if (!e.current) return;
190
+ const l = e.current;
191
+ l.fillStyle = "#000", l.fillRect(0, 0, r, s), l.save(), l.fillStyle = "#fff", l.font = "10px Arial", l.fillText("Player: " + String(h.playerScore), 10, 10), l.fillText("CPU: " + String(h.aiScore), 500, 10), p.draw(), k.draw(), I.draw();
192
+ const m = 4, A = (r - m) * 0.5;
193
+ let v = 0;
194
+ const C = s / 20;
195
+ for (; v < s; )
196
+ l.fillRect(A, v + C * 0.25, m, C * 0.5), v += C;
197
+ l.restore();
198
+ }, L = () => {
199
+ k.update(), I.update(), p.update();
200
+ }, W = () => {
201
+ f.current !== null && (clearInterval(f.current), f.current = null), setTimeout(() => {
202
+ e.current && c.current && e.current.clearRect(0, 0, c.current.width, c.current.height);
831
203
  }, 0);
832
- }, I = () => {
833
- if (S.current)
204
+ }, B = () => {
205
+ if (f.current)
834
206
  return;
835
- const y = O.current, j = ($) => {
836
- y[$.code] = !0;
837
- }, Y = ($) => {
838
- y[$.code] = !1;
839
- }, W = ($) => {
840
- $.preventDefault();
841
- }, V = ($) => {
842
- $.preventDefault();
207
+ const l = P.current, m = (w) => {
208
+ l[w.code] = !0;
209
+ }, A = (w) => {
210
+ l[w.code] = !1;
211
+ }, v = (w) => {
212
+ w.preventDefault();
213
+ }, C = (w) => {
214
+ w.preventDefault();
843
215
  };
844
- document.addEventListener("keydown", j), document.addEventListener("keyup", Y), document.addEventListener("touchstart", W, !1), document.addEventListener("touchmove", V, !1), S.current = window.setInterval(() => {
845
- le(), ie();
846
- }, 1), w.serve(1);
847
- }, M = (y) => {
848
- if (s.current) {
849
- const j = y.touches[0].pageY - s.current.offsetTop - o / 2;
850
- J.position(j);
216
+ document.addEventListener("keydown", m), document.addEventListener("keyup", A), document.addEventListener("touchstart", v, !1), document.addEventListener("touchmove", C, !1), f.current = window.setInterval(() => {
217
+ L(), D();
218
+ }, 1), p.serve(1);
219
+ }, E = (l) => {
220
+ if (c.current) {
221
+ const m = l.touches[0].pageY - c.current.offsetTop - t / 2;
222
+ k.position(m);
851
223
  }
852
224
  };
853
- return Fe(() => {
854
- U(), a.current && (a.current.font = "30px Arial", a.current.fillText("Starting Game", c / 2, _ / 2));
855
- const y = setTimeout(I, 1e3);
225
+ return H(() => {
226
+ R(), e.current && (e.current.font = "30px Arial", e.current.fillText("Starting Game", r / 2, s / 2));
227
+ const l = setTimeout(B, 1e3);
856
228
  return () => {
857
- clearTimeout(y), X();
229
+ clearTimeout(l), W();
858
230
  };
859
- }, []), /* @__PURE__ */ hr.jsx(
231
+ }, []), /* @__PURE__ */ G(
860
232
  "canvas",
861
233
  {
862
- ref: s,
863
- onTouchStart: M,
864
- onTouchMove: M,
234
+ ref: c,
235
+ onTouchStart: E,
236
+ onTouchMove: E,
865
237
  style: d,
866
- width: c,
867
- height: _
238
+ width: r,
239
+ height: s
868
240
  }
869
241
  );
870
242
  };
871
243
  export {
872
- _r as Pong,
873
- _r as default
244
+ N as Pong,
245
+ N as default
874
246
  };
@@ -1,30 +1 @@
1
- (function(z,_){typeof exports=="object"&&typeof module<"u"?_(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],_):(z=typeof globalThis<"u"?globalThis:z||self,_(z.ReactPong={},z.React))})(this,(function(z,_){"use strict";var te={exports:{}},$={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var be;function Le(){if(be)return $;be=1;var E=_,c=Symbol.for("react.element"),x=Symbol.for("react.fragment"),S=Object.prototype.hasOwnProperty,o=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,f={key:!0,ref:!0,__self:!0,__source:!0};function b(R,h,p){var l,a={},j=null,T=null;p!==void 0&&(j=""+p),h.key!==void 0&&(j=""+h.key),h.ref!==void 0&&(T=h.ref);for(l in h)S.call(h,l)&&!f.hasOwnProperty(l)&&(a[l]=h[l]);if(R&&R.defaultProps)for(l in h=R.defaultProps,h)a[l]===void 0&&(a[l]=h[l]);return{$$typeof:c,type:R,key:j,ref:T,props:a,_owner:o.current}}return $.Fragment=x,$.jsx=b,$.jsxs=b,$}var q={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var ge;function Ue(){return ge||(ge=1,process.env.NODE_ENV!=="production"&&(function(){var E=_,c=Symbol.for("react.element"),x=Symbol.for("react.portal"),S=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),f=Symbol.for("react.profiler"),b=Symbol.for("react.provider"),R=Symbol.for("react.context"),h=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),l=Symbol.for("react.suspense_list"),a=Symbol.for("react.memo"),j=Symbol.for("react.lazy"),T=Symbol.for("react.offscreen"),K=Symbol.iterator,V="@@iterator";function O(e){if(e===null||typeof e!="object")return null;var r=K&&e[K]||e[V];return typeof r=="function"?r:null}var k=E.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function d(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];F("error",e,t)}}function F(e,r,t){{var n=k.ReactDebugCurrentFrame,u=n.getStackAddendum();u!==""&&(r+="%s",t=t.concat([u]));var v=t.map(function(s){return String(s)});v.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,v)}}var B=!1,N=!1,I=!1,P=!1,G=!1,H;H=Symbol.for("react.module.reference");function se(e){return!!(typeof e=="string"||typeof e=="function"||e===S||e===f||G||e===o||e===p||e===l||P||e===T||B||N||I||typeof e=="object"&&e!==null&&(e.$$typeof===j||e.$$typeof===a||e.$$typeof===b||e.$$typeof===R||e.$$typeof===h||e.$$typeof===H||e.getModuleId!==void 0))}function le(e,r,t){var n=e.displayName;if(n)return n;var u=r.displayName||r.name||"";return u!==""?t+"("+u+")":t}function ee(e){return e.displayName||"Context"}function M(e){if(e==null)return null;if(typeof e.tag=="number"&&d("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case S:return"Fragment";case x:return"Portal";case f:return"Profiler";case o:return"StrictMode";case p:return"Suspense";case l:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case R:var r=e;return ee(r)+".Consumer";case b:var t=e;return ee(t._context)+".Provider";case h:return le(e,e.render,"ForwardRef");case a:var n=e.displayName||null;return n!==null?n:M(e.type)||"Memo";case j:{var u=e,v=u._payload,s=u._init;try{return M(s(v))}catch{return null}}}return null}var Y=Object.assign,y=0,A,U,W,J,L,_e,Ee;function xe(){}xe.__reactDisabledLog=!0;function Ke(){{if(y===0){A=console.log,U=console.info,W=console.warn,J=console.error,L=console.group,_e=console.groupCollapsed,Ee=console.groupEnd;var e={configurable:!0,enumerable:!0,value:xe,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}y++}}function Ge(){{if(y--,y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:Y({},e,{value:A}),info:Y({},e,{value:U}),warn:Y({},e,{value:W}),error:Y({},e,{value:J}),group:Y({},e,{value:L}),groupCollapsed:Y({},e,{value:_e}),groupEnd:Y({},e,{value:Ee})})}y<0&&d("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ue=k.ReactCurrentDispatcher,ce;function ne(e,r,t){{if(ce===void 0)try{throw Error()}catch(u){var n=u.stack.trim().match(/\n( *(at )?)/);ce=n&&n[1]||""}return`
18
- `+ce+e}}var fe=!1,ae;{var He=typeof WeakMap=="function"?WeakMap:Map;ae=new He}function Se(e,r){if(!e||fe)return"";{var t=ae.get(e);if(t!==void 0)return t}var n;fe=!0;var u=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var v;v=ue.current,ue.current=null,Ke();try{if(r){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(s,[])}catch(C){n=C}Reflect.construct(e,[],s)}else{try{s.call()}catch(C){n=C}e.call(s.prototype)}}else{try{throw Error()}catch(C){n=C}e()}}catch(C){if(C&&n&&typeof C.stack=="string"){for(var i=C.stack.split(`
19
- `),w=n.stack.split(`
20
- `),g=i.length-1,m=w.length-1;g>=1&&m>=0&&i[g]!==w[m];)m--;for(;g>=1&&m>=0;g--,m--)if(i[g]!==w[m]){if(g!==1||m!==1)do if(g--,m--,m<0||i[g]!==w[m]){var D=`
21
- `+i[g].replace(" at new "," at ");return e.displayName&&D.includes("<anonymous>")&&(D=D.replace("<anonymous>",e.displayName)),typeof e=="function"&&ae.set(e,D),D}while(g>=1&&m>=0);break}}}finally{fe=!1,ue.current=v,Ge(),Error.prepareStackTrace=u}var Q=e?e.displayName||e.name:"",X=Q?ne(Q):"";return typeof e=="function"&&ae.set(e,X),X}function Xe(e,r,t){return Se(e,!1)}function Ze(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function oe(e,r,t){if(e==null)return"";if(typeof e=="function")return Se(e,Ze(e));if(typeof e=="string")return ne(e);switch(e){case p:return ne("Suspense");case l:return ne("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case h:return Xe(e.render);case a:return oe(e.type,r,t);case j:{var n=e,u=n._payload,v=n._init;try{return oe(v(u),r,t)}catch{}}}return""}var re=Object.prototype.hasOwnProperty,Te={},we=k.ReactDebugCurrentFrame;function ie(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);we.setExtraStackFrame(t)}else we.setExtraStackFrame(null)}function Qe(e,r,t,n,u){{var v=Function.call.bind(re);for(var s in e)if(v(e,s)){var i=void 0;try{if(typeof e[s]!="function"){var w=Error((n||"React class")+": "+t+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw w.name="Invariant Violation",w}i=e[s](r,s,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){i=g}i&&!(i instanceof Error)&&(ie(u),d("%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).",n||"React class",t,s,typeof i),ie(null)),i instanceof Error&&!(i.message in Te)&&(Te[i.message]=!0,ie(u),d("Failed %s type: %s",t,i.message),ie(null))}}}var $e=Array.isArray;function de(e){return $e(e)}function qe(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function er(e){try{return Pe(e),!1}catch{return!0}}function Pe(e){return""+e}function Ce(e){if(er(e))return d("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",qe(e)),Pe(e)}var Oe=k.ReactCurrentOwner,rr={key:!0,ref:!0,__self:!0,__source:!0},je,ke;function tr(e){if(re.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function nr(e){if(re.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function ar(e,r){typeof e.ref=="string"&&Oe.current}function or(e,r){{var t=function(){je||(je=!0,d("%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)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function ir(e,r){{var t=function(){ke||(ke=!0,d("%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)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var sr=function(e,r,t,n,u,v,s){var i={$$typeof:c,type:e,key:r,ref:t,props:s,_owner:v};return i._store={},Object.defineProperty(i._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(i,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(i,"_source",{configurable:!1,enumerable:!1,writable:!1,value:u}),Object.freeze&&(Object.freeze(i.props),Object.freeze(i)),i};function lr(e,r,t,n,u){{var v,s={},i=null,w=null;t!==void 0&&(Ce(t),i=""+t),nr(r)&&(Ce(r.key),i=""+r.key),tr(r)&&(w=r.ref,ar(r,u));for(v in r)re.call(r,v)&&!rr.hasOwnProperty(v)&&(s[v]=r[v]);if(e&&e.defaultProps){var g=e.defaultProps;for(v in g)s[v]===void 0&&(s[v]=g[v])}if(i||w){var m=typeof e=="function"?e.displayName||e.name||"Unknown":e;i&&or(s,m),w&&ir(s,m)}return sr(e,i,w,u,n,Oe.current,s)}}var ve=k.ReactCurrentOwner,Ae=k.ReactDebugCurrentFrame;function Z(e){if(e){var r=e._owner,t=oe(e.type,e._source,r?r.type:null);Ae.setExtraStackFrame(t)}else Ae.setExtraStackFrame(null)}var pe;pe=!1;function ye(e){return typeof e=="object"&&e!==null&&e.$$typeof===c}function De(){{if(ve.current){var e=M(ve.current.type);if(e)return`
22
-
23
- Check the render method of \``+e+"`."}return""}}function ur(e){return""}var Fe={};function cr(e){{var r=De();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
24
-
25
- Check the top-level render call using <`+t+">.")}return r}}function Ie(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=cr(r);if(Fe[t])return;Fe[t]=!0;var n="";e&&e._owner&&e._owner!==ve.current&&(n=" It was passed a child from "+M(e._owner.type)+"."),Z(e),d('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),Z(null)}}function Me(e,r){{if(typeof e!="object")return;if(de(e))for(var t=0;t<e.length;t++){var n=e[t];ye(n)&&Ie(n,r)}else if(ye(e))e._store&&(e._store.validated=!0);else if(e){var u=O(e);if(typeof u=="function"&&u!==e.entries)for(var v=u.call(e),s;!(s=v.next()).done;)ye(s.value)&&Ie(s.value,r)}}}function fr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===h||r.$$typeof===a))t=r.propTypes;else return;if(t){var n=M(r);Qe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!pe){pe=!0;var u=M(r);d("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",u||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&d("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function dr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){Z(e),d("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),Z(null);break}}e.ref!==null&&(Z(e),d("Invalid attribute `ref` supplied to `React.Fragment`."),Z(null))}}var We={};function Ye(e,r,t,n,u,v){{var s=se(e);if(!s){var i="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(i+=" 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 w=ur();w?i+=w:i+=De();var g;e===null?g="null":de(e)?g="array":e!==void 0&&e.$$typeof===c?(g="<"+(M(e.type)||"Unknown")+" />",i=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,d("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,i)}var m=lr(e,r,t,u,v);if(m==null)return m;if(s){var D=r.children;if(D!==void 0)if(n)if(de(D)){for(var Q=0;Q<D.length;Q++)Me(D[Q],e);Object.freeze&&Object.freeze(D)}else d("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 Me(D,e)}if(re.call(r,"key")){var X=M(e),C=Object.keys(r).filter(function(gr){return gr!=="key"}),he=C.length>0?"{key: someKey, "+C.join(": ..., ")+": ...}":"{key: someKey}";if(!We[X+he]){var br=C.length>0?"{"+C.join(": ..., ")+": ...}":"{}";d(`A props object containing a "key" prop is being spread into JSX:
26
- let props = %s;
27
- <%s {...props} />
28
- React keys must be passed directly to JSX without using spread:
29
- let props = %s;
30
- <%s key={someKey} {...props} />`,he,X,br,X),We[X+he]=!0}}return e===S?dr(m):fr(m),m}}function vr(e,r,t){return Ye(e,r,t,!0)}function pr(e,r,t){return Ye(e,r,t,!1)}var yr=pr,hr=vr;q.Fragment=S,q.jsx=yr,q.jsxs=hr})()),q}var Re;function ze(){return Re||(Re=1,process.env.NODE_ENV==="production"?te.exports=Le():te.exports=Ue()),te.exports}var Ve=ze();function Be(E,c){const x=Math.PI,S=()=>this._context,o=this.props,f=this._score,b=()=>this.state,R=p=>{this.setState(p)},h=Math.random();return{serve(p){const l=.1*x*(1-2*h);R(a=>({...a,ballx:p===1?a.playerx+o.paddleWidth:a.aix-o.ballSize,bally:(o.height-o.ballSize)*h,velx:a.ballSpeed*Math.cos(l)*p,vely:a.ballSpeed*Math.sin(l)}))},update(){const p=E(),l=c(),a=b(),j=a.ballx,T=a.bally,K=a.velx,V=a.vely;if(R(d=>({...d,ballx:j+K,bally:T+V})),0>T||T+o.ballSize>o.height){const d=a.vely<0?0-a.bally:o.height-(a.bally+o.ballSize);R(F=>({...F,bally:T+2*d,vely:V*-1}))}const O=a.velx<0?p:l;if(((d,F,B,N,I,P,G,H)=>d<I+G&&F<P+H&&I<d+B&&P<F+N)(O.position().x,O.position().y,o.paddleWidth,o.paddleHeight,a.ballx,a.bally,o.ballSize,o.ballSize)){const d=a.velx<0?1:-1,F=(a.bally+o.ballSize-O.position().y)/(o.paddleHeight+o.ballSize),B=(F>.5?-1:1)*d,N=.25*x*(2*F+d)+h,I=Math.abs(N)>.2*x?1.1:1;R(P=>({...P,ballx:O===p?P.playerx+o.paddleWidth:P.aix-o.ballSize,velx:I*-1*P.velx,vely:I*B*P.velx*Math.sin(N)}))}(0>a.ballx+o.ballSize||a.ballx>o.width)&&(f(O.name()),this.serve(O.name()===p.name()?1:-1))},draw(){const p=S();if(!p)return;const l=b();p.beginPath(),p.arc(l.ballx,l.bally,o.ballSize,0,2*Math.PI),p.fill(),p.lineWidth=0,p.strokeStyle="#fff",p.stroke()}}}function Ne(){const E=()=>this._context,c=this.props,x=this._keystate,S=()=>this.state,o=f=>{this.setState(f)};return{update(){const f=S();let b=f.playery;x[c.upArrow]&&(b=f.playery-c.paddleSpeed),x[c.downArrow]&&(b=f.playery+c.paddleSpeed),b=Math.max(Math.min(b,c.height-c.paddleHeight),0),o(R=>({...R,playery:b}))},draw(){const f=E();if(!f)return;const b=S();f.fillRect(b.playerx,b.playery,c.paddleWidth,c.paddleHeight)},name(){return"player"},position(f){f!==void 0&&o(R=>({...R,playery:f}));const b=S();return{x:b.playerx,y:b.playery}}}}function Je(){const E=()=>this._context,c=this.props,x=()=>this.state,S=o=>{this.setState(o)};return{update(){const o=x();let f=o.aiy;const b=o.bally-(c.paddleHeight-c.ballSize)*.5;f=f+(b-f)*.1,S(R=>({...R,aiy:f}))},draw(){const o=E();if(!o)return;const f=x();o.fillRect(f.aix,f.aiy,c.paddleWidth,c.paddleHeight)},name(){return"ai"},position(){const o=x();return{x:o.aix,y:o.aiy}}}}const me=({height:E=600,width:c=700,upArrow:x="ArrowUp",downArrow:S="ArrowDown",paddleHeight:o=100,paddleWidth:f=20,paddleSpeed:b=5,ballSize:R=10})=>{const[h,p]=_.useState({ballx:100,bally:100,ballSpeed:2,velx:0,vely:0,aix:670,aiy:100,playerx:10,playery:100,playerScore:0,aiScore:0}),l=_.useRef(null),a=_.useRef(null),j=_.useRef({}),T=_.useRef(null),K=_.useRef(h),V=_.useRef(null),O=_.useRef(null),k=_.useRef(null);_.useEffect(()=>{K.current=h},[h]);const d={display:"block",position:"absolute",margin:"auto",top:"0",bottom:"0",left:"0",right:"0"},F={height:E,width:c,upArrow:x,downArrow:S,paddleHeight:o,paddleWidth:f,paddleSpeed:b,ballSize:R},B=()=>{l.current&&(a.current=l.current.getContext("2d"))},N=y=>{const A=y==="player"?"ai":"player",U=A+"Score";p(W=>({...W,[U]:W[U]+1})),ee(),setTimeout(()=>{a.current&&(a.current.font="30px Arial",a.current.fillStyle="#fff",a.current.fillText(A+" score!",c/2,E/2),a.current.restore())},0),setTimeout(()=>{B(),M()},1e3)},I=()=>({get _context(){return a.current},get state(){return K.current},props:F,_keystate:j.current,setState:y=>{p(y)},_score:N});O.current||(O.current=Ne.call(I())),k.current||(k.current=Je.call(I())),V.current||(V.current=Be.call(I(),()=>O.current,()=>k.current));const P=V.current,G=O.current,H=k.current,se=()=>{if(!a.current)return;const y=a.current;y.fillStyle="#000",y.fillRect(0,0,c,E),y.save(),y.fillStyle="#fff",y.font="10px Arial",y.fillText("Player: "+String(h.playerScore),10,10),y.fillText("CPU: "+String(h.aiScore),500,10),P.draw(),G.draw(),H.draw();const A=4,U=(c-A)*.5;let W=0;const J=E/20;for(;W<E;)y.fillRect(U,W+J*.25,A,J*.5),W+=J;y.restore()},le=()=>{G.update(),H.update(),P.update()},ee=()=>{T.current!==null&&(clearInterval(T.current),T.current=null),setTimeout(()=>{a.current&&l.current&&a.current.clearRect(0,0,l.current.width,l.current.height)},0)},M=()=>{if(T.current)return;const y=j.current,A=L=>{y[L.code]=!0},U=L=>{y[L.code]=!1},W=L=>{L.preventDefault()},J=L=>{L.preventDefault()};document.addEventListener("keydown",A),document.addEventListener("keyup",U),document.addEventListener("touchstart",W,!1),document.addEventListener("touchmove",J,!1),T.current=window.setInterval(()=>{le(),se()},1),P.serve(1)},Y=y=>{if(l.current){const A=y.touches[0].pageY-l.current.offsetTop-o/2;G.position(A)}};return _.useEffect(()=>{B(),a.current&&(a.current.font="30px Arial",a.current.fillText("Starting Game",c/2,E/2));const y=setTimeout(M,1e3);return()=>{clearTimeout(y),ee()}},[]),Ve.jsx("canvas",{ref:l,onTouchStart:Y,onTouchMove:Y,style:d,width:c,height:E})};z.Pong=me,z.default=me,Object.defineProperties(z,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
1
+ (function(h,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],P):(h=typeof globalThis<"u"?globalThis:h||self,P(h.ReactPong={},h.React,h.React))})(this,(function(h,P,p){"use strict";function L(c,r){const i=Math.PI,S=()=>this._context,e=this.props,n=this._score,s=()=>this.state,u=o=>{this.setState(o)},b=Math.random();return{serve(o){const a=.1*i*(1-2*b);u(t=>({...t,ballx:o===1?t.playerx+e.paddleWidth:t.aix-e.ballSize,bally:(e.height-e.ballSize)*b,velx:t.ballSpeed*Math.cos(a)*o,vely:t.ballSpeed*Math.sin(a)}))},update(){const o=c(),a=r(),t=s(),I=t.ballx,x=t.bally,E=t.velx,w=t.vely;if(u(y=>({...y,ballx:I+E,bally:x+w})),0>x||x+e.ballSize>e.height){const y=t.vely<0?0-t.bally:e.height-(t.bally+e.ballSize);u(m=>({...m,bally:x+2*y,vely:w*-1}))}const d=t.velx<0?o:a;if(((y,m,M,z,v,f,_,W)=>y<v+_&&m<f+W&&v<y+M&&f<m+z)(d.position().x,d.position().y,e.paddleWidth,e.paddleHeight,t.ballx,t.bally,e.ballSize,e.ballSize)){const y=t.velx<0?1:-1,m=(t.bally+e.ballSize-d.position().y)/(e.paddleHeight+e.ballSize),M=(m>.5?-1:1)*y,z=.25*i*(2*m+y)+b,v=Math.abs(z)>.2*i?1.1:1;u(f=>({...f,ballx:d===o?f.playerx+e.paddleWidth:f.aix-e.ballSize,velx:v*-1*f.velx,vely:v*M*f.velx*Math.sin(z)}))}(0>t.ballx+e.ballSize||t.ballx>e.width)&&(n(d.name()),this.serve(d.name()===o.name()?1:-1))},draw(){const o=S();if(!o)return;const a=s();o.beginPath(),o.arc(a.ballx,a.bally,e.ballSize,0,2*Math.PI),o.fill(),o.lineWidth=0,o.strokeStyle="#fff",o.stroke()}}}function G(){const c=()=>this._context,r=this.props,i=this._keystate,S=()=>this.state,e=n=>{this.setState(n)};return{update(){const n=S();let s=n.playery;i[r.upArrow]&&(s=n.playery-r.paddleSpeed),i[r.downArrow]&&(s=n.playery+r.paddleSpeed),s=Math.max(Math.min(s,r.height-r.paddleHeight),0),e(u=>({...u,playery:s}))},draw(){const n=c();if(!n)return;const s=S();n.fillRect(s.playerx,s.playery,r.paddleWidth,r.paddleHeight)},name(){return"player"},position(n){n!==void 0&&e(u=>({...u,playery:n}));const s=S();return{x:s.playerx,y:s.playery}}}}function K(){const c=()=>this._context,r=this.props,i=()=>this.state,S=e=>{this.setState(e)};return{update(){const e=i();let n=e.aiy;const s=e.bally-(r.paddleHeight-r.ballSize)*.5;n=n+(s-n)*.1,S(u=>({...u,aiy:n}))},draw(){const e=c();if(!e)return;const n=i();e.fillRect(n.aix,n.aiy,r.paddleWidth,r.paddleHeight)},name(){return"ai"},position(){const e=i();return{x:e.aix,y:e.aiy}}}}const j=({height:c=600,width:r=700,upArrow:i="ArrowUp",downArrow:S="ArrowDown",paddleHeight:e=100,paddleWidth:n=20,paddleSpeed:s=5,ballSize:u=10})=>{const[b,o]=p.useState({ballx:100,bally:100,ballSpeed:2,velx:0,vely:0,aix:670,aiy:100,playerx:10,playery:100,playerScore:0,aiScore:0}),a=p.useRef(null),t=p.useRef(null),I=p.useRef({}),x=p.useRef(null),E=p.useRef(b),w=p.useRef(null),d=p.useRef(null),k=p.useRef(null);p.useEffect(()=>{E.current=b},[b]);const y={display:"block",position:"absolute",margin:"auto",top:"0",bottom:"0",left:"0",right:"0"},m={height:c,width:r,upArrow:i,downArrow:S,paddleHeight:e,paddleWidth:n,paddleSpeed:s,ballSize:u},M=()=>{a.current&&(t.current=a.current.getContext("2d"))},z=l=>{const g=l==="player"?"ai":"player",A=g+"Score";o(R=>({...R,[A]:R[A]+1})),B(),setTimeout(()=>{t.current&&(t.current.font="30px Arial",t.current.fillStyle="#fff",t.current.fillText(g+" score!",r/2,c/2),t.current.restore())},0),setTimeout(()=>{M(),H()},1e3)},v=()=>({get _context(){return t.current},get state(){return E.current},props:m,_keystate:I.current,setState:l=>{o(l)},_score:z});d.current||(d.current=G.call(v())),k.current||(k.current=K.call(v())),w.current||(w.current=L.call(v(),()=>d.current,()=>k.current));const f=w.current,_=d.current,W=k.current,U=()=>{if(!t.current)return;const l=t.current;l.fillStyle="#000",l.fillRect(0,0,r,c),l.save(),l.fillStyle="#fff",l.font="10px Arial",l.fillText("Player: "+String(b.playerScore),10,10),l.fillText("CPU: "+String(b.aiScore),500,10),f.draw(),_.draw(),W.draw();const g=4,A=(r-g)*.5;let R=0;const C=c/20;for(;R<c;)l.fillRect(A,R+C*.25,g,C*.5),R+=C;l.restore()},q=()=>{_.update(),W.update(),f.update()},B=()=>{x.current!==null&&(clearInterval(x.current),x.current=null),setTimeout(()=>{t.current&&a.current&&t.current.clearRect(0,0,a.current.width,a.current.height)},0)},H=()=>{if(x.current)return;const l=I.current,g=T=>{l[T.code]=!0},A=T=>{l[T.code]=!1},R=T=>{T.preventDefault()},C=T=>{T.preventDefault()};document.addEventListener("keydown",g),document.addEventListener("keyup",A),document.addEventListener("touchstart",R,!1),document.addEventListener("touchmove",C,!1),x.current=window.setInterval(()=>{q(),U()},1),f.serve(1)},D=l=>{if(a.current){const g=l.touches[0].pageY-a.current.offsetTop-e/2;_.position(g)}};return p.useEffect(()=>{M(),t.current&&(t.current.font="30px Arial",t.current.fillText("Starting Game",r/2,c/2));const l=setTimeout(H,1e3);return()=>{clearTimeout(l),B()}},[]),P.jsx("canvas",{ref:a,onTouchStart:D,onTouchMove:D,style:y,width:r,height:c})};h.Pong=j,h.default=j,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexium216/react-pong",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "A React 18 ping pong game component built with TypeScript",
5
5
  "main": "./dist/react-pong.umd.js",
6
6
  "module": "./dist/react-pong.es.js",