|
1 | 1 | <template>
|
2 |
| - <div |
3 |
| - ref="containerRef" |
4 |
| - :class="[ |
5 |
| - 'w-full h-full relative pointer-events-none z-[3] overflow-hidden', |
6 |
| - className |
7 |
| - ]" |
8 |
| - /> |
| 2 | + <div ref="containerRef" :class="['w-full h-full relative pointer-events-none z-[3] overflow-hidden', className]" /> |
9 | 3 | </template>
|
10 | 4 |
|
11 | 5 | <script setup lang="ts">
|
@@ -96,18 +90,12 @@ const observerRef = ref<IntersectionObserver | null>(null);
|
96 | 90 | const resizeTimeoutRef = ref<number | null>(null);
|
97 | 91 |
|
98 | 92 | const rgbColor = computed<[number, number, number]>(() => hexToRgb(props.raysColor));
|
99 |
| -const pulsatingValue = computed<number>(() => props.pulsating ? 1.0 : 0.0); |
| 93 | +const pulsatingValue = computed<number>(() => (props.pulsating ? 1.0 : 0.0)); |
100 | 94 | const devicePixelRatio = computed<number>(() => Math.min(window.devicePixelRatio || 1, 2));
|
101 | 95 |
|
102 | 96 | const hexToRgb = (hex: string): [number, number, number] => {
|
103 | 97 | const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
104 |
| - return m |
105 |
| - ? [ |
106 |
| - parseInt(m[1], 16) / 255, |
107 |
| - parseInt(m[2], 16) / 255, |
108 |
| - parseInt(m[3], 16) / 255, |
109 |
| - ] |
110 |
| - : [1, 1, 1]; |
| 98 | + return m ? [parseInt(m[1], 16) / 255, parseInt(m[2], 16) / 255, parseInt(m[3], 16) / 255] : [1, 1, 1]; |
111 | 99 | };
|
112 | 100 |
|
113 | 101 | const getAnchorAndDir = (origin: RaysOrigin, w: number, h: number): AnchorAndDirection => {
|
@@ -288,15 +276,15 @@ const initializeWebGL = async (): Promise<void> => {
|
288 | 276 | mousePos: { value: [0.5, 0.5] },
|
289 | 277 | mouseInfluence: { value: props.mouseInfluence },
|
290 | 278 | noiseAmount: { value: props.noiseAmount },
|
291 |
| - distortion: { value: props.distortion }, |
| 279 | + distortion: { value: props.distortion } |
292 | 280 | };
|
293 | 281 | uniformsRef.value = uniforms;
|
294 | 282 |
|
295 | 283 | const geometry = new Triangle(gl);
|
296 | 284 | const program = new Program(gl, {
|
297 | 285 | vertex: vertexShader,
|
298 | 286 | fragment: fragmentShader,
|
299 |
| - uniforms, |
| 287 | + uniforms |
300 | 288 | });
|
301 | 289 | const mesh = new Mesh(gl, { geometry, program });
|
302 | 290 | meshRef.value = mesh;
|
@@ -330,17 +318,10 @@ const initializeWebGL = async (): Promise<void> => {
|
330 | 318 | if (props.followMouse && props.mouseInfluence > 0.0) {
|
331 | 319 | const smoothing = 0.92;
|
332 | 320 |
|
333 |
| - smoothMouseRef.value.x = |
334 |
| - smoothMouseRef.value.x * smoothing + |
335 |
| - mouseRef.value.x * (1 - smoothing); |
336 |
| - smoothMouseRef.value.y = |
337 |
| - smoothMouseRef.value.y * smoothing + |
338 |
| - mouseRef.value.y * (1 - smoothing); |
339 |
| -
|
340 |
| - uniforms.mousePos.value = [ |
341 |
| - smoothMouseRef.value.x, |
342 |
| - smoothMouseRef.value.y, |
343 |
| - ]; |
| 321 | + smoothMouseRef.value.x = smoothMouseRef.value.x * smoothing + mouseRef.value.x * (1 - smoothing); |
| 322 | + smoothMouseRef.value.y = smoothMouseRef.value.y * smoothing + mouseRef.value.y * (1 - smoothing); |
| 323 | +
|
| 324 | + uniforms.mousePos.value = [smoothMouseRef.value.x, smoothMouseRef.value.y]; |
344 | 325 | }
|
345 | 326 |
|
346 | 327 | try {
|
@@ -376,8 +357,7 @@ const initializeWebGL = async (): Promise<void> => {
|
376 | 357 | if (renderer) {
|
377 | 358 | try {
|
378 | 359 | const canvas = renderer.gl.canvas;
|
379 |
| - const loseContextExt = |
380 |
| - renderer.gl.getExtension('WEBGL_lose_context'); |
| 360 | + const loseContextExt = renderer.gl.getExtension('WEBGL_lose_context'); |
381 | 361 | if (loseContextExt) {
|
382 | 362 | loseContextExt.loseContext();
|
383 | 363 | }
|
@@ -460,7 +440,7 @@ watch(
|
460 | 440 | () => props.saturation,
|
461 | 441 | () => props.mouseInfluence,
|
462 | 442 | () => props.noiseAmount,
|
463 |
| - () => props.distortion, |
| 443 | + () => props.distortion |
464 | 444 | ],
|
465 | 445 | (): void => {
|
466 | 446 | if (!uniformsRef.value || !containerRef.value || !rendererRef.value) return;
|
|
0 commit comments