Commit 77630fec authored by AI Bot's avatar AI Bot

首页3D时间线由Figma导出PNG改为canvas直绘

- 新增 static/timeline-data.js:13年39+5条时间线数据(cn/en),2026年补入真健康医疗、Momenta、奕斯伟计算3条
- addThreeD3.js 按数据直绘切片纹理(逐年块宽/换行宽实测自原稿,虚线年份轴,逐切片绘制规避iOS大画布限制)
- 中文引入 MiSans Light 子集(base.css @font-face),scripts/build-timeline-font.js 并入 npm run build 自动生成(pyftsubset)
- pages/index.js 引入 timeline-data.js
Co-Authored-By: 's avatarClaude Code <noreply@anthropic.com>
parent 63f3037c
...@@ -3,4 +3,5 @@ node_modules/ ...@@ -3,4 +3,5 @@ node_modules/
/npm-debug.log /npm-debug.log
.DS_Store .DS_Store
out/ out/
.python-version .python-versionscripts/.font-cache/
\ No newline at end of file .playwright-mcp/
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"dev": "set NODE_OPTIONS=--openssl-legacy-provider && next", "dev": "set NODE_OPTIONS=--openssl-legacy-provider && next",
"build": "set NODE_OPTIONS=--openssl-legacy-provider && next build", "build": "node scripts/build-timeline-font.js && set NODE_OPTIONS=--openssl-legacy-provider && next build",
"start": "set NODE_OPTIONS=--openssl-legacy-provider && next start", "start": "set NODE_OPTIONS=--openssl-legacy-provider && next start",
"exportwatch": "nodemon -e js,css,json,md,png,jpg,svg --exec \"npm run export\" --ignore .next/ --ignore out/", "exportwatch": "nodemon -e js,css,json,md,png,jpg,svg --exec \"npm run export\" --ignore .next/ --ignore out/",
"export": "npm run build && next export", "export": "npm run build && next export",
......
...@@ -42,6 +42,16 @@ ...@@ -42,6 +42,16 @@
url('/static/fonts/ttf/IBMPlexSerif-Medium.ttf') format('truetype') url('/static/fonts/ttf/IBMPlexSerif-Medium.ttf') format('truetype')
} }
/* 时间线 canvas 专用中文字体:MiSans Light 按字符子集化(仅含 timeline-data.js 用到的字)。
跨平台字形统一接近 PingFang;若 timeline-data.js 新增了子集外的字,会静默回退到 PingFang/雅黑,
需重新子集化。数据字符提取命令见 static/addThreeD3.js 注释 */
@font-face {
font-family: 'MiSans Timeline';
font-style: normal;
font-weight: 300;
src: url('/static/fonts/woff2/MiSans-Timeline-Light.woff2') format('woff2');
}
@font-face { @font-face {
font-family: "PingFang-SC"; font-family: "PingFang-SC";
font-weight: 100; font-weight: 100;
......
...@@ -115,6 +115,11 @@ class FrontPage extends React.Component { ...@@ -115,6 +115,11 @@ class FrontPage extends React.Component {
defer="defer" defer="defer"
src="/static/three.min.js" src="/static/three.min.js"
></script> ></script>
<script
key="timelineData"
defer="defer"
src="/static/timeline-data.js"
></script>
<script <script
key="addThreejs" key="addThreejs"
defer="defer" defer="defer"
......
// 时间线中文字体子集生成:从 static/timeline-data.js 提取所有用到字符,
// 用 pyftsubset 从 MiSans-Light.ttf 裁出 woff2 子集,输出到
// static/fonts/woff2/MiSans-Timeline-Light.woff2(base.css 中 @font-face 引用)。
//
// 用法: npm run timeline-font (或 node scripts/build-timeline-font.js)
// 依赖: python3 + fonttools + brotli (pip install fonttools brotli)
//
// timeline-data.js 新增文案后必须重跑本脚本,否则新字符会回退到系统字体。
// MiSans 由小米以免费商用许可发布: https://hyperos.mi.com/font
const fs = require('fs')
const path = require('path')
const { execFileSync } = require('child_process')
const root = path.join(__dirname, '..')
const dataFile = path.join(root, 'static/timeline-data.js')
const cacheDir = path.join(__dirname, '.font-cache')
const srcTtf = path.join(cacheDir, 'MiSans-Light.ttf')
const outFile = path.join(root, 'static/fonts/woff2/MiSans-Timeline-Light.woff2')
const TTF_URL = 'https://cdn.cnbj1.fds.api.mi-img.com/vipmlmodel/font/MiSans/MiSans.zip'
function extractChars() {
const src = fs.readFileSync(dataFile, 'utf8')
const chars = new Set()
for (const m of src.match(/'((?:[^'\\]|\\.)*)'/g) || []) {
for (const ch of m.slice(1, -1)) chars.add(ch)
}
// 兜底:ASCII 数字/字母/常用标点(年份、日期、证券代码用 IBM Plex Sans,
// 但子集里保留可避免数据改动时意外缺字)
for (const ch of '0123456789.:;,%()-·') chars.add(ch)
return [...chars].sort().join('')
}
function ensureSourceTtf() {
fs.mkdirSync(cacheDir, { recursive: true })
if (fs.existsSync(srcTtf)) return
console.log('下载 MiSans 官方字体包(约 51MB,仅首次)...')
execFileSync('curl', ['-sL', '--max-time', '300', '-o', path.join(cacheDir, 'misans.zip'), TTF_URL], { stdio: 'inherit' })
console.log('解压 MiSans-Light.ttf ...')
// 中文目录名不定,直接全解压后查找
execFileSync('unzip', ['-o', path.join(cacheDir, 'misans.zip'), '*', '-d', cacheDir + '/zip'], { stdio: 'ignore' })
const found = execFileSync('find', [cacheDir + '/zip', '-name', 'MiSans-Light.ttf']).toString().trim().split('\n')[0]
if (!found) throw new Error('压缩包中未找到 MiSans-Light.ttf')
fs.renameSync(found, srcTtf)
fs.rmSync(cacheDir + '/zip', { recursive: true, force: true })
}
function main() {
const text = extractChars()
console.log('时间线数据共', text.length, '个唯一字符')
ensureSourceTtf()
const charFile = path.join(cacheDir, 'chars.txt')
fs.writeFileSync(charFile, text)
execFileSync('pyftsubset', [
srcTtf,
'--text-file=' + charFile,
'--output-file=' + outFile,
'--flavor=woff2',
'--layout-features=*',
'--no-hinting',
'--desubroutinize'
], { stdio: 'inherit' })
const size = (fs.statSync(outFile).size / 1024).toFixed(1)
console.log('已生成', outFile, '(' + size + ' KB)')
}
main()
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment