cos-design 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +104 -8
- package/dist/index.cjs +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.js +428 -2
- package/package.json +89 -70
- package/dist/chunk.js +0 -3
- package/dist/chunk.js.LICENSE.txt +0 -32
- package/dist/css/index.css +0 -21
- package/dist/index.html +0 -1
- package/lib/components/canvasClock/index.d.ts +0 -7
- package/lib/components/index.d.ts +0 -1
- package/lib/css/index.css +0 -21
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [2.1.0] - 2026-06-18
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `Fireworks` 烟花特效组件(Canvas,支持自动燃放与点击触发)
|
|
13
|
+
- `MatrixRain` 黑客帝国数字雨背景组件
|
|
14
|
+
- `ParticleNetwork` 粒子连线网络组件(鼠标互动)
|
|
15
|
+
- `Typewriter` 终端风格打字机文字组件
|
|
16
|
+
- `NeonText` 霓虹灯发光文字组件
|
|
17
|
+
- `WaveButton` 波纹扩散按钮组件
|
|
18
|
+
- 开发环境首页组件导航,路由由配置自动生成
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- 重设计 `Turntable` 为可交互抽奖转盘
|
|
23
|
+
- 修复 `CanvasClock` 画布时钟渲染错位问题
|
|
24
|
+
|
|
25
|
+
## [2.0.0] - 2026-06-18
|
|
26
|
+
|
|
27
|
+
### Changed
|
|
28
|
+
|
|
29
|
+
- 构建工具从 Webpack 5 迁移至 Vite 6
|
|
30
|
+
- React 升级至 18,TypeScript 升级至 5
|
|
31
|
+
- 产物目录从 `lib/` 改为 `dist/`,同时输出 ESM 与 CJS
|
|
32
|
+
- 包管理器统一为 pnpm
|
|
33
|
+
- 样式文件改为 `*.module.less`(CSS Modules 规范)
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
|
|
37
|
+
- 自动注入组件样式(`vite-plugin-lib-inject-css`)
|
|
38
|
+
- GitHub Actions CI 流水线
|
|
39
|
+
- 开源贡献文档(CONTRIBUTING、Issue / PR 模板)
|
|
40
|
+
|
|
41
|
+
### Removed
|
|
42
|
+
|
|
43
|
+
- Webpack 及相关 loader 依赖
|
|
44
|
+
- UMD 格式产物
|
|
45
|
+
|
|
46
|
+
[2.1.0]: https://github.com/jiaxiantao/cos-design/compare/v2.0.0...v2.1.0
|
|
47
|
+
[2.0.0]: https://github.com/jiaxiantao/cos-design/compare/v1.7.5...v2.0.0
|
package/README.md
CHANGED
|
@@ -1,18 +1,114 @@
|
|
|
1
|
-
|
|
1
|
+
# cos-design
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/jiaxiantao/cos-design/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/cos-design)
|
|
5
|
+
[](https://github.com/jiaxiantao/cos-design/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
基于 React 18 + Vite 6 + TypeScript 5 的 React 组件库。
|
|
8
|
+
|
|
9
|
+
## 特性
|
|
10
|
+
|
|
11
|
+
- 开箱即用的 React 组件
|
|
12
|
+
- ESM / CJS 双格式输出,完整 TypeScript 类型支持
|
|
13
|
+
- 样式自动注入,无需手动引入 CSS
|
|
14
|
+
- 使用 pnpm + Vite 的现代工程化方案
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
4
17
|
|
|
5
18
|
```bash
|
|
6
|
-
|
|
19
|
+
pnpm add cos-design
|
|
20
|
+
# or
|
|
21
|
+
npm install cos-design
|
|
7
22
|
# or
|
|
8
|
-
|
|
23
|
+
yarn add cos-design
|
|
9
24
|
```
|
|
10
25
|
|
|
11
|
-
|
|
26
|
+
## 使用
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { CanvasClock, Charge, ReturnCity, Turntable } from 'cos-design';
|
|
30
|
+
|
|
31
|
+
function App() {
|
|
32
|
+
return <CanvasClock width={400} height={400} />;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 组件
|
|
37
|
+
|
|
38
|
+
| 组件 | 说明 |
|
|
39
|
+
| ----------------- | -------------------- |
|
|
40
|
+
| `CanvasClock` | Canvas 画布时钟 |
|
|
41
|
+
| `Charge` | 充电特效 |
|
|
42
|
+
| `ReturnCity` | 回城特效 |
|
|
43
|
+
| `Turntable` | 抽奖转盘 |
|
|
44
|
+
| `Fireworks` | 烟花特效(点击燃放) |
|
|
45
|
+
| `MatrixRain` | 黑客帝国数字雨 |
|
|
46
|
+
| `ParticleNetwork` | 粒子连线网络 |
|
|
47
|
+
| `Typewriter` | 打字机文字效果 |
|
|
48
|
+
| `NeonText` | 霓虹灯发光文字 |
|
|
49
|
+
| `WaveButton` | 波纹扩散按钮 |
|
|
50
|
+
|
|
51
|
+
## 本地开发
|
|
52
|
+
|
|
53
|
+
> **要求 Node.js >= 18**(项目含 `.nvmrc`,推荐使用 Node 20)
|
|
54
|
+
|
|
55
|
+
### 第一步:切换 Node 版本
|
|
12
56
|
|
|
13
57
|
```bash
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
|
|
58
|
+
nvm use
|
|
59
|
+
# 若未安装 Node 20
|
|
60
|
+
nvm install 20 && nvm use 20
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 第二步:安装依赖
|
|
64
|
+
|
|
65
|
+
**不要直接运行 `pnpm install`**(若本机 corepack 有问题会报错),请使用:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run setup
|
|
17
69
|
```
|
|
18
70
|
|
|
71
|
+
该命令会通过 `npx` 直接调用 pnpm,绕过 corepack。
|
|
72
|
+
|
|
73
|
+
### 第三步:启动开发
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
npx --yes pnpm@9 dev
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
访问 `http://localhost:4000` 进入首页,点击卡片跳转到对应组件演示(共 10 个组件)。
|
|
80
|
+
|
|
81
|
+
## 脚本
|
|
82
|
+
|
|
83
|
+
| 命令 | 说明 |
|
|
84
|
+
| ------------------------ | ------------------------------- |
|
|
85
|
+
| `npm run setup` | 安装依赖(推荐,绕过 corepack) |
|
|
86
|
+
| `npx --yes pnpm@9 dev` | 启动本地演示 |
|
|
87
|
+
| `npx --yes pnpm@9 build` | 构建组件库 |
|
|
88
|
+
| `npx --yes pnpm@9 lint` | 代码检查 |
|
|
89
|
+
| `npx --yes pnpm@9 pub` | 构建并发布到 npm |
|
|
90
|
+
|
|
91
|
+
## 修复本机 pnpm(可选)
|
|
92
|
+
|
|
93
|
+
若希望直接使用 `pnpm` 命令,在 **Node 20+** 环境下执行:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
nvm use 20
|
|
97
|
+
corepack disable
|
|
98
|
+
hash -r
|
|
99
|
+
npm install -g pnpm@9
|
|
100
|
+
which pnpm # 确认路径不在 corepack 下
|
|
101
|
+
pnpm -v
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 参与贡献
|
|
105
|
+
|
|
106
|
+
欢迎提交 Issue 与 Pull Request,请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md)。
|
|
107
|
+
|
|
108
|
+
## 更新日志
|
|
109
|
+
|
|
110
|
+
详见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
[MIT](./LICENSE) © jiaxiantao
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const e=require("react/jsx-runtime"),x=require("react"),K="cos-canvasClock",V="cos-canvasTarget",Q={canvasClock:K,canvasTarget:V},z=({width:s=400,height:a=400})=>{const u=x.useRef(null),l=Math.min(s,a),r=l/2-16,m=l/2,y=x.useCallback(t=>{t.clearRect(0,0,l,l),t.save(),t.translate(m,m),t.beginPath(),t.arc(0,0,r,0,Math.PI*2),t.fillStyle="#fff",t.fill(),t.strokeStyle="#d1d5db",t.lineWidth=2,t.stroke();for(let j=0;j<60;j++){const i=j/60*Math.PI*2,h=r-(j%5===0?14:8);t.beginPath(),t.moveTo(Math.cos(i)*h,Math.sin(i)*h),t.lineTo(Math.cos(i)*r,Math.sin(i)*r),t.strokeStyle=j%5===0?"#374151":"#9ca3af",t.lineWidth=j%5===0?2:1,t.stroke()}t.fillStyle="#111827",t.font=`bold ${Math.floor(l/22)}px system-ui, sans-serif`,t.textAlign="center",t.textBaseline="middle";for(let j=1;j<=12;j++){const i=j/12*Math.PI*2-Math.PI/2,h=r-32;t.fillText(String(j),Math.cos(i)*h,Math.sin(i)*h)}const c=new Date,g=c.getHours()%12,f=c.getMinutes(),v=c.getSeconds(),b=c.getMilliseconds(),o=(j,i,h,M,n)=>{t.save(),t.rotate(j),t.beginPath(),t.moveTo(0,h),t.lineTo(i,0),t.lineTo(0,-h),t.closePath(),t.fillStyle=M,t.shadowColor=n,t.shadowBlur=4,t.fill(),t.restore()},d=(g+f/60)/12*Math.PI*2-Math.PI/2,C=(f+v/60)/60*Math.PI*2-Math.PI/2,p=(v+b/1e3)/60*Math.PI*2-Math.PI/2;o(d,r*.5,4,"#111827","rgb(0 0 0 / 40%)"),o(C,r*.72,3,"#1e80ff","rgb(30 128 255 / 40%)"),o(p,r*.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()},[m,r,l]);return x.useEffect(()=>{const t=u.current;if(!t)return;const c=window.devicePixelRatio||1;t.width=l*c,t.height=l*c;const g=t.getContext("2d");if(!g)return;g.setTransform(c,0,0,c,0,0);let f=0;const v=()=>{y(g),f=requestAnimationFrame(v)};return v(),()=>cancelAnimationFrame(f)},[y,l]),e.jsx("div",{className:Q.canvasClock,style:{width:l,height:l},children:e.jsx("canvas",{ref:u,className:Q.canvasTarget,style:{width:l,height:l}})})},tt="cos-chargeContainer",et="cos-contrast",st="cos-text",nt="cos-circle",at="cos-button",k={chargeContainer:tt,contrast:et,text:st,circle:nt,button:at},ot=s=>{const{initQuantity:a=0}=s,[u,l]=x.useState(a);return x.useEffect(()=>{let r=u;setInterval(()=>{r=Number(Number(r+=.01).toFixed(2)),l(r)},500)},[]),e.jsx("div",{className:k.chargeContainer,children:e.jsxs("div",{className:k.contrast,children:[e.jsxs("div",{className:k.text,children:[u?u.toString().padEnd(4,"0"):0,"%"]}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{}),e.jsx("div",{className:k.circle}),e.jsx("div",{className:k.button})]})})},rt="cos-fireworks",ct="cos-canvas",lt="cos-hint",L={fireworks:rt,canvas:ct,hint:lt},U=["#ff6b6b","#ffd93d","#6bcb77","#4d96ff","#a66cff","#ff85c0"],G=()=>U[Math.floor(Math.random()*U.length)],it=(s,a,u)=>{const l=60+Math.floor(Math.random()*30);return Array.from({length:l},()=>{const r=Math.random()*Math.PI*2,m=Math.random()*4+2;return{x:s,y:a,vx:Math.cos(r)*m,vy:Math.sin(r)*m,alpha:1,color:Math.random()>.3?u:G(),decay:Math.random()*.015+.01}})},ut=({width:s=800,height:a=500,auto:u=!0})=>{const l=x.useRef(null),r=x.useRef([]),m=x.useRef(0),y=x.useCallback(c=>{const g=c??Math.random()*s*.6+s*.2;r.current.push({x:g,y:a,vy:-(Math.random()*4+6),targetY:Math.random()*a*.4+a*.1,color:G(),exploded:!1,particles:[]})},[a,s]);x.useEffect(()=>{const c=l.current;if(!c)return;const g=window.devicePixelRatio||1;c.width=s*g,c.height=a*g;const f=c.getContext("2d");if(!f)return;f.setTransform(g,0,0,g,0,0);let v=0;const b=()=>{m.current=requestAnimationFrame(b),f.fillStyle="rgb(15 23 42 / 25%)",f.fillRect(0,0,s,a),u&&Math.random()<.03&&y(),r.current=r.current.filter(o=>o.exploded?(o.particles=o.particles.filter(d=>(d.x+=d.vx,d.y+=d.vy,d.vy+=.06,d.alpha-=d.decay,d.alpha<=0?!1:(f.beginPath(),f.arc(d.x,d.y,2,0,Math.PI*2),f.fillStyle=d.color,f.globalAlpha=d.alpha,f.fill(),f.globalAlpha=1,!0))),o.particles.length>0):(o.y+=o.vy,o.vy*=.98,f.beginPath(),f.arc(o.x,o.y,2.5,0,Math.PI*2),f.fillStyle=o.color,f.fill(),(o.vy>=0||o.y<=o.targetY)&&(o.exploded=!0,o.particles=it(o.x,o.y,o.color)),!0))};return b(),u&&(v=window.setInterval(()=>y(),1200)),()=>{cancelAnimationFrame(m.current),clearInterval(v)}},[u,a,y,s]);const t=c=>{const g=c.currentTarget.getBoundingClientRect();y(c.clientX-g.left)};return e.jsxs("div",{className:L.fireworks,style:{width:s,height:a},children:[e.jsx("canvas",{ref:l,className:L.canvas,style:{width:s,height:a},onClick:t}),e.jsx("p",{className:L.hint,children:"点击画布燃放烟花"})]})},ft="cos-matrixRain",dt="cos-canvas",mt="cos-overlay",ht="cos-title",xt="cos-subtitle",F={matrixRain:ft,canvas:dt,overlay:mt,title:ht,subtitle:xt},Z="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*アイウエオカキクケコ",yt=({width:s=800,height:a=500,density:u=.6,color:l="#00ff41"})=>{const r=x.useRef(null);return x.useEffect(()=>{const m=r.current;if(!m)return;const y=window.devicePixelRatio||1;m.width=s*y,m.height=a*y;const t=m.getContext("2d");if(!t)return;t.setTransform(y,0,0,y,0,0);const c=16,g=Math.floor(s/c*u),f=Array.from({length:g},()=>Math.random()*-50);let v=0;const b=()=>{t.fillStyle="rgb(0 0 0 / 8%)",t.fillRect(0,0,s,a),t.fillStyle=l,t.font=`${c}px monospace`,f.forEach((o,d)=>{const C=Z[Math.floor(Math.random()*Z.length)],p=d/u*c;t.fillStyle=l,t.fillText(C,p,o*c),o*c>a&&Math.random()>.975&&(f[d]=0),f[d]+=1}),v=requestAnimationFrame(b)};return b(),()=>cancelAnimationFrame(v)},[l,u,a,s]),e.jsxs("div",{className:F.matrixRain,style:{width:s,height:a},children:[e.jsx("canvas",{ref:r,className:F.canvas,style:{width:s,height:a}}),e.jsxs("div",{className:F.overlay,children:[e.jsx("h2",{className:F.title,children:"MATRIX"}),e.jsx("p",{className:F.subtitle,children:"数字雨效果"})]})]})},vt="cos-neonText",gt="cos-text",Mt="cos-flicker",bt="cos-reflection",$={neonText:vt,text:gt,flicker:Mt,reflection:bt},pt=({text:s="NEON",color:a="#ff00de",fontSize:u=72,flicker:l=!0})=>e.jsxs("div",{className:$.neonText,children:[e.jsx("h1",{className:`${$.text} ${l?$.flicker:""}`,style:{fontSize:u,"--neon-color":a},children:s}),e.jsx("p",{className:$.reflection,style:{fontSize:u*.35,color:a},children:s})]}),jt="cos-particleNetwork",Rt="cos-canvas",Nt="cos-hint",O={particleNetwork:jt,canvas:Rt,hint:Nt},Ct=({width:s=800,height:a=500,particleCount:u=60,linkDistance:l=120,color:r="#38bdf8"})=>{const m=x.useRef(null),y=x.useRef([]),t=x.useRef({x:-1e3,y:-1e3}),c=x.useCallback(()=>{y.current=Array.from({length:u},()=>({x:Math.random()*s,y:Math.random()*a,vx:(Math.random()-.5)*1.2,vy:(Math.random()-.5)*1.2,radius:Math.random()*2+1}))},[a,u,s]);x.useEffect(()=>{c()},[c]),x.useEffect(()=>{const v=m.current;if(!v)return;const b=window.devicePixelRatio||1;v.width=s*b,v.height=a*b;const o=v.getContext("2d");if(!o)return;o.setTransform(b,0,0,b,0,0);let d=0;const C=()=>{o.fillStyle="#0f172a",o.fillRect(0,0,s,a);const p=y.current,j=t.current;p.forEach(i=>{i.x+=i.vx,i.y+=i.vy,(i.x<0||i.x>s)&&(i.vx*=-1),(i.y<0||i.y>a)&&(i.vy*=-1);const h=j.x-i.x,M=j.y-i.y;Math.sqrt(h*h+M*M)<150&&(i.vx-=h*3e-4,i.vy-=M*3e-4)});for(let i=0;i<p.length;i++)for(let h=i+1;h<p.length;h++){const M=p[i].x-p[h].x,n=p[i].y-p[h].y,R=Math.sqrt(M*M+n*n);R<l&&(o.beginPath(),o.moveTo(p[i].x,p[i].y),o.lineTo(p[h].x,p[h].y),o.strokeStyle=r,o.globalAlpha=1-R/l,o.lineWidth=.8,o.stroke(),o.globalAlpha=1)}p.forEach(i=>{o.beginPath(),o.arc(i.x,i.y,i.radius,0,Math.PI*2),o.fillStyle=r,o.fill()}),d=requestAnimationFrame(C)};return C(),()=>cancelAnimationFrame(d)},[r,a,c,l,s]);const g=v=>{const b=v.currentTarget.getBoundingClientRect();t.current={x:v.clientX-b.left,y:v.clientY-b.top}},f=()=>{t.current={x:-1e3,y:-1e3}};return e.jsxs("div",{className:O.particleNetwork,style:{width:s,height:a},children:[e.jsx("canvas",{ref:m,className:O.canvas,style:{width:s,height:a},onMouseMove:g,onMouseLeave:f}),e.jsx("p",{className:O.hint,children:"移动鼠标与粒子互动"})]})},Pt="cos-returnCityContainer",Tt="cos-star",wt="cos-glassWrap",It="cos-glassItem",q={returnCityContainer:Pt,star:Tt,glassWrap:wt,glassItem:It},At=()=>{const s=(u,l)=>{for(let r=0;r<l;r++)setTimeout(function(){const m=document.createElement("div");m.className=q.star;const y=document.body.clientWidth,t=document.body.clientHeight,c=Math.random()*y+"px",g=Math.random()*t+"px";m.style.top=g,m.style.left=c,u.append(m)},Math.random()*2e3)},a=()=>{const l="150px",r=document.getElementById("glassWrap");if(r)for(let m=0;m<6;m++){const y=document.createElement("div");y.className=q.glassItem,y.style.transform=`rotateY(${m*60}deg) translateZ(${l})`,r.appendChild(y),setTimeout(()=>{y.style.top="0px",y.style.opacity="1"},m*300)}};return x.useEffect(()=>{const u=document.getElementById("returnCityContainer");u&&s(u,document.documentElement.clientWidth/20),a()},[]),e.jsx("div",{id:"returnCityContainer",className:q.returnCityContainer,children:e.jsx("div",{id:"glassWrap",className:q.glassWrap})})},St="cos-turntable",Et="cos-wheelWrap",kt="cos-canvas",Ft="cos-pointer",Bt="cos-spinBtn",Wt="cos-result",I={turntable:St,wheelWrap:Et,canvas:kt,pointer:Ft,spinBtn:Bt,result:Wt},_=["#FF6B6B","#4ECDC4","#FFE66D","#A78BFA","#60A5FA","#F472B6","#34D399","#FB923C"],$t=[{label:"一等奖"},{label:"二等奖"},{label:"三等奖"},{label:"谢谢参与"},{label:"优惠券"},{label:"再来一次"}],qt=s=>1-Math.pow(1-s,3),Dt=({prizes:s=$t,size:a=360,spinDuration:u=4e3,spinRounds:l=5,buttonText:r="开始抽奖",onSpinEnd:m})=>{const y=x.useRef(null),t=x.useRef(0),c=x.useRef(0),g=x.useRef(1),[f,v]=x.useState(!1),[b,o]=x.useState(null),d=a+48,C=(h,M)=>M.color??_[h%_.length],p=x.useCallback(h=>{const M=y.current;if(!M)return;const n=M.getContext("2d");if(!n)return;const R=d/2,P=a/2,S=Math.PI*2/s.length;n.clearRect(0,0,d,d),n.save(),n.translate(R,R),n.rotate(h),s.forEach((N,w)=>{const T=w*S-Math.PI/2,E=T+S,D=C(w,N);n.beginPath(),n.moveTo(0,0),n.arc(0,0,P,T,E),n.closePath(),n.fillStyle=D,n.fill(),n.strokeStyle="rgb(255 255 255 / 35%)",n.lineWidth=2,n.stroke(),n.save(),n.rotate(T+S/2),n.textAlign="right",n.fillStyle="#fff",n.font=`bold ${Math.max(12,Math.floor(a/22))}px system-ui, sans-serif`,n.shadowColor="rgb(0 0 0 / 30%)",n.shadowBlur=4,n.fillText(N.label,P-18,6),n.restore()}),n.beginPath(),n.arc(0,0,P,0,Math.PI*2),n.strokeStyle="#fbbf24",n.lineWidth=6,n.stroke(),n.beginPath(),n.arc(0,0,P-4,0,Math.PI*2),n.strokeStyle="#f59e0b",n.lineWidth=2,n.stroke(),n.restore(),n.save(),n.translate(R,R);for(let N=0;N<12;N++){const w=N/12*Math.PI*2,T=Math.cos(w)*(P+14),E=Math.sin(w)*(P+14);n.beginPath(),n.arc(T,E,3,0,Math.PI*2),n.fillStyle=N%2===0?"#fde68a":"#f59e0b",n.fill()}n.restore()},[d,s,a]);x.useEffect(()=>{const h=y.current;if(!h)return;const M=window.devicePixelRatio||1;g.current=M,h.width=d*M,h.height=d*M;const n=h.getContext("2d");n&&n.setTransform(M,0,0,M,0,0),p(t.current)},[d,p]),x.useEffect(()=>()=>{c.current&&cancelAnimationFrame(c.current)},[]);const j=h=>{const M=360/s.length,n=(h*(180/Math.PI)%360+360)%360;return Math.floor((360-n+M/2)%360/M)%s.length},i=()=>{if(f||s.length===0)return;v(!0),o(null);const h=Math.PI*2/s.length,n=Math.floor(Math.random()*s.length)*h+h/2,R=t.current,P=l*Math.PI*2,S=R+P+(Math.PI*2-n)-R%(Math.PI*2),N=R,w=performance.now(),T=E=>{const D=E-w,H=Math.min(D/u,1),J=qt(H),W=N+(S-N)*J;if(t.current=W,p(W),H<1)c.current=requestAnimationFrame(T);else{const X=j(W),Y=s[X];t.current=W,v(!1),o(Y),m==null||m(Y,X)}};c.current=requestAnimationFrame(T)};return e.jsxs("div",{className:I.turntable,style:{width:d,height:d+80},children:[e.jsxs("div",{className:I.wheelWrap,style:{width:d,height:d},children:[e.jsx("div",{className:I.pointer}),e.jsx("canvas",{ref:y,className:I.canvas,style:{width:d,height:d}}),e.jsx("button",{type:"button",className:I.spinBtn,onClick:i,disabled:f,children:f?"抽奖中...":r})]}),b&&!f&&e.jsxs("p",{className:I.result,children:["恭喜获得:",e.jsx("strong",{children:b.label})]})]})},Lt="cos-typewriter",Ot="cos-terminal",Ht="cos-dots",Xt="cos-text",Yt="cos-prompt",Qt="cos-cursor",A={typewriter:Lt,terminal:Ot,dots:Ht,text:Xt,prompt:Yt,cursor:Qt},Ut=["Hello, cos-design!","欢迎来到组件库 ✨","Build something fun 🚀"],Zt=({texts:s=Ut,speed:a=100,deleteSpeed:u=50,pause:l=2e3})=>{const[r,m]=x.useState(""),[y,t]=x.useState(0),[c,g]=x.useState(!1);return x.useEffect(()=>{const f=s[y%s.length];let v;if(!c&&r===f)v=setTimeout(()=>g(!0),l);else if(c&&r==="")g(!1),t(b=>(b+1)%s.length);else{const b=c?f.slice(0,r.length-1):f.slice(0,r.length+1);v=setTimeout(()=>m(b),c?u:a)}return()=>clearTimeout(v)},[r,c,y,s,a,u,l]),e.jsx("div",{className:A.typewriter,children:e.jsxs("div",{className:A.terminal,children:[e.jsxs("div",{className:A.dots,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]}),e.jsxs("p",{className:A.text,children:[e.jsx("span",{className:A.prompt,children:">"}),r,e.jsx("span",{className:A.cursor,children:"|"})]})]})})},_t="cos-waveButton",Gt="cos-btn",Jt="cos-label",Kt="cos-wave",B={waveButton:_t,btn:Gt,label:Jt,wave:Kt},Vt=({text:s="点我试试",onClick:a,color:u="#38bdf8"})=>e.jsx("div",{className:B.waveButton,children:e.jsxs("button",{type:"button",className:B.btn,style:{"--wave-color":u},onClick:a,children:[e.jsx("span",{className:B.wave}),e.jsx("span",{className:B.wave}),e.jsx("span",{className:B.label,children:s})]})});exports.CanvasClock=z;exports.Charge=ot;exports.Fireworks=ut;exports.MatrixRain=yt;exports.NeonText=pt;exports.ParticleNetwork=Ct;exports.ReturnCity=At;exports.Turntable=Dt;exports.Typewriter=Zt;exports.WaveButton=Vt;
|
package/dist/index.css
ADDED
|
@@ -0,0 +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-fireworks{position:relative;border-radius:12px;overflow:hidden;background:#0f172a}.cos-hint{position:absolute;bottom:12px;left:50%;margin:0;color:#94a3b8cc;font-size:13px;transform:translate(-50%);pointer-events:none}.cos-matrixRain{position:relative;border-radius:12px;overflow:hidden;background:#000}.cos-canvas{display:block}.cos-overlay{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;pointer-events:none}.cos-title{margin:0;color:#00ff41;font-size:48px;font-weight:800;letter-spacing:.3em;text-shadow:0 0 20px #00ff41;animation:cos-flicker 3s infinite}.cos-subtitle{margin:8px 0 0;color:#00ff4199;font-size:14px;letter-spacing:.2em}@keyframes cos-flicker{0%,to{opacity:1}50%{opacity:.85}52%{opacity:.6}54%{opacity:1}}.cos-neonText{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:240px;padding:40px;background:#0a0a0a;border-radius:12px}.cos-text{margin:0;color:var(--neon-color, #ff00de);font-weight:900;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)}.cos-flicker{animation:cos-neon-flicker 2.5s infinite alternate}.cos-reflection{margin:12px 0 0;opacity:.3;font-weight:700;letter-spacing:.15em;transform:scaleY(-1);filter:blur(2px)}@keyframes cos-neon-flicker{0%,19%,21%,23%,25%,54%,56%,to{opacity:1}20%,24%,55%{opacity:.6}}.cos-particleNetwork{position:relative;border-radius:12px;overflow:hidden}.cos-canvas{display:block;cursor:crosshair}.cos-hint{position:absolute;bottom:12px;left:50%;margin:0;color:#94a3b8b3;font-size:13px;transform:translate(-50%);pointer-events:none}.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)}}.cos-typewriter{display:flex;align-items:center;justify-content:center;width:100%;min-height:200px;padding:24px;box-sizing:border-box}.cos-terminal{width:min(560px,100%);padding:20px 24px;border-radius:12px;background:#1e293b;box-shadow:0 16px 48px #00000059}.cos-dots{display:flex;gap:8px;margin-bottom:16px}.cos-dots span{width:12px;height:12px;border-radius:50%}.cos-dots span:nth-child(1){background:#ef4444}.cos-dots span:nth-child(2){background:#eab308}.cos-dots span:nth-child(3){background:#22c55e}.cos-text{margin:0;color:#e2e8f0;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;font-size:20px;line-height:1.6;min-height:1.6em}.cos-prompt{margin-right:8px;color:#38bdf8}.cos-cursor{display:inline-block;margin-left:2px;color:#38bdf8;animation:cos-blink 1s step-end infinite}@keyframes cos-blink{50%{opacity:0}}.cos-waveButton{display:flex;align-items:center;justify-content:center;min-height:200px;padding:40px}.cos-btn{position:relative;padding:16px 48px;border:none;border-radius:50px;background:var(--wave-color, #38bdf8);color:#fff;font-size:18px;font-weight:600;overflow:hidden;cursor:pointer;box-shadow:0 8px 24px #38bdf859;transition:transform .2s}.cos-btn:hover{transform:scale(1.05)}.cos-btn:active{transform:scale(.97)}.cos-label{position:relative;z-index:1}.cos-wave{position:absolute;top:50%;left:50%;width:0;height:0;border-radius:50%;background:#ffffff4d;transform:translate(-50%,-50%);animation:cos-ripple 3s ease-out infinite}.cos-wave:nth-child(2){animation-delay:1s}@keyframes cos-ripple{0%{width:0;height:0;opacity:.6}to{width:300px;height:300px;opacity:0}}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
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 Fireworks: default_2.FC<FireworksProps>;
|
|
17
|
+
|
|
18
|
+
export declare interface FireworksProps {
|
|
19
|
+
width?: number;
|
|
20
|
+
height?: number;
|
|
21
|
+
/** 是否自动燃放,默认 true */
|
|
22
|
+
auto?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export declare const MatrixRain: default_2.FC<MatrixRainProps>;
|
|
26
|
+
|
|
27
|
+
export declare interface MatrixRainProps {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
/** 列密度 0~1,默认 0.6 */
|
|
31
|
+
density?: number;
|
|
32
|
+
/** 主色调 */
|
|
33
|
+
color?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare const NeonText: default_2.FC<NeonTextProps>;
|
|
37
|
+
|
|
38
|
+
export declare interface NeonTextProps {
|
|
39
|
+
/** 显示文字 */
|
|
40
|
+
text?: string;
|
|
41
|
+
/** 霓虹主色 */
|
|
42
|
+
color?: string;
|
|
43
|
+
/** 字号 */
|
|
44
|
+
fontSize?: number;
|
|
45
|
+
/** 是否闪烁 */
|
|
46
|
+
flicker?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare const ParticleNetwork: default_2.FC<ParticleNetworkProps>;
|
|
50
|
+
|
|
51
|
+
export declare interface ParticleNetworkProps {
|
|
52
|
+
width?: number;
|
|
53
|
+
height?: number;
|
|
54
|
+
/** 粒子数量 */
|
|
55
|
+
particleCount?: number;
|
|
56
|
+
/** 连线距离 */
|
|
57
|
+
linkDistance?: number;
|
|
58
|
+
/** 粒子颜色 */
|
|
59
|
+
color?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export declare const ReturnCity: default_2.FC<ReturnCityProps>;
|
|
63
|
+
|
|
64
|
+
export declare interface ReturnCityProps {
|
|
65
|
+
shining?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export declare const Turntable: default_2.FC<TurntableProps>;
|
|
69
|
+
|
|
70
|
+
export declare interface TurntablePrize {
|
|
71
|
+
label: string;
|
|
72
|
+
color?: string;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export declare interface TurntableProps {
|
|
76
|
+
/** 奖品列表 */
|
|
77
|
+
prizes?: TurntablePrize[];
|
|
78
|
+
/** 转盘直径,默认 360 */
|
|
79
|
+
size?: number;
|
|
80
|
+
/** 旋转动画时长(毫秒),默认 4000 */
|
|
81
|
+
spinDuration?: number;
|
|
82
|
+
/** 旋转圈数,默认 5 */
|
|
83
|
+
spinRounds?: number;
|
|
84
|
+
/** 抽奖按钮文案 */
|
|
85
|
+
buttonText?: string;
|
|
86
|
+
/** 旋转结束回调 */
|
|
87
|
+
onSpinEnd?: (prize: TurntablePrize, index: number) => void;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export declare const Typewriter: default_2.FC<TypewriterProps>;
|
|
91
|
+
|
|
92
|
+
export declare interface TypewriterProps {
|
|
93
|
+
/** 轮播文案列表 */
|
|
94
|
+
texts?: string[];
|
|
95
|
+
/** 打字速度(毫秒/字符) */
|
|
96
|
+
speed?: number;
|
|
97
|
+
/** 删除速度(毫秒/字符) */
|
|
98
|
+
deleteSpeed?: number;
|
|
99
|
+
/** 完整展示后的停顿(毫秒) */
|
|
100
|
+
pause?: number;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export declare const WaveButton: default_2.FC<WaveButtonProps>;
|
|
104
|
+
|
|
105
|
+
export declare interface WaveButtonProps {
|
|
106
|
+
/** 按钮文字 */
|
|
107
|
+
text?: string;
|
|
108
|
+
/** 点击回调 */
|
|
109
|
+
onClick?: () => void;
|
|
110
|
+
/** 主色 */
|
|
111
|
+
color?: string;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { }
|