Spaces:
Sleeping
Sleeping
File size: 9,935 Bytes
806144f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | import { useEffect, useMemo, useState } from 'react';
import type { DemoLocale } from './types';
type MarketingScene = {
id: 'brief' | 'copy' | 'visual';
durationMs: number;
};
type MarketingFeatureDemoProps = {
locale: DemoLocale;
isBusy: boolean;
};
const COPY = {
en: {
title: 'Marketing Demo',
busy: 'Running',
hidden: 'Hidden',
play: 'Play',
pause: 'Pause',
replay: 'Replay',
hide: 'Hide',
show: 'Show',
videoName: 'marketing_demo.webm',
step: 'Step',
lanes: {
brief: 'Brief',
copy: 'Copy',
visual: 'Visual',
},
captions: {
brief: 'Collect product + tone inputs',
copy: 'Stream campaign copy blocks',
visual: 'Generate image variations',
},
words: {
briefChips: ['Product', 'Tone', 'Channel'],
copyChips: ['Headline', 'Caption', 'CTA', 'Tags'],
visualCards: ['Hero', 'Social'],
streamWords: ['Drafting', 'Refining', 'Scoring', 'Polishing'],
visualImages: [
'https://upload.wikimedia.org/wikipedia/commons/d/dd/Eggs_in_basket_2020_G1.jpg',
'https://upload.wikimedia.org/wikipedia/commons/c/c2/Fresh_Vegetables_2.jpg',
],
},
},
'zh-TW': {
title: '行銷導覽',
busy: '執行中',
hidden: '已隱藏',
play: '播放',
pause: '暫停',
replay: '重播',
hide: '隱藏',
show: '顯示',
videoName: '行銷導覽影片.webm',
step: '步驟',
lanes: {
brief: '需求',
copy: '文案',
visual: '素材',
},
captions: {
brief: '收集產品與語氣設定',
copy: '串流活動文案區塊',
visual: '生成多版本圖片',
},
words: {
briefChips: ['產品', '語氣', '渠道'],
copyChips: ['標題', '內文', 'CTA', '標籤'],
visualCards: ['主視覺', '社群版'],
streamWords: ['生成', '潤稿', '評估', '優化'],
visualImages: [
'https://upload.wikimedia.org/wikipedia/commons/d/dd/Eggs_in_basket_2020_G1.jpg',
'https://upload.wikimedia.org/wikipedia/commons/c/c2/Fresh_Vegetables_2.jpg',
],
},
},
} as const;
const SCENES: MarketingScene[] = [
{ id: 'brief', durationMs: 1650 },
{ id: 'copy', durationMs: 1750 },
{ id: 'visual', durationMs: 1700 },
];
export default function MarketingFeatureDemo({ locale, isBusy }: MarketingFeatureDemoProps) {
const copy = COPY[locale];
const scenes = useMemo(() => SCENES, []);
const [sceneIndex, setSceneIndex] = useState(0);
const [elapsedMs, setElapsedMs] = useState(0);
const [isPlaying, setIsPlaying] = useState(true);
const [isCollapsed, setIsCollapsed] = useState(false);
const [reducedMotion, setReducedMotion] = useState(false);
useEffect(() => {
const media = window.matchMedia('(prefers-reduced-motion: reduce)');
const apply = () => setReducedMotion(media.matches);
apply();
if (media.addEventListener) {
media.addEventListener('change', apply);
return () => media.removeEventListener('change', apply);
}
media.addListener(apply);
return () => media.removeListener(apply);
}, []);
useEffect(() => {
if (reducedMotion) setIsPlaying(false);
}, [reducedMotion]);
useEffect(() => {
setSceneIndex(0);
setElapsedMs(0);
setIsCollapsed(false);
if (!reducedMotion) setIsPlaying(true);
}, [locale, reducedMotion]);
useEffect(() => {
if (!isBusy) return;
setIsCollapsed(true);
setIsPlaying(false);
}, [isBusy]);
useEffect(() => {
if (!isPlaying || isCollapsed || isBusy || reducedMotion) return;
const timer = window.setInterval(() => {
setElapsedMs((prev) => {
const scene = scenes[sceneIndex];
if (!scene) return 0;
const next = prev + 120;
if (next < scene.durationMs) return next;
setSceneIndex((current) => (current + 1) % scenes.length);
return 0;
});
}, 120);
return () => window.clearInterval(timer);
}, [isPlaying, isCollapsed, isBusy, reducedMotion, scenes, sceneIndex]);
const activeScene = scenes[sceneIndex] ?? scenes[0];
const totalDuration = scenes.reduce((sum, scene) => sum + scene.durationMs, 0);
const previousDuration = scenes.slice(0, sceneIndex).reduce((sum, scene) => sum + scene.durationMs, 0);
const progress = totalDuration > 0 ? Math.round(((previousDuration + elapsedMs) / totalDuration) * 100) : 0;
const sceneCaption = copy.captions[activeScene.id];
const streamOffset = Math.floor(elapsedMs / 420);
const activeStreamWords = copy.words.streamWords.map(
(_word, index) => copy.words.streamWords[(streamOffset + index) % copy.words.streamWords.length]
);
const replay = () => {
setSceneIndex(0);
setElapsedMs(0);
if (!reducedMotion && !isBusy) setIsPlaying(true);
};
if (isCollapsed) {
return (
<section className="marketing-walk-collapsed" aria-live="polite">
<div className="marketing-walk-mini-markers" aria-hidden="true">
<span />
<span />
<span />
</div>
<p>{isBusy ? copy.busy : copy.hidden}</p>
{!isBusy ? (
<button
type="button"
className="ghost-btn"
onClick={() => {
setIsCollapsed(false);
replay();
}}
>
{copy.show}
</button>
) : null}
</section>
);
}
return (
<section className="marketing-walk-video" aria-label={copy.title}>
<header className="marketing-walk-head">
<div>
<h3>{copy.title}</h3>
<small>
{copy.step} {sceneIndex + 1}/{scenes.length}
</small>
</div>
<div className="marketing-walk-actions">
<button
type="button"
className="marketing-walk-icon-btn"
onClick={() => setIsPlaying((prev) => !prev)}
disabled={isBusy || reducedMotion}
aria-label={isPlaying ? copy.pause : copy.play}
>
{isPlaying ? '||' : '>'}
</button>
<button type="button" className="marketing-walk-icon-btn" onClick={replay} disabled={isBusy} aria-label={copy.replay}>
R
</button>
<button type="button" className="marketing-walk-icon-btn" onClick={() => setIsCollapsed(true)} aria-label={copy.hide}>
X
</button>
</div>
</header>
<div className="marketing-walk-frame" data-scene={activeScene.id}>
<div className="marketing-walk-windowbar">
<span />
<span />
<span />
<small>{copy.videoName}</small>
</div>
<div className="marketing-walk-canvas">
<section className="marketing-walk-lane brief">
<span className="marketing-walk-lane-index">1</span>
<small className="marketing-walk-lane-label">{copy.lanes.brief}</small>
<div className="marketing-walk-chip-row">
{copy.words.briefChips.map((item) => (
<span key={item}>{item}</span>
))}
</div>
<div className="marketing-walk-line lg" />
<div className="marketing-walk-line md" />
<p>{locale === 'zh-TW' ? '產品資訊與活動目標已整理。' : 'Product context and campaign goal prepared.'}</p>
</section>
<section className="marketing-walk-lane copy">
<span className="marketing-walk-lane-index">2</span>
<small className="marketing-walk-lane-label">{copy.lanes.copy}</small>
<div className="marketing-walk-copy-card">
{activeStreamWords.slice(0, 3).map((word, index) => (
<div key={`${word}-${index}`} className={`marketing-walk-stream-pill ${index === 0 ? 'lg' : index === 1 ? 'sm' : 'md'}`}>
<span>{word}</span>
</div>
))}
</div>
<div className="marketing-walk-chip-row">
{copy.words.copyChips.map((item) => (
<span key={item}>{item}</span>
))}
</div>
</section>
<section className="marketing-walk-lane visual">
<span className="marketing-walk-lane-index">3</span>
<small className="marketing-walk-lane-label">{copy.lanes.visual}</small>
<div className="marketing-walk-visual-grid">
{copy.words.visualCards.map((label, index) => (
<article key={label}>
<img
src={copy.words.visualImages[index % copy.words.visualImages.length]}
alt={label}
loading="lazy"
referrerPolicy="no-referrer"
/>
<small>{label}</small>
</article>
))}
</div>
<p>{locale === 'zh-TW' ? '輸出可下載圖像與套用按鈕。' : 'Download-ready assets and apply actions.'}</p>
</section>
</div>
</div>
<footer className="marketing-walk-meta">
<div className="marketing-walk-progress-track" aria-hidden="true">
<span style={{ width: `${Math.min(100, Math.max(0, progress))}%` }} />
</div>
<p className="marketing-walk-caption">{sceneCaption}</p>
<div className="marketing-walk-scene-dots">
{scenes.map((scene, index) => (
<button
key={scene.id}
type="button"
className={`marketing-walk-scene-dot ${index === sceneIndex ? 'active' : index < sceneIndex ? 'complete' : ''}`}
onClick={() => {
setSceneIndex(index);
setElapsedMs(0);
}}
aria-label={`${copy.step} ${index + 1}`}
>
<span />
</button>
))}
</div>
</footer>
</section>
);
}
|