@hagicode/hagilight-core 0.16.2-dev.170.1.abf7fea → 0.18.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/README.md CHANGED
@@ -70,7 +70,7 @@ trace; the page does not perform the official website's locale detection itself.
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
73
- `en-US`), `heading`, `message`, and `continueLabel` supply the site's translated
73
+ `en-US`), `heading`, `message`, `continueLabel`, and `loadingLabel` supply the site's translated
74
74
  copy. `links={[{ destination: '/zh-CN/', label: '简体中文', lang: 'zh-CN' }]}`
75
75
  adds native alternative-language links without introducing locale selection or
76
76
  storage rules. Named `head` and `footer` slots accept site-owned metadata and
@@ -95,6 +95,15 @@ modified clicks retain native behavior. Leaving the document or an Astro
95
95
  `astro:before-swap` event cancels the timer; `astro:page-load` mounts a newly
96
96
  rendered transit page once. Back therefore does not re-enter an automatic loop.
97
97
 
98
+ When the beam lands (1,250 ms, or at once when a continuation click starts the navigation early) the
99
+ page sets `data-transit-phase="loading"` on the root and a 3 px loading rail takes over from the beam: the
100
+ same blue-to-green gradient and vertical head, creeping toward 94% and never reaching 100%, with a sheen
101
+ that keeps moving while the next page is awaited. A browser navigation has no readable progress, so the
102
+ rail says "still working", not "x% done"; it is a `progressbar` without a value, named by `loadingLabel`
103
+ or, when that is unset, `heading`. The optional `loadingLabel` also cross-fades the status line into that
104
+ text; it has no English default because a default could not be localized. Under reduced motion the rail
105
+ is a still, partly filled bar. The attribute is style only and never moves the forward clock.
106
+
98
107
  With scripting, incoming search and fragment replace their configured counterparts
99
108
  when nonempty, and the continuation anchor and timer share the resulting URL.
100
109
  For example, `/manual/?utm=a#features` forwards to
package/RootTransit.astro CHANGED
@@ -12,6 +12,8 @@ interface Props {
12
12
  heading?: string;
13
13
  message?: string;
14
14
  continueLabel?: string;
15
+ /** Replaces the status line once the beam lands and the page is loading. Unset keeps the message, since a default here could not be localized. */
16
+ loadingLabel?: string;
15
17
  links?: { destination: string; label: string; lang?: string }[];
16
18
  /** `false` turns the splash off; an object overrides its base URL, prefix, collection size or cache name. */
17
19
  splash?: false | SplashOverrides;
@@ -26,6 +28,7 @@ const {
26
28
  heading = `Opening ${siteName}`,
27
29
  message = 'You will continue automatically. You can also continue now.',
28
30
  continueLabel = `Continue to ${siteName}`,
31
+ loadingLabel,
29
32
  links = [],
30
33
  splash,
31
34
  localeMonitor,
@@ -129,6 +132,12 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
129
132
  initial-value: 0;
130
133
  }
131
134
 
135
+ @property --load {
136
+ syntax: '<number>';
137
+ inherits: true;
138
+ initial-value: 0;
139
+ }
140
+
132
141
  *,
133
142
  *::before,
134
143
  *::after {
@@ -336,6 +345,105 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
336
345
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
337
346
  }
338
347
 
348
+ /*
349
+ * ── 加载轨:光束落地后交棒 ──
350
+ * 浏览器的跳转没有可读的真实进度,所以只做诚实的「还在进行」:--load 向 94% 渐近、永不到 100%,
351
+ * 页面一卸载就被新文档取代。光束的渐变与竖线在这里继续向前,停滞时由流光表明仍在等待。
352
+ */
353
+ .load {
354
+ --load: 0;
355
+ position: relative;
356
+ height: 3px;
357
+ /* 占用路由与标题之间原有的间距(上下各半),整页只多出轨本身的 3px */
358
+ margin: 0.5rem 0 0;
359
+ background: var(--line);
360
+ opacity: 0;
361
+ transition: opacity 240ms var(--ease-out);
362
+ }
363
+
364
+ .load-fill {
365
+ position: absolute;
366
+ inset: 0;
367
+ overflow: hidden;
368
+ background: linear-gradient(90deg, var(--beam-a), var(--beam-b) 52%, var(--beam-c));
369
+ clip-path: inset(0 calc((1 - var(--load)) * 100%) 0 0);
370
+ }
371
+
372
+ .load-sheen {
373
+ position: absolute;
374
+ inset: 0 auto 0 0;
375
+ width: 30%;
376
+ background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.65), transparent);
377
+ transform: translateX(-100%);
378
+ }
379
+
380
+ /* 与路由光束同一种竖线与尾迹 */
381
+ .load-head {
382
+ position: absolute;
383
+ top: -0.375rem;
384
+ bottom: -0.375rem;
385
+ left: calc(var(--load) * 100%);
386
+ width: 2px;
387
+ margin-left: -1px;
388
+ background: linear-gradient(180deg, var(--beam-a), var(--beam-b) 52%, var(--beam-c));
389
+ opacity: min(1, calc(var(--load) * 14));
390
+ transform-origin: center;
391
+ }
392
+
393
+ .load-head::before {
394
+ content: '';
395
+ position: absolute;
396
+ inset: 0 100% 0 auto;
397
+ width: 2.5rem;
398
+ background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--beam-b) 24%, transparent));
399
+ mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
400
+ -webkit-mask-image: linear-gradient(180deg, transparent, #000 22%, #000 78%, transparent);
401
+ }
402
+
403
+ :global(html[data-transit-phase='loading']) .load {
404
+ opacity: 1;
405
+ animation: loadCreep 10s linear both;
406
+ }
407
+
408
+ :global(html[data-transit-phase='loading']) .load-head {
409
+ animation: loadHeadIn 320ms var(--ease-out) both;
410
+ }
411
+
412
+ :global(html[data-transit-phase='loading']) .load-sheen {
413
+ animation: loadSheen 1.5s linear infinite;
414
+ }
415
+
416
+ /* 先快后慢:起步 0.8 s 内到 55%,之后一路放缓到 94% */
417
+ @keyframes loadCreep {
418
+ from {
419
+ --load: 0;
420
+ animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
421
+ }
422
+ 8% {
423
+ --load: 0.55;
424
+ animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
425
+ }
426
+ 40% {
427
+ --load: 0.8;
428
+ animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
429
+ }
430
+ to {
431
+ --load: 0.94;
432
+ }
433
+ }
434
+
435
+ @keyframes loadHeadIn {
436
+ from {
437
+ transform: scaleY(0);
438
+ }
439
+ }
440
+
441
+ @keyframes loadSheen {
442
+ to {
443
+ transform: translateX(340%);
444
+ }
445
+ }
446
+
339
447
  /* ── 标题与状态 ── */
340
448
  .headline {
341
449
  margin: 1rem 0 0;
@@ -345,6 +453,10 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
345
453
  text-wrap: balance;
346
454
  }
347
455
 
456
+ .load + .headline {
457
+ margin-top: 0.5rem;
458
+ }
459
+
348
460
  .status {
349
461
  max-width: 38ch;
350
462
  /* 两行的高度:提示与「已停止」文案互换时,整个版面不跳动 */
@@ -360,6 +472,41 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
360
472
  color: var(--ink);
361
473
  }
362
474
 
475
+ /* 两句话叠在同一格:版面高度取较高者,换句时不跳动 */
476
+ .status-swap {
477
+ display: grid;
478
+ align-content: start;
479
+ }
480
+
481
+ .status-wait,
482
+ .status-load {
483
+ grid-area: 1 / 1;
484
+ transition:
485
+ opacity 280ms var(--ease-out),
486
+ filter 280ms var(--ease-out),
487
+ visibility 0s linear 280ms;
488
+ }
489
+
490
+ .status-load {
491
+ visibility: hidden;
492
+ opacity: 0;
493
+ filter: blur(3px);
494
+ }
495
+
496
+ :global(html[data-transit-phase='loading']) .status-wait {
497
+ visibility: hidden;
498
+ opacity: 0;
499
+ filter: blur(3px);
500
+ }
501
+
502
+ :global(html[data-transit-phase='loading']) .status-load {
503
+ visibility: visible;
504
+ opacity: 1;
505
+ filter: none;
506
+ color: var(--ink);
507
+ transition-delay: 0s;
508
+ }
509
+
363
510
  /* ── 解析过程:每一行都是真实输入 ── */
364
511
  .trace {
365
512
  margin: 0;
@@ -752,6 +899,9 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
752
899
  .splash { transition: none; }
753
900
  .run, .board-reel { --run: 1; }
754
901
  .board-reel { filter: none; }
902
+ /* No motion: a still half-filled rail still says "in progress" without pretending to measure it. */
903
+ .load { --load: 0.35; }
904
+ .load-head, .load-sheen { display: none; }
755
905
  .locales a:hover {
756
906
  transform: none;
757
907
  }
@@ -759,6 +909,9 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
759
909
 
760
910
  @media (forced-colors: active) {
761
911
  .splash { display: none; }
912
+ .load { outline: 1px solid CanvasText; }
913
+ .load-fill { forced-color-adjust: none; background: Highlight; }
914
+ .load-head, .load-sheen { display: none; }
762
915
  .board-row[data-board-destination] { outline: 2px solid Highlight; outline-offset: -2px; }
763
916
  .locales a[aria-current='true'] {
764
917
  outline: 2px solid Highlight;
@@ -784,8 +937,14 @@ const board = boardOption === false ? null : resolveTransitBoard({ locale, site,
784
937
  <main class="stage">
785
938
  <div class="intro">
786
939
  <p class="route" aria-hidden="true"><span class="route-origin">/</span><span class="route-target"><span class="run"><span class="run-ghost">{route.slice(1)}</span><span class="run-solid">{route.slice(1)}</span><span class="run-beam"></span></span></span></p>
940
+ <div class="load" role="progressbar" aria-label={loadingLabel ?? heading}>
941
+ <span class="load-fill"><span class="load-sheen"></span></span>
942
+ <span class="load-head"></span>
943
+ </div>
787
944
  <h1 class="headline">{heading}</h1>
788
- <p class="status">{message}</p>
945
+ {loadingLabel
946
+ ? <p class="status status-swap" aria-live="polite"><span class="status-wait">{message}</span><span class="status-load">{loadingLabel}</span></p>
947
+ : <p class="status">{message}</p>}
789
948
  </div>
790
949
  {board && (
791
950
  <section class="board" data-transit-board aria-hidden="true" style={`--shown: ${board.shown}; --travel: ${board.travel}`}>
@@ -2,7 +2,7 @@ export { DEFAULT_LOCALE, LEGACY_SITE_LOCALE_STORAGE_KEY, SITE_LOCALE_STORAGE_KEY
2
2
  export { LOCALE_MONITOR_COOKIE, LOCALE_MONITOR_STORAGE_KEY, formatLocaleMarker, parseLocaleMarker, type LocaleMarker, } from './root-transit-marker.js';
3
3
  export { mountLocaleMonitor, resolveLocaleMonitor, type LocaleMonitorOptions } from './root-transit-monitor.js';
4
4
  /** The reference route sweep (1,250 ms) and finished-state hold (320 ms). */
5
- export declare const ROOT_TRANSIT_DELAY_MS = 1570;
5
+ export declare const ROOT_TRANSIT_DELAY_MS: number;
6
6
  export interface TransitDestinationOptions {
7
7
  site: string | URL;
8
8
  base?: string;
@@ -3,8 +3,10 @@ import { mountLocaleMonitor } from './root-transit-monitor.js';
3
3
  export { DEFAULT_LOCALE, LEGACY_SITE_LOCALE_STORAGE_KEY, SITE_LOCALE_STORAGE_KEY, SITE_LOCALES, normalizeTransitLocale, resolveTransitLocale, } from './root-transit-locale.js';
4
4
  export { LOCALE_MONITOR_COOKIE, LOCALE_MONITOR_STORAGE_KEY, formatLocaleMarker, parseLocaleMarker, } from './root-transit-marker.js';
5
5
  export { mountLocaleMonitor, resolveLocaleMonitor } from './root-transit-monitor.js';
6
+ /** The reference route sweep: the beam lands here and the loading rail takes over. */
7
+ const ROUTE_RUN_MS = 1250;
6
8
  /** The reference route sweep (1,250 ms) and finished-state hold (320 ms). */
7
- export const ROOT_TRANSIT_DELAY_MS = 1570;
9
+ export const ROOT_TRANSIT_DELAY_MS = ROUTE_RUN_MS + 320;
8
10
  /** Idle-time limit for storing a loaded splash image, so the store never waits on the page. */
9
11
  const SPLASH_STORE_IDLE_TIMEOUT_MS = 1000;
10
12
  /** Resolve a configured local route, applying the deployment base at most once. */
@@ -166,6 +168,31 @@ function mountSplash(win, doc) {
166
168
  }, 0);
167
169
  return release;
168
170
  }
171
+ /**
172
+ * The beam handing off to the loading rail: one attribute on the root, set when the route sweep lands (or when a
173
+ * continuation click starts the navigation early). Style only; the forward clock never reads or waits for it.
174
+ * Without an `animationend` (reduced motion, no animation support) a timer sets it at the same moment.
175
+ */
176
+ function mountLoadingPhase(win, doc) {
177
+ const root = doc.documentElement;
178
+ const run = doc.querySelector('.run');
179
+ let timer;
180
+ const onEnd = (event) => { if (event.target === run)
181
+ enter(); };
182
+ const release = () => {
183
+ win.clearTimeout(timer);
184
+ if (typeof run?.removeEventListener === 'function')
185
+ run.removeEventListener('animationend', onEnd);
186
+ };
187
+ function enter() {
188
+ release();
189
+ root.dataset.transitPhase = 'loading';
190
+ }
191
+ if (typeof run?.addEventListener === 'function')
192
+ run.addEventListener('animationend', onEnd);
193
+ timer = win.setTimeout(enter, ROUTE_RUN_MS);
194
+ return { enter, release };
195
+ }
169
196
  /** Mount once per rendered root; decoration never controls the navigation clock. */
170
197
  export function mountRootTransit(win = window) {
171
198
  const doc = win.document;
@@ -187,9 +214,17 @@ export function mountRootTransit(win = window) {
187
214
  let finished = false;
188
215
  let timer;
189
216
  let releaseSplash = () => { };
217
+ let loading = { enter: () => { }, release: () => { } };
218
+ try {
219
+ loading = mountLoadingPhase(win, doc);
220
+ }
221
+ catch {
222
+ // The rail only decorates; a failure here never changes forwarding.
223
+ }
190
224
  const cleanup = () => {
191
225
  finished = true;
192
226
  win.clearTimeout(timer);
227
+ loading.release();
193
228
  releaseSplash();
194
229
  win.removeEventListener('pagehide', cleanup);
195
230
  doc.removeEventListener('astro:before-swap', cleanup);
@@ -199,6 +234,7 @@ export function mountRootTransit(win = window) {
199
234
  const forward = (destination = target) => {
200
235
  if (finished)
201
236
  return;
237
+ loading.enter();
202
238
  cleanup();
203
239
  win.location.replace(destination);
204
240
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hagicode/hagilight-core",
3
- "version": "0.16.2-dev.170.1.abf7fea",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "description": "Shared TypeScript utilities, components, and assets for HagiCode Astro and Starlight sites",
6
6
  "repository": {