@xingwangzhe/stalux 1.21.6 → 1.21.8

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.6",
3
+ "version": "1.21.8",
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>
@@ -87,7 +87,14 @@ const navs = navsConfig?.items ?? [];
87
87
  </nav>
88
88
  <Search />
89
89
  <script>
90
+ const navWindow = window as Window & {
91
+ __STALUX_NAV_INITIALIZED__?: boolean;
92
+ };
93
+
90
94
  document.addEventListener("astro:page-load", () => {
95
+ if (navWindow.__STALUX_NAV_INITIALIZED__) return;
96
+ navWindow.__STALUX_NAV_INITIALIZED__ = true;
97
+
91
98
  const searchBtn = document.querySelector(
92
99
  '[data-ref="stalux-search-btn"]',
93
100
  );
@@ -141,7 +148,20 @@ const navs = navsConfig?.items ?? [];
141
148
  const btnRight = document.querySelector('[data-ref="stalux-nav-scroll-right"]');
142
149
  if (!navList || !btnLeft || !btnRight) return;
143
150
 
151
+ let frameId = 0;
152
+ let lastScale = "1";
153
+
154
+ function updateScrollButtons() {
155
+ const hasOverflow = navList.scrollWidth > navList.clientWidth;
156
+ const atStart = navList.scrollLeft <= 1;
157
+ const atEnd = navList.scrollLeft + navList.clientWidth >= navList.scrollWidth - 1;
158
+
159
+ btnLeft.toggleAttribute("data-visible", hasOverflow && !atStart);
160
+ btnRight.toggleAttribute("data-visible", hasOverflow && !atEnd);
161
+ }
162
+
144
163
  function updateButtons() {
164
+ frameId = 0;
145
165
  const navWidth = navList.clientWidth;
146
166
  const itemCount = navList.children.length;
147
167
  const baseFontSize = Number.parseFloat(getComputedStyle(navList).fontSize) || 16;
@@ -152,10 +172,17 @@ const navs = navsConfig?.items ?? [];
152
172
  0,
153
173
  ) + gap * Math.max(0, itemCount - 1);
154
174
  const scale = estimatedWidth > navWidth ? Math.max(minFontSize / baseFontSize, navWidth / estimatedWidth) : 1;
155
- navList.style.setProperty("--nav-scale", String(scale));
156
- navList.removeAttribute("data-overflow");
157
- btnLeft.removeAttribute("data-visible");
158
- btnRight.removeAttribute("data-visible");
175
+ const nextScale = String(scale);
176
+ if (nextScale !== lastScale) {
177
+ navList.style.setProperty("--nav-scale", nextScale);
178
+ lastScale = nextScale;
179
+ }
180
+ updateScrollButtons();
181
+ }
182
+
183
+ function scheduleUpdate() {
184
+ if (frameId) return;
185
+ frameId = requestAnimationFrame(updateButtons);
159
186
  }
160
187
 
161
188
  btnLeft.addEventListener("click", () => {
@@ -165,18 +192,16 @@ const navs = navsConfig?.items ?? [];
165
192
  btnRight.addEventListener("click", () => {
166
193
  navList.scrollBy({ left: 300, behavior: "smooth" });
167
194
  });
168
-
169
- // 监听滚动事件更新按钮状态
170
- navList.addEventListener("scroll", updateButtons);
195
+ navList.addEventListener("scroll", scheduleUpdate, { passive: true });
171
196
 
172
197
  // 用 ResizeObserver 监听容器尺寸变化(窗口缩窄/变宽时重新判断)
173
- const ro = new ResizeObserver(updateButtons);
198
+ const ro = new ResizeObserver(scheduleUpdate);
174
199
  ro.observe(navList);
175
200
  if (navList.parentElement) ro.observe(navList.parentElement);
176
- window.addEventListener("resize", updateButtons, { passive: true });
177
- window.addEventListener("load", updateButtons, { once: true });
201
+ window.addEventListener("resize", scheduleUpdate, { passive: true });
202
+ window.addEventListener("load", scheduleUpdate, { once: true });
178
203
 
179
204
  // 初始检测
180
- updateButtons();
205
+ scheduleUpdate();
181
206
  }
182
207
  </script>
@@ -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);
@@ -37,7 +37,7 @@ export type RouteAnimation = {
37
37
  const easing = "cubic-bezier(0.25, 0.9, 0.2, 1)";
38
38
  const exitAnimation: TransitionAnimation = {
39
39
  name: "stalux-page-fade-out",
40
- duration: "0.32s",
40
+ duration: "0.16s",
41
41
  easing,
42
42
  fillMode: "both",
43
43
  };
@@ -48,7 +48,7 @@ function createRouteAnimation(name: string, backName = `${name}-back`): RouteAni
48
48
  old: exitAnimation,
49
49
  new: {
50
50
  name: `stalux-page-${name}-in`,
51
- duration: "0.42s",
51
+ duration: "0.2s",
52
52
  easing,
53
53
  fillMode: "both",
54
54
  },
@@ -57,7 +57,7 @@ function createRouteAnimation(name: string, backName = `${name}-back`): RouteAni
57
57
  old: exitAnimation,
58
58
  new: {
59
59
  name: `stalux-page-${backName}-in`,
60
- duration: "0.42s",
60
+ duration: "0.2s",
61
61
  easing,
62
62
  fillMode: "both",
63
63
  },