Skip to content

Commit

Permalink
Merge pull request capricorn86#488 from capricorn86/task/486-domrect-…
Browse files Browse the repository at this point in the history
…is-not-defined

capricorn86#846@minor: Adds support for Window.DOMRect.
  • Loading branch information
capricorn86 committed May 25, 2022
2 parents 803d779 + b53c4b9 commit cede8a4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/happy-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import XMLParser from './xml-parser/XMLParser';
import XMLSerializer from './xml-serializer/XMLSerializer';
import CSSStyleSheet from './css/CSSStyleSheet';
import Storage from './storage/Storage';
import DOMRect from './nodes/element/DOMRect';
import { URLSearchParams } from 'url';
import Selection from './selection/Selection';

Expand Down Expand Up @@ -208,6 +209,7 @@ export {
XMLSerializer,
CSSStyleSheet,
Storage,
DOMRect,
URLSearchParams,
Selection
};
15 changes: 15 additions & 0 deletions packages/happy-dom/src/nodes/element/DOMRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ export default class DOMRect {
public right = 0;
public bottom = 0;
public left = 0;

/**
* Constructor.
*
* @param [x] X position.
* @param [y] Y position.
* @param [width] Width.
* @param [height] Height.
*/
constructor(x?, y?, width?, height?) {
this.x = x || 0;
this.y = y || 0;
this.width = width || 0;
this.height = height || 0;
}
}
2 changes: 2 additions & 0 deletions packages/happy-dom/src/window/IWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import IHeaders from '../fetch/IHeaders';
import IRequestInit from '../fetch/IRequestInit';
import IResponse from '../fetch/IResponse';
import MediaQueryList from '../match-media/MediaQueryList';
import DOMRect from '../nodes/element/DOMRect';
import Window from './Window';
import { URLSearchParams } from 'url';
import { Performance } from 'perf_hooks';
Expand Down Expand Up @@ -173,6 +174,7 @@ export default interface IWindow extends IEventTarget, NodeJS.Global {
readonly Headers: { new (init?: string[][] | Record<string, string> | IHeaders): IHeaders };
readonly Request: { new (input: string | IRequest, init?: IRequestInit): IRequest };
readonly Response: { new (body?: unknown | null, init?: IResponseInit): IResponse };
readonly DOMRect: typeof DOMRect;

// Events
onload: (event: Event) => void;
Expand Down
2 changes: 2 additions & 0 deletions packages/happy-dom/src/window/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import Plugin from '../navigator/Plugin';
import PluginArray from '../navigator/PluginArray';
import { URLSearchParams } from 'url';
import FetchHandler from '../fetch/FetchHandler';
import DOMRect from '../nodes/element/DOMRect';
import VMGlobalPropertyScript from './VMGlobalPropertyScript';
import * as PerfHooks from 'perf_hooks';
import VM from 'vm';
Expand Down Expand Up @@ -192,6 +193,7 @@ export default class Window extends EventTarget implements IWindow {
public readonly Response: {
new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
} = Response;
public readonly DOMRect: typeof DOMRect;

// Events
public onload: (event: Event) => void = null;
Expand Down

0 comments on commit cede8a4

Please sign in to comment.