@aguacerowx/mapsgl 0.0.46 → 0.0.48

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.
@@ -0,0 +1,40 @@
1
+ import pkg from '../package.json' with { type: 'json' };
2
+
3
+ /**
4
+ * jsDelivr serves the `basis/` folder from the published npm package (no `public/basis/` copy).
5
+ * Use when you consume `@aguacerowx/mapsgl` from the registry and do not host transcoder assets yourself.
6
+ */
7
+ export const JSDELIVR_BASIS_BASE_URL = `https://cdn.jsdelivr.net/npm/@aguacerowx/mapsgl@${pkg.version}/basis/`;
8
+
9
+ /**
10
+ * Default: resolve `mapsgl/basis/` inside this package.
11
+ *
12
+ * We cannot use `new URL('..', new URL('.', import.meta.url))`: Vite aliases `@aguacerowx/mapsgl` to
13
+ * `mapsgl/index.js`, so the "directory" of this module is often `.../mapsgl/` and `..` becomes the
14
+ * monorepo `packages/` folder — wrong (`packages/basis/` instead of `packages/mapsgl/basis/`).
15
+ * Webpack also rejects `new URL('../basis/', import.meta.url)` as an unresolved module, so we locate
16
+ * the `mapsgl` path segment and append `basis/`.
17
+ *
18
+ * In Vite production builds the folder URL becomes your app origin `/basis/`, so place copies under
19
+ * `public/basis/` (or sync from `node_modules/@aguacerowx/mapsgl/basis`).
20
+ * For CDN-only, pass {@link JSDELIVR_BASIS_BASE_URL} as `WeatherLayerManager({ basisBaseUrl: ... })`.
21
+ */
22
+ const _mapsglRootHref = (() => {
23
+ const u = import.meta.url;
24
+ const slashIdx = u.indexOf('/mapsgl/');
25
+ if (slashIdx >= 0) {
26
+ return u.slice(0, slashIdx + '/mapsgl/'.length);
27
+ }
28
+ // e.g. cdn.jsdelivr.net/.../mapsgl@0.0.47/dist/... (no `/mapsgl/` substring)
29
+ const atMatch = u.match(/\/mapsgl@[^/]+\//);
30
+ if (atMatch && atMatch.index !== undefined) {
31
+ return u.slice(0, atMatch.index + atMatch[0].length);
32
+ }
33
+ const srcMarker = '/src/';
34
+ const j = u.lastIndexOf(srcMarker);
35
+ if (j >= 0) {
36
+ return `${u.slice(0, j)}/`;
37
+ }
38
+ return new URL('../', new URL('.', u)).href;
39
+ })();
40
+ export const DEFAULT_BASIS_BASE_URL = new URL('basis/', _mapsglRootHref).href;