pseudo-dom 0.6.0 → 0.7.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 +432 -13
- package/browser/pseudo-dom.js +3364 -603
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoEventListener.d.ts +96 -96
- package/dist/classes/PseudoEventListener.js +151 -151
- package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
- package/dist/classes/PseudoHTMLDocument.js +144 -144
- package/dist/classes/PseudoNodeList.d.ts +34 -34
- package/dist/classes/PseudoNodeList.js +71 -71
- package/dist/classes.d.ts +20 -20
- package/dist/classes.js +31 -31
- package/dist/factories/createEvent.d.ts +28 -28
- package/dist/factories/createEvent.js +56 -56
- package/dist/factories/cssSelectAdapter.d.ts +23 -0
- package/dist/factories/cssSelectAdapter.js +87 -0
- package/dist/factories/cssSelectAdapter.min.js +1 -0
- package/dist/factories/eventDefaults.d.ts +31 -31
- package/dist/factories/eventDefaults.js +105 -105
- package/dist/factories/generateDocument.d.ts +11 -11
- package/dist/factories/generateDocument.js +65 -65
- package/dist/factories/generateNode.d.ts +32 -32
- package/dist/factories/generateNode.js +85 -85
- package/dist/factories/generateNodeList.d.ts +9 -9
- package/dist/factories/generateNodeList.js +13 -13
- package/dist/factories/query.d.ts +33 -0
- package/dist/factories/query.js +66 -0
- package/dist/factories/query.min.js +1 -0
- package/dist/factories.d.ts +11 -11
- package/dist/factories.js +27 -27
- package/dist/functions/activeElement.d.ts +14 -14
- package/dist/functions/activeElement.js +33 -33
- package/dist/functions/getParentNodes.d.ts +11 -11
- package/dist/functions/getParentNodes.js +22 -22
- package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
- package/dist/functions/getParentNodesFromAttribute.js +29 -29
- package/dist/functions/modifierState.d.ts +29 -29
- package/dist/functions/modifierState.js +41 -41
- package/dist/functions.d.ts +5 -5
- package/dist/functions.js +23 -23
- package/dist/interfaces/PseudoAnimation.d.ts +3 -3
- package/dist/interfaces/PseudoAnimation.js +5 -5
- package/dist/interfaces/PseudoAttr.d.ts +11 -11
- package/dist/interfaces/PseudoAttr.js +5 -5
- package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
- package/dist/interfaces/PseudoDOMTokenList.js +5 -5
- package/dist/interfaces/PseudoDocument.d.ts +7 -0
- package/dist/interfaces/PseudoDocument.js +5 -5
- package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
- package/dist/interfaces/PseudoDocumentFragment.js +5 -5
- package/dist/interfaces/PseudoElement.d.ts +20 -7
- package/dist/interfaces/PseudoElement.js +5 -5
- package/dist/interfaces/PseudoEvent.d.ts +79 -79
- package/dist/interfaces/PseudoEvent.js +10 -10
- package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
- package/dist/interfaces/PseudoEventTarget.js +5 -5
- package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -23
- package/dist/interfaces/PseudoHTMLCollection.js +5 -5
- package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
- package/dist/interfaces/PseudoHTMLElement.js +5 -5
- package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
- package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
- package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
- package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
- package/dist/interfaces/PseudoNode.d.ts +179 -179
- package/dist/interfaces/PseudoNode.js +5 -5
- package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
- package/dist/interfaces/PseudoShadowRoot.js +5 -5
- package/dist/main.d.ts +63 -63
- package/dist/main.js +155 -155
- package/dist/services/AnimationService.d.ts +4 -4
- package/dist/services/AnimationService.js +16 -16
- package/dist/services/AttrService.d.ts +37 -37
- package/dist/services/AttrService.js +81 -81
- package/dist/services/CommentService.d.ts +1 -1
- package/dist/services/CommentService.js +13 -13
- package/dist/services/CustomEventService.d.ts +37 -37
- package/dist/services/CustomEventService.js +35 -35
- package/dist/services/DOMTokenListService.d.ts +33 -33
- package/dist/services/DOMTokenListService.js +117 -117
- package/dist/services/DocumentFragmentService.d.ts +13 -13
- package/dist/services/DocumentFragmentService.js +24 -24
- package/dist/services/DocumentService.d.ts +7 -0
- package/dist/services/DocumentService.js +23 -0
- package/dist/services/DocumentService.min.js +1 -1
- package/dist/services/ElementService.d.ts +13 -0
- package/dist/services/ElementService.js +20 -0
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/EventService.d.ts +120 -120
- package/dist/services/EventService.js +250 -250
- package/dist/services/EventTargetService.d.ts +84 -84
- package/dist/services/EventTargetService.js +232 -232
- package/dist/services/FocusEventService.d.ts +32 -32
- package/dist/services/FocusEventService.js +35 -35
- package/dist/services/HTMLCollectionService.d.ts +11 -6
- package/dist/services/HTMLCollectionService.js +25 -8
- package/dist/services/HTMLCollectionService.min.js +1 -1
- package/dist/services/HTMLElementService.d.ts +57 -57
- package/dist/services/HTMLElementService.js +163 -163
- package/dist/services/HTMLSlotElementService.d.ts +4 -4
- package/dist/services/HTMLSlotElementService.js +9 -9
- package/dist/services/InputEventService.d.ts +41 -41
- package/dist/services/InputEventService.js +47 -47
- package/dist/services/KeyboardEventService.d.ts +70 -70
- package/dist/services/KeyboardEventService.js +86 -86
- package/dist/services/MouseEventService.d.ts +80 -80
- package/dist/services/MouseEventService.js +108 -108
- package/dist/services/NamedNodeMapService.d.ts +23 -23
- package/dist/services/NamedNodeMapService.js +77 -77
- package/dist/services/NodeService.d.ts +26 -0
- package/dist/services/NodeService.js +42 -0
- package/dist/services/NodeService.min.js +1 -1
- package/dist/services/PointerEventService.d.ts +51 -51
- package/dist/services/PointerEventService.js +67 -67
- package/dist/services/ShadowRootService.d.ts +4 -4
- package/dist/services/ShadowRootService.js +9 -9
- package/dist/services/TextService.d.ts +1 -1
- package/dist/services/TextService.js +13 -13
- package/dist/services/UIEventService.d.ts +43 -43
- package/dist/services/UIEventService.js +42 -42
- package/dist/simulate.d.ts +32 -32
- package/dist/simulate.js +115 -115
- package/package.json +3 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
require('core-js/modules/esnext.iterator.constructor.js')
|
|
4
|
-
require('core-js/modules/esnext.iterator.filter.js')
|
|
5
4
|
require('core-js/modules/esnext.iterator.find.js')
|
|
5
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
6
6
|
Object.defineProperty(exports, '__esModule', {
|
|
7
7
|
value: true
|
|
8
8
|
})
|
|
@@ -14,26 +14,43 @@ exports.HTMLCollectionService = void 0
|
|
|
14
14
|
*/
|
|
15
15
|
const NodeService_1 = require('./NodeService')
|
|
16
16
|
/**
|
|
17
|
-
* Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of
|
|
18
|
-
*
|
|
17
|
+
* Simulate the behaviour of the HTMLCollection Class when there is no DOM available: a live view of some of a node's
|
|
18
|
+
* element descendants, recomputed each time it is used rather than kept in sync as they change.
|
|
19
19
|
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
20
20
|
* @class
|
|
21
21
|
*/
|
|
22
22
|
class HTMLCollectionService {
|
|
23
23
|
/**
|
|
24
|
-
* @param {NodeService} owner The node
|
|
24
|
+
* @param {NodeService} owner The node this is a live view of a part of
|
|
25
|
+
* @param {function(*): boolean} [predicate] Only elements which pass this are included (every element by default)
|
|
26
|
+
* @param {boolean} [deep=false] Include every matching descendant (true, like getElementsByTagName), not just the
|
|
27
|
+
* direct element children (false, like Element.children)
|
|
25
28
|
* @constructor
|
|
26
29
|
*/
|
|
27
|
-
constructor (owner) {
|
|
30
|
+
constructor (owner, predicate = () => true, deep = false) {
|
|
28
31
|
this.owner = owner
|
|
32
|
+
this.predicate = predicate
|
|
33
|
+
this.deep = deep
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
/**
|
|
32
|
-
* The current
|
|
37
|
+
* The current elements the collection holds, in tree order.
|
|
33
38
|
* @returns {Array<PseudoNode>}
|
|
34
39
|
*/
|
|
35
40
|
elements () {
|
|
36
|
-
|
|
41
|
+
const results = []
|
|
42
|
+
const visit = node => {
|
|
43
|
+
Array.from(node.childNodes).forEach(child => {
|
|
44
|
+
if (child.nodeType === NodeService_1.NodeService.ELEMENT_NODE && this.predicate(child)) {
|
|
45
|
+
results.push(child)
|
|
46
|
+
}
|
|
47
|
+
if (this.deep && child.nodeType === NodeService_1.NodeService.ELEMENT_NODE) {
|
|
48
|
+
visit(child)
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
visit(this.owner)
|
|
53
|
+
return results
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
/**
|
|
@@ -64,7 +81,7 @@ class HTMLCollectionService {
|
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
/**
|
|
67
|
-
* Iterate over the current
|
|
84
|
+
* Iterate over the current elements.
|
|
68
85
|
* @returns {Iterator}
|
|
69
86
|
*/
|
|
70
87
|
[Symbol.iterator] () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.
|
|
1
|
+
"use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.HTMLCollectionService=void 0;const NodeService_1=require("./NodeService");class HTMLCollectionService{constructor(e,t=()=>!0,r=!1){this.owner=e,this.predicate=t,this.deep=r}elements(){const e=[],t=r=>{Array.from(r.childNodes).forEach(r=>{r.nodeType===NodeService_1.NodeService.ELEMENT_NODE&&this.predicate(r)&&e.push(r),this.deep&&r.nodeType===NodeService_1.NodeService.ELEMENT_NODE&&t(r)})};return t(this.owner),e}get length(){return this.elements().length}item(e){return this.elements()[e]||null}namedItem(e){const t=this.elements();return t.find(t=>t.id===e)||t.find(t=>t.getAttribute("name")===e)||null}[Symbol.iterator](){return this.elements()[Symbol.iterator]()}}exports.HTMLCollectionService=HTMLCollectionService,exports.default=HTMLCollectionService;
|
|
@@ -1,57 +1,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 { ElementService } from './ElementService';
|
|
9
|
-
/**
|
|
10
|
-
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
11
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
-
* @class
|
|
13
|
-
* @augments PseudoElement
|
|
14
|
-
* @property {boolean} hidden - State of whether element is visible
|
|
15
|
-
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
16
|
-
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
17
|
-
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
18
|
-
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
19
|
-
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
20
|
-
* @property {Object} style - A container to define all applied inline-styles
|
|
21
|
-
* @property {string} title - The title attribute which affects the text visible on hover
|
|
22
|
-
*/
|
|
23
|
-
export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
|
|
24
|
-
/**
|
|
25
|
-
* Simulate the HTMLElement object when the Dom is not available
|
|
26
|
-
* @param {Object} [elementOptions={}]
|
|
27
|
-
* @param {string} [elementOptions.tagName='']
|
|
28
|
-
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
29
|
-
* @param {Array} [elementOptions.children=[]]
|
|
30
|
-
* @constructor
|
|
31
|
-
*/
|
|
32
|
-
constructor({ tagName, parent, children }?: {
|
|
33
|
-
tagName?: string;
|
|
34
|
-
parent?: PseudoNode | null;
|
|
35
|
-
children?: Array<any>;
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
39
|
-
* @returns {boolean}
|
|
40
|
-
*/
|
|
41
|
-
get canFocus(): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
44
|
-
* script made it (so it is not trusted). A disabled element does nothing.
|
|
45
|
-
*/
|
|
46
|
-
click(): void;
|
|
47
|
-
/**
|
|
48
|
-
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
49
|
-
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
50
|
-
* focus or already has it.
|
|
51
|
-
*/
|
|
52
|
-
focus(): void;
|
|
53
|
-
/**
|
|
54
|
-
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
55
|
-
*/
|
|
56
|
-
blur(): void;
|
|
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 { ElementService } from './ElementService';
|
|
9
|
+
/**
|
|
10
|
+
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
11
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
12
|
+
* @class
|
|
13
|
+
* @augments PseudoElement
|
|
14
|
+
* @property {boolean} hidden - State of whether element is visible
|
|
15
|
+
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
16
|
+
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
17
|
+
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
18
|
+
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
19
|
+
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
20
|
+
* @property {Object} style - A container to define all applied inline-styles
|
|
21
|
+
* @property {string} title - The title attribute which affects the text visible on hover
|
|
22
|
+
*/
|
|
23
|
+
export declare class HTMLElementService extends ElementService implements Partial<PseudoHTMLElement> {
|
|
24
|
+
/**
|
|
25
|
+
* Simulate the HTMLElement object when the Dom is not available
|
|
26
|
+
* @param {Object} [elementOptions={}]
|
|
27
|
+
* @param {string} [elementOptions.tagName='']
|
|
28
|
+
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
29
|
+
* @param {Array} [elementOptions.children=[]]
|
|
30
|
+
* @constructor
|
|
31
|
+
*/
|
|
32
|
+
constructor({ tagName, parent, children }?: {
|
|
33
|
+
tagName?: string;
|
|
34
|
+
parent?: PseudoNode | null;
|
|
35
|
+
children?: Array<any>;
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
get canFocus(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
44
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
45
|
+
*/
|
|
46
|
+
click(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
49
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
50
|
+
* focus or already has it.
|
|
51
|
+
*/
|
|
52
|
+
focus(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
55
|
+
*/
|
|
56
|
+
blur(): void;
|
|
57
|
+
}
|
|
@@ -1,163 +1,163 @@
|
|
|
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.HTMLElementService = void 0
|
|
14
|
-
const ElementService_1 = require('./ElementService')
|
|
15
|
-
const createEvent_1 = __importDefault(require('../factories/createEvent'))
|
|
16
|
-
const activeElement_1 = require('../functions/activeElement')
|
|
17
|
-
/**
|
|
18
|
-
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
19
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
20
|
-
* @class
|
|
21
|
-
* @augments PseudoElement
|
|
22
|
-
* @property {boolean} hidden - State of whether element is visible
|
|
23
|
-
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
24
|
-
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
25
|
-
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
26
|
-
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
27
|
-
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
28
|
-
* @property {Object} style - A container to define all applied inline-styles
|
|
29
|
-
* @property {string} title - The title attribute which affects the text visible on hover
|
|
30
|
-
*/
|
|
31
|
-
class HTMLElementService extends ElementService_1.ElementService {
|
|
32
|
-
/**
|
|
33
|
-
* Simulate the HTMLElement object when the Dom is not available
|
|
34
|
-
* @param {Object} [elementOptions={}]
|
|
35
|
-
* @param {string} [elementOptions.tagName='']
|
|
36
|
-
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
37
|
-
* @param {Array} [elementOptions.children=[]]
|
|
38
|
-
* @constructor
|
|
39
|
-
*/
|
|
40
|
-
constructor ({
|
|
41
|
-
tagName = '',
|
|
42
|
-
parent = null,
|
|
43
|
-
children = []
|
|
44
|
-
} = {}) {
|
|
45
|
-
super({
|
|
46
|
-
tagName,
|
|
47
|
-
attributes: [{
|
|
48
|
-
name: 'hidden',
|
|
49
|
-
value: false
|
|
50
|
-
}, {
|
|
51
|
-
name: 'offsetHeight',
|
|
52
|
-
value: 0
|
|
53
|
-
}, {
|
|
54
|
-
name: 'offsetLeft',
|
|
55
|
-
value: 0
|
|
56
|
-
}, {
|
|
57
|
-
name: 'offsetParent',
|
|
58
|
-
value: null
|
|
59
|
-
}, {
|
|
60
|
-
name: 'offsetTop',
|
|
61
|
-
value: 0
|
|
62
|
-
}, {
|
|
63
|
-
name: 'offsetWidth',
|
|
64
|
-
value: 0
|
|
65
|
-
}, {
|
|
66
|
-
name: 'style',
|
|
67
|
-
value: {}
|
|
68
|
-
}, {
|
|
69
|
-
name: 'title',
|
|
70
|
-
value: ''
|
|
71
|
-
}],
|
|
72
|
-
parent,
|
|
73
|
-
children
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
79
|
-
* @returns {boolean}
|
|
80
|
-
*/
|
|
81
|
-
get canFocus () {
|
|
82
|
-
if (this.hasAttribute('disabled')) {
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
85
|
-
switch (this.tagName) {
|
|
86
|
-
case 'button':
|
|
87
|
-
case 'select':
|
|
88
|
-
case 'textarea':
|
|
89
|
-
return true
|
|
90
|
-
case 'input':
|
|
91
|
-
return String(this.getAttribute('type') || '').toLowerCase() !== 'hidden'
|
|
92
|
-
case 'a':
|
|
93
|
-
return this.hasAttribute('href') || this.hasAttribute('tabindex')
|
|
94
|
-
default:
|
|
95
|
-
return this.hasAttribute('tabindex')
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
101
|
-
* script made it (so it is not trusted). A disabled element does nothing.
|
|
102
|
-
*/
|
|
103
|
-
click () {
|
|
104
|
-
if (this.hasAttribute('disabled')) {
|
|
105
|
-
return
|
|
106
|
-
}
|
|
107
|
-
this.dispatchEvent((0, createEvent_1.default)('click', {}, {
|
|
108
|
-
browser: true
|
|
109
|
-
}))
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
114
|
-
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
115
|
-
* focus or already has it.
|
|
116
|
-
*/
|
|
117
|
-
focus () {
|
|
118
|
-
const root = this.getRootNode()
|
|
119
|
-
const previous = (0, activeElement_1.getActiveElement)(root)
|
|
120
|
-
if (!this.canFocus || previous === this) {
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
const send = (target, type, relatedTarget) => {
|
|
124
|
-
target.dispatchEvent((0, createEvent_1.default)(type, {
|
|
125
|
-
relatedTarget
|
|
126
|
-
}, {
|
|
127
|
-
browser: true,
|
|
128
|
-
trusted: true
|
|
129
|
-
}))
|
|
130
|
-
}
|
|
131
|
-
if (previous) {
|
|
132
|
-
send(previous, 'blur', this)
|
|
133
|
-
send(previous, 'focusout', this)
|
|
134
|
-
}
|
|
135
|
-
(0, activeElement_1.setActiveElement)(root, this)
|
|
136
|
-
send(this, 'focus', previous)
|
|
137
|
-
send(this, 'focusin', previous)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
142
|
-
*/
|
|
143
|
-
blur () {
|
|
144
|
-
const root = this.getRootNode()
|
|
145
|
-
if ((0, activeElement_1.getActiveElement)(root) !== this) {
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
(0, activeElement_1.setActiveElement)(root, null)
|
|
149
|
-
this.dispatchEvent((0, createEvent_1.default)('blur', {
|
|
150
|
-
relatedTarget: null
|
|
151
|
-
}, {
|
|
152
|
-
browser: true,
|
|
153
|
-
trusted: true
|
|
154
|
-
}))
|
|
155
|
-
this.dispatchEvent((0, createEvent_1.default)('focusout', {
|
|
156
|
-
relatedTarget: null
|
|
157
|
-
}, {
|
|
158
|
-
browser: true,
|
|
159
|
-
trusted: true
|
|
160
|
-
}))
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.HTMLElementService = HTMLElementService
|
|
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.HTMLElementService = void 0
|
|
14
|
+
const ElementService_1 = require('./ElementService')
|
|
15
|
+
const createEvent_1 = __importDefault(require('../factories/createEvent'))
|
|
16
|
+
const activeElement_1 = require('../functions/activeElement')
|
|
17
|
+
/**
|
|
18
|
+
* Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
19
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
20
|
+
* @class
|
|
21
|
+
* @augments PseudoElement
|
|
22
|
+
* @property {boolean} hidden - State of whether element is visible
|
|
23
|
+
* @property {number} offsetHeight - The height of the element as offset by the parent element
|
|
24
|
+
* @property {number} offsetLeft - The position of the left side of the element based on the parent element
|
|
25
|
+
* @property {PseudoHTMLElement} offsetParent - A reference to the closest positioned parent element
|
|
26
|
+
* @property {number} offsetTop - The position of the top side of the element based on the parent element
|
|
27
|
+
* @property {number} offsetWidth - The width of the element as offset by the parent element
|
|
28
|
+
* @property {Object} style - A container to define all applied inline-styles
|
|
29
|
+
* @property {string} title - The title attribute which affects the text visible on hover
|
|
30
|
+
*/
|
|
31
|
+
class HTMLElementService extends ElementService_1.ElementService {
|
|
32
|
+
/**
|
|
33
|
+
* Simulate the HTMLElement object when the Dom is not available
|
|
34
|
+
* @param {Object} [elementOptions={}]
|
|
35
|
+
* @param {string} [elementOptions.tagName='']
|
|
36
|
+
* @param {PseudoNode|Object} [elementOptions.parent={}]
|
|
37
|
+
* @param {Array} [elementOptions.children=[]]
|
|
38
|
+
* @constructor
|
|
39
|
+
*/
|
|
40
|
+
constructor ({
|
|
41
|
+
tagName = '',
|
|
42
|
+
parent = null,
|
|
43
|
+
children = []
|
|
44
|
+
} = {}) {
|
|
45
|
+
super({
|
|
46
|
+
tagName,
|
|
47
|
+
attributes: [{
|
|
48
|
+
name: 'hidden',
|
|
49
|
+
value: false
|
|
50
|
+
}, {
|
|
51
|
+
name: 'offsetHeight',
|
|
52
|
+
value: 0
|
|
53
|
+
}, {
|
|
54
|
+
name: 'offsetLeft',
|
|
55
|
+
value: 0
|
|
56
|
+
}, {
|
|
57
|
+
name: 'offsetParent',
|
|
58
|
+
value: null
|
|
59
|
+
}, {
|
|
60
|
+
name: 'offsetTop',
|
|
61
|
+
value: 0
|
|
62
|
+
}, {
|
|
63
|
+
name: 'offsetWidth',
|
|
64
|
+
value: 0
|
|
65
|
+
}, {
|
|
66
|
+
name: 'style',
|
|
67
|
+
value: {}
|
|
68
|
+
}, {
|
|
69
|
+
name: 'title',
|
|
70
|
+
value: ''
|
|
71
|
+
}],
|
|
72
|
+
parent,
|
|
73
|
+
children
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
79
|
+
* @returns {boolean}
|
|
80
|
+
*/
|
|
81
|
+
get canFocus () {
|
|
82
|
+
if (this.hasAttribute('disabled')) {
|
|
83
|
+
return false
|
|
84
|
+
}
|
|
85
|
+
switch (this.tagName) {
|
|
86
|
+
case 'button':
|
|
87
|
+
case 'select':
|
|
88
|
+
case 'textarea':
|
|
89
|
+
return true
|
|
90
|
+
case 'input':
|
|
91
|
+
return String(this.getAttribute('type') || '').toLowerCase() !== 'hidden'
|
|
92
|
+
case 'a':
|
|
93
|
+
return this.hasAttribute('href') || this.hasAttribute('tabindex')
|
|
94
|
+
default:
|
|
95
|
+
return this.hasAttribute('tabindex')
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Click the element: a click event is sent to it, which bubbles and can be cancelled, like one from a user but a
|
|
101
|
+
* script made it (so it is not trusted). A disabled element does nothing.
|
|
102
|
+
*/
|
|
103
|
+
click () {
|
|
104
|
+
if (this.hasAttribute('disabled')) {
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
this.dispatchEvent((0, createEvent_1.default)('click', {}, {
|
|
108
|
+
browser: true
|
|
109
|
+
}))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Give the element the focus. The element which had it gets blur then focusout, and this one gets focus then
|
|
114
|
+
* focusin (blur and focus do not bubble, focusin and focusout do). Nothing happens when the element cannot have the
|
|
115
|
+
* focus or already has it.
|
|
116
|
+
*/
|
|
117
|
+
focus () {
|
|
118
|
+
const root = this.getRootNode()
|
|
119
|
+
const previous = (0, activeElement_1.getActiveElement)(root)
|
|
120
|
+
if (!this.canFocus || previous === this) {
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
const send = (target, type, relatedTarget) => {
|
|
124
|
+
target.dispatchEvent((0, createEvent_1.default)(type, {
|
|
125
|
+
relatedTarget
|
|
126
|
+
}, {
|
|
127
|
+
browser: true,
|
|
128
|
+
trusted: true
|
|
129
|
+
}))
|
|
130
|
+
}
|
|
131
|
+
if (previous) {
|
|
132
|
+
send(previous, 'blur', this)
|
|
133
|
+
send(previous, 'focusout', this)
|
|
134
|
+
}
|
|
135
|
+
(0, activeElement_1.setActiveElement)(root, this)
|
|
136
|
+
send(this, 'focus', previous)
|
|
137
|
+
send(this, 'focusin', previous)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Take the focus away from the element, when it has it: it gets blur then focusout.
|
|
142
|
+
*/
|
|
143
|
+
blur () {
|
|
144
|
+
const root = this.getRootNode()
|
|
145
|
+
if ((0, activeElement_1.getActiveElement)(root) !== this) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
(0, activeElement_1.setActiveElement)(root, null)
|
|
149
|
+
this.dispatchEvent((0, createEvent_1.default)('blur', {
|
|
150
|
+
relatedTarget: null
|
|
151
|
+
}, {
|
|
152
|
+
browser: true,
|
|
153
|
+
trusted: true
|
|
154
|
+
}))
|
|
155
|
+
this.dispatchEvent((0, createEvent_1.default)('focusout', {
|
|
156
|
+
relatedTarget: null
|
|
157
|
+
}, {
|
|
158
|
+
browser: true,
|
|
159
|
+
trusted: true
|
|
160
|
+
}))
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.HTMLElementService = HTMLElementService
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PseudoHTMLSlotElement } from '../interfaces/PseudoHTMLSlotElement';
|
|
2
|
-
import { HTMLElementService } from './HTMLElementService';
|
|
3
|
-
export declare class HTMLSlotElementService extends HTMLElementService implements Partial<PseudoHTMLSlotElement> {
|
|
4
|
-
}
|
|
1
|
+
import { PseudoHTMLSlotElement } from '../interfaces/PseudoHTMLSlotElement';
|
|
2
|
+
import { HTMLElementService } from './HTMLElementService';
|
|
3
|
+
export declare class HTMLSlotElementService extends HTMLElementService implements Partial<PseudoHTMLSlotElement> {
|
|
4
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
exports.HTMLSlotElementService = void 0
|
|
7
|
-
const HTMLElementService_1 = require('./HTMLElementService')
|
|
8
|
-
class HTMLSlotElementService extends HTMLElementService_1.HTMLElementService {}
|
|
9
|
-
exports.HTMLSlotElementService = HTMLSlotElementService
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
exports.HTMLSlotElementService = void 0
|
|
7
|
+
const HTMLElementService_1 = require('./HTMLElementService')
|
|
8
|
+
class HTMLSlotElementService extends HTMLElementService_1.HTMLElementService {}
|
|
9
|
+
exports.HTMLSlotElementService = HTMLSlotElementService
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Substitute for the DOM InputEvent Class.
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
5
|
-
*/
|
|
6
|
-
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
-
/**
|
|
8
|
-
* The options for creating an input event, on top of the ones every UI event has.
|
|
9
|
-
* @typedef {Object} InputEventInit
|
|
10
|
-
* @property {string|null} [data=null] The characters which were entered
|
|
11
|
-
* @property {string} [inputType=''] What kind of change it was, such as insertText
|
|
12
|
-
* @property {boolean} [isComposing=false]
|
|
13
|
-
*/
|
|
14
|
-
export type InputEventInit = UIEventInit & {
|
|
15
|
-
data?: string | null;
|
|
16
|
-
inputType?: string;
|
|
17
|
-
isComposing?: boolean;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Simulate the behaviour of the InputEvent Class when there is no DOM available.
|
|
21
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
22
|
-
* @class
|
|
23
|
-
* @augments UIEventService
|
|
24
|
-
* @property {string|null} data
|
|
25
|
-
* @property {string} inputType
|
|
26
|
-
* @property {boolean} isComposing
|
|
27
|
-
*/
|
|
28
|
-
export declare class InputEventService extends UIEventService {
|
|
29
|
-
private readonly inputData;
|
|
30
|
-
private readonly kind;
|
|
31
|
-
private readonly composing;
|
|
32
|
-
/**
|
|
33
|
-
* @param {string} [typeArg=''] The type of the event
|
|
34
|
-
* @param {InputEventInit} [init={}] The options for the event
|
|
35
|
-
* @constructor
|
|
36
|
-
*/
|
|
37
|
-
constructor(typeArg?: string, init?: InputEventInit);
|
|
38
|
-
get data(): string | null;
|
|
39
|
-
get inputType(): string;
|
|
40
|
-
get isComposing(): boolean;
|
|
41
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @file Substitute for the DOM InputEvent Class.
|
|
3
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { UIEventInit, UIEventService } from './UIEventService';
|
|
7
|
+
/**
|
|
8
|
+
* The options for creating an input event, on top of the ones every UI event has.
|
|
9
|
+
* @typedef {Object} InputEventInit
|
|
10
|
+
* @property {string|null} [data=null] The characters which were entered
|
|
11
|
+
* @property {string} [inputType=''] What kind of change it was, such as insertText
|
|
12
|
+
* @property {boolean} [isComposing=false]
|
|
13
|
+
*/
|
|
14
|
+
export type InputEventInit = UIEventInit & {
|
|
15
|
+
data?: string | null;
|
|
16
|
+
inputType?: string;
|
|
17
|
+
isComposing?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Simulate the behaviour of the InputEvent Class when there is no DOM available.
|
|
21
|
+
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
22
|
+
* @class
|
|
23
|
+
* @augments UIEventService
|
|
24
|
+
* @property {string|null} data
|
|
25
|
+
* @property {string} inputType
|
|
26
|
+
* @property {boolean} isComposing
|
|
27
|
+
*/
|
|
28
|
+
export declare class InputEventService extends UIEventService {
|
|
29
|
+
private readonly inputData;
|
|
30
|
+
private readonly kind;
|
|
31
|
+
private readonly composing;
|
|
32
|
+
/**
|
|
33
|
+
* @param {string} [typeArg=''] The type of the event
|
|
34
|
+
* @param {InputEventInit} [init={}] The options for the event
|
|
35
|
+
* @constructor
|
|
36
|
+
*/
|
|
37
|
+
constructor(typeArg?: string, init?: InputEventInit);
|
|
38
|
+
get data(): string | null;
|
|
39
|
+
get inputType(): string;
|
|
40
|
+
get isComposing(): boolean;
|
|
41
|
+
}
|