happy-dom 16.0.1 → 16.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/nodes/element/Element.cjs +42 -20
- package/cjs/nodes/element/Element.cjs.map +1 -1
- package/cjs/nodes/element/Element.d.ts +10 -10
- package/cjs/nodes/element/Element.d.ts.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
- package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/cjs/window/BrowserWindow.cjs +42 -20
- package/cjs/window/BrowserWindow.cjs.map +1 -1
- package/cjs/window/BrowserWindow.d.ts +10 -10
- package/cjs/window/BrowserWindow.d.ts.map +1 -1
- package/cjs/window/IScrollToOptions.cjs +3 -0
- package/cjs/window/IScrollToOptions.cjs.map +1 -0
- package/cjs/window/IScrollToOptions.d.ts +6 -0
- package/cjs/window/IScrollToOptions.d.ts.map +1 -0
- package/lib/nodes/element/Element.d.ts +10 -10
- package/lib/nodes/element/Element.d.ts.map +1 -1
- package/lib/nodes/element/Element.js +42 -20
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.js +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
- package/lib/window/BrowserWindow.d.ts +10 -10
- package/lib/window/BrowserWindow.d.ts.map +1 -1
- package/lib/window/BrowserWindow.js +42 -20
- package/lib/window/BrowserWindow.js.map +1 -1
- package/lib/window/IScrollToOptions.d.ts +6 -0
- package/lib/window/IScrollToOptions.d.ts.map +1 -0
- package/lib/window/IScrollToOptions.js +2 -0
- package/lib/window/IScrollToOptions.js.map +1 -0
- package/package.json +1 -1
- package/src/nodes/element/Element.ts +53 -23
- package/src/nodes/parent-node/ParentNodeUtility.ts +4 -1
- package/src/window/BrowserWindow.ts +53 -23
- package/src/window/IScrollToOptions.ts +5 -0
@@ -306,6 +306,7 @@ import SVGUnitTypes from '../svg/SVGUnitTypes.js';
|
|
306
306
|
import DOMPoint from '../dom/DOMPoint.js';
|
307
307
|
import SVGAnimatedLengthList from '../svg/SVGAnimatedLengthList.js';
|
308
308
|
import CustomElementReactionStack from '../custom-element/CustomElementReactionStack.js';
|
309
|
+
import IScrollToOptions from './IScrollToOptions.js';
|
309
310
|
|
310
311
|
const TIMER = {
|
311
312
|
setTimeout: globalThis.setTimeout.bind(globalThis),
|
@@ -1144,28 +1145,35 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
|
|
1144
1145
|
* @param x X position or options object.
|
1145
1146
|
* @param y Y position.
|
1146
1147
|
*/
|
1147
|
-
public scroll(x:
|
1148
|
-
if (typeof x
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1148
|
+
public scroll(x: IScrollToOptions | number, y?: number): void {
|
1149
|
+
if (typeof x !== 'object' && arguments.length === 1) {
|
1150
|
+
throw new this.TypeError(
|
1151
|
+
"Failed to execute 'scroll' on 'Window': The provided value is not of type 'ScrollToOptions'."
|
1152
|
+
);
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
const options = typeof x === 'object' ? x : { left: x, top: y };
|
1156
|
+
|
1157
|
+
if (options.behavior === 'smooth') {
|
1158
|
+
this.setTimeout(() => {
|
1159
|
+
if (options.top !== undefined) {
|
1160
|
+
const top = Number(options.top);
|
1161
|
+
this.document.documentElement.scrollTop = isNaN(top) ? 0 : top;
|
1161
1162
|
}
|
1162
|
-
if (
|
1163
|
-
|
1163
|
+
if (options.left !== undefined) {
|
1164
|
+
const left = Number(options.left);
|
1165
|
+
this.document.documentElement.scrollLeft = isNaN(left) ? 0 : left;
|
1164
1166
|
}
|
1167
|
+
});
|
1168
|
+
} else {
|
1169
|
+
if (options.top !== undefined) {
|
1170
|
+
const top = Number(options.top);
|
1171
|
+
this.document.documentElement.scrollTop = isNaN(top) ? 0 : top;
|
1172
|
+
}
|
1173
|
+
if (options.left !== undefined) {
|
1174
|
+
const left = Number(options.left);
|
1175
|
+
this.document.documentElement.scrollLeft = isNaN(left) ? 0 : left;
|
1165
1176
|
}
|
1166
|
-
} else if (x !== undefined && y !== undefined) {
|
1167
|
-
(<number>this.document.documentElement.scrollLeft) = x;
|
1168
|
-
(<number>this.document.documentElement.scrollTop) = y;
|
1169
1177
|
}
|
1170
1178
|
}
|
1171
1179
|
|
@@ -1175,13 +1183,35 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
|
|
1175
1183
|
* @param x X position or options object.
|
1176
1184
|
* @param y Y position.
|
1177
1185
|
*/
|
1178
|
-
public scrollTo(
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1186
|
+
public scrollTo(x: IScrollToOptions | number, y?: number): void {
|
1187
|
+
if (typeof x !== 'object' && arguments.length === 1) {
|
1188
|
+
throw new this.TypeError(
|
1189
|
+
"Failed to execute 'scrollTo' on 'Window': The provided value is not of type 'ScrollToOptions'."
|
1190
|
+
);
|
1191
|
+
}
|
1182
1192
|
this.scroll(x, y);
|
1183
1193
|
}
|
1184
1194
|
|
1195
|
+
/**
|
1196
|
+
* Scrolls by a relative amount from the current position.
|
1197
|
+
*
|
1198
|
+
* @param x Pixels to scroll by from top or scroll options object.
|
1199
|
+
* @param y Pixels to scroll by from left.
|
1200
|
+
*/
|
1201
|
+
public scrollBy(x: IScrollToOptions | number, y?: number): void {
|
1202
|
+
if (typeof x !== 'object' && arguments.length === 1) {
|
1203
|
+
throw new this.TypeError(
|
1204
|
+
"Failed to execute 'scrollBy' on 'Window': The provided value is not of type 'ScrollToOptions'."
|
1205
|
+
);
|
1206
|
+
}
|
1207
|
+
const options = typeof x === 'object' ? x : { left: x, top: y };
|
1208
|
+
this.scroll({
|
1209
|
+
left: this.document.documentElement.scrollLeft + (options.left ?? 0),
|
1210
|
+
top: this.document.documentElement.scrollTop + (options.top ?? 0),
|
1211
|
+
behavior: options.behavior
|
1212
|
+
});
|
1213
|
+
}
|
1214
|
+
|
1185
1215
|
/**
|
1186
1216
|
* Shifts focus away from the window.
|
1187
1217
|
*/
|