source: trip-planner-front/node_modules/postcss-initial/index.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[6a3a178]1var postcss = require('postcss');
2var makeFallbackFunction = require('./lib/rules-fabric');
3
4module.exports = postcss.plugin('postcss-initial', function (opts) {
5 opts = opts || {};
6 opts.reset = opts.reset || 'all';
7 opts.replace = opts.replace || false;
8 var getFallback = makeFallbackFunction(opts.reset === 'inherited');
9 var getPropPrevTo = function (prop, decl) {
10 var foundPrev = false;
11 decl.parent.walkDecls(function (child) {
12 if (child.prop === decl.prop && child.value !== decl.value) {
13 foundPrev = true;
14 }
15 });
16 return foundPrev;
17 };
18 return function (css) {
19 css.walkDecls(function (decl) {
20 if (!/\binitial\b/.test(decl.value)) {
21 return;
22 }
23 var fallBackRules = getFallback(decl.prop, decl.value);
24 if (fallBackRules.length === 0) return;
25 fallBackRules.forEach(function (rule) {
26 if ( !getPropPrevTo(decl.prop, decl) ) {
27 decl.cloneBefore(rule);
28 }
29 });
30 if (opts.replace === true) {
31 decl.remove();
32 }
33 });
34 };
35});
Note: See TracBrowser for help on using the repository browser.