MCPcopy Create free account
hub / github.com/microsoft/SandDance / extractRules

Function extractRules

docs/app/js/sanddance-app.js:22029–22068  ·  view source on GitHub ↗
(args, rules, currentSelector)

Source from the content-addressed store, hash-verified

22027 ], rules, expandSelector(selector, currentSelector));
22028}
22029function extractRules(args, rules, currentSelector) {
22030 if (rules === void 0) rules = {
22031 __order: []
22032 };
22033 if (currentSelector === void 0) currentSelector = "&";
22034 var stylesheet = (0, _stylesheet.Stylesheet).getInstance();
22035 var currentRules = rules[currentSelector];
22036 if (!currentRules) {
22037 currentRules = {};
22038 rules[currentSelector] = currentRules;
22039 rules.__order.push(currentSelector);
22040 }
22041 for(var _i = 0, args_1 = args; _i < args_1.length; _i++){
22042 var arg = args_1[_i];
22043 // If the arg is a string, we need to look up the class map and merge.
22044 if (typeof arg === "string") {
22045 var expandedRules = stylesheet.argsFromClassName(arg);
22046 if (expandedRules) extractRules(expandedRules, rules, currentSelector);
22047 // Else if the arg is an array, we need to recurse in.
22048 } else if (Array.isArray(arg)) extractRules(arg, rules, currentSelector);
22049 else {
22050 for(var prop in arg)if (arg.hasOwnProperty(prop)) {
22051 var propValue = arg[prop];
22052 if (prop === "selectors") {
22053 // every child is a selector.
22054 var selectors = arg.selectors;
22055 for(var newSelector in selectors)if (selectors.hasOwnProperty(newSelector)) extractSelector(currentSelector, rules, newSelector, selectors[newSelector]);
22056 } else if (typeof propValue === "object") // prop is a selector.
22057 {
22058 if (propValue !== null) extractSelector(currentSelector, rules, prop, propValue);
22059 } else if (propValue !== undefined) {
22060 // Else, add the rule to the currentSelector.
22061 if (prop === "margin" || prop === "padding") expandQuads(currentRules, prop, propValue);
22062 else currentRules[prop] = propValue;
22063 }
22064 }
22065 }
22066 }
22067 return rules;
22068}
22069function expandQuads(currentRules, name, value) {
22070 var parts = typeof value === "string" ? value.split(" ") : [
22071 value

Callers 2

extractSelectorFunction · 0.85
styleToRegistrationFunction · 0.85

Calls 2

extractSelectorFunction · 0.85
expandQuadsFunction · 0.85

Tested by

no test coverage detected