@senad-d/drawme 0.1.10 → 0.1.11

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/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ All notable changes to this project are documented here. The format is based on
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.11] - 2026-11-09
10
+
11
+ ### Fixed
12
+
13
+ - Final PNG/JPG exports use the selected page's content width and height to lower the raster scale when needed, targeting a six-million-pixel budget to avoid draw.io `UnknownVizError` failures. Explicit width and height requests remain unchanged.
14
+
9
15
  ## [0.1.10] - 2026-10-27
10
16
 
11
17
  ### Fixed
@@ -142,7 +148,8 @@ Initial release: DrawMe as a native Pi extension for authoring, validating, and
142
148
  - Tooling: ESLint flat config, custom `format:check`, `check:golden` asset-integrity check, Vitest suite
143
149
  with real-CLI integration tests, CI, SonarCloud, and release workflows.
144
150
 
145
- [Unreleased]: https://github.com/senad-d/DrawMe/compare/v0.1.10...HEAD
151
+ [Unreleased]: https://github.com/senad-d/DrawMe/compare/v0.1.11...HEAD
152
+ [0.1.11]: https://github.com/senad-d/DrawMe/compare/v0.1.10...v0.1.11
146
153
  [0.1.10]: https://github.com/senad-d/DrawMe/compare/v0.1.9...v0.1.10
147
154
  [0.1.9]: https://github.com/senad-d/DrawMe/compare/v0.0.1...v0.1.9
148
155
  [0.0.1]: https://github.com/senad-d/DrawMe/releases/tag/v0.0.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senad-d/drawme",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Pi extension for authoring, validating, and exporting editable draw.io diagrams from natural-language descriptions.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -79,7 +79,7 @@
79
79
  "@vitest/coverage-v8": "^5.0.0",
80
80
  "eslint": "^10.8.0",
81
81
  "globals": "^17.8.0",
82
- "typebox": "1.4.3",
82
+ "typebox": "1.4.4",
83
83
  "typescript": "~6.0.3",
84
84
  "typescript-eslint": "^8.10.0",
85
85
  "vitest": "^5.0.0"
package/src/drawio.ts CHANGED
@@ -169,7 +169,8 @@ export function deriveOutput(input: string, format: ExportFormat, embed: boolean
169
169
  *
170
170
  * Export planning rules:
171
171
  * - preview → never `-e`, width-capped at 2000px (Claude vision rejects >2576px)
172
- * - final → `-e` for png/svg/pdf (jpg can't embed), raster scale 2
172
+ * - final → `-e` for png/svg/pdf (jpg can't embed), raster scale 2, lowered so the
173
+ * raster stays within MAX_FINAL_RASTER_PIXELS (larger rasters fail with UnknownVizError)
173
174
  * - animated → final SVG only; defaults the format to SVG and verifies motion after export
174
175
  * - `--width` and `-s` are never combined; an explicit width/height wins
175
176
  * - `-t` (transparent) is PNG-only; `--page-index` is 1-based
@@ -183,6 +184,7 @@ export function planExport(
183
184
  plat: string = platform(),
184
185
  isRoot = false,
185
186
  contentWidth?: number,
187
+ contentHeight?: number,
186
188
  ): ExportPlan {
187
189
  const animated = opts.animated ?? false;
188
190
  const format = opts.format ?? (animated ? "svg" : "png");
@@ -196,7 +198,7 @@ export function planExport(
196
198
  const margin = opts.border ?? DEFAULT_FIT_MARGIN;
197
199
  const args: string[] = ["-x", "-f", format];
198
200
  if (embed) args.push("-e");
199
- const border = planExportSize(opts, mode, raster, contentWidth, margin, args);
201
+ const border = planExportSize(opts, mode, raster, margin, args, contentWidth, contentHeight);
200
202
  // draw.io crops exports to the content, so the border is the image's only outer margin.
201
203
  args.push("-b", String(format === "svg" ? 0 : border));
202
204
  if (opts.transparent && format === "png") args.push("-t");
@@ -212,16 +214,27 @@ export function planExport(
212
214
  return { format, mode, embed, animated, output, args, input: opts.input, linuxExtra, svgMargin: format === "svg" ? margin : 0 };
213
215
  }
214
216
 
217
+ /** Pixel budget for a final raster; draw.io fails with UnknownVizError on much larger images. */
218
+ export const MAX_FINAL_RASTER_PIXELS = 6_000_000;
219
+
220
+ /** The requested scale, lowered so the bordered raster stays within MAX_FINAL_RASTER_PIXELS. */
221
+ export function cappedScale(scale: number, margin: number, contentWidth?: number, contentHeight?: number): number {
222
+ if (!contentWidth || !contentHeight || contentWidth <= 0 || contentHeight <= 0) return scale;
223
+ const area = (contentWidth + 2 * margin) * (contentHeight + 2 * margin);
224
+ const max = Math.floor(Math.sqrt(MAX_FINAL_RASTER_PIXELS / area) * 100) / 100;
225
+ return Math.min(scale, max);
226
+ }
227
+
215
228
  function planExportSize(
216
- opts: ExportOptions, mode: ExportMode, raster: boolean, contentWidth: number | undefined,
217
- margin: number, args: string[],
229
+ opts: ExportOptions, mode: ExportMode, raster: boolean, margin: number, args: string[],
230
+ contentWidth?: number, contentHeight?: number,
218
231
  ): number {
219
232
  if (opts.width != null) args.push("--width", String(opts.width));
220
233
  else if (opts.height != null) args.push("--height", String(opts.height));
221
234
  else if (raster) {
222
235
  if (mode === "preview") args.push("--width", "2000");
223
236
  else {
224
- const scale = opts.scale ?? 2;
237
+ const scale = cappedScale(opts.scale ?? 2, margin, contentWidth, contentHeight);
225
238
  if (contentWidth !== undefined && contentWidth > 0 && scale !== 1) {
226
239
  // With --width the border is in output pixels and applied evenly.
227
240
  const border = Math.round(margin * scale);
@@ -369,8 +382,8 @@ async function withSourceExportQueue<T>(input: string, action: () => Promise<T>)
369
382
  }
370
383
  }
371
384
 
372
- /** Width of the visible content of a page in diagram units, or undefined when it cannot be measured. */
373
- export async function pageContentWidth(input: string, pageIndex: number): Promise<number | undefined> {
385
+ /** Size of the visible content of a page in diagram units, or undefined when it cannot be measured. */
386
+ export async function pageContentSize(input: string, pageIndex: number): Promise<{ width: number; height: number } | undefined> {
374
387
  try {
375
388
  const root = new DOMParser().parseFromString(await readFile(input, "utf8"), "text/xml").documentElement as unknown as DomEl | null;
376
389
  if (!root) return undefined;
@@ -380,7 +393,7 @@ export async function pageContentWidth(input: string, pageIndex: number): Promis
380
393
  if (!model) return undefined;
381
394
  const { cells, ids } = collectCellsWithIds(firstByTag(model, "root"));
382
395
  const bounds = contentBounds(cells, ids);
383
- return bounds ? bounds.maxX - bounds.minX : undefined;
396
+ return bounds ? { width: bounds.maxX - bounds.minX, height: bounds.maxY - bounds.minY } : undefined;
384
397
  } catch {
385
398
  return undefined;
386
399
  }
@@ -454,7 +467,8 @@ async function exportDiagramQueued(opts: ExportOptions): Promise<ExportResult> {
454
467
  );
455
468
  }
456
469
 
457
- const plan = planExport(opts, platform(), isRootUser(), await pageContentWidth(opts.input, opts.pageIndex ?? 1));
470
+ const content = await pageContentSize(opts.input, opts.pageIndex ?? 1);
471
+ const plan = planExport(opts, platform(), isRootUser(), content?.width, content?.height);
458
472
  const fullArgs = [...plan.args, plan.input, ...plan.linuxExtra];
459
473
 
460
474
  const command = await invokeExport(info.binary, fullArgs);