speakid-build-a-sentence 1.0.23 → 1.0.24
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,5 +1,5 @@
|
|
|
1
1
|
import { jsx as a, jsxs as x } from "react/jsx-runtime";
|
|
2
|
-
import { useState as l, useCallback as ge, useRef as
|
|
2
|
+
import { useState as l, useCallback as ge, useRef as oe, useEffect as Y, useMemo as sn, Component as dn } from "react";
|
|
3
3
|
const an = `
|
|
4
4
|
@keyframes spin {
|
|
5
5
|
from { transform: rotate(0deg); }
|
|
@@ -254,7 +254,7 @@ const Te = {
|
|
|
254
254
|
s && s.remove(), document.head.appendChild(u);
|
|
255
255
|
}, gn = (u) => [...u].sort(() => Math.random() - 0.5);
|
|
256
256
|
function yn(u = {}) {
|
|
257
|
-
const { logoUrl: s, showLogo: W = !0 } = u, se =
|
|
257
|
+
const { logoUrl: s, showLogo: W = !0 } = u, se = oe(null), { validateAllSentences: de, errors: H } = ln(), I = () => d || window.innerWidth < 768, f = () => d || window.innerWidth < 768 || window.innerWidth >= 320 && window.innerWidth <= 932 && window.innerHeight >= 390 && window.innerHeight <= 932, y = (e = "medium") => {
|
|
258
258
|
if (!f())
|
|
259
259
|
return {
|
|
260
260
|
padding: "12px 24px",
|
|
@@ -289,17 +289,17 @@ function yn(u = {}) {
|
|
|
289
289
|
}), []);
|
|
290
290
|
const [b, S] = l("select"), [C, K] = l(null), [ue, we] = l(null), [T, Z] = l([]), [D, fe] = l(0), [ae, me] = l([]), [k, le] = l([]), [q, xe] = l(20), [V, L] = l(0), [un, ye] = l(null), [M, z] = l(null), [c, _] = l(!1), [be, ce] = l(!1), [he, De] = l(
|
|
291
291
|
Number(localStorage.getItem("magicSentenceBest")) || 0
|
|
292
|
-
), U =
|
|
292
|
+
), U = oe(null), Re = oe(null), Se = oe(0), [m, E] = l({ list: null, id: null, side: null }), [d, ze] = l(!1), [Ee, Q] = l(1), [We, ee] = l(null), [Pe, Be] = l(!1), [A, Le] = l(!1), [$, Me] = l(!1), [O, Ae] = l(!1), [N, $e] = l(!1), [G, Oe] = l(!1), [X, Ne] = l(!1), [j, Ge] = l(!1), [F, Xe] = l(!1), [wn, je] = l(!1), [fn, Fe] = l(!1);
|
|
293
293
|
Y(() => {
|
|
294
294
|
const e = () => {
|
|
295
|
-
const t = window.innerWidth, n = window.innerHeight, i = t < 768 || t === 926 && n === 428 || t === 932 && n === 430,
|
|
296
|
-
Be(Ce), Le(w), Me(
|
|
297
|
-
const
|
|
295
|
+
const t = window.innerWidth, n = window.innerHeight, i = t < 768 || t === 926 && n === 428 || t === 932 && n === 430, r = n < 700, p = t / n > 1.8, w = t === 768 && n === 1024, o = t === 1024 && n === 768, h = t === 820 && n === 1180, R = t === 1180 && n === 820, v = t === 540 && n === 720, re = t === 720 && n === 540, He = t === 1024 && n === 1366, Ie = t === 1366 && n === 1024, Ce = t >= 1200 && n >= 600 && !i;
|
|
296
|
+
Be(Ce), Le(w), Me(o), Ae(h), $e(R), Oe(v), Ne(re), Ge(He), Xe(Ie), Fe(p);
|
|
297
|
+
const on = i && t > n || i || // ✅ ВСЕ мобильные устройства (включая portrait)
|
|
298
298
|
n < 700 || p || // ✅ Широкие экраны
|
|
299
|
-
t === 1366 && n === 766 || t === 1366 && n === 768 || t === 1280 && n === 720 || t === 1440 && n === 900 || w ||
|
|
300
|
-
if (je(
|
|
299
|
+
t === 1366 && n === 766 || t === 1366 && n === 768 || t === 1280 && n === 720 || t === 1440 && n === 900 || w || o || h || R || v || re || He || Ie || Ce;
|
|
300
|
+
if (je(on), ze(i), i)
|
|
301
301
|
ee(null), Q(1);
|
|
302
|
-
else if (
|
|
302
|
+
else if (r)
|
|
303
303
|
ee(null), Q(1);
|
|
304
304
|
else if (p) {
|
|
305
305
|
const pe = Math.min(1e3, Math.min(t, n) * 0.9);
|
|
@@ -313,28 +313,28 @@ function yn(u = {}) {
|
|
|
313
313
|
}, []);
|
|
314
314
|
const ne = (e, t, n, i) => {
|
|
315
315
|
if (c) return;
|
|
316
|
-
let
|
|
317
|
-
const w = e === "bank" ?
|
|
316
|
+
let r = [...ae], p = [...k];
|
|
317
|
+
const w = e === "bank" ? r : p, o = t === "bank" ? r : p, h = w.findIndex((re) => re.id === n);
|
|
318
318
|
if (h === -1) return;
|
|
319
319
|
const [R] = w.splice(h, 1);
|
|
320
320
|
let v = i;
|
|
321
|
-
e === t && v !== null && v !== void 0 && v > h && (v = v - 1), v == null || v < 0 || v >
|
|
321
|
+
e === t && v !== null && v !== void 0 && v > h && (v = v - 1), v == null || v < 0 || v > o.length ? o.push(R) : o.splice(v, 0, R), e === "bank" ? r = w : p = w, t === "bank" ? r = o : p = o, me(r), le(p);
|
|
322
322
|
}, J = (e, t, n) => {
|
|
323
323
|
if (e.preventDefault(), c) {
|
|
324
324
|
E({ list: null, id: null, side: null });
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const i = e.dataTransfer.getData("application/x-token") || (() => {
|
|
328
|
-
const
|
|
329
|
-
if (!
|
|
330
|
-
const p = ae.some((h) => h.id ===
|
|
331
|
-
return
|
|
328
|
+
const r = e.dataTransfer.getData("text/plain");
|
|
329
|
+
if (!r) return "";
|
|
330
|
+
const p = ae.some((h) => h.id === r), w = k.some((h) => h.id === r), o = p ? "bank" : w ? "selected" : null;
|
|
331
|
+
return o ? JSON.stringify({ from: o, id: r }) : "";
|
|
332
332
|
})();
|
|
333
333
|
if (i) {
|
|
334
334
|
try {
|
|
335
|
-
const
|
|
336
|
-
if (!
|
|
337
|
-
ne(
|
|
335
|
+
const r = JSON.parse(i);
|
|
336
|
+
if (!r || !r.id || !r.from) return;
|
|
337
|
+
ne(r.from, t, r.id, n);
|
|
338
338
|
} catch {
|
|
339
339
|
}
|
|
340
340
|
E({ list: null, id: null, side: null });
|
|
@@ -348,8 +348,8 @@ function yn(u = {}) {
|
|
|
348
348
|
return;
|
|
349
349
|
const i = [...T];
|
|
350
350
|
i[e] = t, Z(i);
|
|
351
|
-
const
|
|
352
|
-
|
|
351
|
+
const r = de(i);
|
|
352
|
+
r.isValid || console.warn("Validation errors:", r.errors);
|
|
353
353
|
}, Je = (e) => e.trim().replace(/\s+/g, " "), ke = (e) => e <= 3 ? 20 : e <= 5 ? 18 : e <= 7 ? 16 : e <= 9 ? 14 : 12, Ye = () => {
|
|
354
354
|
T.some((t) => t.trim().length === 0) || (Z((t) => t.map((n) => Je(n))), L(0), fe(0), Se.current = 0, ye(null), S("getready"));
|
|
355
355
|
};
|
|
@@ -364,9 +364,9 @@ function yn(u = {}) {
|
|
|
364
364
|
if (!t) return;
|
|
365
365
|
const i = gn(
|
|
366
366
|
t.trim().split(/\s+/).filter(Boolean)
|
|
367
|
-
).map((
|
|
367
|
+
).map((r, p) => ({
|
|
368
368
|
id: `${Date.now()}-${e}-${p}-${Math.random().toString(36).slice(2)}`,
|
|
369
|
-
text:
|
|
369
|
+
text: r
|
|
370
370
|
}));
|
|
371
371
|
me(i), le([]), fe(e), Se.current = e, xe(ue || 20), z(null), _(!1), ce(!1), S("play");
|
|
372
372
|
};
|
|
@@ -381,8 +381,8 @@ function yn(u = {}) {
|
|
|
381
381
|
z(null);
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
const t = e.trim().split(/\s+/), n = k.map((
|
|
385
|
-
w === 0 ? (z("correct"), be || (ce(!0), L((
|
|
384
|
+
const t = e.trim().split(/\s+/), n = k.map((o) => o.text), i = t.filter((o) => !n.includes(o)).length, r = n.filter((o) => !t.includes(o)).length, p = t.filter((o, h) => n.includes(o) ? n[h] !== o : !1).length, w = i + r + p;
|
|
385
|
+
w === 0 ? (z("correct"), be || (ce(!0), L((o) => o + 1)), P("correct"), B("Correct! Well done!")) : w === 1 ? (z("almost"), L((o) => o + 0.5), P("half"), B("Almost correct! Just one mistake.")) : (z("wrong"), P("wrong"), B("Not quite right. Keep trying!"));
|
|
386
386
|
}
|
|
387
387
|
return () => {
|
|
388
388
|
U.current !== null && window.clearTimeout(U.current);
|
|
@@ -399,8 +399,8 @@ function yn(u = {}) {
|
|
|
399
399
|
D + 1 < (C || 0) ? te(D + 1) : (S("results"), setTimeout(() => ie(), 600));
|
|
400
400
|
return;
|
|
401
401
|
}
|
|
402
|
-
const n = t.trim().split(/\s+/), i = k.map((h) => h.text),
|
|
403
|
-
|
|
402
|
+
const n = t.trim().split(/\s+/), i = k.map((h) => h.text), r = n.filter((h) => !i.includes(h)).length, p = i.filter((h) => !n.includes(h)).length, w = n.filter((h, R) => i.includes(h) ? i[R] !== h : !1).length, o = r + p + w;
|
|
403
|
+
o === 0 ? (L((h) => h + 1), z("correct"), ce(!0), P("correct"), B("Correct! Well done!")) : o === 1 ? (L((h) => h + 0.5), z("almost"), P("half"), B("Almost correct! Just one mistake.")) : (z("wrong"), P("wrong"), B("Not quite right. Keep trying!")), D + 1 < (C || 0) ? setTimeout(() => te(D + 1), 800) : setTimeout(() => {
|
|
404
404
|
S("results"), setTimeout(() => ie(), 600);
|
|
405
405
|
}, 800);
|
|
406
406
|
}
|
|
@@ -429,7 +429,7 @@ function yn(u = {}) {
|
|
|
429
429
|
}
|
|
430
430
|
i.gain.setValueAtTime(0.1, t.currentTime), n.start(), n.stop(t.currentTime + 0.2);
|
|
431
431
|
}, ie = () => {
|
|
432
|
-
const t = Date.now() + 2500, n = ["#ec4c44", "#f7c948", "#6fcf97", "#56ccf2", "#bb6bd9"], i = document.createElement("canvas"),
|
|
432
|
+
const t = Date.now() + 2500, n = ["#ec4c44", "#f7c948", "#6fcf97", "#56ccf2", "#bb6bd9"], i = document.createElement("canvas"), r = i.getContext("2d");
|
|
433
433
|
i.width = window.innerWidth, i.height = window.innerHeight, i.style.position = "fixed", i.style.top = "0", i.style.left = "0", i.style.pointerEvents = "none", document.body.appendChild(i);
|
|
434
434
|
const p = Array.from({ length: 100 }).map(() => ({
|
|
435
435
|
x: Math.random() * i.width,
|
|
@@ -439,8 +439,8 @@ function yn(u = {}) {
|
|
|
439
439
|
speed: 2 + Math.random() * 4,
|
|
440
440
|
tilt: Math.random() * 2 * Math.PI
|
|
441
441
|
})), w = () => {
|
|
442
|
-
|
|
443
|
-
|
|
442
|
+
r.clearRect(0, 0, i.width, i.height), p.forEach((o) => {
|
|
443
|
+
r.fillStyle = o.color, r.beginPath(), r.ellipse(o.x, o.y, o.size, o.size / 2, o.tilt, 0, 2 * Math.PI), r.fill(), o.y += o.speed, o.x += Math.sin(o.tilt);
|
|
444
444
|
}), Date.now() < t ? requestAnimationFrame(w) : document.body.removeChild(i);
|
|
445
445
|
};
|
|
446
446
|
w();
|
|
@@ -619,13 +619,13 @@ function yn(u = {}) {
|
|
|
619
619
|
},
|
|
620
620
|
onDragOver: (n) => n.preventDefault(),
|
|
621
621
|
onDrop: (n) => {
|
|
622
|
-
const i = n.currentTarget.getBoundingClientRect(),
|
|
622
|
+
const i = n.currentTarget.getBoundingClientRect(), r = i.left + i.width / 2, p = n.clientX > r ? t + 1 : t;
|
|
623
623
|
E({ list: null, id: null, side: null }), n.stopPropagation(), J(n, "bank", p);
|
|
624
624
|
},
|
|
625
625
|
onDragEnter: (n) => {
|
|
626
626
|
if (c) return;
|
|
627
|
-
const i = n.currentTarget.getBoundingClientRect(),
|
|
628
|
-
E({ list: "bank", id: e.id, side: n.clientX >
|
|
627
|
+
const i = n.currentTarget.getBoundingClientRect(), r = i.left + i.width / 2;
|
|
628
|
+
E({ list: "bank", id: e.id, side: n.clientX > r ? "right" : "left" });
|
|
629
629
|
},
|
|
630
630
|
onDragLeave: () => E({ list: null, id: null, side: null }),
|
|
631
631
|
onClick: () => {
|
|
@@ -665,10 +665,10 @@ function yn(u = {}) {
|
|
|
665
665
|
J(e, "selected", 0);
|
|
666
666
|
return;
|
|
667
667
|
}
|
|
668
|
-
let i = k.length,
|
|
668
|
+
let i = k.length, r = 1 / 0;
|
|
669
669
|
n.forEach((p, w) => {
|
|
670
|
-
const
|
|
671
|
-
R <
|
|
670
|
+
const o = p.getBoundingClientRect(), h = o.left + o.width / 2, R = Math.abs(e.clientX - h);
|
|
671
|
+
R < r && (r = R, i = e.clientX < h ? w : w + 1);
|
|
672
672
|
}), e.clientX > t.right - 30 && (i = k.length), e.clientX < t.left + 30 && (i = 0), J(e, "selected", i);
|
|
673
673
|
},
|
|
674
674
|
style: {
|
|
@@ -707,13 +707,13 @@ function yn(u = {}) {
|
|
|
707
707
|
},
|
|
708
708
|
onDragOver: (n) => n.preventDefault(),
|
|
709
709
|
onDrop: (n) => {
|
|
710
|
-
const i = n.currentTarget.getBoundingClientRect(),
|
|
710
|
+
const i = n.currentTarget.getBoundingClientRect(), r = i.left + i.width / 2, p = i.width * 0.25, w = n.clientX < r - p ? t : n.clientX > r + p || n.clientX > r ? t + 1 : t;
|
|
711
711
|
E({ list: null, id: null, side: null }), n.stopPropagation(), J(n, "selected", w);
|
|
712
712
|
},
|
|
713
713
|
onDragEnter: (n) => {
|
|
714
714
|
if (c) return;
|
|
715
|
-
const i = n.currentTarget.getBoundingClientRect(),
|
|
716
|
-
E({ list: "selected", id: e.id, side: n.clientX >
|
|
715
|
+
const i = n.currentTarget.getBoundingClientRect(), r = i.left + i.width / 2;
|
|
716
|
+
E({ list: "selected", id: e.id, side: n.clientX > r ? "right" : "left" });
|
|
717
717
|
},
|
|
718
718
|
onDragLeave: () => E({ list: null, id: null, side: null }),
|
|
719
719
|
onClick: () => {
|
|
@@ -829,7 +829,7 @@ function yn(u = {}) {
|
|
|
829
829
|
}
|
|
830
830
|
)
|
|
831
831
|
] })
|
|
832
|
-
] }), ve = !d && W,
|
|
832
|
+
] }), ve = !d && W, rn = sn(
|
|
833
833
|
() => {
|
|
834
834
|
if (d && window.innerWidth > window.innerHeight || window.innerHeight < 700 || !ve)
|
|
835
835
|
return null;
|
|
@@ -908,7 +908,7 @@ function yn(u = {}) {
|
|
|
908
908
|
alignItems: "center"
|
|
909
909
|
},
|
|
910
910
|
children: /* @__PURE__ */ x("div", { id: "magic-sentence-root", children: [
|
|
911
|
-
|
|
911
|
+
rn,
|
|
912
912
|
b === "select" ? Ze() : null,
|
|
913
913
|
b === "time" ? _e() : null,
|
|
914
914
|
b === "type" ? Qe() : null,
|