@classic-homes/maps-svelte 0.10.0 → 0.11.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.
@@ -2,6 +2,7 @@
2
2
  import { getContext, onDestroy, untrack } from 'svelte';
3
3
  import type {
4
4
  LayerManagerProps,
5
+ LayerManagerEntry,
5
6
  OverlayLayerDefinition,
6
7
  OverlayLayerState,
7
8
  OverlayLayerCategory,
@@ -14,6 +15,7 @@
14
15
  searchLayers,
15
16
  getLayerCategories,
16
17
  groupLayersByCategory,
18
+ groupLayersByHeading,
17
19
  getLayerStatesArray,
18
20
  resolveLayerSourceUrl,
19
21
  } from '@classic-homes/maps-core';
@@ -31,6 +33,11 @@
31
33
 
32
34
  interface Props extends LayerManagerProps {}
33
35
 
36
+ type ListLayer = OverlayLayerDefinition | LayerManagerEntry;
37
+ /** A layer LayerManager can draw: one with a source and a style */
38
+ const isDrawable = (layer: ListLayer): layer is OverlayLayerDefinition =>
39
+ 'source' in layer && 'style' in layer;
40
+
34
41
  let {
35
42
  layers,
36
43
  apiKeys,
@@ -41,10 +48,37 @@
41
48
  allowReorder = false,
42
49
  showOpacity = false,
43
50
  collapsible = true,
51
+ manageLayers = true,
52
+ layerStates: controlledStates,
53
+ title = 'Layers',
54
+ buttonLabel = 'Toggle layer manager',
55
+ buttonClass,
56
+ priority = 'high',
44
57
  onLayerChange,
45
58
  class: className,
46
59
  }: Props = $props();
47
60
 
61
+ /**
62
+ * A layer's state: the app's (`layerStates`, controlled) when given, else
63
+ * LayerManager's own. Controlled rows default to off, idle and opaque.
64
+ */
65
+ function stateOf(id: string): OverlayLayerState | undefined {
66
+ if (controlledStates) {
67
+ const order = layers.findIndex((l) => l.id === id);
68
+ if (order === -1) return undefined;
69
+ return {
70
+ id,
71
+ visible: false,
72
+ opacity: 1,
73
+ loading: false,
74
+ error: null,
75
+ order,
76
+ ...controlledStates[id],
77
+ };
78
+ }
79
+ return layerStates.get(id);
80
+ }
81
+
48
82
  const mapContext = getContext<MapContext>('maplibre-map');
49
83
  const managerId = `layer-manager-${Math.random().toString(36).slice(2, 9)}`;
50
84
 
@@ -135,7 +169,7 @@
135
169
  id: managerId,
136
170
  type: 'layer-manager',
137
171
  position: position as 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right',
138
- priority: 'high',
172
+ priority,
139
173
  zLayer: 'interactive',
140
174
  hasExpandedState: true,
141
175
  })
@@ -194,8 +228,8 @@
194
228
 
195
229
  // Sort by state order for drag-to-reorder support
196
230
  return [...result].sort((a, b) => {
197
- const orderA = layerStates.get(a.id)?.order ?? 0;
198
- const orderB = layerStates.get(b.id)?.order ?? 0;
231
+ const orderA = stateOf(a.id)?.order ?? 0;
232
+ const orderB = stateOf(b.id)?.order ?? 0;
199
233
  return orderA - orderB;
200
234
  });
201
235
  });
@@ -205,10 +239,33 @@
205
239
  showCategories ? groupLayersByCategory(filteredLayers) : null
206
240
  );
207
241
 
242
+ // Free-text headings: any layer with a `group` lists the panel by heading
243
+ const headingGroups = $derived(
244
+ layers.some((l) => l.group) ? groupLayersByHeading(filteredLayers) : null
245
+ );
246
+
247
+ // Loading and failures of switched-on layers, for screen readers
248
+ const statusText = $derived(
249
+ layers
250
+ .flatMap((layer) => {
251
+ const state = stateOf(layer.id);
252
+ if (!state?.visible) return [];
253
+ if (state.error) return [`${layer.name}: ${state.error}`];
254
+ return state.loading ? [`${layer.name} loading`] : [];
255
+ })
256
+ .join('. ')
257
+ );
258
+
208
259
  // Get visible layer states
209
260
  // Depend on stateVersion to recalculate when visibility or opacity changes
210
261
  const visibleLayerStates = $derived.by(() => {
211
262
  void stateVersion;
263
+ if (controlledStates) {
264
+ return layers.flatMap((l) => {
265
+ const state = stateOf(l.id);
266
+ return state?.visible ? [state] : [];
267
+ });
268
+ }
212
269
  return getLayerStatesArray(layerStates).filter((s) => s.visible);
213
270
  });
214
271
 
@@ -262,6 +319,8 @@
262
319
  // Manage sources and layers on the map
263
320
  // Use setTimeout to debounce updates and break reactive chains
264
321
  $effect(() => {
322
+ // The app draws its own layers: never touch the map
323
+ if (!manageLayers) return;
265
324
  // Read visibleLayerStates to establish dependency
266
325
  const states = visibleLayerStates;
267
326
  // Also re-sync after a style reload (setStyle drops our sources/layers),
@@ -294,7 +353,7 @@
294
353
  // (we already react to layer changes via visibleLayerStates)
295
354
  for (const state of states) {
296
355
  const layer = untrack(() => layers.find((l) => l.id === state.id));
297
- if (!layer) continue;
356
+ if (!layer || !isDrawable(layer)) continue;
298
357
 
299
358
  const sourceId = `lm-source-${layer.id}`;
300
359
  const layerId = `lm-layer-${layer.id}`;
@@ -523,6 +582,7 @@
523
582
  if (e.key === 'Escape') {
524
583
  isOpen = false;
525
584
  controlPosition.setExpanded(false);
585
+ toggleButton?.focus();
526
586
  }
527
587
  };
528
588
 
@@ -534,11 +594,17 @@
534
594
  });
535
595
 
536
596
  function handleToggleLayer(layerId: string) {
537
- const currentState = layerStates.get(layerId);
597
+ const currentState = stateOf(layerId);
538
598
  if (!currentState) return;
539
599
 
540
600
  const newVisible = !currentState.visible;
541
601
 
602
+ // Controlled: the app applies the change and passes the state back
603
+ if (controlledStates) {
604
+ onLayerChange?.(layerId, { ...currentState, visible: newVisible });
605
+ return;
606
+ }
607
+
542
608
  // Directly update the state map
543
609
  const newStates = new Map(layerStates);
544
610
  newStates.set(layerId, { ...currentState, visible: newVisible });
@@ -551,9 +617,14 @@
551
617
  }
552
618
 
553
619
  function handleOpacityChange(layerId: string, opacity: number) {
554
- const currentState = layerStates.get(layerId);
620
+ const currentState = stateOf(layerId);
555
621
  if (!currentState) return;
556
622
 
623
+ if (controlledStates) {
624
+ onLayerChange?.(layerId, { ...currentState, opacity });
625
+ return;
626
+ }
627
+
557
628
  // Directly update the state map
558
629
  const newStates = new Map(layerStates);
559
630
  newStates.set(layerId, { ...currentState, opacity });
@@ -695,8 +766,150 @@
695
766
  }
696
767
 
697
768
  const isTop = $derived(position.startsWith('top'));
769
+
770
+ let toggleButton = $state<HTMLButtonElement>();
771
+
772
+ // Fit the open panel to the map it opens over: from the button down to the
773
+ // map's visible edge (or up, for a bottom position), so the list scrolls
774
+ // inside the map instead of running off a phone screen. Re-measured on
775
+ // resize and when a mobile toolbar collapses (visualViewport).
776
+ let panelMaxHeight = $state<number | null>(null);
777
+ $effect(() => {
778
+ if (!isOpen || !toggleButton) return;
779
+ const button = toggleButton;
780
+ const measure = () => {
781
+ const area = button.closest<HTMLElement>('.maplibregl-map')?.getBoundingClientRect();
782
+ const vv = window.visualViewport;
783
+ const viewTop = vv ? vv.offsetTop : 0;
784
+ const viewBottom = vv ? vv.offsetTop + vv.height : window.innerHeight;
785
+ const top = Math.max(area?.top ?? viewTop, viewTop);
786
+ const bottom = Math.min(area?.bottom ?? viewBottom, viewBottom);
787
+ const rect = button.getBoundingClientRect();
788
+ // 4px gap to the button, 8px clear of the map edge
789
+ const room = isTop ? bottom - rect.bottom - 12 : rect.top - top - 12;
790
+ panelMaxHeight = Math.max(120, Math.floor(room));
791
+ };
792
+ measure();
793
+ window.addEventListener('resize', measure);
794
+ window.visualViewport?.addEventListener('resize', measure);
795
+ return () => {
796
+ window.removeEventListener('resize', measure);
797
+ window.visualViewport?.removeEventListener('resize', measure);
798
+ };
799
+ });
698
800
  </script>
699
801
 
802
+ {#snippet layerRow(layer: ListLayer)}
803
+ {@const state = stateOf(layer.id)}
804
+ {#if state}
805
+ <div
806
+ class="classic-layer-item"
807
+ role={allowReorder ? 'listitem' : undefined}
808
+ draggable={allowReorder}
809
+ ondragstart={allowReorder ? (e: DragEvent) => handleDragStart(e, layer.id) : undefined}
810
+ ondragover={allowReorder ? (e: DragEvent) => handleDragOver(e, layer.id) : undefined}
811
+ ondragleave={allowReorder ? handleDragLeave : undefined}
812
+ ondragend={allowReorder ? handleDragEnd : undefined}
813
+ ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
814
+ data-dragging={draggedId === layer.id || undefined}
815
+ data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
816
+ >
817
+ {#if allowReorder}
818
+ <span class="classic-layer-drag-handle text-muted-foreground">
819
+ <svg
820
+ width="12"
821
+ height="12"
822
+ viewBox="0 0 24 24"
823
+ fill="none"
824
+ stroke="currentColor"
825
+ stroke-width="2"
826
+ >
827
+ <circle cx="9" cy="6" r="1" fill="currentColor" />
828
+ <circle cx="15" cy="6" r="1" fill="currentColor" />
829
+ <circle cx="9" cy="12" r="1" fill="currentColor" />
830
+ <circle cx="15" cy="12" r="1" fill="currentColor" />
831
+ <circle cx="9" cy="18" r="1" fill="currentColor" />
832
+ <circle cx="15" cy="18" r="1" fill="currentColor" />
833
+ </svg>
834
+ </span>
835
+ {/if}
836
+
837
+ <Switch
838
+ checked={state.visible}
839
+ onchange={() => handleToggleLayer(layer.id)}
840
+ aria-label={`Toggle ${layer.name}`}
841
+ class="scale-75"
842
+ />
843
+
844
+ <div class="flex-1 min-w-0">
845
+ <div class="flex items-center gap-1">
846
+ <span class="text-sm text-foreground truncate">{layer.name}</span>
847
+ {#if state.loading}
848
+ <svg
849
+ class="classic-layer-loading w-3 h-3 text-muted-foreground"
850
+ viewBox="0 0 24 24"
851
+ fill="none"
852
+ stroke="currentColor"
853
+ stroke-width="2"
854
+ >
855
+ <path
856
+ d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
857
+ />
858
+ </svg>
859
+ {/if}
860
+ </div>
861
+ {#if state.error}
862
+ <span class="classic-layer-error">{state.error}</span>
863
+ {/if}
864
+ </div>
865
+
866
+ {#if showOpacity && state.visible}
867
+ <button
868
+ type="button"
869
+ class="text-muted-foreground hover:text-foreground p-1"
870
+ onclick={() => (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
871
+ aria-label={`Adjust ${layer.name} opacity`}
872
+ aria-expanded={expandedOpacity === layer.id}
873
+ >
874
+ <svg
875
+ width="14"
876
+ height="14"
877
+ viewBox="0 0 24 24"
878
+ fill="none"
879
+ stroke="currentColor"
880
+ stroke-width="2"
881
+ >
882
+ <circle cx="12" cy="12" r="10" />
883
+ <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
884
+ </svg>
885
+ </button>
886
+ {/if}
887
+ </div>
888
+
889
+ {#if expandedOpacity === layer.id}
890
+ <div class="px-3 pb-2">
891
+ <div class="flex items-center gap-2">
892
+ <span class="text-xs text-muted-foreground w-12">Opacity</span>
893
+ <input
894
+ type="range"
895
+ min="0"
896
+ max="100"
897
+ value={state.opacity * 100}
898
+ aria-label={`${layer.name} opacity`}
899
+ aria-valuetext={`${Math.round(state.opacity * 100)}%`}
900
+ oninput={(e) =>
901
+ handleOpacityChange(layer.id, Number((e.target as HTMLInputElement).value) / 100)}
902
+ class="classic-layer-opacity-slider flex-1"
903
+ />
904
+ <span class="text-xs text-muted-foreground w-8 text-right">
905
+ {Math.round(state.opacity * 100)}%
906
+ </span>
907
+ </div>
908
+ </div>
909
+ {/if}
910
+ {/if}
911
+ {/snippet}
912
+
700
913
  <div
701
914
  bind:this={containerElement}
702
915
  class={cn('absolute', !controlPosition.visible && 'invisible', className)}
@@ -708,14 +921,15 @@
708
921
  class={cn(
709
922
  'absolute classic-layer-panel-enter',
710
923
  'bg-card rounded-lg shadow-lg border border-border',
711
- 'w-64',
924
+ 'flex w-64 max-w-[calc(100vw-4rem)] flex-col',
712
925
  isTop ? 'top-full mt-1' : 'bottom-full mb-1',
713
926
  position.includes('right') ? 'right-0' : 'left-0'
714
927
  )}
928
+ style:max-height={panelMaxHeight === null ? undefined : `${panelMaxHeight}px`}
715
929
  >
716
930
  <!-- Header -->
717
931
  <div class="flex items-center justify-between p-3 border-b border-border">
718
- <span class="text-sm font-medium text-foreground">Layers</span>
932
+ <span class="text-sm font-medium text-foreground">{title}</span>
719
933
  {#if collapsible}
720
934
  <button
721
935
  type="button"
@@ -778,8 +992,25 @@
778
992
  {/if}
779
993
 
780
994
  <!-- Layer list -->
781
- <div class="max-h-64 overflow-y-auto">
782
- {#if showCategories && layerGroups && activeCategory === 'all'}
995
+ <div class="min-h-0 flex-1 overflow-y-auto overscroll-contain">
996
+ {#if headingGroups}
997
+ {#each headingGroups as [heading, headingLayers] (heading)}
998
+ <div>
999
+ <div
1000
+ class="px-3 py-2 text-xs font-medium text-muted-foreground uppercase tracking-wider"
1001
+ >
1002
+ {heading}
1003
+ </div>
1004
+ {#each headingLayers as layer (layer.id)}
1005
+ {@render layerRow(layer)}
1006
+ {/each}
1007
+ </div>
1008
+ {/each}
1009
+
1010
+ {#if filteredLayers.length === 0}
1011
+ <div class="p-4 text-center text-sm text-muted-foreground">No layers found</div>
1012
+ {/if}
1013
+ {:else if showCategories && layerGroups && activeCategory === 'all'}
783
1014
  <!-- Grouped by category -->
784
1015
  {#each categories as cat (cat)}
785
1016
  {@const catLayers = layerGroups![cat]}
@@ -791,122 +1022,7 @@
791
1022
  {CATEGORY_META[cat].label}
792
1023
  </div>
793
1024
  {#each catLayers as layer (layer.id)}
794
- {@const state = layerStates.get(layer.id)}
795
- {#if state}
796
- <div
797
- class="classic-layer-item"
798
- role={allowReorder ? 'listitem' : undefined}
799
- draggable={allowReorder}
800
- ondragstart={allowReorder
801
- ? (e: DragEvent) => handleDragStart(e, layer.id)
802
- : undefined}
803
- ondragover={allowReorder
804
- ? (e: DragEvent) => handleDragOver(e, layer.id)
805
- : undefined}
806
- ondragleave={allowReorder ? handleDragLeave : undefined}
807
- ondragend={allowReorder ? handleDragEnd : undefined}
808
- ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
809
- data-dragging={draggedId === layer.id || undefined}
810
- data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
811
- >
812
- {#if allowReorder}
813
- <span class="classic-layer-drag-handle text-muted-foreground">
814
- <svg
815
- width="12"
816
- height="12"
817
- viewBox="0 0 24 24"
818
- fill="none"
819
- stroke="currentColor"
820
- stroke-width="2"
821
- >
822
- <circle cx="9" cy="6" r="1" fill="currentColor" />
823
- <circle cx="15" cy="6" r="1" fill="currentColor" />
824
- <circle cx="9" cy="12" r="1" fill="currentColor" />
825
- <circle cx="15" cy="12" r="1" fill="currentColor" />
826
- <circle cx="9" cy="18" r="1" fill="currentColor" />
827
- <circle cx="15" cy="18" r="1" fill="currentColor" />
828
- </svg>
829
- </span>
830
- {/if}
831
-
832
- <Switch
833
- checked={state.visible}
834
- onchange={() => handleToggleLayer(layer.id)}
835
- aria-label={`Toggle ${layer.name}`}
836
- class="scale-75"
837
- />
838
-
839
- <div class="flex-1 min-w-0">
840
- <div class="flex items-center gap-1">
841
- <span class="text-sm text-foreground truncate">{layer.name}</span>
842
- {#if state.loading}
843
- <svg
844
- class="classic-layer-loading w-3 h-3 text-muted-foreground"
845
- viewBox="0 0 24 24"
846
- fill="none"
847
- stroke="currentColor"
848
- stroke-width="2"
849
- >
850
- <path
851
- d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
852
- />
853
- </svg>
854
- {/if}
855
- </div>
856
- {#if state.error}
857
- <span class="classic-layer-error">{state.error}</span>
858
- {/if}
859
- </div>
860
-
861
- {#if showOpacity && state.visible}
862
- <button
863
- type="button"
864
- class="text-muted-foreground hover:text-foreground p-1"
865
- onclick={() =>
866
- (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
867
- aria-label={`Adjust ${layer.name} opacity`}
868
- aria-expanded={expandedOpacity === layer.id}
869
- >
870
- <svg
871
- width="14"
872
- height="14"
873
- viewBox="0 0 24 24"
874
- fill="none"
875
- stroke="currentColor"
876
- stroke-width="2"
877
- >
878
- <circle cx="12" cy="12" r="10" />
879
- <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
880
- </svg>
881
- </button>
882
- {/if}
883
- </div>
884
-
885
- {#if expandedOpacity === layer.id}
886
- <div class="px-3 pb-2">
887
- <div class="flex items-center gap-2">
888
- <span class="text-xs text-muted-foreground w-12">Opacity</span>
889
- <input
890
- type="range"
891
- min="0"
892
- max="100"
893
- value={state.opacity * 100}
894
- aria-label={`${layer.name} opacity`}
895
- aria-valuetext={`${Math.round(state.opacity * 100)}%`}
896
- oninput={(e) =>
897
- handleOpacityChange(
898
- layer.id,
899
- Number((e.target as HTMLInputElement).value) / 100
900
- )}
901
- class="classic-layer-opacity-slider flex-1"
902
- />
903
- <span class="text-xs text-muted-foreground w-8 text-right">
904
- {Math.round(state.opacity * 100)}%
905
- </span>
906
- </div>
907
- </div>
908
- {/if}
909
- {/if}
1025
+ {@render layerRow(layer)}
910
1026
  {/each}
911
1027
  </div>
912
1028
  {/if}
@@ -914,122 +1030,7 @@
914
1030
  {:else}
915
1031
  <!-- Flat list -->
916
1032
  {#each filteredLayers as layer (layer.id)}
917
- {@const state = layerStates.get(layer.id)}
918
- {#if state}
919
- <div
920
- class="classic-layer-item"
921
- role={allowReorder ? 'listitem' : undefined}
922
- draggable={allowReorder}
923
- ondragstart={allowReorder
924
- ? (e: DragEvent) => handleDragStart(e, layer.id)
925
- : undefined}
926
- ondragover={allowReorder
927
- ? (e: DragEvent) => handleDragOver(e, layer.id)
928
- : undefined}
929
- ondragleave={allowReorder ? handleDragLeave : undefined}
930
- ondragend={allowReorder ? handleDragEnd : undefined}
931
- ondrop={allowReorder ? (e: DragEvent) => handleDrop(e, layer.id) : undefined}
932
- data-dragging={draggedId === layer.id || undefined}
933
- data-drag-over={dragOver?.id === layer.id ? dragOver.position : undefined}
934
- >
935
- {#if allowReorder}
936
- <span class="classic-layer-drag-handle text-muted-foreground">
937
- <svg
938
- width="12"
939
- height="12"
940
- viewBox="0 0 24 24"
941
- fill="none"
942
- stroke="currentColor"
943
- stroke-width="2"
944
- >
945
- <circle cx="9" cy="6" r="1" fill="currentColor" />
946
- <circle cx="15" cy="6" r="1" fill="currentColor" />
947
- <circle cx="9" cy="12" r="1" fill="currentColor" />
948
- <circle cx="15" cy="12" r="1" fill="currentColor" />
949
- <circle cx="9" cy="18" r="1" fill="currentColor" />
950
- <circle cx="15" cy="18" r="1" fill="currentColor" />
951
- </svg>
952
- </span>
953
- {/if}
954
-
955
- <Switch
956
- checked={state.visible}
957
- onchange={() => handleToggleLayer(layer.id)}
958
- aria-label={`Toggle ${layer.name}`}
959
- class="scale-75"
960
- />
961
-
962
- <div class="flex-1 min-w-0">
963
- <div class="flex items-center gap-1">
964
- <span class="text-sm text-foreground truncate">{layer.name}</span>
965
- {#if state.loading}
966
- <svg
967
- class="classic-layer-loading w-3 h-3 text-muted-foreground"
968
- viewBox="0 0 24 24"
969
- fill="none"
970
- stroke="currentColor"
971
- stroke-width="2"
972
- >
973
- <path
974
- d="M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"
975
- />
976
- </svg>
977
- {/if}
978
- </div>
979
- {#if state.error}
980
- <span class="classic-layer-error">{state.error}</span>
981
- {/if}
982
- </div>
983
-
984
- {#if showOpacity && state.visible}
985
- <button
986
- type="button"
987
- class="text-muted-foreground hover:text-foreground p-1"
988
- onclick={() =>
989
- (expandedOpacity = expandedOpacity === layer.id ? null : layer.id)}
990
- aria-label={`Adjust ${layer.name} opacity`}
991
- aria-expanded={expandedOpacity === layer.id}
992
- >
993
- <svg
994
- width="14"
995
- height="14"
996
- viewBox="0 0 24 24"
997
- fill="none"
998
- stroke="currentColor"
999
- stroke-width="2"
1000
- >
1001
- <circle cx="12" cy="12" r="10" />
1002
- <path d="M12 2a10 10 0 0 1 0 20" fill="currentColor" opacity="0.3" />
1003
- </svg>
1004
- </button>
1005
- {/if}
1006
- </div>
1007
-
1008
- {#if expandedOpacity === layer.id}
1009
- <div class="px-3 pb-2">
1010
- <div class="flex items-center gap-2">
1011
- <span class="text-xs text-muted-foreground w-12">Opacity</span>
1012
- <input
1013
- type="range"
1014
- min="0"
1015
- max="100"
1016
- value={state.opacity * 100}
1017
- aria-label={`${layer.name} opacity`}
1018
- aria-valuetext={`${Math.round(state.opacity * 100)}%`}
1019
- oninput={(e) =>
1020
- handleOpacityChange(
1021
- layer.id,
1022
- Number((e.target as HTMLInputElement).value) / 100
1023
- )}
1024
- class="classic-layer-opacity-slider flex-1"
1025
- />
1026
- <span class="text-xs text-muted-foreground w-8 text-right">
1027
- {Math.round(state.opacity * 100)}%
1028
- </span>
1029
- </div>
1030
- </div>
1031
- {/if}
1032
- {/if}
1033
+ {@render layerRow(layer)}
1033
1034
  {/each}
1034
1035
 
1035
1036
  {#if filteredLayers.length === 0}
@@ -1042,15 +1043,17 @@
1042
1043
 
1043
1044
  <!-- Toggle button -->
1044
1045
  <button
1046
+ bind:this={toggleButton}
1045
1047
  type="button"
1046
1048
  class={cn(
1047
1049
  'w-[40px] h-[40px] flex items-center justify-center',
1048
1050
  'bg-card rounded shadow-lg border border-border',
1049
1051
  'hover:bg-muted cursor-pointer',
1050
- 'text-foreground'
1052
+ 'text-foreground',
1053
+ buttonClass
1051
1054
  )}
1052
1055
  onclick={handleToggle}
1053
- aria-label="Toggle layer manager"
1056
+ aria-label={buttonLabel}
1054
1057
  aria-expanded={isOpen}
1055
1058
  aria-haspopup="true"
1056
1059
  >
@@ -1071,4 +1074,5 @@
1071
1074
  <line x1="12" y1="22.76" x2="12" y2="11" />
1072
1075
  </svg>
1073
1076
  </button>
1077
+ <p class="sr-only" aria-live="polite">{statusText}</p>
1074
1078
  </div>
@@ -6,8 +6,8 @@
6
6
  export { MapContainer, MapSkeleton, MapError, MapEmpty, Map, Source, Marker, Popup, PopupCard, PopupHeader, PopupContent, PopupFooter, useLayer, type UseLayerOptions, FillLayer, LineLayer, CircleLayer, SymbolLayer, FillExtrusionLayer, HeatmapLayer, Legend, LegendGroup, CoordinateDisplay, BasemapSwitcher, LayerManager, CustomControl, type CustomControlProps, FitBoundsControl, type FitBoundsControlProps, DeckOverlay, type SvelteFeatureClickEventParams, type SvelteFeatureHoverEventParams, } from './components/index.js';
7
7
  export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useMapInstance, 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, MarkerDragEventParams, 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
- 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';
9
+ export type { LngLat, MapBounds, BoundsArray, MapViewport, GeoJSONFeature, GeoJSONFeatureCollection, MarkerData, MapClickEventParams, MapHoverEventParams, FeatureClickEventParams, FeatureHoverEventParams, MarkerClickEventParams, MarkerDragEventParams, 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, LayerManagerEntry, LayerManagerLayerState, ExtendedControlPosition, ControlPriority, ZIndexLayer, ControlType, ControlOffset, } from '@classic-homes/maps-core';
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, groupLayersByHeading, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
11
11
  export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle, calculateBounds, extendBounds, combineBounds, isValidBounds, boundsOfPositions, padBounds, 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, createClusterStyles, createClusterCirclePaint, createClusterTextLayout, } from '@classic-homes/maps-core';
package/dist/lib/index.js CHANGED
@@ -20,7 +20,7 @@ export { useMapTheme, useReducedMotion, useMapContext, tryUseMapContext, useMapI
20
20
  // Utils
21
21
  export { cn } from './utils.js';
22
22
  // Re-export layer presets and utilities from maps-core
23
- 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';
23
+ 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, groupLayersByHeading, getLayerCategories, createInitialLayerStates, toggleLayerVisibility, setLayerOpacity, } from '@classic-homes/maps-core';
24
24
  // Re-export theme and utilities from maps-core
25
25
  export { THEME_LIGHT, THEME_DARK, lightTheme, darkTheme, lightBasicStyle, darkBasicStyle, generateMapDescription, formatCoordinates, formatDistance, formatArea, createHoverExpression, createSelectionExpression, getHighlightStyle, getSelectionStyle,
26
26
  // Bounds utilities
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-svelte",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Svelte MapLibre components for Classic Theme",
5
5
  "keywords": [
6
6
  "maps",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest run"
38
38
  },
39
39
  "dependencies": {
40
- "@classic-homes/maps-core": "^0.10.0",
40
+ "@classic-homes/maps-core": "^0.11.0",
41
41
  "@classic-homes/theme-svelte": "*",
42
42
  "@classic-homes/theme-tokens": "*",
43
43
  "clsx": "^2.1.0",