cos-design 2.0.0 → 2.2.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/CHANGELOG.md CHANGED
@@ -5,6 +5,32 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.2.0] - 2026-06-18
9
+
10
+ ### Changed
11
+
12
+ - React 升级至 19,Vite 升级至 8
13
+ - TypeScript、ESLint 9(flat config)、Stylelint 17 等依赖升级至最新稳定版
14
+ - react-router 升级至 v7
15
+ - 最低 Node.js 版本要求提升至 20
16
+
17
+ ## [2.1.0] - 2026-06-18
18
+
19
+ ### Added
20
+
21
+ - `Fireworks` 烟花特效组件(Canvas,支持自动燃放与点击触发)
22
+ - `MatrixRain` 黑客帝国数字雨背景组件
23
+ - `ParticleNetwork` 粒子连线网络组件(鼠标互动)
24
+ - `Typewriter` 终端风格打字机文字组件
25
+ - `NeonText` 霓虹灯发光文字组件
26
+ - `WaveButton` 波纹扩散按钮组件
27
+ - 开发环境首页组件导航,路由由配置自动生成
28
+
29
+ ### Changed
30
+
31
+ - 重设计 `Turntable` 为可交互抽奖转盘
32
+ - 修复 `CanvasClock` 画布时钟渲染错位问题
33
+
8
34
  ## [2.0.0] - 2026-06-18
9
35
 
10
36
  ### Changed
@@ -26,4 +52,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
52
  - Webpack 及相关 loader 依赖
27
53
  - UMD 格式产物
28
54
 
55
+ [2.2.0]: https://github.com/jiaxiantao/cos-design/compare/v2.1.0...v2.2.0
56
+ [2.1.0]: https://github.com/jiaxiantao/cos-design/compare/v2.0.0...v2.1.0
29
57
  [2.0.0]: https://github.com/jiaxiantao/cos-design/compare/v1.7.5...v2.0.0
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm version](https://img.shields.io/npm/v/cos-design.svg)](https://www.npmjs.com/package/cos-design)
5
5
  [![license](https://img.shields.io/npm/l/cos-design.svg)](https://github.com/jiaxiantao/cos-design/blob/main/LICENSE)
6
6
 
7
- 基于 React 18 + Vite 6 + TypeScript 5 的 React 组件库。
7
+ 基于 React 19 + Vite 8 + TypeScript 5 的 React 组件库。
8
8
 
9
9
  ## 特性
10
10
 
@@ -35,16 +35,22 @@ function App() {
35
35
 
36
36
  ## 组件
37
37
 
38
- | 组件 | 说明 |
39
- | ------------- | --------------- |
40
- | `CanvasClock` | Canvas 画布时钟 |
41
- | `Charge` | 充电特效 |
42
- | `ReturnCity` | 回城特效 |
43
- | `Turntable` | 转盘 |
38
+ | 组件 | 说明 |
39
+ | ----------------- | -------------------- |
40
+ | `CanvasClock` | Canvas 画布时钟 |
41
+ | `Charge` | 充电特效 |
42
+ | `ReturnCity` | 回城特效 |
43
+ | `Turntable` | 抽奖转盘 |
44
+ | `Fireworks` | 烟花特效(点击燃放) |
45
+ | `MatrixRain` | 黑客帝国数字雨 |
46
+ | `ParticleNetwork` | 粒子连线网络 |
47
+ | `Typewriter` | 打字机文字效果 |
48
+ | `NeonText` | 霓虹灯发光文字 |
49
+ | `WaveButton` | 波纹扩散按钮 |
44
50
 
45
51
  ## 本地开发
46
52
 
47
- > **要求 Node.js >= 18**(项目含 `.nvmrc`,推荐使用 Node 20)
53
+ > **要求 Node.js >= 20**(项目含 `.nvmrc`,推荐使用 Node 22)
48
54
 
49
55
  ### 第一步:切换 Node 版本
50
56
 
@@ -70,15 +76,7 @@ npm run setup
70
76
  npx --yes pnpm@9 dev
71
77
  ```
72
78
 
73
- 访问 `http://localhost:4000` 进入首页,点击卡片跳转到对应组件演示:
74
-
75
- | 路由 | 组件 |
76
- | -------------- | ---------------- |
77
- | `/` | 首页(组件导航) |
78
- | `/canvasClock` | 画布时钟 |
79
- | `/charge` | 充电特效 |
80
- | `/returnCity` | 回城特效 |
81
- | `/turntable` | 转盘 |
79
+ 访问 `http://localhost:4000` 进入首页,点击卡片跳转到对应组件演示(共 10 个组件)。
82
80
 
83
81
  ## 脚本
84
82
 
@@ -103,6 +101,35 @@ which pnpm # 确认路径不在 corepack 下
103
101
  pnpm -v
104
102
  ```
105
103
 
104
+ ## 自动发布(CI/CD)
105
+
106
+ 推送到 `master` 分支后,GitHub Actions 会自动执行 lint、构建,并将**新版本**发布到 [npm](https://www.npmjs.com/package/cos-design)。
107
+
108
+ ### 首次配置(仅需一次)
109
+
110
+ 1. 打开 [npm Access Tokens](https://www.npmjs.com/settings/jiaxiantao/tokens)
111
+ 2. 创建 **Granular Access Token**:
112
+ - Permissions: Packages → **Read and write**
113
+ - 勾选 **Bypass 2FA for publish**(自动化发布必须)
114
+ 3. 打开 GitHub 仓库 → **Settings** → **Secrets and variables** → **Actions**
115
+ 4. 新建 Secret:`NPM_TOKEN`,值为上一步的 token
116
+
117
+ ### 发布新版本
118
+
119
+ ```bash
120
+ # 1. 更新 package.json 中的 version(如 2.2.0)
121
+ # 2. 更新 CHANGELOG.md
122
+ # 3. 提交并推送
123
+ git add .
124
+ git commit -m "chore: release v2.2.0"
125
+ git push origin master
126
+
127
+ # 4.(可选)打 tag
128
+ git tag v2.2.0 && git push origin v2.2.0
129
+ ```
130
+
131
+ 推送后可在 [Actions](https://github.com/jiaxiantao/cos-design/actions) 查看发布进度。若 npm 上已存在相同版本号,会自动跳过发布。
132
+
106
133
  ## 参与贡献
107
134
 
108
135
  欢迎提交 Issue 与 Pull Request,请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md)。
@@ -0,0 +1,7 @@
1
+ import { default as React } from 'react';
2
+ export interface CanvasClockProps {
3
+ width?: number;
4
+ height?: number;
5
+ }
6
+ declare const CanvasClock: React.FC<CanvasClockProps>;
7
+ export default CanvasClock;
@@ -0,0 +1,6 @@
1
+ import { default as React } from 'react';
2
+ export interface ChargeProps {
3
+ initQuantity?: number;
4
+ }
5
+ declare const Charge: (props: ChargeProps) => React.ReactElement;
6
+ export default Charge;
@@ -0,0 +1,9 @@
1
+ import { default as React } from 'react';
2
+ export interface FireworksProps {
3
+ width?: number;
4
+ height?: number;
5
+ /** 是否自动燃放,默认 true */
6
+ auto?: boolean;
7
+ }
8
+ declare const Fireworks: React.FC<FireworksProps>;
9
+ export default Fireworks;
@@ -0,0 +1,20 @@
1
+ export { default as CanvasClock } from './canvasClock';
2
+ export type { CanvasClockProps } from './canvasClock';
3
+ export { default as Charge } from './charge';
4
+ export type { ChargeProps } from './charge';
5
+ export { default as Fireworks } from './fireworks';
6
+ export type { FireworksProps } from './fireworks';
7
+ export { default as MatrixRain } from './matrixRain';
8
+ export type { MatrixRainProps } from './matrixRain';
9
+ export { default as NeonText } from './neonText';
10
+ export type { NeonTextProps } from './neonText';
11
+ export { default as ParticleNetwork } from './particleNetwork';
12
+ export type { ParticleNetworkProps } from './particleNetwork';
13
+ export { default as ReturnCity } from './returnCity';
14
+ export type { ReturnCityProps } from './returnCity';
15
+ export type { TurntablePrize, TurntableProps } from './turntable';
16
+ export { default as Turntable } from './turntable';
17
+ export { default as Typewriter } from './typewriter';
18
+ export type { TypewriterProps } from './typewriter';
19
+ export { default as WaveButton } from './waveButton';
20
+ export type { WaveButtonProps } from './waveButton';
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ export interface MatrixRainProps {
3
+ width?: number;
4
+ height?: number;
5
+ /** 列密度 0~1,默认 0.6 */
6
+ density?: number;
7
+ /** 主色调 */
8
+ color?: string;
9
+ }
10
+ declare const MatrixRain: React.FC<MatrixRainProps>;
11
+ export default MatrixRain;
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ export interface NeonTextProps {
3
+ /** 显示文字 */
4
+ text?: string;
5
+ /** 霓虹主色 */
6
+ color?: string;
7
+ /** 字号 */
8
+ fontSize?: number;
9
+ /** 是否闪烁 */
10
+ flicker?: boolean;
11
+ }
12
+ declare const NeonText: React.FC<NeonTextProps>;
13
+ export default NeonText;
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ export interface ParticleNetworkProps {
3
+ width?: number;
4
+ height?: number;
5
+ /** 粒子数量 */
6
+ particleCount?: number;
7
+ /** 连线距离 */
8
+ linkDistance?: number;
9
+ /** 粒子颜色 */
10
+ color?: string;
11
+ }
12
+ declare const ParticleNetwork: React.FC<ParticleNetworkProps>;
13
+ export default ParticleNetwork;
@@ -0,0 +1,6 @@
1
+ import { default as React } from 'react';
2
+ export interface ReturnCityProps {
3
+ shining?: number;
4
+ }
5
+ declare const ReturnCity: React.FC<ReturnCityProps>;
6
+ export default ReturnCity;
@@ -0,0 +1,21 @@
1
+ import { default as React } from 'react';
2
+ export interface TurntablePrize {
3
+ label: string;
4
+ color?: string;
5
+ }
6
+ export interface TurntableProps {
7
+ /** 奖品列表 */
8
+ prizes?: TurntablePrize[];
9
+ /** 转盘直径,默认 360 */
10
+ size?: number;
11
+ /** 旋转动画时长(毫秒),默认 4000 */
12
+ spinDuration?: number;
13
+ /** 旋转圈数,默认 5 */
14
+ spinRounds?: number;
15
+ /** 抽奖按钮文案 */
16
+ buttonText?: string;
17
+ /** 旋转结束回调 */
18
+ onSpinEnd?: (prize: TurntablePrize, index: number) => void;
19
+ }
20
+ declare const Turntable: React.FC<TurntableProps>;
21
+ export default Turntable;
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ export interface TypewriterProps {
3
+ /** 轮播文案列表 */
4
+ texts?: string[];
5
+ /** 打字速度(毫秒/字符) */
6
+ speed?: number;
7
+ /** 删除速度(毫秒/字符) */
8
+ deleteSpeed?: number;
9
+ /** 完整展示后的停顿(毫秒) */
10
+ pause?: number;
11
+ }
12
+ declare const Typewriter: React.FC<TypewriterProps>;
13
+ export default Typewriter;
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ export interface WaveButtonProps {
3
+ /** 按钮文字 */
4
+ text?: string;
5
+ /** 点击回调 */
6
+ onClick?: () => void;
7
+ /** 主色 */
8
+ color?: string;
9
+ }
10
+ declare const WaveButton: React.FC<WaveButtonProps>;
11
+ export default WaveButton;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const s=require("react/jsx-runtime"),d=require("react"),L="cos-canvasClock",Q="cos-canvasTarget",D={canvasClock:L,canvasTarget:Q},U=({width:r=400,height:b=400})=>{const g=d.useRef(null),a=Math.min(r,b),o=a/2-16,l=a/2,f=d.useCallback(t=>{t.clearRect(0,0,a,a),t.save(),t.translate(l,l),t.beginPath(),t.arc(0,0,o,0,Math.PI*2),t.fillStyle="#fff",t.fill(),t.strokeStyle="#d1d5db",t.lineWidth=2,t.stroke();for(let u=0;u<60;u++){const m=u/60*Math.PI*2,n=o-(u%5===0?14:8);t.beginPath(),t.moveTo(Math.cos(m)*n,Math.sin(m)*n),t.lineTo(Math.cos(m)*o,Math.sin(m)*o),t.strokeStyle=u%5===0?"#374151":"#9ca3af",t.lineWidth=u%5===0?2:1,t.stroke()}t.fillStyle="#111827",t.font=`bold ${Math.floor(a/22)}px system-ui, sans-serif`,t.textAlign="center",t.textBaseline="middle";for(let u=1;u<=12;u++){const m=u/12*Math.PI*2-Math.PI/2,n=o-32;t.fillText(String(u),Math.cos(m)*n,Math.sin(m)*n)}const c=new Date,v=c.getHours()%12,p=c.getMinutes(),M=c.getSeconds(),k=c.getMilliseconds(),x=(u,m,n,i,e)=>{t.save(),t.rotate(u),t.beginPath(),t.moveTo(0,n),t.lineTo(m,0),t.lineTo(0,-n),t.closePath(),t.fillStyle=i,t.shadowColor=e,t.shadowBlur=4,t.fill(),t.restore()},h=(v+p/60)/12*Math.PI*2-Math.PI/2,F=(p+M/60)/60*Math.PI*2-Math.PI/2,R=(M+k/1e3)/60*Math.PI*2-Math.PI/2;x(h,o*.5,4,"#111827","rgb(0 0 0 / 40%)"),x(F,o*.72,3,"#1e80ff","rgb(30 128 255 / 40%)"),x(R,o*.85,2,"#e9686b","rgb(233 104 107 / 40%)"),t.beginPath(),t.arc(0,0,5,0,Math.PI*2),t.fillStyle="#111827",t.fill(),t.restore()},[l,o,a]);return d.useEffect(()=>{const t=g.current;if(!t)return;const c=window.devicePixelRatio||1;t.width=a*c,t.height=a*c;const v=t.getContext("2d");if(!v)return;v.setTransform(c,0,0,c,0,0);let p=0;const M=()=>{f(v),p=requestAnimationFrame(M)};return M(),()=>cancelAnimationFrame(p)},[f,a]),s.jsx("div",{className:D.canvasClock,style:{width:a,height:a},children:s.jsx("canvas",{ref:g,className:D.canvasTarget,style:{width:a,height:a}})})},Z="cos-chargeContainer",_="cos-contrast",G="cos-text",Y="cos-circle",J="cos-button",T={chargeContainer:Z,contrast:_,text:G,circle:Y,button:J},K=r=>{const{initQuantity:b=0}=r,[g,a]=d.useState(b);return d.useEffect(()=>{let o=g;setInterval(()=>{o=Number(Number(o+=.01).toFixed(2)),a(o)},500)},[]),s.jsx("div",{className:T.chargeContainer,children:s.jsxs("div",{className:T.contrast,children:[s.jsxs("div",{className:T.text,children:[g?g.toString().padEnd(4,"0"):0,"%"]}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("span",{}),s.jsx("div",{className:T.circle}),s.jsx("div",{className:T.button})]})})},V="cos-returnCityContainer",X="cos-star",z="cos-glassWrap",tt="cos-glassItem",W={returnCityContainer:V,star:X,glassWrap:z,glassItem:tt},et=()=>{const r=(g,a)=>{for(let o=0;o<a;o++)setTimeout(function(){const l=document.createElement("div");l.className=W.star;const f=document.body.clientWidth,t=document.body.clientHeight,c=Math.random()*f+"px",v=Math.random()*t+"px";l.style.top=v,l.style.left=c,g.append(l)},Math.random()*2e3)},b=()=>{const a="150px",o=document.getElementById("glassWrap");if(o)for(let l=0;l<6;l++){const f=document.createElement("div");f.className=W.glassItem,f.style.transform=`rotateY(${l*60}deg) translateZ(${a})`,o.appendChild(f),setTimeout(()=>{f.style.top="0px",f.style.opacity="1"},l*300)}};return d.useEffect(()=>{const g=document.getElementById("returnCityContainer");g&&r(g,document.documentElement.clientWidth/20),b()},[]),s.jsx("div",{id:"returnCityContainer",className:W.returnCityContainer,children:s.jsx("div",{id:"glassWrap",className:W.glassWrap})})},st="cos-turntable",nt="cos-wheelWrap",at="cos-canvas",ot="cos-pointer",rt="cos-spinBtn",lt="cos-result",w={turntable:st,wheelWrap:nt,canvas:at,pointer:ot,spinBtn:rt,result:lt},O=["#FF6B6B","#4ECDC4","#FFE66D","#A78BFA","#60A5FA","#F472B6","#34D399","#FB923C"],ct=[{label:"一等奖"},{label:"二等奖"},{label:"三等奖"},{label:"谢谢参与"},{label:"优惠券"},{label:"再来一次"}],it=r=>1-Math.pow(1-r,3),ht=({prizes:r=ct,size:b=360,spinDuration:g=4e3,spinRounds:a=5,buttonText:o="开始抽奖",onSpinEnd:l})=>{const f=d.useRef(null),t=d.useRef(0),c=d.useRef(0),v=d.useRef(1),[p,M]=d.useState(!1),[k,x]=d.useState(null),h=b+48,F=(n,i)=>i.color??O[n%O.length],R=d.useCallback(n=>{const i=f.current;if(!i)return;const e=i.getContext("2d");if(!e)return;const C=h/2,P=b/2,N=Math.PI*2/r.length;e.clearRect(0,0,h,h),e.save(),e.translate(C,C),e.rotate(n),r.forEach((y,j)=>{const I=j*N-Math.PI/2,S=I+N,B=F(j,y);e.beginPath(),e.moveTo(0,0),e.arc(0,0,P,I,S),e.closePath(),e.fillStyle=B,e.fill(),e.strokeStyle="rgb(255 255 255 / 35%)",e.lineWidth=2,e.stroke(),e.save(),e.rotate(I+N/2),e.textAlign="right",e.fillStyle="#fff",e.font=`bold ${Math.max(12,Math.floor(b/22))}px system-ui, sans-serif`,e.shadowColor="rgb(0 0 0 / 30%)",e.shadowBlur=4,e.fillText(y.label,P-18,6),e.restore()}),e.beginPath(),e.arc(0,0,P,0,Math.PI*2),e.strokeStyle="#fbbf24",e.lineWidth=6,e.stroke(),e.beginPath(),e.arc(0,0,P-4,0,Math.PI*2),e.strokeStyle="#f59e0b",e.lineWidth=2,e.stroke(),e.restore(),e.save(),e.translate(C,C);for(let y=0;y<12;y++){const j=y/12*Math.PI*2,I=Math.cos(j)*(P+14),S=Math.sin(j)*(P+14);e.beginPath(),e.arc(I,S,3,0,Math.PI*2),e.fillStyle=y%2===0?"#fde68a":"#f59e0b",e.fill()}e.restore()},[h,r,b]);d.useEffect(()=>{const n=f.current;if(!n)return;const i=window.devicePixelRatio||1;v.current=i,n.width=h*i,n.height=h*i;const e=n.getContext("2d");e&&e.setTransform(i,0,0,i,0,0),R(t.current)},[h,R]),d.useEffect(()=>()=>{c.current&&cancelAnimationFrame(c.current)},[]);const u=n=>{const i=360/r.length,e=(n*(180/Math.PI)%360+360)%360;return Math.floor((360-e+i/2)%360/i)%r.length},m=()=>{if(p||r.length===0)return;M(!0),x(null);const n=Math.PI*2/r.length,e=Math.floor(Math.random()*r.length)*n+n/2,C=t.current,P=a*Math.PI*2,N=C+P+(Math.PI*2-e)-C%(Math.PI*2),y=C,j=performance.now(),I=S=>{const B=S-j,E=Math.min(B/g,1),H=it(E),A=y+(N-y)*H;if(t.current=A,R(A),E<1)c.current=requestAnimationFrame(I);else{const $=u(A),q=r[$];t.current=A,M(!1),x(q),l==null||l(q,$)}};c.current=requestAnimationFrame(I)};return s.jsxs("div",{className:w.turntable,style:{width:h,height:h+80},children:[s.jsxs("div",{className:w.wheelWrap,style:{width:h,height:h},children:[s.jsx("div",{className:w.pointer}),s.jsx("canvas",{ref:f,className:w.canvas,style:{width:h,height:h}}),s.jsx("button",{type:"button",className:w.spinBtn,onClick:m,disabled:p,children:p?"抽奖中...":o})]}),k&&!p&&s.jsxs("p",{className:w.result,children:["恭喜获得:",s.jsx("strong",{children:k.label})]})]})};exports.CanvasClock=U;exports.Charge=K;exports.ReturnCity=et;exports.Turntable=ht;
1
+ Object.defineProperty(exports,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={canvasClock:`cos-canvasClock`,canvasTarget:`cos-canvasTarget`},d=({width:e=400,height:t=400})=>{let n=(0,c.useRef)(null),r=Math.min(e,t),i=r/2-16,a=r/2,o=(0,c.useCallback)(e=>{e.clearRect(0,0,r,r),e.save(),e.translate(a,a),e.beginPath(),e.arc(0,0,i,0,Math.PI*2),e.fillStyle=`#fff`,e.fill(),e.strokeStyle=`#d1d5db`,e.lineWidth=2,e.stroke();for(let t=0;t<60;t++){let n=t/60*Math.PI*2,r=i-(t%5==0?14:8);e.beginPath(),e.moveTo(Math.cos(n)*r,Math.sin(n)*r),e.lineTo(Math.cos(n)*i,Math.sin(n)*i),e.strokeStyle=t%5==0?`#374151`:`#9ca3af`,e.lineWidth=t%5==0?2:1,e.stroke()}e.fillStyle=`#111827`,e.font=`bold ${Math.floor(r/22)}px system-ui, sans-serif`,e.textAlign=`center`,e.textBaseline=`middle`;for(let t=1;t<=12;t++){let n=t/12*Math.PI*2-Math.PI/2,r=i-32;e.fillText(String(t),Math.cos(n)*r,Math.sin(n)*r)}let t=new Date,n=t.getHours()%12,o=t.getMinutes(),s=t.getSeconds(),c=t.getMilliseconds(),l=(t,n,r,i,a)=>{e.save(),e.rotate(t),e.beginPath(),e.moveTo(0,r),e.lineTo(n,0),e.lineTo(0,-r),e.closePath(),e.fillStyle=i,e.shadowColor=a,e.shadowBlur=4,e.fill(),e.restore()},u=(n+o/60)/12*Math.PI*2-Math.PI/2,d=(o+s/60)/60*Math.PI*2-Math.PI/2,f=(s+c/1e3)/60*Math.PI*2-Math.PI/2;l(u,i*.5,4,`#111827`,`rgb(0 0 0 / 40%)`),l(d,i*.72,3,`#1e80ff`,`rgb(30 128 255 / 40%)`),l(f,i*.85,2,`#e9686b`,`rgb(233 104 107 / 40%)`),e.beginPath(),e.arc(0,0,5,0,Math.PI*2),e.fillStyle=`#111827`,e.fill(),e.restore()},[a,i,r]);return(0,c.useEffect)(()=>{let e=n.current;if(!e)return;let t=window.devicePixelRatio||1;e.width=r*t,e.height=r*t;let i=e.getContext(`2d`);if(!i)return;i.setTransform(t,0,0,t,0,0);let a=0,s=()=>{o(i),a=requestAnimationFrame(s)};return s(),()=>cancelAnimationFrame(a)},[o,r]),(0,l.jsx)(`div`,{className:u.canvasClock,style:{width:r,height:r},children:(0,l.jsx)(`canvas`,{ref:n,className:u.canvasTarget,style:{width:r,height:r}})})},f={chargeContainer:`cos-chargeContainer`,contrast:`cos-contrast`,hueRotate:`cos-hueRotate`,text:`cos-text`,moveUp:`cos-moveUp`,circle:`cos-circle`,circleRotate:`cos-circleRotate`,button:`cos-button`},p=e=>{let{initQuantity:t=0}=e,[n,r]=(0,c.useState)(t);return(0,c.useEffect)(()=>{let e=n;setInterval(()=>{e=Number(Number(e+=.01).toFixed(2)),r(e)},500)},[]),(0,l.jsx)(`div`,{className:f.chargeContainer,children:(0,l.jsxs)(`div`,{className:f.contrast,children:[(0,l.jsxs)(`div`,{className:f.text,children:[n?n.toString().padEnd(4,`0`):0,`%`]}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`div`,{className:f.circle}),(0,l.jsx)(`div`,{className:f.button})]})})},m={fireworks:`cos-fireworks`,canvas:`cos-canvas`,hint:`cos-hint`},h=[`#ff6b6b`,`#ffd93d`,`#6bcb77`,`#4d96ff`,`#a66cff`,`#ff85c0`],g=()=>h[Math.floor(Math.random()*h.length)],_=(e,t,n)=>{let r=60+Math.floor(Math.random()*30);return Array.from({length:r},()=>{let r=Math.random()*Math.PI*2,i=Math.random()*4+2;return{x:e,y:t,vx:Math.cos(r)*i,vy:Math.sin(r)*i,alpha:1,color:Math.random()>.3?n:g(),decay:Math.random()*.015+.01}})},v=({width:e=800,height:t=500,auto:n=!0})=>{let r=(0,c.useRef)(null),i=(0,c.useRef)([]),a=(0,c.useRef)(0),o=(0,c.useCallback)(n=>{let r=n??Math.random()*e*.6+e*.2;i.current.push({x:r,y:t,vy:-(Math.random()*4+6),targetY:Math.random()*t*.4+t*.1,color:g(),exploded:!1,particles:[]})},[t,e]);return(0,c.useEffect)(()=>{let s=r.current;if(!s)return;let c=window.devicePixelRatio||1;s.width=e*c,s.height=t*c;let l=s.getContext(`2d`);if(!l)return;l.setTransform(c,0,0,c,0,0);let u=0,d=()=>{a.current=requestAnimationFrame(d),l.fillStyle=`rgb(15 23 42 / 25%)`,l.fillRect(0,0,e,t),n&&Math.random()<.03&&o(),i.current=i.current.filter(e=>e.exploded?(e.particles=e.particles.filter(e=>(e.x+=e.vx,e.y+=e.vy,e.vy+=.06,e.alpha-=e.decay,e.alpha<=0?!1:(l.beginPath(),l.arc(e.x,e.y,2,0,Math.PI*2),l.fillStyle=e.color,l.globalAlpha=e.alpha,l.fill(),l.globalAlpha=1,!0))),e.particles.length>0):(e.y+=e.vy,e.vy*=.98,l.beginPath(),l.arc(e.x,e.y,2.5,0,Math.PI*2),l.fillStyle=e.color,l.fill(),(e.vy>=0||e.y<=e.targetY)&&(e.exploded=!0,e.particles=_(e.x,e.y,e.color)),!0))};return d(),n&&(u=window.setInterval(()=>o(),1200)),()=>{cancelAnimationFrame(a.current),clearInterval(u)}},[n,t,o,e]),(0,l.jsxs)(`div`,{className:m.fireworks,style:{width:e,height:t},children:[(0,l.jsx)(`canvas`,{ref:r,className:m.canvas,style:{width:e,height:t},onClick:e=>{let t=e.currentTarget.getBoundingClientRect();o(e.clientX-t.left)}}),(0,l.jsx)(`p`,{className:m.hint,children:`点击画布燃放烟花`})]})},y={matrixRain:`cos-matrixRain`,canvas:`cos-canvas`,overlay:`cos-overlay`,title:`cos-title`,flicker:`cos-flicker`,subtitle:`cos-subtitle`},b=`ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*アイウエオカキクケコ`,x=({width:e=800,height:t=500,density:n=.6,color:r=`#00ff41`})=>{let i=(0,c.useRef)(null);return(0,c.useEffect)(()=>{let a=i.current;if(!a)return;let o=window.devicePixelRatio||1;a.width=e*o,a.height=t*o;let s=a.getContext(`2d`);if(!s)return;s.setTransform(o,0,0,o,0,0);let c=Math.floor(e/16*n),l=Array.from({length:c},()=>Math.random()*-50),u=0,d=()=>{s.fillStyle=`rgb(0 0 0 / 8%)`,s.fillRect(0,0,e,t),s.fillStyle=r,s.font=`16px monospace`,l.forEach((e,i)=>{let a=b[Math.floor(Math.random()*53)],o=i/n*16;s.fillStyle=r,s.fillText(a,o,e*16),e*16>t&&Math.random()>.975&&(l[i]=0),l[i]+=1}),u=requestAnimationFrame(d)};return d(),()=>cancelAnimationFrame(u)},[r,n,t,e]),(0,l.jsxs)(`div`,{className:y.matrixRain,style:{width:e,height:t},children:[(0,l.jsx)(`canvas`,{ref:i,className:y.canvas,style:{width:e,height:t}}),(0,l.jsxs)(`div`,{className:y.overlay,children:[(0,l.jsx)(`h2`,{className:y.title,children:`MATRIX`}),(0,l.jsx)(`p`,{className:y.subtitle,children:`数字雨效果`})]})]})},S={neonText:`cos-neonText`,text:`cos-text`,flicker:`cos-flicker`,"neon-flicker":`cos-neon-flicker`,reflection:`cos-reflection`},C=({text:e=`NEON`,color:t=`#ff00de`,fontSize:n=72,flicker:r=!0})=>(0,l.jsxs)(`div`,{className:S.neonText,children:[(0,l.jsx)(`h1`,{className:`${S.text} ${r?S.flicker:``}`,style:{fontSize:n,"--neon-color":t},children:e}),(0,l.jsx)(`p`,{className:S.reflection,style:{fontSize:n*.35,color:t},children:e})]}),w={particleNetwork:`cos-particleNetwork`,canvas:`cos-canvas`,hint:`cos-hint`},T=({width:e=800,height:t=500,particleCount:n=60,linkDistance:r=120,color:i=`#38bdf8`})=>{let a=(0,c.useRef)(null),o=(0,c.useRef)([]),s=(0,c.useRef)({x:-1e3,y:-1e3}),u=(0,c.useCallback)(()=>{o.current=Array.from({length:n},()=>({x:Math.random()*e,y:Math.random()*t,vx:(Math.random()-.5)*1.2,vy:(Math.random()-.5)*1.2,radius:Math.random()*2+1}))},[t,n,e]);return(0,c.useEffect)(()=>{u()},[u]),(0,c.useEffect)(()=>{let n=a.current;if(!n)return;let c=window.devicePixelRatio||1;n.width=e*c,n.height=t*c;let l=n.getContext(`2d`);if(!l)return;l.setTransform(c,0,0,c,0,0);let u=0,d=()=>{l.fillStyle=`#0f172a`,l.fillRect(0,0,e,t);let n=o.current,a=s.current;n.forEach(n=>{n.x+=n.vx,n.y+=n.vy,(n.x<0||n.x>e)&&(n.vx*=-1),(n.y<0||n.y>t)&&(n.vy*=-1);let r=a.x-n.x,i=a.y-n.y;Math.sqrt(r*r+i*i)<150&&(n.vx-=r*3e-4,n.vy-=i*3e-4)});for(let e=0;e<n.length;e++)for(let t=e+1;t<n.length;t++){let a=n[e].x-n[t].x,o=n[e].y-n[t].y,s=Math.sqrt(a*a+o*o);s<r&&(l.beginPath(),l.moveTo(n[e].x,n[e].y),l.lineTo(n[t].x,n[t].y),l.strokeStyle=i,l.globalAlpha=1-s/r,l.lineWidth=.8,l.stroke(),l.globalAlpha=1)}n.forEach(e=>{l.beginPath(),l.arc(e.x,e.y,e.radius,0,Math.PI*2),l.fillStyle=i,l.fill()}),u=requestAnimationFrame(d)};return d(),()=>cancelAnimationFrame(u)},[i,t,u,r,e]),(0,l.jsxs)(`div`,{className:w.particleNetwork,style:{width:e,height:t},children:[(0,l.jsx)(`canvas`,{ref:a,className:w.canvas,style:{width:e,height:t},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();s.current={x:e.clientX-t.left,y:e.clientY-t.top}},onMouseLeave:()=>{s.current={x:-1e3,y:-1e3}}}),(0,l.jsx)(`p`,{className:w.hint,children:`移动鼠标与粒子互动`})]})},E={returnCityContainer:`cos-returnCityContainer`,star:`cos-star`,glassWrap:`cos-glassWrap`,rotate:`cos-rotate`,glassItem:`cos-glassItem`},D=()=>{let e=(e,t)=>{for(let n=0;n<t;n++)setTimeout(function(){let t=document.createElement(`div`);t.className=E.star;let n=document.body.clientWidth,r=document.body.clientHeight,i=Math.random()*n+`px`,a=Math.random()*r+`px`;t.style.top=a,t.style.left=i,e.append(t)},Math.random()*2e3)},t=()=>{let e=document.getElementById(`glassWrap`);if(e)for(let t=0;t<6;t++){let n=document.createElement(`div`);n.className=E.glassItem,n.style.transform=`rotateY(${360/6*t}deg) translateZ(150px)`,e.appendChild(n),setTimeout(()=>{n.style.top=`0px`,n.style.opacity=`1`},t*300)}};return(0,c.useEffect)(()=>{let n=document.getElementById(`returnCityContainer`);n&&e(n,document.documentElement.clientWidth/20),t()},[]),(0,l.jsx)(`div`,{id:`returnCityContainer`,className:E.returnCityContainer,children:(0,l.jsx)(`div`,{id:`glassWrap`,className:E.glassWrap})})},O={turntable:`cos-turntable`,wheelWrap:`cos-wheelWrap`,canvas:`cos-canvas`,pointer:`cos-pointer`,spinBtn:`cos-spinBtn`,result:`cos-result`,"fade-in":`cos-fade-in`},k=[`#FF6B6B`,`#4ECDC4`,`#FFE66D`,`#A78BFA`,`#60A5FA`,`#F472B6`,`#34D399`,`#FB923C`],A=[{label:`一等奖`},{label:`二等奖`},{label:`三等奖`},{label:`谢谢参与`},{label:`优惠券`},{label:`再来一次`}],j=e=>1-(1-e)**3,M=({prizes:e=A,size:t=360,spinDuration:n=4e3,spinRounds:r=5,buttonText:i=`开始抽奖`,onSpinEnd:a})=>{let o=(0,c.useRef)(null),s=(0,c.useRef)(0),u=(0,c.useRef)(0),d=(0,c.useRef)(1),[f,p]=(0,c.useState)(!1),[m,h]=(0,c.useState)(null),g=t+48,_=(e,t)=>t.color??k[e%k.length],v=(0,c.useCallback)(n=>{let r=o.current;if(!r)return;let i=r.getContext(`2d`);if(!i)return;let a=g/2,s=t/2,c=Math.PI*2/e.length;i.clearRect(0,0,g,g),i.save(),i.translate(a,a),i.rotate(n),e.forEach((e,n)=>{let r=n*c-Math.PI/2,a=r+c,o=_(n,e);i.beginPath(),i.moveTo(0,0),i.arc(0,0,s,r,a),i.closePath(),i.fillStyle=o,i.fill(),i.strokeStyle=`rgb(255 255 255 / 35%)`,i.lineWidth=2,i.stroke(),i.save(),i.rotate(r+c/2),i.textAlign=`right`,i.fillStyle=`#fff`,i.font=`bold ${Math.max(12,Math.floor(t/22))}px system-ui, sans-serif`,i.shadowColor=`rgb(0 0 0 / 30%)`,i.shadowBlur=4,i.fillText(e.label,s-18,6),i.restore()}),i.beginPath(),i.arc(0,0,s,0,Math.PI*2),i.strokeStyle=`#fbbf24`,i.lineWidth=6,i.stroke(),i.beginPath(),i.arc(0,0,s-4,0,Math.PI*2),i.strokeStyle=`#f59e0b`,i.lineWidth=2,i.stroke(),i.restore(),i.save(),i.translate(a,a);for(let e=0;e<12;e++){let t=e/12*Math.PI*2,n=Math.cos(t)*(s+14),r=Math.sin(t)*(s+14);i.beginPath(),i.arc(n,r,3,0,Math.PI*2),i.fillStyle=e%2==0?`#fde68a`:`#f59e0b`,i.fill()}i.restore()},[g,e,t]);(0,c.useEffect)(()=>{let e=o.current;if(!e)return;let t=window.devicePixelRatio||1;d.current=t,e.width=g*t,e.height=g*t;let n=e.getContext(`2d`);n&&n.setTransform(t,0,0,t,0,0),v(s.current)},[g,v]),(0,c.useEffect)(()=>()=>{u.current&&cancelAnimationFrame(u.current)},[]);let y=t=>{let n=360/e.length,r=(180/Math.PI*t%360+360)%360;return Math.floor((360-r+n/2)%360/n)%e.length};return(0,l.jsxs)(`div`,{className:O.turntable,style:{width:g,height:g+80},children:[(0,l.jsxs)(`div`,{className:O.wheelWrap,style:{width:g,height:g},children:[(0,l.jsx)(`div`,{className:O.pointer}),(0,l.jsx)(`canvas`,{ref:o,className:O.canvas,style:{width:g,height:g}}),(0,l.jsx)(`button`,{type:`button`,className:O.spinBtn,onClick:()=>{if(f||e.length===0)return;p(!0),h(null);let t=Math.PI*2/e.length,i=Math.floor(Math.random()*e.length)*t+t/2,o=s.current,c=o+r*Math.PI*2+(Math.PI*2-i)-o%(Math.PI*2),l=o,d=performance.now(),m=t=>{let r=t-d,i=Math.min(r/n,1),o=j(i),f=l+(c-l)*o;if(s.current=f,v(f),i<1)u.current=requestAnimationFrame(m);else{let t=y(f),n=e[t];s.current=f,p(!1),h(n),a?.(n,t)}};u.current=requestAnimationFrame(m)},disabled:f,children:f?`抽奖中...`:i})]}),m&&!f&&(0,l.jsxs)(`p`,{className:O.result,children:[`恭喜获得:`,(0,l.jsx)(`strong`,{children:m.label})]})]})},N={typewriter:`cos-typewriter`,terminal:`cos-terminal`,dots:`cos-dots`,text:`cos-text`,prompt:`cos-prompt`,cursor:`cos-cursor`,blink:`cos-blink`},P=[`Hello, cos-design!`,`欢迎来到组件库 ✨`,`Build something fun 🚀`],F=({texts:e=P,speed:t=100,deleteSpeed:n=50,pause:r=2e3})=>{let[i,a]=(0,c.useState)(``),[o,s]=(0,c.useState)(0),[u,d]=(0,c.useState)(!1);return(0,c.useEffect)(()=>{let c=e[o%e.length],l;if(!u&&i===c)l=setTimeout(()=>d(!0),r);else if(u&&i===``)l=setTimeout(()=>{d(!1),s(t=>(t+1)%e.length)},0);else{let e=u?c.slice(0,i.length-1):c.slice(0,i.length+1);l=setTimeout(()=>a(e),u?n:t)}return()=>clearTimeout(l)},[i,u,o,e,t,n,r]),(0,l.jsx)(`div`,{className:N.typewriter,children:(0,l.jsxs)(`div`,{className:N.terminal,children:[(0,l.jsxs)(`div`,{className:N.dots,children:[(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{}),(0,l.jsx)(`span`,{})]}),(0,l.jsxs)(`p`,{className:N.text,children:[(0,l.jsx)(`span`,{className:N.prompt,children:`>`}),i,(0,l.jsx)(`span`,{className:N.cursor,children:`|`})]})]})})},I={waveButton:`cos-waveButton`,btn:`cos-btn`,label:`cos-label`,wave:`cos-wave`,ripple:`cos-ripple`},L=({text:e=`点我试试`,onClick:t,color:n=`#38bdf8`})=>(0,l.jsx)(`div`,{className:I.waveButton,children:(0,l.jsxs)(`button`,{type:`button`,className:I.btn,style:{"--wave-color":n},onClick:t,children:[(0,l.jsx)(`span`,{className:I.wave}),(0,l.jsx)(`span`,{className:I.wave}),(0,l.jsx)(`span`,{className:I.label,children:e})]})});exports.CanvasClock=d,exports.Charge=p,exports.Fireworks=v,exports.MatrixRain=x,exports.NeonText=C,exports.ParticleNetwork=T,exports.ReturnCity=D,exports.Turntable=M,exports.Typewriter=F,exports.WaveButton=L;
package/dist/index.css CHANGED
@@ -1 +1 @@
1
- .cos-canvasClock{display:inline-flex;align-items:center;justify-content:center;border-radius:50%;background-color:#fff;box-shadow:0 8px 32px #00000040}.cos-canvasTarget{display:block;border-radius:50%}.cos-chargeContainer{width:100vw;height:100vh;background-color:#000;position:relative}.cos-chargeContainer .cos-contrast{width:100%;height:100%;background-color:#000;overflow:hidden;filter:contrast(15) hue-rotate(0);position:relative;animation:cos-hueRotate 6s linear infinite}.cos-chargeContainer .cos-contrast .cos-text{width:300px;height:300px;position:absolute;top:10px;left:50%;margin-left:-150px;text-align:center;z-index:9;font-size:30px;line-height:300px;color:#fff;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.cos-chargeContainer .cos-contrast span{filter:blur(5px);position:absolute;border-radius:10px;background:#00ff6f;animation:cos-moveUp ease-in-out infinite;bottom:0;transition:transform .3s linear;will-change:transform}.cos-chargeContainer .cos-contrast span:nth-child(1){width:20px;height:20px;left:50%;animation-duration:4s;animation-delay:2s}.cos-chargeContainer .cos-contrast span:nth-child(2){width:22px;height:22px;left:54%;animation-duration:4.2s;animation-delay:4s}.cos-chargeContainer .cos-contrast span:nth-child(3){width:24px;height:24px;left:45%;animation-duration:3s;animation-delay:1s}.cos-chargeContainer .cos-contrast span:nth-child(4){width:20px;height:22px;left:54%;animation-duration:5s;animation-delay:0s}.cos-chargeContainer .cos-contrast span:nth-child(5){width:22px;height:22px;left:52%;animation-duration:3.5s;animation-delay:5s}.cos-chargeContainer .cos-contrast span:nth-child(6){width:20px;height:20px;left:50%;animation-duration:4.7s;animation-delay:1.2s}.cos-chargeContainer .cos-contrast span:nth-child(7){width:22px;height:22px;left:54%;animation-duration:2.5s;animation-delay:3.5s}.cos-chargeContainer .cos-contrast span:nth-child(8){width:24px;height:24px;left:51%;animation-duration:5.6s;animation-delay:4.2s}.cos-chargeContainer .cos-contrast span:nth-child(9){width:26px;height:26px;left:42%;animation-duration:5.2s;animation-delay:4s}.cos-chargeContainer .cos-contrast span:nth-child(10){width:26px;height:22px;left:54%;animation-duration:3.8s;animation-delay:4.3s}.cos-chargeContainer .cos-contrast span:nth-child(11){width:22px;height:22px;left:42%;animation-duration:4.2s;animation-delay:.3s}.cos-chargeContainer .cos-contrast span:nth-child(12){width:24px;height:24px;left:46%;animation-duration:4.6s;animation-delay:2s}.cos-chargeContainer .cos-contrast span:nth-child(13){width:22px;height:22px;left:48%;animation-duration:3.8s;animation-delay:3.2s}.cos-chargeContainer .cos-contrast span:nth-child(14){width:26px;height:22px;left:55%;animation-duration:5.2s;animation-delay:2.9s}.cos-chargeContainer .cos-contrast span:nth-child(15){width:26px;height:22px;left:52%;animation-duration:4.9s;animation-delay:4.2s}.cos-chargeContainer .cos-contrast .cos-circle{width:300px;height:300px;position:absolute;top:10px;left:50%;margin-left:-150px;box-sizing:border-box;filter:blur(8px);animation:cos-circleRotate 6s linear infinite}.cos-chargeContainer .cos-contrast .cos-circle:before{content:"";height:200px;width:200px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%) rotate(0);background:#00ff6f;border-radius:42% 38% 62% 49%/45%}.cos-chargeContainer .cos-contrast .cos-circle:after{content:"";width:176px;height:178px;background:#000;border-radius:50%;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.cos-chargeContainer .cos-contrast .cos-button{width:150px;height:50px;background:#00ff6f;position:absolute;left:50%;bottom:0;transform:translate(-50%);border-radius:100px 100px 0 0;filter:blur(5px)}@keyframes cos-circleRotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes cos-hueRotate{0%{filter:contrast(15) hue-rotate(0)}to{filter:contrast(15) hue-rotate(360deg)}}@keyframes cos-moveUp{0%{transform:translateY(0)}to{transform:translateY(calc(0% - 100vh + 245px))}}.cos-returnCityContainer{width:100%;height:100%;overflow:hidden;background:#000;position:relative}.cos-returnCityContainer .cos-star{position:absolute;width:5px;height:5px;border-radius:50%;background:#fd400a;animation:cos-star infinite 2s}.cos-returnCityContainer .cos-glassWrap{width:100px;height:175px;position:absolute;left:50%;bottom:50%;transform:translate(-50%,50%);transform-style:preserve-3d;animation:cos-rotate 10s linear infinite}.cos-returnCityContainer .cos-glassWrap .cos-glassItem{position:absolute;left:0;opacity:0;top:-250px;width:100%;height:100%;transition:all .3s ease-in;border-radius:5px;box-shadow:0 0 10px 3px #ff0000b3;background:#ad470257}@keyframes cos-rotate{0%{transform:translate(-50%,50%) rotateY(360deg)}to{transform:translate(-50%,50%) rotateY(0)}}@keyframes cos-star{0%{filter:blur(1px) contrast(15) hue-rotate(0);opacity:0}50%{opacity:1;filter:blur(1px) contrast(15) hue-rotate(360deg)}to{opacity:0;filter:blur(1px) contrast(15) hue-rotate(0)}}.cos-turntable{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;margin:0 auto;padding:24px;box-sizing:border-box}.cos-wheelWrap{position:relative;display:flex;align-items:center;justify-content:center}.cos-canvas{display:block;border-radius:50%;filter:drop-shadow(0 12px 32px rgba(0,0,0,.35))}.cos-pointer{position:absolute;top:4px;left:50%;z-index:2;width:0;height:0;border-left:14px solid transparent;border-right:14px solid transparent;border-top:28px solid #ef4444;transform:translate(-50%);filter:drop-shadow(0 2px 4px rgba(0,0,0,.3))}.cos-pointer:after{content:"";position:absolute;top:-30px;left:-8px;width:16px;height:16px;border-radius:50%;background:#ef4444;box-shadow:inset 0 -2px 4px #0003}.cos-spinBtn{position:absolute;z-index:3;width:88px;height:88px;border:4px solid #fbbf24;border-radius:50%;background:linear-gradient(145deg,#fff,#f1f5f9);color:#b45309;font-size:14px;font-weight:700;line-height:1.3;cursor:pointer;box-shadow:0 4px 12px #00000026,inset 0 2px 4px #fffc;transition:transform .15s,box-shadow .15s}.cos-spinBtn:hover:not(:disabled){transform:scale(1.05);box-shadow:0 6px 16px #0003,inset 0 2px 4px #fffc}.cos-spinBtn:active:not(:disabled){transform:scale(.97)}.cos-spinBtn:disabled{opacity:.75;cursor:not-allowed}.cos-result{margin:0;padding:10px 20px;border-radius:999px;background:linear-gradient(90deg,#fef3c7,#fde68a);color:#92400e;font-size:15px;animation:cos-fade-in .4s ease}.cos-result strong{color:#b45309;font-size:17px}@keyframes cos-fade-in{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}
1
+ .cos-canvasClock{background-color:#fff;border-radius:50%;justify-content:center;align-items:center;display:inline-flex;box-shadow:0 8px 32px #00000040}.cos-canvasTarget{border-radius:50%;display:block}.cos-chargeContainer{background-color:#000;width:100vw;height:100vh;position:relative}.cos-chargeContainer .cos-contrast{filter:contrast(15)hue-rotate();background-color:#000;width:100%;height:100%;animation:6s linear infinite cos-hueRotate;position:relative;overflow:hidden}.cos-chargeContainer .cos-contrast .cos-text{text-align:center;z-index:9;color:#fff;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;width:300px;height:300px;margin-left:-150px;font-size:30px;line-height:300px;position:absolute;top:10px;left:50%}.cos-chargeContainer .cos-contrast span{filter:blur(5px);will-change:transform;background:#00ff6f;border-radius:10px;transition:transform .3s linear;animation:ease-in-out infinite cos-moveUp;position:absolute;bottom:0}.cos-chargeContainer .cos-contrast span:first-child{width:20px;height:20px;animation-duration:4s;animation-delay:2s;left:50%}.cos-chargeContainer .cos-contrast span:nth-child(2){width:22px;height:22px;animation-duration:4.2s;animation-delay:4s;left:54%}.cos-chargeContainer .cos-contrast span:nth-child(3){width:24px;height:24px;animation-duration:3s;animation-delay:1s;left:45%}.cos-chargeContainer .cos-contrast span:nth-child(4){width:20px;height:22px;animation-duration:5s;animation-delay:0s;left:54%}.cos-chargeContainer .cos-contrast span:nth-child(5){width:22px;height:22px;animation-duration:3.5s;animation-delay:5s;left:52%}.cos-chargeContainer .cos-contrast span:nth-child(6){width:20px;height:20px;animation-duration:4.7s;animation-delay:1.2s;left:50%}.cos-chargeContainer .cos-contrast span:nth-child(7){width:22px;height:22px;animation-duration:2.5s;animation-delay:3.5s;left:54%}.cos-chargeContainer .cos-contrast span:nth-child(8){width:24px;height:24px;animation-duration:5.6s;animation-delay:4.2s;left:51%}.cos-chargeContainer .cos-contrast span:nth-child(9){width:26px;height:26px;animation-duration:5.2s;animation-delay:4s;left:42%}.cos-chargeContainer .cos-contrast span:nth-child(10){width:26px;height:22px;animation-duration:3.8s;animation-delay:4.3s;left:54%}.cos-chargeContainer .cos-contrast span:nth-child(11){width:22px;height:22px;animation-duration:4.2s;animation-delay:.3s;left:42%}.cos-chargeContainer .cos-contrast span:nth-child(12){width:24px;height:24px;animation-duration:4.6s;animation-delay:2s;left:46%}.cos-chargeContainer .cos-contrast span:nth-child(13){width:22px;height:22px;animation-duration:3.8s;animation-delay:3.2s;left:48%}.cos-chargeContainer .cos-contrast span:nth-child(14){width:26px;height:22px;animation-duration:5.2s;animation-delay:2.9s;left:55%}.cos-chargeContainer .cos-contrast span:nth-child(15){width:26px;height:22px;animation-duration:4.9s;animation-delay:4.2s;left:52%}.cos-chargeContainer .cos-contrast .cos-circle{box-sizing:border-box;filter:blur(8px);width:300px;height:300px;margin-left:-150px;animation:6s linear infinite cos-circleRotate;position:absolute;top:10px;left:50%}.cos-chargeContainer .cos-contrast .cos-circle:before{content:"";background:#00ff6f;border-radius:42% 38% 62% 49%/45%;width:200px;height:200px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)rotate(0)}.cos-chargeContainer .cos-contrast .cos-circle:after{content:"";background:#000;border-radius:50%;width:176px;height:178px;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.cos-chargeContainer .cos-contrast .cos-button{filter:blur(5px);background:#00ff6f;border-radius:100px 100px 0 0;width:150px;height:50px;position:absolute;bottom:0;left:50%;transform:translate(-50%)}@keyframes cos-circleRotate{0%{transform:rotate(0)}to{transform:rotate(360deg)}}@keyframes cos-hueRotate{0%{filter:contrast(15)hue-rotate()}to{filter:contrast(15)hue-rotate(360deg)}}@keyframes cos-moveUp{0%{transform:translateY(0)}to{transform:translateY(calc(245px - 100vh))}}.cos-fireworks{background:#0f172a;border-radius:12px;position:relative;overflow:hidden}.cos-matrixRain{background:#000;border-radius:12px;position:relative;overflow:hidden}.cos-canvas{display:block}.cos-overlay{pointer-events:none;flex-direction:column;justify-content:center;align-items:center;display:flex;position:absolute;inset:0}.cos-title{color:#00ff41;letter-spacing:.3em;text-shadow:0 0 20px #00ff41;margin:0;font-size:48px;font-weight:800;animation:3s infinite cos-flicker}.cos-subtitle{color:#00ff4199;letter-spacing:.2em;margin:8px 0 0;font-size:14px}@keyframes cos-flicker{0%,to{opacity:1}50%{opacity:.85}52%{opacity:.6}54%{opacity:1}}.cos-neonText{background:#0a0a0a;border-radius:12px;flex-direction:column;justify-content:center;align-items:center;min-height:240px;padding:40px;display:flex}.cos-text{color:var(--neon-color,#ff00de);letter-spacing:.15em;text-shadow:0 0 5px var(--neon-color), 0 0 10px var(--neon-color), 0 0 20px var(--neon-color), 0 0 40px var(--neon-color), 0 0 80px var(--neon-color);margin:0;font-weight:900}.cos-flicker{animation:2.5s infinite alternate cos-neon-flicker}.cos-reflection{opacity:.3;letter-spacing:.15em;filter:blur(2px);margin:12px 0 0;font-weight:700;transform:scaleY(-1)}@keyframes cos-neon-flicker{0%,19%,21%,23%,25%,54%,56%,to{opacity:1}20%,24%,55%{opacity:.6}}.cos-particleNetwork{border-radius:12px;position:relative;overflow:hidden}.cos-canvas{cursor:crosshair;display:block}.cos-hint{color:#94a3b8b3;pointer-events:none;margin:0;font-size:13px;position:absolute;bottom:12px;left:50%;transform:translate(-50%)}.cos-returnCityContainer{background:#000;width:100%;height:100%;position:relative;overflow:hidden}.cos-returnCityContainer .cos-star{background:#fd400a;border-radius:50%;width:5px;height:5px;animation:2s infinite cos-star;position:absolute}.cos-returnCityContainer .cos-glassWrap{width:100px;height:175px;transform-style:preserve-3d;animation:10s linear infinite cos-rotate;position:absolute;bottom:50%;left:50%;transform:translate(-50%,50%)}.cos-returnCityContainer .cos-glassWrap .cos-glassItem{opacity:0;background:#ad470257;border-radius:5px;width:100%;height:100%;transition:all .3s ease-in;position:absolute;top:-250px;left:0;box-shadow:0 0 10px 3px #ff0000b3}@keyframes cos-rotate{0%{transform:translate(-50%,50%)rotateY(360deg)}to{transform:translate(-50%,50%)rotateY(0)}}@keyframes cos-star{0%{filter:blur(1px)contrast(15)hue-rotate();opacity:0}50%{opacity:1;filter:blur(1px)contrast(15)hue-rotate(360deg)}to{opacity:0;filter:blur(1px)contrast(15)hue-rotate()}}.cos-turntable{box-sizing:border-box;flex-direction:column;justify-content:center;align-items:center;gap:20px;margin:0 auto;padding:24px;display:flex}.cos-wheelWrap{justify-content:center;align-items:center;display:flex;position:relative}.cos-canvas{filter:drop-shadow(0 12px 32px #00000059);border-radius:50%;display:block}.cos-pointer{z-index:2;filter:drop-shadow(0 2px 4px #0000004d);border-top:28px solid #ef4444;border-left:14px solid #0000;border-right:14px solid #0000;width:0;height:0;position:absolute;top:4px;left:50%;transform:translate(-50%)}.cos-pointer:after{content:"";background:#ef4444;border-radius:50%;width:16px;height:16px;position:absolute;top:-30px;left:-8px;box-shadow:inset 0 -2px 4px #0003}.cos-spinBtn{z-index:3;color:#b45309;cursor:pointer;background:linear-gradient(145deg,#fff 0%,#f1f5f9 100%);border:4px solid #fbbf24;border-radius:50%;width:88px;height:88px;font-size:14px;font-weight:700;line-height:1.3;transition:transform .15s,box-shadow .15s;position:absolute;box-shadow:0 4px 12px #00000026,inset 0 2px 4px #fffc}.cos-spinBtn:hover:not(:disabled){transform:scale(1.05);box-shadow:0 6px 16px #0003,inset 0 2px 4px #fffc}.cos-spinBtn:active:not(:disabled){transform:scale(.97)}.cos-spinBtn:disabled{opacity:.75;cursor:not-allowed}.cos-result{color:#92400e;background:linear-gradient(90deg,#fef3c7,#fde68a);border-radius:999px;margin:0;padding:10px 20px;font-size:15px;animation:.4s cos-fade-in}.cos-result strong{color:#b45309;font-size:17px}@keyframes cos-fade-in{0%{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}.cos-typewriter{box-sizing:border-box;justify-content:center;align-items:center;width:100%;min-height:200px;padding:24px;display:flex}.cos-terminal{background:#1e293b;border-radius:12px;width:min(560px,100%);padding:20px 24px;box-shadow:0 16px 48px #00000059}.cos-dots{gap:8px;margin-bottom:16px;display:flex}.cos-dots span{border-radius:50%;width:12px;height:12px}.cos-dots span:first-child{background:#ef4444}.cos-dots span:nth-child(2){background:#eab308}.cos-dots span:nth-child(3){background:#22c55e}.cos-text{color:#e2e8f0;min-height:1.6em;margin:0;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:20px;line-height:1.6}.cos-prompt{color:#38bdf8;margin-right:8px}.cos-cursor{color:#38bdf8;margin-left:2px;animation:1s step-end infinite cos-blink;display:inline-block}@keyframes cos-blink{50%{opacity:0}}.cos-waveButton{justify-content:center;align-items:center;min-height:200px;padding:40px;display:flex}.cos-btn{background:var(--wave-color,#38bdf8);color:#fff;cursor:pointer;border:none;border-radius:50px;padding:16px 48px;font-size:18px;font-weight:600;transition:transform .2s;position:relative;overflow:hidden;box-shadow:0 8px 24px #38bdf859}.cos-btn:hover{transform:scale(1.05)}.cos-btn:active{transform:scale(.97)}.cos-label{z-index:1;position:relative}.cos-wave{background:#ffffff4d;border-radius:50%;width:0;height:0;animation:3s ease-out infinite cos-ripple;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}.cos-wave:nth-child(2){animation-delay:1s}@keyframes cos-ripple{0%{opacity:.6;width:0;height:0}to{opacity:0;width:300px;height:300px}}
package/dist/index.d.ts CHANGED
@@ -1,44 +1 @@
1
- import { default as default_2 } from 'react';
2
-
3
- export declare const CanvasClock: default_2.FC<CanvasClockProps>;
4
-
5
- export declare interface CanvasClockProps {
6
- width?: number;
7
- height?: number;
8
- }
9
-
10
- export declare const Charge: (props: ChargeProps) => JSX.Element;
11
-
12
- export declare interface ChargeProps {
13
- initQuantity?: number;
14
- }
15
-
16
- export declare const ReturnCity: default_2.FC<ReturnCityProps>;
17
-
18
- export declare interface ReturnCityProps {
19
- shining?: number;
20
- }
21
-
22
- export declare const Turntable: default_2.FC<TurntableProps>;
23
-
24
- export declare interface TurntablePrize {
25
- label: string;
26
- color?: string;
27
- }
28
-
29
- export declare interface TurntableProps {
30
- /** 奖品列表 */
31
- prizes?: TurntablePrize[];
32
- /** 转盘直径,默认 360 */
33
- size?: number;
34
- /** 旋转动画时长(毫秒),默认 4000 */
35
- spinDuration?: number;
36
- /** 旋转圈数,默认 5 */
37
- spinRounds?: number;
38
- /** 抽奖按钮文案 */
39
- buttonText?: string;
40
- /** 旋转结束回调 */
41
- onSpinEnd?: (prize: TurntablePrize, index: number) => void;
42
- }
43
-
44
- export { }
1
+ export * from './components';
package/dist/index.js CHANGED
@@ -1,189 +1,563 @@
1
- import { jsx as n, jsxs as S } from "react/jsx-runtime";
2
- import { useRef as W, useCallback as Z, useEffect as F, useState as H } from "react";
3
- import './index.css';const G = "cos-canvasClock", Y = "cos-canvasTarget", j = {
4
- canvasClock: G,
5
- canvasTarget: Y
6
- }, gt = ({ width: r = 400, height: f = 400 }) => {
7
- const u = W(null), a = Math.min(r, f), o = a / 2 - 16, l = a / 2, g = Z(
8
- (t) => {
9
- t.clearRect(0, 0, a, a), t.save(), t.translate(l, l), t.beginPath(), t.arc(0, 0, o, 0, Math.PI * 2), t.fillStyle = "#fff", t.fill(), t.strokeStyle = "#d1d5db", t.lineWidth = 2, t.stroke();
10
- for (let d = 0; d < 60; d++) {
11
- const m = d / 60 * Math.PI * 2, s = o - (d % 5 === 0 ? 14 : 8);
12
- t.beginPath(), t.moveTo(Math.cos(m) * s, Math.sin(m) * s), t.lineTo(Math.cos(m) * o, Math.sin(m) * o), t.strokeStyle = d % 5 === 0 ? "#374151" : "#9ca3af", t.lineWidth = d % 5 === 0 ? 2 : 1, t.stroke();
13
- }
14
- t.fillStyle = "#111827", t.font = `bold ${Math.floor(a / 22)}px system-ui, sans-serif`, t.textAlign = "center", t.textBaseline = "middle";
15
- for (let d = 1; d <= 12; d++) {
16
- const m = d / 12 * Math.PI * 2 - Math.PI / 2, s = o - 32;
17
- t.fillText(String(d), Math.cos(m) * s, Math.sin(m) * s);
18
- }
19
- const c = /* @__PURE__ */ new Date(), y = c.getHours() % 12, p = c.getMinutes(), M = c.getSeconds(), B = c.getMilliseconds(), w = (d, m, s, i, e) => {
20
- t.save(), t.rotate(d), t.beginPath(), t.moveTo(0, s), t.lineTo(m, 0), t.lineTo(0, -s), t.closePath(), t.fillStyle = i, t.shadowColor = e, t.shadowBlur = 4, t.fill(), t.restore();
21
- }, h = (y + p / 60) / 12 * Math.PI * 2 - Math.PI / 2, D = (p + M / 60) / 60 * Math.PI * 2 - Math.PI / 2, A = (M + B / 1e3) / 60 * Math.PI * 2 - Math.PI / 2;
22
- w(h, o * 0.5, 4, "#111827", "rgb(0 0 0 / 40%)"), w(D, o * 0.72, 3, "#1e80ff", "rgb(30 128 255 / 40%)"), w(A, o * 0.85, 2, "#e9686b", "rgb(233 104 107 / 40%)"), t.beginPath(), t.arc(0, 0, 5, 0, Math.PI * 2), t.fillStyle = "#111827", t.fill(), t.restore();
23
- },
24
- [l, o, a]
25
- );
26
- return F(() => {
27
- const t = u.current;
28
- if (!t) return;
29
- const c = window.devicePixelRatio || 1;
30
- t.width = a * c, t.height = a * c;
31
- const y = t.getContext("2d");
32
- if (!y) return;
33
- y.setTransform(c, 0, 0, c, 0, 0);
34
- let p = 0;
35
- const M = () => {
36
- g(y), p = requestAnimationFrame(M);
37
- };
38
- return M(), () => cancelAnimationFrame(p);
39
- }, [g, a]), /* @__PURE__ */ n("div", { className: j.canvasClock, style: { width: a, height: a }, children: /* @__PURE__ */ n("canvas", { ref: u, className: j.canvasTarget, style: { width: a, height: a } }) });
40
- }, x = "cos-chargeContainer", J = "cos-contrast", K = "cos-text", V = "cos-circle", X = "cos-button", k = {
41
- chargeContainer: x,
42
- contrast: J,
43
- text: K,
44
- circle: V,
45
- button: X
46
- }, mt = (r) => {
47
- const { initQuantity: f = 0 } = r, [u, a] = H(f);
48
- return F(() => {
49
- let o = u;
50
- setInterval(() => {
51
- o = Number(Number(o += 0.01).toFixed(2)), a(o);
52
- }, 500);
53
- }, []), /* @__PURE__ */ n("div", { className: k.chargeContainer, children: /* @__PURE__ */ S("div", { className: k.contrast, children: [
54
- /* @__PURE__ */ S("div", { className: k.text, children: [
55
- u ? u.toString().padEnd(4, "0") : 0,
56
- "%"
57
- ] }),
58
- /* @__PURE__ */ n("span", {}),
59
- /* @__PURE__ */ n("span", {}),
60
- /* @__PURE__ */ n("span", {}),
61
- /* @__PURE__ */ n("span", {}),
62
- /* @__PURE__ */ n("span", {}),
63
- /* @__PURE__ */ n("span", {}),
64
- /* @__PURE__ */ n("span", {}),
65
- /* @__PURE__ */ n("span", {}),
66
- /* @__PURE__ */ n("span", {}),
67
- /* @__PURE__ */ n("span", {}),
68
- /* @__PURE__ */ n("span", {}),
69
- /* @__PURE__ */ n("span", {}),
70
- /* @__PURE__ */ n("span", {}),
71
- /* @__PURE__ */ n("span", {}),
72
- /* @__PURE__ */ n("span", {}),
73
- /* @__PURE__ */ n("div", { className: k.circle }),
74
- /* @__PURE__ */ n("div", { className: k.button })
75
- ] }) });
76
- }, z = "cos-returnCityContainer", tt = "cos-star", et = "cos-glassWrap", nt = "cos-glassItem", $ = {
77
- returnCityContainer: z,
78
- star: tt,
79
- glassWrap: et,
80
- glassItem: nt
81
- }, ft = () => {
82
- const r = (u, a) => {
83
- for (let o = 0; o < a; o++)
84
- setTimeout(function() {
85
- const l = document.createElement("div");
86
- l.className = $.star;
87
- const g = document.body.clientWidth, t = document.body.clientHeight, c = Math.random() * g + "px", y = Math.random() * t + "px";
88
- l.style.top = y, l.style.left = c, u.append(l);
89
- }, Math.random() * 2e3);
90
- }, f = () => {
91
- const a = "150px", o = document.getElementById("glassWrap");
92
- if (o)
93
- for (let l = 0; l < 6; l++) {
94
- const g = document.createElement("div");
95
- g.className = $.glassItem, g.style.transform = `rotateY(${l * 60}deg) translateZ(${a})`, o.appendChild(g), setTimeout(() => {
96
- g.style.top = "0px", g.style.opacity = "1";
97
- }, l * 300);
98
- }
99
- };
100
- return F(() => {
101
- const u = document.getElementById("returnCityContainer");
102
- u && r(u, document.documentElement.clientWidth / 20), f();
103
- }, []), /* @__PURE__ */ n("div", { id: "returnCityContainer", className: $.returnCityContainer, children: /* @__PURE__ */ n("div", { id: "glassWrap", className: $.glassWrap }) });
104
- }, st = "cos-turntable", at = "cos-wheelWrap", ot = "cos-canvas", rt = "cos-pointer", lt = "cos-spinBtn", ct = "cos-result", N = {
105
- turntable: st,
106
- wheelWrap: at,
107
- canvas: ot,
108
- pointer: rt,
109
- spinBtn: lt,
110
- result: ct
111
- }, U = ["#FF6B6B", "#4ECDC4", "#FFE66D", "#A78BFA", "#60A5FA", "#F472B6", "#34D399", "#FB923C"], it = [
112
- { label: "一等奖" },
113
- { label: "二等奖" },
114
- { label: "三等奖" },
115
- { label: "谢谢参与" },
116
- { label: "优惠券" },
117
- { label: "再来一次" }
118
- ], ht = (r) => 1 - Math.pow(1 - r, 3), pt = ({
119
- prizes: r = it,
120
- size: f = 360,
121
- spinDuration: u = 4e3,
122
- spinRounds: a = 5,
123
- buttonText: o = "开始抽奖",
124
- onSpinEnd: l
125
- }) => {
126
- const g = W(null), t = W(0), c = W(0), y = W(1), [p, M] = H(!1), [B, w] = H(null), h = f + 48, D = (s, i) => i.color ?? U[s % U.length], A = Z(
127
- (s) => {
128
- const i = g.current;
129
- if (!i) return;
130
- const e = i.getContext("2d");
131
- if (!e) return;
132
- const v = h / 2, C = f / 2, R = Math.PI * 2 / r.length;
133
- e.clearRect(0, 0, h, h), e.save(), e.translate(v, v), e.rotate(s), r.forEach((b, I) => {
134
- const P = I * R - Math.PI / 2, T = P + R, q = D(I, b);
135
- e.beginPath(), e.moveTo(0, 0), e.arc(0, 0, C, P, T), e.closePath(), e.fillStyle = q, e.fill(), e.strokeStyle = "rgb(255 255 255 / 35%)", e.lineWidth = 2, e.stroke(), e.save(), e.rotate(P + R / 2), e.textAlign = "right", e.fillStyle = "#fff", e.font = `bold ${Math.max(12, Math.floor(f / 22))}px system-ui, sans-serif`, e.shadowColor = "rgb(0 0 0 / 30%)", e.shadowBlur = 4, e.fillText(b.label, C - 18, 6), e.restore();
136
- }), e.beginPath(), e.arc(0, 0, C, 0, Math.PI * 2), e.strokeStyle = "#fbbf24", e.lineWidth = 6, e.stroke(), e.beginPath(), e.arc(0, 0, C - 4, 0, Math.PI * 2), e.strokeStyle = "#f59e0b", e.lineWidth = 2, e.stroke(), e.restore(), e.save(), e.translate(v, v);
137
- for (let b = 0; b < 12; b++) {
138
- const I = b / 12 * Math.PI * 2, P = Math.cos(I) * (C + 14), T = Math.sin(I) * (C + 14);
139
- e.beginPath(), e.arc(P, T, 3, 0, Math.PI * 2), e.fillStyle = b % 2 === 0 ? "#fde68a" : "#f59e0b", e.fill();
140
- }
141
- e.restore();
142
- },
143
- [h, r, f]
144
- );
145
- F(() => {
146
- const s = g.current;
147
- if (!s) return;
148
- const i = window.devicePixelRatio || 1;
149
- y.current = i, s.width = h * i, s.height = h * i;
150
- const e = s.getContext("2d");
151
- e && e.setTransform(i, 0, 0, i, 0, 0), A(t.current);
152
- }, [h, A]), F(() => () => {
153
- c.current && cancelAnimationFrame(c.current);
154
- }, []);
155
- const d = (s) => {
156
- const i = 360 / r.length, e = (s * (180 / Math.PI) % 360 + 360) % 360;
157
- return Math.floor((360 - e + i / 2) % 360 / i) % r.length;
158
- }, m = () => {
159
- if (p || r.length === 0) return;
160
- M(!0), w(null);
161
- const s = Math.PI * 2 / r.length, e = Math.floor(Math.random() * r.length) * s + s / 2, v = t.current, C = a * Math.PI * 2, R = v + C + (Math.PI * 2 - e) - v % (Math.PI * 2), b = v, I = performance.now(), P = (T) => {
162
- const q = T - I, L = Math.min(q / u, 1), _ = ht(L), E = b + (R - b) * _;
163
- if (t.current = E, A(E), L < 1)
164
- c.current = requestAnimationFrame(P);
165
- else {
166
- const O = d(E), Q = r[O];
167
- t.current = E, M(!1), w(Q), l == null || l(Q, O);
168
- }
169
- };
170
- c.current = requestAnimationFrame(P);
171
- };
172
- return /* @__PURE__ */ S("div", { className: N.turntable, style: { width: h, height: h + 80 }, children: [
173
- /* @__PURE__ */ S("div", { className: N.wheelWrap, style: { width: h, height: h }, children: [
174
- /* @__PURE__ */ n("div", { className: N.pointer }),
175
- /* @__PURE__ */ n("canvas", { ref: g, className: N.canvas, style: { width: h, height: h } }),
176
- /* @__PURE__ */ n("button", { type: "button", className: N.spinBtn, onClick: m, disabled: p, children: p ? "抽奖中..." : o })
177
- ] }),
178
- B && !p && /* @__PURE__ */ S("p", { className: N.result, children: [
179
- "恭喜获得:",
180
- /* @__PURE__ */ n("strong", { children: B.label })
181
- ] })
182
- ] });
183
- };
184
- export {
185
- gt as CanvasClock,
186
- mt as Charge,
187
- ft as ReturnCity,
188
- pt as Turntable
189
- };
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
+ canvasClock: "cos-canvasClock",
5
+ canvasTarget: "cos-canvasTarget"
6
+ }, s = ({ width: r = 400, height: a = 400 }) => {
7
+ let s = n(null), c = Math.min(r, a), l = c / 2 - 16, u = c / 2, d = e((e) => {
8
+ e.clearRect(0, 0, c, c), e.save(), e.translate(u, u), e.beginPath(), e.arc(0, 0, l, 0, Math.PI * 2), e.fillStyle = "#fff", e.fill(), e.strokeStyle = "#d1d5db", e.lineWidth = 2, e.stroke();
9
+ for (let t = 0; t < 60; t++) {
10
+ let n = t / 60 * Math.PI * 2, r = l - (t % 5 == 0 ? 14 : 8);
11
+ e.beginPath(), e.moveTo(Math.cos(n) * r, Math.sin(n) * r), e.lineTo(Math.cos(n) * l, Math.sin(n) * l), e.strokeStyle = t % 5 == 0 ? "#374151" : "#9ca3af", e.lineWidth = t % 5 == 0 ? 2 : 1, e.stroke();
12
+ }
13
+ e.fillStyle = "#111827", e.font = `bold ${Math.floor(c / 22)}px system-ui, sans-serif`, e.textAlign = "center", e.textBaseline = "middle";
14
+ for (let t = 1; t <= 12; t++) {
15
+ let n = t / 12 * Math.PI * 2 - Math.PI / 2, r = l - 32;
16
+ e.fillText(String(t), Math.cos(n) * r, Math.sin(n) * r);
17
+ }
18
+ let t = /* @__PURE__ */ new Date(), n = t.getHours() % 12, r = t.getMinutes(), i = t.getSeconds(), a = t.getMilliseconds(), o = (t, n, r, i, a) => {
19
+ e.save(), e.rotate(t), e.beginPath(), e.moveTo(0, r), e.lineTo(n, 0), e.lineTo(0, -r), e.closePath(), e.fillStyle = i, e.shadowColor = a, e.shadowBlur = 4, e.fill(), e.restore();
20
+ }, s = (n + r / 60) / 12 * Math.PI * 2 - Math.PI / 2, d = (r + i / 60) / 60 * Math.PI * 2 - Math.PI / 2, f = (i + a / 1e3) / 60 * Math.PI * 2 - Math.PI / 2;
21
+ o(s, l * .5, 4, "#111827", "rgb(0 0 0 / 40%)"), o(d, l * .72, 3, "#1e80ff", "rgb(30 128 255 / 40%)"), o(f, l * .85, 2, "#e9686b", "rgb(233 104 107 / 40%)"), e.beginPath(), e.arc(0, 0, 5, 0, Math.PI * 2), e.fillStyle = "#111827", e.fill(), e.restore();
22
+ }, [
23
+ u,
24
+ l,
25
+ c
26
+ ]);
27
+ return t(() => {
28
+ let e = s.current;
29
+ if (!e) return;
30
+ let t = window.devicePixelRatio || 1;
31
+ e.width = c * t, e.height = c * t;
32
+ let n = e.getContext("2d");
33
+ if (!n) return;
34
+ n.setTransform(t, 0, 0, t, 0, 0);
35
+ let r = 0, i = () => {
36
+ d(n), r = requestAnimationFrame(i);
37
+ };
38
+ return i(), () => cancelAnimationFrame(r);
39
+ }, [d, c]), /* @__PURE__ */ i("div", {
40
+ className: o.canvasClock,
41
+ style: {
42
+ width: c,
43
+ height: c
44
+ },
45
+ children: /* @__PURE__ */ i("canvas", {
46
+ ref: s,
47
+ className: o.canvasTarget,
48
+ style: {
49
+ width: c,
50
+ height: c
51
+ }
52
+ })
53
+ });
54
+ }, c = {
55
+ chargeContainer: "cos-chargeContainer",
56
+ contrast: "cos-contrast",
57
+ hueRotate: "cos-hueRotate",
58
+ text: "cos-text",
59
+ moveUp: "cos-moveUp",
60
+ circle: "cos-circle",
61
+ circleRotate: "cos-circleRotate",
62
+ button: "cos-button"
63
+ }, l = (e) => {
64
+ let { initQuantity: n = 0 } = e, [o, s] = r(n);
65
+ return t(() => {
66
+ let e = o;
67
+ setInterval(() => {
68
+ e = Number(Number(e += .01).toFixed(2)), s(e);
69
+ }, 500);
70
+ }, []), /* @__PURE__ */ i("div", {
71
+ className: c.chargeContainer,
72
+ children: /* @__PURE__ */ a("div", {
73
+ className: c.contrast,
74
+ children: [
75
+ /* @__PURE__ */ a("div", {
76
+ className: c.text,
77
+ children: [o ? o.toString().padEnd(4, "0") : 0, "%"]
78
+ }),
79
+ /* @__PURE__ */ i("span", {}),
80
+ /* @__PURE__ */ i("span", {}),
81
+ /* @__PURE__ */ i("span", {}),
82
+ /* @__PURE__ */ i("span", {}),
83
+ /* @__PURE__ */ i("span", {}),
84
+ /* @__PURE__ */ i("span", {}),
85
+ /* @__PURE__ */ i("span", {}),
86
+ /* @__PURE__ */ i("span", {}),
87
+ /* @__PURE__ */ i("span", {}),
88
+ /* @__PURE__ */ i("span", {}),
89
+ /* @__PURE__ */ i("span", {}),
90
+ /* @__PURE__ */ i("span", {}),
91
+ /* @__PURE__ */ i("span", {}),
92
+ /* @__PURE__ */ i("span", {}),
93
+ /* @__PURE__ */ i("span", {}),
94
+ /* @__PURE__ */ i("div", { className: c.circle }),
95
+ /* @__PURE__ */ i("div", { className: c.button })
96
+ ]
97
+ })
98
+ });
99
+ }, u = {
100
+ fireworks: "cos-fireworks",
101
+ canvas: "cos-canvas",
102
+ hint: "cos-hint"
103
+ }, d = [
104
+ "#ff6b6b",
105
+ "#ffd93d",
106
+ "#6bcb77",
107
+ "#4d96ff",
108
+ "#a66cff",
109
+ "#ff85c0"
110
+ ], f = () => d[Math.floor(Math.random() * d.length)], p = (e, t, n) => {
111
+ let r = 60 + Math.floor(Math.random() * 30);
112
+ return Array.from({ length: r }, () => {
113
+ let r = Math.random() * Math.PI * 2, i = Math.random() * 4 + 2;
114
+ return {
115
+ x: e,
116
+ y: t,
117
+ vx: Math.cos(r) * i,
118
+ vy: Math.sin(r) * i,
119
+ alpha: 1,
120
+ color: Math.random() > .3 ? n : f(),
121
+ decay: Math.random() * .015 + .01
122
+ };
123
+ });
124
+ }, m = ({ width: r = 800, height: o = 500, auto: s = !0 }) => {
125
+ let c = n(null), l = n([]), d = n(0), m = e((e) => {
126
+ let t = e ?? Math.random() * r * .6 + r * .2;
127
+ l.current.push({
128
+ x: t,
129
+ y: o,
130
+ vy: -(Math.random() * 4 + 6),
131
+ targetY: Math.random() * o * .4 + o * .1,
132
+ color: f(),
133
+ exploded: !1,
134
+ particles: []
135
+ });
136
+ }, [o, r]);
137
+ return t(() => {
138
+ let e = c.current;
139
+ if (!e) return;
140
+ let t = window.devicePixelRatio || 1;
141
+ e.width = r * t, e.height = o * t;
142
+ let n = e.getContext("2d");
143
+ if (!n) return;
144
+ n.setTransform(t, 0, 0, t, 0, 0);
145
+ let i = 0, a = () => {
146
+ d.current = requestAnimationFrame(a), n.fillStyle = "rgb(15 23 42 / 25%)", n.fillRect(0, 0, r, o), s && Math.random() < .03 && m(), l.current = l.current.filter((e) => e.exploded ? (e.particles = e.particles.filter((e) => (e.x += e.vx, e.y += e.vy, e.vy += .06, e.alpha -= e.decay, e.alpha <= 0 ? !1 : (n.beginPath(), n.arc(e.x, e.y, 2, 0, Math.PI * 2), n.fillStyle = e.color, n.globalAlpha = e.alpha, n.fill(), n.globalAlpha = 1, !0))), e.particles.length > 0) : (e.y += e.vy, e.vy *= .98, n.beginPath(), n.arc(e.x, e.y, 2.5, 0, Math.PI * 2), n.fillStyle = e.color, n.fill(), (e.vy >= 0 || e.y <= e.targetY) && (e.exploded = !0, e.particles = p(e.x, e.y, e.color)), !0));
147
+ };
148
+ return a(), s && (i = window.setInterval(() => m(), 1200)), () => {
149
+ cancelAnimationFrame(d.current), clearInterval(i);
150
+ };
151
+ }, [
152
+ s,
153
+ o,
154
+ m,
155
+ r
156
+ ]), /* @__PURE__ */ a("div", {
157
+ className: u.fireworks,
158
+ style: {
159
+ width: r,
160
+ height: o
161
+ },
162
+ children: [/* @__PURE__ */ i("canvas", {
163
+ ref: c,
164
+ className: u.canvas,
165
+ style: {
166
+ width: r,
167
+ height: o
168
+ },
169
+ onClick: (e) => {
170
+ let t = e.currentTarget.getBoundingClientRect();
171
+ m(e.clientX - t.left);
172
+ }
173
+ }), /* @__PURE__ */ i("p", {
174
+ className: u.hint,
175
+ children: "点击画布燃放烟花"
176
+ })]
177
+ });
178
+ }, h = {
179
+ matrixRain: "cos-matrixRain",
180
+ canvas: "cos-canvas",
181
+ overlay: "cos-overlay",
182
+ title: "cos-title",
183
+ flicker: "cos-flicker",
184
+ subtitle: "cos-subtitle"
185
+ }, g = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*アイウエオカキクケコ", _ = ({ width: e = 800, height: r = 500, density: o = .6, color: s = "#00ff41" }) => {
186
+ let c = n(null);
187
+ return t(() => {
188
+ let t = c.current;
189
+ if (!t) return;
190
+ let n = window.devicePixelRatio || 1;
191
+ t.width = e * n, t.height = r * n;
192
+ let i = t.getContext("2d");
193
+ if (!i) return;
194
+ i.setTransform(n, 0, 0, n, 0, 0);
195
+ let a = Math.floor(e / 16 * o), l = Array.from({ length: a }, () => Math.random() * -50), u = 0, d = () => {
196
+ i.fillStyle = "rgb(0 0 0 / 8%)", i.fillRect(0, 0, e, r), i.fillStyle = s, i.font = "16px monospace", l.forEach((e, t) => {
197
+ let n = g[Math.floor(Math.random() * 53)], a = t / o * 16;
198
+ i.fillStyle = s, i.fillText(n, a, e * 16), e * 16 > r && Math.random() > .975 && (l[t] = 0), l[t] += 1;
199
+ }), u = requestAnimationFrame(d);
200
+ };
201
+ return d(), () => cancelAnimationFrame(u);
202
+ }, [
203
+ s,
204
+ o,
205
+ r,
206
+ e
207
+ ]), /* @__PURE__ */ a("div", {
208
+ className: h.matrixRain,
209
+ style: {
210
+ width: e,
211
+ height: r
212
+ },
213
+ children: [/* @__PURE__ */ i("canvas", {
214
+ ref: c,
215
+ className: h.canvas,
216
+ style: {
217
+ width: e,
218
+ height: r
219
+ }
220
+ }), /* @__PURE__ */ a("div", {
221
+ className: h.overlay,
222
+ children: [/* @__PURE__ */ i("h2", {
223
+ className: h.title,
224
+ children: "MATRIX"
225
+ }), /* @__PURE__ */ i("p", {
226
+ className: h.subtitle,
227
+ children: "数字雨效果"
228
+ })]
229
+ })]
230
+ });
231
+ }, v = {
232
+ neonText: "cos-neonText",
233
+ text: "cos-text",
234
+ flicker: "cos-flicker",
235
+ "neon-flicker": "cos-neon-flicker",
236
+ reflection: "cos-reflection"
237
+ }, y = ({ text: e = "NEON", color: t = "#ff00de", fontSize: n = 72, flicker: r = !0 }) => /* @__PURE__ */ a("div", {
238
+ className: v.neonText,
239
+ children: [/* @__PURE__ */ i("h1", {
240
+ className: `${v.text} ${r ? v.flicker : ""}`,
241
+ style: {
242
+ fontSize: n,
243
+ "--neon-color": t
244
+ },
245
+ children: e
246
+ }), /* @__PURE__ */ i("p", {
247
+ className: v.reflection,
248
+ style: {
249
+ fontSize: n * .35,
250
+ color: t
251
+ },
252
+ children: e
253
+ })]
254
+ }), b = {
255
+ particleNetwork: "cos-particleNetwork",
256
+ canvas: "cos-canvas",
257
+ hint: "cos-hint"
258
+ }, x = ({ width: r = 800, height: o = 500, particleCount: s = 60, linkDistance: c = 120, color: l = "#38bdf8" }) => {
259
+ let u = n(null), d = n([]), f = n({
260
+ x: -1e3,
261
+ y: -1e3
262
+ }), p = e(() => {
263
+ d.current = Array.from({ length: s }, () => ({
264
+ x: Math.random() * r,
265
+ y: Math.random() * o,
266
+ vx: (Math.random() - .5) * 1.2,
267
+ vy: (Math.random() - .5) * 1.2,
268
+ radius: Math.random() * 2 + 1
269
+ }));
270
+ }, [
271
+ o,
272
+ s,
273
+ r
274
+ ]);
275
+ return t(() => {
276
+ p();
277
+ }, [p]), t(() => {
278
+ let e = u.current;
279
+ if (!e) return;
280
+ let t = window.devicePixelRatio || 1;
281
+ e.width = r * t, e.height = o * t;
282
+ let n = e.getContext("2d");
283
+ if (!n) return;
284
+ n.setTransform(t, 0, 0, t, 0, 0);
285
+ let i = 0, a = () => {
286
+ n.fillStyle = "#0f172a", n.fillRect(0, 0, r, o);
287
+ let e = d.current, t = f.current;
288
+ e.forEach((e) => {
289
+ e.x += e.vx, e.y += e.vy, (e.x < 0 || e.x > r) && (e.vx *= -1), (e.y < 0 || e.y > o) && (e.vy *= -1);
290
+ let n = t.x - e.x, i = t.y - e.y;
291
+ Math.sqrt(n * n + i * i) < 150 && (e.vx -= n * 3e-4, e.vy -= i * 3e-4);
292
+ });
293
+ for (let t = 0; t < e.length; t++) for (let r = t + 1; r < e.length; r++) {
294
+ let i = e[t].x - e[r].x, a = e[t].y - e[r].y, o = Math.sqrt(i * i + a * a);
295
+ o < c && (n.beginPath(), n.moveTo(e[t].x, e[t].y), n.lineTo(e[r].x, e[r].y), n.strokeStyle = l, n.globalAlpha = 1 - o / c, n.lineWidth = .8, n.stroke(), n.globalAlpha = 1);
296
+ }
297
+ e.forEach((e) => {
298
+ n.beginPath(), n.arc(e.x, e.y, e.radius, 0, Math.PI * 2), n.fillStyle = l, n.fill();
299
+ }), i = requestAnimationFrame(a);
300
+ };
301
+ return a(), () => cancelAnimationFrame(i);
302
+ }, [
303
+ l,
304
+ o,
305
+ p,
306
+ c,
307
+ r
308
+ ]), /* @__PURE__ */ a("div", {
309
+ className: b.particleNetwork,
310
+ style: {
311
+ width: r,
312
+ height: o
313
+ },
314
+ children: [/* @__PURE__ */ i("canvas", {
315
+ ref: u,
316
+ className: b.canvas,
317
+ style: {
318
+ width: r,
319
+ height: o
320
+ },
321
+ onMouseMove: (e) => {
322
+ let t = e.currentTarget.getBoundingClientRect();
323
+ f.current = {
324
+ x: e.clientX - t.left,
325
+ y: e.clientY - t.top
326
+ };
327
+ },
328
+ onMouseLeave: () => {
329
+ f.current = {
330
+ x: -1e3,
331
+ y: -1e3
332
+ };
333
+ }
334
+ }), /* @__PURE__ */ i("p", {
335
+ className: b.hint,
336
+ children: "移动鼠标与粒子互动"
337
+ })]
338
+ });
339
+ }, S = {
340
+ returnCityContainer: "cos-returnCityContainer",
341
+ star: "cos-star",
342
+ glassWrap: "cos-glassWrap",
343
+ rotate: "cos-rotate",
344
+ glassItem: "cos-glassItem"
345
+ }, C = () => {
346
+ let e = (e, t) => {
347
+ for (let n = 0; n < t; n++) setTimeout(function() {
348
+ let t = document.createElement("div");
349
+ t.className = S.star;
350
+ let n = document.body.clientWidth, r = document.body.clientHeight, i = Math.random() * n + "px", a = Math.random() * r + "px";
351
+ t.style.top = a, t.style.left = i, e.append(t);
352
+ }, Math.random() * 2e3);
353
+ }, n = () => {
354
+ let e = document.getElementById("glassWrap");
355
+ if (e) for (let t = 0; t < 6; t++) {
356
+ let n = document.createElement("div");
357
+ n.className = S.glassItem, n.style.transform = `rotateY(${360 / 6 * t}deg) translateZ(150px)`, e.appendChild(n), setTimeout(() => {
358
+ n.style.top = "0px", n.style.opacity = "1";
359
+ }, t * 300);
360
+ }
361
+ };
362
+ return t(() => {
363
+ let t = document.getElementById("returnCityContainer");
364
+ t && e(t, document.documentElement.clientWidth / 20), n();
365
+ }, []), /* @__PURE__ */ i("div", {
366
+ id: "returnCityContainer",
367
+ className: S.returnCityContainer,
368
+ children: /* @__PURE__ */ i("div", {
369
+ id: "glassWrap",
370
+ className: S.glassWrap
371
+ })
372
+ });
373
+ }, w = {
374
+ turntable: "cos-turntable",
375
+ wheelWrap: "cos-wheelWrap",
376
+ canvas: "cos-canvas",
377
+ pointer: "cos-pointer",
378
+ spinBtn: "cos-spinBtn",
379
+ result: "cos-result",
380
+ "fade-in": "cos-fade-in"
381
+ }, T = [
382
+ "#FF6B6B",
383
+ "#4ECDC4",
384
+ "#FFE66D",
385
+ "#A78BFA",
386
+ "#60A5FA",
387
+ "#F472B6",
388
+ "#34D399",
389
+ "#FB923C"
390
+ ], E = [
391
+ { label: "一等奖" },
392
+ { label: "二等奖" },
393
+ { label: "三等奖" },
394
+ { label: "谢谢参与" },
395
+ { label: "优惠券" },
396
+ { label: "再来一次" }
397
+ ], D = (e) => 1 - (1 - e) ** 3, O = ({ prizes: o = E, size: s = 360, spinDuration: c = 4e3, spinRounds: l = 5, buttonText: u = "开始抽奖", onSpinEnd: d }) => {
398
+ let f = n(null), p = n(0), m = n(0), h = n(1), [g, _] = r(!1), [v, y] = r(null), b = s + 48, x = (e, t) => t.color ?? T[e % T.length], S = e((e) => {
399
+ let t = f.current;
400
+ if (!t) return;
401
+ let n = t.getContext("2d");
402
+ if (!n) return;
403
+ let r = b / 2, i = s / 2, a = Math.PI * 2 / o.length;
404
+ n.clearRect(0, 0, b, b), n.save(), n.translate(r, r), n.rotate(e), o.forEach((e, t) => {
405
+ let r = t * a - Math.PI / 2, o = r + a, c = x(t, e);
406
+ n.beginPath(), n.moveTo(0, 0), n.arc(0, 0, i, r, o), n.closePath(), n.fillStyle = c, n.fill(), n.strokeStyle = "rgb(255 255 255 / 35%)", n.lineWidth = 2, n.stroke(), n.save(), n.rotate(r + a / 2), n.textAlign = "right", n.fillStyle = "#fff", n.font = `bold ${Math.max(12, Math.floor(s / 22))}px system-ui, sans-serif`, n.shadowColor = "rgb(0 0 0 / 30%)", n.shadowBlur = 4, n.fillText(e.label, i - 18, 6), n.restore();
407
+ }), n.beginPath(), n.arc(0, 0, i, 0, Math.PI * 2), n.strokeStyle = "#fbbf24", n.lineWidth = 6, n.stroke(), n.beginPath(), n.arc(0, 0, i - 4, 0, Math.PI * 2), n.strokeStyle = "#f59e0b", n.lineWidth = 2, n.stroke(), n.restore(), n.save(), n.translate(r, r);
408
+ for (let e = 0; e < 12; e++) {
409
+ let t = e / 12 * Math.PI * 2, r = Math.cos(t) * (i + 14), a = Math.sin(t) * (i + 14);
410
+ n.beginPath(), n.arc(r, a, 3, 0, Math.PI * 2), n.fillStyle = e % 2 == 0 ? "#fde68a" : "#f59e0b", n.fill();
411
+ }
412
+ n.restore();
413
+ }, [
414
+ b,
415
+ o,
416
+ s
417
+ ]);
418
+ t(() => {
419
+ let e = f.current;
420
+ if (!e) return;
421
+ let t = window.devicePixelRatio || 1;
422
+ h.current = t, e.width = b * t, e.height = b * t;
423
+ let n = e.getContext("2d");
424
+ n && n.setTransform(t, 0, 0, t, 0, 0), S(p.current);
425
+ }, [b, S]), t(() => () => {
426
+ m.current && cancelAnimationFrame(m.current);
427
+ }, []);
428
+ let C = (e) => {
429
+ let t = 360 / o.length, n = (180 / Math.PI * e % 360 + 360) % 360;
430
+ return Math.floor((360 - n + t / 2) % 360 / t) % o.length;
431
+ };
432
+ return /* @__PURE__ */ a("div", {
433
+ className: w.turntable,
434
+ style: {
435
+ width: b,
436
+ height: b + 80
437
+ },
438
+ children: [/* @__PURE__ */ a("div", {
439
+ className: w.wheelWrap,
440
+ style: {
441
+ width: b,
442
+ height: b
443
+ },
444
+ children: [
445
+ /* @__PURE__ */ i("div", { className: w.pointer }),
446
+ /* @__PURE__ */ i("canvas", {
447
+ ref: f,
448
+ className: w.canvas,
449
+ style: {
450
+ width: b,
451
+ height: b
452
+ }
453
+ }),
454
+ /* @__PURE__ */ i("button", {
455
+ type: "button",
456
+ className: w.spinBtn,
457
+ onClick: () => {
458
+ if (g || o.length === 0) return;
459
+ _(!0), y(null);
460
+ let e = Math.PI * 2 / o.length, t = Math.floor(Math.random() * o.length) * e + e / 2, n = p.current, r = n + l * Math.PI * 2 + (Math.PI * 2 - t) - n % (Math.PI * 2), i = n, a = performance.now(), s = (e) => {
461
+ let t = e - a, n = Math.min(t / c, 1), l = D(n), u = i + (r - i) * l;
462
+ if (p.current = u, S(u), n < 1) m.current = requestAnimationFrame(s);
463
+ else {
464
+ let e = C(u), t = o[e];
465
+ p.current = u, _(!1), y(t), d?.(t, e);
466
+ }
467
+ };
468
+ m.current = requestAnimationFrame(s);
469
+ },
470
+ disabled: g,
471
+ children: g ? "抽奖中..." : u
472
+ })
473
+ ]
474
+ }), v && !g && /* @__PURE__ */ a("p", {
475
+ className: w.result,
476
+ children: ["恭喜获得:", /* @__PURE__ */ i("strong", { children: v.label })]
477
+ })]
478
+ });
479
+ }, k = {
480
+ typewriter: "cos-typewriter",
481
+ terminal: "cos-terminal",
482
+ dots: "cos-dots",
483
+ text: "cos-text",
484
+ prompt: "cos-prompt",
485
+ cursor: "cos-cursor",
486
+ blink: "cos-blink"
487
+ }, A = [
488
+ "Hello, cos-design!",
489
+ "欢迎来到组件库 ✨",
490
+ "Build something fun 🚀"
491
+ ], j = ({ texts: e = A, speed: n = 100, deleteSpeed: o = 50, pause: s = 2e3 }) => {
492
+ let [c, l] = r(""), [u, d] = r(0), [f, p] = r(!1);
493
+ return t(() => {
494
+ let t = e[u % e.length], r;
495
+ if (!f && c === t) r = setTimeout(() => p(!0), s);
496
+ else if (f && c === "") r = setTimeout(() => {
497
+ p(!1), d((t) => (t + 1) % e.length);
498
+ }, 0);
499
+ else {
500
+ let e = f ? t.slice(0, c.length - 1) : t.slice(0, c.length + 1);
501
+ r = setTimeout(() => l(e), f ? o : n);
502
+ }
503
+ return () => clearTimeout(r);
504
+ }, [
505
+ c,
506
+ f,
507
+ u,
508
+ e,
509
+ n,
510
+ o,
511
+ s
512
+ ]), /* @__PURE__ */ i("div", {
513
+ className: k.typewriter,
514
+ children: /* @__PURE__ */ a("div", {
515
+ className: k.terminal,
516
+ children: [/* @__PURE__ */ a("div", {
517
+ className: k.dots,
518
+ children: [
519
+ /* @__PURE__ */ i("span", {}),
520
+ /* @__PURE__ */ i("span", {}),
521
+ /* @__PURE__ */ i("span", {})
522
+ ]
523
+ }), /* @__PURE__ */ a("p", {
524
+ className: k.text,
525
+ children: [
526
+ /* @__PURE__ */ i("span", {
527
+ className: k.prompt,
528
+ children: ">"
529
+ }),
530
+ c,
531
+ /* @__PURE__ */ i("span", {
532
+ className: k.cursor,
533
+ children: "|"
534
+ })
535
+ ]
536
+ })]
537
+ })
538
+ });
539
+ }, M = {
540
+ waveButton: "cos-waveButton",
541
+ btn: "cos-btn",
542
+ label: "cos-label",
543
+ wave: "cos-wave",
544
+ ripple: "cos-ripple"
545
+ }, N = ({ text: e = "点我试试", onClick: t, color: n = "#38bdf8" }) => /* @__PURE__ */ i("div", {
546
+ className: M.waveButton,
547
+ children: /* @__PURE__ */ a("button", {
548
+ type: "button",
549
+ className: M.btn,
550
+ style: { "--wave-color": n },
551
+ onClick: t,
552
+ children: [
553
+ /* @__PURE__ */ i("span", { className: M.wave }),
554
+ /* @__PURE__ */ i("span", { className: M.wave }),
555
+ /* @__PURE__ */ i("span", {
556
+ className: M.label,
557
+ children: e
558
+ })
559
+ ]
560
+ })
561
+ });
562
+ //#endregion
563
+ export { s as CanvasClock, l as Charge, m as Fireworks, _ as MatrixRain, y as NeonText, x as ParticleNetwork, C as ReturnCity, O as Turntable, j as Typewriter, N as WaveButton };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cos-design",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "A React component library built with Vite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -52,41 +52,46 @@
52
52
  "**/*.{ts,tsx}": "eslint --fix"
53
53
  },
54
54
  "devDependencies": {
55
- "@types/node": "^22.13.10",
56
- "@types/react": "^18.3.18",
57
- "@types/react-dom": "^18.3.5",
58
- "@typescript-eslint/eslint-plugin": "^8.26.0",
59
- "@typescript-eslint/parser": "^8.26.0",
60
- "@vitejs/plugin-react": "^4.3.4",
61
- "eslint": "^8.57.1",
62
- "eslint-config-prettier": "^10.0.2",
63
- "eslint-plugin-prettier": "^5.2.3",
64
- "eslint-plugin-react": "^7.37.4",
65
- "eslint-plugin-react-hooks": "^5.2.0",
55
+ "@eslint/js": "^9.39.1",
56
+ "@types/node": "^22.19.21",
57
+ "@types/react": "^19.2.17",
58
+ "@types/react-dom": "^19.2.3",
59
+ "@vitejs/plugin-react": "^6.0.2",
60
+ "eslint": "^9.39.1",
61
+ "eslint-config-prettier": "^10.1.8",
62
+ "eslint-plugin-prettier": "^5.5.6",
63
+ "eslint-plugin-react": "^7.37.5",
64
+ "eslint-plugin-react-hooks": "^7.1.1",
65
+ "globals": "^16.0.0",
66
66
  "husky": "^9.1.7",
67
- "less": "^4.2.2",
68
- "lint-staged": "^15.4.3",
69
- "only-allow": "^1.2.1",
70
- "prettier": "^3.5.3",
71
- "react": "^18.3.1",
72
- "react-dom": "^18.3.1",
73
- "react-router": "^6.30.0",
74
- "react-router-dom": "^6.30.0",
75
- "stylelint": "^16.15.0",
76
- "stylelint-config-standard": "^37.0.0",
77
- "typescript": "^5.8.2",
78
- "vite": "^6.2.2",
79
- "vite-plugin-dts": "^4.5.3",
80
- "vite-plugin-lib-inject-css": "^2.2.1"
67
+ "less": "^4.6.6",
68
+ "lint-staged": "^16.2.7",
69
+ "only-allow": "^1.2.2",
70
+ "prettier": "^3.8.4",
71
+ "react": "^19.2.7",
72
+ "react-dom": "^19.2.7",
73
+ "react-router": "^7.18.0",
74
+ "react-router-dom": "^7.18.0",
75
+ "stylelint": "^17.13.0",
76
+ "stylelint-config-standard": "^40.0.0",
77
+ "typescript": "^5.9.3",
78
+ "typescript-eslint": "^8.61.1",
79
+ "vite": "^8.0.16",
80
+ "vite-plugin-dts": "^5.0.2",
81
+ "vite-plugin-lib-inject-css": "^2.2.2"
81
82
  },
82
83
  "peerDependencies": {
83
- "react": ">=16.12.0",
84
- "react-dom": ">=16.12.0"
84
+ "react": ">=18.0.0",
85
+ "react-dom": ">=18.0.0"
85
86
  },
86
87
  "engines": {
87
- "node": ">=18",
88
+ "node": ">=20",
88
89
  "pnpm": ">=9"
89
90
  },
91
+ "publishConfig": {
92
+ "access": "public",
93
+ "registry": "https://registry.npmjs.org"
94
+ },
90
95
  "scripts": {
91
96
  "setup": "node scripts/install.mjs",
92
97
  "preinstall": "npx only-allow pnpm",