Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#344@trivial: Continues on CSSStyleDeclaration.
- Loading branch information
1 parent
2e3bfa5
commit 8ec7322
Showing
15 changed files
with
831 additions
and
643 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/happy-dom/src/css/declaration/utilities/CSSStyleDeclarationCSSParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* CSS parser. | ||
*/ | ||
export default class CSSStyleDeclarationCSSParser { | ||
/** | ||
* Class construtor. | ||
* | ||
* @param cssText CSS string. | ||
* @param callback Callback. | ||
*/ | ||
public static parse( | ||
cssText: string, | ||
callback: (name: string, value: string, important: boolean) => void | ||
): void { | ||
const parts = cssText.split(';'); | ||
|
||
for (const part of parts) { | ||
if (part) { | ||
const [name, value]: string[] = part.trim().split(':'); | ||
if (value) { | ||
const trimmedName = name.trim(); | ||
const trimmedValue = value.trim(); | ||
if (trimmedName && trimmedValue) { | ||
const important = trimmedValue.endsWith(' !important'); | ||
const valueWithoutImportant = trimmedValue.replace(' !important', ''); | ||
|
||
if (valueWithoutImportant) { | ||
callback(trimmedName, valueWithoutImportant, important); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.