216 lines
7.3 KiB
CSS
216 lines
7.3 KiB
CSS
/* Adapted from HeroUI ce90ea3, Apache-2.0. See third-party/HEROUI-LICENSE. */
|
|
/* Base scroll-shadow component */
|
|
.hv-scroll-shadow {
|
|
@apply relative;
|
|
--scroll-shadow-size: 40px;
|
|
--scroll-shadow-scrollbar-size: 10px;
|
|
--scroll-shadow-offset: 0px;
|
|
}
|
|
|
|
/* Fade sizes for the scroll-driven variant below. They stay at 0px whenever the scroll
|
|
timeline is inactive, which is exactly the state of a container without overflow. */
|
|
@property --scroll-shadow-start-fade {
|
|
syntax: "<length>";
|
|
inherits: false;
|
|
initial-value: 0px;
|
|
}
|
|
|
|
@property --scroll-shadow-end-fade {
|
|
syntax: "<length>";
|
|
inherits: false;
|
|
initial-value: 0px;
|
|
}
|
|
|
|
@keyframes hv-scroll-shadow-start-fade {
|
|
from {
|
|
--scroll-shadow-start-fade: 0px;
|
|
}
|
|
to {
|
|
--scroll-shadow-start-fade: var(--scroll-shadow-size);
|
|
}
|
|
}
|
|
|
|
@keyframes hv-scroll-shadow-end-fade {
|
|
from {
|
|
--scroll-shadow-end-fade: var(--scroll-shadow-size);
|
|
}
|
|
to {
|
|
--scroll-shadow-end-fade: 0px;
|
|
}
|
|
}
|
|
|
|
/* Orientation: Vertical */
|
|
.hv-scroll-shadow--vertical {
|
|
@apply scrollbar overflow-y-auto;
|
|
}
|
|
|
|
/* Orientation: Horizontal */
|
|
.hv-scroll-shadow--horizontal {
|
|
@apply scrollbar overflow-x-auto;
|
|
}
|
|
|
|
/* Variant: Fade - Vertical */
|
|
.hv-scroll-shadow--fade.hv-scroll-shadow--vertical {
|
|
/* `[data-scroll-shadow-mode="auto"]` lets the scroll-driven variant below reuse this
|
|
plumbing. It only paints once `--scroll-linear-gradient` is set, since an undefined
|
|
variable makes `mask-image` invalid at computed-value time, which resolves to `none`. */
|
|
&:where(
|
|
[data-top-scroll="true"],
|
|
[data-bottom-scroll="true"],
|
|
[data-top-bottom-scroll="true"],
|
|
[data-scroll-shadow-mode="auto"]
|
|
) {
|
|
mask-image:
|
|
linear-gradient(var(--scroll-linear-gradient)),
|
|
linear-gradient(#000, #000);
|
|
mask-position:
|
|
left top,
|
|
right top;
|
|
mask-repeat: no-repeat;
|
|
mask-size:
|
|
calc(100% - var(--scroll-shadow-scrollbar-size)) 100%,
|
|
var(--scroll-shadow-scrollbar-size) 100%;
|
|
-webkit-mask-image:
|
|
linear-gradient(var(--scroll-linear-gradient)),
|
|
linear-gradient(#000, #000);
|
|
-webkit-mask-position:
|
|
left top,
|
|
right top;
|
|
-webkit-mask-repeat: no-repeat;
|
|
-webkit-mask-size:
|
|
calc(100% - var(--scroll-shadow-scrollbar-size)) 100%,
|
|
var(--scroll-shadow-scrollbar-size) 100%;
|
|
}
|
|
|
|
&[data-top-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
0deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
|
|
&[data-bottom-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
180deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
|
|
&[data-top-bottom-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
#000, #000, transparent 0, #000 var(--scroll-shadow-size),
|
|
#000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
}
|
|
|
|
/* Variant: Fade - Horizontal */
|
|
.hv-scroll-shadow--fade.hv-scroll-shadow--horizontal {
|
|
&:where(
|
|
[data-left-scroll="true"],
|
|
[data-right-scroll="true"],
|
|
[data-left-right-scroll="true"],
|
|
[data-scroll-shadow-mode="auto"]
|
|
) {
|
|
mask-image:
|
|
linear-gradient(var(--scroll-linear-gradient)),
|
|
linear-gradient(#000, #000);
|
|
mask-position:
|
|
left top,
|
|
left bottom;
|
|
mask-repeat: no-repeat;
|
|
mask-size:
|
|
100% calc(100% - var(--scroll-shadow-scrollbar-size)),
|
|
100% var(--scroll-shadow-scrollbar-size);
|
|
-webkit-mask-image:
|
|
linear-gradient(var(--scroll-linear-gradient)),
|
|
linear-gradient(#000, #000);
|
|
-webkit-mask-position:
|
|
left top,
|
|
left bottom;
|
|
-webkit-mask-repeat: no-repeat;
|
|
-webkit-mask-size:
|
|
100% calc(100% - var(--scroll-shadow-scrollbar-size)),
|
|
100% var(--scroll-shadow-scrollbar-size);
|
|
}
|
|
|
|
/* `left`/`right` data attributes are logical (before/end of scroll). In RTL the
|
|
start edge is on the right, so the physical fade direction must be swapped. */
|
|
&[data-left-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
270deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
|
|
&:dir(rtl) {
|
|
--scroll-linear-gradient:
|
|
90deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
}
|
|
|
|
&[data-right-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
90deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
|
|
&:dir(rtl) {
|
|
--scroll-linear-gradient:
|
|
270deg, #000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
}
|
|
|
|
&[data-left-right-scroll="true"] {
|
|
--scroll-linear-gradient:
|
|
to right, #000, #000, transparent 0, #000 var(--scroll-shadow-size),
|
|
#000 calc(100% - var(--scroll-shadow-size)), transparent;
|
|
}
|
|
}
|
|
|
|
.hv-scroll-shadow--hide-scrollbar {
|
|
@apply scrollbar-none;
|
|
--scroll-shadow-scrollbar-size: 0px;
|
|
}
|
|
|
|
/* Variant: Fade - scroll-driven
|
|
Where scroll timelines are available the fade is derived from the real scroll state,
|
|
so it is already correct on the first paint and needs no measurement or hydration.
|
|
A container without overflow has an inactive timeline, which leaves both fades at 0px
|
|
and collapses the mask to a no-op. The attribute-driven rules above remain the
|
|
fallback for engines without scroll timelines, and keep serving controlled mode.
|
|
|
|
Two consequences of deriving the mask from CSS alone:
|
|
- Auto mode always resolves a `mask-image`, even with nothing to scroll, so the root is
|
|
always a stacking context and a containing block for fixed descendants. Gating that on
|
|
overflow would need a measurement, which is the flicker this variant exists to avoid.
|
|
- The `animation` shorthand here lives in the components layer, so an `animate-*` utility
|
|
on the root replaces it and pins both fades at 0px, leaving no fade at all. */
|
|
@supports (animation-timeline: scroll(self)) {
|
|
/* `.scroll-shadow` is repeated so these rules outrank the attribute-driven gradients
|
|
above on specificity rather than on source order, which a re-ordering could break. */
|
|
.hv-scroll-shadow.hv-scroll-shadow--fade[data-scroll-shadow-mode="auto"] {
|
|
animation:
|
|
hv-scroll-shadow-start-fade linear both,
|
|
hv-scroll-shadow-end-fade linear both;
|
|
animation-range:
|
|
var(--scroll-shadow-offset)
|
|
calc(var(--scroll-shadow-offset) + var(--scroll-shadow-size)),
|
|
calc(100% - var(--scroll-shadow-size) - var(--scroll-shadow-offset))
|
|
calc(100% - var(--scroll-shadow-offset));
|
|
}
|
|
|
|
/* The orientation rules also outrank the `animation` shorthand above, which resets
|
|
`animation-timeline` to `auto`, so the timeline survives regardless of order. */
|
|
.hv-scroll-shadow.hv-scroll-shadow--fade.hv-scroll-shadow--vertical[data-scroll-shadow-mode="auto"] {
|
|
animation-timeline: scroll(self block), scroll(self block);
|
|
--scroll-linear-gradient:
|
|
180deg, transparent 0, #000 var(--scroll-shadow-start-fade),
|
|
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
|
|
}
|
|
|
|
.hv-scroll-shadow.hv-scroll-shadow--fade.hv-scroll-shadow--horizontal[data-scroll-shadow-mode="auto"] {
|
|
animation-timeline: scroll(self inline), scroll(self inline);
|
|
--scroll-linear-gradient:
|
|
90deg, transparent 0, #000 var(--scroll-shadow-start-fade),
|
|
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
|
|
|
|
/* Inline-axis progress starts at the right edge in RTL, so flip the physical direction */
|
|
&:dir(rtl) {
|
|
--scroll-linear-gradient:
|
|
270deg, transparent 0, #000 var(--scroll-shadow-start-fade),
|
|
#000 calc(100% - var(--scroll-shadow-end-fade)), transparent 100%;
|
|
}
|
|
}
|
|
}
|