|
1 | 1 | <script lang="ts"> |
2 | | - import { onMount } from 'svelte'; |
3 | 2 | import { Tween } from 'svelte/motion'; |
| 3 | + import { onMount } from 'svelte'; |
4 | 4 |
|
5 | 5 | import progressStore from './progress.store'; |
6 | 6 |
|
7 | 7 | const { middleProgress, peopleCount: currentPeopleCount, progress, targetProgress } = $props(); |
8 | | - let currentProgressTween = new Tween<number>(progress); |
| 8 | + let currentProgressTween; |
| 9 | + if (typeof requestAnimationFrame === 'undefined') { |
| 10 | + currentProgressTween = { |
| 11 | + set: () => {}, |
| 12 | + subscribe: () => {}, |
| 13 | + current: progress, |
| 14 | + target: progress, |
| 15 | + }; |
| 16 | + } else { |
| 17 | + currentProgressTween = new Tween<number>(progress); |
| 18 | + } |
9 | 19 | let peopleCount = $state(currentPeopleCount); |
10 | 20 | let currentProgress = $derived(Math.round(currentProgressTween.current)); |
11 | | - onMount(() => { |
12 | | - currentProgressTween.set(progress, { duration: 0 }); |
13 | | - progressStore.update((v) => ({ ...v, amount: progress })); |
14 | | - }); |
15 | | - progressStore.subscribe((v) => { |
16 | | - (currentProgressTween.target = v.amount), (peopleCount = v.people); |
17 | | - }); |
18 | 21 | let waveOffset = $state(0); |
19 | 22 |
|
20 | 23 | let finished = $derived(currentProgress >= targetProgress); |
|
33 | 36 | return; |
34 | 37 | } |
35 | 38 | // No animation during server rendering |
36 | | - if (requestAnimationFrame != null) { |
| 39 | + if (typeof requestAnimationFrame === 'undefined') { |
37 | 40 | return; |
38 | 41 | } |
| 42 | +
|
| 43 | + currentProgressTween.set(progress, { duration: 0 }); |
| 44 | + progressStore.update((v) => ({ ...v, amount: progress })); |
| 45 | + progressStore.subscribe((v) => { |
| 46 | + (currentProgressTween.target = v.amount), (peopleCount = v.people); |
| 47 | + }); |
| 48 | +
|
39 | 49 | let animationFrame: number; |
40 | 50 |
|
41 | 51 | const animateWave = (timestamp: number) => { |
|
0 commit comments