-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.svelte
118 lines (102 loc) · 2.2 KB
/
demo.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<script>
import eases from "eases";
import lerp from "./src/index";
// props
let stepsCount = 30;
let colors = ["#41bbe9", "#b710da", "#fd8978"];
const updateColor = i => e => {
colors[i] = e.target.value;
};
let easing = "linear";
$: getColor = n =>
lerp(...colors, Math.max(0, Math.min(1, eases[easing](n))));
$: steps = Array.from({ length: stepsCount }, (_, i) =>
getColor(i / (stepsCount - 1))
);
const linkText = "@sunify/lerp-color";
const linkChars = linkText.split("");
</script>
<style>
:global(html) {
font-family: Arial, Helvetica, sans-serif;
}
:global(body) {
padding: 4vh 10vw;
text-align: center;
}
a {
text-decoration: none;
}
h1 {
font-size: 50px;
margin-bottom: 50px;
display: inline-block;
background-color: #ffffff;
padding: 20px;
}
h1 a {
background-repeat: no-repeat;
background-size: 100% 4px;
background-position: 0 100%;
}
.steps {
position: absolute;
z-index: -1;
left: 0;
top: 0;
width: 100.5vw;
height: 100%;
display: flex;
}
.steps div {
flex: 1;
}
.pickers {
display: flex;
justify-content: space-between;
}
.controls {
display: flex;
flex-direction: column;
align-items: center;
padding: 100px;
}
.controls input[type="range"] {
margin-bottom: 30px;
width: 50%;
}
</style>
<h1>
<a
href="https://github.com/sunify/lerp-color"
style="background-image: linear-gradient(to right, {colors.join(', ')})">
{#each linkChars as char, i}
<span style="color: {lerp(...colors, i / (linkChars.length - 1))}">
{char}
</span>
{/each}
</a>
demo
</h1>
<div class="pickers">
{#each colors as color, i}
<input
type="color"
class="color-input"
value={color}
on:change={updateColor(i)} />
{/each}
</div>
<div class="controls">
<input type="range" min="3" max="300" bind:value={stepsCount} />
<select bind:value={easing}>
{#each Object.keys(eases) as easing}
<option value={easing}>{easing}</option>
{/each}
</select>
</div>
<div class="steps" id="steps">
{#each steps as step}
<div style="background-color: {step}" />
{/each}
</div>