@xingwangzhe/stalux 1.21.1 → 1.21.3

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.1",
3
+ "version": "1.21.3",
4
4
  "description": "A powerful, modern Astro blog theme — use as template or install as plugin",
5
5
  "keywords": [
6
6
  "astro",
@@ -15,7 +15,7 @@ const { t } = createTranslator(siteConfig.lang || "zh-CN");
15
15
  const navs = navsConfig?.items ?? [];
16
16
  ---
17
17
 
18
- <nav aria-label="Main navigation" transition:persist-props>
18
+ <nav aria-label={t("nav.main")} transition:persist-props>
19
19
  <!-- 汉堡菜单按钮 (仅窄屏显示) -->
20
20
  <button
21
21
  data-ref="stalux-nav-toggle"
@@ -140,17 +140,17 @@ const navs = navsConfig?.items ?? [];
140
140
  if (!navList || !btnLeft || !btnRight) return;
141
141
 
142
142
  function updateButtons() {
143
- const hasOverflow = navList.scrollWidth > navList.clientWidth;
144
- const atStart = navList.scrollLeft <= 4;
145
- const atEnd = navList.scrollLeft >= navList.scrollWidth - navList.clientWidth - 4;
146
-
147
- if (hasOverflow) {
148
- btnLeft.classList.toggle("visible", !atStart);
149
- btnRight.classList.toggle("visible", !atEnd);
150
- } else {
151
- btnLeft.classList.remove("visible");
152
- btnRight.classList.remove("visible");
143
+ const maxScrollLeft = Math.max(0, navList.scrollWidth - navList.clientWidth);
144
+ const hasOverflow = maxScrollLeft > 4;
145
+ const scrollLeft = Math.min(Math.max(navList.scrollLeft, 0), maxScrollLeft);
146
+
147
+ if (navList.scrollLeft !== scrollLeft) {
148
+ navList.scrollLeft = scrollLeft;
153
149
  }
150
+
151
+ navList.toggleAttribute("data-overflow", hasOverflow);
152
+ btnLeft.classList.toggle("visible", hasOverflow && scrollLeft > 4);
153
+ btnRight.classList.toggle("visible", hasOverflow && scrollLeft < maxScrollLeft - 4);
154
154
  }
155
155
 
156
156
  btnLeft.addEventListener("click", () => {
@@ -167,6 +167,9 @@ const navs = navsConfig?.items ?? [];
167
167
  // 用 ResizeObserver 监听容器尺寸变化(窗口缩窄/变宽时重新判断)
168
168
  const ro = new ResizeObserver(updateButtons);
169
169
  ro.observe(navList);
170
+ if (navList.parentElement) ro.observe(navList.parentElement);
171
+ window.addEventListener("resize", updateButtons, { passive: true });
172
+ window.addEventListener("load", updateButtons, { once: true });
170
173
 
171
174
  // 初始检测
172
175
  updateButtons();
package/src/i18n/en.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "nav": {
3
3
  "menu": "Open navigation menu",
4
+ "main": "Main navigation",
4
5
  "scrollLeft": "Scroll navigation left",
5
6
  "scrollRight": "Scroll navigation right",
6
7
  "search": "Search"
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "nav": {
3
3
  "menu": "打开导航菜单",
4
+ "main": "主导航",
4
5
  "scrollLeft": "向左滚动导航",
5
6
  "scrollRight": "向右滚动导航",
6
7
  "search": "搜索"
@@ -1,9 +1,11 @@
1
1
  ---
2
2
  import { getCollection } from "astro:content";
3
+ import { createTranslator } from "@utils/i18n";
3
4
  const configEntries = await getCollection("config");
4
5
  const siteConfig = getSiteData(configEntries);
5
6
  const siteTitle = siteConfig.title;
6
7
  const siteDescription = siteConfig.description;
8
+ const { t } = createTranslator(siteConfig.lang || "zh-CN");
7
9
  import Stalux from "@layouts/Stalux.astro";
8
10
  import styles from "@styles/pages/home.module.css";
9
11
  import Navs from "@components/stalux/layout/navs.astro";
@@ -21,7 +23,7 @@ import { getSiteData, getAuthorData, getHeadData, getNavsData, getLinksData, get
21
23
  <div class={styles.homeNavs}>
22
24
  <Navs />
23
25
  </div>
24
- <h2 class="sr-only" style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;">关于本站</h2>
26
+ <h2 class="sr-only" style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;">{t("ai.about")}</h2>
25
27
  <Author />
26
28
  <TextType />
27
29
  <DateTime />
@@ -2,8 +2,10 @@
2
2
  .navContainer {
3
3
  position: relative;
4
4
  width: 100%;
5
+ min-width: 0;
5
6
  max-width: 100%;
6
7
  overflow: hidden;
8
+ box-sizing: border-box;
7
9
  }
8
10
 
9
11
  .navList {
@@ -11,6 +13,9 @@
11
13
  gap: 2rem;
12
14
  align-items: center;
13
15
  justify-content: center;
16
+ min-width: 0;
17
+ max-width: 100%;
18
+ box-sizing: border-box;
14
19
  transition: transform 0.3s ease;
15
20
  /* 当导航项总宽度超过视口时允许横向滚动,防止右侧项被裁剪 */
16
21
  overflow-x: auto;
@@ -21,6 +26,11 @@
21
26
  -ms-overflow-style: none;
22
27
  }
23
28
 
29
+ .navList[data-overflow] {
30
+ justify-content: flex-start;
31
+ padding-inline: 44px;
32
+ }
33
+
24
34
  .navList::-webkit-scrollbar {
25
35
  display: none;
26
36
  }
@@ -204,7 +214,7 @@
204
214
  position: fixed;
205
215
  top: 0;
206
216
  right: 0;
207
- width: 220px;
217
+ width: min(220px, calc(100vw - 1rem));
208
218
  height: 100vh;
209
219
  background: var(--black-20p);
210
220
  backdrop-filter: blur(20px);