-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: multi elements support for fallback
- Loading branch information
Showing
6 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import {getParents} from './utilities-dom' | ||
import {getNthChildSelector} from './selector-nth-child' | ||
import {DESCENDANT_OPERATOR} from './constants' | ||
import {CssSelector} from './types' | ||
import {DESCENDANT_OPERATOR, SELECTOR_SEPARATOR} from './constants'; | ||
import {CssSelector, SelectorNeedle} from './types'; | ||
import {sanitizeSelectorNeedle} from './utilities-selectors'; | ||
|
||
/** | ||
* Creates chain if :nth-child selectors from root to the element. | ||
*/ | ||
export function getFallbackSelector (element: Element): CssSelector { | ||
export function constructFallbackSelector (element: Element): CssSelector { | ||
const selectors = getParents(element) | ||
.map((element) => getNthChildSelector(element)[0]) | ||
.reverse() | ||
return [':root', ...selectors].join(DESCENDANT_OPERATOR) | ||
} | ||
|
||
/** | ||
* Creates chain if :nth-child selectors from root to the element. | ||
*/ | ||
export function getFallbackSelector (needle: SelectorNeedle): CssSelector { | ||
const elements = sanitizeSelectorNeedle(needle) | ||
return elements.map(constructFallbackSelector).join(SELECTOR_SEPARATOR) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters