pseudo-dom 0.8.0 → 0.9.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 +206 -1
- package/browser/pseudo-dom.js +813 -470
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +41 -41
- package/dist/classes/PseudoHTMLDocument.js +74 -74
- package/dist/factories/createDataset.d.ts +10 -0
- package/dist/factories/createDataset.js +78 -0
- package/dist/factories/createDataset.min.js +1 -0
- package/dist/factories/createStyleDeclaration.d.ts +30 -0
- package/dist/factories/createStyleDeclaration.js +64 -0
- package/dist/factories/createStyleDeclaration.min.js +1 -0
- package/dist/functions/getElementById.d.ts +13 -13
- package/dist/functions/getElementById.js +33 -33
- package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
- package/dist/interfaces/PseudoDocument.d.ts +35 -35
- package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -10
- package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
- package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
- package/dist/services/CSSStyleDeclarationService.js +156 -0
- package/dist/services/CSSStyleDeclarationService.min.js +1 -0
- package/dist/services/DocumentFragmentService.d.ts +21 -21
- package/dist/services/DocumentFragmentService.js +42 -42
- package/dist/services/DocumentService.d.ts +46 -46
- package/dist/services/DocumentService.js +95 -95
- package/dist/services/HTMLElementService.d.ts +87 -57
- package/dist/services/HTMLElementService.js +202 -163
- package/dist/services/HTMLElementService.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,95 +1,95 @@
|
|
|
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.DocumentService = void 0
|
|
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'))
|
|
18
|
-
/**
|
|
19
|
-
* Simulate the behaviour of the Document Class when there is no DOM available.
|
|
20
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
21
|
-
* @class
|
|
22
|
-
* @augments NodeService
|
|
23
|
-
*/
|
|
24
|
-
class DocumentService extends NodeService_1.NodeService {
|
|
25
|
-
get nodeName () {
|
|
26
|
-
return '#document'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get nodeType () {
|
|
30
|
-
return NodeService_1.NodeService.DOCUMENT_NODE
|
|
31
|
-
}
|
|
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) {}
|
|
39
|
-
/**
|
|
40
|
-
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
41
|
-
* @param {string} id
|
|
42
|
-
* @returns {PseudoElement|null}
|
|
43
|
-
*/
|
|
44
|
-
getElementById (id) {
|
|
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
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.DocumentService = DocumentService
|
|
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.DocumentService = void 0
|
|
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'))
|
|
18
|
+
/**
|
|
19
|
+
* Simulate the behaviour of the Document Class when there is no DOM available.
|
|
20
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
21
|
+
* @class
|
|
22
|
+
* @augments NodeService
|
|
23
|
+
*/
|
|
24
|
+
class DocumentService extends NodeService_1.NodeService {
|
|
25
|
+
get nodeName () {
|
|
26
|
+
return '#document'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get nodeType () {
|
|
30
|
+
return NodeService_1.NodeService.DOCUMENT_NODE
|
|
31
|
+
}
|
|
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) {}
|
|
39
|
+
/**
|
|
40
|
+
* The first element, in tree order, whose id matches the given value, or null when there is none.
|
|
41
|
+
* @param {string} id
|
|
42
|
+
* @returns {PseudoElement|null}
|
|
43
|
+
*/
|
|
44
|
+
getElementById (id) {
|
|
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
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.DocumentService = DocumentService
|
|
@@ -1,57 +1,87 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Substitute for the DOM HTMLElement Class.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
|
|
7
|
-
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
16
|
-
* @property {
|
|
17
|
-
* @property {
|
|
18
|
-
* @property {number}
|
|
19
|
-
* @property {
|
|
20
|
-
* @property {
|
|
21
|
-
* @property {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM HTMLElement Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { PseudoHTMLElement } from '../interfaces/PseudoHTMLElement';
|
|
7
|
+
import { PseudoNode } from '../interfaces/PseudoNode';
|
|
8
|
+
import { NodeService } from './NodeService';
|
|
9
|
+
import { ElementService } from './ElementService';
|
|
10
|
+
import { CSSStyleDeclarationService } from './CSSStyleDeclarationService';
|
|
11
|
+
/**
|
|
12
|
+
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
13
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
14
|
+
* @class
|
|
15
|
+
* @augments PseudoElement
|
|
16
|
+
* @property {boolean} hidden - State of whether element is visible
|
|
17
|
+
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
18
|
+
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
19
|
+
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
20
|
+
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
21
|
+
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
22
|
+
* @property {CSSStyleDeclarationService} style - The element's inline styles, live and settable per property
|
|
23
|
+
* @property {Object.<string, string>} dataset - The element's data-* attributes, live, under their camelCase names
|
|
24
|
+
* @property {string} title - The title attribute which affects the text visible on hover
|
|
25
|
+
*/
|
|
26
|
+
export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
|
|
27
|
+
private readonly styleDeclaration;
|
|
28
|
+
private readonly datasetProxy;
|
|
29
|
+
/**
|
|
30
|
+
* Simulate the HTMLElement object when the Dom is not available
|
|
31
|
+
* @param {Object} [elementOptions={}]
|
|
32
|
+
* @param {string} [elementOptions.tagName='']
|
|
33
|
+
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
34
|
+
* @param {Array} [elementOptions.children=[]]
|
|
35
|
+
* @constructor
|
|
36
|
+
*/
|
|
37
|
+
constructor({ tagName, parent, children }?: {
|
|
38
|
+
tagName?: string;
|
|
39
|
+
parent?: PseudoNode | null;
|
|
40
|
+
children?: Array<any>;
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
|
|
44
|
+
* and style.color = 'red' work.
|
|
45
|
+
* @returns {CSSStyleDeclarationService}
|
|
46
|
+
*/
|
|
47
|
+
get style(): CSSStyleDeclarationService;
|
|
48
|
+
/**
|
|
49
|
+
* The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
|
|
50
|
+
* directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
|
|
51
|
+
* @returns {Object.<string, string>}
|
|
52
|
+
*/
|
|
53
|
+
get dataset(): {
|
|
54
|
+
[key: string]: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it.
|
|
58
|
+
* @returns {NodeService}
|
|
59
|
+
*/
|
|
60
|
+
protected cloneShallow(): NodeService;
|
|
61
|
+
/**
|
|
62
|
+
* Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
|
|
63
|
+
* @param {NodeService} other The node to compare with
|
|
64
|
+
* @returns {boolean}
|
|
65
|
+
*/
|
|
66
|
+
protected equalsShallow(other: NodeService): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
69
|
+
* @returns {boolean}
|
|
70
|
+
*/
|
|
71
|
+
get canFocus(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
74
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
75
|
+
*/
|
|
76
|
+
click(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
79
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
80
|
+
* focus or already has it.
|
|
81
|
+
*/
|
|
82
|
+
focus(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
85
|
+
*/
|
|
86
|
+
blur(): void;
|
|
87
|
+
}
|