weapp-tailwindcss 5.0.3 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +9 -0
- package/README.md +5 -133
- package/dist/{auto-dPpsm6FB.js → auto-Cvy0zWpS.js} +1 -1
- package/dist/{bundle-state-CW1X7QIy.js → bundle-state-Cso_ceUo.js} +8 -2
- package/dist/{bundle-state-s5HwfrmR.mjs → bundle-state-DEyxCR4f.mjs} +2 -2
- package/dist/bundlers/shared/generator-css/directives.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +3 -1
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +5 -0
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +2 -0
- package/dist/{chunk-C5U5_Hdc.js → chunk-emK7D4bc.js} +0 -7
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/{defaults-zKUH2mDe.js → defaults-BPUuNYcD.js} +1 -1
- package/dist/defaults.js +1 -1
- package/dist/{generator-Bd1LntD3.js → generator-AD-eX8Tr.js} +2 -2
- package/dist/{generator-DRHWC1t-.mjs → generator-DVWLNO0n.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +6 -6
- package/dist/gulp.mjs +5 -5
- package/dist/{incremental-runtime-class-set-BdCWIuPW.js → incremental-runtime-class-set-vOetpdWs.js} +195 -43
- package/dist/{incremental-runtime-class-set-BcAFhVvu.mjs → incremental-runtime-class-set-xf49kky6.mjs} +194 -42
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-DfnqZ4Bm.js → postcss-Cbi6RFpf.js} +57 -10
- package/dist/{postcss-CJrmfXvi.mjs → postcss-hSUxK7oR.mjs} +55 -8
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-h6TNzFbF.mjs → precheck-Bsn_LMmo.mjs} +19 -33
- package/dist/{precheck-8Ik4q0yI.js → precheck-b8Y8qZg0.js} +17 -31
- package/dist/presets.js +9 -5
- package/dist/presets.mjs +7 -3
- package/dist/reset.js +1 -1
- package/dist/{source-candidates-D7b-Jzsx.mjs → source-candidates-BsWYoIPN.mjs} +1 -1
- package/dist/{source-candidates-DQxvGPSw.js → source-candidates-o2ZrKWzu.js} +2 -2
- package/dist/{tailwindcss-D5RogwtV.mjs → tailwindcss-AWaPVF2B.mjs} +1 -1
- package/dist/{tailwindcss-jvoYizzX.js → tailwindcss-CpQ6X4l6.js} +3 -3
- package/dist/{vite-DT-VUrl0.js → transform-BkGtbxb1.js} +245 -10127
- package/dist/{vite-yCeZWm7n.mjs → transform-DumSZmTh.mjs} +263 -10128
- package/dist/uni-app-x/vite.d.ts +3 -0
- package/dist/{utils-D7Ygohep.js → utils-Dolmt8EO.js} +1 -1
- package/dist/{v3-engine-CmIF_gsq.js → v3-engine-CM0TRa8V.js} +29 -5
- package/dist/{v3-engine-BCUGX3gX.mjs → v3-engine-Cczrkzqt.mjs} +22 -4
- package/dist/vite-CTuHPC91.js +3283 -0
- package/dist/vite-DLXDMHON.mjs +3270 -0
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +201 -42
- package/dist/{webpack-BFMJqCH9.js → webpack-BBHJYKqB.js} +8 -9
- package/dist/{webpack-E0gT72EX.mjs → webpack-DJFw08SK.mjs} +6 -7
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { A as normalizeTailwindV3CssEntrySource, B as splitTailwindV4GeneratedCssBySourceOrder, E as hasTailwindSourceDirectives, F as createCssAppend, G as prependConfigDirective, H as stripTailwindBanner, I as hasTailwindGeneratedCss, L as hasTailwindGeneratedCssMarkers, M as removeTailwindSourceDirectives, N as resolveCssEntrySource, O as normalizeTailwindSourceDirectives, P as VITE_MARKER_RE, R as splitGeneratorPlaceholderCssBySourceOrder, S as resolveTailwindV4SourceOptionsFromPatcher, T as hasTailwindRootDirectives, U as stripTailwindBanners, V as stripGeneratorPlaceholderMarkers, W as normalizeConfigDirective, X as loadTailwindV4DesignSystem, Y as filterUnsupportedMiniProgramTailwindV4Candidates, gt as omitUndefined, h as resolveTailwindV4EntriesFromCss, j as parseImportRequest, l as getRuntimeClassSetSignature, lt as createDebug, n as resolveTailwindV3SourceFromPatcher, r as resolveTailwindV3SourceOptionsFromPatcher, rt as normalizeLegacyContentEntries, st as resolveTailwindV4CssSourceBase, t as resolveTailwindV3Source, w as hasTailwindApplyDirective, x as resolveTailwindV4SourceFromPatcher, y as resolveTailwindV4Source$1, z as splitTailwindGeneratedCssByBanner } from "./v3-engine-Cczrkzqt.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DVWLNO0n.mjs";
|
|
3
|
+
import { p as replaceWxml, r as resolveStyleOptionsFromContext } from "./precheck-Bsn_LMmo.mjs";
|
|
4
|
+
import { r as isUniAppXEnabled } from "./tailwindcss-AWaPVF2B.mjs";
|
|
4
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
5
6
|
import postcss from "postcss";
|
|
6
7
|
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveValidTailwindV4Candidates } from "tailwindcss-patch";
|
|
@@ -435,7 +436,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
|
435
436
|
const css = readFileSync(cssEntry, "utf8");
|
|
436
437
|
const base = path.dirname(path.resolve(cssEntry));
|
|
437
438
|
const entrySource = resolveCssEntrySource(css, base, { removeConfig: false });
|
|
438
|
-
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry,
|
|
439
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
|
|
440
|
+
...sourceOptions,
|
|
441
|
+
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
442
|
+
});
|
|
439
443
|
return withGeneratorSourceMetadata(await resolveTailwindV4Source$1({
|
|
440
444
|
...omitUndefined(singleEntrySourceOptions),
|
|
441
445
|
base,
|
|
@@ -733,7 +737,7 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
733
737
|
}
|
|
734
738
|
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
735
739
|
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
736
|
-
return `@
|
|
740
|
+
return `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}`;
|
|
737
741
|
}
|
|
738
742
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
739
743
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -741,6 +745,10 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
741
745
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
742
746
|
removeConfig: majorVersion === 3
|
|
743
747
|
});
|
|
748
|
+
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
749
|
+
base,
|
|
750
|
+
css: rawSource
|
|
751
|
+
} : void 0;
|
|
744
752
|
if (majorVersion === 3) {
|
|
745
753
|
const sourceOptions = resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
746
754
|
const mergedSourceOptions = omitUndefined({
|
|
@@ -751,10 +759,6 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
751
759
|
cssEntries: selectionOptions?.cssEntries,
|
|
752
760
|
cssSources: createCssEntrySources(selectionOptions?.cssEntries)
|
|
753
761
|
});
|
|
754
|
-
const applyEntrySource = hasTailwindApplyDirective(rawSource) ? {
|
|
755
|
-
base,
|
|
756
|
-
css: rawSource
|
|
757
|
-
} : void 0;
|
|
758
762
|
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
759
763
|
const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
|
|
760
764
|
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
@@ -781,6 +785,13 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
781
785
|
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
782
786
|
}) : void 0;
|
|
783
787
|
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
788
|
+
if (applyEntrySource && !cssHandlerOptions.isMainChunk && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
789
|
+
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(applyEntrySource.css, generatorOptions?.config), void 0), normalizedSourceOptions ?? {});
|
|
790
|
+
return resolveTailwindV4Source$1(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
|
|
791
|
+
base: applyEntrySource.base,
|
|
792
|
+
css
|
|
793
|
+
}));
|
|
794
|
+
}
|
|
784
795
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
785
796
|
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
786
797
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
@@ -797,7 +808,7 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
797
808
|
...preferredCssEntrySource,
|
|
798
809
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
799
810
|
} : preferredCssEntrySource;
|
|
800
|
-
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
811
|
+
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource;
|
|
801
812
|
if (!resolvedEntrySource) {
|
|
802
813
|
const source = await resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
803
814
|
return generatorOptions?.config ? {
|
|
@@ -819,7 +830,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
819
830
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
820
831
|
removeConfig: majorVersion === 3
|
|
821
832
|
});
|
|
822
|
-
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) {
|
|
833
|
+
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(rawSource) && !hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
823
834
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
824
835
|
return resolved ? [resolved] : [];
|
|
825
836
|
}
|
|
@@ -1259,13 +1270,38 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
1259
1270
|
preservePseudoContentInit: majorVersion === 3
|
|
1260
1271
|
});
|
|
1261
1272
|
}
|
|
1273
|
+
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
1274
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
1275
|
+
if (!options.isolateCurrentCssCandidates) return true;
|
|
1276
|
+
return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
1277
|
+
}
|
|
1262
1278
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1263
1279
|
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
1264
1280
|
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
1265
1281
|
return new Set([...scopedRuntime, ...runtime]);
|
|
1266
1282
|
}
|
|
1267
1283
|
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
1268
|
-
return
|
|
1284
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
1285
|
+
}
|
|
1286
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
1287
|
+
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
1288
|
+
}
|
|
1289
|
+
function removeTailwindApplyAtRules(source) {
|
|
1290
|
+
if (!source.includes("@apply")) return source;
|
|
1291
|
+
try {
|
|
1292
|
+
const root = postcss.parse(source);
|
|
1293
|
+
let changed = false;
|
|
1294
|
+
root.walkAtRules("apply", (rule) => {
|
|
1295
|
+
rule.remove();
|
|
1296
|
+
changed = true;
|
|
1297
|
+
});
|
|
1298
|
+
root.walk((node) => {
|
|
1299
|
+
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1300
|
+
});
|
|
1301
|
+
return changed ? root.toString() : source;
|
|
1302
|
+
} catch {
|
|
1303
|
+
return source;
|
|
1304
|
+
}
|
|
1269
1305
|
}
|
|
1270
1306
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
1271
1307
|
if (majorVersion !== 4 || isolateCssSource) return false;
|
|
@@ -1293,7 +1329,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
|
|
|
1293
1329
|
};
|
|
1294
1330
|
}
|
|
1295
1331
|
function isLocalImportRequest(request) {
|
|
1296
|
-
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1332
|
+
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1297
1333
|
}
|
|
1298
1334
|
function isCommentOnlyCss(source) {
|
|
1299
1335
|
try {
|
|
@@ -1411,11 +1447,70 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
|
1411
1447
|
};
|
|
1412
1448
|
}
|
|
1413
1449
|
}
|
|
1450
|
+
function normalizeGeneratedSelector(selector) {
|
|
1451
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1452
|
+
}
|
|
1453
|
+
function collectApplyOnlySourceSelectors(source) {
|
|
1454
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1455
|
+
try {
|
|
1456
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1457
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1458
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1459
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1460
|
+
if (normalized) selectors.add(normalized);
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
} catch {}
|
|
1464
|
+
return selectors;
|
|
1465
|
+
}
|
|
1466
|
+
function hasOnlyApplyBackedSourceRules(source) {
|
|
1467
|
+
let hasApplyRule = false;
|
|
1468
|
+
let hasNonApplyRule = false;
|
|
1469
|
+
try {
|
|
1470
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1471
|
+
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1472
|
+
else hasNonApplyRule = true;
|
|
1473
|
+
});
|
|
1474
|
+
} catch {
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
return hasApplyRule && !hasNonApplyRule;
|
|
1478
|
+
}
|
|
1479
|
+
function filterApplyOnlyGeneratedCss(css, source) {
|
|
1480
|
+
const selectors = collectApplyOnlySourceSelectors(source);
|
|
1481
|
+
if (selectors.size === 0) return css;
|
|
1482
|
+
const selectorList = [...selectors];
|
|
1483
|
+
try {
|
|
1484
|
+
const root = postcss.parse(css);
|
|
1485
|
+
root.walkRules((rule) => {
|
|
1486
|
+
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
1487
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1488
|
+
return selectorList.some((sourceSelector) => {
|
|
1489
|
+
if (normalized === sourceSelector) return true;
|
|
1490
|
+
if (!normalized.startsWith(sourceSelector)) return false;
|
|
1491
|
+
const next = normalized[sourceSelector.length];
|
|
1492
|
+
return next === ":" || next === "[" || next === ".";
|
|
1493
|
+
});
|
|
1494
|
+
});
|
|
1495
|
+
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1496
|
+
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1497
|
+
});
|
|
1498
|
+
root.walkAtRules((rule) => {
|
|
1499
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1500
|
+
});
|
|
1501
|
+
return root.toString();
|
|
1502
|
+
} catch {
|
|
1503
|
+
return css;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
|
|
1507
|
+
return majorVersion === 4 && target === "weapp" && hasTailwindApplyDirective(source) && !hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
1508
|
+
}
|
|
1414
1509
|
async function transformGeneratorUserCss(source, options) {
|
|
1415
1510
|
if (source.trim().length === 0) return "";
|
|
1416
1511
|
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
1417
1512
|
if (cleanedSource.trim().length === 0) return "";
|
|
1418
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
|
|
1513
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1419
1514
|
if (userSource.trim().length === 0) return "";
|
|
1420
1515
|
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1421
1516
|
if (options.generatorTarget !== "weapp") return userSource;
|
|
@@ -1477,6 +1572,32 @@ function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
|
1477
1572
|
return css;
|
|
1478
1573
|
}
|
|
1479
1574
|
}
|
|
1575
|
+
function splitLocalCssImports(source) {
|
|
1576
|
+
try {
|
|
1577
|
+
const root = postcss.parse(source);
|
|
1578
|
+
const importRoot = postcss.root();
|
|
1579
|
+
let changed = false;
|
|
1580
|
+
for (const node of [...root.nodes]) {
|
|
1581
|
+
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
1582
|
+
const request = parseImportRequest(node.params);
|
|
1583
|
+
if (!request || !isLocalImportRequest(request)) continue;
|
|
1584
|
+
importRoot.append(node.clone());
|
|
1585
|
+
node.remove();
|
|
1586
|
+
changed = true;
|
|
1587
|
+
}
|
|
1588
|
+
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
1589
|
+
return changed ? {
|
|
1590
|
+
imports,
|
|
1591
|
+
source: root.toString()
|
|
1592
|
+
} : void 0;
|
|
1593
|
+
} catch {
|
|
1594
|
+
return;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
function restoreLocalCssImports(css, imports) {
|
|
1598
|
+
if (!imports?.trim()) return css;
|
|
1599
|
+
return createCssSourceOrderAppend(imports, css);
|
|
1600
|
+
}
|
|
1480
1601
|
async function generateCssByGenerator(options) {
|
|
1481
1602
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1482
1603
|
const generatorOptions = {
|
|
@@ -1485,6 +1606,8 @@ async function generateCssByGenerator(options) {
|
|
|
1485
1606
|
};
|
|
1486
1607
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1487
1608
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1609
|
+
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
1610
|
+
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
1488
1611
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1489
1612
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1490
1613
|
css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
@@ -1493,16 +1616,21 @@ async function generateCssByGenerator(options) {
|
|
|
1493
1616
|
dependencies: []
|
|
1494
1617
|
};
|
|
1495
1618
|
if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
|
|
1496
|
-
const hasGeneratedCss = hasTailwindGeneratedCss(
|
|
1497
|
-
const hasSourceDirectives = hasTailwindSourceDirectives(
|
|
1498
|
-
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(
|
|
1619
|
+
const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
|
|
1620
|
+
const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
1621
|
+
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1499
1622
|
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1500
1623
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1501
1624
|
try {
|
|
1502
1625
|
await runtimeState.readyPromise;
|
|
1503
|
-
const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(
|
|
1504
|
-
const
|
|
1505
|
-
|
|
1626
|
+
const currentCssCandidates = majorVersion === 4 ? await extractSourceCandidates(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
1627
|
+
const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
|
|
1628
|
+
hasGeneratedCss,
|
|
1629
|
+
hasGeneratedMarkers,
|
|
1630
|
+
rawSource: generatorRawSource
|
|
1631
|
+
});
|
|
1632
|
+
const runtimeWithCurrentCss = isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
1633
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1506
1634
|
cssEntries: opts.cssEntries,
|
|
1507
1635
|
getSourceCandidatesForEntries,
|
|
1508
1636
|
runtime: runtimeWithCurrentCss
|
|
@@ -1519,17 +1647,18 @@ async function generateCssByGenerator(options) {
|
|
|
1519
1647
|
debug("defer empty scoped css source generation: %s", file);
|
|
1520
1648
|
return;
|
|
1521
1649
|
}
|
|
1522
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1650
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1523
1651
|
currentCssCandidates,
|
|
1524
1652
|
cssHandlerOptions,
|
|
1525
1653
|
isolateCssSource,
|
|
1526
1654
|
matchedCssSourceFile
|
|
1527
1655
|
}) : runtimeWithCurrentCss;
|
|
1528
1656
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1657
|
+
const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
|
|
1529
1658
|
return generator.generate({
|
|
1530
1659
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1531
1660
|
candidates: generatorRuntime,
|
|
1532
|
-
incrementalCache:
|
|
1661
|
+
incrementalCache: useIncrementalCache,
|
|
1533
1662
|
scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
1534
1663
|
styleOptions: generatorStyleOptions,
|
|
1535
1664
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
@@ -1551,22 +1680,27 @@ async function generateCssByGenerator(options) {
|
|
|
1551
1680
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
1552
1681
|
};
|
|
1553
1682
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1554
|
-
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(
|
|
1683
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1555
1684
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1556
1685
|
return {
|
|
1557
|
-
css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
1686
|
+
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss, localImportParts?.imports),
|
|
1558
1687
|
target: generated.target,
|
|
1559
1688
|
source: "generator",
|
|
1560
1689
|
dependencies: generated.dependencies,
|
|
1561
1690
|
incremental: true
|
|
1562
1691
|
};
|
|
1563
1692
|
}
|
|
1693
|
+
const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
|
|
1694
|
+
hasGeneratedCss,
|
|
1695
|
+
hasGeneratedMarkers
|
|
1696
|
+
});
|
|
1697
|
+
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(stripTailwindBanner(generated.css), generatorRawSource) : stripTailwindBanner(generated.css);
|
|
1564
1698
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1565
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(
|
|
1699
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(generatorRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(generatorRawSource, generated.rawCss);
|
|
1566
1700
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1567
1701
|
if (orderedExtraCss) {
|
|
1568
|
-
let css =
|
|
1569
|
-
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1702
|
+
let css = generatedCss;
|
|
1703
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1570
1704
|
const userCssOptions = {
|
|
1571
1705
|
generatorTarget: generated.target,
|
|
1572
1706
|
generatorStyleOptions,
|
|
@@ -1586,27 +1720,33 @@ async function generateCssByGenerator(options) {
|
|
|
1586
1720
|
hasSourceDirectives,
|
|
1587
1721
|
hasMatchedCssSourceFile
|
|
1588
1722
|
})) {
|
|
1589
|
-
const userCss = await transformGeneratorUserCss(
|
|
1723
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, userCssOptions);
|
|
1590
1724
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1591
1725
|
}
|
|
1592
1726
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
1593
1727
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1594
|
-
|
|
1595
|
-
|
|
1728
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1729
|
+
css = await appendLegacyCompatCss(css, generatorRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1730
|
+
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1731
|
+
}
|
|
1596
1732
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1597
1733
|
return {
|
|
1598
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1734
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1735
|
+
cssHandlerOptions,
|
|
1736
|
+
isolateCurrentCssCandidates,
|
|
1737
|
+
localImports: localImportParts?.imports
|
|
1738
|
+
}) }), localImportParts?.imports),
|
|
1599
1739
|
target: generated.target,
|
|
1600
1740
|
source: "generator",
|
|
1601
1741
|
dependencies: generated.dependencies
|
|
1602
1742
|
};
|
|
1603
1743
|
}
|
|
1604
1744
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1605
|
-
let css =
|
|
1745
|
+
let css = generatedCss;
|
|
1606
1746
|
if (generated.target === "weapp") {
|
|
1607
|
-
css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1608
|
-
if (hasUserCssLayerBlocks(
|
|
1609
|
-
const layerParts = splitUserCssLayerBlocks(
|
|
1747
|
+
css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1748
|
+
if (hasUserCssLayerBlocks(generatorRawSource)) {
|
|
1749
|
+
const layerParts = splitUserCssLayerBlocks(generatorRawSource);
|
|
1610
1750
|
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
1611
1751
|
generatorTarget: generated.target,
|
|
1612
1752
|
generatorStyleOptions,
|
|
@@ -1626,7 +1766,7 @@ async function generateCssByGenerator(options) {
|
|
|
1626
1766
|
}
|
|
1627
1767
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1628
1768
|
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
1629
|
-
const userCss = await transformGeneratorUserCss(
|
|
1769
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, {
|
|
1630
1770
|
generatorTarget: generated.target,
|
|
1631
1771
|
generatorStyleOptions,
|
|
1632
1772
|
cssUserHandlerOptions,
|
|
@@ -1635,12 +1775,14 @@ async function generateCssByGenerator(options) {
|
|
|
1635
1775
|
});
|
|
1636
1776
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1637
1777
|
}
|
|
1638
|
-
if (hasMatchedCssSourceFile && generated.target === "weapp")
|
|
1778
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
1779
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1780
|
+
}
|
|
1639
1781
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1640
1782
|
hasSourceDirectives,
|
|
1641
1783
|
hasMatchedCssSourceFile
|
|
1642
1784
|
})) {
|
|
1643
|
-
const userCss = await transformGeneratorUserCss(
|
|
1785
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, {
|
|
1644
1786
|
generatorTarget: generated.target,
|
|
1645
1787
|
generatorStyleOptions,
|
|
1646
1788
|
cssUserHandlerOptions,
|
|
@@ -1650,16 +1792,26 @@ async function generateCssByGenerator(options) {
|
|
|
1650
1792
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1651
1793
|
}
|
|
1652
1794
|
return {
|
|
1653
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1795
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1796
|
+
cssHandlerOptions,
|
|
1797
|
+
isolateCurrentCssCandidates,
|
|
1798
|
+
localImports: localImportParts?.imports
|
|
1799
|
+
}) }), localImportParts?.imports),
|
|
1654
1800
|
target: generated.target,
|
|
1655
1801
|
source: "generator",
|
|
1656
1802
|
dependencies: generated.dependencies
|
|
1657
1803
|
};
|
|
1658
1804
|
}
|
|
1659
|
-
|
|
1660
|
-
|
|
1805
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1806
|
+
css = await appendLegacyCompatCss(css, generatorRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1807
|
+
css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1808
|
+
}
|
|
1661
1809
|
return {
|
|
1662
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1810
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1811
|
+
cssHandlerOptions,
|
|
1812
|
+
isolateCurrentCssCandidates,
|
|
1813
|
+
localImports: localImportParts?.imports
|
|
1814
|
+
}) }), localImportParts?.imports),
|
|
1663
1815
|
target: generated.target,
|
|
1664
1816
|
source: "generator",
|
|
1665
1817
|
dependencies: generated.dependencies
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generator = require("./generator-
|
|
2
|
+
const require_generator = require("./generator-AD-eX8Tr.js");
|
|
3
3
|
const require_gulp = require("./gulp.js");
|
|
4
|
-
const require_postcss = require("./postcss-
|
|
5
|
-
const require_vite = require("./vite-
|
|
6
|
-
const require_webpack = require("./webpack-
|
|
4
|
+
const require_postcss = require("./postcss-Cbi6RFpf.js");
|
|
5
|
+
const require_vite = require("./vite-CTuHPC91.js");
|
|
6
|
+
const require_webpack = require("./webpack-BBHJYKqB.js");
|
|
7
7
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
8
8
|
exports.WeappTailwindcss = require_vite.WeappTailwindcss;
|
|
9
9
|
exports.createPlugins = require_gulp.createPlugins;
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as createWeappTailwindcssGenerator } from "./generator-
|
|
1
|
+
import { t as createWeappTailwindcssGenerator } from "./generator-DVWLNO0n.mjs";
|
|
2
2
|
import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
|
|
3
|
-
import { t as weappTailwindcssPostcssPlugin } from "./postcss-
|
|
4
|
-
import { t as WeappTailwindcss } from "./vite-
|
|
5
|
-
import { n as weappTailwindcssPackageDir } from "./webpack-
|
|
3
|
+
import { t as weappTailwindcssPostcssPlugin } from "./postcss-hSUxK7oR.mjs";
|
|
4
|
+
import { t as WeappTailwindcss } from "./vite-DLXDMHON.mjs";
|
|
5
|
+
import { n as weappTailwindcssPackageDir } from "./webpack-DJFw08SK.mjs";
|
|
6
6
|
import { unitConversionComposeRules, unitConversionPresets } from "@weapp-tailwindcss/postcss";
|
|
7
7
|
export { WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, unitConversionComposeRules, unitConversionPresets, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-
|
|
2
|
-
const require_v3_engine = require("./v3-engine-
|
|
3
|
-
const require_generator = require("./generator-
|
|
4
|
-
let postcss = require("postcss");
|
|
5
|
-
postcss = require_chunk.__toESM(postcss);
|
|
1
|
+
const require_chunk = require("./chunk-emK7D4bc.js");
|
|
2
|
+
const require_v3_engine = require("./v3-engine-CM0TRa8V.js");
|
|
3
|
+
const require_generator = require("./generator-AD-eX8Tr.js");
|
|
4
|
+
let postcss$1 = require("postcss");
|
|
5
|
+
postcss$1 = require_chunk.__toESM(postcss$1);
|
|
6
6
|
let tailwindcss_patch = require("tailwindcss-patch");
|
|
7
7
|
let node_process = require("node:process");
|
|
8
8
|
node_process = require_chunk.__toESM(node_process);
|
|
@@ -42,7 +42,7 @@ function resolvePostcssProjectRoot(result, options) {
|
|
|
42
42
|
function replaceRootCss(root, css, result) {
|
|
43
43
|
root.removeAll();
|
|
44
44
|
try {
|
|
45
|
-
const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
|
|
45
|
+
const nextRoot = postcss$1.default.parse(css, { from: resolveInputFile(result) });
|
|
46
46
|
root.append(nextRoot.nodes);
|
|
47
47
|
} catch {
|
|
48
48
|
root.raws = { after: css };
|
|
@@ -65,6 +65,9 @@ function addSourceDependencyMessages(result, files) {
|
|
|
65
65
|
//#endregion
|
|
66
66
|
//#region src/postcss/source-files.ts
|
|
67
67
|
const POSTCSS_SOURCE_PATTERN = require_v3_engine.createSourceScanPattern(require_v3_engine.DEFAULT_SOURCE_SCAN_EXTENSIONS);
|
|
68
|
+
function isTailwindV4ApplyOnlyCss$1(root, options) {
|
|
69
|
+
return options.version === 4 && require_v3_engine.hasTailwindApplyDirective(root.toString()) && !require_v3_engine.hasTailwindRootDirectives(root.toString(), { importFallback: true });
|
|
70
|
+
}
|
|
68
71
|
function getSourceExtension(file) {
|
|
69
72
|
return node_path.default.extname(file).slice(1) || void 0;
|
|
70
73
|
}
|
|
@@ -122,10 +125,11 @@ async function collectAutoTailwindCandidates(root, result, options) {
|
|
|
122
125
|
const projectRoot = resolvePostcssProjectRoot(result, options);
|
|
123
126
|
const sourceEntries = [];
|
|
124
127
|
const hasSourceNone = root.toString().includes("source(none)");
|
|
128
|
+
const shouldSkipAutoScan = isTailwindV4ApplyOnlyCss$1(root, options);
|
|
125
129
|
const inlineCandidates = require_v3_engine.collectCssInlineSourceCandidates(root);
|
|
126
130
|
const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
|
|
127
131
|
if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
|
|
128
|
-
else if (!hasSourceNone) sourceEntries.push({
|
|
132
|
+
else if (!hasSourceNone && !shouldSkipAutoScan) sourceEntries.push({
|
|
129
133
|
base,
|
|
130
134
|
negated: false,
|
|
131
135
|
pattern: POSTCSS_SOURCE_PATTERN
|
|
@@ -179,6 +183,47 @@ function resolvePostcssTailwindVersion(root, result, options) {
|
|
|
179
183
|
//#endregion
|
|
180
184
|
//#region src/postcss.ts
|
|
181
185
|
const PLUGIN_NAME = "weapp-tailwindcss";
|
|
186
|
+
function isTailwindV4ApplyOnlyCss(css) {
|
|
187
|
+
return require_v3_engine.hasTailwindApplyDirective(css) && !require_v3_engine.hasTailwindRootDirectives(css, { importFallback: true });
|
|
188
|
+
}
|
|
189
|
+
function resolveTailwindV4PostcssSourceCss(css, sourceOptions) {
|
|
190
|
+
return isTailwindV4ApplyOnlyCss(css) ? `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}` : css;
|
|
191
|
+
}
|
|
192
|
+
function normalizeSelector(selector) {
|
|
193
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
194
|
+
}
|
|
195
|
+
function collectApplyOnlyCssSelectors(css) {
|
|
196
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
197
|
+
try {
|
|
198
|
+
postcss.parse(css).walkRules((rule) => {
|
|
199
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
200
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
201
|
+
const normalized = normalizeSelector(selector);
|
|
202
|
+
if (normalized) selectors.add(normalized);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
} catch {}
|
|
206
|
+
return selectors;
|
|
207
|
+
}
|
|
208
|
+
function ruleMatchesApplyOnlySelector(rule, selectors) {
|
|
209
|
+
return (rule.selectors ?? [rule.selector]).some((selector) => selectors.has(normalizeSelector(selector)));
|
|
210
|
+
}
|
|
211
|
+
function filterApplyOnlyGeneratedCss(css, rawCss) {
|
|
212
|
+
const selectors = collectApplyOnlyCssSelectors(rawCss);
|
|
213
|
+
if (selectors.size === 0) return css;
|
|
214
|
+
try {
|
|
215
|
+
const root = postcss.parse(css);
|
|
216
|
+
root.walkRules((rule) => {
|
|
217
|
+
if (!ruleMatchesApplyOnlySelector(rule, selectors) && !rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"))) rule.remove();
|
|
218
|
+
});
|
|
219
|
+
root.walkAtRules((rule) => {
|
|
220
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
221
|
+
});
|
|
222
|
+
return root.toString();
|
|
223
|
+
} catch {
|
|
224
|
+
return css;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
182
227
|
const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
183
228
|
return {
|
|
184
229
|
postcssPlugin: PLUGIN_NAME,
|
|
@@ -188,9 +233,11 @@ const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
|
188
233
|
const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
|
|
189
234
|
const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
|
|
190
235
|
const generatorConfig = generatorOptions.config ?? options.config;
|
|
236
|
+
const rawCss = sourceOptions.css ?? root.toString();
|
|
237
|
+
const isApplyOnlyTailwindV4Css = tailwindVersion === 4 && isTailwindV4ApplyOnlyCss(rawCss);
|
|
191
238
|
const generator = require_generator.createWeappTailwindcssGenerator(tailwindVersion === 3 ? await require_v3_engine.resolveTailwindV3Source({
|
|
192
239
|
config: generatorConfig,
|
|
193
|
-
css:
|
|
240
|
+
css: rawCss,
|
|
194
241
|
base: resolvePostcssBase(result, options),
|
|
195
242
|
cwd: resolvePostcssProjectRoot(result, options),
|
|
196
243
|
projectRoot: resolvePostcssProjectRoot(result, options),
|
|
@@ -198,7 +245,7 @@ const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
|
198
245
|
postcssPlugin: options.postcssPlugin
|
|
199
246
|
}) : await require_v3_engine.resolveTailwindV4Source({
|
|
200
247
|
...sourceOptions,
|
|
201
|
-
css: prependConfigDirective(sourceOptions
|
|
248
|
+
css: prependConfigDirective(resolveTailwindV4PostcssSourceCss(rawCss, sourceOptions), generatorConfig),
|
|
202
249
|
base: resolvePostcssBase(result, options),
|
|
203
250
|
projectRoot: resolvePostcssProjectRoot(result, options)
|
|
204
251
|
}));
|
|
@@ -214,7 +261,7 @@ const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
|
214
261
|
target: generatorOptions.target
|
|
215
262
|
};
|
|
216
263
|
const generated = await generator.generate(generateOptions);
|
|
217
|
-
replaceRootCss(root, generated.css, result);
|
|
264
|
+
replaceRootCss(root, isApplyOnlyTailwindV4Css ? filterApplyOnlyGeneratedCss(generated.css, rawCss) : generated.css, result);
|
|
218
265
|
addDependencyMessages(result, generated);
|
|
219
266
|
addSourceDependencyMessages(result, collectedSources.files);
|
|
220
267
|
result.messages.push({
|