leaflet-theme-control 0.1.2 → 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
@@ -6,14 +6,15 @@ A Leaflet control for switching between visual themes using CSS filters. Perfect
6
6
 
7
7
  ## Features
8
8
 
9
- - 🌓 **Multiple themes**: Light, Dark, Grayscale, Custom
10
- - â™ŋ **Accessibility**: Adaptable themes for better visibility
11
- - ðŸŽĻ **CSS Filters**: No need for multiple tile sources
12
- - ðŸ’ū **Persistent**: Saves user preference in localStorage
13
- - 🔍 **System Detection**: Automatically detects OS dark mode preference
14
- - 🌍 **i18n Ready**: Customizable labels via callback function
15
- - ðŸŠķ **Lightweight**: Zero dependencies (except Leaflet)
16
- - ⚡ **Performance**: Instant theme switching without reloading tiles
9
+ - **Multiple themes**: Light, Dark, Grayscale, Custom
10
+ - **Theme Editor**: Customize filters with live preview sliders (optional)
11
+ - **Accessibility**: Adaptable themes for better visibility
12
+ - **CSS Filters**: No need for multiple tile sources
13
+ - **Persistent**: Saves user preference in localStorage
14
+ - **System Detection**: Automatically detects OS dark mode preference
15
+ - **i18n Ready**: Customizable labels with auto-update on language change
16
+ - **Lightweight**: Zero dependencies (except Leaflet)
17
+ - **Performance**: Instant theme switching without reloading tiles
17
18
 
18
19
  ## Installation
19
20
 
@@ -32,31 +33,13 @@ import "leaflet-theme-control/src/leaflet-theme-control.css";
32
33
 
33
34
  **Without bundler (plain HTML):**
34
35
 
35
- ```html
36
- <link rel="stylesheet" href="node_modules/leaflet-theme-control/src/leaflet-theme-control.css" />
37
-
38
- <script type="importmap">
39
- {
40
- "imports": {
41
- "leaflet-theme-control": "./node_modules/leaflet-theme-control/src/leaflet-theme-control.js"
42
- }
43
- }
44
- </script>
45
-
46
- <script type="module">
47
- import { ThemeControl } from "leaflet-theme-control";
48
- // Your code here
49
- </script>
50
- ```
51
-
52
- **Or via CDN (coming soon):**
53
-
54
36
  ```html
55
37
  <link rel="stylesheet" href="https://unpkg.com/leaflet-theme-control/src/leaflet-theme-control.css" />
56
38
 
57
39
  <script type="importmap">
58
40
  {
59
41
  "imports": {
42
+ "leaflet": "https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.js",
60
43
  "leaflet-theme-control": "https://unpkg.com/leaflet-theme-control/src/leaflet-theme-control.js"
61
44
  }
62
45
  }
@@ -64,23 +47,10 @@ import "leaflet-theme-control/src/leaflet-theme-control.css";
64
47
 
65
48
  <script type="module">
66
49
  import { ThemeControl } from "leaflet-theme-control";
50
+ // Your code here
67
51
  </script>
68
52
  ```
69
53
 
70
- ### As local module (development)
71
-
72
- **HTML:**
73
-
74
- ```html
75
- <link rel="stylesheet" href="./third-party/leaflet-theme-control/src/leaflet-theme-control.css" />
76
- ```
77
-
78
- **JavaScript:**
79
-
80
- ```javascript
81
- import { ThemeControl } from "./third-party/leaflet-theme-control/src/leaflet-theme-control.js";
82
- ```
83
-
84
54
  ## Usage
85
55
 
86
56
  ### Basic Example
@@ -209,7 +179,7 @@ console.log(themeControl.getCurrentTheme()); // "dark"
209
179
 
210
180
  // Open editor from custom button
211
181
  myCustomButton.onclick = () => {
212
- themeControl.editor.open();
182
+ themeControl.editor.openThemeSelector();
213
183
  };
214
184
  ```
215
185
 
@@ -237,17 +207,18 @@ See [examples/api.html](examples/api.html) for a complete example.
237
207
 
238
208
  ### Methods
239
209
 
240
- | Method | Returns | Description |
241
- | -------------------- | -------- | ------------------------ |
242
- | `setTheme(themeKey)` | `void` | Switch to specific theme |
243
- | `getCurrentTheme()` | `String` | Get current theme key |
244
- | `getThemes()` | `Object` | Get all available themes |
210
+ | Method | Returns | Description |
211
+ | --------------------- | -------- | ------------------------------------------------- |
212
+ | `setTheme(themeKey)` | `void` | Switch to specific theme |
213
+ | `getCurrentTheme()` | `String` | Get current theme key |
214
+ | `getThemes()` | `Object` | Get all available themes |
215
+ | `updateButtonLabel()` | `void` | Update button label (auto-called on `html[lang]`) |
245
216
 
246
217
  ### Editor API (when `enableEditor: true`)
247
218
 
248
219
  | Method | Returns | Description |
249
220
  | ---------------------------------- | ------- | ------------------------------ |
250
- | `editor.open()` | `void` | Open theme selector panel |
221
+ | `editor.openThemeSelector()` | `void` | Open theme selector panel |
251
222
  | `editor.openThemeEditor(themeKey)` | `void` | Open editor for specific theme |
252
223
  | `editor.close()` | `void` | Close editor panel |
253
224
 
@@ -258,14 +229,6 @@ See [examples/api.html](examples/api.html) for a complete example.
258
229
  - **Grayscale**: Black and white for printing or reduced distraction
259
230
  - **Custom**: Fully customizable theme with combined filters (editable via theme editor)
260
231
 
261
- ## Browser Support
262
-
263
- Works in all modern browsers that support CSS filters:
264
-
265
- - Chrome/Edge 18+
266
- - Firefox 35+
267
- - Safari 9.1+
268
-
269
232
  ## License
270
233
 
271
234
  MIT License. See [LICENSE](LICENSE.md) for details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-theme-control",
3
- "version": "0.1.2",
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",
@@ -25,11 +25,14 @@
25
25
  "leaflet",
26
26
  "dark-mode",
27
27
  "theme",
28
+ "theme-editor",
28
29
  "accessibility",
29
30
  "css-filter",
30
31
  "map",
31
32
  "grayscale",
32
- "high-contrast"
33
+ "high-contrast",
34
+ "filter",
35
+ "leaflet-plugin"
33
36
  ],
34
37
  "author": "Kristjan ESPERANTO",
35
38
  "license": "MIT",
@@ -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