@breadstone/mosaik-themes 0.0.182 → 0.0.184
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/CHANGELOG.md +6 -0
- package/index.cjs +123 -40
- package/index.cjs.map +1 -1
- package/index.d.mts +78 -3
- package/index.d.ts +78 -3
- package/index.js +121 -41
- package/index.js.map +1 -1
- package/index.node.cjs +2710 -0
- package/index.node.cjs.map +1 -0
- package/index.node.d.mts +468 -0
- package/index.node.d.ts +468 -0
- package/index.node.js +2695 -0
- package/index.node.js.map +1 -0
- package/package.json +6 -6
- package/tailwind/v3/plugins/base/buildTailwindPlugin.d.ts +1 -0
- package/tailwind/v3/plugins/base/buildTailwindPlugin.d.ts.map +1 -0
- package/tailwind/v3/plugins/base/buildTailwindPlugin.js +147 -0
- package/tailwind/v3/plugins/base/buildTailwindPlugin.js.map +1 -0
- package/tailwind/v3/plugins/base/c.d.ts +44 -0
- package/tailwind/v3/plugins/base/c.d.ts.map +1 -0
- package/tailwind/v3/plugins/base/c.js +155 -0
- package/tailwind/v3/plugins/base/c.js.map +1 -0
- package/tailwind/v3/presets/base/buildTailwindPreset.d.ts +1 -0
- package/tailwind/v3/presets/base/buildTailwindPreset.d.ts.map +1 -0
- package/tailwind/v3/presets/base/buildTailwindPreset.js +39 -0
- package/tailwind/v3/presets/base/buildTailwindPreset.js.map +1 -0
package/index.d.mts
CHANGED
|
@@ -313,6 +313,31 @@ declare namespace CssTime {
|
|
|
313
313
|
function isCssTime(value: unknown): value is CssTime;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Platform adapter interface for abstracting browser APIs.
|
|
318
|
+
* Allows ThemeObserver and ThemeGenerator to work in both browser and Node.js environments.
|
|
319
|
+
*
|
|
320
|
+
* @public
|
|
321
|
+
*/
|
|
322
|
+
interface IPlatformAdapter {
|
|
323
|
+
/**
|
|
324
|
+
* Checks if media query matches (e.g., prefers-color-scheme).
|
|
325
|
+
*/
|
|
326
|
+
matchMedia(query: string): boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Sets an attribute on the document element.
|
|
329
|
+
*/
|
|
330
|
+
setDocumentAttribute(name: string, value: string): void;
|
|
331
|
+
/**
|
|
332
|
+
* Gets an attribute from the document element.
|
|
333
|
+
*/
|
|
334
|
+
getDocumentAttribute(name: string): string | null;
|
|
335
|
+
/**
|
|
336
|
+
* Observes changes to document element attributes.
|
|
337
|
+
*/
|
|
338
|
+
observeDocumentAttributes(attributes: string[], callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
339
|
+
}
|
|
340
|
+
|
|
316
341
|
/**
|
|
317
342
|
* Theme mode.
|
|
318
343
|
*
|
|
@@ -327,14 +352,17 @@ type ThemeMode = 'system' | 'dark' | 'light';
|
|
|
327
352
|
declare class ThemeObserver {
|
|
328
353
|
private readonly _themeChanged;
|
|
329
354
|
private readonly _themeModeChanged;
|
|
355
|
+
private readonly _platformAdapter;
|
|
330
356
|
private _currentTheme;
|
|
331
357
|
private _currentThemeMode;
|
|
358
|
+
private _unsubscribe?;
|
|
332
359
|
/**
|
|
333
360
|
* Constructs a new instance of the `ThemeObserver` class.
|
|
334
361
|
*
|
|
362
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
335
363
|
* @public
|
|
336
364
|
*/
|
|
337
|
-
constructor();
|
|
365
|
+
constructor(platformAdapter?: IPlatformAdapter);
|
|
338
366
|
/**
|
|
339
367
|
* Fires when the theme changes.
|
|
340
368
|
*
|
|
@@ -350,6 +378,7 @@ declare class ThemeObserver {
|
|
|
350
378
|
*/
|
|
351
379
|
get themeModeChanged(): IEventEmitter<ThemeMode>;
|
|
352
380
|
applyTheme(theme: string, themeMode: ThemeMode): void;
|
|
381
|
+
dispose(): void;
|
|
353
382
|
private observe;
|
|
354
383
|
}
|
|
355
384
|
/**
|
|
@@ -367,7 +396,12 @@ declare class ThemeObserverServiceLocator {
|
|
|
367
396
|
*/
|
|
368
397
|
declare class ThemeGenerator {
|
|
369
398
|
private readonly _strategies;
|
|
370
|
-
|
|
399
|
+
private readonly _platformAdapter;
|
|
400
|
+
/**
|
|
401
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
402
|
+
* @public
|
|
403
|
+
*/
|
|
404
|
+
constructor(platformAdapter?: IPlatformAdapter);
|
|
371
405
|
generatePalette(theme: ITheme, baseColor: CssColor, mode: 'dark' | 'light' | 'system'): IThemePalette;
|
|
372
406
|
generateScheme(theme: ITheme, baseColor: CssColor, mode: 'dark' | 'light' | 'system'): IThemeScheme;
|
|
373
407
|
private resolveMode;
|
|
@@ -537,4 +571,45 @@ declare class TailwindThemeGeneratorStrategy implements IThemeGeneratorStrategy
|
|
|
537
571
|
*/
|
|
538
572
|
declare function createTailwindTheme(): ThemeGeneratorFactoryFn;
|
|
539
573
|
|
|
540
|
-
|
|
574
|
+
/**
|
|
575
|
+
* Browser implementation of the platform adapter.
|
|
576
|
+
* Uses native DOM APIs (window, document, MutationObserver).
|
|
577
|
+
*
|
|
578
|
+
* @public
|
|
579
|
+
*/
|
|
580
|
+
declare class BrowserPlatformAdapter implements IPlatformAdapter {
|
|
581
|
+
matchMedia(query: string): boolean;
|
|
582
|
+
setDocumentAttribute(name: string, value: string): void;
|
|
583
|
+
getDocumentAttribute(name: string): string | null;
|
|
584
|
+
observeDocumentAttributes(attributes: string[], callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Node.js implementation of the platform adapter.
|
|
589
|
+
* No-op implementation that doesn't crash but does nothing.
|
|
590
|
+
*
|
|
591
|
+
* @public
|
|
592
|
+
*/
|
|
593
|
+
declare class NodePlatformAdapter implements IPlatformAdapter {
|
|
594
|
+
matchMedia(_query: string): boolean;
|
|
595
|
+
setDocumentAttribute(_name: string, _value: string): void;
|
|
596
|
+
getDocumentAttribute(_name: string): string | null;
|
|
597
|
+
observeDocumentAttributes(_attributes: string[], _callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Factory that automatically detects the environment and returns the appropriate adapter.
|
|
602
|
+
*
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
declare class PlatformAdapterFactory {
|
|
606
|
+
/**
|
|
607
|
+
* Creates the appropriate platform adapter based on the current environment.
|
|
608
|
+
* Automatically detects if running in browser or Node.js.
|
|
609
|
+
*
|
|
610
|
+
* @public
|
|
611
|
+
*/
|
|
612
|
+
static create(): IPlatformAdapter;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export { BootstrapTheme, BrowserPlatformAdapter, CosmopolitanTheme, CosmopolitanThemeGeneratorStrategy, CssAspectRatio, CssColor, type CssHEXColor, CssLength, type CssLengthUnit, type CssNameColor, type CssRGBAColor, type CssRGBColor, CssShadow, type CssShadowSingle, CssTime, type CssTimeUnit, type IPlatformAdapter, ITheme, type IThemeElevation, type IThemeGeneratorStrategy, type IThemeLayout, type IThemeMetadata, IThemePalette, type IThemeScheme, type IThemeTypography, type IThemeTypographyFontType, JoyTheme, JoyThemeGeneratorStrategy, MaterialThemeGeneratorStrategy, MemphisTheme, MemphisThemeGeneratorStrategy, NodePlatformAdapter, PlatformAdapterFactory, TailwindThemeGeneratorStrategy, ThemeGenerator, ThemeGeneratorServiceLocator, type ThemeMode, ThemeObserver, ThemeObserverServiceLocator, createCosmopolitanTheme, createJoyTheme, createMaterialTheme, createMemphisTheme, createTailwindTheme };
|
package/index.d.ts
CHANGED
|
@@ -313,6 +313,31 @@ declare namespace CssTime {
|
|
|
313
313
|
function isCssTime(value: unknown): value is CssTime;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Platform adapter interface for abstracting browser APIs.
|
|
318
|
+
* Allows ThemeObserver and ThemeGenerator to work in both browser and Node.js environments.
|
|
319
|
+
*
|
|
320
|
+
* @public
|
|
321
|
+
*/
|
|
322
|
+
interface IPlatformAdapter {
|
|
323
|
+
/**
|
|
324
|
+
* Checks if media query matches (e.g., prefers-color-scheme).
|
|
325
|
+
*/
|
|
326
|
+
matchMedia(query: string): boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Sets an attribute on the document element.
|
|
329
|
+
*/
|
|
330
|
+
setDocumentAttribute(name: string, value: string): void;
|
|
331
|
+
/**
|
|
332
|
+
* Gets an attribute from the document element.
|
|
333
|
+
*/
|
|
334
|
+
getDocumentAttribute(name: string): string | null;
|
|
335
|
+
/**
|
|
336
|
+
* Observes changes to document element attributes.
|
|
337
|
+
*/
|
|
338
|
+
observeDocumentAttributes(attributes: string[], callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
339
|
+
}
|
|
340
|
+
|
|
316
341
|
/**
|
|
317
342
|
* Theme mode.
|
|
318
343
|
*
|
|
@@ -327,14 +352,17 @@ type ThemeMode = 'system' | 'dark' | 'light';
|
|
|
327
352
|
declare class ThemeObserver {
|
|
328
353
|
private readonly _themeChanged;
|
|
329
354
|
private readonly _themeModeChanged;
|
|
355
|
+
private readonly _platformAdapter;
|
|
330
356
|
private _currentTheme;
|
|
331
357
|
private _currentThemeMode;
|
|
358
|
+
private _unsubscribe?;
|
|
332
359
|
/**
|
|
333
360
|
* Constructs a new instance of the `ThemeObserver` class.
|
|
334
361
|
*
|
|
362
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
335
363
|
* @public
|
|
336
364
|
*/
|
|
337
|
-
constructor();
|
|
365
|
+
constructor(platformAdapter?: IPlatformAdapter);
|
|
338
366
|
/**
|
|
339
367
|
* Fires when the theme changes.
|
|
340
368
|
*
|
|
@@ -350,6 +378,7 @@ declare class ThemeObserver {
|
|
|
350
378
|
*/
|
|
351
379
|
get themeModeChanged(): IEventEmitter<ThemeMode>;
|
|
352
380
|
applyTheme(theme: string, themeMode: ThemeMode): void;
|
|
381
|
+
dispose(): void;
|
|
353
382
|
private observe;
|
|
354
383
|
}
|
|
355
384
|
/**
|
|
@@ -367,7 +396,12 @@ declare class ThemeObserverServiceLocator {
|
|
|
367
396
|
*/
|
|
368
397
|
declare class ThemeGenerator {
|
|
369
398
|
private readonly _strategies;
|
|
370
|
-
|
|
399
|
+
private readonly _platformAdapter;
|
|
400
|
+
/**
|
|
401
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
402
|
+
* @public
|
|
403
|
+
*/
|
|
404
|
+
constructor(platformAdapter?: IPlatformAdapter);
|
|
371
405
|
generatePalette(theme: ITheme, baseColor: CssColor, mode: 'dark' | 'light' | 'system'): IThemePalette;
|
|
372
406
|
generateScheme(theme: ITheme, baseColor: CssColor, mode: 'dark' | 'light' | 'system'): IThemeScheme;
|
|
373
407
|
private resolveMode;
|
|
@@ -537,4 +571,45 @@ declare class TailwindThemeGeneratorStrategy implements IThemeGeneratorStrategy
|
|
|
537
571
|
*/
|
|
538
572
|
declare function createTailwindTheme(): ThemeGeneratorFactoryFn;
|
|
539
573
|
|
|
540
|
-
|
|
574
|
+
/**
|
|
575
|
+
* Browser implementation of the platform adapter.
|
|
576
|
+
* Uses native DOM APIs (window, document, MutationObserver).
|
|
577
|
+
*
|
|
578
|
+
* @public
|
|
579
|
+
*/
|
|
580
|
+
declare class BrowserPlatformAdapter implements IPlatformAdapter {
|
|
581
|
+
matchMedia(query: string): boolean;
|
|
582
|
+
setDocumentAttribute(name: string, value: string): void;
|
|
583
|
+
getDocumentAttribute(name: string): string | null;
|
|
584
|
+
observeDocumentAttributes(attributes: string[], callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* Node.js implementation of the platform adapter.
|
|
589
|
+
* No-op implementation that doesn't crash but does nothing.
|
|
590
|
+
*
|
|
591
|
+
* @public
|
|
592
|
+
*/
|
|
593
|
+
declare class NodePlatformAdapter implements IPlatformAdapter {
|
|
594
|
+
matchMedia(_query: string): boolean;
|
|
595
|
+
setDocumentAttribute(_name: string, _value: string): void;
|
|
596
|
+
getDocumentAttribute(_name: string): string | null;
|
|
597
|
+
observeDocumentAttributes(_attributes: string[], _callback: (attributeName: string, newValue: string | null) => void): () => void;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Factory that automatically detects the environment and returns the appropriate adapter.
|
|
602
|
+
*
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
declare class PlatformAdapterFactory {
|
|
606
|
+
/**
|
|
607
|
+
* Creates the appropriate platform adapter based on the current environment.
|
|
608
|
+
* Automatically detects if running in browser or Node.js.
|
|
609
|
+
*
|
|
610
|
+
* @public
|
|
611
|
+
*/
|
|
612
|
+
static create(): IPlatformAdapter;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
export { BootstrapTheme, BrowserPlatformAdapter, CosmopolitanTheme, CosmopolitanThemeGeneratorStrategy, CssAspectRatio, CssColor, type CssHEXColor, CssLength, type CssLengthUnit, type CssNameColor, type CssRGBAColor, type CssRGBColor, CssShadow, type CssShadowSingle, CssTime, type CssTimeUnit, type IPlatformAdapter, ITheme, type IThemeElevation, type IThemeGeneratorStrategy, type IThemeLayout, type IThemeMetadata, IThemePalette, type IThemeScheme, type IThemeTypography, type IThemeTypographyFontType, JoyTheme, JoyThemeGeneratorStrategy, MaterialThemeGeneratorStrategy, MemphisTheme, MemphisThemeGeneratorStrategy, NodePlatformAdapter, PlatformAdapterFactory, TailwindThemeGeneratorStrategy, ThemeGenerator, ThemeGeneratorServiceLocator, type ThemeMode, ThemeObserver, ThemeObserverServiceLocator, createCosmopolitanTheme, createJoyTheme, createMaterialTheme, createMemphisTheme, createTailwindTheme };
|
package/index.js
CHANGED
|
@@ -2361,6 +2361,80 @@ var IThemePalette;
|
|
|
2361
2361
|
ITheme2.getPaletteColor = getPaletteColor;
|
|
2362
2362
|
})(ITheme || (ITheme = {}));
|
|
2363
2363
|
var ITheme;
|
|
2364
|
+
|
|
2365
|
+
// src/Theming/Adapters/BrowserPlatformAdapter.ts
|
|
2366
|
+
var BrowserPlatformAdapter = class {
|
|
2367
|
+
static {
|
|
2368
|
+
__name(this, "BrowserPlatformAdapter");
|
|
2369
|
+
}
|
|
2370
|
+
// #region Methods
|
|
2371
|
+
matchMedia(query) {
|
|
2372
|
+
return window.matchMedia(query).matches;
|
|
2373
|
+
}
|
|
2374
|
+
setDocumentAttribute(name, value) {
|
|
2375
|
+
document.documentElement.setAttribute(name, value);
|
|
2376
|
+
}
|
|
2377
|
+
getDocumentAttribute(name) {
|
|
2378
|
+
return document.documentElement.getAttribute(name);
|
|
2379
|
+
}
|
|
2380
|
+
observeDocumentAttributes(attributes, callback) {
|
|
2381
|
+
const observer = new MutationObserver((mutations) => {
|
|
2382
|
+
mutations.forEach((mutation) => {
|
|
2383
|
+
if (mutation.type === "attributes" && mutation.attributeName) {
|
|
2384
|
+
const newValue = document.documentElement.getAttribute(mutation.attributeName);
|
|
2385
|
+
callback(mutation.attributeName, newValue);
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
});
|
|
2389
|
+
observer.observe(document.documentElement, {
|
|
2390
|
+
attributes: true,
|
|
2391
|
+
attributeFilter: attributes
|
|
2392
|
+
});
|
|
2393
|
+
return () => observer.disconnect();
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
|
|
2397
|
+
// src/Theming/Adapters/NodePlatformAdapter.ts
|
|
2398
|
+
var NodePlatformAdapter = class {
|
|
2399
|
+
static {
|
|
2400
|
+
__name(this, "NodePlatformAdapter");
|
|
2401
|
+
}
|
|
2402
|
+
// #region Methods
|
|
2403
|
+
matchMedia(_query) {
|
|
2404
|
+
return false;
|
|
2405
|
+
}
|
|
2406
|
+
setDocumentAttribute(_name, _value) {
|
|
2407
|
+
}
|
|
2408
|
+
getDocumentAttribute(_name) {
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
observeDocumentAttributes(_attributes, _callback) {
|
|
2412
|
+
return () => {
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
|
|
2417
|
+
// src/Theming/Adapters/PlatformAdapterFactory.ts
|
|
2418
|
+
var PlatformAdapterFactory = class {
|
|
2419
|
+
static {
|
|
2420
|
+
__name(this, "PlatformAdapterFactory");
|
|
2421
|
+
}
|
|
2422
|
+
// #region Methods
|
|
2423
|
+
/**
|
|
2424
|
+
* Creates the appropriate platform adapter based on the current environment.
|
|
2425
|
+
* Automatically detects if running in browser or Node.js.
|
|
2426
|
+
*
|
|
2427
|
+
* @public
|
|
2428
|
+
*/
|
|
2429
|
+
static create() {
|
|
2430
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
2431
|
+
return new BrowserPlatformAdapter();
|
|
2432
|
+
}
|
|
2433
|
+
return new NodePlatformAdapter();
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
|
|
2437
|
+
// src/Theming/ThemeObserver.ts
|
|
2364
2438
|
function isThemeMode(value) {
|
|
2365
2439
|
return value === "system" || value === "dark" || value === "light";
|
|
2366
2440
|
}
|
|
@@ -2372,17 +2446,21 @@ var ThemeObserver = class {
|
|
|
2372
2446
|
// #region Fields
|
|
2373
2447
|
_themeChanged;
|
|
2374
2448
|
_themeModeChanged;
|
|
2449
|
+
_platformAdapter;
|
|
2375
2450
|
_currentTheme;
|
|
2376
2451
|
_currentThemeMode;
|
|
2452
|
+
_unsubscribe;
|
|
2377
2453
|
// #region Ctor
|
|
2378
2454
|
/**
|
|
2379
2455
|
* Constructs a new instance of the `ThemeObserver` class.
|
|
2380
2456
|
*
|
|
2457
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
2381
2458
|
* @public
|
|
2382
2459
|
*/
|
|
2383
|
-
constructor() {
|
|
2460
|
+
constructor(platformAdapter) {
|
|
2384
2461
|
this._themeChanged = new PureEventEmitter();
|
|
2385
2462
|
this._themeModeChanged = new PureEventEmitter();
|
|
2463
|
+
this._platformAdapter = platformAdapter ?? PlatformAdapterFactory.create();
|
|
2386
2464
|
this._currentTheme = null;
|
|
2387
2465
|
this._currentThemeMode = null;
|
|
2388
2466
|
this.observe({
|
|
@@ -2413,54 +2491,49 @@ var ThemeObserver = class {
|
|
|
2413
2491
|
// #endregion
|
|
2414
2492
|
// #region Methods
|
|
2415
2493
|
applyTheme(theme, themeMode) {
|
|
2416
|
-
|
|
2494
|
+
this._platformAdapter.setDocumentAttribute("theme", theme);
|
|
2417
2495
|
switch (themeMode) {
|
|
2418
2496
|
case "dark":
|
|
2419
2497
|
case "light":
|
|
2420
|
-
|
|
2498
|
+
this._platformAdapter.setDocumentAttribute("theme-mode", themeMode);
|
|
2421
2499
|
break;
|
|
2422
2500
|
case "system":
|
|
2423
2501
|
default:
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
} else {
|
|
2427
|
-
document.documentElement.setAttribute("theme-mode", "light");
|
|
2428
|
-
}
|
|
2502
|
+
const isDark = this._platformAdapter.matchMedia("(prefers-color-scheme: dark)");
|
|
2503
|
+
this._platformAdapter.setDocumentAttribute("theme-mode", isDark ? "dark" : "light");
|
|
2429
2504
|
break;
|
|
2430
2505
|
}
|
|
2431
2506
|
}
|
|
2507
|
+
dispose() {
|
|
2508
|
+
if (this._unsubscribe) {
|
|
2509
|
+
this._unsubscribe();
|
|
2510
|
+
this._unsubscribe = void 0;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2432
2513
|
observe(cb) {
|
|
2433
|
-
this._currentTheme =
|
|
2434
|
-
this._currentThemeMode =
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
}
|
|
2445
|
-
if (mutation.attributeName === "theme-mode") {
|
|
2446
|
-
const themeMode = document.documentElement.getAttribute("theme-mode");
|
|
2447
|
-
if (!isThemeMode(themeMode)) {
|
|
2448
|
-
throw new Error(`Invalid theme mode: ${String(themeMode)}`);
|
|
2449
|
-
}
|
|
2450
|
-
if (this._currentThemeMode !== themeMode) {
|
|
2451
|
-
this._currentThemeMode = themeMode;
|
|
2452
|
-
cb.themeModeChange(themeMode);
|
|
2453
|
-
}
|
|
2454
|
-
}
|
|
2514
|
+
this._currentTheme = this._platformAdapter.getDocumentAttribute("theme");
|
|
2515
|
+
this._currentThemeMode = this._platformAdapter.getDocumentAttribute("theme-mode");
|
|
2516
|
+
this._unsubscribe = this._platformAdapter.observeDocumentAttributes([
|
|
2517
|
+
"theme",
|
|
2518
|
+
"theme-mode"
|
|
2519
|
+
], (attributeName, newValue) => {
|
|
2520
|
+
if (attributeName === "theme") {
|
|
2521
|
+
const theme = newValue;
|
|
2522
|
+
if (this._currentTheme !== theme) {
|
|
2523
|
+
this._currentTheme = theme;
|
|
2524
|
+
cb.themeChange(theme);
|
|
2455
2525
|
}
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2526
|
+
}
|
|
2527
|
+
if (attributeName === "theme-mode") {
|
|
2528
|
+
const themeMode = newValue;
|
|
2529
|
+
if (!isThemeMode(themeMode)) {
|
|
2530
|
+
throw new Error(`Invalid theme mode: ${String(themeMode)}`);
|
|
2531
|
+
}
|
|
2532
|
+
if (this._currentThemeMode !== themeMode) {
|
|
2533
|
+
this._currentThemeMode = themeMode;
|
|
2534
|
+
cb.themeModeChange(themeMode);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2464
2537
|
});
|
|
2465
2538
|
}
|
|
2466
2539
|
};
|
|
@@ -2750,9 +2823,14 @@ var ThemeGenerator = class {
|
|
|
2750
2823
|
}
|
|
2751
2824
|
// #region Fields
|
|
2752
2825
|
_strategies;
|
|
2826
|
+
_platformAdapter;
|
|
2753
2827
|
// #endregion
|
|
2754
2828
|
// #region Ctor
|
|
2755
|
-
|
|
2829
|
+
/**
|
|
2830
|
+
* @param platformAdapter - Optional platform adapter. Auto-detects if not provided.
|
|
2831
|
+
* @public
|
|
2832
|
+
*/
|
|
2833
|
+
constructor(platformAdapter) {
|
|
2756
2834
|
this._strategies = /* @__PURE__ */ new Map([
|
|
2757
2835
|
[
|
|
2758
2836
|
"material",
|
|
@@ -2771,6 +2849,7 @@ var ThemeGenerator = class {
|
|
|
2771
2849
|
new CosmopolitanThemeGeneratorStrategy()
|
|
2772
2850
|
]
|
|
2773
2851
|
]);
|
|
2852
|
+
this._platformAdapter = platformAdapter ?? PlatformAdapterFactory.create();
|
|
2774
2853
|
}
|
|
2775
2854
|
// #endregion
|
|
2776
2855
|
// #region Methods
|
|
@@ -2786,7 +2865,8 @@ var ThemeGenerator = class {
|
|
|
2786
2865
|
}
|
|
2787
2866
|
resolveMode(mode) {
|
|
2788
2867
|
if (mode === "system") {
|
|
2789
|
-
|
|
2868
|
+
const isDark = this._platformAdapter.matchMedia("(prefers-color-scheme: dark)");
|
|
2869
|
+
return isDark ? "dark" : "light";
|
|
2790
2870
|
}
|
|
2791
2871
|
return mode;
|
|
2792
2872
|
}
|
|
@@ -2898,6 +2978,6 @@ function createTailwindTheme() {
|
|
|
2898
2978
|
}
|
|
2899
2979
|
__name(createTailwindTheme, "createTailwindTheme");
|
|
2900
2980
|
|
|
2901
|
-
export { BootstrapTheme, CosmopolitanTheme, CosmopolitanThemeGeneratorStrategy, CssAspectRatio, CssColor, CssLength, CssShadow, CssTime, ITheme, IThemePalette, JoyTheme, JoyThemeGeneratorStrategy, MaterialThemeGeneratorStrategy, MemphisTheme, MemphisThemeGeneratorStrategy, TailwindThemeGeneratorStrategy, ThemeGenerator, ThemeGeneratorServiceLocator, ThemeObserver, ThemeObserverServiceLocator, createCosmopolitanTheme, createJoyTheme, createMaterialTheme, createMemphisTheme, createTailwindTheme };
|
|
2981
|
+
export { BootstrapTheme, BrowserPlatformAdapter, CosmopolitanTheme, CosmopolitanThemeGeneratorStrategy, CssAspectRatio, CssColor, CssLength, CssShadow, CssTime, ITheme, IThemePalette, JoyTheme, JoyThemeGeneratorStrategy, MaterialThemeGeneratorStrategy, MemphisTheme, MemphisThemeGeneratorStrategy, NodePlatformAdapter, PlatformAdapterFactory, TailwindThemeGeneratorStrategy, ThemeGenerator, ThemeGeneratorServiceLocator, ThemeObserver, ThemeObserverServiceLocator, createCosmopolitanTheme, createJoyTheme, createMaterialTheme, createMemphisTheme, createTailwindTheme };
|
|
2902
2982
|
//# sourceMappingURL=index.js.map
|
|
2903
2983
|
//# sourceMappingURL=index.js.map
|