Skip to content

Commit 61cdce2

Browse files
Que-tinsaitheninja
authored andcommitted
[add] Reduced media handling for animations
[add] Dynamic reduced animations [add] Local reference for the blink animation values
1 parent af89ad9 commit 61cdce2

File tree

2 files changed

+136
-19
lines changed

2 files changed

+136
-19
lines changed

build/to-stylesheet.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,37 @@ ${dark_propsMeta}
5353
})
5454

5555
if (filename.includes('animations')) {
56-
let dark_props = Object.entries(props)
57-
.filter(([prop, val]) =>
58-
prop.includes('-@media:dark'))
5956

60-
dark_props.forEach(([prop, val], index) => {
61-
let hasDarkKeyframe = prop.endsWith('-@media:dark') && val.trim().startsWith('@keyframe')
62-
if (hasDarkKeyframe) {
63-
appendedMeta += `
64-
@media (--OSdark) {
65-
${val.trim().replace(/\n/g, '\n ')};
66-
}`
57+
const [
58+
dark_props,
59+
reduced_props,
60+
] = Object.entries(props).reduce((acc, prop) => {
61+
const [key, val] = prop;
62+
63+
if (val.trim().startsWith('@keyframe')) {
64+
const _val = val.trim().replace(/\n/g, '\n ');
65+
key.endsWith('-@media:dark') && acc[0].push([key, _val]);
66+
key.endsWith('-@media:reduced') && acc[1].push([key, _val]);
6767
}
68+
69+
return acc;
70+
}, [[], []])
71+
72+
73+
dark_props.forEach(([_, val]) => {
74+
appendedMeta += `
75+
@media (--OSdark) {
76+
${val};
77+
}
78+
`
79+
})
80+
81+
reduced_props.forEach(([_, val]) => {
82+
appendedMeta += `
83+
@media (--motionNotOK) {
84+
${val};
85+
}
86+
`
6887
})
6988
}
7089

src/props.animations.js

Lines changed: 107 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const LOCAL_REFERENCES = {
2+
"--animation-blink-@": `0%, 100% { opacity: 1 }
3+
50% { opacity: .5 }`
4+
};
5+
16
export default {
27
"--animation-fade-in": "fade-in .5s var(--ease-3)",
38
"--animation-fade-in-@": `
@@ -39,51 +44,121 @@ export default {
3944
"--animation-scale-up-@": `
4045
@keyframes scale-up {
4146
to { transform: scale(1.25) }
47+
}`,
48+
"--animation-scale-up-@media:reduced": `
49+
@keyframes scale-up {
50+
0% { opacity: 1; }
51+
50% { opacity: 0; transform: scale(1); }
52+
50.01% { transform: scale(1.25); }
53+
100% { opacity: 1; transform: scale(1.25); }
4254
}`,
4355
"--animation-scale-down": "scale-down .5s var(--ease-3)",
4456
"--animation-scale-down-@": `
4557
@keyframes scale-down {
4658
to { transform: scale(.75) }
59+
}`,
60+
"--animation-scale-down-@media:reduced": `
61+
@keyframes scale-down {
62+
0% { opacity: 1; }
63+
50% { opacity: 0; transform: scale(1); }
64+
50.01% { transform: scale(.75); }
65+
100% { opacity: 1; transform: scale(.75); }
4766
}`,
4867
"--animation-slide-out-up": "slide-out-up .5s var(--ease-3)",
4968
"--animation-slide-out-up-@": `
5069
@keyframes slide-out-up {
5170
to { transform: translateY(-100%) }
71+
}`,
72+
"--animation-slide-out-up-@media:reduced": `
73+
@keyframes slide-out-up {
74+
0% { opacity: 1; }
75+
50% { opacity: 0; transform: translateY(0%); }
76+
50.01% { transform: translateY(-100%); }
77+
100% { opacity: 1; transform: translateY(-100%); }
5278
}`,
5379
"--animation-slide-out-down": "slide-out-down .5s var(--ease-3)",
5480
"--animation-slide-out-down-@": `
5581
@keyframes slide-out-down {
5682
to { transform: translateY(100%) }
83+
}`,
84+
"--animation-slide-out-down-@media:reduced": `
85+
@keyframes slide-out-down {
86+
0% { opacity: 1; }
87+
50% { opacity: 0; transform: translateY(0%); }
88+
50.01% { transform: translateY(100%); }
89+
100% { opacity: 1; transform: translateY(100%); }
5790
}`,
5891
"--animation-slide-out-right": "slide-out-right .5s var(--ease-3)",
5992
"--animation-slide-out-right-@": `
6093
@keyframes slide-out-right {
6194
to { transform: translateX(100%) }
95+
}`,
96+
"--animation-slide-out-right-@media:reduced": `
97+
@keyframes slide-out-right {
98+
0% { opacity: 1; }
99+
50% { opacity: 0; transform: translateX(0%); }
100+
50.01% { transform: translateX(100%); }
101+
100% { opacity: 1; transform: translateX(100%); }
62102
}`,
63103
"--animation-slide-out-left": "slide-out-left .5s var(--ease-3)",
64104
"--animation-slide-out-left-@": `
65105
@keyframes slide-out-left {
66106
to { transform: translateX(-100%) }
107+
}`,
108+
"--animation-slide-out-left-@media:reduced": `
109+
@keyframes slide-out-left {
110+
0% { opacity: 1; }
111+
50% { opacity: 0; transform: translateX(0%); }
112+
50.01% { transform: translateX(-100%); }
113+
100% { opacity: 1; transform: translateX(-100%); }
67114
}`,
68115
"--animation-slide-in-up": "slide-in-up .5s var(--ease-3)",
69116
"--animation-slide-in-up-@": `
70117
@keyframes slide-in-up {
71118
from { transform: translateY(100%) }
119+
}`,
120+
"--animation-slide-in-up-@media:reduced": `
121+
@keyframes slide-in-up {
122+
0% { opacity: 1; transform: translateY(100%); }
123+
50% { opacity: 0; transform: translateY(100%); }
124+
50.01% { transform: translateY(0%); }
125+
100% { opacity: 1; transform: translateY(0%); }
72126
}`,
73127
"--animation-slide-in-down": "slide-in-down .5s var(--ease-3)",
74128
"--animation-slide-in-down-@": `
75129
@keyframes slide-in-down {
76130
from { transform: translateY(-100%) }
131+
}`,
132+
"--animation-slide-in-down-@media:reduced": `
133+
@keyframes slide-in-down {
134+
0% { opacity: 1; transform: translateY(-100%); }
135+
50% { opacity: 0; transform: translateY(-100%); }
136+
50.01% { transform: translateY(0%); }
137+
100% { opacity: 1; transform: translateY(0%); }
77138
}`,
78139
"--animation-slide-in-right": "slide-in-right .5s var(--ease-3)",
79140
"--animation-slide-in-right-@": `
80141
@keyframes slide-in-right {
81142
from { transform: translateX(-100%) }
143+
}`,
144+
"--animation-slide-in-right-@media:reduced": `
145+
@keyframes slide-in-right {
146+
0% { opacity: 1; transform: translateX(-100%); }
147+
50% { opacity: 0; transform: translateX(-100%); }
148+
50.01% { transform: translateX(0%); }
149+
100% { opacity: 1; transform: translateX(0%); }
82150
}`,
83151
"--animation-slide-in-left": "slide-in-left .5s var(--ease-3)",
84152
"--animation-slide-in-left-@": `
85153
@keyframes slide-in-left {
86154
from { transform: translateX(100%) }
155+
}`,
156+
"--animation-slide-in-left-@media:reduced": `
157+
@keyframes slide-in-left {
158+
0% { opacity: 1; transform: translateX(100%); }
159+
50% { opacity: 0; transform: translateX(100%); }
160+
50.01% { transform: translateX(0%); }
161+
100% { opacity: 1; transform: translateX(0%); }
87162
}`,
88163
"--animation-shake-x": "shake-x .75s var(--ease-out-5)",
89164
"--animation-shake-x-@": `
@@ -93,6 +168,10 @@ export default {
93168
40% { transform: translateX(5%) }
94169
60% { transform: translateX(-5%) }
95170
80% { transform: translateX(5%) }
171+
}`,
172+
"--animation-shake-x-@media:reduced": `
173+
@keyframes shake-x {
174+
${LOCAL_REFERENCES['--animation-blink-@']}
96175
}`,
97176
"--animation-shake-y": "shake-y .75s var(--ease-out-5)",
98177
"--animation-shake-y-@": `
@@ -102,11 +181,19 @@ export default {
102181
40% { transform: translateY(5%) }
103182
60% { transform: translateY(-5%) }
104183
80% { transform: translateY(5%) }
184+
}`,
185+
"--animation-shake-y-@media:reduced": `
186+
@keyframes shake-y {
187+
${LOCAL_REFERENCES['--animation-blink-@']}
105188
}`,
106189
"--animation-spin": "spin 2s linear infinite",
107190
"--animation-spin-@": `
108191
@keyframes spin {
109192
to { transform: rotate(1turn) }
193+
}`,
194+
"--animation-spin-@media:reduced": `
195+
@keyframes spin {
196+
${LOCAL_REFERENCES['--animation-blink-@']}
110197
}`,
111198
"--animation-ping": "ping 5s var(--ease-out-3) infinite",
112199
"--animation-ping-@": `
@@ -116,31 +203,42 @@ export default {
116203
opacity: 0;
117204
}
118205
}`,
119-
"--animation-blink": "blink 1s var(--ease-out-3) infinite",
120-
"--animation-blink-@": `
121-
@keyframes blink {
122-
0%, 100% {
123-
opacity: 1
124-
}
125-
50% {
126-
opacity: .5
127-
}
206+
"--animation-ping-@media:reduced": `
207+
@keyframes ping {
208+
${LOCAL_REFERENCES['--animation-blink-@']}
128209
}`,
210+
"--animation-blink": "blink 1s var(--ease-out-3) infinite",
211+
"--animation-blink-@": `
212+
@keyframes blink {
213+
${LOCAL_REFERENCES['--animation-blink-@']}
214+
}`,
129215
"--animation-float": "float 3s var(--ease-in-out-3) infinite",
130216
"--animation-float-@": `
131217
@keyframes float {
132218
50% { transform: translateY(-25%) }
219+
}`,
220+
"--animation-float-@media:reduced": `
221+
@keyframes float {
222+
${LOCAL_REFERENCES['--animation-blink-@']}
133223
}`,
134224
"--animation-bounce": "bounce 2s var(--ease-squish-2) infinite",
135225
"--animation-bounce-@": `
136226
@keyframes bounce {
137227
25% { transform: translateY(-20%) }
138228
40% { transform: translateY(-3%) }
139229
0%, 60%, 100% { transform: translateY(0) }
230+
}`,
231+
"--animation-bounce-@media:reduced": `
232+
@keyframes bounce {
233+
${LOCAL_REFERENCES['--animation-blink-@']}
140234
}`,
141235
"--animation-pulse": "pulse 2s var(--ease-out-3) infinite",
142236
"--animation-pulse-@": `
143237
@keyframes pulse {
144238
50% { transform: scale(.9,.9) }
145239
}`,
240+
"--animation-pulse-@media:reduced": `
241+
@keyframes pulse {
242+
${LOCAL_REFERENCES['--animation-blink-@']}
243+
}`,
146244
}

0 commit comments

Comments
 (0)