@diagrammo/dgmo 0.25.3 → 0.25.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/advanced.cjs +131 -42
- package/dist/advanced.js +131 -42
- package/dist/auto.cjs +123 -37
- package/dist/auto.js +95 -95
- package/dist/auto.mjs +123 -37
- package/dist/cli.cjs +144 -144
- package/dist/index.cjs +122 -36
- package/dist/index.js +122 -36
- package/dist/internal.cjs +131 -42
- package/dist/internal.js +131 -42
- package/package.json +1 -1
- package/src/cli.ts +0 -9
- package/src/d3.ts +180 -46
- package/src/render.ts +80 -39
package/dist/auto.mjs
CHANGED
|
@@ -55755,6 +55755,59 @@ function getRotateFn(mode) {
|
|
|
55755
55755
|
if (mode === "angled") return () => Math.round(Math.random() * 30 - 15);
|
|
55756
55756
|
return () => 0;
|
|
55757
55757
|
}
|
|
55758
|
+
function hasCanvas2d() {
|
|
55759
|
+
try {
|
|
55760
|
+
if (typeof document === "undefined") return false;
|
|
55761
|
+
const canvas = document.createElement("canvas");
|
|
55762
|
+
return typeof canvas.getContext === "function" && !!canvas.getContext("2d");
|
|
55763
|
+
} catch {
|
|
55764
|
+
return false;
|
|
55765
|
+
}
|
|
55766
|
+
}
|
|
55767
|
+
function estimateWordWidth(text, size) {
|
|
55768
|
+
return text.length * size * WORDCLOUD_GLYPH_ADVANCE;
|
|
55769
|
+
}
|
|
55770
|
+
function layoutWordsNoCanvas(words, width, height, padding, rotateFn) {
|
|
55771
|
+
const sorted = [...words].sort((a, b) => b.size - a.size);
|
|
55772
|
+
const placed = [];
|
|
55773
|
+
const maxR = Math.sqrt(width * width + height * height) / 2;
|
|
55774
|
+
const aspect = width > 0 ? height / width : 1;
|
|
55775
|
+
for (const w of sorted) {
|
|
55776
|
+
const rotate = rotateFn();
|
|
55777
|
+
const rawW = estimateWordWidth(w.text, w.size) + padding * 2;
|
|
55778
|
+
const rawH = w.size + padding * 2;
|
|
55779
|
+
const rad = rotate * Math.PI / 180;
|
|
55780
|
+
const cos = Math.abs(Math.cos(rad));
|
|
55781
|
+
const sin = Math.abs(Math.sin(rad));
|
|
55782
|
+
const halfW = (rawW * cos + rawH * sin) / 2;
|
|
55783
|
+
const halfH = (rawW * sin + rawH * cos) / 2;
|
|
55784
|
+
let spot = null;
|
|
55785
|
+
for (let t = 0; t < 4e3; t++) {
|
|
55786
|
+
const a = t * 0.25;
|
|
55787
|
+
const r = a * 1.4;
|
|
55788
|
+
if (r > maxR) break;
|
|
55789
|
+
const x = Math.cos(a) * r;
|
|
55790
|
+
const y = Math.sin(a) * r * aspect;
|
|
55791
|
+
if (x - halfW < -width / 2 || x + halfW > width / 2 || y - halfH < -height / 2 || y + halfH > height / 2) {
|
|
55792
|
+
continue;
|
|
55793
|
+
}
|
|
55794
|
+
let collides = false;
|
|
55795
|
+
for (const p of placed) {
|
|
55796
|
+
if (Math.abs(x - p.x) < halfW + p.halfW && Math.abs(y - p.y) < halfH + p.halfH) {
|
|
55797
|
+
collides = true;
|
|
55798
|
+
break;
|
|
55799
|
+
}
|
|
55800
|
+
}
|
|
55801
|
+
if (!collides) {
|
|
55802
|
+
spot = { x, y };
|
|
55803
|
+
break;
|
|
55804
|
+
}
|
|
55805
|
+
}
|
|
55806
|
+
if (!spot) continue;
|
|
55807
|
+
placed.push({ ...w, rotate, x: spot.x, y: spot.y, halfW, halfH });
|
|
55808
|
+
}
|
|
55809
|
+
return placed;
|
|
55810
|
+
}
|
|
55758
55811
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
55759
55812
|
return new Promise((resolve) => {
|
|
55760
55813
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
@@ -55791,13 +55844,19 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
55791
55844
|
"transform",
|
|
55792
55845
|
`translate(${width / 2},${titleHeight + cloudHeight / 2})`
|
|
55793
55846
|
);
|
|
55794
|
-
|
|
55847
|
+
const sized = words.map((w) => ({ ...w, size: fontSize(w.weight) }));
|
|
55848
|
+
const draw = (layoutWords) => {
|
|
55795
55849
|
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(
|
|
55796
55850
|
"transform",
|
|
55797
55851
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
55798
55852
|
).text((d) => d.text);
|
|
55799
55853
|
resolve();
|
|
55800
|
-
}
|
|
55854
|
+
};
|
|
55855
|
+
if (!hasCanvas2d()) {
|
|
55856
|
+
draw(layoutWordsNoCanvas(sized, width, cloudHeight, 2, rotateFn));
|
|
55857
|
+
return;
|
|
55858
|
+
}
|
|
55859
|
+
cloud().size([width, cloudHeight]).words(sized).padding(2).rotate(rotateFn).fontSize((d) => d.size).font(FONT_FAMILY).on("end", draw).start();
|
|
55801
55860
|
});
|
|
55802
55861
|
}
|
|
55803
55862
|
function fitCirclesToContainerAsymmetric(circles, w, h, mLeft, mRight, mTop, mBottom) {
|
|
@@ -57608,7 +57667,7 @@ async function renderForExport(content, theme, palette, viewState, options) {
|
|
|
57608
57667
|
}
|
|
57609
57668
|
return finalizeSvgExport(container, theme, effectivePalette);
|
|
57610
57669
|
}
|
|
57611
|
-
var DEFAULT_CLOUD_OPTIONS, STOP_WORDS, SLOPE_MARGIN, SLOPE_LABEL_FONT_SIZE, SLOPE_CHAR_WIDTH, ARC_MARGIN_TOP, ARC_MARGIN_RIGHT, ARC_MARGIN_BOTTOM, ARC_MARGIN_LEFT, ARC_MARGIN_LEFT_VERTICAL, ARC_NODE_RADIUS, ARC_NODE_STROKE_WIDTH, ARC_NODE_LABEL_FONT, ARC_GROUP_LABEL_FONT, ARC_BAND_HALF_W, ARC_BAND_HALF_H, ARC_BAND_RADIUS, ARC_BAND_LABEL_X_OFFSET, ARC_BAND_LABEL_Y_OFFSET, ARC_BAND_LABEL_BOTTOM_OFFSET, ARC_NODE_LABEL_X_OFFSET, ARC_NODE_LABEL_Y_OFFSET, ARC_STROKE_MIN, ARC_STROKE_MAX, ARC_BASELINE_STROKE_WIDTH, timelineCollapseState, tlBandClipCounter, EXPORT_WIDTH, EXPORT_HEIGHT;
|
|
57670
|
+
var DEFAULT_CLOUD_OPTIONS, STOP_WORDS, SLOPE_MARGIN, SLOPE_LABEL_FONT_SIZE, SLOPE_CHAR_WIDTH, ARC_MARGIN_TOP, ARC_MARGIN_RIGHT, ARC_MARGIN_BOTTOM, ARC_MARGIN_LEFT, ARC_MARGIN_LEFT_VERTICAL, ARC_NODE_RADIUS, ARC_NODE_STROKE_WIDTH, ARC_NODE_LABEL_FONT, ARC_GROUP_LABEL_FONT, ARC_BAND_HALF_W, ARC_BAND_HALF_H, ARC_BAND_RADIUS, ARC_BAND_LABEL_X_OFFSET, ARC_BAND_LABEL_Y_OFFSET, ARC_BAND_LABEL_BOTTOM_OFFSET, ARC_NODE_LABEL_X_OFFSET, ARC_NODE_LABEL_Y_OFFSET, ARC_STROKE_MIN, ARC_STROKE_MAX, ARC_BASELINE_STROKE_WIDTH, timelineCollapseState, tlBandClipCounter, WORDCLOUD_GLYPH_ADVANCE, EXPORT_WIDTH, EXPORT_HEIGHT;
|
|
57612
57671
|
var init_d3 = __esm({
|
|
57613
57672
|
"src/d3.ts"() {
|
|
57614
57673
|
"use strict";
|
|
@@ -57769,6 +57828,7 @@ var init_d3 = __esm({
|
|
|
57769
57828
|
ARC_BASELINE_STROKE_WIDTH = 1;
|
|
57770
57829
|
timelineCollapseState = /* @__PURE__ */ new WeakMap();
|
|
57771
57830
|
tlBandClipCounter = 0;
|
|
57831
|
+
WORDCLOUD_GLYPH_ADVANCE = 0.62;
|
|
57772
57832
|
EXPORT_WIDTH = 1200;
|
|
57773
57833
|
EXPORT_HEIGHT = 800;
|
|
57774
57834
|
}
|
|
@@ -58236,31 +58296,52 @@ init_d3();
|
|
|
58236
58296
|
init_echarts();
|
|
58237
58297
|
init_dgmo_router();
|
|
58238
58298
|
init_registry();
|
|
58239
|
-
|
|
58240
|
-
|
|
58299
|
+
var DOM_GLOBALS = [
|
|
58300
|
+
"document",
|
|
58301
|
+
"window",
|
|
58302
|
+
"navigator",
|
|
58303
|
+
"HTMLElement",
|
|
58304
|
+
"SVGElement"
|
|
58305
|
+
];
|
|
58306
|
+
var domRefCount = 0;
|
|
58307
|
+
var domInstallPromise = null;
|
|
58308
|
+
var domInstalledByUs = false;
|
|
58309
|
+
async function installDom() {
|
|
58241
58310
|
const { JSDOM } = await loadJsdom();
|
|
58242
|
-
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>"
|
|
58243
|
-
|
|
58244
|
-
Object.defineProperty(globalThis, "document", {
|
|
58245
|
-
value: win.document,
|
|
58246
|
-
configurable: true
|
|
58247
|
-
});
|
|
58248
|
-
Object.defineProperty(globalThis, "window", {
|
|
58249
|
-
value: win,
|
|
58250
|
-
configurable: true
|
|
58251
|
-
});
|
|
58252
|
-
Object.defineProperty(globalThis, "navigator", {
|
|
58253
|
-
value: win.navigator,
|
|
58254
|
-
configurable: true
|
|
58255
|
-
});
|
|
58256
|
-
Object.defineProperty(globalThis, "HTMLElement", {
|
|
58257
|
-
value: win.HTMLElement,
|
|
58258
|
-
configurable: true
|
|
58259
|
-
});
|
|
58260
|
-
Object.defineProperty(globalThis, "SVGElement", {
|
|
58261
|
-
value: win.SVGElement,
|
|
58262
|
-
configurable: true
|
|
58311
|
+
const dom = new JSDOM("<!DOCTYPE html><html><body></body></html>", {
|
|
58312
|
+
url: "http://localhost/"
|
|
58263
58313
|
});
|
|
58314
|
+
const win = dom.window;
|
|
58315
|
+
const values = {
|
|
58316
|
+
document: win.document,
|
|
58317
|
+
window: win,
|
|
58318
|
+
navigator: win.navigator,
|
|
58319
|
+
HTMLElement: win.HTMLElement,
|
|
58320
|
+
SVGElement: win.SVGElement
|
|
58321
|
+
};
|
|
58322
|
+
for (const key of DOM_GLOBALS) {
|
|
58323
|
+
Object.defineProperty(globalThis, key, {
|
|
58324
|
+
value: values[key],
|
|
58325
|
+
configurable: true
|
|
58326
|
+
});
|
|
58327
|
+
}
|
|
58328
|
+
domInstalledByUs = true;
|
|
58329
|
+
}
|
|
58330
|
+
async function acquireDom() {
|
|
58331
|
+
if (typeof document !== "undefined" && !domInstalledByUs) return;
|
|
58332
|
+
domRefCount++;
|
|
58333
|
+
if (!domInstallPromise) domInstallPromise = installDom();
|
|
58334
|
+
await domInstallPromise;
|
|
58335
|
+
}
|
|
58336
|
+
function releaseDom() {
|
|
58337
|
+
if (!domInstalledByUs) return;
|
|
58338
|
+
if (--domRefCount > 0) return;
|
|
58339
|
+
for (const key of DOM_GLOBALS) {
|
|
58340
|
+
delete globalThis[key];
|
|
58341
|
+
}
|
|
58342
|
+
domInstalledByUs = false;
|
|
58343
|
+
domInstallPromise = null;
|
|
58344
|
+
domRefCount = 0;
|
|
58264
58345
|
}
|
|
58265
58346
|
async function loadJsdom() {
|
|
58266
58347
|
const spec = ["js", "dom"].join("");
|
|
@@ -58294,16 +58375,21 @@ async function render(content, options) {
|
|
|
58294
58375
|
);
|
|
58295
58376
|
return { svg: svg2, diagnostics };
|
|
58296
58377
|
}
|
|
58297
|
-
await
|
|
58298
|
-
|
|
58299
|
-
|
|
58300
|
-
|
|
58301
|
-
|
|
58302
|
-
|
|
58303
|
-
|
|
58304
|
-
|
|
58305
|
-
|
|
58306
|
-
|
|
58378
|
+
await acquireDom();
|
|
58379
|
+
let svg;
|
|
58380
|
+
try {
|
|
58381
|
+
svg = await renderForExport(content, theme, paletteColors, viewState, {
|
|
58382
|
+
...options?.c4Level !== void 0 && { c4Level: options.c4Level },
|
|
58383
|
+
...options?.c4System !== void 0 && { c4System: options.c4System },
|
|
58384
|
+
...options?.c4Container !== void 0 && {
|
|
58385
|
+
c4Container: options.c4Container
|
|
58386
|
+
},
|
|
58387
|
+
...options?.tagGroup !== void 0 && { tagGroup: options.tagGroup },
|
|
58388
|
+
...options?.mapData !== void 0 && { mapData: options.mapData }
|
|
58389
|
+
});
|
|
58390
|
+
} finally {
|
|
58391
|
+
releaseDom();
|
|
58392
|
+
}
|
|
58307
58393
|
if (chartType === "map") {
|
|
58308
58394
|
try {
|
|
58309
58395
|
const [{ parseMap: parseMap2 }, { resolveMap: resolveMap2 }, { loadMapData: loadMapData2 }] = await Promise.all(
|
|
@@ -59168,7 +59254,7 @@ pre.dgmo, code.language-dgmo, pre > code.language-dgmo,
|
|
|
59168
59254
|
|
|
59169
59255
|
// src/auto/index.ts
|
|
59170
59256
|
init_safe_href();
|
|
59171
|
-
var VERSION = "0.25.
|
|
59257
|
+
var VERSION = "0.25.5";
|
|
59172
59258
|
var DEFAULTS = {
|
|
59173
59259
|
theme: "auto",
|
|
59174
59260
|
palette: "nord",
|