MCPcopy Create free account
hub / github.com/webstudio-is/webstudio / getLeftoverRule

Function getLeftoverRule

apps/builder/app/shared/html.ts:275–295  ·  view source on GitHub ↗
(node: csstree.Rule)

Source from the content-addressed store, hash-verified

273 * If none are, keep entirely. If mixed, keep only non-class selectors.
274 */
275 const getLeftoverRule = (node: csstree.Rule): string | undefined => {
276 if (node.prelude?.type !== "SelectorList") {
277 return csstree.generate(node);
278 }
279 const selectors = node.prelude.children.toArray();
280 const nonClassSelectors = selectors.filter(
281 (sel) => !isClassBasedSelector(sel)
282 );
283 if (nonClassSelectors.length === selectors.length) {
284 // No class selectors found — keep entire rule
285 return csstree.generate(node);
286 }
287 if (nonClassSelectors.length === 0) {
288 // All selectors are class-based — skip entirely
289 return undefined;
290 }
291 // Mixed: rebuild rule with only non-class selectors
292 const selectorStrs = nonClassSelectors.map((sel) => csstree.generate(sel));
293 const body = node.block ? csstree.generate(node.block) : "{}";
294 return `${selectorStrs.join(",")}${body}`;
295 };
296
297 // Walk only top-level children of the stylesheet
298 if (ast.type === "StyleSheet") {

Callers 2

buildLeftoverCssFunction · 0.85

Calls 1

isClassBasedSelectorFunction · 0.85

Tested by

no test coverage detected