|
| 1 | +<script lang="ts"> |
| 2 | +import type { SpinnerTypes } from './types/spinner.type'; |
| 3 | +import { range, durationUnitRegex, calculateRgba } from './utils'; |
| 4 | +export let color: SpinnerTypes['color'] = '#FF3E00'; |
| 5 | +export let unit: SpinnerTypes['unit'] = 'px'; |
| 6 | +export let duration: SpinnerTypes['duration'] = '1s'; |
| 7 | +export let size: SpinnerTypes['size'] = '60'; |
| 8 | +export let pause: SpinnerTypes['pause'] = false; |
| 9 | +let durationUnit: string = duration.match(durationUnitRegex)?.[0] ?? 's'; |
| 10 | +let durationNum: string = duration.replace(durationUnitRegex, ''); |
| 11 | +let rgba: string; |
| 12 | +$: rgba = calculateRgba(color, 1); |
| 13 | +</script> |
| 14 | + |
| 15 | +<span |
| 16 | +class="wrapper" |
| 17 | +style="--size: {size}{unit}; --color: {color}; --rgba: {rgba}; --duration: {duration}" |
| 18 | +> |
| 19 | +{#each range(2, 1) as version} |
| 20 | +<span |
| 21 | +class="circle" |
| 22 | +class:pause-animation={pause} |
| 23 | +style="animation-delay: {version === 1 ? '-1s' : '0s'}; animation-duration: {2 / |
| 24 | ++durationNum + |
| 25 | +durationUnit};" |
| 26 | +/> |
| 27 | +{/each} |
| 28 | +</span> |
| 29 | + |
| 30 | +<style> |
| 31 | +.wrapper { |
| 32 | +display: inherit; |
| 33 | +position: relative; |
| 34 | +width: var(--size); |
| 35 | +height: var(--size); |
| 36 | +} |
| 37 | +.circle { |
| 38 | +position: absolute; |
| 39 | +width: var(--size); |
| 40 | +height: var(--size); |
| 41 | +border: thick solid var(--rgba); |
| 42 | +border-radius: 50%; |
| 43 | +opacity: 1; |
| 44 | +top: 0px; |
| 45 | +left: 0px; |
| 46 | +animation-fill-mode: both; |
| 47 | +animation-iteration-count: infinite; |
| 48 | +animation-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1), cubic-bezier(0.3, 0.61, 0.355, 1); |
| 49 | +animation-direction: normal, normal; |
| 50 | +animation-fill-mode: none, none; |
| 51 | +animation-play-state: running, running; |
| 52 | +animation-name: puff-1, puff-2; |
| 53 | +box-sizing: border-box; |
| 54 | +} |
| 55 | +.pause-animation { |
| 56 | +animation-play-state: paused; |
| 57 | +} |
| 58 | +@keyframes puff-1 { |
| 59 | +0% { |
| 60 | +transform: scale(0); |
| 61 | +} |
| 62 | +100% { |
| 63 | +transform: scale(1); |
| 64 | +} |
| 65 | +} |
| 66 | +@keyframes puff-2 { |
| 67 | +0% { |
| 68 | +opacity: 1; |
| 69 | +} |
| 70 | +100% { |
| 71 | +opacity: 0; |
| 72 | +} |
| 73 | +} |
| 74 | +</style> |
0 commit comments