fix(gates): check:motion 的 CSS 解析器不剥注释,会把紧随其后的令牌整条吞掉
extractCssDeclarations 的声明正则值部分是 `[^;{}]*`,天然跨行、一路吃到下一个 `;`。
它原先不剥注释,于是当一条令牌定义前面有一段含 **ASCII 冒号**的块注释时(例如注释里写
`CONTEXT.md:76`),正则会先从注释里的 `md:` 起匹配,把「注释余文 + 紧随其后的整条
`--transition-hover: 150ms;`」一起吞进 value 捕获组 —— 该声明根本没被采集。
后果不是少个数,是**假红**:R3 随后对着一个明明已定义的令牌报
「引用了未定义的 --transition-hover 令牌(编译后不生效)」。假红比假绿更贵,
它教会人无视这道闸。
发现方式:本批给 globals.css 加 --transition-hover 档时,闸报 `--transition-* 令牌 6`
而 `:root` 里实有 7 条,且判定分母对不上 —— 逐条核对才定位到解析器而非 CSS 写错。
- 新增 stripCssComments:整段替换为**等量换行**,故 lineOf 报出的行号仍指向原文件那一行
(行号错位 = 判据不可行动,等同半个假绿)
- 配套回归用例是双向的:断言采集数 == 实际定义数(4),且注释在/不在时判定必须一致
- 已实测该用例能失败:摘掉修复 → Expected 4 / Received 3;恢复 → 20 passed
门禁:check:motion:test 20/20(原 19 + 新增 1);type-check EXIT=0;
全量 jest 143 套件 / 1769 例通过。
This commit is contained in:
1 parent
da9a5cb650
commit
d346301405
3 files changed
+52
-201
No files matched your search
@@ -220,6 +220,39 @@ export const C = () => <motion.div transition={{ duration: 0.2, ease: [0.1, 0.2,
|
||||
});
|
||||
expect(result.violations).toEqual([]);
|
||||
});
|
||||
|
||||
it('回归:令牌定义紧跟「含 ASCII 冒号的多行注释」之后,仍必须被采集', () => {
|
||||
// 缺陷现场(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('违规夹具:每条规则都必须能判红(防「常绿」)', () => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<HTMLDivElement>(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 (
|
||||
<section
|
||||
id="home"
|
||||
aria-labelledby="hero-heading"
|
||||
className="relative min-h-screen flex flex-col justify-center overflow-hidden bg-[var(--color-bg-primary)]"
|
||||
>
|
||||
<div className="container-wide py-16 md:py-24 lg:py-32 relative z-10 flex-1 flex items-center">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-10 lg:gap-16 items-center w-full">
|
||||
<div>
|
||||
<motion.div
|
||||
{...fadeUp(0)}
|
||||
className="mb-6"
|
||||
>
|
||||
<span className="inline-flex items-center gap-2 px-3 py-1.5 sm:px-4 sm:py-2 rounded-full bg-[var(--color-brand-bg)] text-brand-ink text-xs sm:text-sm font-medium border border-brand/10">
|
||||
{COMPANY_INFO.slogan}
|
||||
</span>
|
||||
</motion.div>
|
||||
|
||||
<motion.p
|
||||
{...fadeUp(0.1)}
|
||||
className="text-lg sm:text-xl lg:text-2xl text-[var(--color-text-secondary)] mb-3 font-medium"
|
||||
>
|
||||
企业数字化转型服务商
|
||||
</motion.p>
|
||||
|
||||
<motion.h1
|
||||
id="hero-heading"
|
||||
{...fadeUp(0.15)}
|
||||
className="text-5xl sm:text-6xl lg:text-7xl tracking-tight mb-5 font-brand leading-[1.1]"
|
||||
style={{ fontWeight: 'normal' }}
|
||||
>
|
||||
{COMPANY_INFO.shortName}
|
||||
</motion.h1>
|
||||
|
||||
<motion.p
|
||||
{...fadeUp(0.25)}
|
||||
className="text-base sm:text-lg text-[var(--color-text-muted)] max-w-lg leading-relaxed mb-8"
|
||||
>
|
||||
{COMPANY_INFO.description}
|
||||
</motion.p>
|
||||
|
||||
<motion.div
|
||||
{...fadeUp(0.35)}
|
||||
className="flex flex-col sm:flex-row items-start gap-4 mb-10"
|
||||
>
|
||||
<Button size="lg" asChild className="min-h-[52px] px-8 text-base font-semibold shadow-lg shadow-brand/20">
|
||||
<StaticLink href="/contact">
|
||||
{CTA_LABELS.consult}
|
||||
<ArrowRight className="w-4 h-4 ml-2" />
|
||||
</StaticLink>
|
||||
</Button>
|
||||
<Button size="lg" variant="ghost" asChild className="text-[var(--color-text-muted)]">
|
||||
<StaticLink href="/products">探索产品</StaticLink>
|
||||
</Button>
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
<motion.div
|
||||
initial={shouldReduceMotion ? {} : { opacity: 0, y: 32 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.28, delay: 0.5, ease: EASE }}
|
||||
>
|
||||
<div
|
||||
ref={cardRef}
|
||||
className="relative overflow-hidden rounded-2xl lg:opacity-95 border border-[var(--color-border-primary)]"
|
||||
style={
|
||||
{
|
||||
'--glow-start': 'var(--color-brand)',
|
||||
'--glow-end': 'var(--color-warning)',
|
||||
} as React.CSSProperties
|
||||
}
|
||||
onMouseMove={handleCardMouseMove}
|
||||
onMouseEnter={() => setIsCardHovered(true)}
|
||||
onMouseLeave={() => setIsCardHovered(false)}
|
||||
>
|
||||
<div
|
||||
className="absolute inset-0 rounded-2xl pointer-events-none transition-opacity duration-normal"
|
||||
style={{
|
||||
opacity: isCardHovered ? 1 : 0,
|
||||
background: `radial-gradient(400px circle at ${mousePos.x}px ${mousePos.y}px, rgba(var(--color-brand-rgb), 0.06), transparent 40%)`,
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="relative rounded-2xl bg-bg-primary/80 backdrop-blur-sm p-6 sm:p-8 lg:p-10">
|
||||
<div className="w-12 h-12 lg:w-14 lg:h-14 rounded-xl bg-[var(--color-brand-bg)] flex items-center justify-center mb-5 lg:mb-6">
|
||||
<Handshake className="w-5 h-5 lg:w-6 lg:h-6 text-brand-ink" strokeWidth={1.8} />
|
||||
</div>
|
||||
|
||||
<h3 className="text-lg lg:text-xl font-semibold text-[var(--color-text-primary)] mb-2">
|
||||
从沟通到落地,全程陪伴
|
||||
</h3>
|
||||
<p className="text-sm text-[var(--color-text-muted)] leading-relaxed mb-6 lg:mb-8">
|
||||
四步合作流程,确保每个项目科学推进、高效交付
|
||||
</p>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3 lg:gap-4 lg:block lg:space-y-4">
|
||||
{JOURNEY_STEPS.map((step, idx) => {
|
||||
const Icon = step.icon;
|
||||
return (
|
||||
<div
|
||||
key={step.label}
|
||||
className="flex items-center gap-3 lg:gap-4 p-2.5 lg:p-3 rounded-lg bg-bg-section/60"
|
||||
>
|
||||
<div className="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-[var(--color-brand-bg)] flex items-center justify-center shrink-0">
|
||||
<Icon className="w-3.5 h-3.5 lg:w-4 lg:h-4 text-brand-ink" strokeWidth={2.2} />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-1.5 lg:gap-2">
|
||||
<span className="text-[10px] lg:text-xs font-bold text-brand-ink">0{idx + 1}</span>
|
||||
<span className="text-xs lg:text-sm font-medium text-[var(--color-text-primary)]">{step.label}</span>
|
||||
</div>
|
||||
<p className="text-[10px] lg:text-xs text-[var(--color-text-muted)] mt-0.5 hidden sm:block">{step.desc}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Integrated capabilities */}
|
||||
<div className="mt-4 pt-4 border-t border-border-primary/50">
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{CAPABILITIES.map((cap, idx) => {
|
||||
const Icon = cap.icon;
|
||||
return (
|
||||
<div
|
||||
key={cap.label}
|
||||
className="flex items-center gap-2 px-3 py-2 rounded-lg border transition-colors duration-200"
|
||||
style={{
|
||||
backgroundColor: idx === 0 ? 'var(--color-brand-bg)' : idx === 1 ? 'rgba(var(--color-accent-blue-rgb), 0.06)' : idx === 2 ? 'rgba(var(--color-accent-purple-rgb), 0.06)' : 'rgba(var(--color-accent-cyan-rgb), 0.06)',
|
||||
borderColor: idx === 0 ? 'rgba(var(--color-brand-rgb), 0.15)' : 'var(--color-border-primary)',
|
||||
}}
|
||||
>
|
||||
<Icon
|
||||
className="w-4 h-4"
|
||||
style={{ color: idx === 0 ? 'var(--color-brand)' : idx === 1 ? 'var(--color-accent-blue)' : idx === 2 ? 'var(--color-accent-purple)' : 'var(--color-accent-cyan)' }}
|
||||
strokeWidth={2.2}
|
||||
/>
|
||||
<span className="text-xs font-medium text-[var(--color-text-primary)]">{cap.label}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user