Skip to content

Commit 2ed5c83

Browse files
committed
refactor(utils): 析出 lowConfidenceClass 到独立模块
1 parent 681e73c commit 2ed5c83

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎app/src/components/session-detail/SessionRawView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import { useRef } from "react";
4848
import SessionScreenCards from "./SessionScreenCards";
4949
import ImageGallery from "../ImageGallery";
50-
import { lowConfidenceClass } from "../structuredBlocks";
50+
import { lowConfidenceClass } from "../../utils/lowConfidence";
5151
import { useRevealChoreography } from "./useRevealChoreography";
5252
import type { GlossaryTerm, SessionDetail, SessionOcrBlock } from "../../types";
5353
import { fmtMs } from "../../utils/fmt";

‎app/src/motion/env.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import { readdirSync } from "node:fs";
3232
import { describe, expect, it } from "vitest";
3333
import { DURATION_TOKENS, EASING_TOKENS } from "../../scripts/gen-tokens.mjs";
34-
import { lowConfidenceClass } from "../components/structuredBlocks";
34+
import { lowConfidenceClass } from "../utils/lowConfidence";
3535
import { AMBIENT_ITEMS, LOW_CONFIDENCE_CLASS, LOW_CONFIDENCE_INK_AMPLITUDE } from "./env";
3636
import {
3737
PRIMITIVES, blockAt, declaredProps, declarationValue, parseRules, readPrimitiveCss,

‎app/src/utils/lowConfidence.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* lowConfidence.ts — 低置信墨度类名的**唯一出口**(批 7 T2:按裁决 C4.2 从 `components/structuredBlocks.ts` 析出)。
3+
*
4+
* @ai-context Why 必须析出:原模块顶层持有两条**大体积数学排版库的静态边**(主包 + 它的样式表,
5+
* 位置 = `components/structuredBlocks.ts:8-9`)⇒ 任何只想要「类名函数」的引用,都会把那个库
6+
* 整个拉进**会话详情的惰性 chunk**(批 6 T34 实测第二份副本 **+227,858 B 原始 / +64,497 B gzip**;
7+
* 首屏预算看不见它,因为懒侧 chunk 不计入)。本模块**零依赖、零副作用**(不读 store、不发请求、
8+
* 不写盘、不碰 DOM)⇒ 那条边随之消失。析出**只搬声明的位置**,不搬语义。
9+
* @ai-context 类名字面量**逐字不改**(`ed-text--low-confidence`):`ui/primitives/Text.css:63` 的规则、
10+
* `motion.css:272/299/325` 的三档名单、`motion/env.ts:44` 的镜像全以它为准;旧名 `ed-low-confidence`
11+
* **仍是退役名**(`motion-coverage.test.ts:67-73` 的「绝不许再出现」名单,不得改回)。
12+
* 阈值(`< 0.5`)与判定形态(`!= null &&`)在搬迁前后逐字相同。
13+
* @ai-context 镜像代价照旧:`motion/env.ts` 的 `LOW_CONFIDENCE_CLASS` 是**双写字面量**(批 6 评审 M-2
14+
* 已登记为合理代价 —— `motion/**` 不宜依赖别层)⇒ 两者一致性由 `motion/env.test.ts` 的 V6 对拍守住,
15+
* 本次**不动**那份镜像。生产调用点:`components/session-detail/SessionRawView.tsx`(1 个;
16+
* 加宽到 ≥2 是批 7 T17 的活)。
17+
*/
18+
19+
/** 低置信墨度类名(与 `motion/env.ts` 的 `LOW_CONFIDENCE_CLASS` 镜像**逐字相同**) */
20+
export const LOW_CONFIDENCE_CLASS = "ed-text--low-confidence";
21+
22+
/**
23+
* 置信度 → 低置信类名(`< 0.5` 判定,阈值与判定形态不变;`null`/`undefined` ⇒ 空串)。
24+
*
25+
* @ai-context 为什么返回空串而不是 `undefined`:调用点直接写 `className={lowConfidenceClass(x)}`,
26+
* 空串让 React 不产出 `class` 属性 —— 既有行为,逐字保留。
27+
* @ai-context 为什么是 `!= null &&`:同时排除 `null` 与 `undefined`,且让 `0`(= 可信度最低)**仍然
28+
* 命中**低置信分支 —— 这是既有语义,不许改成真值判断。
29+
*/
30+
export function lowConfidenceClass(confidence: number | null | undefined): string {
31+
return confidence != null && confidence < 0.5 ? LOW_CONFIDENCE_CLASS : "";
32+
}

0 commit comments

Comments
 (0)