diagram-contracts 0.1.4 → 0.1.5
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.mjs +153 -142
- package/dist/diagram-contracts.browser.mjs +153 -142
- package/dist/index.mjs +153 -142
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1153,6 +1153,149 @@ function wrapLines(text, maxWidth, measureFn) {
|
|
|
1153
1153
|
return lines;
|
|
1154
1154
|
}
|
|
1155
1155
|
|
|
1156
|
+
// src/renderer/defaults.ts
|
|
1157
|
+
var RENDER_DEFAULTS = {
|
|
1158
|
+
image: { fit: "contain" },
|
|
1159
|
+
icon: { foreground: "#666" },
|
|
1160
|
+
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
1161
|
+
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
1162
|
+
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
1163
|
+
text: {
|
|
1164
|
+
anchor: "middle",
|
|
1165
|
+
fontSize: 14,
|
|
1166
|
+
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
1167
|
+
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
1168
|
+
},
|
|
1169
|
+
box: { shape: "rect" },
|
|
1170
|
+
connectorLabel: { background: "#ffffff" },
|
|
1171
|
+
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
1172
|
+
roundedRect: { radius: 8 }
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// src/renderer/shapes.ts
|
|
1176
|
+
var STROKE_DASHARRAY = {
|
|
1177
|
+
dashed: "6 4",
|
|
1178
|
+
dotted: "2 3"
|
|
1179
|
+
};
|
|
1180
|
+
function styleAttrs(styles) {
|
|
1181
|
+
const parts = [];
|
|
1182
|
+
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
1183
|
+
else parts.push('fill="none"');
|
|
1184
|
+
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
1185
|
+
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
1186
|
+
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
1187
|
+
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
1188
|
+
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
1189
|
+
}
|
|
1190
|
+
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
1191
|
+
return parts.join(" ");
|
|
1192
|
+
}
|
|
1193
|
+
function esc(v) {
|
|
1194
|
+
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
1195
|
+
}
|
|
1196
|
+
function pts(coords) {
|
|
1197
|
+
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
1198
|
+
}
|
|
1199
|
+
function renderRect(r, sa) {
|
|
1200
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
1201
|
+
}
|
|
1202
|
+
function renderRoundedRect(r, styles, sa) {
|
|
1203
|
+
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
1204
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
1205
|
+
}
|
|
1206
|
+
function renderCircle(r, sa) {
|
|
1207
|
+
const radius = r.width / 2;
|
|
1208
|
+
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
1209
|
+
}
|
|
1210
|
+
var ASPECT_LOCKED_SHAPES = /* @__PURE__ */ new Set(["circle"]);
|
|
1211
|
+
function renderEllipse(r, sa) {
|
|
1212
|
+
const rx = r.width / 2;
|
|
1213
|
+
const ry = r.height / 2;
|
|
1214
|
+
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
1215
|
+
}
|
|
1216
|
+
function renderDiamond(r, sa) {
|
|
1217
|
+
const cx = r.x + r.width / 2;
|
|
1218
|
+
const cy = r.y + r.height / 2;
|
|
1219
|
+
const points = [
|
|
1220
|
+
[cx, r.y],
|
|
1221
|
+
[r.x + r.width, cy],
|
|
1222
|
+
[cx, r.y + r.height],
|
|
1223
|
+
[r.x, cy]
|
|
1224
|
+
];
|
|
1225
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1226
|
+
}
|
|
1227
|
+
function renderParallelogram(r, sa) {
|
|
1228
|
+
const skew = r.width * 0.2;
|
|
1229
|
+
const points = [
|
|
1230
|
+
[r.x + skew, r.y],
|
|
1231
|
+
[r.x + r.width, r.y],
|
|
1232
|
+
[r.x + r.width - skew, r.y + r.height],
|
|
1233
|
+
[r.x, r.y + r.height]
|
|
1234
|
+
];
|
|
1235
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1236
|
+
}
|
|
1237
|
+
function renderCapsule(r, sa) {
|
|
1238
|
+
const rx = Math.min(r.width, r.height) / 2;
|
|
1239
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
1240
|
+
}
|
|
1241
|
+
function renderCylinder(r, sa) {
|
|
1242
|
+
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
1243
|
+
const ry = ellipseH / 2;
|
|
1244
|
+
const x = r.x;
|
|
1245
|
+
const y = r.y;
|
|
1246
|
+
const w = r.width;
|
|
1247
|
+
const h = r.height;
|
|
1248
|
+
const rx = w / 2;
|
|
1249
|
+
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
1250
|
+
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
1251
|
+
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
1252
|
+
const leftSide = `L ${x},${y + ry}`;
|
|
1253
|
+
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
1254
|
+
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
1255
|
+
}
|
|
1256
|
+
function styles_stroke_only(sa) {
|
|
1257
|
+
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
1258
|
+
}
|
|
1259
|
+
function renderHexagon(r, sa) {
|
|
1260
|
+
const cx = r.x + r.width / 2;
|
|
1261
|
+
const cy = r.y + r.height / 2;
|
|
1262
|
+
const inset = r.width * 0.25;
|
|
1263
|
+
const points = [
|
|
1264
|
+
[r.x + inset, r.y],
|
|
1265
|
+
[r.x + r.width - inset, r.y],
|
|
1266
|
+
[r.x + r.width, cy],
|
|
1267
|
+
[r.x + r.width - inset, r.y + r.height],
|
|
1268
|
+
[r.x + inset, r.y + r.height],
|
|
1269
|
+
[r.x, cy]
|
|
1270
|
+
];
|
|
1271
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1272
|
+
}
|
|
1273
|
+
function renderTriangle(r, sa) {
|
|
1274
|
+
const points = [
|
|
1275
|
+
[r.x + r.width / 2, r.y],
|
|
1276
|
+
[r.x + r.width, r.y + r.height],
|
|
1277
|
+
[r.x, r.y + r.height]
|
|
1278
|
+
];
|
|
1279
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
1280
|
+
}
|
|
1281
|
+
var SHAPE_RENDERERS = {
|
|
1282
|
+
rect: (r, _s, sa) => renderRect(r, sa),
|
|
1283
|
+
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
1284
|
+
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
1285
|
+
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
1286
|
+
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
1287
|
+
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
1288
|
+
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
1289
|
+
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
1290
|
+
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
1291
|
+
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
1292
|
+
};
|
|
1293
|
+
function renderShape(shape, rect, styles) {
|
|
1294
|
+
const sa = styleAttrs(styles);
|
|
1295
|
+
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
1296
|
+
return renderer(rect, styles, sa);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1156
1299
|
// src/graph/rule-engine.ts
|
|
1157
1300
|
var CONSTRAINT_RULES_YAML = `
|
|
1158
1301
|
# Constraint Rules \u2014 declarative definition of constraint behavior
|
|
@@ -2398,12 +2541,19 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
2398
2541
|
}
|
|
2399
2542
|
const wrapWidthOpId = `op.box.wrapWidth.${id}`;
|
|
2400
2543
|
const wrapHeightOpId = `op.box.wrapHeight.${id}`;
|
|
2544
|
+
const shape = getStringProp(node, "shape", RENDER_DEFAULTS.box.shape);
|
|
2545
|
+
const aspectLocked = ASPECT_LOCKED_SHAPES.has(shape);
|
|
2546
|
+
const mirrorHeightToWidth = aspectLocked && heightIntent === "wrap" && typeof widthIntent === "number";
|
|
2547
|
+
const mirrorWidthToHeight = aspectLocked && widthIntent === "wrap" && typeof heightIntent === "number";
|
|
2401
2548
|
if (widthIntent === "wrap") {
|
|
2402
2549
|
const outSid = slotId(id, "resolvedWidth");
|
|
2403
2550
|
addCandidate(graph, outSid, void 0, `box(${id}).wrap`, "weak", wrapWidthOpId);
|
|
2404
2551
|
addOperation(graph, wrapWidthOpId, "resolveSize", [slotId(id, "contentWidth")], [outSid], (inputs) => {
|
|
2405
2552
|
return [num(inputs[0]) + padding * 2];
|
|
2406
2553
|
});
|
|
2554
|
+
if (mirrorWidthToHeight) {
|
|
2555
|
+
addCandidate(graph, outSid, heightIntent, `box(${id}).aspectLock`, "strong");
|
|
2556
|
+
}
|
|
2407
2557
|
}
|
|
2408
2558
|
if (heightIntent === "wrap") {
|
|
2409
2559
|
const outSid = slotId(id, "resolvedHeight");
|
|
@@ -2411,6 +2561,9 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
2411
2561
|
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
2412
2562
|
return [num(inputs[0]) + padding * 2];
|
|
2413
2563
|
});
|
|
2564
|
+
if (mirrorHeightToWidth) {
|
|
2565
|
+
addCandidate(graph, outSid, widthIntent, `box(${id}).aspectLock`, "strong");
|
|
2566
|
+
}
|
|
2414
2567
|
}
|
|
2415
2568
|
const availWidthOpId = `op.box.availW.${id}`;
|
|
2416
2569
|
ensureSlot(graph, id, "availableWidth");
|
|
@@ -4825,148 +4978,6 @@ function collectNonFiniteGeometry(artifact) {
|
|
|
4825
4978
|
return violations;
|
|
4826
4979
|
}
|
|
4827
4980
|
|
|
4828
|
-
// src/renderer/defaults.ts
|
|
4829
|
-
var RENDER_DEFAULTS = {
|
|
4830
|
-
image: { fit: "contain" },
|
|
4831
|
-
icon: { foreground: "#666" },
|
|
4832
|
-
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
4833
|
-
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
4834
|
-
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
4835
|
-
text: {
|
|
4836
|
-
anchor: "middle",
|
|
4837
|
-
fontSize: 14,
|
|
4838
|
-
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
4839
|
-
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
4840
|
-
},
|
|
4841
|
-
box: { shape: "rect" },
|
|
4842
|
-
connectorLabel: { background: "#ffffff" },
|
|
4843
|
-
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
4844
|
-
roundedRect: { radius: 8 }
|
|
4845
|
-
};
|
|
4846
|
-
|
|
4847
|
-
// src/renderer/shapes.ts
|
|
4848
|
-
var STROKE_DASHARRAY = {
|
|
4849
|
-
dashed: "6 4",
|
|
4850
|
-
dotted: "2 3"
|
|
4851
|
-
};
|
|
4852
|
-
function styleAttrs(styles) {
|
|
4853
|
-
const parts = [];
|
|
4854
|
-
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
4855
|
-
else parts.push('fill="none"');
|
|
4856
|
-
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
4857
|
-
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
4858
|
-
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
4859
|
-
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
4860
|
-
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
4861
|
-
}
|
|
4862
|
-
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
4863
|
-
return parts.join(" ");
|
|
4864
|
-
}
|
|
4865
|
-
function esc(v) {
|
|
4866
|
-
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
4867
|
-
}
|
|
4868
|
-
function pts(coords) {
|
|
4869
|
-
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
4870
|
-
}
|
|
4871
|
-
function renderRect(r, sa) {
|
|
4872
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
4873
|
-
}
|
|
4874
|
-
function renderRoundedRect(r, styles, sa) {
|
|
4875
|
-
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
4876
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4877
|
-
}
|
|
4878
|
-
function renderCircle(r, sa) {
|
|
4879
|
-
const radius = r.width / 2;
|
|
4880
|
-
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
4881
|
-
}
|
|
4882
|
-
function renderEllipse(r, sa) {
|
|
4883
|
-
const rx = r.width / 2;
|
|
4884
|
-
const ry = r.height / 2;
|
|
4885
|
-
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
4886
|
-
}
|
|
4887
|
-
function renderDiamond(r, sa) {
|
|
4888
|
-
const cx = r.x + r.width / 2;
|
|
4889
|
-
const cy = r.y + r.height / 2;
|
|
4890
|
-
const points = [
|
|
4891
|
-
[cx, r.y],
|
|
4892
|
-
[r.x + r.width, cy],
|
|
4893
|
-
[cx, r.y + r.height],
|
|
4894
|
-
[r.x, cy]
|
|
4895
|
-
];
|
|
4896
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4897
|
-
}
|
|
4898
|
-
function renderParallelogram(r, sa) {
|
|
4899
|
-
const skew = r.width * 0.2;
|
|
4900
|
-
const points = [
|
|
4901
|
-
[r.x + skew, r.y],
|
|
4902
|
-
[r.x + r.width, r.y],
|
|
4903
|
-
[r.x + r.width - skew, r.y + r.height],
|
|
4904
|
-
[r.x, r.y + r.height]
|
|
4905
|
-
];
|
|
4906
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4907
|
-
}
|
|
4908
|
-
function renderCapsule(r, sa) {
|
|
4909
|
-
const rx = Math.min(r.width, r.height) / 2;
|
|
4910
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4911
|
-
}
|
|
4912
|
-
function renderCylinder(r, sa) {
|
|
4913
|
-
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
4914
|
-
const ry = ellipseH / 2;
|
|
4915
|
-
const x = r.x;
|
|
4916
|
-
const y = r.y;
|
|
4917
|
-
const w = r.width;
|
|
4918
|
-
const h = r.height;
|
|
4919
|
-
const rx = w / 2;
|
|
4920
|
-
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
4921
|
-
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
4922
|
-
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
4923
|
-
const leftSide = `L ${x},${y + ry}`;
|
|
4924
|
-
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
4925
|
-
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
4926
|
-
}
|
|
4927
|
-
function styles_stroke_only(sa) {
|
|
4928
|
-
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
4929
|
-
}
|
|
4930
|
-
function renderHexagon(r, sa) {
|
|
4931
|
-
const cx = r.x + r.width / 2;
|
|
4932
|
-
const cy = r.y + r.height / 2;
|
|
4933
|
-
const inset = r.width * 0.25;
|
|
4934
|
-
const points = [
|
|
4935
|
-
[r.x + inset, r.y],
|
|
4936
|
-
[r.x + r.width - inset, r.y],
|
|
4937
|
-
[r.x + r.width, cy],
|
|
4938
|
-
[r.x + r.width - inset, r.y + r.height],
|
|
4939
|
-
[r.x + inset, r.y + r.height],
|
|
4940
|
-
[r.x, cy]
|
|
4941
|
-
];
|
|
4942
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4943
|
-
}
|
|
4944
|
-
function renderTriangle(r, sa) {
|
|
4945
|
-
const points = [
|
|
4946
|
-
[r.x + r.width / 2, r.y],
|
|
4947
|
-
[r.x + r.width, r.y + r.height],
|
|
4948
|
-
[r.x, r.y + r.height]
|
|
4949
|
-
];
|
|
4950
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4951
|
-
}
|
|
4952
|
-
var SHAPE_RENDERERS = {
|
|
4953
|
-
rect: (r, _s, sa) => renderRect(r, sa),
|
|
4954
|
-
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
4955
|
-
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
4956
|
-
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
4957
|
-
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
4958
|
-
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
4959
|
-
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
4960
|
-
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
4961
|
-
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
4962
|
-
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
4963
|
-
};
|
|
4964
|
-
function renderShape(shape, rect, styles) {
|
|
4965
|
-
const sa = styleAttrs(styles);
|
|
4966
|
-
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
4967
|
-
return renderer(rect, styles, sa);
|
|
4968
|
-
}
|
|
4969
|
-
|
|
4970
4981
|
// src/renderer/connectors.ts
|
|
4971
4982
|
var BASE_MARKER_SIZE = 7;
|
|
4972
4983
|
var BASE_MARKER_HALF = BASE_MARKER_SIZE / 2;
|
|
@@ -229674,6 +229674,149 @@ function wrapLines(text, maxWidth, measureFn) {
|
|
|
229674
229674
|
return lines;
|
|
229675
229675
|
}
|
|
229676
229676
|
|
|
229677
|
+
// src/renderer/defaults.ts
|
|
229678
|
+
var RENDER_DEFAULTS = {
|
|
229679
|
+
image: { fit: "contain" },
|
|
229680
|
+
icon: { foreground: "#666" },
|
|
229681
|
+
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
229682
|
+
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
229683
|
+
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
229684
|
+
text: {
|
|
229685
|
+
anchor: "middle",
|
|
229686
|
+
fontSize: 14,
|
|
229687
|
+
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
229688
|
+
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
229689
|
+
},
|
|
229690
|
+
box: { shape: "rect" },
|
|
229691
|
+
connectorLabel: { background: "#ffffff" },
|
|
229692
|
+
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
229693
|
+
roundedRect: { radius: 8 }
|
|
229694
|
+
};
|
|
229695
|
+
|
|
229696
|
+
// src/renderer/shapes.ts
|
|
229697
|
+
var STROKE_DASHARRAY = {
|
|
229698
|
+
dashed: "6 4",
|
|
229699
|
+
dotted: "2 3"
|
|
229700
|
+
};
|
|
229701
|
+
function styleAttrs(styles) {
|
|
229702
|
+
const parts = [];
|
|
229703
|
+
if (styles.fill != null) parts.push(`fill="${esc2(styles.fill)}"`);
|
|
229704
|
+
else parts.push('fill="none"');
|
|
229705
|
+
if (styles.stroke != null) parts.push(`stroke="${esc2(styles.stroke)}"`);
|
|
229706
|
+
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
229707
|
+
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
229708
|
+
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
229709
|
+
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
229710
|
+
}
|
|
229711
|
+
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
229712
|
+
return parts.join(" ");
|
|
229713
|
+
}
|
|
229714
|
+
function esc2(v) {
|
|
229715
|
+
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
229716
|
+
}
|
|
229717
|
+
function pts(coords) {
|
|
229718
|
+
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
229719
|
+
}
|
|
229720
|
+
function renderRect(r, sa) {
|
|
229721
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
229722
|
+
}
|
|
229723
|
+
function renderRoundedRect(r, styles, sa) {
|
|
229724
|
+
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
229725
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
229726
|
+
}
|
|
229727
|
+
function renderCircle(r, sa) {
|
|
229728
|
+
const radius = r.width / 2;
|
|
229729
|
+
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
229730
|
+
}
|
|
229731
|
+
var ASPECT_LOCKED_SHAPES = /* @__PURE__ */ new Set(["circle"]);
|
|
229732
|
+
function renderEllipse(r, sa) {
|
|
229733
|
+
const rx = r.width / 2;
|
|
229734
|
+
const ry = r.height / 2;
|
|
229735
|
+
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
229736
|
+
}
|
|
229737
|
+
function renderDiamond(r, sa) {
|
|
229738
|
+
const cx = r.x + r.width / 2;
|
|
229739
|
+
const cy = r.y + r.height / 2;
|
|
229740
|
+
const points = [
|
|
229741
|
+
[cx, r.y],
|
|
229742
|
+
[r.x + r.width, cy],
|
|
229743
|
+
[cx, r.y + r.height],
|
|
229744
|
+
[r.x, cy]
|
|
229745
|
+
];
|
|
229746
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
229747
|
+
}
|
|
229748
|
+
function renderParallelogram(r, sa) {
|
|
229749
|
+
const skew = r.width * 0.2;
|
|
229750
|
+
const points = [
|
|
229751
|
+
[r.x + skew, r.y],
|
|
229752
|
+
[r.x + r.width, r.y],
|
|
229753
|
+
[r.x + r.width - skew, r.y + r.height],
|
|
229754
|
+
[r.x, r.y + r.height]
|
|
229755
|
+
];
|
|
229756
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
229757
|
+
}
|
|
229758
|
+
function renderCapsule(r, sa) {
|
|
229759
|
+
const rx = Math.min(r.width, r.height) / 2;
|
|
229760
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
229761
|
+
}
|
|
229762
|
+
function renderCylinder(r, sa) {
|
|
229763
|
+
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
229764
|
+
const ry = ellipseH / 2;
|
|
229765
|
+
const x = r.x;
|
|
229766
|
+
const y = r.y;
|
|
229767
|
+
const w = r.width;
|
|
229768
|
+
const h = r.height;
|
|
229769
|
+
const rx = w / 2;
|
|
229770
|
+
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
229771
|
+
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
229772
|
+
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
229773
|
+
const leftSide = `L ${x},${y + ry}`;
|
|
229774
|
+
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
229775
|
+
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
229776
|
+
}
|
|
229777
|
+
function styles_stroke_only(sa) {
|
|
229778
|
+
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
229779
|
+
}
|
|
229780
|
+
function renderHexagon(r, sa) {
|
|
229781
|
+
const cx = r.x + r.width / 2;
|
|
229782
|
+
const cy = r.y + r.height / 2;
|
|
229783
|
+
const inset = r.width * 0.25;
|
|
229784
|
+
const points = [
|
|
229785
|
+
[r.x + inset, r.y],
|
|
229786
|
+
[r.x + r.width - inset, r.y],
|
|
229787
|
+
[r.x + r.width, cy],
|
|
229788
|
+
[r.x + r.width - inset, r.y + r.height],
|
|
229789
|
+
[r.x + inset, r.y + r.height],
|
|
229790
|
+
[r.x, cy]
|
|
229791
|
+
];
|
|
229792
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
229793
|
+
}
|
|
229794
|
+
function renderTriangle(r, sa) {
|
|
229795
|
+
const points = [
|
|
229796
|
+
[r.x + r.width / 2, r.y],
|
|
229797
|
+
[r.x + r.width, r.y + r.height],
|
|
229798
|
+
[r.x, r.y + r.height]
|
|
229799
|
+
];
|
|
229800
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
229801
|
+
}
|
|
229802
|
+
var SHAPE_RENDERERS = {
|
|
229803
|
+
rect: (r, _s, sa) => renderRect(r, sa),
|
|
229804
|
+
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
229805
|
+
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
229806
|
+
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
229807
|
+
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
229808
|
+
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
229809
|
+
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
229810
|
+
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
229811
|
+
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
229812
|
+
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
229813
|
+
};
|
|
229814
|
+
function renderShape(shape, rect, styles) {
|
|
229815
|
+
const sa = styleAttrs(styles);
|
|
229816
|
+
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
229817
|
+
return renderer(rect, styles, sa);
|
|
229818
|
+
}
|
|
229819
|
+
|
|
229677
229820
|
// src/graph/rule-engine.ts
|
|
229678
229821
|
var CONSTRAINT_RULES_YAML = `
|
|
229679
229822
|
# Constraint Rules \u2014 declarative definition of constraint behavior
|
|
@@ -230916,12 +231059,19 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
230916
231059
|
}
|
|
230917
231060
|
const wrapWidthOpId = `op.box.wrapWidth.${id}`;
|
|
230918
231061
|
const wrapHeightOpId = `op.box.wrapHeight.${id}`;
|
|
231062
|
+
const shape = getStringProp(node, "shape", RENDER_DEFAULTS.box.shape);
|
|
231063
|
+
const aspectLocked = ASPECT_LOCKED_SHAPES.has(shape);
|
|
231064
|
+
const mirrorHeightToWidth = aspectLocked && heightIntent === "wrap" && typeof widthIntent === "number";
|
|
231065
|
+
const mirrorWidthToHeight = aspectLocked && widthIntent === "wrap" && typeof heightIntent === "number";
|
|
230919
231066
|
if (widthIntent === "wrap") {
|
|
230920
231067
|
const outSid = slotId(id, "resolvedWidth");
|
|
230921
231068
|
addCandidate(graph, outSid, void 0, `box(${id}).wrap`, "weak", wrapWidthOpId);
|
|
230922
231069
|
addOperation(graph, wrapWidthOpId, "resolveSize", [slotId(id, "contentWidth")], [outSid], (inputs) => {
|
|
230923
231070
|
return [num(inputs[0]) + padding * 2];
|
|
230924
231071
|
});
|
|
231072
|
+
if (mirrorWidthToHeight) {
|
|
231073
|
+
addCandidate(graph, outSid, heightIntent, `box(${id}).aspectLock`, "strong");
|
|
231074
|
+
}
|
|
230925
231075
|
}
|
|
230926
231076
|
if (heightIntent === "wrap") {
|
|
230927
231077
|
const outSid = slotId(id, "resolvedHeight");
|
|
@@ -230929,6 +231079,9 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
230929
231079
|
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
230930
231080
|
return [num(inputs[0]) + padding * 2];
|
|
230931
231081
|
});
|
|
231082
|
+
if (mirrorHeightToWidth) {
|
|
231083
|
+
addCandidate(graph, outSid, widthIntent, `box(${id}).aspectLock`, "strong");
|
|
231084
|
+
}
|
|
230932
231085
|
}
|
|
230933
231086
|
const availWidthOpId = `op.box.availW.${id}`;
|
|
230934
231087
|
ensureSlot(graph, id, "availableWidth");
|
|
@@ -231877,148 +232030,6 @@ function collectNonFiniteGeometry(artifact) {
|
|
|
231877
232030
|
return violations;
|
|
231878
232031
|
}
|
|
231879
232032
|
|
|
231880
|
-
// src/renderer/defaults.ts
|
|
231881
|
-
var RENDER_DEFAULTS = {
|
|
231882
|
-
image: { fit: "contain" },
|
|
231883
|
-
icon: { foreground: "#666" },
|
|
231884
|
-
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
231885
|
-
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
231886
|
-
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
231887
|
-
text: {
|
|
231888
|
-
anchor: "middle",
|
|
231889
|
-
fontSize: 14,
|
|
231890
|
-
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
231891
|
-
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
231892
|
-
},
|
|
231893
|
-
box: { shape: "rect" },
|
|
231894
|
-
connectorLabel: { background: "#ffffff" },
|
|
231895
|
-
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
231896
|
-
roundedRect: { radius: 8 }
|
|
231897
|
-
};
|
|
231898
|
-
|
|
231899
|
-
// src/renderer/shapes.ts
|
|
231900
|
-
var STROKE_DASHARRAY = {
|
|
231901
|
-
dashed: "6 4",
|
|
231902
|
-
dotted: "2 3"
|
|
231903
|
-
};
|
|
231904
|
-
function styleAttrs(styles) {
|
|
231905
|
-
const parts = [];
|
|
231906
|
-
if (styles.fill != null) parts.push(`fill="${esc2(styles.fill)}"`);
|
|
231907
|
-
else parts.push('fill="none"');
|
|
231908
|
-
if (styles.stroke != null) parts.push(`stroke="${esc2(styles.stroke)}"`);
|
|
231909
|
-
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
231910
|
-
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
231911
|
-
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
231912
|
-
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
231913
|
-
}
|
|
231914
|
-
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
231915
|
-
return parts.join(" ");
|
|
231916
|
-
}
|
|
231917
|
-
function esc2(v) {
|
|
231918
|
-
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
231919
|
-
}
|
|
231920
|
-
function pts(coords) {
|
|
231921
|
-
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
231922
|
-
}
|
|
231923
|
-
function renderRect(r, sa) {
|
|
231924
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
231925
|
-
}
|
|
231926
|
-
function renderRoundedRect(r, styles, sa) {
|
|
231927
|
-
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
231928
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
231929
|
-
}
|
|
231930
|
-
function renderCircle(r, sa) {
|
|
231931
|
-
const radius = r.width / 2;
|
|
231932
|
-
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
231933
|
-
}
|
|
231934
|
-
function renderEllipse(r, sa) {
|
|
231935
|
-
const rx = r.width / 2;
|
|
231936
|
-
const ry = r.height / 2;
|
|
231937
|
-
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
231938
|
-
}
|
|
231939
|
-
function renderDiamond(r, sa) {
|
|
231940
|
-
const cx = r.x + r.width / 2;
|
|
231941
|
-
const cy = r.y + r.height / 2;
|
|
231942
|
-
const points = [
|
|
231943
|
-
[cx, r.y],
|
|
231944
|
-
[r.x + r.width, cy],
|
|
231945
|
-
[cx, r.y + r.height],
|
|
231946
|
-
[r.x, cy]
|
|
231947
|
-
];
|
|
231948
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
231949
|
-
}
|
|
231950
|
-
function renderParallelogram(r, sa) {
|
|
231951
|
-
const skew = r.width * 0.2;
|
|
231952
|
-
const points = [
|
|
231953
|
-
[r.x + skew, r.y],
|
|
231954
|
-
[r.x + r.width, r.y],
|
|
231955
|
-
[r.x + r.width - skew, r.y + r.height],
|
|
231956
|
-
[r.x, r.y + r.height]
|
|
231957
|
-
];
|
|
231958
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
231959
|
-
}
|
|
231960
|
-
function renderCapsule(r, sa) {
|
|
231961
|
-
const rx = Math.min(r.width, r.height) / 2;
|
|
231962
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
231963
|
-
}
|
|
231964
|
-
function renderCylinder(r, sa) {
|
|
231965
|
-
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
231966
|
-
const ry = ellipseH / 2;
|
|
231967
|
-
const x = r.x;
|
|
231968
|
-
const y = r.y;
|
|
231969
|
-
const w = r.width;
|
|
231970
|
-
const h = r.height;
|
|
231971
|
-
const rx = w / 2;
|
|
231972
|
-
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
231973
|
-
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
231974
|
-
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
231975
|
-
const leftSide = `L ${x},${y + ry}`;
|
|
231976
|
-
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
231977
|
-
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
231978
|
-
}
|
|
231979
|
-
function styles_stroke_only(sa) {
|
|
231980
|
-
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
231981
|
-
}
|
|
231982
|
-
function renderHexagon(r, sa) {
|
|
231983
|
-
const cx = r.x + r.width / 2;
|
|
231984
|
-
const cy = r.y + r.height / 2;
|
|
231985
|
-
const inset = r.width * 0.25;
|
|
231986
|
-
const points = [
|
|
231987
|
-
[r.x + inset, r.y],
|
|
231988
|
-
[r.x + r.width - inset, r.y],
|
|
231989
|
-
[r.x + r.width, cy],
|
|
231990
|
-
[r.x + r.width - inset, r.y + r.height],
|
|
231991
|
-
[r.x + inset, r.y + r.height],
|
|
231992
|
-
[r.x, cy]
|
|
231993
|
-
];
|
|
231994
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
231995
|
-
}
|
|
231996
|
-
function renderTriangle(r, sa) {
|
|
231997
|
-
const points = [
|
|
231998
|
-
[r.x + r.width / 2, r.y],
|
|
231999
|
-
[r.x + r.width, r.y + r.height],
|
|
232000
|
-
[r.x, r.y + r.height]
|
|
232001
|
-
];
|
|
232002
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
232003
|
-
}
|
|
232004
|
-
var SHAPE_RENDERERS = {
|
|
232005
|
-
rect: (r, _s, sa) => renderRect(r, sa),
|
|
232006
|
-
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
232007
|
-
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
232008
|
-
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
232009
|
-
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
232010
|
-
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
232011
|
-
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
232012
|
-
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
232013
|
-
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
232014
|
-
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
232015
|
-
};
|
|
232016
|
-
function renderShape(shape, rect, styles) {
|
|
232017
|
-
const sa = styleAttrs(styles);
|
|
232018
|
-
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
232019
|
-
return renderer(rect, styles, sa);
|
|
232020
|
-
}
|
|
232021
|
-
|
|
232022
232033
|
// src/renderer/connectors.ts
|
|
232023
232034
|
var BASE_MARKER_SIZE = 7;
|
|
232024
232035
|
var BASE_MARKER_HALF = BASE_MARKER_SIZE / 2;
|
package/dist/index.mjs
CHANGED
|
@@ -809,6 +809,149 @@ function wrapLines(text, maxWidth, measureFn) {
|
|
|
809
809
|
return lines;
|
|
810
810
|
}
|
|
811
811
|
|
|
812
|
+
// src/renderer/defaults.ts
|
|
813
|
+
var RENDER_DEFAULTS = {
|
|
814
|
+
image: { fit: "contain" },
|
|
815
|
+
icon: { foreground: "#666" },
|
|
816
|
+
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
817
|
+
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
818
|
+
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
819
|
+
text: {
|
|
820
|
+
anchor: "middle",
|
|
821
|
+
fontSize: 14,
|
|
822
|
+
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
823
|
+
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
824
|
+
},
|
|
825
|
+
box: { shape: "rect" },
|
|
826
|
+
connectorLabel: { background: "#ffffff" },
|
|
827
|
+
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
828
|
+
roundedRect: { radius: 8 }
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/renderer/shapes.ts
|
|
832
|
+
var STROKE_DASHARRAY = {
|
|
833
|
+
dashed: "6 4",
|
|
834
|
+
dotted: "2 3"
|
|
835
|
+
};
|
|
836
|
+
function styleAttrs(styles) {
|
|
837
|
+
const parts = [];
|
|
838
|
+
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
839
|
+
else parts.push('fill="none"');
|
|
840
|
+
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
841
|
+
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
842
|
+
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
843
|
+
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
844
|
+
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
845
|
+
}
|
|
846
|
+
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
847
|
+
return parts.join(" ");
|
|
848
|
+
}
|
|
849
|
+
function esc(v) {
|
|
850
|
+
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
851
|
+
}
|
|
852
|
+
function pts(coords) {
|
|
853
|
+
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
854
|
+
}
|
|
855
|
+
function renderRect(r, sa) {
|
|
856
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
857
|
+
}
|
|
858
|
+
function renderRoundedRect(r, styles, sa) {
|
|
859
|
+
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
860
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
861
|
+
}
|
|
862
|
+
function renderCircle(r, sa) {
|
|
863
|
+
const radius = r.width / 2;
|
|
864
|
+
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
865
|
+
}
|
|
866
|
+
var ASPECT_LOCKED_SHAPES = /* @__PURE__ */ new Set(["circle"]);
|
|
867
|
+
function renderEllipse(r, sa) {
|
|
868
|
+
const rx = r.width / 2;
|
|
869
|
+
const ry = r.height / 2;
|
|
870
|
+
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
871
|
+
}
|
|
872
|
+
function renderDiamond(r, sa) {
|
|
873
|
+
const cx = r.x + r.width / 2;
|
|
874
|
+
const cy = r.y + r.height / 2;
|
|
875
|
+
const points = [
|
|
876
|
+
[cx, r.y],
|
|
877
|
+
[r.x + r.width, cy],
|
|
878
|
+
[cx, r.y + r.height],
|
|
879
|
+
[r.x, cy]
|
|
880
|
+
];
|
|
881
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
882
|
+
}
|
|
883
|
+
function renderParallelogram(r, sa) {
|
|
884
|
+
const skew = r.width * 0.2;
|
|
885
|
+
const points = [
|
|
886
|
+
[r.x + skew, r.y],
|
|
887
|
+
[r.x + r.width, r.y],
|
|
888
|
+
[r.x + r.width - skew, r.y + r.height],
|
|
889
|
+
[r.x, r.y + r.height]
|
|
890
|
+
];
|
|
891
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
892
|
+
}
|
|
893
|
+
function renderCapsule(r, sa) {
|
|
894
|
+
const rx = Math.min(r.width, r.height) / 2;
|
|
895
|
+
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
896
|
+
}
|
|
897
|
+
function renderCylinder(r, sa) {
|
|
898
|
+
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
899
|
+
const ry = ellipseH / 2;
|
|
900
|
+
const x = r.x;
|
|
901
|
+
const y = r.y;
|
|
902
|
+
const w = r.width;
|
|
903
|
+
const h = r.height;
|
|
904
|
+
const rx = w / 2;
|
|
905
|
+
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
906
|
+
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
907
|
+
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
908
|
+
const leftSide = `L ${x},${y + ry}`;
|
|
909
|
+
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
910
|
+
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
911
|
+
}
|
|
912
|
+
function styles_stroke_only(sa) {
|
|
913
|
+
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
914
|
+
}
|
|
915
|
+
function renderHexagon(r, sa) {
|
|
916
|
+
const cx = r.x + r.width / 2;
|
|
917
|
+
const cy = r.y + r.height / 2;
|
|
918
|
+
const inset = r.width * 0.25;
|
|
919
|
+
const points = [
|
|
920
|
+
[r.x + inset, r.y],
|
|
921
|
+
[r.x + r.width - inset, r.y],
|
|
922
|
+
[r.x + r.width, cy],
|
|
923
|
+
[r.x + r.width - inset, r.y + r.height],
|
|
924
|
+
[r.x + inset, r.y + r.height],
|
|
925
|
+
[r.x, cy]
|
|
926
|
+
];
|
|
927
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
928
|
+
}
|
|
929
|
+
function renderTriangle(r, sa) {
|
|
930
|
+
const points = [
|
|
931
|
+
[r.x + r.width / 2, r.y],
|
|
932
|
+
[r.x + r.width, r.y + r.height],
|
|
933
|
+
[r.x, r.y + r.height]
|
|
934
|
+
];
|
|
935
|
+
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
936
|
+
}
|
|
937
|
+
var SHAPE_RENDERERS = {
|
|
938
|
+
rect: (r, _s, sa) => renderRect(r, sa),
|
|
939
|
+
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
940
|
+
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
941
|
+
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
942
|
+
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
943
|
+
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
944
|
+
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
945
|
+
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
946
|
+
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
947
|
+
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
948
|
+
};
|
|
949
|
+
function renderShape(shape, rect, styles) {
|
|
950
|
+
const sa = styleAttrs(styles);
|
|
951
|
+
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
952
|
+
return renderer(rect, styles, sa);
|
|
953
|
+
}
|
|
954
|
+
|
|
812
955
|
// src/graph/rule-engine.ts
|
|
813
956
|
var CONSTRAINT_RULES_YAML = `
|
|
814
957
|
# Constraint Rules \u2014 declarative definition of constraint behavior
|
|
@@ -2051,12 +2194,19 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
2051
2194
|
}
|
|
2052
2195
|
const wrapWidthOpId = `op.box.wrapWidth.${id}`;
|
|
2053
2196
|
const wrapHeightOpId = `op.box.wrapHeight.${id}`;
|
|
2197
|
+
const shape = getStringProp(node, "shape", RENDER_DEFAULTS.box.shape);
|
|
2198
|
+
const aspectLocked = ASPECT_LOCKED_SHAPES.has(shape);
|
|
2199
|
+
const mirrorHeightToWidth = aspectLocked && heightIntent === "wrap" && typeof widthIntent === "number";
|
|
2200
|
+
const mirrorWidthToHeight = aspectLocked && widthIntent === "wrap" && typeof heightIntent === "number";
|
|
2054
2201
|
if (widthIntent === "wrap") {
|
|
2055
2202
|
const outSid = slotId(id, "resolvedWidth");
|
|
2056
2203
|
addCandidate(graph, outSid, void 0, `box(${id}).wrap`, "weak", wrapWidthOpId);
|
|
2057
2204
|
addOperation(graph, wrapWidthOpId, "resolveSize", [slotId(id, "contentWidth")], [outSid], (inputs) => {
|
|
2058
2205
|
return [num(inputs[0]) + padding * 2];
|
|
2059
2206
|
});
|
|
2207
|
+
if (mirrorWidthToHeight) {
|
|
2208
|
+
addCandidate(graph, outSid, heightIntent, `box(${id}).aspectLock`, "strong");
|
|
2209
|
+
}
|
|
2060
2210
|
}
|
|
2061
2211
|
if (heightIntent === "wrap") {
|
|
2062
2212
|
const outSid = slotId(id, "resolvedHeight");
|
|
@@ -2064,6 +2214,9 @@ function applyContainerRule(rule, node, graph, parentId) {
|
|
|
2064
2214
|
addOperation(graph, wrapHeightOpId, "resolveSize", [slotId(id, "contentHeight")], [outSid], (inputs) => {
|
|
2065
2215
|
return [num(inputs[0]) + padding * 2];
|
|
2066
2216
|
});
|
|
2217
|
+
if (mirrorHeightToWidth) {
|
|
2218
|
+
addCandidate(graph, outSid, widthIntent, `box(${id}).aspectLock`, "strong");
|
|
2219
|
+
}
|
|
2067
2220
|
}
|
|
2068
2221
|
const availWidthOpId = `op.box.availW.${id}`;
|
|
2069
2222
|
ensureSlot(graph, id, "availableWidth");
|
|
@@ -4478,148 +4631,6 @@ function collectNonFiniteGeometry(artifact) {
|
|
|
4478
4631
|
return violations;
|
|
4479
4632
|
}
|
|
4480
4633
|
|
|
4481
|
-
// src/renderer/defaults.ts
|
|
4482
|
-
var RENDER_DEFAULTS = {
|
|
4483
|
-
image: { fit: "contain" },
|
|
4484
|
-
icon: { foreground: "#666" },
|
|
4485
|
-
table: { borderRadius: 6, stroke: "#d1d5db", strokeWidth: 1, background: "white" },
|
|
4486
|
-
divider: { stroke: "#ccc", strokeWidth: 1 },
|
|
4487
|
-
cell: { fill: "none", stroke: "#e5e7eb", strokeWidth: 0.5 },
|
|
4488
|
-
text: {
|
|
4489
|
-
anchor: "middle",
|
|
4490
|
-
fontSize: 14,
|
|
4491
|
-
lineHeightFactor: SIMPLE_FONT_METRICS.LINE_HEIGHT,
|
|
4492
|
-
capHeightFactor: SIMPLE_FONT_METRICS.CAP_HEIGHT
|
|
4493
|
-
},
|
|
4494
|
-
box: { shape: "rect" },
|
|
4495
|
-
connectorLabel: { background: "#ffffff" },
|
|
4496
|
-
connector: { stroke: "#6b7280", strokeWidth: 1.5, arrowSize: 1, startArrow: "none", endArrow: "arrow" },
|
|
4497
|
-
roundedRect: { radius: 8 }
|
|
4498
|
-
};
|
|
4499
|
-
|
|
4500
|
-
// src/renderer/shapes.ts
|
|
4501
|
-
var STROKE_DASHARRAY = {
|
|
4502
|
-
dashed: "6 4",
|
|
4503
|
-
dotted: "2 3"
|
|
4504
|
-
};
|
|
4505
|
-
function styleAttrs(styles) {
|
|
4506
|
-
const parts = [];
|
|
4507
|
-
if (styles.fill != null) parts.push(`fill="${esc(styles.fill)}"`);
|
|
4508
|
-
else parts.push('fill="none"');
|
|
4509
|
-
if (styles.stroke != null) parts.push(`stroke="${esc(styles.stroke)}"`);
|
|
4510
|
-
if (styles.strokeWidth != null) parts.push(`stroke-width="${styles.strokeWidth}"`);
|
|
4511
|
-
if (styles.strokeStyle != null && styles.strokeStyle !== "solid") {
|
|
4512
|
-
const da = STROKE_DASHARRAY[String(styles.strokeStyle)];
|
|
4513
|
-
if (da) parts.push(`stroke-dasharray="${da}"`);
|
|
4514
|
-
}
|
|
4515
|
-
if (styles.opacity != null) parts.push(`opacity="${styles.opacity}"`);
|
|
4516
|
-
return parts.join(" ");
|
|
4517
|
-
}
|
|
4518
|
-
function esc(v) {
|
|
4519
|
-
return String(v).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
4520
|
-
}
|
|
4521
|
-
function pts(coords) {
|
|
4522
|
-
return coords.map(([px, py]) => `${px},${py}`).join(" ");
|
|
4523
|
-
}
|
|
4524
|
-
function renderRect(r, sa) {
|
|
4525
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" ${sa}/>`;
|
|
4526
|
-
}
|
|
4527
|
-
function renderRoundedRect(r, styles, sa) {
|
|
4528
|
-
const rx = styles.radius != null ? Number(styles.radius) : RENDER_DEFAULTS.roundedRect.radius;
|
|
4529
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4530
|
-
}
|
|
4531
|
-
function renderCircle(r, sa) {
|
|
4532
|
-
const radius = r.width / 2;
|
|
4533
|
-
return `<circle cx="${r.x + radius}" cy="${r.y + radius}" r="${radius}" ${sa}/>`;
|
|
4534
|
-
}
|
|
4535
|
-
function renderEllipse(r, sa) {
|
|
4536
|
-
const rx = r.width / 2;
|
|
4537
|
-
const ry = r.height / 2;
|
|
4538
|
-
return `<ellipse cx="${r.x + rx}" cy="${r.y + ry}" rx="${rx}" ry="${ry}" ${sa}/>`;
|
|
4539
|
-
}
|
|
4540
|
-
function renderDiamond(r, sa) {
|
|
4541
|
-
const cx = r.x + r.width / 2;
|
|
4542
|
-
const cy = r.y + r.height / 2;
|
|
4543
|
-
const points = [
|
|
4544
|
-
[cx, r.y],
|
|
4545
|
-
[r.x + r.width, cy],
|
|
4546
|
-
[cx, r.y + r.height],
|
|
4547
|
-
[r.x, cy]
|
|
4548
|
-
];
|
|
4549
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4550
|
-
}
|
|
4551
|
-
function renderParallelogram(r, sa) {
|
|
4552
|
-
const skew = r.width * 0.2;
|
|
4553
|
-
const points = [
|
|
4554
|
-
[r.x + skew, r.y],
|
|
4555
|
-
[r.x + r.width, r.y],
|
|
4556
|
-
[r.x + r.width - skew, r.y + r.height],
|
|
4557
|
-
[r.x, r.y + r.height]
|
|
4558
|
-
];
|
|
4559
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4560
|
-
}
|
|
4561
|
-
function renderCapsule(r, sa) {
|
|
4562
|
-
const rx = Math.min(r.width, r.height) / 2;
|
|
4563
|
-
return `<rect x="${r.x}" y="${r.y}" width="${r.width}" height="${r.height}" rx="${rx}" ${sa}/>`;
|
|
4564
|
-
}
|
|
4565
|
-
function renderCylinder(r, sa) {
|
|
4566
|
-
const ellipseH = Math.min(r.height * 0.2, 20);
|
|
4567
|
-
const ry = ellipseH / 2;
|
|
4568
|
-
const x = r.x;
|
|
4569
|
-
const y = r.y;
|
|
4570
|
-
const w = r.width;
|
|
4571
|
-
const h = r.height;
|
|
4572
|
-
const rx = w / 2;
|
|
4573
|
-
const topArc = `M ${x},${y + ry} A ${rx},${ry} 0 0,1 ${x + w},${y + ry}`;
|
|
4574
|
-
const rightSide = `L ${x + w},${y + h - ry}`;
|
|
4575
|
-
const bottomArc = `A ${rx},${ry} 0 0,1 ${x},${y + h - ry}`;
|
|
4576
|
-
const leftSide = `L ${x},${y + ry}`;
|
|
4577
|
-
const topEllipseBack = `M ${x},${y + ry} A ${rx},${ry} 0 0,0 ${x + w},${y + ry}`;
|
|
4578
|
-
return `<path d="${topArc} ${rightSide} ${bottomArc} ${leftSide}" ${sa}/><path d="${topEllipseBack}" ${styles_stroke_only(sa)}/>`;
|
|
4579
|
-
}
|
|
4580
|
-
function styles_stroke_only(sa) {
|
|
4581
|
-
return sa.replace(/fill="[^"]*"/, 'fill="none"');
|
|
4582
|
-
}
|
|
4583
|
-
function renderHexagon(r, sa) {
|
|
4584
|
-
const cx = r.x + r.width / 2;
|
|
4585
|
-
const cy = r.y + r.height / 2;
|
|
4586
|
-
const inset = r.width * 0.25;
|
|
4587
|
-
const points = [
|
|
4588
|
-
[r.x + inset, r.y],
|
|
4589
|
-
[r.x + r.width - inset, r.y],
|
|
4590
|
-
[r.x + r.width, cy],
|
|
4591
|
-
[r.x + r.width - inset, r.y + r.height],
|
|
4592
|
-
[r.x + inset, r.y + r.height],
|
|
4593
|
-
[r.x, cy]
|
|
4594
|
-
];
|
|
4595
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4596
|
-
}
|
|
4597
|
-
function renderTriangle(r, sa) {
|
|
4598
|
-
const points = [
|
|
4599
|
-
[r.x + r.width / 2, r.y],
|
|
4600
|
-
[r.x + r.width, r.y + r.height],
|
|
4601
|
-
[r.x, r.y + r.height]
|
|
4602
|
-
];
|
|
4603
|
-
return `<polygon points="${pts(points)}" ${sa}/>`;
|
|
4604
|
-
}
|
|
4605
|
-
var SHAPE_RENDERERS = {
|
|
4606
|
-
rect: (r, _s, sa) => renderRect(r, sa),
|
|
4607
|
-
roundedRect: (r, s, sa) => renderRoundedRect(r, s, sa),
|
|
4608
|
-
circle: (r, _s, sa) => renderCircle(r, sa),
|
|
4609
|
-
ellipse: (r, _s, sa) => renderEllipse(r, sa),
|
|
4610
|
-
diamond: (r, _s, sa) => renderDiamond(r, sa),
|
|
4611
|
-
parallelogram: (r, _s, sa) => renderParallelogram(r, sa),
|
|
4612
|
-
capsule: (r, _s, sa) => renderCapsule(r, sa),
|
|
4613
|
-
cylinder: (r, _s, sa) => renderCylinder(r, sa),
|
|
4614
|
-
hexagon: (r, _s, sa) => renderHexagon(r, sa),
|
|
4615
|
-
triangle: (r, _s, sa) => renderTriangle(r, sa)
|
|
4616
|
-
};
|
|
4617
|
-
function renderShape(shape, rect, styles) {
|
|
4618
|
-
const sa = styleAttrs(styles);
|
|
4619
|
-
const renderer = SHAPE_RENDERERS[shape] ?? SHAPE_RENDERERS.rect;
|
|
4620
|
-
return renderer(rect, styles, sa);
|
|
4621
|
-
}
|
|
4622
|
-
|
|
4623
4634
|
// src/renderer/connectors.ts
|
|
4624
4635
|
var BASE_MARKER_SIZE = 7;
|
|
4625
4636
|
var BASE_MARKER_HALF = BASE_MARKER_SIZE / 2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "diagram-contracts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Rule Catalog driven layout runtime — compile diagrams to deterministic SVG from Draw TSX, Draw Text, or Layout IR",
|
|
6
6
|
"keywords": [
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"commander": "^15.0.0",
|
|
73
73
|
"js-yaml": "^5.0.0",
|
|
74
74
|
"opentype.js": "^2.0.0",
|
|
75
|
+
"typescript": "^6.0.3",
|
|
75
76
|
"zod": "^4.4.3"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
@@ -83,7 +84,6 @@
|
|
|
83
84
|
"esbuild": "^0.28.1",
|
|
84
85
|
"jsdom": "^29.1.1",
|
|
85
86
|
"tsup": "^8.5.1",
|
|
86
|
-
"typescript": "^6.0.3",
|
|
87
87
|
"vitest": "^4.1.9"
|
|
88
88
|
}
|
|
89
89
|
}
|