From 57e07b9418c3c0f06564ef31445f0547107c9c13 Mon Sep 17 00:00:00 2001 From: David Ortner Date: Mon, 23 May 2022 23:33:33 +0200 Subject: [PATCH] #450@trivial: Starts adding support for Range. --- packages/happy-dom/src/range/Range.ts | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 packages/happy-dom/src/range/Range.ts diff --git a/packages/happy-dom/src/range/Range.ts b/packages/happy-dom/src/range/Range.ts new file mode 100644 index 000000000..294f75129 --- /dev/null +++ b/packages/happy-dom/src/range/Range.ts @@ -0,0 +1,59 @@ +import INode from '../nodes/node/INode'; +import IDocument from '../nodes/document/IDocument'; + +/** + * Range. + * + * Reference: + * https://developer.mozilla.org/en-US/docs/Web/API/Range. + */ +export default class Range { + public static _ownerDocument: IDocument = null; + public readonly startOffset: number = 0; + public readonly endOffset: number = 0; + public readonly startContainer: INode = null; + public readonly endContainer: INode = null; + + /** + * Constructor. + */ + constructor() { + this.startContainer = (this.constructor)._ownerDocument; + this.endContainer = (this.constructor)._ownerDocument; + } + + /** + * Returns a boolean value indicating whether the range's start and end points are at the same position. + * + * @returns Collapsed. + */ + public get collapsed(): boolean { + return this.startContainer === this.endContainer && this.startOffset === this.endOffset; + } + + /** + * Returns the deepest Node that contains the startContainer and endContainer nodes. + * + * @returns Node. + */ + public get commonAncestorContainer(): INode { + // TODO: Implement + return null; + } + + /** + * Collapses the current selection. + * + * @param _toStart To start. + */ + public collapse(_toStart?: boolean): void { + // TODO: Implement + } + + /** + * Returns string currently being represented by the selection object. + */ + public toString(): string { + return ''; + } +}