@xingwangzhe/stalux 1.21.7 → 1.21.9

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xingwangzhe/stalux",
3
- "version": "1.21.7",
3
+ "version": "1.21.9",
4
4
  "description": "A powerful, modern Astro blog theme — use as template or install as plugin",
5
5
  "keywords": [
6
6
  "astro",
@@ -8,13 +8,10 @@ const id = headConfig?.bingClarityId;
8
8
 
9
9
  <script is:inline data-astro-rerun define:vars={{ id }}>
10
10
  // 防止重复初始化
11
- if (id && !document.getElementById("stalux-clarity-script") && !window.clarity) {
11
+ const load = () => {
12
+ if (!id || document.getElementById("stalux-clarity-script") || window.clarity) return;
12
13
  (function (c, l, a, r, i, t, y) {
13
- c[a] =
14
- c[a] ||
15
- function () {
16
- (c[a].q = c[a].q || []).push(arguments);
17
- };
14
+ c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments); };
18
15
  t = l.createElement(r);
19
16
  t.id = "stalux-clarity-script";
20
17
  t.async = 1;
@@ -22,5 +19,7 @@ const id = headConfig?.bingClarityId;
22
19
  y = l.getElementsByTagName(r)[0];
23
20
  y.parentNode.insertBefore(t, y);
24
21
  })(window, document, "clarity", "script", id);
25
- }
22
+ };
23
+ if ("requestIdleCallback" in window) requestIdleCallback(load, { timeout: 4000 });
24
+ else window.addEventListener("load", () => setTimeout(load, 0), { once: true });
26
25
  </script>
@@ -6,26 +6,29 @@ const headConfig = getHeadData(configEntries);
6
6
  const gaID = headConfig?.googleAnalyticsId;
7
7
  ---
8
8
 
9
- <script
10
- is:inline
11
- async
12
- src={`https://www.googletagmanager.com/gtag/js?id=${gaID}`}
13
- type="text/javascript"></script>
14
9
  <script is:inline define:vars={{ gaID }}>
15
- window.dataLayer = window.dataLayer || [];
16
- function gtag() {
17
- dataLayer.push(arguments);
18
- }
19
- gtag("js", new Date());
20
- gtag("config", gaID);
21
-
22
- // 视图过渡后重新跟踪页面浏览(仅添加一次)
23
- if (!window.__gtagListenerAdded) {
24
- document.addEventListener("astro:page-load", () => {
25
- gtag("event", "page_view", {
26
- page_path: window.location.pathname,
27
- });
28
- });
29
- window.__gtagListenerAdded = true;
30
- }
10
+ (() => {
11
+ const load = () => {
12
+ if (window.__staluxAnalyticsLoaded) return;
13
+ window.__staluxAnalyticsLoaded = true;
14
+ const script = document.createElement("script");
15
+ script.async = true;
16
+ script.src = `https://www.googletagmanager.com/gtag/js?id=${gaID}`;
17
+ document.head.appendChild(script);
18
+ window.dataLayer = window.dataLayer || [];
19
+ window.gtag = window.gtag || function () {
20
+ window.dataLayer.push(arguments);
21
+ };
22
+ window.gtag("js", new Date());
23
+ window.gtag("config", gaID);
24
+ if (!window.__gtagListenerAdded) {
25
+ document.addEventListener("astro:page-load", () => {
26
+ window.gtag("event", "page_view", { page_path: window.location.pathname });
27
+ });
28
+ window.__gtagListenerAdded = true;
29
+ }
30
+ };
31
+ if ("requestIdleCallback" in window) requestIdleCallback(load, { timeout: 3000 });
32
+ else window.addEventListener("load", () => setTimeout(load, 0), { once: true });
33
+ })();
31
34
  </script>
@@ -2,9 +2,15 @@
2
2
 
3
3
  ---
4
4
 
5
- <script
6
- is:inline
7
- defer
8
- data-astro-rerun
9
- type="text/javascript"
10
- src="https://events.vercount.one/js"></script>
5
+ <script is:inline data-astro-rerun>
6
+ (() => {
7
+ const load = () => {
8
+ const script = document.createElement("script");
9
+ script.defer = true;
10
+ script.src = "https://events.vercount.one/js";
11
+ document.head.appendChild(script);
12
+ };
13
+ if ("requestIdleCallback" in window) requestIdleCallback(load, { timeout: 5000 });
14
+ else window.addEventListener("load", () => setTimeout(load, 0), { once: true });
15
+ })();
16
+ </script>
@@ -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,12 @@ const mdSourceUrl = exportMd
146
143
  let lightbox = null;
147
144
 
148
145
  async function initLightbox() {
146
+ const [{ default: PhotoSwipeLightbox }, { default: PhotoSwipe }] = await Promise.all([
147
+ import("photoswipe/lightbox"),
148
+ import("photoswipe"),
149
+ import("photoswipe/dist/photoswipe.css"),
150
+ ]);
151
+
149
152
  // 销毁旧实例(View Transition 导航后,旧 DOM 已移除,需安全销毁)
150
153
  if (lightbox) {
151
154
  try {
@@ -168,15 +171,24 @@ const mdSourceUrl = exportMd
168
171
  lightbox.init();
169
172
  }
170
173
 
171
- // 1) View Transition 导航后触发
172
- document.addEventListener("astro:page-load", initLightbox);
174
+ let initPromise = null;
175
+ const ensureLightbox = () => {
176
+ if (!initPromise) initPromise = initLightbox();
177
+ return initPromise;
178
+ };
179
+
180
+ // 仅在用户第一次点击图片时加载 PhotoSwipe、其 CSS 和图片尺寸数据,
181
+ // 文章首屏不再为未使用的灯箱支付 JS/CSS 成本。
182
+ document.addEventListener("click", (event) => {
183
+ const target = event.target;
184
+ if (target instanceof Element && target.closest(GALLERY_SELECTOR)) {
185
+ void ensureLightbox();
186
+ }
187
+ }, { capture: true });
173
188
 
174
- // 2) 首屏兜底:避免 astro:page-load 在监听器注册前已触发
175
- if (document.readyState !== "loading") {
176
- setTimeout(initLightbox, 0);
177
- } else {
178
- document.addEventListener("DOMContentLoaded", () => setTimeout(initLightbox, 0));
179
- }
189
+ document.addEventListener("astro:page-load", () => {
190
+ initPromise = null;
191
+ });
180
192
  </script>
181
193
  )
182
194
  }
@@ -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 -->
@@ -142,10 +142,10 @@ ul {
142
142
  --white-95p: rgba(255, 255, 255, 0.95);
143
143
  --white-90p: rgba(255, 255, 255, 0.9);
144
144
  --white-85p: rgba(255, 255, 255, 0.85);
145
- --white-80p: rgba(255, 255, 255, 0.8);
145
+ --white-80p: rgba(255, 255, 255, 0.9);
146
146
  --white-78p: rgba(255, 255, 255, 0.78);
147
147
  --white-75p: rgba(255, 255, 255, 0.75);
148
- --white-70p: rgba(255, 255, 255, 0.7);
148
+ --white-70p: rgba(255, 255, 255, 0.86);
149
149
  --white-60p: rgba(255, 255, 255, 0.6);
150
150
  --white-50p: rgba(255, 255, 255, 0.5);
151
151
  --white-30p: rgba(255, 255, 255, 0.3);