Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Dec 12, 2024
1 parent 770116f commit 9c8e379
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ type Knot = {
level?: number
}

type Path = Knot[]

export type Options = {
root: Element
idName: (name: string) => boolean
Expand Down Expand Up @@ -176,7 +174,7 @@ function tie(element: Element, config: Options): Knot[] {
return level
}

function selector(path: Path): string {
function selector(path: Knot[]): string {
let node = path[0]
let query = node.name
for (let i = 1; i < path.length; i++) {
Expand All @@ -191,7 +189,7 @@ function selector(path: Path): string {
return query
}

function penalty(path: Path): number {
function penalty(path: Knot[]): number {
return path.map((node) => node.penalty).reduce((acc, i) => acc + i, 0)
}

Expand Down Expand Up @@ -247,7 +245,7 @@ function findRootDocument(rootNode: Element | Document, defaults: Options) {
return rootNode
}

function unique(path: Path, rootDocument: Element | Document) {
function unique(path: Knot[], rootDocument: Element | Document) {
const css = selector(path)
switch (rootDocument.querySelectorAll(css).length) {
case 0:
Expand All @@ -262,7 +260,7 @@ function unique(path: Path, rootDocument: Element | Document) {
}

function* optimize(
path: Path,
path: Knot[],
input: Element,
config: Options,
rootDocument: Element | Document,
Expand Down

0 comments on commit 9c8e379

Please sign in to comment.