less 4.8.1 → 5.0.0-alpha.1

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 (129) hide show
  1. package/README.md +19 -5
  2. package/bin/lessc +190 -630
  3. package/dist/less-node.cjs +398 -14282
  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 +33 -40
  13. package/dist/less.cjs +0 -14929
  14. package/dist/less.js +0 -14929
  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 -36
  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/parser-input.js +0 -400
  52. package/lib/less/parser/parser.js +0 -2894
  53. package/lib/less/plugin-manager.js +0 -168
  54. package/lib/less/render.js +0 -41
  55. package/lib/less/source-map-builder.js +0 -82
  56. package/lib/less/source-map-output.js +0 -151
  57. package/lib/less/transform-tree.js +0 -102
  58. package/lib/less/tree/anonymous.js +0 -57
  59. package/lib/less/tree/assignment.js +0 -48
  60. package/lib/less/tree/atrule-syntax.js +0 -8
  61. package/lib/less/tree/atrule.js +0 -340
  62. package/lib/less/tree/attribute.js +0 -63
  63. package/lib/less/tree/call.js +0 -132
  64. package/lib/less/tree/color.js +0 -285
  65. package/lib/less/tree/combinator.js +0 -38
  66. package/lib/less/tree/comment.js +0 -48
  67. package/lib/less/tree/condition.js +0 -65
  68. package/lib/less/tree/container.js +0 -104
  69. package/lib/less/tree/debug-info.js +0 -80
  70. package/lib/less/tree/declaration.js +0 -139
  71. package/lib/less/tree/detached-ruleset.js +0 -45
  72. package/lib/less/tree/dimension.js +0 -215
  73. package/lib/less/tree/element.js +0 -93
  74. package/lib/less/tree/expression.js +0 -100
  75. package/lib/less/tree/extend.js +0 -88
  76. package/lib/less/tree/import.js +0 -299
  77. package/lib/less/tree/index.js +0 -56
  78. package/lib/less/tree/javascript.js +0 -45
  79. package/lib/less/tree/js-eval-node.js +0 -74
  80. package/lib/less/tree/keyword.js +0 -28
  81. package/lib/less/tree/media.js +0 -90
  82. package/lib/less/tree/merge-rules.js +0 -47
  83. package/lib/less/tree/mixin-call.js +0 -283
  84. package/lib/less/tree/mixin-definition.js +0 -319
  85. package/lib/less/tree/namespace-value.js +0 -95
  86. package/lib/less/tree/negative.js +0 -37
  87. package/lib/less/tree/nested-at-rule.js +0 -198
  88. package/lib/less/tree/node.js +0 -310
  89. package/lib/less/tree/operation.js +0 -81
  90. package/lib/less/tree/paren.js +0 -41
  91. package/lib/less/tree/property.js +0 -96
  92. package/lib/less/tree/query-in-parens.js +0 -64
  93. package/lib/less/tree/quoted.js +0 -114
  94. package/lib/less/tree/ruleset.js +0 -1066
  95. package/lib/less/tree/selector.js +0 -201
  96. package/lib/less/tree/unicode-descriptor.js +0 -14
  97. package/lib/less/tree/unit.js +0 -170
  98. package/lib/less/tree/url.js +0 -83
  99. package/lib/less/tree/value.js +0 -60
  100. package/lib/less/tree/variable-call.js +0 -60
  101. package/lib/less/tree/variable.js +0 -85
  102. package/lib/less/utils.js +0 -126
  103. package/lib/less/visitors/extend-visitor.js +0 -505
  104. package/lib/less/visitors/import-sequencer.js +0 -56
  105. package/lib/less/visitors/import-visitor.js +0 -203
  106. package/lib/less/visitors/index.js +0 -15
  107. package/lib/less/visitors/join-selector-visitor.js +0 -65
  108. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  109. package/lib/less/visitors/to-css-visitor.js +0 -332
  110. package/lib/less/visitors/visitor.js +0 -165
  111. package/lib/less-browser/add-default-options.js +0 -53
  112. package/lib/less-browser/bootstrap.js +0 -67
  113. package/lib/less-browser/browser.js +0 -65
  114. package/lib/less-browser/cache.js +0 -43
  115. package/lib/less-browser/error-reporting.js +0 -170
  116. package/lib/less-browser/file-manager.js +0 -112
  117. package/lib/less-browser/image-size.js +0 -28
  118. package/lib/less-browser/index.js +0 -284
  119. package/lib/less-browser/log-listener.js +0 -42
  120. package/lib/less-browser/plugin-loader.js +0 -24
  121. package/lib/less-browser/utils.js +0 -30
  122. package/lib/less-node/environment.js +0 -43
  123. package/lib/less-node/file-manager.js +0 -156
  124. package/lib/less-node/fs.js +0 -14
  125. package/lib/less-node/image-size.js +0 -78
  126. package/lib/less-node/index.js +0 -31
  127. package/lib/less-node/lessc-helper.js +0 -95
  128. package/lib/less-node/plugin-loader.js +0 -62
  129. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,78 +0,0 @@
1
- import { readFileSync } from 'fs';
2
- import { createRequire } from 'module';
3
- import Dimension from '../less/tree/dimension.js';
4
- import Expression from '../less/tree/expression.js';
5
- import functionRegistry from './../less/functions/function-registry.js';
6
-
7
- const require = createRequire(import.meta.url);
8
-
9
- export default environment => {
10
-
11
- function imageSize(functionContext, filePathNode) {
12
- let filePath = filePathNode.value;
13
- const currentFileInfo = functionContext.currentFileInfo;
14
- const currentDirectory = currentFileInfo.rewriteUrls ?
15
- currentFileInfo.currentDirectory : currentFileInfo.entryPath;
16
-
17
- const fragmentStart = filePath.indexOf('#');
18
- if (fragmentStart !== -1) {
19
- filePath = filePath.slice(0, fragmentStart);
20
- }
21
-
22
- const fileManager = environment.getFileManager(filePath, currentDirectory, functionContext.context, environment, true);
23
-
24
- if (!fileManager) {
25
- throw {
26
- type: 'File',
27
- message: `Can not set up FileManager for ${filePathNode}`
28
- };
29
- }
30
-
31
- const fileSync = fileManager.loadFileSync(filePath, currentDirectory, functionContext.context, environment);
32
-
33
- if (fileSync.error) {
34
- throw fileSync.error;
35
- }
36
-
37
- let probe;
38
- try {
39
- probe = require('probe-image-size/sync');
40
- } catch (_) {
41
- return { width: 0, height: 0 };
42
- }
43
-
44
- const size = probe(readFileSync(fileSync.filename));
45
-
46
- if (!size) {
47
- throw {
48
- type: 'File',
49
- message: `Unrecognised image format for '${filePath}'`
50
- };
51
- }
52
-
53
- return {
54
- width: size.width,
55
- height: size.height
56
- };
57
- }
58
-
59
- const imageFunctions = {
60
- 'image-size': function (filePathNode) {
61
- const size = imageSize(this, filePathNode);
62
- return new Expression([
63
- new Dimension(size.width, 'px'),
64
- new Dimension(size.height, 'px')
65
- ]);
66
- },
67
- 'image-width': function (filePathNode) {
68
- const size = imageSize(this, filePathNode);
69
- return new Dimension(size.width, 'px');
70
- },
71
- 'image-height': function (filePathNode) {
72
- const size = imageSize(this, filePathNode);
73
- return new Dimension(size.height, 'px');
74
- }
75
- };
76
-
77
- functionRegistry.addMultiple(imageFunctions);
78
- };
@@ -1,31 +0,0 @@
1
- import { createRequire } from 'module';
2
- import environment from './environment.js';
3
- import FileManager from './file-manager.js';
4
- import UrlFileManager from './url-file-manager.js';
5
- import createFromEnvironment from '../less/index.js';
6
- import lesscHelper from './lessc-helper.js';
7
- import PluginLoader from './plugin-loader.js';
8
- import fs from './fs.js';
9
- import defaultOptions from '../less/default-options.js';
10
- import imageSize from './image-size.js';
11
-
12
- const require = createRequire(import.meta.url);
13
- const { version } = require('../../package.json');
14
-
15
- const less = createFromEnvironment(environment, [new FileManager(), new UrlFileManager()], version);
16
-
17
- // allow people to create less with their own environment
18
- less.createFromEnvironment = createFromEnvironment;
19
- less.lesscHelper = lesscHelper;
20
- less.PluginLoader = PluginLoader;
21
- less.fs = fs;
22
- less.FileManager = FileManager;
23
- less.UrlFileManager = UrlFileManager;
24
-
25
- // Set up options
26
- less.options = defaultOptions();
27
-
28
- // provide image-size functionality
29
- imageSize(less.environment);
30
-
31
- export default less;
@@ -1,95 +0,0 @@
1
- // lessc_helper.js
2
- //
3
- // helper functions for lessc
4
- const lessc_helper = {
5
-
6
- // Stylize a string
7
- stylize : function(str, style) {
8
- const styles = {
9
- 'reset' : [0, 0],
10
- 'bold' : [1, 22],
11
- 'inverse' : [7, 27],
12
- 'underline' : [4, 24],
13
- 'yellow' : [33, 39],
14
- 'green' : [32, 39],
15
- 'red' : [31, 39],
16
- 'grey' : [90, 39]
17
- };
18
- return `\x1b[${styles[style][0]}m${str}\x1b[${styles[style][1]}m`;
19
- },
20
-
21
- // Print command line options
22
- printUsage: function() {
23
- console.log('usage: lessc [option option=parameter ...] <source> [destination]');
24
- console.log('');
25
- console.log('If source is set to `-\' (dash or hyphen-minus), input is read from stdin.');
26
- console.log('');
27
- console.log('options:');
28
- console.log(' -h, --help Prints help (this message) and exit.');
29
- console.log(' --include-path=PATHS Sets include paths. Separated by `:\'. `;\' also supported on windows.');
30
- console.log(' -M, --depends Outputs a makefile import dependency list to stdout.');
31
- console.log(' --no-color Disables colorized output.');
32
- console.log(' --ie-compat Enables IE8 compatibility checks.');
33
- console.log(' --js Enables inline JavaScript in less files');
34
- console.log(' -l, --lint Syntax check only (lint).');
35
- console.log(' -s, --silent Suppresses output of error messages.');
36
- console.log(' --quiet Suppresses output of warnings.');
37
- console.log(' --strict-imports (DEPRECATED) Ignores .less imports inside selector blocks. Has confusing behavior.');
38
- console.log(' --insecure Allows imports from insecure https hosts.');
39
- console.log(' -v, --version Prints version number and exit.');
40
- console.log(' --verbose Be verbose.');
41
- console.log(' --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map).');
42
- console.log(' --source-map-rootpath=X Adds this path onto the sourcemap filename and less file paths.');
43
- console.log(' --source-map-basepath=X Sets sourcemap base path, defaults to current working directory.');
44
- console.log(' --source-map-include-source Puts the less files into the map instead of referencing them.');
45
- console.log(' --source-map-inline Puts the map (and any less files) as a base64 data uri into the output css file.');
46
- console.log(' --source-map-url=URL Sets a custom URL to map file, for sourceMappingURL comment');
47
- console.log(' in generated CSS file.');
48
- console.log(' --source-map-no-annotation Excludes the sourceMappingURL comment from the output css file.');
49
- console.log(' -rp, --rootpath=URL Sets rootpath for url rewriting in relative imports and urls');
50
- console.log(' Works with or without the relative-urls option.');
51
- console.log(' -ru=, --rewrite-urls= Rewrites URLs to make them relative to the base less file.');
52
- console.log(' all|local|off \'all\' rewrites all URLs, \'local\' just those starting with a \'.\'');
53
- console.log('');
54
- console.log(' -m=, --math=');
55
- console.log(' always Less will eagerly perform math operations always.');
56
- console.log(' parens-division Math performed except for division (/) operator');
57
- console.log(' parens | strict Math only performed inside parentheses');
58
- console.log(' strict-legacy Parens required in very strict terms (legacy --strict-math)');
59
- console.log('');
60
- console.log(' -su=on|off Allows mixed units, e.g. 1px+1em or 1px*1px which have units');
61
- console.log(' --strict-units=on|off that cannot be represented.');
62
- console.log(' --global-var=\'VAR=VALUE\' Defines a variable that can be referenced by the file.');
63
- console.log(' --modify-var=\'VAR=VALUE\' Modifies a variable already declared in the file.');
64
- console.log(' --url-args=\'QUERYSTRING\' Adds params into url tokens (e.g. 42, cb=42 or \'a=1&b=2\')');
65
- console.log(' --plugin=PLUGIN=OPTIONS Loads a plugin. You can also omit the --plugin= if the plugin begins');
66
- console.log(' less-plugin. E.g. the clean css plugin is called less-plugin-clean-css');
67
- console.log(' once installed (npm install less-plugin-clean-css), use either with');
68
- console.log(' --plugin=less-plugin-clean-css or just --clean-css');
69
- console.log(' specify options afterwards e.g. --plugin=less-plugin-clean-css="advanced"');
70
- console.log(' or --clean-css="advanced"');
71
- console.log(' --disable-plugin-rule Disallow @plugin statements');
72
- console.log('');
73
- console.log(' --quiet-deprecations Suppress deprecation warnings only (keeps other warnings).');
74
- console.log('');
75
- console.log('-------------------------- Deprecated ----------------');
76
- console.log(' -sm=on|off Legacy parens-only math. Use --math');
77
- console.log(' --strict-math=on|off ');
78
- console.log('');
79
- console.log(' --line-numbers=TYPE (DEPRECATED) Outputs filename and line numbers.');
80
- console.log(' TYPE can be either \'comments\', \'mediaquery\', or \'all\'.');
81
- console.log(' The entire dumpLineNumbers option is deprecated.');
82
- console.log(' Use sourcemaps (--source-map) instead.');
83
- console.log(' All modes will be removed in a future version.');
84
- console.log(' Note: \'mediaquery\' and \'all\' modes generate @media -sass-debug-info');
85
- console.log(' which had short-lived usage and is no longer recommended.');
86
- console.log(' -x, --compress Compresses output by removing some whitespaces.');
87
- console.log(' We recommend you use a dedicated minifer like less-plugin-clean-css');
88
- console.log('');
89
- console.log('Report bugs to: http://github.com/less/less.js/issues');
90
- console.log('Home page: <http://lesscss.org/>');
91
- }
92
- };
93
-
94
- export const { stylize, printUsage } = lessc_helper;
95
- export default lessc_helper;
@@ -1,62 +0,0 @@
1
- import path from 'path';
2
- import { createRequire } from 'module';
3
- import AbstractPluginLoader from '../less/environment/abstract-plugin-loader.js';
4
-
5
- const require = createRequire(import.meta.url);
6
-
7
- /**
8
- * Node Plugin Loader
9
- */
10
- const PluginLoader = function(less) {
11
- this.less = less;
12
- this.require = prefix => {
13
- prefix = path.dirname(prefix);
14
- return id => {
15
- const str = id.slice(0, 2);
16
- if (str === '..' || str === './') {
17
- return require(path.join(prefix, id));
18
- }
19
- else {
20
- return require(id);
21
- }
22
- };
23
- };
24
- };
25
-
26
- PluginLoader.prototype = Object.assign(new AbstractPluginLoader(), {
27
- loadPlugin(filename, basePath, context, environment, fileManager) {
28
- const prefix = filename.slice(0, 1);
29
- const explicit = prefix === '.' || prefix === '/' || filename.slice(-3).toLowerCase() === '.js';
30
- if (!explicit) {
31
- context.prefixes = ['less-plugin-', ''];
32
- }
33
-
34
- if (context.syncImport) {
35
- return fileManager.loadFileSync(filename, basePath, context, environment);
36
- }
37
-
38
- return new Promise((fulfill, reject) => {
39
- fileManager.loadFile(filename, basePath, context, environment).then(
40
- data => {
41
- try {
42
- fulfill(data);
43
- }
44
- catch (e) {
45
- console.log(e);
46
- reject(e);
47
- }
48
- }
49
- ).catch(err => {
50
- reject(err);
51
- });
52
- });
53
- },
54
-
55
- loadPluginSync(filename, basePath, context, environment, fileManager) {
56
- context.syncImport = true;
57
- return this.loadPlugin(filename, basePath, context, environment, fileManager);
58
- }
59
- });
60
-
61
- export default PluginLoader;
62
-
@@ -1,60 +0,0 @@
1
- /* eslint-disable no-unused-vars */
2
- /**
3
- * @todo - remove top eslint rule when FileManagers have JSDoc type
4
- * and are TS-type-checked
5
- */
6
- import { createRequire } from 'module';
7
-
8
- const require = createRequire(import.meta.url);
9
-
10
- const isUrlRe = /^(?:https?:)?\/\//i;
11
- import url from 'url';
12
- let request;
13
- import AbstractFileManager from '../less/environment/abstract-file-manager.js';
14
- import logger from '../less/logger.js';
15
-
16
- const UrlFileManager = function() {}
17
- UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
18
- supports(filename, currentDirectory, options, environment) {
19
- return isUrlRe.test( filename ) || isUrlRe.test(currentDirectory);
20
- },
21
-
22
- loadFile(filename, currentDirectory, options, environment) {
23
- return new Promise((fulfill, reject) => {
24
- if (request === undefined) {
25
- try { request = require('needle'); }
26
- catch (e) { request = null; }
27
- }
28
- if (!request) {
29
- reject({ type: 'File', message: 'optional dependency \'needle\' required to import over http(s)\n' });
30
- return;
31
- }
32
-
33
- let urlStr = isUrlRe.test( filename ) ? filename : url.resolve(currentDirectory, filename);
34
-
35
- /** native-request currently has a bug */
36
- const hackUrlStr = urlStr.indexOf('?') === -1 ? urlStr + '?' : urlStr
37
-
38
- request.get(hackUrlStr, { follow_max: 5 }, (err, resp, body) => {
39
- if (err || resp && resp.statusCode >= 400) {
40
- const message = resp && resp.statusCode === 404
41
- ? `resource '${urlStr}' was not found\n`
42
- : `resource '${urlStr}' gave this Error:\n ${err || resp.statusMessage || resp.statusCode}\n`;
43
- reject({ type: 'File', message });
44
- return;
45
- }
46
- if (resp.statusCode >= 300) {
47
- reject({ type: 'File', message: `resource '${urlStr}' caused too many redirects` });
48
- return;
49
- }
50
- body = body.toString('utf8');
51
- if (!body) {
52
- logger.warn(`Warning: Empty body (HTTP ${resp.statusCode}) returned by "${urlStr}"`);
53
- }
54
- fulfill({ contents: body || '', filename: urlStr });
55
- });
56
- });
57
- }
58
- });
59
-
60
- export default UrlFileManager;