@diagrammo/dgmo 0.1.3 → 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.cjs +40 -11
- package/dist/index.cjs +36 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +6 -0
- package/src/d3.ts +6 -4
- package/src/echarts.ts +2 -1
- package/src/fonts.ts +2 -0
- package/src/sequence/renderer.ts +23 -8
package/dist/index.js
CHANGED
|
@@ -1595,6 +1595,15 @@ var init_palettes = __esm({
|
|
|
1595
1595
|
}
|
|
1596
1596
|
});
|
|
1597
1597
|
|
|
1598
|
+
// src/fonts.ts
|
|
1599
|
+
var FONT_FAMILY;
|
|
1600
|
+
var init_fonts = __esm({
|
|
1601
|
+
"src/fonts.ts"() {
|
|
1602
|
+
"use strict";
|
|
1603
|
+
FONT_FAMILY = "Inter, system-ui, Avenir, Helvetica, Arial, sans-serif";
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1598
1607
|
// src/sequence/renderer.ts
|
|
1599
1608
|
var renderer_exports = {};
|
|
1600
1609
|
__export(renderer_exports, {
|
|
@@ -1606,6 +1615,16 @@ __export(renderer_exports, {
|
|
|
1606
1615
|
renderSequenceDiagram: () => renderSequenceDiagram
|
|
1607
1616
|
});
|
|
1608
1617
|
import * as d3Selection from "d3-selection";
|
|
1618
|
+
function mix(a, b, pct) {
|
|
1619
|
+
const parse = (h) => {
|
|
1620
|
+
const r = h.replace("#", "");
|
|
1621
|
+
const f = r.length === 3 ? r[0] + r[0] + r[1] + r[1] + r[2] + r[2] : r;
|
|
1622
|
+
return [parseInt(f.substring(0, 2), 16), parseInt(f.substring(2, 4), 16), parseInt(f.substring(4, 6), 16)];
|
|
1623
|
+
};
|
|
1624
|
+
const [ar, ag, ab] = parse(a), [br, bg, bb] = parse(b), t = pct / 100;
|
|
1625
|
+
const c = (x, y) => Math.round(x * t + y * (1 - t)).toString(16).padStart(2, "0");
|
|
1626
|
+
return `#${c(ar, br)}${c(ag, bg)}${c(ab, bb)}`;
|
|
1627
|
+
}
|
|
1609
1628
|
function renderRectParticipant(g, palette, isDark) {
|
|
1610
1629
|
g.append("rect").attr("x", -W / 2).attr("y", 0).attr("width", W).attr("height", H).attr("rx", 2).attr("ry", 2).attr("fill", fill(palette, isDark)).attr("stroke", stroke(palette)).attr("stroke-width", SW);
|
|
1611
1630
|
}
|
|
@@ -1895,7 +1914,10 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
1895
1914
|
}
|
|
1896
1915
|
}
|
|
1897
1916
|
const allRenderSteps = buildRenderSequence(messages);
|
|
1898
|
-
|
|
1917
|
+
let renderSteps = hiddenMsgIndices.size > 0 ? allRenderSteps.filter((s) => !hiddenMsgIndices.has(s.messageIndex)) : allRenderSteps;
|
|
1918
|
+
renderSteps = renderSteps.filter(
|
|
1919
|
+
(s) => s.type === "call" || s.label
|
|
1920
|
+
);
|
|
1899
1921
|
const activations = activationsOff ? [] : computeActivations(renderSteps);
|
|
1900
1922
|
const stepSpacing = 35;
|
|
1901
1923
|
const BLOCK_HEADER_SPACE = 30;
|
|
@@ -2090,10 +2112,7 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
2090
2112
|
participants.forEach((p, i) => {
|
|
2091
2113
|
participantX.set(p.id, offsetX + i * PARTICIPANT_GAP);
|
|
2092
2114
|
});
|
|
2093
|
-
const svg = d3Selection.select(container).append("svg").attr("width", "100%").attr("height", totalHeight).attr("viewBox", `0 0 ${svgWidth} ${totalHeight}`).attr("preserveAspectRatio", "xMidYMin meet").attr("class", "sequence-diagram").style(
|
|
2094
|
-
"font-family",
|
|
2095
|
-
"Inter, system-ui, Avenir, Helvetica, Arial, sans-serif"
|
|
2096
|
-
);
|
|
2115
|
+
const svg = d3Selection.select(container).append("svg").attr("width", "100%").attr("height", totalHeight).attr("viewBox", `0 0 ${svgWidth} ${totalHeight}`).attr("preserveAspectRatio", "xMidYMin meet").attr("class", "sequence-diagram").style("font-family", FONT_FAMILY);
|
|
2097
2116
|
const defs = svg.append("defs");
|
|
2098
2117
|
defs.append("marker").attr("id", "seq-arrowhead").attr("viewBox", `0 0 ${ARROWHEAD_SIZE} ${ARROWHEAD_SIZE}`).attr("refX", ARROWHEAD_SIZE).attr("refY", ARROWHEAD_SIZE / 2).attr("markerWidth", ARROWHEAD_SIZE).attr("markerHeight", ARROWHEAD_SIZE).attr("orient", "auto").append("polygon").attr(
|
|
2099
2118
|
"points",
|
|
@@ -2119,7 +2138,7 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
2119
2138
|
const boxY = participantStartY - GROUP_PADDING_TOP;
|
|
2120
2139
|
const boxH = PARTICIPANT_BOX_HEIGHT + GROUP_PADDING_TOP + GROUP_PADDING_BOTTOM;
|
|
2121
2140
|
const resolvedGroupColor = group.color ? resolveColor(group.color, palette) : void 0;
|
|
2122
|
-
const fillColor = resolvedGroupColor ?
|
|
2141
|
+
const fillColor = resolvedGroupColor ? mix(resolvedGroupColor, isDark ? palette.surface : palette.bg, 10) : isDark ? palette.surface : palette.bg;
|
|
2123
2142
|
const strokeColor = resolvedGroupColor || palette.textMuted;
|
|
2124
2143
|
svg.append("rect").attr("x", minX).attr("y", boxY).attr("width", maxX - minX).attr("height", boxH).attr("rx", 6).attr("fill", fillColor).attr("stroke", strokeColor).attr("stroke-width", 1).attr("stroke-opacity", 0.5).attr("class", "group-box").attr("data-group-line", String(group.lineNumber));
|
|
2125
2144
|
svg.append("text").attr("x", minX + 8).attr("y", boxY + GROUP_LABEL_SIZE + 4).attr("fill", strokeColor).attr("font-size", GROUP_LABEL_SIZE).attr("font-weight", "bold").attr("opacity", 0.7).attr("class", "group-label").attr("data-group-line", String(group.lineNumber)).text(group.name);
|
|
@@ -2242,7 +2261,7 @@ function renderSequenceDiagram(container, parsed, palette, isDark, _onNavigateTo
|
|
|
2242
2261
|
if (msg) coveredLines.push(msg.lineNumber);
|
|
2243
2262
|
}
|
|
2244
2263
|
svg.append("rect").attr("x", x).attr("y", y1).attr("width", ACTIVATION_WIDTH).attr("height", y2 - y1).attr("fill", isDark ? palette.surface : palette.bg);
|
|
2245
|
-
const actFill =
|
|
2264
|
+
const actFill = mix(palette.primary, isDark ? palette.surface : palette.bg, isDark ? 15 : 30);
|
|
2246
2265
|
svg.append("rect").attr("x", x).attr("y", y1).attr("width", ACTIVATION_WIDTH).attr("height", y2 - y1).attr("fill", actFill).attr("stroke", palette.primary).attr("stroke-width", 1).attr("stroke-opacity", 0.5).attr("data-participant-id", act.participantId).attr("data-msg-lines", coveredLines.join(",")).attr("class", "activation");
|
|
2247
2266
|
});
|
|
2248
2267
|
for (const ln of deferredLines) {
|
|
@@ -2414,6 +2433,7 @@ var init_renderer = __esm({
|
|
|
2414
2433
|
"src/sequence/renderer.ts"() {
|
|
2415
2434
|
"use strict";
|
|
2416
2435
|
init_colors();
|
|
2436
|
+
init_fonts();
|
|
2417
2437
|
init_parser();
|
|
2418
2438
|
PARTICIPANT_GAP = 160;
|
|
2419
2439
|
PARTICIPANT_BOX_WIDTH = 120;
|
|
@@ -2425,7 +2445,7 @@ var init_renderer = __esm({
|
|
|
2425
2445
|
MESSAGE_START_OFFSET = 30;
|
|
2426
2446
|
LIFELINE_TAIL = 30;
|
|
2427
2447
|
ARROWHEAD_SIZE = 8;
|
|
2428
|
-
fill = (palette, isDark) =>
|
|
2448
|
+
fill = (palette, isDark) => mix(palette.primary, isDark ? palette.surface : palette.bg, isDark ? 15 : 30);
|
|
2429
2449
|
stroke = (palette) => palette.textMuted;
|
|
2430
2450
|
SW = 1.5;
|
|
2431
2451
|
W = PARTICIPANT_BOX_WIDTH;
|
|
@@ -3063,6 +3083,7 @@ function buildChartJsConfig(parsed, palette, _isDark) {
|
|
|
3063
3083
|
}
|
|
3064
3084
|
|
|
3065
3085
|
// src/echarts.ts
|
|
3086
|
+
init_fonts();
|
|
3066
3087
|
init_colors();
|
|
3067
3088
|
init_palettes();
|
|
3068
3089
|
function parseEChart(content, palette) {
|
|
@@ -3297,7 +3318,7 @@ function buildEChartsOption(parsed, palette, _isDark) {
|
|
|
3297
3318
|
color: textColor,
|
|
3298
3319
|
fontSize: 18,
|
|
3299
3320
|
fontWeight: "bold",
|
|
3300
|
-
fontFamily:
|
|
3321
|
+
fontFamily: FONT_FAMILY
|
|
3301
3322
|
}
|
|
3302
3323
|
} : void 0;
|
|
3303
3324
|
const tooltipTheme = {
|
|
@@ -3940,6 +3961,7 @@ function buildFunnelOption(parsed, textColor, colors, titleConfig, tooltipTheme)
|
|
|
3940
3961
|
}
|
|
3941
3962
|
|
|
3942
3963
|
// src/d3.ts
|
|
3964
|
+
init_fonts();
|
|
3943
3965
|
init_colors();
|
|
3944
3966
|
init_palettes();
|
|
3945
3967
|
import * as d3Scale from "d3-scale";
|
|
@@ -5903,8 +5925,8 @@ function renderWordCloud(container, parsed, palette, _isDark, onClickItem) {
|
|
|
5903
5925
|
"transform",
|
|
5904
5926
|
`translate(${width / 2},${titleHeight + cloudHeight / 2})`
|
|
5905
5927
|
);
|
|
5906
|
-
cloud().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(
|
|
5907
|
-
g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family",
|
|
5928
|
+
cloud().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
|
|
5929
|
+
g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family", FONT_FAMILY).style("font-weight", "600").style("fill", (_d, i) => colors[i % colors.length]).style(
|
|
5908
5930
|
"cursor",
|
|
5909
5931
|
(d) => onClickItem && d.lineNumber ? "pointer" : "default"
|
|
5910
5932
|
).attr("text-anchor", "middle").attr(
|
|
@@ -5953,8 +5975,8 @@ function renderWordCloudAsync(container, parsed, palette, _isDark) {
|
|
|
5953
5975
|
"transform",
|
|
5954
5976
|
`translate(${width / 2},${titleHeight + cloudHeight / 2})`
|
|
5955
5977
|
);
|
|
5956
|
-
cloud().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(
|
|
5957
|
-
g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family",
|
|
5978
|
+
cloud().size([width, cloudHeight]).words(words.map((w) => ({ ...w, size: fontSize(w.weight) }))).padding(4).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", (layoutWords) => {
|
|
5979
|
+
g.selectAll("text").data(layoutWords).join("text").style("font-size", (d) => `${d.size}px`).style("font-family", FONT_FAMILY).style("font-weight", "600").style("fill", (_d, i) => colors[i % colors.length]).attr("text-anchor", "middle").attr(
|
|
5958
5980
|
"transform",
|
|
5959
5981
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
5960
5982
|
).text((d) => d.text);
|
|
@@ -6558,6 +6580,7 @@ async function renderD3ForExport(content, theme, palette) {
|
|
|
6558
6580
|
svgEl.style.background = "none";
|
|
6559
6581
|
}
|
|
6560
6582
|
svgEl.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
6583
|
+
svgEl.style.fontFamily = FONT_FAMILY;
|
|
6561
6584
|
return svgEl.outerHTML;
|
|
6562
6585
|
} finally {
|
|
6563
6586
|
document.body.removeChild(container);
|