@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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createElementBlock as e, defineComponent as t, onMounted as n, onUnmounted as r, openBlock as i, ref as a, watch as o } from "vue";
|
|
2
|
+
import { prefersReducedMotion as s } from "@cos-design/shared";
|
|
3
|
+
import './vue.css';//#region src/components/slotMachine/core/engine.ts
|
|
4
|
+
var c = "cos-slot-machine", l = [
|
|
5
|
+
"🍒",
|
|
6
|
+
"🍋",
|
|
7
|
+
"🍊",
|
|
8
|
+
"🍇",
|
|
9
|
+
"⭐",
|
|
10
|
+
"7️⃣"
|
|
11
|
+
], u = 30, d = 8, f = [
|
|
12
|
+
0,
|
|
13
|
+
350,
|
|
14
|
+
700
|
|
15
|
+
], p = 80, m = 3, h = (e) => 1 - (1 - e) ** 3, g = (e, t) => {
|
|
16
|
+
if (t === void 0) return Math.floor(Math.random() * e.length);
|
|
17
|
+
let n = e.indexOf(t);
|
|
18
|
+
return n >= 0 ? n : Math.floor(Math.random() * e.length);
|
|
19
|
+
};
|
|
20
|
+
function _(e, t = {}) {
|
|
21
|
+
let n = {
|
|
22
|
+
symbols: l,
|
|
23
|
+
spinDuration: 3e3,
|
|
24
|
+
spinningText: "旋转中...",
|
|
25
|
+
jackpotText: "🎰 大奖!",
|
|
26
|
+
resultPrefix: "结果:",
|
|
27
|
+
...t
|
|
28
|
+
}, r = !1, i = !1, a = [
|
|
29
|
+
0,
|
|
30
|
+
0,
|
|
31
|
+
0
|
|
32
|
+
], o = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
|
|
33
|
+
b.className = `${c}__machine`;
|
|
34
|
+
let x = [], S = [];
|
|
35
|
+
for (let e = 0; e < 3; e++) {
|
|
36
|
+
let e = document.createElement("div");
|
|
37
|
+
e.className = `${c}__reel`;
|
|
38
|
+
let t = document.createElement("div");
|
|
39
|
+
t.className = `${c}__strip`;
|
|
40
|
+
let n = document.createElement("div");
|
|
41
|
+
n.className = `${c}__mask`, e.append(t, n), b.appendChild(e), x.push(e), S.push(t);
|
|
42
|
+
}
|
|
43
|
+
let C = document.createElement("button");
|
|
44
|
+
C.type = "button", C.className = `${c}__spin-btn`, C.dataset.testid = "slot-machine-spin";
|
|
45
|
+
let w = document.createElement("p");
|
|
46
|
+
w.className = `${c}__result`, w.hidden = !0, y.append(b, C, w), e.appendChild(y);
|
|
47
|
+
let T = () => n.symbols?.length ? n.symbols : l, E = () => T().length * p, D = () => Math.floor(u / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * p, k = () => n.buttonText ?? n.startText ?? "开始", A = () => {
|
|
48
|
+
let e = T(), t = [];
|
|
49
|
+
for (let n = 0; n < u; n++) t.push(...e);
|
|
50
|
+
for (let e of S) {
|
|
51
|
+
e.replaceChildren();
|
|
52
|
+
for (let n of t) {
|
|
53
|
+
let t = document.createElement("div");
|
|
54
|
+
t.className = `${c}__item`, t.style.height = `${p}px`, t.textContent = n, e.appendChild(t);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let n = p * m;
|
|
58
|
+
for (let e of x) e.style.height = `${n}px`;
|
|
59
|
+
}, j = () => {
|
|
60
|
+
S.forEach((e, t) => {
|
|
61
|
+
e.style.transform = `translateY(${a[t]}px)`;
|
|
62
|
+
});
|
|
63
|
+
}, M = () => {
|
|
64
|
+
y.className = c, C.disabled = i, C.setAttribute("aria-busy", String(i)), C.textContent = i ? n.spinningText ?? "旋转中..." : k(), o.length > 0 && !i ? (w.hidden = !1, w.textContent = o[0] === o[1] && o[1] === o[2] ? n.jackpotText ?? "🎰 大奖!" : `${n.resultPrefix ?? "结果:"} ${o.join(" ")}`) : (w.hidden = !0, w.textContent = "");
|
|
65
|
+
}, N = (e) => {
|
|
66
|
+
let t = T();
|
|
67
|
+
if (i || t.length === 0 || r) return;
|
|
68
|
+
i = !0, o = [], M();
|
|
69
|
+
let c = e ?? n.targetResults, l = [
|
|
70
|
+
0,
|
|
71
|
+
1,
|
|
72
|
+
2
|
|
73
|
+
].map((e) => g(t, c?.[e])), u = [...a], m = t.length * p, y = l.map((e, t) => {
|
|
74
|
+
let n = u[t], r = d * m, i = Math.ceil((-n + r) / m) + 1, a = O(e, i);
|
|
75
|
+
for (; n - a < r;) i += 1, a = O(e, i);
|
|
76
|
+
return a;
|
|
77
|
+
}), b = Math.max(n.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
|
|
78
|
+
v = S;
|
|
79
|
+
let C = () => {
|
|
80
|
+
if (S.cancelled || r) return;
|
|
81
|
+
let e = l.map((e) => t[e]);
|
|
82
|
+
a = l.map((e) => O(e, Math.round(D() / m))), o = e, i = !1, j(), M(), n.onSpinEnd?.(e);
|
|
83
|
+
};
|
|
84
|
+
if (s()) {
|
|
85
|
+
C();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
let w = (e) => {
|
|
89
|
+
S.cancelled || r || (a = u.map((t, n) => {
|
|
90
|
+
let r = e - x - f[n];
|
|
91
|
+
if (r < 0) return t;
|
|
92
|
+
let i = Math.min(r / b, 1);
|
|
93
|
+
return t + (y[n] - t) * h(i);
|
|
94
|
+
}), j(), f.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
|
|
95
|
+
};
|
|
96
|
+
_ = requestAnimationFrame(w);
|
|
97
|
+
};
|
|
98
|
+
return C.addEventListener("click", () => N()), A(), j(), M(), {
|
|
99
|
+
update(e) {
|
|
100
|
+
let t = T().join("\0");
|
|
101
|
+
n = {
|
|
102
|
+
...n,
|
|
103
|
+
...e
|
|
104
|
+
}, T().join("\0") !== t && A(), M();
|
|
105
|
+
},
|
|
106
|
+
spin: N,
|
|
107
|
+
reset: () => {
|
|
108
|
+
i || (o = [], M());
|
|
109
|
+
},
|
|
110
|
+
destroy() {
|
|
111
|
+
r || (r = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/components/slotMachine/vue/SlotMachine.vue
|
|
117
|
+
var v = /* @__PURE__ */ t({
|
|
118
|
+
__name: "SlotMachine",
|
|
119
|
+
props: {
|
|
120
|
+
symbols: {},
|
|
121
|
+
spinDuration: {},
|
|
122
|
+
targetResults: {},
|
|
123
|
+
onSpinEnd: { type: Function },
|
|
124
|
+
startText: {},
|
|
125
|
+
buttonText: {},
|
|
126
|
+
spinningText: {},
|
|
127
|
+
jackpotText: {},
|
|
128
|
+
resultPrefix: {}
|
|
129
|
+
},
|
|
130
|
+
emits: ["spin-end"],
|
|
131
|
+
setup(t, { expose: s, emit: c }) {
|
|
132
|
+
let l = t, u = c, d = a(), f = null, p = () => ({
|
|
133
|
+
...l,
|
|
134
|
+
onSpinEnd: (...e) => u("spin-end", ...e)
|
|
135
|
+
});
|
|
136
|
+
return n(() => {
|
|
137
|
+
d.value && (f = _(d.value, p()));
|
|
138
|
+
}), o(() => ({ ...l }), () => f?.update(p()), { deep: !0 }), r(() => {
|
|
139
|
+
f?.destroy(), f = null;
|
|
140
|
+
}), s({
|
|
141
|
+
spin: (e) => f?.spin(e),
|
|
142
|
+
reset: () => f?.reset()
|
|
143
|
+
}), (t, n) => (i(), e("div", {
|
|
144
|
+
ref_key: "hostRef",
|
|
145
|
+
ref: d,
|
|
146
|
+
class: "cos-slotMachine-host"
|
|
147
|
+
}, null, 512));
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
//#endregion
|
|
151
|
+
export { v as SlotMachine };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ElementSize } from './size';
|
|
2
|
+
export interface CanvasBoxSizeInput {
|
|
3
|
+
/** 为 true 时跟随父容器尺寸(需父级有明确高度) */
|
|
4
|
+
fill?: boolean;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
defaultWidth: number;
|
|
8
|
+
defaultHeight: number;
|
|
9
|
+
measured: ElementSize;
|
|
10
|
+
}
|
|
11
|
+
export interface CanvasBoxSize {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
15
|
+
pending: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
|
|
18
|
+
export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured, }: CanvasBoxSizeInput) => CanvasBoxSize;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Component attribute → Core options parsing (v4 Element adapters).
|
|
3
|
+
* Keeps behavior consistent across 91 components.
|
|
4
|
+
*/
|
|
5
|
+
export type BooleanAttrMode =
|
|
6
|
+
/** `options.key = el.hasAttribute(attr)` — always written */
|
|
7
|
+
'presence'
|
|
8
|
+
/** Only when attribute present: `raw !== 'false' && raw !== '0'` (omit when absent) */
|
|
9
|
+
| 'optional-true'
|
|
10
|
+
/** Only when attribute present; when absent leave `undefined` (controlled props like `flipped`) */
|
|
11
|
+
| 'optional-undefined';
|
|
12
|
+
export declare const camelToKebabAttr: (name: string) => string;
|
|
13
|
+
export declare function readStringAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
14
|
+
export declare function readNumberAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string): void;
|
|
15
|
+
export declare function readBooleanAttr<T extends object>(options: T, el: HTMLElement, key: keyof T & string, attr?: string, mode?: BooleanAttrMode): void;
|
|
16
|
+
export declare function readJsonAttr<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, attr?: string): void;
|
|
17
|
+
/** Property setters on the custom element class (`_prizes`, `_items`, …) override attributes. */
|
|
18
|
+
export declare function readPropertyOverride<T extends object, K extends keyof T & string>(options: T, el: HTMLElement, key: K, backingKey: string): void;
|
|
19
|
+
export declare function optionCallbackDispatcher(el: HTMLElement, eventName: string): (...args: unknown[]) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Apply fill / explicit size to the adapter host and make the engine root fill it. */
|
|
2
|
+
export declare function applyCanvasHostBox(container: HTMLElement, root: HTMLElement, opts: {
|
|
3
|
+
fill: boolean;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}): void;
|
|
7
|
+
/**
|
|
8
|
+
* Size the adapter host (React/Vue div or custom element) so percentage widths
|
|
9
|
+
* don't collapse when the host is a shrink-wrapped flex child. Root fills the host
|
|
10
|
+
* unless `rootFillsHost` is false (e.g. PhotoAlbum sizes itself via CSS variables).
|
|
11
|
+
*/
|
|
12
|
+
export declare function applyBlockHostBox(container: HTMLElement, root: HTMLElement, size: {
|
|
13
|
+
width?: number | string;
|
|
14
|
+
height?: number | string;
|
|
15
|
+
rootFillsHost?: boolean;
|
|
16
|
+
}): void;
|
|
17
|
+
/** Toggle empty-state nodes; author `display:` rules must not override `[hidden]`. */
|
|
18
|
+
export declare function setHidden(el: HTMLElement, hidden: boolean): void;
|
|
19
|
+
/** Stable JSON key for options, ignoring functions (callbacks). */
|
|
20
|
+
export declare function optionsFingerprint(value: unknown): string;
|
|
21
|
+
/** True when non-function fields differ (shallow). */
|
|
22
|
+
export declare function optionsVisualChanged(prev: Record<string, unknown>, next: Record<string, unknown>): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { resolveCanvasBoxSize } from './canvas-box';
|
|
10
|
+
export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
|
|
11
|
+
export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
|
|
12
|
+
export type { BooleanAttrMode } from './element-options';
|
|
13
|
+
export { camelToKebabAttr, optionCallbackDispatcher, readBooleanAttr, readJsonAttr, readNumberAttr, readPropertyOverride, readStringAttr, } from './element-options';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** 图片预览组件通用照片项 */
|
|
2
|
+
export interface PhotoItem {
|
|
3
|
+
/** 图片地址 */
|
|
4
|
+
src: string;
|
|
5
|
+
/** 图片替代文本 */
|
|
6
|
+
alt?: string;
|
|
7
|
+
/** 照片标题 */
|
|
8
|
+
title?: string;
|
|
9
|
+
/** 照片说明 */
|
|
10
|
+
description?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 线性浏览:当前索引变化(相册 / 胶卷 / 晾绳等) */
|
|
13
|
+
export type PhotoIndexChangeHandler<T = PhotoItem> = (index: number, photo: T) => void;
|
|
14
|
+
/** 环形浏览:正对镜头的面变化(走马灯 / 旋转木马等) */
|
|
15
|
+
export type PhotoFaceChangeHandler<T = PhotoItem> = (index: number, photo?: T) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface PointerPosition {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
}
|
|
5
|
+
type PointLike = {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
};
|
|
9
|
+
/** 相对元素左上角的指针坐标(兼容 mouse / touch / pointer) */
|
|
10
|
+
export declare const getRelativePointerPosition: (element: Element, event: PointLike | {
|
|
11
|
+
touches?: ArrayLike<PointLike>;
|
|
12
|
+
changedTouches?: ArrayLike<PointLike>;
|
|
13
|
+
}) => PointerPosition | null;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CSSProperties, RefObject } from 'react';
|
|
2
|
+
import { ElementSize } from '../size';
|
|
3
|
+
export type { CanvasBoxSize, CanvasBoxSizeInput } from '../canvas-box';
|
|
4
|
+
export { resolveCanvasBoxSize } from '../canvas-box';
|
|
5
|
+
export interface UseElementSizeOptions {
|
|
6
|
+
/** 为 false 时不观察 */
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** 观察元素尺寸(clientWidth / clientHeight) */
|
|
10
|
+
export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
|
|
11
|
+
export interface UseCanvasBoxOptions {
|
|
12
|
+
/** 为 true 时铺满父容器(父级需有明确高度) */
|
|
13
|
+
fill?: boolean;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
defaultWidth: number;
|
|
17
|
+
defaultHeight: number;
|
|
18
|
+
}
|
|
19
|
+
export interface UseCanvasBoxResult {
|
|
20
|
+
hostRef: RefObject<HTMLDivElement | null>;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
/** 挂到宿主容器的样式(fill 时为 100%×100%) */
|
|
24
|
+
hostStyle: CSSProperties;
|
|
25
|
+
fill: boolean;
|
|
26
|
+
/** 是否处于 fill 模式且尚未量到有效尺寸 */
|
|
27
|
+
pending: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
|
|
30
|
+
export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight, }: UseCanvasBoxOptions) => UseCanvasBoxResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/slotMachine/core';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../../src/components/slotMachine/element';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface SlotMachineOptions {
|
|
2
|
+
/** 符号列表 */
|
|
3
|
+
symbols?: string[];
|
|
4
|
+
/** 单列旋转时长(毫秒),默认 3000;列之间仍有错峰停轮 */
|
|
5
|
+
spinDuration?: number;
|
|
6
|
+
/** 指定下一次停轮结果(长度 3);不传则随机 */
|
|
7
|
+
targetResults?: string[];
|
|
8
|
+
/** 旋转结束回调 */
|
|
9
|
+
onSpinEnd?: (results: string[]) => void;
|
|
10
|
+
/** 开始按钮文案 */
|
|
11
|
+
startText?: string;
|
|
12
|
+
/** 开始按钮文案别名(与 Turntable.buttonText 对齐) */
|
|
13
|
+
buttonText?: string;
|
|
14
|
+
/** 旋转中的按钮文案 */
|
|
15
|
+
spinningText?: string;
|
|
16
|
+
/** 中奖提示 */
|
|
17
|
+
jackpotText?: string;
|
|
18
|
+
/** 普通结果前缀 */
|
|
19
|
+
resultPrefix?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SlotMachineHandle {
|
|
22
|
+
/** 手动旋转;可传入三列结果覆盖 props.targetResults */
|
|
23
|
+
spin: (results?: string[]) => void;
|
|
24
|
+
/** 清除结果文案 */
|
|
25
|
+
reset: () => void;
|
|
26
|
+
}
|
|
27
|
+
export interface SlotMachineController extends SlotMachineHandle {
|
|
28
|
+
update(options: Partial<SlotMachineOptions>): void;
|
|
29
|
+
destroy(): void;
|
|
30
|
+
}
|
|
31
|
+
export type SlotMachineProps = SlotMachineOptions;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SlotMachineOptions } from '../core';
|
|
2
|
+
declare const TAG = "cos-slot-machine";
|
|
3
|
+
declare class CosSlotMachineElement extends HTMLElement {
|
|
4
|
+
private ctrl;
|
|
5
|
+
_symbols?: SlotMachineOptions['symbols'];
|
|
6
|
+
get symbols(): SlotMachineOptions['symbols'] | undefined;
|
|
7
|
+
set symbols(value: SlotMachineOptions['symbols']);
|
|
8
|
+
_targetResults?: SlotMachineOptions['targetResults'];
|
|
9
|
+
get targetResults(): SlotMachineOptions['targetResults'] | undefined;
|
|
10
|
+
set targetResults(value: SlotMachineOptions['targetResults']);
|
|
11
|
+
static get observedAttributes(): string[];
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
disconnectedCallback(): void;
|
|
14
|
+
attributeChangedCallback(): void;
|
|
15
|
+
spin(results?: string[]): void | undefined;
|
|
16
|
+
reset(): void | undefined;
|
|
17
|
+
}
|
|
18
|
+
export { CosSlotMachineElement, TAG };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SlotMachineOptions } from '../core';
|
|
2
|
+
import { SlotMachineHandle } from '../core/types';
|
|
3
|
+
export type { SlotMachineOptions, SlotMachineHandle } from '../core/types';
|
|
4
|
+
declare const SlotMachine: import('react').ForwardRefExoticComponent<SlotMachineOptions & import('react').RefAttributes<SlotMachineHandle>>;
|
|
5
|
+
export default SlotMachine;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
declare module '*.vue' {
|
|
4
|
+
import type { DefineComponent } from 'vue';
|
|
5
|
+
const component: DefineComponent<object, object, unknown>;
|
|
6
|
+
export default component;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module '*.module.less' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.png' {
|
|
20
|
+
const src: string;
|
|
21
|
+
export default src;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.jpg' {
|
|
25
|
+
const src: string;
|
|
26
|
+
export default src;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.mp4' {
|
|
30
|
+
const src: string;
|
|
31
|
+
export default src;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.mp3' {
|
|
35
|
+
const src: string;
|
|
36
|
+
export default src;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.svg' {
|
|
40
|
+
import type { FC, SVGProps } from 'react';
|
|
41
|
+
|
|
42
|
+
export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
|
|
43
|
+
const src: string;
|
|
44
|
+
export default src;
|
|
45
|
+
}
|
package/dist/vue/vue.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.cos-slot-machine{flex-direction:column;align-items:center;gap:20px;padding:24px;display:flex}.cos-slot-machine__machine{background:linear-gradient(#1e293b,#0f172a);border:3px solid #fbbf24;border-radius:16px;gap:8px;padding:16px;display:flex;box-shadow:0 8px 32px #0000004d,inset 0 2px #ffffff1a}.cos-slot-machine__reel{background:#fff;border-radius:8px;width:80px;position:relative;overflow:hidden}.cos-slot-machine__strip{transition:none}.cos-slot-machine__item{justify-content:center;align-items:center;font-size:36px;display:flex}.cos-slot-machine__mask{pointer-events:none;position:absolute;inset:0;box-shadow:inset 0 30px 20px #00000026,inset 0 -30px 20px #00000026}.cos-slot-machine__spin-btn{color:#78350f;cursor:pointer;background:linear-gradient(#fbbf24,#f59e0b);border:none;border-radius:50px;padding:12px 40px;font-size:16px;font-weight:700;box-shadow:0 4px 16px #fbbf2466}.cos-slot-machine__spin-btn:disabled{opacity:.6;cursor:not-allowed}.cos-slot-machine__result{color:#fbbf24;margin:0;font-size:16px;font-weight:600}
|
package/package.json
CHANGED
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cos-design/slot-machine",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "SlotMachine component from cos-design",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"main": "./dist/react/index.cjs",
|
|
7
|
+
"module": "./dist/react/index.js",
|
|
8
|
+
"types": "./dist/react/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"import": {
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"default": "./dist/index.js"
|
|
12
|
+
"types": "./dist/react/index.d.ts",
|
|
13
|
+
"default": "./dist/react/index.js"
|
|
14
14
|
},
|
|
15
15
|
"require": {
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"default": "./dist/index.cjs"
|
|
16
|
+
"types": "./dist/react/index.d.ts",
|
|
17
|
+
"default": "./dist/react/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./vue": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/vue/index.d.ts",
|
|
23
|
+
"default": "./dist/vue/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"./core": {
|
|
27
|
+
"import": {
|
|
28
|
+
"types": "./dist/core/index.d.ts",
|
|
29
|
+
"default": "./dist/core/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"./element": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/element/index.d.ts",
|
|
35
|
+
"default": "./dist/element/index.js"
|
|
18
36
|
}
|
|
19
37
|
}
|
|
20
38
|
},
|
|
@@ -24,11 +42,13 @@
|
|
|
24
42
|
],
|
|
25
43
|
"sideEffects": [
|
|
26
44
|
"**/*.css",
|
|
27
|
-
"**/*.less"
|
|
45
|
+
"**/*.less",
|
|
46
|
+
"./dist/element/index.js"
|
|
28
47
|
],
|
|
29
48
|
"keywords": [
|
|
30
49
|
"cos-design",
|
|
31
50
|
"react",
|
|
51
|
+
"vue",
|
|
32
52
|
"slotMachine",
|
|
33
53
|
"SlotMachine"
|
|
34
54
|
],
|
|
@@ -45,13 +65,25 @@
|
|
|
45
65
|
"license": "MIT",
|
|
46
66
|
"peerDependencies": {
|
|
47
67
|
"react": ">=18.0.0",
|
|
48
|
-
"react-dom": ">=18.0.0"
|
|
68
|
+
"react-dom": ">=18.0.0",
|
|
69
|
+
"vue": ">=3.4.0"
|
|
49
70
|
},
|
|
50
71
|
"publishConfig": {
|
|
51
72
|
"access": "public",
|
|
52
73
|
"registry": "https://registry.npmjs.org"
|
|
53
74
|
},
|
|
75
|
+
"peerDependenciesMeta": {
|
|
76
|
+
"react": {
|
|
77
|
+
"optional": true
|
|
78
|
+
},
|
|
79
|
+
"react-dom": {
|
|
80
|
+
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"vue": {
|
|
83
|
+
"optional": true
|
|
84
|
+
}
|
|
85
|
+
},
|
|
54
86
|
"dependencies": {
|
|
55
|
-
"@cos-design/shared": "
|
|
87
|
+
"@cos-design/shared": "4.1.0"
|
|
56
88
|
}
|
|
57
|
-
}
|
|
89
|
+
}
|
package/dist/index.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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("@cos-design/shared"),u=require("react/jsx-runtime");var d={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`},f=[`🍒`,`🍋`,`🍊`,`🍇`,`⭐`,`7️⃣`],p=30,m=8,h=[0,350,700],g=e=>1-(1-e)**3,_=(e,t)=>{if(t===void 0)return Math.floor(Math.random()*e.length);let n=e.indexOf(t);return n>=0?n:Math.floor(Math.random()*e.length)},v=(0,c.forwardRef)(({symbols:e=f,spinDuration:t=3e3,targetResults:n,onSpinEnd:r,startText:i,buttonText:a,spinningText:o=`旋转中...`,jackpotText:s=`🎰 大奖!`,resultPrefix:v=`结果:`},y)=>{let b=a??i??`开始`,[x,S]=(0,c.useState)(!1),[C,w]=(0,c.useState)([0,0,0]),[T,E]=(0,c.useState)([]),D=(0,c.useRef)(0),O=(0,c.useRef)(!1),k=(0,c.useRef)(C),A=(0,c.useRef)(r),j=(0,c.useRef)(e),M=(0,c.useRef)(n),N=(0,c.useRef)(null);(0,c.useEffect)(()=>{A.current=r},[r]),(0,c.useEffect)(()=>{j.current=e},[e]),(0,c.useEffect)(()=>{M.current=n},[n]),(0,c.useEffect)(()=>{O.current=x},[x]),(0,c.useEffect)(()=>{k.current=C},[C]);let P=e.length*80,F=Math.floor(p/2)*P,I=(0,c.useCallback)(()=>{let t=[];for(let n=0;n<p;n++)t.push(...e);return t},[e])(),L=(e,t)=>-(e-1+t*j.current.length)*80,R=(0,c.useCallback)(e=>{let n=j.current;if(O.current||n.length===0)return;S(!0),E([]);let r=e??M.current,i=[0,1,2].map(e=>_(n,r?.[e])),a=[...k.current],o=n.length*80,s=i.map((e,t)=>{let n=a[t],r=m*o,i=Math.ceil((-n+r)/o)+1,s=L(e,i);for(;n-s<r;)i+=1,s=L(e,i);return s}),c=Math.max(t,16),u=performance.now(),d={cancelled:!1};N.current=d;let f=()=>{if(d.cancelled)return;let e=i.map(e=>n[e]);w(i.map(e=>L(e,Math.round(F/o)))),E(e),S(!1),A.current?.(e)};if((0,l.prefersReducedMotion)()){f();return}let p=e=>{d.cancelled||(w(a.map((t,n)=>{let r=e-u-h[n];if(r<0)return t;let i=g(Math.min(r/c,1));return t+(s[n]-t)*i})),h.every(t=>e-u-t>=c)?f():D.current=requestAnimationFrame(p))};D.current=requestAnimationFrame(p)},[F,t]),z=(0,c.useCallback)(()=>{O.current||E([])},[]);return(0,c.useImperativeHandle)(y,()=>({spin:R,reset:z}),[R,z]),(0,c.useEffect)(()=>()=>{N.current&&(N.current.cancelled=!0),cancelAnimationFrame(D.current)},[]),(0,u.jsxs)(`div`,{className:d.slotMachine,children:[(0,u.jsx)(`div`,{className:d.machine,children:[0,1,2].map(e=>(0,u.jsxs)(`div`,{className:d.reel,style:{height:240},children:[(0,u.jsx)(`div`,{className:d.strip,style:{transform:`translateY(${C[e]}px)`},children:I.map((e,t)=>(0,u.jsx)(`div`,{className:d.item,style:{height:80},children:e},t))}),(0,u.jsx)(`div`,{className:d.mask})]},e))}),(0,u.jsx)(`button`,{type:`button`,className:d.spinBtn,"data-testid":`slot-machine-spin`,onClick:()=>R(),disabled:x,"aria-busy":x,children:x?o:b}),T.length>0&&!x&&(0,u.jsx)(`p`,{className:d.result,children:T[0]===T[1]&&T[1]===T[2]?s:`${v} ${T.join(` `)}`})]})});v.displayName=`SlotMachine`,exports.SlotMachine=v,exports.default=v;
|
package/dist/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.cos-slotMachine-P6FyZ{flex-direction:column;align-items:center;gap:20px;padding:24px;display:flex}.cos-machine-B066r{background:linear-gradient(#1e293b,#0f172a);border:3px solid #fbbf24;border-radius:16px;gap:8px;padding:16px;display:flex;box-shadow:0 8px 32px #0000004d,inset 0 2px #ffffff1a}.cos-reel-eEpJ3{background:#fff;border-radius:8px;width:80px;position:relative;overflow:hidden}.cos-strip-L5Z-a{transition:none}.cos-item-WYJ6q{justify-content:center;align-items:center;font-size:36px;display:flex}.cos-mask-jdrj3{pointer-events:none;position:absolute;inset:0;box-shadow:inset 0 30px 20px #00000026,inset 0 -30px 20px #00000026}.cos-spinBtn-DvDE7{color:#78350f;cursor:pointer;background:linear-gradient(#fbbf24,#f59e0b);border:none;border-radius:50px;padding:12px 40px;font-size:16px;font-weight:700;box-shadow:0 4px 16px #fbbf2466}.cos-spinBtn-DvDE7:disabled{opacity:.6;cursor:not-allowed}.cos-result-dLN5b{color:#fbbf24;margin:0;font-size:16px;font-weight:600}
|
package/dist/index.d.ts
DELETED