@cos-design/smoke-fog 3.5.1 → 3.5.3
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/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.js +101 -47
- package/dist/src/components/smokeFog/index.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("@cos-design/shared"),u=require("react/jsx-runtime");var d={smokeFog:`cos-smokeFog-SYlts`,canvas:`cos-canvas-iOJV7`},f=({width:e=800,height:t=500,density:n=.5})=>{let r=(0,c.useRef)(null),i=(0,c.useRef)([]),a=(0,c.useRef)(0);
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});require('./index.css');var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require("react");c=s(c,1);let l=require("@cos-design/shared"),u=require("react/jsx-runtime");var d={smokeFog:`cos-smokeFog-SYlts`,canvas:`cos-canvas-iOJV7`},f=(e,t)=>{let n=Math.random()*80+40,r=(Math.random()-.5)*.4,i=(Math.random()-.5)*.3-.1,a=Math.random()*.15+.05;return{x:Math.random()*e,y:Math.random()*t,radius:n,baseRadius:n,vx:r,vy:i,baseVx:r,baseVy:i,alpha:a,baseAlpha:a,mass:.55+(n-40)/80*.9,receptivity:.45+Math.random()*.9,phase:Math.random()*Math.PI*2}},p=(e,t,n,r)=>{let i=Math.cos(-n),a=Math.sin(-n),o=e*i-t*a,s=e*a+t*i;return Math.hypot(o/r,s*r)},m=({width:e=800,height:t=500,density:n=.5})=>{let r=(0,c.useRef)(null),i=(0,c.useRef)([]),a=(0,c.useRef)([]),o=(0,c.useRef)(0);(0,c.useEffect)(()=>{let r=Math.floor(20+n*40);i.current=Array.from({length:r},()=>f(e,t))},[n,t,e]);let s=(0,c.useCallback)((n,i)=>{let o=r.current;if(!o)return;let s=o.getBoundingClientRect(),c=(n-s.left)/s.width*e,l=(i-s.top)/s.height*t;a.current.push({x:c,y:l,life:1,windAngle:Math.random()*Math.PI*2,swirl:Math.random()<.5?-1:1,stretch:1.15+Math.random()*.55,radius:Math.min(e,t)*(.28+Math.random()*.12)})},[t,e]);return(0,c.useEffect)(()=>{let e=r.current;if(!e)return;let t=e=>s(e.clientX,e.clientY),n=e=>{let t=e.touches[0];t&&s(t.clientX,t.clientY)};return e.addEventListener(`click`,t),e.addEventListener(`touchstart`,n,{passive:!0}),()=>{e.removeEventListener(`click`,t),e.removeEventListener(`touchstart`,n)}},[s]),(0,c.useEffect)(()=>{let n=r.current;if(!n)return;let s=window.devicePixelRatio||1;n.width=e*s,n.height=t*s;let c=n.getContext(`2d`);if(!c)return;c.setTransform(s,0,0,s,0,0);let u=0,d=document.hidden,f=(0,l.bindVisibilityPause)(e=>{d=e}),m=()=>{if(o.current=requestAnimationFrame(m),d)return;u+=.008,c.fillStyle=`#1a1a2e`,c.fillRect(0,0,e,t);let n=c.createRadialGradient(e*.5,t*.3,0,e*.5,t*.5,e*.7);n.addColorStop(0,`#2d2d44`),n.addColorStop(1,`#1a1a2e`),c.fillStyle=n,c.fillRect(0,0,e,t);let r=i.current,s=a.current;for(let e=s.length-1;e>=0;e--){let t=s[e],n=t.life*t.life,i=t.life>.92?1:.22;for(let e of r){let r=e.x-t.x,a=e.y-t.y,o=p(r,a,t.windAngle,t.stretch);if(o>t.radius)continue;let s=(1-o/t.radius)**1.6,c=.55+.7*Math.sin(e.phase*3.1+o*.05+u*1.7),l=s*e.receptivity*c*i;if(l<.06)continue;let d=Math.hypot(r,a)||1,f=r/d,m=a/d,h=-m*t.swirl,g=f*t.swirl,_=Math.cos(t.windAngle),v=Math.sin(t.windAngle),y=1/e.mass,b=Math.sin(e.phase*5.3+u*3.2+o*.03),x=Math.cos(e.phase*2.7-u*2.1+o*.02),S=l*n*(2.4+b*.8)*y,C=l*n*(1.6+x*1.1)*y,w=l*n*(1.2+b*.6)*y,T=b*l*n*1.2*y,E=x*l*n*1.2*y;e.vx+=f*S+h*C+_*w+T,e.vy+=m*S+g*C+v*w+E,e.alpha*=1-l*n*(.28+Math.abs(b)*.18),e.radius+=e.baseRadius*l*n*(.1+Math.abs(x)*.16)}t.life*=.88,t.radius*=1.01,t.life<.05&&s.splice(e,1)}r.forEach((n,r)=>{n.x+=n.vx+Math.sin(u+r+n.phase)*.15,n.y+=n.vy+Math.cos(u*.7+r*.5+n.phase)*.1;let i=.014+n.mass*.01;n.vx+=(n.baseVx-n.vx)*i,n.vy+=(n.baseVy-n.vy)*i,n.alpha+=(n.baseAlpha-n.alpha)*.01,n.radius+=(n.baseRadius-n.radius)*.012,n.x<-n.radius&&(n.x=e+n.radius),n.x>e+n.radius&&(n.x=-n.radius),n.y<-n.radius&&(n.y=t+n.radius),n.y>t+n.radius&&(n.y=-n.radius);let a=c.createRadialGradient(n.x,n.y,0,n.x,n.y,n.radius);a.addColorStop(0,`rgb(200 200 210 / ${n.alpha})`),a.addColorStop(.5,`rgb(160 160 175 / ${n.alpha*.5})`),a.addColorStop(1,`rgb(160 160 175 / 0)`),c.fillStyle=a,c.beginPath(),c.arc(n.x,n.y,n.radius,0,Math.PI*2),c.fill()})};return m(),()=>{cancelAnimationFrame(o.current),f()}},[t,e]),(0,u.jsx)(`div`,{className:d.smokeFog,style:{width:e,height:t},children:(0,u.jsx)(`canvas`,{ref:r,className:d.canvas,style:{width:e,height:t}})})};exports.SmokeFog=m,exports.default=m;
|
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.cos-smokeFog-SYlts{background:#1a1a2e;border-radius:12px;overflow:hidden}.cos-canvas-iOJV7{display:block}
|
|
1
|
+
.cos-smokeFog-SYlts{background:#1a1a2e;border-radius:12px;overflow:hidden}.cos-canvas-iOJV7{cursor:pointer;touch-action:manipulation;display:block}
|
package/dist/index.js
CHANGED
|
@@ -1,63 +1,117 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { bindVisibilityPause as
|
|
3
|
-
import { jsx as
|
|
4
|
-
import './index.css';var
|
|
1
|
+
import { useCallback as e, useEffect as t, useRef as n } from "react";
|
|
2
|
+
import { bindVisibilityPause as r } from "@cos-design/shared";
|
|
3
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
4
|
+
import './index.css';var a = {
|
|
5
5
|
smokeFog: "cos-smokeFog-SYlts",
|
|
6
6
|
canvas: "cos-canvas-iOJV7"
|
|
7
|
-
},
|
|
8
|
-
let
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
}, o = (e, t) => {
|
|
8
|
+
let n = Math.random() * 80 + 40, r = (Math.random() - .5) * .4, i = (Math.random() - .5) * .3 - .1, a = Math.random() * .15 + .05;
|
|
9
|
+
return {
|
|
10
|
+
x: Math.random() * e,
|
|
11
|
+
y: Math.random() * t,
|
|
12
|
+
radius: n,
|
|
13
|
+
baseRadius: n,
|
|
14
|
+
vx: r,
|
|
15
|
+
vy: i,
|
|
16
|
+
baseVx: r,
|
|
17
|
+
baseVy: i,
|
|
18
|
+
alpha: a,
|
|
19
|
+
baseAlpha: a,
|
|
20
|
+
mass: .55 + (n - 40) / 80 * .9,
|
|
21
|
+
receptivity: .45 + Math.random() * .9,
|
|
22
|
+
phase: Math.random() * Math.PI * 2
|
|
23
|
+
};
|
|
24
|
+
}, s = (e, t, n, r) => {
|
|
25
|
+
let i = Math.cos(-n), a = Math.sin(-n), o = e * i - t * a, s = e * a + t * i;
|
|
26
|
+
return Math.hypot(o / r, s * r);
|
|
27
|
+
}, c = ({ width: c = 800, height: l = 500, density: u = .5 }) => {
|
|
28
|
+
let d = n(null), f = n([]), p = n([]), m = n(0);
|
|
29
|
+
t(() => {
|
|
30
|
+
let e = Math.floor(20 + u * 40);
|
|
31
|
+
f.current = Array.from({ length: e }, () => o(c, l));
|
|
19
32
|
}, [
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
])
|
|
24
|
-
|
|
33
|
+
u,
|
|
34
|
+
l,
|
|
35
|
+
c
|
|
36
|
+
]);
|
|
37
|
+
let h = e((e, t) => {
|
|
38
|
+
let n = d.current;
|
|
39
|
+
if (!n) return;
|
|
40
|
+
let r = n.getBoundingClientRect(), i = (e - r.left) / r.width * c, a = (t - r.top) / r.height * l;
|
|
41
|
+
p.current.push({
|
|
42
|
+
x: i,
|
|
43
|
+
y: a,
|
|
44
|
+
life: 1,
|
|
45
|
+
windAngle: Math.random() * Math.PI * 2,
|
|
46
|
+
swirl: Math.random() < .5 ? -1 : 1,
|
|
47
|
+
stretch: 1.15 + Math.random() * .55,
|
|
48
|
+
radius: Math.min(c, l) * (.28 + Math.random() * .12)
|
|
49
|
+
});
|
|
50
|
+
}, [l, c]);
|
|
51
|
+
return t(() => {
|
|
52
|
+
let e = d.current;
|
|
53
|
+
if (!e) return;
|
|
54
|
+
let t = (e) => h(e.clientX, e.clientY), n = (e) => {
|
|
55
|
+
let t = e.touches[0];
|
|
56
|
+
t && h(t.clientX, t.clientY);
|
|
57
|
+
};
|
|
58
|
+
return e.addEventListener("click", t), e.addEventListener("touchstart", n, { passive: !0 }), () => {
|
|
59
|
+
e.removeEventListener("click", t), e.removeEventListener("touchstart", n);
|
|
60
|
+
};
|
|
61
|
+
}, [h]), t(() => {
|
|
62
|
+
let e = d.current;
|
|
25
63
|
if (!e) return;
|
|
26
64
|
let t = window.devicePixelRatio || 1;
|
|
27
|
-
e.width =
|
|
28
|
-
let
|
|
29
|
-
if (!
|
|
30
|
-
|
|
31
|
-
let i = 0,
|
|
32
|
-
|
|
33
|
-
}),
|
|
34
|
-
if (
|
|
35
|
-
i += .008,
|
|
36
|
-
let e =
|
|
37
|
-
e.addColorStop(0, "#2d2d44"), e.addColorStop(1, "#1a1a2e"),
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
n
|
|
65
|
+
e.width = c * t, e.height = l * t;
|
|
66
|
+
let n = e.getContext("2d");
|
|
67
|
+
if (!n) return;
|
|
68
|
+
n.setTransform(t, 0, 0, t, 0, 0);
|
|
69
|
+
let i = 0, a = document.hidden, o = r((e) => {
|
|
70
|
+
a = e;
|
|
71
|
+
}), u = () => {
|
|
72
|
+
if (m.current = requestAnimationFrame(u), a) return;
|
|
73
|
+
i += .008, n.fillStyle = "#1a1a2e", n.fillRect(0, 0, c, l);
|
|
74
|
+
let e = n.createRadialGradient(c * .5, l * .3, 0, c * .5, l * .5, c * .7);
|
|
75
|
+
e.addColorStop(0, "#2d2d44"), e.addColorStop(1, "#1a1a2e"), n.fillStyle = e, n.fillRect(0, 0, c, l);
|
|
76
|
+
let t = f.current, r = p.current;
|
|
77
|
+
for (let e = r.length - 1; e >= 0; e--) {
|
|
78
|
+
let n = r[e], a = n.life * n.life, o = n.life > .92 ? 1 : .22;
|
|
79
|
+
for (let e of t) {
|
|
80
|
+
let t = e.x - n.x, r = e.y - n.y, c = s(t, r, n.windAngle, n.stretch);
|
|
81
|
+
if (c > n.radius) continue;
|
|
82
|
+
let l = (1 - c / n.radius) ** 1.6, u = .55 + .7 * Math.sin(e.phase * 3.1 + c * .05 + i * 1.7), d = l * e.receptivity * u * o;
|
|
83
|
+
if (d < .06) continue;
|
|
84
|
+
let f = Math.hypot(t, r) || 1, p = t / f, m = r / f, h = -m * n.swirl, g = p * n.swirl, _ = Math.cos(n.windAngle), v = Math.sin(n.windAngle), y = 1 / e.mass, b = Math.sin(e.phase * 5.3 + i * 3.2 + c * .03), x = Math.cos(e.phase * 2.7 - i * 2.1 + c * .02), S = d * a * (2.4 + b * .8) * y, C = d * a * (1.6 + x * 1.1) * y, w = d * a * (1.2 + b * .6) * y, T = b * d * a * 1.2 * y, E = x * d * a * 1.2 * y;
|
|
85
|
+
e.vx += p * S + h * C + _ * w + T, e.vy += m * S + g * C + v * w + E, e.alpha *= 1 - d * a * (.28 + Math.abs(b) * .18), e.radius += e.baseRadius * d * a * (.1 + Math.abs(x) * .16);
|
|
86
|
+
}
|
|
87
|
+
n.life *= .88, n.radius *= 1.01, n.life < .05 && r.splice(e, 1);
|
|
88
|
+
}
|
|
89
|
+
t.forEach((e, t) => {
|
|
90
|
+
e.x += e.vx + Math.sin(i + t + e.phase) * .15, e.y += e.vy + Math.cos(i * .7 + t * .5 + e.phase) * .1;
|
|
91
|
+
let r = .014 + e.mass * .01;
|
|
92
|
+
e.vx += (e.baseVx - e.vx) * r, e.vy += (e.baseVy - e.vy) * r, e.alpha += (e.baseAlpha - e.alpha) * .01, e.radius += (e.baseRadius - e.radius) * .012, e.x < -e.radius && (e.x = c + e.radius), e.x > c + e.radius && (e.x = -e.radius), e.y < -e.radius && (e.y = l + e.radius), e.y > l + e.radius && (e.y = -e.radius);
|
|
93
|
+
let a = n.createRadialGradient(e.x, e.y, 0, e.x, e.y, e.radius);
|
|
94
|
+
a.addColorStop(0, `rgb(200 200 210 / ${e.alpha})`), a.addColorStop(.5, `rgb(160 160 175 / ${e.alpha * .5})`), a.addColorStop(1, "rgb(160 160 175 / 0)"), n.fillStyle = a, n.beginPath(), n.arc(e.x, e.y, e.radius, 0, Math.PI * 2), n.fill();
|
|
41
95
|
});
|
|
42
96
|
};
|
|
43
|
-
return
|
|
44
|
-
cancelAnimationFrame(
|
|
97
|
+
return u(), () => {
|
|
98
|
+
cancelAnimationFrame(m.current), o();
|
|
45
99
|
};
|
|
46
|
-
}, [
|
|
47
|
-
className:
|
|
100
|
+
}, [l, c]), /* @__PURE__ */ i("div", {
|
|
101
|
+
className: a.smokeFog,
|
|
48
102
|
style: {
|
|
49
|
-
width:
|
|
50
|
-
height:
|
|
103
|
+
width: c,
|
|
104
|
+
height: l
|
|
51
105
|
},
|
|
52
|
-
children: /* @__PURE__ */
|
|
53
|
-
ref:
|
|
54
|
-
className:
|
|
106
|
+
children: /* @__PURE__ */ i("canvas", {
|
|
107
|
+
ref: d,
|
|
108
|
+
className: a.canvas,
|
|
55
109
|
style: {
|
|
56
|
-
width:
|
|
57
|
-
height:
|
|
110
|
+
width: c,
|
|
111
|
+
height: l
|
|
58
112
|
}
|
|
59
113
|
})
|
|
60
114
|
});
|
|
61
115
|
};
|
|
62
116
|
//#endregion
|
|
63
|
-
export {
|
|
117
|
+
export { c as SmokeFog, c as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cos-design/smoke-fog",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "SmokeFog component from cos-design",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"registry": "https://registry.npmjs.org"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@cos-design/shared": "3.5.
|
|
55
|
+
"@cos-design/shared": "3.5.3"
|
|
56
56
|
}
|
|
57
57
|
}
|