UNPKG

fela-plugin-important

Version:

Fela plugin that adds !important to every value

53 lines (41 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = important; var _isobject = _interopRequireDefault(require("isobject")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function addImportantToValue(value) { if (typeof value === 'number' || typeof value === 'string' && value.toLowerCase().indexOf('!important') === -1) { return "".concat(value, "!important"); } return value; } function isAnimation(style) { var styleNames = Object.getOwnPropertyNames(style); var isAnimationItem = false; for (var i = 0; i < styleNames.length; i++) { var property = styleNames[i].toString(); isAnimationItem = property === 'to' || property.includes('from') || property.includes('animation') || property.includes('%'); } return isAnimationItem; } function importantPlugin(style) { if (!isAnimation(style)) { for (var property in style) { var value = style[property]; if (property === 'className') {// this is a fixed classname, not a style rule - leave as is } else if ((0, _isobject["default"])(value)) { style[property] = importantPlugin(value); } else if (Array.isArray(value)) { style[property] = value.map(addImportantToValue); } else { style[property] = addImportantToValue(value); } } } return style; } function important() { return importantPlugin; }