@asamuzakjp/dom-selector
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -44,3 +44,3 @@ { | ||
}, | ||
"version": "0.2.2" | ||
"version": "0.3.0" | ||
} |
@@ -1084,25 +1084,7 @@ /** | ||
let nextNode = iterator.nextNode(); | ||
while (nextNode) { | ||
const [...items] = children; | ||
if (items.length) { | ||
if (items.length === 1) { | ||
const item = items.shift(); | ||
const { name: itemName, type: itemType } = item; | ||
if (itemType === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_FUNC.test(itemName)) { | ||
nextNode = this._matchLogicalPseudoFunc(item, nextNode); | ||
if (nextNode) { | ||
res.add(nextNode); | ||
nextNode = null; | ||
} | ||
} else { | ||
const arr = this._match(item, nextNode); | ||
if (arr.length) { | ||
for (const i of arr) { | ||
res.add(i); | ||
} | ||
} | ||
} | ||
} else { | ||
do { | ||
if (nextNode) { | ||
while (nextNode) { | ||
const [...items] = children; | ||
if (items.length) { | ||
if (items.length === 1) { | ||
const item = items.shift(); | ||
@@ -1113,49 +1095,80 @@ const { name: itemName, type: itemType } = item; | ||
nextNode = this._matchLogicalPseudoFunc(item, nextNode); | ||
} else if (itemType === COMBINATOR) { | ||
const leaves = []; | ||
leaves.push(item); | ||
while (items.length) { | ||
const [nextItem] = items; | ||
if (nextItem.type === COMBINATOR || | ||
(nextItem.type === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_NTH.test(nextItem.name)) || | ||
(nextItem.type === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_FUNC.test(nextItem.name))) { | ||
break; | ||
} else { | ||
leaves.push(items.shift()); | ||
if (nextNode) { | ||
res.add(nextNode); | ||
nextNode = null; | ||
} | ||
} else { | ||
const arr = this._match(item, nextNode); | ||
if (arr.length) { | ||
for (const i of arr) { | ||
res.add(i); | ||
} | ||
} | ||
const arr = this._matchCombinator(leaves, nextNode); | ||
if (!arr.length || arr.length === 1) { | ||
[nextNode] = arr; | ||
} else { | ||
if (items.length) { | ||
for (const i of arr) { | ||
const a = this._matchSelector(items, i); | ||
if (a.length) { | ||
for (const j of a) { | ||
res.add(j); | ||
} | ||
} else { | ||
do { | ||
const item = items.shift(); | ||
const { name: itemName, type: itemType } = item; | ||
if (itemType === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_FUNC.test(itemName)) { | ||
nextNode = this._matchLogicalPseudoFunc(item, nextNode); | ||
} else if (itemType === COMBINATOR) { | ||
const leaves = []; | ||
leaves.push(item); | ||
while (items.length) { | ||
const [nextItem] = items; | ||
if (nextItem.type === COMBINATOR || | ||
(nextItem.type === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_NTH.test(nextItem.name)) || | ||
(nextItem.type === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_FUNC.test(nextItem.name))) { | ||
break; | ||
} else { | ||
leaves.push(items.shift()); | ||
} | ||
} | ||
const arr = this._matchCombinator(leaves, nextNode); | ||
if (!arr.length || arr.length === 1) { | ||
[nextNode] = arr; | ||
} else { | ||
if (items.length) { | ||
for (const i of arr) { | ||
const a = this._matchSelector(items, i); | ||
if (a.length) { | ||
for (const j of a) { | ||
res.add(j); | ||
} | ||
} | ||
} | ||
} else { | ||
for (const i of arr) { | ||
res.add(i); | ||
} | ||
} | ||
} else { | ||
for (const i of arr) { | ||
res.add(i); | ||
} | ||
nextNode = null; | ||
} | ||
nextNode = null; | ||
} else { | ||
[nextNode] = this._match(item, nextNode); | ||
} | ||
} else { | ||
[nextNode] = this._match(item, nextNode); | ||
} while (items.length && nextNode); | ||
if (nextNode) { | ||
res.add(nextNode); | ||
} | ||
} while (items.length && nextNode); | ||
if (nextNode) { | ||
res.add(nextNode); | ||
} | ||
} else if (nextNode) { | ||
res.add(nextNode); | ||
} | ||
} else if (nextNode) { | ||
res.add(nextNode); | ||
nextNode = iterator.nextNode(); | ||
} | ||
nextNode = iterator.nextNode(); | ||
} else if (firstChild.type === PSEUDO_CLASS_SELECTOR && | ||
REG_PSEUDO_FUNC.test(firstChild.name) && | ||
node.nodeType === ELEMENT_NODE) { | ||
nextNode = node; | ||
while (nextNode) { | ||
nextNode = this._matchLogicalPseudoFunc(firstChild, nextNode); | ||
if (nextNode) { | ||
res.add(nextNode); | ||
} | ||
nextNode = nextNode.nextElementSibling; | ||
} | ||
} | ||
@@ -1268,3 +1281,8 @@ } | ||
if (arr.length) { | ||
[res] = arr; | ||
const [i, j] = arr; | ||
if (i !== this.#node) { | ||
res = i; | ||
} else if (j) { | ||
res = j; | ||
} | ||
} | ||
@@ -1284,3 +1302,5 @@ return res || null; | ||
for (const i of arr) { | ||
res.add(i); | ||
if (i !== this.#node) { | ||
res.add(i); | ||
} | ||
} | ||
@@ -1287,0 +1307,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47907
1465