@cos-design/slot-machine 3.5.3 → 3.5.4
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/dist/index.cjs +1 -1
- package/dist/index.js +40 -36
- package/dist/src/components/slotMachine/index.d.ts +10 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u={slotMachine:`cos-slotMachine-P6FyZ`,machine:`cos-machine-B066r`,reel:`cos-reel-eEpJ3`,strip:`cos-strip-L5Z-a`,item:`cos-item-WYJ6q`,mask:`cos-mask-jdrj3`,spinBtn:`cos-spinBtn-DvDE7`,result:`cos-result-dLN5b`},d=[`🍒`,`🍋`,`🍊`,`🍇`,`⭐`,`7️⃣`],f=e=>1-(1-e)**3,
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u={slotMachine:`cos-slotMachine-P6FyZ`,machine:`cos-machine-B066r`,reel:`cos-reel-eEpJ3`,strip:`cos-strip-L5Z-a`,item:`cos-item-WYJ6q`,mask:`cos-mask-jdrj3`,spinBtn:`cos-spinBtn-DvDE7`,result:`cos-result-dLN5b`},d=[`🍒`,`🍋`,`🍊`,`🍇`,`⭐`,`7️⃣`],f=30,p=8,m=[0,350,700],h=e=>1-(1-e)**3,g=({symbols:e=d,spinDuration:t=3e3,onSpinEnd:n,startText:r=`开始`,spinningText:i=`旋转中...`,jackpotText:a=`🎰 大奖!`,resultPrefix:o=`结果:`})=>{let[s,g]=(0,c.useState)(!1),[_,v]=(0,c.useState)([0,0,0]),[y,b]=(0,c.useState)([]),x=(0,c.useRef)(0),S=(0,c.useRef)(n),C=(0,c.useRef)(null);(0,c.useEffect)(()=>{S.current=n},[n]);let w=e.length*80,T=Math.floor(f/2)*w,E=(0,c.useCallback)(()=>{let t=[];for(let n=0;n<f;n++)t.push(...e);return t},[e])(),D=(t,n)=>-(t-1+n*e.length)*80;return(0,c.useEffect)(()=>()=>{C.current&&(C.current.cancelled=!0),cancelAnimationFrame(x.current)},[]),(0,l.jsxs)(`div`,{className:u.slotMachine,children:[(0,l.jsx)(`div`,{className:u.machine,children:[0,1,2].map(e=>(0,l.jsxs)(`div`,{className:u.reel,style:{height:240},children:[(0,l.jsx)(`div`,{className:u.strip,style:{transform:`translateY(${_[e]}px)`},children:E.map((e,t)=>(0,l.jsx)(`div`,{className:u.item,style:{height:80},children:e},t))}),(0,l.jsx)(`div`,{className:u.mask})]},e))}),(0,l.jsx)(`button`,{type:`button`,className:u.spinBtn,onClick:()=>{if(s||e.length===0)return;g(!0),b([]);let n=[0,1,2].map(()=>Math.floor(Math.random()*e.length)),r=[..._],i=n.map((e,t)=>{let n=r[t],i=p*w,a=Math.ceil((-n+i)/w)+1,o=D(e,a);for(;n-o<i;)a+=1,o=D(e,a);return o}),a=Math.max(t,16),o=performance.now(),c={cancelled:!1};C.current=c;let l=t=>{if(!c.cancelled){if(v(r.map((e,n)=>{let r=t-o-m[n];if(r<0)return e;let s=h(Math.min(r/a,1));return e+(i[n]-e)*s})),!m.every(e=>t-o-e>=a))x.current=requestAnimationFrame(l);else if(!c.cancelled){let t=n.map(t=>e[t]);v(n.map(e=>D(e,Math.round(T/w)))),b(t),g(!1),S.current?.(t)}}};x.current=requestAnimationFrame(l)},disabled:s,children:s?i:r}),y.length>0&&!s&&(0,l.jsx)(`p`,{className:u.result,children:y[0]===y[1]&&y[1]===y[2]?a:`${o} ${y.join(` `)}`})]})};exports.SlotMachine=g,exports.default=g;
|
package/dist/index.js
CHANGED
|
@@ -16,22 +16,26 @@ import './index.css';var o = {
|
|
|
16
16
|
"🍇",
|
|
17
17
|
"⭐",
|
|
18
18
|
"7️⃣"
|
|
19
|
-
], c =
|
|
20
|
-
|
|
19
|
+
], c = 30, l = 8, u = [
|
|
20
|
+
0,
|
|
21
|
+
350,
|
|
22
|
+
700
|
|
23
|
+
], d = (e) => 1 - (1 - e) ** 3, f = ({ symbols: f = s, spinDuration: p = 3e3, onSpinEnd: m, startText: h = "开始", spinningText: g = "旋转中...", jackpotText: _ = "🎰 大奖!", resultPrefix: v = "结果:" }) => {
|
|
24
|
+
let [y, b] = r(!1), [x, S] = r([
|
|
21
25
|
0,
|
|
22
26
|
0,
|
|
23
27
|
0
|
|
24
|
-
]), [
|
|
28
|
+
]), [C, w] = r([]), T = n(0), E = n(m), D = n(null);
|
|
25
29
|
t(() => {
|
|
26
|
-
|
|
27
|
-
}, [
|
|
28
|
-
let
|
|
30
|
+
E.current = m;
|
|
31
|
+
}, [m]);
|
|
32
|
+
let O = f.length * 80, k = Math.floor(c / 2) * O, A = e(() => {
|
|
29
33
|
let e = [];
|
|
30
|
-
for (let t = 0; t <
|
|
34
|
+
for (let t = 0; t < c; t++) e.push(...f);
|
|
31
35
|
return e;
|
|
32
|
-
}, [
|
|
36
|
+
}, [f])(), j = (e, t) => -(e - 1 + t * f.length) * 80;
|
|
33
37
|
return t(() => () => {
|
|
34
|
-
|
|
38
|
+
D.current && (D.current.cancelled = !0), cancelAnimationFrame(T.current);
|
|
35
39
|
}, []), /* @__PURE__ */ a("div", {
|
|
36
40
|
className: o.slotMachine,
|
|
37
41
|
children: [
|
|
@@ -46,8 +50,8 @@ import './index.css';var o = {
|
|
|
46
50
|
style: { height: 240 },
|
|
47
51
|
children: [/* @__PURE__ */ i("div", {
|
|
48
52
|
className: o.strip,
|
|
49
|
-
style: { transform: `translateY(${
|
|
50
|
-
children:
|
|
53
|
+
style: { transform: `translateY(${x[e]}px)` },
|
|
54
|
+
children: A.map((e, t) => /* @__PURE__ */ i("div", {
|
|
51
55
|
className: o.item,
|
|
52
56
|
style: { height: 80 },
|
|
53
57
|
children: e
|
|
@@ -59,43 +63,43 @@ import './index.css';var o = {
|
|
|
59
63
|
type: "button",
|
|
60
64
|
className: o.spinBtn,
|
|
61
65
|
onClick: () => {
|
|
62
|
-
if (
|
|
63
|
-
|
|
66
|
+
if (y || f.length === 0) return;
|
|
67
|
+
b(!0), w([]);
|
|
64
68
|
let e = [
|
|
65
69
|
0,
|
|
66
70
|
1,
|
|
67
71
|
2
|
|
68
|
-
].map(() => Math.floor(Math.random() *
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
let
|
|
75
|
-
if (!
|
|
76
|
-
if (
|
|
77
|
-
let
|
|
78
|
-
if (
|
|
79
|
-
let
|
|
80
|
-
return e + (t
|
|
81
|
-
})), !
|
|
82
|
-
else if (!
|
|
83
|
-
let t = e.map((e) =>
|
|
84
|
-
|
|
72
|
+
].map(() => Math.floor(Math.random() * f.length)), t = [...x], n = e.map((e, n) => {
|
|
73
|
+
let r = t[n], i = l * O, a = Math.ceil((-r + i) / O) + 1, o = j(e, a);
|
|
74
|
+
for (; r - o < i;) a += 1, o = j(e, a);
|
|
75
|
+
return o;
|
|
76
|
+
}), r = Math.max(p, 16), i = performance.now(), a = { cancelled: !1 };
|
|
77
|
+
D.current = a;
|
|
78
|
+
let o = (s) => {
|
|
79
|
+
if (!a.cancelled) {
|
|
80
|
+
if (S(t.map((e, t) => {
|
|
81
|
+
let a = s - i - u[t];
|
|
82
|
+
if (a < 0) return e;
|
|
83
|
+
let o = d(Math.min(a / r, 1));
|
|
84
|
+
return e + (n[t] - e) * o;
|
|
85
|
+
})), !u.every((e) => s - i - e >= r)) T.current = requestAnimationFrame(o);
|
|
86
|
+
else if (!a.cancelled) {
|
|
87
|
+
let t = e.map((e) => f[e]);
|
|
88
|
+
S(e.map((e) => j(e, Math.round(k / O)))), w(t), b(!1), E.current?.(t);
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
};
|
|
88
|
-
|
|
92
|
+
T.current = requestAnimationFrame(o);
|
|
89
93
|
},
|
|
90
|
-
disabled:
|
|
91
|
-
children:
|
|
94
|
+
disabled: y,
|
|
95
|
+
children: y ? g : h
|
|
92
96
|
}),
|
|
93
|
-
|
|
97
|
+
C.length > 0 && !y && /* @__PURE__ */ i("p", {
|
|
94
98
|
className: o.result,
|
|
95
|
-
children:
|
|
99
|
+
children: C[0] === C[1] && C[1] === C[2] ? _ : `${v} ${C.join(" ")}`
|
|
96
100
|
})
|
|
97
101
|
]
|
|
98
102
|
});
|
|
99
103
|
};
|
|
100
104
|
//#endregion
|
|
101
|
-
export {
|
|
105
|
+
export { f as SlotMachine, f as default };
|
|
@@ -2,8 +2,18 @@ import { default as React } from 'react';
|
|
|
2
2
|
export interface SlotMachineProps {
|
|
3
3
|
/** 符号列表 */
|
|
4
4
|
symbols?: string[];
|
|
5
|
+
/** 单列旋转时长(毫秒),默认 3000;列之间仍有错峰停轮 */
|
|
6
|
+
spinDuration?: number;
|
|
5
7
|
/** 旋转结束回调 */
|
|
6
8
|
onSpinEnd?: (results: string[]) => void;
|
|
9
|
+
/** 开始按钮文案 */
|
|
10
|
+
startText?: string;
|
|
11
|
+
/** 旋转中的按钮文案 */
|
|
12
|
+
spinningText?: string;
|
|
13
|
+
/** 中奖提示 */
|
|
14
|
+
jackpotText?: string;
|
|
15
|
+
/** 普通结果前缀 */
|
|
16
|
+
resultPrefix?: string;
|
|
7
17
|
}
|
|
8
18
|
declare const SlotMachine: React.FC<SlotMachineProps>;
|
|
9
19
|
export default SlotMachine;
|