| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | const { ConcatSource, PrefixSource } = require("webpack-sources"); | 
					
						
							|  |  |  | const CssModule = require("../CssModule"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const HotUpdateChunk = require("../HotUpdateChunk"); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | const { | 
					
						
							|  |  |  | 	CSS_MODULE_TYPE, | 
					
						
							|  |  |  | 	CSS_MODULE_TYPE_GLOBAL, | 
					
						
							| 
									
										
										
										
											2022-12-16 20:56:14 +08:00
										 |  |  | 	CSS_MODULE_TYPE_MODULE, | 
					
						
							|  |  |  | 	CSS_MODULE_TYPE_AUTO | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | } = require("../ModuleTypeConstants"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | const SelfModuleFactory = require("../SelfModuleFactory"); | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | const WebpackError = require("../WebpackError"); | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | const CssExportDependency = require("../dependencies/CssExportDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-01 21:15:19 +08:00
										 |  |  | const CssImportDependency = require("../dependencies/CssImportDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | const CssLocalIdentifierDependency = require("../dependencies/CssLocalIdentifierDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | const CssSelfLocalIdentifierDependency = require("../dependencies/CssSelfLocalIdentifierDependency"); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | const CssUrlDependency = require("../dependencies/CssUrlDependency"); | 
					
						
							|  |  |  | const StaticExportsDependency = require("../dependencies/StaticExportsDependency"); | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | const { compareModulesByIdentifier } = require("../util/comparators"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const createSchemaValidation = require("../util/create-schema-validation"); | 
					
						
							|  |  |  | const createHash = require("../util/createHash"); | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | const memoize = require("../util/memoize"); | 
					
						
							| 
									
										
										
										
											2022-02-01 18:35:12 +08:00
										 |  |  | const nonNumericOnlyHash = require("../util/nonNumericOnlyHash"); | 
					
						
							| 
									
										
										
										
											2022-01-19 01:14:50 +08:00
										 |  |  | const CssExportsGenerator = require("./CssExportsGenerator"); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const CssGenerator = require("./CssGenerator"); | 
					
						
							|  |  |  | const CssParser = require("./CssParser"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** @typedef {import("webpack-sources").Source} Source */ | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | /** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /** @typedef {import("../Chunk")} Chunk */ | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | /** @typedef {import("../ChunkGraph")} ChunkGraph */ | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */ | 
					
						
							|  |  |  | /** @typedef {import("../Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | /** @typedef {import("../Compiler")} Compiler */ | 
					
						
							|  |  |  | /** @typedef {import("../Module")} Module */ | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | /** @typedef {import("../util/memoize")} Memoize */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | const getCssLoadingRuntimeModule = memoize(() => | 
					
						
							|  |  |  | 	require("./CssLoadingRuntimeModule") | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} name name | 
					
						
							|  |  |  |  * @returns {{oneOf: [{$ref: string}], definitions: *}} schema | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const getSchema = name => { | 
					
						
							|  |  |  | 	const { definitions } = require("../../schemas/WebpackOptions.json"); | 
					
						
							|  |  |  | 	return { | 
					
						
							|  |  |  | 		definitions, | 
					
						
							|  |  |  | 		oneOf: [{ $ref: `#/definitions/${name}` }] | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | const generatorValidationOptions = { | 
					
						
							|  |  |  | 	name: "Css Modules Plugin", | 
					
						
							|  |  |  | 	baseDataPath: "generator" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const validateGeneratorOptions = { | 
					
						
							|  |  |  | 	css: createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssGeneratorOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/auto": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssAutoGeneratorOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssAutoGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/module": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssModuleGeneratorOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssModuleGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/global": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssGlobalGeneratorOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssGlobalGeneratorOptions"), | 
					
						
							|  |  |  | 		generatorValidationOptions | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const parserValidationOptions = { | 
					
						
							|  |  |  | 	name: "Css Modules Plugin", | 
					
						
							|  |  |  | 	baseDataPath: "parser" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | const validateParserOptions = { | 
					
						
							|  |  |  | 	css: createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssParserOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/auto": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssAutoParserOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssAutoParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/module": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssModuleParserOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssModuleParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	), | 
					
						
							|  |  |  | 	"css/global": createSchemaValidation( | 
					
						
							|  |  |  | 		require("../../schemas/plugins/css/CssGlobalParserOptions.check.js"), | 
					
						
							|  |  |  | 		() => getSchema("CssGlobalParserOptions"), | 
					
						
							|  |  |  | 		parserValidationOptions | 
					
						
							|  |  |  | 	) | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} str string | 
					
						
							|  |  |  |  * @param {boolean=} omitOptionalUnderscore if true, optional underscore is not added | 
					
						
							|  |  |  |  * @returns {string} escaped string | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2021-12-15 16:19:06 +08:00
										 |  |  | const escapeCss = (str, omitOptionalUnderscore) => { | 
					
						
							| 
									
										
										
										
											2021-12-03 02:37:22 +08:00
										 |  |  | 	const escaped = `${str}`.replace( | 
					
						
							|  |  |  | 		// cspell:word uffff
 | 
					
						
							|  |  |  | 		/[^a-zA-Z0-9_\u0081-\uffff-]/g, | 
					
						
							|  |  |  | 		s => `\\${s}` | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | 	return !omitOptionalUnderscore && /^(?!--)[0-9_-]/.test(escaped) | 
					
						
							| 
									
										
										
										
											2021-12-03 02:37:22 +08:00
										 |  |  | 		? `_${escaped}` | 
					
						
							|  |  |  | 		: escaped; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 17:15:42 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {string} str string | 
					
						
							|  |  |  |  * @returns {string} encoded string | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const LZWEncode = str => { | 
					
						
							|  |  |  | 	/** @type {Map<string, string>} */ | 
					
						
							|  |  |  | 	const map = new Map(); | 
					
						
							|  |  |  | 	let encoded = ""; | 
					
						
							|  |  |  | 	let phrase = str[0]; | 
					
						
							|  |  |  | 	let code = 256; | 
					
						
							|  |  |  | 	let maxCode = "\uffff".charCodeAt(0); | 
					
						
							|  |  |  | 	for (let i = 1; i < str.length; i++) { | 
					
						
							|  |  |  | 		const c = str[i]; | 
					
						
							|  |  |  | 		if (map.has(phrase + c)) { | 
					
						
							|  |  |  | 			phrase += c; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			encoded += phrase.length > 1 ? map.get(phrase) : phrase; | 
					
						
							|  |  |  | 			map.set(phrase + c, String.fromCharCode(code)); | 
					
						
							|  |  |  | 			phrase = c; | 
					
						
							|  |  |  | 			if (++code > maxCode) { | 
					
						
							|  |  |  | 				code = 256; | 
					
						
							|  |  |  | 				map.clear(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	encoded += phrase.length > 1 ? map.get(phrase) : phrase; | 
					
						
							|  |  |  | 	return encoded; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | const plugin = "CssModulesPlugin"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CssModulesPlugin { | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Apply the plugin | 
					
						
							|  |  |  | 	 * @param {Compiler} compiler the compiler instance | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	apply(compiler) { | 
					
						
							|  |  |  | 		compiler.hooks.compilation.tap( | 
					
						
							|  |  |  | 			plugin, | 
					
						
							|  |  |  | 			(compilation, { normalModuleFactory }) => { | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | 				const selfFactory = new SelfModuleFactory(compilation.moduleGraph); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssUrlDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssUrlDependency, | 
					
						
							|  |  |  | 					new CssUrlDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssLocalIdentifierDependency, | 
					
						
							|  |  |  | 					new CssLocalIdentifierDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-17 03:42:44 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssSelfLocalIdentifierDependency, | 
					
						
							|  |  |  | 					selfFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssSelfLocalIdentifierDependency, | 
					
						
							|  |  |  | 					new CssSelfLocalIdentifierDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssExportDependency, | 
					
						
							|  |  |  | 					new CssExportDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-12-01 20:27:00 +08:00
										 |  |  | 				compilation.dependencyFactories.set( | 
					
						
							|  |  |  | 					CssImportDependency, | 
					
						
							|  |  |  | 					normalModuleFactory | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					CssImportDependency, | 
					
						
							|  |  |  | 					new CssImportDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | 				compilation.dependencyTemplates.set( | 
					
						
							|  |  |  | 					StaticExportsDependency, | 
					
						
							|  |  |  | 					new StaticExportsDependency.Template() | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				for (const type of [ | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE, | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE_GLOBAL, | 
					
						
							| 
									
										
										
										
											2022-12-16 20:56:14 +08:00
										 |  |  | 					CSS_MODULE_TYPE_MODULE, | 
					
						
							|  |  |  | 					CSS_MODULE_TYPE_AUTO | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				]) { | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 					normalModuleFactory.hooks.createParser | 
					
						
							|  |  |  | 						.for(type) | 
					
						
							|  |  |  | 						.tap(plugin, parserOptions => { | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 							validateParserOptions[type](parserOptions); | 
					
						
							|  |  |  | 							const { namedExports } = parserOptions; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 							switch (type) { | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								case CSS_MODULE_TYPE: | 
					
						
							| 
									
										
										
										
											2022-12-16 20:56:14 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_AUTO: | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							|  |  |  | 										namedExports | 
					
						
							|  |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_GLOBAL: | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										allowModeSwitch: false, | 
					
						
							|  |  |  | 										namedExports | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									}); | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								case CSS_MODULE_TYPE_MODULE: | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									return new CssParser({ | 
					
						
							| 
									
										
										
										
											2024-01-13 18:23:30 +08:00
										 |  |  | 										defaultMode: "local", | 
					
						
							|  |  |  | 										namedExports | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 									}); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 					normalModuleFactory.hooks.createGenerator | 
					
						
							|  |  |  | 						.for(type) | 
					
						
							|  |  |  | 						.tap(plugin, generatorOptions => { | 
					
						
							| 
									
										
										
										
											2024-01-12 15:47:31 +08:00
										 |  |  | 							validateGeneratorOptions[type](generatorOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return generatorOptions.exportsOnly | 
					
						
							| 
									
										
										
										
											2024-02-22 19:58:59 +08:00
										 |  |  | 								? new CssExportsGenerator( | 
					
						
							|  |  |  | 										generatorOptions.exportsConvention, | 
					
						
							|  |  |  | 										generatorOptions.localIdentName | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								: new CssGenerator( | 
					
						
							|  |  |  | 										generatorOptions.exportsConvention, | 
					
						
							|  |  |  | 										generatorOptions.localIdentName | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2021-12-15 15:34:31 +08:00
										 |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 					normalModuleFactory.hooks.createModuleClass | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 						.for(type) | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 						.tap(plugin, (createData, resolveData) => { | 
					
						
							|  |  |  | 							if (resolveData.dependencies.length > 0) { | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 								// When CSS is imported from CSS there is only one dependency
 | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 								const dependency = resolveData.dependencies[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 								if (dependency instanceof CssImportDependency) { | 
					
						
							|  |  |  | 									const parent = | 
					
						
							|  |  |  | 										/** @type {CssModule} */ | 
					
						
							|  |  |  | 										(compilation.moduleGraph.getParentModule(dependency)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									if (parent instanceof CssModule) { | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 										/** @type {import("../CssModule").Inheritance | undefined} */ | 
					
						
							|  |  |  | 										let inheritance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											(parent.cssLayer !== null && | 
					
						
							|  |  |  | 												parent.cssLayer !== undefined) || | 
					
						
							|  |  |  | 											parent.supports || | 
					
						
							|  |  |  | 											parent.media | 
					
						
							|  |  |  | 										) { | 
					
						
							|  |  |  | 											if (!inheritance) { | 
					
						
							|  |  |  | 												inheritance = []; | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 											inheritance.push([ | 
					
						
							|  |  |  | 												parent.cssLayer, | 
					
						
							|  |  |  | 												parent.supports, | 
					
						
							|  |  |  | 												parent.media | 
					
						
							|  |  |  | 											]); | 
					
						
							|  |  |  | 										} | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 										if (parent.inheritance) { | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 											if (!inheritance) { | 
					
						
							|  |  |  | 												inheritance = []; | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 											inheritance.push(...parent.inheritance); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										return new CssModule({ | 
					
						
							|  |  |  | 											...createData, | 
					
						
							|  |  |  | 											cssLayer: dependency.layer, | 
					
						
							|  |  |  | 											supports: dependency.supports, | 
					
						
							|  |  |  | 											media: dependency.media, | 
					
						
							|  |  |  | 											inheritance | 
					
						
							|  |  |  | 										}); | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 									return new CssModule({ | 
					
						
							|  |  |  | 										...createData, | 
					
						
							|  |  |  | 										cssLayer: dependency.layer, | 
					
						
							|  |  |  | 										supports: dependency.supports, | 
					
						
							|  |  |  | 										media: dependency.media | 
					
						
							|  |  |  | 									}); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 							return new CssModule(createData); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 				const orderedCssModulesPerChunk = new WeakMap(); | 
					
						
							|  |  |  | 				compilation.hooks.afterCodeGeneration.tap("CssModulesPlugin", () => { | 
					
						
							|  |  |  | 					const { chunkGraph } = compilation; | 
					
						
							|  |  |  | 					for (const chunk of compilation.chunks) { | 
					
						
							|  |  |  | 						if (CssModulesPlugin.chunkHasCss(chunk, chunkGraph)) { | 
					
						
							|  |  |  | 							orderedCssModulesPerChunk.set( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								this.getOrderedChunkCssModules(chunk, chunkGraph, compilation) | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				compilation.hooks.contentHash.tap("CssModulesPlugin", chunk => { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					const { | 
					
						
							|  |  |  | 						chunkGraph, | 
					
						
							|  |  |  | 						outputOptions: { | 
					
						
							|  |  |  | 							hashSalt, | 
					
						
							|  |  |  | 							hashDigest, | 
					
						
							|  |  |  | 							hashDigestLength, | 
					
						
							|  |  |  | 							hashFunction | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} = compilation; | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 					const modules = orderedCssModulesPerChunk.get(chunk); | 
					
						
							|  |  |  | 					if (modules === undefined) return; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					const hash = createHash(hashFunction); | 
					
						
							|  |  |  | 					if (hashSalt) hash.update(hashSalt); | 
					
						
							|  |  |  | 					for (const module of modules) { | 
					
						
							|  |  |  | 						hash.update(chunkGraph.getModuleHash(module, chunk.runtime)); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					const digest = /** @type {string} */ (hash.digest(hashDigest)); | 
					
						
							| 
									
										
										
										
											2022-02-01 18:35:12 +08:00
										 |  |  | 					chunk.contentHash.css = nonNumericOnlyHash(digest, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 				compilation.hooks.renderManifest.tap(plugin, (result, options) => { | 
					
						
							|  |  |  | 					const { chunkGraph } = compilation; | 
					
						
							|  |  |  | 					const { hash, chunk, codeGenerationResults } = options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (chunk instanceof HotUpdateChunk) return result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 					/** @type {CssModule[] | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 					const modules = orderedCssModulesPerChunk.get(chunk); | 
					
						
							|  |  |  | 					if (modules !== undefined) { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 						result.push({ | 
					
						
							|  |  |  | 							render: () => | 
					
						
							|  |  |  | 								this.renderChunk({ | 
					
						
							|  |  |  | 									chunk, | 
					
						
							|  |  |  | 									chunkGraph, | 
					
						
							| 
									
										
										
										
											2021-12-15 23:46:13 +08:00
										 |  |  | 									codeGenerationResults, | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 									uniqueName: compilation.outputOptions.uniqueName, | 
					
						
							| 
									
										
										
										
											2024-03-06 14:29:57 +08:00
										 |  |  | 									cssHeadDataCompression: | 
					
						
							|  |  |  | 										compilation.outputOptions.cssHeadDataCompression, | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 									modules | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 								}), | 
					
						
							|  |  |  | 							filenameTemplate: CssModulesPlugin.getChunkFilenameTemplate( | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								compilation.outputOptions | 
					
						
							|  |  |  | 							), | 
					
						
							|  |  |  | 							pathOptions: { | 
					
						
							|  |  |  | 								hash, | 
					
						
							|  |  |  | 								runtime: chunk.runtime, | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								contentHashType: "css" | 
					
						
							|  |  |  | 							}, | 
					
						
							|  |  |  | 							identifier: `css${chunk.id}`, | 
					
						
							|  |  |  | 							hash: chunk.contentHash.css | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return result; | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 				const globalChunkLoading = compilation.outputOptions.chunkLoading; | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Chunk} chunk the chunk | 
					
						
							|  |  |  | 				 * @returns {boolean} true, when enabled | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 				const isEnabledForChunk = chunk => { | 
					
						
							|  |  |  | 					const options = chunk.getEntryOptions(); | 
					
						
							|  |  |  | 					const chunkLoading = | 
					
						
							|  |  |  | 						options && options.chunkLoading !== undefined | 
					
						
							|  |  |  | 							? options.chunkLoading | 
					
						
							|  |  |  | 							: globalChunkLoading; | 
					
						
							|  |  |  | 					return chunkLoading === "jsonp"; | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 				const onceForChunkSet = new WeakSet(); | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** | 
					
						
							|  |  |  | 				 * @param {Chunk} chunk chunk to check | 
					
						
							|  |  |  | 				 * @param {Set<string>} set runtime requirements | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				const handler = (chunk, set) => { | 
					
						
							| 
									
										
										
										
											2023-05-05 21:28:57 +08:00
										 |  |  | 					if (onceForChunkSet.has(chunk)) return; | 
					
						
							|  |  |  | 					onceForChunkSet.add(chunk); | 
					
						
							|  |  |  | 					if (!isEnabledForChunk(chunk)) return; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.publicPath); | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.getChunkCssFilename); | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.hasOwnProperty); | 
					
						
							|  |  |  | 					set.add(RuntimeGlobals.moduleFactoriesAddOnly); | 
					
						
							| 
									
										
										
										
											2021-12-01 16:50:13 +08:00
										 |  |  | 					set.add(RuntimeGlobals.makeNamespaceObject); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-03 23:23:09 +08:00
										 |  |  | 					const CssLoadingRuntimeModule = getCssLoadingRuntimeModule(); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 					compilation.addRuntimeModule(chunk, new CssLoadingRuntimeModule(set)); | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2022-01-13 08:02:15 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hasCssModules) | 
					
						
							|  |  |  | 					.tap(plugin, handler); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.ensureChunkHandlers) | 
					
						
							|  |  |  | 					.tap(plugin, handler); | 
					
						
							|  |  |  | 				compilation.hooks.runtimeRequirementInTree | 
					
						
							|  |  |  | 					.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | 
					
						
							|  |  |  | 					.tap(plugin, handler); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {Iterable<Module>} modules unordered modules | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation compilation | 
					
						
							|  |  |  | 	 * @returns {Module[]} ordered modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	getModulesInOrder(chunk, modules, compilation) { | 
					
						
							|  |  |  | 		if (!modules) return []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 		/** @type {Module[]} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		const modulesList = [...modules]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Get ordered list of modules per chunk group
 | 
					
						
							|  |  |  | 		// Lists are in reverse order to allow to use Array.pop()
 | 
					
						
							|  |  |  | 		const modulesByChunkGroup = Array.from(chunk.groupsIterable, chunkGroup => { | 
					
						
							|  |  |  | 			const sortedModules = modulesList | 
					
						
							|  |  |  | 				.map(module => { | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						module, | 
					
						
							|  |  |  | 						index: chunkGroup.getModulePostOrderIndex(module) | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 				.filter(item => item.index !== undefined) | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				.sort( | 
					
						
							|  |  |  | 					(a, b) => | 
					
						
							|  |  |  | 						/** @type {number} */ (b.index) - /** @type {number} */ (a.index) | 
					
						
							|  |  |  | 				) | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 				.map(item => item.module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return { list: sortedModules, set: new Set(sortedModules) }; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (modulesByChunkGroup.length === 1) | 
					
						
							|  |  |  | 			return modulesByChunkGroup[0].list.reverse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const compareModuleLists = ({ list: a }, { list: b }) => { | 
					
						
							|  |  |  | 			if (a.length === 0) { | 
					
						
							|  |  |  | 				return b.length === 0 ? 0 : 1; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				if (b.length === 0) return -1; | 
					
						
							|  |  |  | 				return compareModulesByIdentifier(a[a.length - 1], b[b.length - 1]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		modulesByChunkGroup.sort(compareModuleLists); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 		/** @type {Module[]} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		const finalModules = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (;;) { | 
					
						
							|  |  |  | 			const failedModules = new Set(); | 
					
						
							|  |  |  | 			const list = modulesByChunkGroup[0].list; | 
					
						
							|  |  |  | 			if (list.length === 0) { | 
					
						
							|  |  |  | 				// done, everything empty
 | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 			/** @type {Module} */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			let selectedModule = list[list.length - 1]; | 
					
						
							|  |  |  | 			let hasFailed = undefined; | 
					
						
							|  |  |  | 			outer: for (;;) { | 
					
						
							|  |  |  | 				for (const { list, set } of modulesByChunkGroup) { | 
					
						
							|  |  |  | 					if (list.length === 0) continue; | 
					
						
							|  |  |  | 					const lastModule = list[list.length - 1]; | 
					
						
							|  |  |  | 					if (lastModule === selectedModule) continue; | 
					
						
							|  |  |  | 					if (!set.has(selectedModule)) continue; | 
					
						
							|  |  |  | 					failedModules.add(selectedModule); | 
					
						
							|  |  |  | 					if (failedModules.has(lastModule)) { | 
					
						
							|  |  |  | 						// There is a conflict, try other alternatives
 | 
					
						
							|  |  |  | 						hasFailed = lastModule; | 
					
						
							|  |  |  | 						continue; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					selectedModule = lastModule; | 
					
						
							|  |  |  | 					hasFailed = false; | 
					
						
							|  |  |  | 					continue outer; // restart
 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (hasFailed) { | 
					
						
							|  |  |  | 				// There is a not resolve-able conflict with the selectedModule
 | 
					
						
							|  |  |  | 				if (compilation) { | 
					
						
							|  |  |  | 					// TODO print better warning
 | 
					
						
							|  |  |  | 					compilation.warnings.push( | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 						new WebpackError( | 
					
						
							|  |  |  | 							`chunk ${chunk.name || chunk.id}\nConflicting order between ${ | 
					
						
							|  |  |  | 								/** @type {Module} */ | 
					
						
							|  |  |  | 								(hasFailed).readableIdentifier(compilation.requestShortener) | 
					
						
							|  |  |  | 							} and ${selectedModule.readableIdentifier( | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 								compilation.requestShortener | 
					
						
							|  |  |  | 							)}`
 | 
					
						
							|  |  |  | 						) | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 				selectedModule = /** @type {Module} */ (hasFailed); | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			// Insert the selected module into the final modules list
 | 
					
						
							|  |  |  | 			finalModules.push(selectedModule); | 
					
						
							|  |  |  | 			// Remove the selected module from all lists
 | 
					
						
							|  |  |  | 			for (const { list, set } of modulesByChunkGroup) { | 
					
						
							|  |  |  | 				const lastModule = list[list.length - 1]; | 
					
						
							|  |  |  | 				if (lastModule === selectedModule) list.pop(); | 
					
						
							|  |  |  | 				else if (hasFailed && set.has(selectedModule)) { | 
					
						
							|  |  |  | 					const idx = list.indexOf(selectedModule); | 
					
						
							|  |  |  | 					if (idx >= 0) list.splice(idx, 1); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			modulesByChunkGroup.sort(compareModuleLists); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return finalModules; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @param {Compilation} compilation compilation | 
					
						
							|  |  |  | 	 * @returns {Module[]} ordered css modules | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	getOrderedChunkCssModules(chunk, chunkGraph, compilation) { | 
					
						
							|  |  |  | 		return [ | 
					
						
							|  |  |  | 			...this.getModulesInOrder( | 
					
						
							|  |  |  | 				chunk, | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Iterable<Module>} */ | 
					
						
							|  |  |  | 				( | 
					
						
							|  |  |  | 					chunkGraph.getOrderedChunkModulesIterableBySourceType( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						"css-import", | 
					
						
							|  |  |  | 						compareModulesByIdentifier | 
					
						
							|  |  |  | 					) | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 				), | 
					
						
							|  |  |  | 				compilation | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			...this.getModulesInOrder( | 
					
						
							|  |  |  | 				chunk, | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Iterable<Module>} */ | 
					
						
							|  |  |  | 				( | 
					
						
							|  |  |  | 					chunkGraph.getOrderedChunkModulesIterableBySourceType( | 
					
						
							|  |  |  | 						chunk, | 
					
						
							|  |  |  | 						"css", | 
					
						
							|  |  |  | 						compareModulesByIdentifier | 
					
						
							|  |  |  | 					) | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 				), | 
					
						
							|  |  |  | 				compilation | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		]; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Object} options options | 
					
						
							|  |  |  | 	 * @param {string | undefined} options.uniqueName unique name | 
					
						
							| 
									
										
										
										
											2024-03-06 14:29:57 +08:00
										 |  |  | 	 * @param {boolean | undefined} options.cssHeadDataCompression compress css head data | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	 * @param {Chunk} options.chunk chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} options.chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @param {CodeGenerationResults} options.codeGenerationResults code generation results | 
					
						
							|  |  |  | 	 * @param {CssModule[]} options.modules ordered css modules | 
					
						
							|  |  |  | 	 * @returns {Source} generated source | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	renderChunk({ | 
					
						
							|  |  |  | 		uniqueName, | 
					
						
							| 
									
										
										
										
											2024-03-06 14:29:57 +08:00
										 |  |  | 		cssHeadDataCompression, | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 		chunk, | 
					
						
							|  |  |  | 		chunkGraph, | 
					
						
							|  |  |  | 		codeGenerationResults, | 
					
						
							| 
									
										
										
										
											2021-12-18 03:24:08 +08:00
										 |  |  | 		modules | 
					
						
							| 
									
										
										
										
											2021-12-18 01:10:00 +08:00
										 |  |  | 	}) { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		const source = new ConcatSource(); | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 		/** @type {string[]} */ | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 		const metaData = []; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		for (const module of modules) { | 
					
						
							|  |  |  | 			try { | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				const codeGenResult = codeGenerationResults.get(module, chunk.runtime); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				let moduleSource = | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 					/** @type {Source} */ | 
					
						
							|  |  |  | 					( | 
					
						
							|  |  |  | 						codeGenResult.sources.get("css") || | 
					
						
							|  |  |  | 							codeGenResult.sources.get("css-import") | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 				let inheritance = [[module.cssLayer, module.supports, module.media]]; | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 				if (module.inheritance) { | 
					
						
							|  |  |  | 					inheritance.push(...module.inheritance); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 				for (let i = 0; i < inheritance.length; i++) { | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 					const layer = inheritance[i][0]; | 
					
						
							|  |  |  | 					const supports = inheritance[i][1]; | 
					
						
							|  |  |  | 					const media = inheritance[i][2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (media) { | 
					
						
							|  |  |  | 						moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 							`@media ${media} {\n`, | 
					
						
							|  |  |  | 							new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 							"}\n" | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					if (supports) { | 
					
						
							|  |  |  | 						moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 							`@supports (${supports}) {\n`, | 
					
						
							|  |  |  | 							new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 							"}\n" | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					// Layer can be anonymous
 | 
					
						
							|  |  |  | 					if (layer !== undefined && layer !== null) { | 
					
						
							|  |  |  | 						moduleSource = new ConcatSource( | 
					
						
							|  |  |  | 							`@layer${layer ? ` ${layer}` : ""} {\n`, | 
					
						
							|  |  |  | 							new PrefixSource("\t", moduleSource), | 
					
						
							|  |  |  | 							"}\n" | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				if (moduleSource) { | 
					
						
							|  |  |  | 					source.add(moduleSource); | 
					
						
							| 
									
										
										
										
											2021-11-30 20:46:42 +08:00
										 |  |  | 					source.add("\n"); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 				/** @type {Map<string, string> | undefined} */ | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				const exports = | 
					
						
							|  |  |  | 					codeGenResult.data && codeGenResult.data.get("css-exports"); | 
					
						
							| 
									
										
										
										
											2023-04-26 05:23:21 +08:00
										 |  |  | 				let moduleId = chunkGraph.getModuleId(module) + ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 				// When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
 | 
					
						
							| 
									
										
										
										
											2023-04-26 05:23:21 +08:00
										 |  |  | 				if (typeof moduleId === "string") { | 
					
						
							|  |  |  | 					moduleId = moduleId.replace(/\\/g, "/"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				metaData.push( | 
					
						
							|  |  |  | 					`${ | 
					
						
							|  |  |  | 						exports | 
					
						
							| 
									
										
										
										
											2024-02-21 16:00:24 +08:00
										 |  |  | 							? Array.from( | 
					
						
							|  |  |  | 									exports, | 
					
						
							|  |  |  | 									([n, v]) => `${escapeCss(n)}:${escapeCss(v)}/` | 
					
						
							|  |  |  | 								).join("") | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 							: "" | 
					
						
							| 
									
										
										
										
											2021-12-15 16:19:06 +08:00
										 |  |  | 					}${escapeCss(moduleId)}`
 | 
					
						
							| 
									
										
										
										
											2021-12-14 23:02:26 +08:00
										 |  |  | 				); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 			} catch (e) { | 
					
						
							| 
									
										
										
										
											2023-06-04 01:52:25 +08:00
										 |  |  | 				/** @type {Error} */ | 
					
						
							|  |  |  | 				(e).message += `\nduring rendering of css ${module.identifier()}`; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 				throw e; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2024-03-06 14:29:57 +08:00
										 |  |  | 		const metaDataStr = metaData.join(","); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		source.add( | 
					
						
							| 
									
										
										
										
											2021-12-15 23:46:13 +08:00
										 |  |  | 			`head{--webpack-${escapeCss( | 
					
						
							|  |  |  | 				(uniqueName ? uniqueName + "-" : "") + chunk.id, | 
					
						
							|  |  |  | 				true | 
					
						
							| 
									
										
										
										
											2024-03-06 14:29:57 +08:00
										 |  |  | 			)}:${cssHeadDataCompression ? LZWEncode(metaDataStr) : metaDataStr};}`
 | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		return source; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 03:26:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {OutputOptions} outputOptions output options | 
					
						
							|  |  |  | 	 * @returns {Chunk["cssFilenameTemplate"] | OutputOptions["cssFilename"] | OutputOptions["cssChunkFilename"]} used filename template | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	static getChunkFilenameTemplate(chunk, outputOptions) { | 
					
						
							|  |  |  | 		if (chunk.cssFilenameTemplate) { | 
					
						
							|  |  |  | 			return chunk.cssFilenameTemplate; | 
					
						
							| 
									
										
										
										
											2021-12-17 19:18:01 +08:00
										 |  |  | 		} else if (chunk.canBeInitial()) { | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 			return outputOptions.cssFilename; | 
					
						
							| 
									
										
										
										
											2021-12-17 19:18:01 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			return outputOptions.cssChunkFilename; | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 02:50:41 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk chunk | 
					
						
							|  |  |  | 	 * @param {ChunkGraph} chunkGraph chunk graph | 
					
						
							|  |  |  | 	 * @returns {boolean} true, when the chunk has css | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	static chunkHasCss(chunk, chunkGraph) { | 
					
						
							| 
									
										
										
										
											2021-12-03 02:29:55 +08:00
										 |  |  | 		return ( | 
					
						
							|  |  |  | 			!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css") || | 
					
						
							|  |  |  | 			!!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import") | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:55:51 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = CssModulesPlugin; |