@diagrammo/dgmo 0.20.0 → 0.20.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.
- package/dist/advanced.cjs +33 -27
- package/dist/advanced.js +31 -25
- package/dist/auto.cjs +31 -25
- package/dist/auto.js +101 -101
- package/dist/auto.mjs +30 -24
- package/dist/cli.cjs +129 -129
- package/dist/index.cjs +30 -24
- package/dist/index.js +29 -23
- package/dist/internal.cjs +33 -27
- package/dist/internal.js +31 -25
- package/package.json +1 -1
- package/src/advanced.ts +1 -4
- package/src/map/load-data.ts +48 -19
package/dist/index.cjs
CHANGED
|
@@ -46016,14 +46016,22 @@ var load_data_exports = {};
|
|
|
46016
46016
|
__export(load_data_exports, {
|
|
46017
46017
|
loadMapData: () => loadMapData
|
|
46018
46018
|
});
|
|
46019
|
-
async function
|
|
46020
|
-
|
|
46019
|
+
async function loadNodeBuiltins() {
|
|
46020
|
+
const [{ readFile }, { fileURLToPath }, { dirname, resolve }] = await Promise.all([
|
|
46021
|
+
import("fs/promises"),
|
|
46022
|
+
import("url"),
|
|
46023
|
+
import("path")
|
|
46024
|
+
]);
|
|
46025
|
+
return { readFile, fileURLToPath, dirname, resolve };
|
|
46026
|
+
}
|
|
46027
|
+
async function readJson(nb, dir, name) {
|
|
46028
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
|
|
46021
46029
|
}
|
|
46022
|
-
async function firstExistingDir(baseDir) {
|
|
46030
|
+
async function firstExistingDir(nb, baseDir) {
|
|
46023
46031
|
for (const rel of CANDIDATE_DIRS) {
|
|
46024
|
-
const dir =
|
|
46032
|
+
const dir = nb.resolve(baseDir, rel);
|
|
46025
46033
|
try {
|
|
46026
|
-
await
|
|
46034
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
|
|
46027
46035
|
return dir;
|
|
46028
46036
|
} catch {
|
|
46029
46037
|
}
|
|
@@ -46039,10 +46047,10 @@ function validate(data) {
|
|
|
46039
46047
|
}
|
|
46040
46048
|
return data;
|
|
46041
46049
|
}
|
|
46042
|
-
function moduleBaseDir() {
|
|
46050
|
+
function moduleBaseDir(nb) {
|
|
46043
46051
|
try {
|
|
46044
46052
|
const url = import_meta.url;
|
|
46045
|
-
if (url) return
|
|
46053
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
46046
46054
|
} catch {
|
|
46047
46055
|
}
|
|
46048
46056
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -46050,7 +46058,8 @@ function moduleBaseDir() {
|
|
|
46050
46058
|
}
|
|
46051
46059
|
function loadMapData() {
|
|
46052
46060
|
cache ??= (async () => {
|
|
46053
|
-
const
|
|
46061
|
+
const nb = await loadNodeBuiltins();
|
|
46062
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
46054
46063
|
const [
|
|
46055
46064
|
worldCoarse,
|
|
46056
46065
|
worldDetail,
|
|
@@ -46061,15 +46070,15 @@ function loadMapData() {
|
|
|
46061
46070
|
naLakes,
|
|
46062
46071
|
gazetteer
|
|
46063
46072
|
] = await Promise.all([
|
|
46064
|
-
readJson(dir, FILES.worldCoarse),
|
|
46065
|
-
readJson(dir, FILES.worldDetail),
|
|
46066
|
-
readJson(dir, FILES.usStates),
|
|
46073
|
+
readJson(nb, dir, FILES.worldCoarse),
|
|
46074
|
+
readJson(nb, dir, FILES.worldDetail),
|
|
46075
|
+
readJson(nb, dir, FILES.usStates),
|
|
46067
46076
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
46068
|
-
readJson(dir, FILES.lakes).catch(() => void 0),
|
|
46069
|
-
readJson(dir, FILES.rivers).catch(() => void 0),
|
|
46070
|
-
readJson(dir, FILES.naLand).catch(() => void 0),
|
|
46071
|
-
readJson(dir, FILES.naLakes).catch(() => void 0),
|
|
46072
|
-
readJson(dir, FILES.gazetteer)
|
|
46077
|
+
readJson(nb, dir, FILES.lakes).catch(() => void 0),
|
|
46078
|
+
readJson(nb, dir, FILES.rivers).catch(() => void 0),
|
|
46079
|
+
readJson(nb, dir, FILES.naLand).catch(() => void 0),
|
|
46080
|
+
readJson(nb, dir, FILES.naLakes).catch(() => void 0),
|
|
46081
|
+
readJson(nb, dir, FILES.gazetteer)
|
|
46073
46082
|
]);
|
|
46074
46083
|
return validate({
|
|
46075
46084
|
worldCoarse,
|
|
@@ -46087,13 +46096,10 @@ function loadMapData() {
|
|
|
46087
46096
|
});
|
|
46088
46097
|
return cache;
|
|
46089
46098
|
}
|
|
46090
|
-
var
|
|
46099
|
+
var import_meta, FILES, CANDIDATE_DIRS, cache;
|
|
46091
46100
|
var init_load_data = __esm({
|
|
46092
46101
|
"src/map/load-data.ts"() {
|
|
46093
46102
|
"use strict";
|
|
46094
|
-
import_promises = require("fs/promises");
|
|
46095
|
-
import_node_url = require("url");
|
|
46096
|
-
import_node_path = require("path");
|
|
46097
46103
|
import_meta = {};
|
|
46098
46104
|
FILES = {
|
|
46099
46105
|
worldCoarse: "world-coarse.json",
|
|
@@ -53705,18 +53711,18 @@ function getRotateFn(mode) {
|
|
|
53705
53711
|
return () => 0;
|
|
53706
53712
|
}
|
|
53707
53713
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
53708
|
-
return new Promise((
|
|
53714
|
+
return new Promise((resolve) => {
|
|
53709
53715
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
53710
53716
|
const { words, cloudOptions } = parsed;
|
|
53711
53717
|
const title = parsed.noTitle ? null : parsed.title;
|
|
53712
53718
|
if (words.length === 0) {
|
|
53713
|
-
|
|
53719
|
+
resolve();
|
|
53714
53720
|
return;
|
|
53715
53721
|
}
|
|
53716
53722
|
const width = exportDims?.width ?? container.clientWidth;
|
|
53717
53723
|
const height = exportDims?.height ?? container.clientHeight;
|
|
53718
53724
|
if (width <= 0 || height <= 0) {
|
|
53719
|
-
|
|
53725
|
+
resolve();
|
|
53720
53726
|
return;
|
|
53721
53727
|
}
|
|
53722
53728
|
const titleHeight = title ? 40 : 0;
|
|
@@ -53745,7 +53751,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
53745
53751
|
"transform",
|
|
53746
53752
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
53747
53753
|
).text((d) => d.text);
|
|
53748
|
-
|
|
53754
|
+
resolve();
|
|
53749
53755
|
}).start();
|
|
53750
53756
|
});
|
|
53751
53757
|
}
|
package/dist/index.js
CHANGED
|
@@ -46032,17 +46032,22 @@ var load_data_exports = {};
|
|
|
46032
46032
|
__export(load_data_exports, {
|
|
46033
46033
|
loadMapData: () => loadMapData
|
|
46034
46034
|
});
|
|
46035
|
-
|
|
46036
|
-
|
|
46037
|
-
import
|
|
46038
|
-
|
|
46039
|
-
|
|
46035
|
+
async function loadNodeBuiltins() {
|
|
46036
|
+
const [{ readFile }, { fileURLToPath }, { dirname, resolve }] = await Promise.all([
|
|
46037
|
+
import("fs/promises"),
|
|
46038
|
+
import("url"),
|
|
46039
|
+
import("path")
|
|
46040
|
+
]);
|
|
46041
|
+
return { readFile, fileURLToPath, dirname, resolve };
|
|
46042
|
+
}
|
|
46043
|
+
async function readJson(nb, dir, name) {
|
|
46044
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
|
|
46040
46045
|
}
|
|
46041
|
-
async function firstExistingDir(baseDir) {
|
|
46046
|
+
async function firstExistingDir(nb, baseDir) {
|
|
46042
46047
|
for (const rel of CANDIDATE_DIRS) {
|
|
46043
|
-
const dir = resolve(baseDir, rel);
|
|
46048
|
+
const dir = nb.resolve(baseDir, rel);
|
|
46044
46049
|
try {
|
|
46045
|
-
await readFile(resolve(dir, FILES.gazetteer), "utf8");
|
|
46050
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
|
|
46046
46051
|
return dir;
|
|
46047
46052
|
} catch {
|
|
46048
46053
|
}
|
|
@@ -46058,10 +46063,10 @@ function validate(data) {
|
|
|
46058
46063
|
}
|
|
46059
46064
|
return data;
|
|
46060
46065
|
}
|
|
46061
|
-
function moduleBaseDir() {
|
|
46066
|
+
function moduleBaseDir(nb) {
|
|
46062
46067
|
try {
|
|
46063
46068
|
const url = import.meta.url;
|
|
46064
|
-
if (url) return dirname(fileURLToPath(url));
|
|
46069
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
46065
46070
|
} catch {
|
|
46066
46071
|
}
|
|
46067
46072
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -46069,7 +46074,8 @@ function moduleBaseDir() {
|
|
|
46069
46074
|
}
|
|
46070
46075
|
function loadMapData() {
|
|
46071
46076
|
cache ??= (async () => {
|
|
46072
|
-
const
|
|
46077
|
+
const nb = await loadNodeBuiltins();
|
|
46078
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
46073
46079
|
const [
|
|
46074
46080
|
worldCoarse,
|
|
46075
46081
|
worldDetail,
|
|
@@ -46080,15 +46086,15 @@ function loadMapData() {
|
|
|
46080
46086
|
naLakes,
|
|
46081
46087
|
gazetteer
|
|
46082
46088
|
] = await Promise.all([
|
|
46083
|
-
readJson(dir, FILES.worldCoarse),
|
|
46084
|
-
readJson(dir, FILES.worldDetail),
|
|
46085
|
-
readJson(dir, FILES.usStates),
|
|
46089
|
+
readJson(nb, dir, FILES.worldCoarse),
|
|
46090
|
+
readJson(nb, dir, FILES.worldDetail),
|
|
46091
|
+
readJson(nb, dir, FILES.usStates),
|
|
46086
46092
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
46087
|
-
readJson(dir, FILES.lakes).catch(() => void 0),
|
|
46088
|
-
readJson(dir, FILES.rivers).catch(() => void 0),
|
|
46089
|
-
readJson(dir, FILES.naLand).catch(() => void 0),
|
|
46090
|
-
readJson(dir, FILES.naLakes).catch(() => void 0),
|
|
46091
|
-
readJson(dir, FILES.gazetteer)
|
|
46093
|
+
readJson(nb, dir, FILES.lakes).catch(() => void 0),
|
|
46094
|
+
readJson(nb, dir, FILES.rivers).catch(() => void 0),
|
|
46095
|
+
readJson(nb, dir, FILES.naLand).catch(() => void 0),
|
|
46096
|
+
readJson(nb, dir, FILES.naLakes).catch(() => void 0),
|
|
46097
|
+
readJson(nb, dir, FILES.gazetteer)
|
|
46092
46098
|
]);
|
|
46093
46099
|
return validate({
|
|
46094
46100
|
worldCoarse,
|
|
@@ -53733,18 +53739,18 @@ function getRotateFn(mode) {
|
|
|
53733
53739
|
return () => 0;
|
|
53734
53740
|
}
|
|
53735
53741
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
53736
|
-
return new Promise((
|
|
53742
|
+
return new Promise((resolve) => {
|
|
53737
53743
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
53738
53744
|
const { words, cloudOptions } = parsed;
|
|
53739
53745
|
const title = parsed.noTitle ? null : parsed.title;
|
|
53740
53746
|
if (words.length === 0) {
|
|
53741
|
-
|
|
53747
|
+
resolve();
|
|
53742
53748
|
return;
|
|
53743
53749
|
}
|
|
53744
53750
|
const width = exportDims?.width ?? container.clientWidth;
|
|
53745
53751
|
const height = exportDims?.height ?? container.clientHeight;
|
|
53746
53752
|
if (width <= 0 || height <= 0) {
|
|
53747
|
-
|
|
53753
|
+
resolve();
|
|
53748
53754
|
return;
|
|
53749
53755
|
}
|
|
53750
53756
|
const titleHeight = title ? 40 : 0;
|
|
@@ -53773,7 +53779,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
53773
53779
|
"transform",
|
|
53774
53780
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
53775
53781
|
).text((d) => d.text);
|
|
53776
|
-
|
|
53782
|
+
resolve();
|
|
53777
53783
|
}).start();
|
|
53778
53784
|
});
|
|
53779
53785
|
}
|
package/dist/internal.cjs
CHANGED
|
@@ -46303,14 +46303,22 @@ var load_data_exports = {};
|
|
|
46303
46303
|
__export(load_data_exports, {
|
|
46304
46304
|
loadMapData: () => loadMapData
|
|
46305
46305
|
});
|
|
46306
|
-
async function
|
|
46307
|
-
|
|
46306
|
+
async function loadNodeBuiltins() {
|
|
46307
|
+
const [{ readFile }, { fileURLToPath }, { dirname: dirname2, resolve }] = await Promise.all([
|
|
46308
|
+
import("fs/promises"),
|
|
46309
|
+
import("url"),
|
|
46310
|
+
import("path")
|
|
46311
|
+
]);
|
|
46312
|
+
return { readFile, fileURLToPath, dirname: dirname2, resolve };
|
|
46313
|
+
}
|
|
46314
|
+
async function readJson(nb, dir, name) {
|
|
46315
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
|
|
46308
46316
|
}
|
|
46309
|
-
async function firstExistingDir(baseDir) {
|
|
46317
|
+
async function firstExistingDir(nb, baseDir) {
|
|
46310
46318
|
for (const rel of CANDIDATE_DIRS) {
|
|
46311
|
-
const dir =
|
|
46319
|
+
const dir = nb.resolve(baseDir, rel);
|
|
46312
46320
|
try {
|
|
46313
|
-
await
|
|
46321
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
|
|
46314
46322
|
return dir;
|
|
46315
46323
|
} catch {
|
|
46316
46324
|
}
|
|
@@ -46326,10 +46334,10 @@ function validate(data) {
|
|
|
46326
46334
|
}
|
|
46327
46335
|
return data;
|
|
46328
46336
|
}
|
|
46329
|
-
function moduleBaseDir() {
|
|
46337
|
+
function moduleBaseDir(nb) {
|
|
46330
46338
|
try {
|
|
46331
46339
|
const url = import_meta.url;
|
|
46332
|
-
if (url) return
|
|
46340
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
46333
46341
|
} catch {
|
|
46334
46342
|
}
|
|
46335
46343
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -46337,7 +46345,8 @@ function moduleBaseDir() {
|
|
|
46337
46345
|
}
|
|
46338
46346
|
function loadMapData() {
|
|
46339
46347
|
cache ??= (async () => {
|
|
46340
|
-
const
|
|
46348
|
+
const nb = await loadNodeBuiltins();
|
|
46349
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
46341
46350
|
const [
|
|
46342
46351
|
worldCoarse,
|
|
46343
46352
|
worldDetail,
|
|
@@ -46348,15 +46357,15 @@ function loadMapData() {
|
|
|
46348
46357
|
naLakes,
|
|
46349
46358
|
gazetteer
|
|
46350
46359
|
] = await Promise.all([
|
|
46351
|
-
readJson(dir, FILES.worldCoarse),
|
|
46352
|
-
readJson(dir, FILES.worldDetail),
|
|
46353
|
-
readJson(dir, FILES.usStates),
|
|
46360
|
+
readJson(nb, dir, FILES.worldCoarse),
|
|
46361
|
+
readJson(nb, dir, FILES.worldDetail),
|
|
46362
|
+
readJson(nb, dir, FILES.usStates),
|
|
46354
46363
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
46355
|
-
readJson(dir, FILES.lakes).catch(() => void 0),
|
|
46356
|
-
readJson(dir, FILES.rivers).catch(() => void 0),
|
|
46357
|
-
readJson(dir, FILES.naLand).catch(() => void 0),
|
|
46358
|
-
readJson(dir, FILES.naLakes).catch(() => void 0),
|
|
46359
|
-
readJson(dir, FILES.gazetteer)
|
|
46364
|
+
readJson(nb, dir, FILES.lakes).catch(() => void 0),
|
|
46365
|
+
readJson(nb, dir, FILES.rivers).catch(() => void 0),
|
|
46366
|
+
readJson(nb, dir, FILES.naLand).catch(() => void 0),
|
|
46367
|
+
readJson(nb, dir, FILES.naLakes).catch(() => void 0),
|
|
46368
|
+
readJson(nb, dir, FILES.gazetteer)
|
|
46360
46369
|
]);
|
|
46361
46370
|
return validate({
|
|
46362
46371
|
worldCoarse,
|
|
@@ -46374,13 +46383,10 @@ function loadMapData() {
|
|
|
46374
46383
|
});
|
|
46375
46384
|
return cache;
|
|
46376
46385
|
}
|
|
46377
|
-
var
|
|
46386
|
+
var import_meta, FILES, CANDIDATE_DIRS, cache;
|
|
46378
46387
|
var init_load_data = __esm({
|
|
46379
46388
|
"src/map/load-data.ts"() {
|
|
46380
46389
|
"use strict";
|
|
46381
|
-
import_promises = require("fs/promises");
|
|
46382
|
-
import_node_url = require("url");
|
|
46383
|
-
import_node_path = require("path");
|
|
46384
46390
|
import_meta = {};
|
|
46385
46391
|
FILES = {
|
|
46386
46392
|
worldCoarse: "world-coarse.json",
|
|
@@ -54055,18 +54061,18 @@ function renderWordCloud(container, parsed, palette, _isDark, onClickItem, expor
|
|
|
54055
54061
|
}).start();
|
|
54056
54062
|
}
|
|
54057
54063
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
54058
|
-
return new Promise((
|
|
54064
|
+
return new Promise((resolve) => {
|
|
54059
54065
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
54060
54066
|
const { words, cloudOptions } = parsed;
|
|
54061
54067
|
const title = parsed.noTitle ? null : parsed.title;
|
|
54062
54068
|
if (words.length === 0) {
|
|
54063
|
-
|
|
54069
|
+
resolve();
|
|
54064
54070
|
return;
|
|
54065
54071
|
}
|
|
54066
54072
|
const width = exportDims?.width ?? container.clientWidth;
|
|
54067
54073
|
const height = exportDims?.height ?? container.clientHeight;
|
|
54068
54074
|
if (width <= 0 || height <= 0) {
|
|
54069
|
-
|
|
54075
|
+
resolve();
|
|
54070
54076
|
return;
|
|
54071
54077
|
}
|
|
54072
54078
|
const titleHeight = title ? 40 : 0;
|
|
@@ -54095,7 +54101,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
54095
54101
|
"transform",
|
|
54096
54102
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
54097
54103
|
).text((d) => d.text);
|
|
54098
|
-
|
|
54104
|
+
resolve();
|
|
54099
54105
|
}).start();
|
|
54100
54106
|
});
|
|
54101
54107
|
}
|
|
@@ -57530,12 +57536,12 @@ var KNOWN_HEADER_OPTIONS = /* @__PURE__ */ new Set([
|
|
|
57530
57536
|
"solid-fill",
|
|
57531
57537
|
"active-tag"
|
|
57532
57538
|
]);
|
|
57533
|
-
function
|
|
57539
|
+
function dirname(filePath) {
|
|
57534
57540
|
const last = filePath.lastIndexOf("/");
|
|
57535
57541
|
return last > 0 ? filePath.substring(0, last) : "/";
|
|
57536
57542
|
}
|
|
57537
57543
|
function resolvePath(base, relative) {
|
|
57538
|
-
const parts =
|
|
57544
|
+
const parts = dirname(base).split("/");
|
|
57539
57545
|
for (const seg of relative.split("/")) {
|
|
57540
57546
|
if (seg === "..") {
|
|
57541
57547
|
if (parts.length > 1) parts.pop();
|
|
@@ -59662,7 +59668,7 @@ init_dgmo_router();
|
|
|
59662
59668
|
|
|
59663
59669
|
// src/migrate/index.ts
|
|
59664
59670
|
var import_node_fs = require("fs");
|
|
59665
|
-
var
|
|
59671
|
+
var import_node_path = require("path");
|
|
59666
59672
|
init_dgmo_router();
|
|
59667
59673
|
|
|
59668
59674
|
// src/migrate/line-classifier.ts
|
package/dist/internal.js
CHANGED
|
@@ -46319,17 +46319,22 @@ var load_data_exports = {};
|
|
|
46319
46319
|
__export(load_data_exports, {
|
|
46320
46320
|
loadMapData: () => loadMapData
|
|
46321
46321
|
});
|
|
46322
|
-
|
|
46323
|
-
|
|
46324
|
-
import
|
|
46325
|
-
|
|
46326
|
-
|
|
46322
|
+
async function loadNodeBuiltins() {
|
|
46323
|
+
const [{ readFile }, { fileURLToPath }, { dirname: dirname2, resolve }] = await Promise.all([
|
|
46324
|
+
import("fs/promises"),
|
|
46325
|
+
import("url"),
|
|
46326
|
+
import("path")
|
|
46327
|
+
]);
|
|
46328
|
+
return { readFile, fileURLToPath, dirname: dirname2, resolve };
|
|
46329
|
+
}
|
|
46330
|
+
async function readJson(nb, dir, name) {
|
|
46331
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), "utf8"));
|
|
46327
46332
|
}
|
|
46328
|
-
async function firstExistingDir(baseDir) {
|
|
46333
|
+
async function firstExistingDir(nb, baseDir) {
|
|
46329
46334
|
for (const rel of CANDIDATE_DIRS) {
|
|
46330
|
-
const dir = resolve(baseDir, rel);
|
|
46335
|
+
const dir = nb.resolve(baseDir, rel);
|
|
46331
46336
|
try {
|
|
46332
|
-
await readFile(resolve(dir, FILES.gazetteer), "utf8");
|
|
46337
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), "utf8");
|
|
46333
46338
|
return dir;
|
|
46334
46339
|
} catch {
|
|
46335
46340
|
}
|
|
@@ -46345,10 +46350,10 @@ function validate(data) {
|
|
|
46345
46350
|
}
|
|
46346
46351
|
return data;
|
|
46347
46352
|
}
|
|
46348
|
-
function moduleBaseDir() {
|
|
46353
|
+
function moduleBaseDir(nb) {
|
|
46349
46354
|
try {
|
|
46350
46355
|
const url = import.meta.url;
|
|
46351
|
-
if (url) return dirname(fileURLToPath(url));
|
|
46356
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
46352
46357
|
} catch {
|
|
46353
46358
|
}
|
|
46354
46359
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
@@ -46356,7 +46361,8 @@ function moduleBaseDir() {
|
|
|
46356
46361
|
}
|
|
46357
46362
|
function loadMapData() {
|
|
46358
46363
|
cache ??= (async () => {
|
|
46359
|
-
const
|
|
46364
|
+
const nb = await loadNodeBuiltins();
|
|
46365
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
46360
46366
|
const [
|
|
46361
46367
|
worldCoarse,
|
|
46362
46368
|
worldDetail,
|
|
@@ -46367,15 +46373,15 @@ function loadMapData() {
|
|
|
46367
46373
|
naLakes,
|
|
46368
46374
|
gazetteer
|
|
46369
46375
|
] = await Promise.all([
|
|
46370
|
-
readJson(dir, FILES.worldCoarse),
|
|
46371
|
-
readJson(dir, FILES.worldDetail),
|
|
46372
|
-
readJson(dir, FILES.usStates),
|
|
46376
|
+
readJson(nb, dir, FILES.worldCoarse),
|
|
46377
|
+
readJson(nb, dir, FILES.worldDetail),
|
|
46378
|
+
readJson(nb, dir, FILES.usStates),
|
|
46373
46379
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
46374
|
-
readJson(dir, FILES.lakes).catch(() => void 0),
|
|
46375
|
-
readJson(dir, FILES.rivers).catch(() => void 0),
|
|
46376
|
-
readJson(dir, FILES.naLand).catch(() => void 0),
|
|
46377
|
-
readJson(dir, FILES.naLakes).catch(() => void 0),
|
|
46378
|
-
readJson(dir, FILES.gazetteer)
|
|
46380
|
+
readJson(nb, dir, FILES.lakes).catch(() => void 0),
|
|
46381
|
+
readJson(nb, dir, FILES.rivers).catch(() => void 0),
|
|
46382
|
+
readJson(nb, dir, FILES.naLand).catch(() => void 0),
|
|
46383
|
+
readJson(nb, dir, FILES.naLakes).catch(() => void 0),
|
|
46384
|
+
readJson(nb, dir, FILES.gazetteer)
|
|
46379
46385
|
]);
|
|
46380
46386
|
return validate({
|
|
46381
46387
|
worldCoarse,
|
|
@@ -54083,18 +54089,18 @@ function renderWordCloud(container, parsed, palette, _isDark, onClickItem, expor
|
|
|
54083
54089
|
}).start();
|
|
54084
54090
|
}
|
|
54085
54091
|
function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
54086
|
-
return new Promise((
|
|
54092
|
+
return new Promise((resolve) => {
|
|
54087
54093
|
d3Selection23.select(container).selectAll(":not([data-d3-tooltip])").remove();
|
|
54088
54094
|
const { words, cloudOptions } = parsed;
|
|
54089
54095
|
const title = parsed.noTitle ? null : parsed.title;
|
|
54090
54096
|
if (words.length === 0) {
|
|
54091
|
-
|
|
54097
|
+
resolve();
|
|
54092
54098
|
return;
|
|
54093
54099
|
}
|
|
54094
54100
|
const width = exportDims?.width ?? container.clientWidth;
|
|
54095
54101
|
const height = exportDims?.height ?? container.clientHeight;
|
|
54096
54102
|
if (width <= 0 || height <= 0) {
|
|
54097
|
-
|
|
54103
|
+
resolve();
|
|
54098
54104
|
return;
|
|
54099
54105
|
}
|
|
54100
54106
|
const titleHeight = title ? 40 : 0;
|
|
@@ -54123,7 +54129,7 @@ function renderWordCloudAsync(container, parsed, palette, _isDark, exportDims) {
|
|
|
54123
54129
|
"transform",
|
|
54124
54130
|
(d) => `translate(${d.x},${d.y}) rotate(${d.rotate})`
|
|
54125
54131
|
).text((d) => d.text);
|
|
54126
|
-
|
|
54132
|
+
resolve();
|
|
54127
54133
|
}).start();
|
|
54128
54134
|
});
|
|
54129
54135
|
}
|
|
@@ -57273,12 +57279,12 @@ var KNOWN_HEADER_OPTIONS = /* @__PURE__ */ new Set([
|
|
|
57273
57279
|
"solid-fill",
|
|
57274
57280
|
"active-tag"
|
|
57275
57281
|
]);
|
|
57276
|
-
function
|
|
57282
|
+
function dirname(filePath) {
|
|
57277
57283
|
const last = filePath.lastIndexOf("/");
|
|
57278
57284
|
return last > 0 ? filePath.substring(0, last) : "/";
|
|
57279
57285
|
}
|
|
57280
57286
|
function resolvePath(base, relative) {
|
|
57281
|
-
const parts =
|
|
57287
|
+
const parts = dirname(base).split("/");
|
|
57282
57288
|
for (const seg of relative.split("/")) {
|
|
57283
57289
|
if (seg === "..") {
|
|
57284
57290
|
if (parts.length > 1) parts.pop();
|
package/package.json
CHANGED
package/src/advanced.ts
CHANGED
|
@@ -631,10 +631,7 @@ export {
|
|
|
631
631
|
} from './echarts';
|
|
632
632
|
export type { ScatterLabelPoint } from './echarts';
|
|
633
633
|
export { ScaleContext } from './utils/scaling';
|
|
634
|
-
export {
|
|
635
|
-
renderLegendSvg,
|
|
636
|
-
renderLegendSvgFromConfig,
|
|
637
|
-
} from './utils/legend-svg';
|
|
634
|
+
export { renderLegendSvg, renderLegendSvgFromConfig } from './utils/legend-svg';
|
|
638
635
|
export type { LegendGroupData } from './utils/legend-types';
|
|
639
636
|
export { LEGEND_HEIGHT, LEGEND_GEAR_PILL_W } from './utils/legend-constants';
|
|
640
637
|
export { renderLegendD3 } from './utils/legend-d3';
|
package/src/map/load-data.ts
CHANGED
|
@@ -10,12 +10,33 @@
|
|
|
10
10
|
// build must inject `MapData` (or supply a fetch/bundle loader) — `resolveMap`
|
|
11
11
|
// takes `MapData` by DI precisely so the browser path can differ. Do NOT assume
|
|
12
12
|
// a green Node smoke test proves the browser load.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
//
|
|
14
|
+
// Node builtins (`fs/promises`, `url`, `path`) are imported LAZILY inside
|
|
15
|
+
// `loadMapData` — never at module top level — so this file can be pulled into a
|
|
16
|
+
// browser bundle (Obsidian's esbuild `platform: browser`, the app's Vite/Rollup
|
|
17
|
+
// web build) without the bundler trying to resolve `node:*`. Mirrors the
|
|
18
|
+
// `await import('jsdom')` seam in render.ts. The web build injects `MapData` via
|
|
19
|
+
// DI and never calls `loadMapData`, so the dynamic import only runs in Node.
|
|
16
20
|
import type { MapData } from './resolved-types';
|
|
17
21
|
import type { BoundaryTopology, Gazetteer } from './data/types';
|
|
18
22
|
|
|
23
|
+
type NodeBuiltins = {
|
|
24
|
+
readFile: typeof import('node:fs/promises').readFile;
|
|
25
|
+
fileURLToPath: typeof import('node:url').fileURLToPath;
|
|
26
|
+
dirname: typeof import('node:path').dirname;
|
|
27
|
+
resolve: typeof import('node:path').resolve;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
async function loadNodeBuiltins(): Promise<NodeBuiltins> {
|
|
31
|
+
const [{ readFile }, { fileURLToPath }, { dirname, resolve }] =
|
|
32
|
+
await Promise.all([
|
|
33
|
+
import('node:fs/promises'),
|
|
34
|
+
import('node:url'),
|
|
35
|
+
import('node:path'),
|
|
36
|
+
]);
|
|
37
|
+
return { readFile, fileURLToPath, dirname, resolve };
|
|
38
|
+
}
|
|
39
|
+
|
|
19
40
|
const FILES = {
|
|
20
41
|
worldCoarse: 'world-coarse.json',
|
|
21
42
|
worldDetail: 'world-detail.json',
|
|
@@ -37,15 +58,22 @@ const CANDIDATE_DIRS = [
|
|
|
37
58
|
|
|
38
59
|
let cache: Promise<MapData> | undefined;
|
|
39
60
|
|
|
40
|
-
async function readJson<T>(
|
|
41
|
-
|
|
61
|
+
async function readJson<T>(
|
|
62
|
+
nb: NodeBuiltins,
|
|
63
|
+
dir: string,
|
|
64
|
+
name: string
|
|
65
|
+
): Promise<T> {
|
|
66
|
+
return JSON.parse(await nb.readFile(nb.resolve(dir, name), 'utf8')) as T;
|
|
42
67
|
}
|
|
43
68
|
|
|
44
|
-
async function firstExistingDir(
|
|
69
|
+
async function firstExistingDir(
|
|
70
|
+
nb: NodeBuiltins,
|
|
71
|
+
baseDir: string
|
|
72
|
+
): Promise<string> {
|
|
45
73
|
for (const rel of CANDIDATE_DIRS) {
|
|
46
|
-
const dir = resolve(baseDir, rel);
|
|
74
|
+
const dir = nb.resolve(baseDir, rel);
|
|
47
75
|
try {
|
|
48
|
-
await readFile(resolve(dir, FILES.gazetteer), 'utf8');
|
|
76
|
+
await nb.readFile(nb.resolve(dir, FILES.gazetteer), 'utf8');
|
|
49
77
|
return dir;
|
|
50
78
|
} catch {
|
|
51
79
|
/* try next candidate */
|
|
@@ -78,10 +106,10 @@ function validate(data: MapData): MapData {
|
|
|
78
106
|
* (dist/cli.cjs, where `import.meta.url` is `undefined` → `fileURLToPath`
|
|
79
107
|
* throws). The `typeof __dirname` guard is safe in ESM (evaluates to
|
|
80
108
|
* 'undefined' without a ReferenceError). */
|
|
81
|
-
function moduleBaseDir(): string {
|
|
109
|
+
function moduleBaseDir(nb: NodeBuiltins): string {
|
|
82
110
|
try {
|
|
83
111
|
const url = import.meta.url;
|
|
84
|
-
if (url) return dirname(fileURLToPath(url));
|
|
112
|
+
if (url) return nb.dirname(nb.fileURLToPath(url));
|
|
85
113
|
} catch {
|
|
86
114
|
/* CJS: import.meta unavailable — fall through */
|
|
87
115
|
}
|
|
@@ -95,7 +123,8 @@ function moduleBaseDir(): string {
|
|
|
95
123
|
* call can retry rather than inheriting a poisoned promise. */
|
|
96
124
|
export function loadMapData(): Promise<MapData> {
|
|
97
125
|
cache ??= (async (): Promise<MapData> => {
|
|
98
|
-
const
|
|
126
|
+
const nb = await loadNodeBuiltins();
|
|
127
|
+
const dir = await firstExistingDir(nb, moduleBaseDir(nb));
|
|
99
128
|
const [
|
|
100
129
|
worldCoarse,
|
|
101
130
|
worldDetail,
|
|
@@ -106,15 +135,15 @@ export function loadMapData(): Promise<MapData> {
|
|
|
106
135
|
naLakes,
|
|
107
136
|
gazetteer,
|
|
108
137
|
] = await Promise.all([
|
|
109
|
-
readJson<BoundaryTopology>(dir, FILES.worldCoarse),
|
|
110
|
-
readJson<BoundaryTopology>(dir, FILES.worldDetail),
|
|
111
|
-
readJson<BoundaryTopology>(dir, FILES.usStates),
|
|
138
|
+
readJson<BoundaryTopology>(nb, dir, FILES.worldCoarse),
|
|
139
|
+
readJson<BoundaryTopology>(nb, dir, FILES.worldDetail),
|
|
140
|
+
readJson<BoundaryTopology>(nb, dir, FILES.usStates),
|
|
112
141
|
// Lakes/rivers/NA assets are optional — older bundles may predate them.
|
|
113
|
-
readJson<BoundaryTopology>(dir, FILES.lakes).catch(() => undefined),
|
|
114
|
-
readJson<BoundaryTopology>(dir, FILES.rivers).catch(() => undefined),
|
|
115
|
-
readJson<BoundaryTopology>(dir, FILES.naLand).catch(() => undefined),
|
|
116
|
-
readJson<BoundaryTopology>(dir, FILES.naLakes).catch(() => undefined),
|
|
117
|
-
readJson<Gazetteer>(dir, FILES.gazetteer),
|
|
142
|
+
readJson<BoundaryTopology>(nb, dir, FILES.lakes).catch(() => undefined),
|
|
143
|
+
readJson<BoundaryTopology>(nb, dir, FILES.rivers).catch(() => undefined),
|
|
144
|
+
readJson<BoundaryTopology>(nb, dir, FILES.naLand).catch(() => undefined),
|
|
145
|
+
readJson<BoundaryTopology>(nb, dir, FILES.naLakes).catch(() => undefined),
|
|
146
|
+
readJson<Gazetteer>(nb, dir, FILES.gazetteer),
|
|
118
147
|
]);
|
|
119
148
|
return validate({
|
|
120
149
|
worldCoarse,
|