From ac61333429afd77661f774c8c037d765b54f9b87 Mon Sep 17 00:00:00 2001 From: jie <2413704818@qq.com> Date: Tue, 6 Oct 2026 16:48:09 +0800 Subject: [PATCH 1/7] chore: add site-wide appearance customization and reading progress --- .gitignore | 3 + docusaurus.config.js | 10 + i18n/en/code.json | 112 ++++ package-lock.json | 96 +-- package.json | 9 +- scripts/copy-fonts.js | 50 ++ .../appearance/AppearancePanel.module.css | 312 ++++++++++ src/components/appearance/AppearancePanel.tsx | 301 ++++++++++ .../appearance/AppearancePanelHost.tsx | 55 ++ .../appearance/NavbarScrollBehavior.tsx | 89 +++ src/components/appearance/ReadingProgress.tsx | 87 +++ src/components/showcase/RingBuffer/sim.ts | 2 +- src/components/showcase/Showcase.tsx | 37 +- src/css/custom.css | 26 +- src/css/xrstyle-appearance.css | 549 ++++++++++++++++++ src/pages/index.tsx | 5 +- src/theme-modules.d.ts | 57 ++ src/theme/ColorModeToggle/index.module.css | 54 ++ src/theme/ColorModeToggle/index.tsx | 64 ++ src/theme/NavbarItem/index.module.css | 24 + src/theme/NavbarItem/index.tsx | 61 ++ src/theme/Root/index.tsx | 25 + src/utils/appearance.ts | 148 +++++ src/utils/motion.ts | 43 ++ src/utils/themeTransition.ts | 62 ++ static/appearance-init.js | 70 +++ tsconfig.json | 25 + 27 files changed, 2282 insertions(+), 94 deletions(-) create mode 100644 scripts/copy-fonts.js create mode 100644 src/components/appearance/AppearancePanel.module.css create mode 100644 src/components/appearance/AppearancePanel.tsx create mode 100644 src/components/appearance/AppearancePanelHost.tsx create mode 100644 src/components/appearance/NavbarScrollBehavior.tsx create mode 100644 src/components/appearance/ReadingProgress.tsx create mode 100644 src/css/xrstyle-appearance.css create mode 100644 src/theme-modules.d.ts create mode 100644 src/theme/ColorModeToggle/index.module.css create mode 100644 src/theme/ColorModeToggle/index.tsx create mode 100644 src/theme/NavbarItem/index.module.css create mode 100644 src/theme/NavbarItem/index.tsx create mode 100644 src/theme/Root/index.tsx create mode 100644 src/utils/appearance.ts create mode 100644 src/utils/motion.ts create mode 100644 src/utils/themeTransition.ts create mode 100644 static/appearance-init.js create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index c13da98..af1e84c 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ Thumbs.db *.swo .docusaurus/** src/data/commitInfo.json + +# Copied webfont assets (generated by scripts/copy-fonts.js) +static/fonts/lxgw/ diff --git a/docusaurus.config.js b/docusaurus.config.js index eb8722d..b9b8f8a 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -12,6 +12,11 @@ module.exports = { projectName: 'xrobot-org.github.io', scripts: [ + { + // Anti-FOUC appearance init: must run synchronously in
. + src: '/appearance-init.js', + async: false, + }, { src: 'https://static.cloudflareinsights.com/beacon.min.js', defer: true, @@ -63,6 +68,7 @@ module.exports = { theme: { customCss: [ require.resolve('./src/css/xrstyle-tokens.css'), + require.resolve('./src/css/xrstyle-appearance.css'), require.resolve('./src/css/xrstyle-components.css'), require.resolve('./src/css/xrstyle-materials.css'), require.resolve('./src/css/custom.css'), @@ -92,6 +98,10 @@ module.exports = { type: 'localeDropdown', position: 'right', }, + { + type: 'custom-xr-appearance', + position: 'right', + }, { href: 'https://github.com/xrobot-org/xrobot-org.github.io', label: 'GitHub', diff --git a/i18n/en/code.json b/i18n/en/code.json index 3e31622..903881e 100644 --- a/i18n/en/code.json +++ b/i18n/en/code.json @@ -1537,5 +1537,117 @@ }, "home.route.port.more3": { "message": "About Performance" + }, + "appearance.panelTitle": { + "message": "Appearance settings", + "description": "The title (aria-label) of the appearance settings panel" + }, + "appearance.panelToggle": { + "message": "Appearance settings", + "description": "The aria-label of the appearance settings (palette) navbar button" + }, + "appearance.colorModeToggle": { + "message": "Toggle color mode", + "description": "The aria-label of the light/dark mode toggle button" + }, + "appearance.scrollProgress.aria": { + "message": "Page scroll progress {n}%", + "description": "The aria-label of the reading progress circle; {n} is the percentage" + }, + "appearance.fontStyle": { + "message": "Font style", + "description": "The font style section of the appearance panel" + }, + "appearance.fontDefault": { + "message": "Default font", + "description": "The default font option" + }, + "appearance.fontWenkai": { + "message": "LXGW WenKai", + "description": "The LXGW WenKai font option" + }, + "appearance.hue": { + "message": "Theme hue", + "description": "The theme hue section of the appearance panel" + }, + "appearance.accentMono": { + "message": "Ink (mono)", + "description": "The mono (ink) accent option" + }, + "appearance.hueReset": { + "message": "Reset", + "description": "The aria-label of the button that resets the accent back to mono" + }, + "appearance.cardDecor": { + "message": "Card decor", + "description": "The card decoration section of the appearance panel" + }, + "appearance.cardDecorSharp": { + "message": "Sharp edges", + "description": "The sharp (square) card decoration option" + }, + "appearance.cardDecorSharpDesc": { + "message": "Square cut, no shadow", + "description": "The description of the sharp card decoration option" + }, + "appearance.cardDecorSoft": { + "message": "Soft rounded", + "description": "The soft rounded card decoration option" + }, + "appearance.cardDecorSoftDesc": { + "message": "Rounded border, soft shadow", + "description": "The description of the soft rounded card decoration option" + }, + "appearance.navbar": { + "message": "Navbar", + "description": "The navbar section of the appearance panel" + }, + "appearance.navbarAutohide": { + "message": "Auto-hide on scroll", + "description": "The auto-hide navbar option" + }, + "appearance.navbarAutohideDesc": { + "message": "Hides when scrolling down, returns when scrolling up", + "description": "The description of the auto-hide navbar option" + }, + "appearance.navbarAlways": { + "message": "Always expanded", + "description": "The always-expanded navbar option" + }, + "appearance.navbarAlwaysDesc": { + "message": "Keeps the full navigation while scrolling", + "description": "The description of the always-expanded navbar option" + }, + "appearance.bgMode": { + "message": "Background", + "description": "The background texture section of the appearance panel" + }, + "appearance.bgPlain": { + "message": "Plain", + "description": "The plain background option" + }, + "appearance.bgGrid": { + "message": "Grid", + "description": "The grid background option" + }, + "appearance.bgDots": { + "message": "Dots", + "description": "The dots background option" + }, + "appearance.preferences": { + "message": "Preferences", + "description": "The preferences section of the appearance panel" + }, + "appearance.animations": { + "message": "Animations", + "description": "The animation preference label" + }, + "appearance.animationsOn": { + "message": "On", + "description": "The animations-on option" + }, + "appearance.animationsOff": { + "message": "Off", + "description": "The animations-off option" } } diff --git a/package-lock.json b/package-lock.json index 84c7038..f579fb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "axios": "^1.12.2", "cheerio": "1.0.0-rc.12", "framer-motion": "^12.23.24", + "lxgw-wenkai-screen-webfont": "^1.7.0", "react": "18.3.1", "react-dom": "18.3.1" }, @@ -23,7 +24,10 @@ "@docusaurus/core": "3.9.2", "@docusaurus/preset-classic": "3.9.2", "@docusaurus/theme-mermaid": "3.9.2", - "prism-react-renderer": "^2.4.1" + "@types/react": "^18.3.31", + "@types/react-dom": "^18.3.7", + "prism-react-renderer": "^2.4.1", + "typescript": "^5.9.3" } }, "node_modules/@ai-sdk/gateway": { @@ -463,7 +467,6 @@ "integrity": "sha512-pO/LpVnQlbJpcHRk+AroWyyFnh01eOlO6/uLZRUmYvr/hpKZKxI6n7ufgTawbo0KrAu2CePfiOkStYOmDuRjzQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/client-common": "4.25.2", "@algolia/requester-common": "4.25.2", @@ -735,7 +738,6 @@ "integrity": "sha512-2BCOP7TN8M+gVDj7/ht3hsaO/B/n5oDbiAyyvnRlNOs+u1o+JWNYTQrmpuNp1/Wq2gcFrI01JAW+paEKDMx/CA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.3", @@ -2776,7 +2778,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" }, @@ -2800,7 +2801,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" } @@ -2915,7 +2915,6 @@ "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -3353,7 +3352,6 @@ "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -4070,7 +4068,6 @@ "integrity": "sha512-Mw6pAUF121MfngQtcUb5quZVqMC68pSYYjCRZkSITC085S3zdk+h/g7i6FxnVdbSU6OztxikSDMh1r7Z+4iPlA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/client-common": "5.40.1", "@algolia/requester-browser-xhr": "5.40.1", @@ -4129,7 +4126,6 @@ "integrity": "sha512-iUNxcXUNg9085TJx0HJLjqtDE0r1RZ0GOGrt8KNQqQT5ugu8lZsHuMUYW/e0lHhq6xBvmktU9Bw4CXP9VQeKrg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/abtesting": "1.6.1", "@algolia/client-abtesting": "5.40.1", @@ -4227,7 +4223,6 @@ "integrity": "sha512-HbjwKeC+pHUFBfLMNzuSjqFE/58+rLVKmOU3lxQrpsxLBOGosYco/Q0GduBb0/jEMRiyEqjNT/01rRdOMWq5pw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@docusaurus/babel": "3.9.2", "@docusaurus/bundler": "3.9.2", @@ -4415,7 +4410,6 @@ "integrity": "sha512-C5wZsGuKTY8jEYsqdxhhFOe1ZDjH0uIYJ9T/jebHwkyxqnr4wW0jTkB72OMqNjsoQRcb0JN3PcSeTwFlVgzCZg==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@docusaurus/core": "3.9.2", "@docusaurus/logger": "3.9.2", @@ -5359,7 +5353,6 @@ "integrity": "sha512-f++rKLQgUVYDAtECQ6fn/is15GkEH9+nZPM3MS0RcxVqoTfawHvDlSCH7JbMhAM6uJ32v3eXLvLmLvjGu7PTQw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/mdx": "^2.0.0" }, @@ -5979,7 +5972,6 @@ "integrity": "sha512-8QqtOQT5ACVlmsvKOJNEaWmRPmcojMOzCz4Hs2BGG/toAp/K38LcsMRyLp349glq5AzJbCEeimEoxaX6v/fLrA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/core": "^7.21.3", "@svgr/babel-preset": "8.1.0", @@ -6670,6 +6662,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/prop-types": { + "version": "15.7.15", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.15.tgz", + "integrity": "sha512-F6bEyamV9jKGAFBEmlQnesRPGOQqS2+Uwi0Em15xenOxHaf2hv6L8YCVn3rPdPJOiJfPiCnLIRyvwVaqMY3MIw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/qs": { "version": "6.14.0", "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.14.0.tgz", @@ -6685,14 +6684,24 @@ "license": "MIT" }, "node_modules/@types/react": { - "version": "19.2.2", - "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.2.tgz", - "integrity": "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA==", + "version": "18.3.31", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.31.tgz", + "integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { - "csstype": "^3.0.2" + "@types/prop-types": "*", + "csstype": "^3.2.2" + } + }, + "node_modules/@types/react-dom": { + "version": "18.3.7", + "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.3.7.tgz", + "integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@types/react": "^18.0.0" } }, "node_modules/@types/react-router": { @@ -7033,8 +7042,7 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz", "integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@xtuc/ieee754": { "version": "1.2.0", @@ -7080,7 +7088,6 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -7173,7 +7180,6 @@ "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -7222,7 +7228,6 @@ "integrity": "sha512-lYx98L6kb1VvXypbPI7Z54C4BJB2VT5QvOYthvPq6/POufZj+YdyeZSKjoLBKHJgGmYWQTHOKtcCTdKf98WOCA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@algolia/cache-browser-local-storage": "4.25.2", "@algolia/cache-common": "4.25.2", @@ -7751,7 +7756,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.9", "caniuse-lite": "^1.0.30001746", @@ -8071,7 +8075,6 @@ "integrity": "sha512-ci2iJH6LeIkvP9eJW6gpueU8cnZhv85ELY8w8WiFtNjMHA5ad6pQLaJo9mEly/9qUyCpvqX8/POVUTf18/HFdw==", "dev": true, "license": "Apache-2.0", - "peer": true, "dependencies": { "@chevrotain/cst-dts-gen": "11.0.3", "@chevrotain/gast": "11.0.3", @@ -8831,7 +8834,6 @@ "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -9154,9 +9156,9 @@ "license": "CC0-1.0" }, "node_modules/csstype": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", - "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", "dev": true, "license": "MIT" }, @@ -9166,7 +9168,6 @@ "integrity": "sha512-iJc4TwyANnOGR1OmWhsS9ayRS3s+XQ185FmuHObThD+5AeJCakAAbWv8KimMTt08xCCLNgneQwFp+JRJOr9qGQ==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=0.10" } @@ -9611,7 +9612,6 @@ "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", "dev": true, "license": "ISC", - "peer": true, "engines": { "node": ">=12" } @@ -10928,7 +10928,6 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -13135,6 +13134,12 @@ "dev": true, "license": "MPL-1.1" }, + "node_modules/lxgw-wenkai-screen-webfont": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/lxgw-wenkai-screen-webfont/-/lxgw-wenkai-screen-webfont-1.7.0.tgz", + "integrity": "sha512-xvfF4V26Mb335xKg3uxljz+V2nq4F5ek0ku9pmyKgT0Dzo/d2rHi7WpnqgvM9mlXAcAKOrxrcDmUZiIs/ZQ9bQ==", + "license": "MIT" + }, "node_modules/mark.js": { "version": "8.11.1", "resolved": "https://registry.npmjs.org/mark.js/-/mark.js-8.11.1.tgz", @@ -15965,7 +15970,6 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -16585,7 +16589,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -17537,7 +17540,6 @@ "integrity": "sha512-8sLjZwK0R+JlxlYcTuVnyT2v+htpdrjDOKuMcOVdYjt52Lh8hWRYpxBPoKx/Zg+bcjc3wx6fmQevMmUztS/ccA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "cssesc": "^3.0.0", "util-deprecate": "^1.0.2" @@ -18431,7 +18433,6 @@ "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "license": "MIT", - "peer": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -18444,7 +18445,6 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", "license": "MIT", - "peer": true, "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" @@ -18506,7 +18506,6 @@ "integrity": "sha512-YMMxTUQV/QFSnbgrP3tjDzLHRg7vsbMn8e9HAa8o/1iXoiomo48b7sk/kkmWEuWNDPJVlKSJRB6Y2fHqdJk+SQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/react": "*" }, @@ -18537,7 +18536,6 @@ "integrity": "sha512-Ys9K+ppnJah3QuaRiLxk+jDWOR1MekYQrlytiXxC1RyfbdsZkS5pvKAzCCr031xHixZwpnsYNT5xysdFHQaYsA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/runtime": "^7.12.13", "history": "^4.9.0", @@ -20541,8 +20539,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", - "peer": true + "license": "0BSD" }, "node_modules/type-fest": { "version": "2.19.0", @@ -20581,6 +20578,20 @@ "is-typedarray": "^1.0.0" } }, + "node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/ufo": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.1.tgz", @@ -20955,7 +20966,6 @@ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -21219,7 +21229,6 @@ "integrity": "sha512-7h/weGm9d/ywQ6qzJ+Xy+r9n/3qgp/thalBbpOi5i223dPXKi04IBtqPN9nTd+jBc7QKfvDbaBnFipYp4sJAUQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/eslint-scope": "^3.7.7", "@types/estree": "^1.0.8", @@ -21843,7 +21852,6 @@ "integrity": "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ==", "dev": true, "license": "MIT", - "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index c386be4..30a7716 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "private": true, "scripts": { "start": "docusaurus start", - "prebuild": "node scripts/fetch-commits.js", + "prestart": "node scripts/copy-fonts.js", + "prebuild": "node scripts/fetch-commits.js && node scripts/copy-fonts.js", "build": "docusaurus build", "deploy": "docusaurus deploy", "serve": "docusaurus serve" @@ -17,6 +18,7 @@ "axios": "^1.12.2", "cheerio": "1.0.0-rc.12", "framer-motion": "^12.23.24", + "lxgw-wenkai-screen-webfont": "^1.7.0", "react": "18.3.1", "react-dom": "18.3.1" }, @@ -25,6 +27,9 @@ "@docusaurus/core": "3.9.2", "@docusaurus/preset-classic": "3.9.2", "@docusaurus/theme-mermaid": "3.9.2", - "prism-react-renderer": "^2.4.1" + "@types/react": "^18.3.31", + "@types/react-dom": "^18.3.7", + "prism-react-renderer": "^2.4.1", + "typescript": "^5.9.3" } } diff --git a/scripts/copy-fonts.js b/scripts/copy-fonts.js new file mode 100644 index 0000000..29738b4 --- /dev/null +++ b/scripts/copy-fonts.js @@ -0,0 +1,50 @@ +/** + * Copy the LXGW WenKai Screen webfont (npm: lxgw-wenkai-screen-webfont) into + * static/fonts/lxgw/ so it ships as a static asset: + * - every top-level *.css of the package -> static/fonts/lxgw/*.css + * - the whole files/ directory -> static/fonts/lxgw/files/ + * The CSS references ./files/... relatively, so the layout must be preserved. + * static/fonts/lxgw/ is gitignored; the copy runs via `prestart` / `prebuild`. + * + * If the target directory exists it is emptied first, so the output always + * matches the installed package version exactly. + */ +const fs = require('fs'); +const path = require('path'); + +const projectRoot = path.resolve(__dirname, '..'); +const sourceDir = path.join(projectRoot, 'node_modules', 'lxgw-wenkai-screen-webfont'); +const targetDir = path.join(projectRoot, 'static', 'fonts', 'lxgw'); + +if (!fs.existsSync(sourceDir)) { + console.error( + '[copy-fonts] node_modules/lxgw-wenkai-screen-webfont not found. Run `npm install` first.' + ); + process.exit(1); +} + +// Empty the target dir but keep it (avoids churn if something watches static/). +if (fs.existsSync(targetDir)) { + fs.rmSync(targetDir, { recursive: true, force: true }); +} +fs.mkdirSync(targetDir, { recursive: true }); + +// Copy all package CSS files (keep original names, e.g. lxgwwenkaiscreen.css). +const entries = fs.readdirSync(sourceDir, { withFileTypes: true }); +let copied = 0; +for (const entry of entries) { + if (entry.isFile() && entry.name.endsWith('.css')) { + fs.copyFileSync(path.join(sourceDir, entry.name), path.join(targetDir, entry.name)); + copied += 1; + } +} + +// Copy the whole font files/ directory (relative ./files/ URLs must resolve). +const sourceFiles = path.join(sourceDir, 'files'); +const targetFiles = path.join(targetDir, 'files'); +fs.cpSync(sourceFiles, targetFiles, { recursive: true }); +const fileCount = fs.readdirSync(targetFiles).length; + +console.log( + `[copy-fonts] LXGW WenKai Screen -> static/fonts/lxgw (${copied} css, ${fileCount} font files)` +); diff --git a/src/components/appearance/AppearancePanel.module.css b/src/components/appearance/AppearancePanel.module.css new file mode 100644 index 0000000..8a84a3d --- /dev/null +++ b/src/components/appearance/AppearancePanel.module.css @@ -0,0 +1,312 @@ +/* Appearance settings panel. Only contract CSS variables and tokens are used + (no hardcoded colors); the hue swatches/slider spectrum use oklch() built + from the hue number itself, matching the Aemeath --color-selection-bar. */ + +.panel { + position: fixed; + top: calc(var(--ifm-navbar-height, 60px) + 8px); + right: 1rem; + z-index: 1900; + width: 20rem; + max-height: calc(100vh - 6rem); + padding: 0.75rem 0.875rem 1rem; + overflow-y: auto; + background: var(--paper-raised); + border: 1px solid var(--line); + border-radius: var(--ifm-button-border-radius); + box-shadow: 0 12px 40px rgb(0 0 0 / 0.18); + animation: panel-in 0.2s ease; +} + +@keyframes panel-in { + from { + opacity: 0; + transform: translateY(-8px); + } +} + +@media (max-width: 767px) { + .panel { + right: 1rem; + left: 1rem; + width: auto; + } +} + +.sectionTitle { + position: relative; + margin: 0.625rem 0 0.5rem; + padding-left: 0.5rem; + font-size: 0.875rem; + font-weight: 700; + line-height: 1.2; + color: var(--ink); +} + +.sectionTitle::before { + content: ''; + position: absolute; + top: 50%; + left: 0; + width: 3px; + height: 0.75rem; + border-radius: 2px; + background: var(--xr-accent); + transform: translateY(-50%); +} + +.options { + display: flex; + gap: 0.5rem; +} + +.option { + flex: 1; + min-width: 0; + padding: 0.5rem 0.625rem; + border: 1px solid var(--line); + border-radius: var(--ifm-button-border-radius); + background: transparent; + color: var(--ink); + font-size: 0.8125rem; + line-height: 1.35; + text-align: left; + cursor: pointer; + transition: + border-color 0.15s ease, + color 0.15s ease, + background-color 0.15s ease; +} + +.option:hover { + background: var(--paper-sunken); +} + +.optionActive { + border-color: var(--xr-accent); + color: var(--xr-accent); +} + +.optionDesc { + display: block; + margin-top: 0.125rem; + font-size: 0.6875rem; + font-weight: 400; + color: var(--ink-muted); +} + +/* 主题色相 */ + +.swatchRow { + display: flex; + gap: 0.4rem; + align-items: center; + margin-bottom: 0.5rem; +} + +.swatch { + flex: 1; + aspect-ratio: 1; + max-width: 1.6rem; + padding: 0; + border: 2px solid var(--line); + border-radius: 50%; + cursor: pointer; + transition: + border-color 0.15s ease, + box-shadow 0.15s ease; +} + +.swatchActive { + border-color: var(--xr-accent); + box-shadow: 0 0 0 1px var(--xr-accent); +} + +.hueRow { + display: flex; + gap: 0.5rem; + align-items: center; +} + +.hueSlider { + flex: 1; + height: 0.75rem; + margin: 0; + appearance: none; + -webkit-appearance: none; + border: 1px solid var(--line); + border-radius: 999px; + background: linear-gradient( + 90deg, + oklch(0.8 0.1 0), + oklch(0.8 0.1 30), + oklch(0.8 0.1 60), + oklch(0.8 0.1 90), + oklch(0.8 0.1 120), + oklch(0.8 0.1 150), + oklch(0.8 0.1 180), + oklch(0.8 0.1 210), + oklch(0.8 0.1 240), + oklch(0.8 0.1 270), + oklch(0.8 0.1 300), + oklch(0.8 0.1 330), + oklch(0.8 0.1 360) + ); + cursor: pointer; +} + +.hueSlider::-webkit-slider-thumb { + appearance: none; + -webkit-appearance: none; + width: 0.5rem; + height: 1rem; + border: none; + border-radius: 0.125rem; + background: rgb(255 255 255 / 0.75); +} + +.hueSlider::-moz-range-thumb { + width: 0.5rem; + height: 1rem; + border: none; + border-radius: 0.125rem; + background: rgb(255 255 255 / 0.75); +} + +.hueDimmed { + opacity: 0.35; +} + +.hueBadge { + min-width: 2.25rem; + padding: 0.25rem 0.25rem; + border-radius: var(--ifm-button-border-radius); + background: var(--paper-sunken); + color: var(--ink); + font-size: 0.75rem; + font-weight: 700; + text-align: center; + font-variant-numeric: tabular-nums; +} + +.resetBtn { + width: 1.75rem; + height: 1.75rem; + padding: 0; + border: 1px solid var(--line); + border-radius: var(--ifm-button-border-radius); + background: transparent; + color: var(--ink-muted); + font-size: 0.875rem; + line-height: 1; + cursor: pointer; + transition: + color 0.15s ease, + border-color 0.15s ease; +} + +.resetBtn:hover { + border-color: var(--xr-accent); + color: var(--xr-accent); +} + +/* 卡片装饰 */ + +.decorCard { + display: flex; + flex-direction: column; + gap: 0.375rem; +} + +.decorCardSharp { + border-radius: 0; + box-shadow: none; +} + +.decorCardSoft { + border-radius: 0.5rem; + box-shadow: 0 2px 8px rgb(0 0 0 / 0.1); +} + +.decorPreview { + display: flex; + gap: 0.25rem; + align-items: flex-end; + margin-bottom: 0.125rem; +} + +.decorChip { + width: 1.25rem; + height: 1.25rem; + border: 1px solid var(--line-strong); + background: var(--paper-sunken); +} + +.decorChipSharp { + border-radius: 0; +} + +.decorChipSoft { + border-radius: 0.375rem; +} + +.decorBtn { + flex: 1; + height: 0.625rem; + border: 1px solid var(--line-strong); + background: var(--paper-sunken); +} + +.decorBtnSharp { + border-radius: 0; +} + +.decorBtnSoft { + border-radius: 999px; +} + +/* 背景纹理 */ + +.bgBtn { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 0.375rem; + align-items: center; + padding: 0.5rem 0.375rem; + border: 1px solid var(--line); + border-radius: var(--ifm-button-border-radius); + background: transparent; + color: var(--ink); + font-size: 0.75rem; + cursor: pointer; + transition: + border-color 0.15s ease, + color 0.15s ease, + background-color 0.15s ease; +} + +.bgBtn:hover { + background: var(--paper-sunken); +} + +.bgPreview { + width: 100%; + height: 1.75rem; + border: 1px solid var(--line); + border-radius: 0.25rem; + background: var(--paper-sunken); +} + +.bgPreviewGrid { + background-image: + linear-gradient(var(--line) 1px, transparent 1px), + linear-gradient(90deg, var(--line) 1px, transparent 1px); + background-size: 6px 6px; +} + +.bgPreviewDots { + background-image: radial-gradient(var(--line-strong) 1px, transparent 1px); + background-size: 6px 6px; +} diff --git a/src/components/appearance/AppearancePanel.tsx b/src/components/appearance/AppearancePanel.tsx new file mode 100644 index 0000000..3b728a8 --- /dev/null +++ b/src/components/appearance/AppearancePanel.tsx @@ -0,0 +1,301 @@ +/** + * Appearance settings panel (rendered next to the navbar palette button by the + * NavbarItem wrapper, fixed under the navbar edge; positioning lives in the + * CSS module). All options apply immediately: localStorage + html data + * attribute (+ --xr-hue when needed), per the shared contract with the CSS + * layer. Initial values are read from localStorage in a mount effect so the + * SSR output (panel closed / defaults) never mismatches. + */ +import React, { useEffect, useState } from 'react'; +import { translate } from '@docusaurus/Translate'; +import { readMotionOff, setMotionOff } from '@site/src/utils/motion'; +import { + DEFAULT_SLIDER_HUE, + readAccentHue, + readBgMode, + readCardDecor, + readFontMode, + readNavbarMode, + writeAccentHue, + writeBgMode, + writeCardDecor, + writeFontMode, + writeNavbarMode, + type BgMode, + type CardDecor, + type FontMode, + type NavbarMode, +} from '@site/src/utils/appearance'; +import styles from './AppearancePanel.module.css'; + +const HUE_PRESETS: readonly number[] = [25, 55, 145, 195, 250, 300]; + +export default function AppearancePanel({ onClose }: { onClose: () => void }): JSX.Element { + const [accent, setAccent] = useState<'mono' | 'hue'>('mono'); + const [hue, setHue] = useState(DEFAULT_SLIDER_HUE); + const [fontMode, setFontMode] = useStateXRobot is all you need
+