Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#450@trivial: Continue on Range implementation.
- Loading branch information
1 parent
acdc0f1
commit 8dcb103
Showing
9 changed files
with
629 additions
and
203 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/happy-dom/src/nodes/element/DOMRectListFactory.ts
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import DOMRect from './DOMRect'; | ||
import IDOMRectList from './IDOMRectList'; | ||
|
||
/** | ||
* DOM rect list factory. | ||
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/getClientRects | ||
*/ | ||
export default class DOMRectListFactory { | ||
/** | ||
* Creates an HTMLCollection. | ||
* | ||
* @param list Nodes. | ||
* @returns HTMLCollection. | ||
*/ | ||
public static create(list?: DOMRect[]): IDOMRectList<DOMRect> { | ||
list = list ? list.slice() : []; | ||
Object.defineProperty(list, 'item', { | ||
value: this.getItem.bind(null, list) | ||
}); | ||
return <IDOMRectList<DOMRect>>list; | ||
} | ||
|
||
/** | ||
* Returns node by index. | ||
* | ||
* @param list | ||
* @param index Index. | ||
*/ | ||
private static getItem(list: DOMRect[], index: number): DOMRect { | ||
return list[index] || null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* HTMLCollection. | ||
*/ | ||
export default interface IDOMRectList<T> extends Array<T> { | ||
/** | ||
* Returns item by index. | ||
* | ||
* @param index Index. | ||
*/ | ||
item(index: number): T; | ||
} |
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
Oops, something went wrong.