leaflet-theme-control 0.0.5 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "leaflet-theme-control",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
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",
@@ -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