|
3 | 3 | --text-shimmer-duration: 1200ms; |
4 | 4 | --text-shimmer-swap: 220ms; |
5 | 5 | --text-shimmer-index: 0; |
6 | | - --text-shimmer-angle: 90deg; |
7 | 6 | --text-shimmer-spread: 5.2ch; |
8 | 7 | --text-shimmer-gutter: calc(var(--text-shimmer-spread) + 1ch); |
9 | | - --text-shimmer-size: calc(200% + var(--text-shimmer-gutter) + var(--text-shimmer-gutter)); |
10 | 8 | --text-shimmer-base-color: var(--text-weak); |
11 | 9 | --text-shimmer-peak-color: var(--text-strong); |
12 | | - --text-shimmer-sweep: linear-gradient( |
13 | | - var(--text-shimmer-angle), |
14 | | - transparent calc(50% - var(--text-shimmer-spread)), |
15 | | - var(--text-shimmer-peak-color) 50%, |
16 | | - transparent calc(50% + var(--text-shimmer-spread)) |
17 | | - ); |
18 | | - --text-shimmer-base: linear-gradient(var(--text-shimmer-base-color), var(--text-shimmer-base-color)); |
19 | 10 |
|
20 | 11 | display: inline-flex; |
21 | 12 | align-items: baseline; |
|
47 | 38 | opacity: 1; |
48 | 39 | } |
49 | 40 |
|
| 41 | +/* Clipped to its box, where the old background sweep painted, so the sweep's travel never adds overflow. */ |
50 | 42 | [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] { |
51 | | - color: var(--text-weaker); |
| 43 | + position: relative; |
| 44 | + overflow: clip; |
| 45 | + color: var(--text-shimmer-base-color); |
52 | 46 | opacity: 0; |
53 | 47 | } |
54 | 48 |
|
55 | 49 | [data-component="text-shimmer"][data-active="true"] [data-slot="text-shimmer-char-shimmer"] { |
56 | 50 | opacity: 1; |
57 | 51 | } |
58 | 52 |
|
59 | | -[data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] { |
60 | | - animation-name: text-shimmer-sweep; |
| 53 | +[data-component="text-shimmer"][data-active="true"] [data-slot="text-shimmer-char-base"] { |
| 54 | + opacity: 0; |
| 55 | +} |
| 56 | + |
| 57 | +/* The sweep is the text again in the peak colour, seen through a soft window that crosses it. The window and the text |
| 58 | + inside it move in opposite directions by the same amount, so the text stays put while the window travels: both are |
| 59 | + transforms, which the compositor runs, where an animated background position restyled and repainted the text on |
| 60 | + every frame. The window's centre runs from one gutter before the text to one gutter past it. */ |
| 61 | +[data-component="text-shimmer"] [data-slot="text-shimmer-sweep"] { |
| 62 | + position: absolute; |
| 63 | + top: 0; |
| 64 | + bottom: 0; |
| 65 | + left: calc(-1 * var(--text-shimmer-spread)); |
| 66 | + right: calc(-1 * var(--text-shimmer-spread)); |
| 67 | + display: none; |
| 68 | + pointer-events: none; |
| 69 | + user-select: none; |
| 70 | + mask-image: linear-gradient( |
| 71 | + 90deg, |
| 72 | + transparent calc(50% - var(--text-shimmer-spread)), |
| 73 | + #000 50%, |
| 74 | + transparent calc(50% + var(--text-shimmer-spread)) |
| 75 | + ); |
| 76 | +} |
| 77 | + |
| 78 | +[data-component="text-shimmer"] [data-slot="text-shimmer-sweep-text"] { |
| 79 | + display: block; |
| 80 | + margin-left: var(--text-shimmer-spread); |
| 81 | + margin-right: var(--text-shimmer-spread); |
| 82 | + white-space: pre; |
| 83 | + color: var(--text-shimmer-peak-color); |
| 84 | +} |
| 85 | + |
| 86 | +[data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] > [data-slot="text-shimmer-sweep"] { |
| 87 | + display: block; |
| 88 | +} |
| 89 | + |
| 90 | +[data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] :is([data-slot="text-shimmer-sweep"], [data-slot="text-shimmer-sweep-text"]) { |
61 | 91 | animation-duration: var(--text-shimmer-duration); |
62 | 92 | animation-iteration-count: infinite; |
63 | 93 | animation-timing-function: linear; |
64 | 94 | animation-fill-mode: both; |
65 | 95 | animation-delay: calc(var(--text-shimmer-step) * var(--text-shimmer-index) * -1); |
66 | | - will-change: background-position; |
67 | 96 | } |
68 | 97 |
|
69 | | -@keyframes text-shimmer-sweep { |
| 98 | +[data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] [data-slot="text-shimmer-sweep"] { |
| 99 | + animation-name: text-shimmer-window; |
| 100 | +} |
| 101 | + |
| 102 | +[data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] [data-slot="text-shimmer-sweep-text"] { |
| 103 | + animation-name: text-shimmer-text; |
| 104 | +} |
| 105 | + |
| 106 | +/* The window is one spread wider than the text on each side, so its percentages carry the spread back out. */ |
| 107 | +@keyframes text-shimmer-window { |
70 | 108 | 0% { |
71 | | - background-position: |
72 | | - 100% 0, |
73 | | - 0 0; |
| 109 | + translate: calc(-50% + var(--text-shimmer-spread) - var(--text-shimmer-gutter)) 0; |
74 | 110 | } |
75 | 111 |
|
76 | 112 | 100% { |
77 | | - background-position: |
78 | | - 0% 0, |
79 | | - 0 0; |
| 113 | + translate: calc(50% - var(--text-shimmer-spread) + var(--text-shimmer-gutter)) 0; |
80 | 114 | } |
81 | 115 | } |
82 | 116 |
|
83 | | -@supports ((-webkit-background-clip: text) or (background-clip: text)) { |
84 | | - [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] { |
85 | | - color: transparent; |
86 | | - -webkit-text-fill-color: transparent; |
87 | | - background-image: var(--text-shimmer-sweep), var(--text-shimmer-base); |
88 | | - background-size: |
89 | | - var(--text-shimmer-size) 100%, |
90 | | - 100% 100%; |
91 | | - background-position: |
92 | | - 100% 0, |
93 | | - 0 0; |
94 | | - background-repeat: no-repeat; |
95 | | - -webkit-background-clip: text; |
96 | | - background-clip: text; |
| 117 | +@keyframes text-shimmer-text { |
| 118 | + 0% { |
| 119 | + translate: calc(50% + var(--text-shimmer-gutter)) 0; |
97 | 120 | } |
98 | 121 |
|
99 | | - [data-component="text-shimmer"][data-active="true"] [data-slot="text-shimmer-char-base"] { |
100 | | - opacity: 0; |
| 122 | + 100% { |
| 123 | + translate: calc(-50% - var(--text-shimmer-gutter)) 0; |
101 | 124 | } |
102 | 125 | } |
103 | 126 |
|
|
108 | 131 | } |
109 | 132 |
|
110 | 133 | [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] { |
111 | | - animation: none !important; |
112 | 134 | color: inherit; |
113 | | - -webkit-text-fill-color: currentColor; |
114 | | - background-image: none; |
| 135 | + } |
| 136 | + |
| 137 | + [data-component="text-shimmer"] [data-slot="text-shimmer-sweep"] { |
| 138 | + display: none !important; |
115 | 139 | } |
116 | 140 |
|
117 | 141 | [data-component="text-shimmer"] [data-slot="text-shimmer-char-base"] { |
|
0 commit comments