| 1183 | * @returns A class name string to append to the result of `style()`. |
| 1184 | */ |
| 1185 | export function scrollFade(this: MacroContext | void, options: ScrollFadeOptions) { |
| 1186 | let {x = 0, y = 0, top = y, bottom = y, start = x, end = x, inset = 0} = options; |
| 1187 | |
| 1188 | let blockMask = '', |
| 1189 | inlineMask = ''; |
| 1190 | |
| 1191 | if (top || bottom) { |
| 1192 | blockMask = `linear-gradient( |
| 1193 | to bottom, |
| 1194 | transparent 0px ${inset > 0 ? `calc(var(--scroll-fade-top, ${inset}px) - ${top}px)` : ''}, |
| 1195 | black var(--scroll-fade-top, ${inset}px), |
| 1196 | black var(--scroll-fade-bottom, calc(100% - ${bottom}px)), |
| 1197 | transparent ${inset > 0 ? `calc(var(--scroll-fade-bottom, 100%) + ${inset}px)` : ''} 100% |
| 1198 | )`; |
| 1199 | } |
| 1200 | |
| 1201 | if (start || end) { |
| 1202 | inlineMask = `linear-gradient( |
| 1203 | to right, |
| 1204 | transparent 0px calc(var(--scroll-fade-left, var(--scroll-fade-left-edge)) - var(--scroll-fade-left-size)), |
| 1205 | black var(--scroll-fade-left, var(--scroll-fade-left-edge)), |
| 1206 | black var(--scroll-fade-right, calc(100% - var(--scroll-fade-right-edge))), |
| 1207 | transparent calc(var(--scroll-fade-right, calc(100% - var(--scroll-fade-right-edge))) + var(--scroll-fade-right-size)) 100% |
| 1208 | )`; |
| 1209 | } |
| 1210 | |
| 1211 | let topAnimation = scrollFadeKeyframes.call( |
| 1212 | this, |
| 1213 | 'top', |
| 1214 | '0px', |
| 1215 | top ? `${top + inset}px` : '', |
| 1216 | '0px' |
| 1217 | ); |
| 1218 | let bottomAnimation = scrollFadeKeyframes.call( |
| 1219 | this, |
| 1220 | 'bottom', |
| 1221 | bottom ? `calc(100% - ${bottom + inset}px)` : '', |
| 1222 | '100%', |
| 1223 | '100%' |
| 1224 | ); |
| 1225 | let leftAnimation = scrollFadeKeyframes.call( |
| 1226 | this, |
| 1227 | 'left', |
| 1228 | '0px', |
| 1229 | start || end ? 'var(--scroll-fade-left-edge)' : '', |
| 1230 | '0px' |
| 1231 | ); |
| 1232 | let rightAnimation = scrollFadeKeyframes.call( |
| 1233 | this, |
| 1234 | 'right', |
| 1235 | start || end ? 'calc(100% - var(--scroll-fade-right-edge))' : '', |
| 1236 | '100%', |
| 1237 | '100%' |
| 1238 | ); |
| 1239 | let animations = [ |
| 1240 | {name: topAnimation, timeline: 'scroll(self y)', range: `0px ${top}px`, rtlDirection: 'normal'}, |
| 1241 | { |
| 1242 | name: bottomAnimation, |