diff --git a/README.md b/README.md index 19a4e3d..a5aa3e6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,10 @@ Mermaid 在构建时通过 Playwright Chromium 渲染,首次安装及 Playwrig 当前仅精确过滤 Astro 7.3 生成的 `use astro:head-inject` 指令警告,其他构建警告保留。Mermaid 渲染器仅用于构建,不再进入浏览器端资源包。 +站内同语言文档通过 Astro `ClientRouter` 获取 HTML 并切换页面,支持前进、后退与锚点。搜索组件在切页时保留,避免重复初始化 Pagefind 和快捷键;搜索结果跳转时关闭弹窗。语言切换采用完整页面加载,以重新初始化搜索翻译。外站链接、下载和新窗口链接保留浏览器默认行为,禁用 JavaScript 时仍可正常打开文档。 + +页面请求与正文图片加载使用 Google 官方 `@material/web` 的 Material 3 进度组件:页面顶部显示不定进度条,图片遮罩显示圆形指示器,不估算百分比。快速切页不显示进度条,也不延长加载时间;图片解码完成后撤去遮罩,失败时提示刷新重试。组件沿用官方尺寸和动画,只映射站点配色;图片淡入使用 Material 的 200ms 标准动效令牌。开启系统“减少动态效果”时改用静态文字,禁用 JavaScript 时直接显示原始图片。实现见 `src/scripts/loading.ts` 与 `src/styles/loading.css`,规范见 [Material Web 进度指示器](https://material-web.dev/components/progress/)。 + ## 编写与维护 文档支持 `.md` 与 `.mdx`:普通文章可以直接使用 Markdown;需要组件时使用 MDX,在 frontmatter 后导入 Starlight 或项目内的 Astro 组件。可按内容使用卡片、步骤、标签页等任意组件,使用其他前端框架的组件前需安装对应的 Astro 集成。提示信息也可直接使用 `:::note` / `:::tip` / `:::caution` / `:::danger` 语法。 @@ -50,7 +54,7 @@ Mermaid 在构建时通过 Playwright Chromium 渲染,首次安装及 Playwrig - 主题配置作为插件选项传入,修改配色会自动使 Astro 内容缓存失效。若修改渲染插件逻辑或升级渲染依赖后仍看到旧图,运行 `npm run astro -- sync --force` 后重新构建。 - MDX 集成保留静态优化,但将 `style` 排除,避免 SVG 内部样式被输出为无效的 `set:html` 属性。该集成需排在 Starlight 之后,以保留代码高亮的处理顺序。 - 除数学公式外,正文、导航、代码块、表单和图表文字均为无衬线字体。KaTeX 保留数学字体。 -- `Head.astro` 增加图表放大脚本和可选的远程正文字体,文档框架沿用 Starlight 默认实现。页眉 Logo 通过 Starlight 配置随主题切换:浅色使用 `public/simba/logo-light.svg`(深灰主体),深色使用原版 `public/simba/logo.svg`(白色主体),两版保留红色标记;搜索、导航、主题和语言切换保留原有行为。 +- `Head.astro` 加载客户端路由、图表放大脚本和可选的远程正文字体。`SiteTitle.astro` 使用静态队标和 `src/assets/site-wordmark.svg` 中的 `ΣDOCS` 轮廓路径,不加载 Logo 字体。浅色使用 `public/simba/logo-light.svg`(深灰主体),深色使用原版 `public/simba/logo.svg`(白色主体),字样颜色跟随主题。搜索保留 Pagefind,切页时复用实例并清理监听器;导航、主题和语言切换沿用 Starlight 组件。 写法和预览见 `src/content/docs/zh-cn/guides/contributing.mdx`。 diff --git a/astro.config.mjs b/astro.config.mjs index 6669e66..354d3fb 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -57,7 +57,11 @@ export default defineConfig({ * the ~1 MB `KaTeX_*.woff2` set into `dist/_astro`. */ customCss: ['./src/styles/custom.css', './src/styles/fonts.generated.css'], - components: { Head: './src/components/Head.astro' }, + components: { + Head: './src/components/Head.astro', + SiteTitle: './src/components/SiteTitle.astro', + Search: './src/components/Search.astro', + }, expressiveCode: { styleOverrides: { codeFontFamily: 'var(--sl-font)', diff --git a/package-lock.json b/package-lock.json index f7801db..d0bc89d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ "@astrojs/markdown-remark": "^7.3.1", "@astrojs/mdx": "^8.0.2", "@astrojs/starlight": "^0.42.3", + "@material/web": "2.5.0", + "@pagefind/default-ui": "1.5.2", "astro": "^7.3.5", "katex": "^0.16.47", "rehype-katex": "^7.0.1", @@ -1744,6 +1746,44 @@ "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", "license": "MIT" }, + "node_modules/@lit-labs/ssr-dom-shim": { + "version": "1.6.0", + "resolved": "https://registry.npmmirror.com/@lit-labs/ssr-dom-shim/-/ssr-dom-shim-1.6.0.tgz", + "integrity": "sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@lit/context": { + "version": "1.1.6", + "resolved": "https://registry.npmmirror.com/@lit/context/-/context-1.1.6.tgz", + "integrity": "sha512-M26qDE6UkQbZA2mQ3RjJ3Gzd8TxP+/0obMgE5HfkfLhEEyYE3Bui4A5XHiGPjy0MUGAyxB3QgVuw2ciS0kHn6A==", + "license": "BSD-3-Clause", + "dependencies": { + "@lit/reactive-element": "^1.6.2 || ^2.1.0" + } + }, + "node_modules/@lit/reactive-element": { + "version": "2.1.2", + "resolved": "https://registry.npmmirror.com/@lit/reactive-element/-/reactive-element-2.1.2.tgz", + "integrity": "sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==", + "license": "BSD-3-Clause", + "dependencies": { + "@lit-labs/ssr-dom-shim": "^1.5.0" + } + }, + "node_modules/@material/web": { + "version": "2.5.0", + "resolved": "https://registry.npmmirror.com/@material/web/-/web-2.5.0.tgz", + "integrity": "sha512-x2Uovyq8E/Zc1xHXd9s1eBMXF5pMHVAt70pISKd0fL3Ajj4L6zQaQUY/awcfR2RDAMKXC7i4+vr0arv1YaOR/g==", + "license": "Apache-2.0", + "workspaces": [ + "catalog" + ], + "dependencies": { + "@lit/context": "^1.1.6", + "lit": "^2.8.0 || ^3.0.0", + "tslib": "^2.4.0" + } + }, "node_modules/@mdx-js/mdx": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/@mdx-js/mdx/-/mdx-3.1.1.tgz", @@ -2676,9 +2716,7 @@ "version": "2.0.7", "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", - "dev": true, - "license": "MIT", - "optional": true + "license": "MIT" }, "node_modules/@types/unist": { "version": "3.0.3", @@ -5797,6 +5835,37 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/lit": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/lit/-/lit-3.3.3.tgz", + "integrity": "sha512-fycuvZg/hkpozL00lm1pEJH5nN/lr9ZXd6mJI2HSN4+Bzc+LDNdEApJ6HFbPkdFNHLvOplIIuJvxkS4XUxqirw==", + "license": "BSD-3-Clause", + "dependencies": { + "@lit/reactive-element": "^2.1.0", + "lit-element": "^4.2.0", + "lit-html": "^3.3.0" + } + }, + "node_modules/lit-element": { + "version": "4.2.2", + "resolved": "https://registry.npmmirror.com/lit-element/-/lit-element-4.2.2.tgz", + "integrity": "sha512-aFKhNToWxoyhkNDmWZwEva2SlQia+jfG0fjIWV//YeTaWrVnOxD89dPKfigCUspXFmjzOEUQpOkejH5Ly6sG0w==", + "license": "BSD-3-Clause", + "dependencies": { + "@lit-labs/ssr-dom-shim": "^1.5.0", + "@lit/reactive-element": "^2.1.0", + "lit-html": "^3.3.0" + } + }, + "node_modules/lit-html": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/lit-html/-/lit-html-3.3.3.tgz", + "integrity": "sha512-el8M6jK2o3RXBnrSHX3ZKrsN8zEV63pSExTO1wYJz7QndGYZ8353e2a5PPX+qHe2aGayfnchQmkAojaWAREOIA==", + "license": "BSD-3-Clause", + "dependencies": { + "@types/trusted-types": "^2.0.2" + } + }, "node_modules/lodash-es": { "version": "4.17.23", "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.23.tgz", @@ -8283,8 +8352,7 @@ "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "license": "0BSD", - "optional": true + "license": "0BSD" }, "node_modules/ufo": { "version": "1.6.4", diff --git a/package.json b/package.json index a534792..5376e42 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,8 @@ "@astrojs/markdown-remark": "^7.3.1", "@astrojs/mdx": "^8.0.2", "@astrojs/starlight": "^0.42.3", + "@material/web": "2.5.0", + "@pagefind/default-ui": "1.5.2", "astro": "^7.3.5", "katex": "^0.16.47", "rehype-katex": "^7.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f567cee..b5e75ab 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,12 @@ importers: '@astrojs/starlight': specifier: ^0.42.3 version: 0.42.4(@astrojs/markdown-remark@7.3.1)(astro@7.3.5(@astrojs/markdown-remark@7.3.1)(@types/node@24.19.0)) + '@material/web': + specifier: 2.5.0 + version: 2.5.0 + '@pagefind/default-ui': + specifier: 1.5.2 + version: 1.5.2 astro: specifier: ^7.3.5 version: 7.3.5(@astrojs/markdown-remark@7.3.1)(@types/node@24.19.0) @@ -754,6 +760,18 @@ packages: '@jridgewell/sourcemap-codec@1.6.0': resolution: {integrity: sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==} + '@lit-labs/ssr-dom-shim@1.6.0': + resolution: {integrity: sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ==} + + '@lit/context@1.1.6': + resolution: {integrity: sha512-M26qDE6UkQbZA2mQ3RjJ3Gzd8TxP+/0obMgE5HfkfLhEEyYE3Bui4A5XHiGPjy0MUGAyxB3QgVuw2ciS0kHn6A==} + + '@lit/reactive-element@2.1.2': + resolution: {integrity: sha512-pbCDiVMnne1lYUIaYNN5wrwQXDtHaYtg7YEFPeW+hws6U47WeFvISGUWekPGKWOP1ygrs0ef0o1VJMk1exos5A==} + + '@material/web@2.5.0': + resolution: {integrity: sha512-x2Uovyq8E/Zc1xHXd9s1eBMXF5pMHVAt70pISKd0fL3Ajj4L6zQaQUY/awcfR2RDAMKXC7i4+vr0arv1YaOR/g==} + '@mdx-js/mdx@3.1.1': resolution: {integrity: sha512-f6ZO2ifpwAQIpzGWaBQT2TXxPv6z3RBzQKpVftEWN78Vl/YweF1uwussDx8ECAXVtr3Rs89fKyG9YlzUs9DyGQ==} @@ -1809,6 +1827,15 @@ packages: resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} engines: {node: '>= 12.0.0'} + lit-element@4.2.2: + resolution: {integrity: sha512-aFKhNToWxoyhkNDmWZwEva2SlQia+jfG0fjIWV//YeTaWrVnOxD89dPKfigCUspXFmjzOEUQpOkejH5Ly6sG0w==} + + lit-html@3.3.3: + resolution: {integrity: sha512-el8M6jK2o3RXBnrSHX3ZKrsN8zEV63pSExTO1wYJz7QndGYZ8353e2a5PPX+qHe2aGayfnchQmkAojaWAREOIA==} + + lit@3.3.3: + resolution: {integrity: sha512-fycuvZg/hkpozL00lm1pEJH5nN/lr9ZXd6mJI2HSN4+Bzc+LDNdEApJ6HFbPkdFNHLvOplIIuJvxkS4XUxqirw==} + lodash-es@4.18.1: resolution: {integrity: sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==} @@ -3160,6 +3187,22 @@ snapshots: '@jridgewell/sourcemap-codec@1.6.0': {} + '@lit-labs/ssr-dom-shim@1.6.0': {} + + '@lit/context@1.1.6': + dependencies: + '@lit/reactive-element': 2.1.2 + + '@lit/reactive-element@2.1.2': + dependencies: + '@lit-labs/ssr-dom-shim': 1.6.0 + + '@material/web@2.5.0': + dependencies: + '@lit/context': 1.1.6 + lit: 3.3.3 + tslib: 2.8.1 + '@mdx-js/mdx@3.1.1': dependencies: '@types/estree': 1.0.9 @@ -3484,8 +3527,7 @@ snapshots: dependencies: '@types/node': 24.19.0 - '@types/trusted-types@2.0.7': - optional: true + '@types/trusted-types@2.0.7': {} '@types/unist@2.0.11': {} @@ -4405,6 +4447,22 @@ snapshots: lightningcss-win32-arm64-msvc: 1.33.0 lightningcss-win32-x64-msvc: 1.33.0 + lit-element@4.2.2: + dependencies: + '@lit-labs/ssr-dom-shim': 1.6.0 + '@lit/reactive-element': 2.1.2 + lit-html: 3.3.3 + + lit-html@3.3.3: + dependencies: + '@types/trusted-types': 2.0.7 + + lit@3.3.3: + dependencies: + '@lit/reactive-element': 2.1.2 + lit-element: 4.2.2 + lit-html: 3.3.3 + lodash-es@4.18.1: {} longest-streak@3.1.0: {} @@ -5460,8 +5518,7 @@ snapshots: ts-dedent@2.3.0: {} - tslib@2.8.1: - optional: true + tslib@2.8.1: {} ufo@1.6.4: {} diff --git a/scripts/check-build.mjs b/scripts/check-build.mjs index f560dfd..2a17d37 100644 --- a/scripts/check-build.mjs +++ b/scripts/check-build.mjs @@ -24,6 +24,18 @@ let diagrams = 0; for (const [path, html] of pages) { const page = relative(root, path).split(sep).join('/'); const base = new URL(page.replace(/index\.html$/, ''), origin); + if (!/http-equiv="refresh"/i.test(html)) { + if (!html.includes('name="astro-view-transitions-enabled"')) { + errors.push(`${page}: missing client-side document navigation`); + } + const wordmark = html.match(/]*class="[^"]*\bsite-wordmark\b[^"]*"[^>]*>[\s\S]*?<\/svg>/)?.[0]; + if (!wordmark || !wordmark.includes(']*(?:Manrope|Archivo)/i.test(html)) { + errors.push(`${page}: unexpected wordmark font request`); + } + } if (html.includes('class="katex-error"')) errors.push(`${page}: invalid math`); if (/]*\sset:html=/.test(html)) errors.push(`${page}: MDX emitted inert SVG styles`); const diagramCount = [...html.matchAll(/class="mermaid-diagram"/g)].length; diff --git a/scripts/generate-fonts.mjs b/scripts/generate-fonts.mjs index e9a7327..8ddd8b9 100644 --- a/scripts/generate-fonts.mjs +++ b/scripts/generate-fonts.mjs @@ -40,14 +40,6 @@ const KATEX_CDN = 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX'; /** Site webfont family requested from the Google Fonts CN API in `Head.astro`. */ export const SANS_FAMILY = 'Noto Sans SC'; -/** - * Heading webfont for the site title in the top-left corner. The title contains - * a Greek `Σ`, so the face must cover Greek as well as Latin: Manrope is a - * variable font (200..800) with a greek subset, and Archivo Black (weight 400) - * is requested as a separate heavy fallback. - */ -export const DISPLAY_FAMILY = 'Manrope'; - const SYSTEM_SANS = [ 'system-ui', '-apple-system', @@ -74,20 +66,6 @@ const fontStack = (families) => /** Site stack: the webfont first, then every plausible local fallback. */ const SANS_STACK = fontStack([SANS_FAMILY, ...SYSTEM_SANS, ...CJK_SANS, 'sans-serif']); -/** - * Display stack for the site title. Only Latin + Greek are covered by the - * webfonts, so the site's CJK fallbacks follow for any Chinese in the title. - * `Archivo Black` covers Greek and is a genuine display cut, so it is a real - * fallback rather than a placeholder. - */ -const DISPLAY_STACK = fontStack([ - DISPLAY_FAMILY, - 'Archivo Black', - ...SYSTEM_SANS, - ...CJK_SANS, - 'sans-serif', -]); - /** * Math stack. Locally installed TeX faces come first, then the platform UI * faces for Latin/Greek symbols, then CJK faces for any Chinese inside math. @@ -252,8 +230,6 @@ const css = `/* --sl-font-mono: ${SANS_STACK}; --sl-font-system-mono: ${SANS_STACK}; - /* Heading face for the site title; see .site-title in custom.css. */ - --sl-font-display: ${DISPLAY_STACK}; } /* diff --git a/src/assets/images/rmic-26/client-operator.png b/src/assets/images/rmic-26/client-operator.png new file mode 100644 index 0000000..04863b6 Binary files /dev/null and b/src/assets/images/rmic-26/client-operator.png differ diff --git a/src/assets/images/rmic-26/client-referee.png b/src/assets/images/rmic-26/client-referee.png new file mode 100644 index 0000000..3ce221d Binary files /dev/null and b/src/assets/images/rmic-26/client-referee.png differ diff --git a/src/assets/site-wordmark.svg b/src/assets/site-wordmark.svg new file mode 100644 index 0000000..c6b7d6a --- /dev/null +++ b/src/assets/site-wordmark.svg @@ -0,0 +1 @@ + diff --git a/src/components/Head.astro b/src/components/Head.astro index ec37634..786235d 100644 --- a/src/components/Head.astro +++ b/src/components/Head.astro @@ -1,5 +1,7 @@ --- import DefaultHead from '@astrojs/starlight/components/Head.astro'; +import { ClientRouter } from 'astro:transitions'; +import '../styles/loading.css'; // A 404 is not a translated document. Starlight would otherwise advertise // nonexistent /zh-cn/404/ and /en/404/ alternates for this custom page. @@ -17,16 +19,14 @@ if (Astro.locals.starlightRoute.id === '404' || Astro.response.status === 404) { * and never swaps, so there is no reflow. A slow or blocked fonts.googleapis.cn * therefore costs nothing but the webfont itself. * - * `Manrope` is the heading face behind `--sl-font-display` for the site title in - * the top-left corner. A variable font, so one request spans 600..800. - * `Archivo Black` is the heavy fallback; the title's Greek `Σ` needs a face with - * a greek subset, which is why these two were chosen. + * The site wordmark is an outlined SVG and does not use a webfont. */ const WEBFONT_CSS = - 'https://fonts.googleapis.cn/css2?family=Archivo+Black&family=Manrope:wght@600..800&family=Noto+Sans+SC:wght@400..700&display=optional'; + 'https://fonts.googleapis.cn/css2?family=Noto+Sans+SC:wght@400..700&display=optional'; --- + |"发现与视频"| Network + Armor <-->|"血量与控制"| Network + Network <--> Red["红方用户端
本车画面、双方血量"] + Network <--> Blue["蓝方用户端
本车画面、双方血量"] + Network <--> Referee["裁判端
双路画面、比赛控制"] +``` + +两车各安装一套系统,选手在用户端查看本车画面和双方血量;裁判端同时查看两路画面,控制比赛进程并同步计时。 + +:::danger[自制裁判系统不允许参赛] +队伍不可修改裁判系统的任意软硬件,正式比赛需要烧录比赛的专用固件。自制裁判系统将无法通过检录。 +::: + +裁判系统借用应遵循下列规则: + +- 正式比赛前提前借用,需 **实名登记**。 +- 比赛现场损坏时,可临时再借一套并记录先前损坏情况。 +- 完赛后归还裁判系统。 +- 赛前或赛中损坏的,按损坏程度收取维修费。 + +## 装甲板模块 + +实时检测水弹击打及物理碰撞。 + +| 项目 | 规定 | +| --- | --- | +| 构成 | 每车安装 2 或 4 块,其中一块为主装甲板,其余为从装甲板 | +| 检测方式 | 压电片持续采样,由主板判定受击 | +| 重复判定抑制 | 同一板位受击后进入 **50 ms** 冷却,四路分别计时 | +| 血量 | 整车共用 **100** 点血量,比赛进行中每次有效受击扣 **3** 点 | +| 供电 | 通过杜邦线提供 **5 V ± 1 V** | +| 通信 | 一路 **UART**,可向主控发送键盘、鼠标控制指令 | + +主装甲板的样式如下所示: + +![装甲板概览](../../../../assets/images/rmic-26/armor_intro.png) + +装甲板安装时的角度、高度和刚性要求见[装甲模块安装规范](/zh-cn/competition/robot-spec/#装甲模块安装)。 + +### 安装与上电 + +1. **连接主从板。** 在断电状态下,将左、后、右三块从装甲板接入主板背面对应接口,接头位置参照上方的主板背面图。 +2. **连接电源。** 电源正极接主板 **5V**,负极接 **GND**,供电电压为 **5 V ± 1 V**。 +3. **固定模块和线缆。** 装甲板与支架刚性连接,固定接头与线缆,保持受击面和灯带外露。 +4. **上电检查。** 在客户端绑定主板并选择所属队伍,检查灯色、血量和各块装甲板的受击响应。 + +```mermaid +flowchart TB + Power["装甲板电源 · 5 V ± 1 V
正极接 5V,负极接 GND"] + Main["主装甲板
ESP32-C3 · 四路受击检测"] + Left["左从装甲板
灯带与压电片"] + Rear["后从装甲板
灯带与压电片"] + Right["右从装甲板
灯带与压电片"] + Power --> Main + Main ---|"左接口"| Left + Main ---|"后接口"| Rear + Main ---|"右接口"| Right +``` + +主板通过配套线缆连接从板的灯带与压电片,统一处理四路受击、灯光和整车血量。 + +### 灯光状态检查表 + +| 灯光 | 状态 | 操作 | +| --- | --- | --- | +| 黄灯闪烁 | 正在连接 Wi-Fi 或获取 IP 地址 | 检查现场热点与设备供电 | +| 绿灯闪烁 | 等待客户端连接 | 绑定装甲板并选择所属队伍 | +| 红色 / 蓝色常亮 | 已连接客户端,显示所属队伍 | 核对红蓝方 | +| 受击的一路熄灭约 **50 ms** | 该路检测到受击 | 对局中核对扣血情况 | +| 四路全灭 | 血量归零,或供电、接线异常 | 查看客户端血量,检查供电与接头 | + +比赛进行中,裁判端允许装甲板扣血;准备和暂停等阶段受击时只闪灯,血量保持原值。 + +调试时,短按主板 **BOOT** 键可输出状态日志,长按至少 **500 ms** 可恢复 100 血并清除受击计数。比赛换局使用裁判端的“重置到未开始”。 + +### 接入机器人主控 + +:::note +本操作为可选项,你可以使用自己的远程控制方案。 +::: + +选手可以选用装甲板串口+裁判机鼠标键盘控制机器人:将装甲板主板的 **TXD / GPIO21** 接机器人主控的 **UART RX**,两端 **GND 共地**。主控串口参数为 **波特率 115200、8N1、无流控**,信号电平为 **3.3 V**。 + +```mermaid +flowchart LR + subgraph ArmorUART["装甲板主板"] + TX["TXD / GPIO21"] + GND1["GND"] + end + subgraph Controller["机器人主控"] + RX2["UART RX"] + GND2["GND"] + end + TX -->|"3.3 V 逻辑 · 115200 8N1"| RX2 + GND1 --- GND2 +``` + +排针位置按实物丝印核对,主控按下文的控制协议解析串口数据。 + +## 图传模块 + +图传模块作用为将机器人第一人称视角画面回传至裁判系统客户端屏幕,安装方式由队伍决定。 + +:::danger[检查电量] +图传仅可使用内部电池供电。选手在借用图传模块时应确保每次测试后均充满电:将 **USB 5V AtoC** 线缆插入图传 **侧边** 的 USB Type-C 充电口,观察到图传底部开口有蓝色 LED 闪烁即正在充电。若蓝色 LED 常亮,则为充满电。本模块没有电量不足提醒,若导致电池欠电失效,则对应借用队伍需要赔偿电池维修费用。 +::: + +固定图传模块,保持镜头无遮挡,并为接口和线缆预留空间。连接客户端后,可用手短暂遮挡本车镜头,确认画面来源;画面方向可在设置中调整左右或上下镜像。 + +## 客户端连接 + +### 安装与网络配置 + +安装组委会提供的 **RMIC::2026** 客户端。 + +现场网络采用以下连接约定: + +| 项目 | 配置 | +| --- | --- | +| Wi-Fi 名称 | `SR-602-2G4` | +| Wi-Fi 密码 | `12345678` | +| 无线频段 | **2.4 GHz** | + +:::note[自动连接] +非现场调试时,可将手机热点 / Wi-Fi 名称更改为上述参数,装甲板与图传将自动连接到该热点,无需其他手动配置。现场检录及参赛期间,参赛队伍不得开启与裁判系统同名的 Wi-Fi 热点,详见[检录要求](/zh-cn/competition/matches/#单局比赛流程)。 +::: + +选手电脑、裁判电脑与车上模块接入同一局域网,允许客户端通过防火墙,并关闭热点的客户端隔离。更换热点或更新固件时,联系组委会处理。 + +:::note[首次启动选择运行模式] +选手选择“用户端”,场边裁判选择“裁判端”。程序会记住所选模式,也可在设置中切换。 +::: + +### 用户端绑定 + +1. **设置现场密码。** 首次进入用户端时,设置至少 **4 位**的密码,用于修改设备绑定、切换队伍或模式,以及退出程序时解锁。 +2. **打开设备设置。** 按 **ESC**,选择“画面与设备设置”→“设备绑定”,输入密码解锁。 +3. **选择本车设备。** 分别选择“图传板”和“装甲板主板”,核对设备 ID,再选择“所属队伍”:队伍一为红方,队伍二为蓝方。 +4. **核对连接。** 确认本车灯色正确,图传显示“接收中”、装甲板显示“在线”,双方血量正常显示。短暂遮挡本车镜头,再次核对画面来源。 +5. **调整画面。** 按需设置镜像、准星和网格。滚轮缩放画面,双击恢复视图。 + +绑定完成后,用户端显示本车画面与双方血量。血量位置显示占位说明时,按页面提示检查装甲板连接。 + +## 选手操作 + +![用户端界面:顶部为双方血量和比赛计时,左下角为操控与 ESC 菜单入口;画面和读数均为合成数据](../../../../assets/images/rmic-26/client-operator.png) + +用户端界面示意,画面与读数为**合成数据**。 + +### 查看画面与比赛状态 + +顶部左侧显示本方血量,右侧显示对方血量,中间显示比赛阶段与剩余时间。图传中断时,最后一帧变灰,页面显示等待或重连原因。 + +开赛前最后 5 秒显示全屏倒计时。暂停时显示原因,并冻结原阶段计时。比赛流程与胜负判定见[单局比赛流程](/zh-cn/competition/matches/#单局比赛流程)。 + +### 使用键盘与鼠标 + +完成 UART 接线和主控协议解析后,即可通过客户端键鼠操作机器人。 + +| 输入 | 协议字段 | 功能与正方向 | +| --- | --- | --- | +| W / S | CH0 `forward` | 前进 / 后退,向前为正 | +| D / A | CH1 `strafe` | 向右 / 向左平移,向右为正 | +| 鼠标水平移动 | CH2 `yaw` | 云台偏航速度,向右为正 | +| 鼠标垂直移动 | CH3 `pitch` | 云台俯仰速度,向上为正 | +| 鼠标左键 | `fire` | 按住为 1,松开为 0,主控据此控制发射 | +| ESC | — | 退出键鼠操作;再次按下打开菜单 | + +1. **赛前调试。** 点击左下角“操控”→“赛前调试”,检查底盘、云台和发射响应。画面中央显示 CH0–CH3 输入值与发射位,便于核对主控收到的数据。 +2. **比赛操作。** 对局开始、本车仍有血量且裁判计时连接正常时,点击“操控”→“比赛操作”。开启后鼠标锁定在画面中,按 ESC 退出。 +3. **恢复操作。** 开赛倒计时、暂停、窗口失焦或连接中断时,客户端会退出操控。回到有效比赛阶段后,再次点击“比赛操作”。 + +“赛前调试”用于未开始、准备和等待开赛阶段,单独调试时也可使用。入口不可用时,悬停查看原因;裁判计时失联时先恢复连接。鼠标灵敏度可在“操控”菜单中调整,本次会话有效。 + +### 客户端控制协议 + +开启操控后,用户端每 **20 ms** 将最新键鼠状态通过 UDP 单播发给绑定的装甲板主板。数据包含目标板号、会话号、序号、操作模式、使能状态、四个通道和发射位。主板每 **20 ms** 将控制状态转换成 UART 帧,机器人主控解析后驱动底盘、云台与发射机构。 + +四个通道均为有符号整数,范围为 **-1000~1000**,表示本车设定最大速度的比例:0 为停止,500 为正方向半速,-1000 为负方向满速。鼠标移动越快,云台通道的绝对值越大;停止移动后通道回零。默认鼠标每秒移动 1000 像素对应满幅,可用灵敏度调整。画面镜像和缩放只影响显示,控制方向按上表约定。 + +#### UART 帧格式 + +每帧固定 **20 字节**,多字节字段采用**小端序**。 + +| 偏移 / 长度(字节) | 字段 | 含义 | +| --- | --- | --- | +| 0 / 2 | 帧头 | `A5 5A` | +| 2 / 1 | 版本 | 固定为 `0x01` | +| 3 / 1 | 帧长 | 固定为 `0x14`,即十进制 20 | +| 4 / 4 | `sequence` | `u32` 序号,每帧递增 | +| 8 / 1 | `flags` | bit0 使能、bit1 赛前调试、bit2 发射,其余位为 0 | +| 9 / 1 | 保留 | 固定为 0 | +| 10 / 2 | `forward` | `i16`,前后速度 | +| 12 / 2 | `strafe` | `i16`,左右速度 | +| 14 / 2 | `yaw` | `i16`,云台偏航速度 | +| 16 / 2 | `pitch` | `i16`,云台俯仰速度 | +| 18 / 2 | CRC16 | 校验字节 0–17,结果小端存放 | + +`flags` 的各位取 1 表示对应状态生效。例如 `0x01` 表示比赛操作已使能,`0x03` 表示赛前调试已使能,`0x05` 表示比赛操作已使能且按住发射。禁能帧的 `flags` 和四个通道均为 0,主控收到后停止运动与发射。 + +CRC 使用 **CRC16-CCITT-FALSE**:`poly=0x1021`、`init=0xFFFF`、`refin=false`、`refout=false`、`xorout=0`。以下是一帧完整数据: + +```text +A5 5A 01 14 78 56 34 12 05 00 E8 03 18 FC C8 00 38 FF 78 60 +``` + +该帧序号为 `0x12345678`,四通道依次为 `[1000, -1000, 200, -200]`,表示比赛模式下使能操控并发送发射状态,CRC 为 `0x6078`。 + +#### 主控接收方法 + +接收端按帧头收齐 20 字节,校验版本、帧长和 CRC,再按递增序号更新控制量。装甲板的操控输入超时设为 **150 ms**,超时后输出禁能帧;主控接收示例的超时设为 **100 ms**,超时后将通道与发射状态清零。上电和超时恢复时,接收器先用一帧完整禁能帧同步,再接收使能帧。 + +[裁判系统源码仓库](https://git.simba-robotics.com/PRAM/simba-rmic-2026)的 `armor/examples/uart_receiver/` 提供 C99 协议接收例程:将串口数据交给 `rmic_receiver_feed`,在控制循环调用 `rmic_receiver_poll`,使用返回的通道值和发射位。主控单独重启后,选手先退出操控,再重新开启。完整协议见仓库中的 `docs/protocol/operator-control.md`。 + +## 裁判端操作 + +![裁判端界面:顶部为比赛控制,中部为双方画面,下方为装甲板列表与设置入口;画面和读数均为合成数据](../../../../assets/images/rmic-26/client-referee.png) + +裁判端界面示意,画面与读数为**合成数据**。 + +### 核对双方设备 + +1. **进入裁判端。** 图传按在线设备自动分配左右画面,装甲板按上报队伍分配槽位。 +2. **核对队伍。** 左格为队伍一 / 红方,右格为队伍二 / 蓝方。编辑画面下方的队名,按回车或点击其他位置保存,按 ESC 取消。 +3. **核对设备。** 如画面或血量对应错误,打开“设置”→“画面槽位”,启用“手动指定槽位”,分别选择双方的图传板与装甲板。 +4. **检查血量。** 下方“装甲板”页显示设备 ID、自报队伍、血量、最近上报时间和四路状态。四路上报完整、最近更新在 **1.5 秒**内时,界面显示有效血量。 + +图传重连后回到原槽位。每路画面下方的镜像设置会同步到绑定该图传板的用户端。 + +### 准备与开赛 + +```mermaid +flowchart LR + Prepare["准备 3 分钟
结束后等待裁判确认"] + Running["确认开赛并倒计时
随后进行 3 分钟对局
仅对局中允许扣血"] + Finished["结束并核对结果
重置到未开始
确认成功后准备下一局"] + Prepare --> Running + Running --> Finished +``` + +点击顶部“开始 3 分钟准备”。准备时间到后进入等待状态;如双方已准备完毕,可点击“跳过准备倒计时”提前进入等待状态。随后由裁判点击“确认开赛”,经过短倒计时才开始对局。 + +开赛倒计时默认 **5 秒**,可设 **1–60 秒**。现场由一台裁判端负责本场计时。 + +### 暂停与恢复 + +| 操作 | 使用方法与状态 | +| --- | --- | +| 选手暂停 | 先取得主裁判批准,再点击“选手暂停”,选择申请队伍、填写原因并勾选“已获得主裁判批准”,最后点击“开始 5 分钟暂停” | +| 官方暂停 | 点击“官方暂停”,填写原因后开始;显示暂停已用时,由裁判决定恢复时间 | +| 恢复 | 点击当前阶段的恢复按钮,继续暂停前的准备、待开赛、倒计时或对局阶段 | +| 结束本局 | 点击并确认,结束计时与扣血,随后核对比赛结果 | + +选手暂停满 **5 分钟**后,裁判点击恢复按钮继续原阶段,也可提前恢复。对局恢复后沿用暂停前的血量,选手重新开启“比赛操作”。 + +### 结束与下一局 + +对局中一方血量归零后,裁判端结束计时并保留本局结果。计时到零而双方仍有血时,裁判按赛事规则核对剩余血量和胜负。 + +正式开赛后,装甲板主板的血量上报连续中断超过 **5 秒**,裁判端直接判该方负,结束本局并停止扣血许可。选手暂停和官方暂停期间仍计算断连时间。计时以最后一次血量上报为准,图传画面中断不触发该判罚;准备和开赛倒计时期间不累计,开赛时仍未接入的主板从开赛时计时。 + +双方界面会显示断连判负原因,血量位置仍显示实际读数或未接入状态。超过时限后重连不能撤销结果;同一次判定中双方均已断连超过 5 秒时,双方均判负。裁判端按本局开赛时的主板 ID 判定,不会用新发现的主板替换断连设备。裁判端和选手端均需使用支持此规则的客户端。 + +本局结束后,点击“重置到未开始”复位。客户端复位当前槽位的装甲板,收到主板回执和四路 100 血上报后,清除本局计时、暂停、结果与最近命中记录。设备槽位、队名、画面设置和录制文件保留。重置等待 **3 秒**仍未完成时,按页面提示检查对应主板后重试。 + +## 使用前检查与故障排查 + +每次上场前,双方与裁判共同确认: + +- 装甲板和图传供电正确,模块与线缆固定,无松脱或遮挡。 +- 用户端绑定本车图传与装甲板,灯色、队伍、裁判端槽位对应正确。 +- 双方画面持续更新,四路血量上报完整,初始血量为 100。 +- 选手端能收到本场裁判计时,底盘、云台和发射方向正确,退出操控后能停止。 + +| 现象 | 检查顺序 | +| --- | --- | +| 找不到图传或装甲板 | 先检查供电,再检查热点名称、密码与 2.4 GHz 频段;确认电脑在同一局域网,防火墙允许通信且热点未隔离客户端 | +| 能发现图传但没有画面 | 核对绑定 ID、设备在线状态与协议提示;检查防火墙、VPN / 虚拟网卡对路由的影响 | +| 有画面但没有血量 | 检查装甲板是否在线、所属队伍和槽位是否匹配,再查看四路上报是否完整、新鲜 | +| 受击闪灯但不扣血 | 确认处于正式对局中,裁判端仍在线且分配了正确装甲板;准备、暂停等阶段只闪灯属于正常状态 | +| 显示“计时同步中断” | 检查局域网与 UDP 5601;同一裁判会话恢复后会自动校正。裁判端重启或地址改变时,在用户端按 ESC,选择“重新接收裁判计时”,确认现场只有一个正式裁判端后重新接收 | +| 重置后仍显示本局结果 | 在裁判端点击“重置到未开始”,按提示检查主板是否在线、是否已回到 100 血 | + +## 致谢 + +:::tip[感谢南京邮电大学 POTENTIAL 战队] +本裁判系统参考南京邮电大学 RM 校内赛开源裁判系统硬件二次开发而来,感谢他们的贡献。 +开源仓库链接:[https://github.com/njupt-robomasters/SmallMaster](https://github.com/njupt-robomasters/SmallMaster) +::: diff --git a/src/content/docs/zh-cn/guides/contributing.mdx b/src/content/docs/zh-cn/guides/contributing.mdx index e3ec652..edc879b 100644 --- a/src/content/docs/zh-cn/guides/contributing.mdx +++ b/src/content/docs/zh-cn/guides/contributing.mdx @@ -159,7 +159,7 @@ flowchart LR 本站不分发字体文件,也不让字体请求阻塞首屏: - **正文**使用思源黑体 `Noto Sans SC`,通过 Google Fonts 中国镜像 `fonts.googleapis.cn` 异步加载,并以 `font-display=optional` 声明。加载失败、被拦截或超时都不会留白,浏览器直接使用本地回退链(`system-ui` → `PingFang SC` / `Microsoft YaHei` → `sans-serif`)。 -- **左上角标题**(`ΣDOCS`)使用粗标题字体 `Manrope` 800,回退到 `Archivo Black`。标题含希腊字母 `Σ`,因此只选用带 greek 子集的字体族;字体族由 `--sl-font-display` 提供,样式在 `custom.css` 的 `.site-title` 中。 +- **左上角标题**(`ΣDOCS`)由 `src/assets/site-wordmark.svg` 中的轮廓路径渲染,不依赖字体下载。`SiteTitle.astro` 将字样与队标组合,字样颜色跟随主题。 - **数学公式**使用 KaTeX 的数学字体,按安装版本固定引用 cdnjs。每条公式样式优先使用对应的 `KaTeX_Main` / `KaTeX_Math` / `KaTeX_Size*` 字体,之后才是本地回退字体。CDN 不可达时仍会显示文字,但替代字体的字形度量不同,复杂公式和大括号可能错位;离线环境不能保证数学排版一致。 - `src/styles/fonts.generated.css` 由 `scripts/generate-fonts.mjs` 在 `npm run dev` / `npm run build` 前自动生成,**不要手工修改**。脚本会校验生成结果中不含任何相对字体路径,因此打包产物不会包含字体文件。 @@ -169,6 +169,8 @@ flowchart LR 顶栏是固定高度的,内部元素超高会被直接裁掉,因此标志尺寸受 `--sl-nav-height - 2 * --sl-nav-pad-y` 约束。`custom.css` 把该高度上调 0.25rem 并给出 `--sl-logo-size`(手机 2.25rem / 桌面 2.625rem)。如果需要更大的标志,必须同时上调 `--sl-nav-height`,否则会被裁切;该变量也会影响固定侧栏与正文的偏移。 +字样修改后应保留为纯路径 SVG,不加入 ``、字体引用或远程资源。站内切页使用 Astro 客户端路由,新增页面脚本应在 `astro:page-load` 时初始化,并避免重复绑定事件;需要随页面替换而释放的监听器应在离开页面时清理。 + ## 发布前检查 1. **核实内容。** 区分正式规则、经验建议、示例与待确认项。 diff --git a/src/scripts/loading.ts b/src/scripts/loading.ts new file mode 100644 index 0000000..857f9d5 --- /dev/null +++ b/src/scripts/loading.ts @@ -0,0 +1,136 @@ +import '@material/web/progress/linear-progress.js'; +import '@material/web/progress/circular-progress.js'; +import type { TransitionBeforePreparationEvent } from 'astro:transitions/client'; + +const message = (zh: string, en: string) => document.documentElement.lang.startsWith('zh') ? zh : en; +// Presentation delay only: fast loads must not be held open to play an animation. +const indicatorDelay = 150; +let pageTimer: ReturnType | undefined; +let navigationId = 0; +let imageController = new AbortController(); + +function finishPageLoad(id = navigationId) { + if (id !== navigationId) return; + clearTimeout(pageTimer); + document.querySelector('.page-load-progress')?.remove(); + document.querySelector('main')?.removeAttribute('aria-busy'); +} + +function beginPageLoad(signal?: AbortSignal) { + finishPageLoad(); + const id = ++navigationId; + document.querySelector('main')?.setAttribute('aria-busy', 'true'); + pageTimer = setTimeout(() => { + if (id !== navigationId || signal?.aborted) return; + const label = message('正在加载页面…', 'Loading page…'); + const container = document.createElement('div'); + container.className = 'page-load-progress'; + const progress = document.createElement('md-linear-progress'); + progress.indeterminate = true; + progress.setAttribute('aria-label', label); + const reduced = document.createElement('span'); + reduced.className = 'page-load-reduced'; + reduced.setAttribute('role', 'status'); + reduced.textContent = label; + container.append(progress, reduced); + document.body.append(container); + }, indicatorDelay); + signal?.addEventListener('abort', () => finishPageLoad(id), { once: true }); + return id; +} + +function setupImages() { + const { signal } = imageController; + for (const image of document.querySelectorAll('.sl-markdown-content img')) { + if (image.closest('.image-load-frame') || image.hasAttribute('data-no-loading-mask')) continue; + // Cached images keep their original DOM and do not flash a loading state. + if (image.complete && image.naturalWidth > 0) continue; + + const media = image.closest('picture') ?? image; + const frame = document.createElement('span'); + frame.className = 'image-load-frame'; + frame.dataset.state = 'loading'; + frame.setAttribute('aria-busy', 'true'); + if (!image.hasAttribute('width') || !image.hasAttribute('height')) frame.classList.add('image-load-unsized'); + const mask = document.createElement('span'); + mask.className = 'image-load-mask'; + const progress = document.createElement('md-circular-progress'); + progress.indeterminate = true; + progress.setAttribute('aria-label', message('正在加载图片', 'Loading image')); + // The text supplies a single accessible status in both motion modes. + progress.setAttribute('aria-hidden', 'true'); + const status = document.createElement('span'); + status.className = 'image-load-status'; + status.setAttribute('role', 'status'); + status.setAttribute('aria-live', 'off'); + status.textContent = message('正在加载图片…', 'Loading image…'); + mask.append(progress, status); + media.before(frame); + frame.append(media, mask); + + const fail = () => { + if (signal.aborted) return; + frame.dataset.state = 'error'; + frame.removeAttribute('aria-busy'); + progress.remove(); + status.setAttribute('aria-live', 'polite'); + status.textContent = message('图片加载失败,请刷新页面重试。', 'Image could not load. Refresh the page to retry.'); + }; + const reveal = async () => { + // Do not reveal a downloaded image until the browser has decoded it. + try { await image.decode(); } catch { /* The native load/error state is authoritative. */ } + if (signal.aborted || !image.isConnected || !image.complete) return; + if (!image.naturalWidth) { fail(); return; } + frame.dataset.state = 'loaded'; + frame.removeAttribute('aria-busy'); + mask.setAttribute('aria-hidden', 'true'); + progress.remove(); + }; + image.addEventListener('load', () => void reveal(), { signal }); + image.addEventListener('error', fail, { signal }); + // Cover a load/error that completed between the initial check and binding. + if (image.complete) { + if (image.naturalWidth) void reveal(); + else fail(); + } + } +} + +document.addEventListener('astro:before-preparation', (rawEvent) => { + const event = rawEvent as TransitionBeforePreparationEvent; + const id = beginPageLoad(event.signal); + const load = event.loader; + event.loader = async () => { + try { await load(); } + catch (error) { finishPageLoad(id); throw error; } + finally { if (event.defaultPrevented) finishPageLoad(id); } + }; + queueMicrotask(() => { if (event.defaultPrevented) finishPageLoad(id); }); +}); +document.addEventListener('astro:before-swap', () => { + imageController.abort(); + finishPageLoad(); +}); +document.addEventListener('astro:after-swap', () => { + imageController = new AbortController(); + setupImages(); +}); +document.addEventListener('astro:page-load', () => { + finishPageLoad(); + setupImages(); +}); +window.addEventListener('pagehide', () => { imageController.abort(); finishPageLoad(); }); +window.addEventListener('pageshow', (event) => { + if (!event.persisted) return; + imageController = new AbortController(); + // Rebind images whose request was still pending when entering the page cache. + document.querySelectorAll('.image-load-frame').forEach((frame) => { + const media = frame.querySelector('picture') ?? frame.querySelector('img'); + if (media) frame.replaceWith(media); + }); + finishPageLoad(); + setupImages(); +}); + +if (document.readyState !== 'complete') beginPageLoad(); +setupImages(); diff --git a/src/scripts/navigation.ts b/src/scripts/navigation.ts new file mode 100644 index 0000000..a4c0714 --- /dev/null +++ b/src/scripts/navigation.ts @@ -0,0 +1,23 @@ +import type { TransitionBeforeSwapEvent } from 'astro:transitions/client'; + +// A language change reloads the document so Pagefind gets the new translations. +// Same-language document links use ClientRouter, including browser history. +document.addEventListener('click', (event) => { + const target = event.target instanceof Element ? event.target.closest('a[href]') : null; + if (!(target instanceof HTMLAnchorElement)) return; + const destination = new URL(target.href, location.href); + if (destination.origin !== location.origin) return; + const locale = (path: string) => /^\/(zh-cn|en)(?:\/|$)/.exec(path)?.[1]; + if (locale(destination.pathname) !== locale(location.pathname)) { + target.setAttribute('data-astro-reload', ''); + } +}, { capture: true }); + +document.addEventListener('astro:before-swap', (event) => { + const next = (event as TransitionBeforeSwapEvent).newDocument; + const theme = document.documentElement.dataset.theme; + if (theme) next.documentElement.dataset.theme = theme; + // A persisted search dialog must not cover the page selected from its results. + document.querySelector('.search-shell dialog[open]')?.close(); + document.body.removeAttribute('data-search-modal-open'); +}); diff --git a/src/scripts/search.ts b/src/scripts/search.ts new file mode 100644 index 0000000..4bd7f84 --- /dev/null +++ b/src/scripts/search.ts @@ -0,0 +1,76 @@ +import { pagefindUserConfig } from 'virtual:starlight/pagefind-config'; + +class DocsSearch extends HTMLElement { + private controller?: AbortController; + private initializing?: Promise; + private ready = false; + + connectedCallback() { + this.controller?.abort(); + this.controller = new AbortController(); + const { signal } = this.controller; + const dialog = this.querySelector('dialog')!; + const openButton = this.querySelector('[data-open-modal]')!; + const apple = /(Mac|iPhone|iPad|iPod)/i.test(navigator.platform); + this.querySelector('kbd')!.textContent = apple ? '⌘ K' : 'Ctrl K'; + openButton.setAttribute('aria-keyshortcuts', apple ? 'Meta+K' : 'Control+K'); + openButton.disabled = false; + const open = async () => { + if (!this.isConnected || this.ownerDocument !== document || dialog.open) return; + dialog.showModal(); + document.body.setAttribute('data-search-modal-open', ''); + try { + await this.initialize(); + if (dialog.open && this.isConnected) this.querySelector('input')?.focus(); + } catch { + this.querySelector('.search-status')!.textContent = this.dataset.error ?? ''; + } + }; + openButton.addEventListener('click', () => void open(), { signal }); + this.querySelector('[data-close-modal]')!.addEventListener('click', () => dialog.close(), { signal }); + dialog.addEventListener('click', (event) => { + if (event.target === dialog || (event.target instanceof Element && event.target.closest('a[href]'))) dialog.close(); + }, { signal }); + dialog.addEventListener('close', () => document.body.removeAttribute('data-search-modal-open'), { signal }); + window.addEventListener('keydown', (event) => { + if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'k' && !event.repeat) { + event.preventDefault(); + if (dialog.open) dialog.close(); + else void open(); + } + }, { signal }); + } + + disconnectedCallback() { + this.controller?.abort(); + this.querySelector('dialog[open]')?.close(); + document.body.removeAttribute('data-search-modal-open'); + } + + private async initialize() { + if (import.meta.env.DEV || this.ready) return; + if (!this.initializing) { + this.querySelector('.search-status')!.textContent = this.dataset.loading ?? ''; + this.initializing = (async () => { + // Pagefind does not publish TypeScript declarations for its default UI. + // @ts-expect-error Missing declarations for @pagefind/default-ui. + const { PagefindUI } = await import('@pagefind/default-ui'); + if (!this.isConnected || this.ownerDocument !== document) return; + new PagefindUI({ + ...pagefindUserConfig, + element: this.querySelector('#starlight__search'), + baseUrl: import.meta.env.BASE_URL, + bundlePath: import.meta.env.BASE_URL.replace(/\/$/, '') + '/pagefind/', + showImages: false, + showSubResults: true, + translations: JSON.parse(this.dataset.translations ?? '{}'), + }); + this.ready = true; + this.querySelector('.search-status')!.textContent = ''; + })().finally(() => { this.initializing = undefined; }); + } + await this.initializing; + } +} + +customElements.define('docs-search', DocsSearch); diff --git a/src/styles/custom.css b/src/styles/custom.css index 06e2cc2..33bc363 100644 --- a/src/styles/custom.css +++ b/src/styles/custom.css @@ -39,18 +39,6 @@ body, button, input, select, textarea, code, pre, kbd, samp { font-family: var(--sl-font); } -/* - * Site title ("ΣDOCS"): a heavy display face instead of the inherited body - * stack. `--sl-font-display` starts with Google's Manrope at weight 800 and - * falls back to Archivo Black, then locally installed faces, so a blocked - * webfont still renders a bold title. - */ -.site-title { - font-family: var(--sl-font-display); - font-weight: 800; - letter-spacing: -0.01em; -} - /* * Logo. The upstream rule sizes the image to exactly the nav's content box * (`nav-height - 2 * nav-pad-y`), so the square mark is capped at 2rem on phones diff --git a/src/styles/loading.css b/src/styles/loading.css new file mode 100644 index 0000000..7b52183 --- /dev/null +++ b/src/styles/loading.css @@ -0,0 +1,80 @@ +/* Official Material Web progress components retain their own geometry/keyframes. + * Only supported color tokens are mapped to this site's theme. Motion tokens: + * https://github.com/material-components/material-web/blob/main/tokens/versions/v0_192/_md-sys-motion.scss + */ +:root { + --md-sys-color-primary: var(--sl-color-text-accent); + --md-sys-color-surface-container-highest: var(--sl-color-gray-5); + --md-sys-motion-duration-short4: 200ms; + --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1); +} + +.page-load-progress { + position: fixed; + inset: 0 0 auto; + z-index: 100; + pointer-events: none; + view-transition-name: docs-loading; +} +.page-load-progress md-linear-progress { display: block; width: 100%; } +.page-load-reduced { display: none; } +::view-transition-old(docs-loading) { display: none; } + +.sl-markdown-content .image-load-frame { + position: relative; + display: block; + width: fit-content; + max-width: 100%; + isolation: isolate; +} +.sl-markdown-content .image-load-frame > :is(img, picture) { margin: 0; } +.image-load-frame[data-state='loading'] > :is(img, picture), +.image-load-frame[data-state='error'] > :is(img, picture) { opacity: 0; } +.image-load-frame[data-state='loaded'] > :is(img, picture) { + opacity: 1; + transition: opacity var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard); +} +.image-load-unsized:not([data-state='loaded']) { min-height: 8rem; min-width: min(16rem, 100%); } +.sl-markdown-content .image-load-mask { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + gap: .75rem; + margin: 0; + padding: 1rem; + border-radius: .25rem; + background: var(--sl-color-gray-6); + color: var(--sl-color-gray-2); + pointer-events: none; + opacity: 1; + transition: opacity var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard), + visibility 0s var(--md-sys-motion-duration-short4); +} +.image-load-mask md-circular-progress { flex: none; } +.image-load-status { font-size: var(--sl-text-sm); line-height: 1.5; text-align: center; } +.image-load-frame[data-state='loaded'] > .image-load-mask { opacity: 0; visibility: hidden; } + +/* Keep a textual status without movement when reduced motion is requested. */ +@media (prefers-reduced-motion: reduce) { + .page-load-progress md-linear-progress, + .image-load-mask md-circular-progress { display: none; } + .page-load-reduced { + display: block; + width: fit-content; + margin-inline: auto; + padding: .25rem .75rem; + color: var(--sl-color-text-accent); + background: var(--sl-color-bg-nav); + font-size: var(--sl-text-sm); + border-bottom: 2px solid currentColor; + } + .image-load-frame[data-state] > :is(img, picture), + .sl-markdown-content .image-load-mask { transition: none; } +} +@media print { + .page-load-progress, .image-load-mask { display: none; } + .image-load-frame[data-state] > :is(img, picture) { opacity: 1; } +}