@india-boundary-corrector/data 0.0.2 β 0.0.4
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/README.md +28 -0
- package/index.d.ts +15 -2
- package/index.js +48 -23
- package/package.json +3 -2
- package/version.js +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
PMTiles data package for India boundary corrections.
|
|
6
6
|
|
|
7
|
+
[**πΊοΈ View PMTiles data on pmtiles.io**](https://pmtiles.io/#url=https%3A%2F%2Fcdn.jsdelivr.net%2Fnpm%2F%40india-boundary-corrector%2Fdata%2Findia_boundary_corrections.pmtiles)
|
|
8
|
+
|
|
7
9
|
## Layers
|
|
8
10
|
|
|
9
11
|
The PMTiles file contains 4 layers:
|
|
@@ -30,6 +32,32 @@ setPmtilesUrl('https://my-cdn.com/india_boundary_corrections.pmtiles');
|
|
|
30
32
|
const version = getDataVersion(); // e.g., "osm_20231215_143022_ne_5.1.2"
|
|
31
33
|
```
|
|
32
34
|
|
|
35
|
+
## PMTiles URL Resolution
|
|
36
|
+
|
|
37
|
+
The `getPmtilesUrl()` function automatically detects the best URL for the PMTiles file:
|
|
38
|
+
|
|
39
|
+
1. **ESM environments** (direct import, jsDelivr): Uses `import.meta.url` to resolve the file relative to the module location
|
|
40
|
+
2. **CDNs requiring fallback** (esm.sh, Skypack, unpkg): These are redirected to jsDelivr (see below)
|
|
41
|
+
3. **Bundled/other environments**: When `import.meta.url` isn't available (CJS, UMD), falls back to jsDelivr CDN with pinned package version
|
|
42
|
+
|
|
43
|
+
### CDN fallback
|
|
44
|
+
|
|
45
|
+
When the package is loaded from jsDelivr, the PMTiles file is resolved relative to the module URL - no extra configuration needed.
|
|
46
|
+
|
|
47
|
+
The following CDNs automatically fall back to jsDelivr:
|
|
48
|
+
- **esm.sh, Skypack**: These CDNs transform JS modules but don't serve static files
|
|
49
|
+
- **unpkg**: Has issues serving PMTiles files (see [#13](https://github.com/ramSeraph/india_boundary_corrector/issues/13))
|
|
50
|
+
|
|
51
|
+
When bundled (Rollup IIFE, Webpack, etc.), `import.meta.url` typically points to the bundle location. If the PMTiles file isn't copied alongside the bundle, the resolved URL will 404. In this case, either:
|
|
52
|
+
- Copy the PMTiles file to your output directory (see below)
|
|
53
|
+
- Use `setPmtilesUrl()` to point to a CDN or self-hosted URL
|
|
54
|
+
|
|
55
|
+
### Self-hosted / Bundled builds
|
|
56
|
+
|
|
57
|
+
If you're bundling this package with a tool like Rollup, Webpack, Vite, or tsup, you may need to copy the PMTiles file to your output directory.
|
|
58
|
+
|
|
59
|
+
See **[Bundling the PMTiles Asset](./bundling-pmtiles.md)** for detailed instructions.
|
|
60
|
+
|
|
33
61
|
## Data Sources
|
|
34
62
|
|
|
35
63
|
- OpenStreetMap boundary relations for India, Pakistan, and disputed territories
|
package/index.d.ts
CHANGED
|
@@ -8,12 +8,17 @@ export const layers: {
|
|
|
8
8
|
toDelNe: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Default CDN URL for the PMTiles file (jsDelivr with pinned version)
|
|
13
|
+
*/
|
|
14
|
+
export const DEFAULT_CDN_URL: string;
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* Get the URL for the PMTiles file.
|
|
13
18
|
* Automatically detects the correct URL based on the environment:
|
|
14
19
|
* - ESM bundlers: Uses import.meta.url
|
|
15
|
-
* -
|
|
16
|
-
* - Fallback:
|
|
20
|
+
* - IIFE/script tags: Uses document.currentScript.src
|
|
21
|
+
* - Fallback: jsDelivr CDN URL
|
|
17
22
|
*/
|
|
18
23
|
export function getPmtilesUrl(): string;
|
|
19
24
|
|
|
@@ -28,3 +33,11 @@ export function setPmtilesUrl(url: string): void;
|
|
|
28
33
|
* Format: osm_YYYYMMDD_HHMMSS_ne_VERSION
|
|
29
34
|
*/
|
|
30
35
|
export function getDataVersion(): string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Resolve PMTiles URL from a given script URL.
|
|
39
|
+
* Useful for testing URL resolution logic.
|
|
40
|
+
* @param scriptUrl - The script URL to resolve from
|
|
41
|
+
* @returns The resolved PMTiles URL
|
|
42
|
+
*/
|
|
43
|
+
export function resolvePmtilesUrl(scriptUrl: string): string;
|
package/index.js
CHANGED
|
@@ -5,8 +5,18 @@ import { packageVersion } from './version.js';
|
|
|
5
5
|
const PACKAGE_NAME = '@india-boundary-corrector/data';
|
|
6
6
|
const PMTILES_FILENAME = 'india_boundary_corrections.pmtiles';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* CDNs that need fallback to jsDelivr:
|
|
10
|
+
* - esm.sh, skypack: JS module transformers only, don't serve static files
|
|
11
|
+
* - unpkg.com: Has issues serving PMTiles files (incorrect content-type, range request problems)
|
|
12
|
+
*/
|
|
13
|
+
const FALLBACK_CDNS = new Set(['esm.sh', 'skypack.dev', 'cdn.skypack.dev', 'unpkg.com']);
|
|
14
|
+
|
|
15
|
+
// Default fallback CDN (jsDelivr has multi-CDN architecture, more reliable)
|
|
16
|
+
export const DEFAULT_CDN_URL = `https://cdn.jsdelivr.net/npm/${PACKAGE_NAME}@${packageVersion}/${PMTILES_FILENAME}`;
|
|
17
|
+
|
|
18
|
+
// Capture document.currentScript.src at module load time (becomes null after script executes)
|
|
19
|
+
const CURRENT_SCRIPT_URL = (typeof document !== 'undefined' && document.currentScript && document.currentScript.src) || null;
|
|
10
20
|
|
|
11
21
|
/**
|
|
12
22
|
* Layer names in the PMTiles file
|
|
@@ -18,46 +28,61 @@ export const layers = {
|
|
|
18
28
|
toDelNe: 'to-del-ne',
|
|
19
29
|
};
|
|
20
30
|
|
|
21
|
-
/**
|
|
22
|
-
* Check if a URL hostname should use CDN fallback.
|
|
23
|
-
* Some CDNs like esm.sh don't host static files, so we need to fall back to unpkg.
|
|
24
|
-
* @param {string} hostname - The hostname to check
|
|
25
|
-
* @returns {boolean} True if CDN fallback should be used
|
|
26
|
-
*/
|
|
27
|
-
export function shouldUseCdnFallback(hostname) {
|
|
28
|
-
// esm.sh doesn't host static files, only transforms JS modules
|
|
29
|
-
return hostname === 'esm.sh';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
31
|
/**
|
|
33
32
|
* Detect the PMTiles URL from various sources:
|
|
34
33
|
* 1. import.meta.url (for ESM bundlers - most reliable)
|
|
35
|
-
* 2.
|
|
34
|
+
* 2. document.currentScript.src (for IIFE/script tags, captured at load time)
|
|
35
|
+
* 3. Fallback to jsDelivr CDN with pinned version
|
|
36
36
|
*
|
|
37
37
|
* Note: When this package is bundled into another bundle, import.meta.url
|
|
38
38
|
* won't work and we fall back to the CDN URL. Users can override with
|
|
39
39
|
* setPmtilesUrl() for self-hosted scenarios.
|
|
40
40
|
*/
|
|
41
41
|
function detectPmtilesUrl() {
|
|
42
|
+
let scriptUrl = null;
|
|
43
|
+
|
|
42
44
|
// Try import.meta.url first (works in ESM environments)
|
|
43
45
|
try {
|
|
44
46
|
if (typeof import.meta !== 'undefined' && import.meta.url) {
|
|
45
|
-
|
|
46
|
-
// Some CDNs don't host static files, fall back to unpkg
|
|
47
|
-
if (shouldUseCdnFallback(moduleUrl.hostname)) {
|
|
48
|
-
return DEFAULT_CDN_URL;
|
|
49
|
-
}
|
|
50
|
-
return new URL(PMTILES_FILENAME, moduleUrl).href;
|
|
47
|
+
scriptUrl = import.meta.url;
|
|
51
48
|
}
|
|
52
49
|
} catch {
|
|
53
|
-
// import.meta not available
|
|
50
|
+
// import.meta not available
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Use captured currentScript.src (for IIFE/script tags)
|
|
54
|
+
if (!scriptUrl && CURRENT_SCRIPT_URL) {
|
|
55
|
+
scriptUrl = CURRENT_SCRIPT_URL;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (scriptUrl) {
|
|
59
|
+
const moduleUrl = new URL('.', scriptUrl);
|
|
60
|
+
// JS-only CDNs don't serve static files, fall back to default
|
|
61
|
+
if (FALLBACK_CDNS.has(moduleUrl.hostname)) {
|
|
62
|
+
return DEFAULT_CDN_URL;
|
|
63
|
+
}
|
|
64
|
+
return new URL(PMTILES_FILENAME, moduleUrl).href;
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
// Fallback to CDN with pinned version
|
|
57
|
-
// This ensures it works even when bundled into another package
|
|
58
68
|
return DEFAULT_CDN_URL;
|
|
59
69
|
}
|
|
60
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Resolve PMTiles URL from a given script URL.
|
|
73
|
+
* Useful for testing URL resolution logic.
|
|
74
|
+
* @param {string} scriptUrl - The script URL to resolve from
|
|
75
|
+
* @returns {string} The resolved PMTiles URL
|
|
76
|
+
*/
|
|
77
|
+
export function resolvePmtilesUrl(scriptUrl) {
|
|
78
|
+
const moduleUrl = new URL('.', scriptUrl);
|
|
79
|
+
// JS-only CDNs don't serve static files, fall back to default
|
|
80
|
+
if (FALLBACK_CDNS.has(moduleUrl.hostname)) {
|
|
81
|
+
return DEFAULT_CDN_URL;
|
|
82
|
+
}
|
|
83
|
+
return new URL(PMTILES_FILENAME, moduleUrl).href;
|
|
84
|
+
}
|
|
85
|
+
|
|
61
86
|
// Cache the detected URL
|
|
62
87
|
let cachedPmtilesUrl = null;
|
|
63
88
|
|
|
@@ -67,7 +92,7 @@ let cachedPmtilesUrl = null;
|
|
|
67
92
|
* Detection priority:
|
|
68
93
|
* 1. Manually set URL via setPmtilesUrl()
|
|
69
94
|
* 2. import.meta.url (ESM environments)
|
|
70
|
-
* 3.
|
|
95
|
+
* 3. jsDelivr CDN fallback (pinned to current version)
|
|
71
96
|
*
|
|
72
97
|
* For self-hosted deployments or custom bundling scenarios,
|
|
73
98
|
* use setPmtilesUrl().
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@india-boundary-corrector/data",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "PMTiles data for India boundary corrections (NE and OSM layers)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -41,5 +41,6 @@
|
|
|
41
41
|
"bugs": {
|
|
42
42
|
"url": "https://github.com/ramSeraph/india_boundary_corrector/issues"
|
|
43
43
|
},
|
|
44
|
-
"homepage": "https://github.com/ramSeraph/india_boundary_corrector#readme"
|
|
44
|
+
"homepage": "https://github.com/ramSeraph/india_boundary_corrector#readme",
|
|
45
|
+
"changelog": "https://github.com/ramSeraph/india_boundary_corrector/blob/main/packages/data/CHANGELOG.md"
|
|
45
46
|
}
|
package/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Auto-generated by scripts/generate-version.js - DO NOT EDIT
|
|
2
|
-
export const packageVersion = '0.0.
|
|
2
|
+
export const packageVersion = '0.0.4';
|