@cos-design/slot-machine 3.5.7 → 4.1.0
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/core/index.d.ts +1 -0
- package/dist/core/index.js +115 -0
- package/dist/core/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/core/packages/shared/src/element-options.d.ts +19 -0
- package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/core/packages/shared/src/index.d.ts +13 -0
- package/dist/{packages/shared/src/use-element-size.d.ts → core/packages/shared/src/react/index.d.ts} +4 -19
- package/dist/core/packages/slotMachine/src/core.d.ts +1 -0
- package/dist/core/packages/slotMachine/src/element.d.ts +1 -0
- package/dist/core/packages/slotMachine/src/react.d.ts +3 -0
- package/dist/core/packages/slotMachine/src/vue.d.ts +2 -0
- package/dist/core/src/components/slotMachine/core/engine.d.ts +2 -0
- package/dist/core/src/components/slotMachine/core/index.d.ts +2 -0
- package/dist/{src/components/slotMachine/index.d.ts → core/src/components/slotMachine/core/types.d.ts} +6 -4
- package/dist/core/src/components/slotMachine/element/index.d.ts +18 -0
- package/dist/core/src/components/slotMachine/index.d.ts +3 -0
- package/dist/core/src/components/slotMachine/react/index.d.ts +5 -0
- package/dist/{src → core/src}/vite-env.d.ts +6 -0
- package/dist/element/element.css +1 -0
- package/dist/element/index.d.ts +1 -0
- package/dist/element/index.js +167 -0
- package/dist/element/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/element/packages/shared/src/element-options.d.ts +19 -0
- package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/element/packages/shared/src/index.d.ts +13 -0
- package/dist/element/packages/shared/src/math.d.ts +2 -0
- package/dist/element/packages/shared/src/photo.d.ts +15 -0
- package/dist/element/packages/shared/src/pointer.d.ts +14 -0
- package/dist/element/packages/shared/src/react/index.d.ts +30 -0
- package/dist/element/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/element/packages/shared/src/size.d.ts +8 -0
- package/dist/element/packages/shared/src/visibility.d.ts +2 -0
- package/dist/element/packages/slotMachine/src/core.d.ts +1 -0
- package/dist/element/packages/slotMachine/src/element.d.ts +1 -0
- package/dist/element/packages/slotMachine/src/index.d.ts +3 -0
- package/dist/element/packages/slotMachine/src/react.d.ts +3 -0
- package/dist/element/packages/slotMachine/src/vue.d.ts +2 -0
- package/dist/element/src/components/slotMachine/core/engine.d.ts +2 -0
- package/dist/element/src/components/slotMachine/core/index.d.ts +2 -0
- package/dist/element/src/components/slotMachine/core/types.d.ts +31 -0
- package/dist/element/src/components/slotMachine/element/index.d.ts +18 -0
- package/dist/element/src/components/slotMachine/index.d.ts +3 -0
- package/dist/element/src/components/slotMachine/react/index.d.ts +5 -0
- package/dist/element/src/vite-env.d.ts +45 -0
- package/dist/react/index.cjs +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +141 -0
- package/dist/react/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/react/packages/shared/src/element-options.d.ts +19 -0
- package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/react/packages/shared/src/index.d.ts +13 -0
- package/dist/react/packages/shared/src/math.d.ts +2 -0
- package/dist/react/packages/shared/src/photo.d.ts +15 -0
- package/dist/react/packages/shared/src/pointer.d.ts +14 -0
- package/dist/react/packages/shared/src/react/index.d.ts +30 -0
- package/dist/react/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/react/packages/shared/src/size.d.ts +8 -0
- package/dist/react/packages/shared/src/visibility.d.ts +2 -0
- package/dist/react/packages/slotMachine/src/core.d.ts +1 -0
- package/dist/react/packages/slotMachine/src/element.d.ts +1 -0
- package/dist/react/packages/slotMachine/src/index.d.ts +3 -0
- package/dist/react/packages/slotMachine/src/react.d.ts +3 -0
- package/dist/react/packages/slotMachine/src/vue.d.ts +2 -0
- package/dist/react/react.css +1 -0
- package/dist/react/src/components/slotMachine/core/engine.d.ts +2 -0
- package/dist/react/src/components/slotMachine/core/index.d.ts +2 -0
- package/dist/react/src/components/slotMachine/core/types.d.ts +31 -0
- package/dist/react/src/components/slotMachine/element/index.d.ts +18 -0
- package/dist/react/src/components/slotMachine/index.d.ts +3 -0
- package/dist/react/src/components/slotMachine/react/index.d.ts +5 -0
- package/dist/react/src/vite-env.d.ts +45 -0
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +151 -0
- package/dist/vue/packages/shared/src/canvas-box.d.ts +18 -0
- package/dist/vue/packages/shared/src/element-options.d.ts +19 -0
- package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
- package/dist/vue/packages/shared/src/index.d.ts +13 -0
- package/dist/vue/packages/shared/src/math.d.ts +2 -0
- package/dist/vue/packages/shared/src/photo.d.ts +15 -0
- package/dist/vue/packages/shared/src/pointer.d.ts +14 -0
- package/dist/vue/packages/shared/src/react/index.d.ts +30 -0
- package/dist/vue/packages/shared/src/reduced-motion.d.ts +4 -0
- package/dist/vue/packages/shared/src/size.d.ts +8 -0
- package/dist/vue/packages/shared/src/visibility.d.ts +2 -0
- package/dist/vue/packages/slotMachine/src/core.d.ts +1 -0
- package/dist/vue/packages/slotMachine/src/element.d.ts +1 -0
- package/dist/vue/packages/slotMachine/src/index.d.ts +3 -0
- package/dist/vue/packages/slotMachine/src/react.d.ts +3 -0
- package/dist/vue/packages/slotMachine/src/vue.d.ts +2 -0
- package/dist/vue/src/components/slotMachine/core/engine.d.ts +2 -0
- package/dist/vue/src/components/slotMachine/core/index.d.ts +2 -0
- package/dist/vue/src/components/slotMachine/core/types.d.ts +31 -0
- package/dist/vue/src/components/slotMachine/element/index.d.ts +18 -0
- package/dist/vue/src/components/slotMachine/index.d.ts +3 -0
- package/dist/vue/src/components/slotMachine/react/index.d.ts +5 -0
- package/dist/vue/src/vite-env.d.ts +45 -0
- package/dist/vue/vue.css +1 -0
- package/package.json +44 -12
- package/dist/index.cjs +0 -1
- package/dist/index.css +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -130
- package/dist/packages/shared/src/index.d.ts +0 -10
- /package/dist/{packages → core/packages}/shared/src/math.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/photo.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/pointer.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/reduced-motion.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/size.d.ts +0 -0
- /package/dist/{packages → core/packages}/shared/src/visibility.d.ts +0 -0
- /package/dist/{packages → core/packages}/slotMachine/src/index.d.ts +0 -0
package/dist/index.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { forwardRef as e, useCallback as t, useEffect as n, useImperativeHandle as r, useRef as i, useState as a } from "react";
|
|
2
|
-
import { prefersReducedMotion as o } from "@cos-design/shared";
|
|
3
|
-
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
4
|
-
import './index.css';var l = {
|
|
5
|
-
slotMachine: "cos-slotMachine-P6FyZ",
|
|
6
|
-
machine: "cos-machine-B066r",
|
|
7
|
-
reel: "cos-reel-eEpJ3",
|
|
8
|
-
strip: "cos-strip-L5Z-a",
|
|
9
|
-
item: "cos-item-WYJ6q",
|
|
10
|
-
mask: "cos-mask-jdrj3",
|
|
11
|
-
spinBtn: "cos-spinBtn-DvDE7",
|
|
12
|
-
result: "cos-result-dLN5b"
|
|
13
|
-
}, u = [
|
|
14
|
-
"🍒",
|
|
15
|
-
"🍋",
|
|
16
|
-
"🍊",
|
|
17
|
-
"🍇",
|
|
18
|
-
"⭐",
|
|
19
|
-
"7️⃣"
|
|
20
|
-
], d = 30, f = 8, p = [
|
|
21
|
-
0,
|
|
22
|
-
350,
|
|
23
|
-
700
|
|
24
|
-
], m = (e) => 1 - (1 - e) ** 3, h = (e, t) => {
|
|
25
|
-
if (t === void 0) return Math.floor(Math.random() * e.length);
|
|
26
|
-
let n = e.indexOf(t);
|
|
27
|
-
return n >= 0 ? n : Math.floor(Math.random() * e.length);
|
|
28
|
-
}, g = e(({ symbols: e = u, spinDuration: g = 3e3, targetResults: _, onSpinEnd: v, startText: y, buttonText: b, spinningText: x = "旋转中...", jackpotText: S = "🎰 大奖!", resultPrefix: C = "结果:" }, w) => {
|
|
29
|
-
let T = b ?? y ?? "开始", [E, D] = a(!1), [O, k] = a([
|
|
30
|
-
0,
|
|
31
|
-
0,
|
|
32
|
-
0
|
|
33
|
-
]), [A, j] = a([]), M = i(0), N = i(!1), P = i(O), F = i(v), I = i(e), L = i(_), R = i(null);
|
|
34
|
-
n(() => {
|
|
35
|
-
F.current = v;
|
|
36
|
-
}, [v]), n(() => {
|
|
37
|
-
I.current = e;
|
|
38
|
-
}, [e]), n(() => {
|
|
39
|
-
L.current = _;
|
|
40
|
-
}, [_]), n(() => {
|
|
41
|
-
N.current = E;
|
|
42
|
-
}, [E]), n(() => {
|
|
43
|
-
P.current = O;
|
|
44
|
-
}, [O]);
|
|
45
|
-
let z = e.length * 80, B = Math.floor(d / 2) * z, V = t(() => {
|
|
46
|
-
let t = [];
|
|
47
|
-
for (let n = 0; n < d; n++) t.push(...e);
|
|
48
|
-
return t;
|
|
49
|
-
}, [e])(), H = (e, t) => -(e - 1 + t * I.current.length) * 80, U = t((e) => {
|
|
50
|
-
let t = I.current;
|
|
51
|
-
if (N.current || t.length === 0) return;
|
|
52
|
-
D(!0), j([]);
|
|
53
|
-
let n = e ?? L.current, r = [
|
|
54
|
-
0,
|
|
55
|
-
1,
|
|
56
|
-
2
|
|
57
|
-
].map((e) => h(t, n?.[e])), i = [...P.current], a = t.length * 80, s = r.map((e, t) => {
|
|
58
|
-
let n = i[t], r = f * a, o = Math.ceil((-n + r) / a) + 1, s = H(e, o);
|
|
59
|
-
for (; n - s < r;) o += 1, s = H(e, o);
|
|
60
|
-
return s;
|
|
61
|
-
}), c = Math.max(g, 16), l = performance.now(), u = { cancelled: !1 };
|
|
62
|
-
R.current = u;
|
|
63
|
-
let d = () => {
|
|
64
|
-
if (u.cancelled) return;
|
|
65
|
-
let e = r.map((e) => t[e]);
|
|
66
|
-
k(r.map((e) => H(e, Math.round(B / a)))), j(e), D(!1), F.current?.(e);
|
|
67
|
-
};
|
|
68
|
-
if (o()) {
|
|
69
|
-
d();
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
let _ = (e) => {
|
|
73
|
-
u.cancelled || (k(i.map((t, n) => {
|
|
74
|
-
let r = e - l - p[n];
|
|
75
|
-
if (r < 0) return t;
|
|
76
|
-
let i = m(Math.min(r / c, 1));
|
|
77
|
-
return t + (s[n] - t) * i;
|
|
78
|
-
})), p.every((t) => e - l - t >= c) ? d() : M.current = requestAnimationFrame(_));
|
|
79
|
-
};
|
|
80
|
-
M.current = requestAnimationFrame(_);
|
|
81
|
-
}, [B, g]), W = t(() => {
|
|
82
|
-
N.current || j([]);
|
|
83
|
-
}, []);
|
|
84
|
-
return r(w, () => ({
|
|
85
|
-
spin: U,
|
|
86
|
-
reset: W
|
|
87
|
-
}), [U, W]), n(() => () => {
|
|
88
|
-
R.current && (R.current.cancelled = !0), cancelAnimationFrame(M.current);
|
|
89
|
-
}, []), /* @__PURE__ */ c("div", {
|
|
90
|
-
className: l.slotMachine,
|
|
91
|
-
children: [
|
|
92
|
-
/* @__PURE__ */ s("div", {
|
|
93
|
-
className: l.machine,
|
|
94
|
-
children: [
|
|
95
|
-
0,
|
|
96
|
-
1,
|
|
97
|
-
2
|
|
98
|
-
].map((e) => /* @__PURE__ */ c("div", {
|
|
99
|
-
className: l.reel,
|
|
100
|
-
style: { height: 240 },
|
|
101
|
-
children: [/* @__PURE__ */ s("div", {
|
|
102
|
-
className: l.strip,
|
|
103
|
-
style: { transform: `translateY(${O[e]}px)` },
|
|
104
|
-
children: V.map((e, t) => /* @__PURE__ */ s("div", {
|
|
105
|
-
className: l.item,
|
|
106
|
-
style: { height: 80 },
|
|
107
|
-
children: e
|
|
108
|
-
}, t))
|
|
109
|
-
}), /* @__PURE__ */ s("div", { className: l.mask })]
|
|
110
|
-
}, e))
|
|
111
|
-
}),
|
|
112
|
-
/* @__PURE__ */ s("button", {
|
|
113
|
-
type: "button",
|
|
114
|
-
className: l.spinBtn,
|
|
115
|
-
"data-testid": "slot-machine-spin",
|
|
116
|
-
onClick: () => U(),
|
|
117
|
-
disabled: E,
|
|
118
|
-
"aria-busy": E,
|
|
119
|
-
children: E ? x : T
|
|
120
|
-
}),
|
|
121
|
-
A.length > 0 && !E && /* @__PURE__ */ s("p", {
|
|
122
|
-
className: l.result,
|
|
123
|
-
children: A[0] === A[1] && A[1] === A[2] ? S : `${C} ${A.join(" ")}`
|
|
124
|
-
})
|
|
125
|
-
]
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
g.displayName = "SlotMachine";
|
|
129
|
-
//#endregion
|
|
130
|
-
export { g as SlotMachine, g as default };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { clamp, lerp } from './math';
|
|
2
|
-
export { bindVisibilityPause } from './visibility';
|
|
3
|
-
export { prefersReducedMotion, bindPrefersReducedMotion } from './reduced-motion';
|
|
4
|
-
export { observeElementSize } from './size';
|
|
5
|
-
export type { ElementSize } from './size';
|
|
6
|
-
export { getRelativePointerPosition } from './pointer';
|
|
7
|
-
export type { PointerPosition } from './pointer';
|
|
8
|
-
export type { PhotoItem, PhotoIndexChangeHandler, PhotoFaceChangeHandler } from './photo';
|
|
9
|
-
export { useElementSize, resolveCanvasBoxSize, useCanvasBox } from './use-element-size';
|
|
10
|
-
export type { UseElementSizeOptions, CanvasBoxSizeInput, CanvasBoxSize, UseCanvasBoxOptions, UseCanvasBoxResult } from './use-element-size';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|