Make css matcher return an Element, not Range
diff --git a/packages/dom/src/css.ts b/packages/dom/src/css.ts
index 1026004..6882b1e 100644
--- a/packages/dom/src/css.ts
+++ b/packages/dom/src/css.ts
@@ -45,11 +45,6 @@
* > “If […] the user agent discovers multiple matching text sequences, then the
* > selection SHOULD be treated as matching all of the matches.”
*
- * Each matching element is returned as a {@link https://developer.mozilla.org/en-US/docs/Web/API/Range
- * | Range} surrounding that element. This in order to make its output reusable
- * as the scope for any subsequents selectors that {@link
- * Selector.refinedBy | refine} this CssSelector.
- *
* @param selector - The {@link CssSelector} to be anchored
* @returns A {@link Matcher} function that applies `selector` to a given {@link https://developer.mozilla.org/en-US/docs/Web/API/Range
* | Range}
@@ -58,7 +53,7 @@
*/
export function createCssSelectorMatcher(
selector: CssSelector,
-): Matcher<Range, Range> {
+): Matcher<Range, Element> {
return async function* matchAll(scope) {
const document = ownerDocument(scope);
for (const element of document.querySelectorAll(selector.value)) {
@@ -69,7 +64,7 @@
scope.isPointInRange(range.startContainer, range.startOffset) &&
scope.isPointInRange(range.endContainer, range.endOffset)
) {
- yield range;
+ yield element;
}
}
};
diff --git a/packages/dom/test/css/match.test.ts b/packages/dom/test/css/match.test.ts
index 9d4c18f..2c5d682 100644
--- a/packages/dom/test/css/match.test.ts
+++ b/packages/dom/test/css/match.test.ts
@@ -54,9 +54,6 @@
assert.equal(matches.length, expected.length, 'Unexpected number of matches');
matches.forEach((match, i) => {
const expectedElement = evaluateXPath(doc, expected[i]);
- // The match should be a Range that exactly contains the expected element.
- assert.equal(match.startContainer.childNodes[match.startOffset], expectedElement);
- assert.equal(match.endContainer, match.startContainer);
- assert.equal(match.endOffset, match.startOffset + 1);
+ assert.equal(match, expectedElement);
});
}