| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							| 
									
										
										
										
											2024-11-01 04:19:07 +08:00
										 |  |  | 	Author Alexander Akait @alexander-akait | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const NormalModule = require("./NormalModule"); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:13:39 +08:00
										 |  |  | const makeSerializable = require("./util/makeSerializable"); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | /** @typedef {import("./Module")} Module */ | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | /** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */ | 
					
						
							|  |  |  | /** @typedef {import("./RequestShortener")} RequestShortener */ | 
					
						
							| 
									
										
										
										
											2023-04-26 00:37:59 +08:00
										 |  |  | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ | 
					
						
							|  |  |  | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 04:30:31 +08:00
										 |  |  | /** @typedef {string | undefined} CssLayer */ | 
					
						
							|  |  |  | /** @typedef {string | undefined} Supports */ | 
					
						
							|  |  |  | /** @typedef {string | undefined} Media */ | 
					
						
							|  |  |  | /** @typedef {[CssLayer, Supports, Media]} InheritanceItem */ | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {InheritanceItem[]} Inheritance */ | 
					
						
							| 
									
										
										
										
											2023-05-02 05:33:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-23 21:39:55 +08:00
										 |  |  | /** @typedef {NormalModuleCreateData & { cssLayer: CssLayer, supports: Supports, media: Media, inheritance?: Inheritance }} CSSModuleCreateData */ | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | class CssModule extends NormalModule { | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-04-26 06:19:06 +08:00
										 |  |  | 	 * @param {CSSModuleCreateData} options options object | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	constructor(options) { | 
					
						
							|  |  |  | 		super(options); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Avoid override `layer` for `Module` class, because it is a feature to run module in specific layer
 | 
					
						
							| 
									
										
										
										
											2023-04-26 00:22:30 +08:00
										 |  |  | 		this.cssLayer = options.cssLayer; | 
					
						
							| 
									
										
										
										
											2023-04-25 21:59:17 +08:00
										 |  |  | 		this.supports = options.supports; | 
					
						
							|  |  |  | 		this.media = options.media; | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		this.inheritance = options.inheritance; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} a unique identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	identifier() { | 
					
						
							|  |  |  | 		let identifier = super.identifier(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 00:22:30 +08:00
										 |  |  | 		if (this.cssLayer) { | 
					
						
							|  |  |  | 			identifier += `|${this.cssLayer}`; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.supports) { | 
					
						
							|  |  |  | 			identifier += `|${this.supports}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.media) { | 
					
						
							|  |  |  | 			identifier += `|${this.media}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		if (this.inheritance) { | 
					
						
							|  |  |  | 			const inheritance = this.inheritance.map( | 
					
						
							|  |  |  | 				(item, index) => | 
					
						
							|  |  |  | 					`inheritance_${index}|${item[0] || ""}|${item[1] || ""}|${ | 
					
						
							|  |  |  | 						item[2] || "" | 
					
						
							|  |  |  | 					}`
 | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			identifier += `|${inheritance.join("|")}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-29 04:35:59 +08:00
										 |  |  | 		// We generate extra code for HMR, so we need to invalidate the module
 | 
					
						
							|  |  |  | 		if (this.hot) { | 
					
						
							|  |  |  | 			identifier += `|${this.hot}`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		return identifier; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {RequestShortener} requestShortener the request shortener | 
					
						
							|  |  |  | 	 * @returns {string} a user readable identifier of the module | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	readableIdentifier(requestShortener) { | 
					
						
							|  |  |  | 		const readableIdentifier = super.readableIdentifier(requestShortener); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		let identifier = `css ${readableIdentifier}`; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.cssLayer) { | 
					
						
							|  |  |  | 			identifier += ` (layer: ${this.cssLayer})`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.supports) { | 
					
						
							|  |  |  | 			identifier += ` (supports: ${this.supports})`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (this.media) { | 
					
						
							|  |  |  | 			identifier += ` (media: ${this.media})`; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return identifier; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Assuming this module is in the cache. Update the (cached) module with | 
					
						
							|  |  |  | 	 * the fresh module from the factory. Usually updates internal references | 
					
						
							|  |  |  | 	 * and properties. | 
					
						
							|  |  |  | 	 * @param {Module} module fresh module | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	updateCacheModule(module) { | 
					
						
							|  |  |  | 		super.updateCacheModule(module); | 
					
						
							|  |  |  | 		const m = /** @type {CssModule} */ (module); | 
					
						
							| 
									
										
										
										
											2023-04-26 00:22:30 +08:00
										 |  |  | 		this.cssLayer = m.cssLayer; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		this.supports = m.supports; | 
					
						
							|  |  |  | 		this.media = m.media; | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		this.inheritance = m.inheritance; | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 00:37:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectSerializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-04-25 21:13:39 +08:00
										 |  |  | 	serialize(context) { | 
					
						
							|  |  |  | 		const { write } = context; | 
					
						
							| 
									
										
										
										
											2023-04-26 00:22:30 +08:00
										 |  |  | 		write(this.cssLayer); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:13:39 +08:00
										 |  |  | 		write(this.supports); | 
					
						
							|  |  |  | 		write(this.media); | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		write(this.inheritance); | 
					
						
							| 
									
										
										
										
											2023-04-25 21:13:39 +08:00
										 |  |  | 		super.serialize(context); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-26 00:37:59 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectDeserializerContext} context context | 
					
						
							|  |  |  | 	 * @returns {CssModule} the deserialized object | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 	static deserialize(context) { | 
					
						
							|  |  |  | 		const obj = new CssModule({ | 
					
						
							|  |  |  | 			// will be deserialized by Module
 | 
					
						
							| 
									
										
										
										
											2024-10-24 11:02:20 +08:00
										 |  |  | 			layer: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 			type: "", | 
					
						
							|  |  |  | 			// will be filled by updateCacheModule
 | 
					
						
							|  |  |  | 			resource: "", | 
					
						
							|  |  |  | 			context: "", | 
					
						
							| 
									
										
										
										
											2024-10-24 11:02:20 +08:00
										 |  |  | 			request: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			userRequest: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			rawRequest: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			loaders: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			matchResource: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			parser: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			parserOptions: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			generator: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			generatorOptions: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			resolveOptions: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			cssLayer: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			supports: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			media: /** @type {EXPECTED_ANY} */ (null), | 
					
						
							|  |  |  | 			inheritance: /** @type {EXPECTED_ANY} */ (null) | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		obj.deserialize(context); | 
					
						
							|  |  |  | 		return obj; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-01 03:05:27 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {ObjectDeserializerContext} context context | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 	deserialize(context) { | 
					
						
							|  |  |  | 		const { read } = context; | 
					
						
							| 
									
										
										
										
											2023-04-26 00:22:30 +08:00
										 |  |  | 		this.cssLayer = read(); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		this.supports = read(); | 
					
						
							|  |  |  | 		this.media = read(); | 
					
						
							| 
									
										
										
										
											2023-05-01 22:46:47 +08:00
										 |  |  | 		this.inheritance = read(); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:49:16 +08:00
										 |  |  | 		super.deserialize(context); | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 21:13:39 +08:00
										 |  |  | makeSerializable(CssModule, "webpack/lib/CssModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-25 20:16:42 +08:00
										 |  |  | module.exports = CssModule; |