Skip to content

Commit

Permalink
#450@trivial: Continue on Range implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 committed May 30, 2022
1 parent d3da6e2 commit ca7052d
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 258 deletions.
5 changes: 4 additions & 1 deletion packages/happy-dom/src/exception/DOMExceptionNameEnum.ts
Expand Up @@ -2,6 +2,9 @@ enum DOMExceptionNameEnum {
invalidStateError = 'InvalidStateError',
indexSizeError = 'IndexSizeError',
syntaxError = 'SyntaxError',
hierarchyRequestError = 'HierarchyRequestError'
hierarchyRequestError = 'HierarchyRequestError',
notSupportedError = 'NotSupportedError',
wrongDocumentError = 'WrongDocumentError',
invalidNodeTypeError = 'InvalidNodeTypeError'
}
export default DOMExceptionNameEnum;
10 changes: 10 additions & 0 deletions packages/happy-dom/src/nodes/document/Document.ts
Expand Up @@ -38,6 +38,7 @@ import DocumentReadyStateManager from './DocumentReadyStateManager';
import Location from '../../location/Location';
import Selection from '../../selection/Selection';
import IShadowRoot from '../shadow-root/IShadowRoot';
import Range from '../../range/Range';

/**
* Document.
Expand Down Expand Up @@ -754,6 +755,15 @@ export default class Document extends Node implements IDocument {
return clone;
}

/**
* Creates a range.
*
* @returns Range.
*/
public createRange(): Range {
return new Range();
}

/**
* Adopts a node.
*
Expand Down
8 changes: 8 additions & 0 deletions packages/happy-dom/src/nodes/document/IDocument.ts
Expand Up @@ -18,6 +18,7 @@ import CSSStyleSheet from '../../css/CSSStyleSheet';
import Location from '../../location/Location';
import DocumentReadyStateEnum from './DocumentReadyStateEnum';
import INodeList from '../node/INodeList';
import Range from '../../range/Range';

/**
* Document.
Expand Down Expand Up @@ -143,6 +144,13 @@ export default interface IDocument extends IParentNode {
*/
importNode(node: INode): INode;

/**
* Creates a range.
*
* @returns Range.
*/
createRange(): Range;

/**
* Returns an element by ID.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/happy-dom/src/nodes/element/Element.ts
Expand Up @@ -2,7 +2,7 @@ import Node from '../node/Node';
import ShadowRoot from '../shadow-root/ShadowRoot';
import Attr from '../../attribute/Attr';
import DOMRect from './DOMRect';
import Range from './Range';
import Range from '../../range/Range';
import DOMTokenList from '../../dom-token-list/DOMTokenList';
import IDOMTokenList from '../../dom-token-list/IDOMTokenList';
import QuerySelector from '../../query-selector/QuerySelector';
Expand Down
237 changes: 0 additions & 237 deletions packages/happy-dom/src/nodes/element/Range.ts

This file was deleted.

45 changes: 45 additions & 0 deletions packages/happy-dom/src/nodes/node/NodeUtility.ts
@@ -0,0 +1,45 @@
import INode from './INode';

/**
* Node utility.
*/
export default class NodeUtility {
/**
* Returns boolean indicating if nodeB is an inclusive ancestor of nodeA.
*
* @see https://dom.spec.whatwg.org/#concept-tree-inclusive-ancestor
* @param nodeA Node A.
* @param nodeB Node B.
* @returns "true" if following.
*/
public static isInclusiveAncestor(nodeA: INode, nodeB: INode): boolean {
let parent: INode = nodeA;
while (parent) {
if (parent === nodeB) {
return true;
}
parent = parent.parentNode;
}
return false;
}

/**
* Returns boolean indicating if nodeB is following nodeA in the document tree.
*
* @see https://dom.spec.whatwg.org/#concept-tree-following
* @param nodeA Node A.
* @param nodeB Node B.
* @returns "true" if following.
*/
public static isFollowing(nodeA: INode, nodeB: INode): boolean {
let current: INode = nodeA.nextSibling;
while (current) {
if (current === nodeB) {
return true;
}
const nextSibling = current.nextSibling;
current = nextSibling ? nextSibling : current.parentNode;
}
return false;
}
}

0 comments on commit ca7052d

Please sign in to comment.