@ng-doc/app
Version:
<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>
57 lines (53 loc) • 2.06 kB
JavaScript
import { __decorate } from 'tslib';
import { DOCUMENT } from '@angular/common';
import * as i0 from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { NG_DOC_STORE_THEME_KEY } from '@ng-doc/app/constants';
import { NgDocStoreService } from '@ng-doc/app/services/store';
import { UntilDestroy } from '@ngneat/until-destroy';
import { Subject } from 'rxjs';
/**
* Service for managing themes.
*/
let NgDocThemeService = class NgDocThemeService {
constructor() {
this.document = inject(DOCUMENT);
this.store = inject(NgDocStoreService);
this.change$ = new Subject();
this.documentElement = this.document.documentElement;
}
/**
* Returns the current theme.
*/
get currentTheme() {
return document.documentElement.getAttribute('data-theme');
}
themeChanges() {
return this.change$.asObservable();
}
/**
* Sets the theme by id.
* @param id - Theme id. If not provided, the theme will be removed.
*/
set(id) {
id
? this.documentElement.setAttribute('data-theme', id)
: this.documentElement.removeAttribute('data-theme');
this.store.set(NG_DOC_STORE_THEME_KEY, id ?? '');
this.change$.next(id ?? null);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocThemeService, providedIn: 'root' }); }
};
NgDocThemeService = __decorate([
UntilDestroy()
], NgDocThemeService);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.3", ngImport: i0, type: NgDocThemeService, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { NgDocThemeService };
//# sourceMappingURL=ng-doc-app-services-theme.mjs.map