Socket
Socket
Sign inDemoInstall

happy-dom

Package Overview
Dependencies
Maintainers
1
Versions
576
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

happy-dom - npm Package Compare versions

Comparing version 13.8.4 to 13.8.5

2

cjs/config/HTMLElementConfigContentModelEnum.d.ts
declare enum HTMLElementConfigContentModelEnum {
rawText = "rawText",
noSelfDescendants = "noSelfDescendants",
noFirsLevelSelfDescendants = "noFirsLevelSelfDescendants",
noFirstLevelSelfDescendants = "noFirstLevelSelfDescendants",
noDescendants = "noDescendants",

@@ -6,0 +6,0 @@ anyDescendants = "anyDescendants"

@@ -46,3 +46,3 @@ import IElement from '../nodes/element/IElement.cjs';

/**
* Matches a psuedo selector.
* Matches a pseudo selector.
*

@@ -54,2 +54,10 @@ * @param element Element.

/**
* Matches a pseudo selector.
*
* @param element Element.
* @param parentChildren Parent children.
* @param pseudo Pseudo.
*/
private matchPseudoItem;
/**
* Matches attribute.

@@ -56,0 +64,0 @@ *

@@ -220,3 +220,3 @@ import HTMLElementConfigContentModelEnum from './HTMLElementConfigContentModelEnum.js';

tagName: 'DD',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -263,3 +263,3 @@ del: {

tagName: 'DT',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -306,3 +306,3 @@ em: {

tagName: 'H1',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -313,3 +313,3 @@ h2: {

tagName: 'H2',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -320,3 +320,3 @@ h3: {

tagName: 'H3',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -327,3 +327,3 @@ h4: {

tagName: 'H4',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -334,3 +334,3 @@ h5: {

tagName: 'H5',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -341,3 +341,3 @@ h6: {

tagName: 'H6',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -408,3 +408,3 @@ head: {

tagName: 'LI',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -487,3 +487,3 @@ main: {

tagName: 'OPTION',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -632,3 +632,3 @@ output: {

tagName: 'TABLE',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -635,0 +635,0 @@ tbody: {

declare enum HTMLElementConfigContentModelEnum {
rawText = "rawText",
noSelfDescendants = "noSelfDescendants",
noFirsLevelSelfDescendants = "noFirsLevelSelfDescendants",
noFirstLevelSelfDescendants = "noFirstLevelSelfDescendants",
noDescendants = "noDescendants",

@@ -6,0 +6,0 @@ anyDescendants = "anyDescendants"

@@ -5,3 +5,3 @@ var HTMLElementConfigContentModelEnum;

HTMLElementConfigContentModelEnum["noSelfDescendants"] = "noSelfDescendants";
HTMLElementConfigContentModelEnum["noFirsLevelSelfDescendants"] = "noFirsLevelSelfDescendants";
HTMLElementConfigContentModelEnum["noFirstLevelSelfDescendants"] = "noFirstLevelSelfDescendants";
HTMLElementConfigContentModelEnum["noDescendants"] = "noDescendants";

@@ -8,0 +8,0 @@ HTMLElementConfigContentModelEnum["anyDescendants"] = "anyDescendants";

@@ -46,3 +46,3 @@ import IElement from '../nodes/element/IElement.js';

/**
* Matches a psuedo selector.
* Matches a pseudo selector.
*

@@ -54,2 +54,10 @@ * @param element Element.

/**
* Matches a pseudo selector.
*
* @param element Element.
* @param parentChildren Parent children.
* @param pseudo Pseudo.
*/
private matchPseudoItem;
/**
* Matches attribute.

@@ -56,0 +64,0 @@ *

@@ -77,3 +77,3 @@ import DOMException from '../exception/DOMException.js';

/**
* Matches a psuedo selector.
* Matches a pseudo selector.
*

@@ -91,5 +91,5 @@ * @param element Element.

}
for (const psuedo of this.pseudos) {
for (const pseudo of this.pseudos) {
// Validation
switch (psuedo.name) {
switch (pseudo.name) {
case 'not':

@@ -100,3 +100,3 @@ case 'nth-child':

case 'nth-last-of-type':
if (!psuedo.arguments) {
if (!pseudo.arguments) {
throw new DOMException(`The selector "${this.getSelectorString()}" is not valid.`);

@@ -108,3 +108,3 @@ }

if (!parent) {
switch (psuedo.name) {
switch (pseudo.name) {
case 'first-child':

@@ -123,79 +123,93 @@ case 'last-child':

}
switch (psuedo.name) {
case 'first-child':
return parentChildren[0] === element;
case 'last-child':
return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
case 'only-child':
return parentChildren.length === 1 && parentChildren[0] === element;
case 'first-of-type':
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
if (!this.matchPseudoItem(element, parentChildren, pseudo)) {
return false;
}
}
return true;
}
/**
* Matches a pseudo selector.
*
* @param element Element.
* @param parentChildren Parent children.
* @param pseudo Pseudo.
*/
matchPseudoItem(element, parentChildren, pseudo) {
switch (pseudo.name) {
case 'first-child':
return parentChildren[0] === element;
case 'last-child':
return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
case 'only-child':
return parentChildren.length === 1 && parentChildren[0] === element;
case 'first-of-type':
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
return false;
case 'last-of-type':
for (let i = parentChildren.length - 1; i >= 0; i--) {
const child = parentChildren[i];
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
return false;
case 'last-of-type':
for (let i = parentChildren.length - 1; i >= 0; i--) {
const child = parentChildren[i];
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
}
return false;
case 'only-of-type':
let isFound = false;
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
if (isFound || child !== element) {
return false;
}
isFound = true;
}
}
return isFound;
case 'checked':
return element[PropertySymbol.tagName] === 'INPUT' && element.checked;
case 'empty':
return !element[PropertySymbol.children].length;
case 'root':
return element[PropertySymbol.tagName] === 'HTML';
case 'not':
return !pseudo.selectorItem.match(element);
case 'nth-child':
const nthChildIndex = pseudo.selectorItem
? parentChildren.filter((child) => pseudo.selectorItem.match(child)).indexOf(element)
: parentChildren.indexOf(element);
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1);
case 'nth-of-type':
if (!element[PropertySymbol.parentNode]) {
return false;
case 'only-of-type':
let isFound = false;
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
if (isFound || child !== element) {
return false;
}
isFound = true;
}
}
return isFound;
case 'checked':
return (element[PropertySymbol.tagName] === 'INPUT' && element.checked);
case 'empty':
return !element[PropertySymbol.children].length;
case 'root':
return element[PropertySymbol.tagName] === 'HTML';
case 'not':
return !psuedo.selectorItem.match(element);
case 'nth-child':
const nthChildIndex = psuedo.selectorItem
? parentChildren.filter((child) => psuedo.selectorItem.match(child)).indexOf(element)
: parentChildren.indexOf(element);
return nthChildIndex !== -1 && psuedo.nthFunction(nthChildIndex + 1);
case 'nth-of-type':
if (!element[PropertySymbol.parentNode]) {
return false;
}
const nthOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.indexOf(element);
return nthOfTypeIndex !== -1 && psuedo.nthFunction(nthOfTypeIndex + 1);
case 'nth-last-child':
const nthLastChildIndex = psuedo.selectorItem
? parentChildren
.filter((child) => psuedo.selectorItem.match(child))
.reverse()
.indexOf(element)
: parentChildren.reverse().indexOf(element);
return nthLastChildIndex !== -1 && psuedo.nthFunction(nthLastChildIndex + 1);
case 'nth-last-of-type':
const nthLastOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
}
const nthOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.indexOf(element);
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1);
case 'nth-last-child':
const nthLastChildIndex = pseudo.selectorItem
? parentChildren
.filter((child) => pseudo.selectorItem.match(child))
.reverse()
.indexOf(element);
return nthLastOfTypeIndex !== -1 && psuedo.nthFunction(nthLastOfTypeIndex + 1);
case 'target':
const hash = element[PropertySymbol.ownerDocument].location.hash;
if (!hash) {
return false;
}
return element.isConnected && element.id === hash.slice(1);
}
.indexOf(element)
: parentChildren.reverse().indexOf(element);
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1);
case 'nth-last-of-type':
const nthLastOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.reverse()
.indexOf(element);
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1);
case 'target':
const hash = element[PropertySymbol.ownerDocument].location.hash;
if (!hash) {
return false;
}
return element.isConnected && element.id === hash.slice(1);
default:
return false;
}
return true;
}

@@ -202,0 +216,0 @@ /**

@@ -1,1 +0,1 @@

export default { version: '13.8.4' };
export default { version: '13.8.5' };

@@ -90,3 +90,3 @@ import * as PropertySymbol from '../PropertySymbol.js';

if (config?.contentModel ===
HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants &&
HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants &&
stackTagNames[stackTagNames.length - 1] === tagName) {

@@ -93,0 +93,0 @@ stack.pop();

{
"name": "happy-dom",
"version": "13.8.4",
"version": "13.8.5",
"license": "MIT",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/capricorn86/happy-dom",

@@ -222,3 +222,3 @@ import HTMLElementConfigContentModelEnum from './HTMLElementConfigContentModelEnum.js';

tagName: 'DD',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -265,3 +265,3 @@ del: {

tagName: 'DT',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -308,3 +308,3 @@ em: {

tagName: 'H1',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -315,3 +315,3 @@ h2: {

tagName: 'H2',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -322,3 +322,3 @@ h3: {

tagName: 'H3',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -329,3 +329,3 @@ h4: {

tagName: 'H4',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -336,3 +336,3 @@ h5: {

tagName: 'H5',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -343,3 +343,3 @@ h6: {

tagName: 'H6',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -410,3 +410,3 @@ head: {

tagName: 'LI',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -489,3 +489,3 @@ main: {

tagName: 'OPTION',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -634,3 +634,3 @@ output: {

tagName: 'TABLE',
contentModel: HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants
contentModel: HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants
},

@@ -637,0 +637,0 @@ tbody: {

enum HTMLElementConfigContentModelEnum {
rawText = 'rawText',
noSelfDescendants = 'noSelfDescendants',
noFirsLevelSelfDescendants = 'noFirsLevelSelfDescendants',
noFirstLevelSelfDescendants = 'noFirstLevelSelfDescendants',
noDescendants = 'noDescendants',

@@ -6,0 +6,0 @@ anyDescendants = 'anyDescendants'

@@ -109,3 +109,3 @@ import DOMException from '../exception/DOMException.js';

/**
* Matches a psuedo selector.
* Matches a pseudo selector.
*

@@ -125,5 +125,5 @@ * @param element Element.

for (const psuedo of this.pseudos) {
for (const pseudo of this.pseudos) {
// Validation
switch (psuedo.name) {
switch (pseudo.name) {
case 'not':

@@ -134,3 +134,3 @@ case 'nth-child':

case 'nth-last-of-type':
if (!psuedo.arguments) {
if (!pseudo.arguments) {
throw new DOMException(`The selector "${this.getSelectorString()}" is not valid.`);

@@ -143,3 +143,3 @@ }

if (!parent) {
switch (psuedo.name) {
switch (pseudo.name) {
case 'first-child':

@@ -159,82 +159,99 @@ case 'last-child':

switch (psuedo.name) {
case 'first-child':
return parentChildren[0] === element;
case 'last-child':
return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
case 'only-child':
return parentChildren.length === 1 && parentChildren[0] === element;
case 'first-of-type':
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
if (!this.matchPseudoItem(element, parentChildren, pseudo)) {
return false;
}
}
return true;
}
/**
* Matches a pseudo selector.
*
* @param element Element.
* @param parentChildren Parent children.
* @param pseudo Pseudo.
*/
private matchPseudoItem(
element: IElement,
parentChildren: IElement[],
pseudo: ISelectorPseudo
): boolean {
switch (pseudo.name) {
case 'first-child':
return parentChildren[0] === element;
case 'last-child':
return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
case 'only-child':
return parentChildren.length === 1 && parentChildren[0] === element;
case 'first-of-type':
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
return false;
case 'last-of-type':
for (let i = parentChildren.length - 1; i >= 0; i--) {
const child = parentChildren[i];
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
return false;
case 'last-of-type':
for (let i = parentChildren.length - 1; i >= 0; i--) {
const child = parentChildren[i];
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
return child === element;
}
}
return false;
case 'only-of-type':
let isFound = false;
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
if (isFound || child !== element) {
return false;
}
isFound = true;
}
}
return isFound;
case 'checked':
return element[PropertySymbol.tagName] === 'INPUT' && (<IHTMLInputElement>element).checked;
case 'empty':
return !(<Element>element)[PropertySymbol.children].length;
case 'root':
return element[PropertySymbol.tagName] === 'HTML';
case 'not':
return !pseudo.selectorItem.match(element);
case 'nth-child':
const nthChildIndex = pseudo.selectorItem
? parentChildren.filter((child) => pseudo.selectorItem.match(child)).indexOf(element)
: parentChildren.indexOf(element);
return nthChildIndex !== -1 && pseudo.nthFunction(nthChildIndex + 1);
case 'nth-of-type':
if (!element[PropertySymbol.parentNode]) {
return false;
case 'only-of-type':
let isFound = false;
for (const child of parentChildren) {
if (child[PropertySymbol.tagName] === element[PropertySymbol.tagName]) {
if (isFound || child !== element) {
return false;
}
isFound = true;
}
}
return isFound;
case 'checked':
return (
element[PropertySymbol.tagName] === 'INPUT' && (<IHTMLInputElement>element).checked
);
case 'empty':
return !(<Element>element)[PropertySymbol.children].length;
case 'root':
return element[PropertySymbol.tagName] === 'HTML';
case 'not':
return !psuedo.selectorItem.match(element);
case 'nth-child':
const nthChildIndex = psuedo.selectorItem
? parentChildren.filter((child) => psuedo.selectorItem.match(child)).indexOf(element)
: parentChildren.indexOf(element);
return nthChildIndex !== -1 && psuedo.nthFunction(nthChildIndex + 1);
case 'nth-of-type':
if (!element[PropertySymbol.parentNode]) {
return false;
}
const nthOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.indexOf(element);
return nthOfTypeIndex !== -1 && psuedo.nthFunction(nthOfTypeIndex + 1);
case 'nth-last-child':
const nthLastChildIndex = psuedo.selectorItem
? parentChildren
.filter((child) => psuedo.selectorItem.match(child))
.reverse()
.indexOf(element)
: parentChildren.reverse().indexOf(element);
return nthLastChildIndex !== -1 && psuedo.nthFunction(nthLastChildIndex + 1);
case 'nth-last-of-type':
const nthLastOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.reverse()
.indexOf(element);
return nthLastOfTypeIndex !== -1 && psuedo.nthFunction(nthLastOfTypeIndex + 1);
case 'target':
const hash = element[PropertySymbol.ownerDocument].location.hash;
if (!hash) {
return false;
}
return element.isConnected && element.id === hash.slice(1);
}
}
const nthOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.indexOf(element);
return nthOfTypeIndex !== -1 && pseudo.nthFunction(nthOfTypeIndex + 1);
case 'nth-last-child':
const nthLastChildIndex = pseudo.selectorItem
? parentChildren
.filter((child) => pseudo.selectorItem.match(child))
.reverse()
.indexOf(element)
: parentChildren.reverse().indexOf(element);
return nthLastChildIndex !== -1 && pseudo.nthFunction(nthLastChildIndex + 1);
case 'nth-last-of-type':
const nthLastOfTypeIndex = parentChildren
.filter((child) => child[PropertySymbol.tagName] === element[PropertySymbol.tagName])
.reverse()
.indexOf(element);
return nthLastOfTypeIndex !== -1 && pseudo.nthFunction(nthLastOfTypeIndex + 1);
case 'target':
const hash = element[PropertySymbol.ownerDocument].location.hash;
if (!hash) {
return false;
}
return element.isConnected && element.id === hash.slice(1);
default:
return false;
}
return true;
}

@@ -241,0 +258,0 @@

@@ -117,3 +117,3 @@ import IDocument from '../nodes/document/IDocument.js';

config?.contentModel ===
HTMLElementConfigContentModelEnum.noFirsLevelSelfDescendants &&
HTMLElementConfigContentModelEnum.noFirstLevelSelfDescendants &&
stackTagNames[stackTagNames.length - 1] === tagName

@@ -120,0 +120,0 @@ ) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc