@xingwangzhe/stalux 1.18.0 → 1.19.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 +1 -1
- package/src/layouts/Stalux.astro +4 -9
- package/src/scripts/background.ts +17 -16
package/package.json
CHANGED
package/src/layouts/Stalux.astro
CHANGED
|
@@ -36,9 +36,9 @@ const fontSubsetUrl = props.fontSubsetId
|
|
|
36
36
|
|
|
37
37
|
// 背景 SVG 以静态 URL 硬编码在 background.ts(纯客户端),
|
|
38
38
|
// 集成在 config:setup 时把 SVG 复制到用户项目 public/background/。
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
39
|
+
// SSR 不渲染背景图,默认露出 .bg-layer 的灰墙底色(--stalux-bg-color),
|
|
40
|
+
// 客户端运行时随机选图;不经过 import.meta.glob 资源管线,
|
|
41
|
+
// 保证增量构建依赖图 hash 稳定。
|
|
42
42
|
const llmPromoteRaw = promoteConfig?.llm_promote ?? "";
|
|
43
43
|
const llmPromote = llmPromoteRaw
|
|
44
44
|
?.replace(/\{author\}/g, authorConfig.name)
|
|
@@ -97,12 +97,7 @@ const llmPromote = llmPromoteRaw
|
|
|
97
97
|
data-stalux-bg-index="0"
|
|
98
98
|
>
|
|
99
99
|
{llmPromote && <div style="display:none">{llmPromote}</div>}
|
|
100
|
-
<div
|
|
101
|
-
class="bg-layer bg-a"
|
|
102
|
-
style={`background-image: url('${initialBg}'); opacity: 1;`}
|
|
103
|
-
aria-hidden="true"
|
|
104
|
-
>
|
|
105
|
-
</div>
|
|
100
|
+
<div class="bg-layer bg-a" style="opacity: 1;" aria-hidden="true"></div>
|
|
106
101
|
<div class="bg-layer bg-b" aria-hidden="true"></div>
|
|
107
102
|
<main class="stalux-main">
|
|
108
103
|
<slot />
|
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
* 管线(import.meta.glob 会给 SVG 打上每次构建随机的 __ASTRO_ASSET_IMAGE__
|
|
7
7
|
* 占位符,破坏增量构建依赖图 hash),也不做任何构建期扫描。
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* 背景行为:
|
|
10
|
+
* - SSR 只渲染灰墙底色(--stalux-bg-color),不渲染任何背景图,构建产物确定。
|
|
11
|
+
* - 首次加载与 VT 软导航每次都会随机选一张背景:astro:page-load 在
|
|
12
|
+
* window load(首访)与 swap 完成后、过渡动画期间(软导航)触发,
|
|
13
|
+
* 此时设置背景,过渡动画中旧图淡出、新图淡入,自然 crossfade 无跳变。
|
|
10
14
|
*/
|
|
11
15
|
declare global {
|
|
12
16
|
interface Window {
|
|
@@ -34,11 +38,11 @@ function setLayerOpacity(layer: "a" | "b", opacity: number): void {
|
|
|
34
38
|
if (el) el.style.opacity = String(opacity);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
function
|
|
41
|
+
function applyBackground(): void {
|
|
38
42
|
// 客户端运行时随机选图,构建产物保持确定性
|
|
39
43
|
const index = Math.floor(Math.random() * backgroundImages.length);
|
|
40
44
|
const layer: "a" | "b" = "a";
|
|
41
|
-
if (backgroundImages.length > 0) {
|
|
45
|
+
if (backgroundImages.length > 0 && backgroundImages[index]) {
|
|
42
46
|
const el = getLayerEl(layer);
|
|
43
47
|
if (el) el.style.backgroundImage = `url('${backgroundImages[index]}')`;
|
|
44
48
|
}
|
|
@@ -48,16 +52,13 @@ function initBackground(): void {
|
|
|
48
52
|
document.body.dataset.staluxBgLayer = layer;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
initBackground();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
55
|
+
// 首次加载与 VT 软导航都触发 astro:page-load:
|
|
56
|
+
// - 首次加载:window load 后触发(router.js addEventListener("load", onPageLoad))。
|
|
57
|
+
// - VT 软导航:swap 完成后、过渡动画期间触发(router.js onPageLoad()),
|
|
58
|
+
// 此时设置随机背景,过渡中旧图淡出、新图淡入,无跳变闪变。
|
|
59
|
+
// 注意:软导航不会重新执行打包的 module 脚本(监听器仍是首访注册的),
|
|
60
|
+
// 所以这里不能做“只执行一次”的去重,每次 page-load 都必须随机;
|
|
61
|
+
// 若软导航后新脚本被重新执行,重复监听导致随机两次也无妨(仍是随机图)。
|
|
62
|
+
// body 的 data-stalux-bg-* 是 SSR 固定占位(a/0,为了构建确定性),
|
|
63
|
+
// 不能再用它判断“服务端已渲染正确背景”,否则随机逻辑永不执行。
|
|
64
|
+
document.addEventListener("astro:page-load", applyBackground);
|