@diagrammo/dgmo 0.20.0 → 0.20.2

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/auto.mjs CHANGED
@@ -45851,7 +45851,7 @@ function resolveMap(parsed, data) {
45851
45851
  const lonSpan = extent2[1][0] - extent2[0][0];
45852
45852
  const latSpan = extent2[1][1] - extent2[0][1];
45853
45853
  const span = Math.max(lonSpan, latSpan);
45854
- const usDominant = (inferredCountry === "US" || subdivisions.includes("us-states")) && !regions.some((r) => r.layer === "country" && r.iso !== "US") && !anyNonUsPoi;
45854
+ const usDominant = (subdivisions.includes("us-states") || regions.some((r) => r.layer === "us-state")) && !regions.some((r) => r.layer === "country" && r.iso !== "US") && !anyNonUsPoi;
45855
45855
  let projection;
45856
45856
  const override = parsed.directives.projection;
45857
45857
  if (override === "equirectangular" || override === "natural-earth" || override === "albers-usa" || override === "mercator") {
@@ -45957,17 +45957,22 @@ var load_data_exports = {};
45957
45957
  __export(load_data_exports, {
45958
45958
  loadMapData: () => loadMapData
45959
45959
  });
45960
- import { readFile } from "fs/promises";
45961
- import { fileURLToPath } from "url";
45962
- import { dirname, resolve } from "path";
45963
- async function readJson(dir, name) {
45964
- return JSON.parse(await readFile(resolve(dir, name), "utf8"));
45960
+ async function loadNodeBuiltins() {
45961
+ const [{ readFile }, { fileURLToPath }, { dirname, resolve }] = await Promise.all([
45962
+ import("fs/promises"),
45963
+ import("url"),
45964
+ import("path")
45965
+ ]);
45966
+ return { readFile, fileURLToPath, dirname, resolve };
45967
+ }
45968
+ async function readJson(nb, dir, name) {
45969
+ return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
45965
45970
  }
45966
- async function firstExistingDir(baseDir) {
45971
+ async function firstExistingDir(nb, baseDir) {
45967
45972
  for (const rel of CANDIDATE_DIRS) {
45968
- const dir = resolve(baseDir, rel);
45973
+ const dir = nb.resolve(baseDir, rel);
45969
45974
  try {
45970
- await readFile(resolve(dir, FILES.gazetteer), "utf8");
45975
+ await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
45971
45976
  return dir;
45972
45977
  } catch {
45973
45978
  }
@@ -45983,10 +45988,10 @@ function validate(data) {
45983
45988
  }
45984
45989
  return data;
45985
45990
  }
45986
- function moduleBaseDir() {
45991
+ function moduleBaseDir(nb) {
45987
45992
  try {
45988
45993
  const url = import.meta.url;
45989
- if (url) return dirname(fileURLToPath(url));
45994
+ if (url) return nb.dirname(nb.fileURLToPath(url));
45990
45995
  } catch {
45991
45996
  }
45992
45997
  if (typeof __dirname !== "undefined") return __dirname;
@@ -45994,7 +45999,8 @@ function moduleBaseDir() {
45994
45999
  }
45995
46000
  function loadMapData() {
45996
46001
  cache ??= (async () => {
45997
- const dir = await firstExistingDir(moduleBaseDir());
46002
+ const nb = await loadNodeBuiltins();
46003
+ const dir = await firstExistingDir(nb, moduleBaseDir(nb));
45998
46004
  const [
45999
46005
  worldCoarse,
46000
46006
  worldDetail,
@@ -46005,15 +46011,15 @@ function loadMapData() {
46005
46011
  naLakes,
46006
46012
  gazetteer
46007
46013
  ] = await Promise.all([
46008
- readJson(dir, FILES.worldCoarse),
46009
- readJson(dir, FILES.worldDetail),
46010
- readJson(dir, FILES.usStates),
46014
+ readJson(nb, dir, FILES.worldCoarse),
46015
+ readJson(nb, dir, FILES.worldDetail),
46016
+ readJson(nb, dir, FILES.usStates),
46011
46017
  // Lakes/rivers/NA assets are optional — older bundles may predate them.
46012
- readJson(dir, FILES.lakes).catch(() => void 0),
46013
- readJson(dir, FILES.rivers).catch(() => void 0),
46014
- readJson(dir, FILES.naLand).catch(() => void 0),
46015
- readJson(dir, FILES.naLakes).catch(() => void 0),
46016
- readJson(dir, FILES.gazetteer)
46018
+ readJson(nb, dir, FILES.lakes).catch(() => void 0),
46019
+ readJson(nb, dir, FILES.rivers).catch(() => void 0),
46020
+ readJson(nb, dir, FILES.naLand).catch(() => void 0),
46021
+ readJson(nb, dir, FILES.naLakes).catch(() => void 0),
46022
+ readJson(nb, dir, FILES.gazetteer)
46017
46023
  ]);
46018
46024
  return validate({
46019
46025
  worldCoarse,
@@ -46098,8 +46104,19 @@ function layoutMap(resolved, data, size, opts) {
46098
46104
  const { width, height } = size;
46099
46105
  const wantsUsStates = resolved.basemaps.subdivisions.includes("us-states");
46100
46106
  const usCrisp = resolved.projection === "albers-usa" && wantsUsStates && !!data.naLand;
46101
- const worldTopo = usCrisp ? data.naLand : resolved.basemaps.world === "detail" ? data.worldDetail : data.worldCoarse;
46107
+ const worldTopo = usCrisp ? data.worldDetail : resolved.basemaps.world === "detail" ? data.worldDetail : data.worldCoarse;
46102
46108
  const worldLayer = decodeLayer(worldTopo);
46109
+ if (usCrisp && data.naLand) {
46110
+ const [nbW, nbS, nbE, nbN] = [-140, 10, -52, 66];
46111
+ const crisp = decodeLayer(data.naLand);
46112
+ for (const [iso, cf] of crisp) {
46113
+ const base = worldLayer.get(iso);
46114
+ if (!base) continue;
46115
+ const [[bw, bs], [be, bn]] = geoBounds2(base);
46116
+ if (bw >= nbW && be <= nbE && bs >= nbS && bn <= nbN)
46117
+ worldLayer.set(iso, cf);
46118
+ }
46119
+ }
46103
46120
  const usLayer = wantsUsStates ? decodeLayer(data.usStates) : null;
46104
46121
  const landTint = isDark ? LAND_TINT_DARK : LAND_TINT_LIGHT;
46105
46122
  const neutralFill = mix(palette.colors.green, palette.bg, landTint);
@@ -46245,6 +46262,10 @@ function layoutMap(resolved, data, size, opts) {
46245
46262
  return p ? stretch(p[0], p[1]) : null;
46246
46263
  };
46247
46264
  } else {
46265
+ projection.clipExtent([
46266
+ [0, 0],
46267
+ [width, height]
46268
+ ]);
46248
46269
  path = geoPath(projection);
46249
46270
  project = (lon, lat) => projection([lon, lat]) ?? null;
46250
46271
  }
@@ -46389,18 +46410,11 @@ function layoutMap(resolved, data, size, opts) {
46389
46410
  placeInset("US-HI", hawaiiProjection(), akRight + 24, width * 0.1);
46390
46411
  }
46391
46412
  const conusFit = resolved.projection === "albers-usa" && !!usLayer;
46392
- const cullExtent = conusFit ? geoBounds2(fitTarget) : resolved.extent;
46393
- const [[exW, exS], [exE, exN]] = cullExtent;
46394
- const lonSpan = exE - exW;
46395
- const latSpan = exN - exS;
46396
- const isGlobalView = lonSpan >= 270 || latSpan >= 130;
46397
- const padLon = Math.max(8, lonSpan * 0.35);
46398
- const padLat = Math.max(8, latSpan * 0.35);
46399
- const vW = exW - padLon;
46400
- const vE = exE + padLon;
46401
- const vS = exS - padLat;
46402
- const vN = exN + padLat;
46403
- const vLonCenter = (exW + exE) / 2;
46413
+ const classifyExtent = conusFit ? geoBounds2(fitTarget) : resolved.extent;
46414
+ const dLonSpan = classifyExtent[1][0] - classifyExtent[0][0];
46415
+ const dLatSpan = classifyExtent[1][1] - classifyExtent[0][1];
46416
+ const isGlobalView = dLonSpan >= 270 || dLatSpan >= 130;
46417
+ const vLonCenter = (classifyExtent[0][0] + classifyExtent[1][0]) / 2;
46404
46418
  const normLon = (lon) => {
46405
46419
  let L = lon;
46406
46420
  while (L < vLonCenter - 180) L += 360;
@@ -46408,23 +46422,28 @@ function layoutMap(resolved, data, size, opts) {
46408
46422
  return L;
46409
46423
  };
46410
46424
  const ringOverlapsView = (ring) => {
46411
- let anyIn = false;
46412
- let loMin = Infinity, loMax = -Infinity, laMin = Infinity, laMax = -Infinity, rawMin = Infinity, rawMax = -Infinity;
46413
- for (const [rawLon, lat] of ring) {
46425
+ let loMin = Infinity, loMax = -Infinity, rawMin = Infinity, rawMax = -Infinity;
46426
+ for (const [rawLon] of ring) {
46414
46427
  const lon = normLon(rawLon);
46415
- if (lon >= vW && lon <= vE && lat >= vS && lat <= vN) anyIn = true;
46416
46428
  if (lon < loMin) loMin = lon;
46417
46429
  if (lon > loMax) loMax = lon;
46418
46430
  if (rawLon < rawMin) rawMin = rawLon;
46419
46431
  if (rawLon > rawMax) rawMax = rawLon;
46420
- if (lat < laMin) laMin = lat;
46421
- if (lat > laMax) laMax = lat;
46422
46432
  }
46423
46433
  if (loMax - loMin > 270) return false;
46424
46434
  if (rawMax - rawMin > 180 && loMax - loMin < 90) return false;
46425
- if (anyIn) return true;
46426
- if (loMax - loMin > 180) return false;
46427
- return !(loMax < vW || loMin > vE || laMax < vS || laMin > vN);
46435
+ let px0 = Infinity, py0 = Infinity, px1 = -Infinity, py1 = -Infinity, anyFinite = false;
46436
+ for (const [lon, lat] of ring) {
46437
+ const p = project(lon, lat);
46438
+ if (!p || !Number.isFinite(p[0]) || !Number.isFinite(p[1])) continue;
46439
+ anyFinite = true;
46440
+ if (p[0] < px0) px0 = p[0];
46441
+ if (p[0] > px1) px1 = p[0];
46442
+ if (p[1] < py0) py0 = p[1];
46443
+ if (p[1] > py1) py1 = p[1];
46444
+ }
46445
+ if (!anyFinite) return false;
46446
+ return !(px1 < 0 || px0 > width || py1 < 0 || py0 > height);
46428
46447
  };
46429
46448
  const cullFeatureToView = (f) => {
46430
46449
  if (isGlobalView) return f;
@@ -46815,19 +46834,39 @@ function layoutMap(resolved, data, size, opts) {
46815
46834
  const text = labelText(p);
46816
46835
  return { text, w: measureLegendText(text, FONT) };
46817
46836
  };
46837
+ const GAP = 3;
46838
+ const inlineRect = (p, w, side) => {
46839
+ switch (side) {
46840
+ case "right":
46841
+ return { x: p.cx + p.r + GAP, y: p.cy - poiLabH / 2, w, h: poiLabH };
46842
+ case "left":
46843
+ return {
46844
+ x: p.cx - p.r - GAP - w,
46845
+ y: p.cy - poiLabH / 2,
46846
+ w,
46847
+ h: poiLabH
46848
+ };
46849
+ case "above":
46850
+ return {
46851
+ x: p.cx - w / 2,
46852
+ y: p.cy - p.r - GAP - poiLabH,
46853
+ w,
46854
+ h: poiLabH
46855
+ };
46856
+ case "below":
46857
+ return { x: p.cx - w / 2, y: p.cy + p.r + GAP, w, h: poiLabH };
46858
+ }
46859
+ };
46818
46860
  const pushInline = (p, text, w, side) => {
46819
- const tx = side === "right" ? p.cx + p.r + 3 : p.cx - p.r - 3;
46820
- obstacles.push({
46821
- x: side === "right" ? tx : tx - w,
46822
- y: p.cy - poiLabH / 2,
46823
- w,
46824
- h: poiLabH
46825
- });
46861
+ const rect = inlineRect(p, w, side);
46862
+ obstacles.push(rect);
46863
+ const anchor = side === "right" ? "start" : side === "left" ? "end" : "middle";
46864
+ const x = side === "right" ? rect.x : side === "left" ? rect.x + w : p.cx;
46826
46865
  labels.push({
46827
- x: tx,
46828
- y: p.cy + FONT / 3,
46866
+ x,
46867
+ y: rect.y + poiLabH / 2 + FONT / 3,
46829
46868
  text,
46830
- anchor: side === "right" ? "start" : "end",
46869
+ anchor,
46831
46870
  color: palette.text,
46832
46871
  halo: true,
46833
46872
  haloColor: palette.bg,
@@ -46836,14 +46875,8 @@ function layoutMap(resolved, data, size, opts) {
46836
46875
  });
46837
46876
  };
46838
46877
  const inlineFits = (p, w, side) => {
46839
- const tx = side === "right" ? p.cx + p.r + 3 : p.cx - p.r - 3;
46840
- const rect = {
46841
- x: side === "right" ? tx : tx - w,
46842
- y: p.cy - poiLabH / 2,
46843
- w,
46844
- h: poiLabH
46845
- };
46846
- return rect.x >= 0 && rect.x + rect.w <= width && !collides(rect);
46878
+ const rect = inlineRect(p, w, side);
46879
+ return rect.x >= 0 && rect.x + rect.w <= width && rect.y >= 0 && rect.y + rect.h <= height && !collides(rect);
46847
46880
  };
46848
46881
  const GROUP_R = 30;
46849
46882
  const groups = [];
@@ -46900,12 +46933,11 @@ function layoutMap(resolved, data, size, opts) {
46900
46933
  if (g.length === 1) {
46901
46934
  const p = g[0];
46902
46935
  const { text, w } = labelInfo(p);
46903
- if (inlineFits(p, w, "right")) {
46904
- pushInline(p, text, w, "right");
46905
- continue;
46906
- }
46907
- if (inlineFits(p, w, "left")) {
46908
- pushInline(p, text, w, "left");
46936
+ const side = ["right", "left", "above", "below"].find(
46937
+ (s) => inlineFits(p, w, s)
46938
+ );
46939
+ if (side) {
46940
+ pushInline(p, text, w, side);
46909
46941
  continue;
46910
46942
  }
46911
46943
  }
@@ -53658,18 +53690,18 @@ function getRotateFn(mode) {
53658
53690
  return () => 0;
53659
53691
  }
53660
53692
  function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
53661
- return new Promise((resolve2) => {
53693
+ return new Promise((resolve) => {
53662
53694
  d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
53663
53695
  const { words, cloudOptions } = parsed;
53664
53696
  const title = parsed.noTitle ? null : parsed.title;
53665
53697
  if (words.length === 0) {
53666
- resolve2();
53698
+ resolve();
53667
53699
  return;
53668
53700
  }
53669
53701
  const width = exportDims?.width ?? container.clientWidth;
53670
53702
  const height = exportDims?.height ?? container.clientHeight;
53671
53703
  if (width <= 0 || height <= 0) {
53672
- resolve2();
53704
+ resolve();
53673
53705
  return;
53674
53706
  }
53675
53707
  const titleHeight = title ? 40 : 0;
@@ -53698,7 +53730,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
53698
53730
  "transform",
53699
53731
  (d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
53700
53732
  ).text((d) => d.text);
53701
- resolve2();
53733
+ resolve();
53702
53734
  }).start();
53703
53735
  });
53704
53736
  }
@@ -57045,7 +57077,7 @@ pre.dgmo, code.language-dgmo, pre > code.language-dgmo,
57045
57077
 
57046
57078
  // src/auto/index.ts
57047
57079
  init_safe_href();
57048
- var VERSION = "0.20.0";
57080
+ var VERSION = "0.20.2";
57049
57081
  var DEFAULTS = {
57050
57082
  theme: "auto",
57051
57083
  palette: "nord",