@xingwangzhe/stalux 1.21.8 → 1.21.10
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
|
@@ -107,9 +107,6 @@ const mdSourceUrl = exportMd
|
|
|
107
107
|
{
|
|
108
108
|
props.hasImage && (
|
|
109
109
|
<script>
|
|
110
|
-
import PhotoSwipeLightbox from "photoswipe/lightbox";
|
|
111
|
-
import PhotoSwipe from "photoswipe";
|
|
112
|
-
|
|
113
110
|
// 选择器必须与 @xingwangzhe/satteri-photoswipe HAST 插件生成的 class 一致
|
|
114
111
|
const GALLERY_SELECTOR = "a.pswp-gallery-item";
|
|
115
112
|
|
|
@@ -146,6 +143,21 @@ const mdSourceUrl = exportMd
|
|
|
146
143
|
let lightbox = null;
|
|
147
144
|
|
|
148
145
|
async function initLightbox() {
|
|
146
|
+
const [{ default: PhotoSwipeLightbox }, { default: PhotoSwipe }, { default: photoSwipeCss }] = await Promise.all([
|
|
147
|
+
import("photoswipe/lightbox"),
|
|
148
|
+
import("photoswipe"),
|
|
149
|
+
import("photoswipe/dist/photoswipe.css?raw"),
|
|
150
|
+
]);
|
|
151
|
+
|
|
152
|
+
// `?raw` keeps Astro from extracting a static stylesheet link.
|
|
153
|
+
// Inject it only after the first gallery interaction.
|
|
154
|
+
if (!document.querySelector("style[data-photoswipe]") && photoSwipeCss) {
|
|
155
|
+
const style = document.createElement("style");
|
|
156
|
+
style.dataset.photoswipe = "true";
|
|
157
|
+
style.textContent = photoSwipeCss;
|
|
158
|
+
document.head.appendChild(style);
|
|
159
|
+
}
|
|
160
|
+
|
|
149
161
|
// 销毁旧实例(View Transition 导航后,旧 DOM 已移除,需安全销毁)
|
|
150
162
|
if (lightbox) {
|
|
151
163
|
try {
|
|
@@ -168,15 +180,24 @@ const mdSourceUrl = exportMd
|
|
|
168
180
|
lightbox.init();
|
|
169
181
|
}
|
|
170
182
|
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
let initPromise = null;
|
|
184
|
+
const ensureLightbox = () => {
|
|
185
|
+
if (!initPromise) initPromise = initLightbox();
|
|
186
|
+
return initPromise;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// 仅在用户第一次点击图片时加载 PhotoSwipe、其 CSS 和图片尺寸数据,
|
|
190
|
+
// 文章首屏不再为未使用的灯箱支付 JS/CSS 成本。
|
|
191
|
+
document.addEventListener("click", (event) => {
|
|
192
|
+
const target = event.target;
|
|
193
|
+
if (target instanceof Element && target.closest(GALLERY_SELECTOR)) {
|
|
194
|
+
void ensureLightbox();
|
|
195
|
+
}
|
|
196
|
+
}, { capture: true });
|
|
173
197
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
} else {
|
|
178
|
-
document.addEventListener("DOMContentLoaded", () => setTimeout(initLightbox, 0));
|
|
179
|
-
}
|
|
198
|
+
document.addEventListener("astro:page-load", () => {
|
|
199
|
+
initPromise = null;
|
|
200
|
+
});
|
|
180
201
|
</script>
|
|
181
202
|
)
|
|
182
203
|
}
|
|
@@ -6,7 +6,6 @@ import PostNavigation from "@components/stalux/posts/postNavigation.astro";
|
|
|
6
6
|
import PostCC from "@components/stalux/posts/postCC.astro";
|
|
7
7
|
import WalineComment from "@components/stalux/posts/WalineComment.astro";
|
|
8
8
|
import { buildWalineProps } from "@utils/waline";
|
|
9
|
-
import PhotoSwipeStyle from "@components/stalux/posts/PhotoSwipeStyle.astro";
|
|
10
9
|
import { getCollection } from "astro:content";
|
|
11
10
|
import "@styles/base/math.css";
|
|
12
11
|
import layoutStyle from "@styles/components/posts/postLayout.module.css";
|
|
@@ -48,8 +47,6 @@ const walineConfig = walineSection && walineSection.serverURL ? {
|
|
|
48
47
|
} : undefined;
|
|
49
48
|
---
|
|
50
49
|
|
|
51
|
-
{props.hasImage && <PhotoSwipeStyle />}
|
|
52
|
-
|
|
53
50
|
<div class={layoutStyle.postLayout}>
|
|
54
51
|
<div class={layoutStyle.container}>
|
|
55
52
|
<!-- Left Sidebar -->
|