less 4.9.0 → 5.0.0-alpha.2

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.
Files changed (131) hide show
  1. package/README.md +19 -5
  2. package/bin/lessc +190 -630
  3. package/dist/less-node.cjs +399 -14570
  4. package/index.cjs +5 -2
  5. package/lib/index.js +164 -0
  6. package/lib/lessc-helper.js +52 -0
  7. package/lib/logger.js +76 -0
  8. package/lib/options.d.ts +46 -0
  9. package/lib/options.js +145 -0
  10. package/lib/types.js +20 -0
  11. package/lib/version.js +19 -0
  12. package/package.json +32 -39
  13. package/dist/less.cjs +0 -15215
  14. package/dist/less.js +0 -15215
  15. package/dist/less.min.js +0 -11
  16. package/dist/less.min.js.map +0 -1
  17. package/lib/less/constants.js +0 -13
  18. package/lib/less/contexts.js +0 -165
  19. package/lib/less/data/colors.js +0 -150
  20. package/lib/less/data/index.js +0 -4
  21. package/lib/less/data/unit-conversions.js +0 -21
  22. package/lib/less/default-options.js +0 -89
  23. package/lib/less/deprecation.js +0 -82
  24. package/lib/less/environment/abstract-file-manager.js +0 -140
  25. package/lib/less/environment/abstract-plugin-loader.js +0 -185
  26. package/lib/less/environment/environment-api.ts +0 -21
  27. package/lib/less/environment/environment.js +0 -59
  28. package/lib/less/environment/file-manager-api.ts +0 -77
  29. package/lib/less/functions/boolean.js +0 -29
  30. package/lib/less/functions/color-blending.js +0 -85
  31. package/lib/less/functions/color.js +0 -452
  32. package/lib/less/functions/data-uri.js +0 -74
  33. package/lib/less/functions/default.js +0 -26
  34. package/lib/less/functions/function-caller.js +0 -55
  35. package/lib/less/functions/function-registry.js +0 -36
  36. package/lib/less/functions/index.js +0 -35
  37. package/lib/less/functions/list.js +0 -158
  38. package/lib/less/functions/math-helper.js +0 -22
  39. package/lib/less/functions/math.js +0 -30
  40. package/lib/less/functions/number.js +0 -95
  41. package/lib/less/functions/string.js +0 -39
  42. package/lib/less/functions/style.js +0 -29
  43. package/lib/less/functions/svg.js +0 -87
  44. package/lib/less/functions/types.js +0 -70
  45. package/lib/less/import-manager.js +0 -183
  46. package/lib/less/index.js +0 -95
  47. package/lib/less/less-error.js +0 -166
  48. package/lib/less/logger.js +0 -34
  49. package/lib/less/parse-tree.js +0 -124
  50. package/lib/less/parse.js +0 -87
  51. package/lib/less/parser/lookup-pattern.js +0 -26
  52. package/lib/less/parser/parser-input.js +0 -400
  53. package/lib/less/parser/parser.js +0 -2998
  54. package/lib/less/plugin-manager.js +0 -168
  55. package/lib/less/render.js +0 -41
  56. package/lib/less/source-map-builder.js +0 -82
  57. package/lib/less/source-map-output.js +0 -151
  58. package/lib/less/transform-tree.js +0 -102
  59. package/lib/less/tree/anonymous.js +0 -61
  60. package/lib/less/tree/assignment.js +0 -48
  61. package/lib/less/tree/atrule-syntax.js +0 -8
  62. package/lib/less/tree/atrule.js +0 -340
  63. package/lib/less/tree/attribute.js +0 -63
  64. package/lib/less/tree/call.js +0 -132
  65. package/lib/less/tree/color.js +0 -285
  66. package/lib/less/tree/combinator.js +0 -38
  67. package/lib/less/tree/comment.js +0 -48
  68. package/lib/less/tree/condition.js +0 -65
  69. package/lib/less/tree/container.js +0 -104
  70. package/lib/less/tree/debug-info.js +0 -80
  71. package/lib/less/tree/declaration.js +0 -139
  72. package/lib/less/tree/detached-ruleset.js +0 -45
  73. package/lib/less/tree/dimension.js +0 -215
  74. package/lib/less/tree/element.js +0 -93
  75. package/lib/less/tree/expression.js +0 -100
  76. package/lib/less/tree/extend.js +0 -88
  77. package/lib/less/tree/import.js +0 -299
  78. package/lib/less/tree/index.js +0 -56
  79. package/lib/less/tree/interpolated-variable.js +0 -106
  80. package/lib/less/tree/javascript.js +0 -45
  81. package/lib/less/tree/js-eval-node.js +0 -80
  82. package/lib/less/tree/keyword.js +0 -28
  83. package/lib/less/tree/media.js +0 -90
  84. package/lib/less/tree/merge-rules.js +0 -47
  85. package/lib/less/tree/mixin-call.js +0 -283
  86. package/lib/less/tree/mixin-definition.js +0 -319
  87. package/lib/less/tree/namespace-value.js +0 -95
  88. package/lib/less/tree/negative.js +0 -37
  89. package/lib/less/tree/nested-at-rule.js +0 -239
  90. package/lib/less/tree/node.js +0 -310
  91. package/lib/less/tree/operation.js +0 -81
  92. package/lib/less/tree/paren.js +0 -41
  93. package/lib/less/tree/property.js +0 -96
  94. package/lib/less/tree/query-in-parens.js +0 -64
  95. package/lib/less/tree/quoted.js +0 -131
  96. package/lib/less/tree/ruleset.js +0 -1068
  97. package/lib/less/tree/selector.js +0 -201
  98. package/lib/less/tree/unicode-descriptor.js +0 -14
  99. package/lib/less/tree/unit.js +0 -170
  100. package/lib/less/tree/url.js +0 -83
  101. package/lib/less/tree/value.js +0 -60
  102. package/lib/less/tree/variable-call.js +0 -60
  103. package/lib/less/tree/variable.js +0 -85
  104. package/lib/less/utils.js +0 -126
  105. package/lib/less/visitors/extend-visitor.js +0 -505
  106. package/lib/less/visitors/import-sequencer.js +0 -56
  107. package/lib/less/visitors/import-visitor.js +0 -203
  108. package/lib/less/visitors/index.js +0 -15
  109. package/lib/less/visitors/join-selector-visitor.js +0 -65
  110. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  111. package/lib/less/visitors/to-css-visitor.js +0 -332
  112. package/lib/less/visitors/visitor.js +0 -165
  113. package/lib/less-browser/add-default-options.js +0 -53
  114. package/lib/less-browser/bootstrap.js +0 -67
  115. package/lib/less-browser/browser.js +0 -65
  116. package/lib/less-browser/cache.js +0 -43
  117. package/lib/less-browser/error-reporting.js +0 -170
  118. package/lib/less-browser/file-manager.js +0 -112
  119. package/lib/less-browser/image-size.js +0 -28
  120. package/lib/less-browser/index.js +0 -284
  121. package/lib/less-browser/log-listener.js +0 -42
  122. package/lib/less-browser/plugin-loader.js +0 -24
  123. package/lib/less-browser/utils.js +0 -30
  124. package/lib/less-node/environment.js +0 -43
  125. package/lib/less-node/file-manager.js +0 -156
  126. package/lib/less-node/fs.js +0 -14
  127. package/lib/less-node/image-size.js +0 -78
  128. package/lib/less-node/index.js +0 -31
  129. package/lib/less-node/lessc-helper.js +0 -95
  130. package/lib/less-node/plugin-loader.js +0 -62
  131. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,185 +0,0 @@
1
- import functionRegistry from '../functions/function-registry.js';
2
- import LessError from '../less-error.js';
3
-
4
- class AbstractPluginLoader {
5
- constructor() {
6
- // Implemented by Node.js plugin loader
7
- this.require = function() {
8
- return null;
9
- }
10
- }
11
-
12
- evalPlugin(contents, context, imports, pluginOptions, fileInfo) {
13
-
14
- let loader, registry, pluginObj, localModule, pluginManager, filename, result;
15
-
16
- pluginManager = context.pluginManager;
17
-
18
- if (fileInfo) {
19
- if (typeof fileInfo === 'string') {
20
- filename = fileInfo;
21
- }
22
- else {
23
- filename = fileInfo.filename;
24
- }
25
- }
26
- const shortname = (new this.less.FileManager()).extractUrlParts(filename).filename;
27
-
28
- if (filename) {
29
- pluginObj = pluginManager.get(filename);
30
-
31
- if (pluginObj) {
32
- result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
33
- if (result) {
34
- return result;
35
- }
36
- try {
37
- if (pluginObj.use) {
38
- pluginObj.use.call(this.context, pluginObj);
39
- }
40
- }
41
- catch (e) {
42
- e.message = e.message || 'Error during @plugin call';
43
- return new LessError(e, imports, filename);
44
- }
45
- return pluginObj;
46
- }
47
- }
48
- localModule = {
49
- exports: {},
50
- pluginManager,
51
- fileInfo
52
- };
53
- registry = functionRegistry.create();
54
-
55
- const registerPlugin = function(obj) {
56
- pluginObj = obj;
57
- };
58
-
59
- try {
60
- loader = new Function('module', 'require', 'registerPlugin', 'functions', 'tree', 'less', 'fileInfo', contents);
61
- loader(localModule, this.require(filename), registerPlugin, registry, this.less.tree, this.less, fileInfo);
62
- }
63
- catch (e) {
64
- return new LessError(e, imports, filename);
65
- }
66
-
67
- if (!pluginObj) {
68
- pluginObj = localModule.exports;
69
- }
70
- pluginObj = this.validatePlugin(pluginObj, filename, shortname);
71
-
72
- if (pluginObj instanceof LessError) {
73
- return pluginObj;
74
- }
75
-
76
- if (pluginObj) {
77
- pluginObj.imports = imports;
78
- pluginObj.filename = filename;
79
-
80
- // For < 3.x (or unspecified minVersion) - setOptions() before install()
81
- if (!pluginObj.minVersion || this.compareVersion('3.0.0', pluginObj.minVersion) < 0) {
82
- result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
83
-
84
- if (result) {
85
- return result;
86
- }
87
- }
88
-
89
- // Run on first load
90
- pluginManager.addPlugin(pluginObj, fileInfo.filename, registry);
91
- pluginObj.functions = registry.getLocalFunctions();
92
-
93
- // Need to call setOptions again because the pluginObj might have functions
94
- result = this.trySetOptions(pluginObj, filename, shortname, pluginOptions);
95
- if (result) {
96
- return result;
97
- }
98
-
99
- // Run every @plugin call
100
- try {
101
- if (pluginObj.use) {
102
- pluginObj.use.call(this.context, pluginObj);
103
- }
104
- }
105
- catch (e) {
106
- e.message = e.message || 'Error during @plugin call';
107
- return new LessError(e, imports, filename);
108
- }
109
-
110
- }
111
- else {
112
- return new LessError({ message: 'Not a valid plugin' }, imports, filename);
113
- }
114
-
115
- return pluginObj;
116
-
117
- }
118
-
119
- trySetOptions(plugin, filename, name, options) {
120
- if (options && !plugin.setOptions) {
121
- return new LessError({
122
- message: `Options have been provided but the plugin ${name} does not support any options.`
123
- });
124
- }
125
- try {
126
- plugin.setOptions && plugin.setOptions(options);
127
- }
128
- catch (e) {
129
- return new LessError(e);
130
- }
131
- }
132
-
133
- validatePlugin(plugin, filename, name) {
134
- if (plugin) {
135
- // support plugins being a function
136
- // so that the plugin can be more usable programmatically
137
- if (typeof plugin === 'function') {
138
- plugin = new plugin();
139
- }
140
-
141
- if (plugin.minVersion) {
142
- if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
143
- return new LessError({
144
- message: `Plugin ${name} requires version ${this.versionToString(plugin.minVersion)}`
145
- });
146
- }
147
- }
148
- return plugin;
149
- }
150
- return null;
151
- }
152
-
153
- compareVersion(aVersion, bVersion) {
154
- if (typeof aVersion === 'string') {
155
- aVersion = aVersion.match(/^(\d+)\.?(\d+)?\.?(\d+)?/);
156
- aVersion.shift();
157
- }
158
- for (let i = 0; i < aVersion.length; i++) {
159
- if (aVersion[i] !== bVersion[i]) {
160
- return parseInt(aVersion[i]) > parseInt(bVersion[i]) ? -1 : 1;
161
- }
162
- }
163
- return 0;
164
- }
165
-
166
- versionToString(version) {
167
- let versionString = '';
168
- for (let i = 0; i < version.length; i++) {
169
- versionString += (versionString ? '.' : '') + version[i];
170
- }
171
- return versionString;
172
- }
173
-
174
- printUsage(plugins) {
175
- for (let i = 0; i < plugins.length; i++) {
176
- const plugin = plugins[i];
177
- if (plugin.printUsage) {
178
- plugin.printUsage();
179
- }
180
- }
181
- }
182
- }
183
-
184
- export default AbstractPluginLoader;
185
-
@@ -1,21 +0,0 @@
1
- export interface Environment {
2
- /**
3
- * Converts a string to a base 64 string
4
- */
5
- encodeBase64(str: string): string
6
- /**
7
- * Lookup the mime-type of a filename
8
- */
9
- mimeLookup(filename: string): string
10
- /**
11
- * Look up the charset of a mime type
12
- * @param mime
13
- */
14
- charsetLookup(mime: string): string
15
- /**
16
- * Gets a source map generator
17
- *
18
- * @todo - Figure out precise type
19
- */
20
- getSourceMapGenerator(): any
21
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * @todo Document why this abstraction exists, and the relationship between
3
- * environment, file managers, and plugin manager
4
- */
5
-
6
- import logger from '../logger.js';
7
-
8
- class Environment {
9
- constructor(externalEnvironment, fileManagers) {
10
- this.fileManagers = fileManagers || [];
11
- externalEnvironment = externalEnvironment || {};
12
-
13
- const optionalFunctions = ['encodeBase64', 'mimeLookup', 'charsetLookup', 'getSourceMapGenerator'];
14
- const requiredFunctions = [];
15
- const functions = requiredFunctions.concat(optionalFunctions);
16
-
17
- for (let i = 0; i < functions.length; i++) {
18
- const propName = functions[i];
19
- const environmentFunc = externalEnvironment[propName];
20
- if (environmentFunc) {
21
- this[propName] = environmentFunc.bind(externalEnvironment);
22
- } else if (i < requiredFunctions.length) {
23
- this.warn(`missing required function in environment - ${propName}`);
24
- }
25
- }
26
- }
27
-
28
- getFileManager(filename, currentDirectory, options, environment, isSync) {
29
-
30
- if (!filename) {
31
- logger.warn('getFileManager called with no filename.. Please report this issue. continuing.');
32
- }
33
- if (currentDirectory === undefined) {
34
- logger.warn('getFileManager called with null directory.. Please report this issue. continuing.');
35
- }
36
-
37
- let fileManagers = this.fileManagers;
38
- if (options.pluginManager) {
39
- fileManagers = [].concat(fileManagers).concat(options.pluginManager.getFileManagers());
40
- }
41
- for (let i = fileManagers.length - 1; i >= 0 ; i--) {
42
- const fileManager = fileManagers[i];
43
- if (fileManager[isSync ? 'supportsSync' : 'supports'](filename, currentDirectory, options, environment)) {
44
- return fileManager;
45
- }
46
- }
47
- return null;
48
- }
49
-
50
- addFileManager(fileManager) {
51
- this.fileManagers.push(fileManager);
52
- }
53
-
54
- clearFileManagers() {
55
- this.fileManagers = [];
56
- }
57
- }
58
-
59
- export default Environment;
@@ -1,77 +0,0 @@
1
- import type { Environment } from './environment-api'
2
-
3
- export interface FileManager {
4
- /**
5
- * Given the full path to a file, return the path component
6
- * Provided by AbstractFileManager
7
- */
8
- getPath(filename: string): string
9
- /**
10
- * Append a .less extension if appropriate. Only called if less thinks one could be added.
11
- * Provided by AbstractFileManager
12
- */
13
- tryAppendLessExtension(filename: string): string
14
- /**
15
- * Whether the rootpath should be converted to be absolute.
16
- * The browser ovverides this to return true because urls must be absolute.
17
- * Provided by AbstractFileManager (returns false)
18
- */
19
- alwaysMakePathsAbsolute(): boolean
20
- /**
21
- * Returns whether a path is absolute
22
- * Provided by AbstractFileManager
23
- */
24
- isPathAbsolute(path: string): boolean
25
- /**
26
- * joins together 2 paths
27
- * Provided by AbstractFileManager
28
- */
29
- join(basePath: string, laterPath: string): string
30
- /**
31
- * Returns the difference between 2 paths
32
- * E.g. url = a/ baseUrl = a/b/ returns ../
33
- * url = a/b/ baseUrl = a/ returns b/
34
- * Provided by AbstractFileManager
35
- */
36
- pathDiff(url: string, baseUrl: string): string
37
- /**
38
- * Returns whether this file manager supports this file for syncronous file retrieval
39
- * If true is returned, loadFileSync will then be called with the file.
40
- * Provided by AbstractFileManager (returns false)
41
- *
42
- * @todo - Narrow Options type
43
- */
44
- supportsSync(
45
- filename: string,
46
- currentDirectory: string,
47
- options: Record<string, any>,
48
- environment: Environment
49
- ): boolean
50
- /**
51
- * If file manager supports async file retrieval for this file type
52
- */
53
- supports(
54
- filename: string,
55
- currentDirectory: string,
56
- options: Record<string, any>,
57
- environment: Environment
58
- ): boolean
59
- /**
60
- * Loads a file asynchronously.
61
- */
62
- loadFile(
63
- filename: string,
64
- currentDirectory: string,
65
- options: Record<string, any>,
66
- environment: Environment
67
- ): Promise<{ filename: string, contents: string }>
68
- /**
69
- * Loads a file synchronously. Expects an immediate return with an object
70
- */
71
- loadFileSync(
72
- filename: string,
73
- currentDirectory: string,
74
- options: Record<string, any>,
75
- environment: Environment
76
- ): { error?: unknown, filename: string, contents: string }
77
- }
@@ -1,29 +0,0 @@
1
- import Anonymous from '../tree/anonymous.js';
2
- import Keyword from '../tree/keyword.js';
3
-
4
- function boolean(condition) {
5
- return condition ? Keyword.True : Keyword.False;
6
- }
7
-
8
- /**
9
- * Functions with evalArgs set to false are sent context
10
- * as the first argument.
11
- */
12
- function If(context, condition, trueValue, falseValue) {
13
- return condition.eval(context) ? trueValue.eval(context)
14
- : (falseValue ? falseValue.eval(context) : new Anonymous);
15
- }
16
- If.evalArgs = false;
17
-
18
- function isdefined(context, variable) {
19
- try {
20
- variable.eval(context);
21
- return Keyword.True;
22
- } catch (e) {
23
- return Keyword.False;
24
- }
25
- }
26
-
27
- isdefined.evalArgs = false;
28
-
29
- export default { isdefined, boolean, 'if': If };
@@ -1,85 +0,0 @@
1
- import Color from '../tree/color.js';
2
-
3
- // Color Blending
4
- // ref: http://www.w3.org/TR/compositing-1
5
-
6
- function colorBlend(mode, color1, color2) {
7
- const ab = color1.alpha; // result
8
-
9
- let // backdrop
10
- cb;
11
-
12
- const as = color2.alpha;
13
-
14
- let // source
15
- cs;
16
-
17
- let ar;
18
- let cr;
19
- const r = [];
20
-
21
- ar = as + ab * (1 - as);
22
- for (let i = 0; i < 3; i++) {
23
- cb = color1.rgb[i] / 255;
24
- cs = color2.rgb[i] / 255;
25
- cr = mode(cb, cs);
26
- if (ar) {
27
- cr = (as * cs + ab * (cb -
28
- as * (cb + cs - cr))) / ar;
29
- }
30
- r[i] = cr * 255;
31
- }
32
-
33
- return new Color(r, ar);
34
- }
35
-
36
- const colorBlendModeFunctions = {
37
- multiply: function(cb, cs) {
38
- return cb * cs;
39
- },
40
- screen: function(cb, cs) {
41
- return cb + cs - cb * cs;
42
- },
43
- overlay: function(cb, cs) {
44
- cb *= 2;
45
- return (cb <= 1) ?
46
- colorBlendModeFunctions.multiply(cb, cs) :
47
- colorBlendModeFunctions.screen(cb - 1, cs);
48
- },
49
- softlight: function(cb, cs) {
50
- let d = 1;
51
- let e = cb;
52
- if (cs > 0.5) {
53
- e = 1;
54
- d = (cb > 0.25) ? Math.sqrt(cb)
55
- : ((16 * cb - 12) * cb + 4) * cb;
56
- }
57
- return cb - (1 - 2 * cs) * e * (d - cb);
58
- },
59
- hardlight: function(cb, cs) {
60
- return colorBlendModeFunctions.overlay(cs, cb);
61
- },
62
- difference: function(cb, cs) {
63
- return Math.abs(cb - cs);
64
- },
65
- exclusion: function(cb, cs) {
66
- return cb + cs - 2 * cb * cs;
67
- },
68
-
69
- // non-w3c functions:
70
- average: function(cb, cs) {
71
- return (cb + cs) / 2;
72
- },
73
- negation: function(cb, cs) {
74
- return 1 - Math.abs(cb + cs - 1);
75
- }
76
- };
77
-
78
- for (const f in colorBlendModeFunctions) {
79
- // eslint-disable-next-line no-prototype-builtins
80
- if (colorBlendModeFunctions.hasOwnProperty(f)) {
81
- colorBlend[f] = colorBlend.bind(null, colorBlendModeFunctions[f]);
82
- }
83
- }
84
-
85
- export default colorBlend;