@iasiv5/dsh-skills 1.0.0 → 1.0.2

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.
Files changed (37) hide show
  1. package/locale/en.json +6 -0
  2. package/locale/zh.json +6 -0
  3. package/package.json +4 -2
  4. package/skills/answer-me-with-html/SKILL.md +4 -2
  5. package/skills/answer-me-with-html/scripts/am.mjs +627 -192
  6. package/skills/guizang-ppt-skill/README.en.md +10 -8
  7. package/skills/guizang-ppt-skill/README.md +10 -8
  8. package/skills/guizang-ppt-skill/SKILL.md +20 -16
  9. package/skills/guizang-ppt-skill/assets/template-swiss.html +1068 -456
  10. package/skills/guizang-ppt-skill/assets/template.html +991 -225
  11. package/skills/guizang-ppt-skill/references/checklist.md +5 -4
  12. package/skills/guizang-ppt-skill/references/components.md +9 -5
  13. package/skills/guizang-ppt-skill/references/gz-components.md +289 -0
  14. package/skills/guizang-ppt-skill/references/layouts-swiss.md +17 -17
  15. package/skills/guizang-ppt-skill/references/layouts.md +1 -1
  16. package/skills/guizang-ppt-skill/references/themes-swiss.md +57 -86
  17. package/skills/guizang-ppt-skill/references/themes.md +65 -63
  18. package/skills/guizang-ppt-skill/scripts/gz-theme.mjs +434 -0
  19. package/skills/guizang-social-card-skill/HANDOFF.md +19 -1
  20. package/skills/guizang-social-card-skill/README.en.md +20 -7
  21. package/skills/guizang-social-card-skill/README.md +20 -7
  22. package/skills/guizang-social-card-skill/SKILL.md +7 -5
  23. package/skills/guizang-social-card-skill/assets/template-editorial-card.html +954 -126
  24. package/skills/guizang-social-card-skill/assets/template-swiss-card.html +588 -84
  25. package/skills/guizang-social-card-skill/package-lock.json +90 -1
  26. package/skills/guizang-social-card-skill/package.json +7 -4
  27. package/skills/guizang-social-card-skill/references/background-systems.md +7 -15
  28. package/skills/guizang-social-card-skill/references/components.md +16 -10
  29. package/skills/guizang-social-card-skill/references/gz-components.md +289 -0
  30. package/skills/guizang-social-card-skill/references/layout-recipes.md +1 -1
  31. package/skills/guizang-social-card-skill/references/production-workflow.md +10 -12
  32. package/skills/guizang-social-card-skill/references/style-system.md +1 -1
  33. package/skills/guizang-social-card-skill/references/theme-presets.md +59 -111
  34. package/skills/guizang-social-card-skill/scripts/gz-fonts.mjs +654 -0
  35. package/skills/guizang-social-card-skill/scripts/gz-theme.mjs +434 -0
  36. package/skills/guizang-social-card-skill/scripts/render.mjs +92 -0
  37. package/skills/guizang-social-card-skill/validate-social-deck.mjs +11 -6
@@ -0,0 +1,654 @@
1
+ #!/usr/bin/env node
2
+ // 歸藏设计系统 · 字体工具(guizang-design v0.1.0 生成,不要手改;内置字体时依赖 subset-font)
3
+ import { createHash } from 'node:crypto'
4
+ import { existsSync } from 'node:fs'
5
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises'
6
+ import { homedir } from 'node:os'
7
+ import { join } from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+
10
+ const FONTS_DIR = (() => { try { return fileURLToPath(new URL('../fonts/', import.meta.url)) } catch { return '' } })()
11
+ const MANIFEST_PATH = join(FONTS_DIR, 'manifest.json')
12
+ const LOCK_PATH = join(FONTS_DIR, 'lock.json')
13
+
14
+ export const cacheDir = () => process.env.GUIZANG_FONT_CACHE || join(homedir(), '.cache', 'guizang-design', 'fonts')
15
+
16
+ // 国内访问 fonts.googleapis.com 不稳定时,可以换成兼容 css2 接口的镜像
17
+ export const cssHost = () => process.env.GUIZANG_FONT_CSS_HOST || 'https://fonts.googleapis.com'
18
+
19
+ // 子集里总是带上的字:ASCII 可见字符、常用中文标点、数字相关符号,避免后期改一个字就缺字
20
+ export const BASE_CHARS =
21
+ Array.from({ length: 95 }, (_, i) => String.fromCharCode(32 + i)).join('') +
22
+ ',。、;:?!“”‘’()《》〈〉【】「」『』—…·¥%+-×÷→←↑↓©®™°±€£¥§¶•–'
23
+
24
+ export const userFontsPath = () => process.env.GUIZANG_USER_FONTS || join(homedir(), '.config', 'guizang-design', 'fonts.json')
25
+
26
+ async function loadUserFonts() {
27
+ const p = userFontsPath()
28
+ if (!existsSync(p)) return []
29
+ const { fonts = [] } = JSON.parse(await readFile(p, 'utf8'))
30
+ return fonts.map((f) => ({ ...f, local: true, status: 'local' }))
31
+ }
32
+
33
+ // 数据源:在设计系统仓库里读 fonts/ 目录;打包进 skill 后(gz-fonts.mjs)改用内嵌的清单和 lock,lock 只读
34
+ const source = {
35
+ manifest: async () => JSON.parse(await readFile(MANIFEST_PATH, 'utf8')),
36
+ lock: async () => (existsSync(LOCK_PATH) ? JSON.parse(await readFile(LOCK_PATH, 'utf8')) : {}),
37
+ saveLock: (lock) => writeFile(LOCK_PATH, JSON.stringify(lock, null, 2) + '\n'),
38
+ }
39
+ export function useEmbeddedData(manifest, lock) {
40
+ source.manifest = async () => manifest
41
+ source.lock = async () => lock
42
+ source.saveLock = async () => {}
43
+ }
44
+
45
+ export async function loadManifest() {
46
+ const manifest = await source.manifest()
47
+ const user = await loadUserFonts()
48
+ const clash = user.find((u) => manifest.fonts.some((f) => f.id === u.id))
49
+ if (clash) throw new Error(`本机字体 ${clash.id} 和内置字体重名,请在 ${userFontsPath()} 里换一个 id`)
50
+ return { ...manifest, fonts: [...manifest.fonts, ...user] }
51
+ }
52
+
53
+ // 登记一款本机字体。文件名带 Italic 的视为斜体;字重取 fvar 范围,静态字体取 OS/2 的 usWeightClass
54
+ export async function addUserFont({ id, family, category = 'sans', script = 'latin', files, note }) {
55
+ const entries = []
56
+ for (const file of files) {
57
+ const buf = await readFile(file)
58
+ const axes = readAxes(buf)
59
+ entries.push({ style: /italic/i.test(file) ? 'italic' : 'normal', ...(axes.wght ? {} : { weight: readWeightClass(buf) }), file })
60
+ }
61
+ const p = userFontsPath()
62
+ const current = existsSync(p) ? JSON.parse(await readFile(p, 'utf8')) : { fonts: [] }
63
+ current.fonts = current.fonts.filter((f) => f.id !== id)
64
+ current.fonts.push({ id, family, category, script, license: 'user', files: entries, ...(note ? { note } : {}) })
65
+ await mkdir(join(p, '..'), { recursive: true })
66
+ await writeFile(p, JSON.stringify(current, null, 2) + '\n')
67
+ return { path: p, files: entries }
68
+ }
69
+
70
+ const loadLock = () => source.lock()
71
+
72
+ export async function getFont(id) {
73
+ const { fonts } = await loadManifest()
74
+ const font = fonts.find((f) => f.id === id)
75
+ if (!font) throw new Error(`字体清单里没有 ${id},可用:${fonts.map((f) => f.id).join(', ')}`)
76
+ return font
77
+ }
78
+
79
+ const fileUrl = (pin, path) => `https://raw.githubusercontent.com/google/fonts/${pin}/${encodeURI(path)}`
80
+ const cachePath = (pin, path) => join(cacheDir(), pin.slice(0, 12), path.replace(/[\[\]]/g, '_'))
81
+
82
+ // ---------- OpenType fvar:读可变字体的轴范围 ----------
83
+
84
+ export function readAxes(buf) {
85
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)
86
+ const numTables = view.getUint16(4)
87
+ for (let i = 0; i < numTables; i++) {
88
+ const rec = 12 + i * 16
89
+ const tag = String.fromCharCode(...buf.subarray(rec, rec + 4))
90
+ if (tag !== 'fvar') continue
91
+ const off = view.getUint32(rec + 8)
92
+ const axesOffset = view.getUint16(off + 4)
93
+ const axisCount = view.getUint16(off + 8)
94
+ const axisSize = view.getUint16(off + 10)
95
+ const axes = {}
96
+ for (let a = 0; a < axisCount; a++) {
97
+ const p = off + axesOffset + a * axisSize
98
+ const fixed = (q) => view.getInt32(q) / 65536
99
+ axes[String.fromCharCode(...buf.subarray(p, p + 4))] = { min: fixed(p + 4), default: fixed(p + 8), max: fixed(p + 12) }
100
+ }
101
+ return axes
102
+ }
103
+ return {}
104
+ }
105
+
106
+ function readWeightClass(buf) {
107
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength)
108
+ for (let i = 0; i < view.getUint16(4); i++) {
109
+ const rec = 12 + i * 16
110
+ if (String.fromCharCode(...buf.subarray(rec, rec + 4)) === 'OS/2') return view.getUint16(view.getUint32(rec + 8) + 4)
111
+ }
112
+ return 400
113
+ }
114
+
115
+ // ---------- 下载与校验 ----------
116
+
117
+ async function download(url, dest) {
118
+ const res = await fetch(url)
119
+ if (!res.ok) throw new Error(`下载失败 ${res.status}:${url}`)
120
+ const buf = Buffer.from(await res.arrayBuffer())
121
+ await mkdir(join(dest, '..'), { recursive: true })
122
+ await writeFile(dest + '.part', buf)
123
+ await rename(dest + '.part', dest)
124
+ return buf
125
+ }
126
+
127
+ // 返回 [{ style, weight: [min,max], buffer }]。缺缓存就下载;lock 里有 sha256 就校验,没有就写入
128
+ export async function fetchFont(id, { log = () => {} } = {}) {
129
+ const { pin } = await loadManifest()
130
+ const font = await getFont(id)
131
+ if (font.local) {
132
+ return Promise.all(font.files.map(async (file) => {
133
+ if (!existsSync(file.file)) throw new Error(`本机字体 ${id} 的文件不存在:${file.file}`)
134
+ const buf = await readFile(file.file)
135
+ const axes = readAxes(buf)
136
+ return { style: file.style, weight: axes.wght ? [axes.wght.min, axes.wght.max] : [file.weight ?? 400, file.weight ?? 400], buffer: buf }
137
+ }))
138
+ }
139
+ const lock = await loadLock()
140
+ let lockChanged = false
141
+ const out = []
142
+ for (const file of font.files) {
143
+ const dest = cachePath(pin, file.path)
144
+ let buf
145
+ if (existsSync(dest)) buf = await readFile(dest)
146
+ else {
147
+ log(`下载 ${font.family} ${file.style}…`)
148
+ buf = await download(fileUrl(pin, file.path), dest)
149
+ }
150
+ const sha256 = createHash('sha256').update(buf).digest('hex')
151
+ const key = `${pin.slice(0, 12)}/${file.path}`
152
+ const axes = readAxes(buf)
153
+ const weight = axes.wght ? [axes.wght.min, axes.wght.max] : [file.weight ?? 400, file.weight ?? 400]
154
+ if (lock[key] && lock[key].sha256 !== sha256) {
155
+ throw new Error(`${key} 的 sha256 和 lock.json 不一致,缓存可能损坏:删掉 ${dest} 重新下载`)
156
+ }
157
+ if (!lock[key]) {
158
+ lock[key] = { sha256, bytes: buf.length, weight, axes: Object.keys(axes) }
159
+ lockChanged = true
160
+ }
161
+ out.push({ style: file.style, weight, buffer: buf })
162
+ }
163
+ if (lockChanged) {
164
+ await source.saveLock(Object.fromEntries(Object.entries(lock).sort(([a], [b]) => a.localeCompare(b))))
165
+ }
166
+ return out
167
+ }
168
+
169
+ // ---------- 在线引用 ----------
170
+
171
+ // 字重范围从 lock.json 读,不需要先下载字体。本机字体不进在线链接;全是本机字体时返回 null
172
+ export async function onlineCssUrl(ids) {
173
+ const { pin, fonts } = await loadManifest()
174
+ const lock = await loadLock()
175
+ const shareable = ids.filter((id) => !fonts.find((f) => f.id === id)?.local)
176
+ if (!shareable.length) return null
177
+ const families = shareable.map((id) => {
178
+ const font = fonts.find((f) => f.id === id)
179
+ if (!font) throw new Error(`字体清单里没有 ${id}`)
180
+ const ranges = font.files.map((file) => {
181
+ const rec = lock[`${pin.slice(0, 12)}/${file.path}`]
182
+ if (!rec) throw new Error(`${id} 还没有 lock 记录,先运行 npm run fonts:fetch -- ${id}`)
183
+ const [lo, hi] = rec.weight
184
+ return { ital: file.style === 'italic' ? 1 : 0, w: lo === hi ? `${lo}` : `${lo}..${hi}` }
185
+ })
186
+ const name = font.family.replace(/ /g, '+')
187
+ if (ranges.some((r) => r.ital)) {
188
+ const spec = ranges.sort((a, b) => a.ital - b.ital || a.w.localeCompare(b.w)).map((r) => `${r.ital},${r.w}`).join(';')
189
+ return `family=${name}:ital,wght@${spec}`
190
+ }
191
+ return `family=${name}:wght@${[...new Set(ranges.map((r) => r.w))].join(';')}`
192
+ })
193
+ return `${cssHost()}/css2?${families.join('&')}&display=swap`
194
+ }
195
+
196
+ // data-gz-fonts 记全部字体(内置时用),href 只含可分发的字体
197
+ export async function fontLinkTag(ids) {
198
+ const url = await onlineCssUrl(ids)
199
+ return `<link rel="stylesheet" data-gz-fonts="${ids.join(' ')}" href="${url ?? 'data:text/css,'}">`
200
+ }
201
+
202
+ // ---------- 内置 ----------
203
+
204
+ // 页面里会被渲染出来的文字:去掉 script / style / 注释和标签,解开常见实体
205
+ export function visibleText(html) {
206
+ return html
207
+ .replace(/<!--[\s\S]*?-->/g, ' ')
208
+ .replace(/<(script|style|template)\b[\s\S]*?<\/\1>/gi, ' ')
209
+ .replace(/<[^>]+>/g, ' ')
210
+ .replace(/&#x([0-9a-f]+);/gi, (_, h) => String.fromCodePoint(parseInt(h, 16)))
211
+ .replace(/&#(\d+);/g, (_, d) => String.fromCodePoint(Number(d)))
212
+ .replace(/&nbsp;/g, ' ').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&amp;/g, '&')
213
+ }
214
+
215
+ const uniqueChars = (s) => [...new Set(Array.from(s))].join('')
216
+
217
+ // 返回内联 @font-face 的 CSS 和每个字体文件的子集大小
218
+ export async function embedCss(ids, text, { log } = {}) {
219
+ const chars = uniqueChars(BASE_CHARS + text)
220
+ const rules = []
221
+ const report = []
222
+ for (const id of ids) {
223
+ const font = await getFont(id)
224
+ for (const file of await fetchFont(id, { log })) {
225
+ // 只有内置字体时才需要 subset-font:在线链接、列表等用法不装依赖也能跑
226
+ const { default: subsetFont } = await import('subset-font')
227
+ const woff2 = await subsetFont(file.buffer, chars, { targetFormat: 'woff2' })
228
+ const [lo, hi] = file.weight
229
+ rules.push(
230
+ `@font-face{font-family:'${font.family}';font-style:${file.style};font-weight:${lo === hi ? lo : `${lo} ${hi}`};` +
231
+ `font-display:block;src:url(data:font/woff2;base64,${woff2.toString('base64')}) format('woff2')}`,
232
+ )
233
+ report.push({ id, style: file.style, bytes: woff2.length, sourceBytes: file.buffer.length })
234
+ }
235
+ }
236
+ return { css: rules.join('\n'), report }
237
+ }
238
+
239
+ const LINK_RE = /<link\b[^>]*\bdata-gz-fonts="([^"]+)"[^>]*>/i
240
+
241
+ // 把 data-gz-fonts 这条在线 link 换成内联字体;页面没有这条 link 就原样返回
242
+ export async function embedFonts(html, opts = {}) {
243
+ const m = LINK_RE.exec(html)
244
+ if (!m) return { html, report: [] }
245
+ const ids = m[1].trim().split(/\s+/)
246
+ const { css, report } = await embedCss(ids, visibleText(html) + (opts.extraText || ''), opts)
247
+ const tag = `<style data-gz-fonts="${ids.join(' ')}" data-gz-embedded>\n${css}\n</style>`
248
+ return { html: html.slice(0, m.index) + tag + html.slice(m.index + m[0].length), report }
249
+ }
250
+
251
+ useEmbeddedData({
252
+ "$comment": "字体清单。只收许可证允许内置分发的字体(OFL 等)。source 固定到 google/fonts 的某次提交,保证所有人拿到同一份文件。status:in-use = 现有 skill 已在用;candidate = 新增候选,等定稿。字重范围以字体文件里的 fvar 为准,scripts/fonts.mjs check 会核对。",
253
+ "pin": "6157dfaa640ca5738b4d1a7070fe389c3036d7fc",
254
+ "fonts": [
255
+ { "id": "playfair-display", "family": "Playfair Display", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "in-use",
256
+ "files": [{ "style": "normal", "path": "ofl/playfairdisplay/PlayfairDisplay[wght].ttf" }, { "style": "italic", "path": "ofl/playfairdisplay/PlayfairDisplay-Italic[wght].ttf" }] },
257
+ { "id": "source-serif-4", "family": "Source Serif 4", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "in-use",
258
+ "files": [{ "style": "normal", "path": "ofl/sourceserif4/SourceSerif4[opsz,wght].ttf" }, { "style": "italic", "path": "ofl/sourceserif4/SourceSerif4-Italic[opsz,wght].ttf" }] },
259
+ { "id": "inter", "family": "Inter", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "in-use",
260
+ "files": [{ "style": "normal", "path": "ofl/inter/Inter[opsz,wght].ttf" }] },
261
+ { "id": "dm-sans", "family": "DM Sans", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "in-use",
262
+ "files": [{ "style": "normal", "path": "ofl/dmsans/DMSans[opsz,wght].ttf" }] },
263
+ { "id": "space-grotesk", "family": "Space Grotesk", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "in-use",
264
+ "files": [{ "style": "normal", "path": "ofl/spacegrotesk/SpaceGrotesk[wght].ttf" }] },
265
+ { "id": "jetbrains-mono", "family": "JetBrains Mono", "category": "mono", "script": "latin", "license": "OFL-1.1", "status": "in-use",
266
+ "files": [{ "style": "normal", "path": "ofl/jetbrainsmono/JetBrainsMono[wght].ttf" }] },
267
+ { "id": "ibm-plex-mono", "family": "IBM Plex Mono", "category": "mono", "script": "latin", "license": "OFL-1.1", "status": "in-use",
268
+ "files": [{ "style": "normal", "weight": 400, "path": "ofl/ibmplexmono/IBMPlexMono-Regular.ttf" }, { "style": "normal", "weight": 500, "path": "ofl/ibmplexmono/IBMPlexMono-Medium.ttf" }, { "style": "normal", "weight": 600, "path": "ofl/ibmplexmono/IBMPlexMono-SemiBold.ttf" }] },
269
+ { "id": "noto-serif-sc", "family": "Noto Serif SC", "category": "serif", "script": "cjk", "license": "OFL-1.1", "status": "in-use",
270
+ "files": [{ "style": "normal", "path": "ofl/notoserifsc/NotoSerifSC[wght].ttf" }] },
271
+ { "id": "noto-sans-sc", "family": "Noto Sans SC", "category": "sans", "script": "cjk", "license": "OFL-1.1", "status": "in-use",
272
+ "files": [{ "style": "normal", "path": "ofl/notosanssc/NotoSansSC[wght].ttf" }] },
273
+
274
+ { "id": "inter-tight", "family": "Inter Tight", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "Inter 的紧排版本,瑞士风大标题",
275
+ "files": [{ "style": "normal", "path": "ofl/intertight/InterTight[wght].ttf" }] },
276
+ { "id": "archivo", "family": "Archivo", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "带宽度轴的怪诞体,海报级瑞士风标题",
277
+ "files": [{ "style": "normal", "path": "ofl/archivo/Archivo[wdth,wght].ttf" }] },
278
+ { "id": "schibsted-grotesk", "family": "Schibsted Grotesk", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "北欧报业怪诞体,正文和标题都稳",
279
+ "files": [{ "style": "normal", "path": "ofl/schibstedgrotesk/SchibstedGrotesk[wght].ttf" }] },
280
+ { "id": "familjen-grotesk", "family": "Familjen Grotesk", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "瑞典怪诞体,个性强,适合大字",
281
+ "files": [{ "style": "normal", "path": "ofl/familjengrotesk/FamiljenGrotesk[wght].ttf" }] },
282
+ { "id": "instrument-sans", "family": "Instrument Sans", "category": "sans", "script": "latin", "license": "OFL-1.1", "status": "candidate",
283
+ "files": [{ "style": "normal", "path": "ofl/instrumentsans/InstrumentSans[wdth,wght].ttf" }] },
284
+ { "id": "newsreader", "family": "Newsreader", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "为长文阅读设计、带光学尺寸,网页正文",
285
+ "files": [{ "style": "normal", "path": "ofl/newsreader/Newsreader[opsz,wght].ttf" }, { "style": "italic", "path": "ofl/newsreader/Newsreader-Italic[opsz,wght].ttf" }] },
286
+ { "id": "fraunces", "family": "Fraunces", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "老式风格展示衬线,杂志大标题",
287
+ "files": [{ "style": "normal", "path": "ofl/fraunces/Fraunces[SOFT,WONK,opsz,wght].ttf" }, { "style": "italic", "path": "ofl/fraunces/Fraunces-Italic[SOFT,WONK,opsz,wght].ttf" }] },
288
+ { "id": "instrument-serif", "family": "Instrument Serif", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "candidate", "note": "窄体展示衬线,只有常规体",
289
+ "files": [{ "style": "normal", "weight": 400, "path": "ofl/instrumentserif/InstrumentSerif-Regular.ttf" }, { "style": "italic", "weight": 400, "path": "ofl/instrumentserif/InstrumentSerif-Italic.ttf" }] },
290
+ { "id": "eb-garamond", "family": "EB Garamond", "category": "serif", "script": "latin", "license": "OFL-1.1", "status": "candidate",
291
+ "files": [{ "style": "normal", "path": "ofl/ebgaramond/EBGaramond[wght].ttf" }, { "style": "italic", "path": "ofl/ebgaramond/EBGaramond-Italic[wght].ttf" }] },
292
+ { "id": "zcool-xiaowei", "family": "ZCOOL XiaoWei", "category": "serif", "script": "cjk", "license": "OFL-1.1", "status": "candidate", "note": "站酷小薇,带书卷气的中文展示宋体",
293
+ "files": [{ "style": "normal", "weight": 400, "path": "ofl/zcoolxiaowei/ZCOOLXiaoWei-Regular.ttf" }] }
294
+ ]
295
+ }, {
296
+ "6157dfaa640c/ofl/archivo/Archivo[wdth,wght].ttf": {
297
+ "sha256": "0e094a7d3c7c4c25cf1310c4b30014f1dae9332220b1c2c88f4fa996f0b05053",
298
+ "bytes": 658596,
299
+ "weight": [
300
+ 100,
301
+ 900
302
+ ],
303
+ "axes": [
304
+ "wght",
305
+ "wdth"
306
+ ]
307
+ },
308
+ "6157dfaa640c/ofl/dmsans/DMSans[opsz,wght].ttf": {
309
+ "sha256": "8cd08d97e89c24d0aa92edd2f0f4c8ee6195eee9b7c9f154865a58b02f0c1c0d",
310
+ "bytes": 240164,
311
+ "weight": [
312
+ 100,
313
+ 1000
314
+ ],
315
+ "axes": [
316
+ "opsz",
317
+ "wght"
318
+ ]
319
+ },
320
+ "6157dfaa640c/ofl/ebgaramond/EBGaramond-Italic[wght].ttf": {
321
+ "sha256": "bba2c4499c93c9612b90b9825d32b07da52fce2fe57562a1eb6b833553f93c4e",
322
+ "bytes": 754468,
323
+ "weight": [
324
+ 400,
325
+ 800
326
+ ],
327
+ "axes": [
328
+ "wght"
329
+ ]
330
+ },
331
+ "6157dfaa640c/ofl/ebgaramond/EBGaramond[wght].ttf": {
332
+ "sha256": "ef9512f92f6d579e5dc75af59a5a4b1b8b47d2eda89e00b954d44520e5369027",
333
+ "bytes": 851176,
334
+ "weight": [
335
+ 400,
336
+ 800
337
+ ],
338
+ "axes": [
339
+ "wght"
340
+ ]
341
+ },
342
+ "6157dfaa640c/ofl/familjengrotesk/FamiljenGrotesk[wght].ttf": {
343
+ "sha256": "2d25fc41321a04561fab20a90fc8bc9ed4d1c0743fe8ba76cc51cd3632138b80",
344
+ "bytes": 90048,
345
+ "weight": [
346
+ 400,
347
+ 700
348
+ ],
349
+ "axes": [
350
+ "wght"
351
+ ]
352
+ },
353
+ "6157dfaa640c/ofl/fraunces/Fraunces-Italic[SOFT,WONK,opsz,wght].ttf": {
354
+ "sha256": "b24448c43702fac4ee856781d461a0dfba8d8e594b6e8e190234b75fed2c0e01",
355
+ "bytes": 414904,
356
+ "weight": [
357
+ 100,
358
+ 900
359
+ ],
360
+ "axes": [
361
+ "opsz",
362
+ "wght",
363
+ "SOFT",
364
+ "WONK"
365
+ ]
366
+ },
367
+ "6157dfaa640c/ofl/fraunces/Fraunces[SOFT,WONK,opsz,wght].ttf": {
368
+ "sha256": "177ff6c0f14e5550a3c624247cd1189611d4eb65d000b14944c63d967958abbb",
369
+ "bytes": 360440,
370
+ "weight": [
371
+ 100,
372
+ 900
373
+ ],
374
+ "axes": [
375
+ "opsz",
376
+ "wght",
377
+ "SOFT",
378
+ "WONK"
379
+ ]
380
+ },
381
+ "6157dfaa640c/ofl/ibmplexmono/IBMPlexMono-Medium.ttf": {
382
+ "sha256": "a9b4c49bb299e05b5f6c481e7fb5e78943d2793249a0c8874ab574a2d1ea6755",
383
+ "bytes": 136704,
384
+ "weight": [
385
+ 500,
386
+ 500
387
+ ],
388
+ "axes": []
389
+ },
390
+ "6157dfaa640c/ofl/ibmplexmono/IBMPlexMono-Regular.ttf": {
391
+ "sha256": "6a3412f058c7d8dfd9170c41e85ade48e5156ecb89356110ca57a0a27734af46",
392
+ "bytes": 135580,
393
+ "weight": [
394
+ 400,
395
+ 400
396
+ ],
397
+ "axes": []
398
+ },
399
+ "6157dfaa640c/ofl/ibmplexmono/IBMPlexMono-SemiBold.ttf": {
400
+ "sha256": "d3c38e55c78f5b0f28009fddba4834ec503278936a5986032424c9bd2d23aa46",
401
+ "bytes": 140216,
402
+ "weight": [
403
+ 600,
404
+ 600
405
+ ],
406
+ "axes": []
407
+ },
408
+ "6157dfaa640c/ofl/instrumentsans/InstrumentSans[wdth,wght].ttf": {
409
+ "sha256": "b24f1812584816958afcf22e22d08e44318c5e51651e25d2438efdde389b33b1",
410
+ "bytes": 194336,
411
+ "weight": [
412
+ 400,
413
+ 700
414
+ ],
415
+ "axes": [
416
+ "wdth",
417
+ "wght"
418
+ ]
419
+ },
420
+ "6157dfaa640c/ofl/instrumentserif/InstrumentSerif-Italic.ttf": {
421
+ "sha256": "08939b8bdf534afec24ae0ef5e03f948940cd9a8fe08e7fecbad040e62327385",
422
+ "bytes": 71592,
423
+ "weight": [
424
+ 400,
425
+ 400
426
+ ],
427
+ "axes": []
428
+ },
429
+ "6157dfaa640c/ofl/instrumentserif/InstrumentSerif-Regular.ttf": {
430
+ "sha256": "498efd461f6ddfcb7a111bf9a565709d2085d48201d501ead960d93e84ffbb88",
431
+ "bytes": 70012,
432
+ "weight": [
433
+ 400,
434
+ 400
435
+ ],
436
+ "axes": []
437
+ },
438
+ "6157dfaa640c/ofl/inter/Inter[opsz,wght].ttf": {
439
+ "sha256": "29160a80ff49ddcab2c97711247e08b1fab27a484a329ce8b813d820dc559031",
440
+ "bytes": 876576,
441
+ "weight": [
442
+ 100,
443
+ 900
444
+ ],
445
+ "axes": [
446
+ "opsz",
447
+ "wght"
448
+ ]
449
+ },
450
+ "6157dfaa640c/ofl/intertight/InterTight[wght].ttf": {
451
+ "sha256": "b81b73dcb64df3c230cabade7df6c5773bf863233f24c9ee51087519f1f88b6f",
452
+ "bytes": 581588,
453
+ "weight": [
454
+ 100,
455
+ 900
456
+ ],
457
+ "axes": [
458
+ "wght"
459
+ ]
460
+ },
461
+ "6157dfaa640c/ofl/jetbrainsmono/JetBrainsMono[wght].ttf": {
462
+ "sha256": "48715a42ec242c21e9f02692891e147d022299a52e48d5e413e1a942193ffeda",
463
+ "bytes": 187208,
464
+ "weight": [
465
+ 100,
466
+ 800
467
+ ],
468
+ "axes": [
469
+ "wght"
470
+ ]
471
+ },
472
+ "6157dfaa640c/ofl/newsreader/Newsreader-Italic[opsz,wght].ttf": {
473
+ "sha256": "796668611f80b64d5adf182fde3b6f29ed83b4e7cbec7b96937e84ac01364792",
474
+ "bytes": 495684,
475
+ "weight": [
476
+ 200,
477
+ 800
478
+ ],
479
+ "axes": [
480
+ "wght",
481
+ "opsz"
482
+ ]
483
+ },
484
+ "6157dfaa640c/ofl/newsreader/Newsreader[opsz,wght].ttf": {
485
+ "sha256": "8a08d13f8a6c0d51be379a60af84f945f65369a67e509ee3c3bdcc421254d7c1",
486
+ "bytes": 451664,
487
+ "weight": [
488
+ 200,
489
+ 800
490
+ ],
491
+ "axes": [
492
+ "wght",
493
+ "opsz"
494
+ ]
495
+ },
496
+ "6157dfaa640c/ofl/notosanssc/NotoSansSC[wght].ttf": {
497
+ "sha256": "a3041811a78c361b1de50f953c805e0244951c21c5bd412f7232ef0d899af0da",
498
+ "bytes": 17772300,
499
+ "weight": [
500
+ 100,
501
+ 900
502
+ ],
503
+ "axes": [
504
+ "wght"
505
+ ]
506
+ },
507
+ "6157dfaa640c/ofl/notoserifsc/NotoSerifSC[wght].ttf": {
508
+ "sha256": "050080d9255a86808f2945bffac582b31ef32bc36411ce29563b4961670c66f9",
509
+ "bytes": 25125512,
510
+ "weight": [
511
+ 200,
512
+ 900
513
+ ],
514
+ "axes": [
515
+ "wght"
516
+ ]
517
+ },
518
+ "6157dfaa640c/ofl/playfairdisplay/PlayfairDisplay-Italic[wght].ttf": {
519
+ "sha256": "a5e26dc5e2e77fb2803a0bf02fd4f81ee136ec8dea863ccdb0c59a263b21378b",
520
+ "bytes": 278688,
521
+ "weight": [
522
+ 400,
523
+ 900
524
+ ],
525
+ "axes": [
526
+ "wght"
527
+ ]
528
+ },
529
+ "6157dfaa640c/ofl/playfairdisplay/PlayfairDisplay[wght].ttf": {
530
+ "sha256": "c40f2293766a503bc70cce9e512ef844a4ccb7cbcde792fe2ea31d191917d8d6",
531
+ "bytes": 300724,
532
+ "weight": [
533
+ 400,
534
+ 900
535
+ ],
536
+ "axes": [
537
+ "wght"
538
+ ]
539
+ },
540
+ "6157dfaa640c/ofl/schibstedgrotesk/SchibstedGrotesk[wght].ttf": {
541
+ "sha256": "6ceeadf6be8e1fd7687011c7fa38ed0edd1abe967a0b73d97caec183552e823d",
542
+ "bytes": 176068,
543
+ "weight": [
544
+ 400,
545
+ 900
546
+ ],
547
+ "axes": [
548
+ "wght"
549
+ ]
550
+ },
551
+ "6157dfaa640c/ofl/sourceserif4/SourceSerif4-Italic[opsz,wght].ttf": {
552
+ "sha256": "15fbc7e4679489a501998c3669272637a6646388ef7e4bd77eebb5bf967a1f42",
553
+ "bytes": 855432,
554
+ "weight": [
555
+ 200,
556
+ 900
557
+ ],
558
+ "axes": [
559
+ "wght",
560
+ "opsz"
561
+ ]
562
+ },
563
+ "6157dfaa640c/ofl/sourceserif4/SourceSerif4[opsz,wght].ttf": {
564
+ "sha256": "97b2d4da6e3cb494b5a1e66ae176914d852ccabef49e0c02c0df25f3e39aca0b",
565
+ "bytes": 1209508,
566
+ "weight": [
567
+ 200,
568
+ 900
569
+ ],
570
+ "axes": [
571
+ "wght",
572
+ "opsz"
573
+ ]
574
+ },
575
+ "6157dfaa640c/ofl/spacegrotesk/SpaceGrotesk[wght].ttf": {
576
+ "sha256": "acad6de1fc93436f5c0f1f4137751ef04f1aea3063e7036535970ffcfbd79f72",
577
+ "bytes": 136676,
578
+ "weight": [
579
+ 300,
580
+ 700
581
+ ],
582
+ "axes": [
583
+ "wght"
584
+ ]
585
+ },
586
+ "6157dfaa640c/ofl/zcoolxiaowei/ZCOOLXiaoWei-Regular.ttf": {
587
+ "sha256": "a42b620140f493db42f741351dfbf343c0936d58588ee8004b8b2a218d997ff1",
588
+ "bytes": 6313808,
589
+ "weight": [
590
+ 400,
591
+ 400
592
+ ],
593
+ "axes": []
594
+ }
595
+ })
596
+
597
+ // ---------- 命令行(被其他脚本 import 时不执行) ----------
598
+ import { fileURLToPath as __toPath } from 'node:url'
599
+ import { resolve as __resolve } from 'node:path'
600
+ if (process.argv[1] && __toPath(import.meta.url) === __resolve(process.argv[1])) {
601
+ // 用法:
602
+ // node scripts/fonts.mjs list 列出清单里的字体
603
+ // node scripts/fonts.mjs fetch [id…|--in-use|--all] 下载到本地缓存并写 lock.json
604
+ // node scripts/fonts.mjs link id… 打印在线引用的 <link>
605
+ // node scripts/fonts.mjs embed in.html [-o out.html] 把在线字体换成按需子集的内联字体
606
+ // node scripts/fonts.mjs add <id> "<Family>" 文件… [--category serif|sans|mono|display] [--script latin|cjk]
607
+ // 登记本机字体:只内置、不进在线链接
608
+
609
+ const [cmd, ...args] = process.argv.slice(2)
610
+ const log = (m) => console.error(m)
611
+ const kb = (n) => `${(n / 1024).toFixed(1)}KB`
612
+
613
+ async function main() {
614
+ const { fonts } = await loadManifest()
615
+ if (cmd === 'list') {
616
+ for (const f of fonts) console.log(`${f.id.padEnd(20)} ${f.family.padEnd(20)} ${f.category.padEnd(6)} ${f.script.padEnd(6)} ${f.status}${f.local ? '(只内置,不分发)' : ''}${f.note ? ' ' + f.note : ''}`)
617
+ } else if (cmd === 'fetch') {
618
+ const ids = args.includes('--all') ? fonts.map((f) => f.id)
619
+ : args.includes('--in-use') || args.length === 0 ? fonts.filter((f) => f.status === 'in-use').map((f) => f.id)
620
+ : args
621
+ for (const id of ids) {
622
+ const files = await fetchFont(id, { log })
623
+ console.log(`${id.padEnd(20)} ${files.map((f) => `${f.style} wght ${f.weight.join('–')} ${kb(f.buffer.length)}`).join(' | ')}`)
624
+ }
625
+ } else if (cmd === 'add') {
626
+ const opt = (k, d) => (args.includes(k) ? args[args.indexOf(k) + 1] : d)
627
+ const [id, family, ...rest] = args
628
+ const files = rest.filter((a, i) => !a.startsWith('--') && !rest[i - 1]?.startsWith('--'))
629
+ if (!id || !family || !files.length) throw new Error('用法:fonts.mjs add <id> "<Family>" 文件… [--category …] [--script …]')
630
+ const r = await addUserFont({ id, family, files, category: opt('--category', 'sans'), script: opt('--script', 'latin') })
631
+ console.log(`已登记 ${family}(${r.files.length} 个文件)→ ${r.path}`)
632
+ console.log(`在主题或页面里把它放到字体栈最前面,例如 --font-display:'${family}',<原来的栈>;分享出去时会自动落回原来的字体`)
633
+ } else if (cmd === 'link') {
634
+ console.log(await fontLinkTag(args))
635
+ } else if (cmd === 'embed') {
636
+ const [input] = args
637
+ const o = args.indexOf('-o')
638
+ const output = o >= 0 ? args[o + 1] : input.replace(/\.html?$/, '.embedded.html')
639
+ const { html, report } = await embedFonts(await readFile(input, 'utf8'), { log })
640
+ await writeFile(output, html)
641
+ for (const r of report) console.log(`${r.id.padEnd(20)} ${r.style.padEnd(7)} ${kb(r.sourceBytes).padStart(10)} → ${kb(r.bytes)}`)
642
+ console.log(`合计内置 ${kb(report.reduce((s, r) => s + r.bytes, 0))} → ${output}`)
643
+ } else {
644
+ console.error('用法:fonts.mjs list | fetch [id…|--in-use|--all] | link id… | embed in.html [-o out.html] | add <id> "<Family>" 文件…')
645
+ process.exit(1)
646
+ }
647
+ }
648
+
649
+ main().catch((e) => {
650
+ console.error(e.message)
651
+ process.exit(1)
652
+ })
653
+
654
+ }