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
@@ -4,10 +4,11 @@
4
4
  * @version 1.0.0
5
5
  */
6
6
  import { PseudoNode } from '../interfaces/PseudoNode';
7
- import { NodeService } from './NodeService';
8
7
  import { PseudoElement } from '../interfaces/PseudoElement';
8
+ import { NodeService } from './NodeService';
9
9
  import { PseudoNamedNodeMap } from '../interfaces/PseudoNamedNodeMap';
10
10
  import { PseudoDOMTokenList } from '../interfaces/PseudoDOMTokenList';
11
+ import { PseudoHTMLCollection } from '../interfaces/PseudoHTMLCollection';
11
12
  type attribute = {
12
13
  name: string;
13
14
  value: any;
@@ -80,6 +81,81 @@ export declare class ElementService extends NodeService implements Partial<Pseud
80
81
  * Some elements have default behaviour, this registers it when the element is added.
81
82
  * @returns {Function}
82
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;
83
159
  applyDefaultEvent(): Function;
84
160
  /**
85
161
  * An element which is added as a child gets its default events (for example a submit button submits its form).
@@ -23,8 +23,10 @@ const AttrService_1 = require('./AttrService')
23
23
  const DOMTokenListService_1 = require('./DOMTokenListService')
24
24
  const NamedNodeMapService_1 = require('./NamedNodeMapService')
25
25
  const getParentNodesFromAttribute_1 = __importDefault(require('../functions/getParentNodesFromAttribute'))
26
+ const HTMLCollectionService_1 = require('./HTMLCollectionService')
26
27
  const cloneObject_1 = __importDefault(require('si-funciona/dist/helpers/objects/cloneObject'))
27
28
  const isEqual_1 = __importDefault(require('si-funciona/dist/helpers/objects/isEqual'))
29
+ const query_1 = require('../factories/query')
28
30
  /**
29
31
  * Simulate the behaviour of the Element Class when there is no DOM available.
30
32
  * @author Joshua Heagle <joshuaheagle@gmail.com>
@@ -184,6 +186,147 @@ class ElementService extends NodeService_1.NodeService {
184
186
  * Some elements have default behaviour, this registers it when the element is added.
185
187
  * @returns {Function}
186
188
  */
189
+ /**
190
+ * A live view of this element's element children (text, comments and the like are not included).
191
+ * @returns {PseudoHTMLCollection}
192
+ */
193
+ get children () {
194
+ return new HTMLCollectionService_1.HTMLCollectionService(this)
195
+ }
196
+
197
+ /**
198
+ * How many element children this element has.
199
+ * @returns {number}
200
+ */
201
+ get childElementCount () {
202
+ return this.children.length
203
+ }
204
+
205
+ /**
206
+ * The first child of this element which is an element, or null when there is none.
207
+ * @returns {PseudoElement|null}
208
+ */
209
+ get firstElementChild () {
210
+ return this.children.item(0)
211
+ }
212
+
213
+ /**
214
+ * The last child of this element which is an element, or null when there is none.
215
+ * @returns {PseudoElement|null}
216
+ */
217
+ get lastElementChild () {
218
+ const elementChildren = this.children
219
+ return elementChildren.item(elementChildren.length - 1)
220
+ }
221
+
222
+ /**
223
+ * The sibling after this one which is an element, or null when there is none.
224
+ * @returns {PseudoElement|null}
225
+ */
226
+ get nextElementSibling () {
227
+ let sibling = this.nextSibling
228
+ while (sibling && sibling.nodeType !== NodeService_1.NodeService.ELEMENT_NODE) {
229
+ sibling = sibling.nextSibling
230
+ }
231
+ return sibling
232
+ }
233
+
234
+ /**
235
+ * The sibling before this one which is an element, or null when there is none.
236
+ * @returns {PseudoElement|null}
237
+ */
238
+ get previousElementSibling () {
239
+ let sibling = this.previousSibling
240
+ while (sibling && sibling.nodeType !== NodeService_1.NodeService.ELEMENT_NODE) {
241
+ sibling = sibling.previousSibling
242
+ }
243
+ return sibling
244
+ }
245
+
246
+ /**
247
+ * Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
248
+ * afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
249
+ * element, as its next sibling).
250
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
251
+ * @param {ElementService} element The element to insert
252
+ * @returns {ElementService|null} The inserted element, or null when the position needed a parent this element does not have
253
+ * @throws {Error} When the position is not one of the four above
254
+ */
255
+ insertAdjacentElement (position, element) {
256
+ return this.insertAdjacent(position, element)
257
+ }
258
+
259
+ /**
260
+ * Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
261
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
262
+ * @param {string} text The text to insert
263
+ * @throws {Error} When the position is not one of the four above
264
+ */
265
+ insertAdjacentText (position, text) {
266
+ this.insertAdjacent(position, text)
267
+ }
268
+
269
+ /**
270
+ * Shared implementation for insertAdjacentElement / insertAdjacentText.
271
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
272
+ * @param {PseudoNode|string} node The node (or text) to insert
273
+ * @returns {PseudoNode|null} The inserted node, or null when the position needed a parent this element does not have
274
+ * @throws {Error} When the position is not one of the four above
275
+ */
276
+ insertAdjacent (position, node) {
277
+ switch (position) {
278
+ case 'beforebegin':
279
+ if (!this.parentNode) {
280
+ return null
281
+ }
282
+ this.before(node)
283
+ return node
284
+ case 'afterbegin':
285
+ this.prepend(node)
286
+ return node
287
+ case 'beforeend':
288
+ this.append(node)
289
+ return node
290
+ case 'afterend':
291
+ if (!this.parentNode) {
292
+ return null
293
+ }
294
+ this.after(node)
295
+ return node
296
+ default:
297
+ throw new Error(`"${position}" is not one of beforebegin, afterbegin, beforeend or afterend.`)
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Not implemented yet (HTML parsing is out of scope for now).
303
+ * @param {string} position beforebegin, afterbegin, beforeend or afterend
304
+ * @param {string} text The markup which would be parsed
305
+ * @throws {Error}
306
+ */
307
+ insertAdjacentHTML (position, text) {
308
+ throw new Error('ElementService.insertAdjacentHTML() is not implemented yet.')
309
+ }
310
+
311
+ /**
312
+ * Whether this element itself (not its descendants) matches the given CSS selector.
313
+ * @param {string} selectors A CSS selector
314
+ * @returns {boolean}
315
+ */
316
+ matches (selectors) {
317
+ return (0, query_1.matches)(this, selectors)
318
+ }
319
+
320
+ /**
321
+ * The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
322
+ * null when none of them do.
323
+ * @param {string} selectors A CSS selector
324
+ * @returns {PseudoElement|null}
325
+ */
326
+ closest (selectors) {
327
+ return (0, query_1.closest)(this, selectors)
328
+ }
329
+
187
330
  applyDefaultEvent () {
188
331
  let callback = event => undefined
189
332
  if (this.defaultEventApplied) {
@@ -1 +1 @@
1
- "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual"));class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"innerHTML",value:""}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}}exports.ElementService=ElementService;
1
+ "use strict";require("core-js/modules/esnext.iterator.constructor.js"),require("core-js/modules/esnext.iterator.every.js"),require("core-js/modules/esnext.iterator.find.js"),require("core-js/modules/esnext.iterator.for-each.js"),require("core-js/modules/esnext.iterator.map.js"),require("core-js/modules/esnext.iterator.some.js");var __importDefault=function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ElementService=void 0;const createEvent_1=__importDefault(require("../factories/createEvent")),NodeService_1=require("./NodeService"),AttrService_1=require("./AttrService"),DOMTokenListService_1=require("./DOMTokenListService"),NamedNodeMapService_1=require("./NamedNodeMapService"),getParentNodesFromAttribute_1=__importDefault(require("../functions/getParentNodesFromAttribute")),HTMLCollectionService_1=require("./HTMLCollectionService"),cloneObject_1=__importDefault(require("si-funciona/dist/helpers/objects/cloneObject")),isEqual_1=__importDefault(require("si-funciona/dist/helpers/objects/isEqual")),query_1=require("../factories/query");class ElementService extends NodeService_1.NodeService{constructor({tagName:e="",attributes:t=[],parent:r=null,children:i=[]}={}){super(),this.defaultEventApplied=!1,this.tokenList=new DOMTokenListService_1.DOMTokenListService,this.tag=e,this.attributeList=t.concat([{name:"className",value:""},{name:"id",value:""},{name:"innerHTML",value:""}]),this.propertyAttributes=this.attributeList.map(({name:e})=>e),this.attributeList.forEach(({name:e,value:t})=>{this[e]=t}),i.forEach(e=>{if(!e||"number"!=typeof e.nodeType)throw new TypeError("The children of an element must be nodes.");this.appendChild(e)}),r&&r.appendChild(this)}currentAttributes(){return this.attributeList.map(({name:e,value:t})=>({name:e,value:this.propertyAttributes.indexOf(e)>=0?this[e]:t}))}get nodeName(){return this.tag}cloneShallow(){const e=new this.constructor({tagName:this.tag});return e.attributeList.length=0,this.currentAttributes().forEach(({name:t,value:r})=>{const i="object"==typeof r&&null!==r?(0,cloneObject_1.default)(r):r;e.attributeList.push({name:t,value:i}),e.propertyAttributes.indexOf(t)>=0&&(e[t]=i)}),e.ownerDocumentStore=this.ownerDocumentStore,e}equalsShallow(e){const t=this.currentAttributes(),r=e.currentAttributes();return this.nodeName===e.nodeName&&t.length===r.length&&t.every(({name:e,value:t})=>{const i=r.find(t=>t.name===e);return void 0!==i&&(0,isEqual_1.default)(t,i.value)})}get tagName(){return this.tag}get nodeType(){return NodeService_1.NodeService.ELEMENT_NODE}get attributes(){return new NamedNodeMapService_1.NamedNodeMapService(this.currentAttributes().map(({name:e,value:t})=>new AttrService_1.AttrService(e,String(t),this)))}get classList(){return this.tokenList}get className(){return this.tokenList.value}set className(e){this.tokenList.value=e}get children(){return new HTMLCollectionService_1.HTMLCollectionService(this)}get childElementCount(){return this.children.length}get firstElementChild(){return this.children.item(0)}get lastElementChild(){const e=this.children;return e.item(e.length-1)}get nextElementSibling(){let e=this.nextSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.nextSibling;return e}get previousElementSibling(){let e=this.previousSibling;for(;e&&e.nodeType!==NodeService_1.NodeService.ELEMENT_NODE;)e=e.previousSibling;return e}insertAdjacentElement(e,t){return this.insertAdjacent(e,t)}insertAdjacentText(e,t){this.insertAdjacent(e,t)}insertAdjacent(e,t){switch(e){case"beforebegin":return this.parentNode?(this.before(t),t):null;case"afterbegin":return this.prepend(t),t;case"beforeend":return this.append(t),t;case"afterend":return this.parentNode?(this.after(t),t):null;default:throw new Error(`"${e}" is not one of beforebegin, afterbegin, beforeend or afterend.`)}}insertAdjacentHTML(e,t){throw new Error("ElementService.insertAdjacentHTML() is not implemented yet.")}matches(e){return(0,query_1.matches)(this,e)}closest(e){return(0,query_1.closest)(this,e)}applyDefaultEvent(){let e=e=>{};if(this.defaultEventApplied)return e;switch(this.tagName){case"button":case"input":e=e=>{const t=String(this.getAttribute("type")||this.type||"").toLowerCase(),r="button"===this.tagName?"button"!==t&&"reset"!==t:/^(submit|image)$/.test(t),i=(0,getParentNodesFromAttribute_1.default)("tagName","form",this);r&&i.length&&!this.hasAttribute("disabled")&&i[i.length-1].dispatchEvent((0,createEvent_1.default)("submit",{},{browser:!0,trusted:e.isTrusted}))},super.setDefaultEvent("click",e),this.defaultEventApplied=!0}return e}childInserted(e){"function"==typeof e.applyDefaultEvent&&e.applyDefaultEvent()}hasAttribute(e){return this.attributeList.some(({name:t})=>t===e)}setAttribute(e,t){const r=this.attributeList.find(({name:t})=>t===e);r?r.value=t:this.attributeList.push({name:e,value:t}),this.propertyAttributes.indexOf(e)>=0&&(this[e]=t)}getAttribute(e){const t=this.currentAttributes().find(({name:t})=>t===e);return t?t.value:null}removeAttribute(e){const t=this.attributeList.findIndex(({name:t})=>t===e);t>=0&&this.attributeList.splice(t,1)}}exports.ElementService=ElementService;
@@ -1,120 +1,120 @@
1
- /**
2
- * @file Substitute for the DOM Event Class.
3
- * @author Joshua Heagle <joshuaheagle@gmail.com>
4
- * @version 1.0.0
5
- */
6
- import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
7
- import { PseudoEvent } from '../interfaces/PseudoEvent';
8
- /**
9
- * The parts of an event which the dispatching of it (EventTargetService) needs to change or read. Not part of the DOM's
10
- * Event, which is why they are kept apart from the event's own properties.
11
- */
12
- export type EventInner = {
13
- currentTarget: PseudoEventTarget | null;
14
- eventPhase: number;
15
- target: PseudoEventTarget;
16
- immediatePropagationStopped: boolean;
17
- propagationStopped: boolean;
18
- /** True for an event which the browser created for a user action, an event which a script created is not trusted. */
19
- trusted: boolean;
20
- /** True while the event is being dispatched. */
21
- dispatching: boolean;
22
- /** True while a passive listener is running, in which preventDefault does nothing. */
23
- inPassiveListener: boolean;
24
- /** The targets the event travels through, the target first and the root last, set while dispatching. */
25
- path: Array<PseudoEventTarget>;
26
- /** Finish the dispatch: no phase, no current target, no path and the stop flags are cleared so the event can be dispatched again. */
27
- finishDispatch: () => void;
28
- };
29
- /**
30
- * Simulate the behaviour of the Event Class when there is no DOM available.
31
- * @author Joshua Heagle <joshuaheagle@gmail.com>
32
- * @class
33
- * @property {number} NONE
34
- * @property {number} CAPTURING_PHASE
35
- * @property {number} AT_TARGET
36
- * @property {number} BUBBLING_PHASE
37
- * @property {boolean} bubbles - A Boolean indicating whether the event bubbles up through the Dom or not.
38
- * @property {boolean} cancelable - A Boolean indicating whether the event is cancelable.
39
- * @property {boolean} composed - A Boolean value indicating whether the event can bubble across the boundary
40
- * between the shadow Dom and the regular Dom.
41
- * @property {function|PseudoEventTarget} currentTarget - A reference to the currently registered target for the event. This
42
- * is the object to which the event is currently slated to be sent; it's possible this has been changed along the way
43
- * through re-targeting.
44
- * @property {boolean} defaultPrevented - Indicates whether event.preventDefault() has been called on the event.
45
- * @property {boolean} immediatePropagationStopped - Flag that no further propagation should occur, including on current
46
- * target.
47
- * @property {boolean} propagationStopped - Flag that no further propagation should occur.
48
- * @property {int} eventPhase - Indicates which phase of the event flow is being processed. Uses EventService constants.
49
- * @property {EventTarget|PseudoEventTarget} target - A reference to the target to which the event was originally
50
- * dispatched.
51
- * @property {int} timeStamp - The time at which the event was created (in milliseconds). By specification, this
52
- * value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this
53
- * to be a DomHighResTimeStamp instead.
54
- * @property {string} type - The name of the event (case-insensitive).
55
- * @property {boolean} isTrusted - Indicates whether the event was initiated by the browser (after a user
56
- * click for instance) or by a script (using an event creation method, like event.initEvent)
57
- */
58
- export declare class EventService implements PseudoEvent {
59
- static readonly NONE = 0;
60
- static readonly CAPTURING_PHASE = 1;
61
- static readonly AT_TARGET = 2;
62
- static readonly BUBBLING_PHASE = 3;
63
- private properties;
64
- /**
65
- *
66
- * @param {string} typeArg
67
- * @param {Object} [eventOptions={}]
68
- * @param {boolean} [eventOptions.bubbles=false]
69
- * @param {boolean} [eventOptions.cancelable=false]
70
- * @param {boolean} [eventOptions.composed=false]
71
- * @constructor
72
- */
73
- constructor(typeArg?: string, { bubbles, cancelable, composed }?: {
74
- bubbles?: boolean;
75
- cancelable?: boolean;
76
- composed?: boolean;
77
- });
78
- get bubbles(): boolean;
79
- get cancelable(): boolean;
80
- get composed(): boolean;
81
- get currentTarget(): PseudoEventTarget;
82
- get defaultPrevented(): boolean;
83
- get eventPhase(): number;
84
- get isTrusted(): boolean;
85
- get target(): PseudoEventTarget;
86
- get timeStamp(): number;
87
- get type(): string;
88
- /**
89
- * Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
90
- * @returns {EventInner}
91
- */
92
- get inner(): EventInner;
93
- /**
94
- * Return an array of targets that will have the event executed open them. The order is based on the eventPhase
95
- * @method
96
- * @returns {Array.<PseudoEventTarget>}
97
- */
98
- composedPath(): Array<PseudoEventTarget>;
99
- /**
100
- * Cancels the event (if it is cancelable).
101
- * @method
102
- * @returns {null}
103
- */
104
- preventDefault(): null;
105
- /**
106
- * For this particular event, no other listener will be called.
107
- * Neither those attached on the same element, nor those attached on elements which will be traversed later (in
108
- * capture phase, for instance)
109
- * @method
110
- * @returns {null}
111
- */
112
- stopImmediatePropagation(): null;
113
- /**
114
- * Stops the propagation of events further along in the Dom.
115
- * @method
116
- * @returns {null}
117
- */
118
- stopPropagation(): null;
119
- private setReadOnlyProperties;
120
- }
1
+ /**
2
+ * @file Substitute for the DOM Event Class.
3
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
4
+ * @version 1.0.0
5
+ */
6
+ import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
7
+ import { PseudoEvent } from '../interfaces/PseudoEvent';
8
+ /**
9
+ * The parts of an event which the dispatching of it (EventTargetService) needs to change or read. Not part of the DOM's
10
+ * Event, which is why they are kept apart from the event's own properties.
11
+ */
12
+ export type EventInner = {
13
+ currentTarget: PseudoEventTarget | null;
14
+ eventPhase: number;
15
+ target: PseudoEventTarget;
16
+ immediatePropagationStopped: boolean;
17
+ propagationStopped: boolean;
18
+ /** True for an event which the browser created for a user action, an event which a script created is not trusted. */
19
+ trusted: boolean;
20
+ /** True while the event is being dispatched. */
21
+ dispatching: boolean;
22
+ /** True while a passive listener is running, in which preventDefault does nothing. */
23
+ inPassiveListener: boolean;
24
+ /** The targets the event travels through, the target first and the root last, set while dispatching. */
25
+ path: Array<PseudoEventTarget>;
26
+ /** Finish the dispatch: no phase, no current target, no path and the stop flags are cleared so the event can be dispatched again. */
27
+ finishDispatch: () => void;
28
+ };
29
+ /**
30
+ * Simulate the behaviour of the Event Class when there is no DOM available.
31
+ * @author Joshua Heagle <joshuaheagle@gmail.com>
32
+ * @class
33
+ * @property {number} NONE
34
+ * @property {number} CAPTURING_PHASE
35
+ * @property {number} AT_TARGET
36
+ * @property {number} BUBBLING_PHASE
37
+ * @property {boolean} bubbles - A Boolean indicating whether the event bubbles up through the Dom or not.
38
+ * @property {boolean} cancelable - A Boolean indicating whether the event is cancelable.
39
+ * @property {boolean} composed - A Boolean value indicating whether the event can bubble across the boundary
40
+ * between the shadow Dom and the regular Dom.
41
+ * @property {function|PseudoEventTarget} currentTarget - A reference to the currently registered target for the event. This
42
+ * is the object to which the event is currently slated to be sent; it's possible this has been changed along the way
43
+ * through re-targeting.
44
+ * @property {boolean} defaultPrevented - Indicates whether event.preventDefault() has been called on the event.
45
+ * @property {boolean} immediatePropagationStopped - Flag that no further propagation should occur, including on current
46
+ * target.
47
+ * @property {boolean} propagationStopped - Flag that no further propagation should occur.
48
+ * @property {int} eventPhase - Indicates which phase of the event flow is being processed. Uses EventService constants.
49
+ * @property {EventTarget|PseudoEventTarget} target - A reference to the target to which the event was originally
50
+ * dispatched.
51
+ * @property {int} timeStamp - The time at which the event was created (in milliseconds). By specification, this
52
+ * value is time since epoch, but in reality browsers' definitions vary; in addition, work is underway to change this
53
+ * to be a DomHighResTimeStamp instead.
54
+ * @property {string} type - The name of the event (case-insensitive).
55
+ * @property {boolean} isTrusted - Indicates whether the event was initiated by the browser (after a user
56
+ * click for instance) or by a script (using an event creation method, like event.initEvent)
57
+ */
58
+ export declare class EventService implements PseudoEvent {
59
+ static readonly NONE = 0;
60
+ static readonly CAPTURING_PHASE = 1;
61
+ static readonly AT_TARGET = 2;
62
+ static readonly BUBBLING_PHASE = 3;
63
+ private properties;
64
+ /**
65
+ *
66
+ * @param {string} typeArg
67
+ * @param {Object} [eventOptions={}]
68
+ * @param {boolean} [eventOptions.bubbles=false]
69
+ * @param {boolean} [eventOptions.cancelable=false]
70
+ * @param {boolean} [eventOptions.composed=false]
71
+ * @constructor
72
+ */
73
+ constructor(typeArg?: string, { bubbles, cancelable, composed }?: {
74
+ bubbles?: boolean;
75
+ cancelable?: boolean;
76
+ composed?: boolean;
77
+ });
78
+ get bubbles(): boolean;
79
+ get cancelable(): boolean;
80
+ get composed(): boolean;
81
+ get currentTarget(): PseudoEventTarget;
82
+ get defaultPrevented(): boolean;
83
+ get eventPhase(): number;
84
+ get isTrusted(): boolean;
85
+ get target(): PseudoEventTarget;
86
+ get timeStamp(): number;
87
+ get type(): string;
88
+ /**
89
+ * Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
90
+ * @returns {EventInner}
91
+ */
92
+ get inner(): EventInner;
93
+ /**
94
+ * Return an array of targets that will have the event executed open them. The order is based on the eventPhase
95
+ * @method
96
+ * @returns {Array.<PseudoEventTarget>}
97
+ */
98
+ composedPath(): Array<PseudoEventTarget>;
99
+ /**
100
+ * Cancels the event (if it is cancelable).
101
+ * @method
102
+ * @returns {null}
103
+ */
104
+ preventDefault(): null;
105
+ /**
106
+ * For this particular event, no other listener will be called.
107
+ * Neither those attached on the same element, nor those attached on elements which will be traversed later (in
108
+ * capture phase, for instance)
109
+ * @method
110
+ * @returns {null}
111
+ */
112
+ stopImmediatePropagation(): null;
113
+ /**
114
+ * Stops the propagation of events further along in the Dom.
115
+ * @method
116
+ * @returns {null}
117
+ */
118
+ stopPropagation(): null;
119
+ private setReadOnlyProperties;
120
+ }