pseudo-dom 0.8.0 → 0.9.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 +206 -1
- package/browser/pseudo-dom.js +813 -470
- package/browser/pseudo-dom.min.js +1 -1
- package/dist/classes/PseudoHTMLDocument.d.ts +41 -41
- package/dist/classes/PseudoHTMLDocument.js +74 -74
- package/dist/factories/createDataset.d.ts +10 -0
- package/dist/factories/createDataset.js +78 -0
- package/dist/factories/createDataset.min.js +1 -0
- package/dist/factories/createStyleDeclaration.d.ts +30 -0
- package/dist/factories/createStyleDeclaration.js +64 -0
- package/dist/factories/createStyleDeclaration.min.js +1 -0
- package/dist/functions/getElementById.d.ts +13 -13
- package/dist/functions/getElementById.js +33 -33
- package/dist/interfaces/PseudoCSSStyleDeclaration.d.ts +14 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.js +5 -0
- package/dist/interfaces/PseudoCSSStyleDeclaration.min.js +1 -0
- package/dist/interfaces/PseudoDocument.d.ts +35 -35
- package/dist/interfaces/PseudoDocumentFragment.d.ts +10 -10
- package/dist/interfaces/PseudoHTMLElement.d.ts +33 -22
- package/dist/services/CSSStyleDeclarationService.d.ts +73 -0
- package/dist/services/CSSStyleDeclarationService.js +156 -0
- package/dist/services/CSSStyleDeclarationService.min.js +1 -0
- package/dist/services/DocumentFragmentService.d.ts +21 -21
- package/dist/services/DocumentFragmentService.js +42 -42
- package/dist/services/DocumentService.d.ts +46 -46
- package/dist/services/DocumentService.js +95 -95
- package/dist/services/HTMLElementService.d.ts +87 -57
- package/dist/services/HTMLElementService.js +202 -163
- package/dist/services/HTMLElementService.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,13 @@ else, document fragments insert their children, and a node cannot be put inside
|
|
|
18
18
|
`DOMTokenListService`, `NamedNodeMapService`, `DocumentService` / `DocumentFragmentService`, `PseudoNodeList`, and
|
|
19
19
|
`generateDocument` for creating a document.
|
|
20
20
|
|
|
21
|
+
`style` is a real, live `CSSStyleDeclaration`: named property access (\`el.style.backgroundColor = 'red'\`) alongside
|
|
22
|
+
\`getPropertyValue\` / \`setProperty\` / \`removeProperty\` / \`getPropertyPriority\` / \`cssText\`; an unset property
|
|
23
|
+
reads as \`''\`, like the DOM's. \`dataset\` is a live `DOMStringMap`: reading/writing/deleting a camelCase name
|
|
24
|
+
(\`el.dataset.fooBar\`) reads/writes/removes the matching \`data-foo-bar\` attribute directly, so it can never fall out
|
|
25
|
+
of sync with the attributes themselves. Both are on \`HTMLElementService\`, matching the DOM (they are not on the base
|
|
26
|
+
Element).
|
|
27
|
+
|
|
21
28
|
Standard events: `createEvent(type, init, { browser, trusted })` makes the kind of event which suits the type (a click is a
|
|
22
29
|
`MouseEvent`, a keydown a `KeyboardEvent`, ...). Like the constructor in a browser it gives nothing (no bubbling, no
|
|
23
30
|
cancelling, not trusted) unless asked, but with `browser: true` it uses `eventDefaults`, the table of how the browser
|
|
@@ -137,6 +144,13 @@ not part of a tree, when it is inserted its children are moved into the tree ins
|
|
|
137
144
|
<dt><a href="#CustomEventService">CustomEventService</a> ⇐ <code><a href="#EventService">EventService</a></code></dt>
|
|
138
145
|
<dd><p>Simulate the behaviour of the CustomEvent Class when there is no DOM available: an event which carries data.</p>
|
|
139
146
|
</dd>
|
|
147
|
+
<dt><a href="#CSSStyleDeclarationService">CSSStyleDeclarationService</a></dt>
|
|
148
|
+
<dd><p>Simulate the behaviour of the CSSStyleDeclaration Class when there is no DOM available: an ordered map of CSS
|
|
149
|
+
property/value pairs, parsed from and serialized back to a cssText string. Values are stored and returned as
|
|
150
|
+
given, with no unit conversion, shorthand expansion or validation - this is a data structure, not a real CSS
|
|
151
|
+
engine. Named property access (declaration.backgroundColor, camelCase) is added on top of this by
|
|
152
|
+
createStyleDeclaration, which wraps an instance of this class in a Proxy.</p>
|
|
153
|
+
</dd>
|
|
140
154
|
<dt><a href="#AttrService">AttrService</a> ⇐ <code><a href="#NodeService">NodeService</a></code></dt>
|
|
141
155
|
<dd><p>Simulate the behaviour of the Attr Class when there is no DOM available.</p>
|
|
142
156
|
</dd>
|
|
@@ -207,6 +221,12 @@ context.</p>
|
|
|
207
221
|
<dt><a href="#nearestElementSibling">nearestElementSibling(node, direction)</a> ⇒ <code>*</code> | <code>null</code></dt>
|
|
208
222
|
<dd><p>Walk up from a node (not including it) to find the nearest element, in the given direction.</p>
|
|
209
223
|
</dd>
|
|
224
|
+
<dt><a href="#kebabToCamel">kebabToCamel(name)</a> ⇒ <code>string</code></dt>
|
|
225
|
+
<dd><p>kebab-case -> camelCase ("background-color" -> "backgroundColor").</p>
|
|
226
|
+
</dd>
|
|
227
|
+
<dt><a href="#camelToKebab">camelToKebab(name)</a> ⇒ <code>string</code></dt>
|
|
228
|
+
<dd><p>camelCase -> kebab-case ("backgroundColor" -> "background-color").</p>
|
|
229
|
+
</dd>
|
|
210
230
|
<dt><a href="#createEvent">createEvent(type, [init], [options])</a> ⇒ <code><a href="#EventService">EventService</a></code></dt>
|
|
211
231
|
<dd><p>Create an event of the kind which suits its type (a click is a MouseEvent, a keydown a KeyboardEvent, ...).
|
|
212
232
|
By default this is like using the constructor of the event in a script: nothing bubbles or can be cancelled unless
|
|
@@ -214,6 +234,9 @@ the init says so, and the event is not trusted. With browser: true the event is
|
|
|
214
234
|
it, using the standard options for its type (see eventDefaults), and trusted: true makes it look like it came from a
|
|
215
235
|
real user action (isTrusted).</p>
|
|
216
236
|
</dd>
|
|
237
|
+
<dt><a href="#dataAttributes">dataAttributes(element)</a> ⇒ <code>Array.<Array.<string>></code></dt>
|
|
238
|
+
<dd><p>Every data-* attribute name currently on the element, as [attributeName, camelCaseName] pairs.</p>
|
|
239
|
+
</dd>
|
|
217
240
|
</dl>
|
|
218
241
|
|
|
219
242
|
<a name="module_pseudoDom/simulate"></a>
|
|
@@ -1823,13 +1846,18 @@ Simulate the behaviour of the HTMLElement Class when there is no DOM available.
|
|
|
1823
1846
|
| offsetParent | <code>PseudoHTMLElement</code> | A reference to the closest positioned parent element |
|
|
1824
1847
|
| offsetTop | <code>number</code> | The position of the top side of the element based on the parent element |
|
|
1825
1848
|
| offsetWidth | <code>number</code> | The width of the element as offset by the parent element |
|
|
1826
|
-
| style | <code>
|
|
1849
|
+
| style | [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService) | The element's inline styles, live and settable per property |
|
|
1850
|
+
| dataset | <code>Object.<string, string></code> | The element's data-* attributes, live, under their camelCase names |
|
|
1827
1851
|
| title | <code>string</code> | The title attribute which affects the text visible on hover |
|
|
1828
1852
|
|
|
1829
1853
|
|
|
1830
1854
|
* [HTMLElementService](#HTMLElementService) ⇐ <code>PseudoElement</code>
|
|
1831
1855
|
* [new HTMLElementService([elementOptions])](#new_HTMLElementService_new)
|
|
1856
|
+
* [.style](#HTMLElementService+style) ⇒ [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
1857
|
+
* [.dataset](#HTMLElementService+dataset) ⇒ <code>Object.<string, string></code>
|
|
1832
1858
|
* [.canFocus](#HTMLElementService+canFocus) ⇒ <code>boolean</code>
|
|
1859
|
+
* [.cloneShallow()](#HTMLElementService+cloneShallow) ⇒ [<code>NodeService</code>](#NodeService)
|
|
1860
|
+
* [.equalsShallow(other)](#HTMLElementService+equalsShallow) ⇒ <code>boolean</code>
|
|
1833
1861
|
* [.click()](#HTMLElementService+click)
|
|
1834
1862
|
* [.focus()](#HTMLElementService+focus)
|
|
1835
1863
|
* [.blur()](#HTMLElementService+blur)
|
|
@@ -1847,12 +1875,43 @@ Simulate the HTMLElement object when the Dom is not available
|
|
|
1847
1875
|
| [elementOptions.parent] | <code>PseudoNode</code> \| <code>Object</code> | <code>{}</code> |
|
|
1848
1876
|
| [elementOptions.children] | <code>Array</code> | <code>[]</code> |
|
|
1849
1877
|
|
|
1878
|
+
<a name="HTMLElementService+style"></a>
|
|
1879
|
+
|
|
1880
|
+
### htmlElementService.style ⇒ [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
1881
|
+
The element's inline styles: a live CSSStyleDeclaration-like object, so both style.setProperty('color', 'red')
|
|
1882
|
+
and style.color = 'red' work.
|
|
1883
|
+
|
|
1884
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
1885
|
+
<a name="HTMLElementService+dataset"></a>
|
|
1886
|
+
|
|
1887
|
+
### htmlElementService.dataset ⇒ <code>Object.<string, string></code>
|
|
1888
|
+
The element's data-* attributes, live, under their camelCase names (data-foo-bar <-> dataset.fooBar). Backed
|
|
1889
|
+
directly by getAttribute / setAttribute, so it is never out of sync with the attributes themselves.
|
|
1890
|
+
|
|
1891
|
+
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
1850
1892
|
<a name="HTMLElementService+canFocus"></a>
|
|
1851
1893
|
|
|
1852
1894
|
### htmlElementService.canFocus ⇒ <code>boolean</code>
|
|
1853
1895
|
Whether this element can have the focus: form controls and links which are not disabled, and anything with a tabindex.
|
|
1854
1896
|
|
|
1855
1897
|
**Kind**: instance property of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
1898
|
+
<a name="HTMLElementService+cloneShallow"></a>
|
|
1899
|
+
|
|
1900
|
+
### htmlElementService.cloneShallow() ⇒ [<code>NodeService</code>](#NodeService)
|
|
1901
|
+
Style is not attribute-backed like most properties (see the constructor), so cloneNode needs its own copy of it.
|
|
1902
|
+
|
|
1903
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
1904
|
+
<a name="HTMLElementService+equalsShallow"></a>
|
|
1905
|
+
|
|
1906
|
+
### htmlElementService.equalsShallow(other) ⇒ <code>boolean</code>
|
|
1907
|
+
Style is not attribute-backed like most properties, so isEqualNode needs to compare it separately too.
|
|
1908
|
+
|
|
1909
|
+
**Kind**: instance method of [<code>HTMLElementService</code>](#HTMLElementService)
|
|
1910
|
+
|
|
1911
|
+
| Param | Type | Description |
|
|
1912
|
+
| --- | --- | --- |
|
|
1913
|
+
| other | [<code>NodeService</code>](#NodeService) | The node to compare with |
|
|
1914
|
+
|
|
1856
1915
|
<a name="HTMLElementService+click"></a>
|
|
1857
1916
|
|
|
1858
1917
|
### htmlElementService.click()
|
|
@@ -3304,6 +3363,119 @@ Stops the propagation of events further along in the Dom.
|
|
|
3304
3363
|
|
|
3305
3364
|
**Kind**: instance method of [<code>CustomEventService</code>](#CustomEventService)
|
|
3306
3365
|
**Overrides**: [<code>stopPropagation</code>](#EventService+stopPropagation)
|
|
3366
|
+
<a name="CSSStyleDeclarationService"></a>
|
|
3367
|
+
|
|
3368
|
+
## CSSStyleDeclarationService
|
|
3369
|
+
Simulate the behaviour of the CSSStyleDeclaration Class when there is no DOM available: an ordered map of CSS
|
|
3370
|
+
property/value pairs, parsed from and serialized back to a cssText string. Values are stored and returned as
|
|
3371
|
+
given, with no unit conversion, shorthand expansion or validation - this is a data structure, not a real CSS
|
|
3372
|
+
engine. Named property access (declaration.backgroundColor, camelCase) is added on top of this by
|
|
3373
|
+
createStyleDeclaration, which wraps an instance of this class in a Proxy.
|
|
3374
|
+
|
|
3375
|
+
**Kind**: global class
|
|
3376
|
+
**Author**: Joshua Heagle <joshuaheagle@gmail.com>
|
|
3377
|
+
|
|
3378
|
+
* [CSSStyleDeclarationService](#CSSStyleDeclarationService)
|
|
3379
|
+
* [new CSSStyleDeclarationService([cssText])](#new_CSSStyleDeclarationService_new)
|
|
3380
|
+
* [.length](#CSSStyleDeclarationService+length) ⇒ <code>number</code>
|
|
3381
|
+
* [.cssText](#CSSStyleDeclarationService+cssText) ⇒ <code>string</code>
|
|
3382
|
+
* [.cssText](#CSSStyleDeclarationService+cssText) ⇒ <code>undefined</code>
|
|
3383
|
+
* [.item(index)](#CSSStyleDeclarationService+item) ⇒ <code>string</code>
|
|
3384
|
+
* [.getPropertyValue(property)](#CSSStyleDeclarationService+getPropertyValue) ⇒ <code>string</code>
|
|
3385
|
+
* [.getPropertyPriority(property)](#CSSStyleDeclarationService+getPropertyPriority) ⇒ <code>string</code>
|
|
3386
|
+
* [.setProperty(property, value, [priority])](#CSSStyleDeclarationService+setProperty) ⇒ <code>undefined</code>
|
|
3387
|
+
* [.removeProperty(property)](#CSSStyleDeclarationService+removeProperty) ⇒ <code>string</code>
|
|
3388
|
+
|
|
3389
|
+
<a name="new_CSSStyleDeclarationService_new"></a>
|
|
3390
|
+
|
|
3391
|
+
### new CSSStyleDeclarationService([cssText])
|
|
3392
|
+
|
|
3393
|
+
| Param | Type | Default | Description |
|
|
3394
|
+
| --- | --- | --- | --- |
|
|
3395
|
+
| [cssText] | <code>string</code> | <code>"''"</code> | Initial declarations, as CSS text ("color: red; font-size: 12px;") |
|
|
3396
|
+
|
|
3397
|
+
<a name="CSSStyleDeclarationService+length"></a>
|
|
3398
|
+
|
|
3399
|
+
### cssStyleDeclarationService.length ⇒ <code>number</code>
|
|
3400
|
+
How many properties are currently set.
|
|
3401
|
+
|
|
3402
|
+
**Kind**: instance property of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3403
|
+
<a name="CSSStyleDeclarationService+cssText"></a>
|
|
3404
|
+
|
|
3405
|
+
### cssStyleDeclarationService.cssText ⇒ <code>string</code>
|
|
3406
|
+
All the declarations as one CSS text string.
|
|
3407
|
+
|
|
3408
|
+
**Kind**: instance property of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3409
|
+
<a name="CSSStyleDeclarationService+cssText"></a>
|
|
3410
|
+
|
|
3411
|
+
### cssStyleDeclarationService.cssText ⇒ <code>undefined</code>
|
|
3412
|
+
Replace every declaration by parsing a CSS text string ("color: red; font-size: 12px !important;").
|
|
3413
|
+
|
|
3414
|
+
**Kind**: instance property of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3415
|
+
|
|
3416
|
+
| Param | Type |
|
|
3417
|
+
| --- | --- |
|
|
3418
|
+
| cssText | <code>string</code> |
|
|
3419
|
+
|
|
3420
|
+
<a name="CSSStyleDeclarationService+item"></a>
|
|
3421
|
+
|
|
3422
|
+
### cssStyleDeclarationService.item(index) ⇒ <code>string</code>
|
|
3423
|
+
The name of the property at the given index, in the order it was set, or '' when there is none (matches the
|
|
3424
|
+
DOM's CSSStyleDeclaration, which is array-like).
|
|
3425
|
+
|
|
3426
|
+
**Kind**: instance method of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3427
|
+
|
|
3428
|
+
| Param | Type |
|
|
3429
|
+
| --- | --- |
|
|
3430
|
+
| index | <code>number</code> |
|
|
3431
|
+
|
|
3432
|
+
<a name="CSSStyleDeclarationService+getPropertyValue"></a>
|
|
3433
|
+
|
|
3434
|
+
### cssStyleDeclarationService.getPropertyValue(property) ⇒ <code>string</code>
|
|
3435
|
+
The value of the given property, or '' when it is not set.
|
|
3436
|
+
|
|
3437
|
+
**Kind**: instance method of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3438
|
+
|
|
3439
|
+
| Param | Type | Description |
|
|
3440
|
+
| --- | --- | --- |
|
|
3441
|
+
| property | <code>string</code> | A CSS property name (kebab-case, e.g. "background-color") |
|
|
3442
|
+
|
|
3443
|
+
<a name="CSSStyleDeclarationService+getPropertyPriority"></a>
|
|
3444
|
+
|
|
3445
|
+
### cssStyleDeclarationService.getPropertyPriority(property) ⇒ <code>string</code>
|
|
3446
|
+
"important" when the property was set with !important, otherwise ''.
|
|
3447
|
+
|
|
3448
|
+
**Kind**: instance method of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3449
|
+
|
|
3450
|
+
| Param | Type | Description |
|
|
3451
|
+
| --- | --- | --- |
|
|
3452
|
+
| property | <code>string</code> | A CSS property name (kebab-case) |
|
|
3453
|
+
|
|
3454
|
+
<a name="CSSStyleDeclarationService+setProperty"></a>
|
|
3455
|
+
|
|
3456
|
+
### cssStyleDeclarationService.setProperty(property, value, [priority]) ⇒ <code>undefined</code>
|
|
3457
|
+
Set a property's value (and optionally its priority). An empty, null or undefined value removes the property
|
|
3458
|
+
instead, like the DOM.
|
|
3459
|
+
|
|
3460
|
+
**Kind**: instance method of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3461
|
+
|
|
3462
|
+
| Param | Type | Default | Description |
|
|
3463
|
+
| --- | --- | --- | --- |
|
|
3464
|
+
| property | <code>string</code> | | A CSS property name (kebab-case) |
|
|
3465
|
+
| value | <code>string</code> | | The value, or '' to remove the property |
|
|
3466
|
+
| [priority] | <code>string</code> | <code>"''"</code> | "important" to mark it !important |
|
|
3467
|
+
|
|
3468
|
+
<a name="CSSStyleDeclarationService+removeProperty"></a>
|
|
3469
|
+
|
|
3470
|
+
### cssStyleDeclarationService.removeProperty(property) ⇒ <code>string</code>
|
|
3471
|
+
Remove a property, returning the value it had (or '' when it was not set).
|
|
3472
|
+
|
|
3473
|
+
**Kind**: instance method of [<code>CSSStyleDeclarationService</code>](#CSSStyleDeclarationService)
|
|
3474
|
+
|
|
3475
|
+
| Param | Type | Description |
|
|
3476
|
+
| --- | --- | --- |
|
|
3477
|
+
| property | <code>string</code> | A CSS property name (kebab-case) |
|
|
3478
|
+
|
|
3307
3479
|
<a name="AttrService"></a>
|
|
3308
3480
|
|
|
3309
3481
|
## AttrService ⇐ [<code>NodeService</code>](#NodeService)
|
|
@@ -4443,6 +4615,28 @@ Walk up from a node (not including it) to find the nearest element, in the given
|
|
|
4443
4615
|
| node | <code>\*</code> | The node to start from |
|
|
4444
4616
|
| direction | <code>'nextSibling'</code> \| <code>'previousSibling'</code> | Which sibling reference to follow |
|
|
4445
4617
|
|
|
4618
|
+
<a name="kebabToCamel"></a>
|
|
4619
|
+
|
|
4620
|
+
## kebabToCamel(name) ⇒ <code>string</code>
|
|
4621
|
+
kebab-case -> camelCase ("background-color" -> "backgroundColor").
|
|
4622
|
+
|
|
4623
|
+
**Kind**: global function
|
|
4624
|
+
|
|
4625
|
+
| Param | Type |
|
|
4626
|
+
| --- | --- |
|
|
4627
|
+
| name | <code>string</code> |
|
|
4628
|
+
|
|
4629
|
+
<a name="camelToKebab"></a>
|
|
4630
|
+
|
|
4631
|
+
## camelToKebab(name) ⇒ <code>string</code>
|
|
4632
|
+
camelCase -> kebab-case ("backgroundColor" -> "background-color").
|
|
4633
|
+
|
|
4634
|
+
**Kind**: global function
|
|
4635
|
+
|
|
4636
|
+
| Param | Type |
|
|
4637
|
+
| --- | --- |
|
|
4638
|
+
| name | <code>string</code> |
|
|
4639
|
+
|
|
4446
4640
|
<a name="createEvent"></a>
|
|
4447
4641
|
|
|
4448
4642
|
## createEvent(type, [init], [options]) ⇒ [<code>EventService</code>](#EventService)
|
|
@@ -4460,3 +4654,14 @@ real user action (isTrusted).
|
|
|
4460
4654
|
| [init] | <code>Object</code> | <code>{}</code> | The options for the event (bubbles, cancelable, composed and those of its kind of event) |
|
|
4461
4655
|
| [options] | <code>CreateEventOptions</code> | <code>{}</code> | Whether the browser is creating the event, and whether it is trusted |
|
|
4462
4656
|
|
|
4657
|
+
<a name="dataAttributes"></a>
|
|
4658
|
+
|
|
4659
|
+
## dataAttributes(element) ⇒ <code>Array.<Array.<string>></code>
|
|
4660
|
+
Every data-* attribute name currently on the element, as [attributeName, camelCaseName] pairs.
|
|
4661
|
+
|
|
4662
|
+
**Kind**: global function
|
|
4663
|
+
|
|
4664
|
+
| Param | Type |
|
|
4665
|
+
| --- | --- |
|
|
4666
|
+
| element | <code>\*</code> |
|
|
4667
|
+
|