@lukso/core 1.1.0-dev.f500300 → 1.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.
Files changed (72) hide show
  1. package/README.md +0 -55
  2. package/dist/chains/index.cjs +0 -1
  3. package/dist/chains/index.cjs.map +1 -1
  4. package/dist/chains/index.js +0 -1
  5. package/dist/chunk-AMRGSLR5.cjs +1 -0
  6. package/dist/chunk-AMRGSLR5.cjs.map +1 -0
  7. package/dist/chunk-DKEXQFNE.js +1 -0
  8. package/dist/chunk-DKXHVRHM.js +84 -0
  9. package/dist/chunk-DKXHVRHM.js.map +1 -0
  10. package/dist/chunk-MBIRTPNM.cjs +84 -0
  11. package/dist/chunk-MBIRTPNM.cjs.map +1 -0
  12. package/dist/config.cjs +0 -1
  13. package/dist/config.cjs.map +1 -1
  14. package/dist/config.js +0 -1
  15. package/dist/index.cjs +5 -14
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +1 -2
  18. package/dist/index.d.ts +1 -2
  19. package/dist/index.js +4 -13
  20. package/dist/mixins/device.cjs +0 -1
  21. package/dist/mixins/device.cjs.map +1 -1
  22. package/dist/mixins/device.js +0 -1
  23. package/dist/mixins/index.cjs +2 -7
  24. package/dist/mixins/index.cjs.map +1 -1
  25. package/dist/mixins/index.d.cts +0 -1
  26. package/dist/mixins/index.d.ts +0 -1
  27. package/dist/mixins/index.js +2 -7
  28. package/dist/mixins/intl.cjs +0 -1
  29. package/dist/mixins/intl.cjs.map +1 -1
  30. package/dist/mixins/intl.js +0 -1
  31. package/dist/services/device.cjs +0 -1
  32. package/dist/services/device.cjs.map +1 -1
  33. package/dist/services/device.js +0 -1
  34. package/dist/services/index.cjs +0 -1
  35. package/dist/services/index.cjs.map +1 -1
  36. package/dist/services/index.js +0 -1
  37. package/dist/services/intl.cjs +0 -1
  38. package/dist/services/intl.cjs.map +1 -1
  39. package/dist/services/intl.js +0 -1
  40. package/dist/utils/index.cjs +2 -7
  41. package/dist/utils/index.cjs.map +1 -1
  42. package/dist/utils/index.d.cts +1 -34
  43. package/dist/utils/index.d.ts +1 -34
  44. package/dist/utils/index.js +1 -6
  45. package/package.json +2 -8
  46. package/src/mixins/index.ts +0 -1
  47. package/src/utils/index.ts +0 -1
  48. package/dist/chunk-CUDG6NPH.cjs +0 -111
  49. package/dist/chunk-CUDG6NPH.cjs.map +0 -1
  50. package/dist/chunk-DWXFDFMM.cjs +0 -1
  51. package/dist/chunk-DWXFDFMM.cjs.map +0 -1
  52. package/dist/chunk-EUXUH3YW.js +0 -15
  53. package/dist/chunk-GFLV5EJV.js +0 -159
  54. package/dist/chunk-GFLV5EJV.js.map +0 -1
  55. package/dist/chunk-JEE6C34P.js +0 -1
  56. package/dist/chunk-JEE6C34P.js.map +0 -1
  57. package/dist/chunk-LQIOVPBE.js +0 -111
  58. package/dist/chunk-LQIOVPBE.js.map +0 -1
  59. package/dist/chunk-QU6NUTY6.cjs +0 -159
  60. package/dist/chunk-QU6NUTY6.cjs.map +0 -1
  61. package/dist/chunk-ZBDE64SD.cjs +0 -15
  62. package/dist/chunk-ZBDE64SD.cjs.map +0 -1
  63. package/dist/mixins/theme.cjs +0 -8
  64. package/dist/mixins/theme.cjs.map +0 -1
  65. package/dist/mixins/theme.d.cts +0 -45
  66. package/dist/mixins/theme.d.ts +0 -45
  67. package/dist/mixins/theme.js +0 -8
  68. package/dist/mixins/theme.js.map +0 -1
  69. package/src/mixins/__tests__/theme.spec.ts +0 -478
  70. package/src/mixins/theme.ts +0 -172
  71. package/src/utils/url-resolver.ts +0 -93
  72. /package/dist/{chunk-EUXUH3YW.js.map → chunk-DKEXQFNE.js.map} +0 -0
@@ -1,478 +0,0 @@
1
- import { html, LitElement } from 'lit'
2
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3
- import { withTheme } from '../theme'
4
-
5
- describe('withTheme Mixin', () => {
6
- let element: any
7
- let TestComponent: any
8
- let tagName: string
9
-
10
- beforeEach(() => {
11
- // Create a unique tag name for each test to avoid registration conflicts
12
- tagName = `test-theme-${Math.random().toString(36).slice(2)}`
13
-
14
- // Create a test component using the mixin
15
- TestComponent = class extends withTheme(LitElement) {
16
- render() {
17
- return html`
18
- <div class="test-content bg-neutral-100 dark:bg-neutral-10">
19
- Theme: ${this.theme}
20
- </div>
21
- `
22
- }
23
- }
24
-
25
- // Register the component before instantiation
26
- if (!customElements.get(tagName)) {
27
- customElements.define(tagName, TestComponent)
28
- }
29
-
30
- element = new TestComponent()
31
- })
32
-
33
- afterEach(() => {
34
- if (element?.parentElement) {
35
- element.remove()
36
- }
37
- })
38
-
39
- describe('Initialization', () => {
40
- it('should have default theme property set to "light"', () => {
41
- expect(element.theme).toBe('light')
42
- })
43
-
44
- it('should have isDark property set to false by default', () => {
45
- expect(element.isDark).toBe(false)
46
- })
47
-
48
- it('should have theme property reflected to attribute', async () => {
49
- document.body.appendChild(element)
50
- await element.updateComplete
51
-
52
- expect(element.hasAttribute('theme')).toBe(true)
53
- expect(element.getAttribute('theme')).toBe('light')
54
- })
55
- })
56
-
57
- describe('Theme Root Creation', () => {
58
- it('should create a theme root div', async () => {
59
- document.body.appendChild(element)
60
- await element.updateComplete
61
-
62
- const shadowRoot = element.shadowRoot
63
- expect(shadowRoot).toBeDefined()
64
-
65
- const themeRoot = shadowRoot?.querySelector('[data-theme-root]')
66
- expect(themeRoot).toBeDefined()
67
- expect(themeRoot?.tagName).toBe('DIV')
68
- })
69
-
70
- it('should have data-theme-root attribute', async () => {
71
- document.body.appendChild(element)
72
- await element.updateComplete
73
-
74
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
75
- expect(themeRoot?.hasAttribute('data-theme-root')).toBe(true)
76
- })
77
-
78
- it('should render content inside theme root', async () => {
79
- document.body.appendChild(element)
80
- await element.updateComplete
81
-
82
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
83
- const content = themeRoot?.querySelector('.test-content')
84
- expect(content).toBeDefined()
85
- })
86
- })
87
-
88
- describe('Light Theme', () => {
89
- it('should not have dark class when theme is light', async () => {
90
- element.theme = 'light'
91
- document.body.appendChild(element)
92
- await element.updateComplete
93
-
94
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
95
- expect(themeRoot?.classList.contains('dark')).toBe(false)
96
- })
97
-
98
- it('should set isDark to false when theme is light', async () => {
99
- element.theme = 'light'
100
- document.body.appendChild(element)
101
- await element.updateComplete
102
-
103
- expect(element.isDark).toBe(false)
104
- })
105
-
106
- it('should update attribute when theme is set to light', async () => {
107
- element.theme = 'light'
108
- document.body.appendChild(element)
109
- await element.updateComplete
110
-
111
- expect(element.getAttribute('theme')).toBe('light')
112
- })
113
- })
114
-
115
- describe('Dark Theme', () => {
116
- it('should have dark class when theme is dark', async () => {
117
- element.theme = 'dark'
118
- document.body.appendChild(element)
119
- await element.updateComplete
120
-
121
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
122
- expect(themeRoot?.classList.contains('dark')).toBe(true)
123
- })
124
-
125
- it('should set isDark to true when theme is dark', async () => {
126
- element.theme = 'dark'
127
- document.body.appendChild(element)
128
- await element.updateComplete
129
-
130
- expect(element.isDark).toBe(true)
131
- })
132
-
133
- it('should update attribute when theme is set to dark', async () => {
134
- element.theme = 'dark'
135
- document.body.appendChild(element)
136
- await element.updateComplete
137
-
138
- expect(element.getAttribute('theme')).toBe('dark')
139
- })
140
- })
141
-
142
- describe('Auto Theme', () => {
143
- it('should set theme to auto', () => {
144
- element.theme = 'auto'
145
- expect(element.theme).toBe('auto')
146
- })
147
-
148
- it('should detect system preference when theme is auto', async () => {
149
- // Mock matchMedia to return dark mode
150
- const matchMediaMock = vi.fn((query) => ({
151
- matches: query === '(prefers-color-scheme: dark)',
152
- media: query,
153
- addEventListener: vi.fn(),
154
- removeEventListener: vi.fn(),
155
- }))
156
- vi.stubGlobal('matchMedia', matchMediaMock)
157
-
158
- element.theme = 'auto'
159
- document.body.appendChild(element)
160
- await element.updateComplete
161
-
162
- expect(element.isDark).toBe(true)
163
-
164
- vi.unstubAllGlobals()
165
- })
166
-
167
- it('should listen for system theme changes when theme is auto', async () => {
168
- const addEventListenerSpy = vi.fn()
169
- const matchMediaMock = vi.fn(() => ({
170
- matches: false,
171
- media: '(prefers-color-scheme: dark)',
172
- addEventListener: addEventListenerSpy,
173
- removeEventListener: vi.fn(),
174
- }))
175
- vi.stubGlobal('matchMedia', matchMediaMock)
176
-
177
- element.theme = 'auto'
178
- document.body.appendChild(element)
179
- await element.updateComplete
180
-
181
- expect(addEventListenerSpy).toHaveBeenCalledWith(
182
- 'change',
183
- expect.any(Function)
184
- )
185
-
186
- vi.unstubAllGlobals()
187
- })
188
-
189
- it('should remove event listener when theme changes from auto', async () => {
190
- const removeEventListenerSpy = vi.fn()
191
- const addEventListenerSpy = vi.fn()
192
- const matchMediaMock = vi.fn(() => ({
193
- matches: false,
194
- media: '(prefers-color-scheme: dark)',
195
- addEventListener: addEventListenerSpy,
196
- removeEventListener: removeEventListenerSpy,
197
- }))
198
- vi.stubGlobal('matchMedia', matchMediaMock)
199
-
200
- element.theme = 'auto'
201
- document.body.appendChild(element)
202
- await element.updateComplete
203
-
204
- // Change theme from auto to light
205
- element.theme = 'light'
206
- await element.updateComplete
207
-
208
- expect(removeEventListenerSpy).toHaveBeenCalled()
209
-
210
- vi.unstubAllGlobals()
211
- })
212
- })
213
-
214
- describe('Theme Switching', () => {
215
- it('should switch from light to dark', async () => {
216
- document.body.appendChild(element)
217
- element.theme = 'light'
218
- await element.updateComplete
219
- await element.updateComplete // Wait for property change update
220
-
221
- let themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
222
- expect(themeRoot?.classList.contains('dark')).toBe(false)
223
-
224
- element.theme = 'dark'
225
- await element.updateComplete
226
- await element.updateComplete // Wait for property change update
227
-
228
- themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
229
- expect(themeRoot?.classList.contains('dark')).toBe(true)
230
- })
231
-
232
- it('should switch from dark to light', async () => {
233
- document.body.appendChild(element)
234
- element.theme = 'dark'
235
- await element.updateComplete
236
- await element.updateComplete // Wait for property change update
237
-
238
- let themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
239
- expect(themeRoot?.classList.contains('dark')).toBe(true)
240
-
241
- element.theme = 'light'
242
- await element.updateComplete
243
- await element.updateComplete // Wait for property change update
244
-
245
- themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
246
- expect(themeRoot?.classList.contains('dark')).toBe(false)
247
- })
248
-
249
- it('should update isDark when switching themes', async () => {
250
- document.body.appendChild(element)
251
- await element.updateComplete
252
-
253
- element.theme = 'dark'
254
- await element.updateComplete
255
- expect(element.isDark).toBe(true)
256
-
257
- element.theme = 'light'
258
- await element.updateComplete
259
- expect(element.isDark).toBe(false)
260
- })
261
- })
262
-
263
- describe('Multiple Instances', () => {
264
- it('should work with multiple component instances', async () => {
265
- const element2 = new TestComponent()
266
-
267
- element.theme = 'dark'
268
- element2.theme = 'light'
269
-
270
- document.body.appendChild(element)
271
- document.body.appendChild(element2)
272
- await element.updateComplete
273
- await element2.updateComplete
274
-
275
- expect(element.isDark).toBe(true)
276
- expect(element2.isDark).toBe(false)
277
-
278
- const themeRoot1 = element.shadowRoot?.querySelector('[data-theme-root]')
279
- const themeRoot2 = element2.shadowRoot?.querySelector('[data-theme-root]')
280
-
281
- expect(themeRoot1?.classList.contains('dark')).toBe(true)
282
- expect(themeRoot2?.classList.contains('dark')).toBe(false)
283
-
284
- element2.remove()
285
- })
286
-
287
- it('should not affect other instances when changing theme', async () => {
288
- const element2 = new TestComponent()
289
-
290
- document.body.appendChild(element)
291
- document.body.appendChild(element2)
292
- await element.updateComplete
293
- await element2.updateComplete
294
-
295
- element.theme = 'dark'
296
- await element.updateComplete
297
-
298
- expect(element.isDark).toBe(true)
299
- expect(element2.isDark).toBe(false)
300
-
301
- element2.remove()
302
- })
303
- })
304
-
305
- describe('Lifecycle', () => {
306
- it('should cleanup event listener on disconnect when theme is auto', async () => {
307
- const removeEventListenerSpy = vi.fn()
308
- const matchMediaMock = vi.fn(() => ({
309
- matches: false,
310
- media: '(prefers-color-scheme: dark)',
311
- addEventListener: vi.fn(),
312
- removeEventListener: removeEventListenerSpy,
313
- }))
314
- vi.stubGlobal('matchMedia', matchMediaMock)
315
-
316
- element.theme = 'auto'
317
- document.body.appendChild(element)
318
- await element.updateComplete
319
-
320
- element.remove()
321
-
322
- expect(removeEventListenerSpy).toHaveBeenCalled()
323
-
324
- vi.unstubAllGlobals()
325
- })
326
-
327
- it('should maintain theme property after disconnection', async () => {
328
- element.theme = 'dark'
329
- document.body.appendChild(element)
330
- await element.updateComplete
331
-
332
- const themeBefore = element.theme
333
- const isDarkBefore = element.isDark
334
-
335
- element.remove()
336
-
337
- expect(element.theme).toBe(themeBefore)
338
- expect(element.isDark).toBe(isDarkBefore)
339
- })
340
- })
341
-
342
- describe('Mixin Composition', () => {
343
- it('should work when composed with other mixins', async () => {
344
- // Simple test mixin
345
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
346
- const withTestFeature = <T extends typeof LitElement>(Base: T): any => {
347
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
- return class extends (Base as any) {
349
- testProperty = 'test'
350
- }
351
- }
352
-
353
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
354
- const ComposedComponent: any = class extends withTheme(
355
- withTestFeature(LitElement)
356
- ) {
357
- render() {
358
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
359
- return html`<div>${(this as any).testProperty}</div>`
360
- }
361
- }
362
-
363
- const composedTagName = `test-composed-${Math.random().toString(36).slice(2)}`
364
- customElements.define(composedTagName, ComposedComponent)
365
-
366
- const composedElement = new ComposedComponent()
367
- document.body.appendChild(composedElement)
368
- await composedElement.updateComplete
369
-
370
- // Should have both theme and test properties
371
- expect(composedElement.theme).toBeDefined()
372
- expect(composedElement.isDark).toBeDefined()
373
- expect(composedElement.testProperty).toBe('test')
374
-
375
- // Should have theme root
376
- const themeRoot =
377
- composedElement.shadowRoot?.querySelector('[data-theme-root]')
378
- expect(themeRoot).toBeDefined()
379
-
380
- composedElement.remove()
381
- })
382
- })
383
-
384
- describe('System Preference Changes', () => {
385
- it('should update isDark when system preference changes in auto mode', async () => {
386
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
387
- const handlers: any[] = []
388
- const matchMediaMock = vi.fn(() => ({
389
- matches: false,
390
- media: '(prefers-color-scheme: dark)',
391
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
392
- addEventListener: (_: string, handler: any) => {
393
- handlers.push(handler)
394
- },
395
- removeEventListener: vi.fn(),
396
- }))
397
- vi.stubGlobal('matchMedia', matchMediaMock)
398
-
399
- element.theme = 'auto'
400
- document.body.appendChild(element)
401
- await element.updateComplete
402
-
403
- expect(element.isDark).toBe(false)
404
-
405
- // Simulate system preference change to dark
406
- expect(handlers.length).toBeGreaterThan(0)
407
- handlers[0]({ matches: true })
408
- await element.updateComplete
409
-
410
- expect(element.isDark).toBe(true)
411
-
412
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
413
- expect(themeRoot?.classList.contains('dark')).toBe(true)
414
-
415
- vi.unstubAllGlobals()
416
- })
417
-
418
- it('should update isDark when system preference changes to light in auto mode', async () => {
419
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
420
- const handlers: any[] = []
421
- const matchMediaMock = vi.fn(() => ({
422
- matches: true, // Start with dark
423
- media: '(prefers-color-scheme: dark)',
424
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
425
- addEventListener: (_: string, handler: any) => {
426
- handlers.push(handler)
427
- },
428
- removeEventListener: vi.fn(),
429
- }))
430
- vi.stubGlobal('matchMedia', matchMediaMock)
431
-
432
- element.theme = 'auto'
433
- document.body.appendChild(element)
434
- await element.updateComplete
435
-
436
- expect(element.isDark).toBe(true)
437
-
438
- // Simulate system preference change to light
439
- expect(handlers.length).toBeGreaterThan(0)
440
- handlers[0]({ matches: false })
441
- await element.updateComplete
442
-
443
- expect(element.isDark).toBe(false)
444
-
445
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
446
- expect(themeRoot?.classList.contains('dark')).toBe(false)
447
-
448
- vi.unstubAllGlobals()
449
- })
450
- })
451
-
452
- describe('Edge Cases', () => {
453
- it('should handle rapid theme changes', () => {
454
- element.theme = 'dark'
455
- element.theme = 'light'
456
- element.theme = 'dark'
457
- element.theme = 'auto'
458
-
459
- expect(element.theme).toBe('auto')
460
- expect(element.isDark).toBeDefined()
461
- })
462
-
463
- it('should handle theme changes before connection', () => {
464
- element.theme = 'dark'
465
- expect(element.theme).toBe('dark')
466
- })
467
-
468
- it('should properly initialize when connected with pre-set theme', async () => {
469
- element.theme = 'dark'
470
- document.body.appendChild(element)
471
- await element.updateComplete
472
-
473
- expect(element.isDark).toBe(true)
474
- const themeRoot = element.shadowRoot?.querySelector('[data-theme-root]')
475
- expect(themeRoot?.classList.contains('dark')).toBe(true)
476
- })
477
- })
478
- })
@@ -1,172 +0,0 @@
1
- /**
2
- * Theme Mixin
3
- *
4
- * Mixin to add theme detection and management to a Lit component
5
- */
6
-
7
- import type { LitElement } from 'lit'
8
- import { property, state } from 'lit/decorators.js'
9
-
10
- export type Theme = 'light' | 'dark' | 'auto'
11
-
12
- /**
13
- * Mixin to add theme management to a Lit component
14
- *
15
- * Provides a `theme` property and `isDark` state that automatically handles:
16
- * - Manual theme selection ('light' or 'dark')
17
- * - Auto theme detection based on system preferences
18
- * - Reactive updates when system theme changes
19
- * - Automatically wraps all rendered content in a themed div with 'dark' class when dark mode is active
20
- *
21
- * All content rendered by the component will be inside a theme-root div that receives the dark class.
22
- * Components can use render() normally - no changes needed.
23
- *
24
- * @typeParam T - The Lit component class being extended
25
- * @returns Extended class with theme management capabilities
26
- *
27
- * @example
28
- * ```typescript
29
- * import { LitElement, html } from 'lit';
30
- * import { customElement } from 'lit/decorators.js';
31
- * import { withTheme } from '@lukso/core/mixins';
32
- *
33
- * @customElement('my-component')
34
- * export class MyComponent extends withTheme(LitElement) {
35
- * render() {
36
- * return html`
37
- * <div class="text-neutral-20 dark:text-neutral-100">
38
- * Current theme: ${this.theme}
39
- * </div>
40
- * `;
41
- * }
42
- * }
43
- * ```
44
- */
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- export function withTheme<T extends typeof LitElement>(Base: T): any {
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- class Mixin extends (Base as any) {
49
- /**
50
- * Theme mode: 'light', 'dark', or 'auto' (follows system preference)
51
- */
52
- @property({ type: String, reflect: true })
53
- theme: Theme = 'light'
54
-
55
- /**
56
- * Computed state indicating if dark mode is active
57
- */
58
- @state()
59
- protected isDark = false
60
-
61
- /**
62
- * The theme root element that wraps all rendered content and receives the dark class
63
- */
64
- private themeRoot!: HTMLDivElement
65
-
66
- private mediaQueryList: MediaQueryList | null = null
67
-
68
- connectedCallback(): void {
69
- super.connectedCallback()
70
- this.updateTheme()
71
- this.updateHostClass()
72
-
73
- // Listen for system theme changes when in 'auto' mode
74
- if (this.theme === 'auto') {
75
- this.mediaQueryList = window.matchMedia('(prefers-color-scheme: dark)')
76
- this.mediaQueryList.addEventListener(
77
- 'change',
78
- this.handleMediaQueryChange
79
- )
80
- }
81
- }
82
-
83
- disconnectedCallback(): void {
84
- super.disconnectedCallback()
85
-
86
- if (this.mediaQueryList) {
87
- this.mediaQueryList.removeEventListener(
88
- 'change',
89
- this.handleMediaQueryChange
90
- )
91
- }
92
- }
93
-
94
- updated(changedProperties: Map<string, any>): void {
95
- super.updated(changedProperties)
96
-
97
- // Handle theme changes
98
- if (changedProperties.has('theme')) {
99
- this.updateTheme()
100
-
101
- // Update media query listener when theme mode changes
102
- if (this.theme === 'auto' && !this.mediaQueryList) {
103
- this.mediaQueryList = window.matchMedia(
104
- '(prefers-color-scheme: dark)'
105
- )
106
- this.mediaQueryList.addEventListener(
107
- 'change',
108
- this.handleMediaQueryChange
109
- )
110
- } else if (this.theme !== 'auto' && this.mediaQueryList) {
111
- this.mediaQueryList.removeEventListener(
112
- 'change',
113
- this.handleMediaQueryChange
114
- )
115
- this.mediaQueryList = null
116
- }
117
- }
118
-
119
- // Update host class when isDark changes
120
- if (changedProperties.has('isDark')) {
121
- this.updateHostClass()
122
- }
123
- }
124
-
125
- /**
126
- * Handle system theme changes
127
- *
128
- * @param event - Media query list event
129
- */
130
- private handleMediaQueryChange = (event: MediaQueryListEvent): void => {
131
- this.isDark = event.matches
132
- }
133
-
134
- /**
135
- * Update isDark state based on theme property
136
- */
137
- protected updateTheme(): void {
138
- if (this.theme === 'auto') {
139
- this.isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
140
- } else {
141
- this.isDark = this.theme === 'dark'
142
- }
143
- }
144
-
145
- /**
146
- * Create the render root with a themed wrapper div
147
- */
148
- createRenderRoot(): Element | ShadowRoot {
149
- const root = super.createRenderRoot()
150
-
151
- this.themeRoot = document.createElement('div')
152
- this.themeRoot.setAttribute('data-theme-root', '')
153
-
154
- root.appendChild(this.themeRoot)
155
- return this.themeRoot
156
- }
157
-
158
- /**
159
- * Update the host element's class based on isDark state
160
- */
161
- private updateHostClass(): void {
162
- if (this.isDark) {
163
- this.themeRoot.classList.add('dark')
164
- } else {
165
- this.themeRoot.classList.remove('dark')
166
- }
167
- }
168
- }
169
-
170
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
- return Mixin as any
172
- }