@classic-homes/maps-core 0.2.6 → 0.2.8

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/dist/index.js CHANGED
@@ -583,6 +583,86 @@ function formatFeatureProperties(properties, options) {
583
583
  function formatLabel(key) {
584
584
  return key.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\b\w/g, (char) => char.toUpperCase());
585
585
  }
586
+ function isValidLongitude(lng) {
587
+ return typeof lng === "number" && isFinite(lng) && lng >= -180 && lng <= 180;
588
+ }
589
+ function isValidLatitude(lat) {
590
+ return typeof lat === "number" && isFinite(lat) && lat >= -90 && lat <= 90;
591
+ }
592
+ function validateCoordinates(coordinates) {
593
+ if (!Array.isArray(coordinates)) {
594
+ return { valid: false, error: "Coordinates must be an array" };
595
+ }
596
+ if (coordinates.length < 2) {
597
+ return { valid: false, error: "Coordinates must have at least 2 elements [lng, lat]" };
598
+ }
599
+ const [lng, lat] = coordinates;
600
+ if (typeof lng !== "number" || typeof lat !== "number") {
601
+ return { valid: false, error: "Longitude and latitude must be numbers" };
602
+ }
603
+ if (!isFinite(lng) || !isFinite(lat)) {
604
+ return { valid: false, error: "Coordinates must be finite numbers" };
605
+ }
606
+ if (lng < -180 || lng > 180) {
607
+ return { valid: false, error: `Longitude ${lng} out of range [-180, 180]` };
608
+ }
609
+ if (lat < -90 || lat > 90) {
610
+ return { valid: false, error: `Latitude ${lat} out of range [-90, 90]` };
611
+ }
612
+ return {
613
+ valid: true,
614
+ normalized: [lng, lat]
615
+ };
616
+ }
617
+ function ensureValidCoordinates(coordinates) {
618
+ const result = validateCoordinates(coordinates);
619
+ if (!result.valid) {
620
+ throw new Error(`Invalid coordinates: ${result.error}`);
621
+ }
622
+ return result.normalized;
623
+ }
624
+ function normalizeLongitude(lng) {
625
+ if (!isFinite(lng)) return NaN;
626
+ let normalized = lng % 360;
627
+ if (normalized > 180) {
628
+ normalized -= 360;
629
+ } else if (normalized < -180) {
630
+ normalized += 360;
631
+ }
632
+ return normalized;
633
+ }
634
+ function clampLatitude(lat) {
635
+ if (!isFinite(lat)) return NaN;
636
+ return Math.max(-90, Math.min(90, lat));
637
+ }
638
+ function validateBoundsArray(bounds) {
639
+ if (!Array.isArray(bounds)) {
640
+ return { valid: false, error: "Bounds must be an array" };
641
+ }
642
+ if (bounds.length !== 2) {
643
+ return { valid: false, error: "Bounds must have exactly 2 elements [southwest, northeast]" };
644
+ }
645
+ const swResult = validateCoordinates(bounds[0]);
646
+ if (!swResult.valid) {
647
+ return { valid: false, error: `Invalid southwest corner: ${swResult.error}` };
648
+ }
649
+ const neResult = validateCoordinates(bounds[1]);
650
+ if (!neResult.valid) {
651
+ return { valid: false, error: `Invalid northeast corner: ${neResult.error}` };
652
+ }
653
+ const [, swLat] = swResult.normalized;
654
+ const [, neLat] = neResult.normalized;
655
+ if (swLat > neLat) {
656
+ return {
657
+ valid: false,
658
+ error: `Southwest latitude (${swLat}) must be less than northeast latitude (${neLat})`
659
+ };
660
+ }
661
+ return {
662
+ valid: true,
663
+ normalized: [swResult.normalized, neResult.normalized]
664
+ };
665
+ }
586
666
 
587
667
  // src/utils/bounds.ts
588
668
  function calculateBounds(geojson) {
@@ -835,13 +915,15 @@ function validateGeometry(geometry, prefix = "") {
835
915
  errors.push(`${p}: unknown geometry type "${geometry.type}"`);
836
916
  return errors;
837
917
  }
838
- if (!geometry.coordinates) {
839
- errors.push(`${p}: missing coordinates`);
840
- return errors;
841
- }
842
- if (!Array.isArray(geometry.coordinates)) {
843
- errors.push(`${p}: coordinates must be an array`);
844
- return errors;
918
+ if (geometry.type !== "GeometryCollection") {
919
+ if (!("coordinates" in geometry) || geometry.coordinates === void 0) {
920
+ errors.push(`${p}: missing coordinates`);
921
+ return errors;
922
+ }
923
+ if (!Array.isArray(geometry.coordinates)) {
924
+ errors.push(`${p}: coordinates must be an array`);
925
+ return errors;
926
+ }
845
927
  }
846
928
  switch (geometry.type) {
847
929
  case "Point":
@@ -866,6 +948,20 @@ function validateGeometry(geometry, prefix = "") {
866
948
  errors.push(`${p}: MultiPolygon must have at least one polygon`);
867
949
  }
868
950
  break;
951
+ case "GeometryCollection": {
952
+ const geomCollection = geometry;
953
+ if (!("geometries" in geometry)) {
954
+ errors.push(`${p}: GeometryCollection must have "geometries" array`);
955
+ } else if (!Array.isArray(geomCollection.geometries)) {
956
+ errors.push(`${p}: GeometryCollection "geometries" must be an array`);
957
+ } else {
958
+ geomCollection.geometries.forEach((geom, idx) => {
959
+ const nestedErrors = validateGeometry(geom, `${p}.geometries[${idx}]`);
960
+ errors.push(...nestedErrors);
961
+ });
962
+ }
963
+ break;
964
+ }
869
965
  }
870
966
  return errors;
871
967
  }
@@ -1015,6 +1111,83 @@ async function expandClusterToBounds(map, sourceId, clusterId, options = {}) {
1015
1111
  ...maxZoom !== void 0 && { maxZoom }
1016
1112
  });
1017
1113
  }
1114
+ function createClusterStyles(options = {}) {
1115
+ const {
1116
+ smallColor = "#51bbd6",
1117
+ mediumColor = "#f1f075",
1118
+ largeColor = "#f28cb1",
1119
+ mediumThreshold = 100,
1120
+ largeThreshold = 750,
1121
+ smallRadius = 20,
1122
+ mediumRadius = 30,
1123
+ largeRadius = 40,
1124
+ strokeColor = "#fff",
1125
+ strokeWidth = 2,
1126
+ opacity = 0.85
1127
+ } = options.circle ?? {};
1128
+ const {
1129
+ textColor = "#333",
1130
+ textSize = 12,
1131
+ fontStack = ["Open Sans Bold", "Arial Unicode MS Bold"],
1132
+ abbreviated = false
1133
+ } = options.text ?? {};
1134
+ const {
1135
+ color: pointColor = "#11b4da",
1136
+ radius: pointRadius = 8,
1137
+ strokeColor: pointStrokeColor = "#fff",
1138
+ strokeWidth: pointStrokeWidth = 1
1139
+ } = options.unclusteredPoint ?? {};
1140
+ return {
1141
+ clusterCirclePaint: {
1142
+ "circle-color": [
1143
+ "step",
1144
+ ["get", "point_count"],
1145
+ smallColor,
1146
+ mediumThreshold,
1147
+ mediumColor,
1148
+ largeThreshold,
1149
+ largeColor
1150
+ ],
1151
+ "circle-radius": [
1152
+ "step",
1153
+ ["get", "point_count"],
1154
+ smallRadius,
1155
+ mediumThreshold,
1156
+ mediumRadius,
1157
+ largeThreshold,
1158
+ largeRadius
1159
+ ],
1160
+ "circle-stroke-color": strokeColor,
1161
+ "circle-stroke-width": strokeWidth,
1162
+ "circle-opacity": opacity
1163
+ },
1164
+ clusterTextPaint: {
1165
+ "text-color": textColor
1166
+ },
1167
+ clusterTextLayout: {
1168
+ "text-field": abbreviated ? ["get", "point_count_abbreviated"] : ["to-string", ["get", "point_count"]],
1169
+ "text-font": fontStack,
1170
+ "text-size": textSize,
1171
+ "text-allow-overlap": true
1172
+ },
1173
+ unclusteredPointPaint: {
1174
+ "circle-color": pointColor,
1175
+ "circle-radius": pointRadius,
1176
+ "circle-stroke-color": pointStrokeColor,
1177
+ "circle-stroke-width": pointStrokeWidth
1178
+ },
1179
+ clusterFilter: ["has", "point_count"],
1180
+ unclusteredFilter: ["!", ["has", "point_count"]]
1181
+ };
1182
+ }
1183
+ function createClusterCirclePaint(options = {}) {
1184
+ const styles = createClusterStyles({ circle: options });
1185
+ return styles.clusterCirclePaint;
1186
+ }
1187
+ function createClusterTextLayout(options = {}) {
1188
+ const styles = createClusterStyles({ text: options });
1189
+ return styles.clusterTextLayout;
1190
+ }
1018
1191
 
1019
1192
  // src/utils/lod.ts
1020
1193
  function groupFeaturesByProperty(geojson, options) {
@@ -3837,4 +4010,4 @@ function createMatchedColorExpression(baseColorExpression, matchedProperty = "ma
3837
4010
  ];
3838
4011
  }
3839
4012
 
3840
- export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, CLASSIC_DARK, CLASSIC_LIGHT, DEFAULT_BASEMAP, DEFAULT_SIMPLIFICATION_THRESHOLDS, EDGE_MARGIN, FLOOD_ZONES, FREE_BASEMAPS, KEYBOARD_CONTROLS, MAPTILER_BASIC, MAPTILER_OUTDOOR, MAPTILER_SATELLITE, MAPTILER_STREETS, MARKER_PROTECTION_CLASS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, PRIORITY_ORDER, PositioningCoordinator, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, STACK_GAP, STADIA_ALIDADE_DARK, STADIA_ALIDADE_SMOOTH, STADIA_STAMEN_TERRAIN, STADIA_STAMEN_TONER, STADIA_STAMEN_WATERCOLOR, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, Z_INDEX_LAYERS, applyMarkerChildProtection, applyMarkerProtection, boundaryColors, boundsToPolygon, buildRTreeIndex, buildSpatialIndex, calculateBounds, calculateCentroid, calculateZoomThresholds, clusterColorExpression, clusterColors, combineBounds, countFeaturesByType, createCategoricalColorExpression, createCircleStyle, createContinuousColorExpression, createDynamicLODManager, createExtrusionHeightExpression, createExtrusionStyle, createFillStyle, createGeoJSONFingerprint, createHeatmapStyle, createHoverExpression, createIdleViewportManager, createInitialLayerStates, createInteractiveExpression, createInteractiveStatusColorExpression, createLineStyle, createLotFillStyle, createLotOutlineStyle, createMatchedColorExpression, createPositioningCoordinator, createPredictiveViewportManager, createRTreeViewportManager, createSelectionExpression, createStatusColorExpression, createViewportManager, createViewportQuery, createZoomExpression, decimalToDMS, deepEqual, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, filterEqual, fingerprintEqual, formatArea, formatBearing, formatBounds, formatCoordinates, formatDistance, formatFeatureProperties, formatLabel, formatPitch, formatPropertyValue, formatScale, formatZoom, generateBoundingPolygon, generateConvexHull, generateFeatureCollectionDescription, generateFeatureTable, generateKeyboardControlsDescription, generateLODData, generateLODDataWithSimplification, generateMapDescription, generateMarkerList, generateMarkersDescription, generateMoveAnnouncement, geoJSONEqual, getAvailabilityColor, getAvailableBasemaps, getChangedPaintProps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getContrastTextColor, getHighlightStyle, getLayerCategories, getLayerStatesArray, getLayerStyleForTheme, getLayersByCategory, getLayersWithErrors, getSelectionStyle, getSimplificationToleranceForZoom, getSimplifiedFeaturesForZoom, getSizeColor, getVisibleLayerIds, groupFeaturesByProperty, groupLayersByCategory, hideAllLayers, inventoryStatusColorExpression, inventoryStatusColors, isAnyLayerLoading, isClusterFeature, isValidBounds, loadGeoJSON, lotAvailabilityColorExpression, lotAvailabilityColors, lotSizeColorExpression, lotSizeColors, nonMatchedColor, paintPropsEqual, queryByBounds, queryByBoundsWithStats, queryRTreeByBounds, queryRTreeByBoundsWithStats, removeMarkerProtection, reorderLayers, resolveBasemapStyle, resolveBasemapThumbnail, resolveLayerSourceUrl, salesOfficeColor, searchLayers, serializeFilter, setLayerError, setLayerLoading, setLayerOpacity, showAllLayers, simplifyFeature, simplifyFeatureCollection, simplifyFeatureCollectionWithStats, simplifyPolygon, toggleLayerVisibility, updateLayerState, validateGeoJSON, zoomToScale };
4013
+ export { BIKE_LANES, BUILTIN_BASEMAPS, BUILTIN_OVERLAY_LAYERS, CATEGORY_META, CITY_LIMITS, CLASSIC_DARK, CLASSIC_LIGHT, DEFAULT_BASEMAP, DEFAULT_SIMPLIFICATION_THRESHOLDS, EDGE_MARGIN, FLOOD_ZONES, FREE_BASEMAPS, KEYBOARD_CONTROLS, MAPTILER_BASIC, MAPTILER_OUTDOOR, MAPTILER_SATELLITE, MAPTILER_STREETS, MARKER_PROTECTION_CLASS, OSM_STANDARD, PARKS, PRIMARY_BASEMAPS, PRIORITY_ORDER, PositioningCoordinator, SATELLITE_BASEMAP, SCHOOL_DISTRICTS, SPORTS_FACILITIES, STACK_GAP, STADIA_ALIDADE_DARK, STADIA_ALIDADE_SMOOTH, STADIA_STAMEN_TERRAIN, STADIA_STAMEN_TONER, STADIA_STAMEN_WATERCOLOR, TOPO_BASEMAP, TRAILS, TRANSIT_ROUTES, WATERSHEDS, ZONING_DISTRICTS, Z_INDEX_LAYERS, applyMarkerChildProtection, applyMarkerProtection, boundaryColors, boundsToPolygon, buildRTreeIndex, buildSpatialIndex, calculateBounds, calculateCentroid, calculateZoomThresholds, clampLatitude, clusterColorExpression, clusterColors, combineBounds, countFeaturesByType, createCategoricalColorExpression, createCircleStyle, createClusterCirclePaint, createClusterStyles, createClusterTextLayout, createContinuousColorExpression, createDynamicLODManager, createExtrusionHeightExpression, createExtrusionStyle, createFillStyle, createGeoJSONFingerprint, createHeatmapStyle, createHoverExpression, createIdleViewportManager, createInitialLayerStates, createInteractiveExpression, createInteractiveStatusColorExpression, createLineStyle, createLotFillStyle, createLotOutlineStyle, createMatchedColorExpression, createPositioningCoordinator, createPredictiveViewportManager, createRTreeViewportManager, createSelectionExpression, createStatusColorExpression, createViewportManager, createViewportQuery, createZoomExpression, decimalToDMS, deepEqual, ensureValidCoordinates, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, filterEqual, fingerprintEqual, formatArea, formatBearing, formatBounds, formatCoordinates, formatDistance, formatFeatureProperties, formatLabel, formatPitch, formatPropertyValue, formatScale, formatZoom, generateBoundingPolygon, generateConvexHull, generateFeatureCollectionDescription, generateFeatureTable, generateKeyboardControlsDescription, generateLODData, generateLODDataWithSimplification, generateMapDescription, generateMarkerList, generateMarkersDescription, generateMoveAnnouncement, geoJSONEqual, getAvailabilityColor, getAvailableBasemaps, getChangedPaintProps, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getContrastTextColor, getHighlightStyle, getLayerCategories, getLayerStatesArray, getLayerStyleForTheme, getLayersByCategory, getLayersWithErrors, getSelectionStyle, getSimplificationToleranceForZoom, getSimplifiedFeaturesForZoom, getSizeColor, getVisibleLayerIds, groupFeaturesByProperty, groupLayersByCategory, hideAllLayers, inventoryStatusColorExpression, inventoryStatusColors, isAnyLayerLoading, isClusterFeature, isValidBounds, isValidLatitude, isValidLongitude, loadGeoJSON, lotAvailabilityColorExpression, lotAvailabilityColors, lotSizeColorExpression, lotSizeColors, nonMatchedColor, normalizeLongitude, paintPropsEqual, queryByBounds, queryByBoundsWithStats, queryRTreeByBounds, queryRTreeByBoundsWithStats, removeMarkerProtection, reorderLayers, resolveBasemapStyle, resolveBasemapThumbnail, resolveLayerSourceUrl, salesOfficeColor, searchLayers, serializeFilter, setLayerError, setLayerLoading, setLayerOpacity, showAllLayers, simplifyFeature, simplifyFeatureCollection, simplifyFeatureCollectionWithStats, simplifyPolygon, toggleLayerVisibility, updateLayerState, validateBoundsArray, validateCoordinates, validateGeoJSON, zoomToScale };
@@ -1,4 +1,4 @@
1
- import { G as GeoJSONFeatureCollection, a as GeoJSONFeature, B as BoundsArray, M as MapBounds } from './data-DDS6ok7I.js';
1
+ import { G as GeoJSONFeatureCollection, a as GeoJSONFeature, B as BoundsArray, M as MapBounds } from './data-CICLgvT6.js';
2
2
  import RBush from 'rbush';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { G as GeoJSONFeatureCollection, a as GeoJSONFeature, B as BoundsArray, M as MapBounds } from './data-DDS6ok7I.cjs';
1
+ import { G as GeoJSONFeatureCollection, a as GeoJSONFeature, B as BoundsArray, M as MapBounds } from './data-CICLgvT6.cjs';
2
2
  import RBush from 'rbush';
3
3
 
4
4
  /**
@@ -144,15 +144,25 @@ declare function getTheme(name: 'light' | 'dark' | typeof THEME_LIGHT | typeof T
144
144
  */
145
145
 
146
146
  /**
147
- * MapLibre style specification (simplified type)
147
+ * MapLibre style specification for theme generation
148
+ *
149
+ * This is a focused subset of the full MapStyleSpec used when
150
+ * generating theme-based styles internally.
148
151
  */
149
152
  interface MapStyleSpec {
153
+ /** Style spec version - must be 8 */
150
154
  version: 8;
155
+ /** Human-readable name for the style */
151
156
  name: string;
152
- sources: Record<string, unknown>;
153
- layers: unknown[];
157
+ /** Map sources keyed by source ID */
158
+ sources: Record<string, Record<string, unknown>>;
159
+ /** Ordered array of layers */
160
+ layers: Array<Record<string, unknown>>;
161
+ /** URL template for glyph PBFs */
154
162
  glyphs?: string;
163
+ /** URL to sprite image and JSON */
155
164
  sprite?: string;
165
+ /** Arbitrary metadata */
156
166
  metadata?: Record<string, unknown>;
157
167
  }
158
168
  /**
@@ -144,15 +144,25 @@ declare function getTheme(name: 'light' | 'dark' | typeof THEME_LIGHT | typeof T
144
144
  */
145
145
 
146
146
  /**
147
- * MapLibre style specification (simplified type)
147
+ * MapLibre style specification for theme generation
148
+ *
149
+ * This is a focused subset of the full MapStyleSpec used when
150
+ * generating theme-based styles internally.
148
151
  */
149
152
  interface MapStyleSpec {
153
+ /** Style spec version - must be 8 */
150
154
  version: 8;
155
+ /** Human-readable name for the style */
151
156
  name: string;
152
- sources: Record<string, unknown>;
153
- layers: unknown[];
157
+ /** Map sources keyed by source ID */
158
+ sources: Record<string, Record<string, unknown>>;
159
+ /** Ordered array of layers */
160
+ layers: Array<Record<string, unknown>>;
161
+ /** URL template for glyph PBFs */
154
162
  glyphs?: string;
163
+ /** URL to sprite image and JSON */
155
164
  sprite?: string;
165
+ /** Arbitrary metadata */
156
166
  metadata?: Record<string, unknown>;
157
167
  }
158
168
  /**
@@ -1,5 +1,5 @@
1
- import { L as LngLat, a as GeoJSONFeature, M as MapBounds, B as BoundsArray, k as MapSourceData, G as GeoJSONFeatureCollection, C as ClusterConfig } from '../data-DDS6ok7I.cjs';
2
- export { E as ExtrusionData, e as GeoJSONGeometry, h as GeoJSONLineString, i as GeoJSONMultiLineString, g as GeoJSONMultiPoint, j as GeoJSONMultiPolygon, f as GeoJSONPoint, c as GeoJSONPolygon, H as HeatmapPoint, d as MapViewport, b as MarkerData } from '../data-DDS6ok7I.cjs';
1
+ import { L as LngLat, a as GeoJSONFeature, M as MapBounds, B as BoundsArray, k as MapSourceData, G as GeoJSONFeatureCollection, C as ClusterConfig } from '../data-CICLgvT6.cjs';
2
+ export { E as ExtrusionData, e as GeoJSONGeometry, l as GeoJSONGeometryCollection, h as GeoJSONLineString, i as GeoJSONMultiLineString, g as GeoJSONMultiPoint, j as GeoJSONMultiPolygon, f as GeoJSONPoint, c as GeoJSONPolygon, H as HeatmapPoint, d as MapViewport, b as MarkerData } from '../data-CICLgvT6.cjs';
3
3
 
4
4
  /**
5
5
  * Map event types
@@ -184,15 +184,97 @@ interface BaseMapProps {
184
184
  /** Custom CSS class */
185
185
  class?: string;
186
186
  }
187
+ /**
188
+ * MapLibre source specification types
189
+ */
190
+ type MapSourceSpec = {
191
+ type: 'vector';
192
+ url?: string;
193
+ tiles?: string[];
194
+ attribution?: string;
195
+ minzoom?: number;
196
+ maxzoom?: number;
197
+ } | {
198
+ type: 'raster';
199
+ url?: string;
200
+ tiles?: string[];
201
+ tileSize?: number;
202
+ attribution?: string;
203
+ } | {
204
+ type: 'raster-dem';
205
+ url?: string;
206
+ tiles?: string[];
207
+ tileSize?: number;
208
+ encoding?: 'terrarium' | 'mapbox';
209
+ } | {
210
+ type: 'geojson';
211
+ data: unknown;
212
+ cluster?: boolean;
213
+ clusterRadius?: number;
214
+ clusterMaxZoom?: number;
215
+ } | {
216
+ type: 'image';
217
+ url: string;
218
+ coordinates: [[number, number], [number, number], [number, number], [number, number]];
219
+ } | {
220
+ type: 'video';
221
+ urls: string[];
222
+ coordinates: [[number, number], [number, number], [number, number], [number, number]];
223
+ };
224
+ /**
225
+ * MapLibre layer specification base
226
+ */
227
+ interface MapLayerSpecBase {
228
+ id: string;
229
+ type: 'fill' | 'line' | 'symbol' | 'circle' | 'heatmap' | 'fill-extrusion' | 'raster' | 'hillshade' | 'background';
230
+ source?: string;
231
+ 'source-layer'?: string;
232
+ minzoom?: number;
233
+ maxzoom?: number;
234
+ filter?: unknown[];
235
+ layout?: Record<string, unknown>;
236
+ paint?: Record<string, unknown>;
237
+ metadata?: Record<string, unknown>;
238
+ }
187
239
  /**
188
240
  * Map style specification
241
+ *
242
+ * Based on MapLibre Style Spec v8. While MapLibre's StyleSpecification
243
+ * is more precise, this interface provides a reasonable subset for
244
+ * typical use cases without requiring the full maplibre-gl types.
245
+ *
246
+ * @see https://maplibre.org/maplibre-style-spec/
189
247
  */
190
248
  interface MapStyleSpec {
249
+ /** Style spec version - must be 8 */
191
250
  version: 8;
251
+ /** Human-readable name for the style */
192
252
  name?: string;
193
- sources: Record<string, unknown>;
194
- layers: unknown[];
195
- [key: string]: unknown;
253
+ /** Map sources keyed by source ID */
254
+ sources: Record<string, MapSourceSpec | Record<string, unknown>>;
255
+ /** Ordered array of layers */
256
+ layers: (MapLayerSpecBase | Record<string, unknown>)[];
257
+ /** URL to sprite image and JSON */
258
+ sprite?: string;
259
+ /** URL template for glyph PBFs */
260
+ glyphs?: string;
261
+ /** Arbitrary metadata */
262
+ metadata?: Record<string, unknown>;
263
+ /** Light settings for 3D */
264
+ light?: Record<string, unknown>;
265
+ /** Terrain settings */
266
+ terrain?: {
267
+ source: string;
268
+ exaggeration?: number;
269
+ };
270
+ /** Default center [lng, lat] */
271
+ center?: [number, number];
272
+ /** Default zoom */
273
+ zoom?: number;
274
+ /** Default bearing */
275
+ bearing?: number;
276
+ /** Default pitch */
277
+ pitch?: number;
196
278
  }
197
279
  /**
198
280
  * Main Map component props
@@ -780,9 +862,14 @@ interface BasemapSwitcherProps extends BaseControlProps {
780
862
  defaultBasemapId?: string;
781
863
  activeBasemapId?: string;
782
864
  onBasemapChange?: (basemap: BasemapDefinition) => void;
865
+ /** Callback when a basemap style fails to load (e.g., missing API key) */
866
+ onStyleError?: (error: {
867
+ basemap: BasemapDefinition;
868
+ reason: string;
869
+ }) => void;
783
870
  columns?: number;
784
871
  thumbnailSize?: number;
785
872
  class?: string;
786
873
  }
787
874
 
788
- export { type BaseControlProps, type BaseLayerProps, type BaseMapEventParams, type BaseMapProps, type BasemapApiKeys, type BasemapCategory, type BasemapDefinition, type BasemapProvider, type BasemapSwitcherProps, BoundsArray, type CircleLayerProps, ClusterConfig, type ControlPosition, type CoordinateDisplayProps, type FeatureClickEventParams, type FeatureHoverEventParams, type FillExtrusionLayerProps, type FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, type GeolocateControlProps, type GradientStop, type HeatmapLayerProps, type LegendConfig, type LegendGroupProps, type LegendItem, type LegendProps, type LineLayerProps, LngLat, MapBounds, type MapClickEventParams, type MapErrorEventParams, type MapHoverEventParams, type MapLoadEventParams, type MapMoveEventParams, type MapProps, MapSourceData, type MapStyleSpec, type MarkerClickEventParams, type MarkerDragEventParams, type MarkerProps, type NavigationControlProps, type PopupEventParams, type PopupProps, type RasterLayerProps, type ScaleControlProps, type SourceProps, type SymbolLayerProps };
875
+ export { type BaseControlProps, type BaseLayerProps, type BaseMapEventParams, type BaseMapProps, type BasemapApiKeys, type BasemapCategory, type BasemapDefinition, type BasemapProvider, type BasemapSwitcherProps, BoundsArray, type CircleLayerProps, ClusterConfig, type ControlPosition, type CoordinateDisplayProps, type FeatureClickEventParams, type FeatureHoverEventParams, type FillExtrusionLayerProps, type FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, type GeolocateControlProps, type GradientStop, type HeatmapLayerProps, type LegendConfig, type LegendGroupProps, type LegendItem, type LegendProps, type LineLayerProps, LngLat, MapBounds, type MapClickEventParams, type MapErrorEventParams, type MapHoverEventParams, type MapLayerSpecBase, type MapLoadEventParams, type MapMoveEventParams, type MapProps, MapSourceData, type MapSourceSpec, type MapStyleSpec, type MarkerClickEventParams, type MarkerDragEventParams, type MarkerProps, type NavigationControlProps, type PopupEventParams, type PopupProps, type RasterLayerProps, type ScaleControlProps, type SourceProps, type SymbolLayerProps };
@@ -1,5 +1,5 @@
1
- import { L as LngLat, a as GeoJSONFeature, M as MapBounds, B as BoundsArray, k as MapSourceData, G as GeoJSONFeatureCollection, C as ClusterConfig } from '../data-DDS6ok7I.js';
2
- export { E as ExtrusionData, e as GeoJSONGeometry, h as GeoJSONLineString, i as GeoJSONMultiLineString, g as GeoJSONMultiPoint, j as GeoJSONMultiPolygon, f as GeoJSONPoint, c as GeoJSONPolygon, H as HeatmapPoint, d as MapViewport, b as MarkerData } from '../data-DDS6ok7I.js';
1
+ import { L as LngLat, a as GeoJSONFeature, M as MapBounds, B as BoundsArray, k as MapSourceData, G as GeoJSONFeatureCollection, C as ClusterConfig } from '../data-CICLgvT6.js';
2
+ export { E as ExtrusionData, e as GeoJSONGeometry, l as GeoJSONGeometryCollection, h as GeoJSONLineString, i as GeoJSONMultiLineString, g as GeoJSONMultiPoint, j as GeoJSONMultiPolygon, f as GeoJSONPoint, c as GeoJSONPolygon, H as HeatmapPoint, d as MapViewport, b as MarkerData } from '../data-CICLgvT6.js';
3
3
 
4
4
  /**
5
5
  * Map event types
@@ -184,15 +184,97 @@ interface BaseMapProps {
184
184
  /** Custom CSS class */
185
185
  class?: string;
186
186
  }
187
+ /**
188
+ * MapLibre source specification types
189
+ */
190
+ type MapSourceSpec = {
191
+ type: 'vector';
192
+ url?: string;
193
+ tiles?: string[];
194
+ attribution?: string;
195
+ minzoom?: number;
196
+ maxzoom?: number;
197
+ } | {
198
+ type: 'raster';
199
+ url?: string;
200
+ tiles?: string[];
201
+ tileSize?: number;
202
+ attribution?: string;
203
+ } | {
204
+ type: 'raster-dem';
205
+ url?: string;
206
+ tiles?: string[];
207
+ tileSize?: number;
208
+ encoding?: 'terrarium' | 'mapbox';
209
+ } | {
210
+ type: 'geojson';
211
+ data: unknown;
212
+ cluster?: boolean;
213
+ clusterRadius?: number;
214
+ clusterMaxZoom?: number;
215
+ } | {
216
+ type: 'image';
217
+ url: string;
218
+ coordinates: [[number, number], [number, number], [number, number], [number, number]];
219
+ } | {
220
+ type: 'video';
221
+ urls: string[];
222
+ coordinates: [[number, number], [number, number], [number, number], [number, number]];
223
+ };
224
+ /**
225
+ * MapLibre layer specification base
226
+ */
227
+ interface MapLayerSpecBase {
228
+ id: string;
229
+ type: 'fill' | 'line' | 'symbol' | 'circle' | 'heatmap' | 'fill-extrusion' | 'raster' | 'hillshade' | 'background';
230
+ source?: string;
231
+ 'source-layer'?: string;
232
+ minzoom?: number;
233
+ maxzoom?: number;
234
+ filter?: unknown[];
235
+ layout?: Record<string, unknown>;
236
+ paint?: Record<string, unknown>;
237
+ metadata?: Record<string, unknown>;
238
+ }
187
239
  /**
188
240
  * Map style specification
241
+ *
242
+ * Based on MapLibre Style Spec v8. While MapLibre's StyleSpecification
243
+ * is more precise, this interface provides a reasonable subset for
244
+ * typical use cases without requiring the full maplibre-gl types.
245
+ *
246
+ * @see https://maplibre.org/maplibre-style-spec/
189
247
  */
190
248
  interface MapStyleSpec {
249
+ /** Style spec version - must be 8 */
191
250
  version: 8;
251
+ /** Human-readable name for the style */
192
252
  name?: string;
193
- sources: Record<string, unknown>;
194
- layers: unknown[];
195
- [key: string]: unknown;
253
+ /** Map sources keyed by source ID */
254
+ sources: Record<string, MapSourceSpec | Record<string, unknown>>;
255
+ /** Ordered array of layers */
256
+ layers: (MapLayerSpecBase | Record<string, unknown>)[];
257
+ /** URL to sprite image and JSON */
258
+ sprite?: string;
259
+ /** URL template for glyph PBFs */
260
+ glyphs?: string;
261
+ /** Arbitrary metadata */
262
+ metadata?: Record<string, unknown>;
263
+ /** Light settings for 3D */
264
+ light?: Record<string, unknown>;
265
+ /** Terrain settings */
266
+ terrain?: {
267
+ source: string;
268
+ exaggeration?: number;
269
+ };
270
+ /** Default center [lng, lat] */
271
+ center?: [number, number];
272
+ /** Default zoom */
273
+ zoom?: number;
274
+ /** Default bearing */
275
+ bearing?: number;
276
+ /** Default pitch */
277
+ pitch?: number;
196
278
  }
197
279
  /**
198
280
  * Main Map component props
@@ -780,9 +862,14 @@ interface BasemapSwitcherProps extends BaseControlProps {
780
862
  defaultBasemapId?: string;
781
863
  activeBasemapId?: string;
782
864
  onBasemapChange?: (basemap: BasemapDefinition) => void;
865
+ /** Callback when a basemap style fails to load (e.g., missing API key) */
866
+ onStyleError?: (error: {
867
+ basemap: BasemapDefinition;
868
+ reason: string;
869
+ }) => void;
783
870
  columns?: number;
784
871
  thumbnailSize?: number;
785
872
  class?: string;
786
873
  }
787
874
 
788
- export { type BaseControlProps, type BaseLayerProps, type BaseMapEventParams, type BaseMapProps, type BasemapApiKeys, type BasemapCategory, type BasemapDefinition, type BasemapProvider, type BasemapSwitcherProps, BoundsArray, type CircleLayerProps, ClusterConfig, type ControlPosition, type CoordinateDisplayProps, type FeatureClickEventParams, type FeatureHoverEventParams, type FillExtrusionLayerProps, type FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, type GeolocateControlProps, type GradientStop, type HeatmapLayerProps, type LegendConfig, type LegendGroupProps, type LegendItem, type LegendProps, type LineLayerProps, LngLat, MapBounds, type MapClickEventParams, type MapErrorEventParams, type MapHoverEventParams, type MapLoadEventParams, type MapMoveEventParams, type MapProps, MapSourceData, type MapStyleSpec, type MarkerClickEventParams, type MarkerDragEventParams, type MarkerProps, type NavigationControlProps, type PopupEventParams, type PopupProps, type RasterLayerProps, type ScaleControlProps, type SourceProps, type SymbolLayerProps };
875
+ export { type BaseControlProps, type BaseLayerProps, type BaseMapEventParams, type BaseMapProps, type BasemapApiKeys, type BasemapCategory, type BasemapDefinition, type BasemapProvider, type BasemapSwitcherProps, BoundsArray, type CircleLayerProps, ClusterConfig, type ControlPosition, type CoordinateDisplayProps, type FeatureClickEventParams, type FeatureHoverEventParams, type FillExtrusionLayerProps, type FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, type GeolocateControlProps, type GradientStop, type HeatmapLayerProps, type LegendConfig, type LegendGroupProps, type LegendItem, type LegendProps, type LineLayerProps, LngLat, MapBounds, type MapClickEventParams, type MapErrorEventParams, type MapHoverEventParams, type MapLayerSpecBase, type MapLoadEventParams, type MapMoveEventParams, type MapProps, MapSourceData, type MapSourceSpec, type MapStyleSpec, type MarkerClickEventParams, type MarkerDragEventParams, type MarkerProps, type NavigationControlProps, type PopupEventParams, type PopupProps, type RasterLayerProps, type ScaleControlProps, type SourceProps, type SymbolLayerProps };
@@ -1,5 +1,5 @@
1
- import { G as GeoJSONFeatureCollection, B as BoundsArray } from '../data-DDS6ok7I.cjs';
2
- import { Q as QueryStats, P as PanVelocity, R as RTreeQueryStats } from '../spatial-J48Btm8f.cjs';
1
+ import { G as GeoJSONFeatureCollection, B as BoundsArray } from '../data-CICLgvT6.cjs';
2
+ import { Q as QueryStats, P as PanVelocity, R as RTreeQueryStats } from '../spatial-D9o4mvDO.cjs';
3
3
  import 'rbush';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
- import { G as GeoJSONFeatureCollection, B as BoundsArray } from '../data-DDS6ok7I.js';
2
- import { Q as QueryStats, P as PanVelocity, R as RTreeQueryStats } from '../spatial-VV-zd88V.js';
1
+ import { G as GeoJSONFeatureCollection, B as BoundsArray } from '../data-CICLgvT6.js';
2
+ import { Q as QueryStats, P as PanVelocity, R as RTreeQueryStats } from '../spatial-D4ZJ4Ul7.js';
3
3
  import 'rbush';
4
4
 
5
5
  /**
@@ -775,6 +775,10 @@ function normalizeBoundsInternal(bounds) {
775
775
  }
776
776
 
777
777
  // src/workers/spatial.worker.ts
778
+ var MAX_VIEWPORT_SAMPLES = 5;
779
+ var WEIGHT_DECAY_FACTOR = 0.7;
780
+ var VELOCITY_MAGNITUDE_THRESHOLD = 1e-5;
781
+ var MAX_SAMPLE_TIME_DELTA_SEC = 1;
778
782
  var state = {
779
783
  initialized: false,
780
784
  indexType: "rtree",
@@ -805,12 +809,12 @@ function calculatePanVelocity(samples) {
805
809
  const current = samples[i];
806
810
  const previous = samples[i - 1];
807
811
  const dt = (current.timestamp - previous.timestamp) / 1e3;
808
- if (dt > 0 && dt < 1) {
812
+ if (dt > 0 && dt < MAX_SAMPLE_TIME_DELTA_SEC) {
809
813
  totalLngDelta += (current.center[0] - previous.center[0]) * weight;
810
814
  totalLatDelta += (current.center[1] - previous.center[1]) * weight;
811
815
  totalTime += dt * weight;
812
816
  }
813
- weight *= 0.7;
817
+ weight *= WEIGHT_DECAY_FACTOR;
814
818
  }
815
819
  if (totalTime === 0) {
816
820
  return { lngPerSec: 0, latPerSec: 0, magnitude: 0 };
@@ -826,7 +830,7 @@ function applyPredictiveBuffer(bounds, velocity, baseBuffer, multiplier) {
826
830
  let bufferMaxLng = baseBuffer;
827
831
  let bufferMinLat = baseBuffer;
828
832
  let bufferMaxLat = baseBuffer;
829
- if (velocity.magnitude > 1e-5) {
833
+ if (velocity.magnitude > VELOCITY_MAGNITUDE_THRESHOLD) {
830
834
  const extraBuffer = baseBuffer * (multiplier - 1);
831
835
  if (velocity.lngPerSec > 0) {
832
836
  bufferMaxLng += extraBuffer * Math.min(1, velocity.lngPerSec / velocity.magnitude);
@@ -976,8 +980,8 @@ function handlePredictiveQuery(requestId, bounds, timestamp, options = {}) {
976
980
  (bounds[0][1] + bounds[1][1]) / 2
977
981
  ];
978
982
  state.predictive.viewportSamples.push({ center, timestamp });
979
- while (state.predictive.viewportSamples.length > 5) {
980
- state.predictive.viewportSamples.shift();
983
+ if (state.predictive.viewportSamples.length > MAX_VIEWPORT_SAMPLES) {
984
+ state.predictive.viewportSamples = state.predictive.viewportSamples.slice(-MAX_VIEWPORT_SAMPLES);
981
985
  }
982
986
  state.predictive.velocity = calculatePanVelocity(state.predictive.viewportSamples);
983
987
  if (state.predictive.lastData && !shouldUpdatePredictive(bounds, state.predictive.lastBounds, minMovement)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-core",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Core utilities and theme for Classic Theme maps",
5
5
  "keywords": [
6
6
  "maps",