@hagicode/hagilight-core 0.14.1-dev.151.1.c2d06ef → 0.14.1-dev.152.1.1b8dd12
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/FooterAvatarPicker.astro +3 -3
- package/FooterBrand.astro +78 -3
- package/README.md +33 -4
- package/RootTransit.astro +201 -13
- package/dist/random-image.d.ts +27 -0
- package/dist/random-image.js +114 -3
- package/dist/root-transit-board.d.ts +42 -0
- package/dist/root-transit-board.js +35 -0
- package/package.json +5 -1
package/FooterAvatarPicker.astro
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
---
|
|
2
|
-
// Rendered only when the footer avatar's random option is on, so a site that turns it off ships no picker script.
|
|
2
|
+
// Rendered only when the footer avatar's random option is on, so a site that turns it off ships no picker script. The footer deals its cats as a fan; the single-image swap stays with the showcase.
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
<script>
|
|
6
|
-
import {
|
|
6
|
+
import { mountRandomFans } from './dist/random-image.js';
|
|
7
7
|
|
|
8
|
-
void
|
|
8
|
+
void mountRandomFans(document);
|
|
9
9
|
</script>
|
package/FooterBrand.astro
CHANGED
|
@@ -16,7 +16,7 @@ interface Props {
|
|
|
16
16
|
links: readonly SiteLink[];
|
|
17
17
|
/** Show the decorative avatar. Defaults to `true`. */
|
|
18
18
|
avatar?: boolean;
|
|
19
|
-
/**
|
|
19
|
+
/** Deal the avatar as a fan of three random cat heads that turns through six per page view. Defaults to `true`. */
|
|
20
20
|
randomAvatar?: boolean;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -31,7 +31,7 @@ const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarMan
|
|
|
31
31
|
<div class="hagilight-brand__lead">
|
|
32
32
|
<div class="hagilight-brand__title">
|
|
33
33
|
{avatarOptions.avatar && (
|
|
34
|
-
<picture class="hagilight-brand__avatar" data-random-
|
|
34
|
+
<picture class="hagilight-brand__avatar" data-random-fan={avatarPool && randomPoolAttribute(avatarPool)}>
|
|
35
35
|
<source type="image/avif" srcset={avatarAvif.src} />
|
|
36
36
|
<source type="image/webp" srcset={avatarWebp.src} />
|
|
37
37
|
<img src={avatarWebp.src} {...footerAvatarImageAttributes()} />
|
|
@@ -116,7 +116,7 @@ const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarMan
|
|
|
116
116
|
min-width: 0;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
/* The decorative avatar keeps a fixed
|
|
119
|
+
/* The decorative avatar keeps a fixed box, so neither the fan nor a swap ever moves the headline. */
|
|
120
120
|
.hagilight-brand__avatar {
|
|
121
121
|
display: block;
|
|
122
122
|
flex: none;
|
|
@@ -132,6 +132,81 @@ const avatarPool = avatarOptions.randomAvatar ? randomPoolFromManifest(avatarMan
|
|
|
132
132
|
object-fit: cover;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
/*
|
|
136
|
+
* The fan: three 56 px cards pivot on a point below the stack, so the side cards open like a hand of cards.
|
|
137
|
+
* The vendored default is the first centre card and fades out as the random cards are dealt over it. Each
|
|
138
|
+
* turn the left card leaves, the others shift left and a card waiting off stage enters on the right.
|
|
139
|
+
*/
|
|
140
|
+
.hagilight-brand__avatar[data-random-fan] {
|
|
141
|
+
--_card-ring: var(--sl-color-bg, var(--ifm-background-color, Canvas));
|
|
142
|
+
position: relative;
|
|
143
|
+
width: 112px;
|
|
144
|
+
height: 76px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.hagilight-brand__avatar[data-random-fan] img,
|
|
148
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card) {
|
|
149
|
+
position: absolute;
|
|
150
|
+
top: 10px;
|
|
151
|
+
left: 28px;
|
|
152
|
+
width: 56px;
|
|
153
|
+
height: 56px;
|
|
154
|
+
box-shadow: 0 0 0 2px var(--_card-ring), 0 3px 8px -2px rgb(0 0 0 / 0.35);
|
|
155
|
+
transform-origin: 50% 140%;
|
|
156
|
+
transition: opacity 320ms ease-out, transform 760ms cubic-bezier(0.16, 1, 0.3, 1);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan) {
|
|
160
|
+
position: absolute;
|
|
161
|
+
inset: 0;
|
|
162
|
+
display: block;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.hagilight-brand__avatar[data-random-fan] img[data-fan-out] {
|
|
166
|
+
opacity: 0;
|
|
167
|
+
transform: scale(0.9);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card) {
|
|
171
|
+
z-index: 0;
|
|
172
|
+
opacity: 0;
|
|
173
|
+
transform: scale(0.6);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="0"]) {
|
|
177
|
+
z-index: 1;
|
|
178
|
+
opacity: 1;
|
|
179
|
+
transform: translate(-6px, 1px) rotate(-17deg);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="1"]) {
|
|
183
|
+
z-index: 3;
|
|
184
|
+
opacity: 1;
|
|
185
|
+
transform: none;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="2"]) {
|
|
189
|
+
z-index: 2;
|
|
190
|
+
opacity: 1;
|
|
191
|
+
transform: translate(6px, 1px) rotate(17deg);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="3"]),
|
|
195
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="4"]) {
|
|
196
|
+
transform: translate(10px, 0) rotate(34deg) scale(0.7);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card[data-slot="5"]) {
|
|
200
|
+
transform: translate(-10px, 0) rotate(-36deg) scale(0.7);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@media (prefers-reduced-motion: reduce) {
|
|
204
|
+
.hagilight-brand__avatar[data-random-fan] img,
|
|
205
|
+
.hagilight-brand__avatar[data-random-fan] :global(.hagilight-fan__card) {
|
|
206
|
+
transition: none;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
135
210
|
/* Hidden in a brand block narrower than 360 px, where the headline needs the full width. */
|
|
136
211
|
@container hagilight-brand (max-width: 359.98px) {
|
|
137
212
|
.hagilight-brand__avatar {
|
package/README.md
CHANGED
|
@@ -39,11 +39,11 @@ const links = resolveSiteLinks('en-US');
|
|
|
39
39
|
|
|
40
40
|
## Footer avatar
|
|
41
41
|
|
|
42
|
-
The footer brand block shows one decorative HagiCode avatar beside the headline. `avatar` defaults to `true`; `avatar={false}` removes the element and its request. The default is `assets/footer/avatar.avif` (128 px, with `avatar.webp` as the fallback) in a 64 px box, hidden below a 360 px container. `randomAvatar` defaults to `true`:
|
|
42
|
+
The footer brand block shows one decorative HagiCode avatar beside the headline. `avatar` defaults to `true`; `avatar={false}` removes the element and its request. The default is `assets/footer/avatar.avif` (128 px, with `avatar.webp` as the fallback) in a 64 px box, hidden below a 360 px container. `randomAvatar` defaults to `true`: the box becomes a 112 × 76 px stage, and once the footer nears the viewport the browser picks 6 distinct entries of the `cat-head-gallery` pool listed in `assets/footer/manifest.json`, preloads them, and deals three as a fan (the default fades out under them). All six loaded: every 3.6 seconds the left card leaves, the others shift left and a waiting card enters on the right, paused while the footer is off screen or the tab is hidden. Fewer than six loaded (or `prefers-reduced-motion: reduce`, which fetches only three) gives a still fan of three; fewer than three keeps the default. The browser picker is `@hagicode/hagilight-core/random-image` (`mountRandomFans`; browser-safe), preloads with a plain `Image()`, not `fetch`, waits up to 3 seconds per image, and makes no request under a data-saver preference. The slot carries `data-random-fan` (the same validated pool list); the single-image swap (`data-random-pool`, `mountRandomImages`) is kept for the showcase illustration. `randomAvatar={false}` ships no pool list and no picker script.
|
|
43
43
|
|
|
44
44
|
`@hagicode/hagilight-core/footer-avatar` resolves the two options (a non-boolean throws a `TypeError`) and gives the shared image attributes. The Astro footers and the Docusaurus footer render the same `<picture class="hagilight-brand__avatar">` markup.
|
|
45
45
|
|
|
46
|
-
A site with a strict `img-src` policy must allow `https://img-gen.hagicode.com` for the
|
|
46
|
+
A site with a strict `img-src` policy must allow `https://img-gen.hagicode.com` for the cat fan. Without it the fan fails and the default stays.
|
|
47
47
|
|
|
48
48
|
**Pool refresh.** The pool is the `pool` object in `assets/footer/manifest.json`: `album`, `maxBytes` (40 KiB) and `entries` (`key`, `bytes`). To change it, take keys from the album's `index.json`, keep 12 to 200 unique keys each at or under `maxBytes`, audit each one as text-free, current and private-data free, and update the list. Then run `npm test`: `test/footer-imagery.test.mjs` fails on a missing file, a size or dimension mismatch, an entry over the cap, or a pool outside 12 to 200. The vendored default is `source.objectKey` in the same manifest.
|
|
49
49
|
|
|
@@ -65,8 +65,8 @@ continuation chip. It bundles its logo and favicon locally; no custom CSS,
|
|
|
65
65
|
animation setup, feature package or analytics is required. By default it also
|
|
66
66
|
requests one image from `img-gen.hagicode.com`; the [splash image](#splash-image)
|
|
67
67
|
section describes that request and how to switch it off.
|
|
68
|
-
The
|
|
69
|
-
|
|
68
|
+
The departures board (see [below](#departures-board)) replaces the old destination/base/origin
|
|
69
|
+
trace; the page does not perform the official website's locale detection itself. Installing core alone never
|
|
70
70
|
changes routes. Consumers that do not import this page keep their current root.
|
|
71
71
|
|
|
72
72
|
`destination` and nonblank `siteName` are required. Optional `locale` (default
|
|
@@ -150,6 +150,35 @@ A site whose Content Security Policy blocks the image host should either set
|
|
|
150
150
|
`splash={false}` or allow `img-src https://img-gen.hagicode.com` and
|
|
151
151
|
`connect-src https://img-gen.hagicode.com`.
|
|
152
152
|
|
|
153
|
+
### Departures board
|
|
154
|
+
|
|
155
|
+
Beside the route sweep, the page shows a board that scrolls through the HagiCode ecosystem sites and stops
|
|
156
|
+
on this site. Every row is real catalog data, localized to the `locale` prop: the site name, its
|
|
157
|
+
description (or its host when it has none), and the host. The caption is the localized "Ecosystem Sites"
|
|
158
|
+
label and the number of sites listed. Nothing is invented: the rows come from the same
|
|
159
|
+
`related-sites.json` the footer uses, so a site added there appears on the board.
|
|
160
|
+
|
|
161
|
+
The reel is driven by the same `--run` variable and easing as the route sweep, so it comes to rest as the
|
|
162
|
+
beam finishes, and this site's row then fills from the left, the same landing as the continue chip. It
|
|
163
|
+
adds no timer and does not move forwarding. The finished state is also the static markup: without
|
|
164
|
+
scripting, or with reduced motion, you see the five-row window already stopped on this site. The board is
|
|
165
|
+
decorative (`aria-hidden`); the heading, message and links carry the page.
|
|
166
|
+
|
|
167
|
+
```astro
|
|
168
|
+
<RootTransit destination="/en-US/" siteName="My site" board={{ siteId: 'newbe-blog' }} />
|
|
169
|
+
<RootTransit destination="/en-US/" siteName="My site" board={{ relatedSites: [{ id: 'docs', name: 'Docs', url: 'https://docs.example/' }] }} />
|
|
170
|
+
<RootTransit destination="/en-US/" siteName="My site" board={false} />
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
| Option | Effect |
|
|
174
|
+
| --- | --- |
|
|
175
|
+
| `siteId` | Leaves that catalog id out, as the footer does, so a site is not listed on its own board. A site whose URL equals `Astro.site` is also left out. |
|
|
176
|
+
| `relatedSites` | Replaces the bundled catalog (`id`, localized `name`, optional `description`, `url`). |
|
|
177
|
+
| `false` | No board. |
|
|
178
|
+
|
|
179
|
+
`@hagicode/hagilight-core/root-transit-board` exposes `resolveTransitBoard()`, the pure function that builds
|
|
180
|
+
the rows. It is build-time only and reads nothing from the browser.
|
|
181
|
+
|
|
153
182
|
### Locale monitor
|
|
154
183
|
|
|
155
184
|
`localeMonitor` is off unless you set it. It shows what the browser's language inputs would resolve to,
|
package/RootTransit.astro
CHANGED
|
@@ -3,6 +3,7 @@ import logo from './logo.png';
|
|
|
3
3
|
import favicon from './favicon.ico';
|
|
4
4
|
import { DEFAULT_LOCALE, resolveLocaleMonitor, resolveTransitDestination, type LocaleMonitorOptions } from './dist/root-transit.js';
|
|
5
5
|
import { resolveSplashConfig, type SplashOverrides } from './dist/splash-images.js';
|
|
6
|
+
import { resolveTransitBoard, type TransitBoardOptions } from './dist/root-transit-board.js';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
destination: string;
|
|
@@ -16,6 +17,8 @@ interface Props {
|
|
|
16
17
|
splash?: false | SplashOverrides;
|
|
17
18
|
/** Shows the locale monitor: what the browser inputs resolve to. It never changes the target or the links. */
|
|
18
19
|
localeMonitor?: boolean | LocaleMonitorOptions;
|
|
20
|
+
/** `false` hides the departures board; an object names this site in the catalog or replaces the bundled sites. */
|
|
21
|
+
board?: false | TransitBoardOptions;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
const {
|
|
@@ -26,6 +29,7 @@ const {
|
|
|
26
29
|
links = [],
|
|
27
30
|
splash,
|
|
28
31
|
localeMonitor,
|
|
32
|
+
board: boardOption,
|
|
29
33
|
} = Astro.props;
|
|
30
34
|
if (!siteName?.trim()) throw new TypeError('Hagilight RootTransit: siteName is required.');
|
|
31
35
|
const splashConfig = resolveSplashConfig(splash);
|
|
@@ -42,12 +46,7 @@ const site = Astro.site ?? Astro.url;
|
|
|
42
46
|
const href = resolveTransitDestination(destination, { site, base });
|
|
43
47
|
const localeLinks = links.map((link) => ({ ...link, href: resolveTransitDestination(link.destination, { site, base }) }));
|
|
44
48
|
const route = new URL(href, site).pathname;
|
|
45
|
-
const
|
|
46
|
-
['destination', route],
|
|
47
|
-
['base', base],
|
|
48
|
-
['origin', new URL(site).origin],
|
|
49
|
-
['source', 'site configuration'],
|
|
50
|
-
];
|
|
49
|
+
const board = boardOption === false ? null : resolveTransitBoard({ locale, site, siteName, route, ...boardOption });
|
|
51
50
|
---
|
|
52
51
|
|
|
53
52
|
<!doctype html>
|
|
@@ -118,6 +117,18 @@ const trace = [
|
|
|
118
117
|
initial-value: 1;
|
|
119
118
|
}
|
|
120
119
|
|
|
120
|
+
@property --lock {
|
|
121
|
+
syntax: '<number>';
|
|
122
|
+
inherits: true;
|
|
123
|
+
initial-value: 1;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@property --reel-blur {
|
|
127
|
+
syntax: '<number>';
|
|
128
|
+
inherits: true;
|
|
129
|
+
initial-value: 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
121
132
|
*,
|
|
122
133
|
*::before,
|
|
123
134
|
*::after {
|
|
@@ -449,6 +460,172 @@ const trace = [
|
|
|
449
460
|
}
|
|
450
461
|
}
|
|
451
462
|
|
|
463
|
+
/* ── 出发看板:生态站点(真实目录数据,随语言本地化)滚过,停在这个站点 ── */
|
|
464
|
+
.board {
|
|
465
|
+
--row: 3.5rem;
|
|
466
|
+
container-type: inline-size;
|
|
467
|
+
margin: 0;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
:global(html[data-transit-ready]) .board {
|
|
471
|
+
animation: boardIn 320ms var(--ease-out) both;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
@keyframes boardIn {
|
|
475
|
+
from {
|
|
476
|
+
opacity: 0;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
.board-caption {
|
|
481
|
+
display: flex;
|
|
482
|
+
justify-content: space-between;
|
|
483
|
+
gap: 1rem;
|
|
484
|
+
margin: 0 0 0.5rem;
|
|
485
|
+
color: var(--muted);
|
|
486
|
+
font-family: var(--font-mono);
|
|
487
|
+
font-size: 0.8125rem;
|
|
488
|
+
line-height: 1.4;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/* 窗口只露出几行,上下渐隐;目标行落在正中,不被渐隐遮住 */
|
|
492
|
+
.board-window {
|
|
493
|
+
height: calc(var(--shown) * var(--row));
|
|
494
|
+
overflow: hidden;
|
|
495
|
+
border-block: 1px solid var(--line);
|
|
496
|
+
mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
|
|
497
|
+
-webkit-mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/* --run 与上方路由光束同时长、同缓动:滚动停下的瞬间,目标行正好对齐 */
|
|
501
|
+
.board-reel {
|
|
502
|
+
--run: 1;
|
|
503
|
+
margin: 0;
|
|
504
|
+
padding: 0;
|
|
505
|
+
list-style: none;
|
|
506
|
+
transform: translateY(calc(var(--run) * var(--travel) * var(--row) * -1));
|
|
507
|
+
filter: blur(calc(var(--reel-blur) * 1px));
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
:global(html[data-transit-ready]) .board-reel {
|
|
511
|
+
animation:
|
|
512
|
+
routeRun var(--run-dur, 1250ms) cubic-bezier(0.3, 0.55, 0.15, 1) both,
|
|
513
|
+
reelBlur var(--run-dur, 1250ms) linear both;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/* 全速时略微虚化,进站时恢复清晰 */
|
|
517
|
+
@keyframes reelBlur {
|
|
518
|
+
0% {
|
|
519
|
+
--reel-blur: 0;
|
|
520
|
+
}
|
|
521
|
+
18% {
|
|
522
|
+
--reel-blur: 1;
|
|
523
|
+
}
|
|
524
|
+
62% {
|
|
525
|
+
--reel-blur: 0.4;
|
|
526
|
+
}
|
|
527
|
+
100% {
|
|
528
|
+
--reel-blur: 0;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
.board-row {
|
|
533
|
+
position: relative;
|
|
534
|
+
display: grid;
|
|
535
|
+
grid-template-areas: 'name aside' 'detail aside';
|
|
536
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
537
|
+
grid-template-rows: 1fr 1fr;
|
|
538
|
+
align-items: center;
|
|
539
|
+
column-gap: 1rem;
|
|
540
|
+
height: var(--row);
|
|
541
|
+
padding-inline: 0.75rem;
|
|
542
|
+
border-top: 1px solid var(--line);
|
|
543
|
+
color: var(--muted);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
.board-row:first-child {
|
|
547
|
+
border-top: 0;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
.board-name,
|
|
551
|
+
.board-detail {
|
|
552
|
+
min-width: 0;
|
|
553
|
+
overflow: hidden;
|
|
554
|
+
text-overflow: ellipsis;
|
|
555
|
+
white-space: nowrap;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
.board-name {
|
|
559
|
+
grid-area: name;
|
|
560
|
+
align-self: end;
|
|
561
|
+
color: var(--ink);
|
|
562
|
+
font-size: 0.9375rem;
|
|
563
|
+
font-weight: 600;
|
|
564
|
+
line-height: 1.35;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
.board-detail {
|
|
568
|
+
grid-area: detail;
|
|
569
|
+
align-self: start;
|
|
570
|
+
font-size: 0.8125rem;
|
|
571
|
+
line-height: 1.5;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
.board-aside {
|
|
575
|
+
grid-area: aside;
|
|
576
|
+
display: none;
|
|
577
|
+
font-family: var(--font-mono);
|
|
578
|
+
font-size: 0.75rem;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
@container (min-width: 32rem) {
|
|
582
|
+
.board-aside {
|
|
583
|
+
display: block;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/* 目标行:背景从左向右填满,和下方「继续」按钮同一种落点语言 */
|
|
588
|
+
.board-row[data-board-destination] {
|
|
589
|
+
--lock: 1;
|
|
590
|
+
isolation: isolate;
|
|
591
|
+
color: var(--ink);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
.board-row[data-board-destination]::before {
|
|
595
|
+
content: '';
|
|
596
|
+
position: absolute;
|
|
597
|
+
inset: 0;
|
|
598
|
+
z-index: -1;
|
|
599
|
+
background: linear-gradient(90deg, var(--accent) 0 3px, color-mix(in srgb, var(--accent) 10%, transparent) 3px);
|
|
600
|
+
transform: scaleX(var(--lock));
|
|
601
|
+
transform-origin: left;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
.board-row[data-board-destination] .board-name,
|
|
605
|
+
.board-row[data-board-destination] .board-aside {
|
|
606
|
+
color: var(--accent);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
.board-row[data-board-destination] .board-detail {
|
|
610
|
+
color: var(--ink);
|
|
611
|
+
font-family: var(--font-mono);
|
|
612
|
+
font-size: 0.75rem;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
:global(html[data-transit-ready]) .board-row[data-board-destination] {
|
|
616
|
+
animation: boardLock 380ms var(--ease-out) both;
|
|
617
|
+
animation-delay: calc(var(--run-dur, 1250ms) * 0.8);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
@keyframes boardLock {
|
|
621
|
+
from {
|
|
622
|
+
--lock: 0;
|
|
623
|
+
}
|
|
624
|
+
to {
|
|
625
|
+
--lock: 1;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
452
629
|
/* ── 语言列表:真实链接,也是手动选择入口 ── */
|
|
453
630
|
.locales-label {
|
|
454
631
|
margin: 0 0 0.75rem;
|
|
@@ -573,7 +750,8 @@ const trace = [
|
|
|
573
750
|
@media (prefers-reduced-motion: reduce) {
|
|
574
751
|
*, *::before, *::after { animation: none !important; transition: none !important; }
|
|
575
752
|
.splash { transition: none; }
|
|
576
|
-
.run { --run: 1; }
|
|
753
|
+
.run, .board-reel { --run: 1; }
|
|
754
|
+
.board-reel { filter: none; }
|
|
577
755
|
.locales a:hover {
|
|
578
756
|
transform: none;
|
|
579
757
|
}
|
|
@@ -581,6 +759,7 @@ const trace = [
|
|
|
581
759
|
|
|
582
760
|
@media (forced-colors: active) {
|
|
583
761
|
.splash { display: none; }
|
|
762
|
+
.board-row[data-board-destination] { outline: 2px solid Highlight; outline-offset: -2px; }
|
|
584
763
|
.locales a[aria-current='true'] {
|
|
585
764
|
outline: 2px solid Highlight;
|
|
586
765
|
forced-color-adjust: none;
|
|
@@ -608,13 +787,22 @@ const trace = [
|
|
|
608
787
|
<h1 class="headline">{heading}</h1>
|
|
609
788
|
<p class="status">{message}</p>
|
|
610
789
|
</div>
|
|
611
|
-
|
|
612
|
-
{
|
|
613
|
-
<
|
|
614
|
-
|
|
790
|
+
{board && (
|
|
791
|
+
<section class="board" data-transit-board aria-hidden="true" style={`--shown: ${board.shown}; --travel: ${board.travel}`}>
|
|
792
|
+
<p class="board-caption"><span>{board.label}</span><span>{board.count}</span></p>
|
|
793
|
+
<div class="board-window">
|
|
794
|
+
<ol class="board-reel">
|
|
795
|
+
{board.rows.map((row) => (
|
|
796
|
+
<li class="board-row" data-board-site={row.id} data-board-destination={row.destination ? '' : undefined}>
|
|
797
|
+
<span class="board-name">{row.name}</span>
|
|
798
|
+
<span class="board-detail">{row.detail}</span>
|
|
799
|
+
<span class="board-aside">{row.aside}</span>
|
|
800
|
+
</li>
|
|
801
|
+
))}
|
|
802
|
+
</ol>
|
|
615
803
|
</div>
|
|
616
|
-
|
|
617
|
-
|
|
804
|
+
</section>
|
|
805
|
+
)}
|
|
618
806
|
<nav class="locales" aria-label={continueLabel}>
|
|
619
807
|
<ul>
|
|
620
808
|
<li><a href={href} data-transit-continue aria-current="true"><span class="chip-label">{continueLabel}</span><span class="chip-filled" aria-hidden="true">{continueLabel}</span></a></li>
|
package/dist/random-image.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export declare const RANDOM_POOL_ATTRIBUTE = "data-random-pool";
|
|
|
11
11
|
export declare const RANDOM_POOL_MIN_ENTRIES = 12;
|
|
12
12
|
export declare const RANDOM_POOL_MAX_ENTRIES = 200;
|
|
13
13
|
export declare const RANDOM_IMAGE_TIMEOUT_MS = 3000;
|
|
14
|
+
export declare const RANDOM_FAN_ATTRIBUTE = "data-random-fan";
|
|
15
|
+
/** Cards shown at once, and cards picked per page view; the rest wait off stage and take turns. */
|
|
16
|
+
export declare const FAN_VISIBLE_CARDS = 3;
|
|
17
|
+
export declare const FAN_DECK_CARDS = 6;
|
|
18
|
+
export declare const FAN_TURN_MS = 3600;
|
|
14
19
|
export interface PreloadImage {
|
|
15
20
|
src: string;
|
|
16
21
|
onload: (() => void) | null;
|
|
@@ -27,6 +32,16 @@ export interface RandomImageEnvironment {
|
|
|
27
32
|
/** Defaults to the browser's data-saver preference. */
|
|
28
33
|
readonly saveData?: () => boolean;
|
|
29
34
|
}
|
|
35
|
+
export interface RandomFanEnvironment extends RandomImageEnvironment {
|
|
36
|
+
/** Defaults to the `prefers-reduced-motion` media query. The fan then stays still at its first three cards. */
|
|
37
|
+
readonly reducedMotion?: () => boolean;
|
|
38
|
+
/** Reports when a slot is on screen: `onChange(true)` as it nears the viewport and again on every change. Defaults to an IntersectionObserver. */
|
|
39
|
+
readonly watch?: (slot: Element, onChange: (visible: boolean) => void) => void;
|
|
40
|
+
/** Defaults to `document.hidden`. */
|
|
41
|
+
readonly tabHidden?: () => boolean;
|
|
42
|
+
/** Starts a repeating timer and returns its stop function. Defaults to `setInterval`. */
|
|
43
|
+
readonly every?: (callback: () => void, ms: number) => () => void;
|
|
44
|
+
}
|
|
30
45
|
/**
|
|
31
46
|
* Checks a pool: 12 to 200 unique `<album>/<key>.avif` object paths, all from one album. Throws a `TypeError`, so a
|
|
32
47
|
* bad pool fails the build instead of the page.
|
|
@@ -34,6 +49,8 @@ export interface RandomImageEnvironment {
|
|
|
34
49
|
export declare function validateRandomPool(entries: unknown): readonly string[];
|
|
35
50
|
/** Picks one entry uniformly. Out-of-range or non-finite random values clamp to the first or last entry. */
|
|
36
51
|
export declare function pickRandomEntry<T>(entries: readonly T[], random?: () => number): T;
|
|
52
|
+
/** Picks up to `count` distinct entries uniformly, in random order (a partial Fisher-Yates shuffle of a copy). */
|
|
53
|
+
export declare function pickRandomEntries<T>(entries: readonly T[], count: number, random?: () => number): T[];
|
|
37
54
|
/** The full image URL of an R2 object path. */
|
|
38
55
|
export declare function poolImageUrl(objectPath: string): string;
|
|
39
56
|
/**
|
|
@@ -67,3 +84,13 @@ export interface RandomPoolManifest {
|
|
|
67
84
|
export declare function randomPoolFromManifest(pool: RandomPoolManifest): readonly string[];
|
|
68
85
|
/** Build-time: the `data-random-pool` attribute value for a validated pool. */
|
|
69
86
|
export declare function randomPoolAttribute(entries: readonly string[]): string;
|
|
87
|
+
/** The fan slot of deck card `card` after `turn` turns: 0 left, 1 centre, 2 right, then the off-stage places in line. */
|
|
88
|
+
export declare function fanSlot(card: number, turn: number, count?: number): number;
|
|
89
|
+
/**
|
|
90
|
+
* Runs the footer fan for every `[data-random-fan]` slot under `root` that has not been handled yet. The slot keeps
|
|
91
|
+
* its vendored default until the footer nears the viewport; then six random pool entries are preloaded and, when
|
|
92
|
+
* all six load, dealt out as a fan of three that turns through the six while the slot is on screen. Fewer than six
|
|
93
|
+
* loaded cards make a still fan of three, fewer than three keep the default. One promise per slot, each resolving
|
|
94
|
+
* `true` when the fan was dealt; none rejects.
|
|
95
|
+
*/
|
|
96
|
+
export declare function mountRandomFans(root: ParentNode, env?: RandomFanEnvironment): Promise<boolean>[];
|
package/dist/random-image.js
CHANGED
|
@@ -11,6 +11,11 @@ export const RANDOM_POOL_ATTRIBUTE = 'data-random-pool';
|
|
|
11
11
|
export const RANDOM_POOL_MIN_ENTRIES = 12;
|
|
12
12
|
export const RANDOM_POOL_MAX_ENTRIES = 200;
|
|
13
13
|
export const RANDOM_IMAGE_TIMEOUT_MS = 3000;
|
|
14
|
+
export const RANDOM_FAN_ATTRIBUTE = 'data-random-fan';
|
|
15
|
+
/** Cards shown at once, and cards picked per page view; the rest wait off stage and take turns. */
|
|
16
|
+
export const FAN_VISIBLE_CARDS = 3;
|
|
17
|
+
export const FAN_DECK_CARDS = 6;
|
|
18
|
+
export const FAN_TURN_MS = 3600;
|
|
14
19
|
const OBJECT_PATH_PATTERN = /^([a-z0-9][a-z0-9_-]*)\/[a-z0-9][a-z0-9_-]*\.avif$/u;
|
|
15
20
|
/**
|
|
16
21
|
* Checks a pool: 12 to 200 unique `<album>/<key>.avif` object paths, all from one album. Throws a `TypeError`, so a
|
|
@@ -33,11 +38,24 @@ export function validateRandomPool(entries) {
|
|
|
33
38
|
throw new TypeError('Hagilight random pool entries must be unique.');
|
|
34
39
|
return Object.freeze([...entries]);
|
|
35
40
|
}
|
|
41
|
+
/** Clamps a random value into [0, 1); a non-finite value counts as 0. */
|
|
42
|
+
function unitFraction(random) {
|
|
43
|
+
const value = random();
|
|
44
|
+
return Number.isFinite(value) ? Math.min(Math.max(value, 0), 1 - Number.EPSILON) : 0;
|
|
45
|
+
}
|
|
36
46
|
/** Picks one entry uniformly. Out-of-range or non-finite random values clamp to the first or last entry. */
|
|
37
47
|
export function pickRandomEntry(entries, random = Math.random) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
return entries[Math.floor(unitFraction(random) * entries.length)];
|
|
49
|
+
}
|
|
50
|
+
/** Picks up to `count` distinct entries uniformly, in random order (a partial Fisher-Yates shuffle of a copy). */
|
|
51
|
+
export function pickRandomEntries(entries, count, random = Math.random) {
|
|
52
|
+
const copy = [...entries];
|
|
53
|
+
const take = Math.min(Math.max(Math.floor(count), 0), copy.length);
|
|
54
|
+
for (let index = 0; index < take; index += 1) {
|
|
55
|
+
const other = index + Math.floor(unitFraction(random) * (copy.length - index));
|
|
56
|
+
[copy[index], copy[other]] = [copy[other], copy[index]];
|
|
57
|
+
}
|
|
58
|
+
return copy.slice(0, take);
|
|
41
59
|
}
|
|
42
60
|
/** The full image URL of an R2 object path. */
|
|
43
61
|
export function poolImageUrl(objectPath) {
|
|
@@ -131,3 +149,96 @@ export function randomPoolFromManifest(pool) {
|
|
|
131
149
|
export function randomPoolAttribute(entries) {
|
|
132
150
|
return JSON.stringify(validateRandomPool(entries));
|
|
133
151
|
}
|
|
152
|
+
/** The fan slot of deck card `card` after `turn` turns: 0 left, 1 centre, 2 right, then the off-stage places in line. */
|
|
153
|
+
export function fanSlot(card, turn, count = FAN_DECK_CARDS) {
|
|
154
|
+
return (((card - turn) % count) + count) % count;
|
|
155
|
+
}
|
|
156
|
+
function prefersReducedMotion() {
|
|
157
|
+
return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
158
|
+
}
|
|
159
|
+
function watchViewport(slot, onChange) {
|
|
160
|
+
if (typeof IntersectionObserver !== 'function') {
|
|
161
|
+
onChange(true);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
new IntersectionObserver((entries) => onChange(entries[entries.length - 1]?.isIntersecting === true), { rootMargin: '0px 0px 160px 0px' }).observe(slot);
|
|
165
|
+
}
|
|
166
|
+
function deal(slot, defaultImage, urls, cards) {
|
|
167
|
+
const stage = slot.ownerDocument.createElement('span');
|
|
168
|
+
stage.className = 'hagilight-fan';
|
|
169
|
+
const deck = urls.slice(0, cards).map((url) => {
|
|
170
|
+
const card = (defaultImage ? defaultImage.cloneNode(false) : slot.ownerDocument.createElement('img'));
|
|
171
|
+
card.removeAttribute('srcset');
|
|
172
|
+
card.removeAttribute('sizes');
|
|
173
|
+
card.removeAttribute('loading');
|
|
174
|
+
card.setAttribute('class', 'hagilight-fan__card');
|
|
175
|
+
card.setAttribute('src', url);
|
|
176
|
+
stage.append(card);
|
|
177
|
+
return card;
|
|
178
|
+
});
|
|
179
|
+
slot.append(stage);
|
|
180
|
+
// Commit the cards' resting pose, so the first slots below animate into a fan instead of appearing in it.
|
|
181
|
+
void slot.offsetWidth;
|
|
182
|
+
defaultImage?.setAttribute('data-fan-out', '');
|
|
183
|
+
deck.forEach((card, index) => card.setAttribute('data-slot', String(index)));
|
|
184
|
+
return deck;
|
|
185
|
+
}
|
|
186
|
+
async function mountFan(slot, env) {
|
|
187
|
+
slot.setAttribute('data-random-state', 'default');
|
|
188
|
+
if ((env.saveData ?? dataSaverEnabled)())
|
|
189
|
+
return false;
|
|
190
|
+
let pool;
|
|
191
|
+
try {
|
|
192
|
+
pool = validateRandomPool(JSON.parse(slot.getAttribute(RANDOM_FAN_ATTRIBUTE) ?? 'null'));
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
// Nothing is fetched until the footer nears the viewport, so the cards deal out where they can be seen.
|
|
198
|
+
let visible = false;
|
|
199
|
+
let near;
|
|
200
|
+
const arrived = new Promise((resolve) => { near = resolve; });
|
|
201
|
+
(env.watch ?? watchViewport)(slot, (isVisible) => {
|
|
202
|
+
visible = isVisible;
|
|
203
|
+
if (isVisible)
|
|
204
|
+
near();
|
|
205
|
+
});
|
|
206
|
+
await arrived;
|
|
207
|
+
const random = env.random ?? Math.random;
|
|
208
|
+
// A full deck turns; a short one, or reduced motion, keeps the first three cards still, so only those are fetched.
|
|
209
|
+
const wantsTurns = !(env.reducedMotion ?? prefersReducedMotion)();
|
|
210
|
+
const urls = pickRandomEntries(pool, wantsTurns ? FAN_DECK_CARDS : FAN_VISIBLE_CARDS, random).map(poolImageUrl);
|
|
211
|
+
const loaded = (await Promise.all(urls.map(async (url) => ((await preloadImage(url, env)) ? url : '')))).filter(Boolean);
|
|
212
|
+
if (loaded.length < FAN_VISIBLE_CARDS)
|
|
213
|
+
return false;
|
|
214
|
+
const turning = wantsTurns && loaded.length === FAN_DECK_CARDS;
|
|
215
|
+
const deck = deal(slot, slot.querySelector('img'), loaded, turning ? FAN_DECK_CARDS : FAN_VISIBLE_CARDS);
|
|
216
|
+
slot.setAttribute('data-random-state', 'fan');
|
|
217
|
+
if (turning) {
|
|
218
|
+
let turn = 0;
|
|
219
|
+
let stop = () => { };
|
|
220
|
+
stop = (env.every ?? ((callback, ms) => {
|
|
221
|
+
const handle = setInterval(callback, ms);
|
|
222
|
+
return () => clearInterval(handle);
|
|
223
|
+
}))(() => {
|
|
224
|
+
if (slot.isConnected === false)
|
|
225
|
+
stop();
|
|
226
|
+
else if (visible && !(env.tabHidden ?? (() => typeof document !== 'undefined' && document.hidden))()) {
|
|
227
|
+
turn += 1;
|
|
228
|
+
deck.forEach((card, index) => card.setAttribute('data-slot', String(fanSlot(index, turn, deck.length))));
|
|
229
|
+
}
|
|
230
|
+
}, FAN_TURN_MS);
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Runs the footer fan for every `[data-random-fan]` slot under `root` that has not been handled yet. The slot keeps
|
|
236
|
+
* its vendored default until the footer nears the viewport; then six random pool entries are preloaded and, when
|
|
237
|
+
* all six load, dealt out as a fan of three that turns through the six while the slot is on screen. Fewer than six
|
|
238
|
+
* loaded cards make a still fan of three, fewer than three keep the default. One promise per slot, each resolving
|
|
239
|
+
* `true` when the fan was dealt; none rejects.
|
|
240
|
+
*/
|
|
241
|
+
export function mountRandomFans(root, env = {}) {
|
|
242
|
+
return Array.from(root.querySelectorAll(`[${RANDOM_FAN_ATTRIBUTE}]:not([data-random-state])`))
|
|
243
|
+
.map((slot) => mountFan(slot, env).catch(() => false));
|
|
244
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type RelatedSite } from './links.js';
|
|
2
|
+
/** Rows the window shows at once; the destination lands on the middle one. */
|
|
3
|
+
export declare const TRANSIT_BOARD_WINDOW = 5;
|
|
4
|
+
export interface TransitBoardOptions {
|
|
5
|
+
/** This site's id in the related-sites catalog, so the board lists the other sites. */
|
|
6
|
+
siteId?: string;
|
|
7
|
+
/** Replaces the bundled HagiCode catalog. */
|
|
8
|
+
relatedSites?: readonly RelatedSite[];
|
|
9
|
+
}
|
|
10
|
+
export interface TransitBoardInput extends TransitBoardOptions {
|
|
11
|
+
locale: string;
|
|
12
|
+
site: string | URL;
|
|
13
|
+
siteName: string;
|
|
14
|
+
/** Pathname the page forwards to. */
|
|
15
|
+
route: string;
|
|
16
|
+
}
|
|
17
|
+
export interface TransitBoardRow {
|
|
18
|
+
id: string;
|
|
19
|
+
name: string;
|
|
20
|
+
/** The site's own description, or its host when it has none. */
|
|
21
|
+
detail: string;
|
|
22
|
+
/** The host, shown beside a described row; empty when `detail` already is the host. */
|
|
23
|
+
aside: string;
|
|
24
|
+
destination: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface TransitBoard {
|
|
27
|
+
/** The localized "Ecosystem Sites" label. */
|
|
28
|
+
label: string;
|
|
29
|
+
/** How many other sites the board lists. */
|
|
30
|
+
count: number;
|
|
31
|
+
/** The ecosystem sites, then this site, then the first of them again so the destination has rows on both sides. */
|
|
32
|
+
rows: readonly TransitBoardRow[];
|
|
33
|
+
/** Rows visible in the window. */
|
|
34
|
+
shown: number;
|
|
35
|
+
/** Rows the reel moves before the destination sits on the focus row. */
|
|
36
|
+
travel: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The departures board: every row is catalog data, localized to `locale`, and the last stop is this site. Build-time
|
|
40
|
+
* only; nothing here reads the browser, so the finished state is also the markup a no-script visitor gets.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveTransitBoard({ locale, site, siteName, route, siteId, relatedSites }: TransitBoardInput): TransitBoard;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { resolveSiteLinks } from './links.js';
|
|
2
|
+
/** Rows the window shows at once; the destination lands on the middle one. */
|
|
3
|
+
export const TRANSIT_BOARD_WINDOW = 5;
|
|
4
|
+
const FOCUS = Math.floor(TRANSIT_BOARD_WINDOW / 2);
|
|
5
|
+
/**
|
|
6
|
+
* The departures board: every row is catalog data, localized to `locale`, and the last stop is this site. Build-time
|
|
7
|
+
* only; nothing here reads the browser, so the finished state is also the markup a no-script visitor gets.
|
|
8
|
+
*/
|
|
9
|
+
export function resolveTransitBoard({ locale, site, siteName, route, siteId, relatedSites }) {
|
|
10
|
+
const links = resolveSiteLinks(locale, {
|
|
11
|
+
siteUrl: new URL(site).href,
|
|
12
|
+
...(siteId === undefined ? {} : { siteId }),
|
|
13
|
+
...(relatedSites === undefined ? {} : { relatedSites }),
|
|
14
|
+
});
|
|
15
|
+
const others = links.relatedSites.map((entry) => {
|
|
16
|
+
const host = new URL(entry.href).host;
|
|
17
|
+
return {
|
|
18
|
+
id: entry.id,
|
|
19
|
+
name: entry.name,
|
|
20
|
+
detail: entry.description || host,
|
|
21
|
+
aside: entry.description ? host : '',
|
|
22
|
+
destination: false,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const destination = { id: 'destination', name: siteName, detail: route, aside: '→', destination: true };
|
|
26
|
+
const rows = [...others, destination, ...others.slice(0, FOCUS)];
|
|
27
|
+
const focus = Math.min(FOCUS, others.length);
|
|
28
|
+
return {
|
|
29
|
+
label: links.labels.relatedSites,
|
|
30
|
+
count: others.length,
|
|
31
|
+
rows,
|
|
32
|
+
shown: Math.min(TRANSIT_BOARD_WINDOW, rows.length),
|
|
33
|
+
travel: others.length - focus,
|
|
34
|
+
};
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hagicode/hagilight-core",
|
|
3
|
-
"version": "0.14.1-dev.
|
|
3
|
+
"version": "0.14.1-dev.152.1.1b8dd12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared TypeScript utilities, components, and assets for HagiCode Astro and Starlight sites",
|
|
6
6
|
"repository": {
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./dist/root-transit.d.ts",
|
|
23
23
|
"default": "./dist/root-transit.js"
|
|
24
24
|
},
|
|
25
|
+
"./root-transit-board": {
|
|
26
|
+
"types": "./dist/root-transit-board.d.ts",
|
|
27
|
+
"default": "./dist/root-transit-board.js"
|
|
28
|
+
},
|
|
25
29
|
"./splash-images": {
|
|
26
30
|
"types": "./dist/splash-images.d.ts",
|
|
27
31
|
"default": "./dist/splash-images.js"
|