@classic-homes/maps-svelte 0.2.8 → 0.2.9

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.
@@ -3,6 +3,7 @@
3
3
  import type { Snippet } from 'svelte';
4
4
  import maplibregl from 'maplibre-gl';
5
5
  import type { PopupProps } from '@classic-homes/maps-core';
6
+ import { normalizePadding, panToFitPopup } from '@classic-homes/maps-core/utils';
6
7
 
7
8
  type Anchor =
8
9
  | 'center'
@@ -44,70 +45,12 @@
44
45
  children,
45
46
  }: Props = $props();
46
47
 
47
- /**
48
- * Helper to normalize padding value into individual sides
49
- */
50
- function normalizePadding(
51
- padding: number | { top: number; right: number; bottom: number; left: number }
52
- ): { top: number; right: number; bottom: number; left: number } {
53
- if (typeof padding === 'number') {
54
- return { top: padding, right: padding, bottom: padding, left: padding };
55
- }
56
- return padding;
57
- }
58
-
59
- /**
60
- * Check if user prefers reduced motion
61
- */
62
- function prefersReducedMotion(): boolean {
63
- if (typeof window === 'undefined') return false;
64
- return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
65
- }
66
-
67
- /**
68
- * Pan the map to ensure the popup is fully visible within the viewport
69
- */
70
- function panToFitPopup(
71
- map: maplibregl.Map,
72
- popup: maplibregl.Popup,
73
- padding: { top: number; right: number; bottom: number; left: number }
74
- ): void {
75
- const popupEl = popup.getElement();
76
- if (!popupEl) return;
77
-
78
- const mapContainer = map.getContainer();
79
- const mapRect = mapContainer.getBoundingClientRect();
80
- const popupRect = popupEl.getBoundingClientRect();
81
-
82
- let dx = 0;
83
- let dy = 0;
84
-
85
- // Calculate overflow on each side
86
- if (popupRect.left < mapRect.left + padding.left) {
87
- dx = popupRect.left - mapRect.left - padding.left;
88
- } else if (popupRect.right > mapRect.right - padding.right) {
89
- dx = popupRect.right - mapRect.right + padding.right;
90
- }
91
-
92
- if (popupRect.top < mapRect.top + padding.top) {
93
- dy = popupRect.top - mapRect.top - padding.top;
94
- } else if (popupRect.bottom > mapRect.bottom - padding.bottom) {
95
- dy = popupRect.bottom - mapRect.bottom + padding.bottom;
96
- }
97
-
98
- // Pan if needed
99
- if (dx !== 0 || dy !== 0) {
100
- map.panBy([dx, dy], {
101
- animate: !prefersReducedMotion(),
102
- });
103
- }
104
- }
105
-
106
48
  const mapContext = getContext<MapContext>('maplibre-map');
107
49
 
108
50
  let popup: maplibregl.Popup | null = $state(null);
109
51
  let containerElement: HTMLDivElement | null = $state(null);
110
52
  let contentElement: HTMLDivElement | null = $state(null);
53
+ let autoPanRafHandle: number | null = null;
111
54
 
112
55
  // Create container for content
113
56
  $effect(() => {
@@ -170,8 +113,13 @@
170
113
 
171
114
  // Auto-pan to fit popup after it renders
172
115
  if (autoPan) {
116
+ // Cancel any pending auto-pan
117
+ if (autoPanRafHandle !== null) {
118
+ cancelAnimationFrame(autoPanRafHandle);
119
+ }
173
120
  // Wait for popup to render before measuring
174
- requestAnimationFrame(() => {
121
+ autoPanRafHandle = requestAnimationFrame(() => {
122
+ autoPanRafHandle = null;
175
123
  if (popup && map) {
176
124
  panToFitPopup(map, popup, normalizePadding(autoPanPadding));
177
125
  }
@@ -193,6 +141,12 @@
193
141
 
194
142
  // Cleanup on destroy
195
143
  onDestroy(() => {
144
+ // Cancel any pending auto-pan animation frame
145
+ if (autoPanRafHandle !== null) {
146
+ cancelAnimationFrame(autoPanRafHandle);
147
+ autoPanRafHandle = null;
148
+ }
149
+
196
150
  if (popup) {
197
151
  popup.remove();
198
152
  popup = null;
@@ -102,12 +102,13 @@
102
102
  }
103
103
  });
104
104
 
105
- // Update event handlers
105
+ // Update event handlers and cursor
106
106
  $effect(() => {
107
107
  if (overlayRef && 'setProps' in overlayRef) {
108
108
  (overlayRef as { setProps: (props: unknown) => void }).setProps({
109
109
  onHover,
110
110
  onClick,
111
+ ...(getCursor ? { getCursor } : {}),
111
112
  });
112
113
  }
113
114
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-svelte",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Svelte MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",
@@ -25,6 +25,7 @@
25
25
  "default": "./dist/lib/index.js"
26
26
  }
27
27
  },
28
+ "sideEffects": false,
28
29
  "files": [
29
30
  "dist"
30
31
  ],