@iasiv5/dsh-skills 0.0.1 → 1.0.1
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.
- package/NOTICE.md +40 -0
- package/README.md +22 -5
- package/cordis.patch.yml +7 -0
- package/icon.svg +19 -0
- package/lib/index.js +86 -0
- package/package.json +39 -10
- package/skills/Geek-skills-keqian-method/SKILL.md +241 -0
- package/skills/Geek-skills-keqian-method/evals/routing-evals.json +48 -0
- package/skills/Geek-skills-keqian-method/references/eval-patterns.md +165 -0
- package/skills/Geek-skills-keqian-method/references/sdd-framework.md +106 -0
- package/skills/Geek-skills-xuefeng-method/SKILL.md +282 -0
- package/skills/Geek-skills-xuefeng-method/evals/routing-evals.json +47 -0
- package/skills/Geek-skills-xuefeng-method/references/behavioral-clusters.md +121 -0
- package/skills/Geek-skills-xuefeng-method/references/drift-detection.md +190 -0
- package/skills/Geek-skills-xuefeng-method/references/model-routing.md +35 -0
- package/skills/Geek-skills-xuefeng-method/references/operating-playbook.md +69 -0
- package/skills/answer-me-with-html/SKILL.md +210 -0
- package/skills/answer-me-with-html/licenses/OFL-Bangers.txt +93 -0
- package/skills/answer-me-with-html/references/settings.md +19 -0
- package/skills/answer-me-with-html/references/video.md +36 -0
- package/skills/answer-me-with-html/scripts/am.mjs +13455 -0
- package/skills/architecture-diagram/SKILL.md +177 -0
- package/skills/architecture-diagram/resources/template.html +434 -0
- package/skills/brainstorming/SKILL.md +247 -0
- package/skills/brainstorming/agents/interface.yaml +24 -0
- package/skills/brainstorming/references/questioning-rules.md +37 -0
- package/skills/brainstorming/references/spec-self-review.md +60 -0
- package/skills/brainstorming/references/spec-template.md +75 -0
- package/skills/brainstorming/results.tsv +9 -0
- package/skills/brainstorming/test-prompts.json +200 -0
- package/skills/cleanup/SKILL.md +160 -0
- package/skills/cleanup/references/agent-paths.md +86 -0
- package/skills/cleanup/references/governance.md +57 -0
- package/skills/cleanup/references/sync-matrix.md +91 -0
- package/skills/cleanup/results.tsv +7 -0
- package/skills/cleanup/test-prompts.json +56 -0
- package/skills/code-review/SKILL.md +212 -0
- package/skills/code-review/resources/FEEDBACK-GUIDELINES.md +32 -0
- package/skills/code-review/resources/FIRMWARE-CHECKS.md +42 -0
- package/skills/code-review/resources/REVIEW-CHECKLIST.md +239 -0
- package/skills/code-review/test-prompts.json +32 -0
- package/skills/codebase-design/DEEPENING.md +37 -0
- package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/codebase-design/SKILL.md +114 -0
- package/skills/codebase-design/agents/openai.yaml +3 -0
- package/skills/darwin-skill/LICENSE +21 -0
- package/skills/darwin-skill/README.md +277 -0
- package/skills/darwin-skill/README_EN.md +264 -0
- package/skills/darwin-skill/SKILL.md +519 -0
- package/skills/darwin-skill/assets/aso-hero.png +0 -0
- package/skills/darwin-skill/assets/banner-check.png +0 -0
- package/skills/darwin-skill/assets/banner-en-check.png +0 -0
- package/skills/darwin-skill/assets/banner-en.svg +190 -0
- package/skills/darwin-skill/assets/banner.svg +94 -0
- package/skills/darwin-skill/assets/chart-loop-en.html +131 -0
- package/skills/darwin-skill/assets/chart-loop-en.png +0 -0
- package/skills/darwin-skill/assets/chart-loop.html +179 -0
- package/skills/darwin-skill/assets/chart-loop.png +0 -0
- package/skills/darwin-skill/assets/chart-phases-en.html +221 -0
- package/skills/darwin-skill/assets/chart-phases-en.png +0 -0
- package/skills/darwin-skill/assets/chart-phases.html +221 -0
- package/skills/darwin-skill/assets/chart-phases.png +0 -0
- package/skills/darwin-skill/assets/chart-ratchet-en.html +271 -0
- package/skills/darwin-skill/assets/chart-ratchet-en.png +0 -0
- package/skills/darwin-skill/assets/chart-ratchet.html +273 -0
- package/skills/darwin-skill/assets/chart-ratchet.png +0 -0
- package/skills/darwin-skill/assets/chart-rubric-en.html +363 -0
- package/skills/darwin-skill/assets/chart-rubric-en.png +0 -0
- package/skills/darwin-skill/assets/chart-rubric.html +363 -0
- package/skills/darwin-skill/assets/chart-rubric.png +0 -0
- package/skills/darwin-skill/assets/hero.gif +0 -0
- package/skills/darwin-skill/assets/result-card-example.png +0 -0
- package/skills/darwin-skill/docs/index.html +1083 -0
- package/skills/darwin-skill/references/runtime-neutrality.md +79 -0
- package/skills/darwin-skill/references/skilllens-evidence.md +142 -0
- package/skills/darwin-skill/scripts/screenshot.mjs +101 -0
- package/skills/darwin-skill/showcase.html +1083 -0
- package/skills/darwin-skill/templates/result-card-dark.html +698 -0
- package/skills/darwin-skill/templates/result-card-white.html +444 -0
- package/skills/darwin-skill/templates/result-card.html +616 -0
- package/skills/darwin-skill/templates/result-card.png +0 -0
- package/skills/darwin-skill/test-prompts.json +20 -0
- package/skills/domain-modeling/ADR-FORMAT.md +47 -0
- package/skills/domain-modeling/GLOSSARY-FORMAT.md +60 -0
- package/skills/domain-modeling/SKILL.md +74 -0
- package/skills/domain-modeling/agents/openai.yaml +3 -0
- package/skills/eli5/SKILL.md +35 -0
- package/skills/eli5/agents/openai.yaml +3 -0
- package/skills/grill-with-docs/SKILL.md +7 -0
- package/skills/grill-with-docs/agents/openai.yaml +5 -0
- package/skills/grilling/SKILL.md +30 -0
- package/skills/grilling/agents/openai.yaml +3 -0
- package/skills/guizang-ppt-skill/.github/ISSUE_TEMPLATE/bug_report.yml +55 -0
- package/skills/guizang-ppt-skill/.github/ISSUE_TEMPLATE/config.yml +8 -0
- package/skills/guizang-ppt-skill/.github/ISSUE_TEMPLATE/feature_request.yml +39 -0
- package/skills/guizang-ppt-skill/.github/ISSUE_TEMPLATE/question.yml +17 -0
- package/skills/guizang-ppt-skill/.github/pull_request_template.md +24 -0
- package/skills/guizang-ppt-skill/.github/workflows/presenter-runtime-sync.yml +24 -0
- package/skills/guizang-ppt-skill/CONTRIBUTING.md +55 -0
- package/skills/guizang-ppt-skill/LICENSE +661 -0
- package/skills/guizang-ppt-skill/README.en.md +423 -0
- package/skills/guizang-ppt-skill/README.md +424 -0
- package/skills/guizang-ppt-skill/SKILL.md +636 -0
- package/skills/guizang-ppt-skill/SPONSORS.md +29 -0
- package/skills/guizang-ppt-skill/assets/motion.min.js +8 -0
- package/skills/guizang-ppt-skill/assets/ppt-skill-showcase.png +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-a/dune.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-a/forest-ink.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-a/indigo-porcelain.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-a/kraft-paper.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-a/monocle-classic.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-b/ikb-dot-gradient.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-b/lemon-green-dot-shadow.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-b/lemon-grid.webp +0 -0
- package/skills/guizang-ppt-skill/assets/screenshot-backgrounds/style-b/safety-orange-halftone.webp +0 -0
- package/skills/guizang-ppt-skill/assets/template-swiss.html +3547 -0
- package/skills/guizang-ppt-skill/assets/template.html +2184 -0
- package/skills/guizang-ppt-skill/docs/unification-plan.md +100 -0
- package/skills/guizang-ppt-skill/references/checklist.md +635 -0
- package/skills/guizang-ppt-skill/references/components.md +443 -0
- package/skills/guizang-ppt-skill/references/gz-components.md +289 -0
- package/skills/guizang-ppt-skill/references/image-prompts.md +178 -0
- package/skills/guizang-ppt-skill/references/layouts-swiss.md +897 -0
- package/skills/guizang-ppt-skill/references/layouts.md +669 -0
- package/skills/guizang-ppt-skill/references/presenter-mode.md +184 -0
- package/skills/guizang-ppt-skill/references/screenshot-framing.md +137 -0
- package/skills/guizang-ppt-skill/references/swiss-layout-lock.md +84 -0
- package/skills/guizang-ppt-skill/references/swiss-map-component.md +215 -0
- package/skills/guizang-ppt-skill/references/themes-swiss.md +132 -0
- package/skills/guizang-ppt-skill/references/themes.md +124 -0
- package/skills/guizang-ppt-skill/scripts/check-presenter-runtime-sync.mjs +39 -0
- package/skills/guizang-ppt-skill/scripts/gz-theme.mjs +434 -0
- package/skills/guizang-ppt-skill/scripts/validate-presenter-mode.mjs +135 -0
- package/skills/guizang-ppt-skill/scripts/validate-swiss-deck.mjs +311 -0
- package/skills/guizang-social-card-skill/AGENT.md +58 -0
- package/skills/guizang-social-card-skill/COMMERCIAL_LICENSING.md +190 -0
- package/skills/guizang-social-card-skill/HANDOFF.md +482 -0
- package/skills/guizang-social-card-skill/LICENSE +662 -0
- package/skills/guizang-social-card-skill/PRODUCT.md +291 -0
- package/skills/guizang-social-card-skill/README.en.md +383 -0
- package/skills/guizang-social-card-skill/README.md +382 -0
- package/skills/guizang-social-card-skill/SKILL.md +338 -0
- package/skills/guizang-social-card-skill/agents/openai.yaml +8 -0
- package/skills/guizang-social-card-skill/assets/magazine-bg-webgl.js +160 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-a/dune.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-a/forest-ink.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-a/indigo-porcelain.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-a/kraft-paper.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-a/monocle-classic.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-b/ikb-dot-gradient.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-b/lemon-green-dot-shadow.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-b/lemon-grid.webp +0 -0
- package/skills/guizang-social-card-skill/assets/screenshot-backgrounds/style-b/safety-orange-halftone.webp +0 -0
- package/skills/guizang-social-card-skill/assets/template-editorial-card.html +1666 -0
- package/skills/guizang-social-card-skill/assets/template-swiss-card.html +1447 -0
- package/skills/guizang-social-card-skill/package-lock.json +146 -0
- package/skills/guizang-social-card-skill/package.json +19 -0
- package/skills/guizang-social-card-skill/references/background-systems.md +100 -0
- package/skills/guizang-social-card-skill/references/category-cookbook.md +258 -0
- package/skills/guizang-social-card-skill/references/components.md +291 -0
- package/skills/guizang-social-card-skill/references/content-planning.md +162 -0
- package/skills/guizang-social-card-skill/references/gz-components.md +289 -0
- package/skills/guizang-social-card-skill/references/image-overlay.md +152 -0
- package/skills/guizang-social-card-skill/references/layout-recipes.md +831 -0
- package/skills/guizang-social-card-skill/references/live-photo-production.md +827 -0
- package/skills/guizang-social-card-skill/references/map-component.md +148 -0
- package/skills/guizang-social-card-skill/references/platform-specs.md +142 -0
- package/skills/guizang-social-card-skill/references/portrait-fill.md +85 -0
- package/skills/guizang-social-card-skill/references/production-workflow.md +174 -0
- package/skills/guizang-social-card-skill/references/qa-checklist.md +110 -0
- package/skills/guizang-social-card-skill/references/screenshot-treatment.md +196 -0
- package/skills/guizang-social-card-skill/references/style-system.md +188 -0
- package/skills/guizang-social-card-skill/references/theme-presets.md +156 -0
- package/skills/guizang-social-card-skill/references/title-shortener.md +128 -0
- package/skills/guizang-social-card-skill/scripts/add-livephoto-maker-note.swift +44 -0
- package/skills/guizang-social-card-skill/scripts/add-livephoto-mov-metadata.swift +140 -0
- package/skills/guizang-social-card-skill/scripts/check-skill-docs.mjs +188 -0
- package/skills/guizang-social-card-skill/scripts/gz-fonts.mjs +654 -0
- package/skills/guizang-social-card-skill/scripts/gz-theme.mjs +434 -0
- package/skills/guizang-social-card-skill/scripts/make-video-contact-sheet.py +83 -0
- package/skills/guizang-social-card-skill/scripts/package-live-photo.py +38 -0
- package/skills/guizang-social-card-skill/scripts/render.mjs +92 -0
- package/skills/guizang-social-card-skill/validate-social-deck.mjs +551 -0
- package/skills/handoff/SKILL.md +141 -0
- package/skills/handoff/agents/interface.yaml +24 -0
- package/skills/handoff/references/handoff-output-template.md +119 -0
- package/skills/handoff/results.tsv +4 -0
- package/skills/handoff/test-prompts.json +56 -0
- package/skills/improve-codebase-architecture/HTML-REPORT.md +123 -0
- package/skills/improve-codebase-architecture/SKILL.md +71 -0
- package/skills/improve-codebase-architecture/agents/openai.yaml +5 -0
- package/skills/note-slides/LICENSE +21 -0
- package/skills/note-slides/README.md +67 -0
- package/skills/note-slides/SKILL.md +174 -0
- package/skills/note-slides/references/checklist.md +66 -0
- package/skills/note-slides/references/content-extraction.md +145 -0
- package/skills/note-slides/references/layouts-general.md +612 -0
- package/skills/note-slides/references/layouts-notes.md +346 -0
- package/skills/note-slides/references/layouts.md +216 -0
- package/skills/note-slides/references/ppt-layout-patterns.md +224 -0
- package/skills/note-slides/references/styles.md +462 -0
- package/skills/note-slides/references/wechat-extraction.md +17 -0
- package/skills/note-slides/scripts/check_deck.py +211 -0
- package/skills/note-slides/scripts/check_plan.py +154 -0
- package/skills/note-slides/scripts/pack_core.py +99 -0
- package/skills/note-slides/scripts/prepare_source.py +188 -0
- package/skills/note-slides/template.html +648 -0
- package/skills/npm-name-claim/SKILL.md +153 -0
- package/skills/npm-name-claim/scripts/claim.sh +238 -0
- package/skills/retro/SKILL.md +44 -0
- package/skills/retro/agents/openai.yaml +5 -0
- package/skills/teach/GLOSSARY-FORMAT.md +35 -0
- package/skills/teach/LEARNING-RECORD-FORMAT.md +46 -0
- package/skills/teach/MISSION-FORMAT.md +31 -0
- package/skills/teach/RESOURCES-FORMAT.md +32 -0
- package/skills/teach/SKILL.md +140 -0
- package/skills/teach/agents/openai.yaml +5 -0
- package/skills/wechat-draft/SKILL.md +97 -0
- package/skills/wechat-draft/agents/interface.yaml +24 -0
- package/skills/wechat-draft/assets/cover.jpg +0 -0
- package/skills/wechat-draft/config.example.json +16 -0
- package/skills/wechat-draft/evals/evals.json +29 -0
- package/skills/wechat-draft/evals/semantic_config.json +152 -0
- package/skills/wechat-draft/evals/trigger_cases.json +65 -0
- package/skills/wechat-draft/references/error-codes.md +37 -0
- package/skills/wechat-draft/references/themes.md +58 -0
- package/skills/wechat-draft/references/usage.md +88 -0
- package/skills/wechat-draft/references/wechat-mp-api.md +107 -0
- package/skills/wechat-draft/requirements.txt +3 -0
- package/skills/wechat-draft/scripts/format.py +1731 -0
- package/skills/wechat-draft/scripts/publish.py +399 -0
- package/skills/wechat-draft/templates/gallery.html +535 -0
- package/skills/wechat-draft/templates/preview.html +269 -0
- package/skills/wechat-draft/themes/bauhaus.json +352 -0
- package/skills/wechat-draft/themes/bold-blue.json +338 -0
- package/skills/wechat-draft/themes/bold-green.json +338 -0
- package/skills/wechat-draft/themes/bold-navy.json +338 -0
- package/skills/wechat-draft/themes/bytedance.json +346 -0
- package/skills/wechat-draft/themes/chinese.json +340 -0
- package/skills/wechat-draft/themes/coffee-house.json +335 -0
- package/skills/wechat-draft/themes/elegant-blue.json +336 -0
- package/skills/wechat-draft/themes/elegant-green.json +336 -0
- package/skills/wechat-draft/themes/elegant-navy.json +336 -0
- package/skills/wechat-draft/themes/focus-blue.json +336 -0
- package/skills/wechat-draft/themes/focus-gold.json +336 -0
- package/skills/wechat-draft/themes/focus-red.json +336 -0
- package/skills/wechat-draft/themes/github.json +336 -0
- package/skills/wechat-draft/themes/ink.json +329 -0
- package/skills/wechat-draft/themes/lavender-dream.json +334 -0
- package/skills/wechat-draft/themes/magazine.json +333 -0
- package/skills/wechat-draft/themes/midnight.json +341 -0
- package/skills/wechat-draft/themes/minimal-blue.json +320 -0
- package/skills/wechat-draft/themes/minimal-gold.json +320 -0
- package/skills/wechat-draft/themes/minimal-gray.json +320 -0
- package/skills/wechat-draft/themes/minimal-navy.json +320 -0
- package/skills/wechat-draft/themes/minimal-red.json +320 -0
- package/skills/wechat-draft/themes/mint-fresh.json +338 -0
- package/skills/wechat-draft/themes/newspaper.json +341 -0
- package/skills/wechat-draft/themes/sports.json +341 -0
- package/skills/wechat-draft/themes/sspai.json +337 -0
- package/skills/wechat-draft/themes/sunset-amber.json +336 -0
- package/skills/wechat-draft/themes/terracotta.json +335 -0
- package/skills/wechat-draft/themes/wechat-native.json +336 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/skills/writing-for-agents/SKILL.md +81 -0
- package/skills/writing-for-agents/agents/openai.yaml +3 -0
- package/skills/writing-plans/SKILL.md +221 -0
- package/skills/writing-plans/agents/interface.yaml +24 -0
- package/skills/writing-plans/references/plan-self-review.md +64 -0
- package/skills/writing-plans/references/plan-template.md +81 -0
- package/skills/writing-plans/references/task-skeleton.md +78 -0
- package/skills/writing-plans/results.tsv +10 -0
- package/skills/writing-plans/test-prompts.json +83 -0
- package/skills-manifest.json +220 -1
- package/index.js +0 -2
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// 歸藏设计系统 · 品牌主题生成(guizang-design v0.1.0 生成,不要手改)
|
|
3
|
+
//
|
|
4
|
+
// node scripts/gz-theme.mjs brand "#4D6BFE" [--family magazine|swiss] [--id brand]
|
|
5
|
+
//
|
|
6
|
+
// 用户给品牌色或 logo 主色时用:颜色被收进现有精调色板的明度 / 彩度区间,并通过 WCAG + APCA 对比度检查。
|
|
7
|
+
// 输出一段 [data-theme="<id>"]{…} CSS,贴进 deck 的 <style> 末尾,再把 <html> 的 data-theme 改成 <id>。
|
|
8
|
+
// 不达标时不输出主题,只给出原因。
|
|
9
|
+
// 色彩基础:sRGB ↔ OKLab / OKLCH、sRGB 色域映射、WCAG 2 对比度、APCA 对比度。
|
|
10
|
+
// 设计系统里所有「科学配色」都建立在这几个函数上:
|
|
11
|
+
// 用 OKLCH 描述颜色(明度 L、彩度 C、色相 H 互相独立,调一个不会把另外两个带偏),
|
|
12
|
+
// 用 WCAG + APCA 两套对比度卡住可读性。纯函数、无依赖。
|
|
13
|
+
|
|
14
|
+
const clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x))
|
|
15
|
+
|
|
16
|
+
// ---------- hex ----------
|
|
17
|
+
|
|
18
|
+
function parseHex(hex) {
|
|
19
|
+
const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(String(hex).trim())
|
|
20
|
+
if (!m) throw new TypeError(`不是合法的 hex 颜色:${hex}`)
|
|
21
|
+
let h = m[1]
|
|
22
|
+
if (h.length === 3) h = h.replace(/./g, (c) => c + c)
|
|
23
|
+
return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16) / 255)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function toHex(rgb) {
|
|
27
|
+
return '#' + rgb.map((c) => Math.round(clamp(c, 0, 1) * 255).toString(16).padStart(2, '0')).join('')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ---------- sRGB 传递函数 ----------
|
|
31
|
+
|
|
32
|
+
const toLinear = (c) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)
|
|
33
|
+
const fromLinear = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055)
|
|
34
|
+
|
|
35
|
+
// ---------- OKLab(Björn Ottosson, 2020) ----------
|
|
36
|
+
|
|
37
|
+
function rgbToOklab([r, g, b]) {
|
|
38
|
+
const R = toLinear(r), G = toLinear(g), B = toLinear(b)
|
|
39
|
+
const l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B)
|
|
40
|
+
const m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B)
|
|
41
|
+
const s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B)
|
|
42
|
+
return [
|
|
43
|
+
0.2104542553 * l + 0.7936177850 * m - 0.0040720468 * s,
|
|
44
|
+
1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s,
|
|
45
|
+
0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s,
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 返回未裁剪的 sRGB,可能超出 [0,1],由调用方判断是否在色域内
|
|
50
|
+
function oklabToRgb([L, a, b]) {
|
|
51
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3
|
|
52
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3
|
|
53
|
+
const s = (L - 0.0894841775 * a - 1.2914855480 * b) ** 3
|
|
54
|
+
return [
|
|
55
|
+
fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
56
|
+
fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
57
|
+
fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s),
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ---------- OKLCH ----------
|
|
62
|
+
|
|
63
|
+
function oklabToOklch([L, a, b]) {
|
|
64
|
+
const C = Math.hypot(a, b)
|
|
65
|
+
let H = (Math.atan2(b, a) * 180) / Math.PI
|
|
66
|
+
if (H < 0) H += 360
|
|
67
|
+
return { l: L, c: C, h: C < 1e-4 ? 0 : H }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function oklchToOklab({ l, c, h }) {
|
|
71
|
+
const r = (h * Math.PI) / 180
|
|
72
|
+
return [l, c * Math.cos(r), c * Math.sin(r)]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hexToOklch = (hex) => oklabToOklch(rgbToOklab(parseHex(hex)))
|
|
76
|
+
|
|
77
|
+
const inGamut = (rgb, eps = 1e-6) => rgb.every((c) => c >= -eps && c <= 1 + eps)
|
|
78
|
+
|
|
79
|
+
// 保持明度和色相,二分降低彩度直到落进 sRGB。和 CSS Color 4 的思路一致,足够用于生成色板
|
|
80
|
+
function oklchToHex({ l, c, h }) {
|
|
81
|
+
l = clamp(l, 0, 1)
|
|
82
|
+
let rgb = oklabToRgb(oklchToOklab({ l, c, h }))
|
|
83
|
+
if (!inGamut(rgb)) {
|
|
84
|
+
let lo = 0, hi = c
|
|
85
|
+
while (hi - lo > 1e-5) {
|
|
86
|
+
const mid = (lo + hi) / 2
|
|
87
|
+
if (inGamut(oklabToRgb(oklchToOklab({ l, c: mid, h })))) lo = mid
|
|
88
|
+
else hi = mid
|
|
89
|
+
}
|
|
90
|
+
rgb = oklabToRgb(oklchToOklab({ l, c: lo, h }))
|
|
91
|
+
}
|
|
92
|
+
return toHex(rgb)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function maxChroma(l, h) {
|
|
96
|
+
let lo = 0, hi = 0.5
|
|
97
|
+
while (hi - lo > 1e-5) {
|
|
98
|
+
const mid = (lo + hi) / 2
|
|
99
|
+
if (inGamut(oklabToRgb(oklchToOklab({ l, c: mid, h })))) lo = mid
|
|
100
|
+
else hi = mid
|
|
101
|
+
}
|
|
102
|
+
return lo
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ---------- 对比度 ----------
|
|
106
|
+
|
|
107
|
+
function luminance(hex) {
|
|
108
|
+
const [r, g, b] = parseHex(hex).map(toLinear)
|
|
109
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// WCAG 2.x:1–21。正文 ≥ 4.5,大字 ≥ 3
|
|
113
|
+
function wcag(fg, bg) {
|
|
114
|
+
const a = luminance(fg), b = luminance(bg)
|
|
115
|
+
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// APCA (SAPC 0.0.98G-4g):返回 Lc,深字浅底为正、浅字深底为负。
|
|
119
|
+
// 参考阈值:正文 |Lc| ≥ 75,大号正文 ≥ 60,标题 ≥ 45,不承担阅读的装饰 ≥ 30。
|
|
120
|
+
// WCAG 2 对深色背景和中等亮度颜色偏差很大,APCA 更接近人眼,两者都看。
|
|
121
|
+
function apca(fg, bg) {
|
|
122
|
+
const y = (hex) => {
|
|
123
|
+
const [r, g, b] = parseHex(hex).map((c) => c ** 2.4)
|
|
124
|
+
let Y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b
|
|
125
|
+
if (Y < 0.022) Y += (0.022 - Y) ** 1.414
|
|
126
|
+
return Y
|
|
127
|
+
}
|
|
128
|
+
const Yt = y(fg), Yb = y(bg)
|
|
129
|
+
if (Math.abs(Yb - Yt) < 0.0005) return 0
|
|
130
|
+
if (Yb > Yt) {
|
|
131
|
+
const s = (Yb ** 0.56 - Yt ** 0.57) * 1.14
|
|
132
|
+
return s < 0.1 ? 0 : (s - 0.027) * 100
|
|
133
|
+
}
|
|
134
|
+
const s = (Yb ** 0.65 - Yt ** 0.62) * 1.14
|
|
135
|
+
return s > -0.1 ? 0 : (s + 0.027) * 100
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 两个颜色在 OKLab 里的距离(ΔEok,×100 便于阅读,≈2 以下肉眼难分)
|
|
139
|
+
function deltaE(a, b) {
|
|
140
|
+
const [L1, a1, b1] = rgbToOklab(parseHex(a))
|
|
141
|
+
const [L2, a2, b2] = rgbToOklab(parseHex(b))
|
|
142
|
+
return Math.hypot(L1 - L2, a1 - a2, b1 - b2) * 100
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const formatOklch = ({ l, c, h }) => `oklch(${(l * 100).toFixed(1)}% ${c.toFixed(4)} ${h.toFixed(1)})`
|
|
146
|
+
|
|
147
|
+
// 从色板派生完整主题:文字角色、线条、accent-on、accent-ink、-rgb 三元组。
|
|
148
|
+
// 派生规则对所有主题一样,自定义品牌主题也走这里,所以「每套主题都可读」是由规则保证的,不靠逐个手调。
|
|
149
|
+
//
|
|
150
|
+
// 文字角色沿用现有模板的层级比例(PPT / 卡片里正文 .82、次要 .72 这类透明度),
|
|
151
|
+
// 但输出实色而不是透明度:导出 PDF 和截图时透明叠加会出问题,实色也能直接算对比度。
|
|
152
|
+
// 比例混出来的颜色对比度不够时,沿 OKLab 继续往墨色方向推,直到达到该角色的下限。
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
// APCA |Lc| 下限。参考 APCA 的使用建议:正文 75、大号正文 / 次要文字 60、标题 45、非阅读元素 15–30
|
|
156
|
+
const ROLE_FLOORS = {
|
|
157
|
+
textBody: { apca: 75, wcag: 7 },
|
|
158
|
+
textSecondary: { apca: 60, wcag: 4.5 },
|
|
159
|
+
textHelper: { apca: 60, wcag: 4.5 },
|
|
160
|
+
accentInk: { apca: 60, wcag: 4.5 },
|
|
161
|
+
// 色块上的正文级文字(≥ 16px):WCAG 4.5 + APCA 45。饱和中等明度的底色(安全橙)上 APCA 会低估深色字,
|
|
162
|
+
// WCAG 会高估白字,两个都要过
|
|
163
|
+
onText: { apca: 45, wcag: 4.5 },
|
|
164
|
+
// 大字(标题、KPI 大数字)只看 APCA 标题线 45:WCAG 对明亮饱和色(安全橙)严重低估可读性
|
|
165
|
+
accentDisplay: { apca: 45, wcag: 0 },
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 大字用的强调色:原色够大字标准就用原色(保持设计),不够就退到 accent-ink(柠檬黄这类浅色强调色)
|
|
169
|
+
const accentDisplay = (accent, accentInk, paper) => (passes(accent, paper, ROLE_FLOORS.accentDisplay) ? accent : accentInk)
|
|
170
|
+
|
|
171
|
+
// 在 OKLab 里线性混合:t=0 得到 a,t=1 得到 b
|
|
172
|
+
function mix(a, b, t) {
|
|
173
|
+
const A = rgbToOklab(parseHex(a))
|
|
174
|
+
const B = rgbToOklab(parseHex(b))
|
|
175
|
+
return toHex(oklabToRgb(A.map((v, i) => v + (B[i] - v) * t)))
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const rgbTriplet = (hex) => parseHex(hex).map((c) => Math.round(c * 255)).join(',')
|
|
179
|
+
|
|
180
|
+
const passes = (fg, bg, floor) => Math.abs(apca(fg, bg)) >= floor.apca && wcag(fg, bg) >= floor.wcag
|
|
181
|
+
|
|
182
|
+
// 从 paper 往 ink 混,比例 t 起步;不达标就加大 t
|
|
183
|
+
function inkRole(ink, paper, t, floor) {
|
|
184
|
+
for (let k = t; k <= 1.0001; k += 0.01) {
|
|
185
|
+
const c = mix(paper, ink, Math.min(k, 1))
|
|
186
|
+
if (!floor || passes(c, paper, floor)) return { hex: c, ratio: +Math.min(k, 1).toFixed(2), adjusted: k > t + 1e-9 }
|
|
187
|
+
}
|
|
188
|
+
return { hex: ink, ratio: 1, adjusted: true }
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 保持色相,调整明度直到能当文字用:浅底往暗调,深底往亮调
|
|
192
|
+
function textSafeAccent(accent, paper, floor = ROLE_FLOORS.accentInk) {
|
|
193
|
+
if (passes(accent, paper, floor)) return { hex: accent, adjusted: false }
|
|
194
|
+
const { l, c, h } = hexToOklch(accent)
|
|
195
|
+
const dark = hexToOklch(paper).l < 0.5
|
|
196
|
+
for (let step = 1; step <= 200; step++) {
|
|
197
|
+
const L = dark ? l + step * 0.005 : l - step * 0.005
|
|
198
|
+
if (L <= 0 || L >= 1) break
|
|
199
|
+
const hex = oklchToHex({ l: L, c, h })
|
|
200
|
+
if (passes(hex, paper, floor)) return { hex, adjusted: true }
|
|
201
|
+
}
|
|
202
|
+
return { hex: dark ? '#ffffff' : '#000000', adjusted: true }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 在 ink 和 paper 里选对比更强的那个当 accent 上的文字色
|
|
206
|
+
function onColor(bg, candidates) {
|
|
207
|
+
return candidates.reduce((best, c) => (Math.abs(apca(c, bg)) > Math.abs(apca(best, bg)) ? c : best))
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 色块上的正文级文字(高亮块正文、标签):设计指定的 accent-on 达到 ROLE_FLOORS.onText 就用它;
|
|
211
|
+
// 不达标(安全橙、中等明度的品牌绿上的白字)换成达标的候选;都不达标取 WCAG 最高的
|
|
212
|
+
function onText(bg, preferred, candidates) {
|
|
213
|
+
const floor = ROLE_FLOORS.onText
|
|
214
|
+
if (passes(preferred, bg, floor)) return preferred
|
|
215
|
+
return candidates.find((c) => passes(c, bg, floor)) || candidates.reduce((best, c) => (wcag(c, bg) > wcag(best, bg) ? c : best))
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 强调色小字既出现在纸色上,也出现在 paper-2 / 灰底卡片上:按两者里对比更低的那个底色来调
|
|
219
|
+
const harderBg = (fg, bgs) => bgs.reduce((a, b) => (Math.abs(apca(fg, b)) < Math.abs(apca(fg, a)) ? b : a))
|
|
220
|
+
|
|
221
|
+
function deriveMagazine(t) {
|
|
222
|
+
const roles = {
|
|
223
|
+
textBody: inkRole(t.ink, t.paper, 0.82, ROLE_FLOORS.textBody),
|
|
224
|
+
textSecondary: inkRole(t.ink, t.paper, 0.72, ROLE_FLOORS.textSecondary),
|
|
225
|
+
// 手调的 muted 达标就用它,否则从 paper→ink 派生一个达标的
|
|
226
|
+
textHelper: passes(t.muted, t.paper, ROLE_FLOORS.textHelper)
|
|
227
|
+
? { hex: t.muted, adjusted: false }
|
|
228
|
+
: inkRole(t.ink, t.paper, 0.55, ROLE_FLOORS.textHelper),
|
|
229
|
+
lineStrong: inkRole(t.ink, t.paper, 0.45),
|
|
230
|
+
line: inkRole(t.ink, t.paper, 0.22),
|
|
231
|
+
lineSubtle: inkRole(t.ink, t.paper, 0.12),
|
|
232
|
+
accentInk: textSafeAccent(t.accent, harderBg(t.accent, [t.paper, t.paper2])),
|
|
233
|
+
}
|
|
234
|
+
return {
|
|
235
|
+
vars: {
|
|
236
|
+
'--paper': t.paper, '--paper-2': t.paper2, '--ink': t.ink, '--muted': t.muted,
|
|
237
|
+
'--accent': t.accent, '--accent-soft': t.accentSoft,
|
|
238
|
+
'--accent-on': onColor(t.accent, [t.ink, t.paper]),
|
|
239
|
+
'--accent-ink': roles.accentInk.hex,
|
|
240
|
+
'--accent-display': accentDisplay(t.accent, roles.accentInk.hex, t.paper),
|
|
241
|
+
// 反色块(以墨色为底)上的强调色文字:同色相提亮到可读,墨水经典的 #111 会变成浅灰
|
|
242
|
+
'--accent-ink-inverse': textSafeAccent(t.accent, t.ink).hex,
|
|
243
|
+
'--text-primary': t.ink,
|
|
244
|
+
'--text-body': roles.textBody.hex,
|
|
245
|
+
'--text-secondary': roles.textSecondary.hex,
|
|
246
|
+
'--text-helper': roles.textHelper.hex,
|
|
247
|
+
'--line-strong': roles.lineStrong.hex,
|
|
248
|
+
'--line': roles.line.hex,
|
|
249
|
+
'--line-subtle': roles.lineSubtle.hex,
|
|
250
|
+
'--ink-rgb': rgbTriplet(t.ink), '--paper-rgb': rgbTriplet(t.paper), '--accent-rgb': rgbTriplet(t.accent),
|
|
251
|
+
'--accent-on-rgb': rgbTriplet(onColor(t.accent, [t.ink, t.paper])),
|
|
252
|
+
'--accent-on-text': onText(t.accent, onColor(t.accent, [t.ink, t.paper]), [t.ink, t.paper, '#ffffff']),
|
|
253
|
+
'--accent-on-text-rgb': rgbTriplet(onText(t.accent, onColor(t.accent, [t.ink, t.paper]), [t.ink, t.paper, '#ffffff'])),
|
|
254
|
+
},
|
|
255
|
+
roles,
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function deriveSwiss(n, t) {
|
|
260
|
+
const textBody = inkRole(n.ink, n.paper, 0.86, ROLE_FLOORS.textBody)
|
|
261
|
+
return {
|
|
262
|
+
vars: {
|
|
263
|
+
'--paper': n.paper, '--paper-2': n.grey1, '--ink': n.ink, '--muted': n.grey3,
|
|
264
|
+
'--grey-1': n.grey1, '--grey-2': n.grey2, '--grey-3': n.grey3,
|
|
265
|
+
'--accent': t.accent, '--accent-on': t.accentOn, '--accent-ink': t.accentInk,
|
|
266
|
+
'--accent-bright': t.accentBright, '--accent-deep': t.accentDeep,
|
|
267
|
+
'--accent-display': accentDisplay(t.accent, t.accentInk, n.paper),
|
|
268
|
+
// 墨色块上的强调色文字:优先用手调的 accent-bright(IKB 的亮蓝),不够再按规则提亮
|
|
269
|
+
'--accent-ink-inverse': textSafeAccent(t.accentBright, n.ink).hex,
|
|
270
|
+
'--accent-soft': mix(n.paper, t.accent, 0.14),
|
|
271
|
+
'--text-primary': n.ink,
|
|
272
|
+
'--text-body': textBody.hex,
|
|
273
|
+
'--text-secondary': n.textSecondary,
|
|
274
|
+
'--text-helper': n.grey3,
|
|
275
|
+
'--text-placeholder': n.textPlaceholder,
|
|
276
|
+
'--text-on-color': t.accentOn,
|
|
277
|
+
'--line-strong': n.textPlaceholder,
|
|
278
|
+
'--line': n.grey2,
|
|
279
|
+
'--line-subtle': n.borderSubtle,
|
|
280
|
+
'--ink-rgb': rgbTriplet(n.ink), '--paper-rgb': rgbTriplet(n.paper), '--accent-rgb': rgbTriplet(t.accent),
|
|
281
|
+
'--accent-on-rgb': rgbTriplet(t.accentOn),
|
|
282
|
+
'--accent-on-text': onText(t.accent, t.accentOn, [n.ink, '#ffffff']),
|
|
283
|
+
'--accent-on-text-rgb': rgbTriplet(onText(t.accent, t.accentOn, [n.ink, '#ffffff'])),
|
|
284
|
+
},
|
|
285
|
+
roles: { textBody },
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// 对一套已派生的主题做可读性体检,返回不达标项(不抛错,由调用方决定是失败还是警告)
|
|
290
|
+
function auditTheme(vars) {
|
|
291
|
+
const bg = vars['--paper']
|
|
292
|
+
const checks = [
|
|
293
|
+
['--text-body', ROLE_FLOORS.textBody],
|
|
294
|
+
['--text-secondary', ROLE_FLOORS.textSecondary],
|
|
295
|
+
['--text-helper', ROLE_FLOORS.textHelper],
|
|
296
|
+
['--accent-ink', ROLE_FLOORS.accentInk],
|
|
297
|
+
]
|
|
298
|
+
const out = []
|
|
299
|
+
for (const [k, floor] of checks) {
|
|
300
|
+
const fg = vars[k]
|
|
301
|
+
const r = { token: k, fg, bg, wcag: +wcag(fg, bg).toFixed(2), apca: +apca(fg, bg).toFixed(1) }
|
|
302
|
+
if (!passes(fg, bg, floor)) out.push({ ...r, floor })
|
|
303
|
+
}
|
|
304
|
+
// 强调色小字也会放在 paper-2 / 灰底卡片上
|
|
305
|
+
const bg2 = vars['--paper-2']
|
|
306
|
+
if (bg2 && !passes(vars['--accent-ink'], bg2, ROLE_FLOORS.accentInk)) {
|
|
307
|
+
out.push({ token: '--accent-ink', fg: vars['--accent-ink'], bg: bg2, wcag: +wcag(vars['--accent-ink'], bg2).toFixed(2), apca: +apca(vars['--accent-ink'], bg2).toFixed(1), floor: ROLE_FLOORS.accentInk })
|
|
308
|
+
}
|
|
309
|
+
// 色块上的正文级文字
|
|
310
|
+
const onT = vars['--accent-on-text']
|
|
311
|
+
if (onT && !passes(onT, vars['--accent'], ROLE_FLOORS.onText)) {
|
|
312
|
+
out.push({ token: '--accent-on-text', fg: onT, bg: vars['--accent'], apca: +apca(onT, vars['--accent']).toFixed(1), wcag: +wcag(onT, vars['--accent']).toFixed(2), note: '色块上只放大号粗体' })
|
|
313
|
+
}
|
|
314
|
+
// accent 上的文字:大号粗体允许到 Lc 45(APCA 标题线),小字要 60
|
|
315
|
+
const onLc = Math.abs(apca(vars['--accent-on'], vars['--accent']))
|
|
316
|
+
if (onLc < 60) out.push({ token: '--accent-on', fg: vars['--accent-on'], bg: vars['--accent'], apca: +onLc.toFixed(1), wcag: +wcag(vars['--accent-on'], vars['--accent']).toFixed(2), note: onLc >= 45 ? '只能用于大号粗体' : '不可用于文字' })
|
|
317
|
+
return out
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 受约束的品牌主题:用户给任意品牌色,生成一套符合家族审美的主题。
|
|
321
|
+
//
|
|
322
|
+
// 不直接用原色。每个颜色槽位都有一个明度 / 彩度区间,区间来自现有精调色板的 OKLCH 实测
|
|
323
|
+
// (见 docs/decisions.md D9),品牌色只贡献色相和「有多鲜艳」的倾向,最终落在区间里。
|
|
324
|
+
// 生成后走和内置主题同一套派生与体检(lib/theme.mjs),不达标就不返回主题。
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
const r3 = (x) => Math.round(x * 1000) / 1000
|
|
328
|
+
|
|
329
|
+
// 由 tokens/palettes.json 的浅色杂志主题实测(node 脚本见 docs/decisions.md D9)
|
|
330
|
+
const MAGAZINE_BANDS = {
|
|
331
|
+
paper: { l: [0.909, 0.963], c: [0.003, 0.036] },
|
|
332
|
+
paper2: { l: [0.864, 0.929], c: [0.007, 0.039] },
|
|
333
|
+
ink: { l: [0.145, 0.279], c: [0.002, 0.063] },
|
|
334
|
+
muted: { l: [0.499, 0.527], c: [0.015, 0.044] },
|
|
335
|
+
accent: { l: [0.4, 0.58], c: [0.04, 0.12] },
|
|
336
|
+
accentSoft: { l: [0.792, 0.905], c: [0.018, 0.063] },
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 瑞士风四个强调色实测彩度 0.181–0.207,下限放宽到 0.15;明度不限,但要留出能派生 bright / deep 的空间
|
|
340
|
+
const SWISS_BANDS = { accent: { l: [0.35, 0.9], c: [0.15, 0.32] } }
|
|
341
|
+
|
|
342
|
+
function place(slot, l, c, h, band, notes) {
|
|
343
|
+
const L = clamp(l, ...band.l)
|
|
344
|
+
const C = Math.min(clamp(c, ...band.c), maxChroma(L, h))
|
|
345
|
+
if (Math.abs(L - l) > 0.02) notes.push(`${slot} 明度 ${r3(l)} → ${r3(L)}`)
|
|
346
|
+
if (Math.abs(C - c) > 0.01) notes.push(`${slot} 彩度 ${r3(c)} → ${r3(C)}`)
|
|
347
|
+
return oklchToHex({ l: L, c: C, h })
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// 纸张是「有一点颜色的米白」:现有 5 套里 4 套是暖米色(色相 80–90°),靛蓝瓷是几乎无彩的冷白。
|
|
351
|
+
// 所以暖色系品牌把纸张色相往 85° 拉,其余色相只留极低彩度,避免红色品牌生成粉色纸
|
|
352
|
+
function paperTone(b, neutral) {
|
|
353
|
+
if (neutral) return { h: 85, c: 0.007 }
|
|
354
|
+
const warm = b.h >= 20 && b.h <= 115
|
|
355
|
+
return warm ? { h: 85 + (b.h - 85) * 0.3, c: clamp(b.c * 0.05, 0.006, 0.014) } : { h: b.h, c: clamp(b.c * 0.02, 0.003, 0.006) }
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function magazineFromBrand(brandHex, { name = '品牌主题' } = {}) {
|
|
359
|
+
const b = hexToOklch(brandHex)
|
|
360
|
+
const notes = []
|
|
361
|
+
const B = MAGAZINE_BANDS
|
|
362
|
+
// 品牌色很灰(c<0.02)时按墨水经典处理:色相没有意义,强调色就用墨色
|
|
363
|
+
const neutral = b.c < 0.02
|
|
364
|
+
const h = neutral ? 85 : b.h
|
|
365
|
+
const paper = paperTone(b, neutral)
|
|
366
|
+
const ink = place('ink', 0.22, neutral ? 0.004 : clamp(b.c * 0.35, 0.01, 0.06), h, B.ink, [])
|
|
367
|
+
if (neutral) notes.push('品牌色接近中性灰,强调色改用墨色(同墨水经典)')
|
|
368
|
+
const accent = neutral ? ink : place('accent', b.l, b.c, b.h, B.accent, notes)
|
|
369
|
+
const t = {
|
|
370
|
+
name, scheme: 'light',
|
|
371
|
+
paper: place('paper', 0.95, paper.c, paper.h, B.paper, []),
|
|
372
|
+
paper2: place('paper2', 0.91, paper.c + 0.006, paper.h, B.paper2, []),
|
|
373
|
+
ink,
|
|
374
|
+
muted: place('muted', 0.51, neutral ? 0.015 : clamp(b.c * 0.3, 0.015, 0.044), h, B.muted, []),
|
|
375
|
+
accent,
|
|
376
|
+
}
|
|
377
|
+
t.accentSoft = neutral ? place('accentSoft', 0.86, 0.018, paper.h, B.accentSoft, []) : place('accentSoft', 0.85, clamp(hexToOklch(accent).c * 0.35, 0.018, 0.063), b.h, B.accentSoft, [])
|
|
378
|
+
return finish('magazine', t, deriveMagazine(t), notes)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function swissFromBrand(brandHex, neutrals, { name = '品牌主题' } = {}) {
|
|
382
|
+
const b = hexToOklch(brandHex)
|
|
383
|
+
const notes = []
|
|
384
|
+
if (b.c < 0.04) {
|
|
385
|
+
return { ok: false, reason: `品牌色 ${brandHex} 几乎没有彩度,瑞士风需要一个高饱和强调色。可以改用杂志风,或从 logo 里另选一个颜色。` }
|
|
386
|
+
}
|
|
387
|
+
const accent = place('accent', b.l, b.c, b.h, SWISS_BANDS.accent, notes)
|
|
388
|
+
const a = hexToOklch(accent)
|
|
389
|
+
const t = {
|
|
390
|
+
name, accent,
|
|
391
|
+
accentBright: oklchToHex({ l: Math.min(a.l + 0.18, 0.92), c: a.c, h: a.h }),
|
|
392
|
+
accentDeep: oklchToHex({ l: Math.max(a.l - 0.15, 0.2), c: a.c, h: a.h }),
|
|
393
|
+
}
|
|
394
|
+
// accent-on / accent-ink 交给派生规则算,和内置主题一致
|
|
395
|
+
const probe = deriveSwiss(neutrals, { ...t, accentOn: neutrals.ink, accentInk: accent })
|
|
396
|
+
t.accentOn = pickOn(accent, neutrals)
|
|
397
|
+
// 强调色小字也放在灰底卡片(grey-1)上,按更暗的灰底来调
|
|
398
|
+
t.accentInk = textSafe(accent, neutrals.grey1)
|
|
399
|
+
return finish('swiss', t, deriveSwiss(neutrals, t), notes)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const pickOn = (accent, n) => (Math.abs(apca('#ffffff', accent)) > Math.abs(apca(n.ink, accent)) ? '#ffffff' : n.ink)
|
|
403
|
+
const textSafe = (accent, paper) => textSafeAccent(accent, paper).hex
|
|
404
|
+
|
|
405
|
+
function finish(family, theme, derived, notes) {
|
|
406
|
+
const problems = auditTheme(derived.vars)
|
|
407
|
+
const hard = problems.filter((p) => !p.note)
|
|
408
|
+
if (hard.length) return { ok: false, family, theme, reason: hard.map((p) => `${p.token} 对比度不足(APCA ${p.apca})`).join(';') }
|
|
409
|
+
return { ok: true, family, theme, vars: derived.vars, notes, limits: problems.filter((p) => p.note).map((p) => `${p.token}:${p.note}`) }
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// 预览用:把品牌色和生成结果并排给出
|
|
413
|
+
const describe = (r) => (r.ok ? `${r.family} ✓ accent ${r.theme.accent} paper ${r.theme.paper || ''} ink ${r.theme.ink || ''}${r.notes.length ? '|调整:' + r.notes.join(',') : ''}` : `✗ ${r.reason}`)
|
|
414
|
+
|
|
415
|
+
const SWISS_NEUTRALS = {"paper":"#fafaf8","ink":"#0a0a0a","grey1":"#f0f0ee","grey2":"#d4d4d2","grey3":"#737373","textSecondary":"#525252","textPlaceholder":"#a3a3a3","borderSubtle":"#e0e0e0"}
|
|
416
|
+
const args = process.argv.slice(2)
|
|
417
|
+
const opt = (k, d) => (args.includes(k) ? args[args.indexOf(k) + 1] : d)
|
|
418
|
+
if (args[0] !== 'brand' || !args[1]) {
|
|
419
|
+
console.error('用法:node scripts/gz-theme.mjs brand "#4D6BFE" [--family magazine|swiss] [--id brand]')
|
|
420
|
+
process.exit(1)
|
|
421
|
+
}
|
|
422
|
+
const family = opt('--family', 'magazine'), id = opt('--id', 'brand')
|
|
423
|
+
const r = family === 'swiss' ? swissFromBrand(args[1], SWISS_NEUTRALS) : magazineFromBrand(args[1])
|
|
424
|
+
if (!r.ok) { console.error('✗ ' + r.reason); process.exit(1) }
|
|
425
|
+
const v = r.vars
|
|
426
|
+
// 一行说清楚:强调色调了什么、小字和色块上的文字各用什么颜色、有什么限制
|
|
427
|
+
const parts = [
|
|
428
|
+
r.notes.length ? r.notes.join(';') : `强调色保持 ${v['--accent']}`,
|
|
429
|
+
`小字强调色 ${v['--accent-ink']}`,
|
|
430
|
+
`色块上的文字 ${v['--accent-on-text']}${v['--accent-on-text'] !== v['--accent-on'] ? `(${v['--accent-on']} 只够大号粗体)` : ''}`,
|
|
431
|
+
...r.limits.filter((l) => !l.startsWith('--accent-on:')),
|
|
432
|
+
]
|
|
433
|
+
console.log(`/* 品牌主题 ${args[1]} · ${family}:${parts.join(';')} */`)
|
|
434
|
+
console.log(`[data-theme="${id}"]{${Object.entries(r.vars).map(([k, v]) => `${k}:${v}`).join(';')};color-scheme:light}`)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import vm from 'node:vm';
|
|
4
|
+
|
|
5
|
+
const file=process.argv[2];
|
|
6
|
+
const targetArg=process.argv.find(x=>x.startsWith('--target-minutes='));
|
|
7
|
+
const targetIndex=process.argv.indexOf('--target-minutes');
|
|
8
|
+
const targetMinutes=Number(targetArg?.split('=')[1]??(targetIndex>=0?process.argv[targetIndex+1]:NaN));
|
|
9
|
+
|
|
10
|
+
if(!file){
|
|
11
|
+
console.error('Usage: node scripts/validate-presenter-mode.mjs <index.html> [--target-minutes 30]');
|
|
12
|
+
process.exit(2);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const html=readFileSync(file,'utf8');
|
|
16
|
+
const source=html.replace(/<!--[\s\S]*?-->/g,'');
|
|
17
|
+
const errors=[];
|
|
18
|
+
const warnings=[];
|
|
19
|
+
|
|
20
|
+
function extractArray(name){
|
|
21
|
+
const marker=new RegExp(`(?:const|let|var)\\s+${name}\\s*=`).exec(source);
|
|
22
|
+
if(!marker)return null;
|
|
23
|
+
const start=source.indexOf('[',marker.index+marker[0].length);
|
|
24
|
+
if(start<0)return null;
|
|
25
|
+
let depth=0,quote='',escaped=false,lineComment=false,blockComment=false;
|
|
26
|
+
for(let i=start;i<source.length;i++){
|
|
27
|
+
const ch=source[i],next=source[i+1];
|
|
28
|
+
if(lineComment){if(ch==='\n')lineComment=false;continue;}
|
|
29
|
+
if(blockComment){if(ch==='*'&&next==='/'){blockComment=false;i++;}continue;}
|
|
30
|
+
if(quote){if(escaped){escaped=false;continue;}if(ch==='\\'){escaped=true;continue;}if(ch===quote)quote='';continue;}
|
|
31
|
+
if(ch==='/'&&next==='/'){lineComment=true;i++;continue;}
|
|
32
|
+
if(ch==='/'&&next==='*'){blockComment=true;i++;continue;}
|
|
33
|
+
if(ch==='"'||ch==="'"||ch==='`'){quote=ch;continue;}
|
|
34
|
+
if(ch==='[')depth++;
|
|
35
|
+
if(ch===']'&&--depth===0)return source.slice(start,i+1);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const slideTags=[...source.matchAll(/<section\b(?=[^>]*\bclass="[^"]*\bslide\b[^"]*")[^>]*>/g)].map(m=>m[0]);
|
|
41
|
+
const slideIds=slideTags.map((tag,i)=>tag.match(/\bdata-slide-id="([^"]+)"/)?.[1]||'');
|
|
42
|
+
if(!slideIds.length)warnings.push('No slides found; only the reusable presenter runtime can be validated.');
|
|
43
|
+
|
|
44
|
+
slideIds.forEach((id,i)=>{
|
|
45
|
+
if(!id)errors.push(`Slide ${i+1}: missing data-slide-id.`);
|
|
46
|
+
else if(!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id))errors.push(`Slide ${i+1}: data-slide-id="${id}" must be a lowercase semantic slug.`);
|
|
47
|
+
});
|
|
48
|
+
const duplicates=slideIds.filter((id,i)=>id&&slideIds.indexOf(id)!==i);
|
|
49
|
+
if(duplicates.length)errors.push(`Duplicate data-slide-id: ${[...new Set(duplicates)].join(', ')}`);
|
|
50
|
+
|
|
51
|
+
let speakerNotes=[];
|
|
52
|
+
const arraySource=extractArray('SPEAKER_NOTES');
|
|
53
|
+
if(!arraySource){
|
|
54
|
+
errors.push('Missing const SPEAKER_NOTES = [...].');
|
|
55
|
+
}else{
|
|
56
|
+
try{speakerNotes=vm.runInNewContext(`(${arraySource})`,Object.create(null),{timeout:1000});}
|
|
57
|
+
catch(error){errors.push(`SPEAKER_NOTES cannot be parsed: ${error.message}`);}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if(!Array.isArray(speakerNotes))errors.push('SPEAKER_NOTES must be an array.');
|
|
61
|
+
else{
|
|
62
|
+
if(speakerNotes.length!==slideIds.length)errors.push(`Notes/slides mismatch: ${speakerNotes.length} notes for ${slideIds.length} slides.`);
|
|
63
|
+
const noteIds=speakerNotes.map(n=>n?.id);
|
|
64
|
+
const noteDupes=noteIds.filter((id,i)=>id&¬eIds.indexOf(id)!==i);
|
|
65
|
+
if(noteDupes.length)errors.push(`Duplicate speaker-note id: ${[...new Set(noteDupes)].join(', ')}`);
|
|
66
|
+
speakerNotes.forEach((note,i)=>{
|
|
67
|
+
if(!note||typeof note!=='object'){errors.push(`Note ${i+1}: must be an object.`);return;}
|
|
68
|
+
for(const field of ['id','title','purpose','transition'])if(typeof note[field]!=='string'||!note[field].trim())errors.push(`Note ${i+1}: ${field} is required.`);
|
|
69
|
+
if(note.minutes!==undefined&¬e.minutes!==null&¬e.minutes!==''&&(!Number.isFinite(Number(note.minutes))||Number(note.minutes)<=0))errors.push(`Note ${i+1}: minutes must be > 0 when provided.`);
|
|
70
|
+
if(note.autoAdvanceSeconds!==undefined&¬e.autoAdvanceSeconds!==null&¬e.autoAdvanceSeconds!==''&&(!Number.isFinite(Number(note.autoAdvanceSeconds))||Number(note.autoAdvanceSeconds)<=0))errors.push(`Note ${i+1}: autoAdvanceSeconds must be > 0 when provided.`);
|
|
71
|
+
if(note.section!==undefined&&(typeof note.section!=='string'||!note.section.trim()))errors.push(`Note ${i+1}: section must be non-empty text when provided.`);
|
|
72
|
+
for(const field of ['cue','interaction','delivery','advance','fallback','pronunciation']){
|
|
73
|
+
const value=note[field];
|
|
74
|
+
if(value===undefined||value===null||value==='')continue;
|
|
75
|
+
const valid=typeof value==='string'?Boolean(value.trim()):Array.isArray(value)&&value.length>0&&value.every(x=>typeof x==='string'&&x.trim());
|
|
76
|
+
if(!valid)errors.push(`Note ${i+1}: ${field} must be non-empty text or an array of non-empty text.`);
|
|
77
|
+
}
|
|
78
|
+
if(!Array.isArray(note.talk)||!note.talk.length)errors.push(`Note ${i+1}: talk must be a non-empty array.`);
|
|
79
|
+
else{
|
|
80
|
+
if(note.talk.some(x=>typeof x!=='string'||!x.trim()))errors.push(`Note ${i+1}: every talk item must be non-empty text.`);
|
|
81
|
+
if(note.talk.length<3||note.talk.length>5)warnings.push(`Note ${i+1} (${note.id}): talk has ${note.talk.length} items; 3-5 is the default.`);
|
|
82
|
+
}
|
|
83
|
+
if(slideIds[i]&¬e.id!==slideIds[i])errors.push(`Position ${i+1}: note id "${note.id}" does not match slide id "${slideIds[i]}".`);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const runtimeChecks=[
|
|
88
|
+
['right-bottom presenter entry','id="ppt-presenter-btn"'],
|
|
89
|
+
['presenter shell','id="ppt-presenter"'],
|
|
90
|
+
['16:9 preview viewport','class="ppt-frame-viewport"'],
|
|
91
|
+
['proportional preview fitter','fitPresenterFrames'],
|
|
92
|
+
['overview control','id="ppt-grid"'],
|
|
93
|
+
['embedded presenter overview','id="ppt-presenter-overview"'],
|
|
94
|
+
['first-page control','id="ppt-first"'],
|
|
95
|
+
['last/restart control','id="ppt-last"'],
|
|
96
|
+
['audience status','id="ppt-sync"'],
|
|
97
|
+
['audience recovery','id="ppt-reopen"'],
|
|
98
|
+
['audience shutdown handling','showAudienceEnded'],
|
|
99
|
+
['direct window sync','postMessage('],
|
|
100
|
+
['BroadcastChannel fallback','BroadcastChannel'],
|
|
101
|
+
['storage fallback','__guizangPptSync'],
|
|
102
|
+
['per-slide timer','id="ppt-slide-clock"'],
|
|
103
|
+
['clear timer status','id="ppt-slide-status"'],
|
|
104
|
+
['rehearsal mode','id="ppt-rehearsal"'],
|
|
105
|
+
['auto advance','id="ppt-auto-toggle"'],
|
|
106
|
+
['laser and circle tools','id="ppt-presenter-ink"'],
|
|
107
|
+
['audience annotation layer','id="ppt-audience-ink"'],
|
|
108
|
+
['black, white, and freeze controls','setScreenMode'],
|
|
109
|
+
['preflight checks','id="ppt-preflight"'],
|
|
110
|
+
['layout presets','data-layout-choice'],
|
|
111
|
+
['capsule auto-advance switch','class="ppt-switch"'],
|
|
112
|
+
['styled interval stepper','class="ppt-stepper"'],
|
|
113
|
+
['reload-free preview navigation','preview-goto'],
|
|
114
|
+
['shortcut help','openShortcuts'],
|
|
115
|
+
];
|
|
116
|
+
for(const [label,needle]of runtimeChecks)if(!html.includes(needle))errors.push(`Presenter runtime missing ${label}.`);
|
|
117
|
+
if(!/\.ppt-preview-stack\s*\{[^}]*grid-template-rows\s*:/s.test(html))errors.push('Presenter preview stack must define vertical grid rows.');
|
|
118
|
+
if(!/\.ppt-frame\s*\{[^}]*aspect-ratio\s*:\s*16\s*\/\s*9/s.test(html))errors.push('Presenter preview frames must declare a 16:9 aspect ratio.');
|
|
119
|
+
if(!/fitPresenterFrames[\s\S]*?16\s*\/\s*9/.test(html))errors.push('Presenter preview fitter must preserve the 16:9 ratio.');
|
|
120
|
+
if(!/id="ppt-timer-toggle"[^>]*>开始计时<\/button>/.test(html))errors.push('Presenter timer must use the explicit label "开始计时".');
|
|
121
|
+
if(!/id="ppt-timer-reset"[^>]*>重置计时<\/button>/.test(html))errors.push('Presenter timer reset must use the explicit label "重置计时".');
|
|
122
|
+
if(!html.includes('继续计时'))errors.push('Presenter timer resume state must use the explicit label "继续计时".');
|
|
123
|
+
if(/\.ppt-preview-stack\{[^}]*grid-template-columns/.test(html))errors.push('Presenter previews must stack vertically; remove grid-template-columns from .ppt-preview-stack.');
|
|
124
|
+
|
|
125
|
+
const timedNotes=speakerNotes.filter(n=>Number.isFinite(Number(n?.minutes))&&Number(n.minutes)>0);
|
|
126
|
+
const planned=timedNotes.reduce((sum,n)=>sum+Number(n.minutes),0);
|
|
127
|
+
const completePlan=speakerNotes.length>0&&timedNotes.length===speakerNotes.length;
|
|
128
|
+
if(timedNotes.length&&!completePlan)warnings.push(`Timing is partial: ${timedNotes.length} of ${speakerNotes.length} notes provide minutes; total-budget checks are skipped.`);
|
|
129
|
+
if(completePlan&&Number.isFinite(targetMinutes)&&targetMinutes>0&&planned>targetMinutes*.9)errors.push(`Planned ${planned.toFixed(1)} min exceeds the 90% speaking budget (${(targetMinutes*.9).toFixed(1)} of ${targetMinutes} min).`);
|
|
130
|
+
if(completePlan&&Number.isFinite(targetMinutes)&&targetMinutes>0&&planned<targetMinutes*.55)warnings.push(`Planned ${planned.toFixed(1)} min is below 55% of the requested ${targetMinutes} min; confirm the deck is not under-scripted.`);
|
|
131
|
+
|
|
132
|
+
warnings.forEach(x=>console.warn(`WARN ${x}`));
|
|
133
|
+
errors.forEach(x=>console.error(`ERROR ${x}`));
|
|
134
|
+
console.log(`Presenter validation: ${slideIds.length} slides, ${speakerNotes.length} notes, ${completePlan?planned.toFixed(1):'partial / —'} planned minutes, ${errors.length} errors, ${warnings.length} warnings.`);
|
|
135
|
+
process.exit(errors.length?1:0);
|