MCPcopy
hub / github.com/cssinjs/jss / onProcessStyle

Function onProcessStyle

packages/jss-plugin-nested/src/index.js:67–109  ·  view source on GitHub ↗
(style, rule, sheet)

Source from the content-addressed store, hash-verified

65 }
66
67 function onProcessStyle(style, rule, sheet) {
68 if (rule.type !== 'style') return style
69
70 const styleRule = rule
71
72 const container = styleRule.options.parent
73 let options
74 let replaceRef
75 for (const prop in style) {
76 const isNested = prop.indexOf('&') !== -1
77 const isNestedConditional = prop[0] === '@'
78
79 if (!isNested && !isNestedConditional) continue
80
81 options = getOptions(styleRule, container, options)
82
83 if (isNested) {
84 let selector = replaceParentRefs(prop, styleRule.selector)
85 // Lazily create the ref replacer function just once for
86 // all nested rules within the sheet.
87 if (!replaceRef) replaceRef = getReplaceRef(container, sheet)
88 // Replace all $refs.
89 selector = selector.replace(refRegExp, replaceRef)
90
91 const name = `${styleRule.key}-${prop}`
92 if ('replaceRule' in container) {
93 // for backward compatibility
94 container.replaceRule(name, style[prop], {...options, selector})
95 } else {
96 container.addRule(name, style[prop], {...options, selector})
97 }
98 } else if (isNestedConditional) {
99 // Place conditional right after the parent rule to ensure right ordering.
100 container
101 .addRule(prop, {}, options)
102 .addRule(styleRule.key, style[prop], {selector: styleRule.selector})
103 }
104
105 delete style[prop]
106 }
107
108 return style
109 }
110
111 return {onProcessStyle}
112}

Callers

nothing calls this directly

Calls 7

getOptionsFunction · 0.85
replaceParentRefsFunction · 0.85
getReplaceRefFunction · 0.85
replaceMethod · 0.80
indexOfMethod · 0.65
replaceRuleMethod · 0.65
addRuleMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…