weapp-tailwindcss 5.0.4 → 5.0.6
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-CFgzVHFP.js} +8 -2
- package/dist/{bundle-state-C-p9eFz1.mjs → bundle-state-CdNXQl-o.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-DRHWC1t-.mjs → generator-Bgn4m8An.mjs} +1 -1
- package/dist/{generator-DaPOkJ7W.js → generator-C56PJYxA.js} +2 -2
- 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-Dt-FUQB5.mjs → incremental-runtime-class-set-BEYHQkZc.mjs} +238 -44
- package/dist/{incremental-runtime-class-set-BYV0yQdp.js → incremental-runtime-class-set-Bmzdjlk0.js} +239 -45
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/{postcss-Du8hY-MN.js → postcss-B7QNe78h.js} +57 -10
- package/dist/{postcss-CJrmfXvi.mjs → postcss-BgINK7Nm.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-Copn2SqE.mjs} +14 -3
- package/dist/{precheck-DgpVCvYk.js → precheck-CyPbGn38.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-BODCmzz5.mjs} +1 -1
- package/dist/{source-candidates-B4NvId_j.js → source-candidates-Caf2GDvx.js} +2 -2
- package/dist/{tailwindcss-D5RogwtV.mjs → tailwindcss-C0Zgo3Es.mjs} +1 -1
- package/dist/{tailwindcss-26ZFr5kv.js → tailwindcss-Tw6CSVHL.js} +3 -3
- package/dist/transform-95ivJthq.js +14868 -0
- package/dist/transform-DgCFGtQR.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-6FVAcrZl.js} +31 -6
- package/dist/{v3-engine-BCUGX3gX.mjs → v3-engine-Ji6AXPh2.mjs} +24 -5
- package/dist/{vite-tjYalmVX.js → vite-Bw6LOXvf.js} +733 -79
- package/dist/{vite-DS4H5d0f.mjs → vite-ChZ2cbn4.mjs} +745 -91
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +247 -45
- package/dist/{webpack-CA-40WU9.mjs → webpack-CMJ7iqN7.mjs} +6 -6
- package/dist/{webpack-0BwLOE_f.js → webpack-nn3P8_S_.js} +8 -8
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -4
- 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-Bmzdjlk0.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-6FVAcrZl.js");
|
|
3
|
+
const require_generator = require("./generator-C56PJYxA.js");
|
|
4
|
+
const require_precheck = require("./precheck-CyPbGn38.js");
|
|
5
|
+
const require_tailwindcss = require("./tailwindcss-Tw6CSVHL.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
|
}
|
|
@@ -1255,6 +1266,15 @@ function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
|
|
|
1255
1266
|
//#region src/bundlers/shared/generator-css.ts
|
|
1256
1267
|
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1257
1268
|
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
1269
|
+
const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
|
|
1270
|
+
"config",
|
|
1271
|
+
"custom-variant",
|
|
1272
|
+
"plugin",
|
|
1273
|
+
"source",
|
|
1274
|
+
"theme",
|
|
1275
|
+
"utility",
|
|
1276
|
+
"variant"
|
|
1277
|
+
]);
|
|
1258
1278
|
function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
|
|
1259
1279
|
if (target !== "weapp") return css;
|
|
1260
1280
|
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
@@ -1263,13 +1283,58 @@ function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight
|
|
|
1263
1283
|
preservePseudoContentInit: majorVersion === 3
|
|
1264
1284
|
});
|
|
1265
1285
|
}
|
|
1286
|
+
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
1287
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
1288
|
+
if (!options.isolateCurrentCssCandidates) return true;
|
|
1289
|
+
return require_tailwindcss.isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
1290
|
+
}
|
|
1266
1291
|
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
1267
1292
|
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
1268
1293
|
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
1269
1294
|
return new Set([...scopedRuntime, ...runtime]);
|
|
1270
1295
|
}
|
|
1271
1296
|
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
1272
|
-
return
|
|
1297
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
1298
|
+
}
|
|
1299
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
1300
|
+
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && require_v3_engine.hasTailwindApplyDirective(options.rawSource) && !require_v3_engine.hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
1301
|
+
}
|
|
1302
|
+
function removeTailwindApplyAtRules(source) {
|
|
1303
|
+
if (!source.includes("@apply")) return source;
|
|
1304
|
+
try {
|
|
1305
|
+
const root = postcss.default.parse(source);
|
|
1306
|
+
let changed = false;
|
|
1307
|
+
root.walkAtRules("apply", (rule) => {
|
|
1308
|
+
rule.remove();
|
|
1309
|
+
changed = true;
|
|
1310
|
+
});
|
|
1311
|
+
root.walk((node) => {
|
|
1312
|
+
if ("nodes" in node && node.nodes?.length === 0) node.remove();
|
|
1313
|
+
});
|
|
1314
|
+
return changed ? root.toString() : source;
|
|
1315
|
+
} catch {
|
|
1316
|
+
return source;
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
function removeTailwindV4GeneratorAtRules(source) {
|
|
1320
|
+
try {
|
|
1321
|
+
const root = postcss.default.parse(source);
|
|
1322
|
+
let changed = false;
|
|
1323
|
+
root.walkAtRules((rule) => {
|
|
1324
|
+
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
1325
|
+
rule.remove();
|
|
1326
|
+
changed = true;
|
|
1327
|
+
});
|
|
1328
|
+
root.walk((node) => {
|
|
1329
|
+
if ("nodes" in node && node.nodes?.length === 0) {
|
|
1330
|
+
node.remove();
|
|
1331
|
+
changed = true;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
return changed ? root.toString() : source;
|
|
1335
|
+
} catch {
|
|
1336
|
+
return source;
|
|
1337
|
+
}
|
|
1273
1338
|
}
|
|
1274
1339
|
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
1275
1340
|
if (majorVersion !== 4 || isolateCssSource) return false;
|
|
@@ -1297,7 +1362,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
|
|
|
1297
1362
|
};
|
|
1298
1363
|
}
|
|
1299
1364
|
function isLocalImportRequest(request) {
|
|
1300
|
-
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1365
|
+
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
1301
1366
|
}
|
|
1302
1367
|
function isCommentOnlyCss(source) {
|
|
1303
1368
|
try {
|
|
@@ -1308,7 +1373,19 @@ function isCommentOnlyCss(source) {
|
|
|
1308
1373
|
}
|
|
1309
1374
|
}
|
|
1310
1375
|
function stripTailwindSourceMediaFragments(source) {
|
|
1311
|
-
|
|
1376
|
+
let removedSourceMediaStart = false;
|
|
1377
|
+
return source.split(/\r?\n/).filter((line) => {
|
|
1378
|
+
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
1379
|
+
removedSourceMediaStart = true;
|
|
1380
|
+
return false;
|
|
1381
|
+
}
|
|
1382
|
+
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
1383
|
+
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
1384
|
+
removedSourceMediaStart = false;
|
|
1385
|
+
return false;
|
|
1386
|
+
}
|
|
1387
|
+
return true;
|
|
1388
|
+
}).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
|
|
1312
1389
|
}
|
|
1313
1390
|
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
1314
1391
|
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
@@ -1415,11 +1492,70 @@ function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
|
1415
1492
|
};
|
|
1416
1493
|
}
|
|
1417
1494
|
}
|
|
1495
|
+
function normalizeGeneratedSelector(selector) {
|
|
1496
|
+
return selector.replace(/:not\(#\\#\)/g, "").trim();
|
|
1497
|
+
}
|
|
1498
|
+
function collectApplyOnlySourceSelectors(source) {
|
|
1499
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1500
|
+
try {
|
|
1501
|
+
postcss.default.parse(source).walkRules((rule) => {
|
|
1502
|
+
if (!rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) return;
|
|
1503
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1504
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1505
|
+
if (normalized) selectors.add(normalized);
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
} catch {}
|
|
1509
|
+
return selectors;
|
|
1510
|
+
}
|
|
1511
|
+
function hasOnlyApplyBackedSourceRules(source) {
|
|
1512
|
+
let hasApplyRule = false;
|
|
1513
|
+
let hasNonApplyRule = false;
|
|
1514
|
+
try {
|
|
1515
|
+
postcss.default.parse(source).walkRules((rule) => {
|
|
1516
|
+
if (rule.nodes?.some((node) => node.type === "atrule" && node.name === "apply")) hasApplyRule = true;
|
|
1517
|
+
else hasNonApplyRule = true;
|
|
1518
|
+
});
|
|
1519
|
+
} catch {
|
|
1520
|
+
return false;
|
|
1521
|
+
}
|
|
1522
|
+
return hasApplyRule && !hasNonApplyRule;
|
|
1523
|
+
}
|
|
1524
|
+
function filterApplyOnlyGeneratedCss(css, source) {
|
|
1525
|
+
const selectors = collectApplyOnlySourceSelectors(source);
|
|
1526
|
+
if (selectors.size === 0) return css;
|
|
1527
|
+
const selectorList = [...selectors];
|
|
1528
|
+
try {
|
|
1529
|
+
const root = postcss.default.parse(css);
|
|
1530
|
+
root.walkRules((rule) => {
|
|
1531
|
+
const isApplySelector = (rule.selectors ?? [rule.selector]).some((selector) => {
|
|
1532
|
+
const normalized = normalizeGeneratedSelector(selector);
|
|
1533
|
+
return selectorList.some((sourceSelector) => {
|
|
1534
|
+
if (normalized === sourceSelector) return true;
|
|
1535
|
+
if (!normalized.startsWith(sourceSelector)) return false;
|
|
1536
|
+
const next = normalized[sourceSelector.length];
|
|
1537
|
+
return next === ":" || next === "[" || next === ".";
|
|
1538
|
+
});
|
|
1539
|
+
});
|
|
1540
|
+
const isVariableRule = rule.nodes?.some((node) => node.type === "decl" && node.prop.startsWith("--"));
|
|
1541
|
+
if (!isApplySelector && !isVariableRule) rule.remove();
|
|
1542
|
+
});
|
|
1543
|
+
root.walkAtRules((rule) => {
|
|
1544
|
+
if (rule.nodes !== void 0 && rule.nodes.length === 0) rule.remove();
|
|
1545
|
+
});
|
|
1546
|
+
return root.toString();
|
|
1547
|
+
} catch {
|
|
1548
|
+
return css;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options) {
|
|
1552
|
+
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);
|
|
1553
|
+
}
|
|
1418
1554
|
async function transformGeneratorUserCss(source, options) {
|
|
1419
1555
|
if (source.trim().length === 0) return "";
|
|
1420
|
-
const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
1556
|
+
const cleanedSource = require_v3_engine.removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
1421
1557
|
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 }));
|
|
1558
|
+
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(require_v3_engine.removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
1423
1559
|
if (userSource.trim().length === 0) return "";
|
|
1424
1560
|
if (isCommentOnlyCss(userSource)) return userSource;
|
|
1425
1561
|
if (options.generatorTarget !== "weapp") return userSource;
|
|
@@ -1481,6 +1617,32 @@ function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
|
1481
1617
|
return css;
|
|
1482
1618
|
}
|
|
1483
1619
|
}
|
|
1620
|
+
function splitLocalCssImports(source) {
|
|
1621
|
+
try {
|
|
1622
|
+
const root = postcss.default.parse(source);
|
|
1623
|
+
const importRoot = postcss.default.root();
|
|
1624
|
+
let changed = false;
|
|
1625
|
+
for (const node of [...root.nodes]) {
|
|
1626
|
+
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
1627
|
+
const request = require_v3_engine.parseImportRequest(node.params);
|
|
1628
|
+
if (!request || !isLocalImportRequest(request)) continue;
|
|
1629
|
+
importRoot.append(node.clone());
|
|
1630
|
+
node.remove();
|
|
1631
|
+
changed = true;
|
|
1632
|
+
}
|
|
1633
|
+
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
1634
|
+
return changed ? {
|
|
1635
|
+
imports,
|
|
1636
|
+
source: root.toString()
|
|
1637
|
+
} : void 0;
|
|
1638
|
+
} catch {
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
}
|
|
1642
|
+
function restoreLocalCssImports(css, imports) {
|
|
1643
|
+
if (!imports?.trim()) return css;
|
|
1644
|
+
return createCssSourceOrderAppend(imports, css);
|
|
1645
|
+
}
|
|
1484
1646
|
async function generateCssByGenerator(options) {
|
|
1485
1647
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
1486
1648
|
const generatorOptions = {
|
|
@@ -1489,6 +1651,9 @@ async function generateCssByGenerator(options) {
|
|
|
1489
1651
|
};
|
|
1490
1652
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1491
1653
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(require_v3_engine.normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
1654
|
+
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
1655
|
+
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
1656
|
+
const userCssRawSource = majorVersion === 4 ? removeTailwindV4GeneratorAtRules(generatorRawSource) : generatorRawSource;
|
|
1492
1657
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
1493
1658
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1494
1659
|
css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
@@ -1497,16 +1662,21 @@ async function generateCssByGenerator(options) {
|
|
|
1497
1662
|
dependencies: []
|
|
1498
1663
|
};
|
|
1499
1664
|
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(
|
|
1665
|
+
const hasGeneratedCss = require_v3_engine.hasTailwindGeneratedCss(generatorRawSource);
|
|
1666
|
+
const hasSourceDirectives = require_v3_engine.hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
1667
|
+
const hasGeneratedMarkers = require_v3_engine.hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
1503
1668
|
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1504
1669
|
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1505
1670
|
try {
|
|
1506
1671
|
await runtimeState.readyPromise;
|
|
1507
|
-
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(
|
|
1508
|
-
const
|
|
1509
|
-
|
|
1672
|
+
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
1673
|
+
const isolateCurrentCssCandidates = shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, {
|
|
1674
|
+
hasGeneratedCss,
|
|
1675
|
+
hasGeneratedMarkers,
|
|
1676
|
+
rawSource: generatorRawSource
|
|
1677
|
+
});
|
|
1678
|
+
const runtimeWithCurrentCss = isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
1679
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
1510
1680
|
cssEntries: opts.cssEntries,
|
|
1511
1681
|
getSourceCandidatesForEntries,
|
|
1512
1682
|
runtime: runtimeWithCurrentCss
|
|
@@ -1523,17 +1693,18 @@ async function generateCssByGenerator(options) {
|
|
|
1523
1693
|
debug("defer empty scoped css source generation: %s", file);
|
|
1524
1694
|
return;
|
|
1525
1695
|
}
|
|
1526
|
-
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1696
|
+
const sourceRuntime = scopedRuntime && (scopedRuntime.size > 0 || isolateCssSource) ? isolateCurrentCssCandidates ? runtimeWithCurrentCss : mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtimeWithCurrentCss, {
|
|
1527
1697
|
currentCssCandidates,
|
|
1528
1698
|
cssHandlerOptions,
|
|
1529
1699
|
isolateCssSource,
|
|
1530
1700
|
matchedCssSourceFile
|
|
1531
1701
|
}) : runtimeWithCurrentCss;
|
|
1532
1702
|
const generatorRuntime = majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(sourceRuntime) : sourceRuntime;
|
|
1703
|
+
const useIncrementalCache = (majorVersion === 3 || majorVersion === 4) && !(majorVersion === 3 && isolateCssSource);
|
|
1533
1704
|
return generator.generate({
|
|
1534
1705
|
bareArbitraryValues: generatorOptions.bareArbitraryValues,
|
|
1535
1706
|
candidates: generatorRuntime,
|
|
1536
|
-
incrementalCache:
|
|
1707
|
+
incrementalCache: useIncrementalCache,
|
|
1537
1708
|
scanSources: shouldScanTailwindV4Sources(majorVersion, generatorOptions.target, generatorRuntime, isolateCssSource),
|
|
1538
1709
|
styleOptions: generatorStyleOptions,
|
|
1539
1710
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
@@ -1555,22 +1726,27 @@ async function generateCssByGenerator(options) {
|
|
|
1555
1726
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
1556
1727
|
};
|
|
1557
1728
|
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(
|
|
1729
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1559
1730
|
const incrementalCss = require_v3_engine.stripTailwindBanner(generated.incrementalCss);
|
|
1560
1731
|
return {
|
|
1561
|
-
css: incrementalCss.trim().length > 0 ? require_v3_engine.createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
1732
|
+
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
1733
|
target: generated.target,
|
|
1563
1734
|
source: "generator",
|
|
1564
1735
|
dependencies: generated.dependencies,
|
|
1565
1736
|
incremental: true
|
|
1566
1737
|
};
|
|
1567
1738
|
}
|
|
1739
|
+
const shouldFilterApplyOnlyCss = shouldFilterApplyOnlyGeneratedCss(majorVersion, generated.target, generatorRawSource, {
|
|
1740
|
+
hasGeneratedCss,
|
|
1741
|
+
hasGeneratedMarkers
|
|
1742
|
+
});
|
|
1743
|
+
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(require_v3_engine.stripTailwindBanner(generated.css), generatorRawSource) : require_v3_engine.stripTailwindBanner(generated.css);
|
|
1568
1744
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
1569
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(
|
|
1745
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? require_v3_engine.splitTailwindV4GeneratedCssBySourceOrder(userCssRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssRawSource, generated.rawCss);
|
|
1570
1746
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
1571
1747
|
if (orderedExtraCss) {
|
|
1572
|
-
let css =
|
|
1573
|
-
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1748
|
+
let css = generatedCss;
|
|
1749
|
+
if (generated.target === "weapp") css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1574
1750
|
const userCssOptions = {
|
|
1575
1751
|
generatorTarget: generated.target,
|
|
1576
1752
|
generatorStyleOptions,
|
|
@@ -1590,27 +1766,33 @@ async function generateCssByGenerator(options) {
|
|
|
1590
1766
|
hasSourceDirectives,
|
|
1591
1767
|
hasMatchedCssSourceFile
|
|
1592
1768
|
})) {
|
|
1593
|
-
const userCss = await transformGeneratorUserCss(
|
|
1769
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
1594
1770
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1595
1771
|
}
|
|
1596
1772
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
1597
1773
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1598
|
-
|
|
1599
|
-
|
|
1774
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1775
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1776
|
+
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1777
|
+
}
|
|
1600
1778
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1601
1779
|
return {
|
|
1602
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1780
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1781
|
+
cssHandlerOptions,
|
|
1782
|
+
isolateCurrentCssCandidates,
|
|
1783
|
+
localImports: localImportParts?.imports
|
|
1784
|
+
}) }), localImportParts?.imports),
|
|
1603
1785
|
target: generated.target,
|
|
1604
1786
|
source: "generator",
|
|
1605
1787
|
dependencies: generated.dependencies
|
|
1606
1788
|
};
|
|
1607
1789
|
}
|
|
1608
1790
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1609
|
-
let css =
|
|
1791
|
+
let css = generatedCss;
|
|
1610
1792
|
if (generated.target === "weapp") {
|
|
1611
|
-
css = inheritLegacyUnitConvertedDeclarations(css,
|
|
1612
|
-
if (hasUserCssLayerBlocks(
|
|
1613
|
-
const layerParts = splitUserCssLayerBlocks(
|
|
1793
|
+
css = inheritLegacyUnitConvertedDeclarations(css, generatorRawSource);
|
|
1794
|
+
if (hasUserCssLayerBlocks(generatorRawSource)) {
|
|
1795
|
+
const layerParts = splitUserCssLayerBlocks(generatorRawSource);
|
|
1614
1796
|
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
1615
1797
|
generatorTarget: generated.target,
|
|
1616
1798
|
generatorStyleOptions,
|
|
@@ -1630,7 +1812,7 @@ async function generateCssByGenerator(options) {
|
|
|
1630
1812
|
}
|
|
1631
1813
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1632
1814
|
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
1633
|
-
const userCss = await transformGeneratorUserCss(
|
|
1815
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
1634
1816
|
generatorTarget: generated.target,
|
|
1635
1817
|
generatorStyleOptions,
|
|
1636
1818
|
cssUserHandlerOptions,
|
|
@@ -1639,12 +1821,14 @@ async function generateCssByGenerator(options) {
|
|
|
1639
1821
|
});
|
|
1640
1822
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1641
1823
|
}
|
|
1642
|
-
if (hasMatchedCssSourceFile && generated.target === "weapp")
|
|
1824
|
+
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
1825
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1826
|
+
}
|
|
1643
1827
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1644
1828
|
hasSourceDirectives,
|
|
1645
1829
|
hasMatchedCssSourceFile
|
|
1646
1830
|
})) {
|
|
1647
|
-
const userCss = await transformGeneratorUserCss(
|
|
1831
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
1648
1832
|
generatorTarget: generated.target,
|
|
1649
1833
|
generatorStyleOptions,
|
|
1650
1834
|
cssUserHandlerOptions,
|
|
@@ -1654,16 +1838,26 @@ async function generateCssByGenerator(options) {
|
|
|
1654
1838
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1655
1839
|
}
|
|
1656
1840
|
return {
|
|
1657
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1841
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1842
|
+
cssHandlerOptions,
|
|
1843
|
+
isolateCurrentCssCandidates,
|
|
1844
|
+
localImports: localImportParts?.imports
|
|
1845
|
+
}) }), localImportParts?.imports),
|
|
1658
1846
|
target: generated.target,
|
|
1659
1847
|
source: "generator",
|
|
1660
1848
|
dependencies: generated.dependencies
|
|
1661
1849
|
};
|
|
1662
1850
|
}
|
|
1663
|
-
|
|
1664
|
-
|
|
1851
|
+
if (!shouldFilterApplyOnlyCss) {
|
|
1852
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1853
|
+
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1854
|
+
}
|
|
1665
1855
|
return {
|
|
1666
|
-
css: finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight
|
|
1856
|
+
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
1857
|
+
cssHandlerOptions,
|
|
1858
|
+
isolateCurrentCssCandidates,
|
|
1859
|
+
localImports: localImportParts?.imports
|
|
1860
|
+
}) }), localImportParts?.imports),
|
|
1667
1861
|
target: generated.target,
|
|
1668
1862
|
source: "generator",
|
|
1669
1863
|
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-C56PJYxA.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-B7QNe78h.js");
|
|
5
|
+
const require_vite = require("./vite-Bw6LOXvf.js");
|
|
6
|
+
const require_webpack = require("./webpack-nn3P8_S_.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-Bgn4m8An.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-BgINK7Nm.mjs";
|
|
4
|
+
import { t as WeappTailwindcss } from "./vite-ChZ2cbn4.mjs";
|
|
5
|
+
import { n as weappTailwindcssPackageDir } from "./webpack-CMJ7iqN7.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-6FVAcrZl.js");
|
|
3
|
+
const require_generator = require("./generator-C56PJYxA.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({
|