pseudo-dom 0.17.0 → 1.0.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 +63 -5869
- package/browser/pseudo-dom.js +14889 -15288
- package/dist/classes/PseudoEventListener.d.ts +11 -37
- package/dist/classes/PseudoEventListener.js +11 -37
- package/dist/classes/PseudoHTMLDocument.d.ts +4 -12
- package/dist/classes/PseudoHTMLDocument.js +1 -11
- package/dist/classes/PseudoNodeList.d.ts +1 -9
- package/dist/classes/PseudoNodeList.js +1 -9
- package/dist/factories/createDataset.d.ts +1 -3
- package/dist/factories/createDataset.js +3 -8
- package/dist/factories/createEvent.d.ts +5 -9
- package/dist/factories/createEvent.js +3 -5
- package/dist/factories/createStyleDeclaration.d.ts +4 -10
- package/dist/factories/createStyleDeclaration.js +4 -10
- package/dist/factories/cssSelectAdapter.d.ts +0 -2
- package/dist/factories/cssSelectAdapter.js +3 -8
- package/dist/factories/eventDefaults.d.ts +5 -9
- package/dist/factories/eventDefaults.js +1 -4
- package/dist/factories/generateDocument.d.ts +2 -4
- package/dist/factories/generateDocument.js +2 -13
- package/dist/factories/generateNodeList.d.ts +1 -2
- package/dist/factories/generateNodeList.js +1 -2
- package/dist/factories/installGlobal.d.ts +2 -3
- package/dist/factories/installGlobal.js +3 -6
- package/dist/factories/logElement.d.ts +2 -4
- package/dist/factories/logElement.js +3 -7
- package/dist/factories/parseHTML.d.ts +3 -5
- package/dist/factories/parseHTML.js +4 -8
- package/dist/factories/query.d.ts +8 -16
- package/dist/factories/query.js +9 -19
- package/dist/factories/serializeHTML.d.ts +4 -10
- package/dist/factories/serializeHTML.js +12 -25
- package/dist/functions/activeElement.d.ts +3 -6
- package/dist/functions/activeElement.js +3 -6
- package/dist/functions/getElementById.d.ts +2 -4
- package/dist/functions/getElementById.js +2 -4
- package/dist/functions/getParentNodes.d.ts +1 -3
- package/dist/functions/getParentNodes.js +1 -3
- package/dist/functions/getParentNodesFromAttribute.d.ts +3 -5
- package/dist/functions/getParentNodesFromAttribute.js +3 -5
- package/dist/functions/modifierState.d.ts +3 -12
- package/dist/functions/modifierState.js +3 -7
- package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +1 -1
- package/dist/interfaces/PseudoDocument.d.ts +4 -9
- package/dist/interfaces/PseudoDocumentFragment.d.ts +1 -2
- package/dist/interfaces/PseudoElement.d.ts +39 -78
- package/dist/interfaces/PseudoEvent.d.ts +11 -43
- package/dist/interfaces/PseudoEvent.js +1 -3
- package/dist/interfaces/PseudoEventTarget.d.ts +7 -16
- package/dist/interfaces/PseudoHTMLCollection.d.ts +2 -4
- package/dist/interfaces/PseudoHTMLElement.d.ts +8 -13
- package/dist/interfaces/PseudoNode.d.ts +3 -13
- package/dist/main.d.ts +1 -6
- package/dist/main.js +1 -6
- package/dist/services/AttrService.d.ts +5 -9
- package/dist/services/AttrService.js +5 -9
- package/dist/services/CSSStyleDeclarationService.d.ts +10 -23
- package/dist/services/CSSStyleDeclarationService.js +10 -23
- package/dist/services/CustomEventService.d.ts +4 -15
- package/dist/services/CustomEventService.js +3 -10
- package/dist/services/DOMTokenListService.d.ts +2 -5
- package/dist/services/DOMTokenListService.js +2 -5
- package/dist/services/DocumentFragmentService.d.ts +1 -5
- package/dist/services/DocumentFragmentService.js +1 -5
- package/dist/services/DocumentService.d.ts +4 -12
- package/dist/services/DocumentService.js +4 -12
- package/dist/services/ElementService.d.ts +62 -120
- package/dist/services/ElementService.js +61 -117
- package/dist/services/EventService.d.ts +6 -44
- package/dist/services/EventService.js +18 -44
- package/dist/services/EventTargetService.d.ts +16 -28
- package/dist/services/EventTargetService.js +16 -28
- package/dist/services/FocusEventService.d.ts +4 -12
- package/dist/services/FocusEventService.js +3 -10
- package/dist/services/HTMLCollectionService.d.ts +6 -16
- package/dist/services/HTMLCollectionService.js +6 -16
- package/dist/services/HTMLElementService.d.ts +132 -154
- package/dist/services/HTMLElementService.js +333 -353
- package/dist/services/InputEventService.d.ts +5 -16
- package/dist/services/InputEventService.js +3 -12
- package/dist/services/KeyboardEventService.d.ts +8 -26
- package/dist/services/KeyboardEventService.js +4 -16
- package/dist/services/MouseEventService.d.ts +7 -30
- package/dist/services/MouseEventService.js +4 -18
- package/dist/services/NamedNodeMapService.d.ts +1 -4
- package/dist/services/NamedNodeMapService.js +1 -4
- package/dist/services/NodeService.d.ts +38 -69
- package/dist/services/NodeService.js +39 -72
- package/dist/services/PointerEventService.d.ts +4 -22
- package/dist/services/PointerEventService.js +3 -15
- package/dist/services/ShadowRootService.d.ts +0 -3
- package/dist/services/ShadowRootService.js +0 -3
- package/dist/services/UIEventService.d.ts +5 -17
- package/dist/services/UIEventService.js +3 -11
- package/dist/simulate.d.ts +7 -9
- package/dist/simulate.js +9 -15
- package/package.json +8 -7
|
@@ -57,27 +57,14 @@ const zeroRect = () => ({
|
|
|
57
57
|
})
|
|
58
58
|
/**
|
|
59
59
|
* Simulate the behaviour of the Element Class when there is no DOM available.
|
|
60
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
61
|
-
* @class
|
|
62
|
-
* @augments PseudoNode
|
|
63
|
-
* @property {string} tagName
|
|
64
|
-
* @property {string} className
|
|
65
|
-
* @property {string} id
|
|
66
|
-
* @property {string} innerHtml
|
|
67
|
-
* @property {Array} attributes
|
|
68
|
-
* @property {function} hasAttribute
|
|
69
|
-
* @property {function} setAttribute
|
|
70
|
-
* @property {function} getAttribute
|
|
71
|
-
* @property {function} removeAttribute
|
|
72
60
|
*/
|
|
73
61
|
class ElementService extends NodeService_1.NodeService {
|
|
74
62
|
/**
|
|
75
|
-
* @param
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @constructor
|
|
63
|
+
* @param settings
|
|
64
|
+
* @param settings.tagName The name of the tag this element represents
|
|
65
|
+
* @param settings.attributes The attributes (also assigned as properties) to start with
|
|
66
|
+
* @param settings.parent The node to add this element to as its last child
|
|
67
|
+
* @param settings.children The nodes to start as children
|
|
81
68
|
*/
|
|
82
69
|
constructor ({
|
|
83
70
|
tagName = '',
|
|
@@ -156,7 +143,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
156
143
|
/**
|
|
157
144
|
* The attributes with the values they have now: the ones which are also properties (className, id, style, ...) can
|
|
158
145
|
* have been changed through the property, which does not change the stored list.
|
|
159
|
-
* @returns {Array<{name: string, value: *}>}
|
|
160
146
|
*/
|
|
161
147
|
currentAttributes () {
|
|
162
148
|
return this.attributeList.map(({
|
|
@@ -175,7 +161,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
175
161
|
/**
|
|
176
162
|
* A copy of this element without its children: the same tag and attributes (the values which are objects, such as
|
|
177
163
|
* style, are copied too rather than shared), but not its parent or listeners.
|
|
178
|
-
* @returns {ElementService}
|
|
179
164
|
*/
|
|
180
165
|
cloneShallow () {
|
|
181
166
|
const copy = new this.constructor({
|
|
@@ -202,8 +187,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
202
187
|
/**
|
|
203
188
|
* Elements are equal when they have the same tag and the same attributes (in any order), which is what isEqualNode
|
|
204
189
|
* checks before it compares the children.
|
|
205
|
-
* @param
|
|
206
|
-
* @returns {boolean}
|
|
190
|
+
* @param other The element to compare with
|
|
207
191
|
*/
|
|
208
192
|
equalsShallow (other) {
|
|
209
193
|
const mine = this.currentAttributes()
|
|
@@ -224,7 +208,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
224
208
|
/**
|
|
225
209
|
* The local part of the element's qualified name. There is no real namespace parsing here, so this is always the
|
|
226
210
|
* same as tagName.
|
|
227
|
-
* @returns {string}
|
|
228
211
|
*/
|
|
229
212
|
get localName () {
|
|
230
213
|
return this.tag
|
|
@@ -233,7 +216,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
233
216
|
/**
|
|
234
217
|
* The element's namespace prefix, or null when it has none. There is no real namespace parsing here, so this is
|
|
235
218
|
* always null.
|
|
236
|
-
* @returns {string|null}
|
|
237
219
|
*/
|
|
238
220
|
get prefix () {
|
|
239
221
|
return null
|
|
@@ -242,7 +224,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
242
224
|
/**
|
|
243
225
|
* The HTML markup of this element's children. Only the getter is here (the setter, which needs to build new
|
|
244
226
|
* elements from parsed HTML, is on HTMLElementService - see its class comment).
|
|
245
|
-
* @returns {string}
|
|
246
227
|
*/
|
|
247
228
|
get innerHTML () {
|
|
248
229
|
return (0, serializeHTML_1.serializeChildren)(this)
|
|
@@ -250,7 +231,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
250
231
|
|
|
251
232
|
/**
|
|
252
233
|
* The HTML markup of this element itself, including its children. Only the getter is here (see innerHTML).
|
|
253
|
-
* @returns {string}
|
|
254
234
|
*/
|
|
255
235
|
get outerHTML () {
|
|
256
236
|
return (0, serializeHTML_1.serializeOuter)(this)
|
|
@@ -281,11 +261,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
281
261
|
|
|
282
262
|
/**
|
|
283
263
|
* Some elements have default behaviour, this registers it when the element is added.
|
|
284
|
-
* @returns {Function}
|
|
285
264
|
*/
|
|
286
265
|
/**
|
|
287
266
|
* A live view of this element's element children (text, comments and the like are not included).
|
|
288
|
-
* @returns {PseudoHTMLCollection}
|
|
289
267
|
*/
|
|
290
268
|
get children () {
|
|
291
269
|
return new HTMLCollectionService_1.HTMLCollectionService(this)
|
|
@@ -293,7 +271,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
293
271
|
|
|
294
272
|
/**
|
|
295
273
|
* How many element children this element has.
|
|
296
|
-
* @returns {number}
|
|
297
274
|
*/
|
|
298
275
|
get childElementCount () {
|
|
299
276
|
return this.children.length
|
|
@@ -301,7 +278,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
301
278
|
|
|
302
279
|
/**
|
|
303
280
|
* The first child of this element which is an element, or null when there is none.
|
|
304
|
-
* @returns {PseudoElement|null}
|
|
305
281
|
*/
|
|
306
282
|
get firstElementChild () {
|
|
307
283
|
return this.children.item(0)
|
|
@@ -309,7 +285,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
309
285
|
|
|
310
286
|
/**
|
|
311
287
|
* The last child of this element which is an element, or null when there is none.
|
|
312
|
-
* @returns {PseudoElement|null}
|
|
313
288
|
*/
|
|
314
289
|
get lastElementChild () {
|
|
315
290
|
const elementChildren = this.children
|
|
@@ -318,7 +293,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
318
293
|
|
|
319
294
|
/**
|
|
320
295
|
* The sibling after this one which is an element, or null when there is none.
|
|
321
|
-
* @returns {PseudoElement|null}
|
|
322
296
|
*/
|
|
323
297
|
get nextElementSibling () {
|
|
324
298
|
let sibling = this.nextSibling
|
|
@@ -330,7 +304,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
330
304
|
|
|
331
305
|
/**
|
|
332
306
|
* The sibling before this one which is an element, or null when there is none.
|
|
333
|
-
* @returns {PseudoElement|null}
|
|
334
307
|
*/
|
|
335
308
|
get previousElementSibling () {
|
|
336
309
|
let sibling = this.previousSibling
|
|
@@ -344,9 +317,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
344
317
|
* Put an element at a position relative to this one: beforebegin (before this element, as its previous sibling),
|
|
345
318
|
* afterbegin (as this element's first child), beforeend (as this element's last child) or afterend (after this
|
|
346
319
|
* element, as its next sibling).
|
|
347
|
-
* @param
|
|
348
|
-
* @param
|
|
349
|
-
* @returns
|
|
320
|
+
* @param position beforebegin, afterbegin, beforeend or afterend
|
|
321
|
+
* @param element The element to insert
|
|
322
|
+
* @returns The inserted element, or null when the position needed a parent this element does not have
|
|
350
323
|
* @throws {Error} When the position is not one of the four above
|
|
351
324
|
*/
|
|
352
325
|
insertAdjacentElement (position, element) {
|
|
@@ -355,8 +328,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
355
328
|
|
|
356
329
|
/**
|
|
357
330
|
* Put text at a position relative to this element, the same as insertAdjacentElement but the text becomes a text node.
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
331
|
+
* @param position beforebegin, afterbegin, beforeend or afterend
|
|
332
|
+
* @param text The text to insert
|
|
360
333
|
* @throws {Error} When the position is not one of the four above
|
|
361
334
|
*/
|
|
362
335
|
insertAdjacentText (position, text) {
|
|
@@ -365,9 +338,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
365
338
|
|
|
366
339
|
/**
|
|
367
340
|
* Shared implementation for insertAdjacentElement / insertAdjacentText.
|
|
368
|
-
* @param
|
|
369
|
-
* @param
|
|
370
|
-
* @returns
|
|
341
|
+
* @param position beforebegin, afterbegin, beforeend or afterend
|
|
342
|
+
* @param node The node (or text) to insert
|
|
343
|
+
* @returns The inserted node, or null when the position needed a parent this element does not have
|
|
371
344
|
* @throws {Error} When the position is not one of the four above
|
|
372
345
|
*/
|
|
373
346
|
insertAdjacent (position, node) {
|
|
@@ -397,8 +370,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
397
370
|
|
|
398
371
|
/**
|
|
399
372
|
* Not implemented yet (HTML parsing is out of scope for now).
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
373
|
+
* @param position beforebegin, afterbegin, beforeend or afterend
|
|
374
|
+
* @param text The markup which would be parsed
|
|
402
375
|
* @throws {Error}
|
|
403
376
|
*/
|
|
404
377
|
insertAdjacentHTML (position, text) {
|
|
@@ -407,8 +380,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
407
380
|
|
|
408
381
|
/**
|
|
409
382
|
* Whether this element itself (not its descendants) matches the given CSS selector.
|
|
410
|
-
* @param
|
|
411
|
-
* @returns {boolean}
|
|
383
|
+
* @param selectors A CSS selector
|
|
412
384
|
*/
|
|
413
385
|
matches (selectors) {
|
|
414
386
|
return (0, query_1.matches)(this, selectors)
|
|
@@ -417,8 +389,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
417
389
|
/**
|
|
418
390
|
* The nearest ancestor of this element (starting with this element itself) which matches the CSS selector, or
|
|
419
391
|
* null when none of them do.
|
|
420
|
-
* @param
|
|
421
|
-
* @returns {PseudoElement|null}
|
|
392
|
+
* @param selectors A CSS selector
|
|
422
393
|
*/
|
|
423
394
|
closest (selectors) {
|
|
424
395
|
return (0, query_1.closest)(this, selectors)
|
|
@@ -452,7 +423,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
452
423
|
|
|
453
424
|
/**
|
|
454
425
|
* An element which is added as a child gets its default events (for example a submit button submits its form).
|
|
455
|
-
* @param
|
|
426
|
+
* @param child The node which was inserted
|
|
456
427
|
*/
|
|
457
428
|
childInserted (child) {
|
|
458
429
|
if (typeof child.applyDefaultEvent === 'function') {
|
|
@@ -462,8 +433,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
462
433
|
|
|
463
434
|
/**
|
|
464
435
|
* Check whether the element has an attribute by that name.
|
|
465
|
-
* @param
|
|
466
|
-
* @returns {boolean}
|
|
436
|
+
* @param attributeName
|
|
467
437
|
*/
|
|
468
438
|
hasAttribute (attributeName) {
|
|
469
439
|
return this.attributeList.some(({
|
|
@@ -473,9 +443,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
473
443
|
|
|
474
444
|
/**
|
|
475
445
|
* Set the value of an attribute, adding the attribute if it did not exist.
|
|
476
|
-
* @param
|
|
477
|
-
* @param
|
|
478
|
-
* @returns {undefined}
|
|
446
|
+
* @param attributeName
|
|
447
|
+
* @param attributeValue
|
|
479
448
|
*/
|
|
480
449
|
setAttribute (attributeName, attributeValue) {
|
|
481
450
|
const existing = this.attributeList.find(({
|
|
@@ -496,8 +465,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
496
465
|
|
|
497
466
|
/**
|
|
498
467
|
* Retrieve the value of an attribute.
|
|
499
|
-
* @param
|
|
500
|
-
* @returns
|
|
468
|
+
* @param attributeName
|
|
469
|
+
* @returns The value, or null when there is no such attribute
|
|
501
470
|
*/
|
|
502
471
|
getAttribute (attributeName) {
|
|
503
472
|
const found = this.currentAttributes().find(({
|
|
@@ -508,8 +477,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
508
477
|
|
|
509
478
|
/**
|
|
510
479
|
* Remove an attribute from the element.
|
|
511
|
-
* @param
|
|
512
|
-
* @returns {undefined}
|
|
480
|
+
* @param attributeName
|
|
513
481
|
*/
|
|
514
482
|
removeAttribute (attributeName) {
|
|
515
483
|
const index = this.attributeList.findIndex(({
|
|
@@ -522,7 +490,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
522
490
|
|
|
523
491
|
/**
|
|
524
492
|
* The name of every attribute on the element, in the order they were set.
|
|
525
|
-
* @returns {Array<string>}
|
|
526
493
|
*/
|
|
527
494
|
getAttributeNames () {
|
|
528
495
|
return this.currentAttributes().map(({
|
|
@@ -532,7 +499,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
532
499
|
|
|
533
500
|
/**
|
|
534
501
|
* Whether the element has any attributes at all.
|
|
535
|
-
* @returns {boolean}
|
|
536
502
|
*/
|
|
537
503
|
hasAttributes () {
|
|
538
504
|
return this.attributeList.length > 0
|
|
@@ -540,8 +506,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
540
506
|
|
|
541
507
|
/**
|
|
542
508
|
* Retrieve the node representation of an attribute.
|
|
543
|
-
* @param
|
|
544
|
-
* @returns
|
|
509
|
+
* @param attributeName
|
|
510
|
+
* @returns An Attr for the attribute, or null when there is no such attribute
|
|
545
511
|
*/
|
|
546
512
|
getAttributeNode (attributeName) {
|
|
547
513
|
return this.hasAttribute(attributeName) ? new AttrService_1.AttrService(attributeName, this.getAttribute(attributeName) || '', this) : null
|
|
@@ -550,9 +516,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
550
516
|
/**
|
|
551
517
|
* Retrieve the node representation of an attribute. There is no real namespace parsing here, so this ignores
|
|
552
518
|
* the namespace and behaves exactly like getAttributeNode.
|
|
553
|
-
* @param
|
|
554
|
-
* @param
|
|
555
|
-
* @returns
|
|
519
|
+
* @param namespace Ignored
|
|
520
|
+
* @param attributeName
|
|
521
|
+
* @returns An Attr for the attribute, or null when there is no such attribute
|
|
556
522
|
*/
|
|
557
523
|
getAttributeNodeNS (namespace, attributeName) {
|
|
558
524
|
return this.getAttributeNode(attributeName)
|
|
@@ -561,9 +527,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
561
527
|
/**
|
|
562
528
|
* Retrieve the value of an attribute. There is no real namespace parsing here, so this ignores the namespace
|
|
563
529
|
* and behaves exactly like getAttribute.
|
|
564
|
-
* @param
|
|
565
|
-
* @param
|
|
566
|
-
* @returns
|
|
530
|
+
* @param namespace Ignored
|
|
531
|
+
* @param attributeName
|
|
532
|
+
* @returns The value, or null when there is no such attribute
|
|
567
533
|
*/
|
|
568
534
|
getAttributeNS (namespace, attributeName) {
|
|
569
535
|
return this.getAttribute(attributeName)
|
|
@@ -572,9 +538,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
572
538
|
/**
|
|
573
539
|
* Check whether the element has an attribute by that name. There is no real namespace parsing here, so this
|
|
574
540
|
* ignores the namespace and behaves exactly like hasAttribute.
|
|
575
|
-
* @param
|
|
576
|
-
* @param
|
|
577
|
-
* @returns {boolean}
|
|
541
|
+
* @param namespace Ignored
|
|
542
|
+
* @param attributeName
|
|
578
543
|
*/
|
|
579
544
|
hasAttributeNS (namespace, attributeName) {
|
|
580
545
|
return this.hasAttribute(attributeName)
|
|
@@ -582,8 +547,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
582
547
|
|
|
583
548
|
/**
|
|
584
549
|
* Remove the node representation of an attribute from the element, and return it.
|
|
585
|
-
* @param
|
|
586
|
-
* @returns
|
|
550
|
+
* @param attr
|
|
551
|
+
* @returns The removed Attr
|
|
587
552
|
* @throws {Error} When the element has no attribute matching attr.name
|
|
588
553
|
*/
|
|
589
554
|
removeAttributeNode (attr) {
|
|
@@ -598,9 +563,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
598
563
|
/**
|
|
599
564
|
* Remove an attribute from the element. There is no real namespace parsing here, so this ignores the namespace
|
|
600
565
|
* and behaves exactly like removeAttribute.
|
|
601
|
-
* @param
|
|
602
|
-
* @param
|
|
603
|
-
* @returns {undefined}
|
|
566
|
+
* @param namespace Ignored
|
|
567
|
+
* @param attributeName
|
|
604
568
|
*/
|
|
605
569
|
removeAttributeNS (namespace, attributeName) {
|
|
606
570
|
this.removeAttribute(attributeName)
|
|
@@ -609,8 +573,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
609
573
|
/**
|
|
610
574
|
* Set the node representation of an attribute, adding the attribute if it did not exist. Returns any previous
|
|
611
575
|
* Attr that had the same name, or null when there was none.
|
|
612
|
-
* @param
|
|
613
|
-
* @returns
|
|
576
|
+
* @param attr
|
|
577
|
+
* @returns The replaced Attr, or null when the attribute was new
|
|
614
578
|
*/
|
|
615
579
|
setAttributeNode (attr) {
|
|
616
580
|
const existing = this.getAttributeNode(attr.name)
|
|
@@ -621,8 +585,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
621
585
|
/**
|
|
622
586
|
* Set the node representation of an attribute. There is no real namespace parsing here, so this behaves
|
|
623
587
|
* exactly like setAttributeNode (Attr.name already carries any prefix).
|
|
624
|
-
* @param
|
|
625
|
-
* @returns
|
|
588
|
+
* @param attr
|
|
589
|
+
* @returns The replaced Attr, or null when the attribute was new
|
|
626
590
|
*/
|
|
627
591
|
setAttributeNodeNS (attr) {
|
|
628
592
|
return this.setAttributeNode(attr)
|
|
@@ -631,10 +595,9 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
631
595
|
/**
|
|
632
596
|
* Set the value of an attribute, adding the attribute if it did not exist. There is no real namespace parsing
|
|
633
597
|
* here, so this ignores the namespace and behaves exactly like setAttribute.
|
|
634
|
-
* @param
|
|
635
|
-
* @param
|
|
636
|
-
* @param
|
|
637
|
-
* @returns {undefined}
|
|
598
|
+
* @param namespace Ignored
|
|
599
|
+
* @param attributeName
|
|
600
|
+
* @param attributeValue
|
|
638
601
|
*/
|
|
639
602
|
setAttributeNS (namespace, attributeName, attributeValue) {
|
|
640
603
|
this.setAttribute(attributeName, attributeValue)
|
|
@@ -643,9 +606,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
643
606
|
/**
|
|
644
607
|
* Add the attribute (with an empty value) when it is not present, or remove it when it is - unless force says
|
|
645
608
|
* which of those to do instead. Returns whether the attribute is present after the call.
|
|
646
|
-
* @param
|
|
647
|
-
* @param
|
|
648
|
-
* @returns {boolean}
|
|
609
|
+
* @param attributeName
|
|
610
|
+
* @param force
|
|
649
611
|
*/
|
|
650
612
|
toggleAttribute (attributeName, force) {
|
|
651
613
|
const present = this.hasAttribute(attributeName)
|
|
@@ -660,7 +622,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
660
622
|
|
|
661
623
|
/**
|
|
662
624
|
* The size of the element and its position, settable directly - there is no layout engine here to compute it.
|
|
663
|
-
* @returns {DOMRect}
|
|
664
625
|
*/
|
|
665
626
|
getBoundingClientRect () {
|
|
666
627
|
return this.boundingClientRect
|
|
@@ -669,7 +630,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
669
630
|
/**
|
|
670
631
|
* The bounding rectangles for each line of text in the element, settable directly - there is no layout engine
|
|
671
632
|
* here to compute it.
|
|
672
|
-
* @returns {Array<DOMRect>}
|
|
673
633
|
*/
|
|
674
634
|
getClientRects () {
|
|
675
635
|
return this.clientRects
|
|
@@ -677,7 +637,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
677
637
|
|
|
678
638
|
/**
|
|
679
639
|
* The Animation objects currently active on the element, settable directly - there is no animation engine here.
|
|
680
|
-
* @returns {Array<*>}
|
|
681
640
|
*/
|
|
682
641
|
getAnimations () {
|
|
683
642
|
return this.animations
|
|
@@ -685,7 +644,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
685
644
|
|
|
686
645
|
/**
|
|
687
646
|
* Whether the element is expected to be visible, settable directly - there is no rendering here to check it.
|
|
688
|
-
* @returns {boolean}
|
|
689
647
|
*/
|
|
690
648
|
checkVisibility () {
|
|
691
649
|
return this.isVisible
|
|
@@ -694,7 +652,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
694
652
|
/**
|
|
695
653
|
* A read-only view of the element's own inline style declarations (there is no CSS cascade here, so this is not a
|
|
696
654
|
* real computed style - just what the element's own style object holds).
|
|
697
|
-
* @returns {{get: function(string): (string|undefined)}}
|
|
698
655
|
*/
|
|
699
656
|
computedStyleMap () {
|
|
700
657
|
const style = this.style
|
|
@@ -708,8 +665,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
708
665
|
|
|
709
666
|
/**
|
|
710
667
|
* Whether this element currently has capture of the given pointer.
|
|
711
|
-
* @param
|
|
712
|
-
* @returns {boolean}
|
|
668
|
+
* @param pointerId
|
|
713
669
|
*/
|
|
714
670
|
hasPointerCapture (pointerId) {
|
|
715
671
|
return this.capturedPointers.has(pointerId)
|
|
@@ -717,8 +673,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
717
673
|
|
|
718
674
|
/**
|
|
719
675
|
* Give this element capture of the given pointer.
|
|
720
|
-
* @param
|
|
721
|
-
* @returns {undefined}
|
|
676
|
+
* @param pointerId
|
|
722
677
|
*/
|
|
723
678
|
setPointerCapture (pointerId) {
|
|
724
679
|
this.capturedPointers.add(pointerId)
|
|
@@ -726,8 +681,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
726
681
|
|
|
727
682
|
/**
|
|
728
683
|
* Release this element's capture of the given pointer, if it had it.
|
|
729
|
-
* @param
|
|
730
|
-
* @returns {undefined}
|
|
684
|
+
* @param pointerId
|
|
731
685
|
*/
|
|
732
686
|
releasePointerCapture (pointerId) {
|
|
733
687
|
this.capturedPointers.delete(pointerId)
|
|
@@ -736,9 +690,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
736
690
|
/**
|
|
737
691
|
* Scroll to the given position (or, given an options object, the position(s) it has). There is no real scrollable
|
|
738
692
|
* viewport here: this just sets scrollLeft / scrollTop.
|
|
739
|
-
* @param
|
|
740
|
-
* @param
|
|
741
|
-
* @returns {undefined}
|
|
693
|
+
* @param x
|
|
694
|
+
* @param y
|
|
742
695
|
*/
|
|
743
696
|
scroll (x = 0, y = 0) {
|
|
744
697
|
if (typeof x === 'number') {
|
|
@@ -756,9 +709,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
756
709
|
|
|
757
710
|
/**
|
|
758
711
|
* Scroll to the given position. An alias for scroll.
|
|
759
|
-
* @param
|
|
760
|
-
* @param
|
|
761
|
-
* @returns {undefined}
|
|
712
|
+
* @param x
|
|
713
|
+
* @param y
|
|
762
714
|
*/
|
|
763
715
|
scrollTo (x = 0, y = 0) {
|
|
764
716
|
this.scroll(x, y)
|
|
@@ -766,9 +718,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
766
718
|
|
|
767
719
|
/**
|
|
768
720
|
* Scroll by the given amount, relative to the current position.
|
|
769
|
-
* @param
|
|
770
|
-
* @param
|
|
771
|
-
* @returns {undefined}
|
|
721
|
+
* @param x
|
|
722
|
+
* @param y
|
|
772
723
|
*/
|
|
773
724
|
scrollBy (x = 0, y = 0) {
|
|
774
725
|
if (typeof x === 'number') {
|
|
@@ -784,13 +735,11 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
784
735
|
/**
|
|
785
736
|
* Scroll an ancestor until this element is in view. There is no real viewport here for that to mean anything, so
|
|
786
737
|
* this does nothing (override it on an instance in a test which needs to observe the call).
|
|
787
|
-
* @returns {undefined}
|
|
788
738
|
*/
|
|
789
739
|
scrollIntoView () {}
|
|
790
740
|
/**
|
|
791
741
|
* Asynchronously ask for the element to be shown fullscreen. There is no real fullscreen here, so this just
|
|
792
742
|
* resolves, like a browser granting the request would.
|
|
793
|
-
* @returns {Promise<void>}
|
|
794
743
|
*/
|
|
795
744
|
requestFullscreen () {
|
|
796
745
|
return Promise.resolve()
|
|
@@ -799,7 +748,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
799
748
|
/**
|
|
800
749
|
* Asynchronously ask for the pointer to be locked to this element. There is no real pointer lock here, so this
|
|
801
750
|
* just resolves, like a browser granting the request would.
|
|
802
|
-
* @returns {Promise<void>}
|
|
803
751
|
*/
|
|
804
752
|
requestPointerLock () {
|
|
805
753
|
return Promise.resolve()
|
|
@@ -807,8 +755,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
807
755
|
|
|
808
756
|
/**
|
|
809
757
|
* Attach a shadow tree to this element and return its ShadowRoot. Throws when it already hosts one.
|
|
810
|
-
* @param
|
|
811
|
-
* @returns {PseudoShadowRoot}
|
|
758
|
+
* @param options
|
|
812
759
|
* @throws {Error}
|
|
813
760
|
*/
|
|
814
761
|
attachShadow (options) {
|
|
@@ -825,7 +772,6 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
825
772
|
/**
|
|
826
773
|
* This element's shadow root, when it has one attached in 'open' mode, or null (including when the mode is
|
|
827
774
|
* 'closed' - it still exists, but is not reachable this way, like the DOM's).
|
|
828
|
-
* @returns {PseudoShadowRoot|null}
|
|
829
775
|
*/
|
|
830
776
|
get shadowRoot () {
|
|
831
777
|
return this.shadowRootInstance && this.shadowRootInstance.mode === 'open' ? this.shadowRootInstance : null
|
|
@@ -833,8 +779,7 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
833
779
|
|
|
834
780
|
/**
|
|
835
781
|
* Read one of the aria-* reflected properties (see the individual aria* getters/setters below).
|
|
836
|
-
* @param
|
|
837
|
-
* @returns {string}
|
|
782
|
+
* @param attributeName A real aria-* attribute name (aria-label, ...)
|
|
838
783
|
*/
|
|
839
784
|
getAriaAttribute (attributeName) {
|
|
840
785
|
return this.getAttribute(attributeName) || ''
|
|
@@ -842,9 +787,8 @@ class ElementService extends NodeService_1.NodeService {
|
|
|
842
787
|
|
|
843
788
|
/**
|
|
844
789
|
* Write one of the aria-* reflected properties.
|
|
845
|
-
* @param
|
|
846
|
-
* @param
|
|
847
|
-
* @returns {undefined}
|
|
790
|
+
* @param attributeName A real aria-* attribute name (aria-label, ...)
|
|
791
|
+
* @param value
|
|
848
792
|
*/
|
|
849
793
|
setAriaAttribute (attributeName, value) {
|
|
850
794
|
this.setAttribute(attributeName, value)
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author Joshua Heagle <joshuaheagle@gmail.com>
|
|
4
|
-
* @version 1.0.0
|
|
2
|
+
* Substitute for the DOM Event Class.
|
|
5
3
|
*/
|
|
6
4
|
import { PseudoEventTarget } from '../interfaces/PseudoEventTarget';
|
|
7
5
|
import { PseudoEvent } from '../interfaces/PseudoEvent';
|
|
@@ -28,32 +26,6 @@ export type EventInner = {
|
|
|
28
26
|
};
|
|
29
27
|
/**
|
|
30
28
|
* 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
29
|
*/
|
|
58
30
|
export declare class EventService implements PseudoEvent {
|
|
59
31
|
static readonly NONE = 0;
|
|
@@ -63,12 +35,11 @@ export declare class EventService implements PseudoEvent {
|
|
|
63
35
|
private properties;
|
|
64
36
|
/**
|
|
65
37
|
*
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @constructor
|
|
38
|
+
* @param typeArg
|
|
39
|
+
* @param eventOptions
|
|
40
|
+
* @param eventOptions.bubbles
|
|
41
|
+
* @param eventOptions.cancelable
|
|
42
|
+
* @param eventOptions.composed
|
|
72
43
|
*/
|
|
73
44
|
constructor(typeArg?: string, { bubbles, cancelable, composed }?: {
|
|
74
45
|
bubbles?: boolean;
|
|
@@ -87,33 +58,24 @@ export declare class EventService implements PseudoEvent {
|
|
|
87
58
|
get type(): string;
|
|
88
59
|
/**
|
|
89
60
|
* Scope several accessors inside the inner object. These are only intended for usage by other DOM classes.
|
|
90
|
-
* @returns {EventInner}
|
|
91
61
|
*/
|
|
92
62
|
get inner(): EventInner;
|
|
93
63
|
/**
|
|
94
64
|
* 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
65
|
*/
|
|
98
66
|
composedPath(): Array<PseudoEventTarget>;
|
|
99
67
|
/**
|
|
100
68
|
* Cancels the event (if it is cancelable).
|
|
101
|
-
* @method
|
|
102
|
-
* @returns {null}
|
|
103
69
|
*/
|
|
104
70
|
preventDefault(): null;
|
|
105
71
|
/**
|
|
106
72
|
* For this particular event, no other listener will be called.
|
|
107
73
|
* Neither those attached on the same element, nor those attached on elements which will be traversed later (in
|
|
108
74
|
* capture phase, for instance)
|
|
109
|
-
* @method
|
|
110
|
-
* @returns {null}
|
|
111
75
|
*/
|
|
112
76
|
stopImmediatePropagation(): null;
|
|
113
77
|
/**
|
|
114
78
|
* Stops the propagation of events further along in the Dom.
|
|
115
|
-
* @method
|
|
116
|
-
* @returns {null}
|
|
117
79
|
*/
|
|
118
80
|
stopPropagation(): null;
|
|
119
81
|
private setReadOnlyProperties;
|