(css, inlinedSelectors, options, ignoredPseudos)
| 353 | */ |
| 354 | |
| 355 | export function removeInlinedSelectorsFromCSS(css, inlinedSelectors, options, ignoredPseudos) { |
| 356 | let root; |
| 357 | try { |
| 358 | root = parseRoot(css); |
| 359 | } catch (e) { |
| 360 | return ''; |
| 361 | } |
| 362 | |
| 363 | const keep = []; |
| 364 | |
| 365 | for (const node of root.nodes) { |
| 366 | // Always preserve non-rule types (at-rules, comments) |
| 367 | if (node.type !== 'rule') { |
| 368 | keep.push(node); |
| 369 | continue; |
| 370 | } |
| 371 | |
| 372 | // Keep rules with pseudos that were ignored during inlining |
| 373 | if (options.preservePseudos && matchesPseudo(node.selectors[0], ignoredPseudos)) { |
| 374 | keep.push(node); |
| 375 | continue; |
| 376 | } |
| 377 | |
| 378 | // Keep rules that match preservedSelectors |
| 379 | if (options.preservedSelectors && node.selectors.some((sel) => matchesPreservedSelector(sel, options.preservedSelectors))) { |
| 380 | keep.push(node); |
| 381 | continue; |
| 382 | } |
| 383 | |
| 384 | // Filter out selectors that were inlined |
| 385 | const remainingSelectors = node.selectors.filter((sel) => !inlinedSelectors.has(sel)); |
| 386 | |
| 387 | if (remainingSelectors.length > 0) { |
| 388 | const clone = node.clone(); |
| 389 | clone.selectors = remainingSelectors; |
| 390 | keep.push(clone); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | if (keep.length === 0) return ''; |
| 395 | return stringifyNodes(keep); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Compares two specificity vectors, returning the winning one. |
nothing calls this directly
no test coverage detected
searching dependent graphs…