角色 · 实验演示
机体合体演示
三块几何体合而为一的合体动画(无动漫形象)。
适用场景
合体动画演示、拼装主题。
三块几何部件滑入就位,卡扣点亮后合为一体,标识浮现。
任务提示词
已带入当前预览参数。可交给支持代码生成的工具,生成后在目标项目中检查效果。
请制作一个可复用的「机体合体演示」网页动效。
用途:三块几何体合而为一的合体动画(无动漫形象)。适用于合体动画演示、拼装主题。
运行环境:React 19 + TypeScript + CSS,现代浏览器;只使用 React 与浏览器 API,不依赖动效引擎,不连接 AI、音乐或渲染服务。
输入与当前参数:
主色:#c23a3a
速度:1 倍(1 倍为基准,2 倍用时减半)
时长:本效果基准总时长 3.9 秒,当前速度下约 3.9 秒;两者都指从起点播放到终态的完整过程。
步骤/条目(按此顺序):1. 一号机;2. 二号机;3. 三号机
动作顺序(时间为 1 倍速度基准秒数,按当前速度等比换算):
1. 第1幕(0.0–1.5 秒):多层面板掠过(一号机、二号机、三号机)
2. 第2幕(0.0–3.9 秒):底色铺满并保持
3. 第3幕(1.4–3.0 秒):容器变形:square→capsule→card
4. 第4幕(3.0–3.9 秒):几何色块过冲放大登场
5. 总时长约 3.9 秒(1 倍速度),结束停在清晰终态。
可调整参数:将上述输入暴露为组件属性;内容、颜色和速度改变后立即更新,保留暂停状态。
输出要求:交付完整的 TypeScript 客户端组件、所需样式与调用示例,自带原创图形素材;不要用静态封面替代动画。提供播放、暂停、重播,演示只在自己的容器内绘制。
检查要点:正常播放到清晰终态;暂停后画面保持,继续播放接上原进度;重播从头开始;参数值与画面一致;中文在手机宽度下不溢出;键盘可操作;离开视口或后台标签页停止动画帧;prefers-reduced-motion 时显示静态终态;避免强闪烁。
参考来源与观察范围:Anime robot combining sequence(https://prompt-motion.com/allforbigfire-86ff3c)。观察自参考案例公开详情页:原始标题、分类标签与创作者公开的动作提示词文本;未观看原视频。 Luca 改编:仅标题级观察(动漫合体需求);动漫形象不使用,改编为几何部件合体原创演示。本站演示、文案、图形与提示词均为原创,未使用参考视频、音频、品牌图形或完整原提示词。
本例边界:
这是实现任务说明,生成结果仍需在目标项目运行和检查,不保证不同模型一次生成就能完全复现。实现与复用
React 客户端组件:CaseDemo 按案例的阶段序列逐层渲染 DOM/SVG,全部阶段渲染器为本站原创实现;播放、暂停、重播、离屏暂停与减少动态效果偏好由共享时间轴管理。
运行环境:React 19、TypeScript 和现代浏览器。依赖只有 React 与浏览器 API,无需安装动效库。
把下面两个文件与「完整可复用源码」里的引擎文件放在同一目录即可运行:案例配置是这份动效的完整数据(阶段序列、参数、文案),引擎负责播放。
import type { CaseSpec } from './case-engine';
/** 机体合体演示:三块几何体合而为一的合体动画(无动漫形象)。(Luca 原创编排,参考改编自 https://prompt-motion.com/allforbigfire-86ff3c) */
export const spec: CaseSpec = {
"slug": "allforbigfire-86ff3c",
"name": "机体合体演示",
"purpose": "三块几何体合而为一的合体动画(无动漫形象)。",
"description": "三块几何部件滑入就位,卡扣点亮后合为一体,标识浮现。",
"scenes": "合体动画演示、拼装主题。",
"category": "角色",
"refTags": [
"Characters"
],
"family": "stage-compose",
"stages": [
{
"kind": "depth-layers",
"at": 0,
"dur": 1.5,
"lines": 3,
"bg": "ink"
},
{
"kind": "backdrop",
"at": 0,
"dur": 3.9,
"bg": "ink",
"fill": true
},
{
"kind": "morph-shape",
"at": 1.45,
"dur": 1.6,
"shapes": [
"square",
"capsule",
"card"
],
"labels": [
"一号机",
"二号机",
"合体完成"
],
"bg": "ink"
},
{
"kind": "brand-pop",
"at": 3,
"dur": 0.9,
"mark": 14,
"bg": "ink"
}
],
"duration": 3.9,
"fields": [
"steps"
],
"maxText": 12,
"defaults": {
"text": "合体!",
"color": "#c23a3a",
"speed": 1,
"from": 0,
"to": 100,
"steps": [
"一号机",
"二号机",
"三号机"
]
},
"sequence": [
"第1幕(0.0–1.5 秒):多层面板沿纵深掠过",
"第2幕(0.0–3.9 秒):底色铺满并保持",
"第3幕(1.4–3.0 秒):同一容器按形状序列连续变形(square→capsule→card)",
"第4幕(3.0–3.9 秒):几何色块过冲放大登场(mark=luca 时为 L↗ 标识)",
"总时长约 3.9 秒(1 倍速度),结束停在清晰终态。"
],
"implementation": "React 客户端组件:CaseDemo 按案例的阶段序列逐层渲染 DOM/SVG,全部阶段渲染器为本站原创实现;播放、暂停、重播、离屏暂停与减少动态效果偏好由共享时间轴管理。",
"limitations": [],
"reference": {
"title": "Anime robot combining sequence",
"url": "https://prompt-motion.com/allforbigfire-86ff3c",
"author": "風の民@",
"handle": "https://x.com/allforbigfire",
"principle": "仅标题级观察(动漫合体需求);动漫形象不使用,改编为几何部件合体原创演示。"
},
"observation": {
"level": "detail-page-observed",
"scope": "观察自参考案例公开详情页:原始标题、分类标签与创作者公开的动作提示词文本;未观看原视频。 Luca 改编:仅标题级观察(动漫合体需求);动漫形象不使用,改编为几何部件合体原创演示。"
},
"status": "实验演示"
};
'use client';
import { useCallback, useState } from 'react';
import { CaseDemo } from './case-engine';
import { spec } from './luca-case-spec';
import { effectiveOptions } from './case-engine';
import { normalizeOptions } from './motion-core';
export default function Example() {
const [playing, setPlaying] = useState(false);
const [run, setRun] = useState(0);
const complete = useCallback(() => setPlaying(false), []);
// 案例层数字有效域统一生效(含 chart-donut 的 0–100 百分比)。
const options = effectiveOptions(spec.stages, normalizeOptions({
"text": "合体!",
"color": "#c23a3a",
"speed": 1,
"from": 0,
"to": 100,
"steps": [
"一号机",
"二号机",
"三号机"
]
}, spec.defaults, spec.maxText), spec.defaults);
return (
<div>
<CaseDemo
spec={spec}
options={options}
playing={playing}
replayKey={run}
onComplete={complete}
/>
<button onClick={() => setPlaying((value) => !value)}>
{playing ? "暂停" : "播放"}
</button>
<button onClick={() => { setRun((value) => value + 1); setPlaying(true); }}>
重播
</button>
</div>
);
}
查看完整可复用源码 · 11 个文件
'use client';
import {
useEffect,
useMemo,
useRef,
useState,
type ReactNode,
} from 'react';
import { clamp, contrastInk, type MotionOptions } from './motion-core';
import {
effectiveOptions,
hashSeed,
mulberry32,
requiredAssetUrls,
sortStages,
stageLocal,
type CaseSpec,
type StageSpec,
} from './case-timeline';
import { useMotionClock } from './motion-clock';
import { TYPE_STAGES } from './stages-type';
import { SHAPE_STAGES } from './stages-shape';
import { UI_STAGES } from './stages-ui';
import { SCENE_STAGES } from './stages-scene';
import { EDITORIAL_STAGES, EDITORIAL_INTERACTIVE } from './stages-editorial';
import './case-engine.css';
export type StageRenderer = (
stage: StageSpec,
t: number,
ctx: StageRenderCtx,
) => ReactNode;
export type StageRenderCtx = {
options: MotionOptions;
rand: () => number;
now: number;
palette: StagePalette;
/** 末幕为字幕条时为真:内容渲染器须在字幕安全区上方避让。 */
captionSafe: boolean;
/** 已就绪可显示的外部资产 URL(collage 插画等);未就绪图层自绘占位。 */
assets: ReadonlySet<string>;
};
export type StagePalette = {
bg: string;
fg: string;
accent: string;
paper: string;
ink: string;
};
/** 全部阶段渲染器:四个族文件各注册一批,kind 缺失在测试与渲染时都会暴露。 */
export const STAGE_RENDERERS: Record<string, StageRenderer> = {
...TYPE_STAGES,
...SHAPE_STAGES,
...UI_STAGES,
...SCENE_STAGES,
...EDITORIAL_STAGES,
};
export const STAGE_KINDS = Object.keys(STAGE_RENDERERS);
export const sstr = (s: StageSpec, k: string, d = ''): string =>
typeof s[k] === 'string' ? (s[k] as string) : d;
export const snum = (s: StageSpec, k: string, d = 0): number =>
typeof s[k] === 'number' ? (s[k] as number) : d;
export const sbool = (s: StageSpec, k: string, d = false): boolean =>
typeof s[k] === 'boolean' ? (s[k] as boolean) : d;
export const slist = (s: StageSpec, k: string, d: string[] = []): string[] =>
Array.isArray(s[k]) ? (s[k] as string[]) : d;
/** 阶段取文案:title=主文字,brand=Luca,body/bodyN=步骤列表第 N 行。 */
export function stageText(s: StageSpec, ctx: StageRenderCtx): string {
const slot = sstr(s, 'text', 'title');
if (slot === 'brand') return 'Luca';
if (slot === 'body') return ctx.options.steps.join(',');
if (slot.startsWith('body')) {
const index = Number(slot.slice(4)) || 0;
return (
ctx.options.steps[index] ?? ctx.options.steps[0] ?? ctx.options.text
);
}
return ctx.options.text;
}
/** 步骤列表按需截取,并保证非空,供多行阶段使用。 */
export function stageLines(s: StageSpec, ctx: StageRenderCtx): string[] {
const count = snum(s, 'lines', 0);
const raw = count > 0 ? ctx.options.steps.slice(0, count) : ctx.options.steps;
const lines = raw.filter(Boolean);
return lines.length > 0 ? lines : [ctx.options.text];
}
const FONT_SIZE: Record<string, number> = {
sm: 5.4,
md: 8.6,
lg: 12.5,
xl: 17,
giant: 27,
};
export const stageFontSize = (s: StageSpec, d = 'md') =>
`${FONT_SIZE[sstr(s, 'size', d)] ?? FONT_SIZE.md}cqw`;
export function stagePalette(bgKey: string, accent: string): StagePalette {
const key = bgKey || 'paper';
const paper = '#fafaf7';
const ink = '#18201d';
// 场景族自绘阶段的时间/季节键:映射到接近其自绘天空明度的底色,
// 保证后续文字层前景色对比正确(dusk/night 深,day/spring/winter 浅)。
const SCENE_TONE: Record<string, string> = {
dusk: '#2b2440',
night: '#10141f',
day: '#dfe8f2',
spring: '#e8f0df',
winter: '#e9edf2',
};
const bg =
key === 'color'
? accent
: key === 'ink'
? ink
: key === 'white'
? '#ffffff'
: key === 'deep'
? '#10151c'
: (SCENE_TONE[key] ?? paper);
const bright = contrastInk(bg) === '#ffffff';
return { bg, fg: bright ? '#ffffff' : ink, accent, paper, ink };
}
export function stageAlign(s: StageSpec) {
return sstr(s, 'align', 'center') === 'start' ? 'flex-start' : 'center';
}
type AssetState = 'loading' | 'ready' | 'error';
/**
* 案例必需资产的聚合就绪状态(R5-02/R5-03):
* - 准备时机 = 播放意图或舞台临近视口(几何判定,不依赖 rAF/IO——部分嵌入环境会停帧),
* 列表首屏外仍不提前下载;
* - 回调按代令牌失效,卸载不留定时器;
* - 失败经 retry 重试成功后递增 readyEpoch,播放器据此从起点完整重播。
*/
function useAssetReadiness(
root: React.RefObject<HTMLElement | null>,
urls: string[],
playing: boolean,
) {
const [armed, setArmed] = useState(false);
const armedRef = useRef(false);
// 已定状态按 attempt 记账:未记录或属旧尝试的一律视为 loading(派生态,避免 effect 内同步 setState)。
const [entries, setEntries] = useState<Record<string, { attempt: number; state: 'ready' | 'error' }>>({});
const [attempt, setAttempt] = useState(0);
const [readyEpoch, setReadyEpoch] = useState(0);
const hadErrorRef = useRef(false);
const statusOf = (url: string): AssetState => {
const entry = entries[url];
return entry && entry.attempt === attempt ? entry.state : 'loading';
};
useEffect(() => {
if (armedRef.current) return;
const el = root.current;
const arm = () => {
armedRef.current = true;
setArmed(true);
};
if (playing) {
arm();
return;
}
if (!el) return;
const isNear = () => {
const rect = el.getBoundingClientRect();
return rect.top < window.innerHeight + 600 && rect.bottom > -600;
};
if (isNear()) {
arm();
return;
}
const onChange = () => {
if (armedRef.current || !isNear()) return;
arm();
stop();
};
const timer = setInterval(onChange, 700);
window.addEventListener('scroll', onChange, { passive: true });
window.addEventListener('resize', onChange);
const stop = () => {
clearInterval(timer);
window.removeEventListener('scroll', onChange);
window.removeEventListener('resize', onChange);
};
return stop;
}, [playing, root]);
useEffect(() => {
if (!armed || urls.length === 0) return;
let alive = true;
const imgs: HTMLImageElement[] = [];
for (const url of urls) {
const img = new Image();
img.decoding = 'async';
img.onload = () => {
if (alive) setEntries((s) => ({ ...s, [url]: { attempt, state: 'ready' } }));
};
img.onerror = () => {
if (alive) setEntries((s) => ({ ...s, [url]: { attempt, state: 'error' } }));
};
img.src = url;
imgs.push(img);
}
return () => {
alive = false;
imgs.forEach((image) => {
image.onload = null;
image.onerror = null;
});
};
}, [armed, urls, attempt]);
// 空清单视为全部就绪(无外部资产的案例不受资产门控影响)。
const allReady = urls.every((url) => statusOf(url) === 'ready');
const anyError = urls.some((url) => statusOf(url) === 'error');
useEffect(() => {
if (anyError) hadErrorRef.current = true;
if (allReady && hadErrorRef.current) {
hadErrorRef.current = false;
setReadyEpoch((n) => n + 1);
}
}, [allReady, anyError]);
return {
armed,
/** 已就绪 URL 集合:渲染器据此挂载真实图层。 */
ready: useMemo(
() =>
new Set(
urls.filter((url) => {
const entry = entries[url];
return entry !== undefined && entry.attempt === attempt && entry.state === 'ready';
}),
),
[urls, entries, attempt],
),
/** 资产在准备中或存在失败:时钟保持,不宣告播放完成。 */
pending: armed && !allReady,
anyError,
retry: () => setAttempt((n) => n + 1),
readyEpoch,
};
}
/**
* 参考改编案例播放器:按 CaseSpec 的阶段序列播放。
* 初始与减少动态效果偏好下显示完整终态;播放、暂停、重播由父级控制。
*/
export function CaseDemo({
spec,
options,
playing = false,
replayKey = 0,
compact = false,
onComplete,
onStatusChange,
}: {
spec: CaseSpec;
options: MotionOptions;
playing?: boolean;
replayKey?: number;
compact?: boolean;
onComplete?: () => void;
onStatusChange?: (status:
| 'playing'
| 'paused'
| 'complete'
| 'waiting'
| 'reduced'
| 'offscreen') => void;
}) {
const root = useRef<HTMLElement>(null);
// 案例层数字有效域统一入口(含 chart-donut 的 0–100 百分比),所有调用方一致。
const opts = useMemo(
() => effectiveOptions(spec.stages, options, spec.defaults),
[spec.stages, options, spec.defaults],
);
// 必需外部资产(collage 插画):聚合就绪状态;未就绪时时钟保持、不宣告完成。
const assetUrls = useMemo(() => requiredAssetUrls(spec.stages), [spec.stages]);
const asset = useAssetReadiness(root, assetUrls, playing);
const { frame, reduced } = useMotionClock({
root,
duration: spec.duration * 1000,
speed: opts.speed,
playing,
replayKey,
onComplete,
hold: asset.pending,
restartSignal: asset.readyEpoch,
});
const waiting = playing && asset.pending && !reduced;
useEffect(() => {
if (!onStatusChange) return;
const status = reduced
? 'reduced'
: waiting
? 'waiting'
: frame >= 1
? 'complete'
: playing
? 'playing'
: 'paused';
onStatusChange(status);
}, [frame, reduced, waiting, playing, onStatusChange]);
const stages = useMemo(() => sortStages(spec.stages), [spec.stages]);
const seed = useMemo(() => hashSeed(spec.slug), [spec.slug]);
const now = frame * spec.duration;
const p = frame;
// 层序模型(P0-1):backdrop 底色板沉底(按时间序叠放,持久不淡出),
// 内容与封面转场在内容栈按时间序渲染。当前可见底色 = 时间上最近的底板。
// 封面转场自绘底色、只在其窗口内存活,结束后由同色底板承接。
const COVER_KINDS = new Set(['circle-fill', 'panel-wipe', 'shard-open']);
const plates = stages.filter((s) => s.kind === 'backdrop');
const acts = stages.filter((s) => s.kind !== 'backdrop');
const maxEnd = stages.reduce((m, s) => Math.max(m, s.at + s.dur), 0);
let trackedBackdrop = 'paper';
for (const pl of plates) {
if (pl.at <= now + 1e-6) trackedBackdrop = sstr(pl, 'bg', 'paper');
}
// 终幕:延伸到片尾的非封面内容层(并列取最先出现的)。
const finalists = acts.reduce<number[]>(
(acc, s, i) => (s.at + s.dur >= maxEnd - 1e-6 ? [...acc, i] : acc),
[],
);
const finalIdx =
finalists.find((i) => !COVER_KINDS.has(acts[i].kind)) ??
finalists[finalists.length - 1] ??
0;
// 字幕避让:只要末幕(含被延长到片尾的主体)中有 caption-bar 就生效。
const captionSafe = acts.some(
(s) => s.at + s.dur >= maxEnd - 1e-6 && s.kind === 'caption-bar',
);
const layers: ReactNode[] = [];
plates.forEach((pl, pi) => {
if (now < pl.at - 1e-6) return;
const palette = stagePalette(sstr(pl, 'bg', 'paper'), opts.color);
layers.push(
<div
key={`plate-${pi}`}
className='motion-layer'
style={{ background: palette.bg }}
/>,
);
});
acts.forEach((stage, i) => {
const t = stageLocal(now, stage);
if (t <= 0) return;
const isCover = COVER_KINDS.has(stage.kind);
const bgKey = isCover ? sstr(stage, 'bg', trackedBackdrop) : trackedBackdrop;
const render = STAGE_RENDERERS[stage.kind];
// 未知 kind 静默跳过:注册表由生成器校验与单元测试双重保证无未知阶段,
// 此处不引用 process/env 等 Node 全局,保持复用包仅依赖 React 与浏览器 API。
if (!render) return;
const rand = mulberry32((seed ^ Math.imul(i + 1, 2654435761)) >>> 0);
const palette = stagePalette(bgKey, opts.color);
// 底板持久;延伸到片尾的内容层与终幕持续保留;其余尾段自动淡出避免叠影。
const reachesEnd = stage.at + stage.dur >= maxEnd - 1e-6;
const fade =
!reachesEnd && i !== finalIdx ? clamp((t - 0.85) / 0.15) : 0;
layers.push(
<div
key={i}
className='motion-layer'
data-stage={stage.kind}
style={{ opacity: 1 - fade }}
>
{render(stage, t, { options: opts, rand, now, palette, captionSafe, assets: asset.ready })}
</div>,
);
});
return (
<figure
ref={root}
className={`motion-stage motion-case${compact ? ' motion-stage--compact' : ''}`}
aria-label={`${opts.text},动效预览`}
data-motion={spec.slug}
data-progress={p.toFixed(4)}
data-assets={
assetUrls.length === 0
? 'none'
: asset.anyError
? 'error'
: asset.pending
? 'loading'
: 'ready'
}
data-status={
reduced
? 'reduced'
: waiting
? 'waiting'
: frame >= 1
? 'complete'
: playing
? 'playing'
: 'paused'
}
style={{ '--motion-color': opts.color } as React.CSSProperties}
>
<div className='motion-art motion-case-art' aria-hidden='true'>
{layers}
</div>
{/* 可交互阶段的稳定可访问 UI 层:不在 aria-hidden 绘图区,compact 列表不渲染(G1)。 */}
{!compact &&
stages.some((s) => EDITORIAL_INTERACTIVE[s.kind]) && now >= (stages.find((s) => EDITORIAL_INTERACTIVE[s.kind])?.at ?? 0) - 1e-6
? (() => {
const stage = stages.find((s) => EDITORIAL_INTERACTIVE[s.kind])!;
const Game = EDITORIAL_INTERACTIVE[stage.kind];
const palette = stagePalette(trackedBackdrop, opts.color);
return (
<div className='motion-case-interactive'>
<Game accent={palette.accent} ink={palette.ink} />
</div>
);
})()
: null}
{!compact && assetUrls.length > 0 && (asset.pending || asset.anyError) ? (
<output className='motion-case-assets'>
{asset.anyError ? (
<>
<span>有插画未能加载</span>
<button type='button' className='motion-asset-retry' onClick={asset.retry}>
重试加载插画
</button>
</>
) : (
<span>插画加载中…</span>
)}
</output>
) : null}
</figure>
);
}
/** 挂载辅助:给调用示例与详情页共用。 */
export function useCaseControls() {
const [playing, setPlaying] = useState(false);
const [run, setRun] = useState(0);
const complete = () => setPlaying(false);
const replay = () => {
setRun((value) => value + 1);
setPlaying(true);
};
return { playing, run, complete, replay, setPlaying };
}
export { effectiveOptions } from './case-timeline';
export type { CaseSpec, StageSpec };
import { type MotionOptions, type RecipeItemData } from './motion-core';
export { activeRecipe, effectiveRecipe, liquidLevels, parseRecipe, RECIPE_TYPES, RECIPE_TYPE_LABEL } from './motion-core';
export type { RecipeItemData, RecipeType } from './motion-core';
/** 一个动作阶段的参数:kind + 时间窗 + 该阶段自己的几何/内容参数。 */
export interface CollageLayerData {
url: string;
x: number;
y: number;
w: number;
rot: number;
/**
* 入场运动方向(不是来向):up 自下方向上、down 自上方向下、
* left 自右侧向左、right 自左侧向右。描述生成器与渲染器共用此契约。
*/
from?: string;
delay?: number;
}
export type StageParam =
| string
| number
| boolean
| string[]
| number[]
| CollageLayerData[]
| RecipeItemData[]
| undefined;
export type StageSpec = {
kind: string;
at: number;
dur: number;
[key: string]: StageParam;
};
export type ObservationLevel =
| 'video-observed'
| 'preview-observed'
| 'detail-page-observed';
/** 案例注册表条目:渲染所需的一切都在数据里,引擎按 spec 播放。 */
export type CaseSpec = {
slug: string;
name: string;
purpose: string;
description: string;
scenes: string;
category: string;
refTags: string[];
family: string;
stages: StageSpec[];
duration: number;
fields: ('text' | 'numbers' | 'steps')[];
maxText: number;
defaults: MotionOptions;
sequence: string[];
implementation: string;
limitations: string[];
reference: {
title: string;
url: string;
author: string;
handle?: string;
principle: string;
};
observation: { level: ObservationLevel; scope: string };
status: '实验演示';
};
export const clamp01 = (n: number) => Math.min(1, Math.max(0, n));
/** 案例必需的外部资产 URL(按阶段顺序去重;覆盖全部用图阶段的统一契约)。
* 约定:用图阶段必须把资源显式写入阶段数据(layers[].url / img / imgs),
* renderer 只消费同一字段,不得私设站点绝对路径回退。 */
export function requiredAssetUrls(stages: StageSpec[]): string[] {
const urls: string[] = [];
const push = (url: unknown) => {
if (typeof url === 'string' && url && !urls.includes(url)) urls.push(url);
};
for (const stage of [...stages].sort((a, b) => a.at - b.at)) {
if (stage.kind === 'collage-layer') {
const raw = stage.layers;
if (!Array.isArray(raw)) continue;
for (const layer of raw as CollageLayerData[]) push(layer?.url);
continue;
}
if (stage.kind === 'image-through' || stage.kind === 'image-layout' || stage.kind === 'image-compare') {
push(stage.img);
continue;
}
if (stage.kind === 'image-cards') {
const imgs = stage.imgs;
if (Array.isArray(imgs)) for (const url of imgs as string[]) push(url);
}
}
return urls;
}
/**
* 案例层数字有效域:chart-donut from/to 是 0–100 百分比;code-motion 的
* from/to 分别是波形幅度 4–40、周期 1–6。其它数字案例保留原域。
* 详情、列表、CaseDemo、提示词、Example 等所有入口统一调用,
* 业务有效值不由各入口自行猜;渲染器仅保留数值边界防御。
*/
export function effectiveOptions<T extends { from: number; to: number }>(
stages: StageSpec[],
options: T,
defaults?: { from: number; to: number },
): T {
const isDonut = stages.some((stage) => stage.kind === 'chart-donut');
const isCodeMotion = stages.some((stage) => stage.kind === 'code-motion');
if (!isDonut && !isCodeMotion) return options;
// 非有限值先按明确契约回退(优先案例默认值,缺省 0/100),再做 0–100 钳制;
// 页面、CaseDemo、prompt、Example、独立包共用同一结果(B1)。
const fbFrom = defaults && Number.isFinite(defaults.from) ? defaults.from : 0;
const fbTo = defaults && Number.isFinite(defaults.to) ? defaults.to : 100;
const bounded = (v: number, fallback: number, min: number, max: number) =>
Math.min(max, Math.max(min, Number.isFinite(v) ? v : fallback));
if (isCodeMotion) {
return {
...options,
from: bounded(options.from, fbFrom, 4, 40),
to: bounded(options.to, fbTo, 1, 6),
};
}
const pct = (v: number, fallback: number) => clamp01(bounded(v, fallback, 0, 100) / 100) * 100;
return { ...options, from: pct(options.from, fbFrom), to: pct(options.to, fbTo) };
}
/** 当前秒数在某个阶段内的本地进度(0–1)。 */
export function stageLocal(now: number, stage: StageSpec) {
return clamp01((now - stage.at) / Math.max(stage.dur, 0.001));
}
export function sortStages(stages: StageSpec[]) {
return [...stages].sort((a, b) => a.at - b.at);
}
export function specDuration(stages: StageSpec[]) {
return stages.reduce((max, s) => Math.max(max, s.at + s.dur), 0);
}
/** 阶段组成签名:用于测试保证每条案例的动作结构唯一。 */
export function stageSignature(stages: StageSpec[]) {
return stages
.map((s) => {
const rest = Object.keys(s)
.filter((k) => k !== 'kind' && k !== 'at' && k !== 'dur')
.sort()
.map((k) => `${k}:${JSON.stringify(s[k] ?? null)}`)
.join(',');
return `${s.kind}@${s.at}+${s.dur}(${rest})`;
})
.join('|');
}
/** 确定性伪随机:同一案例每次播放布局一致,避免跳变。 */
export function hashSeed(text: string) {
let h = 2166136261;
for (let i = 0; i < text.length; i++) {
h ^= text.charCodeAt(i);
h = Math.imul(h, 16777619);
}
return h >>> 0;
}
export function mulberry32(seed: number) {
let a = seed >>> 0;
return () => {
a |= 0;
a = (a + 0x6d2b79f5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
export const easeInOut = (t: number) =>
clamp01(t) < 0.5
? 4 * clamp01(t) ** 3
: 1 - (-2 * clamp01(t) + 2) ** 3 / 2;
export const easeOutQuint = (t: number) => 1 - (1 - clamp01(t)) ** 5;
export const easeOutBack = (t: number) => {
const c = 1.70158 * 0.9;
const x = clamp01(t) - 1;
return 1 + (c + 1) * x ** 3 + c * x ** 2;
};
/** 环形图当前值:起始值→目标值共同驱动中途数值(P0 修复:from 必须被消费)。 */
export function donutValueAt(from: number, to: number, frac: number) {
const f = clamp01(frac);
return Math.round((from + (to - from) * f) * 100) / 100;
}
/** 环线几何(M3):可见轨迹与载具锚点/切线共用同一组参数。
* 坐标为 0–100 视图单位;切线角为该坐标系的 atan2 角。 */
export const ORBIT = { cx: 50, cy: 46, rx: 34, ry: 20 } as const;
export function orbitAnchor(theta: number) {
const { cx, cy, rx, ry } = ORBIT;
return {
x: cx + Math.cos(theta) * rx,
y: cy + Math.sin(theta) * ry,
angleDeg: (Math.atan2(Math.cos(theta) * ry, -Math.sin(theta) * rx) * 180) / Math.PI,
};
}
/** 纯代码案例(M6):点位生成、坐标映射与展示片段共用同一实现。 */
export function codeMotionPoints(amp: number, cycles: number) {
const pts: Array<{ x: number; y: number }> = [];
for (let i = 0; i <= 24; i++) {
const x = i / 24;
pts.push({ x, y: amp * Math.sin(x * cycles * Math.PI * 2) });
}
return pts;
}
/** 视图映射:x∈[0,1]、y=±40 满幅 → SVG viewBox 0–100。 */
export const CODE_MOTION_MAP = { ox: 6, oxSpan: 88, oy: 50, oyScale: 1 } as const;
export function codeMotionView(pt: { x: number; y: number }) {
return { cx: CODE_MOTION_MAP.ox + pt.x * CODE_MOTION_MAP.oxSpan, cy: 50 - (pt.y / 40) * 40 };
}
export function codeMotionSnippet(amp: number, cycles: number, color = '#1b6b50') {
const safeColor = /^#[\da-f]{6}$/i.test(color) ? color.toLowerCase() : '#1b6b50';
return [
'// 运行方式:以下全部是 JavaScript,不含 HTML——可粘贴到任意已打开网页的控制台执行,或存为 .js 文件后在 HTML 的 </body> 前以 <script src="…js"></script> 引入;不能直接把本文件改存为 .html 双击打开。依赖:DOM。',
"const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');",
"svg.setAttribute('viewBox', '0 0 100 100');",
"svg.style.cssText = 'width:min(90vw,420px);aspect-ratio:1;background:#fff';",
'document.body.appendChild(svg);',
"function dot(cx, cy) {",
" const c = document.createElementNS('http://www.w3.org/2000/svg', 'circle');",
" c.setAttribute('cx', cx);",
" c.setAttribute('cy', cy);",
" c.setAttribute('r', 2.2);",
` c.setAttribute('fill', ${JSON.stringify(safeColor)});`,
' svg.appendChild(c);',
'}',
'function points(amp, cycles) {',
' const pts = [];',
' for (let i = 0; i <= 24; i++) {',
' const x = i / 24;',
' pts.push({ x, y: amp * Math.sin(x * cycles * Math.PI * 2) });',
' }',
' return pts;',
'}',
`for (const p of points(${amp}, ${cycles})) dot(6 + p.x * 88, 50 - (p.y / 40) * 40);`,
].join('\n');
}
/** 弹跳落地(用于球体/角色)。 */
export function bounceOut(t: number) {
let x = clamp01(t);
const n = 7.5625;
const d = 2.75;
if (x < 1 / d) return n * x * x;
if (x < 2 / d) return n * (x -= 1.5 / d) * x + 0.75;
if (x < 2.5 / d) return n * (x -= 2.25 / d) * x + 0.9375;
return n * (x -= 2.625 / d) * x + 0.984375;
}
'use client';
import { useEffect, useRef, useState, type RefObject } from 'react';
import { clamp } from './motion-core';
export type MotionClock = {
frame: number;
reduced: boolean;
hasEntered: boolean;
active: boolean;
};
/**
* 播放器共用时间轴:管理 0–1 进度、视口、标签页可见性与减少动态效果偏好。
* 暂停保留当前画面;重播通过递增 replayKey 从头播放;离屏或后台自动停帧。
*/
export function useMotionClock({
root,
duration,
speed,
playing,
replayKey,
onComplete,
hold = false,
restartSignal = 0,
}: {
root: RefObject<HTMLElement | null>;
duration: number;
speed: number;
playing: boolean;
replayKey: number;
onComplete?: () => void;
/** 必需资源未就绪时为真:时钟不推进、不宣告完成(R5-02)。 */
hold?: boolean;
/** 资源重试成功后递增:时钟从起点完整重播(R5-02)。 */
restartSignal?: number;
}): MotionClock {
const progress = useRef(1);
const complete = useRef(onComplete);
const [frame, setFrame] = useState(1);
// replayKey/restartSignal 变化时在 render 阶段派生复位(React 官方模式):
// 进度与显示帧同步回起点,资源保持期间也不会停留在终态画面(R5-02)。
const [prevKeys, setPrevKeys] = useState({ replayKey, restartSignal });
if (prevKeys.replayKey !== replayKey || prevKeys.restartSignal !== restartSignal) {
setPrevKeys({ replayKey, restartSignal });
setFrame(0);
}
// 播放边沿复位显示:首播/播完后再播都从起点帧开始,暂停续播不受影响(R5-02)。
const [prevPlaying, setPrevPlaying] = useState(playing);
const [resetOnPlay, setResetOnPlay] = useState(true);
if (playing !== prevPlaying) {
setPrevPlaying(playing);
if (playing && resetOnPlay) {
setFrame(0);
setResetOnPlay(false);
}
}
const [inView, setInView] = useState(false);
const [hasEntered, setHasEntered] = useState(false);
const [visible, setVisible] = useState(true);
const [reduced, setReduced] = useState(false);
useEffect(() => {
complete.current = onComplete;
}, [onComplete]);
useEffect(() => {
const media = matchMedia('(prefers-reduced-motion: reduce)');
const preference = () => setReduced(media.matches);
const visibility = () => setVisible(!document.hidden);
preference();
visibility();
media.addEventListener('change', preference);
document.addEventListener('visibilitychange', visibility);
const observer = new IntersectionObserver(
([entry]) => {
setInView(entry.isIntersecting);
if (entry.isIntersecting) setHasEntered(true);
},
{ threshold: 0.1 },
);
if (root.current) observer.observe(root.current);
return () => {
observer.disconnect();
media.removeEventListener('change', preference);
document.removeEventListener('visibilitychange', visibility);
};
}, [root]);
const lastKeys = useRef({ replayKey, restartSignal });
useEffect(() => {
if (
lastKeys.current.replayKey !== replayKey ||
lastKeys.current.restartSignal !== restartSignal
) {
lastKeys.current = { replayKey, restartSignal };
progress.current = 0;
}
if (!playing || !inView || !visible || reduced || hold) return;
if (progress.current >= 1) progress.current = 0;
let last = performance.now();
let raf = 0;
const tick = (now: number) => {
progress.current = clamp(
progress.current + ((now - last) * speed) / duration,
);
last = now;
setFrame(progress.current);
if (progress.current < 1) raf = requestAnimationFrame(tick);
else {
setResetOnPlay(true);
complete.current?.();
}
};
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, [playing, inView, visible, reduced, speed, duration, replayKey, hold, restartSignal]);
return {
frame: reduced ? 1 : frame,
reduced,
hasEntered,
active: inView && visible,
};
}
export type MotionKind =
| 'word-reveal'
| 'count-up'
| 'step-flow'
| 'shape-morph'
| 'layered-collage'
| 'dot-assembly';
/** 参数面板可展示的输入种类:主文字、数值区间、步骤列表。 */
export type MotionField = 'text' | 'numbers' | 'steps';
export type MotionOptions = {
text: string;
color: string;
speed: number;
from: number;
to: number;
steps: string[];
/** 只供两条配方案例使用的显式 typed 输入;普通步骤仍由 steps 承载。 */
recipe?: RecipeItemData[];
};
/** 配方数据共享于站点预览与可复制引擎,不依赖 case-timeline。 */
export interface RecipeItemData {
id: string;
t: 'liquid' | 'ice' | 'stir' | 'garnish';
name: string;
amount?: number;
unit?: '份';
color?: string;
off?: boolean;
}
export type RecipeType = RecipeItemData['t'];
export const RECIPE_TYPES: RecipeType[] = ['liquid', 'ice', 'stir', 'garnish'];
export const RECIPE_TYPE_LABEL: Record<RecipeType, string> = {
liquid: '液体', ice: '加冰动作', stir: '搅拌动作', garnish: '装饰动作',
};
export const RECIPE_DEFAULT_COLOR = '#d97706';
/** 严格解析固定身份的配方:统一「份」;不接受符号/单位猜测或混量纲。 */
export function parseRecipe(input: unknown): RecipeItemData[] | undefined {
if (!Array.isArray(input) || input.length === 0) return undefined;
const out: RecipeItemData[] = [];
const ids = new Set<string>();
for (const raw of input) {
if (typeof raw !== 'object' || raw === null) return undefined;
const it = raw as Record<string, unknown>;
if (typeof it.id !== 'string' || !it.id.trim() || ids.has(it.id.trim())) return undefined;
ids.add(it.id.trim());
if (typeof it.t !== 'string' || !RECIPE_TYPES.includes(it.t as RecipeType)) return undefined;
const isOff = it.off === true;
const name = typeof it.name === 'string' ? it.name.trim() : '';
if (!isOff && (!name || Array.from(name).length > 12)) return undefined;
const item: RecipeItemData = { id: it.id.trim(), t: it.t as RecipeType, name };
if (isOff) item.off = true;
if (isOff) { out.push(item); continue; }
if (item.t === 'liquid') {
if (typeof it.amount !== 'number' || !Number.isFinite(it.amount) || it.amount < 0 || it.unit !== '份') return undefined;
item.amount = it.amount;
item.unit = '份';
item.color = typeof it.color === 'string' && /^#[\da-f]{6}$/i.test(it.color) ? it.color : RECIPE_DEFAULT_COLOR;
}
out.push(item);
}
return out.some((item) => item.off !== true) ? out : undefined;
}
export function activeRecipe(items: RecipeItemData[]): RecipeItemData[] {
return items.filter((item) => item.off !== true);
}
/** 无效 override 回退完整默认配方;调用 UI 必须同步显示回退提示。 */
export function effectiveRecipe(items: RecipeItemData[], override?: unknown): RecipeItemData[] {
return activeRecipe(parseRecipe(override) ?? parseRecipe(items) ?? []);
}
/** 将液体总量按杯内高度归一化;因此不溢杯,零量贡献为零。 */
export function liquidLevels(items: RecipeItemData[]) {
const liquids = activeRecipe(items).filter((item) => item.t === 'liquid');
const maxAmount = liquids.reduce((max, item) => Math.max(max, item.amount ?? 0), 0);
const totalScaled = maxAmount > 0
? liquids.reduce((sum, item) => sum + (item.amount ?? 0) / maxAmount, 0)
: 0;
let accumulated = 0;
return liquids.map((item) => {
const amount = item.amount ?? 0;
const scaled = maxAmount > 0 ? amount / maxAmount : 0;
const cumRatio = totalScaled > 0 ? accumulated / totalScaled : 0;
const ratio = totalScaled > 0 ? scaled / totalScaled : 0;
accumulated += scaled;
return { item, cumRatio, ratio };
});
}
/** 每种效果 1 倍速度的基准时长(毫秒)。提示词与播放器共用这一份数值。 */
export const DURATIONS: Record<MotionKind, number> = {
'word-reveal': 2800,
'count-up': 2600,
'step-flow': 4200,
'shape-morph': 5600,
'layered-collage': 3600,
'dot-assembly': 4000,
};
export const clamp = (n: number, min = 0, max = 1) =>
Math.min(max, Math.max(min, n));
export const mix = (a: number, b: number, t: number) => a + (b - a) * t;
export const ease = (t: number) => 1 - (1 - clamp(t)) ** 3;
export function characters(text: string) {
return Array.from(
new Intl.Segmenter('zh-CN', { granularity: 'grapheme' }).segment(text),
(part) => part.segment,
);
}
export function normalizeOptions(
input: Partial<MotionOptions>,
defaults: MotionOptions,
maxText: number,
): MotionOptions {
const finite = (
n: number | undefined,
fallback: number,
min: number,
max: number,
) => (n !== undefined && Number.isFinite(n) ? clamp(n, min, max) : fallback);
const text = characters(input.text?.trim() || defaults.text)
.slice(0, maxText)
.join('');
const steps = (input.steps ?? defaults.steps)
.map((step) => characters(step.trim()).slice(0, 12).join(''))
.filter(Boolean)
.slice(0, 5);
const recipe = input.recipe === undefined ? undefined : parseRecipe(input.recipe);
return {
text,
color: /^#[\da-f]{6}$/i.test(input.color ?? '')
? input.color!
: defaults.color,
speed: finite(input.speed, defaults.speed, 0.5, 2),
from: finite(input.from, defaults.from, -999999, 999999),
to: finite(input.to, defaults.to, -999999, 999999),
steps: steps.length >= 3 ? steps : defaults.steps,
...(recipe ? { recipe } : {}),
};
}
export function countAt(from: number, to: number, progress: number) {
return Math.round(mix(from, to, ease(progress)) * 100) / 100;
}
export function morphAt(progress: number) {
const p = clamp(progress);
const first = p < 0.45;
const t = ease(first ? (p - 0.12) / 0.28 : (p - 0.55) / 0.3);
return {
width: first ? mix(42, 65, t) : mix(65, 82, t),
height: first ? mix(48, 64, t) : mix(64, 176, t),
radius: first ? mix(8, 32, t) : mix(32, 12, t),
};
}
export function contrastInk(hex: string) {
const rgb = [1, 3, 5].map((index) => {
const n = parseInt(hex.slice(index, index + 2), 16) / 255;
return n <= 0.04045 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4;
});
const luminance = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
return 1.05 / (luminance + 0.05) >= 4.5 ? '#ffffff' : '#000000';
}
import type { CSSProperties } from 'react';
import type { StageRenderer } from './case-engine';
import type { StageSpec } from './case-timeline';
import type { StageRenderCtx } from './case-engine';
import { easeOutQuint } from './case-timeline';
import {
sbool,
snum,
sstr,
stageAlign,
stageFontSize,
stageLines,
stageText,
} from './case-engine';
const CHAR_W_CJK = 1.0;
const CHAR_W_LATIN = 0.55;
const LINE_H = 1.22;
function widthUnits(text: string) {
return Array.from(text).reduce(
(w, ch) => w + (ch.codePointAt(0)! > 0x2e80 ? CHAR_W_CJK : CHAR_W_LATIN),
0,
);
}
/**
* P0-3 尺寸约束:字号 = min(档位 cqw, 高度预算 cqh, 单行宽度上限 cqw)。
* 只缩不放;captionSafe 时高度预算扣除字幕安全区(P0-2 预算内避让)。
*/
function fitFont(
s: StageSpec,
ctx: StageRenderCtx,
text: string,
opts: { maxW?: number; wrap?: boolean; cropAllow?: number } = {},
) {
const base = parseFloat(stageFontSize(s));
const maxW = opts.maxW ?? 86;
const units = Math.max(widthUnits(text), 1);
const crop = opts.cropAllow ?? 1;
const widthCap = ((maxW * crop) / units) * 1.0;
const safeTop = ctx.captionSafe ? 26 : 10;
const availH = 90 - safeTop;
let heightCap = availH / LINE_H;
if (opts.wrap !== false) {
const lines = Math.max(1, Math.ceil((units * base) / maxW));
heightCap = availH / (lines * LINE_H);
}
return `min(${base}cqw, ${heightCap.toFixed(2)}cqh, ${widthCap.toFixed(2)}cqw)`;
}
const center: CSSProperties = {
position: 'absolute',
inset: 0,
display: 'flex',
flexDirection: 'column',
};
/** 分段入场:每段的上移/缩放/模糊进度。 */
function segmentT(t: number, i: number, total: number, spread = 0.6) {
const start = (i / Math.max(total, 1)) * spread;
return easeOutQuint((t - start) / (1 - spread));
}
function splitSegments(text: string, per: string) {
if (per === 'word') return text.split(/(\s+)/).filter(Boolean);
return Array.from(text);
}
const FROM_OFFSET: Record<string, [number, number]> = {
up: [0, 34],
down: [0, -34],
left: [42, 0],
right: [-42, 0],
};
/** line-in:标题或短句按字/词入场,方向、字号与字重可调。 */
export const lineIn: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const per = sstr(s, 'per', 'char');
const from = sstr(s, 'from', 'up');
const segments = splitSegments(text, per);
const offset = FROM_OFFSET[from] ?? FROM_OFFSET.up;
const isMask = from === 'mask';
const isScale = from === 'scale';
const isBlur = from === 'blur';
return (
<div
style={{
...center,
alignItems: stageAlign(s),
justifyContent: ctx.captionSafe ? 'flex-start' : 'center',
padding: ctx.captionSafe ? '10cqh 7cqw 0' : '0 7cqw',
}}
>
<div
style={{
fontSize: fitFont(s, ctx, text),
fontWeight: snum(s, 'weight', 800),
lineHeight: 1.18,
letterSpacing: per === 'char' ? '0.02em' : '0',
maxWidth: `${snum(s, 'maxw', 86)}cqw`,
color: ctx.palette.fg,
display: 'flex',
flexWrap: 'wrap',
justifyContent: stageAlign(s),
}}
>
{segments.map((segment, i) => {
const st = segmentT(t, i, segments.length);
const hidden = {
opacity: isBlur ? Math.min(1, st * 1.6) : st,
transform: isScale
? `scale(${0.62 + 0.38 * st})`
: `translate(${(1 - st) * offset[0]}cqw, ${(1 - st) * offset[1] * 0.11}cqw)`,
filter: isBlur ? `blur(${(1 - st) * 8}px)` : undefined,
clipPath: isMask
? `inset(${(1 - st) * 100}% 0 0 0)`
: undefined,
};
return (
<span
key={i}
style={{
display: isMask ? 'inline-block' : 'inline-block',
whiteSpace: 'pre',
...hidden,
}}
>
{segment === ' ' ? '\u00a0' : segment}
</span>
);
})}
</div>
</div>
);
};
/** line-out:一行字按方向退出,为下一阶段腾出画面。 */
export const lineOut: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const to = sstr(s, 'to', 'up');
const e = easeOutQuint(t);
const shift: Record<string, string> = {
up: `translateY(${-e * 46}cqh)`,
down: `translateY(${e * 46}cqh)`,
left: `translateX(${-e * 60}cqw)`,
right: `translateX(${e * 60}cqw)`,
scale: `scale(${1 + e * 1.4})`,
blur: `scale(${1 + e * 0.2})`,
};
return (
<div
style={{
...center,
alignItems: stageAlign(s),
justifyContent: 'center',
padding: '0 7cqw',
opacity: 1 - e,
filter: to === 'blur' ? `blur(${e * 10}px)` : undefined,
transform: shift[to] ?? shift.up,
}}
>
<div
style={{
fontSize: fitFont(s, ctx, text, { wrap: false }),
fontWeight: snum(s, 'weight', 800),
color: ctx.palette.fg,
letterSpacing: '0.02em',
}}
>
{text}
</div>
</div>
);
};
/** big-word:单个大词从很小撑到满幅(或反向),强调尺度跨越。 */
export const bigWord: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const e = easeOutQuint(t);
const fromScale = snum(s, 'fromScale', 0.14);
const drift = snum(s, 'drift', 0.08);
return (
<div style={{ ...center, alignItems: 'center', justifyContent: 'center' }}>
<div
style={{
fontSize: fitFont(s, ctx, text, { wrap: false, maxW: 100, cropAllow: 1.15 }),
fontWeight: 900,
lineHeight: 0.98,
letterSpacing: '-0.04em',
color: ctx.palette.fg,
transform: `scale(${fromScale + (1 - fromScale) * e}) translateY(${(1 - e) * drift * 10}cqh)`,
transformOrigin: ctx.captionSafe ? 'center 30%' : 'center',
}}
>
{text}
</div>
</div>
);
};
/** word-mark:词标组装——字母依次落下,下划线延伸,箭头点上。
* 无 word 参数时回落到用户文字(截 6 字),白名单案例显式传 'Luca'。 */
export const wordMark: StageRenderer = (s, t, ctx) => {
const word = sstr(s, 'word', '') || stageText(s, ctx).slice(0, 6) || 'Luca';
const letters = Array.from(word);
const underline = easeOutQuint((t - 0.45) / 0.4);
const arrow = easeOutQuint((t - 0.72) / 0.28);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
gap: '1.6cqw',
}}
>
<div style={{ display: 'flex', alignItems: 'baseline' }}>
{letters.map((letter, i) => {
const e = easeOutQuint((t - i * 0.09) / 0.42);
return (
<span
key={i}
style={{
fontSize: stageFontSize(s, 'xl'),
fontWeight: 900,
color: ctx.palette.fg,
display: 'inline-block',
opacity: e,
transform: `translateY(${(1 - e) * 30}cqh)`,
}}
>
{letter}
</span>
);
})}
</div>
<div
style={{
width: `${58 * underline}cqw`,
height: '0.9cqw',
background: ctx.palette.accent,
borderRadius: 2,
}}
/>
<span
style={{
fontSize: '5cqw',
color: ctx.palette.fg,
opacity: arrow,
transform: `translate(${(1 - arrow) * -4}cqw, ${(1 - arrow) * 4}cqh)`,
}}
>
↗
</span>
</div>
);
};
/** type-caret:打字机输入,光标闪烁两下后停留。 */
export const typeCaret: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const chars = Array.from(text);
const typed = Math.min(chars.length, Math.floor(easeOutQuint(t) * chars.length * 1.06));
const caretOn = t < 0.92 ? Math.floor(t * 8) % 2 === 0 : true;
return (
<div
style={{
...center,
alignItems: stageAlign(s),
justifyContent: 'center',
padding: '0 7cqw',
}}
>
<div
style={{
fontSize: fitFont(s, ctx, text, { wrap: false, maxW: 92 }),
fontWeight: snum(s, 'weight', 700),
fontFamily: sbool(s, 'mono')
? 'ui-monospace, SFMono-Regular, Menlo, monospace'
: undefined,
color: ctx.palette.fg,
letterSpacing: '0.01em',
}}
>
{chars.slice(0, typed).join('')}
<span
style={{
display: 'inline-block',
width: '0.55cqw',
minWidth: 2,
height: '1em',
background: ctx.palette.accent,
marginLeft: '0.4cqw',
opacity: caretOn ? 1 : 0.15,
verticalAlign: '-0.12em',
}}
/>
</div>
</div>
);
};
/** type-mask:多行文字被遮罩逐行托出,适合成段观点。 */
export const typeMask: StageRenderer = (s, t, ctx) => {
const lines = stageLines(s, ctx);
return (
<div
style={{
...center,
alignItems: stageAlign(s),
justifyContent: ctx.captionSafe ? 'flex-start' : 'center',
gap: '2.4cqh',
padding: ctx.captionSafe ? '12cqh 7cqw 0' : '0 7cqw',
}}
>
{lines.map((line, i) => {
const e = easeOutQuint((t - i * 0.16) / 0.5);
return (
<div
key={i}
style={{
overflow: 'hidden',
padding: '0.4cqw 0',
}}
>
<div
style={{
fontSize: fitFont(s, ctx, line),
fontWeight: snum(s, 'weight', 800),
color: ctx.palette.fg,
transform: `translateY(${(1 - e) * 110}%)`,
}}
>
{line}
</div>
</div>
);
})}
</div>
);
};
/** type-jitter:两层同文案横向错位滑动,受控的印刷错版感(无频闪)。 */
export const typeJitter: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const amount = snum(s, 'amount', 1.6);
const swing = Math.sin(t * Math.PI * 2 * snum(s, 'cycles', 2));
const e = easeOutQuint(Math.min(1, t * 1.6));
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
opacity: e,
}}
>
<div style={{ position: 'relative' }}>
<div
aria-hidden="true"
style={{
fontSize: fitFont(s, ctx, text, { wrap: false, maxW: 96 }),
fontWeight: 900,
color: ctx.palette.accent,
transform: `translateX(${swing * amount}cqw)`,
position: 'absolute',
inset: 0,
opacity: t > 0.92 ? 0 : 1,
}}
>
{text}
</div>
<div
style={{
fontSize: fitFont(s, ctx, text, { wrap: false, maxW: 96 }),
fontWeight: 900,
color: ctx.palette.fg,
transform: `translateX(${-swing * amount * 0.6}cqw)`,
}}
>
{text}
</div>
</div>
</div>
);
};
/** mark-bounds:大字配编辑边界框与四角手柄,依次出现。 */
export const markBounds: StageRenderer = (s, t, ctx) => {
const text = stageText(s, ctx);
const box = easeOutQuint((t - 0.1) / 0.4);
const handles = easeOutQuint((t - 0.5) / 0.35);
const label = sstr(s, 'label', '预览 · 可调参数');
const labelIn = easeOutQuint((t - 0.72) / 0.28);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
position: 'relative',
padding: '3cqw 4cqw',
marginTop: ctx.captionSafe ? '-8cqh' : undefined,
}}
>
<div
style={{
fontSize: fitFont(s, ctx, text),
fontWeight: 900,
lineHeight: 1,
letterSpacing: '-0.03em',
color: ctx.palette.fg,
opacity: easeOutQuint(Math.min(1, t * 2.4)),
}}
>
{text}
</div>
<div
style={{
position: 'absolute',
inset: 0,
border: `${Math.max(1, 0.28)}cqw solid ${ctx.palette.accent}`,
opacity: box,
transform: `scale(${0.94 + box * 0.06})`,
}}
/>
{[
[-1, -1],
[1, -1],
[-1, 1],
[1, 1],
].map(([x, y], i) => (
<div
key={i}
style={{
position: 'absolute',
left: x < 0 ? '-1cqw' : undefined,
right: x > 0 ? '-1cqw' : undefined,
top: y < 0 ? '-1cqw' : undefined,
bottom: y > 0 ? '-1cqw' : undefined,
width: '2cqw',
height: '2cqw',
background: ctx.palette.fg,
border: `0.3cqw solid ${ctx.palette.bg}`,
opacity: handles,
transform: `scale(${handles})`,
}}
/>
))}
<div
style={{
position: 'absolute',
top: '100%',
left: 0,
marginTop: '1.2cqh',
fontSize: '3.4cqw',
color: ctx.palette.accent,
opacity: labelIn,
}}
>
{label}
</div>
</div>
</div>
);
};
/** caption-bar:底部字幕条逐词点亮,像讲解视频的随句字幕。 */
export const captionBar: StageRenderer = (s, t, ctx) => {
const lines = stageLines(s, ctx);
const line = lines[Math.min(lines.length - 1, Math.floor(t * lines.length))];
const words = line.split(/(\s+)/).filter(Boolean);
const localT = (t * lines.length) % 1;
return (
<div
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: '6cqh',
display: 'flex',
justifyContent: 'center',
padding: '0 6cqw',
}}
>
<div
style={{
background: 'rgba(16,21,28,0.82)',
color: '#ffffff',
borderRadius: '1.2cqw',
padding: '1.6cqw 2.6cqw',
fontSize: '4.6cqw',
fontWeight: 700,
display: 'flex',
flexWrap: 'wrap',
gap: '0.6cqw',
maxWidth: '88cqw',
}}
>
{words.map((word, i) => {
const lit = i / Math.max(words.length, 1) <= localT;
return (
<span
key={i}
style={{
whiteSpace: 'pre',
color: lit ? '#ffffff' : 'rgba(255,255,255,0.55)',
}}
>
{word}
</span>
);
})}
</div>
</div>
);
};
export const TYPE_STAGES: Record<string, StageRenderer> = {
'line-in': lineIn,
'line-out': lineOut,
'big-word': bigWord,
'word-mark': wordMark,
'type-caret': typeCaret,
'type-mask': typeMask,
'type-jitter': typeJitter,
'mark-bounds': markBounds,
'caption-bar': captionBar,
};
import {
useEffect,
useMemo,
useRef,
useState,
type CSSProperties,
type ReactNode,
} from 'react';
import type { StageRenderer } from './case-engine';
import {
easeInOut,
easeOutQuint,
hashSeed,
mulberry32,
} from './case-timeline';
import {
sbool,
slist,
snum,
sstr,
stageText,
} from './case-engine';
const center: CSSProperties = {
position: 'absolute',
inset: 0,
display: 'flex',
};
/** Canvas 阶段共用:随容器尺寸重建画布,参数变化时重绘一帧。 */
function useStageCanvas(
draw: (
ctx: CanvasRenderingContext2D,
width: number,
height: number,
) => void,
deps: unknown[],
) {
const drawRef = useRef(draw);
useEffect(() => {
drawRef.current = draw;
});
const ref = useRef<HTMLCanvasElement>(null);
const [size, setSize] = useState({ width: 0, height: 0 });
useEffect(() => {
const el = ref.current;
if (!el) return;
const observer = new ResizeObserver(([entry]) =>
setSize({
width: Math.round(entry.contentRect.width),
height: Math.round(entry.contentRect.height),
}),
);
observer.observe(el);
return () => observer.disconnect();
}, []);
const depsKey = JSON.stringify(deps);
useEffect(() => {
const el = ref.current;
if (!el || !size.width || !size.height) return;
const dpr = Math.min(devicePixelRatio || 1, 2);
const width = Math.round(size.width * dpr);
const height = Math.round(size.height * dpr);
if (el.width !== width || el.height !== height) {
el.width = width;
el.height = height;
}
const ctx = el.getContext('2d');
if (!ctx) return;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
drawRef.current(ctx, size.width, size.height);
}, [size.width, size.height, depsKey]);
return ref;
}
/**
* brand-pop:过冲放大登场。默认 'geo' 渲染中性几何色块(圆角方块+内环),
* 'luca' 渲染蓝底 L↗ 标识(仅品牌主题白名单案例使用)。
*/
export const brandPop: StageRenderer = (s, t, ctx) => {
const e = easeOutQuint(t);
const size = snum(s, 'mark', 16);
const variant = sstr(s, 'subject', 'geo');
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
<span
style={{
width: `${size}cqw`,
height: `${size * 1.05}cqw`,
background: ctx.palette.accent,
color: '#ffffff',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: variant === 'geo' ? '18%' : 0,
position: 'relative',
transform: `scale(${0.4 + e * 0.6})`,
opacity: Math.min(1, t * 2.2),
boxShadow: `0 ${1.6 * e}cqw ${3.4 * e}cqw rgba(24,32,29,${0.28 * e})`,
}}
>
{variant === 'luca' ? (
<>
<span
style={{
fontWeight: 900,
fontSize: `${size * 0.8}cqw`,
lineHeight: `${size * 1.08}cqw`,
position: 'absolute',
left: `${size * 0.19}cqw`,
top: 0,
}}
>
L
</span>
<span
style={{
position: 'absolute',
right: `${size * 0.08}cqw`,
top: `${-size * 0.14}cqw`,
fontSize: `${size * 0.42}cqw`,
fontWeight: 600,
}}
>
↗
</span>
</>
) : (
<span
style={{
width: `${size * 0.42}cqw`,
height: `${size * 0.42}cqw`,
border: `${Math.max(1, size * 0.09)}cqw solid #ffffff`,
borderRadius: '50%',
display: 'inline-block',
}}
/>
)}
</span>
</div>
);
};
const MORPH_GEOMETRY: Record<string, { w: number; h: number; r: number }> = {
button: { w: 30, h: 9, r: 1.2 },
capsule: { w: 40, h: 13, r: 6.5 },
circle: { w: 26, h: 26, r: 13 },
card: { w: 62, h: 40, r: 2.4 },
bar: { w: 70, h: 6, r: 3 },
square: { w: 22, h: 22, r: 2 },
};
/** morph-shape:同一容器按形状序列连续变化,标签随阶段切换。 */
export const morphShape: StageRenderer = (s, t, ctx) => {
const shapes = slist(s, 'shapes', ['button', 'capsule', 'card']);
const labels = slist(s, 'labels', ctx.options.steps);
const count = shapes.length;
const seg = 1 / count;
const index = Math.min(count - 1, Math.floor(t / seg));
const local = easeInOut((t - index * seg) / (seg * 0.7));
const from = MORPH_GEOMETRY[shapes[index]] ?? MORPH_GEOMETRY.card;
const to = MORPH_GEOMETRY[shapes[Math.min(index + 1, count - 1)]] ?? from;
const w = index === count - 1 ? from.w : from.w + (to.w - from.w) * local;
const h = index === count - 1 ? from.h : from.h + (to.h - from.h) * local;
const r = index === count - 1 ? from.r : from.r + (to.r - from.r) * local;
const label = labels[Math.min(index, Math.max(labels.length - 1, 0))] ?? '';
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
width: `${w}cqw`,
height: `${h}cqw`,
borderRadius: `${r}cqw`,
background: ctx.palette.accent,
color: '#ffffff',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '1.2cqh',
transition: 'none',
}}
>
<strong style={{ fontSize: '4.6cqw', fontWeight: 800 }}>{label}</strong>
{index === count - 1 && sstr(s, 'sub') ? (
<span style={{ fontSize: '3cqw', opacity: 0.85 }}>{sstr(s, 'sub')}</span>
) : null}
</div>
</div>
);
};
/** circle-fill:圆形色块从一点扩张铺满,完成场景切换。 */
export const circleFill: StageRenderer = (s, t, ctx) => {
const e = easeInOut(t);
const ox = snum(s, 'ox', 50);
const oy = snum(s, 'oy', 50);
const scale = e * 160;
return (
<div style={{ ...center, overflow: 'hidden' }}>
<div
style={{
position: 'absolute',
left: `${ox}%`,
top: `${oy}%`,
width: '100cqw',
aspectRatio: '1',
borderRadius: '50%',
background: ctx.palette.bg,
transform: `translate(-50%, -50%) scale(${scale / 100})`,
}}
/>
</div>
);
};
/** panel-wipe:斜向色板扫过完成换景。 */
export const panelWipe: StageRenderer = (s, t, ctx) => {
const e = easeInOut(t);
const angle = snum(s, 'angle', -14);
return (
<div style={{ ...center, overflow: 'hidden' }}>
<div
style={{
position: 'absolute',
inset: '-30%',
background: ctx.palette.bg,
transform: `translateX(${(e - 1) * 140}%) rotate(${angle}deg)`,
}}
/>
</div>
);
};
const STROKE_PATHS: Record<string, string> = {
wave: 'M4 60 C 20 30, 34 30, 50 60 S 80 90, 96 60',
spiral:
'M50 50 m0 -2 a2 2 0 1 1 -2 2 a6 6 0 1 1 6 -6 a14 14 0 1 1 -14 14 a24 24 0 1 1 24 -24 a36 36 0 1 1 -36 36',
star: 'M50 12 L58 40 L88 40 L64 58 L72 86 L50 68 L28 86 L36 58 L12 40 L42 40 Z',
loop: 'M10 70 C 10 30, 40 30, 50 50 C 60 70, 90 70, 90 40 C 90 16, 60 16, 56 36',
bolt: 'M56 8 L30 52 L48 52 L42 92 L74 42 L54 42 Z',
triangle: 'M50 14 L88 80 L12 80 Z',
};
/** stroke-draw:SVG 路径按进度描出(几何写作感)。 */
export const strokeDraw: StageRenderer = (s, t, ctx) => {
const key = sstr(s, 'path', 'wave');
const d = STROKE_PATHS[key] ?? STROKE_PATHS.wave;
const e = easeOutQuint(t);
const width = snum(s, 'stroke', 2.2);
return (
<div style={{ ...center, alignItems: 'center', justifyContent: 'center' }}>
<svg
viewBox="0 0 100 100"
style={{ width: '76cqw', height: '76cqh', overflow: 'visible' }}
aria-hidden="true"
>
<path
d={d}
fill="none"
stroke={ctx.palette.fg}
strokeOpacity={0.14}
strokeWidth={width}
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d={d}
fill="none"
stroke={ctx.palette.accent}
strokeWidth={width}
strokeLinecap="round"
strokeLinejoin="round"
strokeDasharray={260}
strokeDashoffset={260 * (1 - e)}
/>
</svg>
</div>
);
};
/** orbit-rings:同心环旋转,轨道点沿环跑,可带彗尾。 */
export const orbitRings: StageRenderer = (s, t, ctx) => {
const rings = snum(s, 'rings', 3);
const trail = sbool(s, 'trail', true);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
position: 'relative',
// 宽高双预算:环是内容主体时必须整环可见(窄高舞台不截断)。
width: 'min(74cqw, 92cqh)',
height: 'min(74cqw, 92cqh)',
}}
>
{Array.from({ length: rings }, (_, i) => {
const frac = (i + 1) / (rings + 0.4);
const dir = i % 2 ? -1 : 1;
return (
<div
key={i}
style={{
position: 'absolute',
inset: `${(1 - frac) * 46}%`,
border: `0.32cqw dashed ${ctx.palette.fg}55`,
borderRadius: '50%',
transform: `rotate(${dir * t * 360 * (1 + i * 0.35)})`,
}}
>
<span
style={{
position: 'absolute',
top: '-0.9cqw',
left: '50%',
width: '1.8cqw',
height: '1.8cqw',
borderRadius: '50%',
background: ctx.palette.accent,
boxShadow: trail
? `0 0 0 ${1.4}cqw ${ctx.palette.accent}22`
: undefined,
}}
/>
</div>
);
})}
</div>
</div>
);
};
/** radial-lines:中心放射细线依次伸出,节拍感强。 */
export const radialLines: StageRenderer = (s, t, ctx) => {
const count = snum(s, 'count', 18);
const inner = snum(s, 'inner', 12);
const len = snum(s, 'len', 22);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
{Array.from({ length: count }, (_, i) => {
const angle = (i / count) * 360;
const e = easeOutQuint((t - (i / count) * 0.5) / 0.5);
return (
<div
key={i}
style={{
position: 'absolute',
width: `${len * e}cqw`,
height: '0.34cqw',
background: i % 3 === 0 ? ctx.palette.accent : `${ctx.palette.fg}aa`,
transformOrigin: '0 50%',
transform: `rotate(${angle}deg) translateX(${inner}cqw)`,
opacity: e,
}}
/>
);
})}
</div>
);
};
/** dot-grid:点阵网格上一道扫描波经过,被扫过的点短暂放大提亮。 */
export const dotGrid: StageRenderer = (s, t, ctx) => {
const cols = snum(s, 'cols', 14);
const rows = snum(s, 'rows', 9);
const wave = t * 1.35;
const dots: ReactNode[] = [];
for (let y = 0; y < rows; y++)
for (let x = 0; x < cols; x++) {
const dist = (x / cols + y / rows) / 2;
const glow = Math.max(0, 1 - Math.abs(dist - wave) * 7);
dots.push(
<span
key={`${x}-${y}`}
style={{
width: `${0.7 + glow * 1.1}cqw`,
height: `${0.7 + glow * 1.1}cqw`,
borderRadius: '50%',
background:
glow > 0.25 ? ctx.palette.accent : `${ctx.palette.fg}44`,
transition: 'none',
}}
/>,
);
}
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
<div
style={{
display: 'grid',
gridTemplateColumns: `repeat(${cols}, auto)`,
gap: '1.6cqw',
}}
>
{dots}
</div>
</div>
);
};
/** beam-edge:暗色金属板上扫过一道高光,逐渐显出浮雕 L↗ 边缘。 */
export const beamEdge: StageRenderer = (s, t, ctx) => {
const e = easeInOut(t);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
background: ctx.palette.bg,
}}
>
<div
style={{
position: 'relative',
fontSize: '34cqw',
fontWeight: 900,
lineHeight: 1,
color: 'transparent',
WebkitTextStroke: `0.22cqw ${ctx.palette.fg}66`,
}}
>
{sstr(s, 'glyph', '◇')}
<span
aria-hidden="true"
style={{
position: 'absolute',
inset: 0,
color: 'transparent',
WebkitTextStroke: `0.3cqw ${ctx.palette.accent}`,
clipPath: `polygon(0 0, ${e * 130 - 15}% 0, ${e * 130 - 30}% 130%, 0 130%)`,
}}
>
{sstr(s, 'glyph', '◇')}
</span>
</div>
</div>
);
};
/** shard-open:两片斜面板向两侧分开,露出后方画面(开场转场)。 */
export const shardOpen: StageRenderer = (s, t, ctx) => {
const e = easeInOut(t);
const shift = e * 105;
return (
<div style={{ ...center, overflow: 'hidden' }}>
<div
style={{
position: 'absolute',
inset: '-12%',
background: ctx.palette.bg,
clipPath: 'polygon(0 0, 68% 0, 34% 100%, 0 100%)',
transform: `translateX(${-shift}%)`,
}}
/>
<div
style={{
position: 'absolute',
inset: '-12%',
background: ctx.palette.bg,
clipPath: 'polygon(72% 0, 100% 0, 100% 100%, 38% 100%)',
transform: `translateX(${shift}%)`,
}}
/>
<div
style={{
position: 'absolute',
left: '48.4%',
top: '-12%',
bottom: '-12%',
width: '0.8cqw',
background: ctx.palette.accent,
opacity: (1 - e) * 0.9,
}}
/>
</div>
);
};
/** dots-text:Canvas 点阵从散落位置聚成短文字。 */
export function DotsTextStage({
text,
color,
t,
seed,
density,
}: {
text: string;
color: string;
t: number;
seed: number;
density: number;
}) {
const dots = useMemo(() => {
return { text, seed, density };
}, [text, seed, density]);
const layout = useRef<{ x: number; y: number; sx: number; sy: number }[]>([]);
const layoutKey = useRef('');
const canvasRef = useStageCanvas(
(ctx, width, height) => {
const key = `${width}x${height}x${dots.text}`;
if (layoutKey.current !== key) {
const mask = document.createElement('canvas');
mask.width = width;
mask.height = height;
const maskCtx = mask.getContext('2d');
if (!maskCtx) return;
const fontSize = Math.min(
height * 0.42,
(width * 0.84) / Math.max(Array.from(dots.text).length, 1),
);
maskCtx.font = `800 ${fontSize}px -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif`;
maskCtx.textAlign = 'center';
maskCtx.textBaseline = 'middle';
maskCtx.fillText(dots.text, width / 2, height / 2);
const pixels = maskCtx.getImageData(0, 0, width, height).data;
const rand = mulberry32(dots.seed);
const found: typeof layout.current = [];
const gap = Math.max(3, Math.round((fontSize / 22) * (1 / dots.density)));
for (let y = 0; y < height; y += gap)
for (let x = 0; x < width; x += gap)
if (pixels[(y * width + x) * 4 + 3] > 120)
found.push({
x,
y,
sx: rand() * width,
sy: rand() * height,
});
const stride = Math.max(1, Math.ceil(found.length / 1300));
layout.current = found.filter((_, i) => i % stride === 0);
layoutKey.current = key;
}
ctx.clearRect(0, 0, width, height);
const e = easeOutQuint(Math.min(1, t * 1.05));
ctx.fillStyle = color;
for (const dot of layout.current) {
ctx.beginPath();
ctx.arc(
dot.sx + (dot.x - dot.sx) * e,
dot.sy + (dot.y - dot.sy) * e,
Math.max(1, width / 420),
0,
Math.PI * 2,
);
ctx.fill();
}
},
[t, dots.text, color, dots.seed, dots.density],
);
return (
<canvas
ref={canvasRef}
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
/>
);
}
export const dotsText: StageRenderer = (s, t, ctx) => (
<DotsTextStage
text={stageText(s, ctx).slice(0, 8)}
color={ctx.palette.accent}
t={t}
seed={hashSeed(sstr(s, 'text', 'title') + ctx.now.toFixed(0))}
density={snum(s, 'density', 1)}
/>
);
/** dots-stream:细流线横向流动的确定性粒子场。 */
export const dotsStream: StageRenderer = (s, t, ctx) => {
const lines = snum(s, 'lines', 9);
const streams = Array.from({ length: lines }, (_, i) => i);
return (
<div style={{ ...center, overflow: 'hidden' }}>
<svg
viewBox="0 0 100 62"
preserveAspectRatio="none"
style={{ width: '100%', height: '100%' }}
aria-hidden="true"
>
{streams.map((i) => {
const y = ((i + 0.5) / lines) * 62;
const phase = (t * (0.7 + (i % 3) * 0.22) + i * 0.13) % 1;
const x = -20 + phase * 140;
const amp = 3 + (i % 4);
return (
<g key={i}>
<path
d={`M0 ${y} Q 25 ${y - amp}, 50 ${y} T 100 ${y}`}
fill="none"
stroke={ctx.palette.fg}
strokeOpacity={0.1}
strokeWidth={0.22}
/>
<circle
cx={x}
cy={y - amp * Math.sin((x / 50) * Math.PI) * 0.5}
r={0.75}
fill={i % 4 === 0 ? ctx.palette.accent : ctx.palette.fg}
opacity={0.85}
/>
</g>
);
})}
</svg>
</div>
);
};
/** dots-orbit:粒子盘旋收拢成环,中心文字亮出。 */
export const dotsOrbit: StageRenderer = (s, t, ctx) => {
const count = snum(s, 'count', 42);
const text = stageText(s, ctx);
const e = easeOutQuint(t);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
}}
>
{Array.from({ length: count }, (_, i) => {
const angle = (i / count) * Math.PI * 2 + t * Math.PI * 1.6;
const radius = (34 - 12 * e) * (0.85 + ((i * 7919) % 30) / 100);
return (
<span
key={i}
style={{
position: 'absolute',
left: `${50 + Math.cos(angle) * radius}%`,
top: `${50 + Math.sin(angle) * radius * 0.86}%`,
width: '1.3cqw',
height: '1.3cqw',
borderRadius: '50%',
background: i % 5 === 0 ? ctx.palette.accent : `${ctx.palette.fg}99`,
opacity: Math.min(1, t * 3),
}}
/>
);
})}
<strong
style={{
fontSize: '8cqw',
fontWeight: 900,
color: ctx.palette.fg,
opacity: easeOutQuint((t - 0.45) / 0.5),
transform: ctx.captionSafe ? 'translateY(-8cqh)' : undefined,
}}
>
{text}
</strong>
</div>
);
};
/** confetti-drift:纸屑缓慢下落漂移(庆祝/周年类)。 */
export const confettiDrift: StageRenderer = (s, t, ctx) => {
const count = snum(s, 'count', 26);
const pieces = Array.from({ length: count }, (_, i) => {
const seedX = ((i * 137) % 100) / 100;
const speed = 0.5 + ((i * 61) % 50) / 100;
const y = ((t * speed + (i % 7) / 7) % 1) * 118 - 9;
const sway = Math.sin(t * 2.2 + i) * 2.2;
const shape = i % 3;
const isAccent = i % 4 === 0;
return (
<span
key={i}
style={{
position: 'absolute',
left: `${seedX * 100 + sway}%`,
top: `${y}%`,
width: shape === 0 ? '1.7cqw' : '1.5cqw',
height: shape === 0 ? '1cqw' : '1.5cqw',
background: isAccent ? ctx.palette.accent : `${ctx.palette.fg}77`,
borderRadius: shape === 1 ? '50%' : shape === 2 ? '50% 0 50% 50%' : '0.2cqw',
transform: `rotate(${t * 90 + i * 30}deg)`,
opacity: 0.9,
}}
/>
);
});
return <div style={{ ...center, overflow: 'hidden' }}>{pieces}</div>;
};
/** backdrop:纯底色板——由引擎以铺满层方式绘制,返回空内容。 */
export const backdropPlate: StageRenderer = () => null;
export const SHAPE_STAGES: Record<string, StageRenderer> = {
'backdrop': backdropPlate,
'brand-pop': brandPop,
'morph-shape': morphShape,
'circle-fill': circleFill,
'panel-wipe': panelWipe,
'stroke-draw': strokeDraw,
'orbit-rings': orbitRings,
'radial-lines': radialLines,
'dot-grid': dotGrid,
'beam-edge': beamEdge,
'shard-open': shardOpen,
'dots-text': dotsText,
'dots-stream': dotsStream,
'dots-orbit': dotsOrbit,
'confetti-drift': confettiDrift,
};
import type { CSSProperties } from 'react';
import type { StageRenderer } from './case-engine';
import { easeOutBack, easeOutQuint } from './case-timeline';
import { countAt, ease, mix } from './motion-core';
import { clamp01, donutValueAt } from './case-timeline';
import {
slist,
snum,
sstr,
stageLines,
stageText,
} from './case-engine';
const center: CSSProperties = {
position: 'absolute',
inset: 0,
display: 'flex',
};
const windowChrome: CSSProperties = {
position: 'absolute',
left: '8cqw',
right: '8cqw',
top: '10cqh',
bottom: '10cqh',
borderRadius: '1.6cqw',
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
};
function titleBar(paletteBg: string, line: string, dots = '#d8dcd5') {
return (
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '0.9cqw',
padding: '1.2cqw 1.6cqw',
borderBottom: `1px solid ${line}`,
background: paletteBg,
}}
>
{[0, 1, 2].map((i) => (
<span
key={i}
style={{
width: '0.9cqw',
height: '0.9cqw',
borderRadius: '50%',
background: dots,
}}
/>
))}
</div>
);
}
/** ui-window:浏览器窗口里地址栏键入、内容块依次落位。 */
export const uiWindow: StageRenderer = (s, t, ctx) => {
const line = `${ctx.palette.fg}22`;
const url = sstr(s, 'url', 'lucahub.cn/lab/motion');
const urlChars = Array.from(url);
const typed = Math.floor(easeOutQuint(Math.min(1, t * 1.5)) * urlChars.length);
const rows = stageLines(s, ctx);
const goIn = easeOutBack((t - 0.18) / 0.3);
return (
<div style={{ ...center, alignItems: 'center', justifyContent: 'center' }}>
<div
style={{
...windowChrome,
background: ctx.palette.bg,
border: `1px solid ${line}`,
boxShadow: `0 2cqw 5cqw rgba(24,32,29,0.14)`,
transform: `translateY(${(1 - easeOutQuint(Math.min(1, t * 2))) * 6}cqh)`,
}}
>
{titleBar(ctx.palette.bg, line)}
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '1cqw',
padding: '1.1cqw 1.6cqw',
borderBottom: `1px solid ${line}`,
}}
>
<div
style={{
flex: 1,
background: `${ctx.palette.fg}0d`,
borderRadius: '1cqw',
padding: '0.8cqw 1.4cqw',
fontSize: '2.6cqw',
color: `${ctx.palette.fg}bb`,
whiteSpace: 'nowrap',
overflow: 'hidden',
}}
>
{urlChars.slice(0, typed).join('')}
<span
style={{
display: 'inline-block',
width: '0.4cqw',
height: '1em',
background: ctx.palette.accent,
verticalAlign: '-0.15em',
opacity: typed < urlChars.length ? 1 : 0,
}}
/>
</div>
<span
style={{
background: ctx.palette.accent,
color: '#ffffff',
borderRadius: '1cqw',
padding: '0.6cqw 1.6cqw',
fontSize: '2.6cqw',
fontWeight: 700,
opacity: Math.max(0, goIn),
transform: `scale(${Math.max(0, goIn)})`,
}}
>
前往
</span>
</div>
<div
style={{
flex: 1,
display: 'grid',
gridTemplateColumns: '1fr 1fr',
gap: '1.4cqw',
padding: '1.6cqw',
alignContent: 'start',
}}
>
{rows.map((row, i) => {
const e = easeOutQuint((t - 0.36 - i * 0.09) / 0.3);
return (
<div
key={i}
style={{
borderRadius: '1.1cqw',
border: `1px solid ${line}`,
padding: '1.3cqw',
background: i === 0 ? `${ctx.palette.accent}12` : 'transparent',
opacity: e,
transform: `translateY(${(1 - e) * 3}cqh)`,
}}
>
<div
style={{
fontSize: '2.7cqw',
fontWeight: 700,
color: ctx.palette.fg,
}}
>
{row}
</div>
<div
style={{
marginTop: '0.9cqw',
height: '0.5cqw',
borderRadius: 1,
background: i === 0 ? ctx.palette.accent : `${ctx.palette.fg}2e`,
width: `${64 + ((i * 23) % 30)}%`,
}}
/>
</div>
);
})}
</div>
</div>
</div>
);
};
/** ui-phone:手机屏从底部升入,页头、卡片与键盘分段出现。 */
export const uiPhone: StageRenderer = (s, t, ctx) => {
const line = `${ctx.palette.fg}22`;
const rows = stageLines(s, ctx);
const frameIn = easeOutQuint(Math.min(1, t * 1.35));
const keyboard = easeOutQuint((t - 0.55) / 0.35);
return (
<div style={{ ...center, alignItems: 'center', justifyContent: 'center' }}>
<div
style={{
width: '38cqw',
height: '80cqh',
borderRadius: '3.4cqw',
border: `0.5cqw solid ${ctx.palette.fg}`,
background: ctx.palette.bg,
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
transform: `translateY(${(1 - frameIn) * 30}cqh)`,
boxShadow: '0 2cqw 6cqw rgba(24,32,29,0.16)',
}}
>
<div
style={{
padding: 'min(2cqw, 2.4cqh)',
borderBottom: `1px solid ${line}`,
fontWeight: 800,
fontSize: 'min(3.2cqw, 3.8cqh)',
color: ctx.palette.fg,
}}
>
{stageText(s, ctx)}
</div>
<div
style={{
flex: 1,
padding: 'min(1.6cqw, 1.8cqh)',
display: 'grid',
gap: 'min(1.2cqw, 1.4cqh)',
alignContent: 'start',
}}
>
{rows.map((row, i) => {
const e = easeOutQuint((t - 0.3 - i * 0.09) / 0.3);
return (
<div
key={i}
style={{
borderRadius: '1.2cqw',
background: i === 0 ? `${ctx.palette.accent}16` : `${ctx.palette.fg}0a`,
padding: 'min(1.3cqw, 1.6cqh)',
fontSize: 'min(2.6cqw, 3.2cqh)',
fontWeight: 600,
color: ctx.palette.fg,
opacity: e,
transform: `translateX(${(1 - e) * (i % 2 ? 6 : -6)}cqw)`,
}}
>
{row}
</div>
);
})}
</div>
<div
style={{
padding: 'min(1.2cqw, 1.4cqh)',
borderTop: `1px solid ${line}`,
display: 'grid',
gridTemplateColumns: 'repeat(10, 1fr)',
gap: 'min(0.5cqw, 0.6cqh)',
opacity: keyboard,
transform: `translateY(${(1 - keyboard) * 100}%)`,
}}
>
{'QWERTYUIOPASDFGHJKLZXCVBNM'.split('').map((key) => (
<span
key={key}
style={{
background: `${ctx.palette.fg}20`,
borderRadius: '0.5cqw',
fontSize: 'min(1.5cqw, 1.8cqh)',
textAlign: 'center',
padding: 'min(0.55cqw, 0.7cqh) 0',
color: ctx.palette.fg,
}}
>
{key}
</span>
))}
</div>
</div>
</div>
);
};
/** ui-rows:列表行骨架到内容依次替换,像数据加载完成。 */
export const uiRows: StageRenderer = (s, t, ctx) => {
const rows = stageLines(s, ctx);
const line = `${ctx.palette.fg}1e`;
return (
<div
style={{
...center,
flexDirection: 'column',
justifyContent: 'center',
gap: '1.6cqh',
padding: '0 12cqw',
}}
>
{rows.map((row, i) => {
const e = easeOutQuint((t - i * 0.14) / 0.4);
const loaded = easeOutQuint((t - 0.3 - i * 0.14) / 0.35);
return (
<div
key={i}
style={{
width: '100%',
display: 'flex',
alignItems: 'center',
gap: '1.6cqw',
border: `1px solid ${line}`,
borderRadius: '1.2cqw',
padding: '1.5cqw 1.8cqw',
background: ctx.palette.bg,
opacity: e,
transform: `translateY(${(1 - e) * 4}cqh)`,
}}
>
<span
style={{
width: '2.6cqw',
height: '2.6cqw',
borderRadius: '50%',
background: i === 0 ? ctx.palette.accent : `${ctx.palette.fg}30`,
transform: `scale(${e})`,
}}
/>
<span
style={{
fontSize: '3.2cqw',
fontWeight: 700,
color: ctx.palette.fg,
opacity: loaded,
}}
>
{row}
</span>
<span
style={{
marginLeft: 'auto',
width: '18%',
height: '0.55cqw',
borderRadius: 1,
background: loaded > 0.9 ? ctx.palette.accent : `${ctx.palette.fg}26`,
}}
/>
</div>
);
})}
</div>
);
};
/** ui-slider:滑杆从起点滑到目标值,气泡数字跟随。 */
export const uiSlider: StageRenderer = (s, t, ctx) => {
const label = sstr(s, 'label', ctx.options.text);
const from = ctx.options.from;
const to = ctx.options.to;
const trackIn = easeOutQuint(Math.min(1, t * 2));
const value = Math.round(mix(from, to, ease(t * 0.82)));
const frac = (value - from) / Math.max(to - from, 1);
return (
<div
style={{
...center,
flexDirection: 'column',
justifyContent: 'center',
gap: '3cqh',
padding: '0 10cqw',
}}
>
<div
style={{
fontSize: '3.4cqw',
fontWeight: 700,
color: `${ctx.palette.fg}cc`,
opacity: trackIn,
}}
>
{label}
</div>
<div style={{ position: 'relative', width: '100%' }}>
<div
style={{
position: 'absolute',
left: `${frac * 100}%`,
top: '-11cqh',
transform: 'translateX(-50%)',
background: ctx.palette.accent,
color: '#ffffff',
borderRadius: '1cqw',
padding: '0.7cqw 1.4cqw',
fontSize: '3cqw',
fontWeight: 800,
opacity: t > 0.08 ? 1 : 0,
transition: 'none',
}}
>
{value}
</div>
<div
style={{
height: '0.9cqw',
borderRadius: 1,
background: `${ctx.palette.fg}22`,
position: 'relative',
overflow: 'visible',
}}
>
<div
style={{
position: 'absolute',
inset: 0,
width: `${frac * 100}%`,
borderRadius: 1,
background: ctx.palette.accent,
}}
/>
<span
style={{
position: 'absolute',
left: `${frac * 100}%`,
top: '50%',
width: '2.8cqw',
height: '2.8cqw',
borderRadius: '50%',
background: '#ffffff',
border: `0.45cqw solid ${ctx.palette.accent}`,
transform: 'translate(-50%, -50%)',
boxShadow: '0 0.5cqw 1.4cqw rgba(24,32,29,0.2)',
}}
/>
</div>
</div>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
width: '100%',
fontSize: '2.6cqw',
color: ctx.palette.fg,
opacity: 0.72 * trackIn,
}}
>
<span>{from}</span>
<span>演示数值</span>
<span>{to}</span>
</div>
</div>
);
};
/** ui-toast:按钮按下后通知卡弹入,带对勾。 */
export const uiToast: StageRenderer = (s, t, ctx) => {
const press = easeOutQuint(Math.min(1, t / 0.3));
const release = easeOutQuint((t - 0.3) / 0.18);
const toast = easeOutBack(Math.max(0, (t - 0.42) / 0.4));
const toastText = sstr(s, 'toast', ctx.options.steps[0] ?? '已完成');
const sub = sstr(s, 'sub', ctx.options.steps[1] ?? '');
return (
<div
style={{
...center,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '4cqh',
}}
>
<div
style={{
background: '#18201d',
color: '#ffffff',
borderRadius: '1.4cqw',
padding: '1.6cqw 4cqw',
fontSize: '3.6cqw',
fontWeight: 800,
transform: `scale(${press * (1 - release * 0.06) + release * 0.06})`,
boxShadow: '0 1cqw 2.6cqw rgba(24,32,29,0.24)',
}}
>
{stageText(s, ctx)}
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '1.6cqw',
background: '#ffffff',
border: '1px solid rgba(24,32,29,0.15)',
borderRadius: '1.4cqw',
padding: '1.6cqw 2.2cqw',
minWidth: '52cqw',
opacity: Math.max(0, toast),
transform: `translateY(${(1 - toast) * 8}cqh) scale(${0.9 + toast * 0.1})`,
boxShadow: '0 1.4cqw 3.4cqw rgba(24,32,29,0.18)',
}}
>
<span
style={{
width: '3cqw',
height: '3cqw',
borderRadius: '50%',
background: '#18201d',
color: '#ffffff',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '2cqw',
fontWeight: 900,
flexShrink: 0,
}}
>
✓
</span>
<span>
<strong
style={{
display: 'block',
fontSize: '3cqw',
color: '#18201d',
}}
>
{toastText}
</strong>
{sub ? (
<small style={{ fontSize: '2.4cqw', color: 'rgba(24,32,29,0.73)' }}>
{sub}
</small>
) : null}
</span>
</div>
</div>
);
};
/** ui-cursor:光标在两个目标间移动并点击,涟漪扩散。 */
export const uiCursor: StageRenderer = (s, t, ctx) => {
const targets = [
{ x: 30, y: 42 },
{ x: 66, y: 60 },
];
const phase = t < 0.5 ? 0 : 1;
const segT = (t * 2) % 1;
const [a, b] = [targets[phase], targets[(phase + 1) % 2]];
const x = mix(a.x, b.x, ease(segT));
const y = mix(a.y, b.y, ease(segT));
const click = segT > 0.82;
const ripple = (segT - 0.82) / 0.18;
const labels = stageLines(s, ctx);
return (
<div style={{ ...center }}>
{targets.map((target, i) => (
<div
key={i}
style={{
position: 'absolute',
left: `${target.x}%`,
top: `${target.y}%`,
transform: 'translate(-50%, -50%)',
background: i === 0 ? ctx.palette.accent : ctx.palette.bg,
color: i === 0 ? '#ffffff' : ctx.palette.fg,
border: i === 0 ? 'none' : `1px solid ${ctx.palette.fg}33`,
borderRadius: '1.2cqw',
padding: '1.4cqw 2.6cqw',
fontSize: '3cqw',
fontWeight: 700,
}}
>
{labels[i] ?? stageText(s, ctx)}
</div>
))}
<span
style={{
position: 'absolute',
left: `${x}%`,
top: `${y}%`,
fontSize: '3.4cqw',
transform: 'translate(-12%, -8%)',
filter: 'drop-shadow(0 0.3cqw 0.6cqw rgba(24,32,29,0.3))',
}}
>
▸
</span>
{click ? (
<span
style={{
position: 'absolute',
left: `${b.x}%`,
top: `${b.y}%`,
width: `${4 + ripple * 7}cqw`,
height: `${4 + ripple * 7}cqw`,
borderRadius: '50%',
border: `0.35cqw solid ${ctx.palette.accent}`,
transform: 'translate(-50%, -50%)',
opacity: 1 - ripple,
}}
/>
) : null}
</div>
);
};
/** chart-bars:柱状图逐根长出,柱顶带演示数值。 */
export const chartBars: StageRenderer = (s, t, ctx) => {
const labels = stageLines(s, ctx);
const values = slist(s, 'values', ['32', '58', '41', '76', '63']).map(Number);
const max = Math.max(...values, 1);
return (
<div
style={{
...center,
flexDirection: 'column',
justifyContent: 'flex-end',
padding: '8cqh 10cqw 7cqh',
}}
>
<div
style={{
display: 'flex',
alignItems: 'flex-end',
gap: '2.4cqw',
width: '100%',
height: '100%',
borderBottom: `2px solid ${ctx.palette.fg}44`,
paddingBottom: '0.5cqh',
}}
>
{labels.map((label, i) => {
const e = easeOutQuint((t - i * 0.1) / 0.42);
const value = values[i % values.length];
return (
<div
key={i}
style={{
flex: 1,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '1cqh',
height: '100%',
justifyContent: 'flex-end',
}}
>
<span
style={{
fontSize: '2.6cqw',
fontWeight: 800,
color: ctx.palette.fg,
opacity: e > 0.5 ? 1 : 0,
}}
>
{Math.round(value * e)}
</span>
<div
style={{
width: '100%',
height: `${(value / max) * 62 * e}cqh`,
background: i === labels.length - 1 ? ctx.palette.accent : `${ctx.palette.fg}55`,
borderRadius: '0.7cqw 0.7cqw 0 0',
}}
/>
<span
style={{
fontSize: '2.4cqw',
color: ctx.palette.fg,
opacity: 0.78 * e,
whiteSpace: 'nowrap',
}}
>
{label}
</span>
</div>
);
})}
</div>
<span
style={{
marginTop: '1.4cqh',
fontSize: '2.2cqw',
color: `${ctx.palette.fg}77`,
}}
>
演示数值,可在参数中修改文字
</span>
</div>
);
};
/** chart-line:折线逐段绘出,数据点弹出。 */
export const chartLine: StageRenderer = (s, t, ctx) => {
const labels = stageLines(s, ctx);
const points = labels.map(
(_, i) => 24 + ((i * 37 + 13) % 46) + (i === labels.length - 1 ? 10 : 0),
);
const width = 100;
const height = 60;
const coords = points.map(
(value, i) =>
`${(i / Math.max(points.length - 1, 1)) * width},${height - value}`,
);
const total = points.length;
const drawn = easeOutQuint(Math.min(1, t * 1.1)) * (total - 1);
const visibleCoords = coords.filter((_, i) => i <= Math.ceil(drawn));
return (
<div
style={{
...center,
flexDirection: 'column',
justifyContent: 'center',
padding: '0 9cqw',
}}
>
<svg viewBox={`0 0 ${width} ${height}`} style={{ width: '100%' }} aria-hidden="true">
<polyline
points={visibleCoords.join(' ')}
fill="none"
stroke={ctx.palette.accent}
strokeWidth={1.6}
strokeLinecap="round"
strokeLinejoin="round"
/>
{coords.map((coord, i) =>
i <= Math.floor(drawn) ? (
<circle
key={i}
cx={coord.split(',')[0]}
cy={coord.split(',')[1]}
r={1.7}
fill={ctx.palette.bg}
stroke={ctx.palette.accent}
strokeWidth={1.2}
/>
) : null,
)}
</svg>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
width: '100%',
marginTop: '1cqh',
}}
>
{labels.map((label, i) => (
<span
key={i}
style={{
fontSize: '2.4cqw',
color: ctx.palette.fg,
opacity: 0.78 * easeOutQuint((t - i * 0.08) / 0.3),
}}
>
{label}
</span>
))}
</div>
</div>
);
};
/** chart-donut:环形图扫过 + 中心计数(百分比 0–100)。 */
export const chartDonut: StageRenderer = (s, t, ctx) => {
const label = sstr(s, 'label', ctx.options.text);
// 动画进度:前 85% 完成扫入,后 15% 停留在目标值(终点精确 = 1)
const frac = ease(clamp01(t / 0.85));
// 百分比边界 0–100:from/to 钳制后插值,读数、圆弧、提示词一致
const from = clamp01(ctx.options.from / 100) * 100;
const to = clamp01(ctx.options.to / 100) * 100;
const value = donutValueAt(from, to, frac);
// 弧比例 = 当前数据值的百分比(非时间进度)
const ratio = clamp01(value / 100);
const radius = 30;
const circumference = 2 * Math.PI * radius;
// 前景色与底板同色时弧不可见;用对比前景色(底板越深前景越亮)
const arcColor = ctx.palette.fg;
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
gap: '5cqw',
flexDirection: 'row',
}}
>
<svg viewBox="0 0 80 80" style={{ width: '42cqw' }} aria-hidden="true">
<circle
cx="40"
cy="40"
r={radius}
fill="none"
stroke={`${ctx.palette.fg}1e`}
strokeWidth={9}
/>
<circle
cx="40"
cy="40"
r={radius}
fill="none"
stroke={arcColor}
strokeWidth={9}
strokeLinecap="round"
strokeDasharray={circumference}
strokeDashoffset={circumference * (1 - ratio)}
transform="rotate(-90 40 40)"
/>
</svg>
<div>
<strong
style={{
fontSize: '11cqw',
fontWeight: 900,
color: ctx.palette.fg,
display: 'block',
}}
>
{value}%
</strong>
<span style={{ fontSize: '3cqw', color: ctx.palette.fg, opacity: 0.78 }}>
{label}
</span>
<small
style={{
display: 'block',
marginTop: '1cqh',
fontSize: '2.2cqw',
color: `${ctx.palette.fg}77`,
}}
>
演示数值
</small>
</div>
</div>
);
};
/** chart-count:大数字滚动 + 变化标签,数字来自参数区间。 */
export const chartCount: StageRenderer = (s, t, ctx) => {
const label = sstr(s, 'label', ctx.options.text);
const value = countAt(ctx.options.from, ctx.options.to, t * 0.9);
const delta = easeOutBack((t - 0.6) / 0.4);
return (
<div
style={{
...center,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '2cqh',
}}
>
<span
style={{
fontSize: '3.6cqw',
fontWeight: 700,
color: `${ctx.palette.fg}bb`,
opacity: easeOutQuint(Math.min(1, t * 3)),
}}
>
{label}
</span>
<strong
style={{
fontSize: '26cqw',
fontWeight: 900,
lineHeight: 1,
letterSpacing: '-0.03em',
color: ctx.palette.fg,
}}
>
{new Intl.NumberFormat('zh-CN', { maximumFractionDigits: 2 }).format(
value,
)}
</strong>
<span
style={{
background: '#18201d',
color: '#ffffff',
borderRadius: '2cqw',
padding: '0.8cqw 2cqw',
fontSize: '3cqw',
fontWeight: 800,
opacity: Math.max(0, delta),
transform: `scale(${Math.max(0, delta)})`,
}}
>
演示数值 · 过程可见
</span>
</div>
);
};
/** flow-nodes:节点依次亮起,连线在节点之间延伸。 */
export const flowNodes: StageRenderer = (s, t, ctx) => {
const nodes = stageLines(s, ctx);
const vertical = sstr(s, 'layout', 'h') === 'v';
const positions = nodes.map((_, i) =>
vertical
? { x: 50, y: 14 + (i * 72) / Math.max(nodes.length - 1, 1) }
: { x: 12 + (i * 76) / Math.max(nodes.length - 1, 1), y: 50 },
);
return (
<div style={{ ...center }}>
<svg
viewBox="0 0 100 100"
preserveAspectRatio="none"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
aria-hidden="true"
>
{positions.slice(0, -1).map((pos, i) => {
const e = easeOutQuint((t - (i + 0.55) / nodes.length) / 0.3);
const next = positions[i + 1];
return (
<line
key={i}
x1={pos.x}
y1={pos.y}
x2={mix(pos.x, next.x, e)}
y2={mix(pos.y, next.y, e)}
stroke={ctx.palette.accent}
strokeWidth={0.8}
strokeDasharray="2.4 1.6"
opacity={e > 0 ? 0.9 : 0}
/>
);
})}
</svg>
{nodes.map((node, i) => {
const e = easeOutBack((t - (i * 0.6) / nodes.length) / 0.35);
const pos = positions[i];
return (
<div
key={i}
style={{
position: 'absolute',
left: `${pos.x}%`,
top: `${pos.y}%`,
transform: `translate(-50%, -50%) scale(${Math.max(0, e)})`,
background: i === nodes.length - 1 ? '#ffffff' : ctx.palette.bg,
color: i === nodes.length - 1 ? '#18201d' : ctx.palette.fg,
border: `1px solid ${i === nodes.length - 1 ? ctx.palette.accent : ctx.palette.fg + '44'}`,
borderRadius: '1.2cqw',
padding: '1.2cqw 2cqw',
fontSize: '2.9cqw',
fontWeight: 700,
whiteSpace: 'nowrap',
boxShadow: '0 0.6cqw 1.6cqw rgba(24,32,29,0.12)',
}}
>
{node}
</div>
);
})}
</div>
);
};
/** timeline-dot:横向时间轴里程碑依次点亮。 */
export const timelineDot: StageRenderer = (s, t, ctx) => {
const milestones = stageLines(s, ctx);
return (
<div
style={{
...center,
flexDirection: 'column',
justifyContent: 'center',
padding: '0 8cqw',
}}
>
<div style={{ position: 'relative', width: '100%' }}>
<div
style={{
position: 'absolute',
left: 0,
top: '50%',
width: '100%',
height: '0.5cqw',
background: `${ctx.palette.fg}22`,
}}
/>
<div
style={{
position: 'absolute',
left: 0,
top: '50%',
width: `${ease(t * 0.9) * 100}%`,
height: '0.5cqw',
background: ctx.palette.accent,
}}
/>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
position: 'relative',
}}
>
{milestones.map((milestone, i) => {
const e = easeOutBack((t - (i * 0.75) / milestones.length) / 0.3);
return (
<div
key={i}
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: '1.2cqh',
transform: `scale(${Math.max(0, e)})`,
opacity: Math.max(0, e),
}}
>
<span
style={{
fontSize: '2.5cqw',
color: ctx.palette.fg,
opacity: 0.75,
}}
>
{`0${i + 1}`}
</span>
<span
style={{
width: '2.2cqw',
height: '2.2cqw',
borderRadius: '50%',
background: i === milestones.length - 1 ? ctx.palette.accent : ctx.palette.bg,
border: `0.4cqw solid ${ctx.palette.accent}`,
}}
/>
<span
style={{
fontSize: '2.9cqw',
fontWeight: 700,
color: ctx.palette.fg,
whiteSpace: 'nowrap',
}}
>
{milestone}
</span>
</div>
);
})}
</div>
</div>
</div>
);
};
/** branch-tree:分叉树逐层绘出,末端节点强调(讲解拆解/递归)。 */
export const branchTree: StageRenderer = (s, t, ctx) => {
const depth = snum(s, 'depth', 3);
const label = stageText(s, ctx);
const nodes: { x: number; y: number; layer: number }[] = [{ x: 50, y: 12, layer: 0 }];
for (let layer = 1; layer <= depth; layer++) {
const count = 2 ** layer;
for (let i = 0; i < count; i++)
nodes.push({
x: 8 + (84 * (i + 0.5)) / count,
y: 12 + (layer * 26),
layer,
});
}
const layerT = (layer: number) =>
easeOutQuint((t - layer * (0.8 / (depth + 1))) / (0.8 / (depth + 1)));
return (
<div style={{ ...center }}>
<svg
viewBox="0 0 100 100"
preserveAspectRatio="none"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
aria-hidden="true"
>
{nodes.slice(1).map((node, i) => {
const parent = nodes[Math.floor(i / 2)];
const e = layerT(node.layer);
return (
<line
key={i}
x1={parent.x}
y1={parent.y}
x2={mix(parent.x, node.x, e)}
y2={mix(parent.y, node.y, e)}
stroke={node.layer === depth ? ctx.palette.accent : `${ctx.palette.fg}55`}
strokeWidth={0.7}
/>
);
})}
{nodes.map((node, i) => (
<circle
key={`n${i}`}
cx={node.x}
cy={node.y}
r={node.layer === 0 ? 2.4 : 1.6}
fill={node.layer === depth ? ctx.palette.accent : ctx.palette.bg}
stroke={ctx.palette.fg}
strokeOpacity={0.5}
strokeWidth={0.5}
opacity={layerT(node.layer)}
/>
))}
</svg>
<span
style={{
position: 'absolute',
left: '50%',
top: '3%',
transform: 'translateX(-50%)',
fontSize: '3cqw',
fontWeight: 800,
color: ctx.palette.fg,
opacity: easeOutQuint(Math.min(1, t * 3)),
}}
>
{label}
</span>
</div>
);
};
/** spectrum-bars:确定性 BPM 节拍的均衡器条(无音频联动)。 */
export const spectrumBars: StageRenderer = (s, t, ctx) => {
const bars = snum(s, 'bars', 16);
const bpm = Math.round(mix(ctx.options.from, ctx.options.to, ease(t * 0.7)));
const beat = (ctx.now * bpm) / 60;
const label = sstr(s, 'label', '节奏 · 演示值');
return (
<div
style={{
...center,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: '2.4cqh',
}}
>
<div
style={{
display: 'flex',
alignItems: 'flex-end',
gap: '1.1cqw',
height: '34cqh',
}}
>
{Array.from({ length: bars }, (_, i) => {
const wave =
Math.abs(Math.sin(beat * Math.PI + i * 0.7)) * (0.35 + ((i * 37) % 60) / 100);
const height = 8 + wave * 88;
return (
<span
key={i}
style={{
width: `${(70 / bars) * 0.8}cqw`,
height: `${height}%`,
background: i % 4 === 0 ? ctx.palette.accent : `${ctx.palette.fg}66`,
borderRadius: '0.4cqw 0.4cqw 0 0',
}}
/>
);
})}
</div>
<span
style={{
fontSize: '3.2cqw',
fontWeight: 800,
color: ctx.palette.fg,
}}
>
{bpm} BPM
</span>
<small style={{ fontSize: '2.3cqw', color: `${ctx.palette.fg}77` }}>
{label} · 确定性时间轴,不含音频
</small>
</div>
);
};
export const UI_STAGES: Record<string, StageRenderer> = {
'ui-window': uiWindow,
'ui-phone': uiPhone,
'ui-rows': uiRows,
'ui-slider': uiSlider,
'ui-toast': uiToast,
'ui-cursor': uiCursor,
'chart-bars': chartBars,
'chart-line': chartLine,
'chart-donut': chartDonut,
'chart-count': chartCount,
'flow-nodes': flowNodes,
'timeline-dot': timelineDot,
'branch-tree': branchTree,
'spectrum-bars': spectrumBars,
};
import type { CSSProperties, ReactNode } from 'react';
import type { StageRenderer } from './case-engine';
import type { CollageLayerData } from './case-timeline';
import { clamp01, easeInOut, easeOutQuint } from './case-timeline';
import { ease, mix } from './motion-core';
import {
sbool,
slist,
snum,
sstr,
stageFontSize,
stageLines,
stageText,
} from './case-engine';
const center: CSSProperties = {
position: 'absolute',
inset: 0,
display: 'flex',
};
type ScenePalette = { sky: string; far: string; near: string; sun: string };
const SCENES: Record<string, ScenePalette> = {
day: { sky: '#dfe8f2', far: '#b7c9dd', near: '#5f7d5a', sun: '#f2c94c' },
dusk: { sky: '#2b2440', far: '#4b3a63', near: '#241f33', sun: '#f2994a' },
night: { sky: '#10141f', far: '#1d2436', near: '#0c101a', sun: '#e8eef7' },
spring: { sky: '#e8f0df', far: '#c3d9b4', near: '#6f9b62', sun: '#f4d35e' },
winter: { sky: '#e9edf2', far: '#cdd8e3', near: '#8fa3b8', sun: '#f0f4f8' },
paper: { sky: '#f6f1e7', far: '#e5d9c3', near: '#c9b28e', sun: '#e2a13c' },
};
/** scene-pan:分层纸艺风景横向平移,远景慢、近景快。 */
export const scenePan: StageRenderer = (s, t, ctx) => {
const scene = SCENES[sstr(s, 'scene', 'day')] ?? SCENES.day;
const drift = ease(t) * 100;
const label = stageText(s, ctx);
const labelIn = easeOutQuint((t - 0.62) / 0.38);
return (
<div style={{ ...center, overflow: 'hidden', background: scene.sky }}>
<svg
viewBox="0 0 200 100"
preserveAspectRatio="xMidYMax slice"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
aria-hidden="true"
>
<circle cx={150 - drift * 0.15} cy="24" r="9" fill={scene.sun} />
{[0, 1].map((k) => (
<g key={k} transform={`translate(${-drift * 0.3 + k * 200} 0)`}>
<path
d="M0 74 L26 46 L52 70 L80 40 L108 68 L134 50 L166 74 L200 56 L200 100 L0 100 Z"
fill={scene.far}
/>
</g>
))}
{[0, 1].map((k) => (
<g key={k} transform={`translate(${-drift * 0.7 + k * 200} 0)`}>
<path
d="M0 88 L34 66 L62 84 L96 62 L128 86 L160 68 L200 88 L200 100 L0 100 Z"
fill={scene.near}
/>
</g>
))}
</svg>
<strong
style={{
position: 'absolute',
left: 0,
right: 0,
top: '16%',
textAlign: 'center',
fontSize: stageFontSize(s, 'lg'),
fontWeight: 900,
color: easeInOut(1) === 1 ? shadeText(scene.sky) : '#ffffff',
opacity: labelIn,
transform: `translateY(${(1 - labelIn) * 3}cqh)`,
textShadow:
shadeText(scene.sky) === '#ffffff'
? '0 0.3cqw 1.4cqw rgba(0,0,0,0.35)'
: 'none',
}}
>
{label}
</strong>
</div>
);
};
function shadeText(sky: string) {
return sky === '#dfe8f2' || sky === '#e8f0df' || sky === '#e9edf2' || sky === '#f6f1e7'
? '#18201d'
: '#ffffff';
}
/** scene-vehicle:自绘小车/纸飞机穿过分层场景,轮组真实转动。 */
export const sceneVehicle: StageRenderer = (s, t, ctx) => {
const scene = SCENES[sstr(s, 'scene', 'paper')] ?? SCENES.paper;
const vehicle = sstr(s, 'vehicle', 'bike');
const x = 6 + ease(t) * 82;
const wheelTurn = t * 720;
return (
<div style={{ ...center, overflow: 'hidden', background: scene.sky }}>
<svg
viewBox="0 0 200 100"
preserveAspectRatio="xMidYMax slice"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
aria-hidden="true"
>
<circle cx={40} cy={20} r="8" fill={scene.sun} />
{[0, 1].map((k) => (
<g key={k} transform={`translate(${-t * 30 + k * 200} 0)`}>
<path d="M0 70 Q 40 52 80 68 T 200 66 L200 100 L0 100 Z" fill={scene.far} />
</g>
))}
<rect x="0" y="86" width="200" height="14" fill={scene.near} />
</svg>
<strong
style={{
position: 'absolute',
left: 0,
right: 0,
top: ctx.captionSafe ? '5cqh' : '12%',
textAlign: 'center',
fontSize: stageFontSize(s, 'md'),
fontWeight: 800,
color: shadeText(scene.sky),
textShadow:
shadeText(scene.sky) === '#ffffff'
? '0 0.3cqw 1.4cqw rgba(0,0,0,0.35)'
: 'none',
}}
>
{stageText(s, ctx)}
</strong>
<div
style={{
position: 'absolute',
left: `${x}%`,
bottom: '9%',
transform: 'translateX(-50%)',
}}
>
<svg
viewBox="0 0 120 70"
style={{ width: '34cqw', display: 'block' }}
aria-hidden="true"
>
{vehicle === 'plane' ? (
<g transform={`rotate(${Math.sin(t * 5) * 4} 60 40)`}>
<path d="M6 40 L86 30 L112 40 L86 50 Z" fill={ctx.palette.accent} />
<path d="M40 34 L58 18 L66 20 L52 36 Z" fill={shadeText(scene.sky) === '#18201d' ? '#18201d' : '#ffffff'} />
</g>
) : (
<g>
<rect x="30" y="18" width="44" height="20" rx="6" fill={ctx.palette.accent} />
<circle cx="60" cy="16" r="7" fill="none" stroke={ctx.palette.fg} strokeWidth="3" />
<g transform={`rotate(${wheelTurn} 34 52)`}>
<circle cx="34" cy="52" r="13" fill="none" stroke={ctx.palette.fg} strokeWidth="3" />
<line x1="34" y1="41" x2="34" y2="63" stroke={ctx.palette.fg} strokeWidth="2" />
</g>
<g transform={`rotate(${wheelTurn} 86 52)`}>
<circle cx="86" cy="52" r="13" fill="none" stroke={ctx.palette.fg} strokeWidth="3" />
<line x1="86" y1="41" x2="86" y2="63" stroke={ctx.palette.fg} strokeWidth="2" />
</g>
<circle cx="52" cy="12" r="6" fill={ctx.palette.fg} />
</g>
)}
</svg>
</div>
</div>
);
};
/** char-bounce:小球/标识沿地面弹跳,带挤压拉伸与残影。 */
export const charBounce: StageRenderer = (s, t, ctx) => {
const bounces = snum(s, 'bounces', 3);
const groundY = 78;
const x = 10 + ease(t) * (ctx.captionSafe ? 42 : 76);
const hop = (t * bounces) % 1;
const height = Math.abs(Math.sin(hop * Math.PI)) * (1 - t * 0.25);
const squash = 1 + Math.sin(hop * Math.PI * 2) * 0.08 * (1 - Math.abs(Math.sin(hop * Math.PI)));
const asMark = sbool(s, 'mark', false);
const ghost = sbool(s, 'trail', true);
return (
<div style={{ ...center, overflow: 'hidden' }}>
<div
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: `${100 - groundY}%`,
height: '0.5cqw',
background: `${ctx.palette.fg}44`,
}}
/>
{ghost
? [0.12, 0.24].map((lag) => (
<span
key={lag}
style={{
position: 'absolute',
left: `${10 + ease(Math.max(0, t - lag)) * 76}%`,
bottom: `${groundY + height * 26 * (1 - lag * 2)}%`,
width: '4cqw',
height: '4cqw',
borderRadius: '50%',
background: ctx.palette.accent,
opacity: 0.18,
}}
/>
))
: null}
<span
style={{
position: 'absolute',
left: `${x}%`,
bottom: `${groundY + height * 26}%`,
transform: 'translate(-50%, 50%)',
}}
>
{asMark ? (
<span
style={{
display: 'inline-flex',
alignItems: 'flex-start',
width: '7cqw',
height: '7.4cqw',
background: ctx.palette.accent,
color: '#fff',
fontWeight: 900,
fontSize: '5.6cqw',
lineHeight: '7.6cqw',
paddingLeft: '1.3cqw',
position: 'relative',
transform: `scaleY(${squash}) scaleX(${2 - squash})`,
}}
>
L
<span style={{ position: 'absolute', right: '0.5cqw', top: '-1cqw', fontSize: '2.6cqw' }}>
↗
</span>
</span>
) : (
<span
style={{
display: 'block',
width: '6.4cqw',
height: '6.4cqw',
borderRadius: '50%',
background: ctx.palette.accent,
transform: `scaleY(${squash}) scaleX(${2 - squash})`,
}}
/>
)}
</span>
<strong
style={{
position: 'absolute',
left: 0,
right: 0,
top: ctx.captionSafe ? '8%' : '14%',
textAlign: 'center',
fontSize: stageFontSize(s, 'xl'),
fontWeight: 900,
color: ctx.palette.fg,
opacity: easeOutQuint((t - 0.55) / 0.45),
transform: `translateY(${(1 - easeOutQuint((t - 0.55) / 0.45)) * 4}cqh)`,
}}
>
{stageLines(s, ctx)[0]}
</strong>
{ctx.captionSafe ? null : (
<span
style={{
position: 'absolute',
left: 0,
right: 0,
bottom: '6%',
textAlign: 'center',
fontSize: '3cqw',
color: ctx.palette.fg,
opacity: easeOutQuint((t - 0.78) / 0.22),
textDecoration: 'underline',
textDecorationColor: ctx.palette.accent,
textDecorationThickness: '0.4cqw',
textUnderlineOffset: '1cqw',
}}
>
{stageLines(s, ctx)[1] ?? stageText(s, ctx)}
</span>
)}
</div>
);
};
/** window-scene:固定车窗框内景致平移,前景茶杯静止(旅途叙事)。 */
export const windowScene: StageRenderer = (s, t, ctx) => {
const seasons = slist(s, 'seasons', ['day', 'dusk', 'night']);
const idx = Math.min(seasons.length - 1, Math.floor(t * seasons.length));
const scene = SCENES[seasons[idx]] ?? SCENES.day;
const drift = (t * 140) % 240;
return (
<div style={{ ...center, background: ctx.palette.bg, alignItems: 'center', justifyContent: 'center' }}>
<div
style={{
position: 'relative',
width: '62cqw',
height: '52cqh',
border: `1.6cqw solid ${ctx.palette.fg}`,
borderRadius: '2cqw',
overflow: 'hidden',
}}
>
<div style={{ position: 'absolute', inset: 0, background: scene.sky }} />
<svg
viewBox="0 0 240 100"
preserveAspectRatio="xMidYMax slice"
style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}
aria-hidden="true"
>
<circle cx={200 - drift * 0.1} cy="22" r="8" fill={scene.sun} />
{[0, 1].map((k) => (
<g key={k} transform={`translate(${-drift + k * 240} 0)`}>
<path d="M0 72 L40 48 L84 70 L128 44 L176 70 L220 52 L240 66 L240 100 L0 100 Z" fill={scene.far} />
<path d="M0 88 L60 74 L120 88 L180 76 L240 90 L240 100 L0 100 Z" fill={scene.near} />
</g>
))}
</svg>
</div>
<div
style={{
position: 'absolute',
left: '8cqw',
bottom: '8cqh',
fontSize: '7cqw',
opacity: 0.92,
}}
aria-hidden="true"
>
☕
</div>
<strong
style={{
position: 'absolute',
left: 0,
right: 0,
top: ctx.captionSafe ? '6cqh' : undefined,
bottom: ctx.captionSafe ? undefined : '5cqh',
textAlign: 'center',
fontSize: '3.4cqw',
fontWeight: 700,
color: `${ctx.palette.fg}bb`,
}}
>
{stageText(s, ctx)}
</strong>
</div>
);
};
/** card-wall:倾斜三维卡片墙,镜头横移后聚焦中心卡。 */
export const cardWall: StageRenderer = (s, t, ctx) => {
const tiles = stageLines(s, ctx);
const cols = 5;
const rows = 3;
const pan = Math.sin(ease(t) * Math.PI) * 3;
const focus = easeOutQuint((t - 0.45) / 0.55);
return (
<div style={{ ...center, overflow: 'hidden', perspective: '90cqw' }}>
<div
style={{
position: 'absolute',
inset: '0 2%',
display: 'grid',
gridTemplateColumns: `repeat(${cols + 2}, 1fr)`,
gap: '1.4cqw',
transform: `rotateY(16deg) rotateX(6deg) translateX(${pan}cqw) scale(${mix(1.04, 1.18, focus)})`,
transformStyle: 'preserve-3d',
alignItems: 'center',
}}
>
{Array.from({ length: (cols + 2) * (rows + 2) }, (_, i) => {
const r = Math.floor(i / (cols + 2));
const c = i % (cols + 2);
const edge = r === 0 || r === rows + 1 || c === 0 || c === cols + 1;
const label = edge ? '' : tiles[(r - 1) * cols + (c - 1)] ?? '';
const isFocus =
!edge &&
r === Math.ceil((rows + 2) / 2) - 1 &&
c === Math.ceil((cols + 2) / 2) - 1;
const e = easeOutQuint((t - i * 0.012) / 0.4);
if (edge) {
return (
<div
key={i}
style={{
aspectRatio: '1.5',
borderRadius: '1cqw',
background: `${ctx.palette.fg}08`,
opacity: e,
}}
/>
);
}
return (
<div
key={i}
style={{
aspectRatio: '1.5',
borderRadius: '1cqw',
background: isFocus ? ctx.palette.accent : `${ctx.palette.fg}0f`,
border: `1px solid ${isFocus ? ctx.palette.accent : ctx.palette.fg + '2a'}`,
color: isFocus ? '#ffffff' : `${ctx.palette.fg}dd`,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: isFocus ? '3.4cqw' : '2.4cqw',
fontWeight: 800,
opacity: e,
transform: `translateZ(${isFocus ? focus * 8 : 0}cqw)`,
boxShadow: isFocus ? `0 1.4cqw 3cqw rgba(24,32,29,0.3)` : 'none',
whiteSpace: 'nowrap',
overflow: 'hidden',
padding: '0 1cqw',
}}
>
{label}
</div>
);
})}
</div>
</div>
);
};
/** camera-push:嵌套窗口逐层推进(递归/深入感)。 */
export const cameraPush: StageRenderer = (s, t, ctx) => {
const depth = snum(s, 'depth', 3);
const zoom = ease(t);
return (
<div style={{ ...center, overflow: 'hidden', background: ctx.palette.bg }}>
{Array.from({ length: depth }, (_, i) => {
const layer = easeOutQuint(Math.min(1, Math.max(0, (zoom * (depth + 0.6) - i) / 1)));
const scale = 0.5 + layer * 1.1;
const opacity = i === 0 ? 1 : Math.min(1, layer * 2);
return (
<div
key={i}
style={{
position: 'absolute',
width: '62cqw',
height: '46cqh',
border: `0.5cqw solid ${i % 2 ? ctx.palette.accent : ctx.palette.fg}`,
borderRadius: '1.6cqw',
background: i === depth - 1 ? ctx.palette.accent : ctx.palette.bg,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
transform: `scale(${scale})`,
opacity,
boxShadow: '0 2cqw 5cqw rgba(24,32,29,0.2)',
}}
>
{sstr(s, 'inner', 'geo') === 'mark' ? (
<span
style={{
fontSize: i === depth - 1 ? '26cqw' : '9cqw',
fontWeight: 900,
color: i === depth - 1 ? '#ffffff' : ctx.palette.fg,
}}
>
L↗
</span>
) : (
<span
style={{
width: i === depth - 1 ? '22cqw' : '8cqw',
height: i === depth - 1 ? '22cqw' : '8cqw',
border: `${Math.max(1, (i === depth - 1 ? 22 : 8) * 0.08)}cqw solid ${
i === depth - 1 ? '#ffffff' : ctx.palette.fg
}`,
borderRadius: '50%',
display: 'inline-block',
}}
/>
)}
</div>
);
})}
<strong
style={{
position: 'absolute',
bottom: '6cqh',
left: 0,
right: 0,
textAlign: 'center',
fontSize: '3.2cqw',
fontWeight: 700,
color: `${ctx.palette.fg}aa`,
opacity: easeOutQuint((t - 0.6) / 0.4),
}}
>
{stageText(s, ctx)}
</strong>
</div>
);
};
/** depth-layers:多层界面面板沿纵深依次掠过(滚动叙事)。 */
export const depthLayers: StageRenderer = (s, t, ctx) => {
const layers = stageLines(s, ctx);
return (
<div style={{ ...center, overflow: 'hidden', perspective: '120cqw' }}>
{layers.map((layer, i) => {
const e = ease(t);
const local = Math.min(1, Math.max(0, e * layers.length - i));
return (
<div
key={i}
style={{
position: 'absolute',
inset: `${6 + i * 4}% ${8 + i * 3}%`,
borderRadius: '1.6cqw',
border: `1px solid ${ctx.palette.fg}33`,
background: i % 2 ? ctx.palette.bg : `${ctx.palette.accent}0d`,
transform: `rotateX(28deg) translateY(${(1 - local) * -46}cqh) translateZ(${i * 6}cqw)`,
opacity: local * (i === layers.length - 1 ? 1 : 1 - easeInOut(Math.max(0, (t - 0.85) / 0.15))),
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
fontSize: '4cqw',
fontWeight: 800,
color: ctx.palette.fg,
}}
>
{layer}
</div>
);
})}
</div>
);
};
/** eye-iris:眼形弧线张开,几何虹膜缓慢旋转(迷幻但连续无频闪)。 */
export const eyeIris: StageRenderer = (s, t, ctx) => {
const open = easeInOut(Math.min(1, t * 1.6));
const petals = snum(s, 'petals', 12);
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
background: ctx.palette.bg,
}}
>
<svg viewBox="0 0 100 56" style={{ width: '78cqw' }} aria-hidden="true">
<path
d={`M4 28 Q 50 ${28 - 26 * open} 96 28 Q 50 ${28 + 26 * open} 4 28 Z`}
fill="none"
stroke={ctx.palette.accent}
strokeWidth={1.4}
/>
<circle
cx="50"
cy="28"
r={13 * open}
fill="none"
stroke={ctx.palette.fg}
strokeWidth={0.8}
strokeDasharray="3 2"
transform={`rotate(${t * 160} 50 28)`}
/>
<circle cx="50" cy="28" r={5 * open} fill={ctx.palette.accent} />
{sstr(s, 'pupil', 'dot') === 'mark' ? (
<text
x="50"
y="31.5"
textAnchor="middle"
fontSize="5"
fontWeight="800"
fill="#ffffff"
opacity={open}
>
L
</text>
) : null}
</svg>
<div
style={{
position: 'absolute',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
{Array.from({ length: petals }, (_, i) => (
<span
key={i}
style={{
position: 'absolute',
width: '0.8cqw',
height: `${6 + ((i * 29) % 8)}cqw`,
background: `${ctx.palette.fg}33`,
transform: `rotate(${(i / petals) * 360 + t * 40}deg) translateY(-30cqw)`,
}}
/>
))}
</div>
</div>
);
};
/** pixel-scene:像素风夜景,窗灯渐次点亮,月亮缓升。 */
export const pixelScene: StageRenderer = (s, t, ctx) => {
const grid = 24;
const cells: ReactNode[] = [];
const moonRise = easeOutQuint(t);
for (let y = 0; y < grid; y++)
for (let x = 0; x < grid; x++) {
let color = 'transparent';
const isSky = y < grid * 0.68;
const isMoon =
(x - 18) ** 2 / 9 + (y - (16 - moonRise * 6)) ** 2 / 9 < 1 && x > 13;
if (isMoon) color = '#f2e9c9';
else if (isSky) color = ((x * 7 + y * 13) % 11 === 0 ? '#31406b' : 'transparent');
else {
const isRoof = y === Math.floor(grid * 0.68) && x % 3 !== 2;
const isWindow =
y > grid * 0.68 + 1 && y < grid - 2 && x % 4 === 1 && (x + y) % 3 === 0;
if (isRoof) color = '#1d2436';
else if (isWindow) color = (x + y) % 4 === 1 && t > 0.3 + ((x % 5) * 0.06) ? '#f4c95d' : '#242c42';
else color = '#141928';
}
if (color !== 'transparent')
cells.push(
<span
key={`${x}-${y}`}
style={{
background: color,
gridColumn: x + 1,
gridRow: y + 1,
}}
/>,
);
}
return (
<div style={{ ...center, alignItems: 'center', justifyContent: 'center', background: '#0c101a' }}>
<div
style={{
display: 'grid',
gridTemplateColumns: `repeat(${grid}, 1fr)`,
gridTemplateRows: `repeat(${grid}, 1fr)`,
width: '74cqw',
height: '74cqh',
imageRendering: 'pixelated',
}}
>
{cells}
</div>
{ctx.captionSafe ? null : (
<strong
style={{
position: 'absolute',
bottom: '5cqh',
left: 0,
right: 0,
textAlign: 'center',
fontSize: '3.4cqw',
fontWeight: 700,
color: '#e8eef7cc',
}}
>
{stageText(s, ctx)}
</strong>
)}
</div>
);
};
/** spiral-rise:文字沿螺旋轨道升起盘旋(金色书页感)。 */
export const spiralRise: StageRenderer = (s, t, ctx) => {
const chars = Array.from(stageText(s, ctx)).slice(0, 14);
const turns = snum(s, 'turns', 1.6);
// 2D 欧氏最小间距,同角不同半径的字符对不再相叠(P0-8)
const placed: { x: number; y: number }[] = [];
const minDist = 10;
const settle = (x: number, y: number) => {
let px = x;
let py = y;
for (let guard = 0; guard < 10; guard++) {
const hit = placed.find((pt) => Math.hypot(pt.x - px, pt.y - py) < minDist);
if (!hit) break;
px += (px - hit.x) * 0.6 + (px >= hit.x ? 2 : -2);
py += (py - hit.y) * 0.6 + (py >= hit.y ? 1.4 : -1.4);
}
placed.push({ x: px, y: py });
return { x: px, y: py };
};
const positions = chars.map((_, i) => {
const local = easeOutQuint((t - i * 0.05) / 0.8);
const angle = local * Math.PI * 2 * turns + i * 0.5;
const radius = (6 + local * 26) * (1 + i * 0.012);
return settle(
50 + Math.cos(angle) * radius,
50 + Math.sin(angle) * radius * 0.6 - local * 14,
);
});
return (
<div
style={{
...center,
alignItems: 'center',
justifyContent: 'center',
background: ctx.palette.bg,
}}
>
<div style={{ position: 'relative', width: '70cqw', height: '70cqh' }}>
{chars.map((char, i) => {
const local = easeOutQuint((t - i * 0.05) / 0.8);
const angle = local * Math.PI * 2 * turns + i * 0.5;
return (
<span
key={i}
style={{
position: 'absolute',
left: `${positions[i].x}%`,
top: `${positions[i].y}%`,
fontSize: `${3.4 + local * 2.6}cqw`,
fontWeight: 800,
color: i % 3 === 0 ? ctx.palette.accent : ctx.palette.fg,
opacity: local,
transform: `translate(-50%, -50%) rotate(${angle * 12}deg)`,
textShadow: `0 0 ${2 + local * 2}cqw ${ctx.palette.accent}44`,
}}
>
{char}
</span>
);
})}
</div>
</div>
);
};
/** 插画图层(展示态):就绪由播放器聚合保证;未就绪仅绘装饰性占位,交互在可访问 UI 层。 */
function CollageImage(props: {
url: string;
ready: boolean;
x: number;
y: number;
w: number;
rot: number;
lt: number;
ink: string;
}) {
const { url, ready, x, y, w, rot, lt, ink } = props;
return (
<div
style={{
position: 'absolute',
left: `${x}%`,
top: `${y}%`,
width: `${w}%`,
aspectRatio: '1 / 1',
transform: `rotate(${rot}deg)`,
pointerEvents: 'none',
userSelect: 'none',
}}
>
{ready ? (
// oxlint-disable-next-line next/no-img-element -- 原创透明插画需 img 标签以利用透明度与层叠。
<img
src={url}
alt=""
loading="lazy"
decoding="async"
draggable={false}
style={{
position: 'absolute',
inset: 0,
width: '100%',
height: '100%',
objectFit: 'contain',
opacity: lt,
pointerEvents: 'none',
userSelect: 'none',
}}
/>
) : lt > 0.05 ? (
<div
aria-hidden
style={{
position: 'absolute',
inset: 0,
borderRadius: '2cqw',
border: `0.35cqw dashed ${ink}55`,
}}
/>
) : null}
</div>
);
}
/** collage-layer:透明插画图层按节奏、位置、旋转叠入(灵感到作品样板)。
* from 契约 = 入场运动方向:up 自下方向上、down 自上方向下、left 自右侧向左、right 自左侧向右。 */
export const collageLayer: StageRenderer = (s, t, ctx) => {
const raw = s.layers;
if (!Array.isArray(raw) || raw.length === 0) return null;
const layers = raw as CollageLayerData[];
const bg = sstr(s, 'bg', ctx.palette.bg);
const title = stageText(s, ctx);
// 时间源统一为阶段真实时长 StageSpec.dur,delay/titleDelay 均按其换算为本地进度
const stageDur = s.dur > 0 ? s.dur : 5.0;
const titleDelay = snum(s, 'titleDelay', 2.5);
const showTitle = sbool(s, 'showTitle', true);
const titleFrac = titleDelay / stageDur;
const titleDurFrac = 1.0 / stageDur;
const titleT = easeOutQuint(clamp01((t - titleFrac) / Math.max(titleDurFrac, 0.01)));
return (
<div style={{ ...center, background: bg }}>
{layers.map((cfg, i) => {
const delay = typeof cfg.delay === 'number' ? cfg.delay : i * 0.6;
const dur = 1.2;
const delayFrac = delay / stageDur;
const durFrac = dur / stageDur;
const lt = easeOutQuint(clamp01((t - delayFrac) / Math.max(durFrac, 0.01)));
const fromDir = typeof cfg.from === 'string' ? cfg.from : 'up';
const ox = fromDir === 'left' ? (1 - lt) * 14 : fromDir === 'right' ? (1 - lt) * -14 : 0;
const oy = fromDir === 'up' ? (1 - lt) * 12 : fromDir === 'down' ? (1 - lt) * -12 : 0;
return (
<CollageImage
key={i}
url={cfg.url}
ready={ctx.assets.has(cfg.url)}
x={(cfg.x ?? 15) + ox}
y={(cfg.y ?? 10) + oy}
w={cfg.w ?? 50}
rot={cfg.rot ?? 0}
lt={lt}
ink={ctx.palette.ink}
/>
);
})}
{showTitle && titleT > 0 ? (
<div
style={{
...center,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'flex-end',
textAlign: 'center',
paddingBottom: ctx.captionSafe ? '14cqh' : '5cqh',
pointerEvents: 'none',
}}
>
<strong
style={{
fontSize: '6.4cqw',
fontWeight: 800,
color: ctx.palette.ink,
opacity: titleT,
transform: `translateY(${(1 - titleT) * 4}cqh)`,
maxWidth: '88cqw',
lineHeight: 1.25,
// 标题安全区:纸面衬底保证繁复插画上的稳定对比(R5 视觉建议)。
background: `${ctx.palette.paper}d9`,
padding: '1cqh 2.6cqw',
borderRadius: '1.6cqw',
boxShadow: `0 0.4cqh 2.4cqh ${ctx.palette.ink}1f`,
}}
>
{title}
</strong>
<span
aria-hidden
style={{
marginTop: '1.1cqh',
width: `${titleT * 16}cqw`,
height: '0.9cqh',
borderRadius: '0.45cqh',
background: ctx.palette.accent,
}}
/>
</div>
) : null}
</div>
);
};
export const SCENE_STAGES: Record<string, StageRenderer> = {
'scene-pan': scenePan,
'scene-vehicle': sceneVehicle,
'char-bounce': charBounce,
'window-scene': windowScene,
'card-wall': cardWall,
'camera-push': cameraPush,
'depth-layers': depthLayers,
'eye-iris': eyeIris,
'pixel-scene': pixelScene,
'spiral-rise': spiralRise,
'collage-layer': collageLayer,
};
/** 编辑部级专用阶段:内容案例的真实主体与动作机制(2026-10-21 合并返修新增)。
* 每个 kind 对应一个可核验的机制承诺;参数消费与描述见 build_cases.py 消费表。 */
import { useState, type ComponentType } from 'react';
import type { CSSProperties } from 'react';
import type { StageRenderCtx, StageRenderer } from './case-engine';
import { slist, snum, sstr, stageLines, stageText } from './case-engine';
import {
clamp01,
codeMotionPoints,
codeMotionSnippet,
codeMotionView,
easeInOut,
easeOutQuint,
effectiveRecipe,
liquidLevels,
ORBIT,
orbitAnchor,
type RecipeItemData,
} from './case-timeline';
interface StageSpecLike { kind: string; at: number; dur: number; [k: string]: unknown }
const center: CSSProperties = { position: 'absolute', inset: 0, display: 'flex' };
const INK = '#18201d';
const PAPER = '#fafaf7';
const cap = (): CSSProperties => ({
position: 'absolute', left: 0, right: 0, bottom: '5cqh', textAlign: 'center',
fontSize: '4.6cqw', fontWeight: 700, color: INK, pointerEvents: 'none',
});
/** 贝塞尔取点与切线(R5):导数同时取 x/y,角度在同一 0–100 视图坐标内计算。 */
function qPoint(a: number, c: number, b: number, u: number) {
const v = 1 - u;
return v * v * a + 2 * v * u * c + u * u * b;
}
function qTangentDeg(ax: number, cx: number, bx: number, ay: number, cy: number, by: number, u: number) {
const v = 1 - u;
const dx = 2 * v * (cx - ax) + 2 * u * (bx - cx);
const dy = 2 * v * (cy - ay) + 2 * u * (by - cy);
return (Math.atan2(dy, dx) * 180) / Math.PI;
}
/* ============ C 组:图像案例(复用 luca-editorial-v1 三张原创插画) ============ */
/** image-through:同一张图贯穿 大字→窗口→网格→作品版面,形态连续。 */
const imageThrough: StageRenderer = (s, t, ctx) => {
const img = sstr(s, 'img', '');
const imgReady = ctx.assets.has(img);
const lines = stageLines(s, ctx);
const word = stageText(s, ctx);
const shrink = easeInOut(clamp01((t - 0.08) / 0.24));
const gridT = easeOutQuint(clamp01((t - 0.4) / 0.18));
const boardT = easeOutQuint(clamp01((t - 0.66) / 0.2));
// 网格接管窗口;待旧画面全部退场,再显示作品文案,避免透明插画相互压字。
const copyT = easeOutQuint(clamp01((t - 0.86) / 0.14));
const showGrid = gridT > 0 && boardT < 1;
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
{boardT < 1 ? (
<div style={{ ...center, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<div style={{
position: 'relative', width: `${34 + shrink * 12}cqw`, height: `${(34 + shrink * 12) * 0.72}cqw`,
marginTop: `${(1 - shrink) * 8}cqh`, border: `0.4cqw solid ${INK}22`, borderRadius: '1.4cqw',
overflow: 'hidden', background: '#fff', opacity: (shrink > 0.02 ? 1 : 0) * (1 - gridT),
}}>
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', objectFit: 'cover', opacity: shrink }} draggable={false} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: 0, border: `0.35cqw dashed ${INK}55` }} />
)}
</div>
<strong style={{ fontSize: '11cqw', color: INK, opacity: 1 - shrink, transform: `scale(${1 - shrink * 0.4})`, position: 'absolute' }}>{word}</strong>
{showGrid ? (
<div style={{ position: 'absolute', inset: 0, background: `${PAPER}e6`, display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '2cqw', padding: '10cqh 16cqw', opacity: gridT * (1 - boardT) }}>
{[0, 1, 2, 3].map((i) => (
<div key={i} style={{ position: 'relative', borderRadius: '1cqw', overflow: 'hidden', outline: i === 2 ? `0.5cqw solid ${ctx.palette.accent}` : `0.2cqw solid ${INK}18`, outlineOffset: '0.3cqw', opacity: gridT, transform: `scale(${0.9 + gridT * 0.1})` }}>
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover', objectPosition: `${20 + i * 20}% 40%` }} draggable={false} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: 0, border: `0.35cqw dashed ${INK}55` }} />
)}
</div>
))}
</div>
) : null}
</div>
) : null}
{boardT > 0 ? (
<div style={{ ...center, gap: '3cqw', padding: '8cqh 8cqw', alignItems: 'center', opacity: boardT, transform: `translateY(${(1 - boardT) * 3}cqh)` }}>
<div style={{ width: '44cqw', height: '52cqh', borderRadius: '1.6cqw', overflow: 'hidden', boxShadow: `0 1cqh 3cqh ${INK}26` }}>
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} draggable={false} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: 0, border: `0.35cqw dashed ${INK}55` }} />
)}
</div>
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: '2cqh', alignItems: 'flex-start', opacity: copyT }}>
<strong style={{ fontSize: '6cqw', color: INK }}>{word}</strong>
{lines.slice(0, 3).map((line, i) => (
<span key={i} style={{ fontSize: '3.6cqw', color: `${INK}b8`, borderBottom: `0.2cqw solid ${INK}22`, paddingBottom: '0.8cqh', width: '88%', opacity: boardT }}>{line}</span>
))}
<span style={{ marginTop: '2cqh', fontSize: '3cqw', color: ctx.palette.accent, fontWeight: 700 }}>{'同一张图 · 从想法到作品'}</span>
</div>
</div>
) : null}
</div>
);
};
/** image-layout:输入句打字 → 图像落进版面槽位 → 标题与文字列对齐成版。 */
const imageLayout: StageRenderer = (s, t, ctx) => {
const img = sstr(s, 'img', '');
const imgReady = ctx.assets.has(img);
const lines = stageLines(s, ctx);
const sentence = lines[0] ?? '说一句,图就位';
const typeN = Math.ceil(clamp01(t / 0.34) * sentence.length);
const drop = easeOutQuint(clamp01((t - 0.34) / 0.24));
const settle = easeInOut(clamp01((t - 0.6) / 0.3));
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '3cqh' }}>
<div style={{ height: '12cqh', display: 'flex', alignItems: 'center', fontSize: '4.8cqw', color: INK, fontWeight: 600 }}>
{sentence.slice(0, typeN)}
{t < 0.4 ? <span style={{ width: '0.5cqw', height: '4cqh', background: ctx.palette.accent, marginLeft: '0.6cqw' }} /> : null}
</div>
<div style={{ position: 'relative', width: '78cqw', height: '58cqh', border: `0.3cqw solid ${INK}1e`, borderRadius: '1.6cqw', background: '#fff', display: 'flex', gap: '3cqw', padding: '3cqw', opacity: 0.35 + drop * 0.65 }}>
<div style={{ width: '42%', borderRadius: '1.2cqw', background: `${INK}0d`, display: 'flex', alignItems: 'center', justifyContent: 'center', overflow: 'hidden' }}>
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" draggable={false} style={{ width: '100%', height: '100%', objectFit: 'contain', opacity: drop, transform: `translateY(${(1 - drop) * -30}cqh) rotate(${(1 - drop) * -8}deg)` }} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: 0, border: `0.35cqw dashed ${INK}55`, borderRadius: '1.2cqw' }} />
)}
</div>
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', gap: '2.2cqh', paddingTop: '1cqh' }}>
<strong style={{ fontSize: '5.4cqw', color: INK, opacity: settle }}>{lines[1] ?? '版面标题'}</strong>
{[0, 1, 2, 3].map((i) => (
<span key={i} style={{ height: '1.6cqh', borderRadius: '1cqh', background: `${INK}1c`, width: `${92 - i * 14}%`, transform: `scaleX(${settle})`, transformOrigin: 'left' }} />
))}
<span style={{ fontSize: '3cqw', color: `${INK}80`, marginTop: 'auto', opacity: settle }}>图文同栅格 · 演示版面</span>
</div>
</div>
</div>
);
};
/** image-cards:三张内容图卡前后景漂浮,最终聚成一叠画册。 */
const imageCards: StageRenderer = (s, t, ctx) => {
const imgs = slist(s, 'imgs', []) as string[];
const gather = easeInOut(clamp01((t - 0.58) / 0.34));
const word = stageText(s, ctx);
return (
<div style={{ ...center, background: ctx.palette.bg }}>
{(imgs as string[]).map((url: string, i: number) => {
const depth = [0.55, 1, 0.75][i];
const drift = Math.sin((t * depth + i * 1.7) * Math.PI * 2);
const x = [16, 44, 66][i];
const y = [16, 30, 44][i];
const gx = [30, 34, 38][i];
const gy = [26, 30, 34][i];
const scale = [0.72, 1, 0.84][i];
return (
<div key={i} style={{
position: 'absolute', left: `${x + (gx - x) * gather + drift * (1 - gather) * 3}cqw`,
top: `${y + (gy - y) * gather}%`, width: `${30 * scale + gather * 4}cqw`, aspectRatio: '1 / 1',
transform: `rotate(${[-8, 3, -2][i] + drift * (1 - gather) * 4}deg)`,
borderRadius: '1.6cqw', overflow: 'hidden', background: '#fff',
boxShadow: `0 ${2 + depth * 2}cqh ${4 + depth * 4}cqh ${INK}${depth > 0.9 ? '33' : '22'}`,
opacity: 0.6 + depth * 0.4, zIndex: i,
}}>
{ctx.assets.has(url) ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={url} alt="" style={{ width: '100%', height: '100%', objectFit: 'cover' }} draggable={false} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: 0, border: `0.35cqw dashed ${INK}55` }} />
)}
</div>
);
})}
<span style={{ ...cap(), opacity: gather }}>{word}</span>
</div>
);
};
/** image-compare:同一张图明暗两层,分割线位置=可见比例,联动真实因果。 */
const imageCompare: StageRenderer = (s, t, ctx) => {
const img = sstr(s, 'img', '');
const imgReady = ctx.assets.has(img);
const word = stageText(s, ctx);
const pos = 0.16 + easeInOut(t) * 0.68;
return (
<div style={{ ...center, background: ctx.palette.bg }}>
{/* 暗层(整幅) */}
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" draggable={false} style={{ position: 'absolute', inset: '6% 8%', width: '84%', height: '72%', objectFit: 'contain', filter: 'brightness(0.42) saturate(0.7)' }} />
) : (
<div aria-hidden style={{ position: 'absolute', inset: '6% 8%', border: `0.35cqw dashed ${INK}55` }} />
)}
{/* 亮层(分割线左侧) */}
<div style={{ position: 'absolute', inset: '6% 8%', width: '84%', height: '72%', clipPath: `inset(0 ${100 - pos * 100}% 0 0)` }}>
{imgReady ? (
// oxlint-disable-next-line next/no-img-element -- 原创插画复用资产。
<img src={img} alt="" draggable={false} style={{ width: '100%', height: '100%', objectFit: 'contain' }} />
) : null}
</div>
<div style={{ position: 'absolute', top: '4%', bottom: '12%', left: `${8 + pos * 84}%`, width: '0.7cqw', background: '#fff', boxShadow: `0 0 1.6cqw ${INK}66`, borderRadius: '1cqw' }}>
<span style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%,-50%)', width: '4.6cqw', height: '4.6cqw', borderRadius: '50%', background: '#fff', boxShadow: `0 0.4cqh 1.6cqh ${INK}44`, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '2.6cqw', color: INK, fontWeight: 800 }}>{'↔'}</span>
</div>
<span style={{ position: 'absolute', left: '11%', top: '8%', fontSize: '3.2cqw', fontWeight: 800, color: ctx.palette.accent }}>{'调亮'}</span>
<span style={{ position: 'absolute', right: '11%', top: '8%', fontSize: '3.2cqw', fontWeight: 800, color: `${PAPER}cc`, textShadow: `0 0 1cqw ${INK}` }}>{'原亮度'}</span>
<span style={{ ...cap() }}>{word}</span>
</div>
);
};
/* ============ D 组:内容重设计 ============ */
/** path-flight:折纸飞机沿弧线爬升穿云,机头跟随切线;两层云速度不同。 */
const pathFlight: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const u = easeInOut(clamp01(t / 0.92));
const x = qPoint(8, 42, 90, u);
const y = qPoint(88, 30, 18, u);
// x/y 各自求导(R5):dx/dθ 与 dy/dθ 都来自真实曲线导数。
const ang = qTangentDeg(8, 42, 90, 88, 30, 18, u);
const lineT = clamp01((t - 0.55) / 0.4);
const half = Math.ceil(word.length / 2);
return (
<div style={{ ...center, background: 'linear-gradient(180deg,#2b2440 0%,#4a3a63 55%,#8a5a6e 100%)' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<path d="M 8 88 Q 42 30 90 18" fill="none" stroke="#ffffff55" strokeWidth="0.4" strokeDasharray="1.6 1.6" pathLength={100} strokeDashoffset={100 - u * 100} />
{/* 可见机头尖点定义为局部原点(0,0);机身在+x方向,沿轨迹切线反向朝后。 */}
<g transform={`translate(${x} ${y}) rotate(${ang + 180})`} opacity="0.96">
<polygon points="0,0 6.5,-2 4,0 6.5,2" fill="#f4efe6" stroke="#2b2440" strokeWidth="0.4" strokeLinejoin="round" />
</g>
</svg>
{[0.35, 0.7, 1.15].map((sp, i) => (
<div key={i} style={{ position: 'absolute', inset: 0, opacity: i === 1 ? 1 : 0.5 }}>
{[0, 1, 2].map((j) => {
const cx = ((j * 46 + 10 - t * sp * 46) % 150 + 150) % 150 - 25;
return (
<div key={j} style={{ position: 'absolute', left: `${cx}%`, top: `${16 + i * 24 + (j % 2) * 6}%`, width: `${16 + (j % 3) * 6}cqw`, height: `${5 + (j % 2) * 2}cqh`, borderRadius: '6cqw', background: i === 1 ? '#e8ddcf' : '#cbb8d6', opacity: 0.85 }} />
);
})}
</div>
))}
{[[word.slice(0, half), 30], [word.slice(half), 44]].map(([line, top], i) => (
<span key={i} style={{ position: 'absolute', left: `${12 + i * 16}%`, top: `${top}%`, fontSize: '4.4cqw', fontWeight: 700, color: '#f6f1e7', opacity: clamp01(lineT * 2 - i), letterSpacing: '0.3cqw' }}>{line}</span>
))}
</div>
);
};
/** orbit-follow:纸飞机沿椭圆虚线绕标题一周。可见轨迹与锚点/切线共用 orbitAnchor(M3)。 */
const orbitFollow: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const th = -Math.PI / 2 + easeInOut(clamp01(t / 0.94)) * Math.PI * 2;
const { x: px, y: py, angleDeg: tangent } = orbitAnchor(th);
// 朝向契约(R5):轨迹锚点是可见机头;局部鼻尖为(0,0),机身向+x,故 rotate = 切线角 + 180°。
return (
<div style={{ ...center, background: ctx.palette.bg, alignItems: 'center', justifyContent: 'center' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<ellipse cx={ORBIT.cx} cy={ORBIT.cy} rx={ORBIT.rx} ry={ORBIT.ry} fill="none" stroke={`${INK}44`} strokeWidth="0.4" strokeDasharray="2 1.6" pathLength={100} strokeDashoffset={100 - clamp01(t / 0.94) * 100} />
{/* 可见机头尖点定义为局部原点(0,0);机身在+x方向,沿轨迹切线反向朝后。 */}
<g transform={`translate(${px} ${py}) rotate(${tangent + 180})`}>
<polygon points="0,0 7.5,-3.5 5,0 7.5,3.5" fill={ctx.palette.accent} stroke={INK} strokeWidth="0.35" strokeLinejoin="round" />
</g>
</svg>
<strong style={{ fontSize: '9cqw', color: INK, textAlign: 'center', maxWidth: '56cqw' }}>{word}</strong>
</div>
);
};
/** bike-ride:侧视骑行,曲柄/踏板/双腿/轮组联动,三层视差后退。 */
const bikeRide: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const cyc = t * Math.PI * 8;
const wheelA = cyc * 1.75;
const hip = { x: 45, y: 40 };
const legs = [0, Math.PI].map((offset) => {
const foot = { x: 55 + Math.cos(cyc + offset) * 6, y: 64 + Math.sin(cyc + offset) * 6 };
const dx = foot.x - hip.x, dy = foot.y - hip.y, d = Math.hypot(dx, dy);
// 两个等长骨段的圆交点,选择膝盖朝前的一支,避免插值拉长腿。
const h = Math.sqrt(18 ** 2 - (d / 2) ** 2);
const knee = { x: hip.x + dx / 2 + dy / d * h, y: hip.y + dy / 2 - dx / d * h };
return { foot, knee };
});
const leg = ({ foot, knee }: typeof legs[number], far: boolean) => (
<g data-bike-part={far ? 'far-leg' : 'near-leg'} stroke={ctx.palette.accent} strokeWidth="2.8" opacity={far ? 0.5 : 1}>
<line x1={hip.x} y1={hip.y} x2={knee.x} y2={knee.y} />
<line x1={knee.x} y1={knee.y} x2={foot.x} y2={foot.y} />
<line x1={foot.x - 1.5} y1={foot.y - 0.8} x2={foot.x + 2} y2={foot.y - 0.8} stroke={INK} strokeWidth="1.6" />
</g>
);
return (
<div style={{ ...center, background: 'linear-gradient(180deg,#dfe8f2 0%,#eef2e4 46%,#d8cfb6 60%,#c9b98f 100%)' }}>
{[[ '#c7d4e4', 26], ['#9fb894', 20]].map(([color, h], i) => (
<div key={i} style={{ position: 'absolute', left: `${(i * 53 - t * (6 + i * 5)) % 160 - 30}%`, bottom: `${34 + i * 6}%`, width: '46%', height: `${h}cqh`, borderRadius: '50% 50% 0 0', background: color as string, opacity: 0.8 }} />
))}
{[0, 1, 2].map((i) => (
<div key={i} style={{ position: 'absolute', left: `${(i * 38 + 18 - t * 34) % 140 - 20}%`, bottom: '22%', width: '1cqw', height: '26cqh', background: `${INK}55`, borderRadius: '1cqw' }} />
))}
<div style={{ position: 'absolute', bottom: '22%', left: 0, right: 0, height: '0.5cqh', background: '#b8a67d' }} />
<svg viewBox="12 8 94 72" preserveAspectRatio="xMidYMax meet" aria-hidden="true" style={{ position: 'absolute', left: 0, bottom: '22.5%', width: '100%', height: '74%', overflow: 'visible' }}>
<g stroke={INK} strokeWidth="1.4" fill="none" strokeLinecap="round" strokeLinejoin="round">
{leg(legs[1], true)}
{[34, 84].map((x) => (
<g key={x} data-bike-part="wheel" transform={`rotate(${wheelA * 180 / Math.PI} ${x} 66)`}>
<circle cx={x} cy="66" r="14" />
{[0, 60, 120].map((a) => <line key={a} x1={x} y1="52" x2={x} y2="80" strokeWidth="0.45" transform={`rotate(${a} ${x} 66)`} />)}
</g>
))}
<path d="M34 66 L47 47 L55 64 Z M47 47 L75 47 L55 64 M75 47 L84 66 M47 47 L45 42" />
<line data-bike-part="seat" x1="40" y1="42" x2="50" y2="42" strokeWidth="2" />
<path data-bike-part="handlebar" d="M75 47 L73 40 L78 40" strokeWidth="1.8" />
<circle cx="55" cy="64" r="3.2" />
{legs.map(({ foot }, i) => (
<g key={i} data-bike-part="crank">
<line x1="55" y1="64" x2={foot.x} y2={foot.y} strokeWidth="1" />
<line x1={foot.x - 2.5} y1={foot.y} x2={foot.x + 2.5} y2={foot.y} strokeWidth="0.7" />
</g>
))}
{leg(legs[0], false)}
<line data-bike-part="torso" x1={hip.x} y1={hip.y} x2="58" y2="28" strokeWidth="4" />
<line x1="58" y1="28" x2="60" y2="24" strokeWidth="2.6" />
<circle cx="61" cy="20" r="4.2" fill={INK} stroke="none" />
<path data-bike-part="arm" d="M58 28 L67 37 L78 40" strokeWidth="2.2" />
</g>
</svg>
<span style={{ ...cap() }}>{word}</span>
</div>
);
};
/** 配方条目解析(M1):液体带份量驱动液位;冰/搅拌/装饰是动作。 */
function recipeItems(s: StageSpecLike, ctx: StageRenderCtx): RecipeItemData[] {
const raw = s.items;
if (!Array.isArray(raw)) return [];
// 配方覆盖完整 typed 序列;通用 steps 文本不再按行号覆盖类型槽位。
return effectiveRecipe(raw as RecipeItemData[], ctx.options.recipe);
}
const itemLabel = (it: RecipeItemData) =>
it.t === 'liquid'
? `${it.name} ${it.amount ?? 0}${it.unit ?? ''}${(it.amount ?? 0) <= 0 ? '(不计液位)' : ''}`
: it.name;
const LIQUID_HUES = ['#d97706', '#b3271e', '#f2c94c', '#e88fb0', '#7a4dbf'];
/** recipe-draw(R1):左清单/右杯体分区;液体按份量分层上涨;冰/搅拌/装饰独立动作不计液位。 */
const recipeDraw: StageRenderer = (s, t, ctx) => {
const name = stageText(s, ctx);
const items = recipeItems(s, ctx);
const levels = liquidLevels(items);
const glassT = clamp01(t / 0.24);
const segOf = (i: number) => clamp01((t - (0.24 + (i * 0.68) / Math.max(1, items.length))) / (0.62 / Math.max(1, items.length)));
const GLASS_X = 14, GLASS_W = 30, GLASS_CX = GLASS_X + GLASS_W / 2, GLASS_TOP = 16, GLASS_BOTTOM = 82;
const GLASS_H = GLASS_BOTTOM - GLASS_TOP - 8;
const GLASS_PATH = `M ${GLASS_X} ${GLASS_TOP} L ${GLASS_X} 68 Q ${GLASS_X} ${GLASS_BOTTOM} ${GLASS_CX} ${GLASS_BOTTOM} Q ${GLASS_X + GLASS_W} ${GLASS_BOTTOM} ${GLASS_X + GLASS_W} 68 L ${GLASS_X + GLASS_W} ${GLASS_TOP} Z`;
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column' }}>
<strong style={{ position: 'absolute', top: '5cqh', left: 0, right: 0, textAlign: 'center', fontSize: 'max(12px, 4.2cqw)', color: INK, opacity: clamp01(t / 0.1) }}>{name}</strong>
<div style={{ position: 'absolute', top: '14cqh', bottom: '9cqh', left: '4cqw', right: '4cqw', display: 'flex', gap: '3cqw', alignItems: 'stretch' }}>
<div style={{ width: '32cqw', display: 'flex', flexDirection: 'column', gap: '1.5cqh', justifyContent: 'center', alignItems: 'flex-start' }}>
{items.map((it, i) => {
const on = t >= 0.24 + (i * 0.68) / Math.max(1, items.length);
const color = it.t === 'liquid' ? it.color ?? LIQUID_HUES[i % LIQUID_HUES.length] : `${INK}88`;
return (
<span key={i} style={{ maxWidth: '100%', minWidth: 0, overflowWrap: 'anywhere', fontSize: 'max(11px, 2.9cqw)', fontWeight: on ? 800 : 500, color: on ? INK : `${INK}66`, borderLeft: `0.8cqw solid ${on ? color : INK + '22'}`, paddingLeft: '1.2cqw', lineHeight: 1.35 }}>
{`${i + 1}. ${itemLabel(it)}`}
</span>
);
})}
</div>
<div style={{ flex: 1, position: 'relative' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<defs><clipPath id="recipe-draw-glass-clip"><path d={GLASS_PATH} /></clipPath></defs>
<path d={GLASS_PATH} fill="#fff" stroke={INK} strokeWidth="1.6" strokeLinecap="round" pathLength={100} strokeDasharray={100} strokeDashoffset={100 - glassT * 100} />
<line x1={GLASS_X - 3} y1={GLASS_TOP} x2={GLASS_X + GLASS_W + 3} y2={GLASS_TOP} stroke={INK} strokeWidth="1.6" strokeLinecap="round" pathLength={100} strokeDasharray={100} strokeDashoffset={100 - glassT * 100} />
<g clipPath="url(#recipe-draw-glass-clip)">{levels.map(({ item, cumRatio, ratio }, i) => {
const seg = segOf(items.indexOf(item));
if (seg <= 0 || ratio <= 0) return null;
const h = ratio * GLASS_H * seg;
const yTop = GLASS_BOTTOM - (cumRatio + ratio * seg) * GLASS_H;
const color = item.color ?? LIQUID_HUES[i % LIQUID_HUES.length];
return <rect key={`l${i}`} x={GLASS_X + 0.7} y={yTop} width={GLASS_W - 1.4} height={h} fill={color} opacity={0.85} />;
})}</g>
{levels.map(({ item, cumRatio, ratio }, i) => {
const seg = segOf(items.indexOf(item));
if (seg <= 0 || ratio <= 0) return null;
const yTop = GLASS_BOTTOM - (cumRatio + ratio * seg) * GLASS_H;
const color = item.color ?? LIQUID_HUES[i % LIQUID_HUES.length];
return <line key={`pour-${i}`} x1={96} y1={yTop - 4} x2={GLASS_X + GLASS_W + 2} y2={yTop + 1} stroke={color} strokeWidth="1.2" opacity={seg < 1 ? 0.9 : 0} strokeLinecap="round" />;
})}
{items.map((it, i) => {
const seg = segOf(i);
if (it.t === 'ice' && seg > 0) {
return <rect key={i} x={GLASS_X + 5 + (i % 2) * 9} y={GLASS_TOP + 4 - (1 - seg) * 16} width="9" height="9" rx="2" fill="#cfe4ef" stroke={INK} strokeWidth="0.8" transform={`rotate(${i * 12 - 6} ${GLASS_X + 9 + (i % 2) * 9} ${GLASS_TOP + 8})`} />;
}
if (it.t === 'stir' && seg > 0) {
const a = seg * 300;
return <line key={i} x1={GLASS_CX} y1={GLASS_TOP + 2} x2={GLASS_CX + Math.cos((a * Math.PI) / 180) * 8} y2={GLASS_TOP + 16 + Math.sin((a * Math.PI) / 180) * 4} stroke={INK} strokeWidth="1.1" strokeLinecap="round" opacity={seg < 1 ? 0.9 : 0.35} />;
}
if (it.t === 'garnish' && seg > 0) {
return <path key={i} d={`M ${GLASS_CX - 7} ${GLASS_TOP + 1} q 7 -5 14 0`} fill="none" stroke="#e88fb0" strokeWidth="1.6" strokeLinecap="round" opacity={seg} />;
}
return null;
})}
</svg>
</div>
</div>
<div style={{ position: 'absolute', bottom: '4.5cqh', left: '30%', right: '30%', display: 'flex', gap: '1cqw' }}>
{items.map((_, i) => (
<span key={i} style={{ flex: 1, height: '1.6cqh', borderRadius: '1cqh', background: t >= 0.24 + ((i + 1) * 0.68) / Math.max(1, items.length) ? ctx.palette.accent : `${INK}1a` }} />
))}
</div>
</div>
);
};
/** recipe-pour(R1):左杯体/右清单分区;液体份量驱动液层;冰/搅/装饰独立动作;份量为演示输入。 */
const recipePour: StageRenderer = (s, t, ctx) => {
const items = recipeItems(s, ctx);
const name = stageText(s, ctx);
const levels = liquidLevels(items);
const CUP_TOP = 20, CUP_BOTTOM = 78, INNER_H = CUP_BOTTOM - CUP_TOP - 6;
const segOf = (i: number) => clamp01((t - (0.14 + (i * 0.68) / Math.max(1, items.length))) / (0.5 / Math.max(1, items.length)));
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column' }}>
<strong style={{ position: 'absolute', top: '5cqh', left: 0, right: 0, textAlign: 'center', fontSize: 'max(12px, 4.6cqw)', color: INK, opacity: clamp01(t / 0.1) }}>{name}</strong>
<div style={{ position: 'absolute', top: '14cqh', bottom: '8cqh', left: '4cqw', right: '4cqw', display: 'flex', gap: '3cqw', alignItems: 'stretch' }}>
<div style={{ flex: 1.1, position: 'relative' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<defs><clipPath id="recipe-pour-glass-clip"><path d="M 26 16 L 26 66 Q 26 78 50 78 Q 74 78 74 66 L 74 16 Z" /></clipPath></defs>
<path d="M 26 16 L 26 66 Q 26 78 50 78 Q 74 78 74 66 L 74 16" fill="#ffffff" stroke={INK} strokeWidth="1.8" strokeLinecap="round" />
<g clipPath="url(#recipe-pour-glass-clip)">{levels.map(({ item, cumRatio, ratio }, i) => {
const seg = segOf(items.indexOf(item));
if (seg <= 0 || ratio <= 0) return null;
const h = ratio * INNER_H * seg;
const yTop = CUP_BOTTOM - 2 - (cumRatio + ratio * seg) * INNER_H;
const color = item.color ?? LIQUID_HUES[i % LIQUID_HUES.length];
return <rect key={`l${i}`} x={27.4} y={yTop} width={45.2} height={h} fill={color} opacity={0.92} />;
})}</g>
{levels.map(({ item, cumRatio, ratio }, i) => {
const seg = segOf(items.indexOf(item));
if (seg <= 0 || ratio <= 0) return null;
const yTop = CUP_BOTTOM - 2 - (cumRatio + ratio * seg) * INNER_H;
const color = item.color ?? LIQUID_HUES[i % LIQUID_HUES.length];
return <line key={`pour-${i}`} x1={92} y1={yTop - 5} x2={62} y2={yTop + 1} stroke={color} strokeWidth="1.6" strokeLinecap="round" opacity={seg < 1 ? 1 : 0} />;
})}
{items.map((it, i) => {
const seg = segOf(i);
if (it.t === 'ice' && seg > 0) return <rect key={i} x={34 + (i % 2) * 10} y={CUP_TOP + 2 - (1 - seg) * 14} width="8" height="8" rx="1.8" fill="#cfe4ef" stroke={INK} strokeWidth="0.8" />;
if (it.t === 'stir' && seg > 0) {
const a = seg * 320;
return <line key={i} x1={50} y1={CUP_TOP} x2={50 + Math.cos((a * Math.PI) / 180) * 10} y2={CUP_TOP + 14 + Math.sin((a * Math.PI) / 180) * 3} stroke={INK} strokeWidth="1.1" strokeLinecap="round" opacity={seg < 1 ? 0.95 : 0.4} />;
}
if (it.t === 'garnish' && seg > 0) return <path key={i} d="M 62 14.5 q 5 -4 10 0" fill="none" stroke="#e88fb0" strokeWidth="1.6" strokeLinecap="round" opacity={seg} />;
return null;
})}
</svg>
</div>
<div style={{ width: '34cqw', display: 'flex', flexDirection: 'column', gap: '1.7cqh', justifyContent: 'center', alignItems: 'flex-start' }}>
{items.map((it, i) => {
const on = t >= 0.14 + (i * 0.68) / Math.max(1, items.length);
const color = it.t === 'liquid' ? it.color ?? LIQUID_HUES[i % LIQUID_HUES.length] : `${INK}88`;
return (
<span key={i} style={{ maxWidth: '100%', minWidth: 0, overflowWrap: 'anywhere', fontSize: 'max(11px, 2.9cqw)', color: on ? INK : `${INK}55`, fontWeight: on ? 800 : 500, borderLeft: `0.8cqw solid ${on ? color : INK + '22'}`, paddingLeft: '1.2cqw', lineHeight: 1.35 }}>
{itemLabel(it)}
</span>
);
})}
<span style={{ maxWidth: '100%', minWidth: 0, overflowWrap: 'anywhere', fontSize: 'max(11px, 2.6cqw)', color: `${INK}66` }}>{'演示配方 · 份量为演示输入'}</span>
</div>
</div>
<span style={{ position: 'absolute', bottom: '2.6cqh', left: 0, right: 0, textAlign: 'center', fontSize: 'max(11px, 3cqw)', color: ctx.palette.accent, fontWeight: 700, opacity: clamp01((t - 0.88) / 0.1) }}>{'成品 · 液体分层可按份量核算'}</span>
</div>
);
};
/** resume-rail:姓名/定位 → 技能栅格 → 真实项目卡 → 站点入口,几何只做转场。 */
const resumeRail: StageRenderer = (s, t, ctx) => {
const [name, role = ''] = stageText(s, ctx).split('·').map((x) => x.trim());
const skills = stageLines(s, ctx).slice(0, 3);
const projects = [
{ title: 'Luca 动效实验室', desc: '站内 241 个原创动效演示与任务提示词' },
{ title: 'WorkBuddy 使用手册', desc: '站内已发布的分章教程' },
];
const seg = (a: number, b: number) => easeOutQuint(clamp01((t - a) / (b - a)));
const nameT = seg(0, 0.14), skillT = seg(0.14, 0.34), projT = seg(0.36, 0.62), railT = seg(0.64, 0.8), endT = seg(0.82, 0.96);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', gap: '2.4cqh', padding: '0 10cqw' }}>
<div style={{ display: 'flex', alignItems: 'baseline', gap: '2cqw', opacity: nameT, transform: `translateY(${(1 - nameT) * 3}cqh)` }}>
<strong style={{ fontSize: '7.4cqw', color: INK }}>{name}</strong>
<span style={{ fontSize: '3.8cqw', color: `${INK}a0` }}>{role}</span>
</div>
<div style={{ display: 'flex', gap: '2cqw', opacity: skillT }}>
{skills.map((skill, i) => (
<span key={i} style={{ fontSize: '3.2cqw', fontWeight: 700, color: ctx.palette.accent, border: `0.3cqw solid ${ctx.palette.accent}66`, borderRadius: '2cqw', padding: '0.8cqh 2.4cqw', transform: `translateY(${(1 - skillT) * (4 + i * 2)}cqh)`, background: '#fff' }}>{skill}</span>
))}
</div>
{projects.map((p, i) => (
<div key={i} style={{ width: '100%', background: '#fff', borderRadius: '1.6cqw', border: `0.25cqw solid ${INK}18`, padding: '1.6cqh 3cqw', display: 'flex', justifyContent: 'space-between', alignItems: 'center', opacity: clamp01(projT * 2 - i), transform: `translateX(${(1 - clamp01(projT * 2 - i)) * 6}cqw)` }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.6cqh', alignItems: 'flex-start' }}>
<strong style={{ fontSize: '4cqw', color: INK }}>{p.title}</strong>
<span style={{ fontSize: '3cqw', color: `${INK}99` }}>{p.desc}</span>
</div>
<span style={{ fontSize: '2.8cqw', color: `${INK}66` }}>{'站内已有'}</span>
</div>
))}
<div style={{ width: '100%', display: 'flex', alignItems: 'center', gap: '2cqw', opacity: railT }}>
<span style={{ height: '0.4cqh', flex: 1, background: `${INK}22`, borderRadius: '1cqh' }} />
<span style={{ fontSize: '2.8cqw', color: `${INK}80` }}>{'方向 · 工具 · 教程'}</span>
<span style={{ height: '0.4cqh', flex: 1, background: `${INK}22`, borderRadius: '1cqh' }} />
</div>
<span style={{ fontSize: '3.6cqw', fontWeight: 800, color: ctx.palette.accent, opacity: endT }}>{'lucahub.cn · 动效实验室'}</span>
</div>
);
};
/** whiteboard-graph:圆节点/带向边/手写公式逐步建立可核对关系(关系示意)。 */
const whiteboardGraph: StageRenderer = (s, t, ctx) => {
const nodes = stageLines(s, ctx).slice(0, 4);
const title = stageText(s, ctx);
const POS = [[22, 30], [70, 26], [26, 70], [68, 68]];
const EDGES = [[0, 1], [0, 2], [1, 3], [2, 3]];
const nodeT = (i: number) => easeOutQuint(clamp01((t - (0.14 + i * 0.12)) / 0.1));
const edgeT = (i: number) => clamp01((t - (0.34 + i * 0.13)) / 0.12);
return (
<div style={{ ...center, background: `repeating-linear-gradient(0deg,${PAPER}, ${PAPER} 9cqh, #eef0ea 9cqh, #eef0ea calc(9cqh + 1px))` }}>
<strong style={{ position: 'absolute', top: '6cqh', left: '8cqw', fontSize: '4.6cqw', color: INK, opacity: clamp01(t / 0.12) }}>{title}</strong>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<defs>
<marker id="wb-arrow" viewBox="0 0 8 8" refX="7" refY="4" markerWidth="5" markerHeight="5" orient="auto"><path d="M0,0 L8,4 L0,8 z" fill={INK} /></marker>
</defs>
{EDGES.map(([a, b], i) => {
const e = edgeT(i);
if (e <= 0) return null;
const [ax, ay] = POS[a]; const [bx, by] = POS[b];
return (
<line key={i} x1={ax + 5} y1={ay + 3} x2={bx - 5} y2={by - 3} stroke={INK} strokeWidth="0.9" markerEnd="url(#wb-arrow)" pathLength={100} strokeDasharray={100} strokeDashoffset={100 - e * 100} opacity={0.85} />
);
})}
{nodes.map((_, i) => {
const nt = nodeT(i);
const [x, y] = POS[i];
return nt > 0 ? (
<g key={i} opacity={nt}>
<circle cx={x} cy={y} r="9" fill="#fff" stroke={INK} strokeWidth="1.2" transform={`scale(${0.6 + nt * 0.4})`} style={{ transformOrigin: `${x}cqw ${y}cqw` }} />
</g>
) : null;
})}
</svg>
{nodes.map((label, i) => {
const nt = nodeT(i);
const [x, y] = POS[i];
return nt > 0 ? (
<span key={i} style={{ position: 'absolute', left: `${x}%`, top: `${y}%`, transform: 'translate(-50%,-50%)', fontSize: '3.2cqw', fontWeight: 700, color: INK, opacity: nt }}>{label}</span>
) : null;
})}
<span style={{ position: 'absolute', bottom: '8cqh', right: '8cqw', fontSize: '3.4cqw', color: ctx.palette.accent, fontWeight: 700, fontFamily: 'ui-monospace,monospace', opacity: clamp01((t - 0.82) / 0.14) }}>{'关系示意 · 方向=箭头'}</span>
<span style={{ position: 'absolute', bottom: '8cqh', left: '8cqw', width: '5cqw', height: '0.8cqh', borderRadius: '1cqh', background: ctx.palette.accent, transform: `rotate(${t * 40}deg)`, opacity: t < 0.8 ? 0.8 : 0 }} />
</div>
);
};
/** life-stages(M2):阶段参数整体插值——背景交叉渐变、身高/姿态/道具随同一过渡因子连续变化,
* 末段 25% 渐回首段参数形成循环衔接。 */
const LIFE_PARAMS = [
{ h: 42, hunch: 0, bg: '#e8f0df', ground: '#cfc6ab', fg: '#18201d', bag: 0, child: 0, cane: 0, companion: 0 },
{ h: 60, hunch: 0, bg: '#dfe8f2', ground: '#cfc6ab', fg: '#18201d', bag: 1, child: 0, cane: 0, companion: 0 },
{ h: 58, hunch: 0.15, bg: '#f2e8d8', ground: '#c9bfa4', fg: '#18201d', bag: 0, child: 1, cane: 0, companion: 0 },
{ h: 52, hunch: 0.5, bg: '#1d2433', ground: '#12182a', fg: '#e8ecf5', bag: 0, child: 0, cane: 1, companion: 1 },
];
const lerpNum = (a: number, b: number, k: number) => a + (b - a) * k;
const lifeStages: StageRenderer = (s, t, ctx) => {
const stages = stageLines(s, ctx).slice(0, 4);
const title = stageText(s, ctx);
const N = stages.length;
const f = clamp01(t / 0.94) * N;
const i = Math.min(N - 1, Math.floor(f));
let local = f - i;
const from = LIFE_PARAMS[i];
// 末段回卷到首段:循环衔接(M2)。
const j = i === N - 1 && local > 0.75 ? 0 : Math.min(N - 1, i + 1);
if (i === N - 1 && local > 0.75) local = (local - 0.75) / 0.25;
const to = LIFE_PARAMS[j];
const k = easeInOut(local);
// 回接段过半后,当前标签随之指向首段(R2:标签与人物/背景共用同一过渡状态)。
const activeIdx = i === N - 1 && j === 0 && k > 0.5 ? 0 : i;
const P = {
h: lerpNum(from.h, to.h, k),
hunch: lerpNum(from.hunch, to.hunch, k),
bag: lerpNum(from.bag, to.bag, k),
child: lerpNum(from.child, to.child, k),
cane: lerpNum(from.cane, to.cane, k),
companion: lerpNum(from.companion, to.companion, k),
};
const fg = k < 0.5 ? from.fg : to.fg;
const yBase = 86;
const headR = 5 + (P.h / 60) * 1.2;
const headY = yBase - P.h - headR;
const shoulderY = yBase - P.h * 0.92;
const hipY = yBase - P.h * 0.42;
const lean = P.hunch * 6;
return (
<div style={{ ...center, background: from.bg }}>
<div style={{ position: 'absolute', inset: 0, background: to.bg, opacity: k }} />
<div style={{ position: 'absolute', bottom: 0, left: 0, right: 0, height: '22%', background: from.ground }} />
<div style={{ position: 'absolute', bottom: 0, left: 0, right: 0, height: '22%', background: to.ground, opacity: k }} />
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<g stroke={fg} strokeWidth="2.4" strokeLinecap="round" fill="none">
<circle cx={50 + lean * 0.4} cy={headY} r={headR} fill={fg} stroke="none" />
<line x1={50 + lean * 0.2} y1={headY + headR} x2={50 + lean} y2={hipY} strokeWidth={3 + P.companion * 1.2} />
<line x1={50 + lean} y1={hipY} x2={44 - P.hunch * 3} y2={yBase} />
<line x1={50 + lean} y1={hipY} x2={56 - P.hunch * 2} y2={yBase} />
<line x1={50 + lean * 0.6} y1={shoulderY} x2={40 - P.child * 4} y2={shoulderY + 10} opacity={1 - P.child} />
<rect x={56} y={shoulderY + 4} width="6.5" height="7.5" rx="2" fill={ctx.palette.accent} stroke="none" opacity={P.bag} />
<circle cx={62 + (1 - P.child) * 4} cy={yBase - headR * 1.1} r={3.6 * P.child} fill={`${ctx.palette.accent}cc`} stroke="none" />
<line x1={57 - P.hunch * 2} y1={shoulderY + 6} x2={61 - P.hunch * 2} y2={yBase + 2} strokeWidth="1.8" opacity={P.cane} />
<circle cx={72} cy={yBase - headR * 0.9} r={3.2 * P.companion} fill={`${fg}aa`} stroke="none" />
<line x1={70} y1={yBase - 6} x2={71.5} y2={yBase} strokeWidth="1.6" opacity={P.companion} />
</g>
</svg>
<div style={{ position: 'absolute', bottom: '4cqh', left: 0, right: 0, display: 'flex', justifyContent: 'center', gap: '2.4cqw' }}>
{stages.map((label, idx) => (
<span key={idx} style={{ fontSize: '3.2cqw', fontWeight: idx === activeIdx ? 800 : 500, color: idx === activeIdx ? ctx.palette.accent : `${fg}66` }}>{label}</span>
))}
</div>
<strong style={{ position: 'absolute', top: '7cqh', fontSize: '4.4cqw', color: fg, opacity: 0.9 }}>{title}</strong>
</div>
);
};
/** code-motion(M6):展示片段=共享实现 codeMotionPoints 的逐字定义+映射行+调用,
* 预览用同一函数与映射绘制,改 amp/cycles 两边同步。 */
const codeMotion: StageRenderer = (s, t, ctx) => {
const amp = Math.min(40, Math.max(4, snum(s, 'amp', ctx.options.from)));
const cycles = Math.min(6, Math.max(1, snum(s, 'cycles', ctx.options.to)));
const title = stageText(s, ctx);
const reveal = clamp01(t / 0.9);
const codeLines = codeMotionSnippet(amp, cycles, ctx.palette.accent).split('\n');
const pts = codeMotionPoints(amp, cycles);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'row', gap: '3cqw', padding: '6cqh 6cqw' }}>
<pre style={{ margin: 0, width: '46%', alignSelf: 'stretch', background: '#141a17', color: '#cfe8d8', borderRadius: '1.6cqw', padding: '2.4cqh 2.4cqw', fontSize: '2.4cqw', lineHeight: 1.7, overflow: 'auto', fontFamily: 'ui-monospace,monospace' }}>
{codeLines.slice(0, Math.max(1, Math.ceil(reveal * codeLines.length))).map((line, i) => (
// span+换行:显示与 textContent/复制都保留换行(R3——div 会把复制品并成一行注释)。
<span key={i} style={{ opacity: 1 - Math.max(0, i - reveal * codeLines.length + 1) }}>{line + '\n'}</span>
))}
</pre>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ flex: 1, alignSelf: 'stretch', background: '#fff', borderRadius: '1.6cqw', border: `0.25cqw solid ${INK}18` }}>
{pts.map((pt, i) => {
const shown = clamp01(reveal * 1.5 - pt.x * 0.5) >= pt.x;
if (!shown) return null;
const v = codeMotionView(pt);
return <circle key={i} cx={v.cx} cy={v.cy} r="2.2" fill={ctx.palette.accent} opacity={0.4 + 0.6 * clamp01(reveal * 1.6 - pt.x)} />;
})}
</svg>
<span style={{ ...cap(), opacity: clamp01((t - 0.86) / 0.12) }}>{title}</span>
</div>
);
};
/** find-target 装饰层:夜空与星点,全部纯绘制(可交互控件在 EDITORIAL_INTERACTIVE 的稳定 UI 层,G1)。 */
const findTarget: StageRenderer = (_s, _t, _ctx) => {
return (
<div style={{ ...center, background: 'radial-gradient(120% 90% at 50% 10%, #1d2440 0%, #0d1020 70%)' }}>
{[[14, 24], [78, 18], [30, 58], [84, 66], [20, 78]].map(([x, y], i) => (
<span key={i} aria-hidden style={{ position: 'absolute', left: `${x}%`, top: `${y}%`, fontSize: `${1.6 + (i % 3)}cqw`, color: '#8fa0c0' }}>{'✦'}</span>
))}
</div>
);
};
/** find-target 交互组件(G1):开始→寻找→命中→重来,渲染于播放器稳定可访问 UI 层。 */
function FindTargetGame({ accent, ink }: { accent: string; ink: string }) {
const [phase, setPhase] = useState<'idle' | 'seek' | 'hit'>('idle');
const TARGET = { x: 58, y: 40 };
if (phase === 'idle') {
return (
<div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: '3cqh' }}>
<span style={{ fontSize: '4.6cqw', fontWeight: 700, color: '#e8ecf5', textAlign: 'center', padding: '0 6cqw' }}>{'夜空里藏了一个目标'}</span>
<button type="button" onClick={() => setPhase('seek')} style={{ font: 'inherit', fontSize: '4.2cqw', fontWeight: 800, padding: '1.6cqh 5cqw', borderRadius: '2cqw', border: 'none', background: accent, color: '#fff', cursor: 'pointer' }}>{'开始寻找'}</button>
</div>
);
}
return (
<div style={{ position: 'absolute', inset: 0, pointerEvents: 'none' }}>
<button
type="button"
aria-label={phase === 'hit' ? '目标已找到' : '藏在星空里的目标'}
onClick={() => setPhase('hit')}
style={{ position: 'absolute', left: `${TARGET.x}%`, top: `${TARGET.y}%`, font: 'inherit', background: 'transparent', border: 'none', cursor: 'pointer', fontSize: phase === 'hit' ? '6cqw' : '3.4cqw', color: phase === 'hit' ? accent : '#cfd8ea', opacity: phase === 'hit' ? 1 : 0.75, textShadow: phase === 'hit' ? `0 0 3cqw ${accent}` : 'none', transition: 'all .3s', pointerEvents: 'auto' }}
>
{'L↗'}
</button>
{phase === 'hit' ? (
<div style={{ position: 'absolute', bottom: '8cqh', left: 0, right: 0, display: 'flex', justifyContent: 'center', gap: '3cqw', alignItems: 'center', pointerEvents: 'none' }}>
<span style={{ fontSize: '4cqw', fontWeight: 800, color: accent }}>{'找到了!'}</span>
<button type="button" onClick={() => setPhase('seek')} style={{ font: 'inherit', fontSize: '3cqw', padding: '0.8cqh 3cqw', borderRadius: '1.6cqw', border: `0.25cqw solid ${ink}55`, background: '#ffffff22', color: '#e8ecf5', cursor: 'pointer', pointerEvents: 'auto' }}>{'再来一次'}</button>
</div>
) : (
<span style={{ position: 'absolute', bottom: '8cqh', left: 0, right: 0, textAlign: 'center', fontSize: '3.2cqw', color: '#c3cde2', pointerEvents: 'none' }}>{'点击发光的目标(可 Tab 聚焦后回车)'}</span>
)}
</div>
);
}
/** bezier-controls:控制点被(自动演示的)游标拖动,同一插值实时驱动曲线。 */
const bezierControls: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const drag1 = easeInOut(clamp01((t - 0.12) / 0.22));
const drag2 = easeInOut(clamp01((t - 0.4) / 0.22));
const p0 = { x: 12, y: 78 };
const p1 = { x: 26 + drag1 * 16, y: 30 + drag1 * -12 };
const p2 = { x: 60 - drag2 * 10, y: 88 - drag2 * 34 };
const p3 = { x: 90, y: 26 };
const cursor = t < 0.34 ? { x: p1.x + 3, y: p1.y - 3 } : t < 0.66 ? { x: p2.x + 3, y: p2.y - 3 } : null;
const path = `M ${p0.x} ${p0.y} C ${p1.x} ${p1.y} ${p2.x} ${p2.y} ${p3.x} ${p3.y}`;
const drawT = easeInOut(clamp01((t - 0.62) / 0.3));
void word;
return (
<div style={{ ...center, background: `repeating-linear-gradient(0deg,${ctx.palette.bg},${ctx.palette.bg} 8cqh,${INK}0d 8cqh,${INK}0d calc(8cqh + 1px)),repeating-linear-gradient(90deg,${ctx.palette.bg},${ctx.palette.bg} 8cqw,${INK}0d 8cqw,${INK}0d calc(8cqw + 1px))` }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<path d={path} fill="none" stroke={ctx.palette.accent} strokeWidth="1.8" strokeLinecap="round" pathLength={100} strokeDasharray={100} strokeDashoffset={100 - drawT * 100} />
{/* 标准控制柄(M5):p0→p1、p3→p2;端点方形实心、控制点圆形空心。 */}
<line x1={p0.x} y1={p0.y} x2={p1.x} y2={p1.y} stroke={`${INK}66`} strokeWidth="0.6" strokeDasharray="1.2 1" />
<line x1={p3.x} y1={p3.y} x2={p2.x} y2={p2.y} stroke={`${INK}66`} strokeWidth="0.6" strokeDasharray="1.2 1" />
{[p0, p3].map((p, i) => (
<rect key={`e${i}`} x={p.x - 1.8} y={p.y - 1.8} width="3.6" height="3.6" fill={INK} />
))}
{[p1, p2].map((p, i) => (
<circle key={`c${i}`} cx={p.x} cy={p.y} r="2" fill="#fff" stroke={ctx.palette.accent} strokeWidth="0.9" />
))}
{cursor ? <circle cx={cursor.x} cy={cursor.y} r="1.8" fill={INK} /> : null}
{cursor ? <circle cx={cursor.x} cy={cursor.y} r="1.8" fill={INK} /> : null}
</svg>
<span style={{ position: 'absolute', top: '7cqh', left: 0, right: 0, textAlign: 'center', fontSize: '3.6cqw', fontWeight: 700, color: `${INK}aa` }}>{'控制点 → 曲线 · 同一插值驱动'}</span>
<span style={{ ...cap() }}>{word}</span>
</div>
);
};
/** dual-window:上下双窗由同一 progress 驱动完全同拍的内容运动。 */
const dualWindow: StageRenderer = (s, t, ctx) => {
const steps = stageLines(s, ctx).slice(0, 3);
const pan = easeInOut(clamp01(t / 0.9));
const win = (label: string) => (
<div style={{ position: 'relative', flex: 1, borderRadius: '1.4cqw', border: `0.35cqw solid ${INK}2e`, overflow: 'hidden', background: '#fff' }}>
<div style={{ height: '3.4cqh', background: `${INK}0f`, display: 'flex', alignItems: 'center', paddingLeft: '1.6cqw', gap: '0.8cqw' }}>
{[0, 1, 2].map((i) => <span key={i} style={{ width: '1.4cqw', height: '1.4cqw', borderRadius: '50%', background: `${INK}33` }} />)}
<span style={{ fontSize: '2.2cqw', color: `${INK}88`, marginLeft: '1cqw' }}>{label}</span>
</div>
<div style={{ position: 'absolute', inset: '3.4cqh 0 0 0' }}>
<div style={{ position: 'absolute', inset: 0, transform: `translateX(${-pan * 14}cqw) scale(${1 + pan * 0.18})`, transformOrigin: '30% 40%' }}>
{[0, 1, 2].map((i) => (
<div key={i} style={{ margin: '2.4cqh 3cqw 0', height: '3cqh', borderRadius: '1.4cqh', background: i === 1 ? ctx.palette.accent : `${INK}1c`, width: `${86 - i * 18}%` }} />
))}
<div style={{ margin: '2.6cqh 3cqw 0', height: '26%', borderRadius: '1.2cqw', background: `${ctx.palette.accent}1c`, border: `0.25cqw solid ${ctx.palette.accent}55` }} />
</div>
</div>
</div>
);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', gap: '2cqh', padding: '7cqh 12cqw 12cqh' }}>
<div style={{ display: 'flex', flexDirection: 'column', gap: '2cqh', width: '100%', height: '100%' }}>
{win(steps[0] ?? '窗口 A')}
<div style={{ alignSelf: 'center', width: '0.6cqw', flex: 1, background: ctx.palette.accent, borderRadius: '1cqw' }} />
{win(steps[1] ?? '窗口 B')}
</div>
<span style={{ fontSize: '3.2cqw', fontWeight: 700, color: INK, opacity: clamp01((t - 0.7) / 0.2) }}>{steps[2] ?? '同拍:同组平移缩放'}</span>
</div>
);
};
/** billing-link:同一组演示用量驱动柱值与合计金额,公式可核算。 */
const billingLink: StageRenderer = (s, t, ctx) => {
const usage = [12, 24, 18, 30, 26];
const unit = ctx.options.from + (ctx.options.to - ctx.options.from) * clamp01(t / 0.85);
const shownBars = Math.ceil(clamp01(t / 0.8) * usage.length);
const total = usage.slice(0, shownBars).reduce((a, b) => a + b, 0);
const amount = total * unit;
const steps = stageLines(s, ctx).slice(0, 5);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', justifyContent: 'flex-end', paddingBottom: '16cqh' }}>
<div style={{ display: 'flex', alignItems: 'flex-end', gap: '3cqw', height: '42cqh' }}>
{usage.map((v, i) => (
<div key={i} style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: '1cqh' }}>
<span style={{ fontSize: '2.6cqw', color: `${INK}88`, opacity: i < shownBars ? 1 : 0 }}>{v}</span>
<span style={{ width: '7cqw', height: `${(v / 30) * 40 * (i < shownBars ? clamp01((t * usage.length - i)) : 0.001)}cqh`, background: ctx.palette.accent, borderRadius: '1cqw 1cqw 0 0' }} />
<span style={{ fontSize: '2.6cqw', color: `${INK}77` }}>{steps[i] ?? `第${i + 1}项`}</span>
</div>
))}
</div>
<output style={{ position: 'absolute', top: '10cqh', right: '8cqw', display: 'flex', flexDirection: 'column', alignItems: 'flex-end', gap: '0.8cqh', background: '#fff', border: `0.3cqw solid ${INK}20`, borderRadius: '1.4cqw', padding: '1.6cqh 3cqw' }}>
<span style={{ fontSize: '2.8cqw', color: `${INK}77` }}>{'合计 = 调用 × 单价(演示)'}</span>
<strong style={{ fontSize: '6.4cqw', color: INK }}>{`¥${amount.toFixed(2)}`}</strong>
<span style={{ fontSize: '2.6cqw', color: ctx.palette.accent, fontWeight: 700 }}>{`单价 ¥${unit.toFixed(2)}`}</span>
</output>
</div>
);
};
/** ohlc-chart:明确 OHLC 演示数据的蜡烛图(影线+实体),逐根揭示。 */
const ohlcChart: StageRenderer = (s, t, ctx) => {
const DATA = [
{ o: 32, c: 38, h: 41, l: 30 }, { o: 38, c: 35, h: 40, l: 33 },
{ o: 35, c: 44, h: 46, l: 34 }, { o: 44, c: 41, h: 47, l: 39 },
{ o: 41, c: 52, h: 54, l: 40 }, { o: 52, c: 49, h: 55, l: 47 },
];
const steps = stageLines(s, ctx).slice(0, 3);
const shown = clamp01(t / 0.86) * DATA.length;
const Y = (v: number) => 88 - (v / 60) * 76;
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
<span style={{ position: 'absolute', top: '7cqh', left: '8cqw', fontSize: '3cqw', color: `${INK}77` }}>{'演示数值 · OHLC 蜡烛'}</span>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ width: '84%', height: '64%' }}>
{[20, 40, 60].map((g) => <line key={g} x1="4" y1={Y(g)} x2="97" y2={Y(g)} stroke={`${INK}14`} strokeWidth="0.4" />)}
{DATA.map((d, i) => {
const k = clamp01(shown - i);
if (k <= 0) return null;
const up = d.c >= d.o;
const color = up ? ctx.palette.accent : '#b3271e';
const x = 12 + i * 14;
return (
<g key={i} opacity={Math.min(1, k * 3)}>
<line x1={x} y1={Y(d.h)} x2={x} y2={Y(d.l)} stroke={color} strokeWidth="0.9" />
<rect x={x - 4.4} y={Y(Math.max(d.o, d.c))} width="8.8" height={Math.max(1.2, Math.abs(Y(d.o) - Y(d.c)))} fill={color} rx="0.8" />
</g>
);
})}
</svg>
<div style={{ display: 'flex', gap: '4cqw', marginTop: '2cqh' }}>
{steps.map((label, i) => (
<span key={i} style={{ fontSize: '3cqw', fontWeight: t > (0.3 + i * 0.28) ? 800 : 500, color: t > (0.3 + i * 0.28) ? ctx.palette.accent : `${INK}66` }}>{label}</span>
))}
</div>
</div>
);
};
/** seasons-window:同一窗外景呈现春夏秋冬四个可辨状态并连续过渡。 */
const seasonsWindow: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const NAMES = ['春', '夏', '秋', '冬'];
const phase = clamp01(t / 0.92) * 3;
const cur = Math.min(3, Math.floor(phase));
const nxt = Math.min(3, cur + 1);
const blend = easeInOut(clamp01((phase - cur - 0.62) / 0.38));
const active = blend >= 0.5 ? nxt : cur;
const scene = (i: number, opacity: number) => (
<g key={i} data-season={NAMES[i]} opacity={opacity}>
<rect width="260" height="110" fill={['#e2eff2', '#dff0f0', '#f6e5cf', '#dce6ed'][i]} />
<circle cx="220" cy="21" r="9" fill={i === 3 ? '#f8faf6' : '#efc46c'} />
<g data-parallax="far" transform={`translate(${-t * 12} 0)`}>
{[0, 300].map((x) => (
<g key={x} transform={`translate(${x} 0)`}>
<path d="M-15 87 L43 30 L83 65 L135 22 L188 80 L224 48 L300 91 V110 H-15Z" fill={['#9faeac', '#91a99c', '#b8a693', '#aebdcc'][i]} />
<path d="M29 44 L43 30 L58 44 L46 40 L40 43Z M119 39 L135 22 L153 42 L137 36 L130 40Z" fill={i === 3 ? '#fff' : '#e8eeee'} />
</g>
))}
</g>
<rect y="81" width="260" height="29" fill={['#cfe0ad', '#97bd79', '#d7b479', '#edf2f2'][i]} />
<g data-parallax="middle" transform={`translate(${-t * 36} 0)`}>
{[0, 320].map((offset) => (
<g key={offset} transform={`translate(${offset} 0)`}>
<path d="M-20 90 Q45 65 100 83 T220 78 T340 84 V110 H-20Z" fill={['#b1c991', '#7da76a', '#bd9b60', '#e0e9e7'][i]} />
{[35, 102, 184, 272].map((x, j) => (
<g key={x} transform={`translate(${x} ${72 + j % 2 * 4})`}>
<rect width="19" height="16" fill={j % 2 ? '#e9d9bd' : '#f4e9d6'} />
<path d="M-3 0 L9.5-9 L22 0Z" fill={i === 3 ? '#fff' : '#a16d53'} />
<rect x="4" y="5" width="4" height="5" fill="#6b837e" /><rect x="12" y="5" width="4" height="5" fill="#6b837e" />
</g>
))}
</g>
))}
</g>
<g data-parallax="near" transform={`translate(${-t * 96} 0)`}>
{[0, 320].map((offset) => (
<g key={offset} transform={`translate(${offset} 0)`}>
{[26, 108, 213, 294].map((x) => (
<g key={x} transform={`translate(${x} 0)`}>
<g fill={['#91b787', '#4f8056', '#cf8c4b', 'none'][i]}>
<ellipse cy="68" rx="14" ry="18" /><circle cx="-9" cy="76" r="10" /><circle cx="9" cy="75" r="10" />
</g>
<path d="M0 108 V65 M0 87 L-9 76 M0 80 L10 69" fill="none" stroke="#685b47" strokeWidth="2.3" strokeLinecap="round" />
{i === 0 ? <g data-season-detail="blossom" fill="#edb6c0"><circle cx="-8" cy="62" r="3" /><circle cx="6" cy="65" r="3" /><circle cx="-12" cy="75" r="3" /><circle cx="11" cy="77" r="3" /></g> : null}
{i === 3 ? <path d="M-9 73 L-5 75 M0 63 V68 M7 68 L11 68" stroke="#fff" strokeWidth="3.5" strokeLinecap="round" /> : null}
</g>
))}
</g>
))}
</g>
{i === 2 ? <g data-season-detail="leaves" fill="#b66b35">{[0, 1, 2, 3, 4].map((k) => <ellipse key={k} cx={(k * 53 + 260 - t * 40) % 260} cy={(k * 29 + t * 90) % 110} rx="2.6" ry="1.3" />)}</g> : null}
{i === 3 ? <g data-season-detail="snow" fill="#fff">{Array.from({ length: 14 }, (_, k) => <circle key={k} cx={(k * 41 + 260 - t * 18) % 260} cy={(k * 27 + t * 74) % 110} r={k % 2 ? 1.2 : 1.8} />)}</g> : null}
</g>
);
return (
<div style={{ ...center, background: '#eee7d8' }}>
<svg viewBox="0 0 320 205" preserveAspectRatio="xMidYMid meet" aria-hidden="true" style={{ width: '100%', height: '100%' }}>
<rect x="22" y="12" width="276" height="126" rx="10" fill="#8b7358" />
<svg data-window-part="landscape" x="30" y="20" width="260" height="110" viewBox="0 0 260 110" overflow="hidden">
{/* 底景始终不透明,叠加下一季,避免末季或交叉淡入时露出空窗。 */}
{scene(cur, 1)}
{nxt !== cur && blend > 0 ? scene(nxt, blend) : null}
</svg>
<g data-window-part="interior" strokeLinejoin="round">
<rect x="26" y="16" width="268" height="118" rx="7" fill="none" stroke="#bfa37a" strokeWidth="4" />
<path d="M14 10 H48 Q33 57 41 130 L17 139 Q26 71 14 10Z M306 10 H272 Q287 57 279 130 L303 139 Q294 71 306 10Z" fill={ctx.palette.accent} />
<path d="M23 19 Q34 65 27 121 M297 19 Q286 65 293 121" fill="none" stroke="#fff" strokeOpacity="0.22" strokeWidth="2" />
<path d="M11 9 H309 V24 Q160 12 11 24Z" fill="#9b8767" />
<path d="M30 135 H290" stroke="#8b7358" strokeWidth="3" />
<path d="M78 151 H242 L260 171 H60Z" fill="#faf7ed" stroke="#b7a68d" strokeWidth="1.5" />
<path d="M60 172 H260 V175 H60Z" fill="#9b8767" />
<g data-window-part="coffee">
<ellipse cx="159" cy="155" rx="25" ry="4" fill="#ded5c0" />
<path d="M174 140 C190 134 191 152 173 151" fill="none" stroke="#faf7ed" strokeWidth="4" />
<path d="M143 137 H175 L172 150 Q159 159 146 150Z" fill="#faf7ed" stroke="#9b8767" strokeWidth="1" />
<path d="M145 145 Q159 151 173 145" fill="none" stroke={ctx.palette.accent} strokeWidth="2" />
<ellipse cx="159" cy="137" rx="16" ry="4" fill="#faf7ed" stroke="#9b8767" strokeWidth="1" />
<ellipse cx="159" cy="137" rx="13" ry="2.5" fill="#73523d" />
</g>
</g>
<text data-window-part="caption" x="160" y="186" textAnchor="middle" fontSize="8.2" fontWeight="600" fill={INK}>{word}</text>
{NAMES.map((name, i) => <text key={name} data-season-label={name} x={136 + i * 16} y="199" textAnchor="middle" fontSize="6.8" fontWeight={i === active ? 800 : 400} fill={i === active ? ctx.palette.accent : '#8b897e'}>{name}</text>)}
</svg>
</div>
);
};
/** doc-morph:同一外轮廓 文档→手机 连续形变,内部线稿同步衔接。 */
const docMorph: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const u = easeInOut(clamp01(t / 0.8));
const DOC = [[26, 18], [74, 18], [74, 82], [26, 82]];
const PHONE = [[36, 14], [64, 14], [64, 86], [36, 86]];
const pt = (i: number) => ({
x: DOC[i][0] + (PHONE[i][0] - DOC[i][0]) * u,
y: DOC[i][1] + (PHONE[i][1] - DOC[i][1]) * u,
});
const pts = [0, 1, 2, 3].map(pt);
const outline = `M ${pts.map((p) => `${p.x} ${p.y}`).join(' L ')} Z`;
const lineW = 36 * (1 - u * 0.72);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'column' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<path d={outline} fill="#fff" stroke={ctx.palette.accent} strokeWidth="1.6" strokeLinejoin="round" />
{[0, 1, 2, 3].map((i) => (
<line key={i} x1={50 - lineW / 2} y1={30 + i * 10 + u * 8} x2={50 - lineW / 2 + lineW * (i === 3 ? 0.6 : 1)} y2={30 + i * 10 + u * 8} stroke={`${INK}${u > 0.6 ? '3a' : '66'}`} strokeWidth="1.2" strokeLinecap="round" opacity={1 - u * 0.35} />
))}
<rect x={50 - 6 * u} y={16 + u * 2} width={12 * u} height={2.4} rx={1.2} fill={INK} opacity={u} />
<circle cx="50" cy={82 - 4 * (1 - u)} r={2.6 * u} fill="none" stroke={INK} strokeWidth="1" opacity={u} />
</svg>
<span style={{ position: 'absolute', bottom: '6cqh', fontSize: '4.2cqw', fontWeight: 700, color: INK }}>{word}</span>
<span style={{ position: 'absolute', bottom: '2.4cqh', fontSize: '2.8cqw', color: `${INK}77` }}>{'同一轮廓 · 连续形变'}</span>
</div>
);
};
/** sine-coord:最小坐标系 + 与公式同源的正弦曲线与采样点。 */
const sineCoord: StageRenderer = (s, t, ctx) => {
const steps = stageLines(s, ctx).slice(0, 3);
const AMP = 22, FREQ = 1;
const drawT = clamp01((t - 0.12) / 0.4);
const dotT = clamp01((t - 0.52) / 0.24);
const Y = (x: number) => 50 - Math.sin(x * FREQ * Math.PI * 2) * AMP;
return (
<div style={{ ...center, background: ctx.palette.bg }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
{Array.from({ length: 9 }, (_, i) => <line key={`v${i}`} x1={8 + i * 10.5} y1="10" x2={8 + i * 10.5} y2="90" stroke={`${INK}10`} strokeWidth="0.3" />)}
<line x1="8" y1="50" x2="94" y2="50" stroke={INK} strokeWidth="0.7" markerEnd="" />
<line x1="8" y1="8" x2="8" y2="92" stroke={INK} strokeWidth="0.7" />
<path d={Array.from({ length: 61 }, (_, i) => { const x = i / 60; return `${i === 0 ? 'M' : 'L'} ${8 + x * 86} ${Y(x)}`; }).join(' ')} fill="none" stroke={ctx.palette.accent} strokeWidth="1.6" strokeLinecap="round" pathLength={100} strokeDasharray={100} strokeDashoffset={100 - drawT * 100} />
{Array.from({ length: 9 }, (_, i) => {
const x = i / 8;
const on = clamp01(dotT * 9 - i);
return on > 0 ? <circle key={i} cx={8 + x * 86} cy={Y(x)} r="1.7" fill={INK} opacity={on} /> : null;
})}
</svg>
<span style={{ position: 'absolute', top: '7cqh', left: '10cqw', fontSize: '4cqw', fontFamily: 'ui-monospace,monospace', fontWeight: 700, color: INK, opacity: clamp01((t - 0.78) / 0.14) }}>{'y = A · sin(2πf·x)'}</span>
<div style={{ position: 'absolute', bottom: '6cqh', display: 'flex', gap: '3.4cqw' }}>
{steps.map((label, i) => (
<span key={i} style={{ fontSize: '3.2cqw', fontWeight: t > 0.35 + i * 0.15 ? 800 : 500, color: t > 0.35 + i * 0.15 ? ctx.palette.accent : `${INK}66` }}>{label}</span>
))}
</div>
</div>
);
};
/** spines-gather(M4):五条书脊收拢为 L↗ 五个笔画。统一 0–100 拉伸 viewBox,
* 端点/长度/方向同系插值,杜绝 cqw/% 横纵混用;标题位于笔画下方安全区。 */
const SPINE_TARGET = [
{ x1: 40, y1: 22, x2: 40, y2: 64 },
{ x1: 40, y1: 64, x2: 58, y2: 64 },
{ x1: 56, y1: 54, x2: 74, y2: 32 },
{ x1: 64, y1: 30, x2: 75, y2: 30 },
{ x1: 76, y1: 32, x2: 76, y2: 43 },
];
const SPINE_SCATTER = [
{ x1: 16, y1: 22, x2: 30, y2: 16 },
{ x1: 30, y1: 12, x2: 48, y2: 14 },
{ x1: 52, y1: 78, x2: 40, y2: 60 },
{ x1: 66, y1: 10, x2: 80, y2: 12 },
{ x1: 86, y1: 30, x2: 84, y2: 44 },
];
const spinesGather: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const g = easeInOut(clamp01((t - 0.2) / 0.56));
const HUES = ['#2455e8', '#0f7a8d', '#d97706', '#b3271e', '#1b6b50'];
return (
<div style={{ ...center, background: ctx.palette.bg }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
{SPINE_TARGET.map((seg, i) => {
const sc = SPINE_SCATTER[i];
const x1 = sc.x1 + (seg.x1 - sc.x1) * g;
const y1 = sc.y1 + (seg.y1 - sc.y1) * g;
const x2 = sc.x2 + (seg.x2 - sc.x2) * g;
const y2 = sc.y2 + (seg.y2 - sc.y2) * g;
return <line key={i} x1={x1} y1={y1} x2={x2} y2={y2} stroke={HUES[i]} strokeWidth="3.4" strokeLinecap="round" opacity={0.94} />;
})}
</svg>
<strong style={{ position: 'absolute', left: 0, right: 0, top: '74%', textAlign: 'center', fontSize: '4.2cqw', color: INK, opacity: g }}>{word}</strong>
<span style={{ position: 'absolute', top: '7cqh', left: 0, right: 0, textAlign: 'center', fontSize: '3cqw', color: `${INK}88` }}>{'书脊 → 笔画 · 逐条收拢'}</span>
</div>
);
};
/** photon-path:光源 → 弧线 → 节点真实偏折 → 探测器点亮,粒子沿同一路径。 */
const photonPath: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const u = clamp01(t / 0.9);
const bend = 0.52;
const A = { x: 12, y: 20 }, C1 = { x: 40, y: 26 }, N = { x: 56, y: 48 };
const C2 = { x: 66, y: 66 }, B = { x: 88, y: 84 };
const pos = u < bend
? { x: qPoint(A.x, C1.x, N.x, u / bend), y: qPoint(A.y, C1.y, N.y, u / bend) }
: { x: qPoint(N.x, C2.x, B.x, (u - bend) / (1 - bend)), y: qPoint(N.y, C2.y, B.y, (u - bend) / (1 - bend)) };
return (
<div style={{ ...center, background: '#10151c' }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<path d={`M ${A.x} ${A.y} Q ${C1.x} ${C1.y} ${N.x} ${N.y}`} fill="none" stroke="#f2c94c66" strokeWidth="0.6" strokeDasharray="1.4 1.4" />
<path d={`M ${N.x} ${N.y} Q ${C2.x} ${C2.y} ${B.x} ${B.y}`} fill="none" stroke="#f2c94c66" strokeWidth="0.6" strokeDasharray="1.4 1.4" />
<circle cx={A.x} cy={A.y} r="4" fill="#f2c94c" opacity={0.9} />
<circle cx={A.x} cy={A.y} r="8" fill="#f2c94c22" />
<circle cx={N.x} cy={N.y} r="3.4" fill="none" stroke="#8fd4e8" strokeWidth="1" />
<rect x={B.x - 4} y={B.y - 3} width="8" height="6" rx="1" fill={u > 0.96 ? '#f2c94c' : 'none'} stroke="#8fd4e8" strokeWidth="1" />
<circle cx={pos.x} cy={pos.y} r="2.2" fill="#ffe9a8" />
<circle cx={pos.x} cy={pos.y} r="4.4" fill="#ffe9a833" />
</svg>
<span style={{ position: 'absolute', left: '9%', top: '30%', fontSize: '2.8cqw', color: '#8fd4e8' }}>{'光源'}</span>
<span style={{ position: 'absolute', left: '58%', top: '42%', fontSize: '2.8cqw', color: '#8fd4e8' }}>{'偏折节点'}</span>
<span style={{ position: 'absolute', right: '6%', bottom: '10%', fontSize: '2.8cqw', color: '#8fd4e8' }}>{'探测器'}</span>
<span style={{ ...cap(), color: '#e8ecf5' }}>{word}</span>
</div>
);
};
/** sync-devices:桌面窗与手机由同一 game-state 驱动,比分同步滚动。 */
const syncDevices: StageRenderer = (s, t, ctx) => {
const score = Math.round(ctx.options.from + (ctx.options.to - ctx.options.from) * clamp01(t / 0.88));
const steps = stageLines(s, ctx).slice(0, 2);
const scene = (w: number, h: number) => (
<div style={{ width: '100%', height: `${h}%`, background: '#10151c', borderRadius: '1cqw', position: 'relative', overflow: 'hidden' }}>
<div style={{ position: 'absolute', left: `${12 + (t * 60) % 70}%`, top: '30%', width: w, height: w, borderRadius: '50%', background: '#f2c94c' }} />
<strong style={{ position: 'absolute', top: '6%', left: 0, right: 0, textAlign: 'center', fontSize: '4.2cqw', color: '#e8ecf5', fontFamily: 'ui-monospace,monospace' }}>{String(score)}</strong>
</div>
);
return (
<div style={{ ...center, background: ctx.palette.bg, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: '4cqw' }}>
<div style={{ width: '44cqw' }}>
{scene(3, 56)}
<span style={{ display: 'block', textAlign: 'center', marginTop: '1.4cqh', fontSize: '3cqw', color: `${INK}88` }}>{steps[0] ?? '桌面端'}</span>
</div>
<span style={{ fontSize: '5cqw', fontWeight: 800, color: ctx.palette.accent }}>{'='}</span>
<div style={{ width: '17cqw', border: `1.2cqw solid ${INK}`, borderRadius: '3cqw', padding: '1cqw', background: '#fff' }}>
<div style={{ height: '2cqh' }} />
{scene(2.4, 74)}
<span style={{ display: 'block', textAlign: 'center', margin: '1cqh 0 0.6cqh', fontSize: '2.4cqw', color: `${INK}88` }}>{steps[1] ?? '手机端'}</span>
</div>
<span style={{ position: 'absolute', top: '7cqh', left: 0, right: 0, textAlign: 'center', fontSize: '3.2cqw', fontWeight: 700, color: `${INK}aa` }}>{'同一状态 · 比分同步滚动(演示值)'}</span>
</div>
);
};
/** cursor-dive:细线网络生长后,光标沿路径下探落点,关联分支收束点亮。 */
const cursorDive: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const dive = easeInOut(clamp01((t - 0.42) / 0.36));
const glow = easeInOut(clamp01((t - 0.82) / 0.14));
const seg = (p: { x: number; y: number }, q: { x: number; y: number }, k: number) => ({
x: p.x + (q.x - p.x) * k, y: p.y + (q.y - p.y) * k,
});
const D = { x: 50, y: 78 };
const A = seg({ x: 18, y: 22 }, D, glow * 0.12);
const B = seg({ x: 82, y: 22 }, D, glow * 0.12);
const C = seg({ x: 50, y: 52 }, D, glow * 0.12);
const edges = [
{ from: A, to: C, at: 0.02, dur: 0.16 },
{ from: A, to: B, at: 0.10, dur: 0.14 },
{ from: B, to: C, at: 0.24, dur: 0.10 },
{ from: C, to: D, at: 0.30, dur: 0.10 },
];
const mid = dive < 0.5 ? seg(A, C, dive * 2) : seg(C, D, (dive - 0.5) * 2);
return (
<div style={{ ...center, background: ctx.palette.bg }}>
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet" aria-hidden="true" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%' }}>
<g stroke={ctx.palette.accent} strokeOpacity={0.35 + glow * 0.65} strokeWidth="0.8" fill="none" strokeLinecap="round">
{edges.map(({ from, to, at, dur }, i) => (
<line key={i} x1={from.x} y1={from.y} x2={to.x} y2={to.y} pathLength={100} strokeDasharray={100} strokeDashoffset={100 * (1 - easeOutQuint(clamp01((t - at) / dur)))} />
))}
</g>
<g stroke={ctx.palette.accent} strokeWidth="1.2" fill="none" strokeLinecap="round">
<line x1={A.x} y1={A.y} x2={C.x} y2={C.y} pathLength={100} strokeDasharray={100} strokeDashoffset={100 * (1 - clamp01(dive * 2))} />
<line x1={C.x} y1={C.y} x2={D.x} y2={D.y} pathLength={100} strokeDasharray={100} strokeDashoffset={100 * (1 - clamp01(dive * 2 - 1))} />
</g>
{[A, B, C, D].map((pt, i) => (
<circle key={i} cx={pt.x} cy={pt.y} r={i === 3 ? 2.4 + glow : 2.4} fill={ctx.palette.bg} stroke={ctx.palette.accent} strokeWidth="0.8" opacity={clamp01((t - [0, 0.24, 0.18, 0.40][i]) / 0.04)} />
))}
<circle cx={D.x} cy={D.y} r={3.4 * glow} fill={ctx.palette.accent} />
<path d="M0 0 L0 7 L2 5 L4 9 L6 8 L4 4 L7 4 Z" transform={`translate(${mid.x} ${mid.y})`} fill="#fff" stroke={INK} strokeWidth="0.6" strokeLinejoin="round" opacity={clamp01((t - 0.40) / 0.04) * (1 - glow)} />
</svg>
<span style={{ position: 'absolute', bottom: '6cqh', left: 0, right: 0, textAlign: 'center', fontSize: '3.2cqw', color: `${INK}99`, opacity: glow }}>{'落点收束 · 关联点亮'}</span>
<strong style={{ position: 'absolute', top: '6cqh', left: '8cqw', fontSize: '4.2cqw', color: INK, opacity: 0.85 }}>{word}</strong>
</div>
);
};
/** poster-break:画框里的海报晃动后真实冲破边框铺满画面。 */
const posterBreak: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const shake = clamp01(t / 0.26);
const amp = shake * 1.6;
const wob = Math.sin(t * 60) * amp;
const burst = easeInOut(clamp01((t - 0.3) / 0.3));
const scale = 1 + burst * 1.5;
const shard = burst;
return (
<div style={{ ...center, background: ctx.palette.bg, overflow: 'hidden' }}>
<div style={{
position: 'absolute', left: '50%', top: '48%', width: '34cqw', height: '48cqh',
transform: `translate(-50%,-50%) rotate(${wob}deg) scale(${scale})`,
background: ctx.palette.accent, borderRadius: '1cqw',
display: 'flex', alignItems: 'center', justifyContent: 'center',
boxShadow: `0 1.6cqh 5cqh ${INK}44`,
}}>
<strong style={{ fontSize: '7cqw', color: '#fff', textAlign: 'center', maxWidth: '90%' }}>{word}</strong>
</div>
{/* 画框四边:抖动期闭合环绕海报;burst 后真实碎裂飞散(未定项修复)。 */}
{[0, 1, 2, 3].map((i) => {
const bw = i % 2 === 0 ? 1.2 : 38;
const bh = i % 2 === 0 ? 54 : 1.2;
const dx = (i % 2 === 0 ? -1 : 1) * shard * 26;
const dy = (i < 2 ? -1 : 1) * shard * 20 + shard * shard * 14;
return (
<div key={i} style={{
position: 'absolute', left: '50%', top: '48%',
width: `${bw}cqw`, height: `${bh}cqh`,
background: INK, opacity: 1 - shard * 0.75,
transform: `translate(calc(-50% + ${(i % 2 === 0 ? (i === 0 ? -19 : 19) : 0) * (1 - shard) + dx}cqw), calc(-50% + ${(i < 2 ? (i === 1 ? -27 : 27) : 0) * (1 - shard) + dy}cqh)) rotate(${shard * (i % 2 === 0 ? 24 : -18)}deg)`,
borderRadius: '0.6cqw',
}} />
);
})}
<span style={{ ...cap(), opacity: clamp01((t - 0.7) / 0.2) }}>{'冲破边框 · 铺满画面'}</span>
</div>
);
};
/** dots-character:散点真实聚合成可辨几何小角色,落位后挥手表情登场。 */
const dotsCharacter: StageRenderer = (s, t, ctx) => {
const word = stageText(s, ctx);
const alive = clamp01((t - 0.6) / 0.3);
const head = { x: 50, y: 34, r: 7 };
const bodyTop = { x: 50, y: 41 }, bodyBot = { x: 50, y: 62 };
const armL = { x: 39, y: 50 };
const armR2 = { x: 66, y: 44 - alive * 6 };
const legL = { x: 44, y: 74 }, legR = { x: 56, y: 74 };
const pts: Array<{ x: number; y: number }> = [];
for (let i = 0; i < 14; i++) {
const a = (i / 14) * Math.PI * 2;
pts.push({ x: head.x + Math.cos(a) * head.r, y: head.y + Math.sin(a) * head.r });
}
for (let i = 0; i < 8; i++) pts.push({ x: 50 + (i % 2 === 0 ? -2.4 : 2.4), y: bodyTop.y + (i / 8) * (bodyBot.y - bodyTop.y) });
for (let i = 0; i < 5; i++) pts.push({ x: bodyTop.x + (armR2.x - bodyTop.x) * (i / 5) + i * 0.3, y: bodyTop.y + 6 + (armR2.y - bodyTop.y - 6) * (i / 5) - (i / 5) * alive * 8 });
for (let i = 0; i < 4; i++) pts.push({ x: 50 + (armL.x - 50) * (i / 4), y: bodyTop.y + 6 + (armL.y - bodyTop.y - 6) * (i / 4) });
for (let i = 0; i < 5; i++) pts.push({ x: 50 + (legL.x - 50) * (i / 5), y: bodyBot.y + (legL.y - bodyBot.y) * (i / 5) });
for (let i = 0; i < 5; i++) pts.push({ x: 50 + (legR.x - 50) * (i / 5), y: bodyBot.y + (legR.y - bodyBot.y) * (i / 5) });
return (
<div style={{ ...center, background: '#141a2e' }}>
{pts.map((pt, i) => {
const sx = ((i * 37) % 90) + 5;
const sy = ((i * 53) % 80) + 10;
const delay = (i % 6) * 0.04;
const k = easeOutQuint(clamp01((t - delay) / 0.5));
const x = sx + (pt.x - sx) * k;
const y = sy + (pt.y - sy) * k;
return <span key={i} style={{ position: 'absolute', left: `${x}%`, top: `${y}%`, width: '1.3cqw', height: '1.3cqw', borderRadius: '50%', background: i < 14 ? ctx.palette.accent : '#cfd8ea', opacity: 0.35 + k * 0.65 }} />;
})}
{alive > 0 ? (
<svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', opacity: alive }}>
<circle cx="47" cy="33" r="0.9" fill={INK} />
<circle cx="53" cy="33" r="0.9" fill={INK} />
<path d="M 47 37 Q 50 39.6 53 37" fill="none" stroke={INK} strokeWidth="0.8" strokeLinecap="round" />
</svg>
) : null}
<span style={{ ...cap(), color: '#e8ecf5', opacity: clamp01((t - 0.82) / 0.14) }}>{word}</span>
</div>
);
};
/** 可交互阶段的稳定可访问 UI 组件(G1):由 CaseDemo 在 figure 级 UI 层渲染,compact 不渲染。 */
export const EDITORIAL_INTERACTIVE: Record<string, ComponentType<{ accent: string; ink: string }>> = {
'find-target': FindTargetGame,
};
export const EDITORIAL_STAGES: Record<string, StageRenderer> = {
'image-through': imageThrough,
'image-layout': imageLayout,
'image-cards': imageCards,
'image-compare': imageCompare,
'path-flight': pathFlight,
'orbit-follow': orbitFollow,
'bike-ride': bikeRide,
'recipe-draw': recipeDraw,
'recipe-pour': recipePour,
'resume-rail': resumeRail,
'whiteboard-graph': whiteboardGraph,
'life-stages': lifeStages,
'code-motion': codeMotion,
'find-target': findTarget,
'bezier-controls': bezierControls,
'dual-window': dualWindow,
'billing-link': billingLink,
'ohlc-chart': ohlcChart,
'seasons-window': seasonsWindow,
'doc-morph': docMorph,
'sine-coord': sineCoord,
'spines-gather': spinesGather,
'photon-path': photonPath,
'sync-devices': syncDevices,
'cursor-dive': cursorDive,
'poster-break': posterBreak,
'dots-character': dotsCharacter,
};
/**
* Luca 品牌素材:站点页头蓝底 L↗ 标识的自包含可复用版本。
* 与站内 .brand-mark(app/globals.css)同一构图,但自带样式与颜色,
* 不依赖站内 CSS 变量,方便整体复制到其他项目。
*/
export const LUCA_BLUE = '#2455e8';
export const LUCA_INK = '#18201d';
export const LUCA_PAPER = '#fafaf7';
export function LucaBrandMark({
size = 72,
blue = LUCA_BLUE,
ink = '#ffffff',
}: {
size?: number;
blue?: string;
ink?: string;
}) {
const unit = size / 36;
return (
<span
className="luca-brand-mark"
aria-hidden="true"
style={{
width: size,
height: size * (38 / 36),
background: blue,
color: ink,
fontSize: unit * 29,
lineHeight: `${unit * 39}px`,
paddingLeft: unit * 7,
}}
>
L
<span
style={{ fontSize: unit * 15, right: unit * 3, top: unit * -5 }}
>
↗
</span>
</span>
);
}
/**
* 站点蓝底白字标识的 SVG 版本:给 Canvas、场景插画等需要矢量图形的位置用。
*/
export function lucaMarkPath(blue = LUCA_BLUE, ink = '#ffffff') {
return `<g><rect width="36" height="38" fill="${blue}"/><text x="7" y="30" font-family="-apple-system,'PingFang SC',sans-serif" font-size="29" font-weight="800" fill="${ink}">L</text><text x="26" y="12" font-size="15" font-weight="600" fill="${ink}">↗</text></g>`;
}
/** Luca 演示常用语义短语(原创文案,可编辑)。 */
export const LUCA_PHRASES = {
brand: 'Luca',
site: 'LucaHub',
tagline: '把想法做成动效',
sections: ['教程', '工具集', '动效实验室', '实践笔记'],
} as const;
/* 参考改编案例播放器样式:只作用于演示舞台内部。
* 根舞台规则(.motion-stage)独立复用时必需;
* 主站中 motion-demo.css 已含相同规则,两处值一致不冲突。 */
.motion-stage {
--motion-color: #2455e8;
position: relative;
margin: 0;
isolation: isolate;
width: 100%;
height: 380px;
overflow: hidden;
container-type: inline-size;
background: #f0f2ed;
color: #18201d;
font-family:
-apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei',
sans-serif;
}
.motion-stage--compact {
height: 240px;
}
.motion-case-art {
container-type: size;
position: absolute;
inset: 0;
overflow: hidden;
}
.motion-layer {
position: absolute;
inset: 0;
}
.luca-brand-mark {
position: relative;
display: inline-flex;
font-weight: 800;
letter-spacing: -0.04em;
}
.luca-brand-mark > span {
position: absolute;
font-weight: 600;
}
/* 案例卡片缩略:与原六项卡片同构,演示区域固定比例。 */
.motion-card .motion-case {
aspect-ratio: 16 / 10;
}
.motion-case-art canvas {
display: block;
}
/* 必需资产状态行(可访问 UI 层,位于 aria-hidden 绘图区之外;R5-03) */
.motion-case-assets {
position: absolute;
top: 5%;
left: 4%;
z-index: 30;
display: flex;
align-items: center;
gap: 1.6cqw;
max-width: 92%;
background: rgba(250, 250, 247, 0.94);
border: 1px solid rgba(24, 32, 29, 0.16);
border-radius: 1.4cqw;
padding: 1.1cqh 2.2cqw;
font-size: 3.2cqw;
line-height: 1.3;
color: #18201d;
}
.motion-asset-retry {
font: inherit;
font-size: 3cqw;
cursor: pointer;
border: 1px solid rgba(24, 32, 29, 0.28);
background: #ffffff;
color: #18201d;
border-radius: 1cqw;
padding: 0.5cqh 1.8cqw;
}
.motion-asset-retry:hover { background: #f1f4ef; }
.motion-asset-retry:focus-visible {
outline: 2px solid #1b6b50;
outline-offset: 1px;
}
/* 可交互阶段的可访问 UI 层(G1):覆盖舞台但不在 aria-hidden 子树。 */
.motion-case-interactive {
position: absolute;
inset: 0;
z-index: 20;
pointer-events: none;
}
.motion-case-interactive > * { pointer-events: auto; }
.motion-case-interactive button:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
参考来源与已知限制
Anime robot combining sequence · 風の民@
https://prompt-motion.com/allforbigfire-86ff3c
观察范围(公开详情页文本):观察自参考案例公开详情页:原始标题、分类标签与创作者公开的动作提示词文本;未观看原视频。 Luca 改编:仅标题级观察(动漫合体需求);动漫形象不使用,改编为几何部件合体原创演示。
仅标题级观察(动漫合体需求);动漫形象不使用,改编为几何部件合体原创演示。本站演示、图形与任务提示词独立编写,未使用参考视频、音乐或品牌素材。
- 这些是实验演示,尚无实际项目使用记录;不提供视频、GIF 或跨框架导出。