fancy-ui-vue 0.4.0 → 0.5.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/README.md +12 -12
- package/dist/components/animated-testimonials/AnimatedTestimonials.vue.js +23 -12
- package/dist/components/bg-falling-stars/FallingStarsBg.vue.js +10 -1
- package/dist/components/bg-falling-stars/bg-falling-stars-core.d.ts +6 -0
- package/dist/components/bg-falling-stars/bg-falling-stars-core.js +24 -2
- package/dist/components/bg-stars/StarsBackground.vue.js +1 -1
- package/dist/components/bg-stars/StarsBackground.vue2.js +13 -1
- package/dist/components/bg-stars/bg-stars-core.d.ts +6 -0
- package/dist/components/bg-stars/bg-stars-core.js +21 -1
- package/dist/components/book/Book.vue.js +5 -83
- package/dist/components/book/Book.vue2.js +82 -1
- package/dist/components/box-reveal/BoxReveal.vue.js +5 -47
- package/dist/components/box-reveal/BoxReveal.vue2.js +48 -1
- package/dist/components/compare/StarField.vue.js +1 -1
- package/dist/components/container-text-flip/ContainerTextFlip.vue.js +1 -1
- package/dist/components/container-text-flip/ContainerTextFlip.vue2.js +14 -5
- package/dist/components/flickering-grid/FlickeringGrid.vue.js +19 -1
- package/dist/components/flickering-grid/flickering-grid-core.d.ts +6 -0
- package/dist/components/flickering-grid/flickering-grid-core.js +30 -1
- package/dist/components/flip-words/FlipWords.vue.js +1 -1
- package/dist/components/flip-words/FlipWords.vue2.js +14 -7
- package/dist/components/frost-glass/FrostGlass.vue.d.ts +31 -0
- package/dist/components/frost-glass/FrostGlass.vue.js +90 -0
- package/dist/components/frost-glass/FrostGlass.vue2.js +4 -0
- package/dist/components/frost-glass/frost-glass-core.d.ts +155 -0
- package/dist/components/frost-glass/frost-glass-core.js +820 -0
- package/dist/components/frost-glass/index.d.ts +2 -0
- package/dist/components/gift-reveal/GiftReveal.vue.d.ts +50 -0
- package/dist/components/gift-reveal/GiftReveal.vue.js +7 -0
- package/dist/components/gift-reveal/GiftReveal.vue2.js +177 -0
- package/dist/components/gift-reveal/gift-reveal-core.d.ts +109 -0
- package/dist/components/gift-reveal/gift-reveal-core.js +116 -0
- package/dist/components/gift-reveal/index.d.ts +2 -0
- package/dist/components/hyper-text/HyperText.vue.js +6 -97
- package/dist/components/hyper-text/HyperText.vue2.js +101 -0
- package/dist/components/letter-pullup/LetterPullup.vue.js +6 -38
- package/dist/components/letter-pullup/LetterPullup.vue2.js +40 -0
- package/dist/components/logo-cloud/AnimatedLogoCloud.vue.js +1 -1
- package/dist/components/matrix-rain/MatrixRain.vue.js +20 -1
- package/dist/components/matrix-rain/matrix-rain-core.d.ts +6 -0
- package/dist/components/matrix-rain/matrix-rain-core.js +28 -6
- package/dist/components/noise-reveal/NoiseReveal.vue.js +7 -0
- package/dist/components/noise-reveal/noise-reveal-core.js +23 -7
- package/dist/components/ornament/Ornament.vue.d.ts +29 -0
- package/dist/components/ornament/Ornament.vue.js +112 -0
- package/dist/components/ornament/Ornament.vue2.js +4 -0
- package/dist/components/ornament/index.d.ts +2 -0
- package/dist/components/ornament/ornament-core.d.ts +177 -0
- package/dist/components/ornament/ornament-core.js +861 -0
- package/dist/components/ripple/Ripple.vue.js +1 -1
- package/dist/components/ripple/Ripple.vue2.js +6 -1
- package/dist/components/snowfall/Snowfall.vue.d.ts +29 -0
- package/dist/components/snowfall/Snowfall.vue.js +81 -0
- package/dist/components/snowfall/Snowfall.vue2.js +4 -0
- package/dist/components/snowfall/index.d.ts +2 -0
- package/dist/components/snowfall/snowfall-core.d.ts +119 -0
- package/dist/components/snowfall/snowfall-core.js +483 -0
- package/dist/components/sparkles/Sparkles.vue.js +10 -1
- package/dist/components/sparkles/sparkles-core.d.ts +6 -0
- package/dist/components/sparkles/sparkles-core.js +26 -2
- package/dist/components/sparkles-text/SparklesText.vue.js +6 -88
- package/dist/components/sparkles-text/SparklesText.vue2.js +100 -0
- package/dist/components/string-lights/StringLights.vue.d.ts +35 -0
- package/dist/components/string-lights/StringLights.vue.js +7 -0
- package/dist/components/string-lights/StringLights.vue2.js +98 -0
- package/dist/components/string-lights/index.d.ts +2 -0
- package/dist/components/string-lights/string-lights-core.d.ts +157 -0
- package/dist/components/string-lights/string-lights-core.js +228 -0
- package/dist/components/terminal-text/TerminalText.vue.js +1 -1
- package/dist/components/terminal-text/TerminalText.vue2.js +36 -4
- package/dist/components/text-generate-effect/TextGenerateEffect.vue.js +5 -72
- package/dist/components/text-generate-effect/TextGenerateEffect.vue2.js +74 -1
- package/dist/components/text-reveal-card/TextRevealCard.vue.js +5 -101
- package/dist/components/text-reveal-card/TextRevealCard.vue2.js +98 -1
- package/dist/components/text-reveal-card/TextRevealStars.vue.js +1 -1
- package/dist/components/text-reveal-card/TextRevealStars.vue2.js +29 -12
- package/dist/index.d.ts +5 -0
- package/dist/index.js +393 -386
- package/dist/styles.css +1669 -185
- package/package.json +2 -2
- package/dist/components/hyper-text/HyperText.vue3.js +0 -5
- package/dist/components/letter-pullup/LetterPullup.vue3.js +0 -5
- package/dist/components/sparkles-text/SparklesText.vue3.js +0 -5
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
const SNOWFALL_DEFAULTS = {
|
|
2
|
+
density: 45,
|
|
3
|
+
speed: 1,
|
|
4
|
+
wind: 0.15,
|
|
5
|
+
depth: 0.8,
|
|
6
|
+
size: 1,
|
|
7
|
+
color: "#f4f7ff",
|
|
8
|
+
glow: 0.5,
|
|
9
|
+
blend: "auto",
|
|
10
|
+
seed: 1
|
|
11
|
+
};
|
|
12
|
+
const MAX_FLAKES = 1600;
|
|
13
|
+
const MAX_PIXEL_RATIO = 2;
|
|
14
|
+
const MAX_STEP = 1 / 20;
|
|
15
|
+
const WIND_SPEED = 70;
|
|
16
|
+
const FLOATS_PER_FLAKE = 8;
|
|
17
|
+
function mulberry32(seed) {
|
|
18
|
+
let a = Math.floor(seed) >>> 0;
|
|
19
|
+
return () => {
|
|
20
|
+
a = a + 1831565813 >>> 0;
|
|
21
|
+
let t = a;
|
|
22
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
23
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
24
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function parseHexColor(value, fallback) {
|
|
28
|
+
if (!value) return [fallback[0], fallback[1], fallback[2]];
|
|
29
|
+
const hex = value.trim().replace(/^#/, "");
|
|
30
|
+
const full = hex.length === 3 ? hex.split("").map((c) => c + c).join("") : hex;
|
|
31
|
+
if (!/^[0-9a-fA-F]{6}$/.test(full)) return [fallback[0], fallback[1], fallback[2]];
|
|
32
|
+
const n = Number.parseInt(full, 16);
|
|
33
|
+
return [(n >> 16 & 255) / 255, (n >> 8 & 255) / 255, (n & 255) / 255];
|
|
34
|
+
}
|
|
35
|
+
function resolveBlend(blend, rgb) {
|
|
36
|
+
if (blend === "glow" || blend === "normal") return blend;
|
|
37
|
+
const luma = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
|
|
38
|
+
return luma >= 0.5 ? "glow" : "normal";
|
|
39
|
+
}
|
|
40
|
+
function flakeCount(density, width, height) {
|
|
41
|
+
if (!Number.isFinite(density) || density <= 0) return 0;
|
|
42
|
+
const area = Math.max(0, width) * Math.max(0, height);
|
|
43
|
+
return Math.min(MAX_FLAKES, Math.round(density * area / 1e5));
|
|
44
|
+
}
|
|
45
|
+
function buildFlakes(seed) {
|
|
46
|
+
const random = mulberry32(seed);
|
|
47
|
+
const ranks = Array.from({ length: MAX_FLAKES }, (_, i) => i);
|
|
48
|
+
for (let i = ranks.length - 1; i > 0; i--) {
|
|
49
|
+
const j = Math.floor(random() * (i + 1));
|
|
50
|
+
const swap = ranks[i];
|
|
51
|
+
ranks[i] = ranks[j];
|
|
52
|
+
ranks[j] = swap;
|
|
53
|
+
}
|
|
54
|
+
const flakes = [];
|
|
55
|
+
for (let i = 0; i < MAX_FLAKES; i++) {
|
|
56
|
+
const depth = Math.pow(random(), 2.4);
|
|
57
|
+
flakes.push([
|
|
58
|
+
random(),
|
|
59
|
+
random(),
|
|
60
|
+
depth,
|
|
61
|
+
ranks[i],
|
|
62
|
+
random(),
|
|
63
|
+
0.35 + random() * 0.9,
|
|
64
|
+
0.3 + random() * 0.7,
|
|
65
|
+
0.6 + random() * 2.2
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
flakes.sort((a, b) => a[2] - b[2]);
|
|
69
|
+
const data = new Float32Array(MAX_FLAKES * FLOATS_PER_FLAKE);
|
|
70
|
+
flakes.forEach((flake, i) => data.set(flake, i * FLOATS_PER_FLAKE));
|
|
71
|
+
return data;
|
|
72
|
+
}
|
|
73
|
+
function fallbackBackground(color) {
|
|
74
|
+
const dot = (x, y, r) => `radial-gradient(circle at ${x}% ${y}%, ${color} 0, transparent ${r}px)`;
|
|
75
|
+
return [
|
|
76
|
+
dot(12, 18, 2),
|
|
77
|
+
dot(31, 64, 3),
|
|
78
|
+
dot(47, 29, 1.5),
|
|
79
|
+
dot(63, 81, 2.5),
|
|
80
|
+
dot(78, 42, 2),
|
|
81
|
+
dot(91, 12, 1.5),
|
|
82
|
+
dot(22, 88, 1.5),
|
|
83
|
+
dot(55, 55, 4)
|
|
84
|
+
].join(", ");
|
|
85
|
+
}
|
|
86
|
+
const VERTEX_SHADER = `
|
|
87
|
+
precision highp float;
|
|
88
|
+
|
|
89
|
+
attribute vec4 aPlace;
|
|
90
|
+
attribute vec4 aTraits;
|
|
91
|
+
|
|
92
|
+
uniform vec2 uView;
|
|
93
|
+
uniform float uPixelRatio;
|
|
94
|
+
uniform float uMaxPoint;
|
|
95
|
+
uniform float uTime;
|
|
96
|
+
uniform float uDrift;
|
|
97
|
+
uniform float uGust;
|
|
98
|
+
uniform float uCount;
|
|
99
|
+
uniform float uDepth;
|
|
100
|
+
uniform float uSize;
|
|
101
|
+
uniform float uGlow;
|
|
102
|
+
|
|
103
|
+
varying float vAlpha;
|
|
104
|
+
varying float vBlur;
|
|
105
|
+
varying float vCore;
|
|
106
|
+
|
|
107
|
+
const float TAU = 6.2831853;
|
|
108
|
+
|
|
109
|
+
// Gusts as a displacement, never a speed, so the wind can never snap: three
|
|
110
|
+
// slow incommensurate waves, felt a moment later lower down the screen.
|
|
111
|
+
float gust(float t) {
|
|
112
|
+
return sin(t * 0.13) * 1.3 + sin(t * 0.29 + 1.7) * 0.7 + sin(t * 0.071 + 4.1) * 1.6;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void main() {
|
|
116
|
+
if (aPlace.w >= uCount) {
|
|
117
|
+
// Not part of this density: park it outside the clip volume.
|
|
118
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
119
|
+
gl_PointSize = 1.0;
|
|
120
|
+
vAlpha = 0.0;
|
|
121
|
+
vBlur = 0.0;
|
|
122
|
+
vCore = 1.0;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
float z = mix(0.42, aPlace.z, uDepth);
|
|
126
|
+
float near = pow(z, 3.0);
|
|
127
|
+
float phase = aTraits.x * TAU;
|
|
128
|
+
float jitter = 0.7 + 0.6 * fract(aTraits.x * 7.13);
|
|
129
|
+
|
|
130
|
+
float core = mix(1.7, 58.0, near) * uSize * jitter;
|
|
131
|
+
// Out of focus from a little past the middle; the far field stays sharp.
|
|
132
|
+
float blur = smoothstep(0.4, 0.92, z);
|
|
133
|
+
// The halo only belongs to sharp flakes; a disc is already soft.
|
|
134
|
+
float pad = 1.0 + uGlow * 4.0 * (1.0 - blur);
|
|
135
|
+
float sprite = core * pad;
|
|
136
|
+
|
|
137
|
+
// The field wraps with a margin wider than the largest sprite, so a flake
|
|
138
|
+
// leaves the canvas entirely before it comes back on the other side.
|
|
139
|
+
float margin = 24.0 + 44.0 * uSize;
|
|
140
|
+
vec2 field = uView + 2.0 * margin;
|
|
141
|
+
|
|
142
|
+
float fall = mix(13.0, 64.0, z) * (0.85 + 0.3 * fract(aTraits.x * 3.7));
|
|
143
|
+
float y = mod(aPlace.y * field.y + uTime * fall, field.y) - margin;
|
|
144
|
+
|
|
145
|
+
float parallax = mix(0.35, 1.35, z);
|
|
146
|
+
float sway = sin(uTime * aTraits.y + phase) * mix(3.0, 26.0, near) * aTraits.z;
|
|
147
|
+
float wind = (uDrift + gust(uTime - y / 500.0) * uGust) * parallax;
|
|
148
|
+
float x = mod(aPlace.x * field.x + wind + sway, field.x) - margin;
|
|
149
|
+
|
|
150
|
+
gl_Position = vec4(x / uView.x * 2.0 - 1.0, 1.0 - y / uView.y * 2.0, 0.0, 1.0);
|
|
151
|
+
// The hardware caps point size; the shape is drawn in sprite units, so a
|
|
152
|
+
// capped sprite only shrinks, it never clips.
|
|
153
|
+
gl_PointSize = min(sprite * uPixelRatio, uMaxPoint);
|
|
154
|
+
|
|
155
|
+
float twinkle = 1.0 + (1.0 - blur) * 0.32 * sin(uTime * aTraits.w * 2.0 + phase * 3.0);
|
|
156
|
+
// Light per pixel falls as the disc spreads; the far field fades into the distance.
|
|
157
|
+
float bright = mix(0.95, 0.15, blur) * mix(0.5, 1.0, smoothstep(0.0, 0.3, z));
|
|
158
|
+
vAlpha = bright * twinkle;
|
|
159
|
+
vBlur = blur;
|
|
160
|
+
vCore = 1.0 / pad;
|
|
161
|
+
}
|
|
162
|
+
`;
|
|
163
|
+
const FRAGMENT_SHADER = `
|
|
164
|
+
precision highp float;
|
|
165
|
+
|
|
166
|
+
uniform vec3 uColor;
|
|
167
|
+
uniform float uGlow;
|
|
168
|
+
|
|
169
|
+
varying float vAlpha;
|
|
170
|
+
varying float vBlur;
|
|
171
|
+
varying float vCore;
|
|
172
|
+
|
|
173
|
+
void main() {
|
|
174
|
+
vec2 p = gl_PointCoord * 2.0 - 1.0;
|
|
175
|
+
float r = length(p);
|
|
176
|
+
if (r > 1.0) discard;
|
|
177
|
+
float rc = r / vCore;
|
|
178
|
+
|
|
179
|
+
// In focus a small bright dot; drifting out of focus it widens into a soft
|
|
180
|
+
// blob before it settles into a disc.
|
|
181
|
+
float sharp = exp(-rc * rc * mix(3.0, 1.4, smoothstep(0.0, 0.5, vBlur)));
|
|
182
|
+
// Out of focus: a flat disc, soft at the edge, its rim a touch brighter.
|
|
183
|
+
float edge = mix(0.4, 0.2, vBlur);
|
|
184
|
+
float disc = 1.0 - smoothstep(1.0 - edge, 1.0, rc);
|
|
185
|
+
float rim = smoothstep(0.55, 0.9, rc) * disc;
|
|
186
|
+
float bokeh = disc * (0.78 + 0.32 * rim);
|
|
187
|
+
float shape = mix(sharp, bokeh, smoothstep(0.35, 0.85, vBlur));
|
|
188
|
+
|
|
189
|
+
float halo = exp(-r * r * 5.0) * (1.0 - smoothstep(0.7, 1.0, r)) * uGlow * 0.32 * (1.0 - vBlur);
|
|
190
|
+
|
|
191
|
+
float a = clamp((shape + halo) * vAlpha, 0.0, 1.0);
|
|
192
|
+
gl_FragColor = vec4(uColor * a, a);
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
const UNIFORMS = [
|
|
196
|
+
"uView",
|
|
197
|
+
"uPixelRatio",
|
|
198
|
+
"uMaxPoint",
|
|
199
|
+
"uTime",
|
|
200
|
+
"uDrift",
|
|
201
|
+
"uGust",
|
|
202
|
+
"uCount",
|
|
203
|
+
"uDepth",
|
|
204
|
+
"uSize",
|
|
205
|
+
"uGlow",
|
|
206
|
+
"uColor"
|
|
207
|
+
];
|
|
208
|
+
function compile(gl, type, source) {
|
|
209
|
+
const shader = gl.createShader(type);
|
|
210
|
+
if (!shader) return null;
|
|
211
|
+
gl.shaderSource(shader, source);
|
|
212
|
+
gl.compileShader(shader);
|
|
213
|
+
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
|
214
|
+
gl.deleteShader(shader);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return shader;
|
|
218
|
+
}
|
|
219
|
+
function setup(gl, seed) {
|
|
220
|
+
const vertex = compile(gl, gl.VERTEX_SHADER, VERTEX_SHADER);
|
|
221
|
+
const fragment = compile(gl, gl.FRAGMENT_SHADER, FRAGMENT_SHADER);
|
|
222
|
+
const program = gl.createProgram();
|
|
223
|
+
if (!vertex || !fragment || !program) {
|
|
224
|
+
if (vertex) gl.deleteShader(vertex);
|
|
225
|
+
if (fragment) gl.deleteShader(fragment);
|
|
226
|
+
if (program) gl.deleteProgram(program);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
gl.attachShader(program, vertex);
|
|
230
|
+
gl.attachShader(program, fragment);
|
|
231
|
+
gl.bindAttribLocation(program, 0, "aPlace");
|
|
232
|
+
gl.bindAttribLocation(program, 1, "aTraits");
|
|
233
|
+
gl.linkProgram(program);
|
|
234
|
+
gl.deleteShader(vertex);
|
|
235
|
+
gl.deleteShader(fragment);
|
|
236
|
+
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
|
237
|
+
gl.deleteProgram(program);
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
gl.useProgram(program);
|
|
241
|
+
const buffer = gl.createBuffer();
|
|
242
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
243
|
+
gl.bufferData(gl.ARRAY_BUFFER, buildFlakes(seed), gl.STATIC_DRAW);
|
|
244
|
+
const stride = FLOATS_PER_FLAKE * 4;
|
|
245
|
+
gl.enableVertexAttribArray(0);
|
|
246
|
+
gl.vertexAttribPointer(0, 4, gl.FLOAT, false, stride, 0);
|
|
247
|
+
gl.enableVertexAttribArray(1);
|
|
248
|
+
gl.vertexAttribPointer(1, 4, gl.FLOAT, false, stride, 16);
|
|
249
|
+
const uniforms = {};
|
|
250
|
+
for (const name of UNIFORMS) uniforms[name] = gl.getUniformLocation(program, name);
|
|
251
|
+
let maxPoint = 64;
|
|
252
|
+
const range = gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
|
|
253
|
+
if (range && typeof range[1] === "number" && range[1] >= 1) maxPoint = range[1];
|
|
254
|
+
gl.disable(gl.DEPTH_TEST);
|
|
255
|
+
gl.enable(gl.BLEND);
|
|
256
|
+
gl.clearColor(0, 0, 0, 0);
|
|
257
|
+
return { program, buffer, uniforms, maxPoint };
|
|
258
|
+
}
|
|
259
|
+
function createSnowfall(elements, options = {}) {
|
|
260
|
+
const { canvas } = elements;
|
|
261
|
+
const releaseContext = options.releaseContext ?? true;
|
|
262
|
+
let gl = null;
|
|
263
|
+
try {
|
|
264
|
+
gl = canvas.getContext("webgl", {
|
|
265
|
+
alpha: true,
|
|
266
|
+
premultipliedAlpha: true,
|
|
267
|
+
antialias: false,
|
|
268
|
+
depth: false,
|
|
269
|
+
powerPreference: "low-power"
|
|
270
|
+
});
|
|
271
|
+
} catch {
|
|
272
|
+
gl = null;
|
|
273
|
+
}
|
|
274
|
+
if (!gl) return null;
|
|
275
|
+
const context = gl;
|
|
276
|
+
const live = {
|
|
277
|
+
density: options.density ?? SNOWFALL_DEFAULTS.density,
|
|
278
|
+
speed: options.speed ?? SNOWFALL_DEFAULTS.speed,
|
|
279
|
+
wind: options.wind ?? SNOWFALL_DEFAULTS.wind,
|
|
280
|
+
depth: options.depth ?? SNOWFALL_DEFAULTS.depth,
|
|
281
|
+
size: options.size ?? SNOWFALL_DEFAULTS.size,
|
|
282
|
+
color: options.color ?? SNOWFALL_DEFAULTS.color,
|
|
283
|
+
glow: options.glow ?? SNOWFALL_DEFAULTS.glow,
|
|
284
|
+
blend: options.blend ?? SNOWFALL_DEFAULTS.blend,
|
|
285
|
+
seed: options.seed ?? SNOWFALL_DEFAULTS.seed,
|
|
286
|
+
paused: options.paused ?? false,
|
|
287
|
+
reducedMotion: options.reducedMotion ?? false
|
|
288
|
+
};
|
|
289
|
+
let gpu = setup(context, live.seed);
|
|
290
|
+
if (!gpu) return null;
|
|
291
|
+
let destroyed = false;
|
|
292
|
+
let contextLost = false;
|
|
293
|
+
let frame = 0;
|
|
294
|
+
let last = 0;
|
|
295
|
+
let inView = true;
|
|
296
|
+
let pageVisible = typeof document === "undefined" || !document.hidden;
|
|
297
|
+
let time = 0;
|
|
298
|
+
let drift = 0;
|
|
299
|
+
function resize() {
|
|
300
|
+
const ratio = Math.min(
|
|
301
|
+
typeof window !== "undefined" && window.devicePixelRatio || 1,
|
|
302
|
+
MAX_PIXEL_RATIO
|
|
303
|
+
);
|
|
304
|
+
const width = Math.max(1, Math.round(canvas.clientWidth * ratio));
|
|
305
|
+
const height = Math.max(1, Math.round(canvas.clientHeight * ratio));
|
|
306
|
+
if (canvas.width === width && canvas.height === height) return;
|
|
307
|
+
canvas.width = width;
|
|
308
|
+
canvas.height = height;
|
|
309
|
+
}
|
|
310
|
+
function clamp01(value) {
|
|
311
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 0;
|
|
312
|
+
}
|
|
313
|
+
let pageBlend = null;
|
|
314
|
+
function draw() {
|
|
315
|
+
if (destroyed || contextLost || !gpu) return;
|
|
316
|
+
resize();
|
|
317
|
+
const u = gpu.uniforms;
|
|
318
|
+
const cssWidth = Math.max(1, canvas.clientWidth);
|
|
319
|
+
const cssHeight = Math.max(1, canvas.clientHeight);
|
|
320
|
+
const rgb = parseHexColor(live.color, [0.957, 0.969, 1]);
|
|
321
|
+
const wind = Math.max(-1, Math.min(1, Number.isFinite(live.wind) ? live.wind : 0));
|
|
322
|
+
const mode = resolveBlend(live.blend, rgb);
|
|
323
|
+
if (mode !== pageBlend) {
|
|
324
|
+
pageBlend = mode;
|
|
325
|
+
canvas.style.mixBlendMode = mode === "glow" ? "screen" : "";
|
|
326
|
+
}
|
|
327
|
+
if (mode === "glow") {
|
|
328
|
+
context.blendFuncSeparate(
|
|
329
|
+
context.ONE,
|
|
330
|
+
context.ONE_MINUS_SRC_COLOR,
|
|
331
|
+
context.ONE,
|
|
332
|
+
context.ONE_MINUS_SRC_ALPHA
|
|
333
|
+
);
|
|
334
|
+
} else {
|
|
335
|
+
context.blendFunc(context.ONE, context.ONE_MINUS_SRC_ALPHA);
|
|
336
|
+
}
|
|
337
|
+
context.viewport(0, 0, canvas.width, canvas.height);
|
|
338
|
+
context.clear(context.COLOR_BUFFER_BIT);
|
|
339
|
+
context.uniform2f(u.uView, cssWidth, cssHeight);
|
|
340
|
+
context.uniform1f(u.uPixelRatio, canvas.width / cssWidth);
|
|
341
|
+
context.uniform1f(u.uMaxPoint, gpu.maxPoint);
|
|
342
|
+
context.uniform1f(u.uTime, time);
|
|
343
|
+
context.uniform1f(u.uDrift, drift);
|
|
344
|
+
context.uniform1f(u.uGust, 14 + 26 * Math.abs(wind));
|
|
345
|
+
context.uniform1f(u.uCount, flakeCount(live.density, cssWidth, cssHeight));
|
|
346
|
+
context.uniform1f(u.uDepth, clamp01(live.depth));
|
|
347
|
+
context.uniform1f(u.uSize, Math.max(0, Number.isFinite(live.size) ? live.size : 1));
|
|
348
|
+
context.uniform1f(u.uGlow, clamp01(live.glow));
|
|
349
|
+
context.uniform3f(u.uColor, rgb[0], rgb[1], rgb[2]);
|
|
350
|
+
context.drawArrays(context.POINTS, 0, MAX_FLAKES);
|
|
351
|
+
}
|
|
352
|
+
function moving() {
|
|
353
|
+
return !live.paused && !live.reducedMotion;
|
|
354
|
+
}
|
|
355
|
+
function shouldRun() {
|
|
356
|
+
return !destroyed && !contextLost && inView && pageVisible && moving();
|
|
357
|
+
}
|
|
358
|
+
function tick(now) {
|
|
359
|
+
frame = 0;
|
|
360
|
+
if (destroyed) return;
|
|
361
|
+
const dt = last === 0 ? 0 : Math.min(Math.max((now - last) / 1e3, 0), MAX_STEP);
|
|
362
|
+
last = now;
|
|
363
|
+
if (moving()) {
|
|
364
|
+
const rate = Number.isFinite(live.speed) ? Math.max(0, live.speed) : 0;
|
|
365
|
+
const wind = Math.max(-1, Math.min(1, Number.isFinite(live.wind) ? live.wind : 0));
|
|
366
|
+
time += dt * rate;
|
|
367
|
+
drift += dt * rate * wind * WIND_SPEED;
|
|
368
|
+
}
|
|
369
|
+
draw();
|
|
370
|
+
if (shouldRun()) frame = requestAnimationFrame(tick);
|
|
371
|
+
else last = 0;
|
|
372
|
+
}
|
|
373
|
+
function wake() {
|
|
374
|
+
if (destroyed || frame !== 0) return;
|
|
375
|
+
if (shouldRun()) {
|
|
376
|
+
last = 0;
|
|
377
|
+
frame = requestAnimationFrame(tick);
|
|
378
|
+
} else {
|
|
379
|
+
draw();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
function releaseGpu() {
|
|
383
|
+
if (!gpu) return;
|
|
384
|
+
context.deleteBuffer(gpu.buffer);
|
|
385
|
+
context.deleteProgram(gpu.program);
|
|
386
|
+
gpu = null;
|
|
387
|
+
}
|
|
388
|
+
function onVisibility() {
|
|
389
|
+
pageVisible = !document.hidden;
|
|
390
|
+
wake();
|
|
391
|
+
}
|
|
392
|
+
function onContextLost(event) {
|
|
393
|
+
event.preventDefault();
|
|
394
|
+
contextLost = true;
|
|
395
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
396
|
+
frame = 0;
|
|
397
|
+
gpu = null;
|
|
398
|
+
}
|
|
399
|
+
function onContextRestored() {
|
|
400
|
+
if (destroyed) return;
|
|
401
|
+
contextLost = false;
|
|
402
|
+
gpu = setup(context, live.seed);
|
|
403
|
+
if (gpu) wake();
|
|
404
|
+
}
|
|
405
|
+
canvas.addEventListener("webglcontextlost", onContextLost, false);
|
|
406
|
+
canvas.addEventListener("webglcontextrestored", onContextRestored, false);
|
|
407
|
+
if (typeof document !== "undefined") {
|
|
408
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
409
|
+
}
|
|
410
|
+
let resizeObserver = null;
|
|
411
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
412
|
+
resizeObserver = new ResizeObserver(() => wake());
|
|
413
|
+
resizeObserver.observe(canvas);
|
|
414
|
+
}
|
|
415
|
+
let intersectionObserver = null;
|
|
416
|
+
if (typeof IntersectionObserver !== "undefined") {
|
|
417
|
+
intersectionObserver = new IntersectionObserver((entries) => {
|
|
418
|
+
for (const entry of entries) inView = entry.isIntersecting;
|
|
419
|
+
wake();
|
|
420
|
+
});
|
|
421
|
+
intersectionObserver.observe(canvas);
|
|
422
|
+
}
|
|
423
|
+
wake();
|
|
424
|
+
return {
|
|
425
|
+
setOptions(next) {
|
|
426
|
+
if (destroyed) return;
|
|
427
|
+
if (next.density !== void 0) live.density = next.density;
|
|
428
|
+
if (next.speed !== void 0) live.speed = next.speed;
|
|
429
|
+
if (next.wind !== void 0) live.wind = next.wind;
|
|
430
|
+
if (next.depth !== void 0) live.depth = next.depth;
|
|
431
|
+
if (next.size !== void 0) live.size = next.size;
|
|
432
|
+
if (next.color !== void 0) live.color = next.color;
|
|
433
|
+
if (next.glow !== void 0) live.glow = next.glow;
|
|
434
|
+
if (next.blend !== void 0) live.blend = next.blend;
|
|
435
|
+
if (next.paused !== void 0) live.paused = next.paused;
|
|
436
|
+
if (next.reducedMotion !== void 0) live.reducedMotion = next.reducedMotion;
|
|
437
|
+
if (next.seed !== void 0 && next.seed !== live.seed) {
|
|
438
|
+
live.seed = next.seed;
|
|
439
|
+
if (gpu && !contextLost) {
|
|
440
|
+
context.bindBuffer(context.ARRAY_BUFFER, gpu.buffer);
|
|
441
|
+
context.bufferData(context.ARRAY_BUFFER, buildFlakes(live.seed), context.STATIC_DRAW);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (frame === 0) wake();
|
|
445
|
+
},
|
|
446
|
+
getTime() {
|
|
447
|
+
return time;
|
|
448
|
+
},
|
|
449
|
+
destroy() {
|
|
450
|
+
if (destroyed) return;
|
|
451
|
+
destroyed = true;
|
|
452
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
453
|
+
frame = 0;
|
|
454
|
+
canvas.removeEventListener("webglcontextlost", onContextLost, false);
|
|
455
|
+
canvas.removeEventListener("webglcontextrestored", onContextRestored, false);
|
|
456
|
+
if (typeof document !== "undefined") {
|
|
457
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
458
|
+
}
|
|
459
|
+
resizeObserver?.disconnect();
|
|
460
|
+
intersectionObserver?.disconnect();
|
|
461
|
+
canvas.style.mixBlendMode = "";
|
|
462
|
+
if (!contextLost) releaseGpu();
|
|
463
|
+
if (releaseContext) context.getExtension("WEBGL_lose_context")?.loseContext();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
export {
|
|
468
|
+
FLOATS_PER_FLAKE,
|
|
469
|
+
FRAGMENT_SHADER,
|
|
470
|
+
MAX_FLAKES,
|
|
471
|
+
MAX_PIXEL_RATIO,
|
|
472
|
+
MAX_STEP,
|
|
473
|
+
SNOWFALL_DEFAULTS,
|
|
474
|
+
VERTEX_SHADER,
|
|
475
|
+
WIND_SPEED,
|
|
476
|
+
buildFlakes,
|
|
477
|
+
createSnowfall,
|
|
478
|
+
fallbackBackground,
|
|
479
|
+
flakeCount,
|
|
480
|
+
mulberry32,
|
|
481
|
+
parseHexColor,
|
|
482
|
+
resolveBlend
|
|
483
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineComponent, useTemplateRef, onMounted, onBeforeUnmount, watch, createElementBlock, openBlock, normalizeStyle, normalizeClass, unref, createElementVNode } from "vue";
|
|
2
2
|
import { cn } from "../../utils.js";
|
|
3
|
+
import { useReducedMotion } from "../../internals/motion/use-media-query.js";
|
|
3
4
|
import { createSparkles } from "./sparkles-core.js";
|
|
4
5
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
6
|
...{ name: "Sparkles", inheritAttrs: false },
|
|
@@ -18,11 +19,12 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
18
19
|
const canvasRef = useTemplateRef("canvasRef");
|
|
19
20
|
let engine = null;
|
|
20
21
|
let resizeObserver = null;
|
|
22
|
+
const reducedMotion = useReducedMotion();
|
|
21
23
|
onMounted(() => {
|
|
22
24
|
if (!canvasRef.value || !containerRef.value) return;
|
|
23
25
|
engine = createSparkles(
|
|
24
26
|
{ canvas: canvasRef.value, container: containerRef.value },
|
|
25
|
-
{ minSize: __props.minSize, maxSize: __props.maxSize, speed: __props.speed, particleDensity: __props.particleDensity, particleColor: __props.particleColor }
|
|
27
|
+
{ minSize: __props.minSize, maxSize: __props.maxSize, speed: __props.speed, particleDensity: __props.particleDensity, particleColor: __props.particleColor, reducedMotion: reducedMotion.value }
|
|
26
28
|
);
|
|
27
29
|
resizeObserver = new ResizeObserver(() => engine?.resize());
|
|
28
30
|
resizeObserver.observe(containerRef.value);
|
|
@@ -38,6 +40,13 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
38
40
|
(color) => engine?.setOptions({ particleColor: color }),
|
|
39
41
|
{ flush: "post" }
|
|
40
42
|
);
|
|
43
|
+
watch(
|
|
44
|
+
reducedMotion,
|
|
45
|
+
(next) => {
|
|
46
|
+
engine?.setOptions({ reducedMotion: next });
|
|
47
|
+
},
|
|
48
|
+
{ flush: "post" }
|
|
49
|
+
);
|
|
41
50
|
return (_ctx, _cache) => {
|
|
42
51
|
return openBlock(), createElementBlock("div", {
|
|
43
52
|
ref_key: "containerRef",
|
|
@@ -17,6 +17,12 @@ export interface SparklesInitOptions {
|
|
|
17
17
|
export interface SparklesLiveOptions {
|
|
18
18
|
/** Hex color (e.g. "#ffffff") or `currentColor` particles are filled with; re-read every frame. */
|
|
19
19
|
particleColor?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Reduced-motion preference, owned by the wrapper (the core never reads
|
|
22
|
+
* `matchMedia`). When true the engine paints one still frame and idles; a
|
|
23
|
+
* flip back to false resumes the drift.
|
|
24
|
+
*/
|
|
25
|
+
reducedMotion?: boolean;
|
|
20
26
|
}
|
|
21
27
|
export interface SparklesEngine {
|
|
22
28
|
setOptions(next: Partial<SparklesLiveOptions>): void;
|
|
@@ -42,6 +42,7 @@ function createSparkles(elements, options, random = Math.random) {
|
|
|
42
42
|
let particles = [];
|
|
43
43
|
let dpr = 1;
|
|
44
44
|
let rafId = 0;
|
|
45
|
+
let reducedMotion = options.reducedMotion ?? false;
|
|
45
46
|
let destroyed = false;
|
|
46
47
|
function resize() {
|
|
47
48
|
if (destroyed) return;
|
|
@@ -51,6 +52,7 @@ function createSparkles(elements, options, random = Math.random) {
|
|
|
51
52
|
canvas.height = rect.height * dpr;
|
|
52
53
|
ctx = canvas.getContext("2d");
|
|
53
54
|
if (ctx) ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
55
|
+
if (reducedMotion && rafId === 0 && particles.length > 0) updateAndDraw();
|
|
54
56
|
}
|
|
55
57
|
function generateParticles() {
|
|
56
58
|
particles = [];
|
|
@@ -93,19 +95,41 @@ function createSparkles(elements, options, random = Math.random) {
|
|
|
93
95
|
ctx.fillStyle = `${fill}${Math.floor(opacity * 255).toString(16).padStart(2, "0")}`;
|
|
94
96
|
ctx.fill();
|
|
95
97
|
}
|
|
98
|
+
if (reducedMotion) {
|
|
99
|
+
rafId = 0;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
96
102
|
rafId = requestAnimationFrame(updateAndDraw);
|
|
97
103
|
}
|
|
98
104
|
resize();
|
|
99
105
|
generateParticles();
|
|
100
|
-
|
|
106
|
+
if (reducedMotion) updateAndDraw();
|
|
107
|
+
else rafId = requestAnimationFrame(updateAndDraw);
|
|
108
|
+
const themeObserver = typeof MutationObserver !== "undefined" ? new MutationObserver(() => {
|
|
109
|
+
if (reducedMotion && rafId === 0 && CURRENT_COLOR.test(particleColor)) updateAndDraw();
|
|
110
|
+
}) : null;
|
|
111
|
+
themeObserver?.observe(document.documentElement, {
|
|
112
|
+
attributes: true,
|
|
113
|
+
attributeFilter: ["class"]
|
|
114
|
+
});
|
|
101
115
|
return {
|
|
102
116
|
setOptions(next) {
|
|
103
|
-
if (
|
|
117
|
+
if (destroyed) return;
|
|
118
|
+
const wasReduced = reducedMotion;
|
|
119
|
+
if (next.reducedMotion !== void 0) reducedMotion = next.reducedMotion;
|
|
120
|
+
if (next.particleColor !== void 0 && next.particleColor !== particleColor) {
|
|
121
|
+
particleColor = next.particleColor;
|
|
122
|
+
if (reducedMotion && rafId === 0) updateAndDraw();
|
|
123
|
+
}
|
|
124
|
+
if (wasReduced && !reducedMotion && rafId === 0) {
|
|
125
|
+
rafId = requestAnimationFrame(updateAndDraw);
|
|
126
|
+
}
|
|
104
127
|
},
|
|
105
128
|
resize,
|
|
106
129
|
destroy() {
|
|
107
130
|
if (destroyed) return;
|
|
108
131
|
destroyed = true;
|
|
132
|
+
themeObserver?.disconnect();
|
|
109
133
|
cancelAnimationFrame(rafId);
|
|
110
134
|
}
|
|
111
135
|
};
|
|
@@ -1,90 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let state = seed >>> 0;
|
|
7
|
-
return () => {
|
|
8
|
-
state = state + 1831565813 >>> 0;
|
|
9
|
-
let t = state;
|
|
10
|
-
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
11
|
-
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
12
|
-
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function generateStar(random, colors) {
|
|
16
|
-
const x = `${random() * 100}%`;
|
|
17
|
-
const y = `${random() * 100}%`;
|
|
18
|
-
const color = random() > 0.5 ? colors.first : colors.second;
|
|
19
|
-
const delay = random() * 2;
|
|
20
|
-
const scale = random() * 1 + 0.3;
|
|
21
|
-
const lifespan = random() * 10 + 5;
|
|
22
|
-
const id = `${x}-${y}-${random()}`;
|
|
23
|
-
return { id, x, y, color, delay, scale, lifespan };
|
|
24
|
-
}
|
|
25
|
-
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
26
|
-
...{ name: "SparklesText", inheritAttrs: false },
|
|
27
|
-
__name: "SparklesText",
|
|
28
|
-
props: {
|
|
29
|
-
text: {},
|
|
30
|
-
sparklesCount: { default: 10 },
|
|
31
|
-
colors: { default: () => ({ first: "#9E7AFF", second: "#FE8BBB" }) },
|
|
32
|
-
class: { type: [Boolean, null, String, Object, Array] },
|
|
33
|
-
seed: { default: 1 }
|
|
34
|
-
},
|
|
35
|
-
setup(__props) {
|
|
36
|
-
const initialRandom = mulberry32(__props.seed);
|
|
37
|
-
const sparkles = ref(
|
|
38
|
-
Array.from({ length: __props.sparklesCount }, () => generateStar(initialRandom, __props.colors))
|
|
39
|
-
);
|
|
40
|
-
let intervalId;
|
|
41
|
-
onMounted(() => {
|
|
42
|
-
const random = mulberry32(__props.seed + 1);
|
|
43
|
-
intervalId = setInterval(() => {
|
|
44
|
-
sparkles.value = sparkles.value.map((star) => {
|
|
45
|
-
if (star.lifespan <= 0) {
|
|
46
|
-
return generateStar(random, __props.colors);
|
|
47
|
-
}
|
|
48
|
-
return { ...star, lifespan: star.lifespan - 0.1 };
|
|
49
|
-
});
|
|
50
|
-
}, 100);
|
|
51
|
-
});
|
|
52
|
-
onBeforeUnmount(() => {
|
|
53
|
-
if (intervalId !== void 0) clearInterval(intervalId);
|
|
54
|
-
});
|
|
55
|
-
return (_ctx, _cache) => {
|
|
56
|
-
return openBlock(), createElementBlock("div", {
|
|
57
|
-
class: normalizeClass(unref(cn)("sparkles-text text-6xl font-bold", __props.class))
|
|
58
|
-
}, [
|
|
59
|
-
createElementVNode("span", _hoisted_1, [
|
|
60
|
-
(openBlock(true), createElementBlock(Fragment, null, renderList(sparkles.value, (sparkle) => {
|
|
61
|
-
return openBlock(), createElementBlock("svg", {
|
|
62
|
-
key: sparkle.id,
|
|
63
|
-
class: "sparkles-star pointer-events-none absolute z-20",
|
|
64
|
-
style: normalizeStyle({
|
|
65
|
-
left: sparkle.x,
|
|
66
|
-
top: sparkle.y,
|
|
67
|
-
"--sparkle-scale": `${sparkle.scale}`,
|
|
68
|
-
animation: `sparkleAnim 0.8s ease-in-out ${sparkle.delay}s infinite`,
|
|
69
|
-
transform: "scale(0) rotate(75deg)",
|
|
70
|
-
opacity: 0
|
|
71
|
-
}),
|
|
72
|
-
width: "21",
|
|
73
|
-
height: "21",
|
|
74
|
-
viewBox: "0 0 21 21"
|
|
75
|
-
}, [
|
|
76
|
-
createElementVNode("path", {
|
|
77
|
-
d: "M9.82531 0.843845C10.0553 0.215178 10.9446 0.215178 11.1746 0.843845L11.8618 2.72026C12.4006 4.19229 12.3916 6.39157 13.5 7.5C14.6084 8.60843 16.8077 8.59935 18.2797 9.13822L20.1561 9.82534C20.7858 10.0553 20.7858 10.9447 20.1561 11.1747L18.2797 11.8618C16.8077 12.4007 14.6084 12.3916 13.5 13.5C12.3916 14.6084 12.4006 16.8077 11.8618 18.2798L11.1746 20.1562C10.9446 20.7858 10.0553 20.7858 9.82531 20.1562L9.13819 18.2798C8.59932 16.8077 8.60843 14.6084 7.5 13.5C6.39157 12.3916 4.19225 12.4007 2.72023 11.8618L0.843814 11.1747C0.215148 10.9447 0.215148 10.0553 0.843814 9.82534L2.72023 9.13822C4.19225 8.59935 6.39157 8.60843 7.5 7.5C8.60843 6.39157 8.59932 4.19229 9.13819 2.72026L9.82531 0.843845Z",
|
|
78
|
-
fill: sparkle.color
|
|
79
|
-
}, null, 8, _hoisted_2)
|
|
80
|
-
], 4);
|
|
81
|
-
}), 128)),
|
|
82
|
-
createTextVNode(" " + toDisplayString(__props.text), 1)
|
|
83
|
-
])
|
|
84
|
-
], 2);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
});
|
|
1
|
+
import _sfc_main from "./SparklesText.vue2.js";
|
|
2
|
+
/* empty css */
|
|
3
|
+
/* empty css */
|
|
4
|
+
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.js";
|
|
5
|
+
const SparklesText = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-f06a1c48"]]);
|
|
88
6
|
export {
|
|
89
|
-
|
|
7
|
+
SparklesText as default
|
|
90
8
|
};
|