@@ -3,14 +3,20 @@ local easing_functions = require("tiny-glimmer.animation.easing")
3
3
local Effect = require (" tiny-glimmer.animation.effect" )
4
4
5
5
local function create_effect (opts )
6
- return Effect .new ({}, opts .update_fn )
6
+ return Effect .new ({}, opts .update_fn , opts . builder )
7
7
end
8
8
9
9
return {
10
10
fade = create_effect ({
11
+ builder = function (self )
12
+ return {
13
+ initial = utils .hex_to_rgb (self .settings .from_color ),
14
+ final = utils .hex_to_rgb (self .settings .to_color ),
15
+ }
16
+ end ,
11
17
update_fn = function (self , progress , ease )
12
- local initial = utils . hex_to_rgb ( self .settings . from_color )
13
- local final = utils . hex_to_rgb ( self .settings . to_color )
18
+ local initial = self .starter . initial
19
+ local final = self .starter . final
14
20
local current = {}
15
21
16
22
local fn = easing_functions [ease ]
@@ -25,9 +31,15 @@ return {
25
31
end ,
26
32
}),
27
33
reverse_fade = create_effect ({
34
+ builder = function (self )
35
+ return {
36
+ initial = utils .hex_to_rgb (self .settings .from_color ),
37
+ final = utils .hex_to_rgb (self .settings .to_color ),
38
+ }
39
+ end ,
28
40
update_fn = function (self , progress , ease )
29
- local initial = utils . hex_to_rgb ( self .settings . from_color )
30
- local final = utils . hex_to_rgb ( self .settings . to_color )
41
+ local initial = self .starter . initial
42
+ local final = self .starter . final
31
43
32
44
local fn = easing_functions [ease ]
33
45
@@ -41,11 +53,16 @@ return {
41
53
end ,
42
54
}),
43
55
bounce = create_effect ({
56
+ builder = function (self )
57
+ return {
58
+ initial = utils .hex_to_rgb (self .settings .from_color ),
59
+ final = utils .hex_to_rgb (self .settings .to_color ),
60
+ }
61
+ end ,
44
62
update_fn = function (self , progress )
45
63
local oscillation = math.abs (math.sin (progress * math.pi * self .settings .oscillation_count ))
46
-
47
- local initial = utils .hex_to_rgb (self .settings .from_color )
48
- local final = utils .hex_to_rgb (self .settings .to_color )
64
+ local initial = self .starter .initial
65
+ local final = self .starter .final
49
66
50
67
local current = {
51
68
r = math.max (initial .r + (final .r - initial .r ) * oscillation , 0 ),
@@ -57,9 +74,15 @@ return {
57
74
end ,
58
75
}),
59
76
left_to_right = create_effect ({
77
+ builder = function (self )
78
+ return {
79
+ initial = utils .hex_to_rgb (self .settings .from_color ),
80
+ final = utils .hex_to_rgb (self .settings .to_color ),
81
+ }
82
+ end ,
60
83
update_fn = function (self , progress )
61
- local initial = utils . hex_to_rgb ( self .settings . from_color )
62
- local final = utils . hex_to_rgb ( self .settings . to_color )
84
+ local initial = self .starter . initial
85
+ local final = self .starter . final
63
86
64
87
local current = {
65
88
r = initial .r + (final .r - initial .r ) * math.min (self .settings .min_progress , progress ),
@@ -71,9 +94,15 @@ return {
71
94
end ,
72
95
}),
73
96
pulse = create_effect ({
97
+ builder = function (self )
98
+ return {
99
+ initial = utils .hex_to_rgb (self .settings .from_color ),
100
+ final = utils .hex_to_rgb (self .settings .to_color ),
101
+ }
102
+ end ,
74
103
update_fn = function (self , progress )
75
- local initial = utils . hex_to_rgb ( self .settings . from_color )
76
- local final = utils . hex_to_rgb ( self .settings . to_color )
104
+ local initial = self .starter . initial
105
+ local final = self .starter . final
77
106
78
107
local pulse = math.abs (math.sin (progress * math.pi * self .settings .pulse_count ))
79
108
pulse = pulse * self .settings .intensity
0 commit comments