@gooddata/sdk-ui-geo 11.62.0-alpha.1 → 11.62.0-alpha.2

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.
@@ -24,8 +24,8 @@ interface IMapInitializationOptions extends IMapOptions {
24
24
  * @remarks
25
25
  * This function handles the creation of a MapLibre GL map instance with all necessary
26
26
  * configuration. It dynamically imports maplibre-gl to avoid bundling issues, points MapLibre
27
- * at the worker script this package ships, sets up the map with safe default options, and
28
- * ensures glyphs are properly configured for text rendering.
27
+ * at the worker this package ships (see `mapWorker.ts`), sets up the map with safe default
28
+ * options, and ensures glyphs are properly configured for text rendering.
29
29
  *
30
30
  * @param options - Map initialization options including container, center, zoom, bounds, etc.
31
31
  * @param locale - Optional MapLibre locale configuration for cooperative gestures
@@ -1 +1 @@
1
- {"version":3,"file":"mapInitialization.d.ts","sourceRoot":"","sources":["../../../../src/next/map/runtime/mapInitialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EAGR,GAAG,IAAI,WAAW,EAElB,KAAK,EACR,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAKhE,OAAO,EAGH,KAAK,sBAAsB,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,GAAG,EAAE,WAAW,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IAEf,UAAU,EAAE,cAAc,aAAa,CAAC,CAAC;CAC5C;AAED,UAAU,yBAA0B,SAAQ,WAAW;IACnD,UAAU,CAAC,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAClD,eAAe,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACvC,EACI,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,EACN,aAAa,EACb,WAAkB,EAClB,UAAU,EACV,eAAe,EACf,eAAe,EACf,UAAU,EACV,6BAAoC,EACpC,qBAA6B,EAC7B,mBAA0B,EAC1B,OAAO,EACP,KAAK,EACL,OAAO,EACP,QAAQ,GACX,EAAE,yBAAyB,EAC5B,MAAM,CAAC,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,kBAAkB,GAC7B,OAAO,CAAC,cAAc,CAAC,CA6HzB"}
1
+ {"version":3,"file":"mapInitialization.d.ts","sourceRoot":"","sources":["../../../../src/next/map/runtime/mapInitialization.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EAGR,GAAG,IAAI,WAAW,EAElB,KAAK,EACR,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAKhE,OAAO,EAGH,KAAK,sBAAsB,EAE9B,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,GAAG,EAAE,WAAW,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;IAEf,UAAU,EAAE,cAAc,aAAa,CAAC,CAAC;CAC5C;AAED,UAAU,yBAA0B,SAAQ,WAAW;IACnD,UAAU,CAAC,EAAE,sBAAsB,CAAC,YAAY,CAAC,CAAC;IAClD,eAAe,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,sBAAsB,CAAC,iBAAiB,CAAC,CAAC;CAC/D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,qBAAqB,CACvC,EACI,SAAS,EACT,MAAM,EACN,IAAI,EACJ,MAAM,EACN,aAAa,EACb,WAAkB,EAClB,UAAU,EACV,eAAe,EACf,eAAe,EACf,UAAU,EACV,6BAAoC,EACpC,qBAA6B,EAC7B,mBAA0B,EAC1B,OAAO,EACP,KAAK,EACL,OAAO,EACP,QAAQ,GACX,EAAE,yBAAyB,EAC5B,MAAM,CAAC,EAAE,eAAe,EACxB,OAAO,CAAC,EAAE,kBAAkB,GAC7B,OAAO,CAAC,cAAc,CAAC,CA8HzB"}
@@ -10,8 +10,8 @@ import { ensureMapLibreWorkerUrl } from "./mapWorker.js";
10
10
  * @remarks
11
11
  * This function handles the creation of a MapLibre GL map instance with all necessary
12
12
  * configuration. It dynamically imports maplibre-gl to avoid bundling issues, points MapLibre
13
- * at the worker script this package ships, sets up the map with safe default options, and
14
- * ensures glyphs are properly configured for text rendering.
13
+ * at the worker this package ships (see `mapWorker.ts`), sets up the map with safe default
14
+ * options, and ensures glyphs are properly configured for text rendering.
15
15
  *
16
16
  * @param options - Map initialization options including container, center, zoom, bounds, etc.
17
17
  * @param locale - Optional MapLibre locale configuration for cooperative gestures
@@ -21,8 +21,10 @@ import { ensureMapLibreWorkerUrl } from "./mapWorker.js";
21
21
  */
22
22
  export async function initializeMapLibreMap({ container, center, zoom, bounds, boundsPadding, interactive = true, dragRotate, pitchWithRotate, touchZoomRotate, navigation, enableGeoChartsViewportConfig = true, preserveDrawingBuffer = false, cooperativeGestures = true, maxZoom, style, basemap, language, }, locale, backend) {
23
23
  const maplibregl = await import("maplibre-gl");
24
- ensureMapLibreWorkerUrl(maplibregl);
25
- const styleSpecification = style ?? (backend ? await fetchMapStyle(backend, basemap, language) : undefined);
24
+ const [styleSpecification] = await Promise.all([
25
+ style ?? (backend ? fetchMapStyle(backend, basemap, language) : undefined),
26
+ ensureMapLibreWorkerUrl(maplibregl),
27
+ ]);
26
28
  if (!styleSpecification) {
27
29
  throw new Error("Map style is required. Provide either a style option or a backend instance.");
28
30
  }
@@ -9,30 +9,52 @@ export interface IMapLibreWorkerConfig {
9
9
  setWorkerUrl: (url: string) => void;
10
10
  }
11
11
  /**
12
- * URL of the self-contained MapLibre worker script that this package ships.
12
+ * URL of the self-contained MapLibre worker file that this package ships, relative to this module.
13
13
  *
14
14
  * @remarks
15
15
  * maplibre-gl 6 does not inline its web worker. It resolves `maplibre-gl-worker.mjs` next to its
16
- * own module through `import.meta.url`, which does not survive bundling: Vite emits no worker file
17
- * and webpack replaces `import.meta.url` with a build-time `file:` path. The build of this package
16
+ * own module through `import.meta.url`, which does not survive bundling. The build of this package
18
17
  * bundles the worker and its shared chunk into `worker/maplibre-gl-worker.js` (see
19
18
  * `scripts/build.sh`), and this URL points at that file relative to this module.
20
19
  *
21
20
  * The relative path is the same from `src/next/map/runtime/` and from `esm/next/map/runtime/`, so
22
- * it also holds when a dev server aliases this package to its sources. Bundlers recognise the
23
- * `new URL("...", import.meta.url)` pattern and emit the file as an asset.
21
+ * it also holds when a dev server aliases this package to its sources. webpack and Vite recognise
22
+ * the `new URL("...", import.meta.url)` pattern and emit the file as an asset. Other bundlers do
23
+ * not: esbuild leaves a URL that resolves next to the bundle and does not exist, and webpack with
24
+ * `parser.javascript.url: false` (Angular CLI) inlines a build-time `file:` URL. The URL must
25
+ * therefore be checked before MapLibre uses it, see {@link resolveMapLibreWorkerUrl}.
24
26
  *
25
27
  * @internal
26
28
  */
27
29
  export declare function getBundledMapLibreWorkerUrl(): string;
28
30
  /**
29
- * Points MapLibre at the bundled worker unless a worker URL is configured already.
31
+ * Resolves the URL MapLibre starts its worker from: the bundled worker file when the bundler
32
+ * emitted it next to the page, the inline worker otherwise.
33
+ *
34
+ * @param assetUrl - URL of the bundled worker file, defaults to {@link getBundledMapLibreWorkerUrl}
35
+ * @internal
36
+ */
37
+ export declare function resolveMapLibreWorkerUrl(assetUrl?: string): Promise<string>;
38
+ /**
39
+ * Creates the function that points MapLibre at a worker unless a worker URL is configured already.
30
40
  *
31
41
  * @remarks
32
- * The worker URL is global to the maplibre-gl module. A consumer that called `setWorkerUrl`
33
- * before the first map is created keeps its own worker.
42
+ * The worker URL is global to the maplibre-gl module. A consumer that called maplibre's own
43
+ * `setWorkerUrl` before the first map is created keeps its own worker; this is also the way to
44
+ * host the worker file yourself on a page whose content security policy does not allow `blob:`
45
+ * workers. Otherwise the bundled worker is resolved once and shared by all maps, which is why the
46
+ * cache lives in the created function: tests create their own, the runtime uses
47
+ * {@link ensureMapLibreWorkerUrl}.
48
+ *
49
+ * @param resolveWorkerUrl - resolves the URL of the worker this package ships
50
+ * @internal
51
+ */
52
+ export declare function createMapLibreWorkerUrlEnsurer(resolveWorkerUrl?: () => Promise<string>): (maplibregl: IMapLibreWorkerConfig) => Promise<void>;
53
+ /**
54
+ * Points MapLibre at a worker unless a worker URL is configured already, see
55
+ * {@link createMapLibreWorkerUrlEnsurer}.
34
56
  *
35
57
  * @internal
36
58
  */
37
- export declare function ensureMapLibreWorkerUrl(maplibregl: IMapLibreWorkerConfig): void;
59
+ export declare const ensureMapLibreWorkerUrl: (maplibregl: IMapLibreWorkerConfig) => Promise<void>;
38
60
  //# sourceMappingURL=mapWorker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mapWorker.d.ts","sourceRoot":"","sources":["../../../../src/next/map/runtime/mapWorker.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IAClC,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,qBAAqB,GAAG,IAAI,CAM/E"}
1
+ {"version":3,"file":"mapWorker.d.ts","sourceRoot":"","sources":["../../../../src/next/map/runtime/mapWorker.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IAClC,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,2BAA2B,IAAI,MAAM,CAEpD;AAwDD;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC1C,QAAQ,GAAE,MAAsC,GACjD,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,8BAA8B,CAC1C,gBAAgB,GAAE,MAAM,OAAO,CAAC,MAAM,CAA4B,GACnE,CAAC,UAAU,EAAE,qBAAqB,KAAK,OAAO,CAAC,IAAI,CAAC,CAoBtD;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,eA5BpB,qBAAqB,KAAK,OAAO,CAAC,IAAI,CA4BiB,CAAC"}
@@ -1,17 +1,19 @@
1
1
  // (C) 2026 GoodData Corporation
2
2
  /**
3
- * URL of the self-contained MapLibre worker script that this package ships.
3
+ * URL of the self-contained MapLibre worker file that this package ships, relative to this module.
4
4
  *
5
5
  * @remarks
6
6
  * maplibre-gl 6 does not inline its web worker. It resolves `maplibre-gl-worker.mjs` next to its
7
- * own module through `import.meta.url`, which does not survive bundling: Vite emits no worker file
8
- * and webpack replaces `import.meta.url` with a build-time `file:` path. The build of this package
7
+ * own module through `import.meta.url`, which does not survive bundling. The build of this package
9
8
  * bundles the worker and its shared chunk into `worker/maplibre-gl-worker.js` (see
10
9
  * `scripts/build.sh`), and this URL points at that file relative to this module.
11
10
  *
12
11
  * The relative path is the same from `src/next/map/runtime/` and from `esm/next/map/runtime/`, so
13
- * it also holds when a dev server aliases this package to its sources. Bundlers recognise the
14
- * `new URL("...", import.meta.url)` pattern and emit the file as an asset.
12
+ * it also holds when a dev server aliases this package to its sources. webpack and Vite recognise
13
+ * the `new URL("...", import.meta.url)` pattern and emit the file as an asset. Other bundlers do
14
+ * not: esbuild leaves a URL that resolves next to the bundle and does not exist, and webpack with
15
+ * `parser.javascript.url: false` (Angular CLI) inlines a build-time `file:` URL. The URL must
16
+ * therefore be checked before MapLibre uses it, see {@link resolveMapLibreWorkerUrl}.
15
17
  *
16
18
  * @internal
17
19
  */
@@ -19,17 +21,95 @@ export function getBundledMapLibreWorkerUrl() {
19
21
  return new URL("../../../../worker/maplibre-gl-worker.js", import.meta.url).href;
20
22
  }
21
23
  /**
22
- * Points MapLibre at the bundled worker unless a worker URL is configured already.
24
+ * Tells whether MapLibre can start the worker from the URL directly: the URL is a same-origin
25
+ * `http(s)` URL and the server has the file as JavaScript.
23
26
  *
24
27
  * @remarks
25
- * The worker URL is global to the maplibre-gl module. A consumer that called `setWorkerUrl`
26
- * before the first map is created keeps its own worker.
28
+ * A cross-origin worker is not used even when it exists: MapLibre starts such a worker through an
29
+ * importing Blob, which needs `blob:` in the content security policy anyway, and webpack breaks
30
+ * that code path. The inline Blob worker is the better choice there.
27
31
  *
28
- * @internal
32
+ * The MIME type is checked because single-page application servers often answer a missing file
33
+ * with `index.html` and status 200, and browsers do not start a module worker from HTML.
29
34
  */
30
- export function ensureMapLibreWorkerUrl(maplibregl) {
31
- if (maplibregl.getWorkerUrl()) {
32
- return;
35
+ async function isReachableSameOriginScript(url) {
36
+ const pageOrigin = typeof location === "undefined" ? undefined : location.origin;
37
+ if (!pageOrigin) {
38
+ return false;
39
+ }
40
+ let parsed;
41
+ try {
42
+ parsed = new URL(url);
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ if (!/^https?:$/.test(parsed.protocol) || parsed.origin !== pageOrigin) {
48
+ return false;
49
+ }
50
+ try {
51
+ const response = await fetch(url, { method: "HEAD" });
52
+ return (response.ok &&
53
+ /^(text|application)\/(javascript|ecmascript)\b/.test(response.headers.get("content-type") ?? ""));
54
+ }
55
+ catch {
56
+ return false;
33
57
  }
34
- maplibregl.setWorkerUrl(getBundledMapLibreWorkerUrl());
35
58
  }
59
+ /**
60
+ * Starts the worker from the worker code this package ships inline. The Blob URL carries the
61
+ * origin of the page, so MapLibre starts it directly. The URL is never revoked: MapLibre creates
62
+ * its workers lazily and the one Blob lives as long as the page.
63
+ */
64
+ async function createInlineWorkerUrl() {
65
+ const { default: source } = await import("../../../../worker/maplibre-gl-worker.source.js");
66
+ return URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
67
+ }
68
+ /**
69
+ * Resolves the URL MapLibre starts its worker from: the bundled worker file when the bundler
70
+ * emitted it next to the page, the inline worker otherwise.
71
+ *
72
+ * @param assetUrl - URL of the bundled worker file, defaults to {@link getBundledMapLibreWorkerUrl}
73
+ * @internal
74
+ */
75
+ export async function resolveMapLibreWorkerUrl(assetUrl = getBundledMapLibreWorkerUrl()) {
76
+ return (await isReachableSameOriginScript(assetUrl)) ? assetUrl : createInlineWorkerUrl();
77
+ }
78
+ /**
79
+ * Creates the function that points MapLibre at a worker unless a worker URL is configured already.
80
+ *
81
+ * @remarks
82
+ * The worker URL is global to the maplibre-gl module. A consumer that called maplibre's own
83
+ * `setWorkerUrl` before the first map is created keeps its own worker; this is also the way to
84
+ * host the worker file yourself on a page whose content security policy does not allow `blob:`
85
+ * workers. Otherwise the bundled worker is resolved once and shared by all maps, which is why the
86
+ * cache lives in the created function: tests create their own, the runtime uses
87
+ * {@link ensureMapLibreWorkerUrl}.
88
+ *
89
+ * @param resolveWorkerUrl - resolves the URL of the worker this package ships
90
+ * @internal
91
+ */
92
+ export function createMapLibreWorkerUrlEnsurer(resolveWorkerUrl = resolveMapLibreWorkerUrl) {
93
+ let resolvedWorkerUrl;
94
+ return async (maplibregl) => {
95
+ if (maplibregl.getWorkerUrl()) {
96
+ return;
97
+ }
98
+ resolvedWorkerUrl ??= resolveWorkerUrl().catch((error) => {
99
+ resolvedWorkerUrl = undefined;
100
+ throw error;
101
+ });
102
+ const workerUrl = await resolvedWorkerUrl;
103
+ // the consumer can configure its own worker while the bundled one is being resolved
104
+ if (!maplibregl.getWorkerUrl()) {
105
+ maplibregl.setWorkerUrl(workerUrl);
106
+ }
107
+ };
108
+ }
109
+ /**
110
+ * Points MapLibre at a worker unless a worker URL is configured already, see
111
+ * {@link createMapLibreWorkerUrlEnsurer}.
112
+ *
113
+ * @internal
114
+ */
115
+ export const ensureMapLibreWorkerUrl = createMapLibreWorkerUrlEnsurer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gooddata/sdk-ui-geo",
3
- "version": "11.62.0-alpha.1",
3
+ "version": "11.62.0-alpha.2",
4
4
  "description": "GoodData.UI SDK - Geo Charts",
5
5
  "license": "MIT",
6
6
  "author": "GoodData Corporation",
@@ -44,12 +44,12 @@
44
44
  "ts-invariant": "0.10.3",
45
45
  "tslib": "2.8.1",
46
46
  "uuid": "11.1.1",
47
- "@gooddata/sdk-backend-spi": "11.62.0-alpha.1",
48
- "@gooddata/sdk-model": "11.62.0-alpha.1",
49
- "@gooddata/sdk-ui-kit": "11.62.0-alpha.1",
50
- "@gooddata/sdk-ui-theme-provider": "11.62.0-alpha.1",
51
- "@gooddata/sdk-ui-vis-commons": "11.62.0-alpha.1",
52
- "@gooddata/sdk-ui": "11.62.0-alpha.1"
47
+ "@gooddata/sdk-model": "11.62.0-alpha.2",
48
+ "@gooddata/sdk-ui": "11.62.0-alpha.2",
49
+ "@gooddata/sdk-backend-spi": "11.62.0-alpha.2",
50
+ "@gooddata/sdk-ui-kit": "11.62.0-alpha.2",
51
+ "@gooddata/sdk-ui-vis-commons": "11.62.0-alpha.2",
52
+ "@gooddata/sdk-ui-theme-provider": "11.62.0-alpha.2"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@microsoft/api-documenter": "7.30.16",
@@ -88,10 +88,10 @@
88
88
  "typescript": "7.0.2",
89
89
  "vitest": "4.1.11",
90
90
  "vitest-dom": "0.1.1",
91
- "@gooddata/eslint-config": "11.62.0-alpha.1",
92
- "@gooddata/oxlint-config": "11.62.0-alpha.1",
93
- "@gooddata/stylelint-config": "11.62.0-alpha.1",
94
- "@gooddata/sdk-backend-mockingbird": "11.62.0-alpha.1"
91
+ "@gooddata/eslint-config": "11.62.0-alpha.2",
92
+ "@gooddata/oxlint-config": "11.62.0-alpha.2",
93
+ "@gooddata/sdk-backend-mockingbird": "11.62.0-alpha.2",
94
+ "@gooddata/stylelint-config": "11.62.0-alpha.2"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "react": "^18.0.0 || ^19.0.0",