@taiga-ui/addon-doc
Version:
Taiga UI based library for developing documentation portals for Angular libraries.
59 lines (55 loc) • 2.37 kB
JavaScript
import * as i0 from '@angular/core';
import { InjectionToken, inject, Injectable } from '@angular/core';
import { WA_LOCAL_STORAGE, WA_WINDOW } from '@ng-web-apis/common';
import { TUI_FALSE_HANDLER } from '@taiga-ui/cdk/constants';
import { TUI_DARK_MODE_DEFAULT_KEY, TUI_DARK_MODE_KEY } from '@taiga-ui/core/tokens';
import { BehaviorSubject } from 'rxjs';
/**
* @deprecated use {@link TUI_DARK_THEME} instead
*/
const TUI_DARK_THEME_DEFAULT_KEY = TUI_DARK_MODE_DEFAULT_KEY;
/**
* @deprecated use {@link TUI_DARK_THEME} instead
*/
const TUI_DARK_THEME_KEY = TUI_DARK_MODE_KEY;
/**
* @deprecated use {@link TUI_DARK_THEME} instead
*/
const TUI_DARK_THEME = new InjectionToken(ngDevMode ? 'TUI_DARK_THEME' : '', {
factory: TUI_FALSE_HANDLER,
});
/**
* @deprecated use {@link TUI_DARK_THEME} instead
*/
class TuiDocThemeDarkService extends BehaviorSubject {
constructor() {
super(isDark(inject(WA_LOCAL_STORAGE), inject(TUI_DARK_THEME_KEY), inject(WA_WINDOW)));
this.storage = inject(WA_LOCAL_STORAGE);
this.key = inject(TUI_DARK_THEME_KEY);
}
next(dark) {
this.storage?.setItem(this.key, String(dark));
super.next(dark);
}
toggle() {
this.next(!this.value);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDocThemeDarkService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDocThemeDarkService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiDocThemeDarkService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: function () { return []; } });
function isDark(storage, key, window) {
const fallback = window.matchMedia('(prefers-color-scheme: dark)').matches ||
inject(TUI_DARK_THEME);
return (storage?.getItem(key) === 'true' || (storage?.getItem(key) === null && fallback));
}
/**
* Generated bundle index. Do not edit.
*/
export { TUI_DARK_THEME, TUI_DARK_THEME_DEFAULT_KEY, TUI_DARK_THEME_KEY, TuiDocThemeDarkService };
//# sourceMappingURL=taiga-ui-addon-doc-services.mjs.map