@remixmate/template-core 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +167 -0
- package/LICENSE +85 -0
- package/README.md +18 -0
- package/dist/index.cjs +2211 -0
- package/dist/index.d.mts +1293 -0
- package/dist/index.d.ts +1293 -0
- package/dist/index.js +2153 -0
- package/package.json +44 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2211 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React3 = require('react');
|
|
4
|
+
var remotion = require('remotion');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var React3__default = /*#__PURE__*/_interopDefault(React3);
|
|
10
|
+
|
|
11
|
+
// src/primitives/Background.tsx
|
|
12
|
+
|
|
13
|
+
// src/utils/diagnostics.ts
|
|
14
|
+
var SAFE_ID = /^[a-zA-Z0-9_.:-]{1,128}$/;
|
|
15
|
+
var reported = /* @__PURE__ */ new Set();
|
|
16
|
+
function sanitizeDiagnosticSrc(src) {
|
|
17
|
+
if (src.startsWith("data:")) {
|
|
18
|
+
const end = src.indexOf(";");
|
|
19
|
+
return src.slice(0, end > 0 ? end : 32);
|
|
20
|
+
}
|
|
21
|
+
return src.split(/[?#]/)[0] ?? src;
|
|
22
|
+
}
|
|
23
|
+
function reportSceneDegraded(report) {
|
|
24
|
+
const { templateId, reason, sceneId, slideId, dedupeKey, detail } = report;
|
|
25
|
+
const key = [templateId ?? "", sceneId ?? "", slideId ?? "", reason, dedupeKey ?? ""].join("|");
|
|
26
|
+
if (reported.has(key)) return;
|
|
27
|
+
reported.add(key);
|
|
28
|
+
const extra = {};
|
|
29
|
+
for (const [k, v] of Object.entries(detail ?? {})) {
|
|
30
|
+
if (v === void 0) continue;
|
|
31
|
+
extra[k] = k === "src" && typeof v === "string" ? sanitizeDiagnosticSrc(v) : v;
|
|
32
|
+
}
|
|
33
|
+
if (!SAFE_ID.test(reason)) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`[core] degraded reason ${JSON.stringify(reason)} is not a safe id; the server will drop it`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
console.warn(
|
|
39
|
+
"__diagnostic_v1__ " + JSON.stringify({
|
|
40
|
+
...extra,
|
|
41
|
+
event: "template.scene.degraded",
|
|
42
|
+
...templateId !== void 0 ? { template_id: templateId } : {},
|
|
43
|
+
...sceneId !== void 0 ? { scene_id: sceneId } : {},
|
|
44
|
+
...slideId !== void 0 ? { slide_id: slideId } : {},
|
|
45
|
+
reason
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function resetSceneDegradedReports() {
|
|
50
|
+
reported.clear();
|
|
51
|
+
}
|
|
52
|
+
function useVideoProbe(src) {
|
|
53
|
+
const [status, setStatus] = React3.useState({
|
|
54
|
+
src: null,
|
|
55
|
+
value: "pending"
|
|
56
|
+
});
|
|
57
|
+
React3.useLayoutEffect(() => {
|
|
58
|
+
if (!src) return;
|
|
59
|
+
const handle = remotion.delayRender(`Probing background video ${src.split(/[?#]/)[0]}`);
|
|
60
|
+
let released = false;
|
|
61
|
+
const release = () => {
|
|
62
|
+
if (released) return;
|
|
63
|
+
released = true;
|
|
64
|
+
remotion.continueRender(handle);
|
|
65
|
+
};
|
|
66
|
+
const probe = document.createElement("video");
|
|
67
|
+
probe.preload = "metadata";
|
|
68
|
+
probe.muted = true;
|
|
69
|
+
const onLoaded = () => {
|
|
70
|
+
setStatus({ src, value: "ok" });
|
|
71
|
+
release();
|
|
72
|
+
};
|
|
73
|
+
const onError = () => {
|
|
74
|
+
setStatus({ src, value: "error" });
|
|
75
|
+
release();
|
|
76
|
+
};
|
|
77
|
+
probe.addEventListener("loadedmetadata", onLoaded, { once: true });
|
|
78
|
+
probe.addEventListener("error", onError, { once: true });
|
|
79
|
+
probe.src = src;
|
|
80
|
+
return () => {
|
|
81
|
+
probe.removeEventListener("loadedmetadata", onLoaded);
|
|
82
|
+
probe.removeEventListener("error", onError);
|
|
83
|
+
probe.removeAttribute("src");
|
|
84
|
+
probe.load();
|
|
85
|
+
release();
|
|
86
|
+
};
|
|
87
|
+
}, [src]);
|
|
88
|
+
return status.src === src ? status.value : "pending";
|
|
89
|
+
}
|
|
90
|
+
var PAN_AMPLITUDE_PCT = 5;
|
|
91
|
+
var PAN_SCALE = 1.12;
|
|
92
|
+
function backgroundMotionStyle(motion, progress) {
|
|
93
|
+
const p = Math.min(Math.max(progress, 0), 1);
|
|
94
|
+
switch (motion) {
|
|
95
|
+
case "kenburns-in":
|
|
96
|
+
return { transform: `scale(${1 + p * 0.15})` };
|
|
97
|
+
case "kenburns-out":
|
|
98
|
+
return { transform: `scale(${1 + (1 - p) * 0.15})` };
|
|
99
|
+
case "pan-left": {
|
|
100
|
+
const tx = PAN_AMPLITUDE_PCT - p * PAN_AMPLITUDE_PCT * 2;
|
|
101
|
+
return { transform: `translateX(${tx}%) scale(${PAN_SCALE})` };
|
|
102
|
+
}
|
|
103
|
+
case "pan-right": {
|
|
104
|
+
const tx = -PAN_AMPLITUDE_PCT + p * PAN_AMPLITUDE_PCT * 2;
|
|
105
|
+
return { transform: `translateX(${tx}%) scale(${PAN_SCALE})` };
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
var FALLBACK_COLOR = "#1a1a2e";
|
|
112
|
+
function warnBackgroundLoadFailed(src, type) {
|
|
113
|
+
reportSceneDegraded({
|
|
114
|
+
reason: "background_load_failed",
|
|
115
|
+
dedupeKey: src,
|
|
116
|
+
detail: { component: "Background", media_type: type, src }
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
var Background = ({
|
|
120
|
+
src,
|
|
121
|
+
type = "image",
|
|
122
|
+
color,
|
|
123
|
+
gradient,
|
|
124
|
+
motion = "static",
|
|
125
|
+
durationFrames,
|
|
126
|
+
fallbackColor = FALLBACK_COLOR
|
|
127
|
+
}) => {
|
|
128
|
+
const frame = remotion.useCurrentFrame();
|
|
129
|
+
const progress = Math.min(frame / Math.max(durationFrames, 1), 1);
|
|
130
|
+
const motionStyle = backgroundMotionStyle(motion, progress);
|
|
131
|
+
const [failedSrc, setFailedSrc] = React3.useState(null);
|
|
132
|
+
const handleError = React3.useCallback(() => {
|
|
133
|
+
if (!src) return;
|
|
134
|
+
warnBackgroundLoadFailed(src, type === "video" ? "video" : "image");
|
|
135
|
+
setFailedSrc(src);
|
|
136
|
+
}, [src, type]);
|
|
137
|
+
const videoProbe = useVideoProbe(type === "video" && src ? src : null);
|
|
138
|
+
const videoFailed = type === "video" && videoProbe === "error";
|
|
139
|
+
React3.useEffect(() => {
|
|
140
|
+
if (videoFailed && src) warnBackgroundLoadFailed(src, "video");
|
|
141
|
+
}, [videoFailed, src]);
|
|
142
|
+
if (color || gradient) {
|
|
143
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
144
|
+
remotion.AbsoluteFill,
|
|
145
|
+
{
|
|
146
|
+
style: {
|
|
147
|
+
background: gradient || color || "#000"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (!src || failedSrc === src || videoFailed) {
|
|
153
|
+
return /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { backgroundColor: fallbackColor } });
|
|
154
|
+
}
|
|
155
|
+
if (type === "video") {
|
|
156
|
+
if (videoProbe !== "ok") return null;
|
|
157
|
+
return /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
158
|
+
remotion.Video,
|
|
159
|
+
{
|
|
160
|
+
src,
|
|
161
|
+
muted: true,
|
|
162
|
+
loop: true,
|
|
163
|
+
onError: handleError,
|
|
164
|
+
style: {
|
|
165
|
+
width: "100%",
|
|
166
|
+
height: "100%",
|
|
167
|
+
objectFit: "cover",
|
|
168
|
+
...motionStyle
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
) });
|
|
172
|
+
}
|
|
173
|
+
return /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
174
|
+
remotion.Img,
|
|
175
|
+
{
|
|
176
|
+
src,
|
|
177
|
+
onError: handleError,
|
|
178
|
+
style: {
|
|
179
|
+
width: "100%",
|
|
180
|
+
height: "100%",
|
|
181
|
+
objectFit: "cover",
|
|
182
|
+
...motionStyle
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
) });
|
|
186
|
+
};
|
|
187
|
+
function useAssetUrl(assetId, resolvedAssets) {
|
|
188
|
+
return React3.useMemo(() => {
|
|
189
|
+
if (!assetId) return null;
|
|
190
|
+
const asset = resolvedAssets.find((a) => a.assetId === assetId);
|
|
191
|
+
if (!asset) return null;
|
|
192
|
+
return asset.url || asset.localPath || null;
|
|
193
|
+
}, [assetId, resolvedAssets]);
|
|
194
|
+
}
|
|
195
|
+
function resolveAssetUrl(assetId, resolvedAssets) {
|
|
196
|
+
if (!assetId) return null;
|
|
197
|
+
const asset = resolvedAssets.find((a) => a.assetId === assetId);
|
|
198
|
+
return asset?.url || asset?.localPath || null;
|
|
199
|
+
}
|
|
200
|
+
function resolveAsset(assetId, resolvedAssets) {
|
|
201
|
+
if (!assetId) return void 0;
|
|
202
|
+
return resolvedAssets.find((a) => a.assetId === assetId);
|
|
203
|
+
}
|
|
204
|
+
var MEDIA_OVERLAY_MASK = "linear-gradient(180deg, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.75) 45%, rgba(0,0,0,1) 78%, rgba(0,0,0,1) 100%)";
|
|
205
|
+
function grainDataUri(blend) {
|
|
206
|
+
const tint = blend === "screen" ? 1 : 0;
|
|
207
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.6' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 ${tint} 0 0 0 0 ${tint} 0 0 0 0 ${tint} 0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(#n)' opacity='0.55'/></svg>`;
|
|
208
|
+
return `url("data:image/svg+xml,${encodeURIComponent(svg)}")`;
|
|
209
|
+
}
|
|
210
|
+
function resolveSceneBackground(background, signaturePreset, defaultMediaMotion = "kenburns-in", defaultOverlayOpacity = 0.35) {
|
|
211
|
+
const preset = background?.preset ?? signaturePreset;
|
|
212
|
+
const isMedia = preset === "image" || preset === "video";
|
|
213
|
+
return {
|
|
214
|
+
preset,
|
|
215
|
+
isSignaturePreset: preset === signaturePreset,
|
|
216
|
+
isMedia,
|
|
217
|
+
paintCanvas: preset !== "none",
|
|
218
|
+
motion: background?.motion ?? defaultMediaMotion,
|
|
219
|
+
blurPx: Math.max(0, background?.blurPx ?? 0),
|
|
220
|
+
overlayOpacity: background?.overlayOpacity ?? (isMedia ? defaultOverlayOpacity : 0)
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
var SceneBackgroundLayer = ({
|
|
224
|
+
background,
|
|
225
|
+
resolvedAssets,
|
|
226
|
+
durationFrames,
|
|
227
|
+
canvasBg,
|
|
228
|
+
noiseBlend,
|
|
229
|
+
signaturePreset,
|
|
230
|
+
defaultGradient,
|
|
231
|
+
defaultMediaMotion = "kenburns-in",
|
|
232
|
+
defaultOverlayColor = "rgba(8, 10, 28, 1)",
|
|
233
|
+
defaultOverlayOpacity = 0.35,
|
|
234
|
+
signature,
|
|
235
|
+
depth
|
|
236
|
+
}) => {
|
|
237
|
+
const { preset, isSignaturePreset, isMedia, paintCanvas, motion, blurPx, overlayOpacity } = resolveSceneBackground(
|
|
238
|
+
background,
|
|
239
|
+
signaturePreset,
|
|
240
|
+
defaultMediaMotion,
|
|
241
|
+
defaultOverlayOpacity
|
|
242
|
+
);
|
|
243
|
+
const imageSrc = preset === "image" ? resolveAssetUrl(background?.assetRef, resolvedAssets) || background?.imageUrl || null : null;
|
|
244
|
+
const videoSrc = preset === "video" ? resolveAssetUrl(background?.videoAssetRef, resolvedAssets) || background?.videoUrl || null : null;
|
|
245
|
+
const videoProbe = useVideoProbe(videoSrc);
|
|
246
|
+
const videoFailed = !!videoSrc && videoProbe === "error";
|
|
247
|
+
React3.useEffect(() => {
|
|
248
|
+
if (videoFailed && videoSrc) warnBackgroundLoadFailed(videoSrc, "video");
|
|
249
|
+
}, [videoFailed, videoSrc]);
|
|
250
|
+
const overlayColor = background?.overlayColor ?? defaultOverlayColor;
|
|
251
|
+
const slotCtx = { preset, isSignaturePreset, isMedia };
|
|
252
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { children: [
|
|
253
|
+
paintCanvas && /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { backgroundColor: canvasBg } }),
|
|
254
|
+
preset === "solid" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
255
|
+
remotion.AbsoluteFill,
|
|
256
|
+
{
|
|
257
|
+
style: {
|
|
258
|
+
background: background?.cssBackground || background?.color || canvasBg
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
),
|
|
262
|
+
preset === "gradient" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
263
|
+
remotion.AbsoluteFill,
|
|
264
|
+
{
|
|
265
|
+
style: {
|
|
266
|
+
background: background?.cssBackground || (background?.color ? `linear-gradient(160deg, ${background.color} 0%, ${canvasBg} 100%)` : defaultGradient)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
preset === "image" && imageSrc && /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: blurPx > 0 ? /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { filter: `blur(${blurPx}px)` }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
271
|
+
Background,
|
|
272
|
+
{
|
|
273
|
+
src: imageSrc,
|
|
274
|
+
type: "image",
|
|
275
|
+
motion,
|
|
276
|
+
durationFrames
|
|
277
|
+
}
|
|
278
|
+
) }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
279
|
+
Background,
|
|
280
|
+
{
|
|
281
|
+
src: imageSrc,
|
|
282
|
+
type: "image",
|
|
283
|
+
motion,
|
|
284
|
+
durationFrames
|
|
285
|
+
}
|
|
286
|
+
) }),
|
|
287
|
+
preset === "video" && videoFailed && /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { backgroundColor: canvasBg } }),
|
|
288
|
+
preset === "video" && videoSrc && videoProbe === "ok" && /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
289
|
+
remotion.Video,
|
|
290
|
+
{
|
|
291
|
+
src: videoSrc,
|
|
292
|
+
muted: background?.videoMuted ?? true,
|
|
293
|
+
loop: background?.videoLoop ?? true,
|
|
294
|
+
onError: () => void 0,
|
|
295
|
+
style: {
|
|
296
|
+
width: "100%",
|
|
297
|
+
height: "100%",
|
|
298
|
+
objectFit: "cover",
|
|
299
|
+
filter: blurPx > 0 ? `blur(${blurPx}px)` : void 0
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
) }),
|
|
303
|
+
preset === "noise" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
304
|
+
remotion.AbsoluteFill,
|
|
305
|
+
{
|
|
306
|
+
style: {
|
|
307
|
+
opacity: background?.noiseOpacity ?? 0.4,
|
|
308
|
+
backgroundImage: grainDataUri(noiseBlend),
|
|
309
|
+
mixBlendMode: noiseBlend
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
),
|
|
313
|
+
isMedia && overlayOpacity > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
314
|
+
remotion.AbsoluteFill,
|
|
315
|
+
{
|
|
316
|
+
style: {
|
|
317
|
+
// 平铺一色即可。html-slide 原本写成 linear-gradient(C 0%, C 100%),
|
|
318
|
+
// 两种写法实测逐像素相同(2026-09-10,1920×1080 image preset),
|
|
319
|
+
// 取简洁的这一种。
|
|
320
|
+
background: overlayColor,
|
|
321
|
+
opacity: overlayOpacity,
|
|
322
|
+
maskImage: MEDIA_OVERLAY_MASK,
|
|
323
|
+
WebkitMaskImage: MEDIA_OVERLAY_MASK
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
),
|
|
327
|
+
signature?.(slotCtx),
|
|
328
|
+
paintCanvas && depth?.(slotCtx)
|
|
329
|
+
] });
|
|
330
|
+
};
|
|
331
|
+
var REFERENCE_LONG_EDGE = 1920;
|
|
332
|
+
function useCanvasScale() {
|
|
333
|
+
const { width, height } = remotion.useVideoConfig();
|
|
334
|
+
return Math.max(width, height) / REFERENCE_LONG_EDGE;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/utils/fontStack.ts
|
|
338
|
+
var WEIGHT_SUFFIXES = [
|
|
339
|
+
"Thin",
|
|
340
|
+
"ExtraLight",
|
|
341
|
+
"UltraLight",
|
|
342
|
+
"Light",
|
|
343
|
+
"Regular",
|
|
344
|
+
"Normal",
|
|
345
|
+
"Medium",
|
|
346
|
+
"Semibold",
|
|
347
|
+
"SemiBold",
|
|
348
|
+
"DemiBold",
|
|
349
|
+
"Bold",
|
|
350
|
+
"ExtraBold",
|
|
351
|
+
"UltraBold",
|
|
352
|
+
"Black",
|
|
353
|
+
"Heavy"
|
|
354
|
+
];
|
|
355
|
+
function deWeighted(family) {
|
|
356
|
+
for (const suffix of WEIGHT_SUFFIXES) {
|
|
357
|
+
if (family.length > suffix.length + 1 && family.endsWith(" " + suffix)) {
|
|
358
|
+
return family.slice(0, -(suffix.length + 1)).trim();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return void 0;
|
|
362
|
+
}
|
|
363
|
+
var CJK_FALLBACKS = ['"Noto Sans SC"', '"Noto Sans CJK SC"'];
|
|
364
|
+
var GENERIC_FAMILIES = /* @__PURE__ */ new Set([
|
|
365
|
+
"sans-serif",
|
|
366
|
+
"serif",
|
|
367
|
+
"monospace",
|
|
368
|
+
"cursive",
|
|
369
|
+
"fantasy",
|
|
370
|
+
"system-ui",
|
|
371
|
+
"ui-sans-serif",
|
|
372
|
+
"ui-serif",
|
|
373
|
+
"ui-monospace",
|
|
374
|
+
"ui-rounded"
|
|
375
|
+
]);
|
|
376
|
+
function quote(family) {
|
|
377
|
+
if (/^".*"$/.test(family) || /^'.*'$/.test(family)) return family;
|
|
378
|
+
if (/^[a-z-]+$/.test(family)) return family;
|
|
379
|
+
return `"${family}"`;
|
|
380
|
+
}
|
|
381
|
+
function fontStack(font) {
|
|
382
|
+
const entries = [];
|
|
383
|
+
const seen = /* @__PURE__ */ new Set();
|
|
384
|
+
let generic;
|
|
385
|
+
const push = (family) => {
|
|
386
|
+
const quoted = quote(family);
|
|
387
|
+
const key = quoted.toLowerCase();
|
|
388
|
+
if (seen.has(key)) return;
|
|
389
|
+
seen.add(key);
|
|
390
|
+
entries.push(quoted);
|
|
391
|
+
};
|
|
392
|
+
for (const raw of (font ?? "").split(",")) {
|
|
393
|
+
const family = raw.trim().replace(/^["']|["']$/g, "");
|
|
394
|
+
if (family.length === 0) continue;
|
|
395
|
+
if (GENERIC_FAMILIES.has(family.toLowerCase())) {
|
|
396
|
+
generic ??= family.toLowerCase();
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
push(family);
|
|
400
|
+
const bare = deWeighted(family);
|
|
401
|
+
if (bare) push(bare);
|
|
402
|
+
}
|
|
403
|
+
if (entries.length === 0) push("PingFang SC");
|
|
404
|
+
for (const fallback of CJK_FALLBACKS) push(fallback);
|
|
405
|
+
entries.push(generic ?? "sans-serif");
|
|
406
|
+
return entries.join(", ");
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/utils/subtitleChunks.ts
|
|
410
|
+
var DEFAULT_SPLIT_MAX_UNITS = 20;
|
|
411
|
+
var DEFAULT_MIN_CHUNK_UNITS = 7;
|
|
412
|
+
var LINE_FILL_LIMIT = 0.9;
|
|
413
|
+
var BREAK_LEVELS = [
|
|
414
|
+
/[。!?!?]/,
|
|
415
|
+
// 句末
|
|
416
|
+
/[::;;]/,
|
|
417
|
+
// 子句
|
|
418
|
+
/[,,]/,
|
|
419
|
+
// 逗号
|
|
420
|
+
/[、]/,
|
|
421
|
+
// 顿号(并列项之间,最弱)
|
|
422
|
+
/ /
|
|
423
|
+
// 空格 —— 只为保护英文单词不被硬切
|
|
424
|
+
];
|
|
425
|
+
var TRAILING_PUNCT = /[。!?;,,、::..…]+$/;
|
|
426
|
+
var ASCII_EM = {
|
|
427
|
+
// 小写
|
|
428
|
+
a: 0.572,
|
|
429
|
+
b: 0.602,
|
|
430
|
+
c: 0.561,
|
|
431
|
+
d: 0.602,
|
|
432
|
+
e: 0.567,
|
|
433
|
+
f: 0.346,
|
|
434
|
+
g: 0.602,
|
|
435
|
+
h: 0.577,
|
|
436
|
+
i: 0.275,
|
|
437
|
+
j: 0.276,
|
|
438
|
+
k: 0.553,
|
|
439
|
+
l: 0.254,
|
|
440
|
+
m: 0.884,
|
|
441
|
+
n: 0.581,
|
|
442
|
+
o: 0.6,
|
|
443
|
+
p: 0.602,
|
|
444
|
+
q: 0.602,
|
|
445
|
+
r: 0.374,
|
|
446
|
+
s: 0.525,
|
|
447
|
+
t: 0.362,
|
|
448
|
+
u: 0.582,
|
|
449
|
+
v: 0.506,
|
|
450
|
+
w: 0.777,
|
|
451
|
+
x: 0.537,
|
|
452
|
+
y: 0.526,
|
|
453
|
+
z: 0.506,
|
|
454
|
+
// 大写
|
|
455
|
+
A: 0.679,
|
|
456
|
+
B: 0.69,
|
|
457
|
+
C: 0.732,
|
|
458
|
+
D: 0.72,
|
|
459
|
+
E: 0.642,
|
|
460
|
+
F: 0.582,
|
|
461
|
+
G: 0.756,
|
|
462
|
+
H: 0.736,
|
|
463
|
+
I: 0.257,
|
|
464
|
+
J: 0.538,
|
|
465
|
+
K: 0.714,
|
|
466
|
+
L: 0.592,
|
|
467
|
+
M: 0.903,
|
|
468
|
+
N: 0.732,
|
|
469
|
+
O: 0.775,
|
|
470
|
+
P: 0.655,
|
|
471
|
+
Q: 0.775,
|
|
472
|
+
R: 0.697,
|
|
473
|
+
S: 0.651,
|
|
474
|
+
T: 0.615,
|
|
475
|
+
U: 0.734,
|
|
476
|
+
V: 0.659,
|
|
477
|
+
W: 0.953,
|
|
478
|
+
X: 0.664,
|
|
479
|
+
Y: 0.691,
|
|
480
|
+
Z: 0.639,
|
|
481
|
+
// 数字
|
|
482
|
+
"0": 0.6,
|
|
483
|
+
"1": 0.41,
|
|
484
|
+
"2": 0.6,
|
|
485
|
+
"3": 0.6,
|
|
486
|
+
"4": 0.6,
|
|
487
|
+
"5": 0.6,
|
|
488
|
+
"6": 0.6,
|
|
489
|
+
"7": 0.553,
|
|
490
|
+
"8": 0.6,
|
|
491
|
+
"9": 0.6,
|
|
492
|
+
// 标点与符号
|
|
493
|
+
" ": 0.333,
|
|
494
|
+
"!": 0.333,
|
|
495
|
+
'"': 0.488,
|
|
496
|
+
"#": 0.6,
|
|
497
|
+
$: 0.6,
|
|
498
|
+
"%": 0.996,
|
|
499
|
+
"&": 0.751,
|
|
500
|
+
"'": 0.281,
|
|
501
|
+
"(": 0.333,
|
|
502
|
+
")": 0.333,
|
|
503
|
+
"*": 0.516,
|
|
504
|
+
"+": 0.605,
|
|
505
|
+
",": 0.275,
|
|
506
|
+
"-": 0.605,
|
|
507
|
+
".": 0.275,
|
|
508
|
+
"/": 0.5,
|
|
509
|
+
":": 0.275,
|
|
510
|
+
";": 0.275,
|
|
511
|
+
"<": 0.605,
|
|
512
|
+
"=": 0.605,
|
|
513
|
+
">": 0.605,
|
|
514
|
+
"?": 0.558,
|
|
515
|
+
"@": 0.866,
|
|
516
|
+
"[": 0.333,
|
|
517
|
+
"\\": 0.5,
|
|
518
|
+
"]": 0.333,
|
|
519
|
+
"^": 0.545,
|
|
520
|
+
_: 0.5,
|
|
521
|
+
"`": 0.333,
|
|
522
|
+
"{": 0.333,
|
|
523
|
+
"|": 0.214,
|
|
524
|
+
"}": 0.333,
|
|
525
|
+
"~": 0.5
|
|
526
|
+
};
|
|
527
|
+
var FALLBACK_NARROW_EM = 0.55;
|
|
528
|
+
function displayWidth(text) {
|
|
529
|
+
let width = 0;
|
|
530
|
+
for (const ch of text) {
|
|
531
|
+
if ((ch.codePointAt(0) ?? 0) >= 4352) {
|
|
532
|
+
width += 1;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
width += ASCII_EM[ch] ?? FALLBACK_NARROW_EM;
|
|
536
|
+
}
|
|
537
|
+
return width;
|
|
538
|
+
}
|
|
539
|
+
var LATIN_RUN = /[A-Za-z]+/g;
|
|
540
|
+
var CJK_PUNCT = new RegExp(
|
|
541
|
+
"[\\u3000-\\u303F\\uFF01-\\uFF0F\\uFF1A-\\uFF20\\uFF3B-\\uFF40\\uFF5B-\\uFF65]"
|
|
542
|
+
);
|
|
543
|
+
function spokenWeight(text) {
|
|
544
|
+
if (!text) return 0;
|
|
545
|
+
let weight = 0;
|
|
546
|
+
for (const ch of text) {
|
|
547
|
+
const cp = ch.codePointAt(0) ?? 0;
|
|
548
|
+
if (cp >= 4352) {
|
|
549
|
+
if (!CJK_PUNCT.test(ch)) weight += 1;
|
|
550
|
+
} else if (ch >= "0" && ch <= "9") weight += 1.2;
|
|
551
|
+
}
|
|
552
|
+
for (const [run] of text.matchAll(LATIN_RUN)) {
|
|
553
|
+
const isAcronym = run.length <= 5 && run === run.toUpperCase();
|
|
554
|
+
weight += isAcronym ? run.length : run.length * 0.33;
|
|
555
|
+
}
|
|
556
|
+
return weight;
|
|
557
|
+
}
|
|
558
|
+
function estimateLineCapacity(availableWidthPx, fontSizePx, letterSpacingPx = 0) {
|
|
559
|
+
const advance = fontSizePx + letterSpacingPx;
|
|
560
|
+
if (!(advance > 0) || !(availableWidthPx > 0)) return DEFAULT_SPLIT_MAX_UNITS;
|
|
561
|
+
return Math.max(1, Math.floor(availableWidthPx / advance));
|
|
562
|
+
}
|
|
563
|
+
function tokenize(text, breakAfter) {
|
|
564
|
+
const tokens = [];
|
|
565
|
+
let current = "";
|
|
566
|
+
for (const ch of text) {
|
|
567
|
+
current += ch;
|
|
568
|
+
if (breakAfter.test(ch)) {
|
|
569
|
+
tokens.push(current);
|
|
570
|
+
current = "";
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (current) tokens.push(current);
|
|
574
|
+
return tokens;
|
|
575
|
+
}
|
|
576
|
+
function hardSplit(token, maxUnits) {
|
|
577
|
+
const total = displayWidth(token);
|
|
578
|
+
if (total <= maxUnits) return [token];
|
|
579
|
+
const out = [];
|
|
580
|
+
let current = "";
|
|
581
|
+
let width = 0;
|
|
582
|
+
let remainingWidth = total;
|
|
583
|
+
let remainingPieces = Math.ceil(total / maxUnits);
|
|
584
|
+
for (const ch of token) {
|
|
585
|
+
const w = displayWidth(ch);
|
|
586
|
+
const target = remainingWidth / remainingPieces;
|
|
587
|
+
const exceedsMax = width + w > maxUnits;
|
|
588
|
+
const exceedsTarget = width + w > target && remainingPieces > 1;
|
|
589
|
+
if (current && (exceedsMax || exceedsTarget)) {
|
|
590
|
+
out.push(current);
|
|
591
|
+
remainingWidth -= width;
|
|
592
|
+
remainingPieces = Math.max(1, remainingPieces - 1);
|
|
593
|
+
current = "";
|
|
594
|
+
width = 0;
|
|
595
|
+
}
|
|
596
|
+
current += ch;
|
|
597
|
+
width += w;
|
|
598
|
+
}
|
|
599
|
+
if (current) out.push(current);
|
|
600
|
+
return out;
|
|
601
|
+
}
|
|
602
|
+
function packTokens(tokens, target, maxUnits) {
|
|
603
|
+
const parts = [];
|
|
604
|
+
let current = "";
|
|
605
|
+
let width = 0;
|
|
606
|
+
for (const token of tokens) {
|
|
607
|
+
const w = displayWidth(token);
|
|
608
|
+
if (!current) {
|
|
609
|
+
current = token;
|
|
610
|
+
width = w;
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
const merged = width + w;
|
|
614
|
+
const worseThanStopping = Math.abs(merged - target) > Math.abs(width - target);
|
|
615
|
+
if (merged > maxUnits || worseThanStopping) {
|
|
616
|
+
parts.push(current);
|
|
617
|
+
current = token;
|
|
618
|
+
width = w;
|
|
619
|
+
} else {
|
|
620
|
+
current = current + token;
|
|
621
|
+
width = merged;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (current) parts.push(current);
|
|
625
|
+
return parts;
|
|
626
|
+
}
|
|
627
|
+
function mergeShort(parts, minChunkUnits, splitMaxUnits) {
|
|
628
|
+
if (parts.length <= 1) return parts;
|
|
629
|
+
const out = [parts[0]];
|
|
630
|
+
for (let i = 1; i < parts.length; i++) {
|
|
631
|
+
const part = parts[i];
|
|
632
|
+
const prev = out[out.length - 1];
|
|
633
|
+
const prevWidth = displayWidth(prev);
|
|
634
|
+
const partWidth = displayWidth(part);
|
|
635
|
+
const tooShort = prevWidth < minChunkUnits || partWidth < minChunkUnits;
|
|
636
|
+
if (tooShort && prevWidth + partWidth <= splitMaxUnits) {
|
|
637
|
+
out[out.length - 1] = prev + part;
|
|
638
|
+
} else {
|
|
639
|
+
out.push(part);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return out;
|
|
643
|
+
}
|
|
644
|
+
function resolveThresholds(options) {
|
|
645
|
+
const maxUnitsPerLine = Math.max(1, options.maxUnitsPerLine);
|
|
646
|
+
const splitMax = Math.max(
|
|
647
|
+
1,
|
|
648
|
+
Math.min(
|
|
649
|
+
options.splitMaxUnits ?? DEFAULT_SPLIT_MAX_UNITS,
|
|
650
|
+
Math.floor(maxUnitsPerLine * LINE_FILL_LIMIT)
|
|
651
|
+
)
|
|
652
|
+
);
|
|
653
|
+
const minChunk = Math.min(
|
|
654
|
+
options.minChunkUnits ?? DEFAULT_MIN_CHUNK_UNITS,
|
|
655
|
+
splitMax
|
|
656
|
+
);
|
|
657
|
+
return { maxUnitsPerLine, splitMax, minChunk };
|
|
658
|
+
}
|
|
659
|
+
function splitSubtitleText(text, options) {
|
|
660
|
+
const trimmed = (text ?? "").trim();
|
|
661
|
+
if (!trimmed) return [];
|
|
662
|
+
const { splitMax, minChunk } = resolveThresholds(options);
|
|
663
|
+
const finish = (parts2) => parts2.map((part) => part.trim().replace(TRAILING_PUNCT, "").trim()).filter(Boolean);
|
|
664
|
+
if (displayWidth(trimmed) <= splitMax) return finish([trimmed]);
|
|
665
|
+
const tooWide = (part) => displayWidth(part) > splitMax;
|
|
666
|
+
const packAtLevel = (part, breakAfter) => {
|
|
667
|
+
const total = displayWidth(part);
|
|
668
|
+
const pieces = Math.max(1, Math.ceil(total / splitMax));
|
|
669
|
+
return packTokens(tokenize(part, breakAfter), total / pieces, splitMax);
|
|
670
|
+
};
|
|
671
|
+
let parts = [trimmed];
|
|
672
|
+
for (const breakAfter of BREAK_LEVELS) {
|
|
673
|
+
parts = parts.flatMap(
|
|
674
|
+
(part) => tooWide(part) ? packAtLevel(part, breakAfter) : [part]
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
parts = parts.flatMap(
|
|
678
|
+
(part) => tooWide(part) ? hardSplit(part, splitMax) : [part]
|
|
679
|
+
);
|
|
680
|
+
return finish(mergeShort(parts, minChunk, splitMax));
|
|
681
|
+
}
|
|
682
|
+
function chunkSubtitleSegments(segments, options) {
|
|
683
|
+
const { minFrames = 0 } = options;
|
|
684
|
+
const out = [];
|
|
685
|
+
for (const segment of segments) {
|
|
686
|
+
const span = segment.endFrame - segment.startFrame;
|
|
687
|
+
const parts = splitSubtitleText(segment.text, options);
|
|
688
|
+
if (parts.length === 0) continue;
|
|
689
|
+
if (parts.length === 1 || span < minFrames * parts.length) {
|
|
690
|
+
const whole = parts.length === 1 ? parts[0] : segment.text.trim().replace(TRAILING_PUNCT, "").trim();
|
|
691
|
+
out.push(whole === segment.text ? segment : { ...segment, text: whole });
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const spoken = parts.map(spokenWeight);
|
|
695
|
+
const totalSpoken = spoken.reduce((sum, w) => sum + w, 0);
|
|
696
|
+
const weights = totalSpoken > 0 ? spoken : parts.map((part) => displayWidth(part));
|
|
697
|
+
const totalWeight = weights.reduce((sum, w) => sum + w, 0) || 1;
|
|
698
|
+
let cursor = segment.startFrame;
|
|
699
|
+
parts.forEach((part, i) => {
|
|
700
|
+
const remaining = parts.length - 1 - i;
|
|
701
|
+
let end;
|
|
702
|
+
if (remaining === 0) {
|
|
703
|
+
end = segment.endFrame;
|
|
704
|
+
} else {
|
|
705
|
+
const frames = Math.round(span * weights[i] / totalWeight);
|
|
706
|
+
end = Math.min(
|
|
707
|
+
Math.max(cursor + 1, cursor + frames),
|
|
708
|
+
segment.endFrame - remaining
|
|
709
|
+
);
|
|
710
|
+
}
|
|
711
|
+
out.push({ text: part, startFrame: cursor, endFrame: end });
|
|
712
|
+
cursor = end;
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
return out;
|
|
716
|
+
}
|
|
717
|
+
function resolveRunFadeOpacity(frame, runStart, runEnd, capFrames) {
|
|
718
|
+
const runLength = Math.max(0, runEnd - runStart);
|
|
719
|
+
const fade = Math.min(
|
|
720
|
+
Math.max(0, Math.floor(capFrames)),
|
|
721
|
+
Math.floor((runLength - 1) / 2)
|
|
722
|
+
);
|
|
723
|
+
if (fade < 1) return 1;
|
|
724
|
+
if (frame <= runStart || frame >= runEnd) return 0;
|
|
725
|
+
if (frame < runStart + fade) return (frame - runStart) / fade;
|
|
726
|
+
if (frame > runEnd - fade) return (runEnd - frame) / fade;
|
|
727
|
+
return 1;
|
|
728
|
+
}
|
|
729
|
+
function resolveChunkFadeOpacity(framesIntoChunk) {
|
|
730
|
+
const FLOOR = 0.35;
|
|
731
|
+
const FRAMES = 4;
|
|
732
|
+
if (framesIntoChunk <= 0) return FLOOR;
|
|
733
|
+
if (framesIntoChunk >= FRAMES) return 1;
|
|
734
|
+
return FLOOR + (1 - FLOOR) * (framesIntoChunk / FRAMES);
|
|
735
|
+
}
|
|
736
|
+
function resolveActiveChunk(chunks, frame, holdFrames) {
|
|
737
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
738
|
+
const chunk = chunks[i];
|
|
739
|
+
if (frame >= chunk.startFrame && frame < chunk.endFrame) return chunk;
|
|
740
|
+
const next = chunks[i + 1];
|
|
741
|
+
if (next && frame >= chunk.endFrame && frame < next.startFrame && next.startFrame - chunk.endFrame <= holdFrames) {
|
|
742
|
+
return chunk;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return void 0;
|
|
746
|
+
}
|
|
747
|
+
var AUTO_BRIGHT_THRESHOLD = 0.55;
|
|
748
|
+
var AUTO_DARK_THRESHOLD = 0.35;
|
|
749
|
+
var SCRIM_HEIGHT_RATIO = 0.28;
|
|
750
|
+
var DEFAULT_MAX_WIDTH_PCT = {
|
|
751
|
+
dark: 85,
|
|
752
|
+
light: 85,
|
|
753
|
+
scrim: 88,
|
|
754
|
+
stroke: 90,
|
|
755
|
+
none: 85
|
|
756
|
+
};
|
|
757
|
+
var HOLD_SEC = 0.5;
|
|
758
|
+
var MIN_DWELL_SEC = 0.6;
|
|
759
|
+
function resolveFontSize(mode, baseSize, scale, fontScale) {
|
|
760
|
+
const size = mode === "stroke" ? Math.max(baseSize + 2, 30) : baseSize;
|
|
761
|
+
return size * scale * fontScale;
|
|
762
|
+
}
|
|
763
|
+
var DEFAULT_BOTTOM_PX = {
|
|
764
|
+
dark: 80,
|
|
765
|
+
light: 80,
|
|
766
|
+
scrim: 80,
|
|
767
|
+
stroke: 80,
|
|
768
|
+
none: 0
|
|
769
|
+
};
|
|
770
|
+
var REFERENCE_HEIGHT = 1920;
|
|
771
|
+
function resolveSubtitleBottomPx(mode, canvas, bottomRatio) {
|
|
772
|
+
if (bottomRatio !== void 0) return canvas.height * bottomRatio;
|
|
773
|
+
return DEFAULT_BOTTOM_PX[mode] * (canvas.height / REFERENCE_HEIGHT);
|
|
774
|
+
}
|
|
775
|
+
function resolveSubtitleMode(mode, captionStyle, backgroundLuma) {
|
|
776
|
+
const requested = mode ?? (captionStyle === "stroke" ? "stroke" : captionStyle === "pill" ? "dark" : void 0);
|
|
777
|
+
if (requested === void 0) return "dark";
|
|
778
|
+
if (requested !== "auto") return requested;
|
|
779
|
+
if (typeof backgroundLuma !== "number" || !Number.isFinite(backgroundLuma)) {
|
|
780
|
+
return "scrim";
|
|
781
|
+
}
|
|
782
|
+
if (backgroundLuma > AUTO_BRIGHT_THRESHOLD) return "dark";
|
|
783
|
+
if (backgroundLuma < AUTO_DARK_THRESHOLD) return "light";
|
|
784
|
+
return "scrim";
|
|
785
|
+
}
|
|
786
|
+
var SubtitleBar = ({
|
|
787
|
+
segments,
|
|
788
|
+
style = "bottom",
|
|
789
|
+
typography,
|
|
790
|
+
captionStyle,
|
|
791
|
+
mode,
|
|
792
|
+
bottomRatio,
|
|
793
|
+
fontScale = 1,
|
|
794
|
+
maxWidthPct,
|
|
795
|
+
backgroundLuma
|
|
796
|
+
}) => {
|
|
797
|
+
const frame = remotion.useCurrentFrame();
|
|
798
|
+
const scale = useCanvasScale();
|
|
799
|
+
const { width, height, fps } = remotion.useVideoConfig();
|
|
800
|
+
const resolved = resolveSubtitleMode(mode, captionStyle, backgroundLuma);
|
|
801
|
+
const bodyFamily = fontStack(typography?.bodyFont);
|
|
802
|
+
const baseSize = typography?.bodySize || 32;
|
|
803
|
+
const fontSize = resolveFontSize(resolved, baseSize, scale, fontScale);
|
|
804
|
+
const widthPct = maxWidthPct ?? DEFAULT_MAX_WIDTH_PCT[resolved];
|
|
805
|
+
const chunks = React3__default.default.useMemo(
|
|
806
|
+
() => chunkSubtitleSegments(segments, {
|
|
807
|
+
maxUnitsPerLine: estimateLineCapacity(
|
|
808
|
+
width * widthPct / 100,
|
|
809
|
+
fontSize
|
|
810
|
+
),
|
|
811
|
+
minFrames: Math.round(fps * MIN_DWELL_SEC)
|
|
812
|
+
}),
|
|
813
|
+
[segments, width, widthPct, fontSize, fps]
|
|
814
|
+
);
|
|
815
|
+
const active = resolveActiveChunk(
|
|
816
|
+
chunks,
|
|
817
|
+
frame,
|
|
818
|
+
Math.round(fps * HOLD_SEC)
|
|
819
|
+
);
|
|
820
|
+
if (resolved === "none" || !active) return null;
|
|
821
|
+
const runStart = chunks[0].startFrame;
|
|
822
|
+
const runEnd = chunks[chunks.length - 1].endFrame;
|
|
823
|
+
const scrimOpacity = resolveRunFadeOpacity(frame, runStart, runEnd, 8);
|
|
824
|
+
const plateOpacity = scrimOpacity;
|
|
825
|
+
const textOpacity = resolveChunkFadeOpacity(frame - active.startFrame);
|
|
826
|
+
const paddingBottom = resolveSubtitleBottomPx(resolved, { height }, bottomRatio);
|
|
827
|
+
const positionStyle = style === "center" ? { justifyContent: "center", alignItems: "center" } : { justifyContent: "flex-end", alignItems: "center", paddingBottom };
|
|
828
|
+
const plate = (background, color, shadow) => ({
|
|
829
|
+
backgroundColor: background,
|
|
830
|
+
color,
|
|
831
|
+
fontWeight: 600,
|
|
832
|
+
fontSize,
|
|
833
|
+
fontFamily: bodyFamily,
|
|
834
|
+
padding: `${16 * scale}px ${32 * scale}px`,
|
|
835
|
+
borderRadius: 12 * scale,
|
|
836
|
+
maxWidth: `${widthPct}%`,
|
|
837
|
+
textAlign: "center",
|
|
838
|
+
lineHeight: 1.4,
|
|
839
|
+
textShadow: shadow
|
|
840
|
+
});
|
|
841
|
+
let captionBoxStyle;
|
|
842
|
+
switch (resolved) {
|
|
843
|
+
case "light":
|
|
844
|
+
captionBoxStyle = plate(
|
|
845
|
+
"rgba(255, 255, 255, 0.85)",
|
|
846
|
+
"#1A1A1A",
|
|
847
|
+
// Weaker than the dark plate's: a light plate on a light photo still
|
|
848
|
+
// needs an edge, but a heavy shadow reads as dirty.
|
|
849
|
+
"0 1px 4px rgba(0,0,0,0.18)"
|
|
850
|
+
);
|
|
851
|
+
break;
|
|
852
|
+
case "scrim":
|
|
853
|
+
captionBoxStyle = {
|
|
854
|
+
...plate("transparent", "#FFFFFF", "0 2px 10px rgba(0,0,0,0.7)"),
|
|
855
|
+
borderRadius: 0,
|
|
856
|
+
padding: `0 ${32 * scale}px`
|
|
857
|
+
};
|
|
858
|
+
break;
|
|
859
|
+
case "stroke":
|
|
860
|
+
captionBoxStyle = {
|
|
861
|
+
backgroundColor: "transparent",
|
|
862
|
+
color: "#FFFFFF",
|
|
863
|
+
fontSize,
|
|
864
|
+
fontWeight: 700,
|
|
865
|
+
fontFamily: bodyFamily,
|
|
866
|
+
padding: `${8 * scale}px ${16 * scale}px`,
|
|
867
|
+
maxWidth: `${widthPct}%`,
|
|
868
|
+
textAlign: "center",
|
|
869
|
+
lineHeight: 1.45,
|
|
870
|
+
textShadow: "1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 2px 10px rgba(0,0,0,0.75)"
|
|
871
|
+
};
|
|
872
|
+
break;
|
|
873
|
+
case "dark":
|
|
874
|
+
default:
|
|
875
|
+
captionBoxStyle = plate(
|
|
876
|
+
"rgba(0, 0, 0, 0.65)",
|
|
877
|
+
"#FFFFFF",
|
|
878
|
+
"0 2px 8px rgba(0,0,0,0.55)"
|
|
879
|
+
);
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
883
|
+
resolved === "scrim" && style !== "center" && /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { zIndex: 10, pointerEvents: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
884
|
+
"div",
|
|
885
|
+
{
|
|
886
|
+
style: {
|
|
887
|
+
position: "absolute",
|
|
888
|
+
left: 0,
|
|
889
|
+
right: 0,
|
|
890
|
+
bottom: 0,
|
|
891
|
+
height: `${SCRIM_HEIGHT_RATIO * 100}%`,
|
|
892
|
+
opacity: scrimOpacity,
|
|
893
|
+
background: "linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.55) 45%, rgba(0,0,0,0) 100%)"
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
) }),
|
|
897
|
+
/* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { display: "flex", zIndex: 11, ...positionStyle }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { ...captionBoxStyle, opacity: plateOpacity }, children: /* @__PURE__ */ jsxRuntime.jsx("span", { style: { opacity: textOpacity }, children: active.text }) }) })
|
|
898
|
+
] });
|
|
899
|
+
};
|
|
900
|
+
var TextLayer = ({
|
|
901
|
+
role,
|
|
902
|
+
content,
|
|
903
|
+
animation = "fade-in",
|
|
904
|
+
typography,
|
|
905
|
+
startFrame,
|
|
906
|
+
endFrame,
|
|
907
|
+
verticalLayout = "center",
|
|
908
|
+
offsetY = 0,
|
|
909
|
+
textShadow
|
|
910
|
+
}) => {
|
|
911
|
+
const frame = remotion.useCurrentFrame();
|
|
912
|
+
const { fps } = remotion.useVideoConfig();
|
|
913
|
+
const scale = useCanvasScale();
|
|
914
|
+
const localFrame = frame - startFrame;
|
|
915
|
+
if (frame < startFrame || frame > endFrame) return null;
|
|
916
|
+
const animDuration = 20;
|
|
917
|
+
const getAnimationStyle = () => {
|
|
918
|
+
switch (animation) {
|
|
919
|
+
case "fade-in": {
|
|
920
|
+
const opacity = remotion.interpolate(localFrame, [0, animDuration], [0, 1], {
|
|
921
|
+
extrapolateRight: "clamp"
|
|
922
|
+
});
|
|
923
|
+
return { opacity };
|
|
924
|
+
}
|
|
925
|
+
case "slide-up": {
|
|
926
|
+
const opacity = remotion.interpolate(localFrame, [0, animDuration], [0, 1], {
|
|
927
|
+
extrapolateRight: "clamp"
|
|
928
|
+
});
|
|
929
|
+
const translateY = remotion.interpolate(
|
|
930
|
+
localFrame,
|
|
931
|
+
[0, animDuration],
|
|
932
|
+
[40, 0],
|
|
933
|
+
{ extrapolateRight: "clamp" }
|
|
934
|
+
);
|
|
935
|
+
return { opacity, transform: `translateY(${translateY}px)` };
|
|
936
|
+
}
|
|
937
|
+
case "zoom-in": {
|
|
938
|
+
const s = remotion.spring({ fps, frame: localFrame, durationInFrames: animDuration });
|
|
939
|
+
return { transform: `scale(${0.5 + s * 0.5})`, opacity: s };
|
|
940
|
+
}
|
|
941
|
+
case "typewriter": {
|
|
942
|
+
const charsToShow = Math.floor(
|
|
943
|
+
remotion.interpolate(localFrame, [0, animDuration * 2], [0, content.length], {
|
|
944
|
+
extrapolateRight: "clamp"
|
|
945
|
+
})
|
|
946
|
+
);
|
|
947
|
+
return { clipPath: `inset(0 ${100 - charsToShow / content.length * 100}% 0 0)` };
|
|
948
|
+
}
|
|
949
|
+
default:
|
|
950
|
+
return {};
|
|
951
|
+
}
|
|
952
|
+
};
|
|
953
|
+
const getRoleStyle = () => {
|
|
954
|
+
const primary = typography?.primaryColor || "#FFFFFF";
|
|
955
|
+
const secondary = typography?.secondaryColor || "#E0E0E0";
|
|
956
|
+
const accent = typography?.accentColor || typography?.primaryColor || "#6C5CE7";
|
|
957
|
+
switch (role) {
|
|
958
|
+
case "title":
|
|
959
|
+
return {
|
|
960
|
+
fontSize: (typography?.titleSize || 56) * scale,
|
|
961
|
+
fontWeight: 700,
|
|
962
|
+
color: primary,
|
|
963
|
+
fontFamily: fontStack(typography?.titleFont),
|
|
964
|
+
textShadow: "0 2px 12px rgba(0,0,0,0.5)"
|
|
965
|
+
};
|
|
966
|
+
case "subtitle":
|
|
967
|
+
return {
|
|
968
|
+
fontSize: (typography?.bodySize || 32) * scale,
|
|
969
|
+
fontWeight: 500,
|
|
970
|
+
color: secondary,
|
|
971
|
+
fontFamily: fontStack(typography?.bodyFont),
|
|
972
|
+
textShadow: "0 1px 6px rgba(0,0,0,0.4)"
|
|
973
|
+
};
|
|
974
|
+
case "badge":
|
|
975
|
+
return {
|
|
976
|
+
fontSize: 24 * scale,
|
|
977
|
+
fontWeight: 600,
|
|
978
|
+
color: "#FFFFFF",
|
|
979
|
+
backgroundColor: accent,
|
|
980
|
+
fontFamily: fontStack(typography?.bodyFont),
|
|
981
|
+
padding: `${6 * scale}px ${18 * scale}px`,
|
|
982
|
+
borderRadius: 20 * scale,
|
|
983
|
+
display: "inline-block"
|
|
984
|
+
};
|
|
985
|
+
case "caption":
|
|
986
|
+
return {
|
|
987
|
+
fontSize: 28 * scale,
|
|
988
|
+
fontWeight: 500,
|
|
989
|
+
color: "#FFFFFF",
|
|
990
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
991
|
+
fontFamily: fontStack(typography?.bodyFont),
|
|
992
|
+
padding: `${8 * scale}px ${16 * scale}px`,
|
|
993
|
+
borderRadius: 6 * scale
|
|
994
|
+
};
|
|
995
|
+
case "callout":
|
|
996
|
+
return {
|
|
997
|
+
fontSize: 36 * scale,
|
|
998
|
+
fontWeight: 600,
|
|
999
|
+
color: primary,
|
|
1000
|
+
fontFamily: fontStack(typography?.bodyFont),
|
|
1001
|
+
borderLeft: `${4 * scale}px solid ${accent}`,
|
|
1002
|
+
paddingLeft: 16 * scale
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
const getPositionStyle = () => {
|
|
1007
|
+
switch (role) {
|
|
1008
|
+
case "title":
|
|
1009
|
+
if (verticalLayout === "top") {
|
|
1010
|
+
return {
|
|
1011
|
+
justifyContent: "flex-start",
|
|
1012
|
+
alignItems: "center",
|
|
1013
|
+
paddingTop: 88 * scale,
|
|
1014
|
+
paddingLeft: 40 * scale,
|
|
1015
|
+
paddingRight: 40 * scale
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
return {
|
|
1019
|
+
justifyContent: "center",
|
|
1020
|
+
alignItems: "center"
|
|
1021
|
+
};
|
|
1022
|
+
case "subtitle":
|
|
1023
|
+
if (verticalLayout === "top") {
|
|
1024
|
+
return {
|
|
1025
|
+
justifyContent: "flex-start",
|
|
1026
|
+
alignItems: "center",
|
|
1027
|
+
paddingTop: 168 * scale,
|
|
1028
|
+
paddingLeft: 40 * scale,
|
|
1029
|
+
paddingRight: 40 * scale
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
return {
|
|
1033
|
+
justifyContent: "center",
|
|
1034
|
+
alignItems: "center"
|
|
1035
|
+
};
|
|
1036
|
+
case "badge":
|
|
1037
|
+
return {
|
|
1038
|
+
justifyContent: "flex-start",
|
|
1039
|
+
alignItems: "flex-start",
|
|
1040
|
+
padding: `${80 * scale}px ${40 * scale}px`
|
|
1041
|
+
};
|
|
1042
|
+
default:
|
|
1043
|
+
return {
|
|
1044
|
+
justifyContent: "center",
|
|
1045
|
+
alignItems: "center"
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1050
|
+
remotion.AbsoluteFill,
|
|
1051
|
+
{
|
|
1052
|
+
style: {
|
|
1053
|
+
display: "flex",
|
|
1054
|
+
zIndex: 10,
|
|
1055
|
+
...getPositionStyle(),
|
|
1056
|
+
...offsetY ? { transform: `translateY(${offsetY * scale}px)` } : null
|
|
1057
|
+
},
|
|
1058
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1059
|
+
"div",
|
|
1060
|
+
{
|
|
1061
|
+
style: {
|
|
1062
|
+
...getRoleStyle(),
|
|
1063
|
+
// 放在 getRoleStyle() 之后:显式传入的阴影要盖掉 role 的默认阴影。
|
|
1064
|
+
// 用 !== undefined 而不是真值判断,这样传 "" 能真的去掉阴影。
|
|
1065
|
+
...textShadow !== void 0 ? { textShadow } : null,
|
|
1066
|
+
...getAnimationStyle(),
|
|
1067
|
+
textAlign: "center"
|
|
1068
|
+
},
|
|
1069
|
+
children: content
|
|
1070
|
+
}
|
|
1071
|
+
)
|
|
1072
|
+
}
|
|
1073
|
+
);
|
|
1074
|
+
};
|
|
1075
|
+
var SceneTransition = ({
|
|
1076
|
+
type,
|
|
1077
|
+
durationFrames,
|
|
1078
|
+
direction,
|
|
1079
|
+
children
|
|
1080
|
+
}) => {
|
|
1081
|
+
const frame = remotion.useCurrentFrame();
|
|
1082
|
+
if (type === "flip-corner" && durationFrames > 0) {
|
|
1083
|
+
const progress = remotion.interpolate(
|
|
1084
|
+
frame,
|
|
1085
|
+
[0, durationFrames],
|
|
1086
|
+
[0, 1],
|
|
1087
|
+
{ extrapolateRight: "clamp", easing: remotion.Easing.inOut(remotion.Easing.ease) }
|
|
1088
|
+
);
|
|
1089
|
+
const t = progress * 2;
|
|
1090
|
+
const foldCenterX = (1 - progress) * 100;
|
|
1091
|
+
const foldCenterY = (1 - progress) * 100;
|
|
1092
|
+
let clipPath;
|
|
1093
|
+
if (t <= 1) {
|
|
1094
|
+
const ry = (1 - t) * 100;
|
|
1095
|
+
const bx = (1 - t) * 100;
|
|
1096
|
+
clipPath = `polygon(100% ${ry}%, 100% 100%, ${bx}% 100%)`;
|
|
1097
|
+
} else {
|
|
1098
|
+
const tx = (2 - t) * 100;
|
|
1099
|
+
const ly = (2 - t) * 100;
|
|
1100
|
+
clipPath = `polygon(${tx}% 0%, 100% 0%, 100% 100%, 0% 100%, 0% ${ly}%)`;
|
|
1101
|
+
}
|
|
1102
|
+
if (direction === "in") {
|
|
1103
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { clipPath, overflow: "hidden" }, children: [
|
|
1104
|
+
children,
|
|
1105
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
1106
|
+
position: "absolute",
|
|
1107
|
+
left: `${foldCenterX}%`,
|
|
1108
|
+
top: `${foldCenterY}%`,
|
|
1109
|
+
width: "250%",
|
|
1110
|
+
height: 70,
|
|
1111
|
+
transform: "translate(-50%, -50%) rotate(-45deg)",
|
|
1112
|
+
background: "linear-gradient(to bottom, transparent, rgba(0,0,0,0.25) 40%, rgba(0,0,0,0.08) 70%, transparent)",
|
|
1113
|
+
pointerEvents: "none"
|
|
1114
|
+
} })
|
|
1115
|
+
] });
|
|
1116
|
+
}
|
|
1117
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: [
|
|
1118
|
+
children,
|
|
1119
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
1120
|
+
position: "absolute",
|
|
1121
|
+
left: `${foldCenterX}%`,
|
|
1122
|
+
top: `${foldCenterY}%`,
|
|
1123
|
+
width: "250%",
|
|
1124
|
+
height: 36,
|
|
1125
|
+
transform: "translate(-50%, -50%) rotate(-45deg)",
|
|
1126
|
+
background: "linear-gradient(to bottom, rgba(0,0,0,0.06), rgba(200,200,200,0.5) 18%, rgba(255,255,255,0.92) 42%, rgba(255,255,255,0.96) 58%, rgba(210,210,210,0.45) 82%, rgba(0,0,0,0.08))",
|
|
1127
|
+
pointerEvents: "none"
|
|
1128
|
+
} }),
|
|
1129
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { style: {
|
|
1130
|
+
position: "absolute",
|
|
1131
|
+
left: `${foldCenterX}%`,
|
|
1132
|
+
top: `${foldCenterY}%`,
|
|
1133
|
+
width: "250%",
|
|
1134
|
+
height: 80,
|
|
1135
|
+
transform: "translate(-50%, 0) rotate(-45deg)",
|
|
1136
|
+
background: "linear-gradient(to bottom, transparent, rgba(0,0,0,0.12))",
|
|
1137
|
+
pointerEvents: "none"
|
|
1138
|
+
} })
|
|
1139
|
+
] });
|
|
1140
|
+
}
|
|
1141
|
+
const getStyle = () => {
|
|
1142
|
+
if (durationFrames <= 0) return {};
|
|
1143
|
+
switch (type) {
|
|
1144
|
+
case "fade": {
|
|
1145
|
+
const opacity = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [0, 1], {
|
|
1146
|
+
extrapolateRight: "clamp"
|
|
1147
|
+
}) : 1;
|
|
1148
|
+
return { opacity };
|
|
1149
|
+
}
|
|
1150
|
+
case "slide-left": {
|
|
1151
|
+
const tx = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [100, 0], {
|
|
1152
|
+
extrapolateRight: "clamp"
|
|
1153
|
+
}) : 0;
|
|
1154
|
+
return { transform: `translateX(${tx}%)` };
|
|
1155
|
+
}
|
|
1156
|
+
case "slide-right": {
|
|
1157
|
+
const tx = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [-100, 0], {
|
|
1158
|
+
extrapolateRight: "clamp"
|
|
1159
|
+
}) : 0;
|
|
1160
|
+
return { transform: `translateX(${tx}%)` };
|
|
1161
|
+
}
|
|
1162
|
+
case "zoom": {
|
|
1163
|
+
const scale = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [0.5, 1], {
|
|
1164
|
+
extrapolateRight: "clamp"
|
|
1165
|
+
}) : 1;
|
|
1166
|
+
const opacity = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [0, 1], {
|
|
1167
|
+
extrapolateRight: "clamp"
|
|
1168
|
+
}) : 1;
|
|
1169
|
+
return { transform: `scale(${scale})`, opacity };
|
|
1170
|
+
}
|
|
1171
|
+
case "wipe": {
|
|
1172
|
+
const pct = direction === "in" ? remotion.interpolate(frame, [0, durationFrames], [0, 100], {
|
|
1173
|
+
extrapolateRight: "clamp"
|
|
1174
|
+
}) : 100;
|
|
1175
|
+
return { clipPath: `inset(0 ${100 - pct}% 0 0)` };
|
|
1176
|
+
}
|
|
1177
|
+
case "flip": {
|
|
1178
|
+
if (direction === "in") {
|
|
1179
|
+
const rotateY = remotion.interpolate(frame, [0, durationFrames], [-120, 0], {
|
|
1180
|
+
extrapolateRight: "clamp"
|
|
1181
|
+
});
|
|
1182
|
+
const opacity = remotion.interpolate(
|
|
1183
|
+
frame,
|
|
1184
|
+
[0, durationFrames * 0.2],
|
|
1185
|
+
[0, 1],
|
|
1186
|
+
{ extrapolateRight: "clamp" }
|
|
1187
|
+
);
|
|
1188
|
+
const scale = remotion.interpolate(
|
|
1189
|
+
frame,
|
|
1190
|
+
[0, durationFrames * 0.5, durationFrames],
|
|
1191
|
+
[0.92, 0.96, 1],
|
|
1192
|
+
{ extrapolateRight: "clamp" }
|
|
1193
|
+
);
|
|
1194
|
+
return {
|
|
1195
|
+
transform: `perspective(1200px) rotateY(${rotateY}deg) scale(${scale})`,
|
|
1196
|
+
transformOrigin: "left center",
|
|
1197
|
+
opacity,
|
|
1198
|
+
backfaceVisibility: "hidden"
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
return {};
|
|
1202
|
+
}
|
|
1203
|
+
default:
|
|
1204
|
+
return {};
|
|
1205
|
+
}
|
|
1206
|
+
};
|
|
1207
|
+
return /* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: getStyle(), children });
|
|
1208
|
+
};
|
|
1209
|
+
var DEFAULT_GRID_PARTICLE_TUNING = {
|
|
1210
|
+
particleCount: 32,
|
|
1211
|
+
vignetteCenterY: "45%",
|
|
1212
|
+
topBand: { height: "22%", strength: 0.8 },
|
|
1213
|
+
bottomBand: { height: "30%", strength: 1.08, midStrength: 0.42 },
|
|
1214
|
+
noiseFilterId: "ki-noise"
|
|
1215
|
+
};
|
|
1216
|
+
var MEDIA_OVERLAY_MASK2 = "linear-gradient(180deg, rgba(0,0,0,0.45) 0%, rgba(0,0,0,0.75) 45%, rgba(0,0,0,1) 78%, rgba(0,0,0,1) 100%)";
|
|
1217
|
+
var GridParticleBackground = ({
|
|
1218
|
+
theme,
|
|
1219
|
+
config,
|
|
1220
|
+
resolvedAssets,
|
|
1221
|
+
hasBottomText = true,
|
|
1222
|
+
tuning: tuningOverride,
|
|
1223
|
+
templateId
|
|
1224
|
+
}) => {
|
|
1225
|
+
const frame = remotion.useCurrentFrame();
|
|
1226
|
+
const { fps, width, height } = remotion.useVideoConfig();
|
|
1227
|
+
const time = frame / fps;
|
|
1228
|
+
const tuning = { ...DEFAULT_GRID_PARTICLE_TUNING, ...tuningOverride };
|
|
1229
|
+
const [failedBgSrc, setFailedBgSrc] = React3.useState(null);
|
|
1230
|
+
const preset = config?.preset ?? "grid-particles";
|
|
1231
|
+
const intensity = Math.max(0, Math.min(1.5, config?.intensity ?? 1));
|
|
1232
|
+
const showGrid = preset === "grid-particles" || preset === "grid-only";
|
|
1233
|
+
const showParticles = preset === "grid-particles" || preset === "particles-only";
|
|
1234
|
+
const showNoise = preset === "noise";
|
|
1235
|
+
if (preset === "solid") {
|
|
1236
|
+
const bg = config?.cssBackground || config?.color || theme.bgGradient;
|
|
1237
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { overflow: "hidden", background: bg }, children: [
|
|
1238
|
+
/* @__PURE__ */ jsxRuntime.jsx(CornerHalos, { theme, time, width, height, dim: 0.55 }),
|
|
1239
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReadabilityScrim, { theme, hasBottomText, tuning })
|
|
1240
|
+
] });
|
|
1241
|
+
}
|
|
1242
|
+
if (preset === "image") {
|
|
1243
|
+
const resolved = resolveAssetUrl(config?.assetRef, resolvedAssets ?? []);
|
|
1244
|
+
const url = resolved && resolved !== failedBgSrc ? resolved : null;
|
|
1245
|
+
const overlay = config?.overlayOpacity ?? 0.35;
|
|
1246
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: [
|
|
1247
|
+
/* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { background: theme.bgGradient } }),
|
|
1248
|
+
url ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1249
|
+
remotion.Img,
|
|
1250
|
+
{
|
|
1251
|
+
src: url,
|
|
1252
|
+
onError: () => {
|
|
1253
|
+
reportSceneDegraded({
|
|
1254
|
+
templateId,
|
|
1255
|
+
reason: "background_load_failed",
|
|
1256
|
+
dedupeKey: url,
|
|
1257
|
+
detail: { component: "GridParticleBackground", src: url }
|
|
1258
|
+
});
|
|
1259
|
+
setFailedBgSrc(url);
|
|
1260
|
+
},
|
|
1261
|
+
style: {
|
|
1262
|
+
position: "absolute",
|
|
1263
|
+
inset: 0,
|
|
1264
|
+
width: "100%",
|
|
1265
|
+
height: "100%",
|
|
1266
|
+
objectFit: "cover",
|
|
1267
|
+
filter: "saturate(0.95)"
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
) : null,
|
|
1271
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1272
|
+
remotion.AbsoluteFill,
|
|
1273
|
+
{
|
|
1274
|
+
style: {
|
|
1275
|
+
background: `rgba(6,9,31,${overlay})`,
|
|
1276
|
+
maskImage: MEDIA_OVERLAY_MASK2,
|
|
1277
|
+
WebkitMaskImage: MEDIA_OVERLAY_MASK2
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
),
|
|
1281
|
+
/* @__PURE__ */ jsxRuntime.jsx(CornerHalos, { theme, time, width, height, dim: 0.6 }),
|
|
1282
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReadabilityScrim, { theme, hasBottomText, tuning })
|
|
1283
|
+
] });
|
|
1284
|
+
}
|
|
1285
|
+
const bgStyle = preset === "gradient" && config?.cssBackground ? config.cssBackground : theme.bgGradient;
|
|
1286
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { overflow: "hidden" }, children: [
|
|
1287
|
+
/* @__PURE__ */ jsxRuntime.jsx(remotion.AbsoluteFill, { style: { background: bgStyle } }),
|
|
1288
|
+
/* @__PURE__ */ jsxRuntime.jsx(CornerHalos, { theme, time, width, height }),
|
|
1289
|
+
showGrid && /* @__PURE__ */ jsxRuntime.jsx(Grid, { theme, intensity }),
|
|
1290
|
+
showParticles && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1291
|
+
Particles,
|
|
1292
|
+
{
|
|
1293
|
+
theme,
|
|
1294
|
+
time,
|
|
1295
|
+
width,
|
|
1296
|
+
height,
|
|
1297
|
+
intensity,
|
|
1298
|
+
count: tuning.particleCount
|
|
1299
|
+
}
|
|
1300
|
+
),
|
|
1301
|
+
showNoise && /* @__PURE__ */ jsxRuntime.jsx(NoiseOverlay, { theme, opacity: 0.2 * intensity, id: tuning.noiseFilterId }),
|
|
1302
|
+
/* @__PURE__ */ jsxRuntime.jsx(ReadabilityScrim, { theme, hasBottomText, tuning })
|
|
1303
|
+
] });
|
|
1304
|
+
};
|
|
1305
|
+
var ReadabilityScrim = ({ theme, hasBottomText, tuning }) => {
|
|
1306
|
+
const { vignetteCenterY, topBand, bottomBand } = tuning;
|
|
1307
|
+
const s = theme.scrimRGB;
|
|
1308
|
+
const a = theme.vignetteAlpha;
|
|
1309
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1311
|
+
remotion.AbsoluteFill,
|
|
1312
|
+
{
|
|
1313
|
+
style: {
|
|
1314
|
+
background: `radial-gradient(ellipse 72% 62% at 50% ${vignetteCenterY}, rgba(${s},0) 0%, rgba(${s},${(a * 0.3).toFixed(3)}) 62%, rgba(${s},${a.toFixed(3)}) 100%)`,
|
|
1315
|
+
pointerEvents: "none"
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
),
|
|
1319
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1320
|
+
"div",
|
|
1321
|
+
{
|
|
1322
|
+
style: {
|
|
1323
|
+
position: "absolute",
|
|
1324
|
+
top: 0,
|
|
1325
|
+
left: 0,
|
|
1326
|
+
right: 0,
|
|
1327
|
+
height: topBand.height,
|
|
1328
|
+
background: `linear-gradient(180deg, rgba(${s},${(a * topBand.strength).toFixed(3)}) 0%, rgba(${s},0) 100%)`,
|
|
1329
|
+
pointerEvents: "none"
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
),
|
|
1333
|
+
hasBottomText && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1334
|
+
"div",
|
|
1335
|
+
{
|
|
1336
|
+
style: {
|
|
1337
|
+
position: "absolute",
|
|
1338
|
+
bottom: 0,
|
|
1339
|
+
left: 0,
|
|
1340
|
+
right: 0,
|
|
1341
|
+
height: bottomBand.height,
|
|
1342
|
+
background: `linear-gradient(0deg, rgba(${s},${(a * bottomBand.strength).toFixed(3)}) 0%, rgba(${s},${(a * bottomBand.midStrength).toFixed(3)}) 45%, rgba(${s},0) 100%)`,
|
|
1343
|
+
pointerEvents: "none"
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
)
|
|
1347
|
+
] });
|
|
1348
|
+
};
|
|
1349
|
+
var Grid = ({ theme, intensity }) => {
|
|
1350
|
+
const { width, height } = remotion.useVideoConfig();
|
|
1351
|
+
const spacing = 72;
|
|
1352
|
+
const thickEvery = 4;
|
|
1353
|
+
const cols = Math.ceil(width / spacing) + 2;
|
|
1354
|
+
const rows = Math.ceil(height / spacing) + 2;
|
|
1355
|
+
const w = (cols + 1) * spacing;
|
|
1356
|
+
const h = (rows + 1) * spacing;
|
|
1357
|
+
const cx = w / 2;
|
|
1358
|
+
const cy = h / 2;
|
|
1359
|
+
const maxDist = Math.sqrt(cx * cx + cy * cy);
|
|
1360
|
+
const [cR, cG, cB] = parseRGB(theme.gridCenterRGB);
|
|
1361
|
+
const [eR, eG, eB] = parseRGB(theme.gridEdgeRGB);
|
|
1362
|
+
const lines = [];
|
|
1363
|
+
for (let i = 0; i <= cols; i++) {
|
|
1364
|
+
const x = i * spacing;
|
|
1365
|
+
const distRatio = Math.abs(x - cx) / maxDist;
|
|
1366
|
+
const isThick = i % thickEvery === 0;
|
|
1367
|
+
const r = Math.round(cR + (eR - cR) * distRatio);
|
|
1368
|
+
const g = Math.round(cG + (eG - cG) * distRatio);
|
|
1369
|
+
const b = Math.round(cB + (eB - cB) * distRatio);
|
|
1370
|
+
const baseA = isThick ? 0.32 - 0.12 * distRatio : 0.16 - 0.06 * distRatio;
|
|
1371
|
+
const a = Math.max(0, baseA * intensity).toFixed(3);
|
|
1372
|
+
lines.push(
|
|
1373
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1374
|
+
"line",
|
|
1375
|
+
{
|
|
1376
|
+
x1: x,
|
|
1377
|
+
y1: 0,
|
|
1378
|
+
x2: x,
|
|
1379
|
+
y2: h,
|
|
1380
|
+
stroke: `rgba(${r},${g},${b},${a})`,
|
|
1381
|
+
strokeWidth: isThick ? 1.6 : 0.7
|
|
1382
|
+
},
|
|
1383
|
+
`v${i}`
|
|
1384
|
+
)
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
for (let j = 0; j <= rows; j++) {
|
|
1388
|
+
const y = j * spacing;
|
|
1389
|
+
const distRatio = Math.abs(y - cy) / maxDist;
|
|
1390
|
+
const isThick = j % thickEvery === 0;
|
|
1391
|
+
const r = Math.round(cR + (eR - cR) * distRatio);
|
|
1392
|
+
const g = Math.round(cG + (eG - cG) * distRatio);
|
|
1393
|
+
const b = Math.round(cB + (eB - cB) * distRatio);
|
|
1394
|
+
const baseA = isThick ? 0.32 - 0.12 * distRatio : 0.16 - 0.06 * distRatio;
|
|
1395
|
+
const a = Math.max(0, baseA * intensity).toFixed(3);
|
|
1396
|
+
lines.push(
|
|
1397
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1398
|
+
"line",
|
|
1399
|
+
{
|
|
1400
|
+
x1: 0,
|
|
1401
|
+
y1: y,
|
|
1402
|
+
x2: w,
|
|
1403
|
+
y2: y,
|
|
1404
|
+
stroke: `rgba(${r},${g},${b},${a})`,
|
|
1405
|
+
strokeWidth: isThick ? 1.6 : 0.7
|
|
1406
|
+
},
|
|
1407
|
+
`h${j}`
|
|
1408
|
+
)
|
|
1409
|
+
);
|
|
1410
|
+
}
|
|
1411
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1412
|
+
"div",
|
|
1413
|
+
{
|
|
1414
|
+
style: {
|
|
1415
|
+
position: "absolute",
|
|
1416
|
+
top: "50%",
|
|
1417
|
+
left: "50%",
|
|
1418
|
+
width: w,
|
|
1419
|
+
height: h,
|
|
1420
|
+
transform: "translate(-50%, -50%) perspective(1400px) rotateX(6deg)",
|
|
1421
|
+
transformOrigin: "center center"
|
|
1422
|
+
},
|
|
1423
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: w, height: h, xmlns: "http://www.w3.org/2000/svg", children: lines })
|
|
1424
|
+
}
|
|
1425
|
+
);
|
|
1426
|
+
};
|
|
1427
|
+
var Particles = ({ theme, time, width, height, intensity, count }) => {
|
|
1428
|
+
const dots = [];
|
|
1429
|
+
for (let i = 0; i < count; i++) {
|
|
1430
|
+
const seed = (i * 9301 + 49297) % 233280;
|
|
1431
|
+
const sx = seed / 233280 * width;
|
|
1432
|
+
const sy = seed * 13 % 233280 / 233280 * height;
|
|
1433
|
+
const driftAmpX = 14 + seed * 7 % 22;
|
|
1434
|
+
const driftAmpY = 18 + seed * 11 % 28;
|
|
1435
|
+
const phase = seed % 1e3 / 1e3 * Math.PI * 2;
|
|
1436
|
+
const speed = 0.18 + seed * 17 % 100 / 600;
|
|
1437
|
+
const x = sx + Math.sin(time * speed + phase) * driftAmpX;
|
|
1438
|
+
const y = sy + Math.cos(time * speed * 0.8 + phase) * driftAmpY;
|
|
1439
|
+
const pulse = 0.35 + 0.45 * Math.sin(time * 1.6 + phase);
|
|
1440
|
+
const radius = 1.2 + seed * 23 % 30 / 14;
|
|
1441
|
+
const a = Math.max(0, pulse * intensity).toFixed(3);
|
|
1442
|
+
dots.push(
|
|
1443
|
+
/* @__PURE__ */ jsxRuntime.jsxs(React3__default.default.Fragment, { children: [
|
|
1444
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: x, cy: y, r: radius, fill: `rgba(${theme.particleRGB},${a})` }),
|
|
1445
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1446
|
+
"circle",
|
|
1447
|
+
{
|
|
1448
|
+
cx: x,
|
|
1449
|
+
cy: y,
|
|
1450
|
+
r: radius * 2.4,
|
|
1451
|
+
fill: "none",
|
|
1452
|
+
stroke: `rgba(${theme.particleRGB},${(Number(a) * 0.25).toFixed(3)})`,
|
|
1453
|
+
strokeWidth: 0.6
|
|
1454
|
+
}
|
|
1455
|
+
)
|
|
1456
|
+
] }, `p${i}`)
|
|
1457
|
+
);
|
|
1458
|
+
}
|
|
1459
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1460
|
+
"svg",
|
|
1461
|
+
{
|
|
1462
|
+
width,
|
|
1463
|
+
height,
|
|
1464
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1465
|
+
style: {
|
|
1466
|
+
position: "absolute",
|
|
1467
|
+
inset: 0,
|
|
1468
|
+
pointerEvents: "none"
|
|
1469
|
+
},
|
|
1470
|
+
children: dots
|
|
1471
|
+
}
|
|
1472
|
+
);
|
|
1473
|
+
};
|
|
1474
|
+
var CornerHalos = ({ theme, time, width, height, dim = 1 }) => {
|
|
1475
|
+
const size = Math.min(width, height) * 0.75;
|
|
1476
|
+
const corners = [
|
|
1477
|
+
{ x: 0, y: 0, color: theme.haloColors[0], phase: 0 },
|
|
1478
|
+
{ x: width, y: 0, color: theme.haloColors[1], phase: 1.5 },
|
|
1479
|
+
{ x: 0, y: height, color: theme.haloColors[2], phase: 3 },
|
|
1480
|
+
{ x: width, y: height, color: theme.haloColors[3], phase: 4.5 }
|
|
1481
|
+
];
|
|
1482
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: corners.map((halo, idx) => {
|
|
1483
|
+
const haloOpacity = (0.18 + 0.1 * Math.sin(time * 1 + halo.phase)) * dim;
|
|
1484
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1485
|
+
"div",
|
|
1486
|
+
{
|
|
1487
|
+
style: {
|
|
1488
|
+
position: "absolute",
|
|
1489
|
+
left: halo.x - size / 2,
|
|
1490
|
+
top: halo.y - size / 2,
|
|
1491
|
+
width: size,
|
|
1492
|
+
height: size,
|
|
1493
|
+
borderRadius: "50%",
|
|
1494
|
+
background: `radial-gradient(circle, rgba(${halo.color},${haloOpacity.toFixed(3)}) 0%, transparent 70%)`,
|
|
1495
|
+
pointerEvents: "none",
|
|
1496
|
+
// 半径变大后 70% 那道停靠会露出可辨认的圆边,糊掉它。
|
|
1497
|
+
filter: "blur(24px)"
|
|
1498
|
+
}
|
|
1499
|
+
},
|
|
1500
|
+
idx
|
|
1501
|
+
);
|
|
1502
|
+
}) });
|
|
1503
|
+
};
|
|
1504
|
+
var NoiseOverlay = ({ theme, opacity, id }) => {
|
|
1505
|
+
const tint = theme.noiseBlend === "screen" ? 1 : 0;
|
|
1506
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1507
|
+
"svg",
|
|
1508
|
+
{
|
|
1509
|
+
style: {
|
|
1510
|
+
position: "absolute",
|
|
1511
|
+
inset: 0,
|
|
1512
|
+
width: "100%",
|
|
1513
|
+
height: "100%",
|
|
1514
|
+
opacity,
|
|
1515
|
+
pointerEvents: "none",
|
|
1516
|
+
mixBlendMode: theme.noiseBlend
|
|
1517
|
+
},
|
|
1518
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1519
|
+
children: [
|
|
1520
|
+
/* @__PURE__ */ jsxRuntime.jsxs("filter", { id, children: [
|
|
1521
|
+
/* @__PURE__ */ jsxRuntime.jsx("feTurbulence", { type: "fractalNoise", baseFrequency: "0.6", numOctaves: "2", stitchTiles: "stitch" }),
|
|
1522
|
+
/* @__PURE__ */ jsxRuntime.jsx("feColorMatrix", { values: `0 0 0 0 ${tint} 0 0 0 0 ${tint} 0 0 0 0 ${tint} 0 0 0 0.6 0` })
|
|
1523
|
+
] }),
|
|
1524
|
+
/* @__PURE__ */ jsxRuntime.jsx("rect", { width: "100%", height: "100%", filter: `url(#${id})` })
|
|
1525
|
+
]
|
|
1526
|
+
}
|
|
1527
|
+
);
|
|
1528
|
+
};
|
|
1529
|
+
function parseRGB(rgb) {
|
|
1530
|
+
const parts = rgb.split(",").map(Number);
|
|
1531
|
+
return [parts[0] ?? 255, parts[1] ?? 255, parts[2] ?? 255];
|
|
1532
|
+
}
|
|
1533
|
+
var FADE_IN_FRAMES = 5;
|
|
1534
|
+
var FADE_OUT_FRAMES = 12;
|
|
1535
|
+
var AudioLayer = ({
|
|
1536
|
+
src,
|
|
1537
|
+
startFrame,
|
|
1538
|
+
durationFrames,
|
|
1539
|
+
volume = 1,
|
|
1540
|
+
fadeIn = FADE_IN_FRAMES,
|
|
1541
|
+
fadeOut = FADE_OUT_FRAMES
|
|
1542
|
+
}) => {
|
|
1543
|
+
const volumeFn = React3.useCallback(
|
|
1544
|
+
(f) => {
|
|
1545
|
+
const inVal = remotion.interpolate(f, [0, fadeIn], [0, volume], {
|
|
1546
|
+
extrapolateLeft: "clamp",
|
|
1547
|
+
extrapolateRight: "clamp"
|
|
1548
|
+
});
|
|
1549
|
+
const outVal = remotion.interpolate(
|
|
1550
|
+
f,
|
|
1551
|
+
[durationFrames - fadeOut, durationFrames],
|
|
1552
|
+
[volume, 0],
|
|
1553
|
+
{ extrapolateLeft: "clamp", extrapolateRight: "clamp" }
|
|
1554
|
+
);
|
|
1555
|
+
return Math.min(inVal, outVal);
|
|
1556
|
+
},
|
|
1557
|
+
[fadeIn, fadeOut, durationFrames, volume]
|
|
1558
|
+
);
|
|
1559
|
+
if (!src) return null;
|
|
1560
|
+
return /* @__PURE__ */ jsxRuntime.jsx(remotion.Sequence, { from: startFrame, durationInFrames: durationFrames, children: /* @__PURE__ */ jsxRuntime.jsx(remotion.Audio, { src, volume: volumeFn }) });
|
|
1561
|
+
};
|
|
1562
|
+
var TimelineSequencer = ({
|
|
1563
|
+
timeline,
|
|
1564
|
+
resolvedAssets,
|
|
1565
|
+
resolve,
|
|
1566
|
+
globalTypography,
|
|
1567
|
+
variantId,
|
|
1568
|
+
bgm,
|
|
1569
|
+
spreadEntryProps = false
|
|
1570
|
+
}) => {
|
|
1571
|
+
const entries = timeline ?? [];
|
|
1572
|
+
const totalFrames = entries[entries.length - 1]?.endFrame ?? 0;
|
|
1573
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(remotion.AbsoluteFill, { style: { backgroundColor: "#000" }, children: [
|
|
1574
|
+
entries.map((entry) => {
|
|
1575
|
+
const Comp = resolve(entry.compositionId);
|
|
1576
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1577
|
+
remotion.Sequence,
|
|
1578
|
+
{
|
|
1579
|
+
from: entry.startFrame,
|
|
1580
|
+
durationInFrames: entry.durationFrames,
|
|
1581
|
+
name: entry.sceneId,
|
|
1582
|
+
children: Comp ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1583
|
+
Comp,
|
|
1584
|
+
{
|
|
1585
|
+
entry,
|
|
1586
|
+
resolvedAssets: resolvedAssets ?? [],
|
|
1587
|
+
typography: globalTypography,
|
|
1588
|
+
variantId,
|
|
1589
|
+
...spreadEntryProps ? entry.props : void 0
|
|
1590
|
+
}
|
|
1591
|
+
) : null
|
|
1592
|
+
},
|
|
1593
|
+
entry.sceneId
|
|
1594
|
+
);
|
|
1595
|
+
}),
|
|
1596
|
+
bgm?.url ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1597
|
+
AudioLayer,
|
|
1598
|
+
{
|
|
1599
|
+
src: bgm.url,
|
|
1600
|
+
startFrame: 0,
|
|
1601
|
+
durationFrames: totalFrames,
|
|
1602
|
+
volume: bgm.volume ?? 0.15,
|
|
1603
|
+
fadeIn: 30,
|
|
1604
|
+
fadeOut: 45
|
|
1605
|
+
}
|
|
1606
|
+
) : null
|
|
1607
|
+
] });
|
|
1608
|
+
};
|
|
1609
|
+
function useActiveSubtitle(segments) {
|
|
1610
|
+
const frame = remotion.useCurrentFrame();
|
|
1611
|
+
return React3.useMemo(() => {
|
|
1612
|
+
const active = segments.find(
|
|
1613
|
+
(s) => frame >= s.startFrame && frame < s.endFrame
|
|
1614
|
+
);
|
|
1615
|
+
return active?.text ?? "";
|
|
1616
|
+
}, [frame, segments]);
|
|
1617
|
+
}
|
|
1618
|
+
function useActiveSubtitleIndex(segments) {
|
|
1619
|
+
const frame = remotion.useCurrentFrame();
|
|
1620
|
+
return React3.useMemo(() => {
|
|
1621
|
+
for (let i = 0; i < segments.length; i++) {
|
|
1622
|
+
const seg = segments[i];
|
|
1623
|
+
if (frame >= seg.startFrame && frame < seg.endFrame) {
|
|
1624
|
+
return i;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
return -1;
|
|
1628
|
+
}, [frame, segments]);
|
|
1629
|
+
}
|
|
1630
|
+
function localizeSubtitles(entry, options = {}) {
|
|
1631
|
+
const { leadFrames = 0 } = options;
|
|
1632
|
+
const sceneStart = entry.startFrame;
|
|
1633
|
+
return (entry.subtitleSegments ?? []).map((seg) => {
|
|
1634
|
+
const localStart = seg.startFrame - sceneStart - leadFrames;
|
|
1635
|
+
return {
|
|
1636
|
+
...seg,
|
|
1637
|
+
// 只有在提前量把起点推到负数时才夹到 0。leadFrames=0 时保持原样:
|
|
1638
|
+
// ppt-to-video / math-principles-expl 会把 startFrame 当作「旁白起拍
|
|
1639
|
+
// 帧」直接消费,无条件夹 0 会悄悄改掉它们的节拍时间轴。
|
|
1640
|
+
startFrame: leadFrames > 0 ? Math.max(0, localStart) : localStart,
|
|
1641
|
+
endFrame: seg.endFrame - sceneStart
|
|
1642
|
+
};
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
function useLocalSubtitles(entry, options = {}) {
|
|
1646
|
+
const { leadFrames = 0 } = options;
|
|
1647
|
+
const segments = entry.subtitleSegments;
|
|
1648
|
+
const sceneStart = entry.startFrame;
|
|
1649
|
+
return React3.useMemo(
|
|
1650
|
+
() => localizeSubtitles({ subtitleSegments: segments, startFrame: sceneStart }, { leadFrames }),
|
|
1651
|
+
[segments, sceneStart, leadFrames]
|
|
1652
|
+
);
|
|
1653
|
+
}
|
|
1654
|
+
function sentenceStartFrames(segments) {
|
|
1655
|
+
if (segments.length === 0) return [];
|
|
1656
|
+
if (segments.some((s) => typeof s.sentenceIndex !== "number")) return null;
|
|
1657
|
+
const firstFrameOf = /* @__PURE__ */ new Map();
|
|
1658
|
+
for (const seg of segments) {
|
|
1659
|
+
const idx = seg.sentenceIndex;
|
|
1660
|
+
if (!firstFrameOf.has(idx)) firstFrameOf.set(idx, seg.startFrame);
|
|
1661
|
+
}
|
|
1662
|
+
return [...firstFrameOf.entries()].sort((a, b) => a[0] - b[0]).map(([, frame]) => frame);
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
// src/digitalHuman/resolve.ts
|
|
1666
|
+
var DIGITAL_HUMAN_ANCHORS = [
|
|
1667
|
+
"top-left",
|
|
1668
|
+
"top-center",
|
|
1669
|
+
"top-right",
|
|
1670
|
+
"center-left",
|
|
1671
|
+
"center",
|
|
1672
|
+
"center-right",
|
|
1673
|
+
"bottom-left",
|
|
1674
|
+
"bottom-center",
|
|
1675
|
+
"bottom-right"
|
|
1676
|
+
];
|
|
1677
|
+
var POSITIONS = [...DIGITAL_HUMAN_ANCHORS, "custom"];
|
|
1678
|
+
var SHAPES = ["rect", "rounded", "circle"];
|
|
1679
|
+
var LAYOUTS = ["overlay", "reserve"];
|
|
1680
|
+
var ON_END = ["freeze", "hide", "loop"];
|
|
1681
|
+
var ENTER = ["none", "fade", "pop", "slide"];
|
|
1682
|
+
var ROLES = ["only", "first", "middle", "last"];
|
|
1683
|
+
var DIGITAL_HUMAN_SIZE_PRESETS = {
|
|
1684
|
+
small: 0.28,
|
|
1685
|
+
medium: 0.42,
|
|
1686
|
+
large: 0.62,
|
|
1687
|
+
full: 0.92
|
|
1688
|
+
};
|
|
1689
|
+
var RANGES = {
|
|
1690
|
+
x: [0, 1],
|
|
1691
|
+
y: [0, 1],
|
|
1692
|
+
margin: [0, 0.5],
|
|
1693
|
+
offsetX: [-1, 1],
|
|
1694
|
+
offsetY: [-1, 1],
|
|
1695
|
+
size: [0.1, 1],
|
|
1696
|
+
aspectRatio: [0.2, 5],
|
|
1697
|
+
cornerRadius: [0, 0.5],
|
|
1698
|
+
borderWidth: [0, 40],
|
|
1699
|
+
focusX: [0, 1],
|
|
1700
|
+
focusY: [0, 1],
|
|
1701
|
+
zoom: [1, 3],
|
|
1702
|
+
startFromSec: [0, 86400]
|
|
1703
|
+
};
|
|
1704
|
+
var AVATAR_SCALE_RANGE = [0.2, 3];
|
|
1705
|
+
var DSL_POSITION_MAP = {
|
|
1706
|
+
center: "center",
|
|
1707
|
+
left: "center-left",
|
|
1708
|
+
right: "center-right",
|
|
1709
|
+
"bottom-left": "bottom-left",
|
|
1710
|
+
"bottom-right": "bottom-right"
|
|
1711
|
+
};
|
|
1712
|
+
var DIGITAL_HUMAN_PROP_KEYS = [
|
|
1713
|
+
"digitalHuman",
|
|
1714
|
+
"avatarAssetId",
|
|
1715
|
+
"avatarPosition",
|
|
1716
|
+
"avatarScale",
|
|
1717
|
+
"avatarOffsetFrames",
|
|
1718
|
+
"avatarSegmentRole"
|
|
1719
|
+
];
|
|
1720
|
+
var MAX_UNWRAP_DEPTH = 8;
|
|
1721
|
+
function isRecord(v) {
|
|
1722
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1723
|
+
}
|
|
1724
|
+
function isPresent(v) {
|
|
1725
|
+
return v !== void 0 && v !== null && v !== "";
|
|
1726
|
+
}
|
|
1727
|
+
function oneOf(v, options) {
|
|
1728
|
+
return typeof v === "string" && options.includes(v) ? v : void 0;
|
|
1729
|
+
}
|
|
1730
|
+
function clamp(v, lo, hi) {
|
|
1731
|
+
return Math.min(hi, Math.max(lo, v));
|
|
1732
|
+
}
|
|
1733
|
+
function pickDigitalHumanInput(props) {
|
|
1734
|
+
const out = {};
|
|
1735
|
+
let layer = props;
|
|
1736
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1737
|
+
for (let depth = 0; depth < MAX_UNWRAP_DEPTH && isRecord(layer) && !seen.has(layer); depth++) {
|
|
1738
|
+
seen.add(layer);
|
|
1739
|
+
for (const key of DIGITAL_HUMAN_PROP_KEYS) {
|
|
1740
|
+
if (out[key] === void 0 && isPresent(layer[key])) out[key] = layer[key];
|
|
1741
|
+
}
|
|
1742
|
+
layer = layer.templateData;
|
|
1743
|
+
}
|
|
1744
|
+
return out;
|
|
1745
|
+
}
|
|
1746
|
+
function isLegacyAvatarInput(input) {
|
|
1747
|
+
return isPresent(input.avatarAssetId) && input.digitalHuman === void 0 && input.avatarOffsetFrames === void 0 && input.avatarSegmentRole === void 0 && input.avatarPosition === void 0 && input.avatarScale === void 0;
|
|
1748
|
+
}
|
|
1749
|
+
function sanitizeDigitalHumanConfig(raw) {
|
|
1750
|
+
const issues = [];
|
|
1751
|
+
const config = {};
|
|
1752
|
+
if (raw === void 0 || raw === null) return { config, issues };
|
|
1753
|
+
if (!isRecord(raw)) return { config, issues: ["digitalHuman"] };
|
|
1754
|
+
const takeEnum = (key, options) => {
|
|
1755
|
+
const v = raw[key];
|
|
1756
|
+
if (v === void 0) return;
|
|
1757
|
+
const ok = oneOf(v, options);
|
|
1758
|
+
if (ok === void 0) issues.push(key);
|
|
1759
|
+
else config[key] = ok;
|
|
1760
|
+
};
|
|
1761
|
+
const takeNumber = (key) => {
|
|
1762
|
+
const v = raw[key];
|
|
1763
|
+
if (v === void 0) return;
|
|
1764
|
+
if (typeof v !== "number" || !Number.isFinite(v)) {
|
|
1765
|
+
issues.push(key);
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
const [lo, hi] = RANGES[key];
|
|
1769
|
+
const c = clamp(v, lo, hi);
|
|
1770
|
+
if (c !== v) issues.push(key);
|
|
1771
|
+
config[key] = c;
|
|
1772
|
+
};
|
|
1773
|
+
const takeBoolean = (key) => {
|
|
1774
|
+
const v = raw[key];
|
|
1775
|
+
if (v === void 0) return;
|
|
1776
|
+
if (typeof v !== "boolean") issues.push(key);
|
|
1777
|
+
else config[key] = v;
|
|
1778
|
+
};
|
|
1779
|
+
const takeString = (key) => {
|
|
1780
|
+
const v = raw[key];
|
|
1781
|
+
if (v === void 0) return;
|
|
1782
|
+
if (typeof v !== "string" || v.trim() === "") issues.push(key);
|
|
1783
|
+
else config[key] = v;
|
|
1784
|
+
};
|
|
1785
|
+
takeBoolean("enabled");
|
|
1786
|
+
takeEnum("position", POSITIONS);
|
|
1787
|
+
takeNumber("x");
|
|
1788
|
+
takeNumber("y");
|
|
1789
|
+
takeNumber("margin");
|
|
1790
|
+
takeNumber("offsetX");
|
|
1791
|
+
takeNumber("offsetY");
|
|
1792
|
+
const size = raw.size;
|
|
1793
|
+
if (size !== void 0) {
|
|
1794
|
+
if (typeof size === "string") {
|
|
1795
|
+
const preset = oneOf(size, Object.keys(DIGITAL_HUMAN_SIZE_PRESETS));
|
|
1796
|
+
if (preset) config.size = preset;
|
|
1797
|
+
else issues.push("size");
|
|
1798
|
+
} else {
|
|
1799
|
+
takeNumber("size");
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
takeNumber("aspectRatio");
|
|
1803
|
+
takeEnum("shape", SHAPES);
|
|
1804
|
+
takeNumber("cornerRadius");
|
|
1805
|
+
takeNumber("borderWidth");
|
|
1806
|
+
takeString("borderColor");
|
|
1807
|
+
takeBoolean("shadow");
|
|
1808
|
+
takeNumber("focusX");
|
|
1809
|
+
takeNumber("focusY");
|
|
1810
|
+
takeNumber("zoom");
|
|
1811
|
+
takeEnum("layout", LAYOUTS);
|
|
1812
|
+
takeEnum("onEnd", ON_END);
|
|
1813
|
+
takeEnum("enter", ENTER);
|
|
1814
|
+
takeBoolean("useVideoAudio");
|
|
1815
|
+
takeString("src");
|
|
1816
|
+
takeNumber("startFromSec");
|
|
1817
|
+
takeString("posterAssetRef");
|
|
1818
|
+
takeString("posterUrl");
|
|
1819
|
+
if (config.position === "custom" && (config.x === void 0 || config.y === void 0)) {
|
|
1820
|
+
issues.push("position");
|
|
1821
|
+
}
|
|
1822
|
+
return { config, issues };
|
|
1823
|
+
}
|
|
1824
|
+
function sizeToRatio(size) {
|
|
1825
|
+
if (size === void 0) return void 0;
|
|
1826
|
+
return typeof size === "number" ? size : DIGITAL_HUMAN_SIZE_PRESETS[size];
|
|
1827
|
+
}
|
|
1828
|
+
function mergeDigitalHumanConfig(config, defaults, dsl = {}) {
|
|
1829
|
+
const shape = config.shape ?? defaults.shape ?? "rounded";
|
|
1830
|
+
const defaultRatio = sizeToRatio(defaults.size) ?? DIGITAL_HUMAN_SIZE_PRESETS.medium;
|
|
1831
|
+
const explicitRatio = sizeToRatio(config.size);
|
|
1832
|
+
const sizeRatio = clamp(
|
|
1833
|
+
explicitRatio ?? defaultRatio * (dsl.scale ?? 1),
|
|
1834
|
+
RANGES.size[0],
|
|
1835
|
+
RANGES.size[1]
|
|
1836
|
+
);
|
|
1837
|
+
return {
|
|
1838
|
+
position: config.position ?? dsl.position ?? defaults.position ?? "bottom-right",
|
|
1839
|
+
x: config.x ?? 0.5,
|
|
1840
|
+
y: config.y ?? 0.5,
|
|
1841
|
+
margin: config.margin ?? defaults.margin ?? 0.03,
|
|
1842
|
+
offsetX: config.offsetX ?? 0,
|
|
1843
|
+
offsetY: config.offsetY ?? 0,
|
|
1844
|
+
sizeRatio,
|
|
1845
|
+
aspectRatio: shape === "circle" ? 1 : config.aspectRatio,
|
|
1846
|
+
shape,
|
|
1847
|
+
cornerRadius: config.cornerRadius ?? 0.08,
|
|
1848
|
+
borderWidth: config.borderWidth ?? (shape === "rect" ? 0 : 4),
|
|
1849
|
+
borderColor: config.borderColor ?? defaults.borderColor,
|
|
1850
|
+
shadow: config.shadow ?? true,
|
|
1851
|
+
focusX: config.focusX ?? defaults.focusX ?? 0.5,
|
|
1852
|
+
focusY: config.focusY ?? defaults.focusY ?? 0.3,
|
|
1853
|
+
zoom: config.zoom ?? 1,
|
|
1854
|
+
layout: config.layout ?? defaults.layout ?? "overlay",
|
|
1855
|
+
onEnd: config.onEnd ?? defaults.onEnd ?? "freeze",
|
|
1856
|
+
enter: config.enter ?? defaults.enter ?? "fade",
|
|
1857
|
+
useVideoAudio: config.useVideoAudio ?? false
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function resolveDigitalHuman(props, resolvedAssets, options) {
|
|
1861
|
+
const input = pickDigitalHumanInput(props);
|
|
1862
|
+
const { config: raw, issues } = sanitizeDigitalHumanConfig(input.digitalHuman);
|
|
1863
|
+
let dslPosition;
|
|
1864
|
+
if (input.avatarPosition !== void 0) {
|
|
1865
|
+
dslPosition = typeof input.avatarPosition === "string" ? DSL_POSITION_MAP[input.avatarPosition] ?? oneOf(input.avatarPosition, DIGITAL_HUMAN_ANCHORS) : void 0;
|
|
1866
|
+
if (!dslPosition) issues.push("avatarPosition");
|
|
1867
|
+
}
|
|
1868
|
+
let dslScale;
|
|
1869
|
+
if (input.avatarScale !== void 0) {
|
|
1870
|
+
if (typeof input.avatarScale === "number" && Number.isFinite(input.avatarScale)) {
|
|
1871
|
+
dslScale = clamp(input.avatarScale, AVATAR_SCALE_RANGE[0], AVATAR_SCALE_RANGE[1]);
|
|
1872
|
+
if (dslScale !== input.avatarScale) issues.push("avatarScale");
|
|
1873
|
+
} else {
|
|
1874
|
+
issues.push("avatarScale");
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
const config = mergeDigitalHumanConfig(raw, options.defaults ?? {}, {
|
|
1878
|
+
position: dslPosition,
|
|
1879
|
+
scale: dslScale
|
|
1880
|
+
});
|
|
1881
|
+
const assetId = typeof input.avatarAssetId === "string" ? input.avatarAssetId : void 0;
|
|
1882
|
+
if (input.avatarAssetId !== void 0 && assetId === void 0) issues.push("avatarAssetId");
|
|
1883
|
+
const asset = assetId ? resolvedAssets.find((a) => a.assetId === assetId) : void 0;
|
|
1884
|
+
const assetUrl = asset?.url || asset?.localPath || null;
|
|
1885
|
+
const src = assetUrl || raw.src || null;
|
|
1886
|
+
const unresolvedAssetId = assetId && !assetUrl ? assetId : void 0;
|
|
1887
|
+
const posterAsset = raw.posterAssetRef ? resolvedAssets.find((a) => a.assetId === raw.posterAssetRef) : void 0;
|
|
1888
|
+
const posterSrc = posterAsset?.url || posterAsset?.localPath || raw.posterUrl || null;
|
|
1889
|
+
let startFrame = 0;
|
|
1890
|
+
if (raw.startFromSec !== void 0) {
|
|
1891
|
+
startFrame = Math.round(raw.startFromSec * options.fps);
|
|
1892
|
+
} else if (input.avatarOffsetFrames !== void 0) {
|
|
1893
|
+
const v = input.avatarOffsetFrames;
|
|
1894
|
+
if (typeof v === "number" && Number.isFinite(v) && v >= 0) startFrame = Math.round(v);
|
|
1895
|
+
else issues.push("avatarOffsetFrames");
|
|
1896
|
+
}
|
|
1897
|
+
let role = "only";
|
|
1898
|
+
if (input.avatarSegmentRole !== void 0) {
|
|
1899
|
+
const r = oneOf(input.avatarSegmentRole, ROLES);
|
|
1900
|
+
if (r) role = r;
|
|
1901
|
+
else issues.push("avatarSegmentRole");
|
|
1902
|
+
}
|
|
1903
|
+
const videoFrames = typeof asset?.duration === "number" && asset.duration > 0 ? Math.round(asset.duration / 1e3 * options.fps) : void 0;
|
|
1904
|
+
const videoSize = typeof asset?.width === "number" && typeof asset?.height === "number" && asset.width > 0 && asset.height > 0 ? { width: asset.width, height: asset.height } : void 0;
|
|
1905
|
+
return {
|
|
1906
|
+
active: !!src && raw.enabled !== false,
|
|
1907
|
+
enabled: raw.enabled !== false,
|
|
1908
|
+
src,
|
|
1909
|
+
asset,
|
|
1910
|
+
posterSrc,
|
|
1911
|
+
config,
|
|
1912
|
+
startFrame,
|
|
1913
|
+
role,
|
|
1914
|
+
videoFrames,
|
|
1915
|
+
videoSize,
|
|
1916
|
+
issues,
|
|
1917
|
+
unresolvedAssetId
|
|
1918
|
+
};
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
// src/digitalHuman/box.ts
|
|
1922
|
+
var DEFAULT_DIGITAL_HUMAN_ASPECT = 3 / 4;
|
|
1923
|
+
function resolveDigitalHumanBox(config, canvas, options = {}) {
|
|
1924
|
+
const W = canvas.width;
|
|
1925
|
+
const H = canvas.height;
|
|
1926
|
+
const short = Math.min(W, H);
|
|
1927
|
+
const aspect = config.aspectRatio ?? (options.videoSize ? options.videoSize.width / options.videoSize.height : DEFAULT_DIGITAL_HUMAN_ASPECT);
|
|
1928
|
+
let height = config.sizeRatio * short;
|
|
1929
|
+
let width = height * aspect;
|
|
1930
|
+
const fit = Math.min(1, W / width, H / height);
|
|
1931
|
+
height *= fit;
|
|
1932
|
+
width *= fit;
|
|
1933
|
+
const inset = {
|
|
1934
|
+
top: options.insets?.top ?? 0,
|
|
1935
|
+
right: options.insets?.right ?? 0,
|
|
1936
|
+
bottom: options.insets?.bottom ?? 0,
|
|
1937
|
+
left: options.insets?.left ?? 0
|
|
1938
|
+
};
|
|
1939
|
+
const m = config.margin * short;
|
|
1940
|
+
let left;
|
|
1941
|
+
let top;
|
|
1942
|
+
if (config.position === "custom") {
|
|
1943
|
+
left = config.x * W - width / 2;
|
|
1944
|
+
top = config.y * H - height / 2;
|
|
1945
|
+
} else {
|
|
1946
|
+
const [v, h] = splitAnchor(config.position);
|
|
1947
|
+
left = h === "left" ? inset.left + m : h === "right" ? W - inset.right - m - width : (W - width) / 2;
|
|
1948
|
+
top = v === "top" ? inset.top + m : v === "bottom" ? H - inset.bottom - m - height : (H - height) / 2;
|
|
1949
|
+
}
|
|
1950
|
+
left += config.offsetX * W;
|
|
1951
|
+
top += config.offsetY * H;
|
|
1952
|
+
const clampedLeft = Math.min(Math.max(left, 0), W - width);
|
|
1953
|
+
const clampedTop = Math.min(Math.max(top, 0), H - height);
|
|
1954
|
+
const clamped = Math.abs(clampedLeft - left) > 1 || Math.abs(clampedTop - top) > 1;
|
|
1955
|
+
const cx = clampedLeft + width / 2;
|
|
1956
|
+
const side = cx < W * 0.4 ? "left" : cx > W * 0.6 ? "right" : "none";
|
|
1957
|
+
const borderRadius = config.shape === "circle" ? Math.min(width, height) / 2 : config.shape === "rounded" ? config.cornerRadius * Math.min(width, height) : 0;
|
|
1958
|
+
return {
|
|
1959
|
+
left: clampedLeft,
|
|
1960
|
+
top: clampedTop,
|
|
1961
|
+
width,
|
|
1962
|
+
height,
|
|
1963
|
+
borderRadius,
|
|
1964
|
+
side,
|
|
1965
|
+
clamped
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
function splitAnchor(anchor) {
|
|
1969
|
+
if (anchor === "center") return ["center", "center"];
|
|
1970
|
+
const [v, h] = anchor.split("-");
|
|
1971
|
+
return [v, h];
|
|
1972
|
+
}
|
|
1973
|
+
function resolveSubtitleMaxWidthPct(box, canvas, opts) {
|
|
1974
|
+
const { bandTop, baseMaxWidthPct } = opts;
|
|
1975
|
+
if (!box || box.side === "none") return baseMaxWidthPct;
|
|
1976
|
+
if (box.top + box.height <= bandTop) return baseMaxWidthPct;
|
|
1977
|
+
const gap = opts.gap ?? 0;
|
|
1978
|
+
const half = canvas.width / 2;
|
|
1979
|
+
const free = box.side === "right" ? box.left - gap - half : half - (box.left + box.width) - gap;
|
|
1980
|
+
const pct = 2 * Math.max(0, free) / canvas.width * 100;
|
|
1981
|
+
return Math.max(opts.minMaxWidthPct ?? 40, Math.min(baseMaxWidthPct, pct));
|
|
1982
|
+
}
|
|
1983
|
+
function resolveReservedRegion(box, canvas, gap = 0) {
|
|
1984
|
+
if (!box || box.side === "none") return { left: 0, width: canvas.width };
|
|
1985
|
+
if (box.side === "right") {
|
|
1986
|
+
return { left: 0, width: Math.max(0, box.left - gap) };
|
|
1987
|
+
}
|
|
1988
|
+
const left = Math.min(canvas.width, box.left + box.width + gap);
|
|
1989
|
+
return { left, width: Math.max(0, canvas.width - left) };
|
|
1990
|
+
}
|
|
1991
|
+
var ENTER_FRAMES_AT_30 = 12;
|
|
1992
|
+
var DEFAULT_BORDER_COLOR = "rgba(255,255,255,0.85)";
|
|
1993
|
+
function reportDigitalHumanIssues(dh, box, templateId, sceneId) {
|
|
1994
|
+
if (dh.unresolvedAssetId) {
|
|
1995
|
+
reportSceneDegraded({
|
|
1996
|
+
templateId,
|
|
1997
|
+
sceneId,
|
|
1998
|
+
reason: "digital_human_unresolved",
|
|
1999
|
+
detail: { asset_id: dh.unresolvedAssetId }
|
|
2000
|
+
});
|
|
2001
|
+
}
|
|
2002
|
+
if (dh.issues.length > 0) {
|
|
2003
|
+
reportSceneDegraded({
|
|
2004
|
+
templateId,
|
|
2005
|
+
sceneId,
|
|
2006
|
+
reason: "digital_human_config_out_of_range",
|
|
2007
|
+
detail: { fields: dh.issues.join(",") }
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
2010
|
+
if (box?.clamped) {
|
|
2011
|
+
reportSceneDegraded({ templateId, sceneId, reason: "digital_human_box_clamped" });
|
|
2012
|
+
}
|
|
2013
|
+
if (dh.active && dh.videoFrames !== void 0 && dh.startFrame >= dh.videoFrames) {
|
|
2014
|
+
reportSceneDegraded({
|
|
2015
|
+
templateId,
|
|
2016
|
+
sceneId,
|
|
2017
|
+
reason: "digital_human_offset_beyond_video",
|
|
2018
|
+
detail: { start_frame: dh.startFrame, video_frames: dh.videoFrames }
|
|
2019
|
+
});
|
|
2020
|
+
}
|
|
2021
|
+
if (dh.active && dh.videoFrames === void 0 && dh.config.onEnd !== "freeze") {
|
|
2022
|
+
reportSceneDegraded({ templateId, sceneId, reason: "digital_human_duration_unknown" });
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
function frameStyle(dh, box, scale) {
|
|
2026
|
+
const { config } = dh;
|
|
2027
|
+
const borderWidth = config.borderWidth * scale;
|
|
2028
|
+
return {
|
|
2029
|
+
position: "absolute",
|
|
2030
|
+
left: box.left,
|
|
2031
|
+
top: box.top,
|
|
2032
|
+
width: box.width,
|
|
2033
|
+
height: box.height,
|
|
2034
|
+
borderRadius: box.borderRadius,
|
|
2035
|
+
overflow: "hidden",
|
|
2036
|
+
boxSizing: "border-box",
|
|
2037
|
+
border: borderWidth > 0 ? `${borderWidth}px solid ${config.borderColor ?? DEFAULT_BORDER_COLOR}` : void 0,
|
|
2038
|
+
boxShadow: config.shadow ? `0 ${12 * scale}px ${36 * scale}px rgba(0,0,0,0.35)` : void 0,
|
|
2039
|
+
// 圆角裁切在部分 Chromium 版本里对视频层不生效,强制独立合成层。
|
|
2040
|
+
transform: "translateZ(0)"
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
function mediaStyle(dh) {
|
|
2044
|
+
const { focusX, focusY, zoom } = dh.config;
|
|
2045
|
+
const origin = `${focusX * 100}% ${focusY * 100}%`;
|
|
2046
|
+
return {
|
|
2047
|
+
width: "100%",
|
|
2048
|
+
height: "100%",
|
|
2049
|
+
objectFit: "cover",
|
|
2050
|
+
objectPosition: origin,
|
|
2051
|
+
transform: zoom !== 1 ? `scale(${zoom})` : void 0,
|
|
2052
|
+
transformOrigin: origin
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
var DigitalHumanLayer = ({
|
|
2056
|
+
dh,
|
|
2057
|
+
box,
|
|
2058
|
+
zIndex = 12
|
|
2059
|
+
}) => {
|
|
2060
|
+
const frame = remotion.useCurrentFrame();
|
|
2061
|
+
const { fps } = remotion.useVideoConfig();
|
|
2062
|
+
const scale = useCanvasScale();
|
|
2063
|
+
if (!dh.active || !dh.src) return null;
|
|
2064
|
+
const { config } = dh;
|
|
2065
|
+
const playEnter = config.enter !== "none" && (dh.role === "only" || dh.role === "first");
|
|
2066
|
+
const enterFrames = Math.max(1, Math.round(ENTER_FRAMES_AT_30 * fps / 30));
|
|
2067
|
+
let opacity = 1;
|
|
2068
|
+
let transform;
|
|
2069
|
+
if (playEnter) {
|
|
2070
|
+
opacity = remotion.interpolate(frame, [0, enterFrames], [0, 1], {
|
|
2071
|
+
extrapolateLeft: "clamp",
|
|
2072
|
+
extrapolateRight: "clamp"
|
|
2073
|
+
});
|
|
2074
|
+
if (config.enter === "pop") {
|
|
2075
|
+
const s = remotion.spring({ frame, fps, config: { damping: 14, stiffness: 160 } });
|
|
2076
|
+
transform = `scale(${0.85 + 0.15 * s})`;
|
|
2077
|
+
} else if (config.enter === "slide") {
|
|
2078
|
+
const dir = box.side === "left" ? -1 : 1;
|
|
2079
|
+
const dx = remotion.interpolate(frame, [0, enterFrames], [40 * scale * dir, 0], {
|
|
2080
|
+
extrapolateLeft: "clamp",
|
|
2081
|
+
extrapolateRight: "clamp"
|
|
2082
|
+
});
|
|
2083
|
+
transform = `translateX(${dx}px)`;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
const playable = dh.videoFrames !== void 0 ? dh.videoFrames - dh.startFrame : void 0;
|
|
2087
|
+
const ended = playable !== void 0 && frame >= playable;
|
|
2088
|
+
if (ended && config.onEnd === "hide") return null;
|
|
2089
|
+
const video = /* @__PURE__ */ jsxRuntime.jsx(
|
|
2090
|
+
remotion.OffthreadVideo,
|
|
2091
|
+
{
|
|
2092
|
+
src: dh.src,
|
|
2093
|
+
startFrom: dh.startFrame,
|
|
2094
|
+
volume: config.useVideoAudio ? 1 : 0,
|
|
2095
|
+
muted: !config.useVideoAudio,
|
|
2096
|
+
style: mediaStyle(dh)
|
|
2097
|
+
}
|
|
2098
|
+
);
|
|
2099
|
+
let media = video;
|
|
2100
|
+
if (playable !== void 0 && playable > 0) {
|
|
2101
|
+
if (config.onEnd === "loop") {
|
|
2102
|
+
media = /* @__PURE__ */ jsxRuntime.jsx(remotion.Loop, { durationInFrames: playable, layout: "none", children: video });
|
|
2103
|
+
} else if (ended) {
|
|
2104
|
+
media = /* @__PURE__ */ jsxRuntime.jsx(remotion.Freeze, { frame: playable - 1, children: video });
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
const base = frameStyle(dh, box, scale);
|
|
2108
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2109
|
+
"div",
|
|
2110
|
+
{
|
|
2111
|
+
style: {
|
|
2112
|
+
position: "absolute",
|
|
2113
|
+
inset: 0,
|
|
2114
|
+
zIndex,
|
|
2115
|
+
pointerEvents: "none",
|
|
2116
|
+
opacity
|
|
2117
|
+
},
|
|
2118
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2119
|
+
"div",
|
|
2120
|
+
{
|
|
2121
|
+
style: {
|
|
2122
|
+
...base,
|
|
2123
|
+
transform: transform ? `${transform} translateZ(0)` : base.transform
|
|
2124
|
+
},
|
|
2125
|
+
children: media
|
|
2126
|
+
}
|
|
2127
|
+
)
|
|
2128
|
+
}
|
|
2129
|
+
);
|
|
2130
|
+
};
|
|
2131
|
+
var DigitalHumanPoster = ({ dh, box, zIndex = 12 }) => {
|
|
2132
|
+
const scale = useCanvasScale();
|
|
2133
|
+
if (!dh.posterSrc || !dh.enabled) return null;
|
|
2134
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, zIndex, pointerEvents: "none" }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: frameStyle(dh, box, scale), children: /* @__PURE__ */ jsxRuntime.jsx(remotion.Img, { src: dh.posterSrc, style: mediaStyle(dh) }) }) });
|
|
2135
|
+
};
|
|
2136
|
+
var ReservedContentScaler = ({ regionWidth, width, height, children }) => {
|
|
2137
|
+
if (regionWidth === void 0 || regionWidth >= width) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
2138
|
+
const scale = Math.max(0, regionWidth) / width;
|
|
2139
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2140
|
+
"div",
|
|
2141
|
+
{
|
|
2142
|
+
style: {
|
|
2143
|
+
position: "absolute",
|
|
2144
|
+
top: 0,
|
|
2145
|
+
left: (regionWidth - width) / 2,
|
|
2146
|
+
width,
|
|
2147
|
+
height,
|
|
2148
|
+
display: "flex",
|
|
2149
|
+
alignItems: "center",
|
|
2150
|
+
justifyContent: "center",
|
|
2151
|
+
transform: `scale(${scale})`,
|
|
2152
|
+
transformOrigin: "center center"
|
|
2153
|
+
},
|
|
2154
|
+
children
|
|
2155
|
+
}
|
|
2156
|
+
);
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
exports.AudioLayer = AudioLayer;
|
|
2160
|
+
exports.Background = Background;
|
|
2161
|
+
exports.DEFAULT_DIGITAL_HUMAN_ASPECT = DEFAULT_DIGITAL_HUMAN_ASPECT;
|
|
2162
|
+
exports.DEFAULT_GRID_PARTICLE_TUNING = DEFAULT_GRID_PARTICLE_TUNING;
|
|
2163
|
+
exports.DEFAULT_MIN_CHUNK_UNITS = DEFAULT_MIN_CHUNK_UNITS;
|
|
2164
|
+
exports.DEFAULT_SPLIT_MAX_UNITS = DEFAULT_SPLIT_MAX_UNITS;
|
|
2165
|
+
exports.DIGITAL_HUMAN_ANCHORS = DIGITAL_HUMAN_ANCHORS;
|
|
2166
|
+
exports.DIGITAL_HUMAN_PROP_KEYS = DIGITAL_HUMAN_PROP_KEYS;
|
|
2167
|
+
exports.DIGITAL_HUMAN_SIZE_PRESETS = DIGITAL_HUMAN_SIZE_PRESETS;
|
|
2168
|
+
exports.DigitalHumanLayer = DigitalHumanLayer;
|
|
2169
|
+
exports.DigitalHumanPoster = DigitalHumanPoster;
|
|
2170
|
+
exports.GridParticleBackground = GridParticleBackground;
|
|
2171
|
+
exports.LINE_FILL_LIMIT = LINE_FILL_LIMIT;
|
|
2172
|
+
exports.ReservedContentScaler = ReservedContentScaler;
|
|
2173
|
+
exports.SceneBackgroundLayer = SceneBackgroundLayer;
|
|
2174
|
+
exports.SceneTransition = SceneTransition;
|
|
2175
|
+
exports.SubtitleBar = SubtitleBar;
|
|
2176
|
+
exports.TextLayer = TextLayer;
|
|
2177
|
+
exports.TimelineSequencer = TimelineSequencer;
|
|
2178
|
+
exports.chunkSubtitleSegments = chunkSubtitleSegments;
|
|
2179
|
+
exports.displayWidth = displayWidth;
|
|
2180
|
+
exports.estimateLineCapacity = estimateLineCapacity;
|
|
2181
|
+
exports.fontStack = fontStack;
|
|
2182
|
+
exports.grainDataUri = grainDataUri;
|
|
2183
|
+
exports.isLegacyAvatarInput = isLegacyAvatarInput;
|
|
2184
|
+
exports.localizeSubtitles = localizeSubtitles;
|
|
2185
|
+
exports.mergeDigitalHumanConfig = mergeDigitalHumanConfig;
|
|
2186
|
+
exports.pickDigitalHumanInput = pickDigitalHumanInput;
|
|
2187
|
+
exports.reportDigitalHumanIssues = reportDigitalHumanIssues;
|
|
2188
|
+
exports.reportSceneDegraded = reportSceneDegraded;
|
|
2189
|
+
exports.resetSceneDegradedReports = resetSceneDegradedReports;
|
|
2190
|
+
exports.resolveActiveChunk = resolveActiveChunk;
|
|
2191
|
+
exports.resolveAsset = resolveAsset;
|
|
2192
|
+
exports.resolveAssetUrl = resolveAssetUrl;
|
|
2193
|
+
exports.resolveChunkFadeOpacity = resolveChunkFadeOpacity;
|
|
2194
|
+
exports.resolveDigitalHuman = resolveDigitalHuman;
|
|
2195
|
+
exports.resolveDigitalHumanBox = resolveDigitalHumanBox;
|
|
2196
|
+
exports.resolveReservedRegion = resolveReservedRegion;
|
|
2197
|
+
exports.resolveRunFadeOpacity = resolveRunFadeOpacity;
|
|
2198
|
+
exports.resolveSceneBackground = resolveSceneBackground;
|
|
2199
|
+
exports.resolveSubtitleBottomPx = resolveSubtitleBottomPx;
|
|
2200
|
+
exports.resolveSubtitleMaxWidthPct = resolveSubtitleMaxWidthPct;
|
|
2201
|
+
exports.resolveSubtitleMode = resolveSubtitleMode;
|
|
2202
|
+
exports.sanitizeDiagnosticSrc = sanitizeDiagnosticSrc;
|
|
2203
|
+
exports.sanitizeDigitalHumanConfig = sanitizeDigitalHumanConfig;
|
|
2204
|
+
exports.sentenceStartFrames = sentenceStartFrames;
|
|
2205
|
+
exports.splitSubtitleText = splitSubtitleText;
|
|
2206
|
+
exports.spokenWeight = spokenWeight;
|
|
2207
|
+
exports.useActiveSubtitle = useActiveSubtitle;
|
|
2208
|
+
exports.useActiveSubtitleIndex = useActiveSubtitleIndex;
|
|
2209
|
+
exports.useAssetUrl = useAssetUrl;
|
|
2210
|
+
exports.useCanvasScale = useCanvasScale;
|
|
2211
|
+
exports.useLocalSubtitles = useLocalSubtitles;
|