@diagrammo/dgmo 0.24.0 → 0.25.1

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.
@@ -113,11 +113,6 @@ export const ER_REGISTRY: ReservedKeyRegistry = staticRegistry([
113
113
  'domain',
114
114
  ]);
115
115
 
116
- export const CLASS_REGISTRY: ReservedKeyRegistry = staticRegistry([
117
- 'color',
118
- 'description',
119
- ]);
120
-
121
116
  export const KANBAN_REGISTRY: ReservedKeyRegistry = staticRegistry([
122
117
  'color',
123
118
  'description',
@@ -221,10 +216,3 @@ export const RACI_REGISTRY: ReservedKeyRegistry = staticRegistry([
221
216
  'color',
222
217
  'description',
223
218
  ]);
224
-
225
- /**
226
- * Wireframe uses a trailing-keyword flag list (§19.5), not key-value
227
- * metadata. This empty registry exists so callers can still pass a
228
- * registry to shared helpers without a special-case.
229
- */
230
- export const WIREFRAME_REGISTRY: ReservedKeyRegistry = staticRegistry([]);
@@ -34,8 +34,30 @@ export function normalizeSvgForEmbed(input: string): string {
34
34
  const tight = computeBBox(svg);
35
35
  if (tight && tight.width > 0 && tight.height > 0) {
36
36
  const pad = 16;
37
- const vb = `${tight.x - pad} ${tight.y - pad} ${tight.width + pad * 2} ${tight.height + pad * 2}`;
38
- svg = svg.replace(/(<svg[^>]*?)viewBox="[^"]*"/, `$1viewBox="${vb}"`);
37
+ const x = tight.x - pad;
38
+ const y = tight.y - pad;
39
+ const w = tight.width + pad * 2;
40
+ const h = tight.height + pad * 2;
41
+ // Genuine content-tightening is ALWAYS a sub-rectangle of the renderer's
42
+ // export canvas. computeBBox is a best-effort string parser: it misreads
43
+ // path arc commands (`A rx ry rot … x y`) and ignores `<g transform>`, so
44
+ // it can return a box that strays OUTSIDE the canvas (negative origin or
45
+ // over-wide). That's a parse error, not real content — applying it shifts the
46
+ // viewBox and CLIPS the diagram (the right/bottom fall off in embeds). Only
47
+ // tighten when the computed box sits within the renderer's viewBox;
48
+ // otherwise keep the already-correct canvas bounds.
49
+ const canvas = readViewBox(svg);
50
+ const TOL = 2;
51
+ const withinCanvas =
52
+ !canvas ||
53
+ (x >= canvas.x - TOL &&
54
+ y >= canvas.y - TOL &&
55
+ x + w <= canvas.x + canvas.width + TOL &&
56
+ y + h <= canvas.y + canvas.height + TOL);
57
+ if (withinCanvas) {
58
+ const vb = `${x} ${y} ${w} ${h}`;
59
+ svg = svg.replace(/(<svg[^>]*?)viewBox="[^"]*"/, `$1viewBox="${vb}"`);
60
+ }
39
61
  }
40
62
 
41
63
  svg = svg.replace(/(<svg[^>]*?) width="[^"]*"/g, '$1');
@@ -73,6 +95,18 @@ export function getEmbedSvgViewBox(
73
95
  * absolute coordinates within their viewBox, so the approximation is close
74
96
  * enough that the rendered output reliably fills the visible area.
75
97
  */
98
+ /** Read the root `<svg>` viewBox as numbers, if present and well-formed. */
99
+ function readViewBox(
100
+ svg: string
101
+ ): { x: number; y: number; width: number; height: number } | null {
102
+ const m = svg.match(/<svg[^>]*?\bviewBox="([^"]+)"/);
103
+ if (!m) return null;
104
+ const n = m[1]!.trim().split(/[\s,]+/).map(Number);
105
+ if (n.length !== 4 || n.some((v) => !Number.isFinite(v)) || n[2]! <= 0 || n[3]! <= 0)
106
+ return null;
107
+ return { x: n[0]!, y: n[1]!, width: n[2]!, height: n[3]! };
108
+ }
109
+
76
110
  function computeBBox(
77
111
  svg: string
78
112
  ): { x: number; y: number; width: number; height: number } | null {