pseudo-dom 0.5.1 → 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.
Files changed (122) hide show
  1. package/README.md +1495 -119
  2. package/browser/pseudo-dom.js +3539 -482
  3. package/browser/pseudo-dom.min.js +1 -1
  4. package/dist/classes/PseudoEventListener.d.ts +96 -96
  5. package/dist/classes/PseudoEventListener.js +151 -151
  6. package/dist/classes/PseudoHTMLDocument.d.ts +67 -67
  7. package/dist/classes/PseudoHTMLDocument.js +144 -144
  8. package/dist/classes/PseudoNodeList.d.ts +34 -34
  9. package/dist/classes/PseudoNodeList.js +71 -71
  10. package/dist/classes.d.ts +20 -20
  11. package/dist/classes.js +31 -31
  12. package/dist/factories/createEvent.d.ts +28 -28
  13. package/dist/factories/createEvent.js +56 -56
  14. package/dist/factories/cssSelectAdapter.d.ts +23 -0
  15. package/dist/factories/cssSelectAdapter.js +87 -0
  16. package/dist/factories/cssSelectAdapter.min.js +1 -0
  17. package/dist/factories/eventDefaults.d.ts +31 -31
  18. package/dist/factories/eventDefaults.js +105 -105
  19. package/dist/factories/generateDocument.d.ts +11 -11
  20. package/dist/factories/generateDocument.js +65 -65
  21. package/dist/factories/generateNode.d.ts +32 -32
  22. package/dist/factories/generateNode.js +85 -85
  23. package/dist/factories/generateNodeList.d.ts +9 -9
  24. package/dist/factories/generateNodeList.js +13 -13
  25. package/dist/factories/query.d.ts +33 -0
  26. package/dist/factories/query.js +66 -0
  27. package/dist/factories/query.min.js +1 -0
  28. package/dist/factories.d.ts +11 -11
  29. package/dist/factories.js +27 -27
  30. package/dist/functions/activeElement.d.ts +14 -14
  31. package/dist/functions/activeElement.js +33 -33
  32. package/dist/functions/getParentNodes.d.ts +11 -11
  33. package/dist/functions/getParentNodes.js +22 -22
  34. package/dist/functions/getParentNodesFromAttribute.d.ts +14 -14
  35. package/dist/functions/getParentNodesFromAttribute.js +29 -29
  36. package/dist/functions/modifierState.d.ts +29 -29
  37. package/dist/functions/modifierState.js +41 -41
  38. package/dist/functions.d.ts +5 -5
  39. package/dist/functions.js +23 -23
  40. package/dist/interfaces/PseudoAnimation.d.ts +3 -3
  41. package/dist/interfaces/PseudoAnimation.js +5 -5
  42. package/dist/interfaces/PseudoAttr.d.ts +11 -11
  43. package/dist/interfaces/PseudoAttr.js +5 -5
  44. package/dist/interfaces/PseudoDOMTokenList.d.ts +16 -16
  45. package/dist/interfaces/PseudoDOMTokenList.js +5 -5
  46. package/dist/interfaces/PseudoDocument.d.ts +7 -0
  47. package/dist/interfaces/PseudoDocument.js +5 -5
  48. package/dist/interfaces/PseudoDocumentFragment.d.ts +3 -3
  49. package/dist/interfaces/PseudoDocumentFragment.js +5 -5
  50. package/dist/interfaces/PseudoElement.d.ts +48 -24
  51. package/dist/interfaces/PseudoElement.js +5 -5
  52. package/dist/interfaces/PseudoEvent.d.ts +79 -79
  53. package/dist/interfaces/PseudoEvent.js +10 -10
  54. package/dist/interfaces/PseudoEventTarget.d.ts +46 -46
  55. package/dist/interfaces/PseudoEventTarget.js +5 -5
  56. package/dist/interfaces/PseudoHTMLCollection.d.ts +23 -2
  57. package/dist/interfaces/PseudoHTMLCollection.js +5 -5
  58. package/dist/interfaces/PseudoHTMLElement.d.ts +22 -22
  59. package/dist/interfaces/PseudoHTMLElement.js +5 -5
  60. package/dist/interfaces/PseudoHTMLSlotElement.d.ts +3 -3
  61. package/dist/interfaces/PseudoHTMLSlotElement.js +5 -5
  62. package/dist/interfaces/PseudoNamedNodeMap.d.ts +11 -11
  63. package/dist/interfaces/PseudoNamedNodeMap.js +5 -5
  64. package/dist/interfaces/PseudoNode.d.ts +179 -179
  65. package/dist/interfaces/PseudoNode.js +5 -5
  66. package/dist/interfaces/PseudoShadowRoot.d.ts +3 -3
  67. package/dist/interfaces/PseudoShadowRoot.js +5 -5
  68. package/dist/main.d.ts +63 -63
  69. package/dist/main.js +155 -155
  70. package/dist/services/AnimationService.d.ts +4 -4
  71. package/dist/services/AnimationService.js +16 -16
  72. package/dist/services/AttrService.d.ts +37 -37
  73. package/dist/services/AttrService.js +81 -81
  74. package/dist/services/CommentService.d.ts +1 -1
  75. package/dist/services/CommentService.js +13 -13
  76. package/dist/services/CustomEventService.d.ts +37 -37
  77. package/dist/services/CustomEventService.js +35 -35
  78. package/dist/services/DOMTokenListService.d.ts +33 -33
  79. package/dist/services/DOMTokenListService.js +117 -117
  80. package/dist/services/DocumentFragmentService.d.ts +13 -13
  81. package/dist/services/DocumentFragmentService.js +24 -24
  82. package/dist/services/DocumentService.d.ts +7 -0
  83. package/dist/services/DocumentService.js +23 -0
  84. package/dist/services/DocumentService.min.js +1 -1
  85. package/dist/services/ElementService.d.ts +77 -1
  86. package/dist/services/ElementService.js +143 -0
  87. package/dist/services/ElementService.min.js +1 -1
  88. package/dist/services/EventService.d.ts +120 -120
  89. package/dist/services/EventService.js +250 -250
  90. package/dist/services/EventTargetService.d.ts +84 -84
  91. package/dist/services/EventTargetService.js +232 -232
  92. package/dist/services/FocusEventService.d.ts +32 -32
  93. package/dist/services/FocusEventService.js +35 -35
  94. package/dist/services/HTMLCollectionService.d.ts +51 -0
  95. package/dist/services/HTMLCollectionService.js +85 -1
  96. package/dist/services/HTMLCollectionService.min.js +1 -1
  97. package/dist/services/HTMLElementService.d.ts +57 -57
  98. package/dist/services/HTMLElementService.js +163 -163
  99. package/dist/services/HTMLSlotElementService.d.ts +4 -4
  100. package/dist/services/HTMLSlotElementService.js +9 -9
  101. package/dist/services/InputEventService.d.ts +41 -41
  102. package/dist/services/InputEventService.js +47 -47
  103. package/dist/services/KeyboardEventService.d.ts +70 -70
  104. package/dist/services/KeyboardEventService.js +86 -86
  105. package/dist/services/MouseEventService.d.ts +80 -80
  106. package/dist/services/MouseEventService.js +108 -108
  107. package/dist/services/NamedNodeMapService.d.ts +23 -23
  108. package/dist/services/NamedNodeMapService.js +77 -77
  109. package/dist/services/NodeService.d.ts +75 -1
  110. package/dist/services/NodeService.js +145 -7
  111. package/dist/services/NodeService.min.js +1 -1
  112. package/dist/services/PointerEventService.d.ts +51 -51
  113. package/dist/services/PointerEventService.js +67 -67
  114. package/dist/services/ShadowRootService.d.ts +4 -4
  115. package/dist/services/ShadowRootService.js +9 -9
  116. package/dist/services/TextService.d.ts +1 -1
  117. package/dist/services/TextService.js +13 -13
  118. package/dist/services/UIEventService.d.ts +43 -43
  119. package/dist/services/UIEventService.js +42 -42
  120. package/dist/simulate.d.ts +32 -32
  121. package/dist/simulate.js +115 -115
  122. package/package.json +3 -2
@@ -1,42 +1,42 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.UIEventService = void 0
7
- /**
8
- * @file Substitute for the DOM UIEvent Class.
9
- * @author Joshua Heagle <joshuaheagle@gmail.com>
10
- * @version 1.0.0
11
- */
12
- const EventService_1 = require('./EventService')
13
- /**
14
- * Simulate the behaviour of the UIEvent Class when there is no DOM available: the events which come from a user
15
- * interface (the mouse, the keyboard, focus and input).
16
- * @author Joshua Heagle <joshuaheagle@gmail.com>
17
- * @class
18
- * @augments EventService
19
- * @property {number} detail
20
- * @property {*} view
21
- */
22
- class UIEventService extends EventService_1.EventService {
23
- /**
24
- * @param {string} [typeArg=''] The type of the event
25
- * @param {UIEventInit} [init={}] The options for the event
26
- * @constructor
27
- */
28
- constructor (typeArg = '', init = {}) {
29
- super(typeArg, init)
30
- this.uiDetail = init.detail || 0
31
- this.uiView = init.view || null
32
- }
33
-
34
- get detail () {
35
- return this.uiDetail
36
- }
37
-
38
- get view () {
39
- return this.uiView
40
- }
41
- }
42
- exports.UIEventService = UIEventService
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.UIEventService = void 0
7
+ /**
8
+ * @file Substitute for the DOM UIEvent Class.
9
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
10
+ * @version 1.0.0
11
+ */
12
+ const EventService_1 = require('./EventService')
13
+ /**
14
+ * Simulate the behaviour of the UIEvent Class when there is no DOM available: the events which come from a user
15
+ * interface (the mouse, the keyboard, focus and input).
16
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
17
+ * @class
18
+ * @augments EventService
19
+ * @property {number} detail
20
+ * @property {*} view
21
+ */
22
+ class UIEventService extends EventService_1.EventService {
23
+ /**
24
+ * @param {string} [typeArg=''] The type of the event
25
+ * @param {UIEventInit} [init={}] The options for the event
26
+ * @constructor
27
+ */
28
+ constructor (typeArg = '', init = {}) {
29
+ super(typeArg, init)
30
+ this.uiDetail = init.detail || 0
31
+ this.uiView = init.view || null
32
+ }
33
+
34
+ get detail () {
35
+ return this.uiDetail
36
+ }
37
+
38
+ get view () {
39
+ return this.uiView
40
+ }
41
+ }
42
+ exports.UIEventService = UIEventService
@@ -1,32 +1,32 @@
1
- /**
2
- * Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
3
- * can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
4
- * and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
5
- * @function click
6
- * @param {*} element The element to click
7
- * @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
8
- * @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
9
- */
10
- export declare const click: (element: any, init?: {
11
- [option: string]: any;
12
- }) => boolean;
13
- /**
14
- * Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
15
- * @function keyPress
16
- * @param {*} element The element which gets the key
17
- * @param {string} key The value of the key, such as a or Enter
18
- * @param {Object} [init={}] Options for the events (for example code, shiftKey)
19
- * @returns {boolean} False when keydown was cancelled, so its default action did not happen
20
- */
21
- export declare const keyPress: (element: any, key: string, init?: {
22
- [option: string]: any;
23
- }) => boolean;
24
- declare const _default: {
25
- click: (element: any, init?: {
26
- [option: string]: any;
27
- }) => boolean;
28
- keyPress: (element: any, key: string, init?: {
29
- [option: string]: any;
30
- }) => boolean;
31
- };
32
- export default _default;
1
+ /**
2
+ * Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
3
+ * can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
4
+ * and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
5
+ * @function click
6
+ * @param {*} element The element to click
7
+ * @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
8
+ * @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
9
+ */
10
+ export declare const click: (element: any, init?: {
11
+ [option: string]: any;
12
+ }) => boolean;
13
+ /**
14
+ * Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
15
+ * @function keyPress
16
+ * @param {*} element The element which gets the key
17
+ * @param {string} key The value of the key, such as a or Enter
18
+ * @param {Object} [init={}] Options for the events (for example code, shiftKey)
19
+ * @returns {boolean} False when keydown was cancelled, so its default action did not happen
20
+ */
21
+ export declare const keyPress: (element: any, key: string, init?: {
22
+ [option: string]: any;
23
+ }) => boolean;
24
+ declare const _default: {
25
+ click: (element: any, init?: {
26
+ [option: string]: any;
27
+ }) => boolean;
28
+ keyPress: (element: any, key: string, init?: {
29
+ [option: string]: any;
30
+ }) => boolean;
31
+ };
32
+ export default _default;
package/dist/simulate.js CHANGED
@@ -1,115 +1,115 @@
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.keyPress = exports.click = void 0
14
- /**
15
- * @file Simulate what a user does, with the events the browser sends for it.
16
- * @author Joshua Heagle <joshuaheagle@gmail.com>
17
- * @version 1.0.0
18
- * @module pseudoDom/simulate
19
- */
20
- const createEvent_1 = __importDefault(require('./factories/createEvent'))
21
- const activeElement_1 = require('./functions/activeElement')
22
- const send = (target, type, init) => target.dispatchEvent((0, createEvent_1.default)(type, init, {
23
- browser: true,
24
- trusted: true
25
- }))
26
- /**
27
- * The nearest element (starting with the element itself) which can have the focus.
28
- * @param {*} element Where to start
29
- * @returns {*|null}
30
- */
31
- const focusableFrom = element => {
32
- let current = element
33
- while (current) {
34
- if (current.canFocus) {
35
- return current
36
- }
37
- current = current.parentNode
38
- }
39
- return null
40
- }
41
- /**
42
- * Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
43
- * can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
44
- * and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
45
- * @function click
46
- * @param {*} element The element to click
47
- * @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
48
- * @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
49
- */
50
- const click = (element, init = {}) => {
51
- if (element.hasAttribute && element.hasAttribute('disabled')) {
52
- return false
53
- }
54
- const pointer = Object.assign({
55
- pointerId: 1,
56
- pointerType: 'mouse',
57
- isPrimary: true,
58
- button: 0
59
- }, init)
60
- send(element, 'pointerdown', Object.assign({
61
- buttons: 1
62
- }, pointer))
63
- if (send(element, 'mousedown', Object.assign({
64
- buttons: 1,
65
- detail: 1
66
- }, init, {
67
- button: 0
68
- }))) {
69
- const focusable = focusableFrom(element)
70
- if (focusable) {
71
- focusable.focus()
72
- } else {
73
- const active = (0, activeElement_1.getActiveElement)(element.getRootNode())
74
- if (active) {
75
- active.blur()
76
- }
77
- }
78
- }
79
- send(element, 'pointerup', Object.assign({
80
- buttons: 0
81
- }, pointer))
82
- send(element, 'mouseup', Object.assign({
83
- buttons: 0,
84
- detail: 1
85
- }, init, {
86
- button: 0
87
- }))
88
- return send(element, 'click', Object.assign({
89
- detail: 1
90
- }, init, {
91
- button: 0
92
- }))
93
- }
94
- exports.click = click
95
- /**
96
- * Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
97
- * @function keyPress
98
- * @param {*} element The element which gets the key
99
- * @param {string} key The value of the key, such as a or Enter
100
- * @param {Object} [init={}] Options for the events (for example code, shiftKey)
101
- * @returns {boolean} False when keydown was cancelled, so its default action did not happen
102
- */
103
- const keyPress = (element, key, init = {}) => {
104
- const options = Object.assign({
105
- key
106
- }, init)
107
- const proceeded = send(element, 'keydown', options)
108
- send(element, 'keyup', options)
109
- return proceeded
110
- }
111
- exports.keyPress = keyPress
112
- exports.default = {
113
- click: exports.click,
114
- keyPress: exports.keyPress
115
- }
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.keyPress = exports.click = void 0
14
+ /**
15
+ * @file Simulate what a user does, with the events the browser sends for it.
16
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
17
+ * @version 1.0.0
18
+ * @module pseudoDom/simulate
19
+ */
20
+ const createEvent_1 = __importDefault(require('./factories/createEvent'))
21
+ const activeElement_1 = require('./functions/activeElement')
22
+ const send = (target, type, init) => target.dispatchEvent((0, createEvent_1.default)(type, init, {
23
+ browser: true,
24
+ trusted: true
25
+ }))
26
+ /**
27
+ * The nearest element (starting with the element itself) which can have the focus.
28
+ * @param {*} element Where to start
29
+ * @returns {*|null}
30
+ */
31
+ const focusableFrom = element => {
32
+ let current = element
33
+ while (current) {
34
+ if (current.canFocus) {
35
+ return current
36
+ }
37
+ current = current.parentNode
38
+ }
39
+ return null
40
+ }
41
+ /**
42
+ * Click an element the way a user does: pointerdown and mousedown, then the focus moves to the nearest element which
43
+ * can have it (or is taken away from the one which had it) unless mousedown was cancelled, then pointerup, mouseup
44
+ * and finally click. Every event is trusted and has the options the browser gives it. A disabled element gets nothing.
45
+ * @function click
46
+ * @param {*} element The element to click
47
+ * @param {Object} [init={}] Options for the events (for example clientX, clientY, shiftKey)
48
+ * @returns {boolean} False when the click was cancelled (or the element is disabled), so its default action did not happen
49
+ */
50
+ const click = (element, init = {}) => {
51
+ if (element.hasAttribute && element.hasAttribute('disabled')) {
52
+ return false
53
+ }
54
+ const pointer = Object.assign({
55
+ pointerId: 1,
56
+ pointerType: 'mouse',
57
+ isPrimary: true,
58
+ button: 0
59
+ }, init)
60
+ send(element, 'pointerdown', Object.assign({
61
+ buttons: 1
62
+ }, pointer))
63
+ if (send(element, 'mousedown', Object.assign({
64
+ buttons: 1,
65
+ detail: 1
66
+ }, init, {
67
+ button: 0
68
+ }))) {
69
+ const focusable = focusableFrom(element)
70
+ if (focusable) {
71
+ focusable.focus()
72
+ } else {
73
+ const active = (0, activeElement_1.getActiveElement)(element.getRootNode())
74
+ if (active) {
75
+ active.blur()
76
+ }
77
+ }
78
+ }
79
+ send(element, 'pointerup', Object.assign({
80
+ buttons: 0
81
+ }, pointer))
82
+ send(element, 'mouseup', Object.assign({
83
+ buttons: 0,
84
+ detail: 1
85
+ }, init, {
86
+ button: 0
87
+ }))
88
+ return send(element, 'click', Object.assign({
89
+ detail: 1
90
+ }, init, {
91
+ button: 0
92
+ }))
93
+ }
94
+ exports.click = click
95
+ /**
96
+ * Press and release a key on an element (the element which has the focus, or one given): keydown and then keyup.
97
+ * @function keyPress
98
+ * @param {*} element The element which gets the key
99
+ * @param {string} key The value of the key, such as a or Enter
100
+ * @param {Object} [init={}] Options for the events (for example code, shiftKey)
101
+ * @returns {boolean} False when keydown was cancelled, so its default action did not happen
102
+ */
103
+ const keyPress = (element, key, init = {}) => {
104
+ const options = Object.assign({
105
+ key
106
+ }, init)
107
+ const proceeded = send(element, 'keydown', options)
108
+ send(element, 'keyup', options)
109
+ return proceeded
110
+ }
111
+ exports.keyPress = keyPress
112
+ exports.default = {
113
+ click: exports.click,
114
+ keyPress: exports.keyPress
115
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pseudo-dom",
3
3
  "description": "Mock the DOM on the server side for managing state and testing",
4
- "version": "0.5.1",
4
+ "version": "0.7.0",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
7
7
  "author": "Joshua Heagle",
@@ -20,10 +20,11 @@
20
20
  "dependencies": {
21
21
  "collect-your-stuff": "^2.1.1",
22
22
  "core-js": "^3.50.0",
23
+ "css-select": "^6.0.0",
23
24
  "si-funciona": "^2.6.1"
24
25
  },
25
26
  "devDependencies": {
26
- "js-build-tools": "^5.0.0",
27
+ "js-build-tools": "^5.2.0",
27
28
  "jsdoc": "^4.0.5",
28
29
  "standard": "^17.1.2",
29
30
  "test-filesystem": "^1.5.1"