weapp-tailwindcss
Version:
把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!
956 lines (955 loc) • 42.3 kB
JavaScript
const require_rolldown_runtime = require("./rolldown-runtime-CVvi-lCc.cjs");
const require_generator = require("./generator-BE34PYSC.cjs");
const require_v4_generation_core = require("./v4-generation-core-CDI6ChiH.cjs");
const require_defaults = require("./defaults.cjs");
const require_style_options = require("./style-options-B_ppaVIg.cjs");
let node_path = require("node:path");
node_path = require_rolldown_runtime.__toESM(node_path, 1);
let node_process = require("node:process");
node_process = require_rolldown_runtime.__toESM(node_process, 1);
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
let _weapp_core_escape = require("@weapp-core/escape");
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.ts
function isRuntimeTransformCandidate(candidate) {
return candidate.length > 0 && !candidate.includes("=") && !candidate.includes("<") && !candidate.includes(">") && !candidate.includes("${");
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.ts
function collectWebpackAssetUserCssMarkers(source) {
const markers = /* @__PURE__ */ new Set();
for (const match of source.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
for (const match of source.matchAll(/@(?:-[\w-]+-)?keyframes\s+((?:\\.|[-\w\u00A0-\uFFFF])+)/gi)) markers.add(`keyframes:${match[1]}`);
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
root.walkRules((rule) => {
for (const selector of rule.selectors) if (!/(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector)) markers.add(`selector:${selector.trim().replace(/\s+/g, " ")}`);
rule.walkDecls((decl) => {
if (decl.prop.startsWith("--")) markers.add(`custom-property:${decl.prop}`);
});
});
root.walkAtRules("font-face", (rule) => {
rule.walkDecls("font-family", (decl) => {
markers.add(`font-face:${decl.value.trim()}`);
});
});
} catch {}
return markers;
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.ts
const WEBPACK_TAILWIND_GENERATED_LAYER_NAMES = /* @__PURE__ */ new Set([
"theme",
"base",
"utilities"
]);
const WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE = /(?:^|[^\w-])\.[^,{]{0,512}(?:\\:|\\\[|\\#)/;
const WEBPACK_TAILWIND_UTILITY_PREFIX_RE = /^\.(?:-?(?:bg|text|border|ring|shadow|drop-shadow|[pmwhz]|px|py|pt|pr|pb|pl|mx|my|mt|mr|mb|ml|min-w|min-h|max-w|max-h|flex|grid|inline|block|hidden|rounded|opacity|translate|scale|rotate|skew|top|right|bottom|left|inset|gap|font|leading|tracking|underline|container)(?:[\-\\{]|$)|\\\[)/;
const WEBPACK_TAILWIND_BANNER_RE = /tailwindcss v4\./;
const WEBPACK_TAILWIND_PREFLIGHT_SELECTORS = /* @__PURE__ */ new Set([
"*",
":after",
":before",
"::after",
"::before",
"::backdrop",
"view",
"text"
]);
const WEBPACK_TAILWIND_PREFLIGHT_PROPS = /* @__PURE__ */ new Set([
"box-sizing",
"border",
"border-width",
"border-style",
"border-color",
"margin",
"padding"
]);
const WEBPACK_TAILWIND_THEME_TOKEN_RE = /^--(?:tw-|color-|spacing|breakpoint-|container-|text-|font-|tracking-|leading-|radius-|shadow-|inset-shadow-|drop-shadow-|ease-|animate-|blur-|perspective-|aspect-|default-)/;
function parseWebpackCssLayerNames(params) {
return params.split(",").map((name) => name.trim()).filter(Boolean);
}
function removeWebpackTailwindGeneratedAssetCss(source) {
const cleaned = require_generator.removeTailwindV4GeneratedUserCssArtifacts(source);
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(cleaned);
let changed = false;
let removingBannerPrefix = false;
for (const node of [...root.nodes]) {
if (node.type === "comment" && WEBPACK_TAILWIND_BANNER_RE.test(node.text)) {
node.remove();
changed = true;
removingBannerPrefix = true;
continue;
}
if (!removingBannerPrefix) continue;
if (isWebpackTailwindGeneratedPrefixNode(node)) {
node.remove();
changed = true;
continue;
}
removingBannerPrefix = false;
}
root.walkAtRules("layer", (rule) => {
const names = parseWebpackCssLayerNames(rule.params);
const hasGeneratedLayerName = names.some((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
const isLayerDeclaration = rule.nodes === void 0;
const shouldRemoveLayer = isLayerDeclaration ? hasGeneratedLayerName : names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name));
if (shouldRemoveLayer && isLayerDeclaration) {
rule.remove();
changed = true;
return;
}
if (shouldRemoveLayer && !names.includes("utilities")) {
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
child.remove();
changed = true;
}
if (rule.nodes?.length === 0) {
rule.remove();
changed = true;
}
return;
}
if (shouldRemoveLayer) {
for (const child of [...rule.nodes ?? []]) if (isWebpackTailwindGeneratedLayerNode(child, names)) {
child.remove();
changed = true;
}
if (rule.nodes?.length === 0) {
rule.remove();
changed = true;
}
}
});
root.walkRules((rule) => {
if (rule.parent?.type === "atrule" && rule.parent.name === "layer") return;
const selector = rule.selector.trim();
if (WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || isWebpackTailwindGeneratedPreflightRule(rule)) {
rule.remove();
changed = true;
}
});
root.walkComments((comment) => {
if (WEBPACK_TAILWIND_BANNER_RE.test(comment.text)) {
comment.remove();
changed = true;
}
});
root.walkAtRules((rule) => {
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
rule.remove();
changed = true;
}
});
return changed ? root.toString() : cleaned;
} catch {
return cleaned;
}
}
function isWebpackTailwindGeneratedPrefixNode(node) {
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, [
"theme",
"base",
"utilities"
], true);
if (node.type !== "atrule") return false;
const names = node.name === "layer" ? parseWebpackCssLayerNames(node.params) : [];
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
if (names.length > 0 && names.every((name) => WEBPACK_TAILWIND_GENERATED_LAYER_NAMES.has(name))) {
if (node.nodes === void 0) return true;
return node.nodes.length > 0 && node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, names));
}
if (node.nodes === void 0 || node.nodes.length === 0) return false;
return node.nodes.every((child) => isWebpackTailwindGeneratedPrefixNode(child));
}
function isWebpackTailwindGeneratedLayerNode(node, layerNames) {
if (node.type === "rule") return isWebpackTailwindGeneratedRule(node, layerNames, false);
if (node.type !== "atrule") return false;
if (node.name === "property" && node.params.trim().startsWith("--tw-")) return true;
if (node.nodes === void 0 || node.nodes.length === 0) return false;
return node.nodes.every((child) => isWebpackTailwindGeneratedLayerNode(child, layerNames));
}
function isWebpackTailwindGeneratedRule(rule, layerNames, includePrefix) {
const selectors = rule.selectors ?? [rule.selector];
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), includePrefix))) return true;
if (selectors.every((selector) => isWebpackTailwindGeneratedUtilitySelector(selector.trim(), true))) return true;
if (layerNames.includes("theme") && isWebpackTailwindGeneratedThemeRule(rule)) return true;
if (layerNames.includes("base") && isWebpackTailwindGeneratedPreflightRule(rule)) return true;
return false;
}
function isWebpackTailwindGeneratedThemeRule(rule) {
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
return declarations.length > 0 && declarations.every((decl) => WEBPACK_TAILWIND_THEME_TOKEN_RE.test(decl.prop) || decl.value.includes("--theme("));
}
function isWebpackTailwindGeneratedPreflightRule(rule) {
const selectors = rule.selectors ?? [rule.selector];
const declarations = (rule.nodes ?? []).filter((node) => node.type === "decl");
return selectors.length > 0 && declarations.length > 0 && selectors.every((selector) => {
const normalized = selector.trim().replace(/\s+/g, " ");
return WEBPACK_TAILWIND_PREFLIGHT_SELECTORS.has(normalized);
}) && declarations.every((decl) => WEBPACK_TAILWIND_PREFLIGHT_PROPS.has(decl.prop));
}
function isOnlyWebpackTailwindGeneratedPreflightCss(source) {
try {
const nodes = _weapp_tailwindcss_postcss.postcss.parse(source).nodes ?? [];
return nodes.length > 0 && nodes.every((node) => {
if (node.type === "rule") return isWebpackTailwindGeneratedPreflightRule(node);
return node.type === "atrule" && (node.nodes === void 0 || node.nodes.length === 0);
});
} catch {
return false;
}
}
function isWebpackTailwindGeneratedUtilitySelector(selector, includePrefix) {
return WEBPACK_TAILWIND_UTILITY_RULE_MARKER_RE.test(selector) || includePrefix && WEBPACK_TAILWIND_UTILITY_PREFIX_RE.test(selector);
}
function collectWebpackCssRuleIdentityMarkers(source) {
const markers = /* @__PURE__ */ new Set();
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
root.walkRules((rule) => {
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[_a-z\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/gi)) markers.add(`class:${match[1]}`);
});
root.walkAtRules("keyframes", (rule) => {
if (rule.params) markers.add(`keyframes:${rule.params}`);
});
} catch {}
return markers;
}
function unescapeCssIdentifier(value) {
return value.replace(/\\([0-9a-f]{1,6}\s?|.)/gi, (_match, escaped) => {
const hex = escaped.trim();
if (/^[0-9a-f]+$/i.test(hex)) return String.fromCodePoint(Number.parseInt(hex, 16));
return escaped;
});
}
function collectGeneratedCssRuntimeCandidates(source) {
const candidates = /* @__PURE__ */ new Set();
if (require_v4_generation_core.hasBundlerGeneratedCssMarker(source) || !require_generator.hasTailwindGeneratedCss(source) && !require_generator.hasTailwindGeneratedCssMarkers(source)) return candidates;
try {
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
for (const selector of rule.selectors) for (const match of selector.matchAll(/\.((?:\\.|[\w\u00A0-\uFFFF-])(?:\\.|[\w\u00A0-\uFFFF-])*)/g)) {
const candidate = unescapeCssIdentifier(match[1]);
if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
}
});
} catch {}
return candidates;
}
function hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource) {
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
if (rawMarkers.size === 0) return false;
const generatorMarkers = collectWebpackAssetUserCssMarkers(generatorRawSource);
for (const marker of rawMarkers) if (!generatorMarkers.has(marker)) return true;
return false;
}
function hasWebpackTailwindSourceDirectives(source) {
return Boolean(source) && (require_generator.hasTailwindRootDirectives(source, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(source, { importFallback: true }) || require_generator.hasTailwindApplyDirective(source) || require_generator.hasTailwindGeneratedCss(source) || require_generator.hasTailwindGeneratedCssMarkers(source));
}
function resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) {
return styleOptions.cssPreflight ?? compilerOptions.cssPreflight ?? require_defaults.getDefaultCssPreflight();
}
function resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) {
return hasMiniProgramPreflightSelector(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0;
}
function removeMiniProgramPreflightSelectorRule(source) {
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
let changed = false;
root.walkRules((rule) => {
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
if (selectors.has("view") && selectors.has("text") && selectors.has("::before") && selectors.has("::after")) {
rule.remove();
changed = true;
}
});
return changed ? root.toString() : source;
} catch {
return source.replace(/(?:^|[}\s])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{[^}]*\}/g, "");
}
}
function dedupeMiniProgramPreflightSelectorRules(source) {
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
let firstRule;
let changed = false;
root.walkRules((rule) => {
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
if (!selectors.has("view") || !selectors.has("text") || !selectors.has("::before") || !selectors.has("::after")) return;
if (!firstRule) {
firstRule = rule;
return;
}
const existingProps = /* @__PURE__ */ new Set();
firstRule.walkDecls((decl) => {
existingProps.add(decl.prop);
});
rule.walkDecls((decl) => {
if (!existingProps.has(decl.prop)) {
firstRule?.append(decl.clone());
existingProps.add(decl.prop);
}
});
rule.remove();
changed = true;
});
return changed ? root.toString() : source;
} catch {
return source;
}
}
function hasMiniProgramPreflightSelector(source) {
try {
let found = false;
_weapp_tailwindcss_postcss.postcss.parse(source).walkRules((rule) => {
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
if (selectors.has("view") && selectors.has("text") && selectors.has("::before") && selectors.has("::after")) {
found = true;
return false;
}
});
return found;
} catch {
return /(?:^|[},])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(source);
}
}
function ensureWebpackMiniProgramTwContentInit(source) {
if (!source.includes("var(--tw-content)")) return source;
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
let changed = false;
root.walkRules((rule) => {
const selectors = new Set((rule.selectors ?? [rule.selector]).map((selector) => selector.trim().replace(/^:before$/, "::before").replace(/^:after$/, "::after")));
if (!selectors.has("view") || !selectors.has("text") || !selectors.has("::before") || !selectors.has("::after")) return;
let hasContentInit = false;
rule.walkDecls("--tw-content", () => {
hasContentInit = true;
});
if (!hasContentInit) {
rule.append(_weapp_tailwindcss_postcss.postcss.decl({
prop: "--tw-content",
value: "''"
}));
changed = true;
}
return false;
});
return changed ? root.toString() : source;
} catch {
return source;
}
}
function removeTailwindV4StandaloneHostPreflightRule(source) {
if (!source.includes("--theme(")) return source;
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
let changed = false;
root.walkRules((rule) => {
if (rule.selector.trim() !== ":host") return;
if (!rule.nodes?.some((node) => node.type === "decl" && node.value?.includes("--theme("))) return;
rule.remove();
changed = true;
});
return changed ? root.toString() : source;
} catch {
return source;
}
}
function collectRuntimeTokenSignatureParts(source) {
return source.match(/[\w-]+_[A-Z][\w-]*/gi) ?? [];
}
function hasMissingRuntimeCandidates(classSet, candidates) {
if (!classSet || !candidates?.size) return false;
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate) && !classSet.has(candidate)) return true;
return false;
}
function hasStaleRuntimeCandidates(classSet, candidates) {
if (!classSet || !candidates) return false;
for (const candidate of classSet) if (isRuntimeTransformCandidate(candidate) && !candidates.has(candidate)) return true;
return false;
}
function resolveGeneratedCssRuntimeCandidates(source, fallbackClassSet) {
const classSet = collectGeneratedCssRuntimeCandidates(source);
if (classSet.size > 0 || fallbackClassSet === void 0) return classSet;
return fallbackClassSet;
}
function getRuntimeClassSetSync(tailwindRuntime) {
if (typeof tailwindRuntime.getClassSetSync !== "function") return /* @__PURE__ */ new Set();
try {
return new Set(tailwindRuntime.getClassSetSync() ?? []);
} catch {
return /* @__PURE__ */ new Set();
}
}
function toMb(bytes) {
return Math.round(bytes / 1024 / 1024);
}
function pruneMapToMaxSize(map, maxSize) {
while (map.size > maxSize) {
const oldestKey = map.keys().next().value;
if (oldestKey === void 0) break;
map.delete(oldestKey);
}
}
function stripTrailingLineWhitespace(source) {
return source.replace(/[ \t]+$/gm, "");
}
function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
pruneMapToMaxSize(cssHandlerOptionsCache, 128);
pruneMapToMaxSize(cssUserHandlerOptionsCache, 128);
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.ts
function resolveWebpackMemoryDebugStats(context) {
if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
const memory = node_process.default.memoryUsage();
const processCacheInstanceSize = context.cache.instance.size;
const processCacheHashMapSize = context.cache.hashMap.size;
return {
phase: context.phase,
process: {
rssMb: toMb(memory.rss),
heapTotalMb: toMb(memory.heapTotal),
heapUsedMb: toMb(memory.heapUsed),
externalMb: toMb(memory.external),
arrayBuffersMb: toMb(memory.arrayBuffers)
},
assets: {
active: context.activeAssetFiles,
activeCss: context.activeCssFiles
},
processCache: {
instance: processCacheInstanceSize,
hashMap: processCacheHashMapSize,
activeCacheKeys: context.activeProcessCacheKeys.size,
activeHashKeys: context.activeProcessHashKeys.size,
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
pruned: true,
pruneSkipped: false
},
webpackCss: {
handlerOptions: context.cssHandlerOptionsCache.size,
userHandlerOptions: context.cssUserHandlerOptionsCache.size,
maxHandlerOptions: 128
},
sourceCandidateScan: context.sourceCandidateScan,
tailwind: { v4: require_generator.getTailwindV4IncrementalGenerateCacheStats() }
};
}
function shouldInjectWebpackCssTracePreflight(_appType, cssHandlerOptions) {
if (includesTailwindPreflightImport(cssHandlerOptions.sourceOptions?.sourceCss)) return true;
return cssHandlerOptions.isMainChunk !== false;
}
function includesTailwindPreflightImport(source) {
if (!source) return false;
try {
let includesPreflight = false;
_weapp_tailwindcss_postcss.postcss.parse(source).walkAtRules((rule) => {
if (rule.name === "tailwind") {
includesPreflight || (includesPreflight = rule.params.trim() === "base");
return;
}
if (rule.name !== "import") return;
const request = require_generator.parseImportRequest(rule.params)?.replaceAll("\\", "/");
includesPreflight || (includesPreflight = request === "tailwindcss" || request === "tailwindcss/preflight.css" || request?.endsWith("/tailwindcss/index.css") === true || request?.endsWith("/tailwindcss/preflight.css") === true);
});
return includesPreflight;
} catch {
return false;
}
}
function finalizeMiniProgramUserCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
const styleOptions = require_style_options.resolveStyleOptionsFromContext(compilerOptions);
if (isWebGeneratorTarget) return source;
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(removeTailwindV4StandaloneHostPreflightRule((0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(require_generator.removeMiniProgramHoverSelectors(source, styleOptions.cssRemoveHoverPseudoClass), {
cssPreflight: options.cssPreflight === false ? false : !require_v4_generation_core.hasMiniProgramTailwindV4PreflightReset(source) ? resolveConfiguredWebpackCssPreflight(compilerOptions, styleOptions) : void 0,
isTailwindcssV4: true,
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
})));
}
function shouldFallbackToWebpackUserCssOnGeneratorError(options) {
return !require_generator.hasTailwindRootDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindSourceDirectives(options.generatorRawSource, { importFallback: true }) && !require_generator.hasTailwindApplyDirective(options.generatorRawSource) && !options.hasExplicitTailwindV4SourceCss && options.configuredMainCssEntryFilesLength === 0;
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.ts
function finalizeTracedWebpackCssAsset(css, cssHandlerOptions, options) {
if (options.finalized === true) return options.annotateCss(css);
if (options.isWebGeneratorTarget || !require_v4_generation_core.isCssSourceTraceEnabled(options.compilerOptions)) return options.annotateCss(css);
const finalized = finalizeMiniProgramUserCssAssetSource(css, options.compilerOptions, options.isWebGeneratorTarget, { cssPreflight: shouldInjectWebpackCssTracePreflight(options.compilerOptions.appType, cssHandlerOptions) });
return options.annotateCss(finalized);
}
function finalizeWebpackCssAssetSource(source, compilerOptions, isWebGeneratorTarget, options = {}) {
const styleOptions = require_style_options.resolveStyleOptionsFromContext(compilerOptions);
if (isWebGeneratorTarget) {
if (options.generatedCss === true) return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_v4_generation_core.stripBundlerGeneratedCssMarkers(source))));
return stripTrailingLineWhitespace(require_generator.stripUnmatchedTailwindSourceMediaCloseFragments(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(require_generator.removeTailwindSourceDirectives(require_v4_generation_core.stripBundlerGeneratedCssMarkers(source), { importFallback: true })))));
}
let finalized = require_generator.removeTailwindSourceDirectives(require_v4_generation_core.stripBundlerGeneratedCssMarkers(source), { importFallback: true });
if (options.generatedCss !== true) {
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
cssPreflight: false,
isTailwindcssV4: true,
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
});
finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
}
try {
finalized = (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(finalized, { preservePreflight: options.cssPreflight !== false });
} catch {}
const shouldRemoveExistingPreflight = options.cssPreflight === false && options.preserveExistingPreflight === false;
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
const hasExistingMiniProgramPreflight = options.preserveExistingPreflight !== false && hasMiniProgramPreflightSelector(source);
finalized = (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(finalized, {
cssPreflight: options.cssPreflight === false && !hasExistingMiniProgramPreflight ? false : !require_v4_generation_core.hasMiniProgramTailwindV4PreflightReset(finalized) ? resolveExistingWebpackCssPreflight(compilerOptions, styleOptions, source) : void 0,
isTailwindcssV4: true,
tailwindcssV4GradientFallback: styleOptions.tailwindcssV4GradientFallback
});
finalized = ensureWebpackMiniProgramTwContentInit(finalized);
if (shouldRemoveExistingPreflight) finalized = removeMiniProgramPreflightSelectorRule(finalized);
else finalized = dedupeMiniProgramPreflightSelectorRules(finalized);
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors(finalized, styleOptions.cssRemoveHoverPseudoClass));
}
function finalizeWebpackCssAssetOutputSource(source, compilerOptions, isWebGeneratorTarget) {
if (isWebGeneratorTarget) return source;
const styleOptions = require_style_options.resolveStyleOptionsFromContext(compilerOptions);
return (0, _weapp_tailwindcss_postcss.stripMiniProgramCssSpecificityPlaceholders)(require_generator.removeMiniProgramHoverSelectors((0, _weapp_tailwindcss_postcss.dedupeCoveredCssRules)(dedupeMiniProgramPreflightSelectorRules(source)), styleOptions.cssRemoveHoverPseudoClass));
}
function collectWebpackJsRuntimeCandidatesFromAssets(options) {
if (options.isWebGeneratorTarget) return;
const candidates = /* @__PURE__ */ new Set();
for (const file of options.jsAssets) {
const sourceLike = options.getAssetSource(file);
if (sourceLike === void 0) continue;
const source = stringifyWebpackSourceLike(sourceLike);
for (const candidate of require_v4_generation_core.collectStrictEscapedRuntimeCandidates(source, _weapp_core_escape.MappingChars2String, options.escapeFragments)) if (isRuntimeTransformCandidate(candidate)) candidates.add(candidate);
}
return candidates;
}
function collectWebpackJsRuntimeTokenSignature(options) {
if (options.isWebGeneratorTarget) return "";
const tokens = [];
for (const file of options.jsAssets) {
const sourceLike = options.getAssetSource(file);
if (sourceLike === void 0) continue;
tokens.push(...collectRuntimeTokenSignatureParts(stringifyWebpackSourceLike(sourceLike)));
}
return tokens.sort().join("\n");
}
function addRuntimeTransformCandidates(target, candidates) {
if (!candidates?.size) return;
for (const candidate of candidates) if (isRuntimeTransformCandidate(candidate)) target.add(candidate);
}
function createWebpackCssSourceTraceTokenSources(compilerOptions, webpackSourceCandidates) {
if (!require_v4_generation_core.isCssSourceTraceEnabled(compilerOptions) || !webpackSourceCandidates) return;
return require_v4_generation_core.createCssTokenSourceMap(webpackSourceCandidates.tokenSources, compilerOptions);
}
function stringifyOptionalWebpackSourceValue(value) {
return typeof value === "string" ? value : value?.toString() ?? "";
}
function stringifyWebpackSourceLike(source) {
if (typeof source === "string") return source;
const value = source.source();
return typeof value === "string" ? value : value.toString();
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.ts
function resolveWebpackGeneratorRawSource(rawSource, cssHandlerOptions) {
const sourceCss = cssHandlerOptions.sourceOptions?.sourceCss;
if (sourceCss && (require_generator.hasTailwindRootDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindSourceDirectives(sourceCss, { importFallback: true }) || require_generator.hasTailwindApplyDirective(sourceCss) || require_generator.hasTailwindGeneratedCss(sourceCss) || require_generator.hasTailwindGeneratedCssMarkers(sourceCss))) return sourceCss;
return rawSource;
}
function shouldConsumeWebpackLoaderGeneratedCss(options) {
if (!options.shouldRegenerateExplicitTailwindV4CssSource) return true;
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
if (options.hasBundlerGeneratedCssMarker) return true;
if (options.watchMode === true && options.loaderGeneratedClassSet && options.sourceCandidates && hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates)) return false;
return Boolean(options.allowMarkerlessRegistryMatch && options.loaderGeneratedClassSet && options.sourceCandidates && !hasMissingRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates) && !hasStaleRuntimeCandidates(options.loaderGeneratedClassSet, options.sourceCandidates));
}
function hasDeferredWebpackGeneratedCss(source, generatedClassSets) {
const selectors = require_v4_generation_core.collectRawSourceClassSelectors(source);
for (const classSet of generatedClassSets) for (const candidate of classSet) if (selectors.has(candidate)) return true;
return false;
}
function hasUsableWebpackGeneratorCssSources(cssSources) {
return Array.isArray(cssSources) && cssSources.some((source) => typeof source?.css === "string" && source.css.length > 0);
}
function normalizeWebpackGeneratorCssSources(cssSources) {
if (!Array.isArray(cssSources)) return;
const normalized = cssSources.filter((source) => typeof source?.css === "string" && source.css.length > 0);
return normalized.length > 0 ? normalized : void 0;
}
function scopeWebpackGeneratorOptionsToCssSource(compilerOptions, sourceFile, options = {}) {
const withoutCssEntries = () => ({
...compilerOptions,
...compilerOptions.cssEntries?.length ? { cssEntries: [] } : {},
tailwindcss: {
...compilerOptions.tailwindcss,
v4: {
...compilerOptions.tailwindcss?.v4,
...compilerOptions.tailwindcss?.v4?.cssEntries?.length || compilerOptions.cssEntries?.length ? { cssEntries: [] } : {}
}
}
});
if (!sourceFile) {
if (options.disableUnmatchedCssEntries !== true) return compilerOptions;
if (!compilerOptions.cssEntries?.length && !compilerOptions.tailwindcss?.v4?.cssEntries?.length) return compilerOptions;
return withoutCssEntries();
}
const resolvedSourceFile = node_path.default.resolve(sourceFile);
if (options.disableUnmatchedCssEntries === true) {
const configuredEntries = [...compilerOptions.cssEntries ?? [], ...compilerOptions.tailwindcss?.v4?.cssEntries ?? []];
if (configuredEntries.length > 0 && !configuredEntries.some((entry) => node_path.default.resolve(entry) === resolvedSourceFile)) return withoutCssEntries();
}
const cssEntries = compilerOptions.cssEntries?.filter((entry) => node_path.default.resolve(entry) === resolvedSourceFile);
const runtimeCssEntries = compilerOptions.tailwindcss?.v4?.cssEntries?.filter((entry) => node_path.default.resolve(entry) === resolvedSourceFile);
const hasScopedCssEntries = Boolean(cssEntries?.length);
const hasScopedRuntimeCssEntries = Boolean(runtimeCssEntries?.length);
if (!hasScopedCssEntries && !hasScopedRuntimeCssEntries) return compilerOptions;
return {
...compilerOptions,
...hasScopedCssEntries ? { cssEntries } : {},
tailwindcss: {
...compilerOptions.tailwindcss,
v4: {
...compilerOptions.tailwindcss?.v4,
...hasScopedRuntimeCssEntries ? { cssEntries: runtimeCssEntries } : hasScopedCssEntries ? { cssEntries } : {}
}
}
};
}
function hasProcessedCssAssetUrl(css) {
return /url\(\s*["']?data:/i.test(css);
}
function shouldUseWebpackAssetAsGeneratorUserCss(rawSource, generatorRawSource, options = {}) {
const rawMarkers = collectWebpackAssetUserCssMarkers(rawSource);
return rawSource !== generatorRawSource && (options.processed === true || !rawSource.includes("data:")) && !require_generator.hasTailwindRootDirectives(rawSource, { importFallback: true }) && !require_generator.hasTailwindSourceDirectives(rawSource, { importFallback: true }) && !require_generator.hasTailwindApplyDirective(rawSource) && rawMarkers.size > 0 && !isOnlyWebpackTailwindGeneratedPreflightCss(rawSource) && (!require_generator.hasTailwindGeneratedCssMarkers(rawSource) || hasAdditionalWebpackAssetUserCssMarkers(rawSource, generatorRawSource));
}
function hasWebpackClassSelector(selector) {
return /(?:^|[^\w-])\.[_a-z\u00A0-\uFFFF\\-]/i.test(selector);
}
function isWebpackKeyframesRule(rule) {
let parent = rule.parent;
while (parent) {
if (parent.type === "atrule" && parent.name.endsWith("keyframes")) return true;
parent = parent.parent;
}
return false;
}
function collectWebpackBareSelectorUserCss(source) {
try {
const normalizedSource = require_generator.removeTailwindSourceDirectives(require_generator.stripTailwindSourceMediaFragments(require_generator.removeTailwindV4GeneratorAtRules(source)), { importFallback: true });
const root = _weapp_tailwindcss_postcss.postcss.parse(normalizedSource);
let changed = false;
root.walkAtRules((rule) => {
if (rule.name === "import" || rule.name === "font-face" || rule.name.endsWith("keyframes")) {
rule.remove();
changed = true;
}
});
root.walkRules((rule) => {
if (isWebpackKeyframesRule(rule) || rule.selectors.some((selector) => hasWebpackClassSelector(selector))) {
rule.remove();
changed = true;
}
});
root.walkAtRules((rule) => {
if (rule.nodes !== void 0 && rule.nodes.length === 0) {
rule.remove();
changed = true;
}
});
return changed ? root.toString() : normalizedSource;
} catch {
return "";
}
}
//#endregion
//#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.ts
function isWebpackTailwindImportRequest(request) {
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/") || request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
}
function removeWebpackGeneratorNonTailwindImports(source) {
if (!source?.includes("@import")) return source;
try {
const root = _weapp_tailwindcss_postcss.postcss.parse(source);
let changed = false;
root.walkAtRules("import", (rule) => {
if (isWebpackTailwindImportRequest(require_generator.parseImportRequest(rule.params))) return;
rule.remove();
changed = true;
});
return changed ? root.toString() : source;
} catch {
return source;
}
}
function isWebpackCssSourceRepresentedInAsset(rawSource, sourceCss) {
if (!sourceCss || !hasWebpackTailwindSourceDirectives(sourceCss)) return false;
const sourceMarkers = collectWebpackCssRuleIdentityMarkers(sourceCss);
if (sourceMarkers.size === 0) return false;
const rawMarkers = collectWebpackCssRuleIdentityMarkers(rawSource);
for (const marker of sourceMarkers) if (!rawMarkers.has(marker)) return false;
return true;
}
function createWebpackGeneratorCssSource(file, css) {
if (!file || !css || !hasWebpackTailwindSourceDirectives(css)) return;
return {
file,
base: node_path.default.dirname(file),
css,
dependencies: [file]
};
}
function createWebpackUserCssSourceAppend(sources, generatorRawSource, currentSourceFile, shouldIncludeSource) {
const matchedSources = [];
const seen = /* @__PURE__ */ new Set();
for (const source of sources) {
const css = source.css;
if (!css || seen.has(css)) continue;
if (shouldIncludeSource && !shouldIncludeSource(source.file)) continue;
seen.add(css);
if ((source.processed === true || !css.includes("data:")) && hasAdditionalWebpackAssetUserCssMarkers(css, generatorRawSource)) matchedSources.push({
css,
file: source.file,
processed: source.processed === true
});
}
const currentFile = currentSourceFile ? node_path.default.resolve(currentSourceFile) : void 0;
const parts = matchedSources.sort((a, b) => {
const aCurrent = currentFile !== void 0 && node_path.default.resolve(a.file) === currentFile;
if (aCurrent !== (currentFile !== void 0 && node_path.default.resolve(b.file) === currentFile)) return aCurrent ? -1 : 1;
return a.file.localeCompare(b.file);
}).map((source) => source.css);
return parts.length > 0 ? {
css: parts.join("\n"),
processed: matchedSources.every((source) => source.processed)
} : void 0;
}
function createWebpackGeneratorUserCssSourceAppend(...sources) {
const parts = sources.filter((source) => source !== void 0 && source.css.trim().length > 0);
if (parts.length === 0) return;
let css = "";
const usedParts = [];
for (const source of parts) {
const merged = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.mergeCoveredCssRuleDeclarations)(css, source.css) : void 0;
if (merged?.changed) css = merged.baseCss;
const nextCss = css.trim().length > 0 ? (0, _weapp_tailwindcss_postcss.filterExistingCssRules)(css, merged?.css ?? source.css) : source.css;
if (!(nextCss.trim().length > 0)) continue;
css = require_v4_generation_core.createCssSourceOrderAppend(css, nextCss);
usedParts.push(source);
}
return {
css,
processed: usedParts.every((source) => source.processed)
};
}
//#endregion
Object.defineProperty(exports, "addRuntimeTransformCandidates", {
enumerable: true,
get: function() {
return addRuntimeTransformCandidates;
}
});
Object.defineProperty(exports, "collectGeneratedCssRuntimeCandidates", {
enumerable: true,
get: function() {
return collectGeneratedCssRuntimeCandidates;
}
});
Object.defineProperty(exports, "collectWebpackBareSelectorUserCss", {
enumerable: true,
get: function() {
return collectWebpackBareSelectorUserCss;
}
});
Object.defineProperty(exports, "collectWebpackJsRuntimeCandidatesFromAssets", {
enumerable: true,
get: function() {
return collectWebpackJsRuntimeCandidatesFromAssets;
}
});
Object.defineProperty(exports, "collectWebpackJsRuntimeTokenSignature", {
enumerable: true,
get: function() {
return collectWebpackJsRuntimeTokenSignature;
}
});
Object.defineProperty(exports, "createWebpackCssSourceTraceTokenSources", {
enumerable: true,
get: function() {
return createWebpackCssSourceTraceTokenSources;
}
});
Object.defineProperty(exports, "createWebpackGeneratorCssSource", {
enumerable: true,
get: function() {
return createWebpackGeneratorCssSource;
}
});
Object.defineProperty(exports, "createWebpackGeneratorUserCssSourceAppend", {
enumerable: true,
get: function() {
return createWebpackGeneratorUserCssSourceAppend;
}
});
Object.defineProperty(exports, "createWebpackUserCssSourceAppend", {
enumerable: true,
get: function() {
return createWebpackUserCssSourceAppend;
}
});
Object.defineProperty(exports, "finalizeTracedWebpackCssAsset", {
enumerable: true,
get: function() {
return finalizeTracedWebpackCssAsset;
}
});
Object.defineProperty(exports, "finalizeWebpackCssAssetOutputSource", {
enumerable: true,
get: function() {
return finalizeWebpackCssAssetOutputSource;
}
});
Object.defineProperty(exports, "finalizeWebpackCssAssetSource", {
enumerable: true,
get: function() {
return finalizeWebpackCssAssetSource;
}
});
Object.defineProperty(exports, "getRuntimeClassSetSync", {
enumerable: true,
get: function() {
return getRuntimeClassSetSync;
}
});
Object.defineProperty(exports, "hasAdditionalWebpackAssetUserCssMarkers", {
enumerable: true,
get: function() {
return hasAdditionalWebpackAssetUserCssMarkers;
}
});
Object.defineProperty(exports, "hasDeferredWebpackGeneratedCss", {
enumerable: true,
get: function() {
return hasDeferredWebpackGeneratedCss;
}
});
Object.defineProperty(exports, "hasMissingRuntimeCandidates", {
enumerable: true,
get: function() {
return hasMissingRuntimeCandidates;
}
});
Object.defineProperty(exports, "hasProcessedCssAssetUrl", {
enumerable: true,
get: function() {
return hasProcessedCssAssetUrl;
}
});
Object.defineProperty(exports, "hasUsableWebpackGeneratorCssSources", {
enumerable: true,
get: function() {
return hasUsableWebpackGeneratorCssSources;
}
});
Object.defineProperty(exports, "isRuntimeTransformCandidate", {
enumerable: true,
get: function() {
return isRuntimeTransformCandidate;
}
});
Object.defineProperty(exports, "isWebpackCssSourceRepresentedInAsset", {
enumerable: true,
get: function() {
return isWebpackCssSourceRepresentedInAsset;
}
});
Object.defineProperty(exports, "normalizeWebpackGeneratorCssSources", {
enumerable: true,
get: function() {
return normalizeWebpackGeneratorCssSources;
}
});
Object.defineProperty(exports, "pruneWebpackCssHandlerOptionCaches", {
enumerable: true,
get: function() {
return pruneWebpackCssHandlerOptionCaches;
}
});
Object.defineProperty(exports, "removeWebpackGeneratorNonTailwindImports", {
enumerable: true,
get: function() {
return removeWebpackGeneratorNonTailwindImports;
}
});
Object.defineProperty(exports, "removeWebpackTailwindGeneratedAssetCss", {
enumerable: true,
get: function() {
return removeWebpackTailwindGeneratedAssetCss;
}
});
Object.defineProperty(exports, "resolveGeneratedCssRuntimeCandidates", {
enumerable: true,
get: function() {
return resolveGeneratedCssRuntimeCandidates;
}
});
Object.defineProperty(exports, "resolveWebpackGeneratorRawSource", {
enumerable: true,
get: function() {
return resolveWebpackGeneratorRawSource;
}
});
Object.defineProperty(exports, "resolveWebpackMemoryDebugStats", {
enumerable: true,
get: function() {
return resolveWebpackMemoryDebugStats;
}
});
Object.defineProperty(exports, "scopeWebpackGeneratorOptionsToCssSource", {
enumerable: true,
get: function() {
return scopeWebpackGeneratorOptionsToCssSource;
}
});
Object.defineProperty(exports, "shouldConsumeWebpackLoaderGeneratedCss", {
enumerable: true,
get: function() {
return shouldConsumeWebpackLoaderGeneratedCss;
}
});
Object.defineProperty(exports, "shouldFallbackToWebpackUserCssOnGeneratorError", {
enumerable: true,
get: function() {
return shouldFallbackToWebpackUserCssOnGeneratorError;
}
});
Object.defineProperty(exports, "shouldUseWebpackAssetAsGeneratorUserCss", {
enumerable: true,
get: function() {
return shouldUseWebpackAssetAsGeneratorUserCss;
}
});
Object.defineProperty(exports, "stringifyOptionalWebpackSourceValue", {
enumerable: true,
get: function() {
return stringifyOptionalWebpackSourceValue;
}
});
Object.defineProperty(exports, "stringifyWebpackSourceLike", {
enumerable: true,
get: function() {
return stringifyWebpackSourceLike;
}
});
Object.defineProperty(exports, "stripTrailingLineWhitespace", {
enumerable: true,
get: function() {
return stripTrailingLineWhitespace;
}
});