leaflet-theme-control 0.0.1

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.
@@ -0,0 +1,186 @@
1
+ import * as L from "leaflet";
2
+
3
+ declare module "leaflet" {
4
+ /**
5
+ * Definition of a theme with its properties.
6
+ */
7
+ interface Theme {
8
+ /**
9
+ * The display label for the theme.
10
+ */
11
+ label: string;
12
+
13
+ /**
14
+ * CSS filter string to apply to map tiles and elements.
15
+ * @example "invert(1) hue-rotate(180deg) saturate(0.6) brightness(0.5)"
16
+ */
17
+ filter: string;
18
+
19
+ /**
20
+ * Icon to display in the theme button (emoji or HTML).
21
+ * @default "🎨"
22
+ */
23
+ icon?: string;
24
+
25
+ /**
26
+ * Style of the Leaflet controls for this theme.
27
+ * @default "light"
28
+ */
29
+ controlStyle?: "light" | "dark";
30
+
31
+ /**
32
+ * CSS class to add to the document root when this theme is active.
33
+ */
34
+ className?: string;
35
+
36
+ /**
37
+ * Additional CSS selectors to apply the filter to.
38
+ * Can be a single selector or an array of selectors.
39
+ * @example ".my-custom-element"
40
+ * @example [".element1", ".element2"]
41
+ */
42
+ applyToSelectors?: string | string[];
43
+ }
44
+
45
+ /**
46
+ * Collection of themes keyed by their unique identifiers.
47
+ */
48
+ interface ThemeCollection {
49
+ [themeKey: string]: Theme;
50
+ }
51
+
52
+ /**
53
+ * Options for the ThemeControl.
54
+ */
55
+ interface ThemeControlOptions extends ControlOptions {
56
+ /**
57
+ * Collection of available themes.
58
+ * If not provided, uses DEFAULT_THEMES (light, dark, grayscale, custom).
59
+ */
60
+ themes?: ThemeCollection;
61
+
62
+ /**
63
+ * The default theme to use on initial load.
64
+ * @default "light"
65
+ */
66
+ defaultTheme?: string;
67
+
68
+ /**
69
+ * LocalStorage key for saving the selected theme.
70
+ * @default "leaflet-theme"
71
+ */
72
+ storageKey?: string;
73
+
74
+ /**
75
+ * Automatically detect and use system dark mode preference.
76
+ * @default true
77
+ */
78
+ detectSystemTheme?: boolean;
79
+
80
+ /**
81
+ * CSS selector for the elements to apply the theme filter to.
82
+ * @default ".leaflet-tile-pane"
83
+ */
84
+ cssSelector?: string;
85
+
86
+ /**
87
+ * Add the theme toggle button to the map.
88
+ * Set to false for programmatic control only.
89
+ * @default true
90
+ */
91
+ addButton?: boolean;
92
+
93
+ /**
94
+ * Enable the theme editor UI for customizing themes.
95
+ * @default false
96
+ */
97
+ enableEditor?: boolean;
98
+
99
+ /**
100
+ * Callback function called when the theme changes.
101
+ * @param themeKey - The key of the newly selected theme
102
+ * @param theme - The theme object
103
+ */
104
+ onChange?: (themeKey: string, theme: Theme) => void;
105
+
106
+ /**
107
+ * Custom function to get translated theme labels.
108
+ * @param themeKey - The key of the theme
109
+ * @returns The translated label
110
+ */
111
+ getLabel?: (themeKey: string) => string;
112
+
113
+ /**
114
+ * Custom function to get translated editor UI labels.
115
+ * @param key - The label key (e.g., "selectTheme", "customize", "close")
116
+ * @returns The translated label
117
+ */
118
+ getEditorLabels?: (key: string) => string;
119
+ }
120
+
121
+ /**
122
+ * Leaflet control for switching between visual themes.
123
+ *
124
+ * Supports multiple themes using CSS filters:
125
+ * - Light (default)
126
+ * - Dark (inverted colors)
127
+ * - Grayscale (black & white)
128
+ * - Custom themes via options
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * import { ThemeControl } from 'leaflet-theme-control';
133
+ *
134
+ * const themeControl = new ThemeControl({
135
+ * position: 'topright',
136
+ * defaultTheme: 'dark',
137
+ * enableEditor: true,
138
+ * onChange: (themeKey, theme) => {
139
+ * console.log('Theme changed to:', themeKey);
140
+ * }
141
+ * }).addTo(map);
142
+ * ```
143
+ */
144
+ class ThemeControl extends Control {
145
+ options: ThemeControlOptions;
146
+
147
+ /**
148
+ * Creates a new ThemeControl instance.
149
+ * @param options - Configuration options
150
+ */
151
+ constructor(options?: ThemeControlOptions);
152
+
153
+ /**
154
+ * Sets the active theme.
155
+ * @param themeKey - The key of the theme to activate
156
+ */
157
+ setTheme(themeKey: string): void;
158
+
159
+ /**
160
+ * Gets the currently active theme key.
161
+ * @returns The key of the current theme
162
+ */
163
+ getCurrentTheme(): string;
164
+
165
+ /**
166
+ * Gets all available themes.
167
+ * @returns The theme collection
168
+ */
169
+ getThemes(): ThemeCollection;
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Default theme presets included with the plugin.
175
+ */
176
+ export const DEFAULT_THEMES: {
177
+ light: L.Theme;
178
+ dark: L.Theme;
179
+ grayscale: L.Theme;
180
+ custom: L.Theme;
181
+ };
182
+
183
+ /**
184
+ * ThemeControl class for managing map themes.
185
+ */
186
+ export { ThemeControl } from "leaflet";