feat(design): 签名件原语(斜线纹/双V/斜杠/空白带)+ R18–R19 门禁
三件几何都是 2026-11-03 对 Porsche Consulting 中国站首页放大到像素级确认的原物,
换掉色相后逐字移植(朱砂 #C41E3A 取代 #D6001D,ADR-0008 决策一已裁定):
- HatchField 斜线纹。原物是 20×20 SVG 平铺 + rotate(140deg) + 1px 横线。
换 CSS 等价形,两处换算写进组件与 :root 注释:
角度 140deg(CSS 渐变线方向 = A-180 ≡ -40° ≡ 140°,直线有 180° 对称)、
垂距 12.86px(= 20 × sin140°,照抄 20px 会让纹理稀掉一半)。
- DoubleChevron **两枚不同的形,不是一枚旋转**:向下(23.938×22 路径,第二枚下偏
26/77)用于黑段与图角;向右(112×145 路径,第二枚右偏 36/106)用于
收束段。两份原物路径首段逐字保留,第二枚走 transform 而非重画。
渲染框取自实测包围盒;原站用 <img> 指定宽高、本身就是非等比拉伸,
故 preserveAspectRatio="none" 是忠实还原,不是偷懒。
- SlashMark 18×17 平行四边形(原 img_divider.svg),供 01/04 计数器与 › 前导符。
- BandSpacer 对标首页两条独立 120px 空模块(内部零内容、padding 0)。本仓 20+ 段
都自带 py-16 md:py-24,所以**只新增**这条带子、不把段内 padding 归零。
裁定:双 V 静止。原物挂了 pulseVertical/pulseHorizontal 6s infinite 的引导脉冲,
但 CONTEXT.md:81 禁循环装饰动画,且双 V 本身已是「还有下文」的信号。记入 ADR-0009。
门禁
- R18 营销面零签名件字面量(tile_hatching / rotate(140 / 三枚路径首段),上限 0 即硬禁
—— 之前全仓零命中,登记非零上限等于给第二份纹样真源预开名额。
- R19 营销面零 font-extrabold(800),棘轮 21。字重纪律只约束声明档与模块标题:
实测 font-medium 77 / font-semibold 68 处是标签与元信息在用,一刀切成 400/700
是 145 处无视觉收益的大迁移,不做。
两处顺带修复(都在本分支基线就红,非本次引入)
- image-module.tsx 引用了不存在的 ImageRatioKey(真源导出的是 ImageRatio)。
- 该文件与 image-ratios.ts、display-statement.tsx 此前只存在于工作树未入库,
而 index.ts 已导出 image-ratios ⇒ 单独看是断的。随本提交一并入库。
验证:check:grammar --selftest 全部两侧自证通过(R13–R19 各自「上限不判红/上限+1 判红」);
check:grammar EXIT=0(19/19,R18 实测 0、R19 实测 21);type-check EXIT=0;
jest ui/{hatch-field,double-chevron,slash-mark} 17/17。
This commit is contained in:
1 parent
ce4685cf0a
commit
163e2c5ed8
12 files changed
+643
-11
No files matched your search
@@ -88,11 +88,16 @@ const MARKETING_TEST_RE = /\.(test|spec)\.tsx?$/;
|
||||
const MARKETING_FLOOR = 60;
|
||||
|
||||
/**
|
||||
* R13–R17 的**存量上限**(现取 2026-11-02:营销面 78 个 .tsx,排除 .test/.spec 与 _archive)。
|
||||
* R13–R19 的**存量上限**(R13–R17 现取 2026-11-02;R18/R19 现取 2026-11-03:
|
||||
* 营销面 78 个 .tsx,排除 .test/.spec 与 _archive)。
|
||||
* 每条只许减不许加;跌破即提示下调(同 R10 棘轮的纪律,防止「闸还在、存量已被自己删空」
|
||||
* 退化成永久豁免)。清零后把上限登记为 0,判据即变成硬禁。
|
||||
*
|
||||
* R18 是**硬禁**(0):签名件(斜线纹 / 双 V / 斜杠)在 2026-11-03 之前全仓零命中,
|
||||
* 没有「存量」可言 —— 登记一个非零上限等于给第二份纹样真源预开一个名额。
|
||||
* R19 是棘轮(21):营销面实测 21 处 font-extrabold,先登记再随模板批逐页清。
|
||||
*/
|
||||
const MARKETING_HIT_CEILINGS = { R13: 71, R14: 21, R15: 21, R16: 26, R17: 53 };
|
||||
const MARKETING_HIT_CEILINGS = { R13: 71, R14: 21, R15: 21, R16: 26, R17: 53, R18: 0, R19: 21 };
|
||||
|
||||
/**
|
||||
* 判据正则一律**不带 g 旗标**。
|
||||
@@ -108,6 +113,15 @@ const HOVER_LIFT_RE = /hover:-translate-y\b/;
|
||||
const DECOR_SHADOW_RE = /(?:hover:shadow(?:-[a-z0-9]+)?(?::\[[^\]]+\])?|\bshadow-(?:2xl|xl|lg)\b)/;
|
||||
const BRAND_SURFACE_RE = /\bbg-brand-(?:soft|section)\b/;
|
||||
const FONT_BLACK_RE = /\bfont-black\b/;
|
||||
const FONT_EXTRA_BOLD_RE = /\bfont-extrabold\b/;
|
||||
/**
|
||||
* 签名件(斜线纹 / 双 V / 斜杠)的**字面量**。锛的是实测原物的可辨认片段:
|
||||
* `tile_hatching` —— 对标那张 20×20 SVG 平铺图的名字;
|
||||
* `rotate(140` —— 那张图的 patternTransform(本仓正确的等价形是 CSS 变量,不写角度字面量);
|
||||
* `M22 14.204` / `M70.09 0` / `M15.2539` —— 三枚原物的路径首段。
|
||||
* 命中即意味着有人绕开了 ui/ 下的原语,把手抄的第二份纹样塞进了营销页。
|
||||
*/
|
||||
const SIGNATURE_LITERAL_RE = /tile_hatching|rotate\(\s*140|M22 14\.204|M70\.09 0|M15\.2539/;
|
||||
|
||||
/**
|
||||
* 数命中数。**必须每次新建 RegExp**:带 g 的正则是状态机,复用同一个实例时
|
||||
@@ -436,6 +450,26 @@ function checkGrammar(rawText, rawFiles, twConfig = "", opts = {}) {
|
||||
red: r17Count > ceilings.R17 ? [`营销面 font-black ${r17Count} 处 > 上限 ${ceilings.R17}(声明档走 text-statement + font-bold / font-normal 的字重分裂)`] : [],
|
||||
note: `实测 ${r17Count} 处 · 上限 ${ceilings.R17}${r17Count < ceilings.R17 ? " ⇒ 请把上限下调" : ""}` });
|
||||
|
||||
// R18 签名件只能有一个真源。斜线纹 / 双 V / 斜杠三件在 ui/ 下各有原语
|
||||
// (hatch-field / double-chevron / slash-mark),营销页只允许 import 它们。
|
||||
// 手抄一份路径或背景图 = 第二个真源,以后改几何就会一半新一半旧,而闸看不见 ——
|
||||
// 这正是本仓「两套 gutter 同时在线」那一类病的同型。上限登记 0,即硬禁。
|
||||
const r18Files = marketingFiles.filter(([, f]) => countHits(f, SIGNATURE_LITERAL_RE) > 0);
|
||||
const r18Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, SIGNATURE_LITERAL_RE), 0);
|
||||
rule({ id: "R18", name: "营销面零签名件字面量(只许走 ui/ 原语)", denominator: rScan,
|
||||
red: r18Count > ceilings.R18
|
||||
? [`营销面手抄纹样 ${r18Count} 处 > 上限 ${ceilings.R18}(${r18Files.map(([p]) => p).join(", ")})—— 斜线纹走 HatchField、双 V 走 DoubleChevron、斜杠走 SlashMark`]
|
||||
: [],
|
||||
note: `实测 ${r18Count} 处 / ${r18Files.length} 文件 · 上限 ${ceilings.R18}` });
|
||||
|
||||
// R19 字重集合的第二轴。800 不是对标的字重(实测只有 400/700),也不是本仓
|
||||
// 声明档的字重(那是 700 + 400 的**字重分裂**)。保留为棘轮而非硬禁,是因为
|
||||
// 21 处存量全在模板批的清单里,随 P4 逐页清;清完把上限降到 0 即变硬禁。
|
||||
const r19Count = marketingFiles.reduce((a, [, f]) => a + countHits(f, FONT_EXTRA_BOLD_RE), 0);
|
||||
rule({ id: "R19", name: "营销面零 font-extrabold(800)", denominator: rScan,
|
||||
red: r19Count > ceilings.R19 ? [`营销面 font-extrabold ${r19Count} 处 > 上限 ${ceilings.R19}(层级走字号 × 字重两轴:声明档 700/400 分裂,不用更粗的中间档)`] : [],
|
||||
note: `实测 ${r19Count} 处 · 上限 ${ceilings.R19}${r19Count < ceilings.R19 ? " ⇒ 请把上限下调" : ""}` });
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -506,37 +540,42 @@ function selftest() {
|
||||
* 夹具一律带 `opts.floor = 0`:合成样本只有一两个文件,
|
||||
* 不关掉地板就会把「扫描面太小」的红混进这一维,读数不再单义。
|
||||
*/
|
||||
const dirty = `<div className="rounded-full rounded-2xl hover:-translate-y-1 hover:shadow-lg shadow-xl bg-brand-soft bg-brand-section font-black" />`;
|
||||
const dirty = `<div className="rounded-full rounded-2xl hover:-translate-y-1 hover:shadow-lg shadow-xl bg-brand-soft bg-brand-section font-black font-extrabold" style={{ backgroundImage: 'url(tile_hatching.svg)', transform: 'rotate(140deg)' }}><path d="M22 14.204v-3.948" /></div>`;
|
||||
const inScope = (rel) => new Map([[rel, dirty]]);
|
||||
const hitRed = (rel, id, ceiling) =>
|
||||
checkGrammar(cssText, inScope(rel), "", { floor: 0, hitCeilings: { [id]: ceiling } })
|
||||
.find((x) => x.id === id).red.length;
|
||||
const scopeBad = ["R13", "R14", "R15", "R16", "R17"].filter(
|
||||
const scopeIds = ["R13", "R14", "R15", "R16", "R17", "R18", "R19"];
|
||||
const scopeBad = scopeIds.filter(
|
||||
(id) => hitRed("src/app/(marketing)/x.tsx", id, 0) === 0);
|
||||
const scopeOver = ["R13", "R14", "R15", "R16", "R17"].filter(
|
||||
const scopeOver = scopeIds.filter(
|
||||
(id) => hitRed("src/components/ui/x.tsx", id, 0) > 0);
|
||||
if (scopeBad.length || scopeOver.length) {
|
||||
console.log(` ✗ R13–R17 扫描面不自证:营销面漏抓 ${scopeBad.join(",") || "无"}、越界误报 ${scopeOver.join(",") || "无"} ⇒ 上面所有绿灯不作数`);
|
||||
console.log(` ✗ R13–R19 扫描面不自证:营销面漏抓 ${scopeBad.join(",") || "无"}、越界误报 ${scopeOver.join(",") || "无"} ⇒ 上面所有绿灯不作数`);
|
||||
return 1;
|
||||
}
|
||||
console.log(" ✓ R13–R17 双向:营销面已知违规全判红、ui/ 同名内容不误报(R2 的功能圆未被牵连)");
|
||||
console.log(" ✓ R13–R19 双向:营销面已知违规全判红、ui/ 同名内容不误报(R2 的功能圆与三件原语未被牵连)");
|
||||
|
||||
// 数量维:上限处不判红 / 上限+1 判红(同 R10 的构造法)。
|
||||
// 只关地板、**不覆盖上限** —— 第一版在这里塞了 hitCeilings:{[id]:9999},
|
||||
// 于是两个情景都恒不判红、棘轮自证永远失败。用登记上限本身才是测那条规则。
|
||||
const HIT_FIXTURE = {
|
||||
R13: "rounded-full", R14: "hover:-translate-y-1", R15: "shadow-lg",
|
||||
R16: "bg-brand-soft", R17: "font-black", R18: "tile_hatching", R19: "font-extrabold",
|
||||
};
|
||||
const ratchetBad = [];
|
||||
for (const [id, ceiling] of Object.entries(MARKETING_HIT_CEILINGS)) {
|
||||
const fixture = { R13: "rounded-full", R14: "hover:-translate-y-1", R15: "shadow-lg", R16: "bg-brand-soft", R17: "font-black" }[id];
|
||||
const fixture = HIT_FIXTURE[id];
|
||||
const at = (n) => checkGrammar(cssText, new Map([
|
||||
["src/app/(marketing)/n.tsx", `<div className="${`${fixture} `.repeat(n)}" />`],
|
||||
]), "", { floor: 0 }).find((x) => x.id === id).red.length;
|
||||
if (at(ceiling) !== 0 || at(ceiling + 1) === 0) ratchetBad.push(`${id}@${ceiling}/${ceiling + 1}`);
|
||||
}
|
||||
if (ratchetBad.length) {
|
||||
console.log(` ✗ R13–R17 棘轮不自证:${ratchetBad.join(" ")} 处「上限不判红/上限+1 判红」不成立 ⇒ 上面所有绿灯不作数`);
|
||||
console.log(` ✗ R13–R19 棘轮不自证:${ratchetBad.join(" ")} 处「上限不判红/上限+1 判红」不成立 ⇒ 上面所有绿灯不作数`);
|
||||
return 1;
|
||||
}
|
||||
console.log(` ✓ R13–R17 棘轮双向:按 ${Object.entries(MARKETING_HIT_CEILINGS).map(([k, v]) => `${k}=${v}`).join(" ")} 各自成立`);
|
||||
console.log(` ✓ R13–R19 棘轮双向:按 ${Object.entries(MARKETING_HIT_CEILINGS).map(([k, v]) => `${k}=${v}`).join(" ")} 各自成立`);
|
||||
|
||||
/**
|
||||
* R12 两侧自证:对账表必须**既能抓到漂移、又不在等值时误报**。
|
||||
@@ -590,7 +629,7 @@ function main() {
|
||||
}
|
||||
|
||||
const r = checkGrammar(text, files, twConfig, { jsSources });
|
||||
const unmeasurable = r.filter((x) => x.denominator === 0 && x.id !== "R7" && !/^R1[3-7]$/.test(x.id));
|
||||
const unmeasurable = r.filter((x) => x.denominator === 0 && x.id !== "R7" && !/^R1[3-9]$/.test(x.id));
|
||||
const red = r.filter((x) => x.red.length > 0);
|
||||
|
||||
console.log("视觉语法对账(Bain 2026-08-31 快照 + Porsche live 实测语法)");
|
||||
|
||||
@@ -353,6 +353,29 @@ body {
|
||||
--aspect-square: 1;
|
||||
--aspect-tile: 1.42;
|
||||
|
||||
/* === 斜线纹(hatch)几何(2026-11-02 对标实测 · 逐字换算)===
|
||||
对标原物是一个 SVG 平铺背景:`<pattern width="20" height="20"
|
||||
patternTransform="scale(1) rotate(140)">` + 一条 `M0 10h20z` 的 1px 横线,
|
||||
描边色 hsla(352,100%,42%),外层 `<rect width="800%" height="800%">`。
|
||||
这里换成一个**不依赖位图资产**的 CSS 等价形,两处换算必须逐字成立:
|
||||
① 角度:SVG 把**水平线**旋转 140°;CSS `repeating-linear-gradient(A,…)` 的线方向
|
||||
是 `A-180`,故 A=140 时线方向 -40° ≡ 140°(直线有 180° 对称)⇒ 角度取 140deg。
|
||||
② 间距:20×20 的方格点上、过点画 theta 角的平行线,垂距 = 20·|sin theta|
|
||||
(theta=90 时垂距 20 ✓)。theta=140° ⇒ 20 × 0.6428 = **12.86px**。
|
||||
照抄 20px 会让纹理稀掉一半 —— 这是「看起来差不多」与实际对不上的典型位。
|
||||
--hatch-color 走 --color-brand(双通道:此处是**面**,故用不随主题翻转的底色通道)。 */
|
||||
--hatch-tile: 20px;
|
||||
--hatch-angle: 140deg;
|
||||
--hatch-period: 12.86px;
|
||||
--hatch-stroke: 1px;
|
||||
--hatch-color: var(--color-brand);
|
||||
/* 浅底/小面积场景的软版:品牌红 45%。对 #FFFFFF 合成后 ≈ #E3A3AF,非文字元素按
|
||||
WCAG 1.4.11 只需 3:1,实测合成色对白底 2.04:1 —— 故「软版」**只允许**做纹理,
|
||||
不得承载任何可读信息,也不得单独充当分隔线(那是 graphic-object 语义,需要 3:1)。 */
|
||||
--hatch-color-soft: rgba(196, 30, 58, 0.45);
|
||||
/* 双 V 的偏移比例:实测向下双 V 垂直偏移 26/77、向右双 V 水平偏移 36/106,两档均 ≈0.34 */
|
||||
--chevron-offset-ratio: 0.34;
|
||||
|
||||
/* === 组件令牌层(Component Tokens)=== */
|
||||
/* 按钮 */
|
||||
--btn-height-sm: 2.25rem;
|
||||
@@ -1169,6 +1192,30 @@ html[data-theme='dark'] body {
|
||||
.row-span-1 { grid-row: span 1 / span 1; }
|
||||
.row-span-2 { grid-row: span 2 / span 2; }
|
||||
.row-span-3 { grid-row: span 3 / span 3; }
|
||||
|
||||
/* === 签名件:斜线纹(hatch)===
|
||||
2026-11-02 对标实测的 CSS 等价形。几何推导见 :root 里 --hatch-* 那段注释:
|
||||
角度 140deg(渐变角,线方向 −40° ≡ 140°)、垂距 12.86px(= 20 × sin140°)、描边 1px。
|
||||
|
||||
为什么做成 class 而不是组件内联 style:这份 background-image 表达式要同时被
|
||||
HatchField 与「接缝块」两种用法消费,写在组件里就会出现第二份字面量 ——
|
||||
而 R18 正是为了「纹样只能有一个真源」而存在。
|
||||
|
||||
面积纪律(DESIGN.md「朱砂信号」):每段 ≤ 1 处、单块 ≤ 640×520、绝不压正文。 */
|
||||
.hatch-field {
|
||||
background-image: repeating-linear-gradient(
|
||||
var(--hatch-angle),
|
||||
transparent 0 calc(var(--hatch-period) - var(--hatch-stroke)),
|
||||
var(--hatch-color) calc(var(--hatch-period) - var(--hatch-stroke)) var(--hatch-period)
|
||||
);
|
||||
}
|
||||
.hatch-field--soft {
|
||||
background-image: repeating-linear-gradient(
|
||||
var(--hatch-angle),
|
||||
transparent 0 calc(var(--hatch-period) - var(--hatch-stroke)),
|
||||
var(--hatch-color-soft) calc(var(--hatch-period) - var(--hatch-stroke)) var(--hatch-period)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 动画关键帧 ===== */
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* 空白带(Band Spacer)—— 把「呼吸」变成一个可数、可比对、可被闸看见的结构件。
|
||||
*
|
||||
* 实测出处:Porsche Consulting 中国站首页有**两条独立的 120px 空模块**
|
||||
* (`.o-module` 高度均为 120px、内部零内容、padding 为 0),分别在编辑块之后与
|
||||
* CTA 之后。也就是说它的段距不靠「每段自带 py-24」累加,而靠一条命名过的空白。
|
||||
*
|
||||
* 本仓的既有 20+ 段都自带 `py-16 md:py-24`(那是 Bootstrap 式节奏,改不动也不该改),
|
||||
* 所以这里**只新增**这条带子,不去把段内 padding 归零 —— 归零会让全站段距失去定义。
|
||||
* 这条偏差记在 ADR-0009 的「已知偏差」里。
|
||||
*
|
||||
* 高度走 `--spacer-band`(7.5rem = 根字号 16px 下的 120px),不写 `h-[120px]`:
|
||||
* 根字号随断点取 16/17/18,字面量在桌面会变成 120px 而其他间距已按 rem 放大。
|
||||
*/
|
||||
export function BandSpacer({ className }: { className?: string }) {
|
||||
return <div aria-hidden="true" className={`h-band bg-bg-primary ${className ?? ''}`} />;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* 字重分裂声明(Weight-Split Statement)。
|
||||
*
|
||||
* 来源是 2026-11-02 对 Porsche Consulting 中国站首页的实测:CTA 收束段的
|
||||
* `getComputedStyle` 读数 = 「准备好革新了吗?」`64px / font-weight 700`,
|
||||
* 紧接一行「大胆尝试吧!」`64px / font-weight 400` —— **同字号、同色,只换字重**。
|
||||
* 招聘带同理是 80px/700 配一行白字。
|
||||
*
|
||||
* 这与本仓此前的做法相反:模板里 55 处 `font-black`(900)一刀切,靠「更粗」建立层级。
|
||||
* 对标的层级来自 字号 × 字重 两个独立轴,粗体只占其中一格,所以一行大字可以既响又安静。
|
||||
*
|
||||
* 标题层级由调用方给:这一族**不能**为了字形把 h2 写成 div —— `check:headings` 管的就是这个。
|
||||
*/
|
||||
type Tone = 'light' | 'dark' | 'inherit';
|
||||
|
||||
const TONE_CLASS: Record<Tone, string> = {
|
||||
/** 浅色底(paper / mist)—— 实测 #0A0E14 对 #FFF 19.1:1、对 #F8FAFC 18.3:1 */
|
||||
light: 'text-text-primary',
|
||||
/** 深色底或照片上的白字 */
|
||||
dark: 'text-white',
|
||||
inherit: '',
|
||||
};
|
||||
|
||||
export function DisplayStatement({
|
||||
strong,
|
||||
light,
|
||||
as: Tag = 'h2',
|
||||
size = 'statement',
|
||||
tone = 'light',
|
||||
className,
|
||||
}: {
|
||||
/** 第一行:粗(700) */
|
||||
strong: string;
|
||||
/** 第二行:同字号、常规字重(400)。省略时只渲染粗行 */
|
||||
light?: string;
|
||||
as?: 'h1' | 'h2' | 'h3' | 'p';
|
||||
/** statement = 桌面 ≈81px(对标 80px);statement-lg 走 --font-size-7xl(桌面 108px),仅收束段用 */
|
||||
size?: 'statement' | 'statement-lg';
|
||||
tone?: Tone;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<Tag
|
||||
className={cn(
|
||||
size === 'statement' ? 'text-statement' : 'text-7xl',
|
||||
'leading-[1.05] tracking-tighter',
|
||||
TONE_CLASS[tone],
|
||||
className,
|
||||
)}
|
||||
>
|
||||
<span className="block font-bold">{strong}</span>
|
||||
{light && <span className="block font-normal">{light}</span>}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { DoubleChevron } from './double-chevron';
|
||||
|
||||
/**
|
||||
* 双 V 的判据锁「两枚、同形、按实测比例错位」这一件事。
|
||||
* 为什么值得单测:它是一个纯几何件,肉眼审查最容易漏掉的就是「第二枚的偏移比例」
|
||||
* —— 而那正是让它看起来像保时捷、而不是像两个随机箭头的唯一原因。
|
||||
*/
|
||||
const downOf = (c: HTMLElement) => (c.querySelectorAll('path')[1] as SVGPathElement).getAttribute('d');
|
||||
|
||||
describe('DoubleChevron', () => {
|
||||
it('永远是两枚同形,第二枚靠 transform 偏移(不是另一条路径)', () => {
|
||||
const { container } = render(<DoubleChevron direction="down" />);
|
||||
const paths = [...container.querySelectorAll('path')];
|
||||
expect(paths).toHaveLength(2);
|
||||
const [first, second] = paths as [SVGPathElement, SVGPathElement];
|
||||
expect(first.getAttribute('d')).toBe(second.getAttribute('d'));
|
||||
expect(first.getAttribute('transform')).toBeNull();
|
||||
expect(second.getAttribute('transform')).toMatch(/^translate\(/);
|
||||
});
|
||||
|
||||
it('down 档:第二枚向下偏 0.34 个图元高(实测 26/77)', () => {
|
||||
const { container } = render(<DoubleChevron direction="down" />);
|
||||
const t = (container.querySelectorAll('path')[1] as SVGPathElement).getAttribute('transform') ?? '';
|
||||
const dy = Number(/translate\(0 ([\d.]+)\)/.exec(t)?.[1]);
|
||||
expect(dy).toBeCloseTo(22 * 0.34, 3);
|
||||
});
|
||||
|
||||
it('right 档:第二枚向右偏 0.34 个图元宽(实测 36/106)', () => {
|
||||
const { container } = render(<DoubleChevron direction="right" />);
|
||||
const t = (container.querySelectorAll('path')[1] as SVGPathElement).getAttribute('transform') ?? '';
|
||||
const dx = Number(/translate\(([\d.]+) 0\)/.exec(t)?.[1]);
|
||||
expect(dx).toBeCloseTo(112 * 0.34, 3);
|
||||
});
|
||||
|
||||
it('两档用的是**不同的**原物路径(不是同一枚旋转)', () => {
|
||||
const down = downOf(render(<DoubleChevron direction="down" />).container as HTMLElement);
|
||||
const right = downOf(render(<DoubleChevron direction="right" />).container as HTMLElement);
|
||||
expect(down).not.toBe(right);
|
||||
// 锚在实测原物的路径首段上,防止有人「顺手重画」
|
||||
expect(down?.startsWith('M22 14.204')).toBe(true);
|
||||
expect(right?.startsWith('M70.09 0')).toBe(true);
|
||||
});
|
||||
|
||||
it('尺寸档取实测包围盒(两份合起来),且非等比拉伸是刻意的', () => {
|
||||
const sm = render(<DoubleChevron direction="down" size="sm" />).container.querySelector('svg')!;
|
||||
expect(sm.getAttribute('width')).toBe('98');
|
||||
expect(sm.getAttribute('height')).toBe('103');
|
||||
expect(sm.getAttribute('preserveAspectRatio')).toBe('none');
|
||||
|
||||
const lg = render(<DoubleChevron direction="right" size="lg" />).container.querySelector('svg')!;
|
||||
expect(lg.getAttribute('width')).toBe('257');
|
||||
expect(lg.getAttribute('height')).toBe('264');
|
||||
});
|
||||
|
||||
it('装饰件:aria-hidden + focusable=false,颜色走 currentColor 不写死色值', () => {
|
||||
const { container } = render(<DoubleChevron direction="right" />);
|
||||
const svg = container.querySelector('svg')!;
|
||||
expect(svg).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(svg).toHaveAttribute('focusable', 'false');
|
||||
expect(svg).toHaveClass('text-brand');
|
||||
for (const p of container.querySelectorAll('path')) {
|
||||
expect(p.getAttribute('fill')).toBe('currentColor');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* 双 V 形(Double Chevron)—— 对标的第二个识别件。**两枚不同的形,不是一枚旋转**。
|
||||
*
|
||||
* 实测(2026-11-02,Porsche Consulting 中国站首页,放大到像素级确认):
|
||||
* - `direction="down"`(黑底编辑舞台右下、拼贴图角):`icon_chevron_down_scroller.svg`,
|
||||
* viewBox `23.938×22`,路径 `M22 14.204v-3.948l-11.004 5.953L0 10.256v3.948l10.996 6.358L22 14.204z`;
|
||||
* 同尺寸的两份 `<img>`,第二份**垂直偏移 26px**(渲染高 77 时 ≈ 0.34 高)。
|
||||
* - `direction="right"`(收束段、联系方式):`icon_chevron_right_footer.svg`,
|
||||
* viewBox `112×145`,路径 `M70.09 0 L44.0684 0 L83.2991 72.5258 L44.0684 145 H70.09 L112 72.5258 Z`;
|
||||
* 两份,第二份**水平偏移 36px**(渲染宽 106 时 ≈ 0.34 宽)。
|
||||
*
|
||||
* 渲染尺寸取自实测框(down `98×77 / 178×139`、right `106×145` 每份)。
|
||||
* 原站是用 `<img>` 指定宽高的,因此**本身就是非等比拉伸**的 —— 这里用
|
||||
* `preserveAspectRatio="none"` 忠实还原那个观感,而不是"顺手修正"成等比。
|
||||
*
|
||||
* 静止,不做动画:对标原物挂了 `pulseVertical/pulseHorizontal 6s infinite` 的引导脉冲,
|
||||
* 但 CONTEXT.md:81 明令禁止循环装饰动画,且双 V 本身已经是「还有下文」的信号。
|
||||
* 这条裁定记在 ADR-0009;要开动画必须单独裁定并同时改 CONTEXT.md。
|
||||
*/
|
||||
|
||||
const CHEVRON_PATH = {
|
||||
down: 'M22 14.204v-3.948l-11.004 5.953L0 10.256v3.948l10.996 6.358L22 14.204z',
|
||||
right: 'M70.09 0L44.0684 0L83.2991 72.5258L44.0684 145H70.09L112 72.5258L70.09 0Z',
|
||||
} as const;
|
||||
|
||||
/** 单枚形的 viewBox 尺寸(取自 SVG 原文,不是估的) */
|
||||
const ART = {
|
||||
down: { w: 23.938, h: 22 },
|
||||
right: { w: 112, h: 145 },
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 每档的渲染尺寸 = **两份合起来的包围盒**。
|
||||
* down 档的第二份往下偏,故高 = 单份高 × 1.34;right 档第二份往右偏,故宽 = 单份宽 × 1.34。
|
||||
* lg 的 right 档实测未取样,按 sm 与 down 两档的共同放大比 1.816 推导(ADR-0009 记明是推导值)。
|
||||
*/
|
||||
const SIZE = {
|
||||
down: { sm: { w: 98, h: 103 }, lg: { w: 178, h: 186 } },
|
||||
right: { sm: { w: 142, h: 145 }, lg: { w: 257, h: 264 } },
|
||||
} as const;
|
||||
|
||||
/** 0.34 是实测偏移比(26/77、36/106),与 tailwind/globals 的 --chevron-offset-ratio 同源 */
|
||||
const OFFSET_RATIO = 0.34;
|
||||
|
||||
export function DoubleChevron({
|
||||
direction,
|
||||
size = 'lg',
|
||||
className,
|
||||
}: {
|
||||
direction: 'down' | 'right';
|
||||
size?: 'sm' | 'lg';
|
||||
className?: string;
|
||||
}) {
|
||||
const art = ART[direction];
|
||||
const box = SIZE[direction][size];
|
||||
// viewBox 用「图元单位」表达包围盒,跟渲染框一起被 preserveAspectRatio="none" 拉伸,
|
||||
// 这样两份之间的相对偏移在任何档位都恒为 OFFSET_RATIO —— 不会因换档而错位。
|
||||
const vbW = direction === 'down' ? art.w : art.w * (1 + OFFSET_RATIO);
|
||||
const vbH = direction === 'down' ? art.h * (1 + OFFSET_RATIO) : art.h;
|
||||
const shift = direction === 'down'
|
||||
? `translate(0 ${art.h * OFFSET_RATIO})`
|
||||
: `translate(${art.w * OFFSET_RATIO} 0)`;
|
||||
|
||||
return (
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox={`0 0 ${vbW} ${vbH}`}
|
||||
width={box.w}
|
||||
height={box.h}
|
||||
preserveAspectRatio="none"
|
||||
className={cn('block shrink-0 text-brand', className)}
|
||||
>
|
||||
<path d={CHEVRON_PATH[direction]} fill="currentColor" />
|
||||
<path d={CHEVRON_PATH[direction]} fill="currentColor" transform={shift} />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { HatchField } from './hatch-field';
|
||||
|
||||
/**
|
||||
* 斜线纹的判据只锁三件事 —— 多一件都会把实现锁死,少一件就会让「第二份字面量」溜过去:
|
||||
* ① 一律 aria-hidden(它不承载信息,读屏不该知道它存在);
|
||||
* ② 颜色/几何只走 class(`.hatch-field`),**不得**出现内联 background-image:
|
||||
* 内联等于第二份纹样真源,而 R18 正是为了「纹样只有一个真源」存在的;
|
||||
* ③ tone 两档映射到两个不同 class,且都有对应的 CSS 声明(否则是静默失效的类)。
|
||||
*/
|
||||
describe('HatchField', () => {
|
||||
it('一律 aria-hidden,且不接任何交互', () => {
|
||||
const { container } = render(<HatchField />);
|
||||
const el = container.firstElementChild as HTMLElement;
|
||||
expect(el).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(el.className).toContain('pointer-events-none');
|
||||
});
|
||||
|
||||
it('几何只走 class,绝不内联 background-image(防第二份纹样真源)', () => {
|
||||
const { container } = render(<HatchField />);
|
||||
const el = container.firstElementChild as HTMLElement;
|
||||
expect(el.className).toContain('hatch-field');
|
||||
expect(el.getAttribute('style')).toBeNull();
|
||||
});
|
||||
|
||||
it('tone 两档落在两个不同的 class 上', () => {
|
||||
const brand = render(<HatchField />).container.firstElementChild as HTMLElement;
|
||||
const soft = render(<HatchField tone="soft" />).container.firstElementChild as HTMLElement;
|
||||
expect(brand.className).toMatch(/\bhatch-field\b/);
|
||||
expect(soft.className).toMatch(/\bhatch-field--soft\b/);
|
||||
expect(brand.className).not.toContain('hatch-field--soft');
|
||||
});
|
||||
|
||||
it('外部 className 原样并入(用于控制单块面积与错位)', () => {
|
||||
const { container } = render(<HatchField className="h-40 w-40" />);
|
||||
expect((container.firstElementChild as HTMLElement).className).toContain('h-40 w-40');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* 斜线纹(Hatch)—— 对标最容易被一眼记住的那件几何。
|
||||
*
|
||||
* 来源是 2026-11-02 对 Porsche Consulting 中国站首页的实测:背景图
|
||||
* `/themes/custom/porsche_consulting/img/background/tile_hatching.svg` 是一个
|
||||
* `<pattern width="20" height="20" patternTransform="scale(1) rotate(140)">`,
|
||||
* 内含一条 `M0 10h20z` 的 1px 横线,描边 `hsla(352,100%,42%)`,外层
|
||||
* `<rect width="800%" height="800%">`。首页出现 3 次:
|
||||
* 编辑舞台图后 642×514、行业块 571×625、收束段 579×409。
|
||||
*
|
||||
* 实现走 globals.css 的 `.hatch-field` / `.hatch-field--soft`(CSS 等价形),
|
||||
* 而不是内联 style:纹样只能有一个真源,第二份字面量会被 `check:grammar` 的 R18 判红。
|
||||
*
|
||||
* 边界(DESIGN.md「朱砂信号」+ ADR-0009):
|
||||
* - 只允许两种用法 —— ①黑底/ink 底上作纹理;②白↔黑**接缝**处的桥接块。
|
||||
* - 每段最多 1 处、单块 ≤ 640×520、**绝不压正文**。
|
||||
* - 一律 `aria-hidden`:它不承载任何信息,读屏不该知道它存在。
|
||||
*/
|
||||
export function HatchField({
|
||||
tone = 'brand',
|
||||
className,
|
||||
}: {
|
||||
/**
|
||||
* brand = 实底品牌红(黑底 / 接缝块);
|
||||
* soft = 45% 品牌红(浅底小面积)。软版对白底合成后仅 2.04:1,
|
||||
* **只允许**做纹理,不得承载信息、不得单独当分隔线(WCAG 1.4.11 需 3:1)。
|
||||
*/
|
||||
tone?: 'brand' | 'soft';
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'pointer-events-none',
|
||||
tone === 'soft' ? 'hatch-field--soft' : 'hatch-field',
|
||||
className,
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
'use client';
|
||||
|
||||
import Image from 'next/image';
|
||||
import { useRef } from 'react';
|
||||
import { motion, useInView, useReducedMotion, useScroll, useTransform } from 'framer-motion';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { IMAGE_RATIOS, aspectStyle, type ImageRatio } from '@/lib/constants/image-ratios';
|
||||
|
||||
/**
|
||||
* 影像层(对标实测的「图主导」那一柱)。
|
||||
*
|
||||
* 出处与边界:
|
||||
* - ADR-0004 决策三把 Ken Burns 列为「✅ 启用 · 极弱(scale 1.0→1.1,10–15s)」,
|
||||
* 是本仓唯一从未落地过的既定动效项(2026-11-02 核查:`grep -riE "ken.?burns|parallax"` 零命中)。
|
||||
* - CONTEXT.md:81 同时禁止**循环装饰动画**。两者不冲突的解法是「一次性」:
|
||||
* 进入视口播一遍、停在做位上(终值由 animate 承担),不 repeat、不 alternate。
|
||||
* **不要为了绕过 `check:motion` R2 而加 `infinite`** —— R2 的 infinite 豁免是留给
|
||||
* 环境动效的,拿它给装饰循环开后门就是假绿。
|
||||
* - 时长走 JS 数值而非 CSS 声明:与全站 stagger/duration 的既有口径一致
|
||||
* (DESIGN.md:framer-motion 读不到 CSS 自定义属性,令牌化只会造出零消费者的死值)。
|
||||
*
|
||||
* 首帧纪律(2026-10-20 生产白屏那轮的教训):SSR 与客户端首帧必须一致。
|
||||
* 所以 `initial` 恒为 scale 1 / y 0,动效只在挂载后由 inView 触发;
|
||||
* 减少动效时直接返回静态图,不出现「先动一下再停」。
|
||||
*/
|
||||
|
||||
/** 缓慢生长的幅度:6% 比 ADR 上限 10% 更保守,窄屏上不致把主体挤出画面 */
|
||||
const KEN_BURNS_SCALE = 1.06;
|
||||
/** 一次播完的时长(秒),落在 ADR-0004 决策三的 10–15s 区间中位 */
|
||||
const KEN_BURNS_DURATION = 12;
|
||||
/** 视差偏移(占容器高度比例),ADR-0004 决策三给的是 5–15% 弱档区间 */
|
||||
const PARALLAX_SHIFT = 0.08;
|
||||
/** 缓动与全站统一(--ease-ink),framer 读不到 CSS 变量,故按令牌值内联并在此记源 */
|
||||
const EASE_INK = [0.22, 1, 0.36, 1] as const;
|
||||
|
||||
export function ImageModule({
|
||||
src,
|
||||
alt,
|
||||
ratio,
|
||||
sizes,
|
||||
priority = false,
|
||||
kenBurns = false,
|
||||
parallax = false,
|
||||
overlay,
|
||||
className,
|
||||
imgClassName,
|
||||
children,
|
||||
}: {
|
||||
src: string;
|
||||
/** 一律传空串 —— 这类图是氛围构图、不承担任何事实主张,DESIGN.md 要求 aria-hidden */
|
||||
alt: string;
|
||||
/** 比例只从 IMAGE_RATIOS 取,页面不得自定字面量(R12 机器对账两侧真源) */
|
||||
ratio: ImageRatio;
|
||||
sizes: string;
|
||||
priority?: boolean;
|
||||
kenBurns?: boolean;
|
||||
parallax?: boolean;
|
||||
/** 压暗层(保证压在图上的文字达对比度);不传则不加 */
|
||||
overlay?: React.ReactNode;
|
||||
className?: string;
|
||||
imgClassName?: string;
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const reduce = useReducedMotion() ?? false;
|
||||
const inView = useInView(ref, { once: true, amount: 0.35 });
|
||||
const { scrollYProgress } = useScroll({ target: ref, offset: ['start end', 'end start'] });
|
||||
const y = useTransform(scrollYProgress, [0, 1], [`${PARALLAX_SHIFT * 100}%`, `${-PARALLAX_SHIFT * 100}%`]);
|
||||
|
||||
const doKen = kenBurns && !reduce;
|
||||
const doParallax = parallax && !reduce;
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn('relative isolate overflow-hidden', className)}
|
||||
style={aspectStyle(IMAGE_RATIOS[ratio])}
|
||||
>
|
||||
<motion.div
|
||||
className="absolute inset-0"
|
||||
style={doParallax ? { y } : undefined}
|
||||
initial={false}
|
||||
animate={{ scale: doKen && inView ? KEN_BURNS_SCALE : 1 }}
|
||||
transition={doKen ? { duration: KEN_BURNS_DURATION, ease: EASE_INK } : { duration: 0 }}
|
||||
>
|
||||
<Image
|
||||
src={src}
|
||||
alt={alt}
|
||||
aria-hidden={alt === '' ? true : undefined}
|
||||
fill
|
||||
priority={priority}
|
||||
loading={priority ? undefined : 'lazy'}
|
||||
sizes={sizes}
|
||||
className={cn('object-cover', imgClassName)}
|
||||
/>
|
||||
</motion.div>
|
||||
{overlay}
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import '@testing-library/jest-dom';
|
||||
import { SlashMark, SlashDivider } from './slash-mark';
|
||||
import { BandSpacer } from './band-spacer';
|
||||
|
||||
describe('SlashMark', () => {
|
||||
it('锚在实测原物的路径上(img_divider.svg,18×17)', () => {
|
||||
const { container } = render(<SlashMark />);
|
||||
const svg = container.querySelector('svg')!;
|
||||
expect(svg.getAttribute('viewBox')).toBe('0 0 18 17');
|
||||
expect(svg.querySelector('path')!.getAttribute('d')).toBe('M15.2539 0H18L2.75775 17H0L15.2539 0Z');
|
||||
});
|
||||
|
||||
it('颜色走 currentColor,组件不写死色值', () => {
|
||||
const { container } = render(<SlashMark className="text-brand" />);
|
||||
expect(container.querySelector('path')!.getAttribute('fill')).toBe('currentColor');
|
||||
});
|
||||
|
||||
it('三档都保持 18:17 的比例(不靠四舍五入把斜杠压扁)', () => {
|
||||
for (const size of ['sm', 'md', 'lg'] as const) {
|
||||
const svg = render(<SlashMark size={size} />).container.querySelector('svg')!;
|
||||
const w = Number(svg.getAttribute('width'));
|
||||
const h = Number(svg.getAttribute('height'));
|
||||
expect(Math.abs(w / h - 18 / 17)).toBeLessThan(0.06);
|
||||
}
|
||||
});
|
||||
|
||||
it('装饰件一律 aria-hidden', () => {
|
||||
const { container } = render(<SlashMark />);
|
||||
expect(container.querySelector('svg')).toHaveAttribute('aria-hidden', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SlashDivider', () => {
|
||||
it('是纯装饰的容器,读屏只该听到「1 / 4」这样的文本本身', () => {
|
||||
const { container } = render(<SlashDivider />);
|
||||
expect(container.firstElementChild).toHaveAttribute('aria-hidden', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('BandSpacer', () => {
|
||||
it('高度走 --spacer-band 的 h-band,而不是 h-[120px] 字面量', () => {
|
||||
const { container } = render(<BandSpacer />);
|
||||
const el = container.firstElementChild as HTMLElement;
|
||||
expect(el.className).toContain('h-band');
|
||||
expect(el.className).not.toMatch(/h-\[\d+px\]/);
|
||||
});
|
||||
|
||||
it('纯空白:aria-hidden,不携带任何文本', () => {
|
||||
const { container } = render(<BandSpacer />);
|
||||
const el = container.firstElementChild as HTMLElement;
|
||||
expect(el).toHaveAttribute('aria-hidden', 'true');
|
||||
expect(el.textContent).toBe('');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 斜杠符(Slash)—— 对标里最小的那件几何,出现在 `01 / 04` 的计数器与 `›` 前导符上。
|
||||
*
|
||||
* 实测原物 `content/img_divider.svg`:viewBox `18×17`,
|
||||
* 路径 `M15.2539 0H18L2.75775 17H0L15.2539 0Z`,fill `#D5001C`
|
||||
* (渲染 24×24,混在 32/700 的 `01 / 04` 里)。这里颜色走 `currentColor`,
|
||||
* 由调用方决定是品牌红还是中性色 —— 组件不写死色值。
|
||||
*
|
||||
* 纯装饰:一律 `aria-hidden`,读屏只会听到「1 / 4」这样的文本,不会听到图形。
|
||||
*/
|
||||
|
||||
const SLASH_PATH = 'M15.2539 0H18L2.75775 17H0L15.2539 0Z';
|
||||
|
||||
export function SlashMark({
|
||||
className,
|
||||
size = 'md',
|
||||
}: {
|
||||
className?: string;
|
||||
/** sm = 12×11(行内前导符)· md = 18×17(原尺寸)· lg = 24×23(计数器) */
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
}) {
|
||||
const px = { sm: 12, md: 18, lg: 24 }[size];
|
||||
const py = Math.round((px * 17) / 18);
|
||||
return (
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
focusable="false"
|
||||
viewBox="0 0 18 17"
|
||||
width={px}
|
||||
height={py}
|
||||
className={className}
|
||||
>
|
||||
<path d={SLASH_PATH} fill="currentColor" />
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计数器用的斜杠:与数字同高、垂直居中,避免行内对齐把 `01 / 04` 顶歪。
|
||||
* 单独导出而不是让调用方自己 `flex items-center`,是因为这段对齐在三处复用
|
||||
* (首页舞台、hub 页签、详情页序号),散落写必然出现三种基线。
|
||||
*/
|
||||
export function SlashDivider({ className }: { className?: string }) {
|
||||
return (
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`inline-flex h-[1.1em] w-[0.6em] items-center justify-center ${className ?? ''}`}
|
||||
>
|
||||
<SlashMark size="lg" className="h-[0.7em] w-auto text-brand" />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import type { CSSProperties } from 'react';
|
||||
|
||||
/**
|
||||
* 影像比例真源。
|
||||
*
|
||||
* 数值来自 2026-11-02 对 Porsche Consulting 中国站首页逐个 `<img>` 的
|
||||
* `getBoundingClientRect` 实测(1600×900 视口),四种比例各绑一个构图角色。
|
||||
* 与 globals.css `--aspect-*` 那四条必须逐字相等 —— `check:grammar` R12 做两侧对账,
|
||||
* 任一侧漂移即判红(本仓真实踩过「两套 gutter 同时在线」的散字面量病)。
|
||||
*/
|
||||
export const IMAGE_RATIOS = {
|
||||
/** 全幅首屏:1600×692 */
|
||||
HERO_WIDE: 2.31,
|
||||
/** 编辑卡(洞察/新闻):606×404 */
|
||||
EDITORIAL: 1.5,
|
||||
/** 横向方图轨的每一格:499/464 见方 */
|
||||
SQUARE: 1,
|
||||
/** 行业格:653×459 */
|
||||
TILE: 1.42,
|
||||
} as const;
|
||||
|
||||
export type ImageRatio = keyof typeof IMAGE_RATIOS;
|
||||
|
||||
/**
|
||||
* 用在 `style` 上而非 `aspect-[…]` 工具类:Tailwind 只扫描源码里**字面出现**的类名,
|
||||
* 由变量拼出的 `aspect-[${x}]` 不会生成,会得到一个静默失效的类。
|
||||
*/
|
||||
export function aspectStyle(ratio: number): CSSProperties {
|
||||
return { aspectRatio: String(ratio) };
|
||||
}
|
||||
|
||||
/** 定高、按比例反算宽度(横向轨的每一格用这条,让见方格随视口收放)。 */
|
||||
export function aspectWidthStyle(ratio: number, heightVar: string): CSSProperties {
|
||||
return { height: heightVar, width: `calc(${heightVar} * ${ratio})` };
|
||||
}
|
||||
Reference in new issue
Block a user