@n1kname/components 0.33.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.33.0",
3
+ "version": "0.35.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -36,7 +36,7 @@
36
36
  "@n1kname/charts": "0.12.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@n1kname/tokens": "^0.6.0",
39
+ "@n1kname/tokens": "^0.7.0",
40
40
  "astro": "^7.4.4"
41
41
  },
42
42
  "publishConfig": {
@@ -3,14 +3,27 @@
3
3
  * Highlights the words a heading or lede is about, with a band that sweeps in once. Give each
4
4
  * mark its place with `n` when there are several, so they sweep one after the other. The look and
5
5
  * the timing live in highlight.css, shared with PageHeader.
6
+ *
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
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.
6
12
  */
7
13
  import './highlight.css';
8
14
 
9
15
  interface Props {
10
16
  /** This mark's place among the marks on the page, from 0. */
11
17
  n?: number;
18
+ variant?: 'band' | 'glow' | 'spotlight';
12
19
  }
13
- const { n = 0 } = Astro.props;
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;
14
24
  ---
15
25
 
16
- <mark class="highlight" 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
@@ -3,6 +3,12 @@
3
3
  * by line, and is mixed into the page colour rather than see-through, so it holds up in dark. It
4
4
  * sweeps in once, a moment after the words land; several marks go one after the other, by --n.
5
5
  *
6
+ * `mark.highlight.glow` is the quiet look: a soft blue light behind the words that fades in once
7
+ * and then holds still. It reaches past the line, so it never stops in a hard edge.
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
+ *
6
12
  * Used by Highlight and PageHeader. A page that writes its words once its data arrives can wrap
7
13
  * them in <mark class="highlight"> itself, and the sweep plays as they land.
8
14
  *
@@ -35,7 +41,93 @@
35
41
  }
36
42
  }
37
43
 
44
+ /* The glow: a soft ellipse of blue behind the words. The atmosphere blue of the case heroes on a
45
+ * light page; on a dark one, the chart blue, since the dark atmosphere blue is too deep to glow. Vertical padding
46
+ * on an inline box moves no text but widens what its background can paint, so the light runs
47
+ * past the line instead of stopping at the glyphs' box. Its strength is a registered property,
48
+ * so it can fade: a gradient can't. */
49
+ @property --highlight-glow {
50
+ syntax: '<percentage>';
51
+ inherits: false;
52
+ initial-value: 0%;
53
+ }
54
+
55
+ :where(mark.highlight.glow) {
56
+ --highlight-glow: 60%;
57
+ --highlight-glow-color: var(--c-atmosphere-b);
58
+ padding: 0.35em 0.3em;
59
+ margin-inline: -0.3em;
60
+ background: radial-gradient(closest-side, color-mix(in oklab, var(--highlight-glow-color) var(--highlight-glow), transparent), transparent)
61
+ no-repeat 50% 55% / 100% 100%;
62
+ }
63
+
64
+ :root[data-theme='dark'] :where(mark.highlight.glow) {
65
+ --highlight-glow: 24%;
66
+ --highlight-glow-color: var(--c-chart-2);
67
+ }
68
+
69
+ @media (prefers-color-scheme: dark) {
70
+ :root:not([data-theme='light']) :where(mark.highlight.glow) {
71
+ --highlight-glow: 24%;
72
+ --highlight-glow-color: var(--c-chart-2);
73
+ }
74
+ }
75
+
76
+ @media (prefers-reduced-motion: no-preference) {
77
+ :where(mark.highlight.glow) {
78
+ animation-name: highlight-glow;
79
+ animation-duration: calc(var(--motion-draw, 1000ms) * 1.6);
80
+ }
81
+ }
82
+
83
+ @keyframes highlight-glow {
84
+ from {
85
+ --highlight-glow: 0%;
86
+ }
87
+ }
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
+
38
126
  @media (forced-colors: active) {
127
+ :where(mark.highlight.spotlight) {
128
+ -webkit-text-fill-color: CanvasText;
129
+ }
130
+
39
131
  :where(mark.highlight, .page-header .text mark) {
40
132
  background: none;
41
133
  text-decoration: underline 0.2em;