pseudo-dom 0.10.0 → 0.11.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 +142 -5
- package/browser/pseudo-dom.js +2948 -584
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/factories/parseHTML.d.ts +13 -0
- package/dist/factories/parseHTML.js +84 -0
- package/dist/factories/parseHTML.min.js +1 -0
- package/dist/factories/serializeHTML.d.ts +15 -0
- package/dist/factories/serializeHTML.js +114 -0
- package/dist/factories/serializeHTML.min.js +1 -0
- package/dist/interfaces/PseudoElement.d.ts +2 -2
- package/dist/interfaces/PseudoShadowRoot.d.ts +12 -12
- package/dist/services/ElementService.d.ts +11 -1
- package/dist/services/ElementService.js +18 -3
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/HTMLElementService.d.ts +119 -87
- package/dist/services/HTMLElementService.js +269 -202
- package/dist/services/HTMLElementService.min.js +1 -1
- package/dist/services/NodeService.d.ts +305 -305
- package/dist/services/NodeService.js +732 -732
- package/dist/services/ShadowRootService.d.ts +16 -16
- package/dist/services/ShadowRootService.js +24 -24
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -49,8 +49,15 @@ Elements can be walked and changed like the DOM: \`children\` is a live \`HTMLCo
|
|
|
49
49
|
children, \`childElementCount\`, \`firstElementChild\` / \`lastElementChild\` and \`nextElementSibling\` /
|
|
50
50
|
\`previousElementSibling\` skip text and comment nodes. \`append\` / \`prepend\` / \`before\` / \`after\` / \`remove\` /
|
|
51
51
|
\`replaceWith\` / \`replaceChildren\` accept nodes or strings (a string becomes a text node) and move a node already in
|
|
52
|
-
a tree rather than duplicating it; \`insertAdjacentElement\` / \`insertAdjacentText\` insert at
|
|
53
|
-
/ beforeend / afterend
|
|
52
|
+
a tree rather than duplicating it; \`insertAdjacentElement\` / \`insertAdjacentText\` / \`insertAdjacentHTML\` insert at
|
|
53
|
+
beforebegin / afterbegin / beforeend / afterend.
|
|
54
|
+
|
|
55
|
+
\`innerHTML\` / \`outerHTML\` parse and serialize real HTML, via [htmlparser2](https://www.npmjs.com/package/htmlparser2)
|
|
56
|
+
(a SAX-style tokenizer; pseudo-dom builds its own nodes from its events, the same way it builds a tree from
|
|
57
|
+
\`css-select\`'s selector matches) - entities decode, void elements (\`br\`, \`img\`, ...) auto-close, and \`class\` /
|
|
58
|
+
\`style\` attributes populate \`className\`/\`classList\` and \`style\` for real, not just a generic attribute. The
|
|
59
|
+
setters (\`innerHTML =\`, \`outerHTML =\`) and \`insertAdjacentHTML\` are on \`HTMLElementService\` (they need to build
|
|
60
|
+
real \`HTMLElement\`s); \`ElementService\` only has the getters (serializing is fine without them).
|
|
54
61
|
|
|
55
62
|
Selector queries work like the DOM's: \`getElementsByTagName\` / \`getElementsByClassName\` (live, on any node) and
|
|
56
63
|
\`querySelector\` / \`querySelectorAll\` (real CSS selectors, via [css-select](https://www.npmjs.com/package/css-select)
|
|
@@ -84,9 +91,9 @@ for real; \`scrollIntoView\` is a real callable no-op (there is no viewport to s
|
|
|
84
91
|
\`requestFullscreen\` / \`requestPointerLock\` resolve, like a browser granting the request would.
|
|
85
92
|
\`computedStyleMap()\` is a thin read-only view of the element's own inline style (there is no CSS cascade).
|
|
86
93
|
|
|
87
|
-
Not implemented yet (these throw a "not implemented" error or are missing): \`
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
Not implemented yet (these throw a "not implemented" error or are missing): the \`aria*\` reflected properties, and
|
|
95
|
+
the \`Attr\`-node / namespaced attribute methods (\`getAttributeNode\`, \`getAttributeNS\`, ...). The API will change
|
|
96
|
+
before 1.0.
|
|
90
97
|
## Modules
|
|
91
98
|
|
|
92
99
|
<dl>
|
|
@@ -235,6 +242,19 @@ order in which an event travels down through them). A node which has no parent h
|
|
|
235
242
|
<dt><a href="#setActiveElement">setActiveElement(root, element)</a></dt>
|
|
236
243
|
<dd><p>Remember the element which has the focus in a tree.</p>
|
|
237
244
|
</dd>
|
|
245
|
+
<dt><a href="#escapeText">escapeText(text)</a> ⇒ <code>string</code></dt>
|
|
246
|
+
<dd><p>Escape text so it is safe inside HTML text content.</p>
|
|
247
|
+
</dd>
|
|
248
|
+
<dt><a href="#escapeAttributeValue">escapeAttributeValue(value)</a> ⇒ <code>string</code></dt>
|
|
249
|
+
<dd><p>Escape a value so it is safe inside a double-quoted HTML attribute.</p>
|
|
250
|
+
</dd>
|
|
251
|
+
<dt><a href="#serializeAttributes">serializeAttributes(element)</a> ⇒ <code>string</code></dt>
|
|
252
|
+
<dd><p>Every attribute of the element, serialized (class instead of className, boolean attributes bare, the never-real
|
|
253
|
+
mock properties left out, style added from the live CSSStyleDeclaration when it is not empty).</p>
|
|
254
|
+
</dd>
|
|
255
|
+
<dt><a href="#serializeNode">serializeNode(node)</a> ⇒ <code>string</code></dt>
|
|
256
|
+
<dd><p>One node, serialized (its own markup only - see serializeChildren for its descendants too).</p>
|
|
257
|
+
</dd>
|
|
238
258
|
<dt><a href="#generateNodeList">generateNodeList([innerList])</a> ⇒ <code><a href="#PseudoNodeList">PseudoNodeList</a></code></dt>
|
|
239
259
|
<dd><p>Create a PseudoNodeList, optionally starting from an existing chain of linkers.</p>
|
|
240
260
|
</dd>
|
|
@@ -2327,9 +2347,13 @@ Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
|
2327
2347
|
* [new HTMLElementService([elementOptions])](#new_HTMLElementService_new)
|
|
2328
2348
|
* [.style](#HTMLElementService+style) ⇒ [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
2329
2349
|
* [.dataset](#HTMLElementService+dataset) ⇒ <code>Object.<string, string></code>
|
|
2350
|
+
* [.innerHTML](#HTMLElementService+innerHTML) ⇒ <code>undefined</code>
|
|
2351
|
+
* [.outerHTML](#HTMLElementService+outerHTML) ⇒ <code>undefined</code>
|
|
2330
2352
|
* [.canFocus](#HTMLElementService+canFocus) ⇒ <code>boolean</code>
|
|
2331
2353
|
* [.cloneShallow()](#HTMLElementService+cloneShallow) ⇒ [<code>NodeService</code>](#NodeService)
|
|
2332
2354
|
* [.equalsShallow(other)](#HTMLElementService+equalsShallow) ⇒ <code>boolean</code>
|
|
2355
|
+
* [.parse(html)](#HTMLElementService+parse) ⇒ <code>Array.<\*></code>
|
|
2356
|
+
* [.insertAdjacentHTML(position, html)](#HTMLElementService+insertAdjacentHTML) ⇒ <code>undefined</code>
|
|
2333
2357
|
* [.click()](#HTMLElementService+click)
|
|
2334
2358
|
* [.focus()](#HTMLElementService+focus)
|
|
2335
2359
|
* [.blur()](#HTMLElementService+blur)
|
|
@@ -2361,6 +2385,30 @@ The element's data-* attributes, live, under their camelCase names (data-foo-bar
|
|
|
2361
2385
|
directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
|
|
2362
2386
|
|
|
2363
2387
|
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2388
|
+
<a name="HTMLElementService+innerHTML"></a>
|
|
2389
|
+
|
|
2390
|
+
### htmlElementService.innerHTML ⇒ <code>undefined</code>
|
|
2391
|
+
Replace this element's children by parsing html. innerHTML's setter is here rather than on ElementService (which
|
|
2392
|
+
only has the getter) because building the new elements needs a concrete element class - see parse().
|
|
2393
|
+
|
|
2394
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2395
|
+
|
|
2396
|
+
| Param | Type |
|
|
2397
|
+
| --- | --- |
|
|
2398
|
+
| html | <code>string</code> |
|
|
2399
|
+
|
|
2400
|
+
<a name="HTMLElementService+outerHTML"></a>
|
|
2401
|
+
|
|
2402
|
+
### htmlElementService.outerHTML ⇒ <code>undefined</code>
|
|
2403
|
+
Replace this element itself, in its parent, by parsing html. Does nothing when it has no parent, like
|
|
2404
|
+
replaceWith. outerHTML's setter is here rather than on ElementService for the same reason as innerHTML's.
|
|
2405
|
+
|
|
2406
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2407
|
+
|
|
2408
|
+
| Param | Type |
|
|
2409
|
+
| --- | --- |
|
|
2410
|
+
| html | <code>string</code> |
|
|
2411
|
+
|
|
2364
2412
|
<a name="HTMLElementService+canFocus"></a>
|
|
2365
2413
|
|
|
2366
2414
|
### htmlElementService.canFocus ⇒ <code>boolean</code>
|
|
@@ -2384,6 +2432,35 @@ Style is not attribute-backed like most properties, so isEqualNode needs to comp
|
|
|
2384
2432
|
| --- | --- | --- |
|
|
2385
2433
|
| other | [<code>NodeService</code>](#NodeService) | The node to compare with |
|
|
2386
2434
|
|
|
2435
|
+
<a name="HTMLElementService+parse"></a>
|
|
2436
|
+
|
|
2437
|
+
### htmlElementService.parse(html) ⇒ <code>Array.<\*></code>
|
|
2438
|
+
Parses html with this class building each new element (matches HTML: parsed elements behave like plain
|
|
2439
|
+
HTMLElements, not whatever specialized class happens to be setting innerHTML / outerHTML).
|
|
2440
|
+
|
|
2441
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2442
|
+
|
|
2443
|
+
| Param | Type |
|
|
2444
|
+
| --- | --- |
|
|
2445
|
+
| html | <code>string</code> |
|
|
2446
|
+
|
|
2447
|
+
<a name="HTMLElementService+insertAdjacentHTML"></a>
|
|
2448
|
+
|
|
2449
|
+
### htmlElementService.insertAdjacentHTML(position, html) ⇒ <code>undefined</code>
|
|
2450
|
+
Parse html and insert the resulting nodes at the given position, like insertAdjacentElement /
|
|
2451
|
+
insertAdjacentText.
|
|
2452
|
+
|
|
2453
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2454
|
+
**Throws**:
|
|
2455
|
+
|
|
2456
|
+
- <code>Error</code> When the position is not one of the four above
|
|
2457
|
+
|
|
2458
|
+
|
|
2459
|
+
| Param | Type | Description |
|
|
2460
|
+
| --- | --- | --- |
|
|
2461
|
+
| position | <code>string</code> | beforebegin, afterbegin, beforeend or afterend |
|
|
2462
|
+
| html | <code>string</code> | The markup to parse |
|
|
2463
|
+
|
|
2387
2464
|
<a name="HTMLElementService+click"></a>
|
|
2388
2465
|
|
|
2389
2466
|
### htmlElementService.click()
|
|
@@ -2773,6 +2850,8 @@ Simulate the behaviour of the Element Class when there is no DOM available.
|
|
|
2773
2850
|
* [.isVisible](#ElementService+isVisible)
|
|
2774
2851
|
* [.localName](#ElementService+localName) ⇒ <code>string</code>
|
|
2775
2852
|
* [.prefix](#ElementService+prefix) ⇒ <code>string</code> \| <code>null</code>
|
|
2853
|
+
* [.innerHTML](#ElementService+innerHTML) ⇒ <code>string</code>
|
|
2854
|
+
* [.outerHTML](#ElementService+outerHTML) ⇒ <code>string</code>
|
|
2776
2855
|
* [.children](#ElementService+children) ⇒ <code>PseudoHTMLCollection</code>
|
|
2777
2856
|
* [.childElementCount](#ElementService+childElementCount) ⇒ <code>number</code>
|
|
2778
2857
|
* [.firstElementChild](#ElementService+firstElementChild) ⇒ <code>PseudoElement</code> \| <code>null</code>
|
|
@@ -2862,6 +2941,19 @@ same as tagName.
|
|
|
2862
2941
|
The element's namespace prefix, or null when it has none. There is no real namespace parsing here, so this is
|
|
2863
2942
|
always null.
|
|
2864
2943
|
|
|
2944
|
+
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
2945
|
+
<a name="ElementService+innerHTML"></a>
|
|
2946
|
+
|
|
2947
|
+
### elementService.innerHTML ⇒ <code>string</code>
|
|
2948
|
+
The HTML markup of this element's children. Only the getter is here (the setter, which needs to build new
|
|
2949
|
+
elements from parsed HTML, is on HTMLElementService - see its class comment).
|
|
2950
|
+
|
|
2951
|
+
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
2952
|
+
<a name="ElementService+outerHTML"></a>
|
|
2953
|
+
|
|
2954
|
+
### elementService.outerHTML ⇒ <code>string</code>
|
|
2955
|
+
The HTML markup of this element itself, including its children. Only the getter is here (see innerHTML).
|
|
2956
|
+
|
|
2865
2957
|
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
2866
2958
|
<a name="ElementService+children"></a>
|
|
2867
2959
|
|
|
@@ -5310,6 +5402,51 @@ Remember the element which has the focus in a tree.
|
|
|
5310
5402
|
| root | <code>Object</code> | The root node of the tree |
|
|
5311
5403
|
| element | <code>Object</code> \| <code>null</code> | The element which now has the focus, or null when nothing has it |
|
|
5312
5404
|
|
|
5405
|
+
<a name="escapeText"></a>
|
|
5406
|
+
|
|
5407
|
+
## escapeText(text) ⇒ <code>string</code>
|
|
5408
|
+
Escape text so it is safe inside HTML text content.
|
|
5409
|
+
|
|
5410
|
+
**Kind**: global function
|
|
5411
|
+
|
|
5412
|
+
| Param | Type |
|
|
5413
|
+
| --- | --- |
|
|
5414
|
+
| text | <code>string</code> |
|
|
5415
|
+
|
|
5416
|
+
<a name="escapeAttributeValue"></a>
|
|
5417
|
+
|
|
5418
|
+
## escapeAttributeValue(value) ⇒ <code>string</code>
|
|
5419
|
+
Escape a value so it is safe inside a double-quoted HTML attribute.
|
|
5420
|
+
|
|
5421
|
+
**Kind**: global function
|
|
5422
|
+
|
|
5423
|
+
| Param | Type |
|
|
5424
|
+
| --- | --- |
|
|
5425
|
+
| value | <code>string</code> |
|
|
5426
|
+
|
|
5427
|
+
<a name="serializeAttributes"></a>
|
|
5428
|
+
|
|
5429
|
+
## serializeAttributes(element) ⇒ <code>string</code>
|
|
5430
|
+
Every attribute of the element, serialized (class instead of className, boolean attributes bare, the never-real
|
|
5431
|
+
mock properties left out, style added from the live CSSStyleDeclaration when it is not empty).
|
|
5432
|
+
|
|
5433
|
+
**Kind**: global function
|
|
5434
|
+
|
|
5435
|
+
| Param | Type |
|
|
5436
|
+
| --- | --- |
|
|
5437
|
+
| element | <code>\*</code> |
|
|
5438
|
+
|
|
5439
|
+
<a name="serializeNode"></a>
|
|
5440
|
+
|
|
5441
|
+
## serializeNode(node) ⇒ <code>string</code>
|
|
5442
|
+
One node, serialized (its own markup only - see serializeChildren for its descendants too).
|
|
5443
|
+
|
|
5444
|
+
**Kind**: global function
|
|
5445
|
+
|
|
5446
|
+
| Param | Type |
|
|
5447
|
+
| --- | --- |
|
|
5448
|
+
| node | <code>\*</code> |
|
|
5449
|
+
|
|
5313
5450
|
<a name="generateNodeList"></a>
|
|
5314
5451
|
|
|
5315
5452
|
## generateNodeList([innerList]) ⇒ [<code>PseudoNodeList</code>](#PseudoNodeList)
|