mulmocast 2.4.5 → 2.4.6

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.
@@ -1,10 +1,21 @@
1
1
  import fs from "node:fs";
2
+ import nodePath from "node:path";
2
3
  import { MulmoBeatMethods } from "../../methods/mulmo_beat.js";
3
4
  import { getHTMLFile } from "../file.js";
4
5
  import { renderHTMLToImage, interpolate, renderHTMLToFrames } from "../html_render.js";
5
6
  import { framesToVideo } from "../ffmpeg_utils.js";
6
7
  import { parrotingImagePath } from "./utils.js";
7
8
  export const imageType = "html_tailwind";
9
+ /**
10
+ * Resolve relative paths in src attributes to file:// absolute paths.
11
+ * Paths starting with http://, https://, file://, data:, or / are left unchanged.
12
+ */
13
+ const resolveRelativeImagePaths = (html, baseDirPath) => {
14
+ return html.replace(/(\bsrc\s*=\s*)(["'])((?!https?:\/\/|file:\/\/|data:|\/)[^"']+)\2/gi, (_, prefix, quote, relativePath) => {
15
+ const absolutePath = nodePath.resolve(baseDirPath, relativePath);
16
+ return `${prefix}${quote}file://${absolutePath}${quote}`;
17
+ });
18
+ };
8
19
  const DEFAULT_ANIMATION_FPS = 30;
9
20
  /** Join html field into a single string (handles both string and string[]) */
10
21
  const joinHtml = (html) => {
@@ -28,7 +39,7 @@ const getAnimationConfig = (params) => {
28
39
  return { fps: DEFAULT_ANIMATION_FPS };
29
40
  };
30
41
  const processHtmlTailwindAnimated = async (params) => {
31
- const { beat, imagePath, canvasSize } = params;
42
+ const { beat, imagePath, canvasSize, context } = params;
32
43
  if (!beat.image || beat.image.type !== imageType)
33
44
  return;
34
45
  const animConfig = getAnimationConfig(params);
@@ -46,13 +57,14 @@ const processHtmlTailwindAnimated = async (params) => {
46
57
  const html = joinHtml(beat.image.html);
47
58
  const template = getHTMLFile("tailwind_animated");
48
59
  const script = "script" in beat.image ? beat.image.script : undefined;
49
- const htmlData = interpolate(template, {
60
+ const rawHtmlData = interpolate(template, {
50
61
  html_body: html,
51
62
  user_script: buildUserScript(script),
52
63
  totalFrames: String(totalFrames),
53
64
  fps: String(fps),
54
65
  custom_style: "",
55
66
  });
67
+ const htmlData = resolveRelativeImagePaths(rawHtmlData, context.fileDirs.mulmoFileDirPath);
56
68
  // imagePath is set to the .mp4 path by imagePluginAgent for animated beats
57
69
  const videoPath = imagePath;
58
70
  // Create frames directory next to the video file
@@ -68,16 +80,17 @@ const processHtmlTailwindAnimated = async (params) => {
68
80
  return videoPath;
69
81
  };
70
82
  const processHtmlTailwindStatic = async (params) => {
71
- const { beat, imagePath, canvasSize } = params;
83
+ const { beat, imagePath, canvasSize, context } = params;
72
84
  if (!beat.image || beat.image.type !== imageType)
73
85
  return;
74
86
  const html = joinHtml(beat.image.html);
75
87
  const template = getHTMLFile("tailwind");
76
88
  const script = "script" in beat.image ? beat.image.script : undefined;
77
- const htmlData = interpolate(template, {
89
+ const rawHtmlData = interpolate(template, {
78
90
  html_body: html,
79
91
  user_script: buildUserScript(script),
80
92
  });
93
+ const htmlData = resolveRelativeImagePaths(rawHtmlData, context.fileDirs.mulmoFileDirPath);
81
94
  await renderHTMLToImage(htmlData, imagePath, canvasSize.width, canvasSize.height);
82
95
  return imagePath;
83
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mulmocast",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "lib/index.node.js",
@@ -339,10 +339,7 @@
339
339
  " </div>",
340
340
  "</div>"
341
341
  ],
342
- "script": [
343
- "const animation = new MulmoAnimation();",
344
- "animation.animate('#t', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"
345
- ],
342
+ "script": ["const animation = new MulmoAnimation();", "animation.animate('#t', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"],
346
343
  "animation": true
347
344
  }
348
345
  },
@@ -490,10 +487,7 @@
490
487
  " <div id='t' class='text-7xl font-bold' style='font-family:\"Courier New\",Monaco,monospace;color:#00ff00;opacity:0'>THE MATRIX</div>",
491
488
  "</div>"
492
489
  ],
493
- "script": [
494
- "const animation = new MulmoAnimation();",
495
- "animation.animate('#t', { opacity: [0, 1] }, { start: 0.3, end: 1.0 });"
496
- ],
490
+ "script": ["const animation = new MulmoAnimation();", "animation.animate('#t', { opacity: [0, 1] }, { start: 0.3, end: 1.0 });"],
497
491
  "animation": true
498
492
  }
499
493
  },
@@ -565,10 +559,7 @@
565
559
  " <div id='t' class='text-7xl font-bold tracking-wide' style='font-family:Georgia,serif;color:#2c3e50;opacity:0'>DOCUMENTARY</div>",
566
560
  "</div>"
567
561
  ],
568
- "script": [
569
- "const animation = new MulmoAnimation();",
570
- "animation.animate('#t', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"
571
- ],
562
+ "script": ["const animation = new MulmoAnimation();", "animation.animate('#t', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"],
572
563
  "animation": true
573
564
  }
574
565
  },
@@ -716,10 +707,7 @@
716
707
  " </div>",
717
708
  "</div>"
718
709
  ],
719
- "script": [
720
- "const animation = new MulmoAnimation();",
721
- "animation.animate('#t', { opacity: [0, 1] }, { start: 1.0, end: 2.5 });"
722
- ],
710
+ "script": ["const animation = new MulmoAnimation();", "animation.animate('#t', { opacity: [0, 1] }, { start: 1.0, end: 2.5 });"],
723
711
  "animation": true
724
712
  }
725
713
  },
@@ -913,10 +901,7 @@
913
901
  " </div>",
914
902
  "</div>"
915
903
  ],
916
- "script": [
917
- "const animation = new MulmoAnimation();",
918
- "animation.animate('#title', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"
919
- ],
904
+ "script": ["const animation = new MulmoAnimation();", "animation.animate('#title', { opacity: [0, 1] }, { start: 0.5, end: 1.5 });"],
920
905
  "animation": true
921
906
  }
922
907
  },
@@ -1368,4 +1353,4 @@
1368
1353
  }
1369
1354
  }
1370
1355
  ]
1371
- }
1356
+ }