less 3.10.0-beta.2 → 3.10.3
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/.DS_Store +0 -0
- package/bin/lessc +6652 -5505
- package/dist/less.cjs.js +6593 -5448
- package/dist/less.js +10 -6
- package/dist/less.min.js +2 -2
- package/dist/less.min.js.map +1 -1
- package/lib/less/constants.js +13 -0
- package/lib/less/contexts.js +164 -0
- package/lib/less/data/colors.js +150 -0
- package/lib/less/data/index.js +4 -0
- package/lib/less/data/unit-conversions.js +21 -0
- package/lib/less/default-options.js +68 -0
- package/lib/less/environment/abstract-file-manager.js +127 -0
- package/lib/less/environment/abstract-plugin-loader.js +187 -0
- package/lib/less/environment/environment-api.js +25 -0
- package/lib/less/environment/environment.js +59 -0
- package/lib/less/environment/file-manager-api.js +103 -0
- package/lib/less/functions/boolean.js +13 -0
- package/lib/less/functions/color-blending.js +84 -0
- package/lib/less/functions/color.js +417 -0
- package/lib/less/functions/data-uri.js +74 -0
- package/lib/less/functions/default.js +25 -0
- package/lib/less/functions/function-caller.js +49 -0
- package/lib/less/functions/function-registry.js +35 -0
- package/lib/less/functions/index.js +33 -0
- package/lib/less/functions/list.js +143 -0
- package/lib/less/functions/math-helper.js +15 -0
- package/lib/less/functions/math.js +28 -0
- package/lib/less/functions/number.js +89 -0
- package/lib/less/functions/string.js +36 -0
- package/lib/less/functions/svg.js +87 -0
- package/lib/less/functions/types.js +70 -0
- package/lib/less/import-manager.js +169 -0
- package/lib/less/index.js +92 -0
- package/lib/less/less-error.js +140 -0
- package/lib/less/logger.js +34 -0
- package/lib/less/parse-tree.js +66 -0
- package/lib/less/parse.js +89 -0
- package/lib/less/parser/chunker.js +122 -0
- package/lib/less/parser/parser-input.js +390 -0
- package/lib/less/parser/parser.js +2418 -0
- package/lib/less/plugin-manager.js +168 -0
- package/lib/less/render.js +42 -0
- package/lib/less/source-map-builder.js +77 -0
- package/lib/less/source-map-output.js +149 -0
- package/lib/less/transform-tree.js +96 -0
- package/lib/less/tree/anonymous.js +37 -0
- package/lib/less/tree/assignment.js +33 -0
- package/lib/less/tree/atrule.js +165 -0
- package/lib/less/tree/attribute.js +34 -0
- package/lib/less/tree/call.js +105 -0
- package/lib/less/tree/color.js +246 -0
- package/lib/less/tree/combinator.js +29 -0
- package/lib/less/tree/comment.js +29 -0
- package/lib/less/tree/condition.js +43 -0
- package/lib/less/tree/debug-info.js +34 -0
- package/lib/less/tree/declaration.js +115 -0
- package/lib/less/tree/detached-ruleset.js +30 -0
- package/lib/less/tree/dimension.js +179 -0
- package/lib/less/tree/element.js +73 -0
- package/lib/less/tree/expression.js +74 -0
- package/lib/less/tree/extend.js +66 -0
- package/lib/less/tree/import.js +184 -0
- package/lib/less/tree/index.js +54 -0
- package/lib/less/tree/javascript.js +33 -0
- package/lib/less/tree/js-eval-node.js +58 -0
- package/lib/less/tree/keyword.js +21 -0
- package/lib/less/tree/media.js +154 -0
- package/lib/less/tree/mixin-call.js +215 -0
- package/lib/less/tree/mixin-definition.js +229 -0
- package/lib/less/tree/namespace-value.js +87 -0
- package/lib/less/tree/negative.js +26 -0
- package/lib/less/tree/node.js +178 -0
- package/lib/less/tree/operation.js +62 -0
- package/lib/less/tree/paren.js +22 -0
- package/lib/less/tree/property.js +77 -0
- package/lib/less/tree/quoted.js +70 -0
- package/lib/less/tree/ruleset.js +867 -0
- package/lib/less/tree/selector.js +146 -0
- package/lib/less/tree/unicode-descriptor.js +13 -0
- package/lib/less/tree/unit.js +141 -0
- package/lib/less/tree/url.js +65 -0
- package/lib/less/tree/value.js +44 -0
- package/lib/less/tree/variable-call.js +46 -0
- package/lib/less/tree/variable.js +67 -0
- package/lib/less/utils.js +122 -0
- package/lib/less/visitors/extend-visitor.js +505 -0
- package/lib/less/visitors/import-sequencer.js +58 -0
- package/lib/less/visitors/import-visitor.js +189 -0
- package/lib/less/visitors/index.js +15 -0
- package/lib/less/visitors/join-selector-visitor.js +57 -0
- package/lib/less/visitors/set-tree-visibility-visitor.js +45 -0
- package/lib/less/visitors/to-css-visitor.js +363 -0
- package/lib/less/visitors/visitor.js +163 -0
- package/lib/less-browser/add-default-options.js +49 -0
- package/lib/less-browser/bootstrap.js +69 -0
- package/lib/less-browser/browser.js +65 -0
- package/lib/less-browser/cache.js +43 -0
- package/lib/less-browser/error-reporting.js +170 -0
- package/lib/less-browser/file-manager.js +113 -0
- package/lib/less-browser/image-size.js +28 -0
- package/lib/less-browser/index.js +285 -0
- package/lib/less-browser/log-listener.js +42 -0
- package/lib/less-browser/plugin-loader.js +26 -0
- package/lib/less-browser/utils.js +24 -0
- package/lib/less-node/environment.js +16 -0
- package/lib/less-node/file-manager.js +177 -0
- package/lib/less-node/fs.js +10 -0
- package/lib/less-node/image-size.js +58 -0
- package/lib/less-node/index.js +27 -0
- package/lib/less-node/lessc-helper.js +89 -0
- package/lib/less-node/plugin-loader.js +53 -0
- package/lib/less-node/url-file-manager.js +49 -0
- package/lib/lessc.js +557 -0
- package/lib/source-map/source-map-0.1.31.js +1933 -0
- package/lib/source-map/source-map-footer.js +4 -0
- package/lib/source-map/source-map-header.js +3 -0
- package/package.json +1 -1
- package/test/.DS_Store +0 -0
- package/test/browser/less.min.js +11 -0
- package/test/browser/less.min.js.map +1 -0
- package/test/css/css-escapes.css +1 -0
- package/test/less/css-escapes.less +3 -1
- package/.git/index +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin Manager
|
|
3
|
+
*/
|
|
4
|
+
class PluginManager {
|
|
5
|
+
constructor(less) {
|
|
6
|
+
this.less = less;
|
|
7
|
+
this.visitors = [];
|
|
8
|
+
this.preProcessors = [];
|
|
9
|
+
this.postProcessors = [];
|
|
10
|
+
this.installedPlugins = [];
|
|
11
|
+
this.fileManagers = [];
|
|
12
|
+
this.iterator = -1;
|
|
13
|
+
this.pluginCache = {};
|
|
14
|
+
this.Loader = new less.PluginLoader(less);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Adds all the plugins in the array
|
|
19
|
+
* @param {Array} plugins
|
|
20
|
+
*/
|
|
21
|
+
addPlugins(plugins) {
|
|
22
|
+
if (plugins) {
|
|
23
|
+
for (let i = 0; i < plugins.length; i++) {
|
|
24
|
+
this.addPlugin(plugins[i]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param plugin
|
|
32
|
+
* @param {String} filename
|
|
33
|
+
*/
|
|
34
|
+
addPlugin(plugin, filename, functionRegistry) {
|
|
35
|
+
this.installedPlugins.push(plugin);
|
|
36
|
+
if (filename) {
|
|
37
|
+
this.pluginCache[filename] = plugin;
|
|
38
|
+
}
|
|
39
|
+
if (plugin.install) {
|
|
40
|
+
plugin.install(this.less, this, functionRegistry || this.less.functions.functionRegistry);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param filename
|
|
47
|
+
*/
|
|
48
|
+
get(filename) {
|
|
49
|
+
return this.pluginCache[filename];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Adds a visitor. The visitor object has options on itself to determine
|
|
54
|
+
* when it should run.
|
|
55
|
+
* @param visitor
|
|
56
|
+
*/
|
|
57
|
+
addVisitor(visitor) {
|
|
58
|
+
this.visitors.push(visitor);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Adds a pre processor object
|
|
63
|
+
* @param {object} preProcessor
|
|
64
|
+
* @param {number} priority - guidelines 1 = before import, 1000 = import, 2000 = after import
|
|
65
|
+
*/
|
|
66
|
+
addPreProcessor(preProcessor, priority) {
|
|
67
|
+
let indexToInsertAt;
|
|
68
|
+
for (indexToInsertAt = 0; indexToInsertAt < this.preProcessors.length; indexToInsertAt++) {
|
|
69
|
+
if (this.preProcessors[indexToInsertAt].priority >= priority) {
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.preProcessors.splice(indexToInsertAt, 0, {preProcessor, priority});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Adds a post processor object
|
|
78
|
+
* @param {object} postProcessor
|
|
79
|
+
* @param {number} priority - guidelines 1 = before compression, 1000 = compression, 2000 = after compression
|
|
80
|
+
*/
|
|
81
|
+
addPostProcessor(postProcessor, priority) {
|
|
82
|
+
let indexToInsertAt;
|
|
83
|
+
for (indexToInsertAt = 0; indexToInsertAt < this.postProcessors.length; indexToInsertAt++) {
|
|
84
|
+
if (this.postProcessors[indexToInsertAt].priority >= priority) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
this.postProcessors.splice(indexToInsertAt, 0, {postProcessor, priority});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param manager
|
|
94
|
+
*/
|
|
95
|
+
addFileManager(manager) {
|
|
96
|
+
this.fileManagers.push(manager);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @returns {Array}
|
|
102
|
+
* @private
|
|
103
|
+
*/
|
|
104
|
+
getPreProcessors() {
|
|
105
|
+
const preProcessors = [];
|
|
106
|
+
for (let i = 0; i < this.preProcessors.length; i++) {
|
|
107
|
+
preProcessors.push(this.preProcessors[i].preProcessor);
|
|
108
|
+
}
|
|
109
|
+
return preProcessors;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @returns {Array}
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
getPostProcessors() {
|
|
118
|
+
const postProcessors = [];
|
|
119
|
+
for (let i = 0; i < this.postProcessors.length; i++) {
|
|
120
|
+
postProcessors.push(this.postProcessors[i].postProcessor);
|
|
121
|
+
}
|
|
122
|
+
return postProcessors;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @returns {Array}
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
getVisitors() {
|
|
131
|
+
return this.visitors;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
visitor() {
|
|
135
|
+
const self = this;
|
|
136
|
+
return {
|
|
137
|
+
first: function() {
|
|
138
|
+
self.iterator = -1;
|
|
139
|
+
return self.visitors[self.iterator];
|
|
140
|
+
},
|
|
141
|
+
get: function() {
|
|
142
|
+
self.iterator += 1;
|
|
143
|
+
return self.visitors[self.iterator];
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @returns {Array}
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
getFileManagers() {
|
|
154
|
+
return this.fileManagers;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
let pm;
|
|
159
|
+
|
|
160
|
+
function PluginManagerFactory(less, newFactory) {
|
|
161
|
+
if (newFactory || !pm) {
|
|
162
|
+
pm = new PluginManager(less);
|
|
163
|
+
}
|
|
164
|
+
return pm;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
//
|
|
168
|
+
export default PluginManagerFactory;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
let PromiseConstructor;
|
|
2
|
+
import * as utils from './utils';
|
|
3
|
+
|
|
4
|
+
export default (environment, ParseTree, ImportManager) => {
|
|
5
|
+
const render = function (input, options, callback) {
|
|
6
|
+
if (typeof options === 'function') {
|
|
7
|
+
callback = options;
|
|
8
|
+
options = utils.copyOptions(this.options, {});
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
options = utils.copyOptions(this.options, options || {});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!callback) {
|
|
15
|
+
const self = this;
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
render.call(self, input, options, (err, output) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
reject(err);
|
|
20
|
+
} else {
|
|
21
|
+
resolve(output);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
this.parse(input, options, (err, root, imports, options) => {
|
|
27
|
+
if (err) { return callback(err); }
|
|
28
|
+
|
|
29
|
+
let result;
|
|
30
|
+
try {
|
|
31
|
+
const parseTree = new ParseTree(root, imports);
|
|
32
|
+
result = parseTree.toCSS(options);
|
|
33
|
+
}
|
|
34
|
+
catch (err) { return callback(err); }
|
|
35
|
+
|
|
36
|
+
callback(null, result);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return render;
|
|
42
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export default (SourceMapOutput, environment) => {
|
|
2
|
+
class SourceMapBuilder {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this.options = options;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
toCSS(rootNode, options, imports) {
|
|
8
|
+
const sourceMapOutput = new SourceMapOutput(
|
|
9
|
+
{
|
|
10
|
+
contentsIgnoredCharsMap: imports.contentsIgnoredChars,
|
|
11
|
+
rootNode,
|
|
12
|
+
contentsMap: imports.contents,
|
|
13
|
+
sourceMapFilename: this.options.sourceMapFilename,
|
|
14
|
+
sourceMapURL: this.options.sourceMapURL,
|
|
15
|
+
outputFilename: this.options.sourceMapOutputFilename,
|
|
16
|
+
sourceMapBasepath: this.options.sourceMapBasepath,
|
|
17
|
+
sourceMapRootpath: this.options.sourceMapRootpath,
|
|
18
|
+
outputSourceFiles: this.options.outputSourceFiles,
|
|
19
|
+
sourceMapGenerator: this.options.sourceMapGenerator,
|
|
20
|
+
sourceMapFileInline: this.options.sourceMapFileInline
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const css = sourceMapOutput.toCSS(options);
|
|
24
|
+
this.sourceMap = sourceMapOutput.sourceMap;
|
|
25
|
+
this.sourceMapURL = sourceMapOutput.sourceMapURL;
|
|
26
|
+
if (this.options.sourceMapInputFilename) {
|
|
27
|
+
this.sourceMapInputFilename = sourceMapOutput.normalizeFilename(this.options.sourceMapInputFilename);
|
|
28
|
+
}
|
|
29
|
+
if (this.options.sourceMapBasepath !== undefined && this.sourceMapURL !== undefined) {
|
|
30
|
+
this.sourceMapURL = sourceMapOutput.removeBasepath(this.sourceMapURL);
|
|
31
|
+
}
|
|
32
|
+
return css + this.getCSSAppendage();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
getCSSAppendage() {
|
|
36
|
+
|
|
37
|
+
let sourceMapURL = this.sourceMapURL;
|
|
38
|
+
if (this.options.sourceMapFileInline) {
|
|
39
|
+
if (this.sourceMap === undefined) {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
sourceMapURL = `data:application/json;base64,${environment.encodeBase64(this.sourceMap)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (sourceMapURL) {
|
|
46
|
+
return `/*# sourceMappingURL=${sourceMapURL} */`;
|
|
47
|
+
}
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getExternalSourceMap() {
|
|
52
|
+
return this.sourceMap;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
setExternalSourceMap(sourceMap) {
|
|
56
|
+
this.sourceMap = sourceMap;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
isInline() {
|
|
60
|
+
return this.options.sourceMapFileInline;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
getSourceMapURL() {
|
|
64
|
+
return this.sourceMapURL;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
getOutputFilename() {
|
|
68
|
+
return this.options.sourceMapOutputFilename;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getInputFilename() {
|
|
72
|
+
return this.sourceMapInputFilename;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return SourceMapBuilder;
|
|
77
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
export default environment => {
|
|
2
|
+
class SourceMapOutput {
|
|
3
|
+
constructor(options) {
|
|
4
|
+
this._css = [];
|
|
5
|
+
this._rootNode = options.rootNode;
|
|
6
|
+
this._contentsMap = options.contentsMap;
|
|
7
|
+
this._contentsIgnoredCharsMap = options.contentsIgnoredCharsMap;
|
|
8
|
+
if (options.sourceMapFilename) {
|
|
9
|
+
this._sourceMapFilename = options.sourceMapFilename.replace(/\\/g, '/');
|
|
10
|
+
}
|
|
11
|
+
this._outputFilename = options.outputFilename;
|
|
12
|
+
this.sourceMapURL = options.sourceMapURL;
|
|
13
|
+
if (options.sourceMapBasepath) {
|
|
14
|
+
this._sourceMapBasepath = options.sourceMapBasepath.replace(/\\/g, '/');
|
|
15
|
+
}
|
|
16
|
+
if (options.sourceMapRootpath) {
|
|
17
|
+
this._sourceMapRootpath = options.sourceMapRootpath.replace(/\\/g, '/');
|
|
18
|
+
if (this._sourceMapRootpath.charAt(this._sourceMapRootpath.length - 1) !== '/') {
|
|
19
|
+
this._sourceMapRootpath += '/';
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
this._sourceMapRootpath = '';
|
|
23
|
+
}
|
|
24
|
+
this._outputSourceFiles = options.outputSourceFiles;
|
|
25
|
+
this._sourceMapGeneratorConstructor = environment.getSourceMapGenerator();
|
|
26
|
+
|
|
27
|
+
this._lineNumber = 0;
|
|
28
|
+
this._column = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
removeBasepath(path) {
|
|
32
|
+
if (this._sourceMapBasepath && path.indexOf(this._sourceMapBasepath) === 0) {
|
|
33
|
+
path = path.substring(this._sourceMapBasepath.length);
|
|
34
|
+
if (path.charAt(0) === '\\' || path.charAt(0) === '/') {
|
|
35
|
+
path = path.substring(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return path;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
normalizeFilename(filename) {
|
|
43
|
+
filename = filename.replace(/\\/g, '/');
|
|
44
|
+
filename = this.removeBasepath(filename);
|
|
45
|
+
return (this._sourceMapRootpath || '') + filename;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
add(chunk, fileInfo, index, mapLines) {
|
|
49
|
+
// ignore adding empty strings
|
|
50
|
+
if (!chunk) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let lines;
|
|
55
|
+
let sourceLines;
|
|
56
|
+
let columns;
|
|
57
|
+
let sourceColumns;
|
|
58
|
+
let i;
|
|
59
|
+
|
|
60
|
+
if (fileInfo && fileInfo.filename) {
|
|
61
|
+
let inputSource = this._contentsMap[fileInfo.filename];
|
|
62
|
+
|
|
63
|
+
// remove vars/banner added to the top of the file
|
|
64
|
+
if (this._contentsIgnoredCharsMap[fileInfo.filename]) {
|
|
65
|
+
// adjust the index
|
|
66
|
+
index -= this._contentsIgnoredCharsMap[fileInfo.filename];
|
|
67
|
+
if (index < 0) { index = 0; }
|
|
68
|
+
// adjust the source
|
|
69
|
+
inputSource = inputSource.slice(this._contentsIgnoredCharsMap[fileInfo.filename]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ignore empty content
|
|
73
|
+
if (inputSource === undefined) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
inputSource = inputSource.substring(0, index);
|
|
78
|
+
sourceLines = inputSource.split('\n');
|
|
79
|
+
sourceColumns = sourceLines[sourceLines.length - 1];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
lines = chunk.split('\n');
|
|
83
|
+
columns = lines[lines.length - 1];
|
|
84
|
+
|
|
85
|
+
if (fileInfo && fileInfo.filename) {
|
|
86
|
+
if (!mapLines) {
|
|
87
|
+
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
|
|
88
|
+
original: { line: sourceLines.length, column: sourceColumns.length},
|
|
89
|
+
source: this.normalizeFilename(fileInfo.filename)});
|
|
90
|
+
} else {
|
|
91
|
+
for (i = 0; i < lines.length; i++) {
|
|
92
|
+
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + i + 1, column: i === 0 ? this._column : 0},
|
|
93
|
+
original: { line: sourceLines.length + i, column: i === 0 ? sourceColumns.length : 0},
|
|
94
|
+
source: this.normalizeFilename(fileInfo.filename)});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (lines.length === 1) {
|
|
100
|
+
this._column += columns.length;
|
|
101
|
+
} else {
|
|
102
|
+
this._lineNumber += lines.length - 1;
|
|
103
|
+
this._column = columns.length;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
this._css.push(chunk);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
isEmpty() {
|
|
110
|
+
return this._css.length === 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
toCSS(context) {
|
|
114
|
+
this._sourceMapGenerator = new this._sourceMapGeneratorConstructor({ file: this._outputFilename, sourceRoot: null });
|
|
115
|
+
|
|
116
|
+
if (this._outputSourceFiles) {
|
|
117
|
+
for (const filename in this._contentsMap) {
|
|
118
|
+
if (this._contentsMap.hasOwnProperty(filename)) {
|
|
119
|
+
let source = this._contentsMap[filename];
|
|
120
|
+
if (this._contentsIgnoredCharsMap[filename]) {
|
|
121
|
+
source = source.slice(this._contentsIgnoredCharsMap[filename]);
|
|
122
|
+
}
|
|
123
|
+
this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), source);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this._rootNode.genCSS(context, this);
|
|
129
|
+
|
|
130
|
+
if (this._css.length > 0) {
|
|
131
|
+
let sourceMapURL;
|
|
132
|
+
const sourceMapContent = JSON.stringify(this._sourceMapGenerator.toJSON());
|
|
133
|
+
|
|
134
|
+
if (this.sourceMapURL) {
|
|
135
|
+
sourceMapURL = this.sourceMapURL;
|
|
136
|
+
} else if (this._sourceMapFilename) {
|
|
137
|
+
sourceMapURL = this._sourceMapFilename;
|
|
138
|
+
}
|
|
139
|
+
this.sourceMapURL = sourceMapURL;
|
|
140
|
+
|
|
141
|
+
this.sourceMap = sourceMapContent;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return this._css.join('');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return SourceMapOutput;
|
|
149
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import contexts from './contexts';
|
|
2
|
+
import visitor from './visitors';
|
|
3
|
+
import tree from './tree';
|
|
4
|
+
|
|
5
|
+
export default (root, options = {}) => {
|
|
6
|
+
let evaldRoot;
|
|
7
|
+
let variables = options.variables;
|
|
8
|
+
const evalEnv = new contexts.Eval(options);
|
|
9
|
+
|
|
10
|
+
//
|
|
11
|
+
// Allows setting variables with a hash, so:
|
|
12
|
+
//
|
|
13
|
+
// `{ color: new tree.Color('#f01') }` will become:
|
|
14
|
+
//
|
|
15
|
+
// new tree.Declaration('@color',
|
|
16
|
+
// new tree.Value([
|
|
17
|
+
// new tree.Expression([
|
|
18
|
+
// new tree.Color('#f01')
|
|
19
|
+
// ])
|
|
20
|
+
// ])
|
|
21
|
+
// )
|
|
22
|
+
//
|
|
23
|
+
if (typeof variables === 'object' && !Array.isArray(variables)) {
|
|
24
|
+
variables = Object.keys(variables).map(k => {
|
|
25
|
+
let value = variables[k];
|
|
26
|
+
|
|
27
|
+
if (!(value instanceof tree.Value)) {
|
|
28
|
+
if (!(value instanceof tree.Expression)) {
|
|
29
|
+
value = new tree.Expression([value]);
|
|
30
|
+
}
|
|
31
|
+
value = new tree.Value([value]);
|
|
32
|
+
}
|
|
33
|
+
return new tree.Declaration(`@${k}`, value, false, null, 0);
|
|
34
|
+
});
|
|
35
|
+
evalEnv.frames = [new tree.Ruleset(null, variables)];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const visitors = [
|
|
39
|
+
new visitor.JoinSelectorVisitor(),
|
|
40
|
+
new visitor.MarkVisibleSelectorsVisitor(true),
|
|
41
|
+
new visitor.ExtendVisitor(),
|
|
42
|
+
new visitor.ToCSSVisitor({compress: Boolean(options.compress)})
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const preEvalVisitors = [];
|
|
46
|
+
let v;
|
|
47
|
+
let visitorIterator;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* first() / get() allows visitors to be added while visiting
|
|
51
|
+
*
|
|
52
|
+
* @todo Add scoping for visitors just like functions for @plugin; right now they're global
|
|
53
|
+
*/
|
|
54
|
+
if (options.pluginManager) {
|
|
55
|
+
visitorIterator = options.pluginManager.visitor();
|
|
56
|
+
for (var i = 0; i < 2; i++) {
|
|
57
|
+
visitorIterator.first();
|
|
58
|
+
while ((v = visitorIterator.get())) {
|
|
59
|
+
if (v.isPreEvalVisitor) {
|
|
60
|
+
if (i === 0 || preEvalVisitors.indexOf(v) === -1) {
|
|
61
|
+
preEvalVisitors.push(v);
|
|
62
|
+
v.run(root);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (i === 0 || visitors.indexOf(v) === -1) {
|
|
67
|
+
if (v.isPreVisitor) {
|
|
68
|
+
visitors.unshift(v);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
visitors.push(v);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
evaldRoot = root.eval(evalEnv);
|
|
80
|
+
|
|
81
|
+
for (var i = 0; i < visitors.length; i++) {
|
|
82
|
+
visitors[i].run(evaldRoot);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Run any remaining visitors added after eval pass
|
|
86
|
+
if (options.pluginManager) {
|
|
87
|
+
visitorIterator.first();
|
|
88
|
+
while ((v = visitorIterator.get())) {
|
|
89
|
+
if (visitors.indexOf(v) === -1 && preEvalVisitors.indexOf(v) === -1) {
|
|
90
|
+
v.run(evaldRoot);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return evaldRoot;
|
|
96
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Node from './node';
|
|
2
|
+
|
|
3
|
+
class Anonymous extends Node {
|
|
4
|
+
constructor(value, index, currentFileInfo, mapLines, rulesetLike, visibilityInfo) {
|
|
5
|
+
super();
|
|
6
|
+
|
|
7
|
+
this.value = value;
|
|
8
|
+
this._index = index;
|
|
9
|
+
this._fileInfo = currentFileInfo;
|
|
10
|
+
this.mapLines = mapLines;
|
|
11
|
+
this.rulesetLike = (typeof rulesetLike === 'undefined') ? false : rulesetLike;
|
|
12
|
+
this.allowRoot = true;
|
|
13
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
eval() {
|
|
17
|
+
return new Anonymous(this.value, this._index, this._fileInfo, this.mapLines, this.rulesetLike, this.visibilityInfo());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
compare(other) {
|
|
21
|
+
return other.toCSS && this.toCSS() === other.toCSS() ? 0 : undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
isRulesetLike() {
|
|
25
|
+
return this.rulesetLike;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
genCSS(context, output) {
|
|
29
|
+
this.nodeVisible = Boolean(this.value);
|
|
30
|
+
if (this.nodeVisible) {
|
|
31
|
+
output.add(this.value, this._fileInfo, this._index, this.mapLines);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Anonymous.prototype.type = 'Anonymous';
|
|
37
|
+
export default Anonymous;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Node from './node';
|
|
2
|
+
|
|
3
|
+
class Assignment extends Node {
|
|
4
|
+
constructor(key, val) {
|
|
5
|
+
super();
|
|
6
|
+
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.value = val;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
accept(visitor) {
|
|
12
|
+
this.value = visitor.visit(this.value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
eval(context) {
|
|
16
|
+
if (this.value.eval) {
|
|
17
|
+
return new Assignment(this.key, this.value.eval(context));
|
|
18
|
+
}
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
genCSS(context, output) {
|
|
23
|
+
output.add(`${this.key}=`);
|
|
24
|
+
if (this.value.genCSS) {
|
|
25
|
+
this.value.genCSS(context, output);
|
|
26
|
+
} else {
|
|
27
|
+
output.add(this.value);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Assignment.prototype.type = 'Assignment';
|
|
33
|
+
export default Assignment;
|