ngx-css-variables
Version:
Css variables module for Angular 2/4/5
147 lines (138 loc) • 3.63 kB
JavaScript
/**
* @license ngx-css-variables
* MIT license
*/
import { Directive, ElementRef, Injectable, Input, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var CssVarsDirective = (function () {
function CssVarsDirective(el) {
this.el = el;
}
/**
* @return {?}
*/
CssVarsDirective.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
if (!this.cssVars)
return;
Object.keys(this.cssVars).forEach(function (key) {
_this.el.nativeElement.style.setProperty(key, _this.cssVars[key]);
});
};
CssVarsDirective.decorators = [
{ type: Directive, args: [{
selector: '[css-vars]'
},] },
];
/** @nocollapse */
CssVarsDirective.ctorParameters = function () { return [
{ type: ElementRef, },
]; };
CssVarsDirective.propDecorators = {
"cssVars": [{ type: Input, args: ['css-vars',] },],
};
return CssVarsDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var CssVarsService = (function () {
function CssVarsService() {
this.head = document.head || document.getElementsByTagName('head')[0];
}
/**
* @param {?} vars
* @return {?}
*/
CssVarsService.prototype.setVariables = /**
* @param {?} vars
* @return {?}
*/
function (vars) {
var /** @type {?} */ style = document.createElement('style');
style.type = 'text/css';
var /** @type {?} */ styles = [];
Object.keys(vars).forEach(function (property) {
styles.push(property + ": " + vars[property]);
});
var /** @type {?} */ css = ":root {" + styles.join('; ') + "}";
style.appendChild(document.createTextNode(css));
this.head.appendChild(style);
return css;
};
CssVarsService.decorators = [
{ type: Injectable },
];
/** @nocollapse */
CssVarsService.ctorParameters = function () { return []; };
return CssVarsService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var CssVarsModule = (function () {
function CssVarsModule() {
}
/**
* @return {?}
*/
CssVarsModule.forRoot = /**
* @return {?}
*/
function () {
return {
ngModule: CssVarsModule,
providers: [CssVarsService]
};
};
/**
* @return {?}
*/
CssVarsModule.forChild = /**
* @return {?}
*/
function () {
return {
ngModule: CssVarsModule,
providers: [CssVarsService]
};
};
CssVarsModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [CssVarsDirective],
exports: [CssVarsDirective]
},] },
];
/** @nocollapse */
CssVarsModule.ctorParameters = function () { return []; };
return CssVarsModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* Generated bundle index. Do not edit.
*/
export { CssVarsModule, CssVarsDirective, CssVarsService };
//# sourceMappingURL=ngx-css-variables.js.map