Skip to content

Commit 8fb0a60

Browse files
committed
feat(docs): add centralized breakpoint configuration module
Create a single source of truth for responsive breakpoints (640px/960px) with CSS variables for documentation and VueUse hooks for Vue components.
1 parent c482496 commit 8fb0a60

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* SGEMM Optimization - 断点配置模块
3+
* 单一真相源:所有断点值从此模块导出
4+
*
5+
* 设计说明:
6+
* - CSS 规范不允许在 @media 中使用 var(),因此 CSS 媒体查询使用字面值
7+
* - 此模块作为 JS 层的断点真相源,供 Vue 组件和未来扩展使用
8+
* - CSS 中的断点变量 (--bp-sm, --bp-lg) 作为文档化引用
9+
*/
10+
11+
/** 断点常量 - 与 VitePress 核心保持一致 */
12+
export const BREAKPOINTS = {
13+
/** 移动端断点:640px 以下 */
14+
sm: 640,
15+
/** 平板/桌面断点:960px 以下 */
16+
lg: 960,
17+
} as const
18+
19+
/** 断点名称类型 */
20+
export type BreakpointName = keyof typeof BREAKPOINTS
21+
22+
/**
23+
* 生成媒体查询字符串(min-width 策略)
24+
* @param name 断点名称
25+
* @returns 媒体查询字符串,如 "(min-width: 640px)"
26+
*/
27+
export function minQuery(name: BreakpointName): string {
28+
return `(min-width: ${BREAKPOINTS[name]}px)`
29+
}
30+
31+
/**
32+
* 生成媒体查询字符串(max-width 策略)
33+
* @param name 断点名称
34+
* @returns 媒体查询字符串,如 "(max-width: 639px)"
35+
*/
36+
export function maxQuery(name: BreakpointName): string {
37+
return `(max-width: ${BREAKPOINTS[name] - 1}px)`
38+
}
39+
40+
/**
41+
* VueUse 响应式断点钩子
42+
* 在 Vue 组件中使用,获取当前视口状态
43+
*
44+
* @example
45+
* ```vue
46+
* <script setup>
47+
* import { useBreakpoint } from './breakpoints'
48+
* const { isMobile, isDesktop } = useBreakpoint()
49+
* </script>
50+
*
51+
* <template>
52+
* <div v-if="isMobile">移动端视图</div>
53+
* <div v-else>桌面端视图</div>
54+
* </template>
55+
* ```
56+
*/
57+
export function useBreakpoint() {
58+
// 动态导入 VueUse,避免在非 Vue 环境中报错
59+
// VitePress 已内置 @vueuse/core
60+
const { useMediaQuery } = require('@vueuse/core')
61+
62+
return {
63+
/** 是否为移动端(< 640px) */
64+
isMobile: useMediaQuery(maxQuery('sm')),
65+
/** 是否为平板/移动端(< 960px) */
66+
isCompact: useMediaQuery(maxQuery('lg')),
67+
/** 是否为桌面端(>= 960px) */
68+
isDesktop: useMediaQuery(minQuery('lg')),
69+
}
70+
}

docs/.vitepress/theme/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { watch, onMounted } from 'vue'
44
import { useData } from 'vitepress'
55
import Citation from '../components/Citation.vue'
66
import PerfCompare from '../components/PerfCompare.vue'
7+
// 导出断点模块供组件使用
8+
export { useBreakpoint, BREAKPOINTS, minQuery, maxQuery } from './breakpoints'
79

810
export default {
911
extends: DefaultTheme,

docs/.vitepress/theme/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
*/
88

99
:root {
10+
/* 断点变量 - 文档化引用,值与 breakpoints.ts 保持同步
11+
注意:CSS 规范不允许在 @media 中使用 var(),
12+
媒体查询必须使用字面值,变更时需同步更新 */
13+
--bp-sm: 640px;
14+
--bp-lg: 960px;
15+
1016
--vp-c-brand-1: #76b900;
1117
--vp-c-brand-2: #679f00;
1218
--vp-c-brand-3: #8bcd29;
@@ -879,6 +885,7 @@ div[class*='language-'] code,
879885
padding: 16px 18px;
880886
}
881887

888+
/* 平板/桌面断点 --bp-lg: 960px (见 breakpoints.ts) */
882889
@media (max-width: 960px) {
883890
.VPHero,
884891
.home-shell {
@@ -916,6 +923,7 @@ div[class*='language-'] code,
916923
}
917924
}
918925

926+
/* 移动端断点 --bp-sm: 640px (见 breakpoints.ts) */
919927
@media (max-width: 640px) {
920928
.VPNavBar,
921929
.VPHero,

0 commit comments

Comments
 (0)