happy-dom 6.0.4 → 7.0.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.
Potentially problematic release.
This version of happy-dom might be problematic. Click here for more details.
- package/lib/css/CSSParser.js +12 -6
- package/lib/css/CSSParser.js.map +1 -1
- package/lib/css/CSSRule.d.ts +15 -13
- package/lib/css/CSSRule.js +18 -13
- package/lib/css/CSSRule.js.map +1 -1
- package/lib/css/CSSRuleTypeEnum.d.ts +17 -0
- package/lib/css/CSSRuleTypeEnum.js +21 -0
- package/lib/css/CSSRuleTypeEnum.js.map +1 -0
- package/lib/css/CSSStyleSheet.d.ts +6 -16
- package/lib/css/CSSStyleSheet.js +11 -19
- package/lib/css/CSSStyleSheet.js.map +1 -1
- package/lib/css/declaration/AbstractCSSStyleDeclaration.d.ts +76 -0
- package/lib/css/declaration/AbstractCSSStyleDeclaration.js +182 -0
- package/lib/css/declaration/AbstractCSSStyleDeclaration.js.map +1 -0
- package/lib/css/declaration/CSSStyleDeclaration.d.ts +1194 -0
- package/lib/css/declaration/CSSStyleDeclaration.js +3566 -0
- package/lib/css/declaration/CSSStyleDeclaration.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.d.ts +12 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.js +34 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationCSSParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.d.ts +131 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.js +133 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.d.ts +40 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.js +42 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.d.ts +49 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js +244 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationElementStyle.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.d.ts +167 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.js +537 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.d.ts +65 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.js +565 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertyManager.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.d.ts +809 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.js +2303 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.js.map +1 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.d.ts +127 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.js +411 -0
- package/lib/css/declaration/utilities/CSSStyleDeclarationValueParser.js.map +1 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.d.ts +4 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.js +3 -0
- package/lib/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.js.map +1 -0
- package/lib/css/rules/CSSContainerRule.d.ts +15 -0
- package/lib/css/rules/CSSContainerRule.js +31 -0
- package/lib/css/rules/CSSContainerRule.js.map +1 -0
- package/lib/css/rules/CSSFontFaceRule.d.ts +10 -3
- package/lib/css/rules/CSSFontFaceRule.js +16 -0
- package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframeRule.d.ts +10 -3
- package/lib/css/rules/CSSKeyframeRule.js +16 -0
- package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframesRule.d.ts +1 -1
- package/lib/css/rules/CSSKeyframesRule.js +1 -1
- package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
- package/lib/css/rules/CSSMediaRule.d.ts +1 -1
- package/lib/css/rules/CSSStyleRule.d.ts +10 -3
- package/lib/css/rules/CSSStyleRule.js +16 -0
- package/lib/css/rules/CSSStyleRule.js.map +1 -1
- package/lib/event/Event.d.ts +2 -3
- package/lib/event/Event.js.map +1 -1
- package/lib/event/events/IMediaQueryListInit.d.ts +5 -0
- package/lib/event/events/IMediaQueryListInit.js +3 -0
- package/lib/event/events/IMediaQueryListInit.js.map +1 -0
- package/lib/event/events/MediaQueryListEvent.d.ts +16 -0
- package/lib/event/events/MediaQueryListEvent.js +28 -0
- package/lib/event/events/MediaQueryListEvent.js.map +1 -0
- package/lib/exception/DOMException.js +5 -3
- package/lib/exception/DOMException.js.map +1 -1
- package/lib/exception/DOMExceptionNameEnum.d.ts +2 -1
- package/lib/exception/DOMExceptionNameEnum.js +1 -0
- package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
- package/lib/file/Blob.d.ts +9 -0
- package/lib/file/Blob.js +14 -0
- package/lib/file/Blob.js.map +1 -1
- package/lib/index.d.ts +9 -2
- package/lib/index.js +16 -2
- package/lib/index.js.map +1 -1
- package/lib/match-media/MediaQueryList.d.ts +19 -8
- package/lib/match-media/MediaQueryList.js +56 -13
- package/lib/match-media/MediaQueryList.js.map +1 -1
- package/lib/{attribute → nodes/attr}/Attr.d.ts +8 -7
- package/lib/{attribute → nodes/attr}/Attr.js +12 -5
- package/lib/nodes/attr/Attr.js.map +1 -0
- package/lib/nodes/attr/IAttr.d.ts +14 -0
- package/lib/nodes/attr/IAttr.js +3 -0
- package/lib/nodes/attr/IAttr.js.map +1 -0
- package/lib/nodes/child-node/ChildNodeUtility.js +2 -1
- package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +4 -4
- package/lib/nodes/document/Document.js +5 -8
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +3 -3
- package/lib/nodes/element/Element.d.ts +11 -9
- package/lib/nodes/element/Element.js +2 -1
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/IElement.d.ts +10 -8
- package/lib/nodes/html-element/HTMLElement.d.ts +21 -5
- package/lib/nodes/html-element/HTMLElement.js +74 -11
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-element/IHTMLElement.d.ts +5 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.d.ts +2 -2
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.d.ts +2 -2
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.js +1 -1
- package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -1
- package/lib/nodes/html-style-element/HTMLStyleElement.js +1 -1
- package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
- package/lib/nodes/node/INode.d.ts +2 -0
- package/lib/nodes/node/Node.d.ts +5 -1
- package/lib/nodes/node/Node.js +7 -1
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeTypeEnum.d.ts +2 -0
- package/lib/nodes/node/NodeTypeEnum.js +2 -0
- package/lib/nodes/node/NodeTypeEnum.js.map +1 -1
- package/lib/nodes/svg-element/ISVGElement.d.ts +1 -1
- package/lib/nodes/svg-element/SVGElement.d.ts +4 -4
- package/lib/nodes/svg-element/SVGElement.js +2 -2
- package/lib/nodes/svg-element/SVGElement.js.map +1 -1
- package/lib/window/IWindow.d.ts +23 -3
- package/lib/window/Window.d.ts +35 -6
- package/lib/window/Window.js +58 -23
- package/lib/window/Window.js.map +1 -1
- package/package.json +2 -2
- package/src/css/CSSParser.ts +14 -6
- package/src/css/CSSRule.ts +15 -13
- package/src/css/CSSRuleTypeEnum.ts +18 -0
- package/src/css/CSSStyleSheet.ts +12 -22
- package/src/css/declaration/AbstractCSSStyleDeclaration.ts +202 -0
- package/src/css/declaration/CSSStyleDeclaration.ts +4743 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationCSSParser.ts +35 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementDefaultCSS.ts +130 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementInheritedProperties.ts +39 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationElementStyle.ts +282 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertyGetParser.ts +743 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertyManager.ts +592 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationPropertySetParser.ts +3026 -0
- package/src/css/declaration/utilities/CSSStyleDeclarationValueParser.ts +437 -0
- package/src/css/declaration/utilities/ICSSStyleDeclarationPropertyValue.ts +4 -0
- package/src/css/rules/CSSContainerRule.ts +23 -0
- package/src/css/rules/CSSFontFaceRule.ts +17 -2
- package/src/css/rules/CSSKeyframeRule.ts +17 -2
- package/src/css/rules/CSSKeyframesRule.ts +1 -1
- package/src/css/rules/CSSStyleRule.ts +17 -2
- package/src/event/Event.ts +2 -3
- package/src/event/events/IMediaQueryListInit.ts +6 -0
- package/src/event/events/MediaQueryListEvent.ts +25 -0
- package/src/exception/DOMException.ts +3 -3
- package/src/exception/DOMExceptionNameEnum.ts +2 -1
- package/src/file/Blob.ts +16 -0
- package/src/index.ts +15 -1
- package/src/match-media/MediaQueryList.ts +63 -10
- package/src/{attribute → nodes/attr}/Attr.ts +11 -8
- package/src/nodes/attr/IAttr.ts +15 -0
- package/src/nodes/child-node/ChildNodeUtility.ts +2 -1
- package/src/nodes/document/Document.ts +8 -10
- package/src/nodes/document/IDocument.ts +3 -3
- package/src/nodes/element/Element.ts +13 -10
- package/src/nodes/element/IElement.ts +8 -8
- package/src/nodes/html-element/HTMLElement.ts +94 -16
- package/src/nodes/html-element/IHTMLElement.ts +3 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +2 -2
- package/src/nodes/html-script-element/HTMLScriptElement.ts +2 -2
- package/src/nodes/html-select-element/HTMLSelectElement.ts +1 -1
- package/src/nodes/html-style-element/HTMLStyleElement.ts +1 -1
- package/src/nodes/node/INode.ts +2 -0
- package/src/nodes/node/Node.ts +7 -1
- package/src/nodes/node/NodeTypeEnum.ts +2 -0
- package/src/nodes/svg-element/ISVGElement.ts +1 -1
- package/src/nodes/svg-element/SVGElement.ts +5 -5
- package/src/window/IWindow.ts +23 -3
- package/src/window/Window.ts +51 -11
- package/lib/attribute/Attr.js.map +0 -1
- package/lib/css/CSSStyleDeclaration.d.ts +0 -3017
- package/lib/css/CSSStyleDeclaration.js +0 -4643
- package/lib/css/CSSStyleDeclaration.js.map +0 -1
- package/src/css/CSSStyleDeclaration.ts +0 -5026
package/src/css/CSSRule.ts
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
import CSSStyleSheet from './CSSStyleSheet';
|
2
|
+
import CSSRuleTypeEnum from './CSSRuleTypeEnum';
|
2
3
|
|
3
4
|
/**
|
4
5
|
* CSSRule interface.
|
5
6
|
*/
|
6
7
|
export default class CSSRule {
|
7
|
-
public static
|
8
|
-
public static
|
9
|
-
public static
|
10
|
-
public static
|
11
|
-
public static
|
12
|
-
public static
|
13
|
-
public static
|
14
|
-
public static
|
15
|
-
public static
|
16
|
-
public static
|
17
|
-
public static
|
18
|
-
public static
|
19
|
-
public static
|
8
|
+
public static CONTAINER_RULE = CSSRuleTypeEnum.containerRule;
|
9
|
+
public static STYLE_RULE = CSSRuleTypeEnum.styleRule;
|
10
|
+
public static IMPORT_RULE = CSSRuleTypeEnum.importRule;
|
11
|
+
public static MEDIA_RULE = CSSRuleTypeEnum.mediaRule;
|
12
|
+
public static FONT_FACE_RULE = CSSRuleTypeEnum.fontFaceRule;
|
13
|
+
public static PAGE_RULE = CSSRuleTypeEnum.pageRule;
|
14
|
+
public static KEYFRAMES_RULE = CSSRuleTypeEnum.keyframesRule;
|
15
|
+
public static KEYFRAME_RULE = CSSRuleTypeEnum.keyframeRule;
|
16
|
+
public static NAMESPACE_RULE = CSSRuleTypeEnum.namespaceRule;
|
17
|
+
public static COUNTER_STYLE_RULE = CSSRuleTypeEnum.counterStyleRule;
|
18
|
+
public static SUPPORTS_RULE = CSSRuleTypeEnum.supportsRule;
|
19
|
+
public static DOCUMENT_RULE = CSSRuleTypeEnum.documentRule;
|
20
|
+
public static FONT_FEATURE_VALUES_RULE = CSSRuleTypeEnum.fontFeatureValuesRule;
|
21
|
+
public static REGION_STYLE_RULE = CSSRuleTypeEnum.regionStyleRule;
|
20
22
|
|
21
23
|
public parentRule: CSSRule = null;
|
22
24
|
public parentStyleSheet: CSSStyleSheet = null;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
enum CSSRuleTypeEnum {
|
2
|
+
containerRule = 0,
|
3
|
+
styleRule = 1,
|
4
|
+
importRule = 3,
|
5
|
+
mediaRule = 4,
|
6
|
+
fontFaceRule = 5,
|
7
|
+
pageRule = 6,
|
8
|
+
keyframesRule = 7,
|
9
|
+
keyframeRule = 8,
|
10
|
+
namespaceRule = 10,
|
11
|
+
counterStyleRule = 11,
|
12
|
+
supportsRule = 12,
|
13
|
+
documentRule = 13,
|
14
|
+
fontFeatureValuesRule = 14,
|
15
|
+
regionStyleRule = 16
|
16
|
+
}
|
17
|
+
|
18
|
+
export default CSSRuleTypeEnum;
|
package/src/css/CSSStyleSheet.ts
CHANGED
@@ -5,7 +5,7 @@ import CSSRule from './CSSRule';
|
|
5
5
|
import MediaList from './MediaList';
|
6
6
|
|
7
7
|
/**
|
8
|
-
*
|
8
|
+
* CSS StyleSheet.
|
9
9
|
*
|
10
10
|
* Reference:
|
11
11
|
* https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet.
|
@@ -16,20 +16,16 @@ export default class CSSStyleSheet {
|
|
16
16
|
public namespaceURI: string = null;
|
17
17
|
public readonly cssRules: CSSRule[] = [];
|
18
18
|
|
19
|
-
//
|
20
|
-
// https://wicg.github.io/construct-stylesheets/
|
21
|
-
// TODO: Not fully implemented.
|
19
|
+
// TODO: MediaList is not fully implemented.
|
22
20
|
public media: MediaList | string;
|
23
21
|
public title: string;
|
24
22
|
public alternate: boolean;
|
25
23
|
public disabled: boolean;
|
24
|
+
private _currentText: string = null;
|
26
25
|
|
27
26
|
/**
|
28
27
|
* Constructor.
|
29
28
|
*
|
30
|
-
* Constructable Stylesheets is a new feature that only Blink supports:
|
31
|
-
* https://wicg.github.io/construct-stylesheets/.
|
32
|
-
*
|
33
29
|
* @param [options] Options.
|
34
30
|
* @param [options.media] Media.
|
35
31
|
* @param [options.title] Title.
|
@@ -51,9 +47,7 @@ export default class CSSStyleSheet {
|
|
51
47
|
/**
|
52
48
|
* Inserts a rule.
|
53
49
|
*
|
54
|
-
*
|
55
|
-
* https://wicg.github.io/construct-stylesheets/.
|
56
|
-
*
|
50
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule
|
57
51
|
* @param rule Rule.
|
58
52
|
* @param [index] Index.
|
59
53
|
* @returns The newly inserterted rule's index.
|
@@ -79,8 +73,7 @@ export default class CSSStyleSheet {
|
|
79
73
|
DOMExceptionNameEnum.indexSizeError
|
80
74
|
);
|
81
75
|
}
|
82
|
-
this.cssRules.splice(index, 0);
|
83
|
-
this.cssRules.push(rules[0]);
|
76
|
+
this.cssRules.splice(index, 0, rules[0]);
|
84
77
|
return index;
|
85
78
|
}
|
86
79
|
|
@@ -94,9 +87,7 @@ export default class CSSStyleSheet {
|
|
94
87
|
/**
|
95
88
|
* Removes a rule.
|
96
89
|
*
|
97
|
-
*
|
98
|
-
* https://wicg.github.io/construct-stylesheets/.
|
99
|
-
*
|
90
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/deleteRule
|
100
91
|
* @param index Index.
|
101
92
|
*/
|
102
93
|
public deleteRule(index: number): void {
|
@@ -106,9 +97,7 @@ export default class CSSStyleSheet {
|
|
106
97
|
/**
|
107
98
|
* Replaces all CSS rules.
|
108
99
|
*
|
109
|
-
*
|
110
|
-
* https://wicg.github.io/construct-stylesheets/.
|
111
|
-
*
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replace
|
112
101
|
* @param text CSS text.
|
113
102
|
* @returns Promise.
|
114
103
|
*/
|
@@ -119,12 +108,13 @@ export default class CSSStyleSheet {
|
|
119
108
|
/**
|
120
109
|
* Replaces all CSS rules.
|
121
110
|
*
|
122
|
-
*
|
123
|
-
* https://wicg.github.io/construct-stylesheets/.
|
124
|
-
*
|
111
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/replaceSync
|
125
112
|
* @param text CSS text.
|
126
113
|
*/
|
127
114
|
public replaceSync(text: string): void {
|
128
|
-
(
|
115
|
+
if (this._currentText !== text) {
|
116
|
+
this._currentText = text;
|
117
|
+
(<CSSRule[]>this.cssRules) = CSSParser.parseFromString(this, text);
|
118
|
+
}
|
129
119
|
}
|
130
120
|
}
|
@@ -0,0 +1,202 @@
|
|
1
|
+
import IElement from '../../nodes/element/IElement';
|
2
|
+
import Attr from '../../nodes/attr/Attr';
|
3
|
+
import CSSRule from '../CSSRule';
|
4
|
+
import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum';
|
5
|
+
import DOMException from '../../exception/DOMException';
|
6
|
+
import CSSStyleDeclarationElementStyle from './utilities/CSSStyleDeclarationElementStyle';
|
7
|
+
import CSSStyleDeclarationPropertyManager from './utilities/CSSStyleDeclarationPropertyManager';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* CSS Style Declaration.
|
11
|
+
*/
|
12
|
+
export default abstract class AbstractCSSStyleDeclaration {
|
13
|
+
public readonly parentRule: CSSRule = null;
|
14
|
+
protected _style: CSSStyleDeclarationPropertyManager = null;
|
15
|
+
protected _ownerElement: IElement;
|
16
|
+
protected _computed: boolean;
|
17
|
+
protected _elementStyle: CSSStyleDeclarationElementStyle = null;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Constructor.
|
21
|
+
*
|
22
|
+
* @param [ownerElement] Computed style element.
|
23
|
+
* @param [computed] Computed.
|
24
|
+
*/
|
25
|
+
constructor(ownerElement: IElement = null, computed = false) {
|
26
|
+
this._style = !ownerElement ? new CSSStyleDeclarationPropertyManager() : null;
|
27
|
+
this._ownerElement = ownerElement;
|
28
|
+
this._computed = ownerElement ? computed : false;
|
29
|
+
this._elementStyle = ownerElement
|
30
|
+
? new CSSStyleDeclarationElementStyle(ownerElement, this._computed)
|
31
|
+
: null;
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Returns length.
|
36
|
+
*
|
37
|
+
* @returns Length.
|
38
|
+
*/
|
39
|
+
public get length(): number {
|
40
|
+
if (this._ownerElement) {
|
41
|
+
const style = this._elementStyle.getElementStyle();
|
42
|
+
return style.size();
|
43
|
+
}
|
44
|
+
|
45
|
+
return this._style.size();
|
46
|
+
}
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Returns the style decleration as a CSS text.
|
50
|
+
*
|
51
|
+
* @returns CSS text.
|
52
|
+
*/
|
53
|
+
public get cssText(): string {
|
54
|
+
if (this._ownerElement) {
|
55
|
+
if (this._computed) {
|
56
|
+
return '';
|
57
|
+
}
|
58
|
+
|
59
|
+
return this._elementStyle.getElementStyle().toString();
|
60
|
+
}
|
61
|
+
|
62
|
+
return this._style.toString();
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Sets CSS text.
|
67
|
+
*
|
68
|
+
* @param cssText CSS text.
|
69
|
+
*/
|
70
|
+
public set cssText(cssText: string) {
|
71
|
+
if (this._computed) {
|
72
|
+
throw new DOMException(
|
73
|
+
`Failed to execute 'cssText' on 'CSSStyleDeclaration': These styles are computed, and the properties are therefore read-only.`,
|
74
|
+
DOMExceptionNameEnum.domException
|
75
|
+
);
|
76
|
+
}
|
77
|
+
|
78
|
+
if (this._ownerElement) {
|
79
|
+
const style = new CSSStyleDeclarationPropertyManager({ cssText });
|
80
|
+
if (!style.size()) {
|
81
|
+
delete this._ownerElement['_attributes']['style'];
|
82
|
+
} else {
|
83
|
+
if (!this._ownerElement['_attributes']['style']) {
|
84
|
+
Attr._ownerDocument = this._ownerElement.ownerDocument;
|
85
|
+
this._ownerElement['_attributes']['style'] = new Attr();
|
86
|
+
this._ownerElement['_attributes']['style'].name = 'style';
|
87
|
+
}
|
88
|
+
|
89
|
+
this._ownerElement['_attributes']['style'].value = style.toString();
|
90
|
+
}
|
91
|
+
} else {
|
92
|
+
this._style = new CSSStyleDeclarationPropertyManager({ cssText });
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Returns item.
|
98
|
+
*
|
99
|
+
* @param index Index.
|
100
|
+
* @returns Item.
|
101
|
+
*/
|
102
|
+
public item(index: number): string {
|
103
|
+
if (this._ownerElement) {
|
104
|
+
return this._elementStyle.getElementStyle().item(index);
|
105
|
+
}
|
106
|
+
return this._style.item(index);
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Set a property.
|
111
|
+
*
|
112
|
+
* @param name Property name.
|
113
|
+
* @param value Value. Must not contain "!important" as that should be set using the priority parameter.
|
114
|
+
* @param [priority] Can be "important", or an empty string.
|
115
|
+
*/
|
116
|
+
public setProperty(name: string, value: string, priority?: 'important' | '' | undefined): void {
|
117
|
+
if (this._computed) {
|
118
|
+
throw new DOMException(
|
119
|
+
`Failed to execute 'setProperty' on 'CSSStyleDeclaration': These styles are computed, and therefore the '${name}' property is read-only.`,
|
120
|
+
DOMExceptionNameEnum.domException
|
121
|
+
);
|
122
|
+
}
|
123
|
+
|
124
|
+
if (priority !== '' && priority !== undefined && priority !== 'important') {
|
125
|
+
return;
|
126
|
+
}
|
127
|
+
|
128
|
+
if (!value) {
|
129
|
+
this.removeProperty(name);
|
130
|
+
} else if (this._ownerElement) {
|
131
|
+
if (!this._ownerElement['_attributes']['style']) {
|
132
|
+
Attr._ownerDocument = this._ownerElement.ownerDocument;
|
133
|
+
this._ownerElement['_attributes']['style'] = new Attr();
|
134
|
+
this._ownerElement['_attributes']['style'].name = 'style';
|
135
|
+
}
|
136
|
+
|
137
|
+
const style = this._elementStyle.getElementStyle();
|
138
|
+
style.set(name, value, !!priority);
|
139
|
+
|
140
|
+
this._ownerElement['_attributes']['style'].value = style.toString();
|
141
|
+
} else {
|
142
|
+
this._style.set(name, value, !!priority);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Removes a property.
|
148
|
+
*
|
149
|
+
* @param name Property name in kebab case.
|
150
|
+
* @param value Value. Must not contain "!important" as that should be set using the priority parameter.
|
151
|
+
* @param [priority] Can be "important", or an empty string.
|
152
|
+
*/
|
153
|
+
public removeProperty(name: string): void {
|
154
|
+
if (this._computed) {
|
155
|
+
throw new DOMException(
|
156
|
+
`Failed to execute 'removeProperty' on 'CSSStyleDeclaration': These styles are computed, and therefore the '${name}' property is read-only.`,
|
157
|
+
DOMExceptionNameEnum.domException
|
158
|
+
);
|
159
|
+
}
|
160
|
+
|
161
|
+
if (this._ownerElement) {
|
162
|
+
const style = this._elementStyle.getElementStyle();
|
163
|
+
style.remove(name);
|
164
|
+
const newCSSText = style.toString();
|
165
|
+
if (newCSSText) {
|
166
|
+
this._ownerElement['_attributes']['style'].value = newCSSText;
|
167
|
+
} else {
|
168
|
+
delete this._ownerElement['_attributes']['style'];
|
169
|
+
}
|
170
|
+
} else {
|
171
|
+
this._style.remove(name);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Returns a property.
|
177
|
+
*
|
178
|
+
* @param name Property name in kebab case.
|
179
|
+
* @returns Property value.
|
180
|
+
*/
|
181
|
+
public getPropertyValue(name: string): string {
|
182
|
+
if (this._ownerElement) {
|
183
|
+
const style = this._elementStyle.getElementStyle();
|
184
|
+
return style.get(name)?.value || '';
|
185
|
+
}
|
186
|
+
return this._style.get(name)?.value || '';
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Returns a property.
|
191
|
+
*
|
192
|
+
* @param name Property name in kebab case.
|
193
|
+
* @returns "important" if set to be important.
|
194
|
+
*/
|
195
|
+
public getPropertyPriority(name: string): string {
|
196
|
+
if (this._ownerElement) {
|
197
|
+
const style = this._elementStyle.getElementStyle();
|
198
|
+
return style.get(name)?.important ? 'important' : '';
|
199
|
+
}
|
200
|
+
return this._style.get(name)?.important ? 'important' : '';
|
201
|
+
}
|
202
|
+
}
|