From 4afab7c92950c84a41d38583becaaa802a1d2363 Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Sat, 17 Oct 2026 07:48:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(motion):=20DEC-N3=20=E7=9A=84=208=20?= =?UTF-8?q?=E6=9D=A1=E5=8A=A8=E6=95=88=E8=BF=9D=E5=8F=8D=E5=BD=92=E9=9B=B6?= =?UTF-8?q?=EF=BC=8C=E5=88=A4=E6=8D=AE=E4=BB=8E=E4=BB=A4=E7=89=8C=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E7=A7=BB=E5=88=B0=E6=B6=88=E8=B4=B9=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6 处写死贝塞尔收进 ease-ink [0.22,1,0.36,1](各处注释标 CONTEXT.md:77 出处); globals.css:1486 的裸时长 opacity 0.6s 改 var(--transition-slower)。 --transition-gentle = 1000ms 这一条量过再定:实测 src/ 里零消费 (只有 tailwind.config.js 的 duration-gentle 映射,无一处使用),入场消费点 0 ⇒ 原「令牌声明一律 ≤700ms」是把 CONTEXT.md:82 的**入场**红线读成了对调色板的禁令。 现口径改为按用途在消费点判红:非 infinite 的声明(含 var() 解析出的时长)>700ms 必红, infinite 循环环境动效维持豁免。 负对照(真树注入→还原):塞回 [0.16,1,0.3,1] + opacity 900ms 裸字面量 + opacity var(--transition-gentle) ⇒ check:motion EXIT=1,4 红命中 easing-palette×1、 css-transition-token×1、entrance-cap×2;还原后 EXIT=0、违规 0。 读数:check:motion EXIT=0(0 违反)、check:motion:test EXIT=0(21/21)。 --- .../check-motion-constraints.test.ts | 38 +++++++++++++++++-- scripts/utils/check-motion-constraints.ts | 28 ++++++++------ src/app/(marketing)/template.tsx | 7 +++- src/app/globals.css | 11 +++++- src/components/ui/brand-visuals.tsx | 6 ++- src/components/ui/page-transition.tsx | 6 ++- 6 files changed, 73 insertions(+), 23 deletions(-) diff --git a/scripts/utils/__tests__/check-motion-constraints.test.ts b/scripts/utils/__tests__/check-motion-constraints.test.ts index 6019edd..76cb1ec 100644 --- a/scripts/utils/__tests__/check-motion-constraints.test.ts +++ b/scripts/utils/__tests__/check-motion-constraints.test.ts @@ -272,7 +272,8 @@ describe('违规夹具:每条规则都必须能判红(防「常绿」)', ( expect(result.byRule('token-band').map((v) => v.token)).toEqual(['250ms', '400ms']); }); - it('R2 entrance-cap —— 令牌 1200ms / framer 1.4s / duration-900 类 / 配置串 1.1s', () => { + it('R2 entrance-cap —— framer 1.4s / duration-900 类 / 内联 0.9s / 配置串 1.1s / 超上限令牌被非循环声明消费', () => { + // DEC-N3(2026-10-08)后口径:令牌声明自身不判(声明无用途),**消费点**判红。 const result = scanFixture({ css: ` :root { @@ -295,10 +296,10 @@ describe('违规夹具:每条规则都必须能判红(防「常绿」)', ( config: `module.exports = { theme: { extend: { animation: { 'slow-in': 'fadeIn 1.1s var(--ease-ink) forwards' } } } };`, }); expect(result.exitCode).toBe(EXIT_VIOLATION); - // 令牌自身 + 经 var() 解析到该令牌的声明 + framer 1.4s + duration-900 类 + 内联 0.9s + 配置串 1.1s - expect(result.countOf('entrance-cap')).toBe(6); + // 经 var() 解析到超上限令牌的 .banner 声明 + framer 1.4s + duration-900 类 + 内联 0.9s + 配置串 1.1s。 + // `--transition-gentle: 1200ms` 声明本身**不再**计入(用途未知,判红在消费点)。 + expect(result.countOf('entrance-cap')).toBe(5); expect(result.byRule('entrance-cap').map((violation) => violation.file)).toEqual([ - 'src/app/globals.css', 'src/app/globals.css', 'src/components/card.tsx', 'src/components/card.tsx', @@ -307,6 +308,35 @@ describe('违规夹具:每条规则都必须能判红(防「常绿」)', ( ]); }); + it('R2 按用途分类(DEC-N3)—— 超上限令牌:零消费不判红;被非循环声明消费必判红;仅 infinite 消费豁免', () => { + const tokenCss = (usage: string) => ` +:root { + --transition-instant: 100ms; + --transition-fast: 180ms; + --transition-normal: 280ms; + --transition-gentle: 1000ms; + --ease-ink: cubic-bezier(0.22, 1, 0.36, 1); +} +${usage} +`; + // ① 真实仓库形状:1000ms 档存在但 src/ 零消费 ⇒ 不得判红(这正是 DEC-N3 的拍定依据) + const unconsumed = scanFixture({ css: tokenCss('') }); + expect(unconsumed.countOf('entrance-cap')).toBe(0); + expect(unconsumed.exitCode).toBe(EXIT_CLEAN); + + // ② 负对照:把它接入一个非循环 transition ⇒ **必须**在消费点判 entrance-cap + const consumed = scanFixture({ css: tokenCss('.hero { transition: opacity var(--transition-gentle) var(--ease-ink); }') }); + expect(consumed.exitCode).toBe(EXIT_VIOLATION); + expect(consumed.countOf('entrance-cap')).toBe(1); + expect(consumed.byRule('entrance-cap')[0]?.file).toBe('src/app/globals.css'); + + // ③ 循环环境动效(infinite)消费 ⇒ 按既有豁免不属「入场」 + const ambient = scanFixture({ + css: tokenCss('.aura { animation: auraPulse var(--transition-gentle) var(--ease-ink) infinite; }'), + }); + expect(ambient.countOf('entrance-cap')).toBe(0); + }); + it('R3 css-transition-token —— 裸 ms/s 字面量与悬空 var() 引用', () => { const result = scanFixture({ css: ` diff --git a/scripts/utils/check-motion-constraints.ts b/scripts/utils/check-motion-constraints.ts index abaa0e0..2c188cf 100644 --- a/scripts/utils/check-motion-constraints.ts +++ b/scripts/utils/check-motion-constraints.ts @@ -26,8 +26,15 @@ * 例外一:带 `infinite` 的循环动画不计入(循环不属「入场」,另立门禁)。 * 例外二:`*-delay` 声明判的是**延迟/错落**而非时长,属 `CONTEXT.md:78` * 的 stagger 口径(子元素 30–60ms、Section 间 100–150ms),本脚本不判。 - * `--transition-*` 家族里非 fast/normal/instant 的成员(slow / slower / gentle) - * 同样受此上限约束 —— `gentle: 1000ms` 就是这么被抓出来的。 + * ── DEC-N3(2026-10-08):**按用途分类判定,不再一刀切判令牌声明**。 + * CONTEXT.md:82 禁的是「>700ms 的**入场**动效」;令牌声明自身不携带用途, + * 用途只存在于消费点。实测 `--transition-gentle = 1000ms` 在 src/ 零消费 + * (仅 tailwind.config.js 的 duration-gentle 映射,无一处使用), + * 入场消费点为 0 ⇒ 原「令牌声明一律 ≤700ms」是把红线读成了对调色板的禁令。 + * 现口径:**消费点判红** —— 任何非 infinite 的 transition/animation 声明 + * (含经 var(--transition-*) 解析出的时长)超过 700ms 即判红;infinite + * 循环环境动效维持既有豁免。闸的失败面(负对照)见 R2 测试: + * 把超上限令牌接入非循环声明,必判红。 * R3 `css-transition-token` CSS/内联 transition 声明的时长必须走 `var(--transition-*)` 令牌, * 不得写裸 ms/s 字面量(令牌层是唯一事实来源)。 * 例外:含 `!important` 的 `prefers-reduced-motion` 硬开关(globals.css:767-775)。 @@ -110,9 +117,9 @@ export const MOTION_RULES: readonly RuleSpec[] = [ }, { id: 'entrance-cap', - title: 'R2 时长硬上限:任何动效时长不得超过 700ms(infinite 循环动画除外)', + title: 'R2 时长硬上限:任何**消费点**的动效时长不得超过 700ms(infinite 循环动画豁免;令牌声明按用途在消费点判定,DEC-N3)', source: 'CONTEXT.md:82', - suggestion: '降到 ≤ 700ms,入场动画应落到 var(--transition-fast)…var(--transition-normal)', + suggestion: '降到 ≤ 700ms,入场动画应落到 var(--transition-fast)…var(--transition-normal);超上限档位(如 --transition-gentle)禁止接入非循环声明', }, { id: 'css-transition-token', @@ -463,14 +470,11 @@ export function scanCssText( `--transition-${name} 是入场档,必须落在 ${MOTION_SPEC.entranceMinMs}–${MOTION_SPEC.entranceMaxMs}ms(实测 ${ms}ms)`, ); } - if (ms > MOTION_SPEC.entranceCapMs) { - push( - 'entrance-cap', - declaration.line, - declaration.value.trim(), - `--transition-${name} = ${ms}ms 超过 ${MOTION_SPEC.entranceCapMs}ms 入场硬上限`, - ); - } + // DEC-N3(2026-10-08):此处**不再**对令牌声明做 700ms 上限判定。 + // CONTEXT.md:82 的禁令对象是「入场动效」,而声明自身无用途;用途在消费点, + // 由本文件下方「R2 消费点」分支(裸字面量 / var() 解析)判红,infinite 循环豁免照旧。 + // 负对照:`--transition-x: 1000ms` + `.y { transition: opacity var(--transition-x) }` + // 必在 .y 那一行触发 entrance-cap(见 __tests__ R2 按用途分类用例)。 continue; } diff --git a/src/app/(marketing)/template.tsx b/src/app/(marketing)/template.tsx index 84939a7..7acf595 100644 --- a/src/app/(marketing)/template.tsx +++ b/src/app/(marketing)/template.tsx @@ -13,7 +13,9 @@ const pageVariants: Variants = { y: 0, transition: { duration: 0.28, - ease: [0.16, 1, 0.3, 1] as [number, number, number, number], + // DEC-N3(2026-10-08):原 [0.16, 1, 0.3, 1] 是令牌层之外的写死曲线, + // 归口到 CONTEXT.md:77 的统一缓动 ease-ink = [0.22, 1, 0.36, 1](globals.css --ease-ink)。 + ease: [0.22, 1, 0.36, 1] as [number, number, number, number], }, }, exit: { @@ -21,7 +23,8 @@ const pageVariants: Variants = { y: -4, transition: { duration: 0.2, - ease: [0.16, 1, 0.3, 1] as [number, number, number, number], + // 同上:退场同样走 ease-ink(与 page-transition.tsx exit 的曲线一致)。 + ease: [0.22, 1, 0.36, 1] as [number, number, number, number], }, }, }; diff --git a/src/app/globals.css b/src/app/globals.css index ac86319..5389e54 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -289,6 +289,12 @@ body { --transition-normal: 280ms; --transition-slow: 450ms; --transition-slower: 700ms; + /* --transition-gentle(DEC-N3,2026-10-08 拍定口径): + 1000ms 这档**不违反** CONTEXT.md:82「禁止 >700ms 入场动效」——前提是它不用于入场。 + 实测消费点(本树):仅下方 tailwind.config.js 的 duration-gentle 映射,src/ 零引用, + 即入场/循环环境/其他三类**均无消费者**。故闸改为**按消费点用途分类判定**: + 任何非 infinite 的 transition/animation 声明解析到 >700ms 即判红; + infinite 循环环境动效按既有口径豁免。**禁止**把本档接入任何入场动效声明。 */ --transition-gentle: 1000ms; /* 缓动曲线(按性格分类) */ @@ -1483,7 +1489,10 @@ p, li, span { -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0; - transition: opacity 0.6s var(--ease-out); + /* DEC-N3(2026-10-08):原 `opacity 0.6s` 是裸时长字面量,归口令牌层。 + 600ms 取最近档 --transition-slower(700ms)——光晕渐显属环境性淡入而非入场/可操作反馈, + 曲线沿用令牌层 --ease-out(=ease-ink,「背景过渡、光晕变化」正是其声明用途)。 */ + transition: opacity var(--transition-slower) var(--ease-out); pointer-events: none; } diff --git a/src/components/ui/brand-visuals.tsx b/src/components/ui/brand-visuals.tsx index 9581051..4294dba 100644 --- a/src/components/ui/brand-visuals.tsx +++ b/src/components/ui/brand-visuals.tsx @@ -63,7 +63,8 @@ export function DataBar({ value, max = 100, label, color = 'brand' }: { value: n initial={{ width: 0 }} whileInView={{ width: `${percentage}%` }} viewport={{ once: true }} - transition={{ duration: 0.28, ease: [0.16, 1, 0.3, 1], delay: 0.2 }} + // DEC-N3(2026-10-08):[0.16, 1, 0.3, 1] 不在令牌层,统一收编为 ease-ink [0.22, 1, 0.36, 1] + transition={{ duration: 0.28, ease: [0.22, 1, 0.36, 1], delay: 0.2 }} className="h-full rounded-full" style={{ backgroundColor: colorMap[color] }} /> @@ -92,7 +93,8 @@ export function BrandStamp({ children }: { children: React.ReactNode }) { initial={shouldReduceMotion ? {} : { scale: 1.3, opacity: 0, rotate: -12 }} whileInView={{ scale: 1, opacity: 1, rotate: -5 }} viewport={{ once: true }} - transition={{ duration: 0.28, ease: [0.16, 1, 0.3, 1] }} + // DEC-N3(2026-10-08):同上,曲线归口令牌层 ease-ink。 + transition={{ duration: 0.28, ease: [0.22, 1, 0.36, 1] }} className="inline-block px-3 py-1.5 border-2 border-[var(--color-brand)] rounded-sm" style={{ transform: 'rotate(-5deg)', diff --git a/src/components/ui/page-transition.tsx b/src/components/ui/page-transition.tsx index a2c0531..380e8bc 100644 --- a/src/components/ui/page-transition.tsx +++ b/src/components/ui/page-transition.tsx @@ -17,7 +17,8 @@ const pageVariants = { scale: 1, transition: { duration: 0.28, - ease: [0.25, 1, 0.5, 1] as const, + // DEC-N3(2026-10-08):原 [0.25, 1, 0.5, 1] 收编进令牌层统一缓动 ease-ink(CONTEXT.md:77)。 + ease: [0.22, 1, 0.36, 1] as const, staggerChildren: 0.05, }, }, @@ -73,7 +74,8 @@ const sectionVariants = { transition: { delay: i * 0.06, duration: 0.28, - ease: [0.25, 1, 0.5, 1] as const, + // DEC-N3(2026-10-08):同 animate 变体,归口 ease-ink。 + ease: [0.22, 1, 0.36, 1] as const, }, }), };