<script lang="ts">
	export let content: string;
	const words = content.split(' ');
	export let delay = 0;
	const delays: number[] = [];
	let total = delay;
	for (let i = 0; i < words.length; i++) {
		const delay = total + words[i].length * 35;
		total = delay;
		delays.push(delay);
	}
</script>

<div class="wrapper">
	{#each words as word, i}
		<span class="word" style="--delay:{2000 + delays[i]}ms">{word}</span>
	{/each}
</div>

<style>
	.wrapper {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-wrap: wrap;
		width: 100%;
	}

	.word {
		opacity: 0;
		margin: 0 0.1em;
		animation: fadeIn 1s ease forwards;
		animation-delay: var(--delay);
		color: white;
	}
	@keyframes fadeIn {
		from {
			opacity: 0;
		}
		to {
			opacity: 1;
		}
	}
</style>
