@cos-design/slot-machine 3.5.7 → 4.0.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.
Files changed (105) hide show
  1. package/dist/core/index.d.ts +1 -0
  2. package/dist/core/index.js +115 -0
  3. package/dist/core/packages/shared/src/canvas-box.d.ts +18 -0
  4. package/dist/core/packages/shared/src/host-layout.d.ts +22 -0
  5. package/dist/{packages → core/packages}/shared/src/index.d.ts +3 -2
  6. package/dist/{packages/shared/src/use-element-size.d.ts → core/packages/shared/src/react/index.d.ts} +4 -19
  7. package/dist/core/packages/slotMachine/src/core.d.ts +1 -0
  8. package/dist/core/packages/slotMachine/src/element.d.ts +1 -0
  9. package/dist/core/packages/slotMachine/src/react.d.ts +3 -0
  10. package/dist/core/packages/slotMachine/src/vue.d.ts +2 -0
  11. package/dist/core/src/components/slotMachine/core/engine.d.ts +2 -0
  12. package/dist/core/src/components/slotMachine/core/index.d.ts +2 -0
  13. package/dist/{src/components/slotMachine/index.d.ts → core/src/components/slotMachine/core/types.d.ts} +6 -4
  14. package/dist/core/src/components/slotMachine/element/index.d.ts +18 -0
  15. package/dist/core/src/components/slotMachine/index.d.ts +3 -0
  16. package/dist/core/src/components/slotMachine/react/index.d.ts +5 -0
  17. package/dist/{src → core/src}/vite-env.d.ts +6 -0
  18. package/dist/element/element.css +1 -0
  19. package/dist/element/index.d.ts +1 -0
  20. package/dist/element/index.js +180 -0
  21. package/dist/element/packages/shared/src/canvas-box.d.ts +18 -0
  22. package/dist/element/packages/shared/src/host-layout.d.ts +22 -0
  23. package/dist/element/packages/shared/src/index.d.ts +11 -0
  24. package/dist/element/packages/shared/src/math.d.ts +2 -0
  25. package/dist/element/packages/shared/src/photo.d.ts +15 -0
  26. package/dist/element/packages/shared/src/pointer.d.ts +14 -0
  27. package/dist/element/packages/shared/src/react/index.d.ts +30 -0
  28. package/dist/element/packages/shared/src/reduced-motion.d.ts +4 -0
  29. package/dist/element/packages/shared/src/size.d.ts +8 -0
  30. package/dist/element/packages/shared/src/visibility.d.ts +2 -0
  31. package/dist/element/packages/slotMachine/src/core.d.ts +1 -0
  32. package/dist/element/packages/slotMachine/src/element.d.ts +1 -0
  33. package/dist/element/packages/slotMachine/src/index.d.ts +3 -0
  34. package/dist/element/packages/slotMachine/src/react.d.ts +3 -0
  35. package/dist/element/packages/slotMachine/src/vue.d.ts +2 -0
  36. package/dist/element/src/components/slotMachine/core/engine.d.ts +2 -0
  37. package/dist/element/src/components/slotMachine/core/index.d.ts +2 -0
  38. package/dist/element/src/components/slotMachine/core/types.d.ts +31 -0
  39. package/dist/element/src/components/slotMachine/element/index.d.ts +18 -0
  40. package/dist/element/src/components/slotMachine/index.d.ts +3 -0
  41. package/dist/element/src/components/slotMachine/react/index.d.ts +5 -0
  42. package/dist/element/src/vite-env.d.ts +45 -0
  43. package/dist/react/index.cjs +1 -0
  44. package/dist/react/index.d.ts +3 -0
  45. package/dist/react/index.js +141 -0
  46. package/dist/react/packages/shared/src/canvas-box.d.ts +18 -0
  47. package/dist/react/packages/shared/src/host-layout.d.ts +22 -0
  48. package/dist/react/packages/shared/src/index.d.ts +11 -0
  49. package/dist/react/packages/shared/src/math.d.ts +2 -0
  50. package/dist/react/packages/shared/src/photo.d.ts +15 -0
  51. package/dist/react/packages/shared/src/pointer.d.ts +14 -0
  52. package/dist/react/packages/shared/src/react/index.d.ts +30 -0
  53. package/dist/react/packages/shared/src/reduced-motion.d.ts +4 -0
  54. package/dist/react/packages/shared/src/size.d.ts +8 -0
  55. package/dist/react/packages/shared/src/visibility.d.ts +2 -0
  56. package/dist/react/packages/slotMachine/src/core.d.ts +1 -0
  57. package/dist/react/packages/slotMachine/src/element.d.ts +1 -0
  58. package/dist/react/packages/slotMachine/src/index.d.ts +3 -0
  59. package/dist/react/packages/slotMachine/src/react.d.ts +3 -0
  60. package/dist/react/packages/slotMachine/src/vue.d.ts +2 -0
  61. package/dist/react/react.css +1 -0
  62. package/dist/react/src/components/slotMachine/core/engine.d.ts +2 -0
  63. package/dist/react/src/components/slotMachine/core/index.d.ts +2 -0
  64. package/dist/react/src/components/slotMachine/core/types.d.ts +31 -0
  65. package/dist/react/src/components/slotMachine/element/index.d.ts +18 -0
  66. package/dist/react/src/components/slotMachine/index.d.ts +3 -0
  67. package/dist/react/src/components/slotMachine/react/index.d.ts +5 -0
  68. package/dist/react/src/vite-env.d.ts +45 -0
  69. package/dist/vue/index.d.ts +2 -0
  70. package/dist/vue/index.js +151 -0
  71. package/dist/vue/packages/shared/src/canvas-box.d.ts +18 -0
  72. package/dist/vue/packages/shared/src/host-layout.d.ts +22 -0
  73. package/dist/vue/packages/shared/src/index.d.ts +11 -0
  74. package/dist/vue/packages/shared/src/math.d.ts +2 -0
  75. package/dist/vue/packages/shared/src/photo.d.ts +15 -0
  76. package/dist/vue/packages/shared/src/pointer.d.ts +14 -0
  77. package/dist/vue/packages/shared/src/react/index.d.ts +30 -0
  78. package/dist/vue/packages/shared/src/reduced-motion.d.ts +4 -0
  79. package/dist/vue/packages/shared/src/size.d.ts +8 -0
  80. package/dist/vue/packages/shared/src/visibility.d.ts +2 -0
  81. package/dist/vue/packages/slotMachine/src/core.d.ts +1 -0
  82. package/dist/vue/packages/slotMachine/src/element.d.ts +1 -0
  83. package/dist/vue/packages/slotMachine/src/index.d.ts +3 -0
  84. package/dist/vue/packages/slotMachine/src/react.d.ts +3 -0
  85. package/dist/vue/packages/slotMachine/src/vue.d.ts +2 -0
  86. package/dist/vue/src/components/slotMachine/core/engine.d.ts +2 -0
  87. package/dist/vue/src/components/slotMachine/core/index.d.ts +2 -0
  88. package/dist/vue/src/components/slotMachine/core/types.d.ts +31 -0
  89. package/dist/vue/src/components/slotMachine/element/index.d.ts +18 -0
  90. package/dist/vue/src/components/slotMachine/index.d.ts +3 -0
  91. package/dist/vue/src/components/slotMachine/react/index.d.ts +5 -0
  92. package/dist/vue/src/vite-env.d.ts +45 -0
  93. package/dist/vue/vue.css +1 -0
  94. package/package.json +43 -11
  95. package/dist/index.cjs +0 -1
  96. package/dist/index.css +0 -1
  97. package/dist/index.d.ts +0 -3
  98. package/dist/index.js +0 -130
  99. /package/dist/{packages → core/packages}/shared/src/math.d.ts +0 -0
  100. /package/dist/{packages → core/packages}/shared/src/photo.d.ts +0 -0
  101. /package/dist/{packages → core/packages}/shared/src/pointer.d.ts +0 -0
  102. /package/dist/{packages → core/packages}/shared/src/reduced-motion.d.ts +0 -0
  103. /package/dist/{packages → core/packages}/shared/src/size.d.ts +0 -0
  104. /package/dist/{packages → core/packages}/shared/src/visibility.d.ts +0 -0
  105. /package/dist/{packages → core/packages}/slotMachine/src/index.d.ts +0 -0
@@ -0,0 +1 @@
1
+ export * from './src/components/slotMachine/core';
@@ -0,0 +1,115 @@
1
+ import { prefersReducedMotion as e } from "@cos-design/shared";
2
+ //#region src/components/slotMachine/core/engine.ts
3
+ var t = "cos-slot-machine", n = [
4
+ "🍒",
5
+ "🍋",
6
+ "🍊",
7
+ "🍇",
8
+ "⭐",
9
+ "7️⃣"
10
+ ], r = 30, i = 8, a = [
11
+ 0,
12
+ 350,
13
+ 700
14
+ ], o = 80, s = 3, c = (e) => 1 - (1 - e) ** 3, l = (e, t) => {
15
+ if (t === void 0) return Math.floor(Math.random() * e.length);
16
+ let n = e.indexOf(t);
17
+ return n >= 0 ? n : Math.floor(Math.random() * e.length);
18
+ };
19
+ function u(u, d = {}) {
20
+ let f = {
21
+ symbols: n,
22
+ spinDuration: 3e3,
23
+ spinningText: "旋转中...",
24
+ jackpotText: "🎰 大奖!",
25
+ resultPrefix: "结果:",
26
+ ...d
27
+ }, p = !1, m = !1, h = [
28
+ 0,
29
+ 0,
30
+ 0
31
+ ], g = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
32
+ b.className = `${t}__machine`;
33
+ let x = [], S = [];
34
+ for (let e = 0; e < 3; e++) {
35
+ let e = document.createElement("div");
36
+ e.className = `${t}__reel`;
37
+ let n = document.createElement("div");
38
+ n.className = `${t}__strip`;
39
+ let r = document.createElement("div");
40
+ r.className = `${t}__mask`, e.append(n, r), b.appendChild(e), x.push(e), S.push(n);
41
+ }
42
+ let C = document.createElement("button");
43
+ C.type = "button", C.className = `${t}__spin-btn`, C.dataset.testid = "slot-machine-spin";
44
+ let w = document.createElement("p");
45
+ w.className = `${t}__result`, w.hidden = !0, y.append(b, C, w), u.appendChild(y);
46
+ let T = () => f.symbols?.length ? f.symbols : n, E = () => T().length * o, D = () => Math.floor(r / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * o, k = () => f.buttonText ?? f.startText ?? "开始", A = () => {
47
+ let e = T(), n = [];
48
+ for (let t = 0; t < r; t++) n.push(...e);
49
+ for (let e of S) {
50
+ e.replaceChildren();
51
+ for (let r of n) {
52
+ let n = document.createElement("div");
53
+ n.className = `${t}__item`, n.style.height = `${o}px`, n.textContent = r, e.appendChild(n);
54
+ }
55
+ }
56
+ let i = o * s;
57
+ for (let e of x) e.style.height = `${i}px`;
58
+ }, j = () => {
59
+ S.forEach((e, t) => {
60
+ e.style.transform = `translateY(${h[t]}px)`;
61
+ });
62
+ }, M = () => {
63
+ y.className = t, C.disabled = m, C.setAttribute("aria-busy", String(m)), C.textContent = m ? f.spinningText ?? "旋转中..." : k(), g.length > 0 && !m ? (w.hidden = !1, w.textContent = g[0] === g[1] && g[1] === g[2] ? f.jackpotText ?? "🎰 大奖!" : `${f.resultPrefix ?? "结果:"} ${g.join(" ")}`) : (w.hidden = !0, w.textContent = "");
64
+ }, N = (t) => {
65
+ let n = T();
66
+ if (m || n.length === 0 || p) return;
67
+ m = !0, g = [], M();
68
+ let r = t ?? f.targetResults, s = [
69
+ 0,
70
+ 1,
71
+ 2
72
+ ].map((e) => l(n, r?.[e])), u = [...h], d = n.length * o, y = s.map((e, t) => {
73
+ let n = u[t], r = i * d, a = Math.ceil((-n + r) / d) + 1, o = O(e, a);
74
+ for (; n - o < r;) a += 1, o = O(e, a);
75
+ return o;
76
+ }), b = Math.max(f.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
77
+ v = S;
78
+ let C = () => {
79
+ if (S.cancelled || p) return;
80
+ let e = s.map((e) => n[e]);
81
+ h = s.map((e) => O(e, Math.round(D() / d))), g = e, m = !1, j(), M(), f.onSpinEnd?.(e);
82
+ };
83
+ if (e()) {
84
+ C();
85
+ return;
86
+ }
87
+ let w = (e) => {
88
+ S.cancelled || p || (h = u.map((t, n) => {
89
+ let r = e - x - a[n];
90
+ if (r < 0) return t;
91
+ let i = Math.min(r / b, 1);
92
+ return t + (y[n] - t) * c(i);
93
+ }), j(), a.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
94
+ };
95
+ _ = requestAnimationFrame(w);
96
+ };
97
+ return C.addEventListener("click", () => N()), A(), j(), M(), {
98
+ update(e) {
99
+ let t = T().join("\0");
100
+ f = {
101
+ ...f,
102
+ ...e
103
+ }, T().join("\0") !== t && A(), M();
104
+ },
105
+ spin: N,
106
+ reset: () => {
107
+ m || (g = [], M());
108
+ },
109
+ destroy() {
110
+ p || (p = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
111
+ }
112
+ };
113
+ }
114
+ //#endregion
115
+ export { u as createSlotMachine };
@@ -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,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;
@@ -6,5 +6,6 @@ export type { ElementSize } from './size';
6
6
  export { getRelativePointerPosition } from './pointer';
7
7
  export type { PointerPosition } from './pointer';
8
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';
9
+ export { resolveCanvasBoxSize } from './canvas-box';
10
+ export type { CanvasBoxSizeInput, CanvasBoxSize } from './canvas-box';
11
+ export { applyCanvasHostBox, applyBlockHostBox, setHidden, optionsFingerprint, optionsVisualChanged, } from './host-layout';
@@ -1,28 +1,13 @@
1
1
  import { CSSProperties, RefObject } from 'react';
2
- import { ElementSize } from './size';
2
+ import { ElementSize } from '../size';
3
+ export type { CanvasBoxSize, CanvasBoxSizeInput } from '../canvas-box';
4
+ export { resolveCanvasBoxSize } from '../canvas-box';
3
5
  export interface UseElementSizeOptions {
4
6
  /** 为 false 时不观察 */
5
7
  enabled?: boolean;
6
8
  }
7
9
  /** 观察元素尺寸(clientWidth / clientHeight) */
8
10
  export declare const useElementSize: <T extends Element>(ref: RefObject<T | null>, options?: UseElementSizeOptions) => ElementSize;
9
- export interface CanvasBoxSizeInput {
10
- /** 为 true 时跟随父容器尺寸(需父级有明确高度) */
11
- fill?: boolean;
12
- width?: number;
13
- height?: number;
14
- defaultWidth: number;
15
- defaultHeight: number;
16
- measured: ElementSize;
17
- }
18
- export interface CanvasBoxSize {
19
- width: number;
20
- height: number;
21
- /** 是否处于 fill 模式且尚未量到有效尺寸 */
22
- pending: boolean;
23
- }
24
- /** 根据 fill / 显式宽高 / 测量结果解析画布逻辑尺寸 */
25
- export declare const resolveCanvasBoxSize: ({ fill, width, height, defaultWidth, defaultHeight, measured }: CanvasBoxSizeInput) => CanvasBoxSize;
26
11
  export interface UseCanvasBoxOptions {
27
12
  /** 为 true 时铺满父容器(父级需有明确高度) */
28
13
  fill?: boolean;
@@ -42,4 +27,4 @@ export interface UseCanvasBoxResult {
42
27
  pending: boolean;
43
28
  }
44
29
  /** 画布/效果宿主尺寸:fill 时跟随父容器,否则用显式宽高或默认值 */
45
- export declare const useCanvasBox: ({ fill, width: widthProp, height: heightProp, defaultWidth, defaultHeight }: UseCanvasBoxOptions) => UseCanvasBoxResult;
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,3 @@
1
+ export { default } from '../../../src/components/slotMachine/react';
2
+ export { default as SlotMachine } from '../../../src/components/slotMachine/react';
3
+ export type * from '../../../src/components/slotMachine/core/types';
@@ -0,0 +1,2 @@
1
+ export { default as SlotMachine } from '../../../src/components/slotMachine/vue/SlotMachine.vue';
2
+ export type * from '../../../src/components/slotMachine/core/types';
@@ -0,0 +1,2 @@
1
+ import { SlotMachineController, SlotMachineOptions } from './types';
2
+ export declare function createSlotMachine(container: HTMLElement, initial?: SlotMachineOptions): SlotMachineController;
@@ -0,0 +1,2 @@
1
+ export { createSlotMachine } from './engine';
2
+ export type { SlotMachineController, SlotMachineHandle, SlotMachineOptions, SlotMachineProps, } from './types';
@@ -1,5 +1,4 @@
1
- import { default as React } from 'react';
2
- export interface SlotMachineProps {
1
+ export interface SlotMachineOptions {
3
2
  /** 符号列表 */
4
3
  symbols?: string[];
5
4
  /** 单列旋转时长(毫秒),默认 3000;列之间仍有错峰停轮 */
@@ -25,5 +24,8 @@ export interface SlotMachineHandle {
25
24
  /** 清除结果文案 */
26
25
  reset: () => void;
27
26
  }
28
- declare const SlotMachine: React.ForwardRefExoticComponent<SlotMachineProps & React.RefAttributes<SlotMachineHandle>>;
29
- export default SlotMachine;
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,3 @@
1
+ export { default } from './react';
2
+ export { default as SlotMachine } from './react';
3
+ export type * from './core/types';
@@ -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;
@@ -1,5 +1,11 @@
1
1
  /// <reference types="vite/client" />
2
2
 
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue';
5
+ const component: DefineComponent<object, object, unknown>;
6
+ export default component;
7
+ }
8
+
3
9
  declare module '*.module.less' {
4
10
  const classes: { readonly [key: string]: string };
5
11
  export default classes;
@@ -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}
@@ -0,0 +1 @@
1
+ export * from './src/components/slotMachine/element';
@@ -0,0 +1,180 @@
1
+ import { prefersReducedMotion as e } from "@cos-design/shared";
2
+ import './element.css';//#region src/components/slotMachine/core/engine.ts
3
+ var t = "cos-slot-machine", n = [
4
+ "🍒",
5
+ "🍋",
6
+ "🍊",
7
+ "🍇",
8
+ "⭐",
9
+ "7️⃣"
10
+ ], r = 30, i = 8, a = [
11
+ 0,
12
+ 350,
13
+ 700
14
+ ], o = 80, s = 3, c = (e) => 1 - (1 - e) ** 3, l = (e, t) => {
15
+ if (t === void 0) return Math.floor(Math.random() * e.length);
16
+ let n = e.indexOf(t);
17
+ return n >= 0 ? n : Math.floor(Math.random() * e.length);
18
+ };
19
+ function u(u, d = {}) {
20
+ let f = {
21
+ symbols: n,
22
+ spinDuration: 3e3,
23
+ spinningText: "旋转中...",
24
+ jackpotText: "🎰 大奖!",
25
+ resultPrefix: "结果:",
26
+ ...d
27
+ }, p = !1, m = !1, h = [
28
+ 0,
29
+ 0,
30
+ 0
31
+ ], g = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
32
+ b.className = `${t}__machine`;
33
+ let x = [], S = [];
34
+ for (let e = 0; e < 3; e++) {
35
+ let e = document.createElement("div");
36
+ e.className = `${t}__reel`;
37
+ let n = document.createElement("div");
38
+ n.className = `${t}__strip`;
39
+ let r = document.createElement("div");
40
+ r.className = `${t}__mask`, e.append(n, r), b.appendChild(e), x.push(e), S.push(n);
41
+ }
42
+ let C = document.createElement("button");
43
+ C.type = "button", C.className = `${t}__spin-btn`, C.dataset.testid = "slot-machine-spin";
44
+ let w = document.createElement("p");
45
+ w.className = `${t}__result`, w.hidden = !0, y.append(b, C, w), u.appendChild(y);
46
+ let T = () => f.symbols?.length ? f.symbols : n, E = () => T().length * o, D = () => Math.floor(r / 2) * E(), O = (e, t) => -(e - 1 + t * T().length) * o, k = () => f.buttonText ?? f.startText ?? "开始", A = () => {
47
+ let e = T(), n = [];
48
+ for (let t = 0; t < r; t++) n.push(...e);
49
+ for (let e of S) {
50
+ e.replaceChildren();
51
+ for (let r of n) {
52
+ let n = document.createElement("div");
53
+ n.className = `${t}__item`, n.style.height = `${o}px`, n.textContent = r, e.appendChild(n);
54
+ }
55
+ }
56
+ let i = o * s;
57
+ for (let e of x) e.style.height = `${i}px`;
58
+ }, j = () => {
59
+ S.forEach((e, t) => {
60
+ e.style.transform = `translateY(${h[t]}px)`;
61
+ });
62
+ }, M = () => {
63
+ y.className = t, C.disabled = m, C.setAttribute("aria-busy", String(m)), C.textContent = m ? f.spinningText ?? "旋转中..." : k(), g.length > 0 && !m ? (w.hidden = !1, w.textContent = g[0] === g[1] && g[1] === g[2] ? f.jackpotText ?? "🎰 大奖!" : `${f.resultPrefix ?? "结果:"} ${g.join(" ")}`) : (w.hidden = !0, w.textContent = "");
64
+ }, N = (t) => {
65
+ let n = T();
66
+ if (m || n.length === 0 || p) return;
67
+ m = !0, g = [], M();
68
+ let r = t ?? f.targetResults, s = [
69
+ 0,
70
+ 1,
71
+ 2
72
+ ].map((e) => l(n, r?.[e])), u = [...h], d = n.length * o, y = s.map((e, t) => {
73
+ let n = u[t], r = i * d, a = Math.ceil((-n + r) / d) + 1, o = O(e, a);
74
+ for (; n - o < r;) a += 1, o = O(e, a);
75
+ return o;
76
+ }), b = Math.max(f.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
77
+ v = S;
78
+ let C = () => {
79
+ if (S.cancelled || p) return;
80
+ let e = s.map((e) => n[e]);
81
+ h = s.map((e) => O(e, Math.round(D() / d))), g = e, m = !1, j(), M(), f.onSpinEnd?.(e);
82
+ };
83
+ if (e()) {
84
+ C();
85
+ return;
86
+ }
87
+ let w = (e) => {
88
+ S.cancelled || p || (h = u.map((t, n) => {
89
+ let r = e - x - a[n];
90
+ if (r < 0) return t;
91
+ let i = Math.min(r / b, 1);
92
+ return t + (y[n] - t) * c(i);
93
+ }), j(), a.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
94
+ };
95
+ _ = requestAnimationFrame(w);
96
+ };
97
+ return C.addEventListener("click", () => N()), A(), j(), M(), {
98
+ update(e) {
99
+ let t = T().join("\0");
100
+ f = {
101
+ ...f,
102
+ ...e
103
+ }, T().join("\0") !== t && A(), M();
104
+ },
105
+ spin: N,
106
+ reset: () => {
107
+ m || (g = [], M());
108
+ },
109
+ destroy() {
110
+ p || (p = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
111
+ }
112
+ };
113
+ }
114
+ //#endregion
115
+ //#region src/components/slotMachine/element/index.ts
116
+ var d = "cos-slot-machine";
117
+ function f(e) {
118
+ let t = {};
119
+ if (e.hasAttribute("start-text") && (t.startText = e.getAttribute("start-text") ?? void 0), e.hasAttribute("button-text") && (t.buttonText = e.getAttribute("button-text") ?? void 0), e.hasAttribute("spinning-text") && (t.spinningText = e.getAttribute("spinning-text") ?? void 0), e.hasAttribute("jackpot-text") && (t.jackpotText = e.getAttribute("jackpot-text") ?? void 0), e.hasAttribute("result-prefix") && (t.resultPrefix = e.getAttribute("result-prefix") ?? void 0), e.hasAttribute("spin-duration") && (t.spinDuration = Number(e.getAttribute("spin-duration"))), e.hasAttribute("symbols")) try {
120
+ t.symbols = JSON.parse(e.getAttribute("symbols") ?? "null");
121
+ } catch {}
122
+ let n = e._symbols;
123
+ if (n !== void 0 && (t.symbols = n), e.hasAttribute("target-results")) try {
124
+ t.targetResults = JSON.parse(e.getAttribute("target-results") ?? "null");
125
+ } catch {}
126
+ let r = e._targetResults;
127
+ return r !== void 0 && (t.targetResults = r), t.onSpinEnd = (...t) => {
128
+ e.dispatchEvent(new CustomEvent("spin-end", {
129
+ detail: t.length <= 1 ? t[0] : t,
130
+ bubbles: !0
131
+ }));
132
+ }, t;
133
+ }
134
+ var p = class extends HTMLElement {
135
+ ctrl = null;
136
+ _symbols;
137
+ get symbols() {
138
+ return this._symbols;
139
+ }
140
+ set symbols(e) {
141
+ this._symbols = e, this.ctrl?.update(f(this));
142
+ }
143
+ _targetResults;
144
+ get targetResults() {
145
+ return this._targetResults;
146
+ }
147
+ set targetResults(e) {
148
+ this._targetResults = e, this.ctrl?.update(f(this));
149
+ }
150
+ static get observedAttributes() {
151
+ return [
152
+ "symbols",
153
+ "spin-duration",
154
+ "target-results",
155
+ "start-text",
156
+ "button-text",
157
+ "spinning-text",
158
+ "jackpot-text",
159
+ "result-prefix"
160
+ ];
161
+ }
162
+ connectedCallback() {
163
+ this.ctrl = u(this, f(this));
164
+ }
165
+ disconnectedCallback() {
166
+ this.ctrl?.destroy(), this.ctrl = null;
167
+ }
168
+ attributeChangedCallback() {
169
+ this.ctrl?.update(f(this));
170
+ }
171
+ spin(e) {
172
+ return this.ctrl?.spin(e);
173
+ }
174
+ reset() {
175
+ return this.ctrl?.reset();
176
+ }
177
+ };
178
+ typeof customElements < "u" && !customElements.get("cos-slot-machine") && customElements.define(d, p);
179
+ //#endregion
180
+ export { p as CosSlotMachineElement, d as TAG };
@@ -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,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,11 @@
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';
@@ -0,0 +1,2 @@
1
+ export declare const clamp: (value: number, min: number, max: number) => number;
2
+ export declare const lerp: (a: number, b: number, t: number) => number;
@@ -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,4 @@
1
+ /** 当前是否偏好减少动效 */
2
+ export declare const prefersReducedMotion: () => boolean;
3
+ /** 监听 prefers-reduced-motion 变化;返回取消订阅函数 */
4
+ export declare const bindPrefersReducedMotion: (onChange: (reduced: boolean) => void) => () => void;
@@ -0,0 +1,8 @@
1
+ export interface ElementSize {
2
+ width: number;
3
+ height: number;
4
+ }
5
+ /** 观察元素内容尺寸;返回取消订阅函数 */
6
+ export declare const observeElementSize: (element: Element, onChange: (size: ElementSize) => void, options?: {
7
+ box?: ResizeObserverBoxOptions;
8
+ }) => () => void;
@@ -0,0 +1,2 @@
1
+ /** 注册 visibilitychange,页面隐藏时暂停动画循环 */
2
+ export declare const bindVisibilityPause: (onChange: (paused: boolean) => void) => () => void;
@@ -0,0 +1 @@
1
+ export * from '../../../src/components/slotMachine/core';
@@ -0,0 +1 @@
1
+ export * from '../../../src/components/slotMachine/element';
@@ -0,0 +1,3 @@
1
+ export { default } from '../../../src/components/slotMachine';
2
+ export { default as SlotMachine } from '../../../src/components/slotMachine';
3
+ export type * from '../../../src/components/slotMachine';
@@ -0,0 +1,3 @@
1
+ export { default } from '../../../src/components/slotMachine/react';
2
+ export { default as SlotMachine } from '../../../src/components/slotMachine/react';
3
+ export type * from '../../../src/components/slotMachine/core/types';
@@ -0,0 +1,2 @@
1
+ export { default as SlotMachine } from '../../../src/components/slotMachine/vue/SlotMachine.vue';
2
+ export type * from '../../../src/components/slotMachine/core/types';