@lalalic/markcut 3.2.30 → 3.2.32

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.
@@ -290,7 +290,8 @@ function compileLeaf(node2, ctx, parentKind) {
290
290
  src: node2.src,
291
291
  volume: node2.volume ?? 1,
292
292
  foreground: node2.foreground,
293
- speaker: node2.speaker
293
+ speaker: node2.speaker,
294
+ isNarration: node2.isNarration
294
295
  };
295
296
  return { stream, duration: end ?? 0 };
296
297
  }
@@ -349,7 +350,7 @@ function compileLeaf(node2, ctx, parentKind) {
349
350
  waypoints: node2.waypoints,
350
351
  routeColor: node2.routeColor ?? "#4285F4",
351
352
  routeWeight: node2.routeWeight ?? 4,
352
- zoom: node2.zoom ?? 10,
353
+ zoom: node2.zoom,
353
354
  center: node2.center,
354
355
  mapType: node2.mapType ?? "roadmap",
355
356
  language: node2.language,
@@ -550,7 +551,7 @@ function compileMap(node2, ctx, parentKind) {
550
551
  waypoints: node2.waypoints,
551
552
  routeColor: node2.routeColor ?? "#4285F4",
552
553
  routeWeight: node2.routeWeight ?? 4,
553
- zoom: node2.zoom ?? 10,
554
+ zoom: node2.zoom,
554
555
  center: node2.center,
555
556
  mapType: node2.mapType ?? "roadmap",
556
557
  language: node2.language,
@@ -1193,14 +1194,34 @@ init_compiler();
1193
1194
  import { execSync as execSync2 } from "node:child_process";
1194
1195
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync, renameSync } from "node:fs";
1195
1196
  import { createHash } from "node:crypto";
1196
- import { join, dirname as dirname2, resolve as resolvePath, relative } from "node:path";
1197
+ import { join, dirname as dirname3, resolve as resolvePath, relative } from "node:path";
1197
1198
 
1198
1199
  // src/render/cli-tools.ts
1199
1200
  import { execSync } from "node:child_process";
1201
+
1202
+ // src/queue-cli.mjs
1203
+ import { fileURLToPath } from "node:url";
1204
+ import { resolve, dirname } from "node:path";
1205
+ function shellQuote(value2) {
1206
+ return "'" + String(value2).replace(/'/g, "'\\''") + "'";
1207
+ }
1208
+ var queueWorker = resolve(dirname(fileURLToPath(import.meta.url)), "queue-worker.mjs");
1209
+ function queueCommand(command, env = process.env) {
1210
+ const template = env.MARKCUT_QUEUE_CLI_TEMPLATE;
1211
+ if (env.MARKCUT_QUEUE_ACTIVE === "1" || env.MARKCUT_QUEUE_ENABLED === "0") return command;
1212
+ if (!template) {
1213
+ return `${shellQuote(process.execPath)} ${shellQuote(queueWorker)} run --queue media-ai -- /bin/sh -c ${shellQuote(`MARKCUT_QUEUE_ACTIVE=1 ${command}`)}`;
1214
+ }
1215
+ if (!template.includes("{command}")) throw Error("MARKCUT_QUEUE_CLI_TEMPLATE must contain {command}");
1216
+ return template.replaceAll("{command}", shellQuote(`MARKCUT_QUEUE_ACTIVE=1 ${command}`));
1217
+ }
1218
+
1219
+ // src/render/cli-tools.ts
1200
1220
  import { existsSync, mkdirSync } from "node:fs";
1201
- import { dirname } from "node:path";
1221
+ import { dirname as dirname2 } from "node:path";
1202
1222
 
1203
1223
  // src/config.mjs
1224
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
1204
1225
  var args = (function parseArgs(argv) {
1205
1226
  const CLI_OVERRIDE_FLAGS = {
1206
1227
  "--itt": "itt",
@@ -1253,8 +1274,9 @@ var DEFAULT_AGENT_CLI = args.cliOverrides.agent || process.env.MARKCUT_AGENT_CLI
1253
1274
  var DEFAULT_EDIT_CLI = args.cliOverrides.editCli || process.env.MARKCUT_EDIT_CLI || "npx pi --session-id {sessionid} --system-prompt {systemprompt} -p {prompt}";
1254
1275
  var DEFAULT_TTI_CLI = args.cliOverrides.tti || process.env.MARKCUT_TTI_CLI || 'uvx --from mflux mflux-generate-flux2 --model flux2-klein-4b --steps 2 --prompt "{input}" --output "{output}" --seed {seed}';
1255
1276
  var DEFAULT_TTV_CLI = args.cliOverrides.ttv || process.env.MARKCUT_TTV_CLI || "";
1256
- var DEFAULT_ITT_CLI = args.cliOverrides.itt || process.env.MARKCUT_ITT_CLI || 'uvx --from mlx-vlm mlx_vlm.generate --model mlx-community/MiniCPM-V-4.6-bf16 --max-tokens 2048 --prompt "{prompt}" --image {input} --temperature 0.0 --thinking-mode disabled';
1257
- var DEFAULT_VTT_CLI = args.cliOverrides.vtt || process.env.MARKCUT_VTT_CLI || `uvx --from mlx-vlm mlx_vlm.generate --model mlx-community/MiniCPM-V-4.6-bf16 --max-tokens 2048 --prompt "{prompt}" --video {input} --temperature 0.0 --processor-kwargs '{"max_num_frames": 32, "stack_frames": 1, "max_slice_nums": 1, "use_image_id": false}'`;
1277
+ var DEFAULT_VISION_INFER = fileURLToPath2(new URL("./vision/default-infer.mjs", import.meta.url));
1278
+ var DEFAULT_ITT_CLI = args.cliOverrides.itt || process.env.MARKCUT_ITT_CLI || `node ${JSON.stringify(DEFAULT_VISION_INFER)} --prompt "{prompt}" {input}`;
1279
+ var DEFAULT_VTT_CLI = args.cliOverrides.vtt || process.env.MARKCUT_VTT_CLI || "";
1258
1280
 
1259
1281
  // src/render/cli-tools.ts
1260
1282
  function substituteCli(template, input, output, seed) {
@@ -1275,10 +1297,10 @@ function substituteCli(template, input, output, seed) {
1275
1297
  return template.replace(/\{input\}/g, safeInput).replace(/\{output\}/g, safeOutput).replace(/\{seed\}/g, safeSeed);
1276
1298
  }
1277
1299
  function generateTTS(text3, outputPath, cli) {
1278
- mkdirSync(dirname(outputPath), { recursive: true });
1300
+ mkdirSync(dirname2(outputPath), { recursive: true });
1279
1301
  const cmd = substituteCli(cli ?? DEFAULT_TTS_CLI, text3, outputPath);
1280
1302
  try {
1281
- execSync(cmd, { stdio: "pipe" });
1303
+ execSync(queueCommand(cmd), { stdio: "pipe" });
1282
1304
  } catch (e) {
1283
1305
  console.warn(` \u26A0 TTS failed: ${e.message}`);
1284
1306
  return "";
@@ -1288,16 +1310,16 @@ function generateTTS(text3, outputPath, cli) {
1288
1310
  async function generateSTT(audioPath, outputDir, cli) {
1289
1311
  const cmd = substituteCli(cli ?? DEFAULT_STT_CLI, audioPath, outputDir);
1290
1312
  try {
1291
- execSync(cmd, { stdio: "pipe" });
1313
+ execSync(queueCommand(cmd), { stdio: "pipe" });
1292
1314
  } catch (e) {
1293
1315
  console.warn(` \u26A0 STT failed: ${e.message}`);
1294
1316
  }
1295
1317
  }
1296
1318
  function generateTTI(prompt, outputPath, cli, seed) {
1297
- mkdirSync(dirname(outputPath), { recursive: true });
1319
+ mkdirSync(dirname2(outputPath), { recursive: true });
1298
1320
  const cmd = substituteCli(cli ?? DEFAULT_TTI_CLI, prompt, outputPath, seed);
1299
1321
  try {
1300
- execSync(cmd, {
1322
+ execSync(queueCommand(cmd), {
1301
1323
  encoding: "utf-8",
1302
1324
  stdio: ["pipe", "pipe", "pipe"],
1303
1325
  timeout: 3e5,
@@ -1310,7 +1332,7 @@ function generateTTI(prompt, outputPath, cli, seed) {
1310
1332
  return existsSync(outputPath) ? outputPath : "";
1311
1333
  }
1312
1334
  function generateTTV(prompt, outputPath, cli, ttiCmd, seed) {
1313
- mkdirSync(dirname(outputPath), { recursive: true });
1335
+ mkdirSync(dirname2(outputPath), { recursive: true });
1314
1336
  if (!cli) {
1315
1337
  const pngPath = outputPath.replace(/\.mp4$/, ".png");
1316
1338
  const imageResult = generateTTI(prompt, pngPath, ttiCmd, seed);
@@ -1320,7 +1342,7 @@ function generateTTV(prompt, outputPath, cli, ttiCmd, seed) {
1320
1342
  }
1321
1343
  try {
1322
1344
  execSync(
1323
- `ffmpeg -y -loop 1 -i "${pngPath}" -c:v libx264 -t 3 -pix_fmt yuv420p "${outputPath}"`,
1345
+ queueCommand(`ffmpeg -y -loop 1 -i "${pngPath}" -c:v libx264 -t 3 -pix_fmt yuv420p "${outputPath}"`),
1324
1346
  { stdio: ["pipe", "pipe", "pipe"], timeout: 6e4 }
1325
1347
  );
1326
1348
  } catch (e) {
@@ -1335,7 +1357,7 @@ function generateTTV(prompt, outputPath, cli, ttiCmd, seed) {
1335
1357
  }
1336
1358
  const cmd = substituteCli(cli, prompt, outputPath, seed);
1337
1359
  try {
1338
- execSync(cmd, {
1360
+ execSync(queueCommand(cmd), {
1339
1361
  encoding: "utf-8",
1340
1362
  stdio: ["pipe", "pipe", "pipe"],
1341
1363
  timeout: 3e5,
@@ -1628,7 +1650,7 @@ import { default as default2 } from "node:path";
1628
1650
  import { default as default3 } from "node:process";
1629
1651
 
1630
1652
  // node_modules/vfile/lib/minurl.js
1631
- import { fileURLToPath } from "node:url";
1653
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
1632
1654
 
1633
1655
  // node_modules/vfile/lib/minurl.shared.js
1634
1656
  function isUrl(fileUrlOrPath) {
@@ -1751,9 +1773,9 @@ var VFile = class {
1751
1773
  * @returns {undefined}
1752
1774
  * Nothing.
1753
1775
  */
1754
- set dirname(dirname3) {
1776
+ set dirname(dirname4) {
1755
1777
  assertPath(this.basename, "dirname");
1756
- this.path = default2.join(dirname3 || "", this.basename);
1778
+ this.path = default2.join(dirname4 || "", this.basename);
1757
1779
  }
1758
1780
  /**
1759
1781
  * Get the extname (including dot) (example: `'.js'`).
@@ -1812,7 +1834,7 @@ var VFile = class {
1812
1834
  */
1813
1835
  set path(path) {
1814
1836
  if (isUrl(path)) {
1815
- path = fileURLToPath(path);
1837
+ path = fileURLToPath3(path);
1816
1838
  }
1817
1839
  assertNonEmpty(path, "path");
1818
1840
  if (this.path !== path) {
@@ -2352,7 +2374,7 @@ var Processor = class _Processor extends CallableInstance {
2352
2374
  assertParser("process", this.parser || this.Parser);
2353
2375
  assertCompiler("process", this.compiler || this.Compiler);
2354
2376
  return done ? executor(void 0, done) : new Promise(executor);
2355
- function executor(resolve, reject) {
2377
+ function executor(resolve2, reject) {
2356
2378
  const realFile = vfile(file);
2357
2379
  const parseTree = (
2358
2380
  /** @type {HeadTree extends undefined ? Node : HeadTree} */
@@ -2383,8 +2405,8 @@ var Processor = class _Processor extends CallableInstance {
2383
2405
  function realDone(error, file2) {
2384
2406
  if (error || !file2) {
2385
2407
  reject(error);
2386
- } else if (resolve) {
2387
- resolve(file2);
2408
+ } else if (resolve2) {
2409
+ resolve2(file2);
2388
2410
  } else {
2389
2411
  ok(done, "`done` is defined if `resolve` is not");
2390
2412
  done(void 0, file2);
@@ -2486,7 +2508,7 @@ var Processor = class _Processor extends CallableInstance {
2486
2508
  file = void 0;
2487
2509
  }
2488
2510
  return done ? executor(void 0, done) : new Promise(executor);
2489
- function executor(resolve, reject) {
2511
+ function executor(resolve2, reject) {
2490
2512
  ok(
2491
2513
  typeof file !== "function",
2492
2514
  "`file` can\u2019t be a `done` anymore, we checked"
@@ -2500,8 +2522,8 @@ var Processor = class _Processor extends CallableInstance {
2500
2522
  );
2501
2523
  if (error) {
2502
2524
  reject(error);
2503
- } else if (resolve) {
2504
- resolve(resultingTree);
2525
+ } else if (resolve2) {
2526
+ resolve2(resultingTree);
2505
2527
  } else {
2506
2528
  ok(done, "`done` is defined if `resolve` is not");
2507
2529
  done(void 0, resultingTree, file2);
@@ -5329,10 +5351,10 @@ function resolveAll(constructs2, events, context) {
5329
5351
  const called = [];
5330
5352
  let index2 = -1;
5331
5353
  while (++index2 < constructs2.length) {
5332
- const resolve = constructs2[index2].resolveAll;
5333
- if (resolve && !called.includes(resolve)) {
5334
- events = resolve(events, context);
5335
- called.push(resolve);
5354
+ const resolve2 = constructs2[index2].resolveAll;
5355
+ if (resolve2 && !called.includes(resolve2)) {
5356
+ events = resolve2(events, context);
5357
+ called.push(resolve2);
5336
5358
  }
5337
5359
  }
5338
5360
  return events;
@@ -10427,7 +10449,8 @@ function preserveVariantAttrs(node2, attrs) {
10427
10449
  "layout",
10428
10450
  "componentName",
10429
10451
  "props",
10430
- "speaker"
10452
+ "speaker",
10453
+ "isNarration"
10431
10454
  ]);
10432
10455
  for (const [k, v] of Object.entries(attrs)) {
10433
10456
  if (!STANDARD.has(k)) {
@@ -10525,6 +10548,7 @@ function parseNodeLine(content3, lineNum) {
10525
10548
  id: attrs.id,
10526
10549
  src,
10527
10550
  speaker: attrs.speaker,
10551
+ isNarration: attrs.isNarration,
10528
10552
  duration: attrs.duration,
10529
10553
  start: attrs.start,
10530
10554
  startFrom: attrs.startFrom,
@@ -10828,6 +10852,12 @@ function processMDASTListItem(item, parent, lines) {
10828
10852
  }
10829
10853
  }
10830
10854
  }
10855
+ if (/^script(?:\s|$)/.test(text3) && !node2.script?.trim() && !node2.on) {
10856
+ throw new DslError("script requires text content", {
10857
+ line: firstPara.position?.start?.line,
10858
+ lineText: text3
10859
+ });
10860
+ }
10831
10861
  }
10832
10862
  function applySceneMetadata(scene, attrs) {
10833
10863
  for (const [k, v] of Object.entries(attrs)) {
@@ -11161,6 +11191,7 @@ async function resolveScripts(root, options) {
11161
11191
  }
11162
11192
  if (!generated) continue;
11163
11193
  node2.src = resolvePath(generated);
11194
+ node2.isNarration = true;
11164
11195
  delete node2.script;
11165
11196
  }
11166
11197
  if (totalScripts > 0) {
@@ -11490,7 +11521,7 @@ async function resolveIncludes(root, options) {
11490
11521
  const resolved = await resolveAll2(subRoot, {
11491
11522
  ...options,
11492
11523
  includeOutputDir: outputDir,
11493
- baseDir: dirname2(absPath),
11524
+ baseDir: dirname3(absPath),
11494
11525
  variants: variantChain
11495
11526
  });
11496
11527
  const compiled = compileDescriptiveRoot(resolved);
@@ -114,6 +114,7 @@ export const audio = base.extend({
114
114
  volume: z.number().min(0).max(1).default(1),
115
115
  foreground: z.boolean().optional().describe("ducks parent video audio while playing"),
116
116
  speaker: z.string().optional().describe("speaker name for multi-turn dialogue; set by resolveDialogue"),
117
+ isNarration: z.boolean().optional().describe("generated or explicitly marked recorded narration"),
117
118
  });
118
119
  export type Audio = z.infer<typeof audio>;
119
120
 
@@ -281,7 +282,7 @@ export const mapStream = base.extend({
281
282
  waypoints: z.array(mapWaypoint).default(() => []),
282
283
  routeColor: z.string().default("#4285F4"),
283
284
  routeWeight: z.number().default(4),
284
- zoom: z.number().default(10),
285
+ zoom: z.number().optional().describe("Optional fixed zoom; route view auto-fits when omitted"),
285
286
  center: z.object({ lat: z.number(), lng: z.number() }).optional().describe("map view center (defaults to first waypoint)"),
286
287
  mapType: z.enum(["roadmap", "satellite", "hybrid", "terrain"]).default("roadmap").describe("Google Maps style"),
287
288
  language: z.string().optional().describe("Google Maps UI/label language, e.g. zh-CN"),
package/src/types/Map.tsx CHANGED
@@ -37,6 +37,7 @@ import {
37
37
  } from "@vis.gl/react-google-maps";
38
38
  import type { Map3DRef } from "@vis.gl/react-google-maps";
39
39
  import { resolveTween } from "../utils/tween";
40
+ import { fitRouteViewport } from "../utils/map-viewport";
40
41
  import {
41
42
  makeSyntheticLeg,
42
43
  isSyntheticMode,
@@ -460,17 +461,20 @@ function OverviewMap({
460
461
  function RouteMap({
461
462
  stream, onTilesLoaded,
462
463
  }: { stream: MapStream; onTilesLoaded: () => void }) {
463
- const { fps } = useVideoConfig();
464
+ const { fps, width, height } = useVideoConfig();
464
465
  const frame = useCurrentFrame();
465
466
  const waypoints = stream.waypoints ?? [];
466
467
  const start = stream.start ?? 0;
467
468
  const end = stream.end ?? start + (stream.duration ?? 1);
468
- const fallbackCenter = stream.center ?? { lat: waypoints[0]!.lat, lng: waypoints[0]!.lng };
469
+ // Fit all observed stops to the video composition by default. Explicit
470
+ // stream/camera center and zoom take precedence over automatic framing.
471
+ const fitted = React.useMemo(() => fitRouteViewport(waypoints, width, height), [waypoints, width, height]);
472
+ const fallbackCenter = stream.center ?? fitted?.center ?? waypoints[0] ?? {lat: 0, lng: 0};
469
473
  const center = {
470
474
  lat: resolveTween(frame, fps, stream.camera?.center?.lat, start, end, fallbackCenter.lat),
471
475
  lng: resolveTween(frame, fps, stream.camera?.center?.lng, start, end, fallbackCenter.lng),
472
476
  };
473
- const zoom = resolveTween(frame, fps, stream.camera?.zoom, start, end, stream.zoom ?? 10);
477
+ const zoom = resolveTween(frame, fps, stream.camera?.zoom, start, end, stream.zoom ?? fitted?.zoom ?? 10);
474
478
  return (
475
479
  <GoogleMap
476
480
  mapId={String(stream.id ?? "map-route")}
@@ -0,0 +1,47 @@
1
+ /** Deterministic Web Mercator framing for route waypoints in a video frame. */
2
+ export type MapLocation = {lat: number; lng: number};
3
+ export type RouteViewport = {center: MapLocation; zoom: number};
4
+
5
+ const TILE = 256;
6
+ const MAX_MERCATOR_LAT = 85.05112878;
7
+ const clamp = (n: number, lo: number, hi: number) => Math.max(lo, Math.min(hi, n));
8
+ const wrap = (n: number, mod: number) => ((n % mod) + mod) % mod;
9
+
10
+ /** Fit observed points, not an inferred road, inside the given composition. */
11
+ export function fitRouteViewport(
12
+ locations: readonly MapLocation[],
13
+ width: number,
14
+ height: number,
15
+ {padding = 0.14, minZoom = 2, maxZoom = 17}: {padding?: number; minZoom?: number; maxZoom?: number} = {},
16
+ ): RouteViewport | null {
17
+ if (!(width > 0 && height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) return null;
18
+ if (!(padding >= 0 && padding < 0.5) || minZoom > maxZoom) return null;
19
+ const points = locations.filter(p => Number.isFinite(p.lat) && Number.isFinite(p.lng) &&
20
+ Math.abs(p.lat) <= 90 && Math.abs(p.lng) <= 180);
21
+ if (!points.length) return null;
22
+
23
+ const xs = points.map(p => wrap((p.lng + 180) / 360 * TILE, TILE)).sort((a,b)=>a-b);
24
+ // Minimum circular longitude interval also works across the date line.
25
+ let gap = -1, largestGapIndex = 0;
26
+ for (let i=0; i<xs.length; i++) {
27
+ const next = i+1 < xs.length ? xs[i+1] : xs[0] + TILE;
28
+ if (next-xs[i] > gap) {gap = next-xs[i]; largestGapIndex=i;}
29
+ }
30
+ const left = xs[(largestGapIndex+1)%xs.length];
31
+ const spanX = TILE-gap;
32
+ const midX = wrap(left+spanX/2,TILE);
33
+ const lng = wrap(midX/TILE*360,360)-180;
34
+
35
+ const ys = points.map(p=>{
36
+ const sine = Math.sin(clamp(p.lat,-MAX_MERCATOR_LAT,MAX_MERCATOR_LAT)*Math.PI/180);
37
+ return TILE * (0.5-Math.log((1+sine)/(1-sine))/(4*Math.PI));
38
+ });
39
+ const top = Math.min(...ys), bottom = Math.max(...ys);
40
+ const midY = (top+bottom)/2;
41
+ const lat = (180/Math.PI)*(2*Math.atan(Math.exp(Math.PI-2*Math.PI*midY/TILE))-Math.PI/2);
42
+ const spanY = bottom-top;
43
+ const usableWidth=width*(1-2*padding),usableHeight=height*(1-2*padding);
44
+ const xZoom=spanX>0 ? Math.log2(usableWidth/spanX) : maxZoom;
45
+ const yZoom=spanY>0 ? Math.log2(usableHeight/spanY) : maxZoom;
46
+ return {center:{lat,lng},zoom:clamp(Math.min(xZoom,yZoom),minZoom,maxZoom)};
47
+ }
@@ -0,0 +1,57 @@
1
+ import {describe,expect,it} from 'vitest';
2
+ import {fitRouteViewport} from '../src/utils/map-viewport';
3
+ import {parseMarkdownDescriptive} from '../src/descriptive/markdown';
4
+ import {compileDescriptiveRoot} from '../src/descriptive/compiler';
5
+ import {mapStream} from '../src/schema/index';
6
+
7
+ const points=[{lat:45.347,lng:-75.911},{lat:45.320,lng:-75.928}];
8
+ describe('fitRouteViewport',()=>{
9
+ it('fills a tall 9:16 frame for the genuine September GPS pair',()=>{
10
+ const fit=fitRouteViewport(points,720,1280)!;
11
+ expect(fit.center.lat).toBeCloseTo(45.3335,2);
12
+ expect(fit.center.lng).toBeCloseTo(-75.9195,3);
13
+ expect(fit.zoom).toBeGreaterThan(13);
14
+ expect(fit.zoom).toBeLessThan(17);
15
+ });
16
+ it('fits both points inside the requested viewport with padding',()=>{
17
+ const r=fitRouteViewport(points,720,1280,{padding:0.14})!;
18
+ const y=(lat:number)=>256*(0.5-Math.log((1+Math.sin(lat*Math.PI/180))/(1-Math.sin(lat*Math.PI/180)))/(4*Math.PI));
19
+ const spanX=Math.abs(points[0].lng-points[1].lng)/360*256*Math.pow(2,r.zoom);
20
+ const spanY=Math.abs(y(points[0].lat)-y(points[1].lat))*Math.pow(2,r.zoom);
21
+ expect(spanX).toBeLessThanOrEqual(720*0.72+0.01);
22
+ expect(spanY).toBeLessThanOrEqual(1280*0.72+0.01);
23
+ });
24
+ it('is different for square and landscape compositions',()=>{
25
+ const portrait=fitRouteViewport(points,720,1280)!;
26
+ const landscape=fitRouteViewport(points,1280,720)!;
27
+ expect(portrait.zoom).toBeGreaterThan(landscape.zoom);
28
+ });
29
+ it('picks the short antimeridian interval',()=>{
30
+ const v=fitRouteViewport([{lat:10,lng:179.8},{lat:10,lng:-179.8}],720,1280)!;
31
+ expect(Math.abs(v.center.lng)).toBeCloseTo(180,2);
32
+ expect(v.zoom).toBeGreaterThan(9);
33
+ });
34
+ it('limits zoom for identical points and filters invalid input',()=>{
35
+ expect(fitRouteViewport([points[0],points[0]],720,1280)?.zoom).toBe(17);
36
+ expect(fitRouteViewport([{lat:NaN,lng:0}],720,1280)).toBeNull();
37
+ expect(fitRouteViewport(points,0,1280)).toBeNull();
38
+ });
39
+ });
40
+
41
+ describe('route map compilation',()=>{
42
+ function compiled(zoom=''){
43
+ const text=`# video\nwidth:720 height:1280 fps:30\n\n## locations\n- map view:route duration:16 ${zoom} waypoints:[45.347,-75.911,"Afternoon"; 45.320,-75.928,"Evening"]`;
44
+ const root=compileDescriptiveRoot(parseMarkdownDescriptive(text));
45
+ return root.children[0].children[0] as any;
46
+ }
47
+ it('does not inject fixed zoom for automatic fit',()=>{
48
+ const map=compiled();
49
+ expect(map.zoom).toBeUndefined();
50
+ expect(mapStream.parse(map).zoom).toBeUndefined();
51
+ });
52
+ it('preserves explicit fixed zoom overrides',()=>{
53
+ const map=compiled('zoom:12');
54
+ expect(map.zoom).toBe(12);
55
+ expect(mapStream.parse(map).zoom).toBe(12);
56
+ });
57
+ });
@@ -11,7 +11,7 @@ describe('Markcut Remotion MCP App',()=>{
11
11
  const html=buildPreviewHtml();
12
12
  expect(html).toContain('id="remotion-root"');
13
13
  expect(html).toContain('id="player-version"');
14
- expect(html).toContain('>v35</span>');
14
+ expect(html).toContain('>'+RESOURCE_URI.match(/video-preview-(v\d+)/)?.[1]+'</span>');
15
15
  expect(html).toContain('id="video-md-version"');
16
16
  expect(html).toContain('<textarea id="feedback" rows="3"');
17
17
  expect(html).toContain('id="comment-tools"');
@@ -0,0 +1,58 @@
1
+ import {describe,expect,it} from 'vitest';
2
+ import {extractRemotePreviewAudio,isRecordedNarration,previewBgmGain,withoutRecordedNarration} from '../src/mcp/audio-preview-tree';
3
+
4
+ const remote='https://neoy.qili2.com/files/_neoy/markcut/generated/test/audio.mp3';
5
+ const soundtrack={type:'audio',src:remote,isBackground:true,volume:0.95};
6
+ const narration={type:'audio',src:'assets/tts/voice-001.mp3',foreground:true};
7
+ const ambient={type:'audio',src:'assets/stream.mp3',foreground:true};
8
+ const publishedNarration={type:'audio',src:'https://neoy.qili2.com/files/generated/run/file-3.mp3',isNarration:true};
9
+ const fx={type:'audio',src:'https://neoy.qili2.com/files/fx/swoosh.mp3',name:'transition'};
10
+ const video={type:'video',src:'https://neoy.qili2.com/files/environment.mp4',volume:1};
11
+ const scene={type:'scene',name:'Opening',children:[{type:'image',src:'image.jpg'},narration,ambient,fx,video]};
12
+ const root={type:'root',fps:30,subtitle:{src:'captions.vtt'},children:[soundtrack,scene]};
13
+
14
+ describe('MCP Web Audio preview source preservation and narration mixing',()=>{
15
+ it('captures remote background music before returning the visual tree',()=>{
16
+ const {audio,playbackRoot}=extractRemotePreviewAudio(root);
17
+ expect(audio).toBe(soundtrack);
18
+ expect(playbackRoot.children.map((node:{type:string})=>node.type)).toEqual(['scene']);
19
+ expect(playbackRoot.children[0].children).toEqual(scene.children);
20
+ expect(root.children[0]).toBe(soundtrack);
21
+ });
22
+ it('Browser TTS removes only identified narration, retaining BGM, ambient audio, SFX, video sound',()=>{
23
+ const processed=withoutRecordedNarration(root);
24
+ expect(processed.children[0]).toEqual(soundtrack);
25
+ expect(processed.children[1].children).toEqual([scene.children[0],ambient,fx,video]);
26
+ expect(processed.subtitle).toBeUndefined();
27
+ expect(root.subtitle.src).toBe('captions.vtt');
28
+ });
29
+ it('retains local BGM and other remote audio when extracting the music bed',()=>{
30
+ const local={type:'audio',src:'assets/music.mp3',isBackground:true};
31
+ const extra={type:'audio',src:'https://neoy.qili2.com/files/second-bed.mp3',isBackground:true};
32
+ const {audio,playbackRoot}=extractRemotePreviewAudio({...root,children:[local,soundtrack,extra,scene]});
33
+ expect(audio).toBe(soundtrack);
34
+ expect(withoutRecordedNarration(playbackRoot).children).toEqual([local,extra,{...scene,children:[scene.children[0],ambient,fx,video]}]);
35
+ });
36
+ it('identifies synthetic speech without treating environment or sound effects as narration',()=>{
37
+ expect(isRecordedNarration(narration)).toBe(true);
38
+ expect(isRecordedNarration(publishedNarration)).toBe(true);
39
+ expect(withoutRecordedNarration({type:'root',children:[publishedNarration,ambient]}).children).toEqual([ambient]);
40
+ expect(isRecordedNarration({type:'audio',speaker:'Ray'})).toBe(true);
41
+ expect(isRecordedNarration({type:'audio',role:'narration'})).toBe(true);
42
+ expect(isRecordedNarration(ambient)).toBe(false);
43
+ expect(isRecordedNarration(fx)).toBe(false);
44
+ expect(isRecordedNarration(soundtrack)).toBe(false);
45
+ });
46
+ it('ducks the BGM during synthesized speech and restores its gain afterward',()=>{
47
+ expect(previewBgmGain(1,0.95,false,false)).toBeCloseTo(0.95);
48
+ expect(previewBgmGain(1,0.95,false,true)).toBeCloseTo(0.266);
49
+ expect(previewBgmGain(0.5,0.95,false,true)).toBeCloseTo(0.133);
50
+ expect(previewBgmGain(1,0.95,true,true)).toBe(0);
51
+ expect(previewBgmGain(1,0.95,false,false)).toBeCloseTo(0.95);
52
+ });
53
+ it('does not create an external audio source when there is no remote BGM',()=>{
54
+ const {audio,playbackRoot}=extractRemotePreviewAudio({type:'root',children:[scene]});
55
+ expect(audio).toBeNull();
56
+ expect(playbackRoot.children[0].children).toEqual(scene.children);
57
+ });
58
+ });