cssstyle 1.4.0 → 2.3.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/{MIT-LICENSE.txt → LICENSE} +0 -0
- package/README.md +7 -19
- package/lib/CSSStyleDeclaration.js +5 -0
- package/lib/CSSStyleDeclaration.test.js +556 -0
- package/lib/allExtraProperties.js +60 -241
- package/lib/allProperties.js +454 -449
- package/lib/allWebkitProperties.js +194 -0
- package/lib/implementedProperties.js +1 -1
- package/lib/parsers.js +33 -8
- package/lib/parsers.test.js +139 -0
- package/lib/properties/fontSize.js +11 -1
- package/lib/properties.js +9 -2
- package/lib/utils/colorSpace.js +21 -0
- package/package.json +27 -30
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -50
- package/.travis.yml +0 -15
- package/scripts/download_latest_properties.js +0 -88
- package/scripts/generate_implemented_properties.js +0 -61
- package/scripts/generate_properties.js +0 -292
- package/tests/tests.js +0 -669
package/.travis.yml
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* W3C provides JSON list of all CSS properties and their status in the standard
|
|
5
|
-
*
|
|
6
|
-
* documentation: https://www.w3.org/Style/CSS/all-properties.en.html
|
|
7
|
-
* JSON url: ( https://www.w3.org/Style/CSS/all-properties.en.json )
|
|
8
|
-
*
|
|
9
|
-
* Download that file, filter out duplicates and filter the properties based on the wanted standard level
|
|
10
|
-
*
|
|
11
|
-
* ED - Editors' Draft (not a W3C Technical Report)
|
|
12
|
-
* FPWD - First Public Working Draft
|
|
13
|
-
* WD - Working Draft
|
|
14
|
-
* LC - Last Call Working Draft
|
|
15
|
-
* CR - Candidate Recommendation
|
|
16
|
-
* PR - Proposed Recommendation
|
|
17
|
-
* REC - Recommendation
|
|
18
|
-
* NOTE - Working Group Note
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
var fs = require('fs');
|
|
22
|
-
var path = require('path');
|
|
23
|
-
|
|
24
|
-
var request = require('request');
|
|
25
|
-
|
|
26
|
-
const { camelToDashed } = require('../lib/parsers');
|
|
27
|
-
|
|
28
|
-
var url = 'https://www.w3.org/Style/CSS/all-properties.en.json';
|
|
29
|
-
|
|
30
|
-
console.log('Downloading CSS properties...');
|
|
31
|
-
|
|
32
|
-
function toCamelCase(propName) {
|
|
33
|
-
return propName.replace(/-([a-z])/g, function(g) {
|
|
34
|
-
return g[1].toUpperCase();
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
request(url, function(error, response, body) {
|
|
39
|
-
if (!error && response.statusCode === 200) {
|
|
40
|
-
var allCSSProperties = JSON.parse(body);
|
|
41
|
-
|
|
42
|
-
// Filter out all properties newer than Working Draft
|
|
43
|
-
var workingDraftAndOlderProperties = allCSSProperties.filter(function(cssProp) {
|
|
44
|
-
// TODO: --* css Needs additional logic to this module, so filter it out for now
|
|
45
|
-
return cssProp.status !== 'ED' && cssProp.status !== 'FPWD' && cssProp.property !== '--*';
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Remove duplicates, there can be many properties in different states of standard
|
|
49
|
-
// and add only property names to the list
|
|
50
|
-
var CSSpropertyNames = [];
|
|
51
|
-
workingDraftAndOlderProperties.forEach(function(cssProp) {
|
|
52
|
-
const camelCaseName = toCamelCase(cssProp.property);
|
|
53
|
-
|
|
54
|
-
if (CSSpropertyNames.indexOf(camelCaseName) === -1) {
|
|
55
|
-
CSSpropertyNames.push(camelCaseName);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
var out_file = fs.createWriteStream(path.resolve(__dirname, './../lib/allProperties.js'), {
|
|
60
|
-
encoding: 'utf-8',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
var date_today = new Date();
|
|
64
|
-
out_file.write(
|
|
65
|
-
"'use strict';\n\n// autogenerated - " +
|
|
66
|
-
(date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) +
|
|
67
|
-
'\n\n'
|
|
68
|
-
);
|
|
69
|
-
out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n');
|
|
70
|
-
|
|
71
|
-
out_file.write('var allProperties = new Set();\n');
|
|
72
|
-
out_file.write('module.exports = allProperties;\n');
|
|
73
|
-
|
|
74
|
-
CSSpropertyNames.forEach(function(property) {
|
|
75
|
-
out_file.write('allProperties.add(' + JSON.stringify(camelToDashed(property)) + ');\n');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
out_file.end(function(err) {
|
|
79
|
-
if (err) {
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
console.log('Generated ' + Object.keys(CSSpropertyNames).length + ' properties.');
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const t = require('babel-types');
|
|
6
|
-
const generate = require('babel-generator').default;
|
|
7
|
-
const camelToDashed = require('../lib/parsers').camelToDashed;
|
|
8
|
-
|
|
9
|
-
const dashedProperties = fs
|
|
10
|
-
.readdirSync(path.resolve(__dirname, '../lib/properties'))
|
|
11
|
-
.filter(propertyFile => propertyFile.substr(-3) === '.js')
|
|
12
|
-
.map(propertyFile => camelToDashed(propertyFile.replace('.js', '')));
|
|
13
|
-
|
|
14
|
-
const out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/implementedProperties.js'), {
|
|
15
|
-
encoding: 'utf-8',
|
|
16
|
-
});
|
|
17
|
-
var date_today = new Date();
|
|
18
|
-
out_file.write(
|
|
19
|
-
"'use strict';\n\n// autogenerated - " +
|
|
20
|
-
(date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) +
|
|
21
|
-
'\n\n'
|
|
22
|
-
);
|
|
23
|
-
out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n');
|
|
24
|
-
|
|
25
|
-
const statements = [];
|
|
26
|
-
statements.push(
|
|
27
|
-
t.variableDeclaration('var', [
|
|
28
|
-
t.variableDeclarator(
|
|
29
|
-
t.identifier('implementedProperties'),
|
|
30
|
-
t.newExpression(t.identifier('Set'), [])
|
|
31
|
-
),
|
|
32
|
-
])
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
dashedProperties.forEach(property => {
|
|
36
|
-
statements.push(
|
|
37
|
-
t.expressionStatement(
|
|
38
|
-
t.callExpression(
|
|
39
|
-
t.memberExpression(t.identifier('implementedProperties'), t.identifier('add')),
|
|
40
|
-
[t.stringLiteral(property)]
|
|
41
|
-
)
|
|
42
|
-
)
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
statements.push(
|
|
47
|
-
t.expressionStatement(
|
|
48
|
-
t.assignmentExpression(
|
|
49
|
-
'=',
|
|
50
|
-
t.memberExpression(t.identifier('module'), t.identifier('exports')),
|
|
51
|
-
t.identifier('implementedProperties')
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
out_file.write(generate(t.program(statements)).code + '\n');
|
|
57
|
-
out_file.end(function(err) {
|
|
58
|
-
if (err) {
|
|
59
|
-
throw err;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var babylon = require('babylon');
|
|
6
|
-
var t = require('babel-types');
|
|
7
|
-
var generate = require('babel-generator').default;
|
|
8
|
-
var traverse = require('babel-traverse').default;
|
|
9
|
-
var resolve = require('resolve');
|
|
10
|
-
|
|
11
|
-
var camelToDashed = require('../lib/parsers').camelToDashed;
|
|
12
|
-
|
|
13
|
-
var basename = path.basename;
|
|
14
|
-
var dirname = path.dirname;
|
|
15
|
-
|
|
16
|
-
var uniqueIndex = 0;
|
|
17
|
-
function getUniqueIndex() {
|
|
18
|
-
return uniqueIndex++;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var property_files = fs
|
|
22
|
-
.readdirSync(path.resolve(__dirname, '../lib/properties'))
|
|
23
|
-
.filter(function(property) {
|
|
24
|
-
return property.substr(-3) === '.js';
|
|
25
|
-
});
|
|
26
|
-
var out_file = fs.createWriteStream(path.resolve(__dirname, '../lib/properties.js'), {
|
|
27
|
-
encoding: 'utf-8',
|
|
28
|
-
});
|
|
29
|
-
var date_today = new Date();
|
|
30
|
-
out_file.write(
|
|
31
|
-
"'use strict';\n\n// autogenerated - " +
|
|
32
|
-
(date_today.getMonth() + 1 + '/' + date_today.getDate() + '/' + date_today.getFullYear()) +
|
|
33
|
-
'\n\n'
|
|
34
|
-
);
|
|
35
|
-
out_file.write('/*\n *\n * https://www.w3.org/Style/CSS/all-properties.en.html\n */\n\n');
|
|
36
|
-
|
|
37
|
-
function isModuleDotExports(node) {
|
|
38
|
-
return (
|
|
39
|
-
t.isMemberExpression(node, { computed: false }) &&
|
|
40
|
-
t.isIdentifier(node.object, { name: 'module' }) &&
|
|
41
|
-
t.isIdentifier(node.property, { name: 'exports' })
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
function isRequire(node, filename) {
|
|
45
|
-
if (
|
|
46
|
-
t.isCallExpression(node) &&
|
|
47
|
-
t.isIdentifier(node.callee, { name: 'require' }) &&
|
|
48
|
-
node.arguments.length === 1 &&
|
|
49
|
-
t.isStringLiteral(node.arguments[0])
|
|
50
|
-
) {
|
|
51
|
-
var relative = node.arguments[0].value;
|
|
52
|
-
var fullPath = resolve.sync(relative, { basedir: dirname(filename) });
|
|
53
|
-
return { relative: relative, fullPath: fullPath };
|
|
54
|
-
} else {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// step 1: parse all files and figure out their dependencies
|
|
60
|
-
var parsedFilesByPath = {};
|
|
61
|
-
property_files.map(function(property) {
|
|
62
|
-
var filename = path.resolve(__dirname, '../lib/properties/' + property);
|
|
63
|
-
var src = fs.readFileSync(filename, 'utf8');
|
|
64
|
-
property = basename(property, '.js');
|
|
65
|
-
var ast = babylon.parse(src);
|
|
66
|
-
var dependencies = [];
|
|
67
|
-
traverse(ast, {
|
|
68
|
-
enter(path) {
|
|
69
|
-
var r;
|
|
70
|
-
if ((r = isRequire(path.node, filename))) {
|
|
71
|
-
dependencies.push(r.fullPath);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
parsedFilesByPath[filename] = {
|
|
76
|
-
filename: filename,
|
|
77
|
-
property: property,
|
|
78
|
-
ast: ast,
|
|
79
|
-
dependencies: dependencies,
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// step 2: serialize the files in an order where dependencies are always above
|
|
84
|
-
// the files they depend on
|
|
85
|
-
var externalDependencies = [];
|
|
86
|
-
var parsedFiles = [];
|
|
87
|
-
var addedFiles = {};
|
|
88
|
-
function addFile(filename, dependencyPath) {
|
|
89
|
-
if (dependencyPath.indexOf(filename) !== -1) {
|
|
90
|
-
throw new Error(
|
|
91
|
-
'Circular dependency: ' +
|
|
92
|
-
dependencyPath
|
|
93
|
-
.slice(dependencyPath.indexOf(filename))
|
|
94
|
-
.concat([filename])
|
|
95
|
-
.join(' -> ')
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
var file = parsedFilesByPath[filename];
|
|
99
|
-
if (addedFiles[filename]) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (!file) {
|
|
103
|
-
externalDependencies.push(filename);
|
|
104
|
-
} else {
|
|
105
|
-
file.dependencies.forEach(function(dependency) {
|
|
106
|
-
addFile(dependency, dependencyPath.concat([filename]));
|
|
107
|
-
});
|
|
108
|
-
parsedFiles.push(parsedFilesByPath[filename]);
|
|
109
|
-
}
|
|
110
|
-
addedFiles[filename] = true;
|
|
111
|
-
}
|
|
112
|
-
Object.keys(parsedFilesByPath).forEach(function(filename) {
|
|
113
|
-
addFile(filename, []);
|
|
114
|
-
});
|
|
115
|
-
// Step 3: add files to output
|
|
116
|
-
// renaming exports to local variables `moduleName_export_exportName`
|
|
117
|
-
// and updating require calls as appropriate
|
|
118
|
-
var moduleExportsByPath = {};
|
|
119
|
-
var statements = [];
|
|
120
|
-
externalDependencies.forEach(function(filename, i) {
|
|
121
|
-
var id = t.identifier(
|
|
122
|
-
'external_dependency_' + basename(filename, '.js').replace(/[^A-Za-z]/g, '') + '_' + i
|
|
123
|
-
);
|
|
124
|
-
moduleExportsByPath[filename] = { defaultExports: id };
|
|
125
|
-
var relativePath = path.relative(path.resolve(__dirname + '/../lib'), filename);
|
|
126
|
-
if (relativePath[0] !== '.') {
|
|
127
|
-
relativePath = './' + relativePath;
|
|
128
|
-
}
|
|
129
|
-
statements.push(
|
|
130
|
-
t.variableDeclaration('var', [
|
|
131
|
-
t.variableDeclarator(
|
|
132
|
-
id,
|
|
133
|
-
t.callExpression(t.identifier('require'), [t.stringLiteral(relativePath)])
|
|
134
|
-
),
|
|
135
|
-
])
|
|
136
|
-
);
|
|
137
|
-
});
|
|
138
|
-
function getRequireValue(node, file) {
|
|
139
|
-
var r, e;
|
|
140
|
-
// replace require("./foo").bar with the named export from foo
|
|
141
|
-
if (
|
|
142
|
-
t.isMemberExpression(node, { computed: false }) &&
|
|
143
|
-
(r = isRequire(node.object, file.filename))
|
|
144
|
-
) {
|
|
145
|
-
e = moduleExportsByPath[r.fullPath];
|
|
146
|
-
if (!e) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!e.namedExports) {
|
|
150
|
-
return t.memberExpression(e.defaultExports, node.property);
|
|
151
|
-
}
|
|
152
|
-
if (!e.namedExports[node.property.name]) {
|
|
153
|
-
throw new Error(r.relative + ' does not export ' + node.property.name);
|
|
154
|
-
}
|
|
155
|
-
return e.namedExports[node.property.name];
|
|
156
|
-
|
|
157
|
-
// replace require("./foo") with the default export of foo
|
|
158
|
-
} else if ((r = isRequire(node, file.filename))) {
|
|
159
|
-
e = moduleExportsByPath[r.fullPath];
|
|
160
|
-
if (!e) {
|
|
161
|
-
if (/^\.\.\//.test(r.relative)) {
|
|
162
|
-
node.arguments[0].value = r.relative.substr(1);
|
|
163
|
-
}
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
return e.defaultExports;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
parsedFiles.forEach(function(file) {
|
|
170
|
-
var namedExports = {};
|
|
171
|
-
var localVariableMap = {};
|
|
172
|
-
|
|
173
|
-
traverse(file.ast, {
|
|
174
|
-
enter(path) {
|
|
175
|
-
// replace require calls with the corresponding value
|
|
176
|
-
var r;
|
|
177
|
-
if ((r = getRequireValue(path.node, file))) {
|
|
178
|
-
path.replaceWith(r);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// if we see `var foo = require('bar')` we can just inline the variable
|
|
183
|
-
// representing `require('bar')` wherever `foo` was used.
|
|
184
|
-
if (
|
|
185
|
-
t.isVariableDeclaration(path.node) &&
|
|
186
|
-
path.node.declarations.length === 1 &&
|
|
187
|
-
t.isIdentifier(path.node.declarations[0].id) &&
|
|
188
|
-
(r = getRequireValue(path.node.declarations[0].init, file))
|
|
189
|
-
) {
|
|
190
|
-
var newName = 'compiled_local_variable_reference_' + getUniqueIndex();
|
|
191
|
-
path.scope.rename(path.node.declarations[0].id.name, newName);
|
|
192
|
-
localVariableMap[newName] = r;
|
|
193
|
-
path.remove();
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// rename all top level functions to keep them local to the module
|
|
198
|
-
if (t.isFunctionDeclaration(path.node) && t.isProgram(path.parent)) {
|
|
199
|
-
path.scope.rename(path.node.id.name, file.property + '_local_fn_' + path.node.id.name);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// rename all top level variables to keep them local to the module
|
|
204
|
-
if (t.isVariableDeclaration(path.node) && t.isProgram(path.parent)) {
|
|
205
|
-
path.node.declarations.forEach(function(declaration) {
|
|
206
|
-
path.scope.rename(
|
|
207
|
-
declaration.id.name,
|
|
208
|
-
file.property + '_local_var_' + declaration.id.name
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// replace module.exports.bar with a variable for the named export
|
|
215
|
-
if (
|
|
216
|
-
t.isMemberExpression(path.node, { computed: false }) &&
|
|
217
|
-
isModuleDotExports(path.node.object)
|
|
218
|
-
) {
|
|
219
|
-
var name = path.node.property.name;
|
|
220
|
-
var identifier = t.identifier(file.property + '_export_' + name);
|
|
221
|
-
path.replaceWith(identifier);
|
|
222
|
-
namedExports[name] = identifier;
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
traverse(file.ast, {
|
|
227
|
-
enter(path) {
|
|
228
|
-
if (
|
|
229
|
-
t.isIdentifier(path.node) &&
|
|
230
|
-
Object.prototype.hasOwnProperty.call(localVariableMap, path.node.name)
|
|
231
|
-
) {
|
|
232
|
-
path.replaceWith(localVariableMap[path.node.name]);
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
var defaultExports = t.objectExpression(
|
|
237
|
-
Object.keys(namedExports).map(function(name) {
|
|
238
|
-
return t.objectProperty(t.identifier(name), namedExports[name]);
|
|
239
|
-
})
|
|
240
|
-
);
|
|
241
|
-
moduleExportsByPath[file.filename] = {
|
|
242
|
-
namedExports: namedExports,
|
|
243
|
-
defaultExports: defaultExports,
|
|
244
|
-
};
|
|
245
|
-
statements.push(
|
|
246
|
-
t.variableDeclaration(
|
|
247
|
-
'var',
|
|
248
|
-
Object.keys(namedExports).map(function(name) {
|
|
249
|
-
return t.variableDeclarator(namedExports[name]);
|
|
250
|
-
})
|
|
251
|
-
)
|
|
252
|
-
);
|
|
253
|
-
statements.push.apply(statements, file.ast.program.body);
|
|
254
|
-
});
|
|
255
|
-
var propertyDefinitions = [];
|
|
256
|
-
parsedFiles.forEach(function(file) {
|
|
257
|
-
var dashed = camelToDashed(file.property);
|
|
258
|
-
propertyDefinitions.push(
|
|
259
|
-
t.objectProperty(
|
|
260
|
-
t.identifier(file.property),
|
|
261
|
-
t.identifier(file.property + '_export_definition')
|
|
262
|
-
)
|
|
263
|
-
);
|
|
264
|
-
if (file.property !== dashed) {
|
|
265
|
-
propertyDefinitions.push(
|
|
266
|
-
t.objectProperty(t.stringLiteral(dashed), t.identifier(file.property + '_export_definition'))
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
});
|
|
270
|
-
var definePropertiesCall = t.callExpression(
|
|
271
|
-
t.memberExpression(t.identifier('Object'), t.identifier('defineProperties')),
|
|
272
|
-
[t.identifier('prototype'), t.objectExpression(propertyDefinitions)]
|
|
273
|
-
);
|
|
274
|
-
statements.push(
|
|
275
|
-
t.expressionStatement(
|
|
276
|
-
t.assignmentExpression(
|
|
277
|
-
'=',
|
|
278
|
-
t.memberExpression(t.identifier('module'), t.identifier('exports')),
|
|
279
|
-
t.functionExpression(
|
|
280
|
-
null,
|
|
281
|
-
[t.identifier('prototype')],
|
|
282
|
-
t.blockStatement([t.expressionStatement(definePropertiesCall)])
|
|
283
|
-
)
|
|
284
|
-
)
|
|
285
|
-
)
|
|
286
|
-
);
|
|
287
|
-
out_file.write(generate(t.program(statements)).code + '\n');
|
|
288
|
-
out_file.end(function(err) {
|
|
289
|
-
if (err) {
|
|
290
|
-
throw err;
|
|
291
|
-
}
|
|
292
|
-
});
|