astro-nosferatu 0.1.0 → 0.2.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.
@@ -0,0 +1,76 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { NavItem } from "../types/components";
4
+
5
+ interface Props extends HTMLAttributes<"ul"> {
6
+ items: NavItem[];
7
+ }
8
+
9
+ const { items, class: className, ...attrs } = Astro.props;
10
+ ---
11
+
12
+ <ul {...attrs} class:list={["nf-nav-items-mobile", className]}>
13
+ {items.map(({ text, href, icon: Icon, current }) => (
14
+ <li class="nf-nav-items-mobile-item">
15
+ <a
16
+ class="nf-nav-items-mobile-link"
17
+ href={href}
18
+ aria-current={current ? "page" : undefined}
19
+ >
20
+ {Icon && (
21
+ <span class="nf-nav-items-mobile-icon" aria-hidden="true">
22
+ <Icon width="1em" height="1em" stroke-width="2" />
23
+ </span>
24
+ )}
25
+ {text}
26
+ </a>
27
+ </li>
28
+ ))}
29
+ </ul>
30
+
31
+ <style>
32
+ .nf-nav-items-mobile {
33
+ margin: var(--nf-spacing-none);
34
+ padding: var(--nf-spacing-none);
35
+ list-style: none;
36
+ }
37
+
38
+ /* The border color is set by an enclosing Navbar; alone, it is grey */
39
+ .nf-nav-items-mobile-item {
40
+ border-block-end: 1px solid
41
+ var(
42
+ --nf-navbar-border-color,
43
+ light-dark(var(--nf-grey-l-30), var(--nf-grey-d-120))
44
+ );
45
+ }
46
+
47
+ .nf-nav-items-mobile-link {
48
+ display: flex;
49
+ align-items: center;
50
+ justify-content: center;
51
+ gap: var(--nf-spacing-base-low-2);
52
+ padding: var(--nf-spacing-base);
53
+ color: inherit;
54
+ font-size: 1rem;
55
+ text-decoration: none;
56
+
57
+ &:focus-visible {
58
+ outline: 2px solid currentColor;
59
+ outline-offset: -2px;
60
+ }
61
+
62
+ &[aria-current="page"] {
63
+ color: var(
64
+ --nf-navbar-active-color,
65
+ light-dark(var(--nf-purple-l-70), var(--nf-purple-d-30))
66
+ );
67
+ }
68
+ }
69
+
70
+ /* Never squashed: in a tight row, the text gives way instead */
71
+ .nf-nav-items-mobile-icon {
72
+ display: flex;
73
+ flex: none;
74
+ font-size: 22px;
75
+ }
76
+ </style>
@@ -0,0 +1,40 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ /* Either a text logo or an image logo, never both and never neither */
5
+ type Props = HTMLAttributes<"a"> &
6
+ (
7
+ | { text: string; src?: never; alt?: never }
8
+ | { src: string; alt: string; text?: never }
9
+ );
10
+
11
+ const { text, src, alt, href = "/", class: className, ...attrs } = Astro.props;
12
+ ---
13
+
14
+ <a {...attrs} href={href} class:list={["nf-nav-logo", className]}>
15
+ {src ? <img class="nf-nav-logo-image" src={src} alt={alt} /> : text}
16
+ </a>
17
+
18
+ <style>
19
+ .nf-nav-logo {
20
+ --nf-nav-logo-block-size: 32px;
21
+
22
+ display: inline-flex;
23
+ align-items: center;
24
+ color: inherit;
25
+ font-size: 1.5rem;
26
+ font-weight: 700;
27
+ line-height: 1;
28
+ text-decoration: none;
29
+
30
+ &:focus-visible {
31
+ outline: 2px solid currentColor;
32
+ outline-offset: 2px;
33
+ }
34
+ }
35
+
36
+ .nf-nav-logo-image {
37
+ block-size: var(--nf-nav-logo-block-size);
38
+ inline-size: auto;
39
+ }
40
+ </style>
@@ -0,0 +1,62 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { IconComponent } from "../types/components";
4
+
5
+ interface NavSocialItem {
6
+ icon: IconComponent;
7
+ href: string;
8
+ /** The link's accessible name: the icon is its only content. */
9
+ label: string;
10
+ }
11
+
12
+ interface Props extends HTMLAttributes<"ul"> {
13
+ items: NavSocialItem[];
14
+ }
15
+
16
+ const { items, class: className, ...attrs } = Astro.props;
17
+ ---
18
+
19
+ <ul {...attrs} class:list={["nf-nav-social", className]}>
20
+ {items.map(({ icon: Icon, href, label }) => (
21
+ <li>
22
+ <a class="nf-nav-social-link" href={href} aria-label={label}>
23
+ <span class="nf-nav-social-icon" aria-hidden="true">
24
+ <Icon width="1em" height="1em" stroke-width="2" />
25
+ </span>
26
+ </a>
27
+ </li>
28
+ ))}
29
+ </ul>
30
+
31
+ <style>
32
+ .nf-nav-social {
33
+ display: flex;
34
+ gap: var(--nf-spacing-base);
35
+ margin: var(--nf-spacing-none);
36
+ padding: var(--nf-spacing-none);
37
+ list-style: none;
38
+ }
39
+
40
+ .nf-nav-social-link {
41
+ /* 6px: no spacing step has it, so it is built from two that do */
42
+ --nf-nav-social-link-padding: calc(
43
+ var(--nf-spacing-base-low-3) + var(--nf-spacing-base-low-4)
44
+ );
45
+
46
+ display: flex;
47
+ padding: var(--nf-nav-social-link-padding);
48
+ color: inherit;
49
+
50
+ &:focus-visible {
51
+ outline: 2px solid currentColor;
52
+ outline-offset: -2px;
53
+ }
54
+ }
55
+
56
+ /* Never squashed: in a tight row, the text gives way instead */
57
+ .nf-nav-social-icon {
58
+ display: flex;
59
+ flex: none;
60
+ font-size: 22px;
61
+ }
62
+ </style>
@@ -0,0 +1,311 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { ColorPalette } from "../types/components";
4
+ /*
5
+ * Iconoir is a dependency of this package, so these resolve from here under
6
+ * any package manager and the consumer installs nothing.
7
+ */
8
+ import Menu from "iconoir/icons/regular/menu.svg";
9
+ import Xmark from "iconoir/icons/regular/xmark.svg";
10
+
11
+ interface Props extends HTMLAttributes<"header"> {
12
+ /* The current item's color. Falls back to purple, not grey: a grey current item would not stand out */
13
+ color?: ColorPalette;
14
+ /** Accessible name of the desktop nav and the mobile menu */
15
+ label?: string;
16
+ /** Accessible name of the burger, which both opens and closes the menu */
17
+ menuLabel?: string;
18
+ }
19
+
20
+ const {
21
+ color,
22
+ label = "Main",
23
+ menuLabel = "Menu",
24
+ class: className,
25
+ "data-ui-color": _color,
26
+ ...attrs
27
+ } = Astro.props;
28
+
29
+ const hasDesktopItems = Astro.slots.has("nav-items-desktop");
30
+ const hasMobileItems = Astro.slots.has("nav-items-mobile");
31
+
32
+ /* Frontmatter runs per render, so a random suffix keeps each navbar's menu id unique */
33
+ const menuId = `nf-navbar-menu-${crypto.randomUUID().slice(0, 8)}`;
34
+ ---
35
+
36
+ <header {...attrs} data-ui-color={color} class:list={["nf-navbar", className]}>
37
+ <div class="nf-navbar-container">
38
+ <div class="nf-navbar-logo">
39
+ <slot name="nav-logo" />
40
+ </div>
41
+ {hasDesktopItems && (
42
+ <nav class="nf-navbar-items-desktop" aria-label={label}>
43
+ <slot name="nav-items-desktop" />
44
+ </nav>
45
+ )}
46
+ <div class="nf-navbar-social">
47
+ <slot name="nav-social" />
48
+ </div>
49
+ {hasMobileItems && (
50
+ <button
51
+ class="nf-navbar-burger"
52
+ type="button"
53
+ popovertarget={menuId}
54
+ aria-label={menuLabel}
55
+ >
56
+ <span class="nf-navbar-burger-open" aria-hidden="true">
57
+ <Menu width="1em" height="1em" stroke-width="2" />
58
+ </span>
59
+ <span class="nf-navbar-burger-close" aria-hidden="true">
60
+ <Xmark width="1em" height="1em" stroke-width="2" />
61
+ </span>
62
+ </button>
63
+ )}
64
+ </div>
65
+ {hasMobileItems && (
66
+ <nav id={menuId} class="nf-navbar-menu" popover aria-label={label}>
67
+ <slot name="nav-items-mobile" />
68
+ </nav>
69
+ )}
70
+ </header>
71
+
72
+ <style>
73
+ /*
74
+ * Every color property is read with a fallback, never declared on the root:
75
+ * the slotted lists and the menu inherit them, and an ancestor can set them.
76
+ */
77
+ .nf-navbar {
78
+ --nf-navbar-max-inline-size: 1036px;
79
+ --nf-navbar-block-size: 80px;
80
+ --nf-navbar-z-index: 100;
81
+ --nf-navbar-transition-duration: 0.25s;
82
+
83
+ container: nf-navbar / inline-size;
84
+ position: sticky;
85
+ inset-block-start: 0;
86
+ z-index: var(--nf-navbar-z-index);
87
+ block-size: var(--nf-navbar-block-size);
88
+ padding-inline: var(--nf-spacing-base);
89
+ color: var(
90
+ --nf-navbar-text-color,
91
+ light-dark(var(--nf-grey-l-100), var(--nf-grey-d-10))
92
+ );
93
+ background-color: var(
94
+ --nf-navbar-surface-color,
95
+ light-dark(var(--nf-grey-l-10), var(--nf-grey-d-100))
96
+ );
97
+
98
+ &[data-ui-color="blue"] {
99
+ --nf-navbar-active-color: light-dark(
100
+ var(--nf-blue-l-70),
101
+ var(--nf-blue-d-30)
102
+ );
103
+ }
104
+
105
+ &[data-ui-color="cyan"] {
106
+ --nf-navbar-active-color: light-dark(
107
+ var(--nf-cyan-l-70),
108
+ var(--nf-cyan-d-30)
109
+ );
110
+ }
111
+
112
+ &[data-ui-color="green"] {
113
+ --nf-navbar-active-color: light-dark(
114
+ var(--nf-green-l-70),
115
+ var(--nf-green-d-30)
116
+ );
117
+ }
118
+
119
+ &[data-ui-color="grey"] {
120
+ --nf-navbar-active-color: light-dark(
121
+ var(--nf-grey-l-70),
122
+ var(--nf-grey-d-30)
123
+ );
124
+ }
125
+
126
+ &[data-ui-color="orange"] {
127
+ --nf-navbar-active-color: light-dark(
128
+ var(--nf-orange-l-70),
129
+ var(--nf-orange-d-30)
130
+ );
131
+ }
132
+
133
+ &[data-ui-color="pink"] {
134
+ --nf-navbar-active-color: light-dark(
135
+ var(--nf-pink-l-70),
136
+ var(--nf-pink-d-30)
137
+ );
138
+ }
139
+
140
+ &[data-ui-color="purple"] {
141
+ --nf-navbar-active-color: light-dark(
142
+ var(--nf-purple-l-70),
143
+ var(--nf-purple-d-30)
144
+ );
145
+ }
146
+
147
+ &[data-ui-color="red"] {
148
+ --nf-navbar-active-color: light-dark(
149
+ var(--nf-red-l-70),
150
+ var(--nf-red-d-30)
151
+ );
152
+ }
153
+
154
+ &[data-ui-color="yellow"] {
155
+ --nf-navbar-active-color: light-dark(
156
+ var(--nf-yellow-l-70),
157
+ var(--nf-yellow-d-30)
158
+ );
159
+ }
160
+ }
161
+
162
+ .nf-navbar-container {
163
+ /* 64px between the logo and the desktop list: two of the largest step */
164
+ --nf-navbar-logo-gap: calc(2 * var(--nf-spacing-base-up-4));
165
+ --nf-navbar-gap: var(--nf-spacing-base-up-2);
166
+
167
+ display: flex;
168
+ align-items: center;
169
+ column-gap: var(--nf-navbar-gap);
170
+ block-size: 100%;
171
+ margin-inline: auto;
172
+ max-inline-size: var(--nf-navbar-max-inline-size);
173
+ }
174
+
175
+ /* Pushes everything after the logo to the inline end */
176
+ .nf-navbar-logo {
177
+ margin-inline-end: auto;
178
+ }
179
+
180
+ .nf-navbar-items-desktop {
181
+ display: none;
182
+ }
183
+
184
+ /* Sized to their content: in a tight bar, the logo gives way instead */
185
+ .nf-navbar-social {
186
+ display: flex;
187
+ flex: none;
188
+ }
189
+
190
+ .nf-navbar-burger {
191
+ display: flex;
192
+ flex: none;
193
+ /* The icons are 1em, so this is their size */
194
+ font-size: 22px;
195
+ padding: var(--nf-spacing-base-low-3);
196
+ border: none;
197
+ border-radius: var(--nf-border-radius-base-low-1);
198
+ color: inherit;
199
+ background: none;
200
+ cursor: pointer;
201
+
202
+ &:focus-visible {
203
+ outline: 2px solid currentColor;
204
+ outline-offset: -2px;
205
+ }
206
+ }
207
+
208
+ .nf-navbar-burger-open {
209
+ display: flex;
210
+ }
211
+
212
+ /* The burger turns into the close button while the menu is open */
213
+ .nf-navbar-burger-close {
214
+ display: none;
215
+ }
216
+
217
+ .nf-navbar:has(.nf-navbar-menu:popover-open) {
218
+ .nf-navbar-burger-open {
219
+ display: none;
220
+ }
221
+
222
+ .nf-navbar-burger-close {
223
+ display: flex;
224
+ }
225
+ }
226
+
227
+ /*
228
+ * 856px mirrors --nf-container-small-size: a container-query condition
229
+ * cannot read a custom property, so keep the two in step by hand. The
230
+ * query measures this navbar (the named container), never the viewport.
231
+ */
232
+ @container nf-navbar (width >= 856px) {
233
+ .nf-navbar-container {
234
+ --nf-navbar-gap: var(--nf-navbar-logo-gap);
235
+ }
236
+
237
+ /* Growing, it takes the free space the logo's auto margin would */
238
+ .nf-navbar-items-desktop {
239
+ display: block;
240
+ flex: 1;
241
+ }
242
+
243
+ .nf-navbar-burger {
244
+ display: none;
245
+ }
246
+ }
247
+
248
+ /*
249
+ * A popover, not a modal dialog: it opens 4px below the bar, so the burger stays
250
+ * reachable and closes it. Esc and a click outside close it too.
251
+ */
252
+ .nf-navbar-menu {
253
+ /* Off the inline end, by the panel's width plus the gap beside it */
254
+ --nf-navbar-menu-offset: calc(100% + var(--nf-spacing-base-low-2));
255
+
256
+ position: fixed;
257
+ /* Just below the bar, with a 4px gap */
258
+ inset-block: calc(
259
+ var(--nf-navbar-block-size) + var(--nf-spacing-base-low-3)
260
+ )
261
+ var(--nf-spacing-base-low-2);
262
+ inset-inline: var(--nf-spacing-base-low-2);
263
+ inline-size: auto;
264
+ block-size: auto;
265
+ margin: var(--nf-spacing-none);
266
+ padding: var(--nf-spacing-none);
267
+ border: none;
268
+ border-radius: var(--nf-border-radius-base);
269
+ color: var(
270
+ --nf-navbar-text-color,
271
+ light-dark(var(--nf-grey-l-100), var(--nf-grey-d-10))
272
+ );
273
+ background-color: var(
274
+ --nf-navbar-surface-color,
275
+ light-dark(var(--nf-grey-l-10), var(--nf-grey-d-100))
276
+ );
277
+ translate: var(--nf-navbar-menu-offset) 0;
278
+ transition-property: translate, display, overlay;
279
+ transition-duration: var(--nf-navbar-transition-duration);
280
+ transition-timing-function: ease-out;
281
+ transition-behavior: allow-discrete;
282
+
283
+ /* translate is physical, so in right-to-left text it comes from the left */
284
+ &:dir(rtl) {
285
+ --nf-navbar-menu-offset: calc(-100% - var(--nf-spacing-base-low-2));
286
+ }
287
+
288
+ &:popover-open {
289
+ translate: 0 0;
290
+
291
+ @starting-style {
292
+ translate: var(--nf-navbar-menu-offset) 0;
293
+ }
294
+ }
295
+
296
+ /* Starts below the bar, so the bar and its burger stay undimmed */
297
+ &::backdrop {
298
+ inset-block-start: var(--nf-navbar-block-size);
299
+ background-color: light-dark(
300
+ var(--nf-grey-l-100-25),
301
+ var(--nf-grey-d-200-25)
302
+ );
303
+ }
304
+ }
305
+
306
+ @media (prefers-reduced-motion: reduce) {
307
+ .nf-navbar {
308
+ --nf-navbar-transition-duration: 0s;
309
+ }
310
+ }
311
+ </style>
@@ -0,0 +1,166 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import type { ColorPalette } from "../types/components";
4
+
5
+ interface Props extends HTMLAttributes<"div"> {
6
+ color?: ColorPalette;
7
+ /** The `id` of the element whose scroll progress the bar shows. */
8
+ target?: string;
9
+ }
10
+
11
+ const {
12
+ color,
13
+ target,
14
+ class: className,
15
+ "data-ui-color": _color,
16
+ "data-ui-target": _target,
17
+ ...attrs
18
+ } = Astro.props;
19
+
20
+ /*
21
+ * `target` is interpolated into raw CSS below, so it must be a plain
22
+ * identifier: that keeps it from breaking out of the selector or the
23
+ * <style> element, and makes `--nf-reading-progress-<target>` a valid name.
24
+ */
25
+ const TARGET_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/;
26
+
27
+ if (target !== undefined && !TARGET_PATTERN.test(target)) {
28
+ throw new Error(
29
+ `ReadingProgress: target ${JSON.stringify(target)} is not a valid id; it must match ${TARGET_PATTERN}.`,
30
+ );
31
+ }
32
+
33
+ /*
34
+ * The one place a component reaches outside its markup (library-styles,
35
+ * "Components are self-styled through tokens"): the tracked element declares
36
+ * the view timeline, and :root scopes it so the fixed bar can see it.
37
+ */
38
+ const timeline = `--nf-reading-progress-${target}`;
39
+ const targetCss = target
40
+ ? `@supports (animation-timeline: scroll()) {
41
+ :root { timeline-scope: ${timeline}; }
42
+ #${target} { view-timeline: ${timeline} block; }
43
+ .nf-reading-progress[data-ui-target="${target}"] {
44
+ animation-timeline: ${timeline};
45
+ animation-range: contain 0% contain 100%;
46
+ }
47
+ }`
48
+ : undefined;
49
+ ---
50
+
51
+ {targetCss && <style is:inline set:html={targetCss} />}
52
+ <div
53
+ {...attrs}
54
+ aria-hidden="true"
55
+ data-ui-color={color}
56
+ data-ui-target={target}
57
+ class:list={["nf-reading-progress", className]}
58
+ ></div>
59
+
60
+ <style>
61
+ .nf-reading-progress {
62
+ --nf-reading-progress-block-size: 6px;
63
+
64
+ position: fixed;
65
+ /* Read with a fallback, never declared, so an ancestor (a layout, :root) can set it */
66
+ inset-block-start: var(--nf-reading-progress-inset-block-start, 0px);
67
+ inset-inline: 0;
68
+ z-index: 100;
69
+ block-size: var(--nf-reading-progress-block-size);
70
+ background-color: var(
71
+ --nf-reading-progress-color,
72
+ light-dark(var(--nf-grey-l-40), var(--nf-grey-d-50))
73
+ );
74
+ /* The bar is its own fill: the uncovered part is the transparent track */
75
+ scale: 0 1;
76
+ transform-origin: 0 50%;
77
+ pointer-events: none;
78
+
79
+ &[data-ui-color="blue"] {
80
+ --nf-reading-progress-color: light-dark(
81
+ var(--nf-blue-l-40),
82
+ var(--nf-blue-d-50)
83
+ );
84
+ }
85
+
86
+ &[data-ui-color="cyan"] {
87
+ --nf-reading-progress-color: light-dark(
88
+ var(--nf-cyan-l-40),
89
+ var(--nf-cyan-d-50)
90
+ );
91
+ }
92
+
93
+ &[data-ui-color="green"] {
94
+ --nf-reading-progress-color: light-dark(
95
+ var(--nf-green-l-40),
96
+ var(--nf-green-d-50)
97
+ );
98
+ }
99
+
100
+ &[data-ui-color="grey"] {
101
+ --nf-reading-progress-color: light-dark(
102
+ var(--nf-grey-l-40),
103
+ var(--nf-grey-d-50)
104
+ );
105
+ }
106
+
107
+ &[data-ui-color="orange"] {
108
+ --nf-reading-progress-color: light-dark(
109
+ var(--nf-orange-l-40),
110
+ var(--nf-orange-d-50)
111
+ );
112
+ }
113
+
114
+ &[data-ui-color="pink"] {
115
+ --nf-reading-progress-color: light-dark(
116
+ var(--nf-pink-l-40),
117
+ var(--nf-pink-d-50)
118
+ );
119
+ }
120
+
121
+ &[data-ui-color="purple"] {
122
+ --nf-reading-progress-color: light-dark(
123
+ var(--nf-purple-l-40),
124
+ var(--nf-purple-d-50)
125
+ );
126
+ }
127
+
128
+ &[data-ui-color="red"] {
129
+ --nf-reading-progress-color: light-dark(
130
+ var(--nf-red-l-40),
131
+ var(--nf-red-d-50)
132
+ );
133
+ }
134
+
135
+ &[data-ui-color="yellow"] {
136
+ --nf-reading-progress-color: light-dark(
137
+ var(--nf-yellow-l-40),
138
+ var(--nf-yellow-d-50)
139
+ );
140
+ }
141
+ }
142
+
143
+ @keyframes nf-reading-progress-fill {
144
+ from {
145
+ scale: 0 1;
146
+ }
147
+
148
+ to {
149
+ scale: 1 1;
150
+ }
151
+ }
152
+
153
+ /*
154
+ * Longhands only: the `animation` shorthand resets animation-timeline.
155
+ * Unsupported browsers skip this block and keep the empty bar.
156
+ */
157
+ @supports (animation-timeline: scroll()) {
158
+ .nf-reading-progress {
159
+ animation-name: nf-reading-progress-fill;
160
+ animation-duration: auto;
161
+ animation-timing-function: linear;
162
+ animation-fill-mode: both;
163
+ animation-timeline: scroll(root block);
164
+ }
165
+ }
166
+ </style>