Skip to content
forked from jsdom/cssstyle

A Node JS implementation of the CSS Object Model CSSStyleDeclaration interface

License

Notifications You must be signed in to change notification settings

ExE-Boss/cssstyle

 
 

Repository files navigation

CSSStyleDeclaration

A Node JS implementation of the CSS Object Model CSSStyleDeclaration interface.

NpmVersion Build Status codecov

Background

This package is an extension of the CSSStyleDeclaration class in Nikita Vasilyev's CSSOM with added support for CSS 2 & 3 properties. The primary use case is for testing browser code in a Node environment.

It was originally created by Chad Walker, it is now maintained by the jsdom community.

Bug reports and pull requests are welcome.

APIs

This package exposes two flavors of the CSSStyleDeclaration interface depending on the imported module.

cssstyle module

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.

Here is a crude example of using the onChangeCallback to implement the style property of HTMLElement:

const CSSStyleDeclaration = require('cssstyle');

class HTMLElement extends Element {
  constructor() {
    this._style = new CSSStyleDeclaration(newCSSText => {
      this.setAttributeNS(null, "style", newCSSText);
    });
  }

  get style() {
    return this._style;
  }

  set style(text) {
    this._style.cssText = text;
  }
}

cssstyle/webidl2js-wrapper module

This module exports the CSSStyleDeclaration interface wrapper API generated by 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 method of the wrapper.

privateData

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.

About

A Node JS implementation of the CSS Object Model CSSStyleDeclaration interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%