weapp-tailwindcss 5.0.4 → 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/dist/{auto-BZ4n4Icc.js → auto-Cvy0zWpS.js} +1 -1
- package/dist/{bundle-state-D3RZHkXz.js → bundle-state-Cso_ceUo.js} +8 -2
- package/dist/{bundle-state-C-p9eFz1.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-D6vf50IK.js → chunk-emK7D4bc.js} +7 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/{defaults-C5w9OOrj.js → defaults-BPUuNYcD.js} +1 -1
- package/dist/defaults.js +1 -1
- package/dist/{generator-DaPOkJ7W.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-BYV0yQdp.js → incremental-runtime-class-set-vOetpdWs.js} +195 -43
- package/dist/{incremental-runtime-class-set-Dt-FUQB5.mjs → incremental-runtime-class-set-xf49kky6.mjs} +194 -42
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-Du8hY-MN.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-lfenbOTF.mjs → precheck-Bsn_LMmo.mjs} +14 -3
- package/dist/{precheck-DgpVCvYk.js → precheck-b8Y8qZg0.js} +17 -6
- 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-B4NvId_j.js → source-candidates-o2ZrKWzu.js} +2 -2
- package/dist/{tailwindcss-D5RogwtV.mjs → tailwindcss-AWaPVF2B.mjs} +1 -1
- package/dist/{tailwindcss-26ZFr5kv.js → tailwindcss-CpQ6X4l6.js} +3 -3
- package/dist/transform-BkGtbxb1.js +14868 -0
- package/dist/transform-DumSZmTh.mjs +14871 -0
- package/dist/uni-app-x/vite.d.ts +3 -0
- package/dist/{utils-nta4tfFs.js → utils-Dolmt8EO.js} +1 -1
- package/dist/{v3-engine-CBahpuIg.js → v3-engine-CM0TRa8V.js} +29 -5
- package/dist/{v3-engine-BCUGX3gX.mjs → v3-engine-Cczrkzqt.mjs} +22 -4
- package/dist/{vite-tjYalmVX.js → vite-CTuHPC91.js} +733 -79
- package/dist/{vite-DS4H5d0f.mjs → vite-DLXDMHON.mjs} +745 -91
- 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-0BwLOE_f.js → webpack-BBHJYKqB.js} +8 -8
- package/dist/{webpack-CA-40WU9.mjs → webpack-DJFw08SK.mjs} +6 -6
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +2 -3
- package/dist/transform-Crn84vTL.js +0 -257
- package/dist/transform-FAxHXVZp.mjs +0 -255
package/dist/{incremental-runtime-class-set-BYV0yQdp.js → incremental-runtime-class-set-vOetpdWs.js}
RENAMED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-
|
|
2
|
-
const require_v3_engine = require("./v3-engine-
|
|
3
|
-
const require_generator = require("./generator-
|
|
4
|
-
const require_precheck = require("./precheck-
|
|
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
|
+
const require_precheck = require("./precheck-b8Y8qZg0.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-CpQ6X4l6.js");
|
|
5
6
|
let node_fs = require("node:fs");
|
|
6
7
|
let postcss = require("postcss");
|
|
7
8
|
postcss = require_chunk.__toESM(postcss);
|
|
@@ -439,7 +440,10 @@ async function resolveTailwindV4CssEntrySource(cssEntry, sourceOptions) {
|
|
|
439
440
|
const css = (0, node_fs.readFileSync)(cssEntry, "utf8");
|
|
440
441
|
const base = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
441
442
|
const entrySource = require_v3_engine.resolveCssEntrySource(css, base, { removeConfig: false });
|
|
442
|
-
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry,
|
|
443
|
+
const config = resolveExistingConfigPath(entrySource?.config, entrySource?.configRequest, cssEntry, {
|
|
444
|
+
...sourceOptions,
|
|
445
|
+
sourceFile: sourceOptions.sourceFile ?? cssEntry
|
|
446
|
+
});
|
|
443
447
|
return withGeneratorSourceMetadata(await require_v3_engine.resolveTailwindV4Source({
|
|
444
448
|
...require_v3_engine.omitUndefined(singleEntrySourceOptions),
|
|
445
449
|
base,
|
|
@@ -737,7 +741,7 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
737
741
|
}
|
|
738
742
|
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
739
743
|
if (!require_v3_engine.hasTailwindApplyDirective(css) || require_v3_engine.hasTailwindRootDirectives(css)) return css;
|
|
740
|
-
return `@
|
|
744
|
+
return `@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);\n${css}`;
|
|
741
745
|
}
|
|
742
746
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
743
747
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -745,6 +749,10 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
745
749
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
746
750
|
removeConfig: majorVersion === 3
|
|
747
751
|
});
|
|
752
|
+
const applyEntrySource = require_v3_engine.hasTailwindApplyDirective(rawSource) ? {
|
|
753
|
+
base,
|
|
754
|
+
css: rawSource
|
|
755
|
+
} : void 0;
|
|
748
756
|
if (majorVersion === 3) {
|
|
749
757
|
const sourceOptions = require_v3_engine.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
750
758
|
const mergedSourceOptions = require_v3_engine.omitUndefined({
|
|
@@ -755,10 +763,6 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
755
763
|
cssEntries: selectionOptions?.cssEntries,
|
|
756
764
|
cssSources: createCssEntrySources(selectionOptions?.cssEntries)
|
|
757
765
|
});
|
|
758
|
-
const applyEntrySource = require_v3_engine.hasTailwindApplyDirective(rawSource) ? {
|
|
759
|
-
base,
|
|
760
|
-
css: rawSource
|
|
761
|
-
} : void 0;
|
|
762
766
|
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions, mergedSourceOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
763
767
|
const shouldPreferSourceSideEntry = shouldPreferResolvedSourceSideEntry(cssEntrySource, sourceSideEntrySource);
|
|
764
768
|
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) || shouldPreferSourceSideEntry ? sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
@@ -785,6 +789,13 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
785
789
|
cssSources: mergeCssSources(sourceOptions.cssSources, sourceOptions.cssSources?.length ? void 0 : createCssEntrySources(selectionOptions?.cssEntries ?? sourceOptions.cssEntries))
|
|
786
790
|
}) : void 0;
|
|
787
791
|
const normalizedSourceOptions = resolvedSourceOptions ? normalizeTailwindV4CssSourceConfigs(resolvedSourceOptions) : void 0;
|
|
792
|
+
if (applyEntrySource && !cssHandlerOptions.isMainChunk && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
793
|
+
const css = createTailwindV4ApplyReferenceSource(require_v3_engine.normalizeConfigDirective(require_v3_engine.prependConfigDirective(applyEntrySource.css, generatorOptions?.config), void 0), normalizedSourceOptions ?? {});
|
|
794
|
+
return require_v3_engine.resolveTailwindV4Source(createSingleTailwindV4SourceOptions(normalizedSourceOptions ?? {}, {
|
|
795
|
+
base: applyEntrySource.base,
|
|
796
|
+
css
|
|
797
|
+
}));
|
|
798
|
+
}
|
|
788
799
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions?.cssEntries?.length ?? 0) <= 1;
|
|
789
800
|
const sourceSideEntrySource = normalizedSourceOptions && shouldPreferSourceSideEntry && canResolveSourceSideCssEntry(file, cssHandlerOptions, normalizedSourceOptions) ? resolveSourceSideCssEntrySource(file, normalizedSourceOptions, { removeConfig: false }) : void 0;
|
|
790
801
|
const matchedCssEntrySource = normalizedSourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, normalizedSourceOptions) : void 0;
|
|
@@ -801,7 +812,7 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
801
812
|
...preferredCssEntrySource,
|
|
802
813
|
css: require_v3_engine.prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
803
814
|
} : preferredCssEntrySource;
|
|
804
|
-
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
815
|
+
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource ?? applyEntrySource;
|
|
805
816
|
if (!resolvedEntrySource) {
|
|
806
817
|
const source = await require_v3_engine.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
807
818
|
return generatorOptions?.config ? {
|
|
@@ -823,7 +834,7 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
823
834
|
importFallback: generatorOptions?.importFallback ?? false,
|
|
824
835
|
removeConfig: majorVersion === 3
|
|
825
836
|
});
|
|
826
|
-
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) {
|
|
837
|
+
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk || !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(rawSource) && !require_v3_engine.hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions?.importFallback ?? false })) {
|
|
827
838
|
const resolved = await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions);
|
|
828
839
|
return resolved ? [resolved] : [];
|
|
829
840
|
}
|
|
@@ -1263,13 +1274,38 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
1263
1274
|
preservePseudoContentInit: majorVersion === 3
|
|
1264
1275
|
});
|
|
1265
1276
|
}
|
|
1277
|
+
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
1278
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
1279
|
+
if (!options.isolateCurrentCssCandidates) return true;
|
|
1280
|
+
return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
1281
|
+
}
|
|
1266
1282
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1267
1283
|
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
1268
1284
|
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
1269
1285
|
return new Set([...scopedRuntime, ...runtime]);
|
|
1270
1286
|
}
|
|
1271
1287
|
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
1272
|
-
return
|
|
1288
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
1289
|
+
}
|
|
1290
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
1291
|
+
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(options.rawSource) && !require_v3_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
1292
|
+
}
|
|
1293
|
+
function removeTailwindApplyAtRules(source) {
|
|
1294
|
+
if (!source.includes("@apply")) return source;
|
|
1295
|
+
try {
|
|
1296
|
+
const root = postcss.default.parse(source);
|
|
1297
|
+
let changed = false;
|
|
1298
|
+
root.walkAtRules("apply", (rule) => {
|
|
1299
|
+
rule.remove();
|
|
1300
|
+
changed = true;
|
|
1301
|
+
});
|
|
1302
|
+
root.walk((node) => {
|
|
1303
|
+
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1304
|
+
});
|
|
1305
|
+
return changed ? root.toString() : source;
|
|
1306
|
+
} catch {
|
|
1307
|
+
return source;
|
|
1308
|
+
}
|
|
1273
1309
|
}
|
|
1274
1310
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
1275
1311
|
if (majorVersion !== 4 || isolateCssSource) return false;
|
|
@@ -1297,7 +1333,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
|
|
|
1297
1333
|
};
|
|
1298
1334
|
}
|
|
1299
1335
|
function isLocalImportRequest(request) {
|
|
1300
|
-
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1336
|
+
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1301
1337
|
}
|
|
1302
1338
|
function isCommentOnlyCss(source) {
|
|
1303
1339
|
try {
|
|
@@ -1415,11 +1451,70 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
|
1415
1451
|
};
|
|
1416
1452
|
}
|
|
1417
1453
|
}
|
|
1454
|
+
function normalizeGeneratedSelector(selector) {
|
|
1455
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1456
|
+
}
|
|
1457
|
+
function collectApplyOnlySourceSelectors(source) {
|
|
1458
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1459
|
+
try {
|
|
1460
|
+
postcss.default.parse(source).walkRules((rule) => {
|
|
1461
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1462
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1463
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1464
|
+
if (normalized) selectors.add(normalized);
|
|
1465
|
+
}
|
|
1466
|
+
});
|
|
1467
|
+
} catch {}
|
|
1468
|
+
return selectors;
|
|
1469
|
+
}
|
|
1470
|
+
function hasOnlyApplyBackedSourceRules(source) {
|
|
1471
|
+
let hasApplyRule = false;
|
|
1472
|
+
let hasNonApplyRule = false;
|
|
1473
|
+
try {
|
|
1474
|
+
postcss.default.parse(source).walkRules((rule) => {
|
|
1475
|
+
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1476
|
+
else hasNonApplyRule = true;
|
|
1477
|
+
});
|
|
1478
|
+
} catch {
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
return hasApplyRule && !hasNonApplyRule;
|
|
1482
|
+
}
|
|
1483
|
+
function filterApplyOnlyGeneratedCss(css, source) {
|
|
1484
|
+
const selectors = collectApplyOnlySourceSelectors(source);
|
|
1485
|
+
if (selectors.size === 0) return css;
|
|
1486
|
+
const selectorList = [...selectors];
|
|
1487
|
+
try {
|
|
1488
|
+
const root = postcss.default.parse(css);
|
|
1489
|
+
root.walkRules((rule) => {
|
|
1490
|
+
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
1491
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1492
|
+
return selectorList.some((sourceSelector) => {
|
|
1493
|
+
if (normalized === sourceSelector) return true;
|
|
1494
|
+
if (!normalized.startsWith(sourceSelector)) return false;
|
|
1495
|
+
const next = normalized[sourceSelector.length];
|
|
1496
|
+
return next === ":" || next === "[" || next === ".";
|
|
1497
|
+
});
|
|
1498
|
+
});
|
|
1499
|
+
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1500
|
+
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1501
|
+
});
|
|
1502
|
+
root.walkAtRules((rule) => {
|
|
1503
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1504
|
+
});
|
|
1505
|
+
return root.toString();
|
|
1506
|
+
} catch {
|
|
1507
|
+
return css;
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
|
|
1511
|
+
return majorVersion === 4 && target === "weapp" && require_v3_engine.hasTailwindApplyDirective(source) && !require_v3_engine.hasTailwindRootDirectives(source) && !options.hasGeneratedCss && !options.hasGeneratedMarkers && collectApplyOnlySourceSelectors(source).size > 0 && hasOnlyApplyBackedSourceRules(source);
|
|
1512
|
+
}
|
|
1418
1513
|
async function transformGeneratorUserCss(source, options) {
|
|
1419
1514
|
if (source.trim().length === 0) return "";
|
|
1420
1515
|
const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
1421
1516
|
if (cleanedSource.trim().length === 0) return "";
|
|
1422
|
-
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback }));
|
|
1517
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1423
1518
|
if (userSource.trim().length === 0) return "";
|
|
1424
1519
|
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1425
1520
|
if (options.generatorTarget !== "weapp") return userSource;
|
|
@@ -1481,6 +1576,32 @@ function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
|
1481
1576
|
return css;
|
|
1482
1577
|
}
|
|
1483
1578
|
}
|
|
1579
|
+
function splitLocalCssImports(source) {
|
|
1580
|
+
try {
|
|
1581
|
+
const root = postcss.default.parse(source);
|
|
1582
|
+
const importRoot = postcss.default.root();
|
|
1583
|
+
let changed = false;
|
|
1584
|
+
for (const node of [...root.nodes]) {
|
|
1585
|
+
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
1586
|
+
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1587
|
+
if (!request || !isLocalImportRequest(request)) continue;
|
|
1588
|
+
importRoot.append(node.clone());
|
|
1589
|
+
node.remove();
|
|
1590
|
+
changed = true;
|
|
1591
|
+
}
|
|
1592
|
+
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
1593
|
+
return changed ? {
|
|
1594
|
+
imports,
|
|
1595
|
+
source: root.toString()
|
|
1596
|
+
} : void 0;
|
|
1597
|
+
} catch {
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
function restoreLocalCssImports(css, imports) {
|
|
1602
|
+
if (!imports?.trim()) return css;
|
|
1603
|
+
return createCssSourceOrderAppend(imports, css);
|
|
1604
|
+
}
|
|
1484
1605
|
async function generateCssByGenerator(options) {
|
|
1485
1606
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1486
1607
|
const generatorOptions = {
|
|
@@ -1489,6 +1610,8 @@ async function generateCssByGenerator(options) {
|
|
|
1489
1610
|
};
|
|
1490
1611
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1491
1612
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1613
|
+
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
1614
|
+
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
1492
1615
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1493
1616
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1494
1617
|
css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
@@ -1497,16 +1620,21 @@ async function generateCssByGenerator(options) {
|
|
|
1497
1620
|
dependencies: []
|
|
1498
1621
|
};
|
|
1499
1622
|
if (isPureLocalCssImportWrapper(effectiveRawSource)) return;
|
|
1500
|
-
const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(
|
|
1501
|
-
const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(
|
|
1502
|
-
const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(
|
|
1623
|
+
const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(generatorRawSource);
|
|
1624
|
+
const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
1625
|
+
const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1503
1626
|
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1504
1627
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1505
1628
|
try {
|
|
1506
1629
|
await runtimeState.readyPromise;
|
|
1507
|
-
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1630
|
+
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
1631
|
+
const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
|
|
1632
|
+
hasGeneratedCss,
|
|
1633
|
+
hasGeneratedMarkers,
|
|
1634
|
+
rawSource: generatorRawSource
|
|
1635
|
+
});
|
|
1636
|
+
const runtimeWithCurrentCss = isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
1637
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1510
1638
|
cssEntries: opts.cssEntries,
|
|
1511
1639
|
getSourceCandidatesForEntries,
|
|
1512
1640
|
runtime: runtimeWithCurrentCss
|
|
@@ -1523,17 +1651,18 @@ async function generateCssByGenerator(options) {
|
|
|
1523
1651
|
debug("defer empty scoped css source generation: %s", file);
|
|
1524
1652
|
return;
|
|
1525
1653
|
}
|
|
1526
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1654
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1527
1655
|
currentCssCandidates,
|
|
1528
1656
|
cssHandlerOptions,
|
|
1529
1657
|
isolateCssSource,
|
|
1530
1658
|
matchedCssSourceFile
|
|
1531
1659
|
}) : runtimeWithCurrentCss;
|
|
1532
1660
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1661
|
+
const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
|
|
1533
1662
|
return generator.generate({
|
|
1534
1663
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1535
1664
|
candidates: generatorRuntime,
|
|
1536
|
-
incrementalCache:
|
|
1665
|
+
incrementalCache: useIncrementalCache,
|
|
1537
1666
|
scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
1538
1667
|
styleOptions: generatorStyleOptions,
|
|
1539
1668
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
@@ -1555,22 +1684,27 @@ async function generateCssByGenerator(options) {
|
|
|
1555
1684
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
1556
1685
|
};
|
|
1557
1686
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1558
|
-
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(
|
|
1687
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1559
1688
|
const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
|
|
1560
1689
|
return {
|
|
1561
|
-
css: incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
1690
|
+
css: restoreLocalCssImports(incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss, localImportParts?.imports),
|
|
1562
1691
|
target: generated.target,
|
|
1563
1692
|
source: "generator",
|
|
1564
1693
|
dependencies: generated.dependencies,
|
|
1565
1694
|
incremental: true
|
|
1566
1695
|
};
|
|
1567
1696
|
}
|
|
1697
|
+
const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
|
|
1698
|
+
hasGeneratedCss,
|
|
1699
|
+
hasGeneratedMarkers
|
|
1700
|
+
});
|
|
1701
|
+
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(require_v3_engine.stripTailwindBanner(generated.css), generatorRawSource) : require_v3_engine.stripTailwindBanner(generated.css);
|
|
1568
1702
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1569
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(
|
|
1703
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(generatorRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(generatorRawSource, generated.rawCss);
|
|
1570
1704
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1571
1705
|
if (orderedExtraCss) {
|
|
1572
|
-
let css =
|
|
1573
|
-
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1706
|
+
let css = generatedCss;
|
|
1707
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1574
1708
|
const userCssOptions = {
|
|
1575
1709
|
generatorTarget: generated.target,
|
|
1576
1710
|
generatorStyleOptions,
|
|
@@ -1590,27 +1724,33 @@ async function generateCssByGenerator(options) {
|
|
|
1590
1724
|
hasSourceDirectives,
|
|
1591
1725
|
hasMatchedCssSourceFile
|
|
1592
1726
|
})) {
|
|
1593
|
-
const userCss = await transformGeneratorUserCss(
|
|
1727
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, userCssOptions);
|
|
1594
1728
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1595
1729
|
}
|
|
1596
1730
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
1597
1731
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1598
|
-
|
|
1599
|
-
|
|
1732
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1733
|
+
css = await appendLegacyCompatCss(css, generatorRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1734
|
+
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1735
|
+
}
|
|
1600
1736
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1601
1737
|
return {
|
|
1602
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1738
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1739
|
+
cssHandlerOptions,
|
|
1740
|
+
isolateCurrentCssCandidates,
|
|
1741
|
+
localImports: localImportParts?.imports
|
|
1742
|
+
}) }), localImportParts?.imports),
|
|
1603
1743
|
target: generated.target,
|
|
1604
1744
|
source: "generator",
|
|
1605
1745
|
dependencies: generated.dependencies
|
|
1606
1746
|
};
|
|
1607
1747
|
}
|
|
1608
1748
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1609
|
-
let css =
|
|
1749
|
+
let css = generatedCss;
|
|
1610
1750
|
if (generated.target === "weapp") {
|
|
1611
|
-
css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1612
|
-
if (hasUserCssLayerBlocks(
|
|
1613
|
-
const layerParts = splitUserCssLayerBlocks(
|
|
1751
|
+
css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1752
|
+
if (hasUserCssLayerBlocks(generatorRawSource)) {
|
|
1753
|
+
const layerParts = splitUserCssLayerBlocks(generatorRawSource);
|
|
1614
1754
|
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
1615
1755
|
generatorTarget: generated.target,
|
|
1616
1756
|
generatorStyleOptions,
|
|
@@ -1630,7 +1770,7 @@ async function generateCssByGenerator(options) {
|
|
|
1630
1770
|
}
|
|
1631
1771
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1632
1772
|
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
1633
|
-
const userCss = await transformGeneratorUserCss(
|
|
1773
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, {
|
|
1634
1774
|
generatorTarget: generated.target,
|
|
1635
1775
|
generatorStyleOptions,
|
|
1636
1776
|
cssUserHandlerOptions,
|
|
@@ -1639,12 +1779,14 @@ async function generateCssByGenerator(options) {
|
|
|
1639
1779
|
});
|
|
1640
1780
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1641
1781
|
}
|
|
1642
|
-
if (hasMatchedCssSourceFile && generated.target === "weapp")
|
|
1782
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
1783
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1784
|
+
}
|
|
1643
1785
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1644
1786
|
hasSourceDirectives,
|
|
1645
1787
|
hasMatchedCssSourceFile
|
|
1646
1788
|
})) {
|
|
1647
|
-
const userCss = await transformGeneratorUserCss(
|
|
1789
|
+
const userCss = await transformGeneratorUserCss(generatorRawSource, {
|
|
1648
1790
|
generatorTarget: generated.target,
|
|
1649
1791
|
generatorStyleOptions,
|
|
1650
1792
|
cssUserHandlerOptions,
|
|
@@ -1654,16 +1796,26 @@ async function generateCssByGenerator(options) {
|
|
|
1654
1796
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1655
1797
|
}
|
|
1656
1798
|
return {
|
|
1657
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1799
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1800
|
+
cssHandlerOptions,
|
|
1801
|
+
isolateCurrentCssCandidates,
|
|
1802
|
+
localImports: localImportParts?.imports
|
|
1803
|
+
}) }), localImportParts?.imports),
|
|
1658
1804
|
target: generated.target,
|
|
1659
1805
|
source: "generator",
|
|
1660
1806
|
dependencies: generated.dependencies
|
|
1661
1807
|
};
|
|
1662
1808
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1809
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1810
|
+
css = await appendLegacyCompatCss(css, generatorRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1811
|
+
css = await appendLegacyContainerCompatCss(css, generatorRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1812
|
+
}
|
|
1665
1813
|
return {
|
|
1666
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1814
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1815
|
+
cssHandlerOptions,
|
|
1816
|
+
isolateCurrentCssCandidates,
|
|
1817
|
+
localImports: localImportParts?.imports
|
|
1818
|
+
}) }), localImportParts?.imports),
|
|
1667
1819
|
target: generated.target,
|
|
1668
1820
|
source: "generator",
|
|
1669
1821
|
dependencies: generated.dependencies
|