@swissquote/crafty-preset-lightningcss 1.22.3 → 1.23.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.
@@ -1,84 +1,6 @@
1
1
  require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
- /***/ 4737:
5
- /***/ ((__unused_webpack_module, exports) => {
6
-
7
- "use strict";
8
-
9
-
10
- Object.defineProperty(exports, "__esModule", ({
11
- value: true
12
- }));
13
- exports["default"] = void 0;
14
- class CssSyntaxError extends Error {
15
- constructor(error) {
16
- super(error);
17
- const {
18
- reason,
19
- line,
20
- column,
21
- file
22
- } = error;
23
- this.name = "CssSyntaxError";
24
-
25
- // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
26
- // We don't need `plugin` and `file` properties.
27
- this.message = `${this.name}\n\n`;
28
- if (typeof line !== "undefined") {
29
- this.message += `(${line}:${column}) `;
30
- }
31
- this.message += file ? `${file} ` : "<css input> ";
32
- this.message += `${reason}`;
33
- const code = error.showSourceCode();
34
- if (code) {
35
- this.message += `\n\n${code}\n`;
36
- }
37
-
38
- // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
39
- this.stack = false;
40
- }
41
- }
42
- exports["default"] = CssSyntaxError;
43
-
44
- /***/ }),
45
-
46
- /***/ 2046:
47
- /***/ ((__unused_webpack_module, exports) => {
48
-
49
- "use strict";
50
-
51
-
52
- Object.defineProperty(exports, "__esModule", ({
53
- value: true
54
- }));
55
- exports["default"] = void 0;
56
- class Warning extends Error {
57
- constructor(warning) {
58
- super(warning);
59
- const {
60
- text,
61
- line,
62
- column
63
- } = warning;
64
- this.name = "Warning";
65
-
66
- // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
67
- // We don't need `plugin` properties.
68
- this.message = `${this.name}\n\n`;
69
- if (typeof line !== "undefined") {
70
- this.message += `(${line}:${column}) `;
71
- }
72
- this.message += `${text}`;
73
-
74
- // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
75
- this.stack = false;
76
- }
77
- }
78
- exports["default"] = Warning;
79
-
80
- /***/ }),
81
-
82
4
  /***/ 7178:
83
5
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
84
6
 
@@ -104,8 +26,6 @@ exports["default"] = loader;
104
26
  var _postcss = _interopRequireDefault(__nccwpck_require__(7802));
105
27
  var _package = _interopRequireDefault(__nccwpck_require__(4956));
106
28
  var _semver = __nccwpck_require__(9337);
107
- var _CssSyntaxError = _interopRequireDefault(__nccwpck_require__(4737));
108
- var _Warning = _interopRequireDefault(__nccwpck_require__(2046));
109
29
  var _options = _interopRequireDefault(__nccwpck_require__(1096));
110
30
  var _plugins = __nccwpck_require__(3966);
111
31
  var _utils = __nccwpck_require__(4017);
@@ -117,8 +37,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
117
37
 
118
38
  async function loader(content, map, meta) {
119
39
  const rawOptions = this.getOptions(_options.default);
120
- const plugins = [];
121
40
  const callback = this.async();
41
+ if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && this._module.type === "css") {
42
+ this.emitWarning(new Error('You can\'t use `experiments.css` (`experiments.futureDefaults` enable built-in CSS support by default) and `css-loader` together, please set `experiments.css` to `false` or set `{ type: "javascript/auto" }` for rules with `css-loader` in your webpack config (now css-loader does nothing).'));
43
+ callback(null, content, map, meta);
44
+ return;
45
+ }
122
46
  let options;
123
47
  try {
124
48
  options = (0, _utils.normalizeOptions)(rawOptions, this);
@@ -126,6 +50,7 @@ async function loader(content, map, meta) {
126
50
  callback(error);
127
51
  return;
128
52
  }
53
+ const plugins = [];
129
54
  const replacements = [];
130
55
  const exports = [];
131
56
  if ((0, _utils.shouldUseModulesPlugins)(options)) {
@@ -217,11 +142,11 @@ async function loader(content, map, meta) {
217
142
  if (error.file) {
218
143
  this.addDependency(error.file);
219
144
  }
220
- callback(error.name === "CssSyntaxError" ? new _CssSyntaxError.default(error) : error);
145
+ callback(error.name === "CssSyntaxError" ? (0, _utils.syntaxErrorFactory)(error) : error);
221
146
  return;
222
147
  }
223
148
  for (const warning of result.warnings()) {
224
- this.emitWarning(new _Warning.default(warning));
149
+ this.emitWarning((0, _utils.warningFactory)(warning));
225
150
  }
226
151
  const imports = [].concat(icssPluginImports.sort(_utils.sort)).concat(importPluginImports.sort(_utils.sort)).concat(urlPluginImports.sort(_utils.sort));
227
152
  const api = [].concat(importPluginApi.sort(_utils.sort)).concat(icssPluginApi.sort(_utils.sort));
@@ -243,15 +168,29 @@ async function loader(content, map, meta) {
243
168
  });
244
169
  }
245
170
  }
171
+ let isTemplateLiteralSupported = false;
172
+ if (
173
+ // eslint-disable-next-line no-underscore-dangle
174
+ this._compilation &&
175
+ // eslint-disable-next-line no-underscore-dangle
176
+ this._compilation.options &&
177
+ // eslint-disable-next-line no-underscore-dangle
178
+ this._compilation.options.output &&
179
+ // eslint-disable-next-line no-underscore-dangle
180
+ this._compilation.options.output.environment &&
181
+ // eslint-disable-next-line no-underscore-dangle
182
+ this._compilation.options.output.environment.templateLiteral) {
183
+ isTemplateLiteralSupported = true;
184
+ }
246
185
  const importCode = (0, _utils.getImportCode)(imports, options);
247
186
  let moduleCode;
248
187
  try {
249
- moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, this);
188
+ moduleCode = (0, _utils.getModuleCode)(result, api, replacements, options, isTemplateLiteralSupported, this);
250
189
  } catch (error) {
251
190
  callback(error);
252
191
  return;
253
192
  }
254
- const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options);
193
+ const exportCode = (0, _utils.getExportCode)(exports, replacements, needToUseIcssPlugin, options, isTemplateLiteralSupported);
255
194
  callback(null, `${importCode}${moduleCode}${exportCode}`);
256
195
  }
257
196
 
@@ -1099,6 +1038,8 @@ exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
1099
1038
  exports.shouldUseURLPlugin = shouldUseURLPlugin;
1100
1039
  exports.sort = sort;
1101
1040
  exports.stringifyRequest = stringifyRequest;
1041
+ exports.syntaxErrorFactory = syntaxErrorFactory;
1042
+ exports.warningFactory = warningFactory;
1102
1043
  var _url = __nccwpck_require__(7310);
1103
1044
  var _path = _interopRequireDefault(__nccwpck_require__(1017));
1104
1045
  var _postcssModulesValues = _interopRequireDefault(__nccwpck_require__(9103));
@@ -1862,7 +1803,7 @@ function printParams(media, dedupe, supports, layer) {
1862
1803
  }
1863
1804
  return result;
1864
1805
  }
1865
- function getModuleCode(result, api, replacements, options, loaderContext) {
1806
+ function getModuleCode(result, api, replacements, options, isTemplateLiteralSupported, loaderContext) {
1866
1807
  if (options.modules.exportOnlyLocals === true) {
1867
1808
  return "";
1868
1809
  }
@@ -1871,7 +1812,7 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
1871
1812
  const sourceMap = result.map;
1872
1813
  sourceMapValue = `,${normalizeSourceMapForRuntime(sourceMap, loaderContext)}`;
1873
1814
  }
1874
- let code = JSON.stringify(result.css);
1815
+ let code = isTemplateLiteralSupported ? convertToTemplateLiteral(result.css) : JSON.stringify(result.css);
1875
1816
  let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___"});\n`;
1876
1817
  for (const item of api) {
1877
1818
  const {
@@ -1897,7 +1838,7 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
1897
1838
  localName
1898
1839
  } = item;
1899
1840
  if (localName) {
1900
- code = code.replace(new RegExp(replacementName, "g"), () => options.modules.namedExport ? `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
1841
+ code = code.replace(new RegExp(replacementName, "g"), () => options.modules.namedExport ? isTemplateLiteralSupported ? `\${ ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] }` : `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "` : isTemplateLiteralSupported ? `\${${importName}.locals[${JSON.stringify(localName)}]}` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`);
1901
1842
  } else {
1902
1843
  const {
1903
1844
  hash,
@@ -1906,7 +1847,7 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
1906
1847
  const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? "needQuotes: true" : []);
1907
1848
  const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(", ")} }` : "";
1908
1849
  beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
1909
- code = code.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
1850
+ code = code.replace(new RegExp(replacementName, "g"), () => isTemplateLiteralSupported ? `\${${replacementName}}` : `" + ${replacementName} + "`);
1910
1851
  }
1911
1852
  }
1912
1853
 
@@ -1919,10 +1860,21 @@ function getModuleCode(result, api, replacements, options, loaderContext) {
1919
1860
  // 5 - layer
1920
1861
  return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
1921
1862
  }
1863
+ const SLASH = "\\".charCodeAt(0);
1864
+ const BACKTICK = "`".charCodeAt(0);
1865
+ const DOLLAR = "$".charCodeAt(0);
1866
+ function convertToTemplateLiteral(str) {
1867
+ let escapedString = "";
1868
+ for (let i = 0; i < str.length; i++) {
1869
+ const code = str.charCodeAt(i);
1870
+ escapedString += code === SLASH || code === BACKTICK || code === DOLLAR ? `\\${str[i]}` : str[i];
1871
+ }
1872
+ return `\`${escapedString}\``;
1873
+ }
1922
1874
  function dashesCamelCase(str) {
1923
1875
  return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
1924
1876
  }
1925
- function getExportCode(exports, replacements, icssPluginUsed, options) {
1877
+ function getExportCode(exports, replacements, icssPluginUsed, options, isTemplateLiteralSupported) {
1926
1878
  let code = "// Exports\n";
1927
1879
  if (icssPluginUsed) {
1928
1880
  let localsCode = "";
@@ -1930,12 +1882,12 @@ function getExportCode(exports, replacements, icssPluginUsed, options) {
1930
1882
  const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
1931
1883
  for (const name of normalizedNames) {
1932
1884
  if (options.modules.namedExport) {
1933
- localsCode += `export var ${name} = ${JSON.stringify(value)};\n`;
1885
+ localsCode += `export var ${name} = ${isTemplateLiteralSupported ? convertToTemplateLiteral(value) : JSON.stringify(value)};\n`;
1934
1886
  } else {
1935
1887
  if (localsCode) {
1936
1888
  localsCode += `,\n`;
1937
1889
  }
1938
- localsCode += `\t${JSON.stringify(name)}: ${JSON.stringify(value)}`;
1890
+ localsCode += `\t${JSON.stringify(name)}: ${isTemplateLiteralSupported ? convertToTemplateLiteral(value) : JSON.stringify(value)}`;
1939
1891
  }
1940
1892
  }
1941
1893
  };
@@ -1956,14 +1908,14 @@ function getExportCode(exports, replacements, icssPluginUsed, options) {
1956
1908
  } = item;
1957
1909
  localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
1958
1910
  if (options.modules.namedExport) {
1959
- return `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
1911
+ return isTemplateLiteralSupported ? `\${${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}]}` : `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
1960
1912
  } else if (options.modules.exportOnlyLocals) {
1961
- return `" + ${importName}[${JSON.stringify(localName)}] + "`;
1913
+ return isTemplateLiteralSupported ? `\${${importName}[${JSON.stringify(localName)}]}` : `" + ${importName}[${JSON.stringify(localName)}] + "`;
1962
1914
  }
1963
- return `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
1915
+ return isTemplateLiteralSupported ? `\${${importName}.locals[${JSON.stringify(localName)}]}` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
1964
1916
  });
1965
1917
  } else {
1966
- localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => `" + ${replacementName} + "`);
1918
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => isTemplateLiteralSupported ? `\${${replacementName}}` : `" + ${replacementName} + "`);
1967
1919
  }
1968
1920
  }
1969
1921
  if (options.modules.exportOnlyLocals) {
@@ -2068,6 +2020,44 @@ function combineRequests(preRequest, url) {
2068
2020
  const idx = url.indexOf("!=!");
2069
2021
  return idx !== -1 ? url.slice(0, idx + 3) + preRequest + url.slice(idx + 3) : preRequest + url;
2070
2022
  }
2023
+ function warningFactory(warning) {
2024
+ let message = "";
2025
+ if (typeof warning.line !== "undefined") {
2026
+ message += `(${warning.line}:${warning.column}) `;
2027
+ }
2028
+ if (typeof warning.plugin !== "undefined") {
2029
+ message += `from "${warning.plugin}" plugin: `;
2030
+ }
2031
+ message += warning.text;
2032
+ if (warning.node) {
2033
+ message += `\n\nCode:\n ${warning.node.toString()}\n`;
2034
+ }
2035
+ const obj = new Error(message, {
2036
+ cause: warning
2037
+ });
2038
+ obj.stack = null;
2039
+ return obj;
2040
+ }
2041
+ function syntaxErrorFactory(error) {
2042
+ let message = "\nSyntaxError\n\n";
2043
+ if (typeof error.line !== "undefined") {
2044
+ message += `(${error.line}:${error.column}) `;
2045
+ }
2046
+ if (typeof error.plugin !== "undefined") {
2047
+ message += `from "${error.plugin}" plugin: `;
2048
+ }
2049
+ message += error.file ? `${error.file} ` : "<css input> ";
2050
+ message += `${error.reason}`;
2051
+ const code = error.showSourceCode();
2052
+ if (code) {
2053
+ message += `\n\n${code}\n`;
2054
+ }
2055
+ const obj = new Error(message, {
2056
+ cause: error
2057
+ });
2058
+ obj.stack = null;
2059
+ return obj;
2060
+ }
2071
2061
 
2072
2062
  /***/ }),
2073
2063
 
@@ -3088,9 +3078,19 @@ function localizeNode(rule, mode, localAliasMap) {
3088
3078
  hasLocals: false,
3089
3079
  explicit: context.explicit,
3090
3080
  };
3091
- newNodes = node.map((childNode) =>
3092
- transform(childNode, childContext)
3093
- );
3081
+ newNodes = node.map((childNode) => {
3082
+ const newContext = {
3083
+ ...childContext,
3084
+ enforceNoSpacing: false,
3085
+ };
3086
+
3087
+ const result = transform(childNode, newContext);
3088
+
3089
+ childContext.global = newContext.global;
3090
+ childContext.hasLocals = newContext.hasLocals;
3091
+
3092
+ return result;
3093
+ });
3094
3094
 
3095
3095
  node = node.clone();
3096
3096
  node.nodes = normalizeNodeArray(newNodes);
@@ -3231,19 +3231,34 @@ function localizeDeclNode(node, context) {
3231
3231
  return node;
3232
3232
  }
3233
3233
 
3234
- function isWordAFunctionArgument(wordNode, functionNode) {
3235
- return functionNode
3236
- ? functionNode.nodes.some(
3237
- (functionNodeChild) =>
3238
- functionNodeChild.sourceIndex === wordNode.sourceIndex
3239
- )
3240
- : false;
3241
- }
3234
+ // `none` is special value, other is global values
3235
+ const specialKeywords = [
3236
+ "none",
3237
+ "inherit",
3238
+ "initial",
3239
+ "revert",
3240
+ "revert-layer",
3241
+ "unset",
3242
+ ];
3242
3243
 
3243
3244
  function localizeDeclarationValues(localize, declaration, context) {
3244
3245
  const valueNodes = valueParser(declaration.value);
3245
3246
 
3246
3247
  valueNodes.walk((node, index, nodes) => {
3248
+ if (
3249
+ node.type === "function" &&
3250
+ (node.value.toLowerCase() === "var" || node.value.toLowerCase() === "env")
3251
+ ) {
3252
+ return false;
3253
+ }
3254
+
3255
+ if (
3256
+ node.type === "word" &&
3257
+ specialKeywords.includes(node.value.toLowerCase())
3258
+ ) {
3259
+ return;
3260
+ }
3261
+
3247
3262
  const subContext = {
3248
3263
  options: context.options,
3249
3264
  global: context.global,
@@ -3260,63 +3275,84 @@ function localizeDeclaration(declaration, context) {
3260
3275
  const isAnimation = /animation$/i.test(declaration.prop);
3261
3276
 
3262
3277
  if (isAnimation) {
3263
- const validIdent = /^-?[_a-z][_a-z0-9-]*$/i;
3278
+ // letter
3279
+ // An uppercase letter or a lowercase letter.
3280
+ //
3281
+ // ident-start code point
3282
+ // A letter, a non-ASCII code point, or U+005F LOW LINE (_).
3283
+ //
3284
+ // ident code point
3285
+ // An ident-start code point, a digit, or U+002D HYPHEN-MINUS (-).
3286
+
3287
+ // We don't validate `hex digits`, because we don't need it, it is work of linters.
3288
+ const validIdent =
3289
+ /^-?([a-z\u0080-\uFFFF_]|(\\[^\r\n\f])|-)((\\[^\r\n\f])|[a-z\u0080-\uFFFF_0-9-])*$/i;
3264
3290
 
3265
3291
  /*
3266
3292
  The spec defines some keywords that you can use to describe properties such as the timing
3267
3293
  function. These are still valid animation names, so as long as there is a property that accepts
3268
3294
  a keyword, it is given priority. Only when all the properties that can take a keyword are
3269
3295
  exhausted can the animation name be set to the keyword. I.e.
3270
-
3296
+
3271
3297
  animation: infinite infinite;
3272
-
3298
+
3273
3299
  The animation will repeat an infinite number of times from the first argument, and will have an
3274
3300
  animation name of infinite from the second.
3275
3301
  */
3276
3302
  const animationKeywords = {
3303
+ // animation-direction
3304
+ $normal: 1,
3305
+ $reverse: 1,
3277
3306
  $alternate: 1,
3278
3307
  "$alternate-reverse": 1,
3308
+ // animation-fill-mode
3309
+ $forwards: 1,
3279
3310
  $backwards: 1,
3280
3311
  $both: 1,
3312
+ // animation-iteration-count
3313
+ $infinite: 1,
3314
+ // animation-play-state
3315
+ $paused: 1,
3316
+ $running: 1,
3317
+ // animation-timing-function
3281
3318
  $ease: 1,
3282
3319
  "$ease-in": 1,
3283
- "$ease-in-out": 1,
3284
3320
  "$ease-out": 1,
3285
- $forwards: 1,
3286
- $infinite: 1,
3321
+ "$ease-in-out": 1,
3287
3322
  $linear: 1,
3288
- $none: Infinity, // No matter how many times you write none, it will never be an animation name
3289
- $normal: 1,
3290
- $paused: 1,
3291
- $reverse: 1,
3292
- $running: 1,
3293
3323
  "$step-end": 1,
3294
3324
  "$step-start": 1,
3325
+ // Special
3326
+ $none: Infinity, // No matter how many times you write none, it will never be an animation name
3327
+ // Global values
3295
3328
  $initial: Infinity,
3296
3329
  $inherit: Infinity,
3297
3330
  $unset: Infinity,
3331
+ $revert: Infinity,
3332
+ "$revert-layer": Infinity,
3298
3333
  };
3299
-
3300
- const didParseAnimationName = false;
3301
3334
  let parsedAnimationKeywords = {};
3302
- let stepsFunctionNode = null;
3303
3335
  const valueNodes = valueParser(declaration.value).walk((node) => {
3304
- /* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */
3336
+ // If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh.
3305
3337
  if (node.type === "div") {
3306
3338
  parsedAnimationKeywords = {};
3339
+
3340
+ return;
3341
+ }
3342
+ // Do not handle nested functions
3343
+ else if (node.type === "function") {
3344
+ return false;
3307
3345
  }
3308
- if (node.type === "function" && node.value.toLowerCase() === "steps") {
3309
- stepsFunctionNode = node;
3346
+ // Ignore all except word
3347
+ else if (node.type !== "word") {
3348
+ return;
3310
3349
  }
3311
- const value =
3312
- node.type === "word" &&
3313
- !isWordAFunctionArgument(node, stepsFunctionNode)
3314
- ? node.value.toLowerCase()
3315
- : null;
3350
+
3351
+ const value = node.type === "word" ? node.value.toLowerCase() : null;
3316
3352
 
3317
3353
  let shouldParseAnimationName = false;
3318
3354
 
3319
- if (!didParseAnimationName && value && validIdent.test(value)) {
3355
+ if (value && validIdent.test(value)) {
3320
3356
  if ("$" + value in animationKeywords) {
3321
3357
  parsedAnimationKeywords["$" + value] =
3322
3358
  "$" + value in parsedAnimationKeywords
@@ -3337,6 +3373,7 @@ function localizeDeclaration(declaration, context) {
3337
3373
  localizeNextItem: shouldParseAnimationName && !context.global,
3338
3374
  localAliasMap: context.localAliasMap,
3339
3375
  };
3376
+
3340
3377
  return localizeDeclNode(node, subContext);
3341
3378
  });
3342
3379
 
@@ -4041,12 +4078,24 @@ function markDirtyUp(node) {
4041
4078
  }
4042
4079
 
4043
4080
  class Container extends Node {
4044
- push(child) {
4045
- child.parent = this
4046
- this.proxyOf.nodes.push(child)
4081
+ append(...children) {
4082
+ for (let child of children) {
4083
+ let nodes = this.normalize(child, this.last)
4084
+ for (let node of nodes) this.proxyOf.nodes.push(node)
4085
+ }
4086
+
4087
+ this.markDirty()
4088
+
4047
4089
  return this
4048
4090
  }
4049
4091
 
4092
+ cleanRaws(keepBetween) {
4093
+ super.cleanRaws(keepBetween)
4094
+ if (this.nodes) {
4095
+ for (let node of this.nodes) node.cleanRaws(keepBetween)
4096
+ }
4097
+ }
4098
+
4050
4099
  each(callback) {
4051
4100
  if (!this.proxyOf.nodes) return undefined
4052
4101
  let iterator = this.getIterator()
@@ -4064,104 +4113,109 @@ class Container extends Node {
4064
4113
  return result
4065
4114
  }
4066
4115
 
4067
- walk(callback) {
4068
- return this.each((child, i) => {
4069
- let result
4070
- try {
4071
- result = callback(child, i)
4072
- } catch (e) {
4073
- throw child.addToError(e)
4074
- }
4075
- if (result !== false && child.walk) {
4076
- result = child.walk(callback)
4077
- }
4116
+ every(condition) {
4117
+ return this.nodes.every(condition)
4118
+ }
4078
4119
 
4079
- return result
4080
- })
4120
+ getIterator() {
4121
+ if (!this.lastEach) this.lastEach = 0
4122
+ if (!this.indexes) this.indexes = {}
4123
+
4124
+ this.lastEach += 1
4125
+ let iterator = this.lastEach
4126
+ this.indexes[iterator] = 0
4127
+
4128
+ return iterator
4081
4129
  }
4082
4130
 
4083
- walkDecls(prop, callback) {
4084
- if (!callback) {
4085
- callback = prop
4086
- return this.walk((child, i) => {
4087
- if (child.type === 'decl') {
4088
- return callback(child, i)
4131
+ getProxyProcessor() {
4132
+ return {
4133
+ get(node, prop) {
4134
+ if (prop === 'proxyOf') {
4135
+ return node
4136
+ } else if (!node[prop]) {
4137
+ return node[prop]
4138
+ } else if (
4139
+ prop === 'each' ||
4140
+ (typeof prop === 'string' && prop.startsWith('walk'))
4141
+ ) {
4142
+ return (...args) => {
4143
+ return node[prop](
4144
+ ...args.map(i => {
4145
+ if (typeof i === 'function') {
4146
+ return (child, index) => i(child.toProxy(), index)
4147
+ } else {
4148
+ return i
4149
+ }
4150
+ })
4151
+ )
4152
+ }
4153
+ } else if (prop === 'every' || prop === 'some') {
4154
+ return cb => {
4155
+ return node[prop]((child, ...other) =>
4156
+ cb(child.toProxy(), ...other)
4157
+ )
4158
+ }
4159
+ } else if (prop === 'root') {
4160
+ return () => node.root().toProxy()
4161
+ } else if (prop === 'nodes') {
4162
+ return node.nodes.map(i => i.toProxy())
4163
+ } else if (prop === 'first' || prop === 'last') {
4164
+ return node[prop].toProxy()
4165
+ } else {
4166
+ return node[prop]
4089
4167
  }
4090
- })
4091
- }
4092
- if (prop instanceof RegExp) {
4093
- return this.walk((child, i) => {
4094
- if (child.type === 'decl' && prop.test(child.prop)) {
4095
- return callback(child, i)
4168
+ },
4169
+
4170
+ set(node, prop, value) {
4171
+ if (node[prop] === value) return true
4172
+ node[prop] = value
4173
+ if (prop === 'name' || prop === 'params' || prop === 'selector') {
4174
+ node.markDirty()
4096
4175
  }
4097
- })
4098
- }
4099
- return this.walk((child, i) => {
4100
- if (child.type === 'decl' && child.prop === prop) {
4101
- return callback(child, i)
4176
+ return true
4102
4177
  }
4103
- })
4178
+ }
4104
4179
  }
4105
4180
 
4106
- walkRules(selector, callback) {
4107
- if (!callback) {
4108
- callback = selector
4181
+ index(child) {
4182
+ if (typeof child === 'number') return child
4183
+ if (child.proxyOf) child = child.proxyOf
4184
+ return this.proxyOf.nodes.indexOf(child)
4185
+ }
4109
4186
 
4110
- return this.walk((child, i) => {
4111
- if (child.type === 'rule') {
4112
- return callback(child, i)
4113
- }
4114
- })
4115
- }
4116
- if (selector instanceof RegExp) {
4117
- return this.walk((child, i) => {
4118
- if (child.type === 'rule' && selector.test(child.selector)) {
4119
- return callback(child, i)
4120
- }
4121
- })
4122
- }
4123
- return this.walk((child, i) => {
4124
- if (child.type === 'rule' && child.selector === selector) {
4125
- return callback(child, i)
4187
+ insertAfter(exist, add) {
4188
+ let existIndex = this.index(exist)
4189
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse()
4190
+ existIndex = this.index(exist)
4191
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node)
4192
+
4193
+ let index
4194
+ for (let id in this.indexes) {
4195
+ index = this.indexes[id]
4196
+ if (existIndex < index) {
4197
+ this.indexes[id] = index + nodes.length
4126
4198
  }
4127
- })
4199
+ }
4200
+
4201
+ this.markDirty()
4202
+
4203
+ return this
4128
4204
  }
4129
4205
 
4130
- walkAtRules(name, callback) {
4131
- if (!callback) {
4132
- callback = name
4133
- return this.walk((child, i) => {
4134
- if (child.type === 'atrule') {
4135
- return callback(child, i)
4136
- }
4137
- })
4138
- }
4139
- if (name instanceof RegExp) {
4140
- return this.walk((child, i) => {
4141
- if (child.type === 'atrule' && name.test(child.name)) {
4142
- return callback(child, i)
4143
- }
4144
- })
4145
- }
4146
- return this.walk((child, i) => {
4147
- if (child.type === 'atrule' && child.name === name) {
4148
- return callback(child, i)
4149
- }
4150
- })
4151
- }
4206
+ insertBefore(exist, add) {
4207
+ let existIndex = this.index(exist)
4208
+ let type = existIndex === 0 ? 'prepend' : false
4209
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
4210
+ existIndex = this.index(exist)
4211
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
4152
4212
 
4153
- walkComments(callback) {
4154
- return this.walk((child, i) => {
4155
- if (child.type === 'comment') {
4156
- return callback(child, i)
4213
+ let index
4214
+ for (let id in this.indexes) {
4215
+ index = this.indexes[id]
4216
+ if (existIndex <= index) {
4217
+ this.indexes[id] = index + nodes.length
4157
4218
  }
4158
- })
4159
- }
4160
-
4161
- append(...children) {
4162
- for (let child of children) {
4163
- let nodes = this.normalize(child, this.last)
4164
- for (let node of nodes) this.proxyOf.nodes.push(node)
4165
4219
  }
4166
4220
 
4167
4221
  this.markDirty()
@@ -4169,6 +4223,56 @@ class Container extends Node {
4169
4223
  return this
4170
4224
  }
4171
4225
 
4226
+ normalize(nodes, sample) {
4227
+ if (typeof nodes === 'string') {
4228
+ nodes = cleanSource(parse(nodes).nodes)
4229
+ } else if (Array.isArray(nodes)) {
4230
+ nodes = nodes.slice(0)
4231
+ for (let i of nodes) {
4232
+ if (i.parent) i.parent.removeChild(i, 'ignore')
4233
+ }
4234
+ } else if (nodes.type === 'root' && this.type !== 'document') {
4235
+ nodes = nodes.nodes.slice(0)
4236
+ for (let i of nodes) {
4237
+ if (i.parent) i.parent.removeChild(i, 'ignore')
4238
+ }
4239
+ } else if (nodes.type) {
4240
+ nodes = [nodes]
4241
+ } else if (nodes.prop) {
4242
+ if (typeof nodes.value === 'undefined') {
4243
+ throw new Error('Value field is missed in node creation')
4244
+ } else if (typeof nodes.value !== 'string') {
4245
+ nodes.value = String(nodes.value)
4246
+ }
4247
+ nodes = [new Declaration(nodes)]
4248
+ } else if (nodes.selector) {
4249
+ nodes = [new Rule(nodes)]
4250
+ } else if (nodes.name) {
4251
+ nodes = [new AtRule(nodes)]
4252
+ } else if (nodes.text) {
4253
+ nodes = [new Comment(nodes)]
4254
+ } else {
4255
+ throw new Error('Unknown node type in node creation')
4256
+ }
4257
+
4258
+ let processed = nodes.map(i => {
4259
+ /* c8 ignore next */
4260
+ if (!i[my]) Container.rebuild(i)
4261
+ i = i.proxyOf
4262
+ if (i.parent) i.parent.removeChild(i)
4263
+ if (i[isClean]) markDirtyUp(i)
4264
+ if (typeof i.raws.before === 'undefined') {
4265
+ if (sample && typeof sample.raws.before !== 'undefined') {
4266
+ i.raws.before = sample.raws.before.replace(/\S/g, '')
4267
+ }
4268
+ }
4269
+ i.parent = this.proxyOf
4270
+ return i
4271
+ })
4272
+
4273
+ return processed
4274
+ }
4275
+
4172
4276
  prepend(...children) {
4173
4277
  children = children.reverse()
4174
4278
  for (let child of children) {
@@ -4184,46 +4288,15 @@ class Container extends Node {
4184
4288
  return this
4185
4289
  }
4186
4290
 
4187
- cleanRaws(keepBetween) {
4188
- super.cleanRaws(keepBetween)
4189
- if (this.nodes) {
4190
- for (let node of this.nodes) node.cleanRaws(keepBetween)
4191
- }
4192
- }
4193
-
4194
- insertBefore(exist, add) {
4195
- let existIndex = this.index(exist)
4196
- let type = existIndex === 0 ? 'prepend' : false
4197
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex], type).reverse()
4198
- existIndex = this.index(exist)
4199
- for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
4200
-
4201
- let index
4202
- for (let id in this.indexes) {
4203
- index = this.indexes[id]
4204
- if (existIndex <= index) {
4205
- this.indexes[id] = index + nodes.length
4206
- }
4207
- }
4208
-
4209
- this.markDirty()
4210
-
4291
+ push(child) {
4292
+ child.parent = this
4293
+ this.proxyOf.nodes.push(child)
4211
4294
  return this
4212
4295
  }
4213
4296
 
4214
- insertAfter(exist, add) {
4215
- let existIndex = this.index(exist)
4216
- let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse()
4217
- existIndex = this.index(exist)
4218
- for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node)
4219
-
4220
- let index
4221
- for (let id in this.indexes) {
4222
- index = this.indexes[id]
4223
- if (existIndex < index) {
4224
- this.indexes[id] = index + nodes.length
4225
- }
4226
- }
4297
+ removeAll() {
4298
+ for (let node of this.proxyOf.nodes) node.parent = undefined
4299
+ this.proxyOf.nodes = []
4227
4300
 
4228
4301
  this.markDirty()
4229
4302
 
@@ -4248,15 +4321,6 @@ class Container extends Node {
4248
4321
  return this
4249
4322
  }
4250
4323
 
4251
- removeAll() {
4252
- for (let node of this.proxyOf.nodes) node.parent = undefined
4253
- this.proxyOf.nodes = []
4254
-
4255
- this.markDirty()
4256
-
4257
- return this
4258
- }
4259
-
4260
4324
  replaceValues(pattern, opts, callback) {
4261
4325
  if (!callback) {
4262
4326
  callback = opts
@@ -4275,139 +4339,112 @@ class Container extends Node {
4275
4339
  return this
4276
4340
  }
4277
4341
 
4278
- every(condition) {
4279
- return this.nodes.every(condition)
4280
- }
4281
-
4282
4342
  some(condition) {
4283
4343
  return this.nodes.some(condition)
4284
4344
  }
4285
4345
 
4286
- index(child) {
4287
- if (typeof child === 'number') return child
4288
- if (child.proxyOf) child = child.proxyOf
4289
- return this.proxyOf.nodes.indexOf(child)
4290
- }
4346
+ walk(callback) {
4347
+ return this.each((child, i) => {
4348
+ let result
4349
+ try {
4350
+ result = callback(child, i)
4351
+ } catch (e) {
4352
+ throw child.addToError(e)
4353
+ }
4354
+ if (result !== false && child.walk) {
4355
+ result = child.walk(callback)
4356
+ }
4291
4357
 
4292
- get first() {
4293
- if (!this.proxyOf.nodes) return undefined
4294
- return this.proxyOf.nodes[0]
4358
+ return result
4359
+ })
4295
4360
  }
4296
4361
 
4297
- get last() {
4298
- if (!this.proxyOf.nodes) return undefined
4299
- return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
4362
+ walkAtRules(name, callback) {
4363
+ if (!callback) {
4364
+ callback = name
4365
+ return this.walk((child, i) => {
4366
+ if (child.type === 'atrule') {
4367
+ return callback(child, i)
4368
+ }
4369
+ })
4370
+ }
4371
+ if (name instanceof RegExp) {
4372
+ return this.walk((child, i) => {
4373
+ if (child.type === 'atrule' && name.test(child.name)) {
4374
+ return callback(child, i)
4375
+ }
4376
+ })
4377
+ }
4378
+ return this.walk((child, i) => {
4379
+ if (child.type === 'atrule' && child.name === name) {
4380
+ return callback(child, i)
4381
+ }
4382
+ })
4300
4383
  }
4301
4384
 
4302
- normalize(nodes, sample) {
4303
- if (typeof nodes === 'string') {
4304
- nodes = cleanSource(parse(nodes).nodes)
4305
- } else if (Array.isArray(nodes)) {
4306
- nodes = nodes.slice(0)
4307
- for (let i of nodes) {
4308
- if (i.parent) i.parent.removeChild(i, 'ignore')
4309
- }
4310
- } else if (nodes.type === 'root' && this.type !== 'document') {
4311
- nodes = nodes.nodes.slice(0)
4312
- for (let i of nodes) {
4313
- if (i.parent) i.parent.removeChild(i, 'ignore')
4314
- }
4315
- } else if (nodes.type) {
4316
- nodes = [nodes]
4317
- } else if (nodes.prop) {
4318
- if (typeof nodes.value === 'undefined') {
4319
- throw new Error('Value field is missed in node creation')
4320
- } else if (typeof nodes.value !== 'string') {
4321
- nodes.value = String(nodes.value)
4385
+ walkComments(callback) {
4386
+ return this.walk((child, i) => {
4387
+ if (child.type === 'comment') {
4388
+ return callback(child, i)
4322
4389
  }
4323
- nodes = [new Declaration(nodes)]
4324
- } else if (nodes.selector) {
4325
- nodes = [new Rule(nodes)]
4326
- } else if (nodes.name) {
4327
- nodes = [new AtRule(nodes)]
4328
- } else if (nodes.text) {
4329
- nodes = [new Comment(nodes)]
4330
- } else {
4331
- throw new Error('Unknown node type in node creation')
4332
- }
4390
+ })
4391
+ }
4333
4392
 
4334
- let processed = nodes.map(i => {
4335
- /* c8 ignore next */
4336
- if (!i[my]) Container.rebuild(i)
4337
- i = i.proxyOf
4338
- if (i.parent) i.parent.removeChild(i)
4339
- if (i[isClean]) markDirtyUp(i)
4340
- if (typeof i.raws.before === 'undefined') {
4341
- if (sample && typeof sample.raws.before !== 'undefined') {
4342
- i.raws.before = sample.raws.before.replace(/\S/g, '')
4393
+ walkDecls(prop, callback) {
4394
+ if (!callback) {
4395
+ callback = prop
4396
+ return this.walk((child, i) => {
4397
+ if (child.type === 'decl') {
4398
+ return callback(child, i)
4399
+ }
4400
+ })
4401
+ }
4402
+ if (prop instanceof RegExp) {
4403
+ return this.walk((child, i) => {
4404
+ if (child.type === 'decl' && prop.test(child.prop)) {
4405
+ return callback(child, i)
4343
4406
  }
4407
+ })
4408
+ }
4409
+ return this.walk((child, i) => {
4410
+ if (child.type === 'decl' && child.prop === prop) {
4411
+ return callback(child, i)
4344
4412
  }
4345
- i.parent = this.proxyOf
4346
- return i
4347
4413
  })
4348
-
4349
- return processed
4350
4414
  }
4351
4415
 
4352
- getProxyProcessor() {
4353
- return {
4354
- set(node, prop, value) {
4355
- if (node[prop] === value) return true
4356
- node[prop] = value
4357
- if (prop === 'name' || prop === 'params' || prop === 'selector') {
4358
- node.markDirty()
4359
- }
4360
- return true
4361
- },
4416
+ walkRules(selector, callback) {
4417
+ if (!callback) {
4418
+ callback = selector
4362
4419
 
4363
- get(node, prop) {
4364
- if (prop === 'proxyOf') {
4365
- return node
4366
- } else if (!node[prop]) {
4367
- return node[prop]
4368
- } else if (
4369
- prop === 'each' ||
4370
- (typeof prop === 'string' && prop.startsWith('walk'))
4371
- ) {
4372
- return (...args) => {
4373
- return node[prop](
4374
- ...args.map(i => {
4375
- if (typeof i === 'function') {
4376
- return (child, index) => i(child.toProxy(), index)
4377
- } else {
4378
- return i
4379
- }
4380
- })
4381
- )
4382
- }
4383
- } else if (prop === 'every' || prop === 'some') {
4384
- return cb => {
4385
- return node[prop]((child, ...other) =>
4386
- cb(child.toProxy(), ...other)
4387
- )
4388
- }
4389
- } else if (prop === 'root') {
4390
- return () => node.root().toProxy()
4391
- } else if (prop === 'nodes') {
4392
- return node.nodes.map(i => i.toProxy())
4393
- } else if (prop === 'first' || prop === 'last') {
4394
- return node[prop].toProxy()
4395
- } else {
4396
- return node[prop]
4420
+ return this.walk((child, i) => {
4421
+ if (child.type === 'rule') {
4422
+ return callback(child, i)
4397
4423
  }
4398
- }
4424
+ })
4399
4425
  }
4426
+ if (selector instanceof RegExp) {
4427
+ return this.walk((child, i) => {
4428
+ if (child.type === 'rule' && selector.test(child.selector)) {
4429
+ return callback(child, i)
4430
+ }
4431
+ })
4432
+ }
4433
+ return this.walk((child, i) => {
4434
+ if (child.type === 'rule' && child.selector === selector) {
4435
+ return callback(child, i)
4436
+ }
4437
+ })
4400
4438
  }
4401
4439
 
4402
- getIterator() {
4403
- if (!this.lastEach) this.lastEach = 0
4404
- if (!this.indexes) this.indexes = {}
4405
-
4406
- this.lastEach += 1
4407
- let iterator = this.lastEach
4408
- this.indexes[iterator] = 0
4440
+ get first() {
4441
+ if (!this.proxyOf.nodes) return undefined
4442
+ return this.proxyOf.nodes[0]
4443
+ }
4409
4444
 
4410
- return iterator
4445
+ get last() {
4446
+ if (!this.proxyOf.nodes) return undefined
4447
+ return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
4411
4448
  }
4412
4449
  }
4413
4450
 
@@ -4527,7 +4564,7 @@ class CssSyntaxError extends Error {
4527
4564
 
4528
4565
  let mark, aside
4529
4566
  if (color) {
4530
- let { bold, red, gray } = pico.createColors(true)
4567
+ let { bold, gray, red } = pico.createColors(true)
4531
4568
  mark = text => bold(red(text))
4532
4569
  aside = text => gray(text)
4533
4570
  } else {
@@ -4708,7 +4745,7 @@ fromJSON.default = fromJSON
4708
4745
 
4709
4746
  let { SourceMapConsumer, SourceMapGenerator } = __nccwpck_require__(175)
4710
4747
  let { fileURLToPath, pathToFileURL } = __nccwpck_require__(7310)
4711
- let { resolve, isAbsolute } = __nccwpck_require__(1017)
4748
+ let { isAbsolute, resolve } = __nccwpck_require__(1017)
4712
4749
  let { nanoid } = __nccwpck_require__(4951)
4713
4750
 
4714
4751
  let terminalHighlight = __nccwpck_require__(1526)
@@ -4766,48 +4803,6 @@ class Input {
4766
4803
  if (this.map) this.map.file = this.from
4767
4804
  }
4768
4805
 
4769
- fromOffset(offset) {
4770
- let lastLine, lineToIndex
4771
- if (!this[fromOffsetCache]) {
4772
- let lines = this.css.split('\n')
4773
- lineToIndex = new Array(lines.length)
4774
- let prevIndex = 0
4775
-
4776
- for (let i = 0, l = lines.length; i < l; i++) {
4777
- lineToIndex[i] = prevIndex
4778
- prevIndex += lines[i].length + 1
4779
- }
4780
-
4781
- this[fromOffsetCache] = lineToIndex
4782
- } else {
4783
- lineToIndex = this[fromOffsetCache]
4784
- }
4785
- lastLine = lineToIndex[lineToIndex.length - 1]
4786
-
4787
- let min = 0
4788
- if (offset >= lastLine) {
4789
- min = lineToIndex.length - 1
4790
- } else {
4791
- let max = lineToIndex.length - 2
4792
- let mid
4793
- while (min < max) {
4794
- mid = min + ((max - min) >> 1)
4795
- if (offset < lineToIndex[mid]) {
4796
- max = mid - 1
4797
- } else if (offset >= lineToIndex[mid + 1]) {
4798
- min = mid + 1
4799
- } else {
4800
- min = mid
4801
- break
4802
- }
4803
- }
4804
- }
4805
- return {
4806
- line: min + 1,
4807
- col: offset - lineToIndex[min] + 1
4808
- }
4809
- }
4810
-
4811
4806
  error(message, line, column, opts = {}) {
4812
4807
  let result, endLine, endColumn
4813
4808
 
@@ -4842,10 +4837,10 @@ class Input {
4842
4837
  message,
4843
4838
  origin.endLine === undefined
4844
4839
  ? origin.line
4845
- : { line: origin.line, column: origin.column },
4840
+ : { column: origin.column, line: origin.line },
4846
4841
  origin.endLine === undefined
4847
4842
  ? origin.column
4848
- : { line: origin.endLine, column: origin.endColumn },
4843
+ : { column: origin.endColumn, line: origin.endLine },
4849
4844
  origin.source,
4850
4845
  origin.file,
4851
4846
  opts.plugin
@@ -4853,35 +4848,84 @@ class Input {
4853
4848
  } else {
4854
4849
  result = new CssSyntaxError(
4855
4850
  message,
4856
- endLine === undefined ? line : { line, column },
4857
- endLine === undefined ? column : { line: endLine, column: endColumn },
4851
+ endLine === undefined ? line : { column, line },
4852
+ endLine === undefined ? column : { column: endColumn, line: endLine },
4858
4853
  this.css,
4859
4854
  this.file,
4860
4855
  opts.plugin
4861
4856
  )
4862
4857
  }
4863
4858
 
4864
- result.input = { line, column, endLine, endColumn, source: this.css }
4865
- if (this.file) {
4866
- if (pathToFileURL) {
4867
- result.input.url = pathToFileURL(this.file).toString()
4859
+ result.input = { column, endColumn, endLine, line, source: this.css }
4860
+ if (this.file) {
4861
+ if (pathToFileURL) {
4862
+ result.input.url = pathToFileURL(this.file).toString()
4863
+ }
4864
+ result.input.file = this.file
4865
+ }
4866
+
4867
+ return result
4868
+ }
4869
+
4870
+ fromOffset(offset) {
4871
+ let lastLine, lineToIndex
4872
+ if (!this[fromOffsetCache]) {
4873
+ let lines = this.css.split('\n')
4874
+ lineToIndex = new Array(lines.length)
4875
+ let prevIndex = 0
4876
+
4877
+ for (let i = 0, l = lines.length; i < l; i++) {
4878
+ lineToIndex[i] = prevIndex
4879
+ prevIndex += lines[i].length + 1
4880
+ }
4881
+
4882
+ this[fromOffsetCache] = lineToIndex
4883
+ } else {
4884
+ lineToIndex = this[fromOffsetCache]
4885
+ }
4886
+ lastLine = lineToIndex[lineToIndex.length - 1]
4887
+
4888
+ let min = 0
4889
+ if (offset >= lastLine) {
4890
+ min = lineToIndex.length - 1
4891
+ } else {
4892
+ let max = lineToIndex.length - 2
4893
+ let mid
4894
+ while (min < max) {
4895
+ mid = min + ((max - min) >> 1)
4896
+ if (offset < lineToIndex[mid]) {
4897
+ max = mid - 1
4898
+ } else if (offset >= lineToIndex[mid + 1]) {
4899
+ min = mid + 1
4900
+ } else {
4901
+ min = mid
4902
+ break
4903
+ }
4868
4904
  }
4869
- result.input.file = this.file
4870
4905
  }
4906
+ return {
4907
+ col: offset - lineToIndex[min] + 1,
4908
+ line: min + 1
4909
+ }
4910
+ }
4871
4911
 
4872
- return result
4912
+ mapResolve(file) {
4913
+ if (/^\w+:\/\//.test(file)) {
4914
+ return file
4915
+ }
4916
+ return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
4873
4917
  }
4874
4918
 
4875
4919
  origin(line, column, endLine, endColumn) {
4876
4920
  if (!this.map) return false
4877
4921
  let consumer = this.map.consumer()
4878
4922
 
4879
- let from = consumer.originalPositionFor({ line, column })
4923
+ let from = consumer.originalPositionFor({ column, line })
4880
4924
  if (!from.source) return false
4881
4925
 
4882
4926
  let to
4883
4927
  if (typeof endLine === 'number') {
4884
- to = consumer.originalPositionFor({ line: endLine, column: endColumn })
4928
+ to = consumer.originalPositionFor({ column: endColumn, line: endLine })
4885
4929
  }
4886
4930
 
4887
4931
  let fromUrl
@@ -4896,11 +4940,11 @@ class Input {
4896
4940
  }
4897
4941
 
4898
4942
  let result = {
4899
- url: fromUrl.toString(),
4900
- line: from.line,
4901
4943
  column: from.column,
4944
+ endColumn: to && to.column,
4902
4945
  endLine: to && to.line,
4903
- endColumn: to && to.column
4946
+ line: from.line,
4947
+ url: fromUrl.toString()
4904
4948
  }
4905
4949
 
4906
4950
  if (fromUrl.protocol === 'file:') {
@@ -4918,17 +4962,6 @@ class Input {
4918
4962
  return result
4919
4963
  }
4920
4964
 
4921
- mapResolve(file) {
4922
- if (/^\w+:\/\//.test(file)) {
4923
- return file
4924
- }
4925
- return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
4926
- }
4927
-
4928
- get from() {
4929
- return this.file || this.id
4930
- }
4931
-
4932
4965
  toJSON() {
4933
4966
  let json = {}
4934
4967
  for (let name of ['hasBOM', 'css', 'file', 'id']) {
@@ -4944,6 +4977,10 @@ class Input {
4944
4977
  }
4945
4978
  return json
4946
4979
  }
4980
+
4981
+ get from() {
4982
+ return this.file || this.id
4983
+ }
4947
4984
  }
4948
4985
 
4949
4986
  module.exports = Input
@@ -4973,37 +5010,37 @@ let parse = __nccwpck_require__(8317)
4973
5010
  let Root = __nccwpck_require__(9659)
4974
5011
 
4975
5012
  const TYPE_TO_CLASS_NAME = {
4976
- document: 'Document',
4977
- root: 'Root',
4978
5013
  atrule: 'AtRule',
4979
- rule: 'Rule',
5014
+ comment: 'Comment',
4980
5015
  decl: 'Declaration',
4981
- comment: 'Comment'
5016
+ document: 'Document',
5017
+ root: 'Root',
5018
+ rule: 'Rule'
4982
5019
  }
4983
5020
 
4984
5021
  const PLUGIN_PROPS = {
4985
- postcssPlugin: true,
4986
- prepare: true,
4987
- Once: true,
4988
- Document: true,
4989
- Root: true,
4990
- Declaration: true,
4991
- Rule: true,
4992
5022
  AtRule: true,
4993
- Comment: true,
4994
- DeclarationExit: true,
4995
- RuleExit: true,
4996
5023
  AtRuleExit: true,
5024
+ Comment: true,
4997
5025
  CommentExit: true,
4998
- RootExit: true,
5026
+ Declaration: true,
5027
+ DeclarationExit: true,
5028
+ Document: true,
4999
5029
  DocumentExit: true,
5000
- OnceExit: true
5030
+ Once: true,
5031
+ OnceExit: true,
5032
+ postcssPlugin: true,
5033
+ prepare: true,
5034
+ Root: true,
5035
+ RootExit: true,
5036
+ Rule: true,
5037
+ RuleExit: true
5001
5038
  }
5002
5039
 
5003
5040
  const NOT_VISITORS = {
5041
+ Once: true,
5004
5042
  postcssPlugin: true,
5005
- prepare: true,
5006
- Once: true
5043
+ prepare: true
5007
5044
  }
5008
5045
 
5009
5046
  const CHILDREN = 0
@@ -5049,260 +5086,87 @@ function toStack(node) {
5049
5086
  }
5050
5087
 
5051
5088
  return {
5052
- node,
5053
- events,
5054
5089
  eventIndex: 0,
5055
- visitors: [],
5056
- visitorIndex: 0,
5057
- iterator: 0
5058
- }
5059
- }
5060
-
5061
- function cleanMarks(node) {
5062
- node[isClean] = false
5063
- if (node.nodes) node.nodes.forEach(i => cleanMarks(i))
5064
- return node
5065
- }
5066
-
5067
- let postcss = {}
5068
-
5069
- class LazyResult {
5070
- constructor(processor, css, opts) {
5071
- this.stringified = false
5072
- this.processed = false
5073
-
5074
- let root
5075
- if (
5076
- typeof css === 'object' &&
5077
- css !== null &&
5078
- (css.type === 'root' || css.type === 'document')
5079
- ) {
5080
- root = cleanMarks(css)
5081
- } else if (css instanceof LazyResult || css instanceof Result) {
5082
- root = cleanMarks(css.root)
5083
- if (css.map) {
5084
- if (typeof opts.map === 'undefined') opts.map = {}
5085
- if (!opts.map.inline) opts.map.inline = false
5086
- opts.map.prev = css.map
5087
- }
5088
- } else {
5089
- let parser = parse
5090
- if (opts.syntax) parser = opts.syntax.parse
5091
- if (opts.parser) parser = opts.parser
5092
- if (parser.parse) parser = parser.parse
5093
-
5094
- try {
5095
- root = parser(css, opts)
5096
- } catch (error) {
5097
- this.processed = true
5098
- this.error = error
5099
- }
5100
-
5101
- if (root && !root[my]) {
5102
- /* c8 ignore next 2 */
5103
- Container.rebuild(root)
5104
- }
5105
- }
5106
-
5107
- this.result = new Result(processor, root, opts)
5108
- this.helpers = { ...postcss, result: this.result, postcss }
5109
- this.plugins = this.processor.plugins.map(plugin => {
5110
- if (typeof plugin === 'object' && plugin.prepare) {
5111
- return { ...plugin, ...plugin.prepare(this.result) }
5112
- } else {
5113
- return plugin
5114
- }
5115
- })
5116
- }
5117
-
5118
- get [Symbol.toStringTag]() {
5119
- return 'LazyResult'
5120
- }
5121
-
5122
- get processor() {
5123
- return this.result.processor
5124
- }
5125
-
5126
- get opts() {
5127
- return this.result.opts
5128
- }
5129
-
5130
- get css() {
5131
- return this.stringify().css
5132
- }
5133
-
5134
- get content() {
5135
- return this.stringify().content
5136
- }
5137
-
5138
- get map() {
5139
- return this.stringify().map
5140
- }
5141
-
5142
- get root() {
5143
- return this.sync().root
5144
- }
5145
-
5146
- get messages() {
5147
- return this.sync().messages
5148
- }
5149
-
5150
- warnings() {
5151
- return this.sync().warnings()
5152
- }
5153
-
5154
- toString() {
5155
- return this.css
5156
- }
5157
-
5158
- then(onFulfilled, onRejected) {
5159
- if (process.env.NODE_ENV !== 'production') {
5160
- if (!('from' in this.opts)) {
5161
- warnOnce(
5162
- 'Without `from` option PostCSS could generate wrong source map ' +
5163
- 'and will not find Browserslist config. Set it to CSS file path ' +
5164
- 'or to `undefined` to prevent this warning.'
5165
- )
5166
- }
5167
- }
5168
- return this.async().then(onFulfilled, onRejected)
5169
- }
5170
-
5171
- catch(onRejected) {
5172
- return this.async().catch(onRejected)
5173
- }
5174
-
5175
- finally(onFinally) {
5176
- return this.async().then(onFinally, onFinally)
5177
- }
5178
-
5179
- async() {
5180
- if (this.error) return Promise.reject(this.error)
5181
- if (this.processed) return Promise.resolve(this.result)
5182
- if (!this.processing) {
5183
- this.processing = this.runAsync()
5184
- }
5185
- return this.processing
5186
- }
5187
-
5188
- sync() {
5189
- if (this.error) throw this.error
5190
- if (this.processed) return this.result
5191
- this.processed = true
5192
-
5193
- if (this.processing) {
5194
- throw this.getAsyncError()
5195
- }
5196
-
5197
- for (let plugin of this.plugins) {
5198
- let promise = this.runOnRoot(plugin)
5199
- if (isPromise(promise)) {
5200
- throw this.getAsyncError()
5201
- }
5202
- }
5203
-
5204
- this.prepareVisitors()
5205
- if (this.hasListener) {
5206
- let root = this.result.root
5207
- while (!root[isClean]) {
5208
- root[isClean] = true
5209
- this.walkSync(root)
5210
- }
5211
- if (this.listeners.OnceExit) {
5212
- if (root.type === 'document') {
5213
- for (let subRoot of root.nodes) {
5214
- this.visitSync(this.listeners.OnceExit, subRoot)
5215
- }
5216
- } else {
5217
- this.visitSync(this.listeners.OnceExit, root)
5218
- }
5219
- }
5220
- }
5221
-
5222
- return this.result
5223
- }
5224
-
5225
- stringify() {
5226
- if (this.error) throw this.error
5227
- if (this.stringified) return this.result
5228
- this.stringified = true
5229
-
5230
- this.sync()
5090
+ events,
5091
+ iterator: 0,
5092
+ node,
5093
+ visitorIndex: 0,
5094
+ visitors: []
5095
+ }
5096
+ }
5231
5097
 
5232
- let opts = this.result.opts
5233
- let str = stringify
5234
- if (opts.syntax) str = opts.syntax.stringify
5235
- if (opts.stringifier) str = opts.stringifier
5236
- if (str.stringify) str = str.stringify
5098
+ function cleanMarks(node) {
5099
+ node[isClean] = false
5100
+ if (node.nodes) node.nodes.forEach(i => cleanMarks(i))
5101
+ return node
5102
+ }
5237
5103
 
5238
- let map = new MapGenerator(str, this.result.root, this.result.opts)
5239
- let data = map.generate()
5240
- this.result.css = data[0]
5241
- this.result.map = data[1]
5104
+ let postcss = {}
5242
5105
 
5243
- return this.result
5244
- }
5106
+ class LazyResult {
5107
+ constructor(processor, css, opts) {
5108
+ this.stringified = false
5109
+ this.processed = false
5245
5110
 
5246
- walkSync(node) {
5247
- node[isClean] = true
5248
- let events = getEvents(node)
5249
- for (let event of events) {
5250
- if (event === CHILDREN) {
5251
- if (node.nodes) {
5252
- node.each(child => {
5253
- if (!child[isClean]) this.walkSync(child)
5254
- })
5255
- }
5256
- } else {
5257
- let visitors = this.listeners[event]
5258
- if (visitors) {
5259
- if (this.visitSync(visitors, node.toProxy())) return
5260
- }
5111
+ let root
5112
+ if (
5113
+ typeof css === 'object' &&
5114
+ css !== null &&
5115
+ (css.type === 'root' || css.type === 'document')
5116
+ ) {
5117
+ root = cleanMarks(css)
5118
+ } else if (css instanceof LazyResult || css instanceof Result) {
5119
+ root = cleanMarks(css.root)
5120
+ if (css.map) {
5121
+ if (typeof opts.map === 'undefined') opts.map = {}
5122
+ if (!opts.map.inline) opts.map.inline = false
5123
+ opts.map.prev = css.map
5261
5124
  }
5262
- }
5263
- }
5125
+ } else {
5126
+ let parser = parse
5127
+ if (opts.syntax) parser = opts.syntax.parse
5128
+ if (opts.parser) parser = opts.parser
5129
+ if (parser.parse) parser = parser.parse
5264
5130
 
5265
- visitSync(visitors, node) {
5266
- for (let [plugin, visitor] of visitors) {
5267
- this.result.lastPlugin = plugin
5268
- let promise
5269
5131
  try {
5270
- promise = visitor(node, this.helpers)
5271
- } catch (e) {
5272
- throw this.handleError(e, node.proxyOf)
5273
- }
5274
- if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
5275
- return true
5132
+ root = parser(css, opts)
5133
+ } catch (error) {
5134
+ this.processed = true
5135
+ this.error = error
5276
5136
  }
5277
- if (isPromise(promise)) {
5278
- throw this.getAsyncError()
5137
+
5138
+ if (root && !root[my]) {
5139
+ /* c8 ignore next 2 */
5140
+ Container.rebuild(root)
5279
5141
  }
5280
5142
  }
5281
- }
5282
5143
 
5283
- runOnRoot(plugin) {
5284
- this.result.lastPlugin = plugin
5285
- try {
5286
- if (typeof plugin === 'object' && plugin.Once) {
5287
- if (this.result.root.type === 'document') {
5288
- let roots = this.result.root.nodes.map(root =>
5289
- plugin.Once(root, this.helpers)
5290
- )
5144
+ this.result = new Result(processor, root, opts)
5145
+ this.helpers = { ...postcss, postcss, result: this.result }
5146
+ this.plugins = this.processor.plugins.map(plugin => {
5147
+ if (typeof plugin === 'object' && plugin.prepare) {
5148
+ return { ...plugin, ...plugin.prepare(this.result) }
5149
+ } else {
5150
+ return plugin
5151
+ }
5152
+ })
5153
+ }
5291
5154
 
5292
- if (isPromise(roots[0])) {
5293
- return Promise.all(roots)
5294
- }
5155
+ async() {
5156
+ if (this.error) return Promise.reject(this.error)
5157
+ if (this.processed) return Promise.resolve(this.result)
5158
+ if (!this.processing) {
5159
+ this.processing = this.runAsync()
5160
+ }
5161
+ return this.processing
5162
+ }
5295
5163
 
5296
- return roots
5297
- }
5164
+ catch(onRejected) {
5165
+ return this.async().catch(onRejected)
5166
+ }
5298
5167
 
5299
- return plugin.Once(this.result.root, this.helpers)
5300
- } else if (typeof plugin === 'function') {
5301
- return plugin(this.result.root, this.result)
5302
- }
5303
- } catch (error) {
5304
- throw this.handleError(error)
5305
- }
5168
+ finally(onFinally) {
5169
+ return this.async().then(onFinally, onFinally)
5306
5170
  }
5307
5171
 
5308
5172
  getAsyncError() {
@@ -5348,6 +5212,44 @@ class LazyResult {
5348
5212
  return error
5349
5213
  }
5350
5214
 
5215
+ prepareVisitors() {
5216
+ this.listeners = {}
5217
+ let add = (plugin, type, cb) => {
5218
+ if (!this.listeners[type]) this.listeners[type] = []
5219
+ this.listeners[type].push([plugin, cb])
5220
+ }
5221
+ for (let plugin of this.plugins) {
5222
+ if (typeof plugin === 'object') {
5223
+ for (let event in plugin) {
5224
+ if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
5225
+ throw new Error(
5226
+ `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
5227
+ `Try to update PostCSS (${this.processor.version} now).`
5228
+ )
5229
+ }
5230
+ if (!NOT_VISITORS[event]) {
5231
+ if (typeof plugin[event] === 'object') {
5232
+ for (let filter in plugin[event]) {
5233
+ if (filter === '*') {
5234
+ add(plugin, event, plugin[event][filter])
5235
+ } else {
5236
+ add(
5237
+ plugin,
5238
+ event + '-' + filter.toLowerCase(),
5239
+ plugin[event][filter]
5240
+ )
5241
+ }
5242
+ }
5243
+ } else if (typeof plugin[event] === 'function') {
5244
+ add(plugin, event, plugin[event])
5245
+ }
5246
+ }
5247
+ }
5248
+ }
5249
+ }
5250
+ this.hasListener = Object.keys(this.listeners).length > 0
5251
+ }
5252
+
5351
5253
  async runAsync() {
5352
5254
  this.plugin = 0
5353
5255
  for (let i = 0; i < this.plugins.length; i++) {
@@ -5405,42 +5307,122 @@ class LazyResult {
5405
5307
  return this.stringify()
5406
5308
  }
5407
5309
 
5408
- prepareVisitors() {
5409
- this.listeners = {}
5410
- let add = (plugin, type, cb) => {
5411
- if (!this.listeners[type]) this.listeners[type] = []
5412
- this.listeners[type].push([plugin, cb])
5310
+ runOnRoot(plugin) {
5311
+ this.result.lastPlugin = plugin
5312
+ try {
5313
+ if (typeof plugin === 'object' && plugin.Once) {
5314
+ if (this.result.root.type === 'document') {
5315
+ let roots = this.result.root.nodes.map(root =>
5316
+ plugin.Once(root, this.helpers)
5317
+ )
5318
+
5319
+ if (isPromise(roots[0])) {
5320
+ return Promise.all(roots)
5321
+ }
5322
+
5323
+ return roots
5324
+ }
5325
+
5326
+ return plugin.Once(this.result.root, this.helpers)
5327
+ } else if (typeof plugin === 'function') {
5328
+ return plugin(this.result.root, this.result)
5329
+ }
5330
+ } catch (error) {
5331
+ throw this.handleError(error)
5332
+ }
5333
+ }
5334
+
5335
+ stringify() {
5336
+ if (this.error) throw this.error
5337
+ if (this.stringified) return this.result
5338
+ this.stringified = true
5339
+
5340
+ this.sync()
5341
+
5342
+ let opts = this.result.opts
5343
+ let str = stringify
5344
+ if (opts.syntax) str = opts.syntax.stringify
5345
+ if (opts.stringifier) str = opts.stringifier
5346
+ if (str.stringify) str = str.stringify
5347
+
5348
+ let map = new MapGenerator(str, this.result.root, this.result.opts)
5349
+ let data = map.generate()
5350
+ this.result.css = data[0]
5351
+ this.result.map = data[1]
5352
+
5353
+ return this.result
5354
+ }
5355
+
5356
+ sync() {
5357
+ if (this.error) throw this.error
5358
+ if (this.processed) return this.result
5359
+ this.processed = true
5360
+
5361
+ if (this.processing) {
5362
+ throw this.getAsyncError()
5413
5363
  }
5364
+
5414
5365
  for (let plugin of this.plugins) {
5415
- if (typeof plugin === 'object') {
5416
- for (let event in plugin) {
5417
- if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
5418
- throw new Error(
5419
- `Unknown event ${event} in ${plugin.postcssPlugin}. ` +
5420
- `Try to update PostCSS (${this.processor.version} now).`
5421
- )
5422
- }
5423
- if (!NOT_VISITORS[event]) {
5424
- if (typeof plugin[event] === 'object') {
5425
- for (let filter in plugin[event]) {
5426
- if (filter === '*') {
5427
- add(plugin, event, plugin[event][filter])
5428
- } else {
5429
- add(
5430
- plugin,
5431
- event + '-' + filter.toLowerCase(),
5432
- plugin[event][filter]
5433
- )
5434
- }
5435
- }
5436
- } else if (typeof plugin[event] === 'function') {
5437
- add(plugin, event, plugin[event])
5438
- }
5366
+ let promise = this.runOnRoot(plugin)
5367
+ if (isPromise(promise)) {
5368
+ throw this.getAsyncError()
5369
+ }
5370
+ }
5371
+
5372
+ this.prepareVisitors()
5373
+ if (this.hasListener) {
5374
+ let root = this.result.root
5375
+ while (!root[isClean]) {
5376
+ root[isClean] = true
5377
+ this.walkSync(root)
5378
+ }
5379
+ if (this.listeners.OnceExit) {
5380
+ if (root.type === 'document') {
5381
+ for (let subRoot of root.nodes) {
5382
+ this.visitSync(this.listeners.OnceExit, subRoot)
5439
5383
  }
5384
+ } else {
5385
+ this.visitSync(this.listeners.OnceExit, root)
5440
5386
  }
5441
5387
  }
5442
5388
  }
5443
- this.hasListener = Object.keys(this.listeners).length > 0
5389
+
5390
+ return this.result
5391
+ }
5392
+
5393
+ then(onFulfilled, onRejected) {
5394
+ if (process.env.NODE_ENV !== 'production') {
5395
+ if (!('from' in this.opts)) {
5396
+ warnOnce(
5397
+ 'Without `from` option PostCSS could generate wrong source map ' +
5398
+ 'and will not find Browserslist config. Set it to CSS file path ' +
5399
+ 'or to `undefined` to prevent this warning.'
5400
+ )
5401
+ }
5402
+ }
5403
+ return this.async().then(onFulfilled, onRejected)
5404
+ }
5405
+
5406
+ toString() {
5407
+ return this.css
5408
+ }
5409
+
5410
+ visitSync(visitors, node) {
5411
+ for (let [plugin, visitor] of visitors) {
5412
+ this.result.lastPlugin = plugin
5413
+ let promise
5414
+ try {
5415
+ promise = visitor(node, this.helpers)
5416
+ } catch (e) {
5417
+ throw this.handleError(e, node.proxyOf)
5418
+ }
5419
+ if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
5420
+ return true
5421
+ }
5422
+ if (isPromise(promise)) {
5423
+ throw this.getAsyncError()
5424
+ }
5425
+ }
5444
5426
  }
5445
5427
 
5446
5428
  visitTick(stack) {
@@ -5499,6 +5481,61 @@ class LazyResult {
5499
5481
  }
5500
5482
  stack.pop()
5501
5483
  }
5484
+
5485
+ walkSync(node) {
5486
+ node[isClean] = true
5487
+ let events = getEvents(node)
5488
+ for (let event of events) {
5489
+ if (event === CHILDREN) {
5490
+ if (node.nodes) {
5491
+ node.each(child => {
5492
+ if (!child[isClean]) this.walkSync(child)
5493
+ })
5494
+ }
5495
+ } else {
5496
+ let visitors = this.listeners[event]
5497
+ if (visitors) {
5498
+ if (this.visitSync(visitors, node.toProxy())) return
5499
+ }
5500
+ }
5501
+ }
5502
+ }
5503
+
5504
+ warnings() {
5505
+ return this.sync().warnings()
5506
+ }
5507
+
5508
+ get content() {
5509
+ return this.stringify().content
5510
+ }
5511
+
5512
+ get css() {
5513
+ return this.stringify().css
5514
+ }
5515
+
5516
+ get map() {
5517
+ return this.stringify().map
5518
+ }
5519
+
5520
+ get messages() {
5521
+ return this.sync().messages
5522
+ }
5523
+
5524
+ get opts() {
5525
+ return this.result.opts
5526
+ }
5527
+
5528
+ get processor() {
5529
+ return this.result.processor
5530
+ }
5531
+
5532
+ get root() {
5533
+ return this.sync().root
5534
+ }
5535
+
5536
+ get [Symbol.toStringTag]() {
5537
+ return 'LazyResult'
5538
+ }
5502
5539
  }
5503
5540
 
5504
5541
  LazyResult.registerPostcss = dependant => {
@@ -5521,6 +5558,15 @@ Document.registerLazyResult(LazyResult)
5521
5558
 
5522
5559
 
5523
5560
  let list = {
5561
+ comma(string) {
5562
+ return list.split(string, [','], true)
5563
+ },
5564
+
5565
+ space(string) {
5566
+ let spaces = [' ', '\n', '\t']
5567
+ return list.split(string, spaces)
5568
+ },
5569
+
5524
5570
  split(string, separators, last) {
5525
5571
  let array = []
5526
5572
  let current = ''
@@ -5562,15 +5608,6 @@ let list = {
5562
5608
 
5563
5609
  if (last || current !== '') array.push(current.trim())
5564
5610
  return array
5565
- },
5566
-
5567
- space(string) {
5568
- let spaces = [' ', '\n', '\t']
5569
- return list.split(string, spaces)
5570
- },
5571
-
5572
- comma(string) {
5573
- return list.split(string, [','], true)
5574
5611
  }
5575
5612
  }
5576
5613
 
@@ -5587,7 +5624,7 @@ list.default = list
5587
5624
 
5588
5625
 
5589
5626
  let { SourceMapConsumer, SourceMapGenerator } = __nccwpck_require__(175)
5590
- let { dirname, resolve, relative, sep } = __nccwpck_require__(1017)
5627
+ let { dirname, relative, resolve, sep } = __nccwpck_require__(1017)
5591
5628
  let { pathToFileURL } = __nccwpck_require__(7310)
5592
5629
 
5593
5630
  let Input = __nccwpck_require__(5508)
@@ -5603,100 +5640,29 @@ class MapGenerator {
5603
5640
  this.opts = opts
5604
5641
  this.css = cssString
5605
5642
  this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
5606
- }
5607
-
5608
- isMap() {
5609
- if (typeof this.opts.map !== 'undefined') {
5610
- return !!this.opts.map
5611
- }
5612
- return this.previous().length > 0
5613
- }
5614
-
5615
- previous() {
5616
- if (!this.previousMaps) {
5617
- this.previousMaps = []
5618
- if (this.root) {
5619
- this.root.walk(node => {
5620
- if (node.source && node.source.input.map) {
5621
- let map = node.source.input.map
5622
- if (!this.previousMaps.includes(map)) {
5623
- this.previousMaps.push(map)
5624
- }
5625
- }
5626
- })
5627
- } else {
5628
- let input = new Input(this.css, this.opts)
5629
- if (input.map) this.previousMaps.push(input.map)
5630
- }
5631
- }
5632
-
5633
- return this.previousMaps
5634
- }
5635
-
5636
- isInline() {
5637
- if (typeof this.mapOpts.inline !== 'undefined') {
5638
- return this.mapOpts.inline
5639
- }
5640
-
5641
- let annotation = this.mapOpts.annotation
5642
- if (typeof annotation !== 'undefined' && annotation !== true) {
5643
- return false
5644
- }
5645
-
5646
- if (this.previous().length) {
5647
- return this.previous().some(i => i.inline)
5648
- }
5649
- return true
5650
- }
5651
5643
 
5652
- isSourcesContent() {
5653
- if (typeof this.mapOpts.sourcesContent !== 'undefined') {
5654
- return this.mapOpts.sourcesContent
5655
- }
5656
- if (this.previous().length) {
5657
- return this.previous().some(i => i.withContent())
5658
- }
5659
- return true
5644
+ this.memoizedFileURLs = new Map()
5645
+ this.memoizedPaths = new Map()
5646
+ this.memoizedURLs = new Map()
5660
5647
  }
5661
5648
 
5662
- clearAnnotation() {
5663
- if (this.mapOpts.annotation === false) return
5649
+ addAnnotation() {
5650
+ let content
5664
5651
 
5665
- if (this.root) {
5666
- let node
5667
- for (let i = this.root.nodes.length - 1; i >= 0; i--) {
5668
- node = this.root.nodes[i]
5669
- if (node.type !== 'comment') continue
5670
- if (node.text.indexOf('# sourceMappingURL=') === 0) {
5671
- this.root.removeChild(i)
5672
- }
5673
- }
5674
- } else if (this.css) {
5675
- this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
5652
+ if (this.isInline()) {
5653
+ content =
5654
+ 'data:application/json;base64,' + this.toBase64(this.map.toString())
5655
+ } else if (typeof this.mapOpts.annotation === 'string') {
5656
+ content = this.mapOpts.annotation
5657
+ } else if (typeof this.mapOpts.annotation === 'function') {
5658
+ content = this.mapOpts.annotation(this.opts.to, this.root)
5659
+ } else {
5660
+ content = this.outputFile() + '.map'
5676
5661
  }
5677
- }
5662
+ let eol = '\n'
5663
+ if (this.css.includes('\r\n')) eol = '\r\n'
5678
5664
 
5679
- setSourcesContent() {
5680
- let already = {}
5681
- if (this.root) {
5682
- this.root.walk(node => {
5683
- if (node.source) {
5684
- let from = node.source.input.from
5685
- if (from && !already[from]) {
5686
- already[from] = true
5687
- let fromUrl = this.usesFileUrls
5688
- ? this.toFileUrl(from)
5689
- : this.toUrl(this.path(from))
5690
- this.map.setSourceContent(fromUrl, node.source.input.css)
5691
- }
5692
- }
5693
- })
5694
- } else if (this.css) {
5695
- let from = this.opts.from
5696
- ? this.toUrl(this.path(this.opts.from))
5697
- : '<no source>'
5698
- this.map.setSourceContent(from, this.css)
5699
- }
5665
+ this.css += eol + '/*# sourceMappingURL=' + content + ' */'
5700
5666
  }
5701
5667
 
5702
5668
  applyPrevMaps() {
@@ -5714,57 +5680,37 @@ class MapGenerator {
5714
5680
  map = prev.consumer()
5715
5681
  }
5716
5682
 
5717
- this.map.applySourceMap(map, from, this.toUrl(this.path(root)))
5718
- }
5719
- }
5720
-
5721
- isAnnotation() {
5722
- if (this.isInline()) {
5723
- return true
5724
- }
5725
- if (typeof this.mapOpts.annotation !== 'undefined') {
5726
- return this.mapOpts.annotation
5727
- }
5728
- if (this.previous().length) {
5729
- return this.previous().some(i => i.annotation)
5730
- }
5731
- return true
5732
- }
5733
-
5734
- toBase64(str) {
5735
- if (Buffer) {
5736
- return Buffer.from(str).toString('base64')
5737
- } else {
5738
- return window.btoa(unescape(encodeURIComponent(str)))
5739
- }
5740
- }
5741
-
5742
- addAnnotation() {
5743
- let content
5744
-
5745
- if (this.isInline()) {
5746
- content =
5747
- 'data:application/json;base64,' + this.toBase64(this.map.toString())
5748
- } else if (typeof this.mapOpts.annotation === 'string') {
5749
- content = this.mapOpts.annotation
5750
- } else if (typeof this.mapOpts.annotation === 'function') {
5751
- content = this.mapOpts.annotation(this.opts.to, this.root)
5752
- } else {
5753
- content = this.outputFile() + '.map'
5683
+ this.map.applySourceMap(map, from, this.toUrl(this.path(root)))
5754
5684
  }
5755
- let eol = '\n'
5756
- if (this.css.includes('\r\n')) eol = '\r\n'
5685
+ }
5757
5686
 
5758
- this.css += eol + '/*# sourceMappingURL=' + content + ' */'
5687
+ clearAnnotation() {
5688
+ if (this.mapOpts.annotation === false) return
5689
+
5690
+ if (this.root) {
5691
+ let node
5692
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
5693
+ node = this.root.nodes[i]
5694
+ if (node.type !== 'comment') continue
5695
+ if (node.text.indexOf('# sourceMappingURL=') === 0) {
5696
+ this.root.removeChild(i)
5697
+ }
5698
+ }
5699
+ } else if (this.css) {
5700
+ this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
5701
+ }
5759
5702
  }
5760
5703
 
5761
- outputFile() {
5762
- if (this.opts.to) {
5763
- return this.path(this.opts.to)
5764
- } else if (this.opts.from) {
5765
- return this.path(this.opts.from)
5704
+ generate() {
5705
+ this.clearAnnotation()
5706
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
5707
+ return this.generateMap()
5766
5708
  } else {
5767
- return 'to.css'
5709
+ let result = ''
5710
+ this.stringify(this.root, i => {
5711
+ result += i
5712
+ })
5713
+ return [result]
5768
5714
  }
5769
5715
  }
5770
5716
 
@@ -5778,11 +5724,11 @@ class MapGenerator {
5778
5724
  } else {
5779
5725
  this.map = new SourceMapGenerator({ file: this.outputFile() })
5780
5726
  this.map.addMapping({
5727
+ generated: { column: 0, line: 1 },
5728
+ original: { column: 0, line: 1 },
5781
5729
  source: this.opts.from
5782
5730
  ? this.toUrl(this.path(this.opts.from))
5783
- : '<no source>',
5784
- generated: { line: 1, column: 0 },
5785
- original: { line: 1, column: 0 }
5731
+ : '<no source>'
5786
5732
  })
5787
5733
  }
5788
5734
 
@@ -5797,48 +5743,6 @@ class MapGenerator {
5797
5743
  }
5798
5744
  }
5799
5745
 
5800
- path(file) {
5801
- if (file.indexOf('<') === 0) return file
5802
- if (/^\w+:\/\//.test(file)) return file
5803
- if (this.mapOpts.absolute) return file
5804
-
5805
- let from = this.opts.to ? dirname(this.opts.to) : '.'
5806
-
5807
- if (typeof this.mapOpts.annotation === 'string') {
5808
- from = dirname(resolve(from, this.mapOpts.annotation))
5809
- }
5810
-
5811
- file = relative(from, file)
5812
- return file
5813
- }
5814
-
5815
- toUrl(path) {
5816
- if (sep === '\\') {
5817
- path = path.replace(/\\/g, '/')
5818
- }
5819
- return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
5820
- }
5821
-
5822
- toFileUrl(path) {
5823
- if (pathToFileURL) {
5824
- return pathToFileURL(path).toString()
5825
- } else {
5826
- throw new Error(
5827
- '`map.absolute` option is not available in this PostCSS build'
5828
- )
5829
- }
5830
- }
5831
-
5832
- sourcePath(node) {
5833
- if (this.mapOpts.from) {
5834
- return this.toUrl(this.mapOpts.from)
5835
- } else if (this.usesFileUrls) {
5836
- return this.toFileUrl(node.source.input.from)
5837
- } else {
5838
- return this.toUrl(this.path(node.source.input.from))
5839
- }
5840
- }
5841
-
5842
5746
  generateString() {
5843
5747
  this.css = ''
5844
5748
  this.map = new SourceMapGenerator({ file: this.outputFile() })
@@ -5848,9 +5752,9 @@ class MapGenerator {
5848
5752
 
5849
5753
  let noSource = '<no source>'
5850
5754
  let mapping = {
5851
- source: '',
5852
- generated: { line: 0, column: 0 },
5853
- original: { line: 0, column: 0 }
5755
+ generated: { column: 0, line: 0 },
5756
+ original: { column: 0, line: 0 },
5757
+ source: ''
5854
5758
  }
5855
5759
 
5856
5760
  let lines, last
@@ -5907,17 +5811,171 @@ class MapGenerator {
5907
5811
  })
5908
5812
  }
5909
5813
 
5910
- generate() {
5911
- this.clearAnnotation()
5912
- if (pathAvailable && sourceMapAvailable && this.isMap()) {
5913
- return this.generateMap()
5814
+ isAnnotation() {
5815
+ if (this.isInline()) {
5816
+ return true
5817
+ }
5818
+ if (typeof this.mapOpts.annotation !== 'undefined') {
5819
+ return this.mapOpts.annotation
5820
+ }
5821
+ if (this.previous().length) {
5822
+ return this.previous().some(i => i.annotation)
5823
+ }
5824
+ return true
5825
+ }
5826
+
5827
+ isInline() {
5828
+ if (typeof this.mapOpts.inline !== 'undefined') {
5829
+ return this.mapOpts.inline
5830
+ }
5831
+
5832
+ let annotation = this.mapOpts.annotation
5833
+ if (typeof annotation !== 'undefined' && annotation !== true) {
5834
+ return false
5835
+ }
5836
+
5837
+ if (this.previous().length) {
5838
+ return this.previous().some(i => i.inline)
5839
+ }
5840
+ return true
5841
+ }
5842
+
5843
+ isMap() {
5844
+ if (typeof this.opts.map !== 'undefined') {
5845
+ return !!this.opts.map
5846
+ }
5847
+ return this.previous().length > 0
5848
+ }
5849
+
5850
+ isSourcesContent() {
5851
+ if (typeof this.mapOpts.sourcesContent !== 'undefined') {
5852
+ return this.mapOpts.sourcesContent
5853
+ }
5854
+ if (this.previous().length) {
5855
+ return this.previous().some(i => i.withContent())
5856
+ }
5857
+ return true
5858
+ }
5859
+
5860
+ outputFile() {
5861
+ if (this.opts.to) {
5862
+ return this.path(this.opts.to)
5863
+ } else if (this.opts.from) {
5864
+ return this.path(this.opts.from)
5914
5865
  } else {
5915
- let result = ''
5916
- this.stringify(this.root, i => {
5917
- result += i
5866
+ return 'to.css'
5867
+ }
5868
+ }
5869
+
5870
+ path(file) {
5871
+ if (this.mapOpts.absolute) return file
5872
+ if (file.charCodeAt(0) === 60 /* `<` */) return file
5873
+ if (/^\w+:\/\//.test(file)) return file
5874
+ let cached = this.memoizedPaths.get(file)
5875
+ if (cached) return cached
5876
+
5877
+ let from = this.opts.to ? dirname(this.opts.to) : '.'
5878
+
5879
+ if (typeof this.mapOpts.annotation === 'string') {
5880
+ from = dirname(resolve(from, this.mapOpts.annotation))
5881
+ }
5882
+
5883
+ let path = relative(from, file)
5884
+ this.memoizedPaths.set(file, path)
5885
+
5886
+ return path
5887
+ }
5888
+
5889
+ previous() {
5890
+ if (!this.previousMaps) {
5891
+ this.previousMaps = []
5892
+ if (this.root) {
5893
+ this.root.walk(node => {
5894
+ if (node.source && node.source.input.map) {
5895
+ let map = node.source.input.map
5896
+ if (!this.previousMaps.includes(map)) {
5897
+ this.previousMaps.push(map)
5898
+ }
5899
+ }
5900
+ })
5901
+ } else {
5902
+ let input = new Input(this.css, this.opts)
5903
+ if (input.map) this.previousMaps.push(input.map)
5904
+ }
5905
+ }
5906
+
5907
+ return this.previousMaps
5908
+ }
5909
+
5910
+ setSourcesContent() {
5911
+ let already = {}
5912
+ if (this.root) {
5913
+ this.root.walk(node => {
5914
+ if (node.source) {
5915
+ let from = node.source.input.from
5916
+ if (from && !already[from]) {
5917
+ already[from] = true
5918
+ let fromUrl = this.usesFileUrls
5919
+ ? this.toFileUrl(from)
5920
+ : this.toUrl(this.path(from))
5921
+ this.map.setSourceContent(fromUrl, node.source.input.css)
5922
+ }
5923
+ }
5918
5924
  })
5919
- return [result]
5925
+ } else if (this.css) {
5926
+ let from = this.opts.from
5927
+ ? this.toUrl(this.path(this.opts.from))
5928
+ : '<no source>'
5929
+ this.map.setSourceContent(from, this.css)
5930
+ }
5931
+ }
5932
+
5933
+ sourcePath(node) {
5934
+ if (this.mapOpts.from) {
5935
+ return this.toUrl(this.mapOpts.from)
5936
+ } else if (this.usesFileUrls) {
5937
+ return this.toFileUrl(node.source.input.from)
5938
+ } else {
5939
+ return this.toUrl(this.path(node.source.input.from))
5940
+ }
5941
+ }
5942
+
5943
+ toBase64(str) {
5944
+ if (Buffer) {
5945
+ return Buffer.from(str).toString('base64')
5946
+ } else {
5947
+ return window.btoa(unescape(encodeURIComponent(str)))
5948
+ }
5949
+ }
5950
+
5951
+ toFileUrl(path) {
5952
+ let cached = this.memoizedFileURLs.get(path)
5953
+ if (cached) return cached
5954
+
5955
+ if (pathToFileURL) {
5956
+ let fileURL = pathToFileURL(path).toString()
5957
+ this.memoizedFileURLs.set(path, fileURL)
5958
+
5959
+ return fileURL
5960
+ } else {
5961
+ throw new Error(
5962
+ '`map.absolute` option is not available in this PostCSS build'
5963
+ )
5964
+ }
5965
+ }
5966
+
5967
+ toUrl(path) {
5968
+ let cached = this.memoizedURLs.get(path)
5969
+ if (cached) return cached
5970
+
5971
+ if (sep === '\\') {
5972
+ path = path.replace(/\\/g, '/')
5920
5973
  }
5974
+
5975
+ let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent)
5976
+ this.memoizedURLs.set(path, url)
5977
+
5978
+ return url
5921
5979
  }
5922
5980
  }
5923
5981
 
@@ -5960,35 +6018,63 @@ class NoWorkResult {
5960
6018
  }
5961
6019
  })
5962
6020
 
5963
- let map = new MapGenerator(str, root, this._opts, css)
5964
- if (map.isMap()) {
5965
- let [generatedCSS, generatedMap] = map.generate()
5966
- if (generatedCSS) {
5967
- this.result.css = generatedCSS
5968
- }
5969
- if (generatedMap) {
5970
- this.result.map = generatedMap
6021
+ let map = new MapGenerator(str, root, this._opts, css)
6022
+ if (map.isMap()) {
6023
+ let [generatedCSS, generatedMap] = map.generate()
6024
+ if (generatedCSS) {
6025
+ this.result.css = generatedCSS
6026
+ }
6027
+ if (generatedMap) {
6028
+ this.result.map = generatedMap
6029
+ }
6030
+ }
6031
+ }
6032
+
6033
+ async() {
6034
+ if (this.error) return Promise.reject(this.error)
6035
+ return Promise.resolve(this.result)
6036
+ }
6037
+
6038
+ catch(onRejected) {
6039
+ return this.async().catch(onRejected)
6040
+ }
6041
+
6042
+ finally(onFinally) {
6043
+ return this.async().then(onFinally, onFinally)
6044
+ }
6045
+
6046
+ sync() {
6047
+ if (this.error) throw this.error
6048
+ return this.result
6049
+ }
6050
+
6051
+ then(onFulfilled, onRejected) {
6052
+ if (process.env.NODE_ENV !== 'production') {
6053
+ if (!('from' in this._opts)) {
6054
+ warnOnce(
6055
+ 'Without `from` option PostCSS could generate wrong source map ' +
6056
+ 'and will not find Browserslist config. Set it to CSS file path ' +
6057
+ 'or to `undefined` to prevent this warning.'
6058
+ )
5971
6059
  }
5972
6060
  }
5973
- }
5974
6061
 
5975
- get [Symbol.toStringTag]() {
5976
- return 'NoWorkResult'
6062
+ return this.async().then(onFulfilled, onRejected)
5977
6063
  }
5978
6064
 
5979
- get processor() {
5980
- return this.result.processor
6065
+ toString() {
6066
+ return this._css
5981
6067
  }
5982
6068
 
5983
- get opts() {
5984
- return this.result.opts
6069
+ warnings() {
6070
+ return []
5985
6071
  }
5986
6072
 
5987
- get css() {
6073
+ get content() {
5988
6074
  return this.result.css
5989
6075
  }
5990
6076
 
5991
- get content() {
6077
+ get css() {
5992
6078
  return this.result.css
5993
6079
  }
5994
6080
 
@@ -5996,6 +6082,18 @@ class NoWorkResult {
5996
6082
  return this.result.map
5997
6083
  }
5998
6084
 
6085
+ get messages() {
6086
+ return []
6087
+ }
6088
+
6089
+ get opts() {
6090
+ return this.result.opts
6091
+ }
6092
+
6093
+ get processor() {
6094
+ return this.result.processor
6095
+ }
6096
+
5999
6097
  get root() {
6000
6098
  if (this._root) {
6001
6099
  return this._root
@@ -6018,48 +6116,8 @@ class NoWorkResult {
6018
6116
  }
6019
6117
  }
6020
6118
 
6021
- get messages() {
6022
- return []
6023
- }
6024
-
6025
- warnings() {
6026
- return []
6027
- }
6028
-
6029
- toString() {
6030
- return this._css
6031
- }
6032
-
6033
- then(onFulfilled, onRejected) {
6034
- if (process.env.NODE_ENV !== 'production') {
6035
- if (!('from' in this._opts)) {
6036
- warnOnce(
6037
- 'Without `from` option PostCSS could generate wrong source map ' +
6038
- 'and will not find Browserslist config. Set it to CSS file path ' +
6039
- 'or to `undefined` to prevent this warning.'
6040
- )
6041
- }
6042
- }
6043
-
6044
- return this.async().then(onFulfilled, onRejected)
6045
- }
6046
-
6047
- catch(onRejected) {
6048
- return this.async().catch(onRejected)
6049
- }
6050
-
6051
- finally(onFinally) {
6052
- return this.async().then(onFinally, onFinally)
6053
- }
6054
-
6055
- async() {
6056
- if (this.error) return Promise.reject(this.error)
6057
- return Promise.resolve(this.result)
6058
- }
6059
-
6060
- sync() {
6061
- if (this.error) throw this.error
6062
- return this.result
6119
+ get [Symbol.toStringTag]() {
6120
+ return 'NoWorkResult'
6063
6121
  }
6064
6122
  }
6065
6123
 
@@ -6127,25 +6185,215 @@ class Node {
6127
6185
  this[name] = defaults[name]
6128
6186
  }
6129
6187
  }
6130
- }
6188
+ }
6189
+
6190
+ addToError(error) {
6191
+ error.postcssNode = this
6192
+ if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
6193
+ let s = this.source
6194
+ error.stack = error.stack.replace(
6195
+ /\n\s{4}at /,
6196
+ `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
6197
+ )
6198
+ }
6199
+ return error
6200
+ }
6201
+
6202
+ after(add) {
6203
+ this.parent.insertAfter(this, add)
6204
+ return this
6205
+ }
6206
+
6207
+ assign(overrides = {}) {
6208
+ for (let name in overrides) {
6209
+ this[name] = overrides[name]
6210
+ }
6211
+ return this
6212
+ }
6213
+
6214
+ before(add) {
6215
+ this.parent.insertBefore(this, add)
6216
+ return this
6217
+ }
6218
+
6219
+ cleanRaws(keepBetween) {
6220
+ delete this.raws.before
6221
+ delete this.raws.after
6222
+ if (!keepBetween) delete this.raws.between
6223
+ }
6224
+
6225
+ clone(overrides = {}) {
6226
+ let cloned = cloneNode(this)
6227
+ for (let name in overrides) {
6228
+ cloned[name] = overrides[name]
6229
+ }
6230
+ return cloned
6231
+ }
6232
+
6233
+ cloneAfter(overrides = {}) {
6234
+ let cloned = this.clone(overrides)
6235
+ this.parent.insertAfter(this, cloned)
6236
+ return cloned
6237
+ }
6238
+
6239
+ cloneBefore(overrides = {}) {
6240
+ let cloned = this.clone(overrides)
6241
+ this.parent.insertBefore(this, cloned)
6242
+ return cloned
6243
+ }
6244
+
6245
+ error(message, opts = {}) {
6246
+ if (this.source) {
6247
+ let { end, start } = this.rangeBy(opts)
6248
+ return this.source.input.error(
6249
+ message,
6250
+ { column: start.column, line: start.line },
6251
+ { column: end.column, line: end.line },
6252
+ opts
6253
+ )
6254
+ }
6255
+ return new CssSyntaxError(message)
6256
+ }
6257
+
6258
+ getProxyProcessor() {
6259
+ return {
6260
+ get(node, prop) {
6261
+ if (prop === 'proxyOf') {
6262
+ return node
6263
+ } else if (prop === 'root') {
6264
+ return () => node.root().toProxy()
6265
+ } else {
6266
+ return node[prop]
6267
+ }
6268
+ },
6269
+
6270
+ set(node, prop, value) {
6271
+ if (node[prop] === value) return true
6272
+ node[prop] = value
6273
+ if (
6274
+ prop === 'prop' ||
6275
+ prop === 'value' ||
6276
+ prop === 'name' ||
6277
+ prop === 'params' ||
6278
+ prop === 'important' ||
6279
+ /* c8 ignore next */
6280
+ prop === 'text'
6281
+ ) {
6282
+ node.markDirty()
6283
+ }
6284
+ return true
6285
+ }
6286
+ }
6287
+ }
6288
+
6289
+ markDirty() {
6290
+ if (this[isClean]) {
6291
+ this[isClean] = false
6292
+ let next = this
6293
+ while ((next = next.parent)) {
6294
+ next[isClean] = false
6295
+ }
6296
+ }
6297
+ }
6298
+
6299
+ next() {
6300
+ if (!this.parent) return undefined
6301
+ let index = this.parent.index(this)
6302
+ return this.parent.nodes[index + 1]
6303
+ }
6304
+
6305
+ positionBy(opts, stringRepresentation) {
6306
+ let pos = this.source.start
6307
+ if (opts.index) {
6308
+ pos = this.positionInside(opts.index, stringRepresentation)
6309
+ } else if (opts.word) {
6310
+ stringRepresentation = this.toString()
6311
+ let index = stringRepresentation.indexOf(opts.word)
6312
+ if (index !== -1) pos = this.positionInside(index, stringRepresentation)
6313
+ }
6314
+ return pos
6315
+ }
6316
+
6317
+ positionInside(index, stringRepresentation) {
6318
+ let string = stringRepresentation || this.toString()
6319
+ let column = this.source.start.column
6320
+ let line = this.source.start.line
6321
+
6322
+ for (let i = 0; i < index; i++) {
6323
+ if (string[i] === '\n') {
6324
+ column = 1
6325
+ line += 1
6326
+ } else {
6327
+ column += 1
6328
+ }
6329
+ }
6330
+
6331
+ return { column, line }
6332
+ }
6333
+
6334
+ prev() {
6335
+ if (!this.parent) return undefined
6336
+ let index = this.parent.index(this)
6337
+ return this.parent.nodes[index - 1]
6338
+ }
6339
+
6340
+ rangeBy(opts) {
6341
+ let start = {
6342
+ column: this.source.start.column,
6343
+ line: this.source.start.line
6344
+ }
6345
+ let end = this.source.end
6346
+ ? {
6347
+ column: this.source.end.column + 1,
6348
+ line: this.source.end.line
6349
+ }
6350
+ : {
6351
+ column: start.column + 1,
6352
+ line: start.line
6353
+ }
6354
+
6355
+ if (opts.word) {
6356
+ let stringRepresentation = this.toString()
6357
+ let index = stringRepresentation.indexOf(opts.word)
6358
+ if (index !== -1) {
6359
+ start = this.positionInside(index, stringRepresentation)
6360
+ end = this.positionInside(index + opts.word.length, stringRepresentation)
6361
+ }
6362
+ } else {
6363
+ if (opts.start) {
6364
+ start = {
6365
+ column: opts.start.column,
6366
+ line: opts.start.line
6367
+ }
6368
+ } else if (opts.index) {
6369
+ start = this.positionInside(opts.index)
6370
+ }
6371
+
6372
+ if (opts.end) {
6373
+ end = {
6374
+ column: opts.end.column,
6375
+ line: opts.end.line
6376
+ }
6377
+ } else if (opts.endIndex) {
6378
+ end = this.positionInside(opts.endIndex)
6379
+ } else if (opts.index) {
6380
+ end = this.positionInside(opts.index + 1)
6381
+ }
6382
+ }
6131
6383
 
6132
- error(message, opts = {}) {
6133
- if (this.source) {
6134
- let { start, end } = this.rangeBy(opts)
6135
- return this.source.input.error(
6136
- message,
6137
- { line: start.line, column: start.column },
6138
- { line: end.line, column: end.column },
6139
- opts
6140
- )
6384
+ if (
6385
+ end.line < start.line ||
6386
+ (end.line === start.line && end.column <= start.column)
6387
+ ) {
6388
+ end = { column: start.column + 1, line: start.line }
6141
6389
  }
6142
- return new CssSyntaxError(message)
6390
+
6391
+ return { end, start }
6143
6392
  }
6144
6393
 
6145
- warn(result, text, opts) {
6146
- let data = { node: this }
6147
- for (let i in opts) data[i] = opts[i]
6148
- return result.warn(text, data)
6394
+ raw(prop, defaultType) {
6395
+ let str = new Stringifier()
6396
+ return str.raw(this, prop, defaultType)
6149
6397
  }
6150
6398
 
6151
6399
  remove() {
@@ -6156,42 +6404,6 @@ class Node {
6156
6404
  return this
6157
6405
  }
6158
6406
 
6159
- toString(stringifier = stringify) {
6160
- if (stringifier.stringify) stringifier = stringifier.stringify
6161
- let result = ''
6162
- stringifier(this, i => {
6163
- result += i
6164
- })
6165
- return result
6166
- }
6167
-
6168
- assign(overrides = {}) {
6169
- for (let name in overrides) {
6170
- this[name] = overrides[name]
6171
- }
6172
- return this
6173
- }
6174
-
6175
- clone(overrides = {}) {
6176
- let cloned = cloneNode(this)
6177
- for (let name in overrides) {
6178
- cloned[name] = overrides[name]
6179
- }
6180
- return cloned
6181
- }
6182
-
6183
- cloneBefore(overrides = {}) {
6184
- let cloned = this.clone(overrides)
6185
- this.parent.insertBefore(this, cloned)
6186
- return cloned
6187
- }
6188
-
6189
- cloneAfter(overrides = {}) {
6190
- let cloned = this.clone(overrides)
6191
- this.parent.insertAfter(this, cloned)
6192
- return cloned
6193
- }
6194
-
6195
6407
  replaceWith(...nodes) {
6196
6408
  if (this.parent) {
6197
6409
  let bookmark = this
@@ -6215,28 +6427,6 @@ class Node {
6215
6427
  return this
6216
6428
  }
6217
6429
 
6218
- next() {
6219
- if (!this.parent) return undefined
6220
- let index = this.parent.index(this)
6221
- return this.parent.nodes[index + 1]
6222
- }
6223
-
6224
- prev() {
6225
- if (!this.parent) return undefined
6226
- let index = this.parent.index(this)
6227
- return this.parent.nodes[index - 1]
6228
- }
6229
-
6230
- before(add) {
6231
- this.parent.insertBefore(this, add)
6232
- return this
6233
- }
6234
-
6235
- after(add) {
6236
- this.parent.insertAfter(this, add)
6237
- return this
6238
- }
6239
-
6240
6430
  root() {
6241
6431
  let result = this
6242
6432
  while (result.parent && result.parent.type !== 'document') {
@@ -6245,17 +6435,6 @@ class Node {
6245
6435
  return result
6246
6436
  }
6247
6437
 
6248
- raw(prop, defaultType) {
6249
- let str = new Stringifier()
6250
- return str.raw(this, prop, defaultType)
6251
- }
6252
-
6253
- cleanRaws(keepBetween) {
6254
- delete this.raws.before
6255
- delete this.raws.after
6256
- if (!keepBetween) delete this.raws.between
6257
- }
6258
-
6259
6438
  toJSON(_, inputs) {
6260
6439
  let fixed = {}
6261
6440
  let emitInputs = inputs == null
@@ -6288,9 +6467,9 @@ class Node {
6288
6467
  inputsNextIndex++
6289
6468
  }
6290
6469
  fixed[name] = {
6470
+ end: value.end,
6291
6471
  inputId,
6292
- start: value.start,
6293
- end: value.end
6472
+ start: value.start
6294
6473
  }
6295
6474
  } else {
6296
6475
  fixed[name] = value
@@ -6304,118 +6483,6 @@ class Node {
6304
6483
  return fixed
6305
6484
  }
6306
6485
 
6307
- positionInside(index) {
6308
- let string = this.toString()
6309
- let column = this.source.start.column
6310
- let line = this.source.start.line
6311
-
6312
- for (let i = 0; i < index; i++) {
6313
- if (string[i] === '\n') {
6314
- column = 1
6315
- line += 1
6316
- } else {
6317
- column += 1
6318
- }
6319
- }
6320
-
6321
- return { line, column }
6322
- }
6323
-
6324
- positionBy(opts) {
6325
- let pos = this.source.start
6326
- if (opts.index) {
6327
- pos = this.positionInside(opts.index)
6328
- } else if (opts.word) {
6329
- let index = this.toString().indexOf(opts.word)
6330
- if (index !== -1) pos = this.positionInside(index)
6331
- }
6332
- return pos
6333
- }
6334
-
6335
- rangeBy(opts) {
6336
- let start = {
6337
- line: this.source.start.line,
6338
- column: this.source.start.column
6339
- }
6340
- let end = this.source.end
6341
- ? {
6342
- line: this.source.end.line,
6343
- column: this.source.end.column + 1
6344
- }
6345
- : {
6346
- line: start.line,
6347
- column: start.column + 1
6348
- }
6349
-
6350
- if (opts.word) {
6351
- let index = this.toString().indexOf(opts.word)
6352
- if (index !== -1) {
6353
- start = this.positionInside(index)
6354
- end = this.positionInside(index + opts.word.length)
6355
- }
6356
- } else {
6357
- if (opts.start) {
6358
- start = {
6359
- line: opts.start.line,
6360
- column: opts.start.column
6361
- }
6362
- } else if (opts.index) {
6363
- start = this.positionInside(opts.index)
6364
- }
6365
-
6366
- if (opts.end) {
6367
- end = {
6368
- line: opts.end.line,
6369
- column: opts.end.column
6370
- }
6371
- } else if (opts.endIndex) {
6372
- end = this.positionInside(opts.endIndex)
6373
- } else if (opts.index) {
6374
- end = this.positionInside(opts.index + 1)
6375
- }
6376
- }
6377
-
6378
- if (
6379
- end.line < start.line ||
6380
- (end.line === start.line && end.column <= start.column)
6381
- ) {
6382
- end = { line: start.line, column: start.column + 1 }
6383
- }
6384
-
6385
- return { start, end }
6386
- }
6387
-
6388
- getProxyProcessor() {
6389
- return {
6390
- set(node, prop, value) {
6391
- if (node[prop] === value) return true
6392
- node[prop] = value
6393
- if (
6394
- prop === 'prop' ||
6395
- prop === 'value' ||
6396
- prop === 'name' ||
6397
- prop === 'params' ||
6398
- prop === 'important' ||
6399
- /* c8 ignore next */
6400
- prop === 'text'
6401
- ) {
6402
- node.markDirty()
6403
- }
6404
- return true
6405
- },
6406
-
6407
- get(node, prop) {
6408
- if (prop === 'proxyOf') {
6409
- return node
6410
- } else if (prop === 'root') {
6411
- return () => node.root().toProxy()
6412
- } else {
6413
- return node[prop]
6414
- }
6415
- }
6416
- }
6417
- }
6418
-
6419
6486
  toProxy() {
6420
6487
  if (!this.proxyCache) {
6421
6488
  this.proxyCache = new Proxy(this, this.getProxyProcessor())
@@ -6423,26 +6490,19 @@ class Node {
6423
6490
  return this.proxyCache
6424
6491
  }
6425
6492
 
6426
- addToError(error) {
6427
- error.postcssNode = this
6428
- if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
6429
- let s = this.source
6430
- error.stack = error.stack.replace(
6431
- /\n\s{4}at /,
6432
- `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
6433
- )
6434
- }
6435
- return error
6493
+ toString(stringifier = stringify) {
6494
+ if (stringifier.stringify) stringifier = stringifier.stringify
6495
+ let result = ''
6496
+ stringifier(this, i => {
6497
+ result += i
6498
+ })
6499
+ return result
6436
6500
  }
6437
6501
 
6438
- markDirty() {
6439
- if (this[isClean]) {
6440
- this[isClean] = false
6441
- let next = this
6442
- while ((next = next.parent)) {
6443
- next[isClean] = false
6444
- }
6445
- }
6502
+ warn(result, text, opts) {
6503
+ let data = { node: this }
6504
+ for (let i in opts) data[i] = opts[i]
6505
+ return result.warn(text, data)
6446
6506
  }
6447
6507
 
6448
6508
  get proxyOf() {
@@ -6543,55 +6603,150 @@ class Parser {
6543
6603
  this.customProperty = false
6544
6604
 
6545
6605
  this.createTokenizer()
6546
- this.root.source = { input, start: { offset: 0, line: 1, column: 1 } }
6606
+ this.root.source = { input, start: { column: 1, line: 1, offset: 0 } }
6547
6607
  }
6548
6608
 
6549
- createTokenizer() {
6550
- this.tokenizer = tokenizer(this.input)
6551
- }
6609
+ atrule(token) {
6610
+ let node = new AtRule()
6611
+ node.name = token[1].slice(1)
6612
+ if (node.name === '') {
6613
+ this.unnamedAtrule(node, token)
6614
+ }
6615
+ this.init(node, token[2])
6616
+
6617
+ let type
6618
+ let prev
6619
+ let shift
6620
+ let last = false
6621
+ let open = false
6622
+ let params = []
6623
+ let brackets = []
6552
6624
 
6553
- parse() {
6554
- let token
6555
6625
  while (!this.tokenizer.endOfFile()) {
6556
6626
  token = this.tokenizer.nextToken()
6627
+ type = token[0]
6557
6628
 
6558
- switch (token[0]) {
6559
- case 'space':
6560
- this.spaces += token[1]
6629
+ if (type === '(' || type === '[') {
6630
+ brackets.push(type === '(' ? ')' : ']')
6631
+ } else if (type === '{' && brackets.length > 0) {
6632
+ brackets.push('}')
6633
+ } else if (type === brackets[brackets.length - 1]) {
6634
+ brackets.pop()
6635
+ }
6636
+
6637
+ if (brackets.length === 0) {
6638
+ if (type === ';') {
6639
+ node.source.end = this.getPosition(token[2])
6640
+ node.source.end.offset++
6641
+ this.semicolon = true
6642
+ break
6643
+ } else if (type === '{') {
6644
+ open = true
6645
+ break
6646
+ } else if (type === '}') {
6647
+ if (params.length > 0) {
6648
+ shift = params.length - 1
6649
+ prev = params[shift]
6650
+ while (prev && prev[0] === 'space') {
6651
+ prev = params[--shift]
6652
+ }
6653
+ if (prev) {
6654
+ node.source.end = this.getPosition(prev[3] || prev[2])
6655
+ node.source.end.offset++
6656
+ }
6657
+ }
6658
+ this.end(token)
6561
6659
  break
6660
+ } else {
6661
+ params.push(token)
6662
+ }
6663
+ } else {
6664
+ params.push(token)
6665
+ }
6562
6666
 
6563
- case ';':
6564
- this.freeSemicolon(token)
6565
- break
6667
+ if (this.tokenizer.endOfFile()) {
6668
+ last = true
6669
+ break
6670
+ }
6671
+ }
6566
6672
 
6567
- case '}':
6568
- this.end(token)
6569
- break
6673
+ node.raws.between = this.spacesAndCommentsFromEnd(params)
6674
+ if (params.length) {
6675
+ node.raws.afterName = this.spacesAndCommentsFromStart(params)
6676
+ this.raw(node, 'params', params)
6677
+ if (last) {
6678
+ token = params[params.length - 1]
6679
+ node.source.end = this.getPosition(token[3] || token[2])
6680
+ node.source.end.offset++
6681
+ this.spaces = node.raws.between
6682
+ node.raws.between = ''
6683
+ }
6684
+ } else {
6685
+ node.raws.afterName = ''
6686
+ node.params = ''
6687
+ }
6570
6688
 
6571
- case 'comment':
6572
- this.comment(token)
6573
- break
6689
+ if (open) {
6690
+ node.nodes = []
6691
+ this.current = node
6692
+ }
6693
+ }
6574
6694
 
6575
- case 'at-word':
6576
- this.atrule(token)
6577
- break
6695
+ checkMissedSemicolon(tokens) {
6696
+ let colon = this.colon(tokens)
6697
+ if (colon === false) return
6578
6698
 
6579
- case '{':
6580
- this.emptyRule(token)
6581
- break
6699
+ let founded = 0
6700
+ let token
6701
+ for (let j = colon - 1; j >= 0; j--) {
6702
+ token = tokens[j]
6703
+ if (token[0] !== 'space') {
6704
+ founded += 1
6705
+ if (founded === 2) break
6706
+ }
6707
+ }
6708
+ // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
6709
+ // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
6710
+ // And because we need it after that one we do +1 to get the next one.
6711
+ throw this.input.error(
6712
+ 'Missed semicolon',
6713
+ token[0] === 'word' ? token[3] + 1 : token[2]
6714
+ )
6715
+ }
6582
6716
 
6583
- default:
6584
- this.other(token)
6585
- break
6717
+ colon(tokens) {
6718
+ let brackets = 0
6719
+ let token, type, prev
6720
+ for (let [i, element] of tokens.entries()) {
6721
+ token = element
6722
+ type = token[0]
6723
+
6724
+ if (type === '(') {
6725
+ brackets += 1
6726
+ }
6727
+ if (type === ')') {
6728
+ brackets -= 1
6729
+ }
6730
+ if (brackets === 0 && type === ':') {
6731
+ if (!prev) {
6732
+ this.doubleColon(token)
6733
+ } else if (prev[0] === 'word' && prev[1] === 'progid') {
6734
+ continue
6735
+ } else {
6736
+ return i
6737
+ }
6586
6738
  }
6739
+
6740
+ prev = token
6587
6741
  }
6588
- this.endFile()
6742
+ return false
6589
6743
  }
6590
6744
 
6591
6745
  comment(token) {
6592
6746
  let node = new Comment()
6593
6747
  this.init(node, token[2])
6594
6748
  node.source.end = this.getPosition(token[3] || token[2])
6749
+ node.source.end.offset++
6595
6750
 
6596
6751
  let text = token[1].slice(2, -2)
6597
6752
  if (/^\s*$/.test(text)) {
@@ -6606,86 +6761,8 @@ class Parser {
6606
6761
  }
6607
6762
  }
6608
6763
 
6609
- emptyRule(token) {
6610
- let node = new Rule()
6611
- this.init(node, token[2])
6612
- node.selector = ''
6613
- node.raws.between = ''
6614
- this.current = node
6615
- }
6616
-
6617
- other(start) {
6618
- let end = false
6619
- let type = null
6620
- let colon = false
6621
- let bracket = null
6622
- let brackets = []
6623
- let customProperty = start[1].startsWith('--')
6624
-
6625
- let tokens = []
6626
- let token = start
6627
- while (token) {
6628
- type = token[0]
6629
- tokens.push(token)
6630
-
6631
- if (type === '(' || type === '[') {
6632
- if (!bracket) bracket = token
6633
- brackets.push(type === '(' ? ')' : ']')
6634
- } else if (customProperty && colon && type === '{') {
6635
- if (!bracket) bracket = token
6636
- brackets.push('}')
6637
- } else if (brackets.length === 0) {
6638
- if (type === ';') {
6639
- if (colon) {
6640
- this.decl(tokens, customProperty)
6641
- return
6642
- } else {
6643
- break
6644
- }
6645
- } else if (type === '{') {
6646
- this.rule(tokens)
6647
- return
6648
- } else if (type === '}') {
6649
- this.tokenizer.back(tokens.pop())
6650
- end = true
6651
- break
6652
- } else if (type === ':') {
6653
- colon = true
6654
- }
6655
- } else if (type === brackets[brackets.length - 1]) {
6656
- brackets.pop()
6657
- if (brackets.length === 0) bracket = null
6658
- }
6659
-
6660
- token = this.tokenizer.nextToken()
6661
- }
6662
-
6663
- if (this.tokenizer.endOfFile()) end = true
6664
- if (brackets.length > 0) this.unclosedBracket(bracket)
6665
-
6666
- if (end && colon) {
6667
- if (!customProperty) {
6668
- while (tokens.length) {
6669
- token = tokens[tokens.length - 1][0]
6670
- if (token !== 'space' && token !== 'comment') break
6671
- this.tokenizer.back(tokens.pop())
6672
- }
6673
- }
6674
- this.decl(tokens, customProperty)
6675
- } else {
6676
- this.unknownWord(tokens)
6677
- }
6678
- }
6679
-
6680
- rule(tokens) {
6681
- tokens.pop()
6682
-
6683
- let node = new Rule()
6684
- this.init(node, tokens[0][2])
6685
-
6686
- node.raws.between = this.spacesAndCommentsFromEnd(tokens)
6687
- this.raw(node, 'selector', tokens)
6688
- this.current = node
6764
+ createTokenizer() {
6765
+ this.tokenizer = tokenizer(this.input)
6689
6766
  }
6690
6767
 
6691
6768
  decl(tokens, customProperty) {
@@ -6701,6 +6778,7 @@ class Parser {
6701
6778
  node.source.end = this.getPosition(
6702
6779
  last[3] || last[2] || findLastWithPosition(tokens)
6703
6780
  )
6781
+ node.source.end.offset++
6704
6782
 
6705
6783
  while (tokens[0][0] !== 'word') {
6706
6784
  if (tokens.length === 1) this.unknownWord(tokens)
@@ -6744,137 +6822,70 @@ class Parser {
6744
6822
  while (tokens.length) {
6745
6823
  next = tokens[0][0]
6746
6824
  if (next !== 'space' && next !== 'comment') break
6747
- firstSpaces.push(tokens.shift())
6748
- }
6749
-
6750
- this.precheckMissedSemicolon(tokens)
6751
-
6752
- for (let i = tokens.length - 1; i >= 0; i--) {
6753
- token = tokens[i]
6754
- if (token[1].toLowerCase() === '!important') {
6755
- node.important = true
6756
- let string = this.stringFrom(tokens, i)
6757
- string = this.spacesFromEnd(tokens) + string
6758
- if (string !== ' !important') node.raws.important = string
6759
- break
6760
- } else if (token[1].toLowerCase() === 'important') {
6761
- let cache = tokens.slice(0)
6762
- let str = ''
6763
- for (let j = i; j > 0; j--) {
6764
- let type = cache[j][0]
6765
- if (str.trim().indexOf('!') === 0 && type !== 'space') {
6766
- break
6767
- }
6768
- str = cache.pop()[1] + str
6769
- }
6770
- if (str.trim().indexOf('!') === 0) {
6771
- node.important = true
6772
- node.raws.important = str
6773
- tokens = cache
6774
- }
6775
- }
6776
-
6777
- if (token[0] !== 'space' && token[0] !== 'comment') {
6778
- break
6779
- }
6780
- }
6781
-
6782
- let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment')
6783
-
6784
- if (hasWord) {
6785
- node.raws.between += firstSpaces.map(i => i[1]).join('')
6786
- firstSpaces = []
6787
- }
6788
- this.raw(node, 'value', firstSpaces.concat(tokens), customProperty)
6789
-
6790
- if (node.value.includes(':') && !customProperty) {
6791
- this.checkMissedSemicolon(tokens)
6792
- }
6793
- }
6794
-
6795
- atrule(token) {
6796
- let node = new AtRule()
6797
- node.name = token[1].slice(1)
6798
- if (node.name === '') {
6799
- this.unnamedAtrule(node, token)
6800
- }
6801
- this.init(node, token[2])
6802
-
6803
- let type
6804
- let prev
6805
- let shift
6806
- let last = false
6807
- let open = false
6808
- let params = []
6809
- let brackets = []
6810
-
6811
- while (!this.tokenizer.endOfFile()) {
6812
- token = this.tokenizer.nextToken()
6813
- type = token[0]
6814
-
6815
- if (type === '(' || type === '[') {
6816
- brackets.push(type === '(' ? ')' : ']')
6817
- } else if (type === '{' && brackets.length > 0) {
6818
- brackets.push('}')
6819
- } else if (type === brackets[brackets.length - 1]) {
6820
- brackets.pop()
6821
- }
6825
+ firstSpaces.push(tokens.shift())
6826
+ }
6822
6827
 
6823
- if (brackets.length === 0) {
6824
- if (type === ';') {
6825
- node.source.end = this.getPosition(token[2])
6826
- this.semicolon = true
6827
- break
6828
- } else if (type === '{') {
6829
- open = true
6830
- break
6831
- } else if (type === '}') {
6832
- if (params.length > 0) {
6833
- shift = params.length - 1
6834
- prev = params[shift]
6835
- while (prev && prev[0] === 'space') {
6836
- prev = params[--shift]
6837
- }
6838
- if (prev) {
6839
- node.source.end = this.getPosition(prev[3] || prev[2])
6840
- }
6828
+ this.precheckMissedSemicolon(tokens)
6829
+
6830
+ for (let i = tokens.length - 1; i >= 0; i--) {
6831
+ token = tokens[i]
6832
+ if (token[1].toLowerCase() === '!important') {
6833
+ node.important = true
6834
+ let string = this.stringFrom(tokens, i)
6835
+ string = this.spacesFromEnd(tokens) + string
6836
+ if (string !== ' !important') node.raws.important = string
6837
+ break
6838
+ } else if (token[1].toLowerCase() === 'important') {
6839
+ let cache = tokens.slice(0)
6840
+ let str = ''
6841
+ for (let j = i; j > 0; j--) {
6842
+ let type = cache[j][0]
6843
+ if (str.trim().indexOf('!') === 0 && type !== 'space') {
6844
+ break
6841
6845
  }
6842
- this.end(token)
6843
- break
6844
- } else {
6845
- params.push(token)
6846
+ str = cache.pop()[1] + str
6847
+ }
6848
+ if (str.trim().indexOf('!') === 0) {
6849
+ node.important = true
6850
+ node.raws.important = str
6851
+ tokens = cache
6846
6852
  }
6847
- } else {
6848
- params.push(token)
6849
6853
  }
6850
6854
 
6851
- if (this.tokenizer.endOfFile()) {
6852
- last = true
6855
+ if (token[0] !== 'space' && token[0] !== 'comment') {
6853
6856
  break
6854
6857
  }
6855
6858
  }
6856
6859
 
6857
- node.raws.between = this.spacesAndCommentsFromEnd(params)
6858
- if (params.length) {
6859
- node.raws.afterName = this.spacesAndCommentsFromStart(params)
6860
- this.raw(node, 'params', params)
6861
- if (last) {
6862
- token = params[params.length - 1]
6863
- node.source.end = this.getPosition(token[3] || token[2])
6864
- this.spaces = node.raws.between
6865
- node.raws.between = ''
6866
- }
6867
- } else {
6868
- node.raws.afterName = ''
6869
- node.params = ''
6860
+ let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment')
6861
+
6862
+ if (hasWord) {
6863
+ node.raws.between += firstSpaces.map(i => i[1]).join('')
6864
+ firstSpaces = []
6870
6865
  }
6866
+ this.raw(node, 'value', firstSpaces.concat(tokens), customProperty)
6871
6867
 
6872
- if (open) {
6873
- node.nodes = []
6874
- this.current = node
6868
+ if (node.value.includes(':') && !customProperty) {
6869
+ this.checkMissedSemicolon(tokens)
6875
6870
  }
6876
6871
  }
6877
6872
 
6873
+ doubleColon(token) {
6874
+ throw this.input.error(
6875
+ 'Double colon',
6876
+ { offset: token[2] },
6877
+ { offset: token[2] + token[1].length }
6878
+ )
6879
+ }
6880
+
6881
+ emptyRule(token) {
6882
+ let node = new Rule()
6883
+ this.init(node, token[2])
6884
+ node.selector = ''
6885
+ node.raws.between = ''
6886
+ this.current = node
6887
+ }
6888
+
6878
6889
  end(token) {
6879
6890
  if (this.current.nodes && this.current.nodes.length) {
6880
6891
  this.current.raws.semicolon = this.semicolon
@@ -6886,6 +6897,7 @@ class Parser {
6886
6897
 
6887
6898
  if (this.current.parent) {
6888
6899
  this.current.source.end = this.getPosition(token[2])
6900
+ this.current.source.end.offset++
6889
6901
  this.current = this.current.parent
6890
6902
  } else {
6891
6903
  this.unexpectedClose(token)
@@ -6898,6 +6910,7 @@ class Parser {
6898
6910
  this.current.raws.semicolon = this.semicolon
6899
6911
  }
6900
6912
  this.current.raws.after = (this.current.raws.after || '') + this.spaces
6913
+ this.root.source.end = this.getPosition(this.tokenizer.position())
6901
6914
  }
6902
6915
 
6903
6916
  freeSemicolon(token) {
@@ -6916,23 +6929,128 @@ class Parser {
6916
6929
  getPosition(offset) {
6917
6930
  let pos = this.input.fromOffset(offset)
6918
6931
  return {
6919
- offset,
6932
+ column: pos.col,
6920
6933
  line: pos.line,
6921
- column: pos.col
6934
+ offset
6922
6935
  }
6923
6936
  }
6924
6937
 
6925
6938
  init(node, offset) {
6926
6939
  this.current.push(node)
6927
6940
  node.source = {
6928
- start: this.getPosition(offset),
6929
- input: this.input
6941
+ input: this.input,
6942
+ start: this.getPosition(offset)
6930
6943
  }
6931
6944
  node.raws.before = this.spaces
6932
6945
  this.spaces = ''
6933
6946
  if (node.type !== 'comment') this.semicolon = false
6934
6947
  }
6935
6948
 
6949
+ other(start) {
6950
+ let end = false
6951
+ let type = null
6952
+ let colon = false
6953
+ let bracket = null
6954
+ let brackets = []
6955
+ let customProperty = start[1].startsWith('--')
6956
+
6957
+ let tokens = []
6958
+ let token = start
6959
+ while (token) {
6960
+ type = token[0]
6961
+ tokens.push(token)
6962
+
6963
+ if (type === '(' || type === '[') {
6964
+ if (!bracket) bracket = token
6965
+ brackets.push(type === '(' ? ')' : ']')
6966
+ } else if (customProperty && colon && type === '{') {
6967
+ if (!bracket) bracket = token
6968
+ brackets.push('}')
6969
+ } else if (brackets.length === 0) {
6970
+ if (type === ';') {
6971
+ if (colon) {
6972
+ this.decl(tokens, customProperty)
6973
+ return
6974
+ } else {
6975
+ break
6976
+ }
6977
+ } else if (type === '{') {
6978
+ this.rule(tokens)
6979
+ return
6980
+ } else if (type === '}') {
6981
+ this.tokenizer.back(tokens.pop())
6982
+ end = true
6983
+ break
6984
+ } else if (type === ':') {
6985
+ colon = true
6986
+ }
6987
+ } else if (type === brackets[brackets.length - 1]) {
6988
+ brackets.pop()
6989
+ if (brackets.length === 0) bracket = null
6990
+ }
6991
+
6992
+ token = this.tokenizer.nextToken()
6993
+ }
6994
+
6995
+ if (this.tokenizer.endOfFile()) end = true
6996
+ if (brackets.length > 0) this.unclosedBracket(bracket)
6997
+
6998
+ if (end && colon) {
6999
+ if (!customProperty) {
7000
+ while (tokens.length) {
7001
+ token = tokens[tokens.length - 1][0]
7002
+ if (token !== 'space' && token !== 'comment') break
7003
+ this.tokenizer.back(tokens.pop())
7004
+ }
7005
+ }
7006
+ this.decl(tokens, customProperty)
7007
+ } else {
7008
+ this.unknownWord(tokens)
7009
+ }
7010
+ }
7011
+
7012
+ parse() {
7013
+ let token
7014
+ while (!this.tokenizer.endOfFile()) {
7015
+ token = this.tokenizer.nextToken()
7016
+
7017
+ switch (token[0]) {
7018
+ case 'space':
7019
+ this.spaces += token[1]
7020
+ break
7021
+
7022
+ case ';':
7023
+ this.freeSemicolon(token)
7024
+ break
7025
+
7026
+ case '}':
7027
+ this.end(token)
7028
+ break
7029
+
7030
+ case 'comment':
7031
+ this.comment(token)
7032
+ break
7033
+
7034
+ case 'at-word':
7035
+ this.atrule(token)
7036
+ break
7037
+
7038
+ case '{':
7039
+ this.emptyRule(token)
7040
+ break
7041
+
7042
+ default:
7043
+ this.other(token)
7044
+ break
7045
+ }
7046
+ }
7047
+ this.endFile()
7048
+ }
7049
+
7050
+ precheckMissedSemicolon(/* tokens */) {
7051
+ // Hook for Safe Parser
7052
+ }
7053
+
6936
7054
  raw(node, prop, tokens, customProperty) {
6937
7055
  let token, type
6938
7056
  let length = tokens.length
@@ -6963,11 +7081,22 @@ class Parser {
6963
7081
  }
6964
7082
  if (!clean) {
6965
7083
  let raw = tokens.reduce((all, i) => all + i[1], '')
6966
- node.raws[prop] = { value, raw }
7084
+ node.raws[prop] = { raw, value }
6967
7085
  }
6968
7086
  node[prop] = value
6969
7087
  }
6970
7088
 
7089
+ rule(tokens) {
7090
+ tokens.pop()
7091
+
7092
+ let node = new Rule()
7093
+ this.init(node, tokens[0][2])
7094
+
7095
+ node.raws.between = this.spacesAndCommentsFromEnd(tokens)
7096
+ this.raw(node, 'selector', tokens)
7097
+ this.current = node
7098
+ }
7099
+
6971
7100
  spacesAndCommentsFromEnd(tokens) {
6972
7101
  let lastTokenType
6973
7102
  let spaces = ''
@@ -6979,6 +7108,8 @@ class Parser {
6979
7108
  return spaces
6980
7109
  }
6981
7110
 
7111
+ // Errors
7112
+
6982
7113
  spacesAndCommentsFromStart(tokens) {
6983
7114
  let next
6984
7115
  let spaces = ''
@@ -6986,59 +7117,34 @@ class Parser {
6986
7117
  next = tokens[0][0]
6987
7118
  if (next !== 'space' && next !== 'comment') break
6988
7119
  spaces += tokens.shift()[1]
6989
- }
6990
- return spaces
6991
- }
6992
-
6993
- spacesFromEnd(tokens) {
6994
- let lastTokenType
6995
- let spaces = ''
6996
- while (tokens.length) {
6997
- lastTokenType = tokens[tokens.length - 1][0]
6998
- if (lastTokenType !== 'space') break
6999
- spaces = tokens.pop()[1] + spaces
7000
- }
7001
- return spaces
7002
- }
7003
-
7004
- stringFrom(tokens, from) {
7005
- let result = ''
7006
- for (let i = from; i < tokens.length; i++) {
7007
- result += tokens[i][1]
7008
- }
7009
- tokens.splice(from, tokens.length - from)
7010
- return result
7011
- }
7012
-
7013
- colon(tokens) {
7014
- let brackets = 0
7015
- let token, type, prev
7016
- for (let [i, element] of tokens.entries()) {
7017
- token = element
7018
- type = token[0]
7019
-
7020
- if (type === '(') {
7021
- brackets += 1
7022
- }
7023
- if (type === ')') {
7024
- brackets -= 1
7025
- }
7026
- if (brackets === 0 && type === ':') {
7027
- if (!prev) {
7028
- this.doubleColon(token)
7029
- } else if (prev[0] === 'word' && prev[1] === 'progid') {
7030
- continue
7031
- } else {
7032
- return i
7033
- }
7034
- }
7120
+ }
7121
+ return spaces
7122
+ }
7035
7123
 
7036
- prev = token
7124
+ spacesFromEnd(tokens) {
7125
+ let lastTokenType
7126
+ let spaces = ''
7127
+ while (tokens.length) {
7128
+ lastTokenType = tokens[tokens.length - 1][0]
7129
+ if (lastTokenType !== 'space') break
7130
+ spaces = tokens.pop()[1] + spaces
7037
7131
  }
7038
- return false
7132
+ return spaces
7039
7133
  }
7040
7134
 
7041
- // Errors
7135
+ stringFrom(tokens, from) {
7136
+ let result = ''
7137
+ for (let i = from; i < tokens.length; i++) {
7138
+ result += tokens[i][1]
7139
+ }
7140
+ tokens.splice(from, tokens.length - from)
7141
+ return result
7142
+ }
7143
+
7144
+ unclosedBlock() {
7145
+ let pos = this.current.source.start
7146
+ throw this.input.error('Unclosed block', pos.line, pos.column)
7147
+ }
7042
7148
 
7043
7149
  unclosedBracket(bracket) {
7044
7150
  throw this.input.error(
@@ -7048,14 +7154,6 @@ class Parser {
7048
7154
  )
7049
7155
  }
7050
7156
 
7051
- unknownWord(tokens) {
7052
- throw this.input.error(
7053
- 'Unknown word',
7054
- { offset: tokens[0][2] },
7055
- { offset: tokens[0][2] + tokens[0][1].length }
7056
- )
7057
- }
7058
-
7059
7157
  unexpectedClose(token) {
7060
7158
  throw this.input.error(
7061
7159
  'Unexpected }',
@@ -7064,16 +7162,11 @@ class Parser {
7064
7162
  )
7065
7163
  }
7066
7164
 
7067
- unclosedBlock() {
7068
- let pos = this.current.source.start
7069
- throw this.input.error('Unclosed block', pos.line, pos.column)
7070
- }
7071
-
7072
- doubleColon(token) {
7165
+ unknownWord(tokens) {
7073
7166
  throw this.input.error(
7074
- 'Double colon',
7075
- { offset: token[2] },
7076
- { offset: token[2] + token[1].length }
7167
+ 'Unknown word',
7168
+ { offset: tokens[0][2] },
7169
+ { offset: tokens[0][2] + tokens[0][1].length }
7077
7170
  )
7078
7171
  }
7079
7172
 
@@ -7084,32 +7177,6 @@ class Parser {
7084
7177
  { offset: token[2] + token[1].length }
7085
7178
  )
7086
7179
  }
7087
-
7088
- precheckMissedSemicolon(/* tokens */) {
7089
- // Hook for Safe Parser
7090
- }
7091
-
7092
- checkMissedSemicolon(tokens) {
7093
- let colon = this.colon(tokens)
7094
- if (colon === false) return
7095
-
7096
- let founded = 0
7097
- let token
7098
- for (let j = colon - 1; j >= 0; j--) {
7099
- token = tokens[j]
7100
- if (token[0] !== 'space') {
7101
- founded += 1
7102
- if (founded === 2) break
7103
- }
7104
- }
7105
- // If the token is a word, e.g. `!important`, `red` or any other valid property's value.
7106
- // Then we need to return the colon after that word token. [3] is the "end" colon of that word.
7107
- // And because we need it after that one we do +1 to get the next one.
7108
- throw this.input.error(
7109
- 'Missed semicolon',
7110
- token[0] === 'word' ? token[3] + 1 : token[2]
7111
- )
7112
- }
7113
7180
  }
7114
7181
 
7115
7182
  module.exports = Parser
@@ -7267,22 +7334,37 @@ class PreviousMap {
7267
7334
  return this.consumerCache
7268
7335
  }
7269
7336
 
7270
- withContent() {
7271
- return !!(
7272
- this.consumer().sourcesContent &&
7273
- this.consumer().sourcesContent.length > 0
7274
- )
7275
- }
7337
+ decodeInline(text) {
7338
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
7339
+ let baseUri = /^data:application\/json;base64,/
7340
+ let charsetUri = /^data:application\/json;charset=utf-?8,/
7341
+ let uri = /^data:application\/json,/
7276
7342
 
7277
- startWith(string, start) {
7278
- if (!string) return false
7279
- return string.substr(0, start.length) === start
7343
+ if (charsetUri.test(text) || uri.test(text)) {
7344
+ return decodeURIComponent(text.substr(RegExp.lastMatch.length))
7345
+ }
7346
+
7347
+ if (baseCharsetUri.test(text) || baseUri.test(text)) {
7348
+ return fromBase64(text.substr(RegExp.lastMatch.length))
7349
+ }
7350
+
7351
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1]
7352
+ throw new Error('Unsupported source map encoding ' + encoding)
7280
7353
  }
7281
7354
 
7282
7355
  getAnnotationURL(sourceMapString) {
7283
7356
  return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
7284
7357
  }
7285
7358
 
7359
+ isMap(map) {
7360
+ if (typeof map !== 'object') return false
7361
+ return (
7362
+ typeof map.mappings === 'string' ||
7363
+ typeof map._mappings === 'string' ||
7364
+ Array.isArray(map.sections)
7365
+ )
7366
+ }
7367
+
7286
7368
  loadAnnotation(css) {
7287
7369
  let comments = css.match(/\/\*\s*# sourceMappingURL=/gm)
7288
7370
  if (!comments) return
@@ -7297,24 +7379,6 @@ class PreviousMap {
7297
7379
  }
7298
7380
  }
7299
7381
 
7300
- decodeInline(text) {
7301
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
7302
- let baseUri = /^data:application\/json;base64,/
7303
- let charsetUri = /^data:application\/json;charset=utf-?8,/
7304
- let uri = /^data:application\/json,/
7305
-
7306
- if (charsetUri.test(text) || uri.test(text)) {
7307
- return decodeURIComponent(text.substr(RegExp.lastMatch.length))
7308
- }
7309
-
7310
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
7311
- return fromBase64(text.substr(RegExp.lastMatch.length))
7312
- }
7313
-
7314
- let encoding = text.match(/data:application\/json;([^,]+),/)[1]
7315
- throw new Error('Unsupported source map encoding ' + encoding)
7316
- }
7317
-
7318
7382
  loadFile(path) {
7319
7383
  this.root = dirname(path)
7320
7384
  if (existsSync(path)) {
@@ -7360,12 +7424,15 @@ class PreviousMap {
7360
7424
  }
7361
7425
  }
7362
7426
 
7363
- isMap(map) {
7364
- if (typeof map !== 'object') return false
7365
- return (
7366
- typeof map.mappings === 'string' ||
7367
- typeof map._mappings === 'string' ||
7368
- Array.isArray(map.sections)
7427
+ startWith(string, start) {
7428
+ if (!string) return false
7429
+ return string.substr(0, start.length) === start
7430
+ }
7431
+
7432
+ withContent() {
7433
+ return !!(
7434
+ this.consumer().sourcesContent &&
7435
+ this.consumer().sourcesContent.length > 0
7369
7436
  )
7370
7437
  }
7371
7438
  }
@@ -7389,28 +7456,10 @@ let Root = __nccwpck_require__(9659)
7389
7456
 
7390
7457
  class Processor {
7391
7458
  constructor(plugins = []) {
7392
- this.version = '8.4.23'
7459
+ this.version = '8.4.31'
7393
7460
  this.plugins = this.normalize(plugins)
7394
7461
  }
7395
7462
 
7396
- use(plugin) {
7397
- this.plugins = this.plugins.concat(this.normalize([plugin]))
7398
- return this
7399
- }
7400
-
7401
- process(css, opts = {}) {
7402
- if (
7403
- this.plugins.length === 0 &&
7404
- typeof opts.parser === 'undefined' &&
7405
- typeof opts.stringifier === 'undefined' &&
7406
- typeof opts.syntax === 'undefined'
7407
- ) {
7408
- return new NoWorkResult(this, css, opts)
7409
- } else {
7410
- return new LazyResult(this, css, opts)
7411
- }
7412
- }
7413
-
7414
7463
  normalize(plugins) {
7415
7464
  let normalized = []
7416
7465
  for (let i of plugins) {
@@ -7440,6 +7489,24 @@ class Processor {
7440
7489
  }
7441
7490
  return normalized
7442
7491
  }
7492
+
7493
+ process(css, opts = {}) {
7494
+ if (
7495
+ this.plugins.length === 0 &&
7496
+ typeof opts.parser === 'undefined' &&
7497
+ typeof opts.stringifier === 'undefined' &&
7498
+ typeof opts.syntax === 'undefined'
7499
+ ) {
7500
+ return new NoWorkResult(this, css, opts)
7501
+ } else {
7502
+ return new LazyResult(this, css, opts)
7503
+ }
7504
+ }
7505
+
7506
+ use(plugin) {
7507
+ this.plugins = this.plugins.concat(this.normalize([plugin]))
7508
+ return this
7509
+ }
7443
7510
  }
7444
7511
 
7445
7512
  module.exports = Processor
@@ -7518,16 +7585,6 @@ class Root extends Container {
7518
7585
  if (!this.nodes) this.nodes = []
7519
7586
  }
7520
7587
 
7521
- removeChild(child, ignore) {
7522
- let index = this.index(child)
7523
-
7524
- if (!ignore && index === 0 && this.nodes.length > 1) {
7525
- this.nodes[1].raws.before = this.nodes[index].raws.before
7526
- }
7527
-
7528
- return super.removeChild(child)
7529
- }
7530
-
7531
7588
  normalize(child, sample, type) {
7532
7589
  let nodes = super.normalize(child)
7533
7590
 
@@ -7548,6 +7605,16 @@ class Root extends Container {
7548
7605
  return nodes
7549
7606
  }
7550
7607
 
7608
+ removeChild(child, ignore) {
7609
+ let index = this.index(child)
7610
+
7611
+ if (!ignore && index === 0 && this.nodes.length > 1) {
7612
+ this.nodes[1].raws.before = this.nodes[index].raws.before
7613
+ }
7614
+
7615
+ return super.removeChild(child)
7616
+ }
7617
+
7551
7618
  toResult(opts = {}) {
7552
7619
  let lazy = new LazyResult(new Processor(), this, opts)
7553
7620
  return lazy.stringify()
@@ -7612,17 +7679,17 @@ Container.registerRule(Rule)
7612
7679
 
7613
7680
 
7614
7681
  const DEFAULT_RAW = {
7615
- colon: ': ',
7616
- indent: ' ',
7617
- beforeDecl: '\n',
7618
- beforeRule: '\n',
7619
- beforeOpen: ' ',
7682
+ after: '\n',
7620
7683
  beforeClose: '\n',
7621
7684
  beforeComment: '\n',
7622
- after: '\n',
7623
- emptyBody: '',
7685
+ beforeDecl: '\n',
7686
+ beforeOpen: ' ',
7687
+ beforeRule: '\n',
7688
+ colon: ': ',
7624
7689
  commentLeft: ' ',
7625
7690
  commentRight: ' ',
7691
+ emptyBody: '',
7692
+ indent: ' ',
7626
7693
  semicolon: false
7627
7694
  }
7628
7695
 
@@ -7630,57 +7697,9 @@ function capitalize(str) {
7630
7697
  return str[0].toUpperCase() + str.slice(1)
7631
7698
  }
7632
7699
 
7633
- class Stringifier {
7634
- constructor(builder) {
7635
- this.builder = builder
7636
- }
7637
-
7638
- stringify(node, semicolon) {
7639
- /* c8 ignore start */
7640
- if (!this[node.type]) {
7641
- throw new Error(
7642
- 'Unknown AST node type ' +
7643
- node.type +
7644
- '. ' +
7645
- 'Maybe you need to change PostCSS stringifier.'
7646
- )
7647
- }
7648
- /* c8 ignore stop */
7649
- this[node.type](node, semicolon)
7650
- }
7651
-
7652
- document(node) {
7653
- this.body(node)
7654
- }
7655
-
7656
- root(node) {
7657
- this.body(node)
7658
- if (node.raws.after) this.builder(node.raws.after)
7659
- }
7660
-
7661
- comment(node) {
7662
- let left = this.raw(node, 'left', 'commentLeft')
7663
- let right = this.raw(node, 'right', 'commentRight')
7664
- this.builder('/*' + left + node.text + right + '*/', node)
7665
- }
7666
-
7667
- decl(node, semicolon) {
7668
- let between = this.raw(node, 'between', 'colon')
7669
- let string = node.prop + between + this.rawValue(node, 'value')
7670
-
7671
- if (node.important) {
7672
- string += node.raws.important || ' !important'
7673
- }
7674
-
7675
- if (semicolon) string += ';'
7676
- this.builder(string, node)
7677
- }
7678
-
7679
- rule(node) {
7680
- this.block(node, this.rawValue(node, 'selector'))
7681
- if (node.raws.ownSemicolon) {
7682
- this.builder(node.raws.ownSemicolon, node, 'end')
7683
- }
7700
+ class Stringifier {
7701
+ constructor(builder) {
7702
+ this.builder = builder
7684
7703
  }
7685
7704
 
7686
7705
  atrule(node, semicolon) {
@@ -7701,20 +7720,33 @@ class Stringifier {
7701
7720
  }
7702
7721
  }
7703
7722
 
7704
- body(node) {
7705
- let last = node.nodes.length - 1
7706
- while (last > 0) {
7707
- if (node.nodes[last].type !== 'comment') break
7708
- last -= 1
7723
+ beforeAfter(node, detect) {
7724
+ let value
7725
+ if (node.type === 'decl') {
7726
+ value = this.raw(node, null, 'beforeDecl')
7727
+ } else if (node.type === 'comment') {
7728
+ value = this.raw(node, null, 'beforeComment')
7729
+ } else if (detect === 'before') {
7730
+ value = this.raw(node, null, 'beforeRule')
7731
+ } else {
7732
+ value = this.raw(node, null, 'beforeClose')
7709
7733
  }
7710
7734
 
7711
- let semicolon = this.raw(node, 'semicolon')
7712
- for (let i = 0; i < node.nodes.length; i++) {
7713
- let child = node.nodes[i]
7714
- let before = this.raw(child, 'before')
7715
- if (before) this.builder(before)
7716
- this.stringify(child, last !== i || semicolon)
7735
+ let buf = node.parent
7736
+ let depth = 0
7737
+ while (buf && buf.type !== 'root') {
7738
+ depth += 1
7739
+ buf = buf.parent
7740
+ }
7741
+
7742
+ if (value.includes('\n')) {
7743
+ let indent = this.raw(node, null, 'indent')
7744
+ if (indent.length) {
7745
+ for (let step = 0; step < depth; step++) value += indent
7746
+ }
7717
7747
  }
7748
+
7749
+ return value
7718
7750
  }
7719
7751
 
7720
7752
  block(node, start) {
@@ -7733,6 +7765,44 @@ class Stringifier {
7733
7765
  this.builder('}', node, 'end')
7734
7766
  }
7735
7767
 
7768
+ body(node) {
7769
+ let last = node.nodes.length - 1
7770
+ while (last > 0) {
7771
+ if (node.nodes[last].type !== 'comment') break
7772
+ last -= 1
7773
+ }
7774
+
7775
+ let semicolon = this.raw(node, 'semicolon')
7776
+ for (let i = 0; i < node.nodes.length; i++) {
7777
+ let child = node.nodes[i]
7778
+ let before = this.raw(child, 'before')
7779
+ if (before) this.builder(before)
7780
+ this.stringify(child, last !== i || semicolon)
7781
+ }
7782
+ }
7783
+
7784
+ comment(node) {
7785
+ let left = this.raw(node, 'left', 'commentLeft')
7786
+ let right = this.raw(node, 'right', 'commentRight')
7787
+ this.builder('/*' + left + node.text + right + '*/', node)
7788
+ }
7789
+
7790
+ decl(node, semicolon) {
7791
+ let between = this.raw(node, 'between', 'colon')
7792
+ let string = node.prop + between + this.rawValue(node, 'value')
7793
+
7794
+ if (node.important) {
7795
+ string += node.raws.important || ' !important'
7796
+ }
7797
+
7798
+ if (semicolon) string += ';'
7799
+ this.builder(string, node)
7800
+ }
7801
+
7802
+ document(node) {
7803
+ this.body(node)
7804
+ }
7805
+
7736
7806
  raw(node, own, detect) {
7737
7807
  let value
7738
7808
  if (!detect) detect = own
@@ -7787,42 +7857,20 @@ class Stringifier {
7787
7857
  return value
7788
7858
  }
7789
7859
 
7790
- rawSemicolon(root) {
7791
- let value
7792
- root.walk(i => {
7793
- if (i.nodes && i.nodes.length && i.last.type === 'decl') {
7794
- value = i.raws.semicolon
7795
- if (typeof value !== 'undefined') return false
7796
- }
7797
- })
7798
- return value
7799
- }
7800
-
7801
- rawEmptyBody(root) {
7802
- let value
7803
- root.walk(i => {
7804
- if (i.nodes && i.nodes.length === 0) {
7805
- value = i.raws.after
7806
- if (typeof value !== 'undefined') return false
7807
- }
7808
- })
7809
- return value
7810
- }
7811
-
7812
- rawIndent(root) {
7813
- if (root.raws.indent) return root.raws.indent
7860
+ rawBeforeClose(root) {
7814
7861
  let value
7815
7862
  root.walk(i => {
7816
- let p = i.parent
7817
- if (p && p !== root && p.parent && p.parent === root) {
7818
- if (typeof i.raws.before !== 'undefined') {
7819
- let parts = i.raws.before.split('\n')
7820
- value = parts[parts.length - 1]
7821
- value = value.replace(/\S/g, '')
7863
+ if (i.nodes && i.nodes.length > 0) {
7864
+ if (typeof i.raws.after !== 'undefined') {
7865
+ value = i.raws.after
7866
+ if (value.includes('\n')) {
7867
+ value = value.replace(/[^\n]+$/, '')
7868
+ }
7822
7869
  return false
7823
7870
  }
7824
7871
  }
7825
7872
  })
7873
+ if (value) value = value.replace(/\S/g, '')
7826
7874
  return value
7827
7875
  }
7828
7876
 
@@ -7864,6 +7912,17 @@ class Stringifier {
7864
7912
  return value
7865
7913
  }
7866
7914
 
7915
+ rawBeforeOpen(root) {
7916
+ let value
7917
+ root.walk(i => {
7918
+ if (i.type !== 'decl') {
7919
+ value = i.raws.between
7920
+ if (typeof value !== 'undefined') return false
7921
+ }
7922
+ })
7923
+ return value
7924
+ }
7925
+
7867
7926
  rawBeforeRule(root) {
7868
7927
  let value
7869
7928
  root.walk(i => {
@@ -7881,71 +7940,53 @@ class Stringifier {
7881
7940
  return value
7882
7941
  }
7883
7942
 
7884
- rawBeforeClose(root) {
7943
+ rawColon(root) {
7885
7944
  let value
7886
- root.walk(i => {
7887
- if (i.nodes && i.nodes.length > 0) {
7888
- if (typeof i.raws.after !== 'undefined') {
7889
- value = i.raws.after
7890
- if (value.includes('\n')) {
7891
- value = value.replace(/[^\n]+$/, '')
7892
- }
7893
- return false
7894
- }
7945
+ root.walkDecls(i => {
7946
+ if (typeof i.raws.between !== 'undefined') {
7947
+ value = i.raws.between.replace(/[^\s:]/g, '')
7948
+ return false
7895
7949
  }
7896
7950
  })
7897
- if (value) value = value.replace(/\S/g, '')
7898
7951
  return value
7899
7952
  }
7900
7953
 
7901
- rawBeforeOpen(root) {
7954
+ rawEmptyBody(root) {
7902
7955
  let value
7903
7956
  root.walk(i => {
7904
- if (i.type !== 'decl') {
7905
- value = i.raws.between
7957
+ if (i.nodes && i.nodes.length === 0) {
7958
+ value = i.raws.after
7906
7959
  if (typeof value !== 'undefined') return false
7907
7960
  }
7908
7961
  })
7909
7962
  return value
7910
7963
  }
7911
7964
 
7912
- rawColon(root) {
7965
+ rawIndent(root) {
7966
+ if (root.raws.indent) return root.raws.indent
7913
7967
  let value
7914
- root.walkDecls(i => {
7915
- if (typeof i.raws.between !== 'undefined') {
7916
- value = i.raws.between.replace(/[^\s:]/g, '')
7917
- return false
7968
+ root.walk(i => {
7969
+ let p = i.parent
7970
+ if (p && p !== root && p.parent && p.parent === root) {
7971
+ if (typeof i.raws.before !== 'undefined') {
7972
+ let parts = i.raws.before.split('\n')
7973
+ value = parts[parts.length - 1]
7974
+ value = value.replace(/\S/g, '')
7975
+ return false
7976
+ }
7918
7977
  }
7919
7978
  })
7920
7979
  return value
7921
7980
  }
7922
7981
 
7923
- beforeAfter(node, detect) {
7982
+ rawSemicolon(root) {
7924
7983
  let value
7925
- if (node.type === 'decl') {
7926
- value = this.raw(node, null, 'beforeDecl')
7927
- } else if (node.type === 'comment') {
7928
- value = this.raw(node, null, 'beforeComment')
7929
- } else if (detect === 'before') {
7930
- value = this.raw(node, null, 'beforeRule')
7931
- } else {
7932
- value = this.raw(node, null, 'beforeClose')
7933
- }
7934
-
7935
- let buf = node.parent
7936
- let depth = 0
7937
- while (buf && buf.type !== 'root') {
7938
- depth += 1
7939
- buf = buf.parent
7940
- }
7941
-
7942
- if (value.includes('\n')) {
7943
- let indent = this.raw(node, null, 'indent')
7944
- if (indent.length) {
7945
- for (let step = 0; step < depth; step++) value += indent
7984
+ root.walk(i => {
7985
+ if (i.nodes && i.nodes.length && i.last.type === 'decl') {
7986
+ value = i.raws.semicolon
7987
+ if (typeof value !== 'undefined') return false
7946
7988
  }
7947
- }
7948
-
7989
+ })
7949
7990
  return value
7950
7991
  }
7951
7992
 
@@ -7958,6 +7999,32 @@ class Stringifier {
7958
7999
 
7959
8000
  return value
7960
8001
  }
8002
+
8003
+ root(node) {
8004
+ this.body(node)
8005
+ if (node.raws.after) this.builder(node.raws.after)
8006
+ }
8007
+
8008
+ rule(node) {
8009
+ this.block(node, this.rawValue(node, 'selector'))
8010
+ if (node.raws.ownSemicolon) {
8011
+ this.builder(node.raws.ownSemicolon, node, 'end')
8012
+ }
8013
+ }
8014
+
8015
+ stringify(node, semicolon) {
8016
+ /* c8 ignore start */
8017
+ if (!this[node.type]) {
8018
+ throw new Error(
8019
+ 'Unknown AST node type ' +
8020
+ node.type +
8021
+ '. ' +
8022
+ 'Maybe you need to change PostCSS stringifier.'
8023
+ )
8024
+ }
8025
+ /* c8 ignore stop */
8026
+ this[node.type](node, semicolon)
8027
+ }
7961
8028
  }
7962
8029
 
7963
8030
  module.exports = Stringifier
@@ -8015,21 +8082,21 @@ function registerInput(dependant) {
8015
8082
  }
8016
8083
 
8017
8084
  const HIGHLIGHT_THEME = {
8018
- 'brackets': pico.cyan,
8019
- 'at-word': pico.cyan,
8020
- 'comment': pico.gray,
8021
- 'string': pico.green,
8022
- 'class': pico.yellow,
8023
- 'hash': pico.magenta,
8024
- 'call': pico.cyan,
8085
+ ';': pico.yellow,
8086
+ ':': pico.yellow,
8025
8087
  '(': pico.cyan,
8026
8088
  ')': pico.cyan,
8027
- '{': pico.yellow,
8028
- '}': pico.yellow,
8029
8089
  '[': pico.yellow,
8030
8090
  ']': pico.yellow,
8031
- ':': pico.yellow,
8032
- ';': pico.yellow
8091
+ '{': pico.yellow,
8092
+ '}': pico.yellow,
8093
+ 'at-word': pico.cyan,
8094
+ 'brackets': pico.cyan,
8095
+ 'call': pico.cyan,
8096
+ 'class': pico.yellow,
8097
+ 'comment': pico.gray,
8098
+ 'hash': pico.magenta,
8099
+ 'string': pico.green
8033
8100
  }
8034
8101
 
8035
8102
  function getTokenType([type, value], processor) {
@@ -8104,7 +8171,7 @@ const AT = '@'.charCodeAt(0)
8104
8171
 
8105
8172
  const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g
8106
8173
  const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g
8107
- const RE_BAD_BRACKET = /.[\n"'(/\\]/
8174
+ const RE_BAD_BRACKET = /.[\r\n"'(/\\]/
8108
8175
  const RE_HEX_ESCAPE = /[\da-f]/i
8109
8176
 
8110
8177
  module.exports = function tokenizer(input, options = {}) {
@@ -8341,8 +8408,8 @@ module.exports = function tokenizer(input, options = {}) {
8341
8408
 
8342
8409
  return {
8343
8410
  back,
8344
- nextToken,
8345
8411
  endOfFile,
8412
+ nextToken,
8346
8413
  position
8347
8414
  }
8348
8415
  }
@@ -8396,8 +8463,8 @@ class Warning {
8396
8463
  toString() {
8397
8464
  if (this.node) {
8398
8465
  return this.node.error(this.text, {
8399
- plugin: this.plugin,
8400
8466
  index: this.index,
8467
+ plugin: this.plugin,
8401
8468
  word: this.word
8402
8469
  }).message
8403
8470
  }
@@ -8441,8 +8508,17 @@ var _path = _interopRequireDefault(__nccwpck_require__(1017));
8441
8508
  var _utils = __nccwpck_require__(1911);
8442
8509
  var _options = _interopRequireDefault(__nccwpck_require__(5814));
8443
8510
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8444
- const loaderAPI = () => {};
8445
- loaderAPI.pitch = function loader(request) {
8511
+ // eslint-disable-next-line consistent-return
8512
+ const loader = function loader(content) {
8513
+ if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && this._module.type === "css") {
8514
+ return content;
8515
+ }
8516
+ };
8517
+ loader.pitch = function pitch(request) {
8518
+ if (this._compiler && this._compiler.options && this._compiler.options.experiments && this._compiler.options.experiments.css && this._module && this._module.type === "css") {
8519
+ this.emitWarning(new Error('You can\'t use `experiments.css` (`experiments.futureDefaults` enable built-in CSS support by default) and `style-loader` together, please set `experiments.css` to `false` or set `{ type: "javascript/auto" }` for rules with `style-loader` in your webpack config (now `style-loader` does nothing).'));
8520
+ return;
8521
+ }
8446
8522
  const options = this.getOptions(_options.default);
8447
8523
  const injectType = options.injectType || "styleTag";
8448
8524
  const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
@@ -8459,6 +8535,8 @@ loaderAPI.pitch = function loader(request) {
8459
8535
  case "linkTag":
8460
8536
  {
8461
8537
  const hmrCode = this.hot ? (0, _utils.getLinkHmrCode)(esModule, this, request) : "";
8538
+
8539
+ // eslint-disable-next-line consistent-return
8462
8540
  return `
8463
8541
  ${(0, _utils.getImportLinkAPICode)(esModule, this)}
8464
8542
  ${(0, _utils.getImportInsertBySelectorCode)(esModule, this, insertType, options)}
@@ -8482,6 +8560,8 @@ ${esModule ? "export default {}" : ""}`;
8482
8560
  const isSingleton = injectType === "lazySingletonStyleTag";
8483
8561
  const isAuto = injectType === "lazyAutoStyleTag";
8484
8562
  const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, true) : "";
8563
+
8564
+ // eslint-disable-next-line consistent-return
8485
8565
  return `
8486
8566
  var exported = {};
8487
8567
 
@@ -8539,6 +8619,8 @@ ${(0, _utils.getExportLazyStyleCode)(esModule, this, request)}
8539
8619
  const isSingleton = injectType === "singletonStyleTag";
8540
8620
  const isAuto = injectType === "autoStyleTag";
8541
8621
  const hmrCode = this.hot ? (0, _utils.getStyleHmrCode)(esModule, this, request, false) : "";
8622
+
8623
+ // eslint-disable-next-line consistent-return
8542
8624
  return `
8543
8625
  ${(0, _utils.getImportStyleAPICode)(esModule, this)}
8544
8626
  ${(0, _utils.getImportStyleDomAPICode)(esModule, this, isSingleton, isAuto)}
@@ -8567,7 +8649,7 @@ ${(0, _utils.getExportStyleCode)(esModule, this, request)}
8567
8649
  }
8568
8650
  }
8569
8651
  };
8570
- var _default = loaderAPI;
8652
+ var _default = loader;
8571
8653
  exports["default"] = _default;
8572
8654
 
8573
8655
  /***/ }),
@@ -9007,7 +9089,7 @@ module.exports = JSON.parse('{"title":"CSS Loader options","additionalProperties
9007
9089
  /***/ ((module) => {
9008
9090
 
9009
9091
  "use strict";
9010
- module.exports = JSON.parse('{"name":"postcss","version":"8.4.23","description":"Tool for transforming styles with JS plugins","engines":{"node":"^10 || ^12 || >=14"},"exports":{".":{"require":"./lib/postcss.js","import":"./lib/postcss.mjs"},"./lib/at-rule":"./lib/at-rule.js","./lib/comment":"./lib/comment.js","./lib/container":"./lib/container.js","./lib/css-syntax-error":"./lib/css-syntax-error.js","./lib/declaration":"./lib/declaration.js","./lib/fromJSON":"./lib/fromJSON.js","./lib/input":"./lib/input.js","./lib/lazy-result":"./lib/lazy-result.js","./lib/no-work-result":"./lib/no-work-result.js","./lib/list":"./lib/list.js","./lib/map-generator":"./lib/map-generator.js","./lib/node":"./lib/node.js","./lib/parse":"./lib/parse.js","./lib/parser":"./lib/parser.js","./lib/postcss":"./lib/postcss.js","./lib/previous-map":"./lib/previous-map.js","./lib/processor":"./lib/processor.js","./lib/result":"./lib/result.js","./lib/root":"./lib/root.js","./lib/rule":"./lib/rule.js","./lib/stringifier":"./lib/stringifier.js","./lib/stringify":"./lib/stringify.js","./lib/symbols":"./lib/symbols.js","./lib/terminal-highlight":"./lib/terminal-highlight.js","./lib/tokenize":"./lib/tokenize.js","./lib/warn-once":"./lib/warn-once.js","./lib/warning":"./lib/warning.js","./package.json":"./package.json"},"main":"./lib/postcss.js","types":"./lib/postcss.d.ts","keywords":["css","postcss","rework","preprocessor","parser","source map","transform","manipulation","transpiler"],"funding":[{"type":"opencollective","url":"https://opencollective.com/postcss/"},{"type":"tidelift","url":"https://tidelift.com/funding/github/npm/postcss"},{"type":"github","url":"https://github.com/sponsors/ai"}],"author":"Andrey Sitnik <andrey@sitnik.ru>","license":"MIT","homepage":"https://postcss.org/","repository":"postcss/postcss","bugs":{"url":"https://github.com/postcss/postcss/issues"},"dependencies":{"nanoid":"^3.3.6","picocolors":"^1.0.0","source-map-js":"^1.0.2"},"browser":{"./lib/terminal-highlight":false,"source-map-js":false,"path":false,"url":false,"fs":false}}');
9092
+ module.exports = JSON.parse('{"name":"postcss","version":"8.4.31","description":"Tool for transforming styles with JS plugins","engines":{"node":"^10 || ^12 || >=14"},"exports":{".":{"require":"./lib/postcss.js","import":"./lib/postcss.mjs"},"./lib/at-rule":"./lib/at-rule.js","./lib/comment":"./lib/comment.js","./lib/container":"./lib/container.js","./lib/css-syntax-error":"./lib/css-syntax-error.js","./lib/declaration":"./lib/declaration.js","./lib/fromJSON":"./lib/fromJSON.js","./lib/input":"./lib/input.js","./lib/lazy-result":"./lib/lazy-result.js","./lib/no-work-result":"./lib/no-work-result.js","./lib/list":"./lib/list.js","./lib/map-generator":"./lib/map-generator.js","./lib/node":"./lib/node.js","./lib/parse":"./lib/parse.js","./lib/parser":"./lib/parser.js","./lib/postcss":"./lib/postcss.js","./lib/previous-map":"./lib/previous-map.js","./lib/processor":"./lib/processor.js","./lib/result":"./lib/result.js","./lib/root":"./lib/root.js","./lib/rule":"./lib/rule.js","./lib/stringifier":"./lib/stringifier.js","./lib/stringify":"./lib/stringify.js","./lib/symbols":"./lib/symbols.js","./lib/terminal-highlight":"./lib/terminal-highlight.js","./lib/tokenize":"./lib/tokenize.js","./lib/warn-once":"./lib/warn-once.js","./lib/warning":"./lib/warning.js","./package.json":"./package.json"},"main":"./lib/postcss.js","types":"./lib/postcss.d.ts","keywords":["css","postcss","rework","preprocessor","parser","source map","transform","manipulation","transpiler"],"funding":[{"type":"opencollective","url":"https://opencollective.com/postcss/"},{"type":"tidelift","url":"https://tidelift.com/funding/github/npm/postcss"},{"type":"github","url":"https://github.com/sponsors/ai"}],"author":"Andrey Sitnik <andrey@sitnik.ru>","license":"MIT","homepage":"https://postcss.org/","repository":"postcss/postcss","bugs":{"url":"https://github.com/postcss/postcss/issues"},"dependencies":{"nanoid":"^3.3.6","picocolors":"^1.0.0","source-map-js":"^1.0.2"},"browser":{"./lib/terminal-highlight":false,"source-map-js":false,"path":false,"url":false,"fs":false}}');
9011
9093
 
9012
9094
  /***/ }),
9013
9095