@classic-homes/maps-svelte 0.2.5 → 0.2.6
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/lib/components/controls/CustomControl.svelte +96 -0
- package/dist/lib/components/controls/CustomControl.svelte.d.ts +26 -0
- package/dist/lib/components/controls/index.d.ts +1 -0
- package/dist/lib/components/controls/index.js +1 -0
- package/dist/lib/components/index.d.ts +1 -1
- package/dist/lib/components/index.js +1 -1
- package/dist/lib/composables/useMapTheme.svelte.js +6 -4
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type {
|
|
3
|
+
ControlPriority,
|
|
4
|
+
ExtendedControlPosition,
|
|
5
|
+
ZIndexLayer,
|
|
6
|
+
} from '@classic-homes/maps-core';
|
|
7
|
+
|
|
8
|
+
export interface CustomControlProps {
|
|
9
|
+
/** Position on the map (default: 'top-right') */
|
|
10
|
+
position?: ExtendedControlPosition;
|
|
11
|
+
/** Fallback positions if primary is occupied */
|
|
12
|
+
fallbacks?: ExtendedControlPosition[];
|
|
13
|
+
/** Priority for collision resolution (default: 'normal') */
|
|
14
|
+
priority?: ControlPriority;
|
|
15
|
+
/** Z-index layer (default: 'interactive') */
|
|
16
|
+
zLayer?: ZIndexLayer;
|
|
17
|
+
/** Optional unique ID (auto-generated if not provided) */
|
|
18
|
+
id?: string;
|
|
19
|
+
/** Whether the control has an expandable state */
|
|
20
|
+
hasExpandedState?: boolean;
|
|
21
|
+
/** Additional CSS class names */
|
|
22
|
+
class?: string;
|
|
23
|
+
/** Inline styles (merged with positioning styles) */
|
|
24
|
+
style?: string;
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script lang="ts">
|
|
29
|
+
import { cn } from '../../utils.js';
|
|
30
|
+
import { useControlPosition } from '../../composables/useControlPosition.svelte.js';
|
|
31
|
+
import type { Snippet } from 'svelte';
|
|
32
|
+
import { setContext } from 'svelte';
|
|
33
|
+
|
|
34
|
+
interface Props extends CustomControlProps {
|
|
35
|
+
children: Snippet;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
position = 'top-right',
|
|
40
|
+
fallbacks,
|
|
41
|
+
priority = 'normal',
|
|
42
|
+
zLayer = 'interactive',
|
|
43
|
+
id,
|
|
44
|
+
hasExpandedState = false,
|
|
45
|
+
class: className,
|
|
46
|
+
style: userStyle,
|
|
47
|
+
children,
|
|
48
|
+
}: Props = $props();
|
|
49
|
+
|
|
50
|
+
const controlId = id ?? `custom-control-${Math.random().toString(36).slice(2, 9)}`;
|
|
51
|
+
let controlElement: HTMLDivElement;
|
|
52
|
+
|
|
53
|
+
const controlPosition = useControlPosition(() => controlElement, {
|
|
54
|
+
id: controlId,
|
|
55
|
+
type: 'custom',
|
|
56
|
+
position,
|
|
57
|
+
fallbacks,
|
|
58
|
+
priority,
|
|
59
|
+
zLayer,
|
|
60
|
+
hasExpandedState,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const mergedStyle = $derived(
|
|
64
|
+
userStyle ? `${controlPosition.style}; ${userStyle}` : controlPosition.style
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// Expose setExpanded via context
|
|
68
|
+
setContext('custom-control', {
|
|
69
|
+
setExpanded: controlPosition.setExpanded,
|
|
70
|
+
});
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<!--
|
|
74
|
+
CustomControl component for positioning arbitrary content on the map
|
|
75
|
+
|
|
76
|
+
This component integrates with the map's positioning coordinator for
|
|
77
|
+
collision avoidance and proper stacking with other controls.
|
|
78
|
+
|
|
79
|
+
@example
|
|
80
|
+
```svelte
|
|
81
|
+
<Map>
|
|
82
|
+
<CustomControl position="top-right">
|
|
83
|
+
<div class="bg-white p-2 rounded shadow">
|
|
84
|
+
Custom widget content
|
|
85
|
+
</div>
|
|
86
|
+
</CustomControl>
|
|
87
|
+
</Map>
|
|
88
|
+
```
|
|
89
|
+
-->
|
|
90
|
+
<div
|
|
91
|
+
bind:this={controlElement}
|
|
92
|
+
class={cn(!controlPosition.visible && 'invisible', className)}
|
|
93
|
+
style={mergedStyle}
|
|
94
|
+
>
|
|
95
|
+
{@render children()}
|
|
96
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ControlPriority, ExtendedControlPosition, ZIndexLayer } from '@classic-homes/maps-core';
|
|
2
|
+
export interface CustomControlProps {
|
|
3
|
+
/** Position on the map (default: 'top-right') */
|
|
4
|
+
position?: ExtendedControlPosition;
|
|
5
|
+
/** Fallback positions if primary is occupied */
|
|
6
|
+
fallbacks?: ExtendedControlPosition[];
|
|
7
|
+
/** Priority for collision resolution (default: 'normal') */
|
|
8
|
+
priority?: ControlPriority;
|
|
9
|
+
/** Z-index layer (default: 'interactive') */
|
|
10
|
+
zLayer?: ZIndexLayer;
|
|
11
|
+
/** Optional unique ID (auto-generated if not provided) */
|
|
12
|
+
id?: string;
|
|
13
|
+
/** Whether the control has an expandable state */
|
|
14
|
+
hasExpandedState?: boolean;
|
|
15
|
+
/** Additional CSS class names */
|
|
16
|
+
class?: string;
|
|
17
|
+
/** Inline styles (merged with positioning styles) */
|
|
18
|
+
style?: string;
|
|
19
|
+
}
|
|
20
|
+
import type { Snippet } from 'svelte';
|
|
21
|
+
interface Props extends CustomControlProps {
|
|
22
|
+
children: Snippet;
|
|
23
|
+
}
|
|
24
|
+
declare const CustomControl: import("svelte").Component<Props, {}, "">;
|
|
25
|
+
type CustomControl = ReturnType<typeof CustomControl>;
|
|
26
|
+
export default CustomControl;
|
|
@@ -3,3 +3,4 @@ export { default as LegendGroup } from './LegendGroup.svelte';
|
|
|
3
3
|
export { default as CoordinateDisplay } from './CoordinateDisplay.svelte';
|
|
4
4
|
export { default as BasemapSwitcher } from './BasemapSwitcher.svelte';
|
|
5
5
|
export { default as LayerManager } from './LayerManager.svelte';
|
|
6
|
+
export { default as CustomControl, type CustomControlProps } from './CustomControl.svelte';
|
|
@@ -3,3 +3,4 @@ export { default as LegendGroup } from './LegendGroup.svelte';
|
|
|
3
3
|
export { default as CoordinateDisplay } from './CoordinateDisplay.svelte';
|
|
4
4
|
export { default as BasemapSwitcher } from './BasemapSwitcher.svelte';
|
|
5
5
|
export { default as LayerManager } from './LayerManager.svelte';
|
|
6
|
+
export { default as CustomControl } from './CustomControl.svelte';
|
|
@@ -2,4 +2,4 @@ export { MapContainer, MapSkeleton, MapError, MapEmpty } from './base/index.js';
|
|
|
2
2
|
export { Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, } from './core/index.js';
|
|
3
3
|
export { FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './layers/index.js';
|
|
4
4
|
export { DeckOverlay } from './deck/index.js';
|
|
5
|
-
export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, } from './controls/index.js';
|
|
5
|
+
export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, } from './controls/index.js';
|
|
@@ -7,4 +7,4 @@ export { FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, Hea
|
|
|
7
7
|
// Deck.gl components
|
|
8
8
|
export { DeckOverlay } from './deck/index.js';
|
|
9
9
|
// Control components
|
|
10
|
-
export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, } from './controls/index.js';
|
|
10
|
+
export { Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, } from './controls/index.js';
|
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import { lightTheme, darkTheme,
|
|
1
|
+
import { lightTheme, darkTheme, DEFAULT_BASEMAP, THEME_LIGHT, THEME_DARK, } from '@classic-homes/maps-core';
|
|
2
|
+
// Use the default MapTiler basemap style (works well for both light and dark modes)
|
|
3
|
+
const defaultStyle = DEFAULT_BASEMAP.style;
|
|
2
4
|
/**
|
|
3
5
|
* Create a reactive map theme based on system/document dark mode
|
|
4
6
|
* @param getPreference - A getter function that returns the current theme preference
|
|
5
7
|
*/
|
|
6
8
|
export function useMapTheme(getPreference) {
|
|
7
9
|
let currentTheme = $state(lightTheme);
|
|
8
|
-
let currentStyle = $state(
|
|
10
|
+
let currentStyle = $state(defaultStyle);
|
|
9
11
|
let isDark = $state(false);
|
|
10
12
|
function updateTheme() {
|
|
11
13
|
const preference = getPreference();
|
|
12
14
|
if (preference !== 'auto') {
|
|
13
15
|
isDark = preference === 'dark';
|
|
14
16
|
currentTheme = isDark ? darkTheme : lightTheme;
|
|
15
|
-
currentStyle =
|
|
17
|
+
currentStyle = defaultStyle;
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
20
|
// Check for dark class on html element
|
|
19
21
|
if (typeof document !== 'undefined') {
|
|
20
22
|
isDark = document.documentElement.classList.contains('dark');
|
|
21
23
|
currentTheme = isDark ? darkTheme : lightTheme;
|
|
22
|
-
currentStyle =
|
|
24
|
+
currentStyle = defaultStyle;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
$effect(() => {
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Svelte MapLibre components for the Classic Theme design system
|
|
5
5
|
*/
|
|
6
|
-
export { MapContainer, MapSkeleton, MapError, MapEmpty, Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, DeckOverlay, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './components/index.js';
|
|
7
|
-
export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, type MapContextValue, } from './composables/index.js';
|
|
6
|
+
export { MapContainer, MapSkeleton, MapError, MapEmpty, Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, DeckOverlay, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './components/index.js';
|
|
7
|
+
export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useControlPosition, type MapContextValue, type UseControlPositionOptions, type UseControlPositionResult, } from './composables/index.js';
|
|
8
8
|
export { cn } from './utils.js';
|
|
9
|
-
export type { LngLat, MapBounds, BoundsArray, MapViewport, GeoJSONFeature, GeoJSONFeatureCollection, MarkerData, MapClickEventParams, MapHoverEventParams, FeatureClickEventParams, FeatureHoverEventParams, MarkerClickEventParams, MapMoveEventParams, BaseMapProps, MapProps, SourceProps, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, MarkerProps, PopupProps, LegendItem, GradientStop, LegendProps, CoordinateDisplayProps, LegendConfig, LegendGroupProps, BasemapProvider, BasemapCategory, BasemapDefinition, BasemapApiKeys, BasemapSwitcherProps, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, OverlayApiKeys, LayerManagerProps, } from '@classic-homes/maps-core';
|
|
9
|
+
export type { LngLat, MapBounds, BoundsArray, MapViewport, GeoJSONFeature, GeoJSONFeatureCollection, MarkerData, MapClickEventParams, MapHoverEventParams, FeatureClickEventParams, FeatureHoverEventParams, MarkerClickEventParams, MapMoveEventParams, BaseMapProps, MapProps, SourceProps, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, MarkerProps, PopupProps, LegendItem, GradientStop, LegendProps, CoordinateDisplayProps, LegendConfig, LegendGroupProps, BasemapProvider, BasemapCategory, BasemapDefinition, BasemapApiKeys, BasemapSwitcherProps, OverlayLayerCategory, OverlayLayerDefinition, OverlayLayerState, OverlayApiKeys, LayerManagerProps, ExtendedControlPosition, ControlPriority, ZIndexLayer, ControlType, ControlOffset, } from '@classic-homes/maps-core';
|
|
10
10
|
export { CATEGORY_META, SCHOOL_DISTRICTS, CITY_LIMITS, ZONING_DISTRICTS, PARKS, TRAILS, SPORTS_FACILITIES, TRANSIT_ROUTES, BIKE_LANES, FLOOD_ZONES, WATERSHEDS, BUILTIN_OVERLAY_LAYERS, resolveLayerSourceUrl, getLayerStyleForTheme, searchLayers, getLayersByCategory, groupLayersByCategory, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
|
|
11
|
-
export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle, calculateBounds, extendBounds, combineBounds, isValidBounds, loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType, BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
|
|
11
|
+
export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle, calculateBounds, extendBounds, combineBounds, isValidBounds, loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType, DEFAULT_BASEMAP, SATELLITE_BASEMAP, TOPO_BASEMAP, PRIMARY_BASEMAPS, BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
|
|
12
12
|
export type { LoadGeoJSONOptions, LoadGeoJSONResult, ValidationResult, ClusterFeatureProperties, ClusterExpandOptions, } from '@classic-homes/maps-core';
|
|
13
13
|
export { isClusterFeature, getClusterExpansionZoom, getClusterChildren, getClusterLeaves, expandCluster, getClusterBounds, expandClusterToBounds, } from '@classic-homes/maps-core';
|
package/dist/lib/index.js
CHANGED
|
@@ -12,11 +12,11 @@ Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter,
|
|
|
12
12
|
// Layers
|
|
13
13
|
FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer,
|
|
14
14
|
// Controls
|
|
15
|
-
Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager,
|
|
15
|
+
Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl,
|
|
16
16
|
// Deck.gl
|
|
17
17
|
DeckOverlay, } from './components/index.js';
|
|
18
18
|
// Composables
|
|
19
|
-
export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, } from './composables/index.js';
|
|
19
|
+
export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useControlPosition, } from './composables/index.js';
|
|
20
20
|
// Utils
|
|
21
21
|
export { cn } from './utils.js';
|
|
22
22
|
// Re-export layer presets and utilities from maps-core
|
|
@@ -28,6 +28,6 @@ calculateBounds, extendBounds, combineBounds, isValidBounds,
|
|
|
28
28
|
// Data utilities
|
|
29
29
|
loadGeoJSON, validateGeoJSON, calculateCentroid, countFeaturesByType, filterByGeometryType,
|
|
30
30
|
// Basemap utilities
|
|
31
|
-
BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
|
|
31
|
+
DEFAULT_BASEMAP, SATELLITE_BASEMAP, TOPO_BASEMAP, PRIMARY_BASEMAPS, BUILTIN_BASEMAPS, FREE_BASEMAPS, OSM_STANDARD, resolveBasemapStyle, getAvailableBasemaps, } from '@classic-homes/maps-core';
|
|
32
32
|
// Re-export cluster utilities from maps-core
|
|
33
33
|
export { isClusterFeature, getClusterExpansionZoom, getClusterChildren, getClusterLeaves, expandCluster, getClusterBounds, expandClusterToBounds, } from '@classic-homes/maps-core';
|