text-shimmer.css 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. [data-component="text-shimmer"] {
  2. --text-shimmer-step: 45ms;
  3. --text-shimmer-duration: 1200ms;
  4. --text-shimmer-swap: 220ms;
  5. --text-shimmer-index: 0;
  6. --text-shimmer-angle: 90deg;
  7. --text-shimmer-spread: 5.2ch;
  8. --text-shimmer-size: 360%;
  9. --text-shimmer-base-color: var(--text-weak);
  10. --text-shimmer-peak-color: var(--text-strong);
  11. --text-shimmer-sweep: linear-gradient(
  12. var(--text-shimmer-angle),
  13. transparent calc(50% - var(--text-shimmer-spread)),
  14. var(--text-shimmer-peak-color) 50%,
  15. transparent calc(50% + var(--text-shimmer-spread))
  16. );
  17. --text-shimmer-base: linear-gradient(var(--text-shimmer-base-color), var(--text-shimmer-base-color));
  18. display: inline-flex;
  19. align-items: baseline;
  20. font: inherit;
  21. letter-spacing: inherit;
  22. line-height: inherit;
  23. }
  24. [data-component="text-shimmer"] [data-slot="text-shimmer-char"] {
  25. display: inline-grid;
  26. white-space: pre;
  27. font: inherit;
  28. letter-spacing: inherit;
  29. line-height: inherit;
  30. }
  31. [data-component="text-shimmer"] [data-slot="text-shimmer-char-base"],
  32. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
  33. grid-area: 1 / 1;
  34. white-space: pre;
  35. transition: opacity var(--text-shimmer-swap) ease-out;
  36. font: inherit;
  37. letter-spacing: inherit;
  38. line-height: inherit;
  39. }
  40. [data-component="text-shimmer"] [data-slot="text-shimmer-char-base"] {
  41. color: inherit;
  42. opacity: 1;
  43. }
  44. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
  45. color: var(--text-weaker);
  46. opacity: 0;
  47. }
  48. [data-component="text-shimmer"][data-active="true"] [data-slot="text-shimmer-char-shimmer"] {
  49. opacity: 1;
  50. }
  51. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"][data-run="true"] {
  52. animation-name: text-shimmer-sweep;
  53. animation-duration: var(--text-shimmer-duration);
  54. animation-iteration-count: infinite;
  55. animation-timing-function: linear;
  56. animation-fill-mode: both;
  57. animation-delay: calc(var(--text-shimmer-step) * var(--text-shimmer-index) * -1);
  58. will-change: background-position;
  59. }
  60. @keyframes text-shimmer-sweep {
  61. 0% {
  62. background-position:
  63. 100% 0,
  64. 0 0;
  65. }
  66. 100% {
  67. background-position:
  68. 0% 0,
  69. 0 0;
  70. }
  71. }
  72. @supports ((-webkit-background-clip: text) or (background-clip: text)) {
  73. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
  74. color: transparent;
  75. -webkit-text-fill-color: transparent;
  76. background-image: var(--text-shimmer-sweep), var(--text-shimmer-base);
  77. background-size:
  78. var(--text-shimmer-size) 100%,
  79. 100% 100%;
  80. background-position:
  81. 100% 0,
  82. 0 0;
  83. background-repeat: no-repeat;
  84. -webkit-background-clip: text;
  85. background-clip: text;
  86. }
  87. [data-component="text-shimmer"][data-active="true"] [data-slot="text-shimmer-char-base"] {
  88. opacity: 0;
  89. }
  90. }
  91. @media (prefers-reduced-motion: reduce) {
  92. [data-component="text-shimmer"] [data-slot="text-shimmer-char-base"],
  93. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
  94. transition-duration: 0ms;
  95. }
  96. [data-component="text-shimmer"] [data-slot="text-shimmer-char-shimmer"] {
  97. animation: none !important;
  98. color: inherit;
  99. -webkit-text-fill-color: currentColor;
  100. background-image: none;
  101. }
  102. [data-component="text-shimmer"] [data-slot="text-shimmer-char-base"] {
  103. opacity: 1 !important;
  104. }
  105. }