@cos-design/slot-machine 3.5.1

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) 2021-present jiaxiantao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("react/jsx-runtime");var u={slotMachine:`cos-slotMachine-P6FyZ`,machine:`cos-machine-B066r`,reel:`cos-reel-eEpJ3`,strip:`cos-strip-L5Z-a`,item:`cos-item-WYJ6q`,mask:`cos-mask-jdrj3`,spinBtn:`cos-spinBtn-DvDE7`,result:`cos-result-dLN5b`},d=[`πŸ’`,`πŸ‹`,`🍊`,`πŸ‡`,`⭐`,`7️⃣`],f=e=>1-(1-e)**3,p=({symbols:e=d,onSpinEnd:t})=>{let[n,r]=(0,c.useState)(!1),[i,a]=(0,c.useState)([0,0,0]),[o,s]=(0,c.useState)([]),p=(0,c.useRef)(0),m=(0,c.useRef)(t),h=(0,c.useRef)(null);(0,c.useEffect)(()=>{m.current=t},[t]);let g=(0,c.useCallback)(()=>{let t=[];for(let n=0;n<20;n++)t.push(...e);return t},[e])();return(0,c.useEffect)(()=>()=>{h.current&&(h.current.cancelled=!0),cancelAnimationFrame(p.current)},[]),(0,l.jsxs)(`div`,{className:u.slotMachine,children:[(0,l.jsx)(`div`,{className:u.machine,children:[0,1,2].map(e=>(0,l.jsxs)(`div`,{className:u.reel,style:{height:240},children:[(0,l.jsx)(`div`,{className:u.strip,style:{transform:`translateY(${i[e]}px)`},children:g.map((e,t)=>(0,l.jsx)(`div`,{className:u.item,style:{height:80},children:e},t))}),(0,l.jsx)(`div`,{className:u.mask})]},e))}),(0,l.jsx)(`button`,{type:`button`,className:u.spinBtn,onClick:()=>{if(n)return;r(!0),s([]);let t=[0,1,2].map(()=>Math.floor(Math.random()*e.length)),o=t.map(t=>-(t-1+e.length*10)*80),c=[...i],l=2e3,u=[0,300,600],d=performance.now(),g={cancelled:!1};h.current=g;let _=n=>{if(!g.cancelled){if(a(c.map((e,t)=>{let r=n-d-u[t];if(r<0)return e;let i=f(Math.min(r/l,1));return e+(o[t]-e)*i})),!u.every(e=>n-d-e>=l))p.current=requestAnimationFrame(_);else if(!g.cancelled){let n=t.map(t=>e[t]);s(n),r(!1),m.current?.(n)}}};p.current=requestAnimationFrame(_)},disabled:n,children:n?`旋转中...`:`εΌ€ε§‹`}),o.length>0&&!n&&(0,l.jsx)(`p`,{className:u.result,children:o[0]===o[1]&&o[1]===o[2]?`🎰 ε€§ε₯–!`:`η»“ζžœ: ${o.join(` `)}`})]})};exports.SlotMachine=p,exports.default=p;
package/dist/index.css ADDED
@@ -0,0 +1 @@
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}
@@ -0,0 +1,3 @@
1
+ export { default } from './src/components/slotMachine/index';
2
+ export { default as SlotMachine } from './src/components/slotMachine/index';
3
+ export type * from './src/components/slotMachine/index';
package/dist/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
2
+ import { jsx as i, jsxs as a } from "react/jsx-runtime";
3
+ import './index.css';var o = {
4
+ slotMachine: "cos-slotMachine-P6FyZ",
5
+ machine: "cos-machine-B066r",
6
+ reel: "cos-reel-eEpJ3",
7
+ strip: "cos-strip-L5Z-a",
8
+ item: "cos-item-WYJ6q",
9
+ mask: "cos-mask-jdrj3",
10
+ spinBtn: "cos-spinBtn-DvDE7",
11
+ result: "cos-result-dLN5b"
12
+ }, s = [
13
+ "πŸ’",
14
+ "πŸ‹",
15
+ "🍊",
16
+ "πŸ‡",
17
+ "⭐",
18
+ "7️⃣"
19
+ ], c = (e) => 1 - (1 - e) ** 3, l = ({ symbols: l = s, onSpinEnd: u }) => {
20
+ let [d, f] = r(!1), [p, m] = r([
21
+ 0,
22
+ 0,
23
+ 0
24
+ ]), [h, g] = r([]), _ = n(0), v = n(u), y = n(null);
25
+ t(() => {
26
+ v.current = u;
27
+ }, [u]);
28
+ let b = e(() => {
29
+ let e = [];
30
+ for (let t = 0; t < 20; t++) e.push(...l);
31
+ return e;
32
+ }, [l])();
33
+ return t(() => () => {
34
+ y.current && (y.current.cancelled = !0), cancelAnimationFrame(_.current);
35
+ }, []), /* @__PURE__ */ a("div", {
36
+ className: o.slotMachine,
37
+ children: [
38
+ /* @__PURE__ */ i("div", {
39
+ className: o.machine,
40
+ children: [
41
+ 0,
42
+ 1,
43
+ 2
44
+ ].map((e) => /* @__PURE__ */ a("div", {
45
+ className: o.reel,
46
+ style: { height: 240 },
47
+ children: [/* @__PURE__ */ i("div", {
48
+ className: o.strip,
49
+ style: { transform: `translateY(${p[e]}px)` },
50
+ children: b.map((e, t) => /* @__PURE__ */ i("div", {
51
+ className: o.item,
52
+ style: { height: 80 },
53
+ children: e
54
+ }, t))
55
+ }), /* @__PURE__ */ i("div", { className: o.mask })]
56
+ }, e))
57
+ }),
58
+ /* @__PURE__ */ i("button", {
59
+ type: "button",
60
+ className: o.spinBtn,
61
+ onClick: () => {
62
+ if (d) return;
63
+ f(!0), g([]);
64
+ let e = [
65
+ 0,
66
+ 1,
67
+ 2
68
+ ].map(() => Math.floor(Math.random() * l.length)), t = e.map((e) => -(e - 1 + l.length * 10) * 80), n = [...p], r = 2e3, i = [
69
+ 0,
70
+ 300,
71
+ 600
72
+ ], a = performance.now(), o = { cancelled: !1 };
73
+ y.current = o;
74
+ let s = (u) => {
75
+ if (!o.cancelled) {
76
+ if (m(n.map((e, n) => {
77
+ let o = u - a - i[n];
78
+ if (o < 0) return e;
79
+ let s = c(Math.min(o / r, 1));
80
+ return e + (t[n] - e) * s;
81
+ })), !i.every((e) => u - a - e >= r)) _.current = requestAnimationFrame(s);
82
+ else if (!o.cancelled) {
83
+ let t = e.map((e) => l[e]);
84
+ g(t), f(!1), v.current?.(t);
85
+ }
86
+ }
87
+ };
88
+ _.current = requestAnimationFrame(s);
89
+ },
90
+ disabled: d,
91
+ children: d ? "旋转中..." : "εΌ€ε§‹"
92
+ }),
93
+ h.length > 0 && !d && /* @__PURE__ */ i("p", {
94
+ className: o.result,
95
+ children: h[0] === h[1] && h[1] === h[2] ? "🎰 ε€§ε₯–!" : `η»“ζžœ: ${h.join(" ")}`
96
+ })
97
+ ]
98
+ });
99
+ };
100
+ //#endregion
101
+ export { l as SlotMachine, l as default };
@@ -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,9 @@
1
+ import { default as React } from 'react';
2
+ export interface SlotMachineProps {
3
+ /** η¬¦ε·εˆ—θ‘¨ */
4
+ symbols?: string[];
5
+ /** ζ—‹θ½¬η»“ζŸε›žθ°ƒ */
6
+ onSpinEnd?: (results: string[]) => void;
7
+ }
8
+ declare const SlotMachine: React.FC<SlotMachineProps>;
9
+ export default SlotMachine;
@@ -0,0 +1,39 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ declare module '*.module.less' {
4
+ const classes: { readonly [key: string]: string };
5
+ export default classes;
6
+ }
7
+
8
+ declare module '*.less' {
9
+ const classes: { readonly [key: string]: string };
10
+ export default classes;
11
+ }
12
+
13
+ declare module '*.png' {
14
+ const src: string;
15
+ export default src;
16
+ }
17
+
18
+ declare module '*.jpg' {
19
+ const src: string;
20
+ export default src;
21
+ }
22
+
23
+ declare module '*.mp4' {
24
+ const src: string;
25
+ export default src;
26
+ }
27
+
28
+ declare module '*.mp3' {
29
+ const src: string;
30
+ export default src;
31
+ }
32
+
33
+ declare module '*.svg' {
34
+ import type { FC, SVGProps } from 'react';
35
+
36
+ export const ReactComponent: FC<SVGProps<SVGSVGElement>>;
37
+ const src: string;
38
+ export default src;
39
+ }
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@cos-design/slot-machine",
3
+ "version": "3.5.1",
4
+ "description": "SlotMachine component from cos-design",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "LICENSE"
24
+ ],
25
+ "sideEffects": [
26
+ "**/*.css",
27
+ "**/*.less"
28
+ ],
29
+ "keywords": [
30
+ "cos-design",
31
+ "react",
32
+ "slotMachine",
33
+ "SlotMachine"
34
+ ],
35
+ "homepage": "https://jiaxiantao.github.io/cos-design/",
36
+ "bugs": {
37
+ "url": "https://github.com/jiaxiantao/cos-design/issues"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/jiaxiantao/cos-design.git",
42
+ "directory": "packages/slotMachine"
43
+ },
44
+ "author": "jiaxiantao <jiaxiantao@souche.com>",
45
+ "license": "MIT",
46
+ "peerDependencies": {
47
+ "react": ">=18.0.0",
48
+ "react-dom": ">=18.0.0"
49
+ },
50
+ "publishConfig": {
51
+ "access": "public",
52
+ "registry": "https://registry.npmjs.org"
53
+ }
54
+ }