{"version":3,"file":"ngx-bj-theme-switcher.mjs","sources":["../../../projects/ngx-bj-theme-switcher/src/lib/ngx-bj-theme-switcher.service.ts","../../../projects/ngx-bj-theme-switcher/src/lib/ngx-bj-theme-switcher.component.ts","../../../projects/ngx-bj-theme-switcher/src/lib/ngx-bj-theme-switcher.component.html","../../../projects/ngx-bj-theme-switcher/src/lib/ngx-bj-theme-switcher.module.ts","../../../projects/ngx-bj-theme-switcher/src/public-api.ts","../../../projects/ngx-bj-theme-switcher/src/ngx-bj-theme-switcher.ts"],"sourcesContent":["import {Injectable} from '@angular/core';\n\n@Injectable({\n  providedIn: 'root'\n})\nexport class NgxBjThemeSwitcherService {\n  private static readonly DEFAULT_THEME: string = 'light';\n\n  private readonly style: HTMLLinkElement;\n  private transitionEnabled: boolean;\n\n  constructor() {\n    this.style = document.createElement('link');\n    this.style.rel = 'stylesheet';\n    document.head.appendChild(this.style);\n\n    if (localStorage.getItem('theme') !== undefined) {\n      this.style.href = `/${this.current}.css`;\n    }\n    this.transitionEnabled = false;\n  }\n\n  public get current(): string {\n    return localStorage.getItem('theme') ?? NgxBjThemeSwitcherService.DEFAULT_THEME;\n  }\n\n  public set current(value: string) {\n    if (!this.transitionEnabled) {\n      this.enableTransition();\n    }\n    localStorage.setItem('theme', value);\n    this.style.href = `/${value}.css`;\n  }\n\n  private enableTransition(): void {\n    this.transitionEnabled = true;\n    document.querySelector('body')!.style.cssText = `transition: all 500ms ease;\n    transition-property: background-color, color;`;\n  }\n}\n","import {Component, OnInit} from '@angular/core';\nimport {NgxBjThemeSwitcherService} from \"./ngx-bj-theme-switcher.service\";\n\n@Component({\n  selector: 'ngx-bj-theme-switcher',\n  templateUrl: './ngx-bj-theme-switcher.component.html',\n})\nexport class NgxBjThemeSwitcherComponent implements OnInit {\n\n  constructor(private themeService: NgxBjThemeSwitcherService) {\n  }\n\n  ngOnInit(): void {\n  }\n\n  public switchTheme(): void {\n    this.themeService.current = this.isDarkMode() ? 'light' : 'dark'\n  }\n\n  public isDarkMode(): boolean {\n    return this.themeService.current === 'dark';\n  }\n\n}\n","<div>\r\n  <a role=\"button\" class=\"text-muted\" (click)=\"switchTheme()\">\r\n    <div [hidden]=\"isDarkMode()\">\r\n      <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\"\r\n           stroke=\"currentColor\"\r\n           stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-moon\">\r\n        <path d=\"M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z\"></path>\r\n      </svg>\r\n    </div>\r\n    <div [hidden]=\"!isDarkMode()\">\r\n      <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\"\r\n           stroke=\"currentColor\"\r\n           stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"feather feather-sun\">\r\n        <circle cx=\"12\" cy=\"12\" r=\"5\"></circle>\r\n        <line x1=\"12\" y1=\"1\" x2=\"12\" y2=\"3\"></line>\r\n        <line x1=\"12\" y1=\"21\" x2=\"12\" y2=\"23\"></line>\r\n        <line x1=\"4.22\" y1=\"4.22\" x2=\"5.64\" y2=\"5.64\"></line>\r\n        <line x1=\"18.36\" y1=\"18.36\" x2=\"19.78\" y2=\"19.78\"></line>\r\n        <line x1=\"1\" y1=\"12\" x2=\"3\" y2=\"12\"></line>\r\n        <line x1=\"21\" y1=\"12\" x2=\"23\" y2=\"12\"></line>\r\n        <line x1=\"4.22\" y1=\"19.78\" x2=\"5.64\" y2=\"18.36\"></line>\r\n        <line x1=\"18.36\" y1=\"5.64\" x2=\"19.78\" y2=\"4.22\"></line>\r\n      </svg>\r\n    </div>\r\n  </a>\r\n</div>\r\n","import { NgModule } from '@angular/core';\nimport { NgxBjThemeSwitcherComponent } from './ngx-bj-theme-switcher.component';\n\n\n\n@NgModule({\n  declarations: [\n    NgxBjThemeSwitcherComponent\n  ],\n  imports: [\n  ],\n  exports: [\n    NgxBjThemeSwitcherComponent\n  ]\n})\nexport class NgxBjThemeSwitcherModule { }\n","/*\n * Public API Surface of ngx-bj-theme-switcher\n */\n\nexport * from './lib/ngx-bj-theme-switcher.service';\nexport * from './lib/ngx-bj-theme-switcher.component';\nexport * from './lib/ngx-bj-theme-switcher.module';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;MAKa,yBAAyB;IAMpC;QACE,IAAI,CAAC,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,YAAY,CAAC;QAC9B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,SAAS,EAAE;YAC/C,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,MAAM,CAAC;SAC1C;QACD,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;KAChC;IAED,IAAW,OAAO;;QAChB,OAAO,MAAA,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,mCAAI,yBAAyB,CAAC,aAAa,CAAC;KACjF;IAED,IAAW,OAAO,CAAC,KAAa;QAC9B,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAC3B,IAAI,CAAC,gBAAgB,EAAE,CAAC;SACzB;QACD,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,KAAK,MAAM,CAAC;KACnC;IAEO,gBAAgB;QACtB,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAE,CAAC,KAAK,CAAC,OAAO,GAAG;kDACF,CAAC;KAChD;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