This commit is contained in:
2022-07-18 02:50:52 +00:00
parent befd344ab0
commit 06181b34d6
8569 changed files with 818704 additions and 352705 deletions
+16 -11
View File
@@ -1,6 +1,12 @@
var template = require('lodash.template');
var decls = require('./decls.json');
function template(string, data) {
return string.replace(/\$\{([\w\-\.]*)\}/g, function (_str, key) {
var v = data[key];
return typeof v !== 'undefined' && v !== null ? v : '';
});
}
/*
Rules legend:
- combined - if rule is combined it will be rendered with template
@@ -23,8 +29,7 @@ function _compileDecls(inputDecls) {
var templateVars = _getRulesMap(inputDecls);
return inputDecls.map(function (decl) {
if (decl.combined && decl.initial) {
var t = template(decl.initial.replace(/\-/g, ''));
decl.initial = t(templateVars);
decl.initial = template(decl.initial.replace(/\-/g, ''), templateVars);
}
return decl;
});
@@ -33,8 +38,8 @@ function _compileDecls(inputDecls) {
function _getRequirements(inputDecls) {
return inputDecls.reduce(function (map, decl) {
if (!decl.contains) return map;
return decl.contains.reduce(function (mapInner, dependensy) {
mapInner[dependensy] = decl;
return decl.contains.reduce(function (mapInner, dependency) {
mapInner[dependency] = decl;
return mapInner;
}, map);
}, {});
@@ -46,11 +51,11 @@ function _expandContainments(inputDecls) {
.filter(function (decl) {
return !decl.contains;
}).map(function (decl) {
var dependensy = requiredMap[decl.prop];
if (dependensy) {
decl.requiredBy = dependensy.prop;
decl.basic = decl.basic || dependensy.basic;
decl.inherited = decl.inherited || dependensy.inherited;
var dependency = requiredMap[decl.prop];
if (dependency) {
decl.requiredBy = dependency.prop;
decl.basic = decl.basic || dependency.basic;
decl.inherited = decl.inherited || dependency.inherited;
}
return decl;
});
@@ -62,7 +67,7 @@ function _clearDecls(rules, value) {
return rules.map(function (rule) {
return {
prop: rule.prop,
value: value.replace(/initial/g, rule.initial)
value: value.replace(/\binitial\b/g, rule.initial)
};
});
}