@chrtco/sdk 0.6.0 → 0.7.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/CHANGELOG.md +7 -0
- package/dist/atlas/browser.cjs +276 -23
- package/dist/atlas/browser.cjs.map +1 -1
- package/dist/atlas/browser.d.cts +63 -1
- package/dist/atlas/browser.d.ts +63 -1
- package/dist/atlas/browser.js +271 -22
- package/dist/atlas/browser.js.map +1 -1
- package/dist/index.cjs +2555 -214
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -12
- package/dist/index.d.ts +266 -12
- package/dist/index.js +2544 -213
- package/dist/index.js.map +1 -1
- package/package.json +20 -3
package/dist/atlas/browser.d.cts
CHANGED
|
@@ -17,6 +17,68 @@ declare function loadS52SymbolImages(map: maplibregl.Map, colorTable?: ColorTabl
|
|
|
17
17
|
*/
|
|
18
18
|
declare function reloadS52SymbolImages(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Browser-only IndexedDB cache for S-52 symbol bitmaps.
|
|
22
|
+
*
|
|
23
|
+
* **First visit** — decodes 363 themed SVGs via the proven `new Image()` +
|
|
24
|
+
* `data:` URL path (identical to `./s52-svg-loader-browser`), adds them to
|
|
25
|
+
* the map immediately, AND in a non-blocking background task converts each
|
|
26
|
+
* decoded image to an `ImageBitmap` and persists it to IndexedDB keyed by
|
|
27
|
+
* `(atlasVersion, colorTable, symbolName)`.
|
|
28
|
+
*
|
|
29
|
+
* **Subsequent visits** — bulk-reads the bitmaps from IDB in a single
|
|
30
|
+
* transaction and `addImage`s them synchronously before any SVG parsing.
|
|
31
|
+
* The live-decode loop only runs for cache misses (atlas version mismatch,
|
|
32
|
+
* cleared storage, theme switch with no prior visit on that theme).
|
|
33
|
+
*
|
|
34
|
+
* **Hardening pass after PR #513**:
|
|
35
|
+
*
|
|
36
|
+
* - Originally tried `createImageBitmap(svgBlob)` — Chromium silently throws
|
|
37
|
+
* `InvalidStateError` for SVG inputs even though the function exists. The
|
|
38
|
+
* per-symbol catch swallowed the error and zero symbols got added to the
|
|
39
|
+
* map. Buoys / lights / beacons disappeared.
|
|
40
|
+
* - The fix is to NEVER let an SVG go through `createImageBitmap` directly.
|
|
41
|
+
* We decode via `new Image()` (which DOES handle SVG everywhere), then
|
|
42
|
+
* route the decoded image through a canvas → `createImageBitmap(canvas)`
|
|
43
|
+
* to get an IDB-storable bitmap. Canvas inputs to `createImageBitmap` are
|
|
44
|
+
* universally supported.
|
|
45
|
+
* - First-visit `addImage` happens off the HTMLImageElement, not the
|
|
46
|
+
* bitmap. The IDB persist is "best effort, never blocks the map" — any
|
|
47
|
+
* bitmap-conversion failure leaves the symbol on the map and just skips
|
|
48
|
+
* the cache write.
|
|
49
|
+
*
|
|
50
|
+
* Gracefully degrades to `loadS52SymbolImages` when IndexedDB is
|
|
51
|
+
* unavailable (private-mode lockdown, exotic browser).
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
interface LoadCachedOptions {
|
|
55
|
+
/**
|
|
56
|
+
* If true, skip the IDB read and force a full live-decode + repopulate.
|
|
57
|
+
* Theme is part of the key so this is rarely needed; left as an escape
|
|
58
|
+
* hatch.
|
|
59
|
+
*/
|
|
60
|
+
forceRefresh?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Stable atlas version, exposed for diagnostics and tests. */
|
|
63
|
+
declare function getS52AtlasVersion(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Drop-in replacement for `loadS52SymbolImages`. On first visit, decodes
|
|
66
|
+
* via the same `new Image()` path the live loader uses and persists each
|
|
67
|
+
* decoded symbol to IndexedDB in a non-blocking background task. On
|
|
68
|
+
* subsequent visits, bulk-hydrates from IDB before any SVG parsing.
|
|
69
|
+
*
|
|
70
|
+
* Falls back to `loadS52SymbolImages` when IndexedDB or canvas-to-bitmap
|
|
71
|
+
* conversion isn't available.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadS52SymbolImagesCached(map: maplibregl.Map, colorTable?: ColorTableName, opts?: LoadCachedOptions): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Theme-switch equivalent of `reloadS52SymbolImages` that routes through
|
|
76
|
+
* the IDB-backed path.
|
|
77
|
+
*/
|
|
78
|
+
declare function reloadS52SymbolImagesCached(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
79
|
+
/** Test/debug helper — wipes the entire bitmap store. */
|
|
80
|
+
declare function clearS52SymbolImageCache(): Promise<void>;
|
|
81
|
+
|
|
20
82
|
/**
|
|
21
83
|
* Browser-only nautical symbol image loaders. Sourced from `./symbols.ts`'s
|
|
22
84
|
* pure data; pushes themed icons into a MapLibre map via `new Image()` +
|
|
@@ -30,4 +92,4 @@ declare function loadSymbolImages(map: maplibregl.Map): Promise<void>;
|
|
|
30
92
|
*/
|
|
31
93
|
declare function loadThemedBridgeImages(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
32
94
|
|
|
33
|
-
export { loadS52SymbolImages, loadSymbolImages, loadThemedBridgeImages, reloadS52SymbolImages };
|
|
95
|
+
export { type LoadCachedOptions, clearS52SymbolImageCache, getS52AtlasVersion, loadS52SymbolImages, loadS52SymbolImagesCached, loadSymbolImages, loadThemedBridgeImages, reloadS52SymbolImages, reloadS52SymbolImagesCached };
|
package/dist/atlas/browser.d.ts
CHANGED
|
@@ -17,6 +17,68 @@ declare function loadS52SymbolImages(map: maplibregl.Map, colorTable?: ColorTabl
|
|
|
17
17
|
*/
|
|
18
18
|
declare function reloadS52SymbolImages(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Browser-only IndexedDB cache for S-52 symbol bitmaps.
|
|
22
|
+
*
|
|
23
|
+
* **First visit** — decodes 363 themed SVGs via the proven `new Image()` +
|
|
24
|
+
* `data:` URL path (identical to `./s52-svg-loader-browser`), adds them to
|
|
25
|
+
* the map immediately, AND in a non-blocking background task converts each
|
|
26
|
+
* decoded image to an `ImageBitmap` and persists it to IndexedDB keyed by
|
|
27
|
+
* `(atlasVersion, colorTable, symbolName)`.
|
|
28
|
+
*
|
|
29
|
+
* **Subsequent visits** — bulk-reads the bitmaps from IDB in a single
|
|
30
|
+
* transaction and `addImage`s them synchronously before any SVG parsing.
|
|
31
|
+
* The live-decode loop only runs for cache misses (atlas version mismatch,
|
|
32
|
+
* cleared storage, theme switch with no prior visit on that theme).
|
|
33
|
+
*
|
|
34
|
+
* **Hardening pass after PR #513**:
|
|
35
|
+
*
|
|
36
|
+
* - Originally tried `createImageBitmap(svgBlob)` — Chromium silently throws
|
|
37
|
+
* `InvalidStateError` for SVG inputs even though the function exists. The
|
|
38
|
+
* per-symbol catch swallowed the error and zero symbols got added to the
|
|
39
|
+
* map. Buoys / lights / beacons disappeared.
|
|
40
|
+
* - The fix is to NEVER let an SVG go through `createImageBitmap` directly.
|
|
41
|
+
* We decode via `new Image()` (which DOES handle SVG everywhere), then
|
|
42
|
+
* route the decoded image through a canvas → `createImageBitmap(canvas)`
|
|
43
|
+
* to get an IDB-storable bitmap. Canvas inputs to `createImageBitmap` are
|
|
44
|
+
* universally supported.
|
|
45
|
+
* - First-visit `addImage` happens off the HTMLImageElement, not the
|
|
46
|
+
* bitmap. The IDB persist is "best effort, never blocks the map" — any
|
|
47
|
+
* bitmap-conversion failure leaves the symbol on the map and just skips
|
|
48
|
+
* the cache write.
|
|
49
|
+
*
|
|
50
|
+
* Gracefully degrades to `loadS52SymbolImages` when IndexedDB is
|
|
51
|
+
* unavailable (private-mode lockdown, exotic browser).
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
interface LoadCachedOptions {
|
|
55
|
+
/**
|
|
56
|
+
* If true, skip the IDB read and force a full live-decode + repopulate.
|
|
57
|
+
* Theme is part of the key so this is rarely needed; left as an escape
|
|
58
|
+
* hatch.
|
|
59
|
+
*/
|
|
60
|
+
forceRefresh?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Stable atlas version, exposed for diagnostics and tests. */
|
|
63
|
+
declare function getS52AtlasVersion(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Drop-in replacement for `loadS52SymbolImages`. On first visit, decodes
|
|
66
|
+
* via the same `new Image()` path the live loader uses and persists each
|
|
67
|
+
* decoded symbol to IndexedDB in a non-blocking background task. On
|
|
68
|
+
* subsequent visits, bulk-hydrates from IDB before any SVG parsing.
|
|
69
|
+
*
|
|
70
|
+
* Falls back to `loadS52SymbolImages` when IndexedDB or canvas-to-bitmap
|
|
71
|
+
* conversion isn't available.
|
|
72
|
+
*/
|
|
73
|
+
declare function loadS52SymbolImagesCached(map: maplibregl.Map, colorTable?: ColorTableName, opts?: LoadCachedOptions): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Theme-switch equivalent of `reloadS52SymbolImages` that routes through
|
|
76
|
+
* the IDB-backed path.
|
|
77
|
+
*/
|
|
78
|
+
declare function reloadS52SymbolImagesCached(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
79
|
+
/** Test/debug helper — wipes the entire bitmap store. */
|
|
80
|
+
declare function clearS52SymbolImageCache(): Promise<void>;
|
|
81
|
+
|
|
20
82
|
/**
|
|
21
83
|
* Browser-only nautical symbol image loaders. Sourced from `./symbols.ts`'s
|
|
22
84
|
* pure data; pushes themed icons into a MapLibre map via `new Image()` +
|
|
@@ -30,4 +92,4 @@ declare function loadSymbolImages(map: maplibregl.Map): Promise<void>;
|
|
|
30
92
|
*/
|
|
31
93
|
declare function loadThemedBridgeImages(map: maplibregl.Map, colorTable: ColorTableName): Promise<void>;
|
|
32
94
|
|
|
33
|
-
export { loadS52SymbolImages, loadSymbolImages, loadThemedBridgeImages, reloadS52SymbolImages };
|
|
95
|
+
export { type LoadCachedOptions, clearS52SymbolImageCache, getS52AtlasVersion, loadS52SymbolImages, loadS52SymbolImagesCached, loadSymbolImages, loadThemedBridgeImages, reloadS52SymbolImages, reloadS52SymbolImagesCached };
|