You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's [CSSOM](https://github.com/NV/CSSOM) with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.
10
10
11
-
This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's [CSSOM](https://github.com/NV/CSSOM) with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.
12
-
13
-
It was originally created by Chad Walker, it is now maintained by the jsdom community.
11
+
It was originally created by Chad Walker, it is now maintained by Jon Sakas and other open source contributors.
14
12
15
13
Bug reports and pull requests are welcome.
14
+
15
+
## APIs
16
+
17
+
This package exposes two flavors of the `CSSStyleDeclaration` interface depending on the imported module.
18
+
19
+
### `cssstyle` module
20
+
21
+
This module default-exports the `CSSStyleDeclaration` interface constructor, with the change that it can be constructed with an optional `onChangeCallback` parameter. Whenever any CSS property is modified through an instance of this class, the callback (if provided) will be called with a string that represents all CSS properties of this element, serialized. This allows the embedding environment to properly reflect the style changes to an element's `style` attribute.
22
+
23
+
Here is a crude example of using the `onChangeCallback` to implement the `style` property of `HTMLElement`:
24
+
```js
25
+
constCSSStyleDeclaration=require('cssstyle');
26
+
27
+
classHTMLElementextendsElement {
28
+
constructor() {
29
+
this._style=newCSSStyleDeclaration(newCSSText=> {
30
+
this.setAttributeNS(null, "style", newCSSText);
31
+
});
32
+
}
33
+
34
+
getstyle() {
35
+
returnthis._style;
36
+
}
37
+
38
+
setstyle(text) {
39
+
this._style.cssText= text;
40
+
}
41
+
}
42
+
```
43
+
44
+
### `cssstyle/webidl2js-wrapper` module
45
+
46
+
This module exports the `CSSStyleDeclaration`[interface wrapper API](https://github.com/jsdom/webidl2js#for-interfaces) generated by [webidl2js](https://github.com/jsdom/webidl2js). Unlike the default export, `CSSStyleDeclaration` constructors installed by the webidl2js wrapper do _not_ support construction, just like how they actually are in browsers. Creating new `CSSStyleDeclaration` objects can be done with the [`create`](https://github.com/jsdom/webidl2js#createglobalobject-constructorargs-privatedata) method of the wrapper.
47
+
48
+
#### `privateData`
49
+
50
+
The `privateData` parameter of `create` and `createImpl` provides a way to specify the `onChangeCallback` that is a constructor parameter in the default export. Only the `onChangeCallback` property is supported on `privateData` currently, with the same semantics as the constructor parameter documented above.
0 commit comments