@n1kname/components 0.34.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n1kname/components",
3
- "version": "0.34.0",
3
+ "version": "0.35.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -5,16 +5,25 @@
5
5
  * the timing live in highlight.css, shared with PageHeader.
6
6
  *
7
7
  * band the highlighter, a band behind the lower half of the words (default)
8
- * glow a soft blue light behind them that fades in once and holds; for a big headline
8
+ * glow a soft blue light behind them that fades in once and holds
9
+ * spotlight a slanted band of blue light that passes through the letters once; the words keep
10
+ * their colour. Each sweep lasts as long as the words have characters, so the light
11
+ * moves at one speed through a short phrase and a long one.
9
12
  */
10
13
  import './highlight.css';
11
14
 
12
15
  interface Props {
13
16
  /** This mark's place among the marks on the page, from 0. */
14
17
  n?: number;
15
- variant?: 'band' | 'glow';
18
+ variant?: 'band' | 'glow' | 'spotlight';
16
19
  }
17
20
  const { n = 0, variant = 'band' } = Astro.props;
21
+ const html = Astro.slots.has('default') ? await Astro.slots.render('default') : '';
22
+ // The words as a reader counts them: no tags, an entity as one character.
23
+ const chars = [...html.replace(/<[^>]*>/g, '').replace(/&#?\w+;/g, 'x')].length;
18
24
  ---
19
25
 
20
- <mark class:list={['highlight', { glow: variant === 'glow' }]} style={`--n: ${n}`}><slot /></mark>
26
+ <mark
27
+ class:list={['highlight', { glow: variant === 'glow', spotlight: variant === 'spotlight' }]}
28
+ style={`--n: ${n}; --chars: ${chars}`}
29
+ ><Fragment set:html={html} /></mark>
package/src/highlight.css CHANGED
@@ -6,6 +6,9 @@
6
6
  * `mark.highlight.glow` is the quiet look: a soft blue light behind the words that fades in once
7
7
  * and then holds still. It reaches past the line, so it never stops in a hard edge.
8
8
  *
9
+ * `mark.highlight.spotlight` passes a slanted band of blue light through the letters once, then
10
+ * rests as plain text. It needs `--chars` (Highlight sets it) to keep one speed.
11
+ *
9
12
  * Used by Highlight and PageHeader. A page that writes its words once its data arrives can wrap
10
13
  * them in <mark class="highlight"> itself, and the sweep plays as they land.
11
14
  *
@@ -83,7 +86,48 @@
83
86
  }
84
87
  }
85
88
 
89
+ /* The spotlight: the words' fill is a gradient clipped to the glyphs, text colour either side of
90
+ * a soft band of light slanted like the streaks. At rest the visible third is plain text colour.
91
+ * One continuous sweep when the words wrap (slice, not clone), at one speed: 175ms a character. */
92
+ :where(mark.highlight.spotlight) {
93
+ --highlight-shine: color-mix(in oklab, var(--c-chart-2), #fff 25%);
94
+ --highlight-strength: 60%;
95
+ padding-inline: 0;
96
+ margin-inline: 0;
97
+ color: var(--c-text);
98
+ background: linear-gradient(105deg,
99
+ var(--c-text) 36%,
100
+ color-mix(in oklab, var(--highlight-shine) var(--highlight-strength), var(--c-text)) 50%,
101
+ var(--c-text) 64%)
102
+ 0 0 / 300% 100% no-repeat;
103
+ -webkit-background-clip: text;
104
+ background-clip: text;
105
+ -webkit-text-fill-color: transparent;
106
+ box-decoration-break: slice;
107
+ -webkit-box-decoration-break: slice;
108
+ }
109
+
110
+ @media (prefers-reduced-motion: no-preference) {
111
+ :where(mark.highlight.spotlight) {
112
+ animation: highlight-spotlight calc(var(--chars, 10) * 175ms) cubic-bezier(0.45, 0, 0.25, 1)
113
+ calc(var(--highlight-delay, 300ms) + var(--n, 0) * var(--highlight-step, 450ms)) both;
114
+ }
115
+ }
116
+
117
+ @keyframes highlight-spotlight {
118
+ from {
119
+ background-position: 100% 0;
120
+ }
121
+ to {
122
+ background-position: 0% 0;
123
+ }
124
+ }
125
+
86
126
  @media (forced-colors: active) {
127
+ :where(mark.highlight.spotlight) {
128
+ -webkit-text-fill-color: CanvasText;
129
+ }
130
+
87
131
  :where(mark.highlight, .page-header .text mark) {
88
132
  background: none;
89
133
  text-decoration: underline 0.2em;