cos-design 2.0.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 CHANGED
@@ -5,6 +5,23 @@ 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.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
+
8
25
  ## [2.0.0] - 2026-06-18
9
26
 
10
27
  ### Changed
@@ -26,4 +43,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
26
43
  - Webpack 及相关 loader 依赖
27
44
  - UMD 格式产物
28
45
 
46
+ [2.1.0]: https://github.com/jiaxiantao/cos-design/compare/v2.0.0...v2.1.0
29
47
  [2.0.0]: https://github.com/jiaxiantao/cos-design/compare/v1.7.5...v2.0.0
package/README.md CHANGED
@@ -35,12 +35,18 @@ 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
 
@@ -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
 
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
+ "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 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{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 CHANGED
@@ -13,6 +13,52 @@ export declare interface ChargeProps {
13
13
  initQuantity?: number;
14
14
  }
15
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
+
16
62
  export declare const ReturnCity: default_2.FC<ReturnCityProps>;
17
63
 
18
64
  export declare interface ReturnCityProps {
@@ -41,4 +87,28 @@ export declare interface TurntableProps {
41
87
  onSpinEnd?: (prize: TurntablePrize, index: number) => void;
42
88
  }
43
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
+
44
114
  export { }
package/dist/index.js CHANGED
@@ -1,189 +1,428 @@
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(
1
+ import { jsx as o, jsxs as N } from "react/jsx-runtime";
2
+ import { useRef as P, useCallback as X, useEffect as w, useState as $ } from "react";
3
+ import './index.css';const et = "cos-canvasClock", nt = "cos-canvasTarget", G = {
4
+ canvasClock: et,
5
+ canvasTarget: nt
6
+ }, Gt = ({ width: e = 400, height: s = 400 }) => {
7
+ const d = P(null), l = Math.min(e, s), r = l / 2 - 16, m = l / 2, y = X(
8
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();
9
+ 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();
10
+ for (let x = 0; x < 60; x++) {
11
+ const i = x / 60 * Math.PI * 2, h = r - (x % 5 === 0 ? 14 : 8);
12
+ t.beginPath(), t.moveTo(Math.cos(i) * h, Math.sin(i) * h), t.lineTo(Math.cos(i) * r, Math.sin(i) * r), t.strokeStyle = x % 5 === 0 ? "#374151" : "#9ca3af", t.lineWidth = x % 5 === 0 ? 2 : 1, t.stroke();
13
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);
14
+ t.fillStyle = "#111827", t.font = `bold ${Math.floor(l / 22)}px system-ui, sans-serif`, t.textAlign = "center", t.textBaseline = "middle";
15
+ for (let x = 1; x <= 12; x++) {
16
+ const i = x / 12 * Math.PI * 2 - Math.PI / 2, h = r - 32;
17
+ t.fillText(String(x), Math.cos(i) * h, Math.sin(i) * h);
18
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();
19
+ const c = /* @__PURE__ */ new Date(), g = c.getHours() % 12, f = c.getMinutes(), v = c.getSeconds(), M = c.getMilliseconds(), a = (x, i, h, p, n) => {
20
+ t.save(), t.rotate(x), t.beginPath(), t.moveTo(0, h), t.lineTo(i, 0), t.lineTo(0, -h), t.closePath(), t.fillStyle = p, t.shadowColor = n, t.shadowBlur = 4, t.fill(), t.restore();
21
+ }, u = (g + f / 60) / 12 * Math.PI * 2 - Math.PI / 2, T = (f + v / 60) / 60 * Math.PI * 2 - Math.PI / 2, b = (v + M / 1e3) / 60 * Math.PI * 2 - Math.PI / 2;
22
+ a(u, r * 0.5, 4, "#111827", "rgb(0 0 0 / 40%)"), a(T, r * 0.72, 3, "#1e80ff", "rgb(30 128 255 / 40%)"), a(b, r * 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
23
  },
24
- [l, o, a]
24
+ [m, r, l]
25
25
  );
26
- return F(() => {
27
- const t = u.current;
26
+ return w(() => {
27
+ const t = d.current;
28
28
  if (!t) return;
29
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);
30
+ t.width = l * c, t.height = l * c;
31
+ const g = t.getContext("2d");
32
+ if (!g) return;
33
+ g.setTransform(c, 0, 0, c, 0, 0);
34
+ let f = 0;
35
+ const v = () => {
36
+ y(g), f = requestAnimationFrame(v);
37
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;
38
+ return v(), () => cancelAnimationFrame(f);
39
+ }, [y, l]), /* @__PURE__ */ o("div", { className: G.canvasClock, style: { width: l, height: l }, children: /* @__PURE__ */ o("canvas", { ref: d, className: G.canvasTarget, style: { width: l, height: l } }) });
40
+ }, st = "cos-chargeContainer", at = "cos-contrast", ot = "cos-text", rt = "cos-circle", ct = "cos-button", E = {
41
+ chargeContainer: st,
42
+ contrast: at,
43
+ text: ot,
44
+ circle: rt,
45
+ button: ct
46
+ }, Jt = (e) => {
47
+ const { initQuantity: s = 0 } = e, [d, l] = $(s);
48
+ return w(() => {
49
+ let r = d;
50
50
  setInterval(() => {
51
- o = Number(Number(o += 0.01).toFixed(2)), a(o);
51
+ r = Number(Number(r += 0.01).toFixed(2)), l(r);
52
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,
53
+ }, []), /* @__PURE__ */ o("div", { className: E.chargeContainer, children: /* @__PURE__ */ N("div", { className: E.contrast, children: [
54
+ /* @__PURE__ */ N("div", { className: E.text, children: [
55
+ d ? d.toString().padEnd(4, "0") : 0,
56
56
  "%"
57
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 })
58
+ /* @__PURE__ */ o("span", {}),
59
+ /* @__PURE__ */ o("span", {}),
60
+ /* @__PURE__ */ o("span", {}),
61
+ /* @__PURE__ */ o("span", {}),
62
+ /* @__PURE__ */ o("span", {}),
63
+ /* @__PURE__ */ o("span", {}),
64
+ /* @__PURE__ */ o("span", {}),
65
+ /* @__PURE__ */ o("span", {}),
66
+ /* @__PURE__ */ o("span", {}),
67
+ /* @__PURE__ */ o("span", {}),
68
+ /* @__PURE__ */ o("span", {}),
69
+ /* @__PURE__ */ o("span", {}),
70
+ /* @__PURE__ */ o("span", {}),
71
+ /* @__PURE__ */ o("span", {}),
72
+ /* @__PURE__ */ o("span", {}),
73
+ /* @__PURE__ */ o("div", { className: E.circle }),
74
+ /* @__PURE__ */ o("div", { className: E.button })
75
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++)
76
+ }, lt = "cos-fireworks", it = "cos-canvas", dt = "cos-hint", Q = {
77
+ fireworks: lt,
78
+ canvas: it,
79
+ hint: dt
80
+ }, J = ["#ff6b6b", "#ffd93d", "#6bcb77", "#4d96ff", "#a66cff", "#ff85c0"], z = () => J[Math.floor(Math.random() * J.length)], ft = (e, s, d) => {
81
+ const l = 60 + Math.floor(Math.random() * 30);
82
+ return Array.from({ length: l }, () => {
83
+ const r = Math.random() * Math.PI * 2, m = Math.random() * 4 + 2;
84
+ return {
85
+ x: e,
86
+ y: s,
87
+ vx: Math.cos(r) * m,
88
+ vy: Math.sin(r) * m,
89
+ alpha: 1,
90
+ color: Math.random() > 0.3 ? d : z(),
91
+ decay: Math.random() * 0.015 + 0.01
92
+ };
93
+ });
94
+ }, Kt = ({ width: e = 800, height: s = 500, auto: d = !0 }) => {
95
+ const l = P(null), r = P([]), m = P(0), y = X(
96
+ (c) => {
97
+ const g = c ?? Math.random() * e * 0.6 + e * 0.2;
98
+ r.current.push({
99
+ x: g,
100
+ y: s,
101
+ vy: -(Math.random() * 4 + 6),
102
+ targetY: Math.random() * s * 0.4 + s * 0.1,
103
+ color: z(),
104
+ exploded: !1,
105
+ particles: []
106
+ });
107
+ },
108
+ [s, e]
109
+ );
110
+ w(() => {
111
+ const c = l.current;
112
+ if (!c) return;
113
+ const g = window.devicePixelRatio || 1;
114
+ c.width = e * g, c.height = s * g;
115
+ const f = c.getContext("2d");
116
+ if (!f) return;
117
+ f.setTransform(g, 0, 0, g, 0, 0);
118
+ let v = 0;
119
+ const M = () => {
120
+ m.current = requestAnimationFrame(M), f.fillStyle = "rgb(15 23 42 / 25%)", f.fillRect(0, 0, e, s), d && Math.random() < 0.03 && y(), r.current = r.current.filter((a) => a.exploded ? (a.particles = a.particles.filter((u) => (u.x += u.vx, u.y += u.vy, u.vy += 0.06, u.alpha -= u.decay, u.alpha <= 0 ? !1 : (f.beginPath(), f.arc(u.x, u.y, 2, 0, Math.PI * 2), f.fillStyle = u.color, f.globalAlpha = u.alpha, f.fill(), f.globalAlpha = 1, !0))), a.particles.length > 0) : (a.y += a.vy, a.vy *= 0.98, f.beginPath(), f.arc(a.x, a.y, 2.5, 0, Math.PI * 2), f.fillStyle = a.color, f.fill(), (a.vy >= 0 || a.y <= a.targetY) && (a.exploded = !0, a.particles = ft(a.x, a.y, a.color)), !0));
121
+ };
122
+ return M(), d && (v = window.setInterval(() => y(), 1200)), () => {
123
+ cancelAnimationFrame(m.current), clearInterval(v);
124
+ };
125
+ }, [d, s, y, e]);
126
+ const t = (c) => {
127
+ const g = c.currentTarget.getBoundingClientRect();
128
+ y(c.clientX - g.left);
129
+ };
130
+ return /* @__PURE__ */ N("div", { className: Q.fireworks, style: { width: e, height: s }, children: [
131
+ /* @__PURE__ */ o("canvas", { ref: l, className: Q.canvas, style: { width: e, height: s }, onClick: t }),
132
+ /* @__PURE__ */ o("p", { className: Q.hint, children: "点击画布燃放烟花" })
133
+ ] });
134
+ }, ut = "cos-matrixRain", mt = "cos-canvas", ht = "cos-overlay", yt = "cos-title", vt = "cos-subtitle", q = {
135
+ matrixRain: ut,
136
+ canvas: mt,
137
+ overlay: ht,
138
+ title: yt,
139
+ subtitle: vt
140
+ }, K = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*アイウエオカキクケコ", Vt = ({ width: e = 800, height: s = 500, density: d = 0.6, color: l = "#00ff41" }) => {
141
+ const r = P(null);
142
+ return w(() => {
143
+ const m = r.current;
144
+ if (!m) return;
145
+ const y = window.devicePixelRatio || 1;
146
+ m.width = e * y, m.height = s * y;
147
+ const t = m.getContext("2d");
148
+ if (!t) return;
149
+ t.setTransform(y, 0, 0, y, 0, 0);
150
+ const c = 16, g = Math.floor(e / c * d), f = Array.from({ length: g }, () => Math.random() * -50);
151
+ let v = 0;
152
+ const M = () => {
153
+ t.fillStyle = "rgb(0 0 0 / 8%)", t.fillRect(0, 0, e, s), t.fillStyle = l, t.font = `${c}px monospace`, f.forEach((a, u) => {
154
+ const T = K[Math.floor(Math.random() * K.length)], b = u / d * c;
155
+ t.fillStyle = l, t.fillText(T, b, a * c), a * c > s && Math.random() > 0.975 && (f[u] = 0), f[u] += 1;
156
+ }), v = requestAnimationFrame(M);
157
+ };
158
+ return M(), () => cancelAnimationFrame(v);
159
+ }, [l, d, s, e]), /* @__PURE__ */ N("div", { className: q.matrixRain, style: { width: e, height: s }, children: [
160
+ /* @__PURE__ */ o("canvas", { ref: r, className: q.canvas, style: { width: e, height: s } }),
161
+ /* @__PURE__ */ N("div", { className: q.overlay, children: [
162
+ /* @__PURE__ */ o("h2", { className: q.title, children: "MATRIX" }),
163
+ /* @__PURE__ */ o("p", { className: q.subtitle, children: "数字雨效果" })
164
+ ] })
165
+ ] });
166
+ }, gt = "cos-neonText", pt = "cos-text", Mt = "cos-flicker", bt = "cos-reflection", O = {
167
+ neonText: gt,
168
+ text: pt,
169
+ flicker: Mt,
170
+ reflection: bt
171
+ }, zt = ({ text: e = "NEON", color: s = "#ff00de", fontSize: d = 72, flicker: l = !0 }) => /* @__PURE__ */ N("div", { className: O.neonText, children: [
172
+ /* @__PURE__ */ o(
173
+ "h1",
174
+ {
175
+ className: `${O.text} ${l ? O.flicker : ""}`,
176
+ style: {
177
+ fontSize: d,
178
+ "--neon-color": s
179
+ },
180
+ children: e
181
+ }
182
+ ),
183
+ /* @__PURE__ */ o("p", { className: O.reflection, style: { fontSize: d * 0.35, color: s }, children: e })
184
+ ] }), xt = "cos-particleNetwork", Nt = "cos-canvas", Ct = "cos-hint", U = {
185
+ particleNetwork: xt,
186
+ canvas: Nt,
187
+ hint: Ct
188
+ }, te = ({
189
+ width: e = 800,
190
+ height: s = 500,
191
+ particleCount: d = 60,
192
+ linkDistance: l = 120,
193
+ color: r = "#38bdf8"
194
+ }) => {
195
+ const m = P(null), y = P([]), t = P({ x: -1e3, y: -1e3 }), c = X(() => {
196
+ y.current = Array.from({ length: d }, () => ({
197
+ x: Math.random() * e,
198
+ y: Math.random() * s,
199
+ vx: (Math.random() - 0.5) * 1.2,
200
+ vy: (Math.random() - 0.5) * 1.2,
201
+ radius: Math.random() * 2 + 1
202
+ }));
203
+ }, [s, d, e]);
204
+ w(() => {
205
+ c();
206
+ }, [c]), w(() => {
207
+ const v = m.current;
208
+ if (!v) return;
209
+ const M = window.devicePixelRatio || 1;
210
+ v.width = e * M, v.height = s * M;
211
+ const a = v.getContext("2d");
212
+ if (!a) return;
213
+ a.setTransform(M, 0, 0, M, 0, 0);
214
+ let u = 0;
215
+ const T = () => {
216
+ a.fillStyle = "#0f172a", a.fillRect(0, 0, e, s);
217
+ const b = y.current, x = t.current;
218
+ b.forEach((i) => {
219
+ i.x += i.vx, i.y += i.vy, (i.x < 0 || i.x > e) && (i.vx *= -1), (i.y < 0 || i.y > s) && (i.vy *= -1);
220
+ const h = x.x - i.x, p = x.y - i.y;
221
+ Math.sqrt(h * h + p * p) < 150 && (i.vx -= h * 3e-4, i.vy -= p * 3e-4);
222
+ });
223
+ for (let i = 0; i < b.length; i++)
224
+ for (let h = i + 1; h < b.length; h++) {
225
+ const p = b[i].x - b[h].x, n = b[i].y - b[h].y, C = Math.sqrt(p * p + n * n);
226
+ C < l && (a.beginPath(), a.moveTo(b[i].x, b[i].y), a.lineTo(b[h].x, b[h].y), a.strokeStyle = r, a.globalAlpha = 1 - C / l, a.lineWidth = 0.8, a.stroke(), a.globalAlpha = 1);
227
+ }
228
+ b.forEach((i) => {
229
+ a.beginPath(), a.arc(i.x, i.y, i.radius, 0, Math.PI * 2), a.fillStyle = r, a.fill();
230
+ }), u = requestAnimationFrame(T);
231
+ };
232
+ return T(), () => cancelAnimationFrame(u);
233
+ }, [r, s, c, l, e]);
234
+ const g = (v) => {
235
+ const M = v.currentTarget.getBoundingClientRect();
236
+ t.current = { x: v.clientX - M.left, y: v.clientY - M.top };
237
+ }, f = () => {
238
+ t.current = { x: -1e3, y: -1e3 };
239
+ };
240
+ return /* @__PURE__ */ N("div", { className: U.particleNetwork, style: { width: e, height: s }, children: [
241
+ /* @__PURE__ */ o(
242
+ "canvas",
243
+ {
244
+ ref: m,
245
+ className: U.canvas,
246
+ style: { width: e, height: s },
247
+ onMouseMove: g,
248
+ onMouseLeave: f
249
+ }
250
+ ),
251
+ /* @__PURE__ */ o("p", { className: U.hint, children: "移动鼠标与粒子互动" })
252
+ ] });
253
+ }, Pt = "cos-returnCityContainer", It = "cos-star", wt = "cos-glassWrap", Tt = "cos-glassItem", H = {
254
+ returnCityContainer: Pt,
255
+ star: It,
256
+ glassWrap: wt,
257
+ glassItem: Tt
258
+ }, ee = () => {
259
+ const e = (d, l) => {
260
+ for (let r = 0; r < l; r++)
84
261
  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);
262
+ const m = document.createElement("div");
263
+ m.className = H.star;
264
+ const y = document.body.clientWidth, t = document.body.clientHeight, c = Math.random() * y + "px", g = Math.random() * t + "px";
265
+ m.style.top = g, m.style.left = c, d.append(m);
89
266
  }, 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);
267
+ }, s = () => {
268
+ const l = "150px", r = document.getElementById("glassWrap");
269
+ if (r)
270
+ for (let m = 0; m < 6; m++) {
271
+ const y = document.createElement("div");
272
+ y.className = H.glassItem, y.style.transform = `rotateY(${m * 60}deg) translateZ(${l})`, r.appendChild(y), setTimeout(() => {
273
+ y.style.top = "0px", y.style.opacity = "1";
274
+ }, m * 300);
98
275
  }
99
276
  };
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 = [
277
+ return w(() => {
278
+ const d = document.getElementById("returnCityContainer");
279
+ d && e(d, document.documentElement.clientWidth / 20), s();
280
+ }, []), /* @__PURE__ */ o("div", { id: "returnCityContainer", className: H.returnCityContainer, children: /* @__PURE__ */ o("div", { id: "glassWrap", className: H.glassWrap }) });
281
+ }, Rt = "cos-turntable", At = "cos-wheelWrap", St = "cos-canvas", Ft = "cos-pointer", Bt = "cos-spinBtn", $t = "cos-result", F = {
282
+ turntable: Rt,
283
+ wheelWrap: At,
284
+ canvas: St,
285
+ pointer: Ft,
286
+ spinBtn: Bt,
287
+ result: $t
288
+ }, V = ["#FF6B6B", "#4ECDC4", "#FFE66D", "#A78BFA", "#60A5FA", "#F472B6", "#34D399", "#FB923C"], Wt = [
112
289
  { label: "一等奖" },
113
290
  { label: "二等奖" },
114
291
  { label: "三等奖" },
115
292
  { label: "谢谢参与" },
116
293
  { label: "优惠券" },
117
294
  { 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
295
+ ], kt = (e) => 1 - Math.pow(1 - e, 3), ne = ({
296
+ prizes: e = Wt,
297
+ size: s = 360,
298
+ spinDuration: d = 4e3,
299
+ spinRounds: l = 5,
300
+ buttonText: r = "开始抽奖",
301
+ onSpinEnd: m
125
302
  }) => {
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();
303
+ const y = P(null), t = P(0), c = P(0), g = P(1), [f, v] = $(!1), [M, a] = $(null), u = s + 48, T = (h, p) => p.color ?? V[h % V.length], b = X(
304
+ (h) => {
305
+ const p = y.current;
306
+ if (!p) return;
307
+ const n = p.getContext("2d");
308
+ if (!n) return;
309
+ const C = u / 2, R = s / 2, W = Math.PI * 2 / e.length;
310
+ n.clearRect(0, 0, u, u), n.save(), n.translate(C, C), n.rotate(h), e.forEach((I, S) => {
311
+ const A = S * W - Math.PI / 2, k = A + W, Y = T(S, I);
312
+ n.beginPath(), n.moveTo(0, 0), n.arc(0, 0, R, A, k), n.closePath(), n.fillStyle = Y, n.fill(), n.strokeStyle = "rgb(255 255 255 / 35%)", n.lineWidth = 2, n.stroke(), n.save(), n.rotate(A + W / 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(I.label, R - 18, 6), n.restore();
313
+ }), n.beginPath(), n.arc(0, 0, R, 0, Math.PI * 2), n.strokeStyle = "#fbbf24", n.lineWidth = 6, n.stroke(), n.beginPath(), n.arc(0, 0, R - 4, 0, Math.PI * 2), n.strokeStyle = "#f59e0b", n.lineWidth = 2, n.stroke(), n.restore(), n.save(), n.translate(C, C);
314
+ for (let I = 0; I < 12; I++) {
315
+ const S = I / 12 * Math.PI * 2, A = Math.cos(S) * (R + 14), k = Math.sin(S) * (R + 14);
316
+ n.beginPath(), n.arc(A, k, 3, 0, Math.PI * 2), n.fillStyle = I % 2 === 0 ? "#fde68a" : "#f59e0b", n.fill();
140
317
  }
141
- e.restore();
318
+ n.restore();
142
319
  },
143
- [h, r, f]
320
+ [u, e, s]
144
321
  );
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(() => () => {
322
+ w(() => {
323
+ const h = y.current;
324
+ if (!h) return;
325
+ const p = window.devicePixelRatio || 1;
326
+ g.current = p, h.width = u * p, h.height = u * p;
327
+ const n = h.getContext("2d");
328
+ n && n.setTransform(p, 0, 0, p, 0, 0), b(t.current);
329
+ }, [u, b]), w(() => () => {
153
330
  c.current && cancelAnimationFrame(c.current);
154
331
  }, []);
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);
332
+ const x = (h) => {
333
+ const p = 360 / e.length, n = (h * (180 / Math.PI) % 360 + 360) % 360;
334
+ return Math.floor((360 - n + p / 2) % 360 / p) % e.length;
335
+ }, i = () => {
336
+ if (f || e.length === 0) return;
337
+ v(!0), a(null);
338
+ const h = Math.PI * 2 / e.length, n = Math.floor(Math.random() * e.length) * h + h / 2, C = t.current, R = l * Math.PI * 2, W = C + R + (Math.PI * 2 - n) - C % (Math.PI * 2), I = C, S = performance.now(), A = (k) => {
339
+ const Y = k - S, j = Math.min(Y / d, 1), tt = kt(j), L = I + (W - I) * tt;
340
+ if (t.current = L, b(L), j < 1)
341
+ c.current = requestAnimationFrame(A);
165
342
  else {
166
- const O = d(E), Q = r[O];
167
- t.current = E, M(!1), w(Q), l == null || l(Q, O);
343
+ const Z = x(L), _ = e[Z];
344
+ t.current = L, v(!1), a(_), m == null || m(_, Z);
168
345
  }
169
346
  };
170
- c.current = requestAnimationFrame(P);
347
+ c.current = requestAnimationFrame(A);
171
348
  };
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 })
349
+ return /* @__PURE__ */ N("div", { className: F.turntable, style: { width: u, height: u + 80 }, children: [
350
+ /* @__PURE__ */ N("div", { className: F.wheelWrap, style: { width: u, height: u }, children: [
351
+ /* @__PURE__ */ o("div", { className: F.pointer }),
352
+ /* @__PURE__ */ o("canvas", { ref: y, className: F.canvas, style: { width: u, height: u } }),
353
+ /* @__PURE__ */ o("button", { type: "button", className: F.spinBtn, onClick: i, disabled: f, children: f ? "抽奖中..." : r })
177
354
  ] }),
178
- B && !p && /* @__PURE__ */ S("p", { className: N.result, children: [
355
+ M && !f && /* @__PURE__ */ N("p", { className: F.result, children: [
179
356
  "恭喜获得:",
180
- /* @__PURE__ */ n("strong", { children: B.label })
357
+ /* @__PURE__ */ o("strong", { children: M.label })
181
358
  ] })
182
359
  ] });
183
- };
360
+ }, Et = "cos-typewriter", qt = "cos-terminal", Dt = "cos-dots", Lt = "cos-text", Ot = "cos-prompt", Ht = "cos-cursor", B = {
361
+ typewriter: Et,
362
+ terminal: qt,
363
+ dots: Dt,
364
+ text: Lt,
365
+ prompt: Ot,
366
+ cursor: Ht
367
+ }, Xt = ["Hello, cos-design!", "欢迎来到组件库 ✨", "Build something fun 🚀"], se = ({
368
+ texts: e = Xt,
369
+ speed: s = 100,
370
+ deleteSpeed: d = 50,
371
+ pause: l = 2e3
372
+ }) => {
373
+ const [r, m] = $(""), [y, t] = $(0), [c, g] = $(!1);
374
+ return w(() => {
375
+ const f = e[y % e.length];
376
+ let v;
377
+ if (!c && r === f)
378
+ v = setTimeout(() => g(!0), l);
379
+ else if (c && r === "")
380
+ g(!1), t((M) => (M + 1) % e.length);
381
+ else {
382
+ const M = c ? f.slice(0, r.length - 1) : f.slice(0, r.length + 1);
383
+ v = setTimeout(() => m(M), c ? d : s);
384
+ }
385
+ return () => clearTimeout(v);
386
+ }, [r, c, y, e, s, d, l]), /* @__PURE__ */ o("div", { className: B.typewriter, children: /* @__PURE__ */ N("div", { className: B.terminal, children: [
387
+ /* @__PURE__ */ N("div", { className: B.dots, children: [
388
+ /* @__PURE__ */ o("span", {}),
389
+ /* @__PURE__ */ o("span", {}),
390
+ /* @__PURE__ */ o("span", {})
391
+ ] }),
392
+ /* @__PURE__ */ N("p", { className: B.text, children: [
393
+ /* @__PURE__ */ o("span", { className: B.prompt, children: ">" }),
394
+ r,
395
+ /* @__PURE__ */ o("span", { className: B.cursor, children: "|" })
396
+ ] })
397
+ ] }) });
398
+ }, Yt = "cos-waveButton", Qt = "cos-btn", Ut = "cos-label", jt = "cos-wave", D = {
399
+ waveButton: Yt,
400
+ btn: Qt,
401
+ label: Ut,
402
+ wave: jt
403
+ }, ae = ({ text: e = "点我试试", onClick: s, color: d = "#38bdf8" }) => /* @__PURE__ */ o("div", { className: D.waveButton, children: /* @__PURE__ */ N(
404
+ "button",
405
+ {
406
+ type: "button",
407
+ className: D.btn,
408
+ style: { "--wave-color": d },
409
+ onClick: s,
410
+ children: [
411
+ /* @__PURE__ */ o("span", { className: D.wave }),
412
+ /* @__PURE__ */ o("span", { className: D.wave }),
413
+ /* @__PURE__ */ o("span", { className: D.label, children: e })
414
+ ]
415
+ }
416
+ ) });
184
417
  export {
185
- gt as CanvasClock,
186
- mt as Charge,
187
- ft as ReturnCity,
188
- pt as Turntable
418
+ Gt as CanvasClock,
419
+ Jt as Charge,
420
+ Kt as Fireworks,
421
+ Vt as MatrixRain,
422
+ zt as NeonText,
423
+ te as ParticleNetwork,
424
+ ee as ReturnCity,
425
+ ne as Turntable,
426
+ se as Typewriter,
427
+ ae as WaveButton
189
428
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cos-design",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A React component library built with Vite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",