@diagrammo/dgmo 0.1.1 → 0.1.2

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/dist/cli.cjs CHANGED
@@ -5144,9 +5144,10 @@ function inferFormat(outputPath) {
5144
5144
  }
5145
5145
  return "png";
5146
5146
  }
5147
- function svgToPng(svg) {
5147
+ function svgToPng(svg, background) {
5148
5148
  const resvg = new import_resvg_js.Resvg(svg, {
5149
- fitTo: { mode: "zoom", value: 2 }
5149
+ fitTo: { mode: "zoom", value: 2 },
5150
+ ...background ? { background } : {}
5150
5151
  });
5151
5152
  const rendered = resvg.render();
5152
5153
  return rendered.asPng();
@@ -5228,20 +5229,21 @@ async function main() {
5228
5229
  process.exit(1);
5229
5230
  }
5230
5231
  const format = inferFormat(opts.output);
5232
+ const pngBg = opts.theme === "transparent" ? void 0 : paletteColors.bg;
5231
5233
  if (opts.output) {
5232
5234
  const outputPath = (0, import_node_path.resolve)(opts.output);
5233
5235
  if (format === "svg") {
5234
5236
  (0, import_node_fs.writeFileSync)(outputPath, svg, "utf-8");
5235
5237
  } else {
5236
- (0, import_node_fs.writeFileSync)(outputPath, svgToPng(svg));
5238
+ (0, import_node_fs.writeFileSync)(outputPath, svgToPng(svg, pngBg));
5237
5239
  }
5238
5240
  console.error(`Wrote ${outputPath}`);
5239
5241
  } else if (inputBasename) {
5240
5242
  const outputPath = (0, import_node_path.resolve)(`${inputBasename}.png`);
5241
- (0, import_node_fs.writeFileSync)(outputPath, svgToPng(svg));
5243
+ (0, import_node_fs.writeFileSync)(outputPath, svgToPng(svg, pngBg));
5242
5244
  console.error(`Wrote ${outputPath}`);
5243
5245
  } else {
5244
- process.stdout.write(svgToPng(svg));
5246
+ process.stdout.write(svgToPng(svg, pngBg));
5245
5247
  }
5246
5248
  }
5247
5249
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagrammo/dgmo",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "DGMO diagram markup language — parser, renderer, and color system",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/cli.ts CHANGED
@@ -124,9 +124,10 @@ function inferFormat(outputPath: string | undefined): 'svg' | 'png' {
124
124
  return 'png';
125
125
  }
126
126
 
127
- function svgToPng(svg: string): Buffer {
127
+ function svgToPng(svg: string, background?: string): Buffer {
128
128
  const resvg = new Resvg(svg, {
129
129
  fitTo: { mode: 'zoom', value: 2 },
130
+ ...(background ? { background } : {}),
130
131
  });
131
132
  const rendered = resvg.render();
132
133
  return rendered.asPng();
@@ -227,6 +228,7 @@ async function main(): Promise<void> {
227
228
 
228
229
  // Determine output format and destination
229
230
  const format = inferFormat(opts.output);
231
+ const pngBg = opts.theme === 'transparent' ? undefined : paletteColors.bg;
230
232
 
231
233
  if (opts.output) {
232
234
  // Explicit output path
@@ -234,17 +236,17 @@ async function main(): Promise<void> {
234
236
  if (format === 'svg') {
235
237
  writeFileSync(outputPath, svg, 'utf-8');
236
238
  } else {
237
- writeFileSync(outputPath, svgToPng(svg));
239
+ writeFileSync(outputPath, svgToPng(svg, pngBg));
238
240
  }
239
241
  console.error(`Wrote ${outputPath}`);
240
242
  } else if (inputBasename) {
241
243
  // File input, no -o → write <basename>.png in cwd
242
244
  const outputPath = resolve(`${inputBasename}.png`);
243
- writeFileSync(outputPath, svgToPng(svg));
245
+ writeFileSync(outputPath, svgToPng(svg, pngBg));
244
246
  console.error(`Wrote ${outputPath}`);
245
247
  } else {
246
248
  // Stdin input, no -o → write PNG to stdout
247
- process.stdout.write(svgToPng(svg));
249
+ process.stdout.write(svgToPng(svg, pngBg));
248
250
  }
249
251
  }
250
252