Initial commit

This commit is contained in:
Ammaar Reshi
2025-01-04 14:06:53 +00:00
parent 7082408604
commit d6025af146
23760 changed files with 3299690 additions and 0 deletions

47
node_modules/motion-dom/src/utils/resolve-elements.ts generated vendored Normal file
View File

@ -0,0 +1,47 @@
export type ElementOrSelector =
| Element
| Element[]
| NodeListOf<Element>
| string
export interface WithQuerySelectorAll {
querySelectorAll: Element["querySelectorAll"]
}
export interface AnimationScope<T = any> {
readonly current: T
animations: any[] // TODO: Refactor to types package AnimationPlaybackControls[]
}
export interface SelectorCache {
[key: string]: NodeListOf<Element>
}
export function resolveElements(
elementOrSelector: ElementOrSelector,
scope?: AnimationScope,
selectorCache?: SelectorCache
): Element[] {
if (elementOrSelector instanceof Element) {
return [elementOrSelector]
} else if (typeof elementOrSelector === "string") {
let root: WithQuerySelectorAll = document
if (scope) {
// TODO: Refactor to utils package
// invariant(
// Boolean(scope.current),
// "Scope provided, but no element detected."
// )
root = scope.current
}
const elements =
selectorCache?.[elementOrSelector] ??
root.querySelectorAll(elementOrSelector)
return elements ? Array.from(elements) : []
}
return Array.from(elementOrSelector)
}