UNPKG

ngx-css-variables

Version:
138 lines (130 loc) 3.84 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) : typeof define === 'function' && 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 */ /** * @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: core.Directive, args: [{ selector: '[css-vars]' },] }, ]; /** @nocollapse */ CssVarsDirective.ctorParameters = function () { return [ { type: core.ElementRef, }, ]; }; CssVarsDirective.propDecorators = { "cssVars": [{ type: core.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: core.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: core.NgModule, args: [{ imports: [ common.CommonModule ], declarations: [CssVarsDirective], exports: [CssVarsDirective] },] }, ]; /** @nocollapse */ CssVarsModule.ctorParameters = function () { return []; }; return CssVarsModule; }()); exports.CssVarsModule = CssVarsModule; exports.CssVarsDirective = CssVarsDirective; exports.CssVarsService = CssVarsService; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=ngx-css-variables.umd.js.map