@dereekb/dbx-web 13.41.0 → 13.43.0

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,16 +1,16 @@
1
1
  {
2
2
  "name": "@dereekb/dbx-web/eslint",
3
- "version": "13.41.0",
3
+ "version": "13.43.0",
4
4
  "type": "module",
5
5
  "peerDependencies": {
6
- "@dereekb/util": "13.41.0",
6
+ "@dereekb/util": "13.43.0",
7
7
  "@typescript-eslint/utils": "8.59.3"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@angular-eslint/template-parser": "21.4.0",
11
11
  "@angular/core": "21.2.11",
12
- "@dereekb/dbx-core": "13.41.0",
13
- "@dereekb/rxjs": "13.41.0",
12
+ "@dereekb/dbx-core": "13.43.0",
13
+ "@dereekb/rxjs": "13.43.0",
14
14
  "@typescript-eslint/parser": "8.59.3",
15
15
  "eslint": "10.4.0",
16
16
  "rxjs": "^7.8.2"
@@ -1,10 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, Injectable, ChangeDetectionStrategy, Component, Directive, Optional, SkipSelf, Injector, output, viewChild, ElementRef, input, signal, effect, computed, NgModule, makeEnvironmentProviders } from '@angular/core';
2
+ import { inject, Injectable, ChangeDetectionStrategy, Component, Directive, Optional, SkipSelf, Injector, output, viewChild, ElementRef, input, signal, effect, computed, NgModule, provideAppInitializer, makeEnvironmentProviders } from '@angular/core';
3
3
  import { asObservable, cleanup, filterMaybe, onTrueToFalse, SubscriptionObject, distinctUntilMapHasDifferentKeys } from '@dereekb/rxjs';
4
4
  import { distinctUntilChanged, switchMap, map, combineLatestWith, shareReplay, NEVER, defaultIfEmpty, tap, EMPTY, interval, of, first, combineLatest, filter, startWith, throttleTime, Subject, merge, delay } from 'rxjs';
5
5
  import { latLngPoint, LAT_LONG_10M_PRECISION, latLngPointFunction, roundNumberToStepFunction, latLngBoundFunction, latLngBoundFromInput, filterUndefinedValues, diffLatLngBoundPoints, latLngBoundCenterPoint, addLatLngPoints, isSameLatLngPoint, isSameVector, vectorMinimumSizeResizeFunction, isSameLatLngBound, isDefaultLatLngPoint, swMostLatLngPoint, neMostLatLngPoint, latLngBoundWrapsMap, isWithinLatLngBoundFunction, overlapsLatLngBoundFunction, isNotFalse, DestroyFunctionObject, getValueFromGetter, pushItemOrArrayItemsIntoArray, spaceSeparatedCssClasses } from '@dereekb/util';
6
6
  import { ComponentStore } from '@ngrx/component-store';
7
- import { LngLatBounds } from 'mapbox-gl';
7
+ import mapboxgl, { LngLatBounds } from 'mapbox-gl';
8
8
  import { bounds } from '@placemarkio/geo-viewport';
9
9
  import { DbxInjectionArrayComponent, DbxInjectionComponent, completeOnDestroy, cleanSubscription, clean } from '@dereekb/dbx-core';
10
10
  import { toSignal, toObservable } from '@angular/core/rxjs-interop';
@@ -1344,14 +1344,77 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.11", ngImpo
1344
1344
  }]
1345
1345
  }] });
1346
1346
 
1347
+ /**
1348
+ * Relative url the mapbox-gl CSP web worker asset is expected to be served from.
1349
+ *
1350
+ * The asset itself is copied out of `node_modules/mapbox-gl/dist/mapbox-gl-csp-worker.js`
1351
+ * by the consuming app's build configuration, which keeps it in version lockstep with the
1352
+ * `mapbox-gl` the app actually bundles.
1353
+ */
1354
+ const DEFAULT_DBX_MAPBOX_WORKER_URL = 'assets/mapbox-gl/mapbox-gl-csp-worker.js';
1355
+ /**
1356
+ * Checks whether the mapbox-gl web worker asset is actually served from the given url.
1357
+ *
1358
+ * @param workerUrl - Url the worker asset is expected at.
1359
+ * @returns True when the asset responds successfully.
1360
+ */
1361
+ async function isDbxMapboxWorkerAssetAvailable(workerUrl) {
1362
+ let available;
1363
+ try {
1364
+ const response = await fetch(workerUrl, { method: 'HEAD' });
1365
+ available = response.ok;
1366
+ }
1367
+ catch {
1368
+ available = false;
1369
+ }
1370
+ return available;
1371
+ }
1372
+ /**
1373
+ * Configures mapbox-gl to load its web worker from a self-hosted copy of mapbox's prebuilt
1374
+ * CSP worker rather than from the blob url it generates itself.
1375
+ *
1376
+ * mapbox-gl's default worker is built by stringifying two of its own functions into a blob.
1377
+ * Only those function bodies are serialized, so any helper the bundler hoists to module
1378
+ * scope is missing at runtime. `@angular/build` unconditionally disables esbuild's
1379
+ * `object-rest-spread` support, which rewrites every object spread in mapbox-gl 3.26.0+ into
1380
+ * exactly such a hoisted helper, and the worker then dies with a `ReferenceError` while
1381
+ * loading tiles. Pointing `workerUrl` at a real file — mapbox's own documented CSP escape
1382
+ * hatch — sidesteps the bug entirely, at any mapbox-gl version.
1383
+ *
1384
+ * Must be applied before the first `Map` is constructed.
1385
+ *
1386
+ * @param inputConfig - Configuration. Optional.
1387
+ * @returns The applied configuration.
1388
+ */
1389
+ async function configureDbxMapboxWorker(inputConfig) {
1390
+ const config = inputConfig ?? {};
1391
+ let result;
1392
+ if (config.enabled === false || typeof window === 'undefined') {
1393
+ result = { configured: false, workerUrl: null, available: null };
1394
+ }
1395
+ else {
1396
+ const workerUrl = config.workerUrl || DEFAULT_DBX_MAPBOX_WORKER_URL;
1397
+ mapboxgl.workerUrl = workerUrl;
1398
+ const available = await isDbxMapboxWorkerAssetAvailable(workerUrl);
1399
+ if (!available) {
1400
+ console.error(`dbx-web/mapbox: the mapbox-gl web worker asset was not found at "${workerUrl}", so the map will fail to load tiles. Copy it into your app's assets by adding this entry to the build target's "assets" in project.json: { "input": "node_modules/mapbox-gl/dist", "glob": "mapbox-gl-csp-worker.js", "output": "assets/mapbox-gl" }`);
1401
+ }
1402
+ result = { configured: true, workerUrl, available };
1403
+ }
1404
+ return result;
1405
+ }
1406
+
1347
1407
  /**
1348
1408
  * Creates EnvironmentProviders for providing DbxMapboxConfig and configuring the NgxMapboxGLModule.
1349
1409
  *
1410
+ * Also registers an app initializer that points mapbox-gl at the self-hosted CSP web worker
1411
+ * asset before any map is created.
1412
+ *
1350
1413
  * @param config - Configuration.
1351
1414
  * @returns EnvironmentProviders.
1352
1415
  */
1353
1416
  function provideDbxMapbox(config) {
1354
- const { dbxMapboxConfig, ngxMapboxGLModuleConfig } = config;
1417
+ const { dbxMapboxConfig, ngxMapboxGLModuleConfig, worker } = config;
1355
1418
  const providers = [
1356
1419
  // config
1357
1420
  {
@@ -1360,6 +1423,8 @@ function provideDbxMapbox(config) {
1360
1423
  },
1361
1424
  // service
1362
1425
  DbxMapboxService,
1426
+ // worker: must be configured before the first Map is constructed
1427
+ provideAppInitializer(() => configureDbxMapboxWorker(worker)),
1363
1428
  // ngxMapboxGL
1364
1429
  provideMapboxGL(ngxMapboxGLModuleConfig)
1365
1430
  ];
@@ -1411,5 +1476,5 @@ function mapboxZoomLevel(input) {
1411
1476
  * Generated bundle index. Do not edit.
1412
1477
  */
1413
1478
 
1414
- export { DEFAULT_MAPBOX_CENTER, DEFAULT_MAPBOX_LAYOUT_DRAWER_WIDTH, DEFAULT_MAPBOX_MAP_STORE_TIMER_REFRESH_PERIOD, DEFAULT_MAPBOX_STYLE, DEFAULT_MAPBOX_ZOOM, DbxMapboxChangeService, DbxMapboxConfig, DbxMapboxInjectionComponent, DbxMapboxInjectionStore, DbxMapboxInjectionStoreInjectionBlockDirective, DbxMapboxInjectionStoreProviderBlock, DbxMapboxLayoutComponent, DbxMapboxLayoutDrawerComponent, DbxMapboxLayoutVirtualResizeSyncComponent, DbxMapboxMapDirective, DbxMapboxMapStore, DbxMapboxMapStoreInjectionBlockDirective, DbxMapboxMapStoreProviderBlock, DbxMapboxMarkerComponent, DbxMapboxMarkersComponent, DbxMapboxMenuComponent, DbxMapboxModule, DbxMapboxService, KNOWN_MAPBOX_STYLES, MAPBOX_MAX_ZOOM_LEVEL, MAPBOX_MIN_ZOOM_LEVEL, dbxMapboxColoredDotStyle, filterByMapboxViewportBound, mapboxViewportBoundFunction, mapboxZoomLevel, provideDbxMapbox, provideMapboxInjectionStoreIfParentIsUnavailable, provideMapboxStoreIfParentIsUnavailable, updateDbxMapboxMapInjectionStoreStateWithInjectionConfig, updateDbxMapboxMapInjectionStoreStateWithRemovedKey };
1479
+ export { DEFAULT_DBX_MAPBOX_WORKER_URL, DEFAULT_MAPBOX_CENTER, DEFAULT_MAPBOX_LAYOUT_DRAWER_WIDTH, DEFAULT_MAPBOX_MAP_STORE_TIMER_REFRESH_PERIOD, DEFAULT_MAPBOX_STYLE, DEFAULT_MAPBOX_ZOOM, DbxMapboxChangeService, DbxMapboxConfig, DbxMapboxInjectionComponent, DbxMapboxInjectionStore, DbxMapboxInjectionStoreInjectionBlockDirective, DbxMapboxInjectionStoreProviderBlock, DbxMapboxLayoutComponent, DbxMapboxLayoutDrawerComponent, DbxMapboxLayoutVirtualResizeSyncComponent, DbxMapboxMapDirective, DbxMapboxMapStore, DbxMapboxMapStoreInjectionBlockDirective, DbxMapboxMapStoreProviderBlock, DbxMapboxMarkerComponent, DbxMapboxMarkersComponent, DbxMapboxMenuComponent, DbxMapboxModule, DbxMapboxService, KNOWN_MAPBOX_STYLES, MAPBOX_MAX_ZOOM_LEVEL, MAPBOX_MIN_ZOOM_LEVEL, configureDbxMapboxWorker, dbxMapboxColoredDotStyle, filterByMapboxViewportBound, isDbxMapboxWorkerAssetAvailable, mapboxViewportBoundFunction, mapboxZoomLevel, provideDbxMapbox, provideMapboxInjectionStoreIfParentIsUnavailable, provideMapboxStoreIfParentIsUnavailable, updateDbxMapboxMapInjectionStoreStateWithInjectionConfig, updateDbxMapboxMapInjectionStoreStateWithRemovedKey };
1415
1480
  //# sourceMappingURL=dereekb-dbx-web-mapbox.mjs.map