summaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/dependencies/CssUrlDependency.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:10:59 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-05-18 23:41:44 +0800
commitfc87c009806dcc98867f6b58efe29b042aa01dee (patch)
tree8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/webpack/lib/dependencies/CssUrlDependency.js
parent3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff)
node: updatemain
Diffstat (limited to 'node_modules/webpack/lib/dependencies/CssUrlDependency.js')
-rw-r--r--node_modules/webpack/lib/dependencies/CssUrlDependency.js164
1 files changed, 0 insertions, 164 deletions
diff --git a/node_modules/webpack/lib/dependencies/CssUrlDependency.js b/node_modules/webpack/lib/dependencies/CssUrlDependency.js
deleted file mode 100644
index 15fc53aa..00000000
--- a/node_modules/webpack/lib/dependencies/CssUrlDependency.js
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Ivan Kopeykin @vankop
-*/
-
-"use strict";
-
-const RawDataUrlModule = require("../asset/RawDataUrlModule");
-const makeSerializable = require("../util/makeSerializable");
-const memoize = require("../util/memoize");
-const ModuleDependency = require("./ModuleDependency");
-
-/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
-/** @typedef {import("../ChunkGraph")} ChunkGraph */
-/** @typedef {import("../Dependency")} Dependency */
-/** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
-/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
-/** @typedef {import("../Module")} Module */
-/** @typedef {import("../ModuleGraph")} ModuleGraph */
-/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
-/** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
-/** @typedef {import("../javascript/JavascriptParser").Range} Range */
-/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
-/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
-/** @typedef {import("../util/Hash")} Hash */
-/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
-
-const getIgnoredRawDataUrlModule = memoize(
- () => new RawDataUrlModule("data:,", "ignored-asset", "(ignored asset)")
-);
-
-class CssUrlDependency extends ModuleDependency {
- /**
- * @param {string} request request
- * @param {Range} range range of the argument
- * @param {"string" | "url"} urlType dependency type e.g. url() or string
- */
- constructor(request, range, urlType) {
- super(request);
- this.range = range;
- this.urlType = urlType;
- }
-
- get type() {
- return "css url()";
- }
-
- get category() {
- return "url";
- }
-
- /**
- * @param {string} context context directory
- * @returns {Module | null} a module
- */
- createIgnoredModule(context) {
- return getIgnoredRawDataUrlModule();
- }
-
- /**
- * @param {ObjectSerializerContext} context context
- */
- serialize(context) {
- const { write } = context;
- write(this.urlType);
- super.serialize(context);
- }
-
- /**
- * @param {ObjectDeserializerContext} context context
- */
- deserialize(context) {
- const { read } = context;
- this.urlType = read();
- super.deserialize(context);
- }
-}
-
-/**
- * @param {string} str string
- * @returns {string} string in quotes if needed
- */
-const cssEscapeString = str => {
- let countWhiteOrBracket = 0;
- let countQuotation = 0;
- let countApostrophe = 0;
- for (let i = 0; i < str.length; i++) {
- const cc = str.charCodeAt(i);
- switch (cc) {
- case 9: // tab
- case 10: // nl
- case 32: // space
- case 40: // (
- case 41: // )
- countWhiteOrBracket++;
- break;
- case 34:
- countQuotation++;
- break;
- case 39:
- countApostrophe++;
- break;
- }
- }
- if (countWhiteOrBracket < 2) {
- return str.replace(/[\n\t ()'"\\]/g, m => `\\${m}`);
- } else if (countQuotation <= countApostrophe) {
- return `"${str.replace(/[\n"\\]/g, m => `\\${m}`)}"`;
- }
- return `'${str.replace(/[\n'\\]/g, m => `\\${m}`)}'`;
-};
-
-CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
- ModuleDependency.Template
-) {
- /**
- * @param {Dependency} dependency the dependency for which the template should be applied
- * @param {ReplaceSource} source the current replace source which can be modified
- * @param {DependencyTemplateContext} templateContext the context object
- * @returns {void}
- */
- apply(
- dependency,
- source,
- { moduleGraph, runtimeTemplate, codeGenerationResults }
- ) {
- const dep = /** @type {CssUrlDependency} */ (dependency);
- const module = /** @type {Module} */ (moduleGraph.getModule(dep));
-
- /** @type {string | undefined} */
- let newValue;
-
- switch (dep.urlType) {
- case "string":
- newValue = cssEscapeString(
- runtimeTemplate.assetUrl({
- module,
- codeGenerationResults
- })
- );
- break;
- case "url":
- newValue = `url(${cssEscapeString(
- runtimeTemplate.assetUrl({
- module,
- codeGenerationResults
- })
- )})`;
- break;
- }
-
- source.replace(
- dep.range[0],
- dep.range[1] - 1,
- /** @type {string} */ (newValue)
- );
- }
-};
-
-makeSerializable(CssUrlDependency, "webpack/lib/dependencies/CssUrlDependency");
-
-CssUrlDependency.PUBLIC_PATH_AUTO = "__WEBPACK_CSS_PUBLIC_PATH_AUTO__";
-
-module.exports = CssUrlDependency;