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.
Files changed (124) hide show
  1. package/.DS_Store +0 -0
  2. package/bin/lessc +6652 -5505
  3. package/dist/less.cjs.js +6593 -5448
  4. package/dist/less.js +10 -6
  5. package/dist/less.min.js +2 -2
  6. package/dist/less.min.js.map +1 -1
  7. package/lib/less/constants.js +13 -0
  8. package/lib/less/contexts.js +164 -0
  9. package/lib/less/data/colors.js +150 -0
  10. package/lib/less/data/index.js +4 -0
  11. package/lib/less/data/unit-conversions.js +21 -0
  12. package/lib/less/default-options.js +68 -0
  13. package/lib/less/environment/abstract-file-manager.js +127 -0
  14. package/lib/less/environment/abstract-plugin-loader.js +187 -0
  15. package/lib/less/environment/environment-api.js +25 -0
  16. package/lib/less/environment/environment.js +59 -0
  17. package/lib/less/environment/file-manager-api.js +103 -0
  18. package/lib/less/functions/boolean.js +13 -0
  19. package/lib/less/functions/color-blending.js +84 -0
  20. package/lib/less/functions/color.js +417 -0
  21. package/lib/less/functions/data-uri.js +74 -0
  22. package/lib/less/functions/default.js +25 -0
  23. package/lib/less/functions/function-caller.js +49 -0
  24. package/lib/less/functions/function-registry.js +35 -0
  25. package/lib/less/functions/index.js +33 -0
  26. package/lib/less/functions/list.js +143 -0
  27. package/lib/less/functions/math-helper.js +15 -0
  28. package/lib/less/functions/math.js +28 -0
  29. package/lib/less/functions/number.js +89 -0
  30. package/lib/less/functions/string.js +36 -0
  31. package/lib/less/functions/svg.js +87 -0
  32. package/lib/less/functions/types.js +70 -0
  33. package/lib/less/import-manager.js +169 -0
  34. package/lib/less/index.js +92 -0
  35. package/lib/less/less-error.js +140 -0
  36. package/lib/less/logger.js +34 -0
  37. package/lib/less/parse-tree.js +66 -0
  38. package/lib/less/parse.js +89 -0
  39. package/lib/less/parser/chunker.js +122 -0
  40. package/lib/less/parser/parser-input.js +390 -0
  41. package/lib/less/parser/parser.js +2418 -0
  42. package/lib/less/plugin-manager.js +168 -0
  43. package/lib/less/render.js +42 -0
  44. package/lib/less/source-map-builder.js +77 -0
  45. package/lib/less/source-map-output.js +149 -0
  46. package/lib/less/transform-tree.js +96 -0
  47. package/lib/less/tree/anonymous.js +37 -0
  48. package/lib/less/tree/assignment.js +33 -0
  49. package/lib/less/tree/atrule.js +165 -0
  50. package/lib/less/tree/attribute.js +34 -0
  51. package/lib/less/tree/call.js +105 -0
  52. package/lib/less/tree/color.js +246 -0
  53. package/lib/less/tree/combinator.js +29 -0
  54. package/lib/less/tree/comment.js +29 -0
  55. package/lib/less/tree/condition.js +43 -0
  56. package/lib/less/tree/debug-info.js +34 -0
  57. package/lib/less/tree/declaration.js +115 -0
  58. package/lib/less/tree/detached-ruleset.js +30 -0
  59. package/lib/less/tree/dimension.js +179 -0
  60. package/lib/less/tree/element.js +73 -0
  61. package/lib/less/tree/expression.js +74 -0
  62. package/lib/less/tree/extend.js +66 -0
  63. package/lib/less/tree/import.js +184 -0
  64. package/lib/less/tree/index.js +54 -0
  65. package/lib/less/tree/javascript.js +33 -0
  66. package/lib/less/tree/js-eval-node.js +58 -0
  67. package/lib/less/tree/keyword.js +21 -0
  68. package/lib/less/tree/media.js +154 -0
  69. package/lib/less/tree/mixin-call.js +215 -0
  70. package/lib/less/tree/mixin-definition.js +229 -0
  71. package/lib/less/tree/namespace-value.js +87 -0
  72. package/lib/less/tree/negative.js +26 -0
  73. package/lib/less/tree/node.js +178 -0
  74. package/lib/less/tree/operation.js +62 -0
  75. package/lib/less/tree/paren.js +22 -0
  76. package/lib/less/tree/property.js +77 -0
  77. package/lib/less/tree/quoted.js +70 -0
  78. package/lib/less/tree/ruleset.js +867 -0
  79. package/lib/less/tree/selector.js +146 -0
  80. package/lib/less/tree/unicode-descriptor.js +13 -0
  81. package/lib/less/tree/unit.js +141 -0
  82. package/lib/less/tree/url.js +65 -0
  83. package/lib/less/tree/value.js +44 -0
  84. package/lib/less/tree/variable-call.js +46 -0
  85. package/lib/less/tree/variable.js +67 -0
  86. package/lib/less/utils.js +122 -0
  87. package/lib/less/visitors/extend-visitor.js +505 -0
  88. package/lib/less/visitors/import-sequencer.js +58 -0
  89. package/lib/less/visitors/import-visitor.js +189 -0
  90. package/lib/less/visitors/index.js +15 -0
  91. package/lib/less/visitors/join-selector-visitor.js +57 -0
  92. package/lib/less/visitors/set-tree-visibility-visitor.js +45 -0
  93. package/lib/less/visitors/to-css-visitor.js +363 -0
  94. package/lib/less/visitors/visitor.js +163 -0
  95. package/lib/less-browser/add-default-options.js +49 -0
  96. package/lib/less-browser/bootstrap.js +69 -0
  97. package/lib/less-browser/browser.js +65 -0
  98. package/lib/less-browser/cache.js +43 -0
  99. package/lib/less-browser/error-reporting.js +170 -0
  100. package/lib/less-browser/file-manager.js +113 -0
  101. package/lib/less-browser/image-size.js +28 -0
  102. package/lib/less-browser/index.js +285 -0
  103. package/lib/less-browser/log-listener.js +42 -0
  104. package/lib/less-browser/plugin-loader.js +26 -0
  105. package/lib/less-browser/utils.js +24 -0
  106. package/lib/less-node/environment.js +16 -0
  107. package/lib/less-node/file-manager.js +177 -0
  108. package/lib/less-node/fs.js +10 -0
  109. package/lib/less-node/image-size.js +58 -0
  110. package/lib/less-node/index.js +27 -0
  111. package/lib/less-node/lessc-helper.js +89 -0
  112. package/lib/less-node/plugin-loader.js +53 -0
  113. package/lib/less-node/url-file-manager.js +49 -0
  114. package/lib/lessc.js +557 -0
  115. package/lib/source-map/source-map-0.1.31.js +1933 -0
  116. package/lib/source-map/source-map-footer.js +4 -0
  117. package/lib/source-map/source-map-header.js +3 -0
  118. package/package.json +1 -1
  119. package/test/.DS_Store +0 -0
  120. package/test/browser/less.min.js +11 -0
  121. package/test/browser/less.min.js.map +1 -0
  122. package/test/css/css-escapes.css +1 -0
  123. package/test/less/css-escapes.less +3 -1
  124. package/.git/index +0 -0
@@ -0,0 +1,13 @@
1
+
2
+ export const Math = {
3
+ ALWAYS: 0,
4
+ PARENS_DIVISION: 1,
5
+ PARENS: 2,
6
+ STRICT_LEGACY: 3
7
+ };
8
+
9
+ export const RewriteUrls = {
10
+ OFF: 0,
11
+ LOCAL: 1,
12
+ ALL: 2
13
+ };
@@ -0,0 +1,164 @@
1
+ const contexts = {};
2
+ export default contexts;
3
+ import * as Constants from './constants';
4
+
5
+ const copyFromOriginal = function copyFromOriginal(original, destination, propertiesToCopy) {
6
+ if (!original) { return; }
7
+
8
+ for (let i = 0; i < propertiesToCopy.length; i++) {
9
+ if (original.hasOwnProperty(propertiesToCopy[i])) {
10
+ destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
11
+ }
12
+ }
13
+ };
14
+
15
+ /*
16
+ parse is used whilst parsing
17
+ */
18
+ const parseCopyProperties = [
19
+ // options
20
+ 'paths', // option - unmodified - paths to search for imports on
21
+ 'rewriteUrls', // option - whether to adjust URL's to be relative
22
+ 'rootpath', // option - rootpath to append to URL's
23
+ 'strictImports', // option -
24
+ 'insecure', // option - whether to allow imports from insecure ssl hosts
25
+ 'dumpLineNumbers', // option - whether to dump line numbers
26
+ 'compress', // option - whether to compress
27
+ 'syncImport', // option - whether to import synchronously
28
+ 'chunkInput', // option - whether to chunk input. more performant but causes parse issues.
29
+ 'mime', // browser only - mime type for sheet import
30
+ 'useFileCache', // browser only - whether to use the per file session cache
31
+ // context
32
+ 'processImports', // option & context - whether to process imports. if false then imports will not be imported.
33
+ // Used by the import manager to stop multiple import visitors being created.
34
+ 'pluginManager' // Used as the plugin manager for the session
35
+ ];
36
+
37
+ contexts.Parse = function(options) {
38
+ copyFromOriginal(options, this, parseCopyProperties);
39
+
40
+ if (typeof this.paths === 'string') { this.paths = [this.paths]; }
41
+ };
42
+
43
+ const evalCopyProperties = [
44
+ 'paths', // additional include paths
45
+ 'compress', // whether to compress
46
+ 'math', // whether math has to be within parenthesis
47
+ 'strictUnits', // whether units need to evaluate correctly
48
+ 'sourceMap', // whether to output a source map
49
+ 'importMultiple', // whether we are currently importing multiple copies
50
+ 'urlArgs', // whether to add args into url tokens
51
+ 'javascriptEnabled', // option - whether Inline JavaScript is enabled. if undefined, defaults to false
52
+ 'pluginManager', // Used as the plugin manager for the session
53
+ 'importantScope', // used to bubble up !important statements
54
+ 'rewriteUrls' // option - whether to adjust URL's to be relative
55
+ ];
56
+
57
+ function isPathRelative(path) {
58
+ return !/^(?:[a-z-]+:|\/|#)/i.test(path);
59
+ }
60
+
61
+ function isPathLocalRelative(path) {
62
+ return path.charAt(0) === '.';
63
+ }
64
+
65
+ contexts.Eval = class {
66
+ constructor(options, frames) {
67
+ copyFromOriginal(options, this, evalCopyProperties);
68
+
69
+ if (typeof this.paths === 'string') { this.paths = [this.paths]; }
70
+
71
+ this.frames = frames || [];
72
+ this.importantScope = this.importantScope || [];
73
+ this.inCalc = false;
74
+ this.mathOn = true;
75
+ }
76
+
77
+ enterCalc() {
78
+ if (!this.calcStack) {
79
+ this.calcStack = [];
80
+ }
81
+ this.calcStack.push(true);
82
+ this.inCalc = true;
83
+ }
84
+
85
+ exitCalc() {
86
+ this.calcStack.pop();
87
+ if (!this.calcStack) {
88
+ this.inCalc = false;
89
+ }
90
+ }
91
+
92
+ inParenthesis() {
93
+ if (!this.parensStack) {
94
+ this.parensStack = [];
95
+ }
96
+ this.parensStack.push(true);
97
+ };
98
+
99
+ outOfParenthesis() {
100
+ this.parensStack.pop();
101
+ };
102
+
103
+ isMathOn(op) {
104
+ if (!this.mathOn) {
105
+ return false;
106
+ }
107
+ if (op === '/' && this.math !== Constants.Math.ALWAYS && (!this.parensStack || !this.parensStack.length)) {
108
+ return false;
109
+ }
110
+ if (this.math > Constants.Math.PARENS_DIVISION) {
111
+ return this.parensStack && this.parensStack.length;
112
+ }
113
+ return true;
114
+ }
115
+
116
+ pathRequiresRewrite(path) {
117
+ const isRelative = this.rewriteUrls === Constants.RewriteUrls.LOCAL ? isPathLocalRelative : isPathRelative;
118
+
119
+ return isRelative(path);
120
+ }
121
+
122
+ rewritePath(path, rootpath) {
123
+ let newPath;
124
+
125
+ rootpath = rootpath || '';
126
+ newPath = this.normalizePath(rootpath + path);
127
+
128
+ // If a path was explicit relative and the rootpath was not an absolute path
129
+ // we must ensure that the new path is also explicit relative.
130
+ if (isPathLocalRelative(path) &&
131
+ isPathRelative(rootpath) &&
132
+ isPathLocalRelative(newPath) === false) {
133
+ newPath = `./${newPath}`;
134
+ }
135
+
136
+ return newPath;
137
+ }
138
+
139
+ normalizePath(path) {
140
+ const segments = path.split('/').reverse();
141
+ let segment;
142
+
143
+ path = [];
144
+ while (segments.length !== 0) {
145
+ segment = segments.pop();
146
+ switch ( segment ) {
147
+ case '.':
148
+ break;
149
+ case '..':
150
+ if ((path.length === 0) || (path[path.length - 1] === '..')) {
151
+ path.push( segment );
152
+ } else {
153
+ path.pop();
154
+ }
155
+ break;
156
+ default:
157
+ path.push(segment);
158
+ break;
159
+ }
160
+ }
161
+
162
+ return path.join('/');
163
+ }
164
+ }
@@ -0,0 +1,150 @@
1
+ export default {
2
+ 'aliceblue':'#f0f8ff',
3
+ 'antiquewhite':'#faebd7',
4
+ 'aqua':'#00ffff',
5
+ 'aquamarine':'#7fffd4',
6
+ 'azure':'#f0ffff',
7
+ 'beige':'#f5f5dc',
8
+ 'bisque':'#ffe4c4',
9
+ 'black':'#000000',
10
+ 'blanchedalmond':'#ffebcd',
11
+ 'blue':'#0000ff',
12
+ 'blueviolet':'#8a2be2',
13
+ 'brown':'#a52a2a',
14
+ 'burlywood':'#deb887',
15
+ 'cadetblue':'#5f9ea0',
16
+ 'chartreuse':'#7fff00',
17
+ 'chocolate':'#d2691e',
18
+ 'coral':'#ff7f50',
19
+ 'cornflowerblue':'#6495ed',
20
+ 'cornsilk':'#fff8dc',
21
+ 'crimson':'#dc143c',
22
+ 'cyan':'#00ffff',
23
+ 'darkblue':'#00008b',
24
+ 'darkcyan':'#008b8b',
25
+ 'darkgoldenrod':'#b8860b',
26
+ 'darkgray':'#a9a9a9',
27
+ 'darkgrey':'#a9a9a9',
28
+ 'darkgreen':'#006400',
29
+ 'darkkhaki':'#bdb76b',
30
+ 'darkmagenta':'#8b008b',
31
+ 'darkolivegreen':'#556b2f',
32
+ 'darkorange':'#ff8c00',
33
+ 'darkorchid':'#9932cc',
34
+ 'darkred':'#8b0000',
35
+ 'darksalmon':'#e9967a',
36
+ 'darkseagreen':'#8fbc8f',
37
+ 'darkslateblue':'#483d8b',
38
+ 'darkslategray':'#2f4f4f',
39
+ 'darkslategrey':'#2f4f4f',
40
+ 'darkturquoise':'#00ced1',
41
+ 'darkviolet':'#9400d3',
42
+ 'deeppink':'#ff1493',
43
+ 'deepskyblue':'#00bfff',
44
+ 'dimgray':'#696969',
45
+ 'dimgrey':'#696969',
46
+ 'dodgerblue':'#1e90ff',
47
+ 'firebrick':'#b22222',
48
+ 'floralwhite':'#fffaf0',
49
+ 'forestgreen':'#228b22',
50
+ 'fuchsia':'#ff00ff',
51
+ 'gainsboro':'#dcdcdc',
52
+ 'ghostwhite':'#f8f8ff',
53
+ 'gold':'#ffd700',
54
+ 'goldenrod':'#daa520',
55
+ 'gray':'#808080',
56
+ 'grey':'#808080',
57
+ 'green':'#008000',
58
+ 'greenyellow':'#adff2f',
59
+ 'honeydew':'#f0fff0',
60
+ 'hotpink':'#ff69b4',
61
+ 'indianred':'#cd5c5c',
62
+ 'indigo':'#4b0082',
63
+ 'ivory':'#fffff0',
64
+ 'khaki':'#f0e68c',
65
+ 'lavender':'#e6e6fa',
66
+ 'lavenderblush':'#fff0f5',
67
+ 'lawngreen':'#7cfc00',
68
+ 'lemonchiffon':'#fffacd',
69
+ 'lightblue':'#add8e6',
70
+ 'lightcoral':'#f08080',
71
+ 'lightcyan':'#e0ffff',
72
+ 'lightgoldenrodyellow':'#fafad2',
73
+ 'lightgray':'#d3d3d3',
74
+ 'lightgrey':'#d3d3d3',
75
+ 'lightgreen':'#90ee90',
76
+ 'lightpink':'#ffb6c1',
77
+ 'lightsalmon':'#ffa07a',
78
+ 'lightseagreen':'#20b2aa',
79
+ 'lightskyblue':'#87cefa',
80
+ 'lightslategray':'#778899',
81
+ 'lightslategrey':'#778899',
82
+ 'lightsteelblue':'#b0c4de',
83
+ 'lightyellow':'#ffffe0',
84
+ 'lime':'#00ff00',
85
+ 'limegreen':'#32cd32',
86
+ 'linen':'#faf0e6',
87
+ 'magenta':'#ff00ff',
88
+ 'maroon':'#800000',
89
+ 'mediumaquamarine':'#66cdaa',
90
+ 'mediumblue':'#0000cd',
91
+ 'mediumorchid':'#ba55d3',
92
+ 'mediumpurple':'#9370d8',
93
+ 'mediumseagreen':'#3cb371',
94
+ 'mediumslateblue':'#7b68ee',
95
+ 'mediumspringgreen':'#00fa9a',
96
+ 'mediumturquoise':'#48d1cc',
97
+ 'mediumvioletred':'#c71585',
98
+ 'midnightblue':'#191970',
99
+ 'mintcream':'#f5fffa',
100
+ 'mistyrose':'#ffe4e1',
101
+ 'moccasin':'#ffe4b5',
102
+ 'navajowhite':'#ffdead',
103
+ 'navy':'#000080',
104
+ 'oldlace':'#fdf5e6',
105
+ 'olive':'#808000',
106
+ 'olivedrab':'#6b8e23',
107
+ 'orange':'#ffa500',
108
+ 'orangered':'#ff4500',
109
+ 'orchid':'#da70d6',
110
+ 'palegoldenrod':'#eee8aa',
111
+ 'palegreen':'#98fb98',
112
+ 'paleturquoise':'#afeeee',
113
+ 'palevioletred':'#d87093',
114
+ 'papayawhip':'#ffefd5',
115
+ 'peachpuff':'#ffdab9',
116
+ 'peru':'#cd853f',
117
+ 'pink':'#ffc0cb',
118
+ 'plum':'#dda0dd',
119
+ 'powderblue':'#b0e0e6',
120
+ 'purple':'#800080',
121
+ 'rebeccapurple':'#663399',
122
+ 'red':'#ff0000',
123
+ 'rosybrown':'#bc8f8f',
124
+ 'royalblue':'#4169e1',
125
+ 'saddlebrown':'#8b4513',
126
+ 'salmon':'#fa8072',
127
+ 'sandybrown':'#f4a460',
128
+ 'seagreen':'#2e8b57',
129
+ 'seashell':'#fff5ee',
130
+ 'sienna':'#a0522d',
131
+ 'silver':'#c0c0c0',
132
+ 'skyblue':'#87ceeb',
133
+ 'slateblue':'#6a5acd',
134
+ 'slategray':'#708090',
135
+ 'slategrey':'#708090',
136
+ 'snow':'#fffafa',
137
+ 'springgreen':'#00ff7f',
138
+ 'steelblue':'#4682b4',
139
+ 'tan':'#d2b48c',
140
+ 'teal':'#008080',
141
+ 'thistle':'#d8bfd8',
142
+ 'tomato':'#ff6347',
143
+ 'turquoise':'#40e0d0',
144
+ 'violet':'#ee82ee',
145
+ 'wheat':'#f5deb3',
146
+ 'white':'#ffffff',
147
+ 'whitesmoke':'#f5f5f5',
148
+ 'yellow':'#ffff00',
149
+ 'yellowgreen':'#9acd32'
150
+ };
@@ -0,0 +1,4 @@
1
+ import colors from './colors';
2
+ import unitConversions from './unit-conversions';
3
+
4
+ export default { colors, unitConversions };
@@ -0,0 +1,21 @@
1
+ export default {
2
+ length: {
3
+ 'm': 1,
4
+ 'cm': 0.01,
5
+ 'mm': 0.001,
6
+ 'in': 0.0254,
7
+ 'px': 0.0254 / 96,
8
+ 'pt': 0.0254 / 72,
9
+ 'pc': 0.0254 / 72 * 12
10
+ },
11
+ duration: {
12
+ 's': 1,
13
+ 'ms': 0.001
14
+ },
15
+ angle: {
16
+ 'rad': 1 / (2 * Math.PI),
17
+ 'deg': 1 / 360,
18
+ 'grad': 1 / 400,
19
+ 'turn': 1
20
+ }
21
+ };
@@ -0,0 +1,68 @@
1
+ // Export a new default each time
2
+ export default () => ({
3
+ /* Inline Javascript - @plugin still allowed */
4
+ javascriptEnabled: false,
5
+
6
+ /* Outputs a makefile import dependency list to stdout. */
7
+ depends: false,
8
+
9
+ /* (DEPRECATED) Compress using less built-in compression.
10
+ * This does an okay job but does not utilise all the tricks of
11
+ * dedicated css compression. */
12
+ compress: false,
13
+
14
+ /* Runs the less parser and just reports errors without any output. */
15
+ lint: false,
16
+
17
+ /* Sets available include paths.
18
+ * If the file in an @import rule does not exist at that exact location,
19
+ * less will look for it at the location(s) passed to this option.
20
+ * You might use this for instance to specify a path to a library which
21
+ * you want to be referenced simply and relatively in the less files. */
22
+ paths: [],
23
+
24
+ /* color output in the terminal */
25
+ color: true,
26
+
27
+ /* The strictImports controls whether the compiler will allow an @import inside of either
28
+ * @media blocks or (a later addition) other selector blocks.
29
+ * See: https://github.com/less/less.js/issues/656 */
30
+ strictImports: false,
31
+
32
+ /* Allow Imports from Insecure HTTPS Hosts */
33
+ insecure: false,
34
+
35
+ /* Allows you to add a path to every generated import and url in your css.
36
+ * This does not affect less import statements that are processed, just ones
37
+ * that are left in the output css. */
38
+ rootpath: '',
39
+
40
+ /* By default URLs are kept as-is, so if you import a file in a sub-directory
41
+ * that references an image, exactly the same URL will be output in the css.
42
+ * This option allows you to re-write URL's in imported files so that the
43
+ * URL is always relative to the base imported file */
44
+ rewriteUrls: false,
45
+
46
+ /* How to process math
47
+ * 0 always - eagerly try to solve all operations
48
+ * 1 parens-division - require parens for division "/"
49
+ * 2 parens | strict - require parens for all operations
50
+ * 3 strict-legacy - legacy strict behavior (super-strict)
51
+ */
52
+ math: 0,
53
+
54
+ /* Without this option, less attempts to guess at the output unit when it does maths. */
55
+ strictUnits: false,
56
+
57
+ /* Effectively the declaration is put at the top of your base Less file,
58
+ * meaning it can be used but it also can be overridden if this variable
59
+ * is defined in the file. */
60
+ globalVars: null,
61
+
62
+ /* As opposed to the global variable option, this puts the declaration at the
63
+ * end of your base file, meaning it will override anything defined in your Less file. */
64
+ modifyVars: null,
65
+
66
+ /* This option allows you to specify a argument to go on to every URL. */
67
+ urlArgs: ''
68
+ });
@@ -0,0 +1,127 @@
1
+ class AbstractFileManager {
2
+ getPath(filename) {
3
+ let j = filename.lastIndexOf('?');
4
+ if (j > 0) {
5
+ filename = filename.slice(0, j);
6
+ }
7
+ j = filename.lastIndexOf('/');
8
+ if (j < 0) {
9
+ j = filename.lastIndexOf('\\');
10
+ }
11
+ if (j < 0) {
12
+ return '';
13
+ }
14
+ return filename.slice(0, j + 1);
15
+ }
16
+
17
+ tryAppendExtension(path, ext) {
18
+ return /(\.[a-z]*$)|([\?;].*)$/.test(path) ? path : path + ext;
19
+ }
20
+
21
+ tryAppendLessExtension(path) {
22
+ return this.tryAppendExtension(path, '.less');
23
+ };
24
+
25
+ supportsSync() { return false; }
26
+
27
+ alwaysMakePathsAbsolute() { return false; }
28
+
29
+ isPathAbsolute(filename) {
30
+ return (/^(?:[a-z-]+:|\/|\\|#)/i).test(filename);
31
+ }
32
+ // TODO: pull out / replace?
33
+ join(basePath, laterPath) {
34
+ if (!basePath) {
35
+ return laterPath;
36
+ }
37
+ return basePath + laterPath;
38
+ };
39
+
40
+ pathDiff(url, baseUrl) {
41
+ // diff between two paths to create a relative path
42
+ const urlParts = this.extractUrlParts(url);
43
+ const baseUrlParts = this.extractUrlParts(baseUrl);
44
+
45
+ let i;
46
+ let max;
47
+ let urlDirectories;
48
+ let baseUrlDirectories;
49
+ let diff = '';
50
+ if (urlParts.hostPart !== baseUrlParts.hostPart) {
51
+ return '';
52
+ }
53
+ max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
54
+ for (i = 0; i < max; i++) {
55
+ if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
56
+ }
57
+ baseUrlDirectories = baseUrlParts.directories.slice(i);
58
+ urlDirectories = urlParts.directories.slice(i);
59
+ for (i = 0; i < baseUrlDirectories.length - 1; i++) {
60
+ diff += '../';
61
+ }
62
+ for (i = 0; i < urlDirectories.length - 1; i++) {
63
+ diff += `${urlDirectories[i]}/`;
64
+ }
65
+ return diff;
66
+ };
67
+ // helper function, not part of API
68
+ extractUrlParts(url, baseUrl) {
69
+ // urlParts[1] = protocol://hostname/ OR /
70
+ // urlParts[2] = / if path relative to host base
71
+ // urlParts[3] = directories
72
+ // urlParts[4] = filename
73
+ // urlParts[5] = parameters
74
+
75
+ const urlPartsRegex = /^((?:[a-z-]+:)?\/{2}(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i;
76
+
77
+ const urlParts = url.match(urlPartsRegex);
78
+ const returner = {};
79
+ let rawDirectories = [];
80
+ const directories = [];
81
+ let i;
82
+ let baseUrlParts;
83
+
84
+ if (!urlParts) {
85
+ throw new Error(`Could not parse sheet href - '${url}'`);
86
+ }
87
+
88
+ // Stylesheets in IE don't always return the full path
89
+ if (baseUrl && (!urlParts[1] || urlParts[2])) {
90
+ baseUrlParts = baseUrl.match(urlPartsRegex);
91
+ if (!baseUrlParts) {
92
+ throw new Error(`Could not parse page url - '${baseUrl}'`);
93
+ }
94
+ urlParts[1] = urlParts[1] || baseUrlParts[1] || '';
95
+ if (!urlParts[2]) {
96
+ urlParts[3] = baseUrlParts[3] + urlParts[3];
97
+ }
98
+ }
99
+
100
+ if (urlParts[3]) {
101
+ rawDirectories = urlParts[3].replace(/\\/g, '/').split('/');
102
+
103
+ // collapse '..' and skip '.'
104
+ for (i = 0; i < rawDirectories.length; i++) {
105
+
106
+ if (rawDirectories[i] === '..') {
107
+ directories.pop();
108
+ }
109
+ else if (rawDirectories[i] !== '.') {
110
+ directories.push(rawDirectories[i]);
111
+ }
112
+
113
+ }
114
+ }
115
+
116
+ returner.hostPart = urlParts[1];
117
+ returner.directories = directories;
118
+ returner.rawPath = (urlParts[1] || '') + rawDirectories.join('/');
119
+ returner.path = (urlParts[1] || '') + directories.join('/');
120
+ returner.filename = urlParts[4];
121
+ returner.fileUrl = returner.path + (urlParts[4] || '');
122
+ returner.url = returner.fileUrl + (urlParts[5] || '');
123
+ return returner;
124
+ };
125
+ }
126
+
127
+ export default AbstractFileManager;