cos-design 3.8.0 → 3.8.1
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.
- package/CHANGELOG.md +19 -0
- package/dist/index.cjs +2 -2
- package/dist/index.js +118 -103
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2887,24 +2887,29 @@ var Pe = {
|
|
|
2887
2887
|
for (; t.length < 9;) t.push({ label: `奖品 ${t.length + 1}` });
|
|
2888
2888
|
return t.slice(0, 9);
|
|
2889
2889
|
}, Nt = t(({ items: e = jt, targetIndex: t, buttonText: i = "开始抽奖", spinningText: o = "抽奖中…", onDrawEnd: l, disabled: f = !1 }, p) => {
|
|
2890
|
-
let m = Mt(e), [h, g] = c(null), [_, v] = c(null), [y, b] = c(!1), x = s([]),
|
|
2890
|
+
let m = Mt(e), [h, g] = c(null), [_, v] = c(null), [y, b] = c(!1), x = s([]), C = s(l), w = s(t);
|
|
2891
2891
|
r(() => {
|
|
2892
|
-
|
|
2892
|
+
C.current = l;
|
|
2893
2893
|
}, [l]), r(() => {
|
|
2894
|
-
|
|
2894
|
+
w.current = t;
|
|
2895
2895
|
}, [t]);
|
|
2896
|
-
let
|
|
2896
|
+
let T = n(() => {
|
|
2897
2897
|
x.current.forEach((e) => window.clearTimeout(e)), x.current = [];
|
|
2898
2898
|
}, []);
|
|
2899
|
-
r(() =>
|
|
2900
|
-
let
|
|
2901
|
-
|
|
2902
|
-
}, [
|
|
2899
|
+
r(() => T, [T]);
|
|
2900
|
+
let E = n(() => {
|
|
2901
|
+
T(), b(!1), g(null), v(null);
|
|
2902
|
+
}, [T]), D = n((e) => {
|
|
2903
2903
|
if (y || f) return;
|
|
2904
|
-
|
|
2905
|
-
let t = ((typeof e == "number" ? e : typeof
|
|
2904
|
+
T(), v(null), b(!0);
|
|
2905
|
+
let t = ((typeof e == "number" ? e : typeof w.current == "number" ? w.current : Math.floor(Math.random() * 9)) % 9 + 9) % 9;
|
|
2906
|
+
if (S()) {
|
|
2907
|
+
g(t), v(t), b(!1), C.current?.(m[t], t);
|
|
2908
|
+
return;
|
|
2909
|
+
}
|
|
2910
|
+
let n = 18 + t, r = 0, i = () => {
|
|
2906
2911
|
if (g(r % 9), r += 1, r > n) {
|
|
2907
|
-
g(t), v(t), b(!1),
|
|
2912
|
+
g(t), v(t), b(!1), C.current?.(m[t], t);
|
|
2908
2913
|
return;
|
|
2909
2914
|
}
|
|
2910
2915
|
let e = 60 + Math.floor(r * 12);
|
|
@@ -2913,14 +2918,14 @@ var Pe = {
|
|
|
2913
2918
|
i();
|
|
2914
2919
|
}, [
|
|
2915
2920
|
m,
|
|
2916
|
-
|
|
2921
|
+
T,
|
|
2917
2922
|
f,
|
|
2918
2923
|
y
|
|
2919
2924
|
]);
|
|
2920
2925
|
return a(p, () => ({
|
|
2921
|
-
draw:
|
|
2922
|
-
reset:
|
|
2923
|
-
}), [
|
|
2926
|
+
draw: D,
|
|
2927
|
+
reset: E
|
|
2928
|
+
}), [D, E]), /* @__PURE__ */ d("div", {
|
|
2924
2929
|
className: At.nineGrid,
|
|
2925
2930
|
children: [/* @__PURE__ */ u("div", {
|
|
2926
2931
|
className: At.board,
|
|
@@ -2944,7 +2949,7 @@ var Pe = {
|
|
|
2944
2949
|
type: "button",
|
|
2945
2950
|
className: At.button,
|
|
2946
2951
|
"data-testid": "nine-grid-draw",
|
|
2947
|
-
onClick: () =>
|
|
2952
|
+
onClick: () => D(),
|
|
2948
2953
|
disabled: y || f,
|
|
2949
2954
|
"aria-busy": y,
|
|
2950
2955
|
children: y ? o : i
|
|
@@ -11457,6 +11462,8 @@ var Wl = {
|
|
|
11457
11462
|
width: f,
|
|
11458
11463
|
height: p
|
|
11459
11464
|
},
|
|
11465
|
+
"aria-label": i,
|
|
11466
|
+
"data-testid": "scratch-card-canvas",
|
|
11460
11467
|
onMouseDown: O,
|
|
11461
11468
|
onMouseMove: k,
|
|
11462
11469
|
onMouseUp: A,
|
|
@@ -11497,59 +11504,62 @@ var yu = {
|
|
|
11497
11504
|
0,
|
|
11498
11505
|
0,
|
|
11499
11506
|
0
|
|
11500
|
-
]), [
|
|
11507
|
+
]), [C, w] = c([]), T = s(0), E = s(!1), D = s(b), O = s(o), k = s(e), A = s(i), j = s(null);
|
|
11501
11508
|
r(() => {
|
|
11502
|
-
|
|
11509
|
+
O.current = o;
|
|
11503
11510
|
}, [o]), r(() => {
|
|
11504
|
-
|
|
11511
|
+
k.current = e;
|
|
11505
11512
|
}, [e]), r(() => {
|
|
11506
|
-
|
|
11513
|
+
A.current = i;
|
|
11507
11514
|
}, [i]), r(() => {
|
|
11508
|
-
|
|
11515
|
+
E.current = v;
|
|
11509
11516
|
}, [v]), r(() => {
|
|
11510
|
-
|
|
11517
|
+
D.current = b;
|
|
11511
11518
|
}, [b]);
|
|
11512
|
-
let
|
|
11519
|
+
let M = e.length * 80, N = Math.floor(xu / 2) * M, P = n(() => {
|
|
11513
11520
|
let t = [];
|
|
11514
11521
|
for (let n = 0; n < xu; n++) t.push(...e);
|
|
11515
11522
|
return t;
|
|
11516
|
-
}, [e])(),
|
|
11517
|
-
let n =
|
|
11518
|
-
if (
|
|
11519
|
-
y(!0),
|
|
11520
|
-
let r = e ??
|
|
11523
|
+
}, [e])(), F = (e, t) => -(e - 1 + t * k.current.length) * 80, I = n((e) => {
|
|
11524
|
+
let n = k.current;
|
|
11525
|
+
if (E.current || n.length === 0) return;
|
|
11526
|
+
y(!0), w([]);
|
|
11527
|
+
let r = e ?? A.current, i = [
|
|
11521
11528
|
0,
|
|
11522
11529
|
1,
|
|
11523
11530
|
2
|
|
11524
|
-
].map((e) => Tu(n, r?.[e])), a = [...
|
|
11525
|
-
let n = a[t], r = Su * o, i = Math.ceil((-n + r) / o) + 1, s =
|
|
11526
|
-
for (; n - s < r;) i += 1, s =
|
|
11531
|
+
].map((e) => Tu(n, r?.[e])), a = [...D.current], o = n.length * 80, s = i.map((e, t) => {
|
|
11532
|
+
let n = a[t], r = Su * o, i = Math.ceil((-n + r) / o) + 1, s = F(e, i);
|
|
11533
|
+
for (; n - s < r;) i += 1, s = F(e, i);
|
|
11527
11534
|
return s;
|
|
11528
11535
|
}), c = Math.max(t, 16), l = performance.now(), u = { cancelled: !1 };
|
|
11529
|
-
|
|
11530
|
-
let d = (
|
|
11531
|
-
if (
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11536
|
+
j.current = u;
|
|
11537
|
+
let d = () => {
|
|
11538
|
+
if (u.cancelled) return;
|
|
11539
|
+
let e = i.map((e) => n[e]);
|
|
11540
|
+
x(i.map((e) => F(e, Math.round(N / o)))), w(e), y(!1), O.current?.(e);
|
|
11541
|
+
};
|
|
11542
|
+
if (S()) {
|
|
11543
|
+
d();
|
|
11544
|
+
return;
|
|
11545
|
+
}
|
|
11546
|
+
let f = (e) => {
|
|
11547
|
+
u.cancelled || (x(a.map((t, n) => {
|
|
11548
|
+
let r = e - l - Cu[n];
|
|
11549
|
+
if (r < 0) return t;
|
|
11550
|
+
let i = wu(Math.min(r / c, 1));
|
|
11551
|
+
return t + (s[n] - t) * i;
|
|
11552
|
+
})), Cu.every((t) => e - l - t >= c) ? d() : T.current = requestAnimationFrame(f));
|
|
11553
|
+
};
|
|
11554
|
+
T.current = requestAnimationFrame(f);
|
|
11555
|
+
}, [N, t]), L = n(() => {
|
|
11556
|
+
E.current || w([]);
|
|
11547
11557
|
}, []);
|
|
11548
11558
|
return a(g, () => ({
|
|
11549
|
-
spin:
|
|
11550
|
-
reset:
|
|
11551
|
-
}), [
|
|
11552
|
-
|
|
11559
|
+
spin: I,
|
|
11560
|
+
reset: L
|
|
11561
|
+
}), [I, L]), r(() => () => {
|
|
11562
|
+
j.current && (j.current.cancelled = !0), cancelAnimationFrame(T.current);
|
|
11553
11563
|
}, []), /* @__PURE__ */ d("div", {
|
|
11554
11564
|
className: yu.slotMachine,
|
|
11555
11565
|
children: [
|
|
@@ -11565,7 +11575,7 @@ var yu = {
|
|
|
11565
11575
|
children: [/* @__PURE__ */ u("div", {
|
|
11566
11576
|
className: yu.strip,
|
|
11567
11577
|
style: { transform: `translateY(${b[e]}px)` },
|
|
11568
|
-
children:
|
|
11578
|
+
children: P.map((e, t) => /* @__PURE__ */ u("div", {
|
|
11569
11579
|
className: yu.item,
|
|
11570
11580
|
style: { height: 80 },
|
|
11571
11581
|
children: e
|
|
@@ -11577,14 +11587,14 @@ var yu = {
|
|
|
11577
11587
|
type: "button",
|
|
11578
11588
|
className: yu.spinBtn,
|
|
11579
11589
|
"data-testid": "slot-machine-spin",
|
|
11580
|
-
onClick: () =>
|
|
11590
|
+
onClick: () => I(),
|
|
11581
11591
|
disabled: v,
|
|
11582
11592
|
"aria-busy": v,
|
|
11583
11593
|
children: v ? p : _
|
|
11584
11594
|
}),
|
|
11585
|
-
|
|
11595
|
+
C.length > 0 && !v && /* @__PURE__ */ u("p", {
|
|
11586
11596
|
className: yu.result,
|
|
11587
|
-
children:
|
|
11597
|
+
children: C[0] === C[1] && C[1] === C[2] ? m : `${h} ${C.join(" ")}`
|
|
11588
11598
|
})
|
|
11589
11599
|
]
|
|
11590
11600
|
});
|
|
@@ -12024,24 +12034,24 @@ var Du = {
|
|
|
12024
12034
|
{ label: "优惠券" },
|
|
12025
12035
|
{ label: "再来一次" }
|
|
12026
12036
|
], Wu = (e) => 1 - (1 - e) ** 3, Gu = t(({ prizes: e = Uu, size: t = 360, spinDuration: i = 4e3, spinRounds: o = 5, targetIndex: l, buttonText: f = "开始抽奖", spinningText: p = "抽奖中...", resultPrefix: m = "恭喜获得:", onSpinEnd: h }, g) => {
|
|
12027
|
-
let _ = s(null), v = s(0), y = s(0), b = s(1), x = s(!1), [
|
|
12037
|
+
let _ = s(null), v = s(0), y = s(0), b = s(1), x = s(!1), [C, w] = c(!1), [T, E] = c(null), D = s(h), O = s(e), k = s(l), A = s(null);
|
|
12028
12038
|
r(() => {
|
|
12029
|
-
|
|
12039
|
+
D.current = h;
|
|
12030
12040
|
}, [h]), r(() => {
|
|
12031
|
-
|
|
12041
|
+
O.current = e;
|
|
12032
12042
|
}, [e]), r(() => {
|
|
12033
|
-
|
|
12043
|
+
k.current = l;
|
|
12034
12044
|
}, [l]), r(() => {
|
|
12035
|
-
x.current =
|
|
12036
|
-
}, [
|
|
12037
|
-
let
|
|
12045
|
+
x.current = C;
|
|
12046
|
+
}, [C]);
|
|
12047
|
+
let j = t + 48, M = (e, t) => t.color ?? Hu[e % Hu.length], N = n((e) => {
|
|
12038
12048
|
let n = _.current;
|
|
12039
12049
|
if (!n) return;
|
|
12040
12050
|
let r = n.getContext("2d");
|
|
12041
12051
|
if (!r) return;
|
|
12042
|
-
let i =
|
|
12043
|
-
r.clearRect(0, 0,
|
|
12044
|
-
let i = n * s - Math.PI / 2, a = i + s, c =
|
|
12052
|
+
let i = O.current, a = j / 2, o = t / 2, s = Math.PI * 2 / i.length;
|
|
12053
|
+
r.clearRect(0, 0, j, j), r.save(), r.translate(a, a), r.rotate(e), i.forEach((e, n) => {
|
|
12054
|
+
let i = n * s - Math.PI / 2, a = i + s, c = M(n, e);
|
|
12045
12055
|
r.beginPath(), r.moveTo(0, 0), r.arc(0, 0, o, i, a), r.closePath(), r.fillStyle = c, r.fill(), r.strokeStyle = "rgb(255 255 255 / 35%)", r.lineWidth = 2, r.stroke(), r.save(), r.rotate(i + s / 2), r.textAlign = "right", r.fillStyle = "#fff", r.font = `bold ${Math.max(12, Math.floor(t / 22))}px system-ui, sans-serif`, r.shadowColor = "rgb(0 0 0 / 30%)", r.shadowBlur = 4, r.fillText(e.label, o - 18, 6), r.restore();
|
|
12046
12056
|
}), r.beginPath(), r.arc(0, 0, o, 0, Math.PI * 2), r.strokeStyle = "#fbbf24", r.lineWidth = 6, r.stroke(), r.beginPath(), r.arc(0, 0, o - 4, 0, Math.PI * 2), r.strokeStyle = "#f59e0b", r.lineWidth = 2, r.stroke(), r.restore(), r.save(), r.translate(a, a);
|
|
12047
12057
|
for (let e = 0; e < 12; e++) {
|
|
@@ -12049,58 +12059,63 @@ var Du = {
|
|
|
12049
12059
|
r.beginPath(), r.arc(n, i, 3, 0, Math.PI * 2), r.fillStyle = e % 2 == 0 ? "#fde68a" : "#f59e0b", r.fill();
|
|
12050
12060
|
}
|
|
12051
12061
|
r.restore();
|
|
12052
|
-
}, [
|
|
12062
|
+
}, [j, t]);
|
|
12053
12063
|
r(() => {
|
|
12054
12064
|
let e = _.current;
|
|
12055
12065
|
if (!e) return;
|
|
12056
12066
|
let t = window.devicePixelRatio || 1;
|
|
12057
|
-
b.current = t, e.width =
|
|
12067
|
+
b.current = t, e.width = j * t, e.height = j * t;
|
|
12058
12068
|
let n = e.getContext("2d");
|
|
12059
|
-
n && n.setTransform(t, 0, 0, t, 0, 0),
|
|
12069
|
+
n && n.setTransform(t, 0, 0, t, 0, 0), N(v.current);
|
|
12060
12070
|
}, [
|
|
12061
|
-
|
|
12062
|
-
|
|
12071
|
+
j,
|
|
12072
|
+
N,
|
|
12063
12073
|
e
|
|
12064
12074
|
]), r(() => () => {
|
|
12065
|
-
|
|
12075
|
+
A.current && (A.current.cancelled = !0), y.current && cancelAnimationFrame(y.current);
|
|
12066
12076
|
}, []);
|
|
12067
|
-
let
|
|
12068
|
-
let t =
|
|
12077
|
+
let P = n((e) => {
|
|
12078
|
+
let t = O.current;
|
|
12069
12079
|
if (x.current || t.length === 0) return;
|
|
12070
|
-
|
|
12071
|
-
let n = Math.PI * 2 / t.length, r =
|
|
12072
|
-
|
|
12080
|
+
w(!0), E(null);
|
|
12081
|
+
let n = Math.PI * 2 / t.length, r = k.current, a = e ?? r, s = a === void 0 ? Math.floor(Math.random() * t.length) : (Math.floor(a) % t.length + t.length) % t.length, c = s * n + n / 2, l = v.current, u = l + o * Math.PI * 2 + (Math.PI * 2 - c) - l % (Math.PI * 2), d = l, f = performance.now(), p = { cancelled: !1 };
|
|
12082
|
+
A.current = p;
|
|
12073
12083
|
let m = (e) => {
|
|
12074
12084
|
if (p.cancelled) return;
|
|
12075
|
-
let n =
|
|
12076
|
-
|
|
12077
|
-
else if (!p.cancelled) {
|
|
12078
|
-
let e = t[s];
|
|
12079
|
-
v.current = o, C(!1), T(e), E.current?.(e, s);
|
|
12080
|
-
}
|
|
12085
|
+
let n = t[s];
|
|
12086
|
+
v.current = e, N(e), w(!1), E(n), D.current?.(n, s);
|
|
12081
12087
|
};
|
|
12082
|
-
|
|
12088
|
+
if (S()) {
|
|
12089
|
+
m(u);
|
|
12090
|
+
return;
|
|
12091
|
+
}
|
|
12092
|
+
let h = (e) => {
|
|
12093
|
+
if (p.cancelled) return;
|
|
12094
|
+
let t = e - f, n = Math.min(t / i, 1), r = Wu(n), a = d + (u - d) * r;
|
|
12095
|
+
v.current = a, N(a), n < 1 ? y.current = requestAnimationFrame(h) : m(a);
|
|
12096
|
+
};
|
|
12097
|
+
y.current = requestAnimationFrame(h);
|
|
12083
12098
|
}, [
|
|
12084
|
-
|
|
12099
|
+
N,
|
|
12085
12100
|
i,
|
|
12086
12101
|
o
|
|
12087
|
-
]),
|
|
12088
|
-
x.current ||
|
|
12102
|
+
]), F = n(() => {
|
|
12103
|
+
x.current || E(null);
|
|
12089
12104
|
}, []);
|
|
12090
12105
|
return a(g, () => ({
|
|
12091
|
-
spin:
|
|
12092
|
-
reset:
|
|
12093
|
-
}), [
|
|
12106
|
+
spin: P,
|
|
12107
|
+
reset: F
|
|
12108
|
+
}), [P, F]), /* @__PURE__ */ d("div", {
|
|
12094
12109
|
className: Vu.turntable,
|
|
12095
12110
|
style: {
|
|
12096
|
-
width:
|
|
12097
|
-
height:
|
|
12111
|
+
width: j,
|
|
12112
|
+
height: j + 80
|
|
12098
12113
|
},
|
|
12099
12114
|
children: [/* @__PURE__ */ d("div", {
|
|
12100
12115
|
className: Vu.wheelWrap,
|
|
12101
12116
|
style: {
|
|
12102
|
-
width:
|
|
12103
|
-
height:
|
|
12117
|
+
width: j,
|
|
12118
|
+
height: j
|
|
12104
12119
|
},
|
|
12105
12120
|
children: [
|
|
12106
12121
|
/* @__PURE__ */ u("div", { className: Vu.pointer }),
|
|
@@ -12108,23 +12123,23 @@ var Du = {
|
|
|
12108
12123
|
ref: _,
|
|
12109
12124
|
className: Vu.canvas,
|
|
12110
12125
|
style: {
|
|
12111
|
-
width:
|
|
12112
|
-
height:
|
|
12126
|
+
width: j,
|
|
12127
|
+
height: j
|
|
12113
12128
|
}
|
|
12114
12129
|
}),
|
|
12115
12130
|
/* @__PURE__ */ u("button", {
|
|
12116
12131
|
type: "button",
|
|
12117
12132
|
className: Vu.spinBtn,
|
|
12118
12133
|
"data-testid": "turntable-spin",
|
|
12119
|
-
onClick: () =>
|
|
12120
|
-
disabled:
|
|
12121
|
-
"aria-busy":
|
|
12122
|
-
children:
|
|
12134
|
+
onClick: () => P(),
|
|
12135
|
+
disabled: C,
|
|
12136
|
+
"aria-busy": C,
|
|
12137
|
+
children: C ? p : f
|
|
12123
12138
|
})
|
|
12124
12139
|
]
|
|
12125
|
-
}),
|
|
12140
|
+
}), T && !C && /* @__PURE__ */ d("p", {
|
|
12126
12141
|
className: Vu.result,
|
|
12127
|
-
children: [m, /* @__PURE__ */ u("strong", { children:
|
|
12142
|
+
children: [m, /* @__PURE__ */ u("strong", { children: T.label })]
|
|
12128
12143
|
})]
|
|
12129
12144
|
});
|
|
12130
12145
|
});
|
package/package.json
CHANGED