@bicharts/chart-host 0.1.8 → 0.1.9

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.
@@ -1,4 +1,9 @@
1
1
  /*! @bicharts/chart-host — Apache-2.0. Bundled reference data: GeoNames (https://www.geonames.org/) CC BY 4.0; Natural Earth and US Census/TIGER (public domain). Full text: NOTICE in this package. */
2
+ import {
3
+ NA_ISO3,
4
+ NA_LAT_MAX,
5
+ clipFeatureToLat
6
+ } from "./chunk-X7PWWEGM.mjs";
2
7
 
3
8
  // src/contract.ts
4
9
  var HOST_CONTRACT_VERSION = "1.0.0";
@@ -75,8 +80,11 @@ function resolveOptions(p) {
75
80
  }
76
81
 
77
82
  // src/geoLazy.ts
78
- var cache = /* @__PURE__ */ new Map();
79
- function assetFor(geoKind) {
83
+ var byKind = /* @__PURE__ */ new Map();
84
+ var byAsset = /* @__PURE__ */ new Map();
85
+ var _na;
86
+ function geoAssetFor(geoKind) {
87
+ if (!geoKind) return null;
80
88
  const k = geoKind.toLowerCase();
81
89
  if (/^country/.test(k)) return "world";
82
90
  if (k === "north-america") return "world";
@@ -84,37 +92,55 @@ function assetFor(geoKind) {
84
92
  if (k === "us-zip5") return "us-zip3";
85
93
  return null;
86
94
  }
95
+ function northAmerica(world) {
96
+ if (!_na) {
97
+ _na = {
98
+ type: "FeatureCollection",
99
+ features: world.features.filter((f) => NA_ISO3.has(f?.id) && f?.geometry && f.geometry.type !== "Point").map((f) => clipFeatureToLat(f, NA_LAT_MAX)).filter((f) => f !== null)
100
+ };
101
+ }
102
+ return _na;
103
+ }
104
+ function fromAssets(key) {
105
+ const asset = geoAssetFor(key);
106
+ if (!asset) return void 0;
107
+ const geo = byAsset.get(asset);
108
+ if (!geo) return void 0;
109
+ return key === "north-america" ? northAmerica(geo) : geo;
110
+ }
87
111
  async function loadGeo(geoKind) {
88
112
  if (!geoKind) return void 0;
89
113
  const key = geoKind.toLowerCase();
90
- if (cache.has(key)) return cache.get(key);
91
- const asset = assetFor(key);
114
+ const already = geoFromCache(key);
115
+ if (already) return already;
116
+ const asset = geoAssetFor(key);
92
117
  if (!asset) return void 0;
93
- let geo;
94
118
  if (asset === "us-states") {
95
- geo = (await import("./geoUsStates.generated-2ZZRXWWJ.mjs")).US_STATES;
119
+ byAsset.set(asset, (await import("./geoUsStates.generated-2ZZRXWWJ.mjs")).US_STATES);
96
120
  } else if (asset === "us-zip3") {
97
- geo = (await import("./geoUsZip3.generated-56OL4TTZ.mjs")).US_ZIP3;
121
+ byAsset.set(asset, (await import("./geoUsZip3.generated-56OL4TTZ.mjs")).US_ZIP3);
98
122
  } else {
99
- const { WORLD_110M } = await import("./geoWorld110m.generated-O2WOIRYY.mjs");
100
- if (key === "north-america") {
101
- const { NA_ISO3, NA_LAT_MAX, clipFeatureToLat } = await import("./geoNaRegions-SAINMZXG.mjs");
102
- geo = {
103
- type: "FeatureCollection",
104
- features: WORLD_110M.features.filter((f) => NA_ISO3.has(f?.id) && f?.geometry && f.geometry.type !== "Point").map((f) => clipFeatureToLat(f, NA_LAT_MAX)).filter((f) => f !== null)
105
- };
106
- } else {
107
- geo = WORLD_110M;
108
- }
123
+ byAsset.set(asset, (await import("./geoWorld110m.generated-O2WOIRYY.mjs")).WORLD_110M);
109
124
  }
110
- cache.set(key, geo);
111
- return geo;
125
+ return fromAssets(key);
112
126
  }
113
127
  function geoFromCache(geoKind) {
114
- return geoKind ? cache.get(geoKind.toLowerCase()) : void 0;
128
+ if (!geoKind) return void 0;
129
+ const key = geoKind.toLowerCase();
130
+ return byKind.get(key) ?? fromAssets(key);
115
131
  }
116
132
  function registerGeo(geoKind, geo) {
117
- if (geoKind && geo) cache.set(geoKind.toLowerCase(), geo);
133
+ if (geoKind && geo) byKind.set(geoKind.toLowerCase(), geo);
134
+ }
135
+ function registerGeoAsset(asset, geo) {
136
+ if (!asset || !geo) return;
137
+ byAsset.set(asset, geo);
138
+ if (asset === "world") _na = void 0;
139
+ }
140
+ function clearGeoCache() {
141
+ byKind.clear();
142
+ byAsset.clear();
143
+ _na = void 0;
118
144
  }
119
145
 
120
146
  // ../shape-core/dist/chunk-U5UKZYHK.mjs
@@ -1393,12 +1419,15 @@ export {
1393
1419
  COLOR_SCALE_SELF_CLAMP_PCT_MIN,
1394
1420
  COLOR_SCALE_SELF_CLAMP_PCT_MAX,
1395
1421
  resolveOptions,
1422
+ geoAssetFor,
1396
1423
  loadGeo,
1397
1424
  geoFromCache,
1398
1425
  registerGeo,
1426
+ registerGeoAsset,
1427
+ clearGeoCache,
1399
1428
  buildRenderPayload,
1400
1429
  createMarkResolver,
1401
1430
  compileRenderFn,
1402
1431
  createChartHost
1403
1432
  };
1404
- //# sourceMappingURL=chunk-LWVJSMWU.mjs.map
1433
+ //# sourceMappingURL=chunk-3NDJV3DA.mjs.map