css-loader 1.0.1 → 7.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.js ADDED
@@ -0,0 +1,1068 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WEBPACK_IGNORE_COMMENT_REGEXP = void 0;
7
+ exports.camelCase = camelCase;
8
+ exports.combineRequests = combineRequests;
9
+ exports.defaultGetLocalIdent = defaultGetLocalIdent;
10
+ exports.getExportCode = getExportCode;
11
+ exports.getFilter = getFilter;
12
+ exports.getImportCode = getImportCode;
13
+ exports.getModuleCode = getModuleCode;
14
+ exports.getModulesOptions = getModulesOptions;
15
+ exports.getModulesPlugins = getModulesPlugins;
16
+ exports.getPreRequester = getPreRequester;
17
+ exports.isDataUrl = isDataUrl;
18
+ exports.isURLRequestable = isURLRequestable;
19
+ exports.normalizeOptions = normalizeOptions;
20
+ exports.normalizeSourceMap = normalizeSourceMap;
21
+ exports.normalizeUrl = normalizeUrl;
22
+ exports.requestify = requestify;
23
+ exports.resolveRequests = resolveRequests;
24
+ exports.shouldUseIcssPlugin = shouldUseIcssPlugin;
25
+ exports.shouldUseImportPlugin = shouldUseImportPlugin;
26
+ exports.shouldUseModulesPlugins = shouldUseModulesPlugins;
27
+ exports.shouldUseURLPlugin = shouldUseURLPlugin;
28
+ exports.sort = sort;
29
+ exports.stringifyRequest = stringifyRequest;
30
+ exports.supportTemplateLiteral = supportTemplateLiteral;
31
+ exports.syntaxErrorFactory = syntaxErrorFactory;
32
+ exports.warningFactory = warningFactory;
33
+ var _url = require("url");
34
+ var _path = _interopRequireDefault(require("path"));
35
+ var _postcssModulesValues = _interopRequireDefault(require("postcss-modules-values"));
36
+ var _postcssModulesLocalByDefault = _interopRequireDefault(require("postcss-modules-local-by-default"));
37
+ var _postcssModulesExtractImports = _interopRequireDefault(require("postcss-modules-extract-imports"));
38
+ var _postcssModulesScope = _interopRequireDefault(require("postcss-modules-scope"));
39
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
40
+ /*
41
+ MIT License http://www.opensource.org/licenses/mit-license.php
42
+ Author Tobias Koppers @sokra
43
+ */
44
+
45
+ const WEBPACK_IGNORE_COMMENT_REGEXP = exports.WEBPACK_IGNORE_COMMENT_REGEXP = /webpackIgnore:(\s+)?(true|false)/;
46
+ function stringifyRequest(loaderContext, request) {
47
+ return JSON.stringify(loaderContext.utils.contextify(loaderContext.context || loaderContext.rootContext, request));
48
+ }
49
+
50
+ // We can't use path.win32.isAbsolute because it also matches paths starting with a forward slash
51
+ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
52
+ const IS_MODULE_REQUEST = /^[^?]*~/;
53
+ function urlToRequest(url, root) {
54
+ let request;
55
+ if (IS_NATIVE_WIN32_PATH.test(url)) {
56
+ // absolute windows path, keep it
57
+ request = url;
58
+ } else if (typeof root !== "undefined" && /^\//.test(url)) {
59
+ request = root + url;
60
+ } else if (/^\.\.?\//.test(url)) {
61
+ // A relative url stays
62
+ request = url;
63
+ } else {
64
+ // every other url is threaded like a relative url
65
+ request = `./${url}`;
66
+ }
67
+
68
+ // A `~` makes the url an module
69
+ if (IS_MODULE_REQUEST.test(request)) {
70
+ request = request.replace(IS_MODULE_REQUEST, "");
71
+ }
72
+ return request;
73
+ }
74
+
75
+ // eslint-disable-next-line no-useless-escape
76
+ const regexSingleEscape = /[ -,.\/:-@[\]\^`{-~]/;
77
+ const regexExcessiveSpaces = /(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g;
78
+ const preserveCamelCase = string => {
79
+ let result = string;
80
+ let isLastCharLower = false;
81
+ let isLastCharUpper = false;
82
+ let isLastLastCharUpper = false;
83
+ for (let i = 0; i < result.length; i++) {
84
+ const character = result[i];
85
+ if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
86
+ result = `${result.slice(0, i)}-${result.slice(i)}`;
87
+ isLastCharLower = false;
88
+ isLastLastCharUpper = isLastCharUpper;
89
+ isLastCharUpper = true;
90
+ i += 1;
91
+ } else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
92
+ result = `${result.slice(0, i - 1)}-${result.slice(i - 1)}`;
93
+ isLastLastCharUpper = isLastCharUpper;
94
+ isLastCharUpper = false;
95
+ isLastCharLower = true;
96
+ } else {
97
+ isLastCharLower = character.toLowerCase() === character && character.toUpperCase() !== character;
98
+ isLastLastCharUpper = isLastCharUpper;
99
+ isLastCharUpper = character.toUpperCase() === character && character.toLowerCase() !== character;
100
+ }
101
+ }
102
+ return result;
103
+ };
104
+ function camelCase(input) {
105
+ let result = input.trim();
106
+ if (result.length === 0) {
107
+ return "";
108
+ }
109
+ if (result.length === 1) {
110
+ return result.toLowerCase();
111
+ }
112
+ const hasUpperCase = result !== result.toLowerCase();
113
+ if (hasUpperCase) {
114
+ result = preserveCamelCase(result);
115
+ }
116
+ return result.replace(/^[_.\- ]+/, "").toLowerCase().replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toUpperCase()).replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toUpperCase());
117
+ }
118
+ function escape(string) {
119
+ let output = "";
120
+ let counter = 0;
121
+ while (counter < string.length) {
122
+ // eslint-disable-next-line no-plusplus
123
+ const character = string.charAt(counter++);
124
+ let value;
125
+
126
+ // eslint-disable-next-line no-control-regex
127
+ if (/[\t\n\f\r\x0B]/.test(character)) {
128
+ const codePoint = character.charCodeAt();
129
+ value = `\\${codePoint.toString(16).toUpperCase()} `;
130
+ } else if (character === "\\" || regexSingleEscape.test(character)) {
131
+ value = `\\${character}`;
132
+ } else {
133
+ value = character;
134
+ }
135
+ output += value;
136
+ }
137
+ const firstChar = string.charAt(0);
138
+ if (/^-[-\d]/.test(output)) {
139
+ output = `\\-${output.slice(1)}`;
140
+ } else if (/\d/.test(firstChar)) {
141
+ output = `\\3${firstChar} ${output.slice(1)}`;
142
+ }
143
+
144
+ // Remove spaces after `\HEX` escapes that are not followed by a hex digit,
145
+ // since they’re redundant. Note that this is only possible if the escape
146
+ // sequence isn’t preceded by an odd number of backslashes.
147
+ output = output.replace(regexExcessiveSpaces, ($0, $1, $2) => {
148
+ if ($1 && $1.length % 2) {
149
+ // It’s not safe to remove the space, so don’t.
150
+ return $0;
151
+ }
152
+
153
+ // Strip the space.
154
+ return ($1 || "") + $2;
155
+ });
156
+ return output;
157
+ }
158
+ function gobbleHex(str) {
159
+ const lower = str.toLowerCase();
160
+ let hex = "";
161
+ let spaceTerminated = false;
162
+
163
+ // eslint-disable-next-line no-undefined
164
+ for (let i = 0; i < 6 && lower[i] !== undefined; i++) {
165
+ const code = lower.charCodeAt(i);
166
+ // check to see if we are dealing with a valid hex char [a-f|0-9]
167
+ const valid = code >= 97 && code <= 102 || code >= 48 && code <= 57;
168
+ // https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
169
+ spaceTerminated = code === 32;
170
+ if (!valid) {
171
+ break;
172
+ }
173
+ hex += lower[i];
174
+ }
175
+ if (hex.length === 0) {
176
+ // eslint-disable-next-line no-undefined
177
+ return undefined;
178
+ }
179
+ const codePoint = parseInt(hex, 16);
180
+ const isSurrogate = codePoint >= 0xd800 && codePoint <= 0xdfff;
181
+ // Add special case for
182
+ // "If this number is zero, or is for a surrogate, or is greater than the maximum allowed code point"
183
+ // https://drafts.csswg.org/css-syntax/#maximum-allowed-code-point
184
+ if (isSurrogate || codePoint === 0x0000 || codePoint > 0x10ffff) {
185
+ return ["\uFFFD", hex.length + (spaceTerminated ? 1 : 0)];
186
+ }
187
+ return [String.fromCodePoint(codePoint), hex.length + (spaceTerminated ? 1 : 0)];
188
+ }
189
+ const CONTAINS_ESCAPE = /\\/;
190
+ function unescape(str) {
191
+ const needToProcess = CONTAINS_ESCAPE.test(str);
192
+ if (!needToProcess) {
193
+ return str;
194
+ }
195
+ let ret = "";
196
+ for (let i = 0; i < str.length; i++) {
197
+ if (str[i] === "\\") {
198
+ const gobbled = gobbleHex(str.slice(i + 1, i + 7));
199
+
200
+ // eslint-disable-next-line no-undefined
201
+ if (gobbled !== undefined) {
202
+ ret += gobbled[0];
203
+ i += gobbled[1];
204
+
205
+ // eslint-disable-next-line no-continue
206
+ continue;
207
+ }
208
+
209
+ // Retain a pair of \\ if double escaped `\\\\`
210
+ // https://github.com/postcss/postcss-selector-parser/commit/268c9a7656fb53f543dc620aa5b73a30ec3ff20e
211
+ if (str[i + 1] === "\\") {
212
+ ret += "\\";
213
+ i += 1;
214
+
215
+ // eslint-disable-next-line no-continue
216
+ continue;
217
+ }
218
+
219
+ // if \\ is at the end of the string retain it
220
+ // https://github.com/postcss/postcss-selector-parser/commit/01a6b346e3612ce1ab20219acc26abdc259ccefb
221
+ if (str.length === i + 1) {
222
+ ret += str[i];
223
+ }
224
+
225
+ // eslint-disable-next-line no-continue
226
+ continue;
227
+ }
228
+ ret += str[i];
229
+ }
230
+ return ret;
231
+ }
232
+ function normalizePath(file) {
233
+ return _path.default.sep === "\\" ? file.replace(/\\/g, "/") : file;
234
+ }
235
+
236
+ // eslint-disable-next-line no-control-regex
237
+ const filenameReservedRegex = /[<>:"/\\|?*]/g;
238
+ // eslint-disable-next-line no-control-regex
239
+ const reControlChars = /[\u0000-\u001f\u0080-\u009f]/g;
240
+ function escapeLocalIdent(localident) {
241
+ // TODO simplify?
242
+ return escape(localident
243
+ // For `[hash]` placeholder
244
+ .replace(/^((-?[0-9])|--)/, "_$1").replace(filenameReservedRegex, "-").replace(reControlChars, "-").replace(/\./g, "-"));
245
+ }
246
+ function defaultGetLocalIdent(loaderContext, localIdentName, localName, options) {
247
+ const {
248
+ context,
249
+ hashSalt,
250
+ hashStrategy
251
+ } = options;
252
+ const {
253
+ resourcePath
254
+ } = loaderContext;
255
+ let relativeResourcePath = normalizePath(_path.default.relative(context, resourcePath));
256
+
257
+ // eslint-disable-next-line no-underscore-dangle
258
+ if (loaderContext._module && loaderContext._module.matchResource) {
259
+ relativeResourcePath = `${normalizePath(
260
+ // eslint-disable-next-line no-underscore-dangle
261
+ _path.default.relative(context, loaderContext._module.matchResource))}`;
262
+ }
263
+
264
+ // eslint-disable-next-line no-param-reassign
265
+ options.content = hashStrategy === "minimal-subset" && /\[local\]/.test(localIdentName) ? relativeResourcePath : `${relativeResourcePath}\x00${localName}`;
266
+ let {
267
+ hashFunction,
268
+ hashDigest,
269
+ hashDigestLength
270
+ } = options;
271
+ const matches = localIdentName.match(/\[(?:([^:\]]+):)?(?:(hash|contenthash|fullhash))(?::([a-z]+\d*))?(?::(\d+))?\]/i);
272
+ if (matches) {
273
+ const hashName = matches[2] || hashFunction;
274
+ hashFunction = matches[1] || hashFunction;
275
+ hashDigest = matches[3] || hashDigest;
276
+ hashDigestLength = matches[4] || hashDigestLength;
277
+
278
+ // `hash` and `contenthash` are same in `loader-utils` context
279
+ // let's keep `hash` for backward compatibility
280
+
281
+ // eslint-disable-next-line no-param-reassign
282
+ localIdentName = localIdentName.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash|fullhash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, () => hashName === "fullhash" ? "[fullhash]" : "[contenthash]");
283
+ }
284
+ let localIdentHash = "";
285
+ for (let tier = 0; localIdentHash.length < hashDigestLength; tier++) {
286
+ const hash = (loaderContext.utils.createHash ||
287
+ // TODO remove in the next major release
288
+ // eslint-disable-next-line no-underscore-dangle
289
+ loaderContext._compiler.webpack.util.createHash)(hashFunction);
290
+ if (hashSalt) {
291
+ hash.update(hashSalt);
292
+ }
293
+ const tierSalt = Buffer.allocUnsafe(4);
294
+ tierSalt.writeUInt32LE(tier);
295
+ hash.update(tierSalt);
296
+ // TODO: bug in webpack with unicode characters with strings
297
+ hash.update(Buffer.from(options.content, "utf8"));
298
+ localIdentHash = (localIdentHash + hash.digest(hashDigest)
299
+ // Remove all leading digits
300
+ ).replace(/^\d+/, "")
301
+ // Replace all slashes with underscores (same as in base64url)
302
+ .replace(/\//g, "_")
303
+ // Remove everything that is not an alphanumeric or underscore
304
+ .replace(/[^A-Za-z0-9_]+/g, "").slice(0, hashDigestLength);
305
+ }
306
+
307
+ // TODO need improve on webpack side, we should allow to pass hash/contentHash without chunk property, also `data` for `getPath` should be looks good without chunk property
308
+ const ext = _path.default.extname(resourcePath);
309
+ const base = _path.default.basename(resourcePath);
310
+ const name = base.slice(0, base.length - ext.length);
311
+ const data = {
312
+ filename: _path.default.relative(context, resourcePath),
313
+ contentHash: localIdentHash,
314
+ chunk: {
315
+ name,
316
+ hash: localIdentHash,
317
+ contentHash: localIdentHash
318
+ }
319
+ };
320
+
321
+ // eslint-disable-next-line no-underscore-dangle
322
+ let result = loaderContext._compilation.getPath(localIdentName, data);
323
+ if (/\[folder\]/gi.test(result)) {
324
+ const dirname = _path.default.dirname(resourcePath);
325
+ let directory = normalizePath(_path.default.relative(context, `${dirname + _path.default.sep}_`));
326
+ directory = directory.substring(0, directory.length - 1);
327
+ let folder = "";
328
+ if (directory.length > 1) {
329
+ folder = _path.default.basename(directory);
330
+ }
331
+ result = result.replace(/\[folder\]/gi, () => folder);
332
+ }
333
+ if (options.regExp) {
334
+ const match = resourcePath.match(options.regExp);
335
+ if (match) {
336
+ match.forEach((matched, i) => {
337
+ result = result.replace(new RegExp(`\\[${i}\\]`, "ig"), matched);
338
+ });
339
+ }
340
+ }
341
+ return result;
342
+ }
343
+ function fixedEncodeURIComponent(str) {
344
+ return str.replace(/[!'()*]/g, c => `%${c.charCodeAt(0).toString(16)}`);
345
+ }
346
+ function isDataUrl(url) {
347
+ if (/^data:/i.test(url)) {
348
+ return true;
349
+ }
350
+ return false;
351
+ }
352
+ const NATIVE_WIN32_PATH = /^[A-Z]:[/\\]|^\\\\/i;
353
+ function normalizeUrl(url, isStringValue) {
354
+ let normalizedUrl = url.replace(/^( |\t\n|\r\n|\r|\f)*/g, "").replace(/( |\t\n|\r\n|\r|\f)*$/g, "");
355
+ if (isStringValue && /\\(\n|\r\n|\r|\f)/.test(normalizedUrl)) {
356
+ normalizedUrl = normalizedUrl.replace(/\\(\n|\r\n|\r|\f)/g, "");
357
+ }
358
+ if (NATIVE_WIN32_PATH.test(url)) {
359
+ try {
360
+ normalizedUrl = decodeURI(normalizedUrl);
361
+ } catch (error) {
362
+ // Ignore
363
+ }
364
+ return normalizedUrl;
365
+ }
366
+ normalizedUrl = unescape(normalizedUrl);
367
+ if (isDataUrl(url)) {
368
+ // Todo fixedEncodeURIComponent is workaround. Webpack resolver shouldn't handle "!" in dataURL
369
+ return fixedEncodeURIComponent(normalizedUrl);
370
+ }
371
+ try {
372
+ normalizedUrl = decodeURI(normalizedUrl);
373
+ } catch (error) {
374
+ // Ignore
375
+ }
376
+ return normalizedUrl;
377
+ }
378
+ function requestify(url, rootContext, needToResolveURL = true) {
379
+ if (needToResolveURL) {
380
+ if (/^file:/i.test(url)) {
381
+ return (0, _url.fileURLToPath)(url);
382
+ }
383
+ return url.charAt(0) === "/" ? urlToRequest(url, rootContext) : urlToRequest(url);
384
+ }
385
+ if (url.charAt(0) === "/" || /^file:/i.test(url)) {
386
+ return url;
387
+ }
388
+
389
+ // A `~` makes the url an module
390
+ if (IS_MODULE_REQUEST.test(url)) {
391
+ return url.replace(IS_MODULE_REQUEST, "");
392
+ }
393
+ return url;
394
+ }
395
+ function getFilter(filter, resourcePath) {
396
+ return (...args) => {
397
+ if (typeof filter === "function") {
398
+ return filter(...args, resourcePath);
399
+ }
400
+ return true;
401
+ };
402
+ }
403
+ function getValidLocalName(localName, exportLocalsConvention) {
404
+ const result = exportLocalsConvention(localName);
405
+ return Array.isArray(result) ? result[0] : result;
406
+ }
407
+ const IS_MODULES = /\.module(s)?\.\w+$/i;
408
+ const IS_ICSS = /\.icss\.\w+$/i;
409
+ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) {
410
+ if (typeof rawOptions.modules === "boolean" && rawOptions.modules === false) {
411
+ return false;
412
+ }
413
+ const resourcePath =
414
+ // eslint-disable-next-line no-underscore-dangle
415
+ loaderContext._module && loaderContext._module.matchResource || loaderContext.resourcePath;
416
+ let auto;
417
+ let rawModulesOptions;
418
+ if (typeof rawOptions.modules === "undefined") {
419
+ rawModulesOptions = {};
420
+ auto = true;
421
+ } else if (typeof rawOptions.modules === "boolean") {
422
+ rawModulesOptions = {};
423
+ } else if (typeof rawOptions.modules === "string") {
424
+ rawModulesOptions = {
425
+ mode: rawOptions.modules
426
+ };
427
+ } else {
428
+ rawModulesOptions = rawOptions.modules;
429
+ ({
430
+ auto
431
+ } = rawModulesOptions);
432
+ }
433
+ const needNamedExport = exportType === "css-style-sheet" || exportType === "string";
434
+ const namedExport = typeof rawModulesOptions.namedExport !== "undefined" ? rawModulesOptions.namedExport : needNamedExport || esModule;
435
+ const exportLocalsConvention = typeof rawModulesOptions.exportLocalsConvention !== "undefined" ? rawModulesOptions.exportLocalsConvention : namedExport ? "as-is" : "camel-case-only";
436
+ const modulesOptions = {
437
+ auto,
438
+ mode: "local",
439
+ exportGlobals: false,
440
+ localIdentName: "[hash:base64]",
441
+ localIdentContext: loaderContext.rootContext,
442
+ // eslint-disable-next-line no-underscore-dangle
443
+ localIdentHashSalt: loaderContext.hashSalt ||
444
+ // TODO remove in the next major release
445
+ // eslint-disable-next-line no-underscore-dangle
446
+ loaderContext._compilation.outputOptions.hashSalt,
447
+ localIdentHashFunction: loaderContext.hashFunction ||
448
+ // TODO remove in the next major release
449
+ // eslint-disable-next-line no-underscore-dangle
450
+ loaderContext._compilation.outputOptions.hashFunction,
451
+ localIdentHashDigest: loaderContext.hashDigest ||
452
+ // TODO remove in the next major release
453
+ // eslint-disable-next-line no-underscore-dangle
454
+ loaderContext._compilation.outputOptions.hashDigest,
455
+ localIdentHashDigestLength: loaderContext.hashDigestLength ||
456
+ // TODO remove in the next major release
457
+ // eslint-disable-next-line no-underscore-dangle
458
+ loaderContext._compilation.outputOptions.hashDigestLength,
459
+ // eslint-disable-next-line no-undefined
460
+ localIdentRegExp: undefined,
461
+ // eslint-disable-next-line no-undefined
462
+ getLocalIdent: undefined,
463
+ // TODO improve me and enable by default
464
+ exportOnlyLocals: false,
465
+ ...rawModulesOptions,
466
+ exportLocalsConvention,
467
+ namedExport
468
+ };
469
+ if (typeof modulesOptions.exportLocalsConvention === "string") {
470
+ // eslint-disable-next-line no-shadow
471
+ const {
472
+ exportLocalsConvention
473
+ } = modulesOptions;
474
+ modulesOptions.exportLocalsConvention = name => {
475
+ switch (exportLocalsConvention) {
476
+ case "camel-case":
477
+ case "camelCase":
478
+ {
479
+ return [name, camelCase(name)];
480
+ }
481
+ case "camel-case-only":
482
+ case "camelCaseOnly":
483
+ {
484
+ return camelCase(name);
485
+ }
486
+ case "dashes":
487
+ {
488
+ return [name, dashesCamelCase(name)];
489
+ }
490
+ case "dashes-only":
491
+ case "dashesOnly":
492
+ {
493
+ return dashesCamelCase(name);
494
+ }
495
+ case "as-is":
496
+ case "asIs":
497
+ default:
498
+ return name;
499
+ }
500
+ };
501
+ }
502
+ if (typeof modulesOptions.auto === "boolean") {
503
+ const isModules = modulesOptions.auto && IS_MODULES.test(resourcePath);
504
+ let isIcss;
505
+ if (!isModules) {
506
+ isIcss = IS_ICSS.test(resourcePath);
507
+ if (isIcss) {
508
+ modulesOptions.mode = "icss";
509
+ }
510
+ }
511
+ if (!isModules && !isIcss) {
512
+ return false;
513
+ }
514
+ } else if (modulesOptions.auto instanceof RegExp) {
515
+ const isModules = modulesOptions.auto.test(resourcePath);
516
+ if (!isModules) {
517
+ return false;
518
+ }
519
+ } else if (typeof modulesOptions.auto === "function") {
520
+ const {
521
+ resourceQuery,
522
+ resourceFragment
523
+ } = loaderContext;
524
+ const isModule = modulesOptions.auto(resourcePath, resourceQuery, resourceFragment);
525
+ if (!isModule) {
526
+ return false;
527
+ }
528
+ }
529
+ if (typeof modulesOptions.mode === "function") {
530
+ modulesOptions.mode = modulesOptions.mode(loaderContext.resourcePath, loaderContext.resourceQuery, loaderContext.resourceFragment);
531
+ }
532
+ if (needNamedExport) {
533
+ if (esModule === false) {
534
+ throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'esModule' option to be enabled");
535
+ }
536
+ if (modulesOptions.namedExport === false) {
537
+ throw new Error("The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'modules.namedExport' option to be enabled");
538
+ }
539
+ }
540
+ if (modulesOptions.namedExport === true && esModule === false) {
541
+ throw new Error("The 'modules.namedExport' option requires the 'esModule' option to be enabled");
542
+ }
543
+ return modulesOptions;
544
+ }
545
+ function normalizeOptions(rawOptions, loaderContext) {
546
+ const exportType = typeof rawOptions.exportType === "undefined" ? "array" : rawOptions.exportType;
547
+ const esModule = typeof rawOptions.esModule === "undefined" ? true : rawOptions.esModule;
548
+ const modulesOptions = getModulesOptions(rawOptions, esModule, exportType, loaderContext);
549
+ return {
550
+ url: typeof rawOptions.url === "undefined" ? true : rawOptions.url,
551
+ import: typeof rawOptions.import === "undefined" ? true : rawOptions.import,
552
+ modules: modulesOptions,
553
+ sourceMap: typeof rawOptions.sourceMap === "boolean" ? rawOptions.sourceMap : loaderContext.sourceMap,
554
+ importLoaders: typeof rawOptions.importLoaders === "string" ? parseInt(rawOptions.importLoaders, 10) : rawOptions.importLoaders,
555
+ esModule,
556
+ exportType
557
+ };
558
+ }
559
+ function shouldUseImportPlugin(options) {
560
+ if (options.modules.exportOnlyLocals) {
561
+ return false;
562
+ }
563
+ if (typeof options.import === "boolean") {
564
+ return options.import;
565
+ }
566
+ return true;
567
+ }
568
+ function shouldUseURLPlugin(options) {
569
+ if (options.modules.exportOnlyLocals) {
570
+ return false;
571
+ }
572
+ if (typeof options.url === "boolean") {
573
+ return options.url;
574
+ }
575
+ return true;
576
+ }
577
+ function shouldUseModulesPlugins(options) {
578
+ if (typeof options.modules === "boolean" && options.modules === false) {
579
+ return false;
580
+ }
581
+ return options.modules.mode !== "icss";
582
+ }
583
+ function shouldUseIcssPlugin(options) {
584
+ return Boolean(options.modules);
585
+ }
586
+ function getModulesPlugins(options, loaderContext) {
587
+ const {
588
+ mode,
589
+ getLocalIdent,
590
+ localIdentName,
591
+ localIdentContext,
592
+ localIdentHashSalt,
593
+ localIdentHashFunction,
594
+ localIdentHashDigest,
595
+ localIdentHashDigestLength,
596
+ localIdentRegExp,
597
+ hashStrategy
598
+ } = options.modules;
599
+ let plugins = [];
600
+ try {
601
+ plugins = [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
602
+ mode
603
+ }), (0, _postcssModulesExtractImports.default)(), (0, _postcssModulesScope.default)({
604
+ generateScopedName(exportName, resourceFile, rawCss, node) {
605
+ let localIdent;
606
+ if (typeof getLocalIdent !== "undefined") {
607
+ localIdent = getLocalIdent(loaderContext, localIdentName, unescape(exportName), {
608
+ context: localIdentContext,
609
+ hashSalt: localIdentHashSalt,
610
+ hashFunction: localIdentHashFunction,
611
+ hashDigest: localIdentHashDigest,
612
+ hashDigestLength: localIdentHashDigestLength,
613
+ hashStrategy,
614
+ regExp: localIdentRegExp,
615
+ node
616
+ });
617
+ }
618
+
619
+ // A null/undefined value signals that we should invoke the default
620
+ // getLocalIdent method.
621
+ if (typeof localIdent === "undefined" || localIdent === null) {
622
+ localIdent = defaultGetLocalIdent(loaderContext, localIdentName, unescape(exportName), {
623
+ context: localIdentContext,
624
+ hashSalt: localIdentHashSalt,
625
+ hashFunction: localIdentHashFunction,
626
+ hashDigest: localIdentHashDigest,
627
+ hashDigestLength: localIdentHashDigestLength,
628
+ hashStrategy,
629
+ regExp: localIdentRegExp,
630
+ node
631
+ });
632
+ return escapeLocalIdent(localIdent).replace(/\\\[local\\]/gi, exportName);
633
+ }
634
+ return escapeLocalIdent(localIdent);
635
+ },
636
+ exportGlobals: options.modules.exportGlobals
637
+ })];
638
+ } catch (error) {
639
+ loaderContext.emitError(error);
640
+ }
641
+ return plugins;
642
+ }
643
+ const ABSOLUTE_SCHEME = /^[a-z0-9+\-.]+:/i;
644
+ function getURLType(source) {
645
+ if (source[0] === "/") {
646
+ if (source[1] === "/") {
647
+ return "scheme-relative";
648
+ }
649
+ return "path-absolute";
650
+ }
651
+ if (IS_NATIVE_WIN32_PATH.test(source)) {
652
+ return "path-absolute";
653
+ }
654
+ return ABSOLUTE_SCHEME.test(source) ? "absolute" : "path-relative";
655
+ }
656
+ function normalizeSourceMap(map, resourcePath) {
657
+ let newMap = map;
658
+
659
+ // Some loader emit source map as string
660
+ // Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
661
+ if (typeof newMap === "string") {
662
+ newMap = JSON.parse(newMap);
663
+ }
664
+ delete newMap.file;
665
+ const {
666
+ sourceRoot
667
+ } = newMap;
668
+ delete newMap.sourceRoot;
669
+ if (newMap.sources) {
670
+ // Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
671
+ // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map
672
+ newMap.sources = newMap.sources.map(source => {
673
+ // Non-standard syntax from `postcss`
674
+ if (source.indexOf("<") === 0) {
675
+ return source;
676
+ }
677
+ const sourceType = getURLType(source);
678
+
679
+ // Do no touch `scheme-relative` and `absolute` URLs
680
+ if (sourceType === "path-relative" || sourceType === "path-absolute") {
681
+ const absoluteSource = sourceType === "path-relative" && sourceRoot ? _path.default.resolve(sourceRoot, normalizePath(source)) : normalizePath(source);
682
+ return _path.default.relative(_path.default.dirname(resourcePath), absoluteSource);
683
+ }
684
+ return source;
685
+ });
686
+ }
687
+ return newMap;
688
+ }
689
+ function getPreRequester({
690
+ loaders,
691
+ loaderIndex
692
+ }) {
693
+ const cache = Object.create(null);
694
+ return number => {
695
+ if (cache[number]) {
696
+ return cache[number];
697
+ }
698
+ if (number === false) {
699
+ cache[number] = "";
700
+ } else {
701
+ const loadersRequest = loaders.slice(loaderIndex, loaderIndex + 1 + (typeof number !== "number" ? 0 : number)).map(x => x.request).join("!");
702
+ cache[number] = `-!${loadersRequest}!`;
703
+ }
704
+ return cache[number];
705
+ };
706
+ }
707
+ function getImportCode(imports, options) {
708
+ let code = "";
709
+ for (const item of imports) {
710
+ const {
711
+ importName,
712
+ url,
713
+ icss,
714
+ type
715
+ } = item;
716
+ if (options.esModule) {
717
+ if (icss && options.modules.namedExport) {
718
+ code += `import ${options.modules.exportOnlyLocals ? "" : `${importName}, `}* as ${importName}_NAMED___ from ${url};\n`;
719
+ } else {
720
+ code += type === "url" ? `var ${importName} = new URL(${url}, import.meta.url);\n` : `import ${importName} from ${url};\n`;
721
+ }
722
+ } else {
723
+ code += `var ${importName} = require(${url});\n`;
724
+ }
725
+ }
726
+ return code ? `// Imports\n${code}` : "";
727
+ }
728
+ function normalizeSourceMapForRuntime(map, loaderContext) {
729
+ const resultMap = map ? map.toJSON() : null;
730
+ if (resultMap) {
731
+ delete resultMap.file;
732
+
733
+ /* eslint-disable no-underscore-dangle */
734
+ if (loaderContext._compilation && loaderContext._compilation.options && loaderContext._compilation.options.devtool && loaderContext._compilation.options.devtool.includes("nosources")) {
735
+ /* eslint-enable no-underscore-dangle */
736
+
737
+ delete resultMap.sourcesContent;
738
+ }
739
+ resultMap.sourceRoot = "";
740
+ resultMap.sources = resultMap.sources.map(source => {
741
+ // Non-standard syntax from `postcss`
742
+ if (source.indexOf("<") === 0) {
743
+ return source;
744
+ }
745
+ const sourceType = getURLType(source);
746
+ if (sourceType !== "path-relative") {
747
+ return source;
748
+ }
749
+ const resourceDirname = _path.default.dirname(loaderContext.resourcePath);
750
+ const absoluteSource = _path.default.resolve(resourceDirname, source);
751
+ const contextifyPath = normalizePath(_path.default.relative(loaderContext.rootContext, absoluteSource));
752
+ return `webpack://./${contextifyPath}`;
753
+ });
754
+ }
755
+ return JSON.stringify(resultMap);
756
+ }
757
+ function printParams(media, dedupe, supports, layer) {
758
+ let result = "";
759
+ if (typeof layer !== "undefined") {
760
+ result = `, ${JSON.stringify(layer)}`;
761
+ }
762
+ if (typeof supports !== "undefined") {
763
+ result = `, ${JSON.stringify(supports)}${result}`;
764
+ } else if (result.length > 0) {
765
+ result = `, undefined${result}`;
766
+ }
767
+ if (dedupe) {
768
+ result = `, true${result}`;
769
+ } else if (result.length > 0) {
770
+ result = `, false${result}`;
771
+ }
772
+ if (media) {
773
+ result = `${JSON.stringify(media)}${result}`;
774
+ } else if (result.length > 0) {
775
+ result = `""${result}`;
776
+ }
777
+ return result;
778
+ }
779
+ function getModuleCode(result, api, replacements, options, isTemplateLiteralSupported, loaderContext) {
780
+ if (options.modules.exportOnlyLocals === true) {
781
+ return "";
782
+ }
783
+ let sourceMapValue = "";
784
+ if (options.sourceMap) {
785
+ const sourceMap = result.map;
786
+ sourceMapValue = `,${normalizeSourceMapForRuntime(sourceMap, loaderContext)}`;
787
+ }
788
+ let code = isTemplateLiteralSupported ? convertToTemplateLiteral(result.css) : JSON.stringify(result.css);
789
+ let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap ? "___CSS_LOADER_API_SOURCEMAP_IMPORT___" : "___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___"});\n`;
790
+ for (const item of api) {
791
+ const {
792
+ url,
793
+ layer,
794
+ supports,
795
+ media,
796
+ dedupe
797
+ } = item;
798
+ if (url) {
799
+ // eslint-disable-next-line no-undefined
800
+ const printedParam = printParams(media, undefined, supports, layer);
801
+ beforeCode += `___CSS_LOADER_EXPORT___.push([module.id, ${JSON.stringify(`@import url(${url});`)}${printedParam.length > 0 ? `, ${printedParam}` : ""}]);\n`;
802
+ } else {
803
+ const printedParam = printParams(media, dedupe, supports, layer);
804
+ beforeCode += `___CSS_LOADER_EXPORT___.i(${item.importName}${printedParam.length > 0 ? `, ${printedParam}` : ""});\n`;
805
+ }
806
+ }
807
+ for (const item of replacements) {
808
+ const {
809
+ replacementName,
810
+ importName,
811
+ localName
812
+ } = item;
813
+ if (localName) {
814
+ 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)}] + "`);
815
+ } else {
816
+ const {
817
+ hash,
818
+ needQuotes
819
+ } = item;
820
+ const getUrlOptions = [].concat(hash ? [`hash: ${JSON.stringify(hash)}`] : []).concat(needQuotes ? "needQuotes: true" : []);
821
+ const preparedOptions = getUrlOptions.length > 0 ? `, { ${getUrlOptions.join(", ")} }` : "";
822
+ beforeCode += `var ${replacementName} = ___CSS_LOADER_GET_URL_IMPORT___(${importName}${preparedOptions});\n`;
823
+ code = code.replace(new RegExp(replacementName, "g"), () => isTemplateLiteralSupported ? `\${${replacementName}}` : `" + ${replacementName} + "`);
824
+ }
825
+ }
826
+
827
+ // Indexes description:
828
+ // 0 - module id
829
+ // 1 - CSS code
830
+ // 2 - media
831
+ // 3 - source map
832
+ // 4 - supports
833
+ // 5 - layer
834
+ return `${beforeCode}// Module\n___CSS_LOADER_EXPORT___.push([module.id, ${code}, ""${sourceMapValue}]);\n`;
835
+ }
836
+ const SLASH = "\\".charCodeAt(0);
837
+ const BACKTICK = "`".charCodeAt(0);
838
+ const DOLLAR = "$".charCodeAt(0);
839
+ function convertToTemplateLiteral(str) {
840
+ let escapedString = "";
841
+ for (let i = 0; i < str.length; i++) {
842
+ const code = str.charCodeAt(i);
843
+ escapedString += code === SLASH || code === BACKTICK || code === DOLLAR ? `\\${str[i]}` : str[i];
844
+ }
845
+ return `\`${escapedString}\``;
846
+ }
847
+ function dashesCamelCase(str) {
848
+ return str.replace(/-+(\w)/g, (match, firstLetter) => firstLetter.toUpperCase());
849
+ }
850
+ const validIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/u;
851
+ const keywords = new Set(["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "module"]);
852
+ function getExportCode(exports, replacements, icssPluginUsed, options, isTemplateLiteralSupported) {
853
+ let code = "// Exports\n";
854
+ if (icssPluginUsed) {
855
+ let localsCode = "";
856
+ let identifierId = 0;
857
+ const addExportToLocalsCode = (names, value) => {
858
+ const normalizedNames = Array.isArray(names) ? new Set(names) : new Set([names]);
859
+ for (let name of normalizedNames) {
860
+ const serializedValue = isTemplateLiteralSupported ? convertToTemplateLiteral(value) : JSON.stringify(value);
861
+ if (options.modules.namedExport) {
862
+ if (name === "default") {
863
+ name = `_${name}`;
864
+ }
865
+ if (!validIdentifier.test(name) || keywords.has(name)) {
866
+ identifierId += 1;
867
+ const id = `_${identifierId.toString(16)}`;
868
+ localsCode += `var ${id} = ${serializedValue};\n`;
869
+ localsCode += `export { ${id} as ${JSON.stringify(name)} };\n`;
870
+ } else {
871
+ localsCode += `export var ${name} = ${serializedValue};\n`;
872
+ }
873
+ } else {
874
+ if (localsCode) {
875
+ localsCode += `,\n`;
876
+ }
877
+ localsCode += `\t${JSON.stringify(name)}: ${serializedValue}`;
878
+ }
879
+ }
880
+ };
881
+ for (const {
882
+ name,
883
+ value
884
+ } of exports) {
885
+ addExportToLocalsCode(options.modules.exportLocalsConvention(name), value);
886
+ }
887
+ for (const item of replacements) {
888
+ const {
889
+ replacementName,
890
+ localName
891
+ } = item;
892
+ if (localName) {
893
+ const {
894
+ importName
895
+ } = item;
896
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => {
897
+ if (options.modules.namedExport) {
898
+ return isTemplateLiteralSupported ? `\${${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}]}` : `" + ${importName}_NAMED___[${JSON.stringify(getValidLocalName(localName, options.modules.exportLocalsConvention))}] + "`;
899
+ } else if (options.modules.exportOnlyLocals) {
900
+ return isTemplateLiteralSupported ? `\${${importName}[${JSON.stringify(localName)}]}` : `" + ${importName}[${JSON.stringify(localName)}] + "`;
901
+ }
902
+ return isTemplateLiteralSupported ? `\${${importName}.locals[${JSON.stringify(localName)}]}` : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`;
903
+ });
904
+ } else {
905
+ localsCode = localsCode.replace(new RegExp(replacementName, "g"), () => isTemplateLiteralSupported ? `\${${replacementName}}` : `" + ${replacementName} + "`);
906
+ }
907
+ }
908
+ if (options.modules.exportOnlyLocals) {
909
+ code += options.modules.namedExport ? localsCode : `${options.esModule ? "export default" : "module.exports ="} {\n${localsCode}\n};\n`;
910
+ return code;
911
+ }
912
+ code += options.modules.namedExport ? localsCode : `___CSS_LOADER_EXPORT___.locals = {${localsCode ? `\n${localsCode}\n` : ""}};\n`;
913
+ }
914
+ const isCSSStyleSheetExport = options.exportType === "css-style-sheet";
915
+ if (isCSSStyleSheetExport) {
916
+ code += "var ___CSS_LOADER_STYLE_SHEET___ = new CSSStyleSheet();\n";
917
+ code += "___CSS_LOADER_STYLE_SHEET___.replaceSync(___CSS_LOADER_EXPORT___.toString());\n";
918
+ }
919
+ let finalExport;
920
+ switch (options.exportType) {
921
+ case "string":
922
+ finalExport = "___CSS_LOADER_EXPORT___.toString()";
923
+ break;
924
+ case "css-style-sheet":
925
+ finalExport = "___CSS_LOADER_STYLE_SHEET___";
926
+ break;
927
+ default:
928
+ case "array":
929
+ finalExport = "___CSS_LOADER_EXPORT___";
930
+ break;
931
+ }
932
+ code += `${options.esModule ? "export default" : "module.exports ="} ${finalExport};\n`;
933
+ return code;
934
+ }
935
+ async function resolveRequests(resolve, context, possibleRequests) {
936
+ return resolve(context, possibleRequests[0]).then(result => result).catch(error => {
937
+ const [, ...tailPossibleRequests] = possibleRequests;
938
+ if (tailPossibleRequests.length === 0) {
939
+ throw error;
940
+ }
941
+ return resolveRequests(resolve, context, tailPossibleRequests);
942
+ });
943
+ }
944
+ function isURLRequestable(url, options = {}) {
945
+ // Protocol-relative URLs
946
+ if (/^\/\//.test(url)) {
947
+ return {
948
+ requestable: false,
949
+ needResolve: false
950
+ };
951
+ }
952
+
953
+ // `#` URLs
954
+ if (/^#/.test(url)) {
955
+ return {
956
+ requestable: false,
957
+ needResolve: false
958
+ };
959
+ }
960
+
961
+ // Data URI
962
+ if (isDataUrl(url) && options.isSupportDataURL) {
963
+ try {
964
+ decodeURIComponent(url);
965
+ } catch (ignoreError) {
966
+ return {
967
+ requestable: false,
968
+ needResolve: false
969
+ };
970
+ }
971
+ return {
972
+ requestable: true,
973
+ needResolve: false
974
+ };
975
+ }
976
+
977
+ // `file:` protocol
978
+ if (/^file:/i.test(url)) {
979
+ return {
980
+ requestable: true,
981
+ needResolve: true
982
+ };
983
+ }
984
+
985
+ // Absolute URLs
986
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !NATIVE_WIN32_PATH.test(url)) {
987
+ if (options.isSupportAbsoluteURL && /^https?:/i.test(url)) {
988
+ return {
989
+ requestable: true,
990
+ needResolve: false
991
+ };
992
+ }
993
+ return {
994
+ requestable: false,
995
+ needResolve: false
996
+ };
997
+ }
998
+ return {
999
+ requestable: true,
1000
+ needResolve: true
1001
+ };
1002
+ }
1003
+ function sort(a, b) {
1004
+ return a.index - b.index;
1005
+ }
1006
+ function combineRequests(preRequest, url) {
1007
+ const idx = url.indexOf("!=!");
1008
+ return idx !== -1 ? url.slice(0, idx + 3) + preRequest + url.slice(idx + 3) : preRequest + url;
1009
+ }
1010
+ function warningFactory(warning) {
1011
+ let message = "";
1012
+ if (typeof warning.line !== "undefined") {
1013
+ message += `(${warning.line}:${warning.column}) `;
1014
+ }
1015
+ if (typeof warning.plugin !== "undefined") {
1016
+ message += `from "${warning.plugin}" plugin: `;
1017
+ }
1018
+ message += warning.text;
1019
+ if (warning.node) {
1020
+ message += `\n\nCode:\n ${warning.node.toString()}\n`;
1021
+ }
1022
+ const obj = new Error(message, {
1023
+ cause: warning
1024
+ });
1025
+ obj.stack = null;
1026
+ return obj;
1027
+ }
1028
+ function syntaxErrorFactory(error) {
1029
+ let message = "\nSyntaxError\n\n";
1030
+ if (typeof error.line !== "undefined") {
1031
+ message += `(${error.line}:${error.column}) `;
1032
+ }
1033
+ if (typeof error.plugin !== "undefined") {
1034
+ message += `from "${error.plugin}" plugin: `;
1035
+ }
1036
+ message += error.file ? `${error.file} ` : "<css input> ";
1037
+ message += `${error.reason}`;
1038
+ const code = error.showSourceCode();
1039
+ if (code) {
1040
+ message += `\n\n${code}\n`;
1041
+ }
1042
+ const obj = new Error(message, {
1043
+ cause: error
1044
+ });
1045
+ obj.stack = null;
1046
+ return obj;
1047
+ }
1048
+ function supportTemplateLiteral(loaderContext) {
1049
+ if (loaderContext.environment && loaderContext.environment.templateLiteral) {
1050
+ return true;
1051
+ }
1052
+
1053
+ // TODO remove in the next major release
1054
+ if (
1055
+ // eslint-disable-next-line no-underscore-dangle
1056
+ loaderContext._compilation &&
1057
+ // eslint-disable-next-line no-underscore-dangle
1058
+ loaderContext._compilation.options &&
1059
+ // eslint-disable-next-line no-underscore-dangle
1060
+ loaderContext._compilation.options.output &&
1061
+ // eslint-disable-next-line no-underscore-dangle
1062
+ loaderContext._compilation.options.output.environment &&
1063
+ // eslint-disable-next-line no-underscore-dangle
1064
+ loaderContext._compilation.options.output.environment.templateLiteral) {
1065
+ return true;
1066
+ }
1067
+ return false;
1068
+ }