Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite #140

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ad0f846
Migrate `CSSStyleDeclaration` to WebIDL2JS
ExE-Boss Apr 1, 2020
c6b72e0
Use `[ReflectStyle]` for basic properties
ExE-Boss Mar 27, 2021
584c686
fix: configure eslint for nodejs
cdoublev Jun 14, 2021
7eaff97
fix: cssFloat conformance to CSSOM specification
cdoublev Jun 14, 2021
2620fc1
fix: reorganize properties
cdoublev Jun 14, 2021
9581e9f
test: add test for IDL attributes and pascal cased webkit properties
cdoublev Jun 14, 2021
ef0c38d
fix: generate implemented properties without babel
cdoublev Jun 14, 2021
f8eb678
fix: define properties without babel
cdoublev Jun 14, 2021
69c3c29
fix: download latest all properties
cdoublev Jun 14, 2021
a1b0ad9
fix: download properties with NodeJS https instead of request
cdoublev Jun 14, 2021
b7f9c7e
test: conversion of value to DOM String
cdoublev Jun 14, 2021
164e9bb
fix: remove useless string conversion and null type checking
cdoublev Jun 14, 2021
2efea52
fix: preprocess value and parse empty string early
cdoublev Jun 14, 2021
1db507d
fix: remove isValid eval from parsers and properties
cdoublev Jun 14, 2021
e61163a
test: parse keyword and custom identifier
cdoublev Jun 14, 2021
7346693
feat: parse keyword and custom identifier
cdoublev Jun 14, 2021
c8b7caa
fix: use parseKeyword in all parsers and property setters
cdoublev Jun 14, 2021
0d1048b
fix: remove value type eval from parsers and properties
cdoublev Jun 14, 2021
6a8d196
test: reorganize and cleanup tests
cdoublev Jun 14, 2021
e5e3e24
test: conformance to specifications
cdoublev Jun 14, 2021
97b3f29
fix: conformance to specifications
cdoublev Jun 14, 2021
3fff0e9
test: computed calc()
cdoublev Jun 14, 2021
bdcbd05
feat: computed calc()
cdoublev Jun 14, 2021
edff656
test: custom var()
cdoublev Jun 14, 2021
3cb4847
feat: custom var()
cdoublev Jun 14, 2021
44aef98
doc: add usefull links
cdoublev Jun 14, 2021
1d78a5b
fix: add support for values with exponent
cdoublev Jun 14, 2021
95a5a72
test: add tests for leading/trailing 0
cdoublev Jun 14, 2021
c4e62f3
test: add tests for 0 as length and angle
cdoublev Jun 14, 2021
1f5d12b
fix: 0 as angle
cdoublev Jun 14, 2021
7f9c2ad
test: add tests for lowercased length/angle/time
cdoublev Jun 14, 2021
995b7e5
test: add tests for conversion to canonical length/angle/time unit
cdoublev Jun 14, 2021
88624b3
test: add tests for invalid numeric types
cdoublev Jun 14, 2021
17e192b
test: add tests for color
cdoublev Jun 14, 2021
258bc65
fix: parsing color
cdoublev Jun 14, 2021
4941929
feat: color gradient
cdoublev Jun 14, 2021
3c48a09
fix: use parsePosition to parse background-position
cdoublev Jun 14, 2021
c96faaa
test: add tests for string
cdoublev Jun 14, 2021
8a57f11
fix: parsing string
cdoublev Jun 14, 2021
8e5890b
test: add tests for resource
cdoublev Jun 14, 2021
68570e9
fix: parsing resource
cdoublev Jun 14, 2021
d73ac61
feat: parse box, shape box, geometry box
cdoublev Jun 14, 2021
299e65e
fix: handle background size/position/attachment/origin/clip
cdoublev Jun 14, 2021
fff4ca4
feat: border-radius
cdoublev Jun 14, 2021
9d7bb77
feat: parse positive numeric
cdoublev Jun 14, 2021
5ece810
feat: parse basic shape
cdoublev Jun 14, 2021
651e5ed
fix: clip args with calc() and separated by space
cdoublev Jun 14, 2021
80affd5
feat: clip-path
cdoublev Jun 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules
lib/CSSStyleDeclaration.js
lib/Function.js
lib/VoidFunction.js
lib/implementedProperties.js
lib/properties.js
lib/utils.js
jest.config.js
10 changes: 2 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ module.exports = {
},
env: {
es6: true,
node: true,
},
globals: {
exports: true,
module: true,
require: true,
window: true,
describe: true,
it: true,
test: true,
Expand All @@ -34,7 +31,7 @@ module.exports = {
},
overrides: [
{
files: ['lib/implementedProperties.js', 'lib/properties.js'],
files: ['lib/implementedProperties.js'],
rules: {
'prettier/prettier': 'off',
},
Expand All @@ -47,9 +44,6 @@ module.exports = {
},
{
files: ['scripts/**/*', 'tests/**/*'],
env: {
node: true,
},
},
],
};
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
node_modules
npm-debug.log
lib/CSSStyleDeclaration.js
lib/Function.js
lib/VoidFunction.js
lib/implementedProperties.js
lib/properties.js
lib/utils.js
coverage
src/CSSStyleDeclaration-properties.webidl
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/*
!lib/
lib/Function.js
lib/VoidFunction.js
!LICENSE
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ install:
- npm install
- npm install -g codecov
node_js:
- "8"
- "10"
- "12"

Expand Down
45 changes: 40 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,47 @@ A Node JS implementation of the CSS Object Model [CSSStyleDeclaration interface]

[![NpmVersion](https://img.shields.io/npm/v/cssstyle.svg)](https://www.npmjs.com/package/cssstyle) [![Build Status](https://travis-ci.org/jsdom/cssstyle.svg?branch=master)](https://travis-ci.org/jsdom/cssstyle) [![codecov](https://codecov.io/gh/jsdom/cssstyle/branch/master/graph/badge.svg)](https://codecov.io/gh/jsdom/cssstyle)

---
## Background

#### Background
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.

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.

It was originally created by Chad Walker, it is now maintained by the jsdom community.
It was originally created by Chad Walker, it is now maintained by Jon Sakas and other open source contributors.

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`:
```js
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](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.

#### `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.
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
const webidlWrapper = require('./webidl2js-wrapper.js');

const sharedGlobalObject = {};
webidlWrapper.install(sharedGlobalObject, ['Window']);

const origCSSStyleDeclaration = sharedGlobalObject.CSSStyleDeclaration;

/**
* @constructor
* @param {((cssText: string) => void) | null} [onChangeCallback]
* The callback that is invoked whenever a property changes.
*/
function CSSStyleDeclaration(onChangeCallback = null) {
if (new.target === undefined) {
throw new TypeError("Class constructor CSSStyleDeclaration cannot be invoked without 'new'");
}

if (onChangeCallback !== null && typeof onChangeCallback !== 'function') {
throw new TypeError('Failed to construct CSSStyleDeclaration: parameter 1 is not a function');
}

return webidlWrapper.create(sharedGlobalObject, undefined, { onChangeCallback });
}

sharedGlobalObject.CSSStyleDeclaration = CSSStyleDeclaration;
Object.defineProperty(CSSStyleDeclaration, 'prototype', {
value: origCSSStyleDeclaration.prototype,
writable: false,
});
CSSStyleDeclaration.prototype.constructor = CSSStyleDeclaration;
Object.setPrototypeOf(CSSStyleDeclaration, Object.getPrototypeOf(origCSSStyleDeclaration));

module.exports = CSSStyleDeclaration;
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module.exports = {
"collectCoverage": true,
"collectCoverageFrom": [
"lib/**/*.js",
"!lib/CSSStyleDeclaration.js",
"!lib/implementedProperties.js",
"!lib/properties.js",
"!lib/utils.js",
],
"coverageDirectory": "coverage",
};
Loading