diff --git a/scripts/utils/__tests__/check-motion-constraints.test.ts b/scripts/utils/__tests__/check-motion-constraints.test.ts index 469bae1..6019edd 100644 --- a/scripts/utils/__tests__/check-motion-constraints.test.ts +++ b/scripts/utils/__tests__/check-motion-constraints.test.ts @@ -220,6 +220,39 @@ export const C = () => { + // 缺陷现场(2026-10-16):extractCssDeclarations 原先不剥注释,而值部分 `[^;{}]*` 跨行吃到下一个 `;`。 + // 于是注释里的 `CONTEXT.md:76` 起匹配后,把注释余文连同下一行 `--transition-hover: 150ms;` + // 一起吞进 value 组 ⇒ 该令牌没被采集 ⇒ 闸对**已定义**的令牌报「悬空引用=死样式」的假红。 + // 两条断言互为对照:采集数必须等于实际定义数,且引用它不产生违规。 + const withColonComment = ` +:root { + --transition-instant: 100ms; + /* hover 档:动效四原则 CONTEXT.md:76 早就写了「hover 150ms」,但仓库从来没有这个档。 + 补在此处闭合 C-1。 */ + --transition-hover: 150ms; + --transition-fast: 180ms; + --transition-normal: 280ms; + --ease-ink: cubic-bezier(0.22, 1, 0.36, 1); +} +.card { transition: border-color var(--transition-hover) var(--ease-out), background var(--transition-hover) var(--ease-out); } +`; + const withoutComment = withColonComment + .split('\n') + .filter((l) => !/^\s*(\/\*|\*|.*\*\/)\s*/.test(l) && !/hover 档|补在此处/.test(l)) + .join('\n'); + + const a = scanFixture({ css: withColonComment }); + const b = scanFixture({ css: withoutComment }); + + // 4 = instant / hover / fast / normal。修复前这里只采到 3(hover 被注释吞掉) + expect(a.counts.transitionTokens).toBe(4); + expect(b.counts.transitionTokens).toBe(4); + // 注释在不在,判定必须一致:不得因注释而多出「悬空引用」 + expect(a.countOf('css-transition-token')).toBe(0); + expect(b.countOf('css-transition-token')).toBe(0); + }); }); describe('违规夹具:每条规则都必须能判红(防「常绿」)', () => { diff --git a/scripts/utils/check-motion-constraints.ts b/scripts/utils/check-motion-constraints.ts index 4653cac..abaa0e0 100644 --- a/scripts/utils/check-motion-constraints.ts +++ b/scripts/utils/check-motion-constraints.ts @@ -235,15 +235,33 @@ export interface CssDeclaration { isCustomProperty: boolean; } +/** + * 剥 CSS 注释,但**保留换行条数**,使 lineOf 算出的行号仍指向原文件那一行。 + * + * 为什么必须在扫描之前剥(2026-10-16 真实踩到,不是假想): + * 下面的声明正则值部分 `[^;{}]*` 天然跨行、一路吃到下一个 `;`。若某条令牌定义前面有一段 + * 含 **ASCII 冒号**的块注释(例如注释里写 `CONTEXT.md:76`),正则会先从注释里的 `md:` 起匹配, + * 把「注释余文 + 紧随其后的整条 `--transition-hover: 150ms;`」一起吞进 value 组 —— + * 该声明于是**根本没被采集**,闸转而报「引用了未定义的 --transition-hover(死样式)」, + * 是一条对着已存在令牌的**假红**。假红比假绿更贵:它教会人无视这道闸。 + * 现场:globals.css 的 :root 实有 7 个 `--transition-*`,本闸只采到 6 个,即此因。 + */ +export function stripCssComments(text: string): string { + return text.replace(/\/\*[\s\S]*?\*\//g, (m) => "\n".repeat((m.match(/\n/g) ?? []).length)); +} + /** * 从 CSS 文本里抽出「属性: 值」声明。 * `[^;{}]*` 天然跨行,故 globals.css:314 那种多行值也能拿到完整串。 * 自定义属性(`--transition-*` / `--ease-*` / `--card-transition`)与普通声明都会拿到, * 由调用方按 prop 名分流;`--card-transition` 这类「组件级过渡令牌」也在射程内, * 因为它同样是编译进产物的 CSS 值。 + * ⚠ 扫描前先过 stripCssComments,否则注释里的 ASCII 冒号会吞掉紧随其后的声明。 */ -export function extractCssDeclarations(text: string): CssDeclaration[] { +export function extractCssDeclarations(rawText: string): CssDeclaration[] { const declarations: CssDeclaration[] = []; + // 扫描前先剥注释:见 stripCssComments 里记的假红事故 + const text = stripCssComments(rawText); const lineOf = makeLineResolver(text); const pattern = /(--[\w-]+|[a-z][\w-]*)\s*:\s*([^;{}]*)/gi; let match: RegExpExecArray | null = pattern.exec(text); diff --git a/src/components/sections/hero-section-v2.tsx b/src/components/sections/hero-section-v2.tsx deleted file mode 100644 index 528530d..0000000 --- a/src/components/sections/hero-section-v2.tsx +++ /dev/null @@ -1,200 +0,0 @@ -'use client'; - -import { useCallback, useRef, useState } from 'react'; -import { motion } from 'framer-motion'; -import { StaticLink } from '@/components/ui/static-link'; -import { CTA_LABELS } from '@/lib/constants/cta-labels'; -import { Button } from '@/components/ui/button'; - -import { COMPANY_INFO } from '@/lib/constants'; -import { ArrowRight, MessageSquare, Search, Rocket, Handshake } from 'lucide-react'; -import { useReducedMotion } from '@/hooks/use-reduced-motion'; - -const EASE = [0.16, 1, 0.3, 1] as const; - -const CAPABILITIES = [ - { icon: MessageSquare, label: '需求沟通' }, - { icon: Search, label: '方案诊断' }, - { icon: Rocket, label: '敏捷交付' }, - { icon: Handshake, label: '长期陪跑' }, -]; - -const JOURNEY_STEPS = [ - { icon: MessageSquare, label: '需求沟通', desc: '深入理解您的业务痛点' }, - { icon: Search, label: '方案诊断', desc: '量身定制技术路径' }, - { icon: Rocket, label: '敏捷交付', desc: '快速迭代持续验证' }, - { icon: Handshake, label: '长期陪跑', desc: '持续优化保障落地' }, -]; - -export function HeroSectionV2() { - const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); - const [isCardHovered, setIsCardHovered] = useState(false); - const cardRef = useRef(null); - const shouldReduceMotion = useReducedMotion(); - - const handleCardMouseMove = useCallback((e: React.MouseEvent) => { - if (!cardRef.current) { return; } - const rect = cardRef.current.getBoundingClientRect(); - setMousePos({ - x: e.clientX - rect.left, - y: e.clientY - rect.top, - }); - }, []); - - const fadeUp = (delay: number) => ({ - initial: shouldReduceMotion ? {} : { opacity: 0, y: 24 }, - animate: { opacity: 1, y: 0 }, - transition: { duration: 0.28, delay, ease: EASE }, - }); - - return ( -
-
-
-
- - - {COMPANY_INFO.slogan} - - - - - 企业数字化转型服务商 - - - - {COMPANY_INFO.shortName} - - - - {COMPANY_INFO.description} - - - - - - -
- - -
setIsCardHovered(true)} - onMouseLeave={() => setIsCardHovered(false)} - > -
- -
-
- -
- -

- 从沟通到落地,全程陪伴 -

-

- 四步合作流程,确保每个项目科学推进、高效交付 -

- -
- {JOURNEY_STEPS.map((step, idx) => { - const Icon = step.icon; - return ( -
-
- -
-
-
- 0{idx + 1} - {step.label} -
-

{step.desc}

-
-
- ); - })} -
- - {/* Integrated capabilities */} -
-
- {CAPABILITIES.map((cap, idx) => { - const Icon = cap.icon; - return ( -
- - {cap.label} -
- ); - })} -
-
-
-
- -
-
-
- ); -}