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
Copy file name to clipboardExpand all lines: README.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,30 +18,33 @@ This package exposes two flavors of the `CSSStyleDeclaration` interface dependin
18
18
19
19
### `cssstyle` module
20
20
21
-
This module default-exports the `CSSStyleDeclaration` interface constructor, with the change that it can be constructed and takes an `onChangeCallback` optional parameter:
22
-
23
-
```ts
24
-
export=classCSSStyleDeclaration {
25
-
/**
26
-
* @paramonChangeCallback The callback that is invoked whenever a property changes.
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
+
}
29
41
}
30
42
```
31
43
32
44
### `cssstyle/webidl2js-wrapper` module
33
45
34
-
This module exports the `CSSStyleDeclaration`[interface wrapper API](https://github.com/jsdom/webidl2js#for-interfaces) generated by [webidl2js](https://github.com/jsdom/webidl2js).
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.
35
47
36
48
#### `privateData`
37
49
38
-
The `privateData` argument takes the following properties:
39
-
40
-
```ts
41
-
interfaceCSSStyleDeclarationPrivateData {
42
-
/**
43
-
* The callback that is invoked whenever a property changes.
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