pseudo-dom 0.7.0 → 0.8.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/README.md +262 -236
- package/browser/pseudo-dom.js +628 -548
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +41 -67
- package/dist/classes/PseudoHTMLDocument.js +74 -144
- package/dist/classes/PseudoHTMLDocument.min.js +1 -1
- package/dist/factories/cssSelectAdapter.d.ts +23 -23
- package/dist/factories/cssSelectAdapter.js +87 -87
- package/dist/factories/query.d.ts +33 -33
- package/dist/factories/query.js +66 -66
- package/dist/functions/getElementById.d.ts +13 -0
- package/dist/functions/getElementById.js +33 -0
- package/dist/functions/getElementById.min.js +1 -0
- package/dist/interfaces/PseudoDocument.d.ts +25 -0
- package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -3
- package/dist/interfaces/PseudoElement.d.ts +702 -702
- package/dist/services/DocumentFragmentService.d.ts +21 -13
- package/dist/services/DocumentFragmentService.js +42 -24
- package/dist/services/DocumentFragmentService.min.js +1 -1
- package/dist/services/DocumentService.d.ts +28 -1
- package/dist/services/DocumentService.js +64 -15
- package/dist/services/DocumentService.min.js +1 -1
- package/dist/services/ElementService.d.ts +191 -191
- package/dist/services/ElementService.js +426 -426
- package/dist/services/HTMLCollectionService.d.ts +54 -54
- package/dist/services/HTMLCollectionService.js +92 -92
- package/dist/services/NodeService.d.ts +297 -297
- package/dist/services/NodeService.js +721 -721
- package/package.json +2 -2
- package/dist/classes.d.ts +0 -20
- package/dist/classes.js +0 -31
- package/dist/classes.min.js +0 -1
- package/dist/factories/generateNode.d.ts +0 -32
- package/dist/factories/generateNode.js +0 -85
- package/dist/factories/generateNode.min.js +0 -1
- package/dist/factories.d.ts +0 -11
- package/dist/factories.js +0 -27
- package/dist/factories.min.js +0 -1
- package/dist/functions.d.ts +0 -5
- package/dist/functions.js +0 -23
- package/dist/functions.min.js +0 -1
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { NodeService } from './NodeService';
|
|
2
|
-
import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
get
|
|
13
|
-
|
|
1
|
+
import { NodeService } from './NodeService';
|
|
2
|
+
import { PseudoDocumentFragment } from '../interfaces/PseudoDocumentFragment';
|
|
3
|
+
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
4
|
+
/**
|
|
5
|
+
* Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
|
|
6
|
+
* not part of a tree, when it is inserted its children are moved into the tree instead.
|
|
7
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
8
|
+
* @class
|
|
9
|
+
* @augments NodeService
|
|
10
|
+
*/
|
|
11
|
+
export declare class DocumentFragmentService extends NodeService implements PseudoDocumentFragment {
|
|
12
|
+
get nodeName(): string;
|
|
13
|
+
get nodeType(): number;
|
|
14
|
+
/**
|
|
15
|
+
* The first element, in tree order, whose id matches the given value, or null when there is none (the DOM's
|
|
16
|
+
* NonElementParentNode mixin, which Document and DocumentFragment both implement).
|
|
17
|
+
* @param {string} id
|
|
18
|
+
* @returns {PseudoElement|null}
|
|
19
|
+
*/
|
|
20
|
+
getElementById(id: string): PseudoElement | null;
|
|
21
|
+
}
|
|
@@ -1,24 +1,42 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(exports, '__esModule', {
|
|
11
|
+
value: true
|
|
12
|
+
})
|
|
13
|
+
exports.DocumentFragmentService = void 0
|
|
14
|
+
const NodeService_1 = require('./NodeService')
|
|
15
|
+
const getElementById_1 = __importDefault(require('../functions/getElementById'))
|
|
16
|
+
/**
|
|
17
|
+
* Simulate the behaviour of the DocumentFragment Class when there is no DOM available: a container for nodes which is
|
|
18
|
+
* not part of a tree, when it is inserted its children are moved into the tree instead.
|
|
19
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
20
|
+
* @class
|
|
21
|
+
* @augments NodeService
|
|
22
|
+
*/
|
|
23
|
+
class DocumentFragmentService extends NodeService_1.NodeService {
|
|
24
|
+
get nodeName () {
|
|
25
|
+
return '#document-fragment'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get nodeType () {
|
|
29
|
+
return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The first element, in tree order, whose id matches the given value, or null when there is none (the DOM's
|
|
34
|
+
* NonElementParentNode mixin, which Document and DocumentFragment both implement).
|
|
35
|
+
* @param {string} id
|
|
36
|
+
* @returns {PseudoElement|null}
|
|
37
|
+
*/
|
|
38
|
+
getElementById (id) {
|
|
39
|
+
return (0, getElementById_1.default)(this, id)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.DocumentFragmentService = DocumentFragmentService
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentFragmentService=void 0;const NodeService_1=require("./NodeService");class DocumentFragmentService extends NodeService_1.NodeService{get nodeName(){return"#document-fragment"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE}}exports.DocumentFragmentService=DocumentFragmentService;
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentFragmentService=void 0;const NodeService_1=require("./NodeService"),getElementById_1=__importDefault(require("../functions/getElementById"));class DocumentFragmentService extends NodeService_1.NodeService{get nodeName(){return"#document-fragment"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_FRAGMENT_NODE}getElementById(e){return(0,getElementById_1.default)(this,e)}}exports.DocumentFragmentService=DocumentFragmentService;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { NodeService } from './NodeService';
|
|
1
|
+
import { NodeService, TextService, CommentService } from './NodeService';
|
|
2
2
|
import { PseudoDocument } from '../interfaces/PseudoDocument';
|
|
3
3
|
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
4
|
+
import { DocumentFragmentService } from './DocumentFragmentService';
|
|
4
5
|
/**
|
|
5
6
|
* Simulate the behaviour of the Document Class when there is no DOM available.
|
|
6
7
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -10,10 +11,36 @@ import { PseudoElement } from '../interfaces/PseudoElement';
|
|
|
10
11
|
export declare class DocumentService extends NodeService implements PseudoDocument {
|
|
11
12
|
get nodeName(): string;
|
|
12
13
|
get nodeType(): number;
|
|
14
|
+
get textContent(): string | null;
|
|
15
|
+
set textContent(text: string | null);
|
|
13
16
|
/**
|
|
14
17
|
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
15
18
|
* @param {string} id
|
|
16
19
|
* @returns {PseudoElement|null}
|
|
17
20
|
*/
|
|
18
21
|
getElementById(id: string): PseudoElement | null;
|
|
22
|
+
/**
|
|
23
|
+
* Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
|
|
24
|
+
* @param {string} [tagName='div'] The type of element to create
|
|
25
|
+
* @returns {PseudoElement}
|
|
26
|
+
*/
|
|
27
|
+
createElement(tagName?: string): PseudoElement;
|
|
28
|
+
/**
|
|
29
|
+
* Make a text node which belongs to this document.
|
|
30
|
+
* @param {string} [data=''] The text
|
|
31
|
+
* @returns {TextService}
|
|
32
|
+
*/
|
|
33
|
+
createTextNode(data?: string): TextService;
|
|
34
|
+
/**
|
|
35
|
+
* Make a comment which belongs to this document.
|
|
36
|
+
* @param {string} [data=''] The comment
|
|
37
|
+
* @returns {CommentService}
|
|
38
|
+
*/
|
|
39
|
+
createComment(data?: string): CommentService;
|
|
40
|
+
/**
|
|
41
|
+
* Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
|
|
42
|
+
* then inserted in one go.
|
|
43
|
+
* @returns {DocumentFragmentService}
|
|
44
|
+
*/
|
|
45
|
+
createDocumentFragment(): DocumentFragmentService;
|
|
19
46
|
}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule
|
|
5
|
+
? mod
|
|
6
|
+
: {
|
|
7
|
+
default: mod
|
|
8
|
+
}
|
|
9
|
+
}
|
|
3
10
|
Object.defineProperty(exports, '__esModule', {
|
|
4
11
|
value: true
|
|
5
12
|
})
|
|
6
13
|
exports.DocumentService = void 0
|
|
7
14
|
const NodeService_1 = require('./NodeService')
|
|
15
|
+
const HTMLElementService_1 = require('./HTMLElementService')
|
|
16
|
+
const DocumentFragmentService_1 = require('./DocumentFragmentService')
|
|
17
|
+
const getElementById_1 = __importDefault(require('../functions/getElementById'))
|
|
8
18
|
/**
|
|
9
19
|
* Simulate the behaviour of the Document Class when there is no DOM available.
|
|
10
20
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
@@ -20,27 +30,66 @@ class DocumentService extends NodeService_1.NodeService {
|
|
|
20
30
|
return NodeService_1.NodeService.DOCUMENT_NODE
|
|
21
31
|
}
|
|
22
32
|
|
|
33
|
+
// A document has no text of its own, and setting it does nothing
|
|
34
|
+
get textContent () {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
set textContent (text) {}
|
|
23
39
|
/**
|
|
24
40
|
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
25
41
|
* @param {string} id
|
|
26
42
|
* @returns {PseudoElement|null}
|
|
27
43
|
*/
|
|
28
44
|
getElementById (id) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return
|
|
45
|
+
return (0, getElementById_1.default)(this, id)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Make an element of the given type which belongs to this document but is not added anywhere until it is appended.
|
|
50
|
+
* @param {string} [tagName='div'] The type of element to create
|
|
51
|
+
* @returns {PseudoElement}
|
|
52
|
+
*/
|
|
53
|
+
createElement (tagName = 'div') {
|
|
54
|
+
// Like the DOM, the new element is not added anywhere: it has no parent until it is appended
|
|
55
|
+
const element = new HTMLElementService_1.HTMLElementService({
|
|
56
|
+
tagName
|
|
57
|
+
})
|
|
58
|
+
element.ownerDocumentStore = this
|
|
59
|
+
return element
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Make a text node which belongs to this document.
|
|
64
|
+
* @param {string} [data=''] The text
|
|
65
|
+
* @returns {TextService}
|
|
66
|
+
*/
|
|
67
|
+
createTextNode (data = '') {
|
|
68
|
+
const text = new NodeService_1.TextService(data)
|
|
69
|
+
text.ownerDocumentStore = this
|
|
70
|
+
return text
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Make a comment which belongs to this document.
|
|
75
|
+
* @param {string} [data=''] The comment
|
|
76
|
+
* @returns {CommentService}
|
|
77
|
+
*/
|
|
78
|
+
createComment (data = '') {
|
|
79
|
+
const comment = new NodeService_1.CommentService(data)
|
|
80
|
+
comment.ownerDocumentStore = this
|
|
81
|
+
return comment
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Make an empty document fragment which belongs to this document, a container for nodes which can be built up and
|
|
86
|
+
* then inserted in one go.
|
|
87
|
+
* @returns {DocumentFragmentService}
|
|
88
|
+
*/
|
|
89
|
+
createDocumentFragment () {
|
|
90
|
+
const fragment = new DocumentFragmentService_1.DocumentFragmentService()
|
|
91
|
+
fragment.ownerDocumentStore = this
|
|
92
|
+
return fragment
|
|
44
93
|
}
|
|
45
94
|
}
|
|
46
95
|
exports.DocumentService = DocumentService
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentService=void 0;const NodeService_1=require("./NodeService");class DocumentService extends NodeService_1.NodeService{get nodeName(){return"#document"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_NODE}getElementById(e){
|
|
1
|
+
"use strict";var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.DocumentService=void 0;const NodeService_1=require("./NodeService"),HTMLElementService_1=require("./HTMLElementService"),DocumentFragmentService_1=require("./DocumentFragmentService"),getElementById_1=__importDefault(require("../functions/getElementById"));class DocumentService extends NodeService_1.NodeService{get nodeName(){return"#document"}get nodeType(){return NodeService_1.NodeService.DOCUMENT_NODE}get textContent(){return null}set textContent(e){}getElementById(e){return(0,getElementById_1.default)(this,e)}createElement(e="div"){const t=new HTMLElementService_1.HTMLElementService({tagName:e});return t.ownerDocumentStore=this,t}createTextNode(e=""){const t=new NodeService_1.TextService(e);return t.ownerDocumentStore=this,t}createComment(e=""){const t=new NodeService_1.CommentService(e);return t.ownerDocumentStore=this,t}createDocumentFragment(){const e=new DocumentFragmentService_1.DocumentFragmentService;return e.ownerDocumentStore=this,e}}exports.DocumentService=DocumentService;
|
|
@@ -1,191 +1,191 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Substitute for the DOM Element Class.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
7
|
-
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
8
|
-
import { NodeService } from './NodeService';
|
|
9
|
-
import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
|
|
10
|
-
import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
|
|
11
|
-
import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
|
|
12
|
-
type attribute = {
|
|
13
|
-
name: string;
|
|
14
|
-
value: any;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Simulate the behaviour of the Element Class when there is no DOM available.
|
|
18
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
19
|
-
* @class
|
|
20
|
-
* @augments PseudoNode
|
|
21
|
-
* @property {string} tagName
|
|
22
|
-
* @property {string} className
|
|
23
|
-
* @property {string} id
|
|
24
|
-
* @property {string} innerHtml
|
|
25
|
-
* @property {Array} attributes
|
|
26
|
-
* @property {function} hasAttribute
|
|
27
|
-
* @property {function} setAttribute
|
|
28
|
-
* @property {function} getAttribute
|
|
29
|
-
* @property {function} removeAttribute
|
|
30
|
-
*/
|
|
31
|
-
export declare class ElementService extends NodeService implements Partial<PseudoElement> {
|
|
32
|
-
id: string;
|
|
33
|
-
innerHTML: string;
|
|
34
|
-
type: string;
|
|
35
|
-
private readonly tag;
|
|
36
|
-
private readonly attributeList;
|
|
37
|
-
private readonly propertyAttributes;
|
|
38
|
-
private readonly tokenList;
|
|
39
|
-
private defaultEventApplied;
|
|
40
|
-
/**
|
|
41
|
-
* @param {Object} [settings={}]
|
|
42
|
-
* @param {string} [settings.tagName=''] The name of the tag this element represents
|
|
43
|
-
* @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
|
|
44
|
-
* @param {PseudoNode|null} [settings.parent=null] The node to add this element to as its last child
|
|
45
|
-
* @param {Array<PseudoNode>} [settings.children=[]] The nodes to start as children
|
|
46
|
-
* @constructor
|
|
47
|
-
*/
|
|
48
|
-
constructor({ tagName, attributes, parent, children }?: {
|
|
49
|
-
tagName?: string;
|
|
50
|
-
attributes?: Array<attribute>;
|
|
51
|
-
parent?: PseudoNode | null;
|
|
52
|
-
children?: Array<any>;
|
|
53
|
-
});
|
|
54
|
-
/**
|
|
55
|
-
* The attributes with the values they have now: the ones which are also properties (className, id, style, ...) can
|
|
56
|
-
* have been changed through the property, which does not change the stored list.
|
|
57
|
-
* @returns {Array<{name: string, value: *}>}
|
|
58
|
-
*/
|
|
59
|
-
private currentAttributes;
|
|
60
|
-
get nodeName(): string;
|
|
61
|
-
/**
|
|
62
|
-
* A copy of this element without its children: the same tag and attributes (the values which are objects, such as
|
|
63
|
-
* style, are copied too rather than shared), but not its parent or listeners.
|
|
64
|
-
* @returns {ElementService}
|
|
65
|
-
*/
|
|
66
|
-
protected cloneShallow(): NodeService;
|
|
67
|
-
/**
|
|
68
|
-
* Elements are equal when they have the same tag and the same attributes (in any order), which is what isEqualNode
|
|
69
|
-
* checks before it compares the children.
|
|
70
|
-
* @param {NodeService} other The element to compare with
|
|
71
|
-
* @returns {boolean}
|
|
72
|
-
*/
|
|
73
|
-
protected equalsShallow(other: NodeService): boolean;
|
|
74
|
-
get tagName(): string;
|
|
75
|
-
get nodeType(): number;
|
|
76
|
-
get attributes(): PseudoNamedNodeMap;
|
|
77
|
-
get classList(): PseudoDOMTokenList;
|
|
78
|
-
get className(): string;
|
|
79
|
-
set className(className: string);
|
|
80
|
-
/**
|
|
81
|
-
* Some elements have default behaviour, this registers it when the element is added.
|
|
82
|
-
* @returns {Function}
|
|
83
|
-
*/
|
|
84
|
-
/**
|
|
85
|
-
* A live view of this element's element children (text, comments and the like are not included).
|
|
86
|
-
* @returns {PseudoHTMLCollection}
|
|
87
|
-
*/
|
|
88
|
-
get children(): PseudoHTMLCollection;
|
|
89
|
-
/**
|
|
90
|
-
* How many element children this element has.
|
|
91
|
-
* @returns {number}
|
|
92
|
-
*/
|
|
93
|
-
get childElementCount(): number;
|
|
94
|
-
/**
|
|
95
|
-
* The first child of this element which is an element, or null when there is none.
|
|
96
|
-
* @returns {PseudoElement|null}
|
|
97
|
-
*/
|
|
98
|
-
get firstElementChild(): PseudoElement | null;
|
|
99
|
-
/**
|
|
100
|
-
* The last child of this element which is an element, or null when there is none.
|
|
101
|
-
* @returns {PseudoElement|null}
|
|
102
|
-
*/
|
|
103
|
-
get lastElementChild(): PseudoElement | null;
|
|
104
|
-
/**
|
|
105
|
-
* The sibling after this one which is an element, or null when there is none.
|
|
106
|
-
* @returns {PseudoElement|null}
|
|
107
|
-
*/
|
|
108
|
-
get nextElementSibling(): PseudoElement | null;
|
|
109
|
-
/**
|
|
110
|
-
* The sibling before this one which is an element, or null when there is none.
|
|
111
|
-
* @returns {PseudoElement|null}
|
|
112
|
-
*/
|
|
113
|
-
get previousElementSibling(): PseudoElement | null;
|
|
114
|
-
/**
|
|
115
|
-
* Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
|
|
116
|
-
* afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
|
|
117
|
-
* element, as its next sibling).
|
|
118
|
-
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
119
|
-
* @param {ElementService} element The element to insert
|
|
120
|
-
* @returns {ElementService|null} The inserted element, or null when the position needed a parent this element does not have
|
|
121
|
-
* @throws {Error} When the position is not one of the four above
|
|
122
|
-
*/
|
|
123
|
-
insertAdjacentElement(position: string, element: PseudoElement): PseudoElement | null;
|
|
124
|
-
/**
|
|
125
|
-
* Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
|
|
126
|
-
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
127
|
-
* @param {string} text The text to insert
|
|
128
|
-
* @throws {Error} When the position is not one of the four above
|
|
129
|
-
*/
|
|
130
|
-
insertAdjacentText(position: string, text: string): void;
|
|
131
|
-
/**
|
|
132
|
-
* Shared implementation for insertAdjacentElement / insertAdjacentText.
|
|
133
|
-
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
134
|
-
* @param {PseudoNode|string} node The node (or text) to insert
|
|
135
|
-
* @returns {PseudoNode|null} The inserted node, or null when the position needed a parent this element does not have
|
|
136
|
-
* @throws {Error} When the position is not one of the four above
|
|
137
|
-
*/
|
|
138
|
-
private insertAdjacent;
|
|
139
|
-
/**
|
|
140
|
-
* Not implemented yet (HTML parsing is out of scope for now).
|
|
141
|
-
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
142
|
-
* @param {string} text The markup which would be parsed
|
|
143
|
-
* @throws {Error}
|
|
144
|
-
*/
|
|
145
|
-
insertAdjacentHTML(position: string, text: string): void;
|
|
146
|
-
/**
|
|
147
|
-
* Whether this element itself (not its descendants) matches the given CSS selector.
|
|
148
|
-
* @param {string} selectors A CSS selector
|
|
149
|
-
* @returns {boolean}
|
|
150
|
-
*/
|
|
151
|
-
matches(selectors: string): boolean;
|
|
152
|
-
/**
|
|
153
|
-
* The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
|
|
154
|
-
* null when none of them do.
|
|
155
|
-
* @param {string} selectors A CSS selector
|
|
156
|
-
* @returns {PseudoElement|null}
|
|
157
|
-
*/
|
|
158
|
-
closest(selectors: string): PseudoElement | null;
|
|
159
|
-
applyDefaultEvent(): Function;
|
|
160
|
-
/**
|
|
161
|
-
* An element which is added as a child gets its default events (for example a submit button submits its form).
|
|
162
|
-
* @param {NodeService} child The node which was inserted
|
|
163
|
-
*/
|
|
164
|
-
protected childInserted(child: NodeService): void;
|
|
165
|
-
/**
|
|
166
|
-
* Check whether the element has an attribute by that name.
|
|
167
|
-
* @param {string} attributeName
|
|
168
|
-
* @returns {boolean}
|
|
169
|
-
*/
|
|
170
|
-
hasAttribute(attributeName: string): boolean;
|
|
171
|
-
/**
|
|
172
|
-
* Set the value of an attribute, adding the attribute if it did not exist.
|
|
173
|
-
* @param {string} attributeName
|
|
174
|
-
* @param {string} attributeValue
|
|
175
|
-
* @returns {undefined}
|
|
176
|
-
*/
|
|
177
|
-
setAttribute(attributeName: string, attributeValue: string): void;
|
|
178
|
-
/**
|
|
179
|
-
* Retrieve the value of an attribute.
|
|
180
|
-
* @param {string} attributeName
|
|
181
|
-
* @returns {string|null} The value, or null when there is no such attribute
|
|
182
|
-
*/
|
|
183
|
-
getAttribute(attributeName: string): string | null;
|
|
184
|
-
/**
|
|
185
|
-
* Remove an attribute from the element.
|
|
186
|
-
* @param {string} attributeName
|
|
187
|
-
* @returns {undefined}
|
|
188
|
-
*/
|
|
189
|
-
removeAttribute(attributeName: string): void;
|
|
190
|
-
}
|
|
191
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM Element Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
7
|
+
import { PseudoElement } from '../interfaces/PseudoElement';
|
|
8
|
+
import { NodeService } from './NodeService';
|
|
9
|
+
import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
|
|
10
|
+
import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
|
|
11
|
+
import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
|
|
12
|
+
type attribute = {
|
|
13
|
+
name: string;
|
|
14
|
+
value: any;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Simulate the behaviour of the Element Class when there is no DOM available.
|
|
18
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
19
|
+
* @class
|
|
20
|
+
* @augments PseudoNode
|
|
21
|
+
* @property {string} tagName
|
|
22
|
+
* @property {string} className
|
|
23
|
+
* @property {string} id
|
|
24
|
+
* @property {string} innerHtml
|
|
25
|
+
* @property {Array} attributes
|
|
26
|
+
* @property {function} hasAttribute
|
|
27
|
+
* @property {function} setAttribute
|
|
28
|
+
* @property {function} getAttribute
|
|
29
|
+
* @property {function} removeAttribute
|
|
30
|
+
*/
|
|
31
|
+
export declare class ElementService extends NodeService implements Partial<PseudoElement> {
|
|
32
|
+
id: string;
|
|
33
|
+
innerHTML: string;
|
|
34
|
+
type: string;
|
|
35
|
+
private readonly tag;
|
|
36
|
+
private readonly attributeList;
|
|
37
|
+
private readonly propertyAttributes;
|
|
38
|
+
private readonly tokenList;
|
|
39
|
+
private defaultEventApplied;
|
|
40
|
+
/**
|
|
41
|
+
* @param {Object} [settings={}]
|
|
42
|
+
* @param {string} [settings.tagName=''] The name of the tag this element represents
|
|
43
|
+
* @param {Array<{name: string, value: *}>} [settings.attributes=[]] The attributes (also assigned as properties) to start with
|
|
44
|
+
* @param {PseudoNode|null} [settings.parent=null] The node to add this element to as its last child
|
|
45
|
+
* @param {Array<PseudoNode>} [settings.children=[]] The nodes to start as children
|
|
46
|
+
* @constructor
|
|
47
|
+
*/
|
|
48
|
+
constructor({ tagName, attributes, parent, children }?: {
|
|
49
|
+
tagName?: string;
|
|
50
|
+
attributes?: Array<attribute>;
|
|
51
|
+
parent?: PseudoNode | null;
|
|
52
|
+
children?: Array<any>;
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* The attributes with the values they have now: the ones which are also properties (className, id, style, ...) can
|
|
56
|
+
* have been changed through the property, which does not change the stored list.
|
|
57
|
+
* @returns {Array<{name: string, value: *}>}
|
|
58
|
+
*/
|
|
59
|
+
private currentAttributes;
|
|
60
|
+
get nodeName(): string;
|
|
61
|
+
/**
|
|
62
|
+
* A copy of this element without its children: the same tag and attributes (the values which are objects, such as
|
|
63
|
+
* style, are copied too rather than shared), but not its parent or listeners.
|
|
64
|
+
* @returns {ElementService}
|
|
65
|
+
*/
|
|
66
|
+
protected cloneShallow(): NodeService;
|
|
67
|
+
/**
|
|
68
|
+
* Elements are equal when they have the same tag and the same attributes (in any order), which is what isEqualNode
|
|
69
|
+
* checks before it compares the children.
|
|
70
|
+
* @param {NodeService} other The element to compare with
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
protected equalsShallow(other: NodeService): boolean;
|
|
74
|
+
get tagName(): string;
|
|
75
|
+
get nodeType(): number;
|
|
76
|
+
get attributes(): PseudoNamedNodeMap;
|
|
77
|
+
get classList(): PseudoDOMTokenList;
|
|
78
|
+
get className(): string;
|
|
79
|
+
set className(className: string);
|
|
80
|
+
/**
|
|
81
|
+
* Some elements have default behaviour, this registers it when the element is added.
|
|
82
|
+
* @returns {Function}
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* A live view of this element's element children (text, comments and the like are not included).
|
|
86
|
+
* @returns {PseudoHTMLCollection}
|
|
87
|
+
*/
|
|
88
|
+
get children(): PseudoHTMLCollection;
|
|
89
|
+
/**
|
|
90
|
+
* How many element children this element has.
|
|
91
|
+
* @returns {number}
|
|
92
|
+
*/
|
|
93
|
+
get childElementCount(): number;
|
|
94
|
+
/**
|
|
95
|
+
* The first child of this element which is an element, or null when there is none.
|
|
96
|
+
* @returns {PseudoElement|null}
|
|
97
|
+
*/
|
|
98
|
+
get firstElementChild(): PseudoElement | null;
|
|
99
|
+
/**
|
|
100
|
+
* The last child of this element which is an element, or null when there is none.
|
|
101
|
+
* @returns {PseudoElement|null}
|
|
102
|
+
*/
|
|
103
|
+
get lastElementChild(): PseudoElement | null;
|
|
104
|
+
/**
|
|
105
|
+
* The sibling after this one which is an element, or null when there is none.
|
|
106
|
+
* @returns {PseudoElement|null}
|
|
107
|
+
*/
|
|
108
|
+
get nextElementSibling(): PseudoElement | null;
|
|
109
|
+
/**
|
|
110
|
+
* The sibling before this one which is an element, or null when there is none.
|
|
111
|
+
* @returns {PseudoElement|null}
|
|
112
|
+
*/
|
|
113
|
+
get previousElementSibling(): PseudoElement | null;
|
|
114
|
+
/**
|
|
115
|
+
* Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
|
|
116
|
+
* afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
|
|
117
|
+
* element, as its next sibling).
|
|
118
|
+
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
119
|
+
* @param {ElementService} element The element to insert
|
|
120
|
+
* @returns {ElementService|null} The inserted element, or null when the position needed a parent this element does not have
|
|
121
|
+
* @throws {Error} When the position is not one of the four above
|
|
122
|
+
*/
|
|
123
|
+
insertAdjacentElement(position: string, element: PseudoElement): PseudoElement | null;
|
|
124
|
+
/**
|
|
125
|
+
* Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
|
|
126
|
+
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
127
|
+
* @param {string} text The text to insert
|
|
128
|
+
* @throws {Error} When the position is not one of the four above
|
|
129
|
+
*/
|
|
130
|
+
insertAdjacentText(position: string, text: string): void;
|
|
131
|
+
/**
|
|
132
|
+
* Shared implementation for insertAdjacentElement / insertAdjacentText.
|
|
133
|
+
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
134
|
+
* @param {PseudoNode|string} node The node (or text) to insert
|
|
135
|
+
* @returns {PseudoNode|null} The inserted node, or null when the position needed a parent this element does not have
|
|
136
|
+
* @throws {Error} When the position is not one of the four above
|
|
137
|
+
*/
|
|
138
|
+
private insertAdjacent;
|
|
139
|
+
/**
|
|
140
|
+
* Not implemented yet (HTML parsing is out of scope for now).
|
|
141
|
+
* @param {string} position beforebegin, afterbegin, beforeend or afterend
|
|
142
|
+
* @param {string} text The markup which would be parsed
|
|
143
|
+
* @throws {Error}
|
|
144
|
+
*/
|
|
145
|
+
insertAdjacentHTML(position: string, text: string): void;
|
|
146
|
+
/**
|
|
147
|
+
* Whether this element itself (not its descendants) matches the given CSS selector.
|
|
148
|
+
* @param {string} selectors A CSS selector
|
|
149
|
+
* @returns {boolean}
|
|
150
|
+
*/
|
|
151
|
+
matches(selectors: string): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
|
|
154
|
+
* null when none of them do.
|
|
155
|
+
* @param {string} selectors A CSS selector
|
|
156
|
+
* @returns {PseudoElement|null}
|
|
157
|
+
*/
|
|
158
|
+
closest(selectors: string): PseudoElement | null;
|
|
159
|
+
applyDefaultEvent(): Function;
|
|
160
|
+
/**
|
|
161
|
+
* An element which is added as a child gets its default events (for example a submit button submits its form).
|
|
162
|
+
* @param {NodeService} child The node which was inserted
|
|
163
|
+
*/
|
|
164
|
+
protected childInserted(child: NodeService): void;
|
|
165
|
+
/**
|
|
166
|
+
* Check whether the element has an attribute by that name.
|
|
167
|
+
* @param {string} attributeName
|
|
168
|
+
* @returns {boolean}
|
|
169
|
+
*/
|
|
170
|
+
hasAttribute(attributeName: string): boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Set the value of an attribute, adding the attribute if it did not exist.
|
|
173
|
+
* @param {string} attributeName
|
|
174
|
+
* @param {string} attributeValue
|
|
175
|
+
* @returns {undefined}
|
|
176
|
+
*/
|
|
177
|
+
setAttribute(attributeName: string, attributeValue: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Retrieve the value of an attribute.
|
|
180
|
+
* @param {string} attributeName
|
|
181
|
+
* @returns {string|null} The value, or null when there is no such attribute
|
|
182
|
+
*/
|
|
183
|
+
getAttribute(attributeName: string): string | null;
|
|
184
|
+
/**
|
|
185
|
+
* Remove an attribute from the element.
|
|
186
|
+
* @param {string} attributeName
|
|
187
|
+
* @returns {undefined}
|
|
188
|
+
*/
|
|
189
|
+
removeAttribute(attributeName: string): void;
|
|
190
|
+
}
|
|
191
|
+
export {};
|