happy-dom 2.40.2 → 2.42.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.

Files changed (43) hide show
  1. package/lib/css/CSSStyleDeclaration.d.ts +12 -12
  2. package/lib/css/CSSStyleDeclaration.js +13 -4
  3. package/lib/css/CSSStyleDeclaration.js.map +1 -1
  4. package/lib/index.d.ts +2 -1
  5. package/lib/index.js +3 -1
  6. package/lib/index.js.map +1 -1
  7. package/lib/nodes/document/Document.d.ts +13 -0
  8. package/lib/nodes/document/Document.js +21 -0
  9. package/lib/nodes/document/Document.js.map +1 -1
  10. package/lib/nodes/document/IDocument.d.ts +7 -0
  11. package/lib/nodes/element/DOMTokenList.d.ts +101 -0
  12. package/lib/nodes/element/DOMTokenList.js +205 -0
  13. package/lib/nodes/element/DOMTokenList.js.map +1 -0
  14. package/lib/nodes/element/Element.d.ts +5 -5
  15. package/lib/nodes/element/Element.js +3 -3
  16. package/lib/nodes/element/Element.js.map +1 -1
  17. package/lib/nodes/element/IDOMTokenList.d.ts +16 -0
  18. package/lib/nodes/element/IDOMTokenList.js +3 -0
  19. package/lib/nodes/element/IDOMTokenList.js.map +1 -0
  20. package/lib/nodes/element/IElement.d.ts +2 -2
  21. package/lib/selection/Selection.d.ts +95 -0
  22. package/lib/selection/Selection.js +127 -0
  23. package/lib/selection/Selection.js.map +1 -0
  24. package/lib/window/IWindow.d.ts +3 -0
  25. package/lib/window/Window.d.ts +3 -0
  26. package/lib/window/Window.js +3 -0
  27. package/lib/window/Window.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/css/CSSStyleDeclaration.ts +41 -36
  30. package/src/index.ts +3 -1
  31. package/src/nodes/document/Document.ts +19 -0
  32. package/src/nodes/document/IDocument.ts +8 -0
  33. package/src/nodes/element/DOMTokenList.ts +201 -0
  34. package/src/nodes/element/Element.ts +4 -3
  35. package/src/nodes/element/IDOMTokenList.ts +17 -0
  36. package/src/nodes/element/IElement.ts +2 -2
  37. package/src/selection/Selection.ts +140 -0
  38. package/src/window/IWindow.ts +3 -0
  39. package/src/window/Window.ts +3 -0
  40. package/lib/nodes/element/ClassList.d.ts +0 -40
  41. package/lib/nodes/element/ClassList.js +0 -99
  42. package/lib/nodes/element/ClassList.js.map +0 -1
  43. package/src/nodes/element/ClassList.ts +0 -92
@@ -0,0 +1,201 @@
1
+ import DOMException from '../../exception/DOMException';
2
+ import Element from './Element';
3
+ import IDOMTokenList from './IDOMTokenList';
4
+
5
+ /**
6
+ * DOM Token List.
7
+ */
8
+ export default class DOMTokenList implements IDOMTokenList<string> {
9
+ private _ownerElement: Element;
10
+ private _list: string[];
11
+ /**
12
+ * Adds class names.
13
+ *
14
+ * @param ownerElement Owner element.
15
+ */
16
+ constructor(ownerElement: Element) {
17
+ this._ownerElement = ownerElement;
18
+ }
19
+
20
+ /**
21
+ * Get ClassName.
22
+ *
23
+ * @param index Index.
24
+ * */
25
+ public item(index: number): string {
26
+ this._refreshListFromClass();
27
+ return index >= 0 && this._list[index] ? this._list[index] : null;
28
+ }
29
+
30
+ /**
31
+ * Replace Token.
32
+ *
33
+ * @param token Token.
34
+ * @param newToken NewToken.
35
+ */
36
+ public replace(token: string, newToken: string): boolean {
37
+ if (!this.contains(token)) {
38
+ return false;
39
+ }
40
+ const index = this._list.indexOf(token);
41
+ this._list[index] = newToken;
42
+ const value = this._list ? this._list.join(' ') : '';
43
+ this._ownerElement.setAttribute('class', value);
44
+ return true;
45
+ }
46
+
47
+ /**
48
+ * Supports.
49
+ *
50
+ * @param token Token.
51
+ */
52
+ public supports(token: string): boolean {
53
+ // TODO May IT IN ERROR.
54
+ throw new DOMException(
55
+ `Failed to execute '${token}' on 'DOMTokenList': DOMTokenList has no supported tokens.`,
56
+ 'TypeError'
57
+ );
58
+ }
59
+ /**
60
+ * Returns an iterator, allowing you to go through all values of the key/value pairs contained in this object.
61
+ *
62
+ *
63
+ */
64
+ public values(): IterableIterator<string> {
65
+ this._refreshListFromClass();
66
+ return this._list.values();
67
+ }
68
+ /**
69
+ * Returns an iterator, allowing you to go through all key/value pairs contained in this object.
70
+ *
71
+ *
72
+ */
73
+ public entries(): IterableIterator<[number, string]> {
74
+ this._refreshListFromClass();
75
+ return this._list.entries();
76
+ }
77
+ /**
78
+ * Executes a provided callback function once for each DOMTokenList element.
79
+ *
80
+ * @param callback
81
+ * @param thisArg
82
+ */
83
+ public forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void {
84
+ this._refreshListFromClass();
85
+ return this._list.forEach(callback, thisArg);
86
+ }
87
+ /**
88
+ * Returns an iterator, allowing you to go through all keys of the key/value pairs contained in this object.
89
+ *
90
+ */
91
+ public keys(): IterableIterator<number> {
92
+ this._refreshListFromClass();
93
+ return this._list.keys();
94
+ }
95
+
96
+ /**
97
+ * Adds class names.
98
+ *
99
+ * @param classNames Class names.
100
+ */
101
+ public add(...classNames: string[]): void {
102
+ this._refreshListFromClass();
103
+ for (const className of classNames) {
104
+ if (!this._list.includes(className)) {
105
+ if (className.includes(' ')) {
106
+ throw new DOMException(
107
+ `Failed to execute 'add' on 'DOMTokenList': The token provided ('${className}') contains HTML space characters, which are not valid in tokens.`
108
+ );
109
+ }
110
+ this._list.push(className);
111
+ }
112
+ }
113
+ this._list = Array.from(new Set(this._list));
114
+ const value = this._list ? this._list.join(' ') : '';
115
+ this._ownerElement.setAttribute('class', value);
116
+ }
117
+
118
+ /**
119
+ * Removes class names.
120
+ *
121
+ * @param classNames Class names.
122
+ */
123
+ public remove(...classNames: string[]): void {
124
+ this._refreshListFromClass();
125
+ for (const className of classNames) {
126
+ const index = this._list.indexOf(className);
127
+ if (index !== -1) {
128
+ this._list.splice(index, 1);
129
+ }
130
+ }
131
+ const value = this._list ? this._list.join(' ') : '';
132
+ this._ownerElement.setAttribute('class', value);
133
+ }
134
+
135
+ /**
136
+ * Check if the list contains a class.
137
+ *
138
+ * @param className Class name.
139
+ * @returns TRUE if it contains.
140
+ */
141
+ public contains(className: string): boolean {
142
+ this._refreshListFromClass();
143
+ return this._list.includes(className);
144
+ }
145
+
146
+ /**
147
+ * Toggle a class name.
148
+ *
149
+ * @param className A string representing the class name you want to toggle.
150
+ * @param force If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
151
+ * @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
152
+ */
153
+ public toggle(className: string, force?: boolean): boolean {
154
+ let shouldAdd: boolean;
155
+ if (force !== undefined) {
156
+ shouldAdd = force;
157
+ } else {
158
+ shouldAdd = !this.contains(className);
159
+ }
160
+
161
+ if (shouldAdd) {
162
+ this.add(className);
163
+ return true;
164
+ }
165
+
166
+ this.remove(className);
167
+ return false;
168
+ }
169
+
170
+ /**
171
+ * Refresh list from class.
172
+ */
173
+ private _refreshListFromClass(): void {
174
+ const attr = this._ownerElement.getAttribute('class');
175
+ this._list = attr ? Array.from(new Set(attr.split(' '))) : [];
176
+ }
177
+
178
+ /**
179
+ * Set Value.
180
+ */
181
+ public set value(value: string) {
182
+ this._ownerElement.setAttribute('class', value);
183
+ this._list = value ? Array.from(new Set(value.split(' '))) : [];
184
+ }
185
+
186
+ /**
187
+ * Get Value.
188
+ */
189
+ public get value(): string {
190
+ this._refreshListFromClass();
191
+ return this._list ? this._list.join(' ') : '';
192
+ }
193
+
194
+ /**
195
+ * Get Length.
196
+ */
197
+ public get length(): number {
198
+ this._refreshListFromClass();
199
+ return this._list.length;
200
+ }
201
+ }
@@ -3,7 +3,7 @@ import ShadowRoot from '../shadow-root/ShadowRoot';
3
3
  import Attr from '../../attribute/Attr';
4
4
  import DOMRect from './DOMRect';
5
5
  import Range from './Range';
6
- import ClassList from './ClassList';
6
+ import DOMTokenList from './DOMTokenList';
7
7
  import QuerySelector from '../../query-selector/QuerySelector';
8
8
  import SelectorItem from '../../query-selector/SelectorItem';
9
9
  import MutationRecord from '../../mutation-observer/MutationRecord';
@@ -36,11 +36,12 @@ export default class Element extends Node implements IElement {
36
36
  public tagName: string = null;
37
37
  public nodeType = Node.ELEMENT_NODE;
38
38
  public shadowRoot: IShadowRoot = null;
39
- public readonly classList = new ClassList(this);
39
+ public _attributes: { [k: string]: Attr } = {};
40
+ public readonly classList = new DOMTokenList(this);
40
41
  public scrollTop = 0;
41
42
  public scrollLeft = 0;
42
43
  public children: IHTMLCollection<IElement> = HTMLCollectionFactory.create();
43
- public _attributes: { [k: string]: Attr } = {};
44
+
44
45
  public readonly namespaceURI: string = null;
45
46
 
46
47
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * IDOMTokenList.
3
+ */
4
+ export default interface IDOMTokenList<T> {
5
+ item(index: number): string;
6
+ contains(token: string): boolean;
7
+ add(...tokens: string[]): void;
8
+ remove(...tokens: string[]): void;
9
+ toggle(token: string, force?: boolean): boolean;
10
+ replace(token: string, newToken: string): boolean;
11
+ supports(token: string): boolean;
12
+
13
+ values(): IterableIterator<T>;
14
+ entries(): IterableIterator<[number, T]>;
15
+ forEach(callback: (currentValue, currentIndex, listObj) => void, thisArg?: this): void;
16
+ keys(): IterableIterator<number>;
17
+ }
@@ -2,7 +2,7 @@ import IShadowRoot from '../shadow-root/IShadowRoot';
2
2
  import Attr from '../../attribute/Attr';
3
3
  import DOMRect from './DOMRect';
4
4
  import Range from './Range';
5
- import ClassList from './ClassList';
5
+ import DOMTokenList from './DOMTokenList';
6
6
  import INode from './../node/INode';
7
7
  import IChildNode from '../child-node/IChildNode';
8
8
  import IParentNode from '../parent-node/IParentNode';
@@ -16,7 +16,7 @@ export type TInsertAdjacentPositions = 'beforebegin' | 'afterbegin' | 'beforeend
16
16
  export default interface IElement extends IChildNode, INonDocumentTypeChildNode, IParentNode {
17
17
  readonly tagName: string;
18
18
  readonly shadowRoot: IShadowRoot;
19
- readonly classList: ClassList;
19
+ readonly classList: DOMTokenList;
20
20
  readonly namespaceURI: string;
21
21
  scrollTop: number;
22
22
  scrollLeft: number;
@@ -0,0 +1,140 @@
1
+ import INode from '../nodes/node/INode';
2
+
3
+ /**
4
+ * Selection.
5
+ *
6
+ * Reference:
7
+ * https://developer.mozilla.org/en-US/docs/Web/API/Selection.
8
+ */
9
+ export default class Selection {
10
+ public readonly anchorNode: INode = null;
11
+ public readonly anchorOffset: number = 0;
12
+ public readonly baseNode: INode = null;
13
+ public readonly baseOffset: number = 0;
14
+ public readonly extentNode: INode = null;
15
+ public readonly extentOffset: number = 0;
16
+ public readonly focusNode: INode = null;
17
+ public readonly focusOffset: number = 0;
18
+ public readonly isCollapsed: boolean = true;
19
+ public readonly rangeCount: number = 0;
20
+ public readonly type: string = 'None';
21
+
22
+ /**
23
+ * Adds a range.
24
+ *
25
+ * @param _range Range.
26
+ */
27
+ public addRange(_range: object): void {
28
+ // Do nothing.
29
+ }
30
+
31
+ /**
32
+ * Collapses the current selection to a single point.
33
+ *
34
+ * @param _node Node.
35
+ * @param _offset Offset.
36
+ */
37
+ public collapse(_node: INode, _offset?: number): void {
38
+ // Do nothing.
39
+ }
40
+
41
+ /**
42
+ * Collapses the selection to the end.
43
+ */
44
+ public collapseToEnd(): void {
45
+ // Do nothing.
46
+ }
47
+
48
+ /**
49
+ * Collapses the selection to the start.
50
+ */
51
+ public collapseToStart(): void {
52
+ // Do nothing.
53
+ }
54
+
55
+ /**
56
+ * Indicates whether a specified node is part of the selection.
57
+ *
58
+ * @param _node Node.
59
+ * @param _partialContainer Partial container.
60
+ * @returns Always returns "true" for now.
61
+ */
62
+ public containsNode(_node: INode, _partialContainer?: INode): boolean {
63
+ return true;
64
+ }
65
+
66
+ /**
67
+ * Deletes the selected text from the document's DOM.
68
+ */
69
+ public deleteFromDocument(): void {
70
+ // Do nothing.
71
+ }
72
+
73
+ /**
74
+ * Moves the focus of the selection to a specified point.
75
+ *
76
+ * @param _node Node.
77
+ * @param _offset Offset.
78
+ */
79
+ public extend(_node: INode, _offset?: number): void {
80
+ // Do nothing.
81
+ }
82
+
83
+ /**
84
+ * Moves the focus of the selection to a specified point.
85
+ *
86
+ * @param _index Index.
87
+ */
88
+ public getRangeAt(_index: number): object {
89
+ throw new Error('Not a valid index.');
90
+ }
91
+
92
+ /**
93
+ * Removes a range from a selection.
94
+ *
95
+ * @param _range Range.
96
+ */
97
+ public removeRange(_range: object): void {
98
+ // Do nothing.
99
+ }
100
+
101
+ /**
102
+ * Removes all ranges.
103
+ */
104
+ public removeAllRanges(): void {
105
+ // Do nothing.
106
+ }
107
+
108
+ /**
109
+ * Selects all children.
110
+ *
111
+ * @param _parentNode Parent node.
112
+ */
113
+ public selectAllChildren(_parentNode: INode): void {
114
+ // Do nothing.
115
+ }
116
+
117
+ /**
118
+ * Sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them.
119
+ *
120
+ * @param _anchorNode Anchor node.
121
+ * @param _anchorOffset Anchor offset.
122
+ * @param _focusNode Focus node.
123
+ * @param _focusOffset Focus offset.
124
+ */
125
+ public setBaseAndExtent(
126
+ _anchorNode: INode,
127
+ _anchorOffset: number,
128
+ _focusNode: INode,
129
+ _focusOffset: number
130
+ ): void {
131
+ // Do nothing.
132
+ }
133
+
134
+ /**
135
+ * Returns string currently being represented by the selection object.
136
+ */
137
+ public toString(): string {
138
+ return '';
139
+ }
140
+ }
@@ -68,6 +68,7 @@ import Window from './Window';
68
68
  import URLSearchParams from '../url-search-params/URLSearchParams';
69
69
  import HTMLCollection from '../nodes/element/HTMLCollection';
70
70
  import NodeList from '../nodes/node/NodeList';
71
+ import Selection from '../selection/Selection';
71
72
 
72
73
  /**
73
74
  * Window.
@@ -148,6 +149,7 @@ export default interface IWindow {
148
149
  readonly NodeList: typeof NodeList;
149
150
  readonly CSSUnitValue: typeof CSSUnitValue;
150
151
  readonly CSS: CSS;
152
+ readonly Selection: typeof Selection;
151
153
 
152
154
  // Events
153
155
  onload: (event: Event) => void;
@@ -164,6 +166,7 @@ export default interface IWindow {
164
166
  readonly top: IWindow;
165
167
  readonly parent: IWindow;
166
168
  readonly window: IWindow;
169
+ readonly globalThis: IWindow;
167
170
  readonly screen: Screen;
168
171
  readonly innerWidth: number;
169
172
  readonly innerHeight: number;
@@ -73,6 +73,7 @@ import URLSearchParams from '../url-search-params/URLSearchParams';
73
73
  import HTMLCollection from '../nodes/element/HTMLCollection';
74
74
  import NodeList from '../nodes/node/NodeList';
75
75
  import MediaQueryList from '../match-media/MediaQueryList';
76
+ import Selection from '../selection/Selection';
76
77
  import * as PerfHooks from 'perf_hooks';
77
78
 
78
79
  const FETCH_RESPONSE_TYPE_METHODS = ['blob', 'json', 'text'];
@@ -160,6 +161,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
160
161
  public readonly NodeList = NodeList;
161
162
  public readonly MediaQueryList = MediaQueryList;
162
163
  public readonly CSSUnitValue = CSSUnitValue;
164
+ public readonly Selection = Selection;
163
165
 
164
166
  // Events
165
167
  public onload: (event: Event) => void = null;
@@ -176,6 +178,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
176
178
  public readonly top = this;
177
179
  public readonly parent = this;
178
180
  public readonly window = this;
181
+ public readonly globalThis = this;
179
182
  public readonly screen = new Screen();
180
183
  public readonly innerWidth = 1024;
181
184
  public readonly innerHeight = 768;
@@ -1,40 +0,0 @@
1
- import Element from './Element';
2
- /**
3
- * Class list.
4
- */
5
- export default class ClassList {
6
- private _ownerElement;
7
- /**
8
- * Adds class names.
9
- *
10
- * @param ownerElement Owner element.
11
- */
12
- constructor(ownerElement: Element);
13
- /**
14
- * Adds class names.
15
- *
16
- * @param classNames Class names.
17
- */
18
- add(...classNames: string[]): void;
19
- /**
20
- * Adds class names.
21
- *
22
- * @param classNames Class names.
23
- */
24
- remove(...classNames: string[]): void;
25
- /**
26
- * Check if the list contains a class.
27
- *
28
- * @param className Class name.
29
- * @returns TRUE if it contains.
30
- */
31
- contains(className: string): boolean;
32
- /**
33
- * Toggle a class name.
34
- *
35
- * @param className A string representing the class name you want to toggle.
36
- * @param force If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
37
- * @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
38
- */
39
- toggle(className: string, force?: boolean): boolean;
40
- }
@@ -1,99 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- var DOMException_1 = __importDefault(require("../../exception/DOMException"));
7
- /**
8
- * Class list.
9
- */
10
- var ClassList = /** @class */ (function () {
11
- /**
12
- * Adds class names.
13
- *
14
- * @param ownerElement Owner element.
15
- */
16
- function ClassList(ownerElement) {
17
- this._ownerElement = ownerElement;
18
- }
19
- /**
20
- * Adds class names.
21
- *
22
- * @param classNames Class names.
23
- */
24
- ClassList.prototype.add = function () {
25
- var classNames = [];
26
- for (var _i = 0; _i < arguments.length; _i++) {
27
- classNames[_i] = arguments[_i];
28
- }
29
- var attr = this._ownerElement.getAttribute('class');
30
- var list = attr ? attr.split(' ') : [];
31
- for (var _a = 0, classNames_1 = classNames; _a < classNames_1.length; _a++) {
32
- var className = classNames_1[_a];
33
- if (!list.includes(className)) {
34
- if (className.includes(' ')) {
35
- throw new DOMException_1.default("Failed to execute 'add' on 'DOMTokenList': The token provided ('".concat(className, "') contains HTML space characters, which are not valid in tokens."));
36
- }
37
- list.push(className);
38
- }
39
- }
40
- this._ownerElement.setAttribute('class', list.join(' '));
41
- };
42
- /**
43
- * Adds class names.
44
- *
45
- * @param classNames Class names.
46
- */
47
- ClassList.prototype.remove = function () {
48
- var classNames = [];
49
- for (var _i = 0; _i < arguments.length; _i++) {
50
- classNames[_i] = arguments[_i];
51
- }
52
- var attr = this._ownerElement.getAttribute('class');
53
- var list = attr ? attr.split(' ') : [];
54
- for (var _a = 0, classNames_2 = classNames; _a < classNames_2.length; _a++) {
55
- var className = classNames_2[_a];
56
- var index = list.indexOf(className);
57
- if (index !== -1) {
58
- list.splice(index, 1);
59
- }
60
- }
61
- this._ownerElement.setAttribute('class', list.join(' '));
62
- };
63
- /**
64
- * Check if the list contains a class.
65
- *
66
- * @param className Class name.
67
- * @returns TRUE if it contains.
68
- */
69
- ClassList.prototype.contains = function (className) {
70
- var attr = this._ownerElement.getAttribute('class');
71
- var list = attr ? attr.split(' ') : [];
72
- return list.includes(className);
73
- };
74
- /**
75
- * Toggle a class name.
76
- *
77
- * @param className A string representing the class name you want to toggle.
78
- * @param force If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
79
- * @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
80
- */
81
- ClassList.prototype.toggle = function (className, force) {
82
- var shouldAdd;
83
- if (force !== undefined) {
84
- shouldAdd = force;
85
- }
86
- else {
87
- shouldAdd = !this.contains(className);
88
- }
89
- if (shouldAdd) {
90
- this.add(className);
91
- return true;
92
- }
93
- this.remove(className);
94
- return false;
95
- };
96
- return ClassList;
97
- }());
98
- exports.default = ClassList;
99
- //# sourceMappingURL=ClassList.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ClassList.js","sourceRoot":"","sources":["../../../src/nodes/element/ClassList.ts"],"names":[],"mappings":";;;;;AAAA,8EAAwD;AAGxD;;GAEG;AACH;IAGC;;;;OAIG;IACH,mBAAY,YAAqB;QAChC,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,uBAAG,GAAV;QAAW,oBAAuB;aAAvB,UAAuB,EAAvB,qBAAuB,EAAvB,IAAuB;YAAvB,+BAAuB;;QACjC,IAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtD,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,KAAwB,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EAAE;YAA/B,IAAM,SAAS,mBAAA;YACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC9B,IAAI,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAC5B,MAAM,IAAI,sBAAY,CACrB,0EAAmE,SAAS,sEAAmE,CAC/I,CAAC;iBACF;gBACD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;aACrB;SACD;QACD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACI,0BAAM,GAAb;QAAc,oBAAuB;aAAvB,UAAuB,EAAvB,qBAAuB,EAAvB,IAAuB;YAAvB,+BAAuB;;QACpC,IAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtD,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,KAAwB,UAAU,EAAV,yBAAU,EAAV,wBAAU,EAAV,IAAU,EAAE;YAA/B,IAAM,SAAS,mBAAA;YACnB,IAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YACtC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;gBACjB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;aACtB;SACD;QACD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;OAKG;IACI,4BAAQ,GAAf,UAAgB,SAAiB;QAChC,IAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QACtD,IAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;IAED;;;;;;OAMG;IACI,0BAAM,GAAb,UAAc,SAAiB,EAAE,KAAe;QAC/C,IAAI,SAAkB,CAAC;QACvB,IAAI,KAAK,KAAK,SAAS,EAAE;YACxB,SAAS,GAAG,KAAK,CAAC;SAClB;aAAM;YACN,SAAS,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;SACtC;QAED,IAAI,SAAS,EAAE;YACd,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACpB,OAAO,IAAI,CAAC;SACZ;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;IACd,CAAC;IACF,gBAAC;AAAD,CAAC,AArFD,IAqFC"}
@@ -1,92 +0,0 @@
1
- import DOMException from '../../exception/DOMException';
2
- import Element from './Element';
3
-
4
- /**
5
- * Class list.
6
- */
7
- export default class ClassList {
8
- private _ownerElement: Element;
9
-
10
- /**
11
- * Adds class names.
12
- *
13
- * @param ownerElement Owner element.
14
- */
15
- constructor(ownerElement: Element) {
16
- this._ownerElement = ownerElement;
17
- }
18
-
19
- /**
20
- * Adds class names.
21
- *
22
- * @param classNames Class names.
23
- */
24
- public add(...classNames: string[]): void {
25
- const attr = this._ownerElement.getAttribute('class');
26
- const list = attr ? attr.split(' ') : [];
27
- for (const className of classNames) {
28
- if (!list.includes(className)) {
29
- if (className.includes(' ')) {
30
- throw new DOMException(
31
- `Failed to execute 'add' on 'DOMTokenList': The token provided ('${className}') contains HTML space characters, which are not valid in tokens.`
32
- );
33
- }
34
- list.push(className);
35
- }
36
- }
37
- this._ownerElement.setAttribute('class', list.join(' '));
38
- }
39
-
40
- /**
41
- * Adds class names.
42
- *
43
- * @param classNames Class names.
44
- */
45
- public remove(...classNames: string[]): void {
46
- const attr = this._ownerElement.getAttribute('class');
47
- const list = attr ? attr.split(' ') : [];
48
- for (const className of classNames) {
49
- const index = list.indexOf(className);
50
- if (index !== -1) {
51
- list.splice(index, 1);
52
- }
53
- }
54
- this._ownerElement.setAttribute('class', list.join(' '));
55
- }
56
-
57
- /**
58
- * Check if the list contains a class.
59
- *
60
- * @param className Class name.
61
- * @returns TRUE if it contains.
62
- */
63
- public contains(className: string): boolean {
64
- const attr = this._ownerElement.getAttribute('class');
65
- const list = attr ? attr.split(' ') : [];
66
- return list.includes(className);
67
- }
68
-
69
- /**
70
- * Toggle a class name.
71
- *
72
- * @param className A string representing the class name you want to toggle.
73
- * @param force If included, turns the toggle into a one way-only operation. If set to `false`, then class name will only be removed, but not added. If set to `true`, then class name will only be added, but not removed.
74
- * @returns A boolean value, `true` or `false`, indicating whether class name is in the list after the call or not.
75
- */
76
- public toggle(className: string, force?: boolean): boolean {
77
- let shouldAdd: boolean;
78
- if (force !== undefined) {
79
- shouldAdd = force;
80
- } else {
81
- shouldAdd = !this.contains(className);
82
- }
83
-
84
- if (shouldAdd) {
85
- this.add(className);
86
- return true;
87
- }
88
-
89
- this.remove(className);
90
- return false;
91
- }
92
- }