ngx-css-variables
Version:
Css variables module for Angular 2/4/5
5 lines • 2.23 kB
JavaScript
!function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?factory(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-css-variables",["exports","@angular/core","@angular/common"],factory):factory((global.ng=global.ng||{},global.ng.NgxCssVariablesModule={}),global.ng.core,global.ng.common)}(this,function(exports,core,common){"use strict";/**
* @license ngx-css-variables
* MIT license
*/
var CssVarsDirective=function(){function CssVarsDirective(el){this.el=el}return CssVarsDirective.prototype.ngOnInit=function(){var _this=this;this.cssVars&&Object.keys(this.cssVars).forEach(function(key){_this.el.nativeElement.style.setProperty(key,_this.cssVars[key])})},CssVarsDirective.decorators=[{type:core.Directive,args:[{selector:"[css-vars]"}]}],CssVarsDirective.ctorParameters=function(){return[{type:core.ElementRef}]},CssVarsDirective.propDecorators={cssVars:[{type:core.Input,args:["css-vars"]}]},CssVarsDirective}(),CssVarsService=function(){function CssVarsService(){this.head=document.head||document.getElementsByTagName("head")[0]}return CssVarsService.prototype.setVariables=function(vars){var style=document.createElement("style");style.type="text/css";var styles=[];Object.keys(vars).forEach(function(property){styles.push(property+": "+vars[property])});var css=":root {"+styles.join("; ")+"}";return style.appendChild(document.createTextNode(css)),this.head.appendChild(style),css},CssVarsService.decorators=[{type:core.Injectable}],CssVarsService.ctorParameters=function(){return[]},CssVarsService}(),CssVarsModule=function(){function CssVarsModule(){}return CssVarsModule.forRoot=function(){return{ngModule:CssVarsModule,providers:[CssVarsService]}},CssVarsModule.forChild=function(){return{ngModule:CssVarsModule,providers:[CssVarsService]}},CssVarsModule.decorators=[{type:core.NgModule,args:[{imports:[common.CommonModule],declarations:[CssVarsDirective],exports:[CssVarsDirective]}]}],CssVarsModule.ctorParameters=function(){return[]},CssVarsModule}();exports.CssVarsModule=CssVarsModule,exports.CssVarsDirective=CssVarsDirective,exports.CssVarsService=CssVarsService,Object.defineProperty(exports,"__esModule",{value:!0})});