/* MIT License http://www.opensource.org/licenses/mit-license.php */ "use strict"; const { CSS_TEXT_TYPE } = require("../ModuleSourceTypeConstants"); const makeSerializable = require("../util/makeSerializable"); const ModuleDependency = require("./ModuleDependency"); /** @import { ReplaceSource } from "webpack-sources" */ /** @import CodeGenerationResults from "../CodeGenerationResults" */ /** @import Dependency, { UpdateHashContext } from "../Dependency" */ /** @import { DependencyTemplateContext } from "../DependencyTemplate" */ /** @import Module from "../Module" */ /** @import { Range } from "../javascript/JavascriptParser" */ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */ /** @import Hash from "../util/Hash" */ const TRAILING_WHITESPACE_REGEXP = /\s+$/; // One pass over the source: each char is replaced once and replacements aren't // re-scanned, so this matches the `&`-first sequential escape chain exactly // while avoiding two extra full-string scans + intermediate strings. const ATTR_ESCAPE_REGEXP = /[&"']/g; /** @type {Record} */ const ATTR_ESCAPES = { "&": "&", '"': """, "'": "'" }; /** * @param {string} c matched character * @returns {string} the HTML-attribute-escaped entity */ const escapeAttrChar = (c) => ATTR_ESCAPES[c]; /** * Represents inline CSS in an HTML module — either a `` * block (a stylesheet) or an element's `style="..."` attribute (a CSS * block's contents). The content is fed into webpack's CSS pipeline as a * virtual CSS module with `exportType: "text"` so `url()` and `\@import` * references are resolved relative to the HTML file. At render time the * original content range is replaced with the processed CSS text read from * the CSS module's code generation data. */ class HtmlInlineStyleDependency extends ModuleDependency { /** * Creates an instance of HtmlInlineStyleDependency. * @param {string} request virtual request resolving to the inline CSS (data URI) * @param {Range} range range of the inline CSS content (between ``, or the `style` attribute value) * @param {boolean=} attribute true when the source is a `style="..."` attribute (a block's contents) rather than a `