pseudo-dom 0.15.0 → 0.16.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 CHANGED
@@ -59,6 +59,13 @@ reflected properties (`ariaLabel`, `ariaExpanded`, `ariaValueNow`, ...) are real
59
59
  matching `aria-*` attribute (`ariaLabel` <-> `aria-label`; the mapping isn't camelCase-to-kebab-case, so
60
60
  `ariaColCount` <-> `aria-colcount`, not `aria-col-count`).
61
61
 
62
+ `getAttributeNode` / `setAttributeNode` / `removeAttributeNode` give and take real `Attr` nodes (backed by
63
+ `AttrService`) instead of plain strings - `setAttributeNode` returns whatever `Attr` previously held that name (or
64
+ `null` when it's new), and `removeAttributeNode` throws when the element has no attribute matching the one given, like
65
+ the DOM's. Every `*NS` method (`getAttributeNS`, `hasAttributeNS`, `setAttributeNS`, `removeAttributeNS`,
66
+ `getAttributeNodeNS`, `setAttributeNodeNS`) behaves exactly like its non-NS counterpart, ignoring the namespace
67
+ argument entirely - there's no real namespace parsing here, matching `getElementsByTagNameNS`.
68
+
62
69
  **`style`** is a real, live `CSSStyleDeclaration`:
63
70
 
64
71
  - Named property access (`el.style.backgroundColor = 'red'`) alongside `getPropertyValue` / `setProperty` /
@@ -169,9 +176,6 @@ it) - useful for watching pseudo-dom-driven code run, or checking a final result
169
176
  - There are text and comment nodes (`PseudoText`, `PseudoComment`); `textContent` works like the DOM's (the text of
170
177
  everything below, and setting it replaces the children with a text node)
171
178
 
172
- ## Not implemented yet
173
-
174
- - The `Attr`-node / namespaced attribute methods (`getAttributeNode`, `getAttributeNS`, ...)
175
179
  ## Modules
176
180
 
177
181
  <dl>
@@ -2961,6 +2965,15 @@ Simulate the behaviour of the Element Class when there is no DOM available.
2961
2965
  * [.removeAttribute(attributeName)](#ElementService+removeAttribute) ⇒ <code>undefined</code>
2962
2966
  * [.getAttributeNames()](#ElementService+getAttributeNames) ⇒ <code>Array.&lt;string&gt;</code>
2963
2967
  * [.hasAttributes()](#ElementService+hasAttributes) ⇒ <code>boolean</code>
2968
+ * [.getAttributeNode(attributeName)](#ElementService+getAttributeNode) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
2969
+ * [.getAttributeNodeNS(namespace, attributeName)](#ElementService+getAttributeNodeNS) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
2970
+ * [.getAttributeNS(namespace, attributeName)](#ElementService+getAttributeNS) ⇒ <code>string</code> \| <code>null</code>
2971
+ * [.hasAttributeNS(namespace, attributeName)](#ElementService+hasAttributeNS) ⇒ <code>boolean</code>
2972
+ * [.removeAttributeNode(attr)](#ElementService+removeAttributeNode) ⇒ [<code>AttrService</code>](#AttrService)
2973
+ * [.removeAttributeNS(namespace, attributeName)](#ElementService+removeAttributeNS) ⇒ <code>undefined</code>
2974
+ * [.setAttributeNode(attr)](#ElementService+setAttributeNode) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
2975
+ * [.setAttributeNodeNS(attr)](#ElementService+setAttributeNodeNS) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
2976
+ * [.setAttributeNS(namespace, attributeName, attributeValue)](#ElementService+setAttributeNS) ⇒ <code>undefined</code>
2964
2977
  * [.toggleAttribute(attributeName, [force])](#ElementService+toggleAttribute) ⇒ <code>boolean</code>
2965
2978
  * [.getBoundingClientRect()](#ElementService+getBoundingClientRect) ⇒ <code>DOMRect</code>
2966
2979
  * [.getClientRects()](#ElementService+getClientRects) ⇒ <code>Array.&lt;DOMRect&gt;</code>
@@ -3272,6 +3285,128 @@ The name of every attribute on the element, in the order they were set.
3272
3285
  Whether the element has any attributes at all.
3273
3286
 
3274
3287
  **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3288
+ <a name="ElementService+getAttributeNode"></a>
3289
+
3290
+ ### elementService.getAttributeNode(attributeName) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
3291
+ Retrieve the node representation of an attribute.
3292
+
3293
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3294
+ **Returns**: [<code>AttrService</code>](#AttrService) \| <code>null</code> - An Attr for the attribute, or null when there is no such attribute
3295
+
3296
+ | Param | Type |
3297
+ | --- | --- |
3298
+ | attributeName | <code>string</code> |
3299
+
3300
+ <a name="ElementService+getAttributeNodeNS"></a>
3301
+
3302
+ ### elementService.getAttributeNodeNS(namespace, attributeName) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
3303
+ Retrieve the node representation of an attribute. There is no real namespace parsing here, so this ignores
3304
+ the namespace and behaves exactly like getAttributeNode.
3305
+
3306
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3307
+ **Returns**: [<code>AttrService</code>](#AttrService) \| <code>null</code> - An Attr for the attribute, or null when there is no such attribute
3308
+
3309
+ | Param | Type | Description |
3310
+ | --- | --- | --- |
3311
+ | namespace | <code>string</code> | Ignored |
3312
+ | attributeName | <code>string</code> | |
3313
+
3314
+ <a name="ElementService+getAttributeNS"></a>
3315
+
3316
+ ### elementService.getAttributeNS(namespace, attributeName) ⇒ <code>string</code> \| <code>null</code>
3317
+ Retrieve the value of an attribute. There is no real namespace parsing here, so this ignores the namespace
3318
+ and behaves exactly like getAttribute.
3319
+
3320
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3321
+ **Returns**: <code>string</code> \| <code>null</code> - The value, or null when there is no such attribute
3322
+
3323
+ | Param | Type | Description |
3324
+ | --- | --- | --- |
3325
+ | namespace | <code>string</code> | Ignored |
3326
+ | attributeName | <code>string</code> | |
3327
+
3328
+ <a name="ElementService+hasAttributeNS"></a>
3329
+
3330
+ ### elementService.hasAttributeNS(namespace, attributeName) ⇒ <code>boolean</code>
3331
+ Check whether the element has an attribute by that name. There is no real namespace parsing here, so this
3332
+ ignores the namespace and behaves exactly like hasAttribute.
3333
+
3334
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3335
+
3336
+ | Param | Type | Description |
3337
+ | --- | --- | --- |
3338
+ | namespace | <code>string</code> | Ignored |
3339
+ | attributeName | <code>string</code> | |
3340
+
3341
+ <a name="ElementService+removeAttributeNode"></a>
3342
+
3343
+ ### elementService.removeAttributeNode(attr) ⇒ [<code>AttrService</code>](#AttrService)
3344
+ Remove the node representation of an attribute from the element, and return it.
3345
+
3346
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3347
+ **Returns**: [<code>AttrService</code>](#AttrService) - The removed Attr
3348
+ **Throws**:
3349
+
3350
+ - <code>Error</code> When the element has no attribute matching attr.name
3351
+
3352
+
3353
+ | Param | Type |
3354
+ | --- | --- |
3355
+ | attr | [<code>AttrService</code>](#AttrService) |
3356
+
3357
+ <a name="ElementService+removeAttributeNS"></a>
3358
+
3359
+ ### elementService.removeAttributeNS(namespace, attributeName) ⇒ <code>undefined</code>
3360
+ Remove an attribute from the element. There is no real namespace parsing here, so this ignores the namespace
3361
+ and behaves exactly like removeAttribute.
3362
+
3363
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3364
+
3365
+ | Param | Type | Description |
3366
+ | --- | --- | --- |
3367
+ | namespace | <code>string</code> | Ignored |
3368
+ | attributeName | <code>string</code> | |
3369
+
3370
+ <a name="ElementService+setAttributeNode"></a>
3371
+
3372
+ ### elementService.setAttributeNode(attr) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
3373
+ Set the node representation of an attribute, adding the attribute if it did not exist. Returns any previous
3374
+ Attr that had the same name, or null when there was none.
3375
+
3376
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3377
+ **Returns**: [<code>AttrService</code>](#AttrService) \| <code>null</code> - The replaced Attr, or null when the attribute was new
3378
+
3379
+ | Param | Type |
3380
+ | --- | --- |
3381
+ | attr | [<code>AttrService</code>](#AttrService) |
3382
+
3383
+ <a name="ElementService+setAttributeNodeNS"></a>
3384
+
3385
+ ### elementService.setAttributeNodeNS(attr) ⇒ [<code>AttrService</code>](#AttrService) \| <code>null</code>
3386
+ Set the node representation of an attribute. There is no real namespace parsing here, so this behaves
3387
+ exactly like setAttributeNode (Attr.name already carries any prefix).
3388
+
3389
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3390
+ **Returns**: [<code>AttrService</code>](#AttrService) \| <code>null</code> - The replaced Attr, or null when the attribute was new
3391
+
3392
+ | Param | Type |
3393
+ | --- | --- |
3394
+ | attr | [<code>AttrService</code>](#AttrService) |
3395
+
3396
+ <a name="ElementService+setAttributeNS"></a>
3397
+
3398
+ ### elementService.setAttributeNS(namespace, attributeName, attributeValue) ⇒ <code>undefined</code>
3399
+ Set the value of an attribute, adding the attribute if it did not exist. There is no real namespace parsing
3400
+ here, so this ignores the namespace and behaves exactly like setAttribute.
3401
+
3402
+ **Kind**: instance method of [<code>ElementService</code>](#ElementService)
3403
+
3404
+ | Param | Type | Description |
3405
+ | --- | --- | --- |
3406
+ | namespace | <code>string</code> | Ignored |
3407
+ | attributeName | <code>string</code> | |
3408
+ | attributeValue | <code>string</code> | |
3409
+
3275
3410
  <a name="ElementService+toggleAttribute"></a>
3276
3411
 
3277
3412
  ### elementService.toggleAttribute(attributeName, [force]) ⇒ <code>boolean</code>
@@ -2605,6 +2605,108 @@
2605
2605
  return this.attributeList.length > 0
2606
2606
  }
2607
2607
 
2608
+ /**
2609
+ * Retrieve the node representation of an attribute.
2610
+ * @param {string} attributeName
2611
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
2612
+ */
2613
+ getAttributeNode (attributeName) {
2614
+ return this.hasAttribute(attributeName) ? new AttrService_1.AttrService(attributeName, this.getAttribute(attributeName) || '', this) : null
2615
+ }
2616
+
2617
+ /**
2618
+ * Retrieve the node representation of an attribute. There is no real namespace parsing here, so this ignores
2619
+ * the namespace and behaves exactly like getAttributeNode.
2620
+ * @param {string} namespace Ignored
2621
+ * @param {string} attributeName
2622
+ * @returns {AttrService|null} An Attr for the attribute, or null when there is no such attribute
2623
+ */
2624
+ getAttributeNodeNS (namespace, attributeName) {
2625
+ return this.getAttributeNode(attributeName)
2626
+ }
2627
+
2628
+ /**
2629
+ * Retrieve the value of an attribute. There is no real namespace parsing here, so this ignores the namespace
2630
+ * and behaves exactly like getAttribute.
2631
+ * @param {string} namespace Ignored
2632
+ * @param {string} attributeName
2633
+ * @returns {string|null} The value, or null when there is no such attribute
2634
+ */
2635
+ getAttributeNS (namespace, attributeName) {
2636
+ return this.getAttribute(attributeName)
2637
+ }
2638
+
2639
+ /**
2640
+ * Check whether the element has an attribute by that name. There is no real namespace parsing here, so this
2641
+ * ignores the namespace and behaves exactly like hasAttribute.
2642
+ * @param {string} namespace Ignored
2643
+ * @param {string} attributeName
2644
+ * @returns {boolean}
2645
+ */
2646
+ hasAttributeNS (namespace, attributeName) {
2647
+ return this.hasAttribute(attributeName)
2648
+ }
2649
+
2650
+ /**
2651
+ * Remove the node representation of an attribute from the element, and return it.
2652
+ * @param {AttrService} attr
2653
+ * @returns {AttrService} The removed Attr
2654
+ * @throws {Error} When the element has no attribute matching attr.name
2655
+ */
2656
+ removeAttributeNode (attr) {
2657
+ if (!this.hasAttribute(attr.name)) {
2658
+ throw new Error(`Failed to execute 'removeAttributeNode': The node provided is owned by another element (no attribute named '${attr.name}')`)
2659
+ }
2660
+ const removed = this.getAttributeNode(attr.name)
2661
+ this.removeAttribute(attr.name)
2662
+ return removed
2663
+ }
2664
+
2665
+ /**
2666
+ * Remove an attribute from the element. There is no real namespace parsing here, so this ignores the namespace
2667
+ * and behaves exactly like removeAttribute.
2668
+ * @param {string} namespace Ignored
2669
+ * @param {string} attributeName
2670
+ * @returns {undefined}
2671
+ */
2672
+ removeAttributeNS (namespace, attributeName) {
2673
+ this.removeAttribute(attributeName)
2674
+ }
2675
+
2676
+ /**
2677
+ * Set the node representation of an attribute, adding the attribute if it did not exist. Returns any previous
2678
+ * Attr that had the same name, or null when there was none.
2679
+ * @param {AttrService} attr
2680
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
2681
+ */
2682
+ setAttributeNode (attr) {
2683
+ const existing = this.getAttributeNode(attr.name)
2684
+ this.setAttribute(attr.name, attr.value)
2685
+ return existing
2686
+ }
2687
+
2688
+ /**
2689
+ * Set the node representation of an attribute. There is no real namespace parsing here, so this behaves
2690
+ * exactly like setAttributeNode (Attr.name already carries any prefix).
2691
+ * @param {AttrService} attr
2692
+ * @returns {AttrService|null} The replaced Attr, or null when the attribute was new
2693
+ */
2694
+ setAttributeNodeNS (attr) {
2695
+ return this.setAttributeNode(attr)
2696
+ }
2697
+
2698
+ /**
2699
+ * Set the value of an attribute, adding the attribute if it did not exist. There is no real namespace parsing
2700
+ * here, so this ignores the namespace and behaves exactly like setAttribute.
2701
+ * @param {string} namespace Ignored
2702
+ * @param {string} attributeName
2703
+ * @param {string} attributeValue
2704
+ * @returns {undefined}
2705
+ */
2706
+ setAttributeNS (namespace, attributeName, attributeValue) {
2707
+ this.setAttribute(attributeName, attributeValue)
2708
+ }
2709
+
2608
2710
  /**
2609
2711
  * Add the attribute (with an empty value) when it is not present, or remove it when it is - unless force says
2610
2712
  * which of those to do instead. Returns whether the attribute is present after the call.