leaflet-theme-control 0.0.5 → 0.1.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.
- package/package.json +2 -2
- package/src/leaflet-theme-control.js +28 -0
- package/types/index.d.ts +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "leaflet-theme-control",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/kristjanesperanto/leaflet-theme-control/issues"
|
|
42
42
|
},
|
|
43
|
-
"homepage": "https://github.
|
|
43
|
+
"homepage": "https://kristjanesperanto.github.io/leaflet-theme-control/",
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"leaflet": ">=2.0.0-alpha.1"
|
|
46
46
|
},
|
|
@@ -57,6 +57,9 @@ export class ThemeControl extends Control {
|
|
|
57
57
|
// AbortController for automatic event cleanup
|
|
58
58
|
this._abortController = new AbortController()
|
|
59
59
|
|
|
60
|
+
// Setup MutationObserver to watch for language changes on html[lang]
|
|
61
|
+
this._setupLanguageObserver()
|
|
62
|
+
|
|
60
63
|
// Setup media query listener for system theme changes
|
|
61
64
|
if (this.options.detectSystemTheme) {
|
|
62
65
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
|
@@ -143,6 +146,12 @@ export class ThemeControl extends Control {
|
|
|
143
146
|
// Abort all event listeners
|
|
144
147
|
this._abortController.abort()
|
|
145
148
|
|
|
149
|
+
// Disconnect language observer
|
|
150
|
+
if (this._langObserver) {
|
|
151
|
+
this._langObserver.disconnect()
|
|
152
|
+
this._langObserver = null
|
|
153
|
+
}
|
|
154
|
+
|
|
146
155
|
// Cleanup editor
|
|
147
156
|
if (this.editor) {
|
|
148
157
|
this.editor.cleanup()
|
|
@@ -152,6 +161,25 @@ export class ThemeControl extends Control {
|
|
|
152
161
|
this.map = null
|
|
153
162
|
}
|
|
154
163
|
|
|
164
|
+
_setupLanguageObserver() {
|
|
165
|
+
// Watch for changes to html[lang] attribute
|
|
166
|
+
this._langObserver = new MutationObserver((mutations) => {
|
|
167
|
+
for (const mutation of mutations) {
|
|
168
|
+
if (mutation.type === 'attributes' && mutation.attributeName === 'lang') {
|
|
169
|
+
// Language changed, update button label
|
|
170
|
+
this.updateButtonLabel()
|
|
171
|
+
break
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
// Observe the html element for lang attribute changes
|
|
177
|
+
this._langObserver.observe(document.documentElement, {
|
|
178
|
+
attributes: true,
|
|
179
|
+
attributeFilter: ['lang'],
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
155
183
|
_updateButton(button, themeKey) {
|
|
156
184
|
if (!button) return // No button if addButton: false
|
|
157
185
|
|
package/types/index.d.ts
CHANGED
|
@@ -116,6 +116,18 @@ declare module "leaflet" {
|
|
|
116
116
|
* @returns The translated label
|
|
117
117
|
*/
|
|
118
118
|
getEditorLabels?: (key: string) => string;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Position of the theme editor panel.
|
|
122
|
+
* @default "topright"
|
|
123
|
+
*/
|
|
124
|
+
panelPosition?: "topright" | "topleft" | "bottomright" | "bottomleft";
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Z-index for the theme editor panel.
|
|
128
|
+
* @default 1000
|
|
129
|
+
*/
|
|
130
|
+
panelZIndex?: number;
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
/**
|
|
@@ -167,6 +179,13 @@ declare module "leaflet" {
|
|
|
167
179
|
* @returns The theme collection
|
|
168
180
|
*/
|
|
169
181
|
getThemes(): ThemeCollection;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Updates the button label text.
|
|
185
|
+
* Useful for updating translations after a language change.
|
|
186
|
+
* Called automatically when html[lang] attribute changes (since v0.1.0).
|
|
187
|
+
*/
|
|
188
|
+
updateButtonLabel(): void;
|
|
170
189
|
}
|
|
171
190
|
}
|
|
172
191
|
|