@gehdoc/svg-to-video 0.27.6 → 0.27.8

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/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  [![GitHub Release](https://img.shields.io/github/v/release/GehDoc/svg-to-video?logo=github&logoColor=white&label=release&color=2b3137)](https://github.com/GehDoc/svg-to-video/releases)
9
9
  [![npm Version](https://img.shields.io/npm/v/@gehdoc/svg-to-video?logo=npm&logoColor=white&label=npm&color=CB3837)](https://www.npmjs.com/package/@gehdoc/svg-to-video)
10
10
  [![MCP Registry](https://img.shields.io/badge/MCP-io.github.GehDoc%2Fsvg--to--video-purple?logo=modelcontextprotocol&logoColor=white)](https://registry.modelcontextprotocol.io/v0/servers/io.github.GehDoc%2Fsvg-to-video/versions/latest)
11
+ [![llms.txt](https://img.shields.io/badge/llms.txt-available-blue)](https://gehdoc.github.io/svg-to-video/llms.txt)
11
12
  [![Docker Image](https://img.shields.io/docker/v/gehdoc/svg-to-video?label=docker&logo=docker&logoColor=white&sort=semver&color=2496ed)](https://hub.docker.com/r/gehdoc/svg-to-video)
12
13
  [![Last Commit](https://img.shields.io/github/last-commit/GehDoc/svg-to-video?logo=github&logoColor=white)](https://github.com/GehDoc/svg-to-video/commits/main)
13
14
 
@@ -21,7 +21,7 @@ export class ConversionTracker {
21
21
  typeof performance !== 'undefined' ? performance.now() : Date.now();
22
22
  }
23
23
  start() {
24
- this.trackFn('conversion-start', {
24
+ return this.trackFn('conversion-start', {
25
25
  format: this.options.format,
26
26
  isTransparent: this.options.isTransparent,
27
27
  captureMethod: this.options.captureMethod,
@@ -31,7 +31,7 @@ export class ConversionTracker {
31
31
  }
32
32
  success(totalFrames) {
33
33
  const processDurationSec = calculateElapsedSec(this.startTimeMs);
34
- this.trackFn('conversion-success', {
34
+ return this.trackFn('conversion-success', {
35
35
  format: this.options.format,
36
36
  isTransparent: this.options.isTransparent,
37
37
  captureMethod: this.options.captureMethod,
@@ -44,7 +44,7 @@ export class ConversionTracker {
44
44
  failed(error) {
45
45
  const processDurationSec = calculateElapsedSec(this.startTimeMs);
46
46
  const errorMessage = typeof error === 'string' ? error : error.message;
47
- this.trackFn('conversion-failed', {
47
+ return this.trackFn('conversion-failed', {
48
48
  error: errorMessage,
49
49
  format: this.options.format,
50
50
  isTransparent: this.options.isTransparent,
@@ -54,7 +54,7 @@ export class ConversionTracker {
54
54
  }
55
55
  cancel() {
56
56
  const processDurationSec = calculateElapsedSec(this.startTimeMs);
57
- this.trackFn('conversion-cancel', {
57
+ return this.trackFn('conversion-cancel', {
58
58
  format: this.options.format,
59
59
  isTransparent: this.options.isTransparent,
60
60
  captureMethod: this.options.captureMethod,
package/dist/src/index.js CHANGED
@@ -11,7 +11,7 @@ import { formatRegistry } from './formats/registry.js';
11
11
  import { pkg } from './utils/packageInfo.js';
12
12
  import { JSDOM } from 'jsdom'; // For duration detection in Node environment
13
13
  import { Logger } from './utils/logger.js';
14
- import { trackEvent } from './utils/analytics.js';
14
+ import { trackEvent, flushAnalytics } from './utils/analytics.js';
15
15
  import { ConversionTracker } from '#shared/rendererTracking.js';
16
16
  const frameFileExtension = 'png';
17
17
  async function main() {
@@ -55,7 +55,7 @@ Resources:
55
55
  .action(async () => {
56
56
  await import('./mcp.js');
57
57
  });
58
- program.parse(process.argv);
58
+ await program.parseAsync(process.argv);
59
59
  }
60
60
  /**
61
61
  * main function to run the conversion process
@@ -73,16 +73,19 @@ async function run(svgPath, fps, outDir, options) {
73
73
  const outputFileName = `${inputBasename}${ext}`;
74
74
  const outputFullPath = path.join(outDir, outputFileName);
75
75
  if (fs.existsSync(outputFullPath) && !options.force) {
76
- throw logger.fatal(`Output file "${outputFullPath}" already exists. Use the --force (-f) flag to overwrite it.`);
76
+ await logger.fatal(`Output file "${outputFullPath}" already exists. Use the --force (-f) flag to overwrite it.`);
77
+ return;
77
78
  }
78
79
  try {
79
80
  validateOptions(options);
80
81
  }
81
82
  catch (error) {
82
- throw logger.fatal(error instanceof Error ? error.message : String(error));
83
+ await logger.fatal(error instanceof Error ? error.message : String(error));
84
+ return;
83
85
  }
84
86
  if (!fs.existsSync(svgPath)) {
85
- throw logger.fatal(`Input SVG file "${svgPath}" does not exist.`);
87
+ await logger.fatal(`Input SVG file "${svgPath}" does not exist.`);
88
+ return;
86
89
  }
87
90
  const svg = fs.readFileSync(svgPath, 'utf-8');
88
91
  const dom = new JSDOM('');
@@ -93,7 +96,8 @@ async function run(svgPath, fps, outDir, options) {
93
96
  logger.info('šŸ” Duration not provided, attempting to auto-detect...');
94
97
  duration = detectedDuration;
95
98
  if (duration === undefined) {
96
- throw logger.fatal('Could not detect duration. Please provide a duration using -d or --duration.');
99
+ await logger.fatal('Could not detect duration. Please provide a duration using -d or --duration.');
100
+ return;
97
101
  }
98
102
  logger.info(`āœ… Auto-detected duration: ${duration}s`);
99
103
  }
@@ -126,6 +130,23 @@ async function run(svgPath, fps, outDir, options) {
126
130
  videoDurationSec: duration,
127
131
  }, trackEvent);
128
132
  tracker.start();
133
+ let isCancelled = false;
134
+ const handleSignal = async (signal) => {
135
+ if (isCancelled)
136
+ return;
137
+ isCancelled = true;
138
+ logger.info(`\nāš ļø Received ${signal}. Cancelling conversion...`);
139
+ tracker.cancel();
140
+ if (!options.keepFrames && totalFrames > 0 && padWidth > 0) {
141
+ cleanupFrames(totalFrames, padWidth, outDir, logger);
142
+ }
143
+ await flushAnalytics();
144
+ process.exit(130);
145
+ };
146
+ const sigintListener = () => void handleSignal('SIGINT');
147
+ const sigtermListener = () => void handleSignal('SIGTERM');
148
+ process.once('SIGINT', sigintListener);
149
+ process.once('SIGTERM', sigtermListener);
129
150
  try {
130
151
  fs.mkdirSync(outDir, { recursive: true });
131
152
  await createFrames(svg, parsedDim, fps, totalFrames, padWidth, outDir, puppeteerArgs, options.resolution, options.scale, options.transparent, options.bgColor, logger);
@@ -134,6 +155,7 @@ async function run(svgPath, fps, outDir, options) {
134
155
  cleanupFrames(totalFrames, padWidth, outDir, logger);
135
156
  }
136
157
  tracker.success(totalFrames);
158
+ await flushAnalytics();
137
159
  logger.done(outputFullPath, {
138
160
  duration,
139
161
  fps,
@@ -144,8 +166,23 @@ async function run(svgPath, fps, outDir, options) {
144
166
  });
145
167
  }
146
168
  catch (error) {
147
- tracker.failed(error instanceof Error ? error : String(error));
148
- throw error;
169
+ if (!isCancelled) {
170
+ tracker.failed(error instanceof Error ? error : String(error));
171
+ if (!options.keepFrames) {
172
+ try {
173
+ cleanupFrames(totalFrames, padWidth, outDir, logger);
174
+ }
175
+ catch {
176
+ // ignore frame cleanup error during exception handling
177
+ }
178
+ }
179
+ await flushAnalytics();
180
+ await logger.fatal('Conversion failed', error instanceof Error ? error.message : String(error));
181
+ }
182
+ }
183
+ finally {
184
+ process.removeListener('SIGINT', sigintListener);
185
+ process.removeListener('SIGTERM', sigtermListener);
149
186
  }
150
187
  }
151
188
  /**
@@ -264,7 +301,8 @@ function convertToOutput(outputFileName, format, fps, padWidth, hold, outDir, tr
264
301
  }
265
302
  }
266
303
  catch (error) {
267
- throw logger.fatal('FFmpeg execution failed', error instanceof Error ? error.message : String(error));
304
+ const details = error instanceof Error ? error.message : String(error);
305
+ throw new Error(`FFmpeg execution failed: ${details}`);
268
306
  }
269
307
  }
270
308
  /**
@@ -289,7 +327,8 @@ function getFrameFilename(frame, padWidth) {
289
327
  const prefix = ('' + frame).padStart(padWidth, '0');
290
328
  return `${prefix}.${frameFileExtension}`;
291
329
  }
292
- main().catch((err) => {
330
+ main().catch(async (err) => {
331
+ await flushAnalytics();
293
332
  console.error(err);
294
333
  process.exit(1);
295
334
  });
@@ -5,6 +5,7 @@ const umami = new Umami({
5
5
  hostUrl: UMAMI_HOST_URL,
6
6
  websiteId: UMAMI_WEBSITE_ID,
7
7
  });
8
+ const activePromises = new Set();
8
9
  export function isOptedOut() {
9
10
  const dnt = process.env.DO_NOT_TRACK;
10
11
  if (dnt) {
@@ -13,7 +14,10 @@ export function isOptedOut() {
13
14
  return true;
14
15
  }
15
16
  }
16
- if (process.env.CI || process.env.NODE_ENV === 'test') {
17
+ if (process.env.CI ||
18
+ process.env.NODE_ENV === 'test' ||
19
+ process.env.VITEST ||
20
+ process.env.PLAYWRIGHT_TEST) {
17
21
  return true;
18
22
  }
19
23
  return false;
@@ -26,11 +30,14 @@ export function resolveInterfaceType(defaultType = 'cli') {
26
30
  }
27
31
  export function trackEvent(eventName, properties, interfaceType) {
28
32
  if (isOptedOut()) {
29
- return;
33
+ return Promise.resolve(false);
30
34
  }
31
- sendEvent(eventName, properties, interfaceType).catch(() => {
32
- // Silent fail-safe
35
+ const promise = sendEvent(eventName, properties, interfaceType).catch(() => false);
36
+ activePromises.add(promise);
37
+ promise.finally(() => {
38
+ activePromises.delete(promise);
33
39
  });
40
+ return promise;
34
41
  }
35
42
  export async function sendEvent(eventName, properties, interfaceType) {
36
43
  if (isOptedOut()) {
@@ -59,3 +66,20 @@ export async function sendEvent(eventName, properties, interfaceType) {
59
66
  clearTimeout(timeoutId);
60
67
  }
61
68
  }
69
+ export async function flushAnalytics(timeoutMs = 3000) {
70
+ if (activePromises.size === 0) {
71
+ return;
72
+ }
73
+ const active = Array.from(activePromises);
74
+ const flushPromise = Promise.allSettled(active);
75
+ if (timeoutMs <= 0) {
76
+ await flushPromise;
77
+ return;
78
+ }
79
+ let timeoutId;
80
+ const timeoutPromise = new Promise((resolve) => {
81
+ timeoutId = setTimeout(() => resolve(), timeoutMs);
82
+ });
83
+ await Promise.race([flushPromise.then(() => { }), timeoutPromise]);
84
+ clearTimeout(timeoutId);
85
+ }
@@ -1,3 +1,4 @@
1
+ import { flushAnalytics } from './analytics.js';
1
2
  export function isLoggerJsonOutput(obj) {
2
3
  return (typeof obj === 'object' &&
3
4
  obj !== null &&
@@ -64,9 +65,9 @@ export class Logger {
64
65
  }
65
66
  }
66
67
  /**
67
- * Output fatal error (as JSON or stderr string) and terminate execution
68
+ * Output fatal error (as JSON or stderr string), await pending analytics, and terminate execution
68
69
  */
69
- fatal(msg, details) {
70
+ async fatal(msg, details) {
70
71
  if (this.isJson) {
71
72
  const payload = {
72
73
  success: false,
@@ -80,6 +81,7 @@ export class Logger {
80
81
  if (details)
81
82
  console.error(details);
82
83
  }
84
+ await flushAnalytics();
83
85
  process.exit(1);
84
86
  }
85
87
  }
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@gehdoc/svg-to-video",
3
3
  "mcpName": "io.github.GehDoc/svg-to-video",
4
- "version": "0.27.6",
4
+ "version": "0.27.8",
5
5
  "type": "module",
6
- "description": "Professional animated SVG to Video (MP4/WebM/MKV/MOV) and Animated Image (aPNG/GIF) converter featuring frame-accurate rendering, CLI automation, and a serverless Web Studio.",
6
+ "description": "Professional animated SVG to Video (MP4/WebM/MKV/MOV) and Animated Image (aPNG/GIF) converter featuring frame-accurate rendering, CLI automation, Model Context Protocol (MCP) server integration, and a serverless Web Studio.",
7
7
  "imports": {
8
8
  "#shared/*": "./dist/shared/*"
9
9
  },
10
10
  "author": "GehDoc",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/GehDoc/svg-to-video.git"
13
+ "url": "https://github.com/GehDoc/svg-to-video"
14
14
  },
15
15
  "bugs": {
16
16
  "url": "https://github.com/GehDoc/svg-to-video/issues"