@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,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';
@@ -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,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;
@@ -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
+ }
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./react.css');let e=require("react"),t=require("@cos-design/shared"),n=require("react/jsx-runtime");var r=`cos-slot-machine`,i=[`🍒`,`🍋`,`🍊`,`🍇`,`⭐`,`7️⃣`],a=30,o=8,s=[0,350,700],c=80,l=3,u=e=>1-(1-e)**3,d=(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)};function f(e,n={}){let f={symbols:i,spinDuration:3e3,spinningText:`旋转中...`,jackpotText:`🎰 大奖!`,resultPrefix:`结果:`,...n},p=!1,m=!1,h=[0,0,0],g=[],_=0,v=null,y=document.createElement(`div`),b=document.createElement(`div`);b.className=`${r}__machine`;let x=[],S=[];for(let e=0;e<3;e++){let e=document.createElement(`div`);e.className=`${r}__reel`;let t=document.createElement(`div`);t.className=`${r}__strip`;let n=document.createElement(`div`);n.className=`${r}__mask`,e.append(t,n),b.appendChild(e),x.push(e),S.push(t)}let C=document.createElement(`button`);C.type=`button`,C.className=`${r}__spin-btn`,C.dataset.testid=`slot-machine-spin`;let w=document.createElement(`p`);w.className=`${r}__result`,w.hidden=!0,y.append(b,C,w),e.appendChild(y);let T=()=>f.symbols?.length?f.symbols:i,E=()=>T().length*c,D=()=>Math.floor(a/2)*E(),O=(e,t)=>-(e-1+t*T().length)*c,k=()=>f.buttonText??f.startText??`开始`,A=()=>{let e=T(),t=[];for(let n=0;n<a;n++)t.push(...e);for(let e of S){e.replaceChildren();for(let n of t){let t=document.createElement(`div`);t.className=`${r}__item`,t.style.height=`${c}px`,t.textContent=n,e.appendChild(t)}}let n=c*l;for(let e of x)e.style.height=`${n}px`},j=()=>{S.forEach((e,t)=>{e.style.transform=`translateY(${h[t]}px)`})},M=()=>{y.className=r,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=``)},N=e=>{let n=T();if(m||n.length===0||p)return;m=!0,g=[],M();let r=e??f.targetResults,i=[0,1,2].map(e=>d(n,r?.[e])),a=[...h],l=n.length*c,y=i.map((e,t)=>{let n=a[t],r=o*l,i=Math.ceil((-n+r)/l)+1,s=O(e,i);for(;n-s<r;)i+=1,s=O(e,i);return s}),b=Math.max(f.spinDuration??3e3,16),x=performance.now(),S={cancelled:!1};v=S;let C=()=>{if(S.cancelled||p)return;let e=i.map(e=>n[e]);h=i.map(e=>O(e,Math.round(D()/l))),g=e,m=!1,j(),M(),f.onSpinEnd?.(e)};if((0,t.prefersReducedMotion)()){C();return}let w=e=>{S.cancelled||p||(h=a.map((t,n)=>{let r=e-x-s[n];if(r<0)return t;let i=Math.min(r/b,1);return t+(y[n]-t)*u(i)}),j(),s.every(t=>e-x-t>=b)?C():_=requestAnimationFrame(w))};_=requestAnimationFrame(w)};return C.addEventListener(`click`,()=>N()),A(),j(),M(),{update(e){let t=T().join(`\0`);f={...f,...e},T().join(`\0`)!==t&&A(),M()},spin:N,reset:()=>{m||(g=[],M())},destroy(){p||(p=!0,v&&(v.cancelled=!0),cancelAnimationFrame(_),y.remove())}}}var p=(0,e.forwardRef)((r,i)=>{let a=(0,e.useRef)(null),o=(0,e.useRef)(null),s=(0,e.useRef)(r);s.current=r;let c=(0,e.useMemo)(()=>(0,t.optionsFingerprint)(r),[r]);return(0,e.useImperativeHandle)(i,()=>({spin:(...e)=>o.current?.spin?.(...e),reset:(...e)=>o.current?.reset?.(...e)})),(0,e.useEffect)(()=>{let e=a.current;if(!e)return;let t=f(e,s.current);return o.current=t,()=>{t.destroy(),o.current=null}},[]),(0,e.useEffect)(()=>{o.current?.update(s.current)},[c]),(0,n.jsx)(`div`,{ref:a,className:`cos-slotMachine-host`})});p.displayName=`SlotMachine`,exports.SlotMachine=p,exports.default=p;
@@ -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,141 @@
1
+ import { forwardRef as e, useEffect as t, useImperativeHandle as n, useMemo as r, useRef as i } from "react";
2
+ import { optionsFingerprint as a, prefersReducedMotion as o } from "@cos-design/shared";
3
+ import { jsx as s } from "react/jsx-runtime";
4
+ import './react.css';//#region src/components/slotMachine/core/engine.ts
5
+ var c = "cos-slot-machine", l = [
6
+ "🍒",
7
+ "🍋",
8
+ "🍊",
9
+ "🍇",
10
+ "⭐",
11
+ "7️⃣"
12
+ ], u = 30, d = 8, f = [
13
+ 0,
14
+ 350,
15
+ 700
16
+ ], p = 80, m = 3, h = (e) => 1 - (1 - e) ** 3, g = (e, t) => {
17
+ if (t === void 0) return Math.floor(Math.random() * e.length);
18
+ let n = e.indexOf(t);
19
+ return n >= 0 ? n : Math.floor(Math.random() * e.length);
20
+ };
21
+ function _(e, t = {}) {
22
+ let n = {
23
+ symbols: l,
24
+ spinDuration: 3e3,
25
+ spinningText: "旋转中...",
26
+ jackpotText: "🎰 大奖!",
27
+ resultPrefix: "结果:",
28
+ ...t
29
+ }, r = !1, i = !1, a = [
30
+ 0,
31
+ 0,
32
+ 0
33
+ ], s = [], _ = 0, v = null, y = document.createElement("div"), b = document.createElement("div");
34
+ b.className = `${c}__machine`;
35
+ let x = [], S = [];
36
+ for (let e = 0; e < 3; e++) {
37
+ let e = document.createElement("div");
38
+ e.className = `${c}__reel`;
39
+ let t = document.createElement("div");
40
+ t.className = `${c}__strip`;
41
+ let n = document.createElement("div");
42
+ n.className = `${c}__mask`, e.append(t, n), b.appendChild(e), x.push(e), S.push(t);
43
+ }
44
+ let C = document.createElement("button");
45
+ C.type = "button", C.className = `${c}__spin-btn`, C.dataset.testid = "slot-machine-spin";
46
+ let w = document.createElement("p");
47
+ w.className = `${c}__result`, w.hidden = !0, y.append(b, C, w), e.appendChild(y);
48
+ 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 = () => {
49
+ let e = T(), t = [];
50
+ for (let n = 0; n < u; n++) t.push(...e);
51
+ for (let e of S) {
52
+ e.replaceChildren();
53
+ for (let n of t) {
54
+ let t = document.createElement("div");
55
+ t.className = `${c}__item`, t.style.height = `${p}px`, t.textContent = n, e.appendChild(t);
56
+ }
57
+ }
58
+ let n = p * m;
59
+ for (let e of x) e.style.height = `${n}px`;
60
+ }, j = () => {
61
+ S.forEach((e, t) => {
62
+ e.style.transform = `translateY(${a[t]}px)`;
63
+ });
64
+ }, M = () => {
65
+ y.className = c, C.disabled = i, C.setAttribute("aria-busy", String(i)), C.textContent = i ? n.spinningText ?? "旋转中..." : k(), s.length > 0 && !i ? (w.hidden = !1, w.textContent = s[0] === s[1] && s[1] === s[2] ? n.jackpotText ?? "🎰 大奖!" : `${n.resultPrefix ?? "结果:"} ${s.join(" ")}`) : (w.hidden = !0, w.textContent = "");
66
+ }, N = (e) => {
67
+ let t = T();
68
+ if (i || t.length === 0 || r) return;
69
+ i = !0, s = [], M();
70
+ let c = e ?? n.targetResults, l = [
71
+ 0,
72
+ 1,
73
+ 2
74
+ ].map((e) => g(t, c?.[e])), u = [...a], m = t.length * p, y = l.map((e, t) => {
75
+ let n = u[t], r = d * m, i = Math.ceil((-n + r) / m) + 1, a = O(e, i);
76
+ for (; n - a < r;) i += 1, a = O(e, i);
77
+ return a;
78
+ }), b = Math.max(n.spinDuration ?? 3e3, 16), x = performance.now(), S = { cancelled: !1 };
79
+ v = S;
80
+ let C = () => {
81
+ if (S.cancelled || r) return;
82
+ let e = l.map((e) => t[e]);
83
+ a = l.map((e) => O(e, Math.round(D() / m))), s = e, i = !1, j(), M(), n.onSpinEnd?.(e);
84
+ };
85
+ if (o()) {
86
+ C();
87
+ return;
88
+ }
89
+ let w = (e) => {
90
+ S.cancelled || r || (a = u.map((t, n) => {
91
+ let r = e - x - f[n];
92
+ if (r < 0) return t;
93
+ let i = Math.min(r / b, 1);
94
+ return t + (y[n] - t) * h(i);
95
+ }), j(), f.every((t) => e - x - t >= b) ? C() : _ = requestAnimationFrame(w));
96
+ };
97
+ _ = requestAnimationFrame(w);
98
+ };
99
+ return C.addEventListener("click", () => N()), A(), j(), M(), {
100
+ update(e) {
101
+ let t = T().join("\0");
102
+ n = {
103
+ ...n,
104
+ ...e
105
+ }, T().join("\0") !== t && A(), M();
106
+ },
107
+ spin: N,
108
+ reset: () => {
109
+ i || (s = [], M());
110
+ },
111
+ destroy() {
112
+ r || (r = !0, v && (v.cancelled = !0), cancelAnimationFrame(_), y.remove());
113
+ }
114
+ };
115
+ }
116
+ //#endregion
117
+ //#region src/components/slotMachine/react/index.tsx
118
+ var v = e((e, o) => {
119
+ let c = i(null), l = i(null), u = i(e);
120
+ u.current = e;
121
+ let d = r(() => a(e), [e]);
122
+ return n(o, () => ({
123
+ spin: (...e) => l.current?.spin?.(...e),
124
+ reset: (...e) => l.current?.reset?.(...e)
125
+ })), t(() => {
126
+ let e = c.current;
127
+ if (!e) return;
128
+ let t = _(e, u.current);
129
+ return l.current = t, () => {
130
+ t.destroy(), l.current = null;
131
+ };
132
+ }, []), t(() => {
133
+ l.current?.update(u.current);
134
+ }, [d]), /* @__PURE__ */ s("div", {
135
+ ref: c,
136
+ className: "cos-slotMachine-host"
137
+ });
138
+ });
139
+ v.displayName = "SlotMachine";
140
+ //#endregion
141
+ export { v as SlotMachine, v as default };
@@ -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';
@@ -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,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';
@@ -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,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;
@@ -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
+ }
@@ -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';