pseudo-dom 0.10.0 → 0.12.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 +313 -84
- package/browser/pseudo-dom.js +3270 -538
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/factories/generateDocument.js +70 -65
- package/dist/factories/generateDocument.min.js +1 -1
- package/dist/factories/installGlobal.d.ts +14 -0
- package/dist/factories/installGlobal.js +40 -0
- package/dist/factories/installGlobal.min.js +1 -0
- package/dist/factories/logElement.d.ts +9 -0
- package/dist/factories/logElement.js +23 -0
- package/dist/factories/logElement.min.js +1 -0
- 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 +25 -0
- package/dist/factories/serializeHTML.js +156 -0
- package/dist/factories/serializeHTML.min.js +1 -0
- package/dist/interfaces/PseudoElement.d.ts +765 -765
- package/dist/interfaces/PseudoShadowRoot.d.ts +12 -12
- package/dist/main.d.ts +69 -63
- package/dist/main.js +169 -155
- package/dist/main.min.js +1 -1
- package/dist/services/ElementService.d.ts +371 -361
- package/dist/services/ElementService.js +732 -717
- package/dist/services/ElementService.min.js +1 -1
- package/dist/services/HTMLElementService.d.ts +32 -0
- package/dist/services/HTMLElementService.js +67 -0
- 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 +4 -2
package/README.md
CHANGED
|
@@ -1,92 +1,173 @@
|
|
|
1
1
|
# Pseudo DOM
|
|
2
2
|
|
|
3
|
-
Mock the DOM for server
|
|
3
|
+
Mock the DOM for server-side DOM state and in tests.
|
|
4
4
|
|
|
5
5
|
## Status: early development (0.x)
|
|
6
6
|
|
|
7
|
-
Pseudo DOM recreates the browser DOM API (following the MDN documentation) so DOM-dependent code can run in Node
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`generateDocument`
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
7
|
+
Pseudo DOM recreates the browser DOM API (following the MDN documentation) so DOM-dependent code can run in Node -
|
|
8
|
+
in tests, without a real or headless browser. It's written in TypeScript and ships type definitions. The API will
|
|
9
|
+
change before 1.0.
|
|
10
|
+
|
|
11
|
+
## At a glance
|
|
12
|
+
|
|
13
|
+
- **Tree & events** - a real node tree with full event dispatch (capture → target → bubble) and standard event
|
|
14
|
+
defaults for clicks, focus and more
|
|
15
|
+
- **Elements** - attributes, `classList`, a real live `style` and `dataset`, `children`, and DOM-style mutation
|
|
16
|
+
(`append`, `before`, `remove`, `replaceWith`, ...)
|
|
17
|
+
- **HTML parsing** - `innerHTML` / `outerHTML` / `insertAdjacentHTML` parse and serialize real HTML
|
|
18
|
+
- **Queries** - `querySelector` / `querySelectorAll` with real CSS selectors, `getElementById`, `matches`, `closest`
|
|
19
|
+
- **Document** - `createElement`, `createTextNode`, and `generateDocument()` to get a `window`-like object with
|
|
20
|
+
`document` already on it
|
|
21
|
+
- **Cloning & comparison** - `cloneNode`, `isEqualNode`, `compareDocumentPosition`, `contains`
|
|
22
|
+
- **Running headlessly** - `installGlobal()` makes code written against real DOM globals (`document.createElement`,
|
|
23
|
+
...) run unmodified in Node; `logElement()` prints a readable, indented view of an element to the console
|
|
24
|
+
|
|
25
|
+
Everything below goes into more detail, section by section.
|
|
26
|
+
|
|
27
|
+
## Tree, nodes & events
|
|
28
|
+
|
|
29
|
+
A real tree: `parentNode`, `previousSibling` / `nextSibling`, `firstChild` / `lastChild`, `appendChild`,
|
|
30
|
+
`insertBefore`, `removeChild`, `replaceChild`, `contains`, `getRootNode`. Nodes move when they're added somewhere
|
|
31
|
+
else, document fragments insert their children instead of themselves, and a node can't be put inside itself.
|
|
32
|
+
|
|
33
|
+
`EventService` / `EventTargetService` dispatch an event through the tree the way the DOM does:
|
|
34
|
+
|
|
35
|
+
- Capture down from the root, hit the target, then bubble back up
|
|
36
|
+
- `stopPropagation`, `stopImmediatePropagation`, `once`, `passive`, `preventDefault`, and the target's default action
|
|
37
|
+
(clicking a submit button sends a `submit` event to its form)
|
|
38
|
+
- `createEvent(type, init, { browser, trusted })` makes the kind of event that suits the type (a click is a
|
|
39
|
+
`MouseEvent`, a keydown a `KeyboardEvent`, ...). Like a real constructor, it gives nothing (no bubbling, no
|
|
40
|
+
cancelling, not trusted) unless asked - but `browser: true` applies `eventDefaults`, the table of how a browser
|
|
41
|
+
creates each standard type (click bubbles and can be cancelled; focus doesn't bubble but focusin does; input
|
|
42
|
+
bubbles but can't be cancelled; ...), and `trusted: true` makes `isTrusted` true, as for a real user action
|
|
43
|
+
- The event kinds: `PseudoUIEvent`, `PseudoMouseEvent`, `PseudoPointerEvent`, `PseudoKeyboardEvent`,
|
|
44
|
+
`PseudoFocusEvent`, `PseudoInputEvent`, `PseudoCustomEvent`
|
|
45
|
+
- Elements have `click()` (an untrusted click, like a script's) and `focus()` / `blur()` (blur/focusout/focus/focusin
|
|
46
|
+
and the related targets, with a focused element tracked per tree)
|
|
47
|
+
- `simulate.click(element)` / `simulate.keyPress(element, key)` send what a real user action sends - pointerdown,
|
|
48
|
+
mousedown, the focus moving, pointerup, mouseup, click; keydown, keyup - all trusted
|
|
49
|
+
|
|
50
|
+
## Elements
|
|
51
|
+
|
|
52
|
+
`ElementService` / `HTMLElementService` cover `Element` and `HTMLElement`: attributes, `NamedNodeMap`, `classList`.
|
|
53
|
+
`AttrService`, `DOMTokenListService` and `NamedNodeMapService` back them.
|
|
54
|
+
|
|
55
|
+
**Attribute helpers** work like the DOM's: `getAttributeNames`, `hasAttributes`, `toggleAttribute(name, [force])`.
|
|
56
|
+
`localName` matches `tagName` and `prefix` is always `null` (there's no real namespace parsing);
|
|
57
|
+
`getElementsByTagNameNS` behaves exactly like `getElementsByTagName`, ignoring the namespace.
|
|
58
|
+
|
|
59
|
+
**`style`** is a real, live `CSSStyleDeclaration`:
|
|
60
|
+
|
|
61
|
+
- Named property access (`el.style.backgroundColor = 'red'`) alongside `getPropertyValue` / `setProperty` /
|
|
62
|
+
`removeProperty` / `getPropertyPriority` / `cssText`
|
|
63
|
+
- An unset property reads as `''`, like the DOM's
|
|
64
|
+
|
|
65
|
+
**`dataset`** is a live `DOMStringMap`: reading/writing/deleting a camelCase name (`el.dataset.fooBar`)
|
|
66
|
+
reads/writes/removes the matching `data-foo-bar` attribute directly, so it can never fall out of sync with the
|
|
67
|
+
attributes themselves.
|
|
68
|
+
|
|
69
|
+
*(`style` and `dataset` are both on `HTMLElementService`, matching the DOM - they're not on the base `Element`.)*
|
|
70
|
+
|
|
71
|
+
**Traversal & mutation** work like the DOM's:
|
|
72
|
+
|
|
73
|
+
- `children` is a live `HTMLCollection` of just the element children; `childElementCount`, `firstElementChild` /
|
|
74
|
+
`lastElementChild` and `nextElementSibling` / `previousElementSibling` skip text and comment nodes
|
|
75
|
+
- `append` / `prepend` / `before` / `after` / `remove` / `replaceWith` / `replaceChildren` accept nodes or strings (a
|
|
76
|
+
string becomes a text node), and move a node already in a tree rather than duplicating it
|
|
77
|
+
- `insertAdjacentElement` / `insertAdjacentText` / `insertAdjacentHTML` insert at beforebegin / afterbegin /
|
|
78
|
+
beforeend / afterend
|
|
79
|
+
|
|
80
|
+
**`attachShadow({mode})`** attaches a real (`DocumentFragmentService`-based) `ShadowRoot`, with `host` and `mode`
|
|
81
|
+
set. `element.shadowRoot` reaches it when the mode is `'open'`, like the DOM's (a `'closed'` one still exists, just
|
|
82
|
+
not reachable this way); attaching a second one throws.
|
|
83
|
+
|
|
84
|
+
### HTML parsing
|
|
85
|
+
|
|
86
|
+
`innerHTML` / `outerHTML` / `insertAdjacentHTML` parse and serialize real HTML, via
|
|
87
|
+
[htmlparser2](https://www.npmjs.com/package/htmlparser2) (a SAX-style tokenizer - pseudo-dom builds its own nodes
|
|
88
|
+
from its events, the same way it builds matches from `css-select`).
|
|
89
|
+
|
|
90
|
+
- Entities decode, and void elements (`br`, `img`, ...) auto-close
|
|
91
|
+
- `class` / `style` attributes populate `className` / `classList` and `style` for real, not just a generic attribute
|
|
92
|
+
- The setters (`innerHTML =`, `outerHTML =`) and `insertAdjacentHTML` are on `HTMLElementService` (building new
|
|
93
|
+
elements needs a concrete element class); `ElementService` only has the getters, since serializing doesn't
|
|
94
|
+
|
|
95
|
+
### Layout (mocked, not computed)
|
|
96
|
+
|
|
97
|
+
There's no layout engine, so anything that would need one is **settable directly** rather than really computed - set
|
|
98
|
+
the value a test needs, and the getter/method returns it:
|
|
99
|
+
|
|
100
|
+
- `clientWidth` / `clientHeight` / `clientTop` / `clientLeft` / `scrollWidth` / `scrollHeight` (plain numbers,
|
|
101
|
+
alongside the existing `offsetWidth` etc.)
|
|
102
|
+
- `boundingClientRect` backs `getBoundingClientRect()`, `clientRects` backs `getClientRects()`, `animations` backs
|
|
103
|
+
`getAnimations()`, `isVisible` backs `checkVisibility()`
|
|
104
|
+
|
|
105
|
+
A few things in this group are genuinely real, not mocked:
|
|
106
|
+
|
|
107
|
+
- `scrollLeft` / `scrollTop` are plain settable numbers, and `scroll` / `scrollTo` / `scrollBy` (a number pair or an
|
|
108
|
+
options object) update them for real; `scrollIntoView` is a callable no-op (there's no viewport to scroll within)
|
|
109
|
+
- `hasPointerCapture` / `setPointerCapture` / `releasePointerCapture` genuinely track capture per pointer id
|
|
110
|
+
- `requestFullscreen` / `requestPointerLock` resolve, like a browser granting the request would
|
|
111
|
+
- `computedStyleMap()` is a thin read-only view of the element's own inline style (there's no CSS cascade)
|
|
112
|
+
|
|
113
|
+
## Queries
|
|
114
|
+
|
|
115
|
+
`getElementsByTagName` / `getElementsByClassName` (live, on any node) and `querySelector` / `querySelectorAll` (real
|
|
116
|
+
CSS selectors, via [css-select](https://www.npmjs.com/package/css-select) matched against pseudo-dom's own tree
|
|
117
|
+
through a custom adapter) are on `NodeService`, so `Document`, `DocumentFragment` and `Element` all have them.
|
|
118
|
+
`querySelectorAll` returns a plain array - a snapshot taken when it's called, like the DOM's.
|
|
119
|
+
|
|
120
|
+
`matches` / `closest` are on `ElementService`. `getElementById` is on both `DocumentService` and
|
|
121
|
+
`DocumentFragmentService` (the DOM's `NonElementParentNode` mixin, so a `ShadowRoot` gets it too).
|
|
122
|
+
|
|
123
|
+
## Document
|
|
124
|
+
|
|
125
|
+
`DocumentService` matches the real `Document` - it's not an `Element`, so it has no `tagName` / `classList` /
|
|
126
|
+
`matches` / etc:
|
|
127
|
+
|
|
128
|
+
- `createElement`, `createTextNode`, `createComment`, `createDocumentFragment`
|
|
129
|
+
- `getElementById`
|
|
130
|
+
- `textContent` is always `null`
|
|
131
|
+
|
|
132
|
+
`DocumentFragmentService` is the plain `DocumentFragment`. `PseudoHTMLDocument` - what `generateDocument()` actually
|
|
133
|
+
creates - only adds the `html` / `head` / `body` structure on top of `DocumentService`. `PseudoNodeList` backs
|
|
134
|
+
`childNodes`.
|
|
135
|
+
|
|
136
|
+
## Running headlessly
|
|
137
|
+
|
|
138
|
+
Code written against a real DOM's globals (`document.createElement`, `new Node()`, ...) can run unmodified in Node,
|
|
139
|
+
without an `if (typeof document === 'undefined')` check at every call site:
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
if (typeof document === 'undefined') {
|
|
143
|
+
require('pseudo-dom').installGlobal(globalThis)
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`installGlobal(target = globalThis)` fills in `document` / `Node` / `Element` / `HTMLElement` on `target`, using
|
|
148
|
+
[browser-or-node](https://www.npmjs.com/package/browser-or-node) to check whether a real DOM (a real browser, or a
|
|
149
|
+
jsdom-based test environment) is already there first - it's always safe to call, everywhere: it does nothing when
|
|
150
|
+
one is.
|
|
151
|
+
|
|
152
|
+
There's no real rendering to look at, so `logElement(node, [label])` prints a readable, indented view of a node's
|
|
153
|
+
markup to the console (`prettyPrint(node, [indent])`, from the same module, returns the string instead of printing
|
|
154
|
+
it) - useful for watching pseudo-dom-driven code run, or checking a final result, from a terminal.
|
|
155
|
+
|
|
156
|
+
## Cloning, comparison & connection
|
|
157
|
+
|
|
158
|
+
- `cloneNode(deep)` copies an element with its attributes (objects such as `style` are copied too, not shared) and,
|
|
159
|
+
when deep, everything below it - without the parent or the event listeners
|
|
160
|
+
- `isEqualNode` compares two nodes by what they hold (tag, attributes in any order, text and children in order)
|
|
161
|
+
- `compareDocumentPosition` says where another node is (`NodeService.DOCUMENT_POSITION_*`)
|
|
162
|
+
- `isConnected` is true when the tree has a document at the top; `ownerDocument` says which one made the node
|
|
163
|
+
- `normalize` joins neighbouring text nodes
|
|
164
|
+
- There are text and comment nodes (`PseudoText`, `PseudoComment`); `textContent` works like the DOM's (the text of
|
|
165
|
+
everything below, and setting it replaces the children with a text node)
|
|
166
|
+
|
|
167
|
+
## Not implemented yet
|
|
168
|
+
|
|
169
|
+
- The `aria*` reflected properties
|
|
170
|
+
- The `Attr`-node / namespaced attribute methods (`getAttributeNode`, `getAttributeNS`, ...)
|
|
90
171
|
## Modules
|
|
91
172
|
|
|
92
173
|
<dl>
|
|
@@ -235,6 +316,23 @@ order in which an event travels down through them). A node which has no parent h
|
|
|
235
316
|
<dt><a href="#setActiveElement">setActiveElement(root, element)</a></dt>
|
|
236
317
|
<dd><p>Remember the element which has the focus in a tree.</p>
|
|
237
318
|
</dd>
|
|
319
|
+
<dt><a href="#escapeText">escapeText(text)</a> ⇒ <code>string</code></dt>
|
|
320
|
+
<dd><p>Escape text so it is safe inside HTML text content.</p>
|
|
321
|
+
</dd>
|
|
322
|
+
<dt><a href="#escapeAttributeValue">escapeAttributeValue(value)</a> ⇒ <code>string</code></dt>
|
|
323
|
+
<dd><p>Escape a value so it is safe inside a double-quoted HTML attribute.</p>
|
|
324
|
+
</dd>
|
|
325
|
+
<dt><a href="#serializeAttributes">serializeAttributes(element)</a> ⇒ <code>string</code></dt>
|
|
326
|
+
<dd><p>Every attribute of the element, serialized (class instead of className, boolean attributes bare, the never-real
|
|
327
|
+
mock properties left out, style added from the live CSSStyleDeclaration when it is not empty).</p>
|
|
328
|
+
</dd>
|
|
329
|
+
<dt><a href="#serializeNode">serializeNode(node)</a> ⇒ <code>string</code></dt>
|
|
330
|
+
<dd><p>One node, serialized (its own markup only - see serializeChildren for its descendants too).</p>
|
|
331
|
+
</dd>
|
|
332
|
+
<dt><a href="#prettyPrintNode">prettyPrintNode(node, depth, indent)</a> ⇒ <code>string</code></dt>
|
|
333
|
+
<dd><p>One node, indented for readability (see prettyPrint) - unlike serializeNode, every non-empty node is its own
|
|
334
|
+
line, so the structure of a whole tree is easy to read at a glance.</p>
|
|
335
|
+
</dd>
|
|
238
336
|
<dt><a href="#generateNodeList">generateNodeList([innerList])</a> ⇒ <code><a href="#PseudoNodeList">PseudoNodeList</a></code></dt>
|
|
239
337
|
<dd><p>Create a PseudoNodeList, optionally starting from an existing chain of linkers.</p>
|
|
240
338
|
</dd>
|
|
@@ -2327,9 +2425,13 @@ Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
|
2327
2425
|
* [new HTMLElementService([elementOptions])](#new_HTMLElementService_new)
|
|
2328
2426
|
* [.style](#HTMLElementService+style) ⇒ [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
2329
2427
|
* [.dataset](#HTMLElementService+dataset) ⇒ <code>Object.<string, string></code>
|
|
2428
|
+
* [.innerHTML](#HTMLElementService+innerHTML) ⇒ <code>undefined</code>
|
|
2429
|
+
* [.outerHTML](#HTMLElementService+outerHTML) ⇒ <code>undefined</code>
|
|
2330
2430
|
* [.canFocus](#HTMLElementService+canFocus) ⇒ <code>boolean</code>
|
|
2331
2431
|
* [.cloneShallow()](#HTMLElementService+cloneShallow) ⇒ [<code>NodeService</code>](#NodeService)
|
|
2332
2432
|
* [.equalsShallow(other)](#HTMLElementService+equalsShallow) ⇒ <code>boolean</code>
|
|
2433
|
+
* [.parse(html)](#HTMLElementService+parse) ⇒ <code>Array.<\*></code>
|
|
2434
|
+
* [.insertAdjacentHTML(position, html)](#HTMLElementService+insertAdjacentHTML) ⇒ <code>undefined</code>
|
|
2333
2435
|
* [.click()](#HTMLElementService+click)
|
|
2334
2436
|
* [.focus()](#HTMLElementService+focus)
|
|
2335
2437
|
* [.blur()](#HTMLElementService+blur)
|
|
@@ -2361,6 +2463,30 @@ The element's data-* attributes, live, under their camelCase names (data-foo-bar
|
|
|
2361
2463
|
directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
|
|
2362
2464
|
|
|
2363
2465
|
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2466
|
+
<a name="HTMLElementService+innerHTML"></a>
|
|
2467
|
+
|
|
2468
|
+
### htmlElementService.innerHTML ⇒ <code>undefined</code>
|
|
2469
|
+
Replace this element's children by parsing html. innerHTML's setter is here rather than on ElementService (which
|
|
2470
|
+
only has the getter) because building the new elements needs a concrete element class - see parse().
|
|
2471
|
+
|
|
2472
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2473
|
+
|
|
2474
|
+
| Param | Type |
|
|
2475
|
+
| --- | --- |
|
|
2476
|
+
| html | <code>string</code> |
|
|
2477
|
+
|
|
2478
|
+
<a name="HTMLElementService+outerHTML"></a>
|
|
2479
|
+
|
|
2480
|
+
### htmlElementService.outerHTML ⇒ <code>undefined</code>
|
|
2481
|
+
Replace this element itself, in its parent, by parsing html. Does nothing when it has no parent, like
|
|
2482
|
+
replaceWith. outerHTML's setter is here rather than on ElementService for the same reason as innerHTML's.
|
|
2483
|
+
|
|
2484
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2485
|
+
|
|
2486
|
+
| Param | Type |
|
|
2487
|
+
| --- | --- |
|
|
2488
|
+
| html | <code>string</code> |
|
|
2489
|
+
|
|
2364
2490
|
<a name="HTMLElementService+canFocus"></a>
|
|
2365
2491
|
|
|
2366
2492
|
### htmlElementService.canFocus ⇒ <code>boolean</code>
|
|
@@ -2384,6 +2510,35 @@ Style is not attribute-backed like most properties, so isEqualNode needs to comp
|
|
|
2384
2510
|
| --- | --- | --- |
|
|
2385
2511
|
| other | [<code>NodeService</code>](#NodeService) | The node to compare with |
|
|
2386
2512
|
|
|
2513
|
+
<a name="HTMLElementService+parse"></a>
|
|
2514
|
+
|
|
2515
|
+
### htmlElementService.parse(html) ⇒ <code>Array.<\*></code>
|
|
2516
|
+
Parses html with this class building each new element (matches HTML: parsed elements behave like plain
|
|
2517
|
+
HTMLElements, not whatever specialized class happens to be setting innerHTML / outerHTML).
|
|
2518
|
+
|
|
2519
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2520
|
+
|
|
2521
|
+
| Param | Type |
|
|
2522
|
+
| --- | --- |
|
|
2523
|
+
| html | <code>string</code> |
|
|
2524
|
+
|
|
2525
|
+
<a name="HTMLElementService+insertAdjacentHTML"></a>
|
|
2526
|
+
|
|
2527
|
+
### htmlElementService.insertAdjacentHTML(position, html) ⇒ <code>undefined</code>
|
|
2528
|
+
Parse html and insert the resulting nodes at the given position, like insertAdjacentElement /
|
|
2529
|
+
insertAdjacentText.
|
|
2530
|
+
|
|
2531
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
2532
|
+
**Throws**:
|
|
2533
|
+
|
|
2534
|
+
- <code>Error</code> When the position is not one of the four above
|
|
2535
|
+
|
|
2536
|
+
|
|
2537
|
+
| Param | Type | Description |
|
|
2538
|
+
| --- | --- | --- |
|
|
2539
|
+
| position | <code>string</code> | beforebegin, afterbegin, beforeend or afterend |
|
|
2540
|
+
| html | <code>string</code> | The markup to parse |
|
|
2541
|
+
|
|
2387
2542
|
<a name="HTMLElementService+click"></a>
|
|
2388
2543
|
|
|
2389
2544
|
### htmlElementService.click()
|
|
@@ -2773,6 +2928,8 @@ Simulate the behaviour of the Element Class when there is no DOM available.
|
|
|
2773
2928
|
* [.isVisible](#ElementService+isVisible)
|
|
2774
2929
|
* [.localName](#ElementService+localName) ⇒ <code>string</code>
|
|
2775
2930
|
* [.prefix](#ElementService+prefix) ⇒ <code>string</code> \| <code>null</code>
|
|
2931
|
+
* [.innerHTML](#ElementService+innerHTML) ⇒ <code>string</code>
|
|
2932
|
+
* [.outerHTML](#ElementService+outerHTML) ⇒ <code>string</code>
|
|
2776
2933
|
* [.children](#ElementService+children) ⇒ <code>PseudoHTMLCollection</code>
|
|
2777
2934
|
* [.childElementCount](#ElementService+childElementCount) ⇒ <code>number</code>
|
|
2778
2935
|
* [.firstElementChild](#ElementService+firstElementChild) ⇒ <code>PseudoElement</code> \| <code>null</code>
|
|
@@ -2862,6 +3019,19 @@ same as tagName.
|
|
|
2862
3019
|
The element's namespace prefix, or null when it has none. There is no real namespace parsing here, so this is
|
|
2863
3020
|
always null.
|
|
2864
3021
|
|
|
3022
|
+
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
3023
|
+
<a name="ElementService+innerHTML"></a>
|
|
3024
|
+
|
|
3025
|
+
### elementService.innerHTML ⇒ <code>string</code>
|
|
3026
|
+
The HTML markup of this element's children. Only the getter is here (the setter, which needs to build new
|
|
3027
|
+
elements from parsed HTML, is on HTMLElementService - see its class comment).
|
|
3028
|
+
|
|
3029
|
+
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
3030
|
+
<a name="ElementService+outerHTML"></a>
|
|
3031
|
+
|
|
3032
|
+
### elementService.outerHTML ⇒ <code>string</code>
|
|
3033
|
+
The HTML markup of this element itself, including its children. Only the getter is here (see innerHTML).
|
|
3034
|
+
|
|
2865
3035
|
**Kind**: instance property of [<code>ElementService</code>](#ElementService)
|
|
2866
3036
|
<a name="ElementService+children"></a>
|
|
2867
3037
|
|
|
@@ -5310,6 +5480,65 @@ Remember the element which has the focus in a tree.
|
|
|
5310
5480
|
| root | <code>Object</code> | The root node of the tree |
|
|
5311
5481
|
| element | <code>Object</code> \| <code>null</code> | The element which now has the focus, or null when nothing has it |
|
|
5312
5482
|
|
|
5483
|
+
<a name="escapeText"></a>
|
|
5484
|
+
|
|
5485
|
+
## escapeText(text) ⇒ <code>string</code>
|
|
5486
|
+
Escape text so it is safe inside HTML text content.
|
|
5487
|
+
|
|
5488
|
+
**Kind**: global function
|
|
5489
|
+
|
|
5490
|
+
| Param | Type |
|
|
5491
|
+
| --- | --- |
|
|
5492
|
+
| text | <code>string</code> |
|
|
5493
|
+
|
|
5494
|
+
<a name="escapeAttributeValue"></a>
|
|
5495
|
+
|
|
5496
|
+
## escapeAttributeValue(value) ⇒ <code>string</code>
|
|
5497
|
+
Escape a value so it is safe inside a double-quoted HTML attribute.
|
|
5498
|
+
|
|
5499
|
+
**Kind**: global function
|
|
5500
|
+
|
|
5501
|
+
| Param | Type |
|
|
5502
|
+
| --- | --- |
|
|
5503
|
+
| value | <code>string</code> |
|
|
5504
|
+
|
|
5505
|
+
<a name="serializeAttributes"></a>
|
|
5506
|
+
|
|
5507
|
+
## serializeAttributes(element) ⇒ <code>string</code>
|
|
5508
|
+
Every attribute of the element, serialized (class instead of className, boolean attributes bare, the never-real
|
|
5509
|
+
mock properties left out, style added from the live CSSStyleDeclaration when it is not empty).
|
|
5510
|
+
|
|
5511
|
+
**Kind**: global function
|
|
5512
|
+
|
|
5513
|
+
| Param | Type |
|
|
5514
|
+
| --- | --- |
|
|
5515
|
+
| element | <code>\*</code> |
|
|
5516
|
+
|
|
5517
|
+
<a name="serializeNode"></a>
|
|
5518
|
+
|
|
5519
|
+
## serializeNode(node) ⇒ <code>string</code>
|
|
5520
|
+
One node, serialized (its own markup only - see serializeChildren for its descendants too).
|
|
5521
|
+
|
|
5522
|
+
**Kind**: global function
|
|
5523
|
+
|
|
5524
|
+
| Param | Type |
|
|
5525
|
+
| --- | --- |
|
|
5526
|
+
| node | <code>\*</code> |
|
|
5527
|
+
|
|
5528
|
+
<a name="prettyPrintNode"></a>
|
|
5529
|
+
|
|
5530
|
+
## prettyPrintNode(node, depth, indent) ⇒ <code>string</code>
|
|
5531
|
+
One node, indented for readability (see prettyPrint) - unlike serializeNode, every non-empty node is its own
|
|
5532
|
+
line, so the structure of a whole tree is easy to read at a glance.
|
|
5533
|
+
|
|
5534
|
+
**Kind**: global function
|
|
5535
|
+
|
|
5536
|
+
| Param | Type |
|
|
5537
|
+
| --- | --- |
|
|
5538
|
+
| node | <code>\*</code> |
|
|
5539
|
+
| depth | <code>number</code> |
|
|
5540
|
+
| indent | <code>string</code> |
|
|
5541
|
+
|
|
5313
5542
|
<a name="generateNodeList"></a>
|
|
5314
5543
|
|
|
5315
5544
|
## generateNodeList([innerList]) ⇒ [<code>PseudoNodeList</code>](#PseudoNodeList)
|