leaflet-theme-control 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -8,13 +8,13 @@ A Leaflet control for switching between visual themes using CSS filters. Perfect
8
8
 
9
9
  - **Multiple themes**: Light, Dark, Grayscale, Custom
10
10
  - **Theme Editor**: Customize filters with live preview sliders (optional)
11
- - **Accessibility**: Adaptable themes for better visibility
11
+ - **Accessibility**: Adaptable themes for better visibility
12
12
  - **CSS Filters**: No need for multiple tile sources
13
13
  - **Persistent**: Saves user preference in localStorage
14
14
  - **System Detection**: Automatically detects OS dark mode preference
15
15
  - **i18n Ready**: Customizable labels with auto-update on language change
16
16
  - **Lightweight**: Zero dependencies (except Leaflet)
17
- - **Performance**: Instant theme switching without reloading tiles
17
+ - **Performance**: Instant theme switching without reloading tiles
18
18
 
19
19
  ## Installation
20
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-theme-control",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A Leaflet control for switching between visual themes (light, dark, grayscale, custom, etc.) using CSS filters",
5
5
  "main": "src/leaflet-theme-control.js",
6
6
  "module": "src/leaflet-theme-control.js",
@@ -51,6 +51,16 @@ export class ThemeControl extends Control {
51
51
  })
52
52
  }
53
53
 
54
+ // Store original themes for reset functionality in editor
55
+ // This ensures reset uses user-provided values, not DEFAULT_THEMES
56
+ this.originalThemes = {}
57
+ for (const [key, theme] of Object.entries(this.options.themes)) {
58
+ this.originalThemes[key] = {
59
+ filter: theme.filter,
60
+ controlStyle: theme.controlStyle,
61
+ }
62
+ }
63
+
54
64
  this.root = document.documentElement
55
65
  this.savedTheme = localStorage.getItem(this.options.storageKey)
56
66
 
@@ -593,16 +593,16 @@ export class ThemeEditor {
593
593
  delete this.customFilters[themeKey]
594
594
  this._saveCustomFilters()
595
595
 
596
- // Restore default filter and controlStyle from DEFAULT_THEMES
596
+ // Restore original filter and controlStyle from user-provided themes
597
597
  // but KEEP user-defined properties like applyToSelectors
598
- const defaultTheme = DEFAULT_THEMES[themeKey]
598
+ const originalTheme = this.themeControl.originalThemes[themeKey]
599
599
  const currentTheme = this.themeControl.options.themes[themeKey]
600
600
 
601
- if (defaultTheme && currentTheme) {
601
+ if (originalTheme && currentTheme) {
602
602
  // Only reset the editable properties (filter, controlStyle)
603
603
  // Keep other properties like applyToSelectors, icon, label, className
604
- currentTheme.filter = defaultTheme.filter
605
- currentTheme.controlStyle = defaultTheme.controlStyle
604
+ currentTheme.filter = originalTheme.filter
605
+ currentTheme.controlStyle = originalTheme.controlStyle
606
606
  }
607
607
  else if (!currentTheme) {
608
608
  // Theme doesn't exist - this shouldn't happen
@@ -610,8 +610,8 @@ export class ThemeEditor {
610
610
  return
611
611
  }
612
612
  else {
613
- // For custom themes not in DEFAULT_THEMES, we can't reset
614
- console.warn(`Theme "${themeKey}" has no default in DEFAULT_THEMES, cannot reset filter values`)
613
+ // For themes not in originalThemes, we can't reset
614
+ console.warn(`Theme "${themeKey}" has no original values, cannot reset filter values`)
615
615
  }
616
616
 
617
617
  // Reapply theme if it's currently active
package/types/index.d.ts CHANGED
@@ -130,6 +130,28 @@ declare module "leaflet" {
130
130
  panelZIndex?: number;
131
131
  }
132
132
 
133
+ /**
134
+ * Theme editor for customizing theme filters.
135
+ * Only available when enableEditor is true.
136
+ */
137
+ class ThemeEditor {
138
+ /**
139
+ * Opens the theme selector panel.
140
+ */
141
+ openThemeSelector(): void;
142
+
143
+ /**
144
+ * Opens the theme editor for a specific theme.
145
+ * @param themeKey - The key of the theme to edit
146
+ */
147
+ openThemeEditor(themeKey: string): void;
148
+
149
+ /**
150
+ * Closes the editor panel.
151
+ */
152
+ close(): void;
153
+ }
154
+
133
155
  /**
134
156
  * Leaflet control for switching between visual themes.
135
157
  *
@@ -156,6 +178,11 @@ declare module "leaflet" {
156
178
  class ThemeControl extends Control {
157
179
  options: ThemeControlOptions;
158
180
 
181
+ /**
182
+ * Theme editor instance (only available when enableEditor is true).
183
+ */
184
+ editor?: ThemeEditor;
185
+
159
186
  /**
160
187
  * Creates a new ThemeControl instance.
161
188
  * @param options - Configuration options