weapp-tailwindcss 5.0.0-next.30 → 5.0.0-next.31
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/bundlers/shared/generator-css/directives.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{incremental-runtime-class-set-BdZHkoTs.mjs → incremental-runtime-class-set-Boqi1QlB.mjs} +256 -7
- package/dist/{incremental-runtime-class-set-BxvZONkv.js → incremental-runtime-class-set-FAOHZmzh.js} +261 -6
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{vite-C65DdWEj.js → vite-BgTPSkQS.js} +10 -3
- package/dist/{vite-rmL1rsA_.mjs → vite-fFRpSvyz.mjs} +10 -3
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +201 -6
- package/dist/{webpack-CqGvjvSQ.js → webpack-BXSWVdXh.js} +1 -1
- package/dist/{webpack-BU2Er4qg.mjs → webpack-Dx2AZpGU.mjs} +1 -1
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ interface TailwindDirectiveOptions {
|
|
|
3
3
|
}
|
|
4
4
|
export declare function parseImportRequest(params: string): string | undefined;
|
|
5
5
|
export declare function normalizeTailwindSourceForGenerator(rawSource: string, options?: TailwindDirectiveOptions): string;
|
|
6
|
+
export declare function normalizeTailwindV3CssEntrySource(rawSource: string): string;
|
|
6
7
|
export declare function normalizeTailwindSourceDirectives(rawSource: string, options?: TailwindDirectiveOptions): string;
|
|
7
8
|
export declare function removeTailwindSourceDirectives(rawSource: string, options?: TailwindDirectiveOptions): string;
|
|
8
9
|
export declare function hasTailwindSourceDirectives(rawSource: string, options?: TailwindDirectiveOptions): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function wrapUserLayerComponentsCss(css: string): string;
|
|
2
|
+
export declare function extractMarkedUserLayerComponentsCss(css: string): {
|
|
3
|
+
layers: string[];
|
|
4
|
+
rest: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function reorderMarkedUserLayerComponentsCss(css: string): string;
|
|
7
|
+
export declare function mergeMarkedUserLayerComponentsCss(baseCss: string, markedCss: string): {
|
|
8
|
+
css: string;
|
|
9
|
+
merged: boolean;
|
|
10
|
+
};
|
package/dist/gulp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("./chunk-C5U5_Hdc.js");
|
|
3
3
|
const require_v3_engine = require("./v3-engine-CHItlVq5.js");
|
|
4
|
-
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-
|
|
4
|
+
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-FAOHZmzh.js");
|
|
5
5
|
const require_precheck = require("./precheck-D7gJSmJz.js");
|
|
6
6
|
const require_tailwindcss = require("./tailwindcss-B-e2RiXr.js");
|
|
7
7
|
const require_source_candidates = require("./source-candidates-DNM8iwXW.js");
|
package/dist/gulp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { b as ensureRuntimeClassSet, n as getCompilerContext, t as shouldSkipJsTransform, y as createTailwindRuntimeReadyPromise } from "./precheck-D7K12zeX.mjs";
|
|
2
2
|
import { B as createDebug, _ as resolveViteSourceScanEntries, l as getRuntimeClassSetSignature } from "./v3-engine-DcvCCHfs.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { c as hasTailwindRootDirectives, i as generateCssByGenerator, r as emitHmrTiming, s as processCachedTask, t as createBundleRuntimeClassSetManager, u as normalizeTailwindSourceForGenerator } from "./incremental-runtime-class-set-Boqi1QlB.mjs";
|
|
4
4
|
import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C7dJHZ0G.mjs";
|
|
5
5
|
import { t as createSourceCandidateCollector } from "./source-candidates-CX2ozpKM.mjs";
|
|
6
6
|
import fs from "node:fs";
|
|
@@ -104,6 +104,11 @@ const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?
|
|
|
104
104
|
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
105
105
|
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
106
106
|
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
107
|
+
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
108
|
+
["tailwindcss/base", "base"],
|
|
109
|
+
["tailwindcss/components", "components"],
|
|
110
|
+
["tailwindcss/utilities", "utilities"]
|
|
111
|
+
]);
|
|
107
112
|
function parseImportRequest(params) {
|
|
108
113
|
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
109
114
|
}
|
|
@@ -283,6 +288,24 @@ function hasPreprocessorOnlySyntax(rawSource) {
|
|
|
283
288
|
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
284
289
|
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
285
290
|
}
|
|
291
|
+
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
292
|
+
try {
|
|
293
|
+
const root = postcss.parse(rawSource);
|
|
294
|
+
let changed = false;
|
|
295
|
+
root.walkAtRules("import", (node) => {
|
|
296
|
+
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
297
|
+
if (!layer) return;
|
|
298
|
+
node.replaceWith(postcss.atRule({
|
|
299
|
+
name: "tailwind",
|
|
300
|
+
params: layer
|
|
301
|
+
}));
|
|
302
|
+
changed = true;
|
|
303
|
+
});
|
|
304
|
+
return changed ? root.toString() : rawSource;
|
|
305
|
+
} catch {
|
|
306
|
+
return rawSource;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
286
309
|
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
287
310
|
if (!options.importFallback) return rawSource;
|
|
288
311
|
try {
|
|
@@ -1018,14 +1041,14 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1018
1041
|
css: rawSource
|
|
1019
1042
|
} : void 0;
|
|
1020
1043
|
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
1021
|
-
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ?
|
|
1044
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
1022
1045
|
if (!resolvedEntrySource) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1023
1046
|
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1024
1047
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined(mergedSourceOptions));
|
|
1025
1048
|
return resolveTailwindV3Source({
|
|
1026
1049
|
...mergedSourceOptions,
|
|
1027
1050
|
base: resolvedEntrySource.base,
|
|
1028
|
-
css: resolvedEntrySource.css,
|
|
1051
|
+
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
1029
1052
|
...config ? { config } : {}
|
|
1030
1053
|
});
|
|
1031
1054
|
}
|
|
@@ -1372,6 +1395,125 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
1372
1395
|
}
|
|
1373
1396
|
}
|
|
1374
1397
|
//#endregion
|
|
1398
|
+
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
1399
|
+
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
1400
|
+
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
1401
|
+
const UTILITY_LAYER_INSERTION_RES = [
|
|
1402
|
+
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
1403
|
+
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
1404
|
+
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
1405
|
+
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
1406
|
+
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
1407
|
+
];
|
|
1408
|
+
function appendCss(base, extra) {
|
|
1409
|
+
if (!base) return extra;
|
|
1410
|
+
if (!extra) return base;
|
|
1411
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1412
|
+
return `${base}\n${extra}`;
|
|
1413
|
+
}
|
|
1414
|
+
function removeFirstCssOccurrence(css, chunk) {
|
|
1415
|
+
const trimmed = chunk.trim();
|
|
1416
|
+
if (!trimmed) return css;
|
|
1417
|
+
const index = css.indexOf(trimmed);
|
|
1418
|
+
if (index === -1) return css;
|
|
1419
|
+
return appendCss(css.slice(0, index).trimEnd(), css.slice(index + trimmed.length).trimStart());
|
|
1420
|
+
}
|
|
1421
|
+
function collectSelectorsFromCss(css) {
|
|
1422
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1423
|
+
try {
|
|
1424
|
+
postcss.parse(css).walkRules((rule) => {
|
|
1425
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1426
|
+
const normalized = selector.trim();
|
|
1427
|
+
if (normalized) selectors.add(normalized);
|
|
1428
|
+
}
|
|
1429
|
+
});
|
|
1430
|
+
} catch {}
|
|
1431
|
+
return selectors;
|
|
1432
|
+
}
|
|
1433
|
+
function matchesLayerSelector(selector, layerSelector) {
|
|
1434
|
+
if (selector === layerSelector) return true;
|
|
1435
|
+
if (!selector.startsWith(layerSelector)) return false;
|
|
1436
|
+
const next = selector[layerSelector.length];
|
|
1437
|
+
return next === ":" || next === "[";
|
|
1438
|
+
}
|
|
1439
|
+
function removeCssRulesForSelectors(css, layerCss) {
|
|
1440
|
+
const selectors = [...collectSelectorsFromCss(layerCss)];
|
|
1441
|
+
if (selectors.length === 0) return css;
|
|
1442
|
+
try {
|
|
1443
|
+
const root = postcss.parse(css);
|
|
1444
|
+
root.walkRules((rule) => {
|
|
1445
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectors.some((layerSelector) => matchesLayerSelector(selector.trim(), layerSelector)))) rule.remove();
|
|
1446
|
+
});
|
|
1447
|
+
return root.toString();
|
|
1448
|
+
} catch {
|
|
1449
|
+
return removeFirstCssOccurrence(css, layerCss);
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function wrapUserLayerComponentsCss(css) {
|
|
1453
|
+
return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
|
|
1454
|
+
}
|
|
1455
|
+
function extractMarkedUserLayerComponentsCss(css) {
|
|
1456
|
+
const layers = [];
|
|
1457
|
+
let rest = "";
|
|
1458
|
+
let cursor = 0;
|
|
1459
|
+
while (cursor < css.length) {
|
|
1460
|
+
const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
|
|
1461
|
+
if (startIndex === -1) {
|
|
1462
|
+
rest += css.slice(cursor);
|
|
1463
|
+
break;
|
|
1464
|
+
}
|
|
1465
|
+
rest += css.slice(cursor, startIndex);
|
|
1466
|
+
const contentStart = startIndex + 47;
|
|
1467
|
+
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
1468
|
+
if (endIndex === -1) {
|
|
1469
|
+
rest += css.slice(startIndex);
|
|
1470
|
+
break;
|
|
1471
|
+
}
|
|
1472
|
+
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
1473
|
+
if (layerCss) layers.push(layerCss);
|
|
1474
|
+
cursor = endIndex + 45;
|
|
1475
|
+
}
|
|
1476
|
+
return {
|
|
1477
|
+
layers,
|
|
1478
|
+
rest
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
function findUtilityLayerInsertionIndex(css) {
|
|
1482
|
+
let index = -1;
|
|
1483
|
+
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
1484
|
+
const match = pattern.exec(css);
|
|
1485
|
+
if (!match) continue;
|
|
1486
|
+
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
1487
|
+
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
1488
|
+
}
|
|
1489
|
+
return index;
|
|
1490
|
+
}
|
|
1491
|
+
function reorderMarkedUserLayerComponentsCss(css) {
|
|
1492
|
+
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
1493
|
+
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
1494
|
+
if (layers.length === 0) return rest;
|
|
1495
|
+
const layerCss = layers.join("\n");
|
|
1496
|
+
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
1497
|
+
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
1498
|
+
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
1499
|
+
}
|
|
1500
|
+
function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
|
|
1501
|
+
if (!markedCss.includes(USER_LAYER_COMPONENTS_START)) return {
|
|
1502
|
+
css: baseCss,
|
|
1503
|
+
merged: false
|
|
1504
|
+
};
|
|
1505
|
+
const { layers } = extractMarkedUserLayerComponentsCss(markedCss);
|
|
1506
|
+
if (layers.length === 0) return {
|
|
1507
|
+
css: baseCss,
|
|
1508
|
+
merged: false
|
|
1509
|
+
};
|
|
1510
|
+
const layerCss = layers.join("\n");
|
|
1511
|
+
return {
|
|
1512
|
+
css: reorderMarkedUserLayerComponentsCss(appendCss(removeCssRulesForSelectors(baseCss, layerCss), wrapUserLayerComponentsCss(layerCss))),
|
|
1513
|
+
merged: true
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
//#endregion
|
|
1375
1517
|
//#region src/bundlers/shared/generator-css.ts
|
|
1376
1518
|
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1377
1519
|
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
@@ -1445,6 +1587,9 @@ function createCssSourceOrderAppend(base, extra) {
|
|
|
1445
1587
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1446
1588
|
return `${base}\n${extra}`;
|
|
1447
1589
|
}
|
|
1590
|
+
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
1591
|
+
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
1592
|
+
}
|
|
1448
1593
|
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
1449
1594
|
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1450
1595
|
if (placeholderParts) return placeholderParts;
|
|
@@ -1452,6 +1597,84 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
1452
1597
|
if (exactParts) return exactParts;
|
|
1453
1598
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
1454
1599
|
}
|
|
1600
|
+
function splitUserCssLayerBlocks(source) {
|
|
1601
|
+
if (!source.includes("@layer")) return {
|
|
1602
|
+
layer: "",
|
|
1603
|
+
rest: source
|
|
1604
|
+
};
|
|
1605
|
+
try {
|
|
1606
|
+
const root = postcss.parse(source);
|
|
1607
|
+
const layerRoot = postcss.root();
|
|
1608
|
+
const restRoot = postcss.root();
|
|
1609
|
+
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1610
|
+
return {
|
|
1611
|
+
layer: layerRoot.toString(),
|
|
1612
|
+
rest: restRoot.toString()
|
|
1613
|
+
};
|
|
1614
|
+
} catch {
|
|
1615
|
+
return {
|
|
1616
|
+
layer: source,
|
|
1617
|
+
rest: ""
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
function hasUserCssLayerBlocks(source) {
|
|
1622
|
+
if (!source.includes("@layer")) return false;
|
|
1623
|
+
try {
|
|
1624
|
+
let hasLayerBlock = false;
|
|
1625
|
+
postcss.parse(source).walkAtRules("layer", (node) => {
|
|
1626
|
+
if (node.nodes?.length) hasLayerBlock = true;
|
|
1627
|
+
});
|
|
1628
|
+
return hasLayerBlock;
|
|
1629
|
+
} catch {
|
|
1630
|
+
return true;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
function collectUserLayerSelectors(source) {
|
|
1634
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1635
|
+
try {
|
|
1636
|
+
postcss.parse(source).walkRules((rule) => {
|
|
1637
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1638
|
+
const normalized = selector.trim();
|
|
1639
|
+
if (normalized) selectors.add(normalized);
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
} catch {}
|
|
1643
|
+
return selectors;
|
|
1644
|
+
}
|
|
1645
|
+
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1646
|
+
if (selector === userLayerSelector) return true;
|
|
1647
|
+
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1648
|
+
const next = selector[userLayerSelector.length];
|
|
1649
|
+
return next === ":" || next === "[";
|
|
1650
|
+
}
|
|
1651
|
+
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1652
|
+
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1653
|
+
if (selectors.size === 0) return {
|
|
1654
|
+
layer: "",
|
|
1655
|
+
rest: css
|
|
1656
|
+
};
|
|
1657
|
+
try {
|
|
1658
|
+
const root = postcss.parse(css);
|
|
1659
|
+
const layerRoot = postcss.root();
|
|
1660
|
+
const selectorList = [...selectors];
|
|
1661
|
+
root.walkRules((rule) => {
|
|
1662
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1663
|
+
layerRoot.append(rule.clone());
|
|
1664
|
+
rule.remove();
|
|
1665
|
+
}
|
|
1666
|
+
});
|
|
1667
|
+
return {
|
|
1668
|
+
layer: layerRoot.toString(),
|
|
1669
|
+
rest: root.toString()
|
|
1670
|
+
};
|
|
1671
|
+
} catch {
|
|
1672
|
+
return {
|
|
1673
|
+
layer: "",
|
|
1674
|
+
rest: css
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1455
1678
|
async function transformGeneratorUserCss(source, options) {
|
|
1456
1679
|
if (source.trim().length === 0) return "";
|
|
1457
1680
|
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
@@ -1580,7 +1803,7 @@ async function generateCssByGenerator(options) {
|
|
|
1580
1803
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
1581
1804
|
};
|
|
1582
1805
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1583
|
-
if (typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1806
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1584
1807
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1585
1808
|
return {
|
|
1586
1809
|
css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
@@ -1602,9 +1825,14 @@ async function generateCssByGenerator(options) {
|
|
|
1602
1825
|
styleHandler,
|
|
1603
1826
|
importFallback: generatorOptions.importFallback
|
|
1604
1827
|
};
|
|
1828
|
+
const afterLayerParts = generated.target === "weapp" ? splitUserCssLayerBlocks(orderedExtraCss.after) : {
|
|
1829
|
+
layer: "",
|
|
1830
|
+
rest: orderedExtraCss.after
|
|
1831
|
+
};
|
|
1605
1832
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1833
|
+
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
1834
|
+
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
1835
|
+
css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
1608
1836
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
1609
1837
|
hasSourceDirectives,
|
|
1610
1838
|
hasMatchedCssSourceFile
|
|
@@ -1613,6 +1841,7 @@ async function generateCssByGenerator(options) {
|
|
|
1613
1841
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1614
1842
|
}
|
|
1615
1843
|
if (generated.target === "weapp") {
|
|
1844
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1616
1845
|
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1617
1846
|
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1618
1847
|
}
|
|
@@ -1625,7 +1854,27 @@ async function generateCssByGenerator(options) {
|
|
|
1625
1854
|
}
|
|
1626
1855
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1627
1856
|
let css = stripTailwindBanner(generated.css);
|
|
1628
|
-
if (generated.target === "weapp")
|
|
1857
|
+
if (generated.target === "weapp") {
|
|
1858
|
+
css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
1859
|
+
if (hasUserCssLayerBlocks(effectiveRawSource)) {
|
|
1860
|
+
const layerParts = splitUserCssLayerBlocks(effectiveRawSource);
|
|
1861
|
+
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
1862
|
+
generatorTarget: generated.target,
|
|
1863
|
+
generatorStyleOptions,
|
|
1864
|
+
cssUserHandlerOptions,
|
|
1865
|
+
styleHandler,
|
|
1866
|
+
importFallback: generatorOptions.importFallback
|
|
1867
|
+
});
|
|
1868
|
+
const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
|
|
1869
|
+
layer: layerUserCss,
|
|
1870
|
+
rest: css
|
|
1871
|
+
} : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
|
|
1872
|
+
if (layerCss.layer.trim().length > 0) {
|
|
1873
|
+
css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
1874
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1629
1878
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1630
1879
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1631
1880
|
hasSourceDirectives,
|
|
@@ -1972,4 +2221,4 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
1972
2221
|
};
|
|
1973
2222
|
}
|
|
1974
2223
|
//#endregion
|
|
1975
|
-
export { validateCandidatesByGenerator as a,
|
|
2224
|
+
export { validateCandidatesByGenerator as a, hasTailwindRootDirectives as c, hasTailwindGeneratedCssMarkers as d, generateCssByGenerator as i, hasTailwindSourceDirectives as l, createHmrTimingRecorder as n, mergeMarkedUserLayerComponentsCss as o, emitHmrTiming as r, processCachedTask as s, createBundleRuntimeClassSetManager as t, normalizeTailwindSourceForGenerator as u };
|
package/dist/{incremental-runtime-class-set-BxvZONkv.js → incremental-runtime-class-set-FAOHZmzh.js}
RENAMED
|
@@ -108,6 +108,11 @@ const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?
|
|
|
108
108
|
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
109
109
|
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
110
110
|
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
111
|
+
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
112
|
+
["tailwindcss/base", "base"],
|
|
113
|
+
["tailwindcss/components", "components"],
|
|
114
|
+
["tailwindcss/utilities", "utilities"]
|
|
115
|
+
]);
|
|
111
116
|
function parseImportRequest(params) {
|
|
112
117
|
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
113
118
|
}
|
|
@@ -287,6 +292,24 @@ function hasPreprocessorOnlySyntax(rawSource) {
|
|
|
287
292
|
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
288
293
|
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
289
294
|
}
|
|
295
|
+
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
296
|
+
try {
|
|
297
|
+
const root = postcss.default.parse(rawSource);
|
|
298
|
+
let changed = false;
|
|
299
|
+
root.walkAtRules("import", (node) => {
|
|
300
|
+
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
301
|
+
if (!layer) return;
|
|
302
|
+
node.replaceWith(postcss.default.atRule({
|
|
303
|
+
name: "tailwind",
|
|
304
|
+
params: layer
|
|
305
|
+
}));
|
|
306
|
+
changed = true;
|
|
307
|
+
});
|
|
308
|
+
return changed ? root.toString() : rawSource;
|
|
309
|
+
} catch {
|
|
310
|
+
return rawSource;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
290
313
|
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
291
314
|
if (!options.importFallback) return rawSource;
|
|
292
315
|
try {
|
|
@@ -1022,14 +1045,14 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
1022
1045
|
css: rawSource
|
|
1023
1046
|
} : void 0;
|
|
1024
1047
|
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
1025
|
-
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ?
|
|
1048
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
1026
1049
|
if (!resolvedEntrySource) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1027
1050
|
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? require_v3_engine.resolveTailwindV3Source(mergedSourceOptions) : require_v3_engine.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
1028
1051
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, require_v3_engine.omitUndefined(mergedSourceOptions));
|
|
1029
1052
|
return require_v3_engine.resolveTailwindV3Source({
|
|
1030
1053
|
...mergedSourceOptions,
|
|
1031
1054
|
base: resolvedEntrySource.base,
|
|
1032
|
-
css: resolvedEntrySource.css,
|
|
1055
|
+
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
1033
1056
|
...config ? { config } : {}
|
|
1034
1057
|
});
|
|
1035
1058
|
}
|
|
@@ -1376,6 +1399,125 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
1376
1399
|
}
|
|
1377
1400
|
}
|
|
1378
1401
|
//#endregion
|
|
1402
|
+
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
1403
|
+
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
1404
|
+
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
1405
|
+
const UTILITY_LAYER_INSERTION_RES = [
|
|
1406
|
+
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
1407
|
+
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
1408
|
+
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
1409
|
+
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
1410
|
+
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
1411
|
+
];
|
|
1412
|
+
function appendCss(base, extra) {
|
|
1413
|
+
if (!base) return extra;
|
|
1414
|
+
if (!extra) return base;
|
|
1415
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1416
|
+
return `${base}\n${extra}`;
|
|
1417
|
+
}
|
|
1418
|
+
function removeFirstCssOccurrence(css, chunk) {
|
|
1419
|
+
const trimmed = chunk.trim();
|
|
1420
|
+
if (!trimmed) return css;
|
|
1421
|
+
const index = css.indexOf(trimmed);
|
|
1422
|
+
if (index === -1) return css;
|
|
1423
|
+
return appendCss(css.slice(0, index).trimEnd(), css.slice(index + trimmed.length).trimStart());
|
|
1424
|
+
}
|
|
1425
|
+
function collectSelectorsFromCss(css) {
|
|
1426
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1427
|
+
try {
|
|
1428
|
+
postcss.default.parse(css).walkRules((rule) => {
|
|
1429
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1430
|
+
const normalized = selector.trim();
|
|
1431
|
+
if (normalized) selectors.add(normalized);
|
|
1432
|
+
}
|
|
1433
|
+
});
|
|
1434
|
+
} catch {}
|
|
1435
|
+
return selectors;
|
|
1436
|
+
}
|
|
1437
|
+
function matchesLayerSelector(selector, layerSelector) {
|
|
1438
|
+
if (selector === layerSelector) return true;
|
|
1439
|
+
if (!selector.startsWith(layerSelector)) return false;
|
|
1440
|
+
const next = selector[layerSelector.length];
|
|
1441
|
+
return next === ":" || next === "[";
|
|
1442
|
+
}
|
|
1443
|
+
function removeCssRulesForSelectors(css, layerCss) {
|
|
1444
|
+
const selectors = [...collectSelectorsFromCss(layerCss)];
|
|
1445
|
+
if (selectors.length === 0) return css;
|
|
1446
|
+
try {
|
|
1447
|
+
const root = postcss.default.parse(css);
|
|
1448
|
+
root.walkRules((rule) => {
|
|
1449
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectors.some((layerSelector) => matchesLayerSelector(selector.trim(), layerSelector)))) rule.remove();
|
|
1450
|
+
});
|
|
1451
|
+
return root.toString();
|
|
1452
|
+
} catch {
|
|
1453
|
+
return removeFirstCssOccurrence(css, layerCss);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
function wrapUserLayerComponentsCss(css) {
|
|
1457
|
+
return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
|
|
1458
|
+
}
|
|
1459
|
+
function extractMarkedUserLayerComponentsCss(css) {
|
|
1460
|
+
const layers = [];
|
|
1461
|
+
let rest = "";
|
|
1462
|
+
let cursor = 0;
|
|
1463
|
+
while (cursor < css.length) {
|
|
1464
|
+
const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
|
|
1465
|
+
if (startIndex === -1) {
|
|
1466
|
+
rest += css.slice(cursor);
|
|
1467
|
+
break;
|
|
1468
|
+
}
|
|
1469
|
+
rest += css.slice(cursor, startIndex);
|
|
1470
|
+
const contentStart = startIndex + 47;
|
|
1471
|
+
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
1472
|
+
if (endIndex === -1) {
|
|
1473
|
+
rest += css.slice(startIndex);
|
|
1474
|
+
break;
|
|
1475
|
+
}
|
|
1476
|
+
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
1477
|
+
if (layerCss) layers.push(layerCss);
|
|
1478
|
+
cursor = endIndex + 45;
|
|
1479
|
+
}
|
|
1480
|
+
return {
|
|
1481
|
+
layers,
|
|
1482
|
+
rest
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
function findUtilityLayerInsertionIndex(css) {
|
|
1486
|
+
let index = -1;
|
|
1487
|
+
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
1488
|
+
const match = pattern.exec(css);
|
|
1489
|
+
if (!match) continue;
|
|
1490
|
+
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
1491
|
+
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
1492
|
+
}
|
|
1493
|
+
return index;
|
|
1494
|
+
}
|
|
1495
|
+
function reorderMarkedUserLayerComponentsCss(css) {
|
|
1496
|
+
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
1497
|
+
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
1498
|
+
if (layers.length === 0) return rest;
|
|
1499
|
+
const layerCss = layers.join("\n");
|
|
1500
|
+
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
1501
|
+
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
1502
|
+
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
1503
|
+
}
|
|
1504
|
+
function mergeMarkedUserLayerComponentsCss(baseCss, markedCss) {
|
|
1505
|
+
if (!markedCss.includes(USER_LAYER_COMPONENTS_START)) return {
|
|
1506
|
+
css: baseCss,
|
|
1507
|
+
merged: false
|
|
1508
|
+
};
|
|
1509
|
+
const { layers } = extractMarkedUserLayerComponentsCss(markedCss);
|
|
1510
|
+
if (layers.length === 0) return {
|
|
1511
|
+
css: baseCss,
|
|
1512
|
+
merged: false
|
|
1513
|
+
};
|
|
1514
|
+
const layerCss = layers.join("\n");
|
|
1515
|
+
return {
|
|
1516
|
+
css: reorderMarkedUserLayerComponentsCss(appendCss(removeCssRulesForSelectors(baseCss, layerCss), wrapUserLayerComponentsCss(layerCss))),
|
|
1517
|
+
merged: true
|
|
1518
|
+
};
|
|
1519
|
+
}
|
|
1520
|
+
//#endregion
|
|
1379
1521
|
//#region src/bundlers/shared/generator-css.ts
|
|
1380
1522
|
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
1381
1523
|
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
@@ -1449,6 +1591,9 @@ function createCssSourceOrderAppend(base, extra) {
|
|
|
1449
1591
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
1450
1592
|
return `${base}\n${extra}`;
|
|
1451
1593
|
}
|
|
1594
|
+
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
1595
|
+
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
1596
|
+
}
|
|
1452
1597
|
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
1453
1598
|
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
1454
1599
|
if (placeholderParts) return placeholderParts;
|
|
@@ -1456,6 +1601,84 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
1456
1601
|
if (exactParts) return exactParts;
|
|
1457
1602
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
1458
1603
|
}
|
|
1604
|
+
function splitUserCssLayerBlocks(source) {
|
|
1605
|
+
if (!source.includes("@layer")) return {
|
|
1606
|
+
layer: "",
|
|
1607
|
+
rest: source
|
|
1608
|
+
};
|
|
1609
|
+
try {
|
|
1610
|
+
const root = postcss.default.parse(source);
|
|
1611
|
+
const layerRoot = postcss.default.root();
|
|
1612
|
+
const restRoot = postcss.default.root();
|
|
1613
|
+
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
1614
|
+
return {
|
|
1615
|
+
layer: layerRoot.toString(),
|
|
1616
|
+
rest: restRoot.toString()
|
|
1617
|
+
};
|
|
1618
|
+
} catch {
|
|
1619
|
+
return {
|
|
1620
|
+
layer: source,
|
|
1621
|
+
rest: ""
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
function hasUserCssLayerBlocks(source) {
|
|
1626
|
+
if (!source.includes("@layer")) return false;
|
|
1627
|
+
try {
|
|
1628
|
+
let hasLayerBlock = false;
|
|
1629
|
+
postcss.default.parse(source).walkAtRules("layer", (node) => {
|
|
1630
|
+
if (node.nodes?.length) hasLayerBlock = true;
|
|
1631
|
+
});
|
|
1632
|
+
return hasLayerBlock;
|
|
1633
|
+
} catch {
|
|
1634
|
+
return true;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
function collectUserLayerSelectors(source) {
|
|
1638
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
1639
|
+
try {
|
|
1640
|
+
postcss.default.parse(source).walkRules((rule) => {
|
|
1641
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
1642
|
+
const normalized = selector.trim();
|
|
1643
|
+
if (normalized) selectors.add(normalized);
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
} catch {}
|
|
1647
|
+
return selectors;
|
|
1648
|
+
}
|
|
1649
|
+
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
1650
|
+
if (selector === userLayerSelector) return true;
|
|
1651
|
+
if (!selector.startsWith(userLayerSelector)) return false;
|
|
1652
|
+
const next = selector[userLayerSelector.length];
|
|
1653
|
+
return next === ":" || next === "[";
|
|
1654
|
+
}
|
|
1655
|
+
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
1656
|
+
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
1657
|
+
if (selectors.size === 0) return {
|
|
1658
|
+
layer: "",
|
|
1659
|
+
rest: css
|
|
1660
|
+
};
|
|
1661
|
+
try {
|
|
1662
|
+
const root = postcss.default.parse(css);
|
|
1663
|
+
const layerRoot = postcss.default.root();
|
|
1664
|
+
const selectorList = [...selectors];
|
|
1665
|
+
root.walkRules((rule) => {
|
|
1666
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
1667
|
+
layerRoot.append(rule.clone());
|
|
1668
|
+
rule.remove();
|
|
1669
|
+
}
|
|
1670
|
+
});
|
|
1671
|
+
return {
|
|
1672
|
+
layer: layerRoot.toString(),
|
|
1673
|
+
rest: root.toString()
|
|
1674
|
+
};
|
|
1675
|
+
} catch {
|
|
1676
|
+
return {
|
|
1677
|
+
layer: "",
|
|
1678
|
+
rest: css
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1459
1682
|
async function transformGeneratorUserCss(source, options) {
|
|
1460
1683
|
if (source.trim().length === 0) return "";
|
|
1461
1684
|
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
@@ -1584,7 +1807,7 @@ async function generateCssByGenerator(options) {
|
|
|
1584
1807
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
1585
1808
|
};
|
|
1586
1809
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
1587
|
-
if (typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1810
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
1588
1811
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
1589
1812
|
return {
|
|
1590
1813
|
css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
@@ -1606,9 +1829,14 @@ async function generateCssByGenerator(options) {
|
|
|
1606
1829
|
styleHandler,
|
|
1607
1830
|
importFallback: generatorOptions.importFallback
|
|
1608
1831
|
};
|
|
1832
|
+
const afterLayerParts = generated.target === "weapp" ? splitUserCssLayerBlocks(orderedExtraCss.after) : {
|
|
1833
|
+
layer: "",
|
|
1834
|
+
rest: orderedExtraCss.after
|
|
1835
|
+
};
|
|
1609
1836
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1837
|
+
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
1838
|
+
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
1839
|
+
css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
1612
1840
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
1613
1841
|
hasSourceDirectives,
|
|
1614
1842
|
hasMatchedCssSourceFile
|
|
@@ -1617,6 +1845,7 @@ async function generateCssByGenerator(options) {
|
|
|
1617
1845
|
css = createCssSourceOrderAppend(css, userCss);
|
|
1618
1846
|
}
|
|
1619
1847
|
if (generated.target === "weapp") {
|
|
1848
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1620
1849
|
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1621
1850
|
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1622
1851
|
}
|
|
@@ -1629,7 +1858,27 @@ async function generateCssByGenerator(options) {
|
|
|
1629
1858
|
}
|
|
1630
1859
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
1631
1860
|
let css = stripTailwindBanner(generated.css);
|
|
1632
|
-
if (generated.target === "weapp")
|
|
1861
|
+
if (generated.target === "weapp") {
|
|
1862
|
+
css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
1863
|
+
if (hasUserCssLayerBlocks(effectiveRawSource)) {
|
|
1864
|
+
const layerParts = splitUserCssLayerBlocks(effectiveRawSource);
|
|
1865
|
+
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
1866
|
+
generatorTarget: generated.target,
|
|
1867
|
+
generatorStyleOptions,
|
|
1868
|
+
cssUserHandlerOptions,
|
|
1869
|
+
styleHandler,
|
|
1870
|
+
importFallback: generatorOptions.importFallback
|
|
1871
|
+
});
|
|
1872
|
+
const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
|
|
1873
|
+
layer: layerUserCss,
|
|
1874
|
+
rest: css
|
|
1875
|
+
} : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
|
|
1876
|
+
if (layerCss.layer.trim().length > 0) {
|
|
1877
|
+
css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
1878
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1633
1882
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
1634
1883
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
1635
1884
|
hasSourceDirectives,
|
|
@@ -2018,6 +2267,12 @@ Object.defineProperty(exports, "hasTailwindSourceDirectives", {
|
|
|
2018
2267
|
return hasTailwindSourceDirectives;
|
|
2019
2268
|
}
|
|
2020
2269
|
});
|
|
2270
|
+
Object.defineProperty(exports, "mergeMarkedUserLayerComponentsCss", {
|
|
2271
|
+
enumerable: true,
|
|
2272
|
+
get: function() {
|
|
2273
|
+
return mergeMarkedUserLayerComponentsCss;
|
|
2274
|
+
}
|
|
2275
|
+
});
|
|
2021
2276
|
Object.defineProperty(exports, "normalizeTailwindSourceForGenerator", {
|
|
2022
2277
|
enumerable: true,
|
|
2023
2278
|
get: function() {
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_generator = require("./generator-CrU-Ghc1.js");
|
|
3
3
|
const require_gulp = require("./gulp.js");
|
|
4
4
|
const require_postcss = require("./postcss-DAWf9D3C.js");
|
|
5
|
-
const require_vite = require("./vite-
|
|
6
|
-
const require_webpack = require("./webpack-
|
|
5
|
+
const require_vite = require("./vite-BgTPSkQS.js");
|
|
6
|
+
const require_webpack = require("./webpack-BXSWVdXh.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
1
|
import { t as createWeappTailwindcssGenerator } from "./generator-Qw-tZ0Z2.mjs";
|
|
2
2
|
import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
|
|
3
3
|
import { t as weappTailwindcssPostcssPlugin } from "./postcss-C6zOQqlL.mjs";
|
|
4
|
-
import { t as WeappTailwindcss } from "./vite-
|
|
5
|
-
import { n as weappTailwindcssPackageDir } from "./webpack-
|
|
4
|
+
import { t as WeappTailwindcss } from "./vite-fFRpSvyz.mjs";
|
|
5
|
+
import { n as weappTailwindcssPackageDir } from "./webpack-Dx2AZpGU.mjs";
|
|
6
6
|
import { unitConversionComposeRules, unitConversionPresets } from "@weapp-tailwindcss/postcss";
|
|
7
7
|
export { WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, unitConversionComposeRules, unitConversionPresets, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-C5U5_Hdc.js");
|
|
2
2
|
const require_v3_engine = require("./v3-engine-CHItlVq5.js");
|
|
3
3
|
const require_generator = require("./generator-CrU-Ghc1.js");
|
|
4
|
-
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-
|
|
4
|
+
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-FAOHZmzh.js");
|
|
5
5
|
const require_precheck = require("./precheck-D7gJSmJz.js");
|
|
6
6
|
const require_utils = require("./utils-D7Ygohep.js");
|
|
7
7
|
const require_tailwindcss = require("./tailwindcss-B-e2RiXr.js");
|
|
@@ -22389,7 +22389,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
22389
22389
|
return collected;
|
|
22390
22390
|
}
|
|
22391
22391
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
22392
|
-
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].filter(([
|
|
22392
|
+
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].filter(([, css]) => css.length > 0);
|
|
22393
22393
|
if (viteCssResults.length === 0) return 0;
|
|
22394
22394
|
let injected = 0;
|
|
22395
22395
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -22402,7 +22402,13 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
22402
22402
|
for (const [sourceFile, sourceCss] of viteCssResults) {
|
|
22403
22403
|
if (require_bundle_state.normalizeOutputPathKey(sourceFile) === mainFileKey || options.opts.mainCssChunkMatcher(sourceFile, options.opts.appType)) continue;
|
|
22404
22404
|
const css = require_bundle_state.stripBundlerGeneratedCssMarkers(sourceCss).trim();
|
|
22405
|
-
if (css.length === 0
|
|
22405
|
+
if (css.length === 0) continue;
|
|
22406
|
+
const mergedLayerCss = require_incremental_runtime_class_set.mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
22407
|
+
if (mergedLayerCss.merged) {
|
|
22408
|
+
nextCss = mergedLayerCss.css;
|
|
22409
|
+
continue;
|
|
22410
|
+
}
|
|
22411
|
+
if (nextCss.includes(css)) continue;
|
|
22406
22412
|
nextCss = appendCss(nextCss, css);
|
|
22407
22413
|
}
|
|
22408
22414
|
if (nextCss === originalSource) continue;
|
|
@@ -24218,6 +24224,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
24218
24224
|
if (!generated) return;
|
|
24219
24225
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
24220
24226
|
viteGeneratedCssByFile.set(file, generated.css);
|
|
24227
|
+
if (generated.css.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, generated.css);
|
|
24221
24228
|
markViteProcessedCssSource(file);
|
|
24222
24229
|
rememberTailwindRootCssModule(id);
|
|
24223
24230
|
recordGeneratorCandidates(runtime);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { C as __esmMin, S as __commonJSMin, _ as toCustomAttributesEntities, a as vitePluginName, c as createAttributeMatcher, d as _defineProperty, f as init_defineProperty, h as babelParse, l as analyzeSource, m as replaceWxml, n as getCompilerContext, p as isClassContextLiteralPath, s as generateCode, t as shouldSkipJsTransform, u as JsTokenUpdater, v as collectRuntimeClassSet, w as __require, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-D7K12zeX.mjs";
|
|
2
2
|
import { B as createDebug, E as filterUnsupportedMiniProgramTailwindV4Candidates, J as findNearestPackageRoot, U as findTailwindConfig, W as resolveTailwindcssOptions, _ as resolveViteSourceScanEntries, g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as createViteSourceScanMatcher, q as omitUndefined, v as resolveViteTailwindV4CssDependencies } from "./v3-engine-DcvCCHfs.mjs";
|
|
3
3
|
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Qw-tZ0Z2.mjs";
|
|
4
|
-
import { a as validateCandidatesByGenerator, c as
|
|
4
|
+
import { a as validateCandidatesByGenerator, c as hasTailwindRootDirectives, d as hasTailwindGeneratedCssMarkers, i as generateCssByGenerator, l as hasTailwindSourceDirectives, n as createHmrTimingRecorder, o as mergeMarkedUserLayerComponentsCss, s as processCachedTask, t as createBundleRuntimeClassSetManager, u as normalizeTailwindSourceForGenerator } from "./incremental-runtime-class-set-Boqi1QlB.mjs";
|
|
5
5
|
import { o as resolveUniUtsPlatform } from "./utils-DsaS975I.mjs";
|
|
6
6
|
import { c as upsertTailwindV4CssSource, i as resolveUniAppXOptions, r as isUniAppXEnabled, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C7dJHZ0G.mjs";
|
|
7
7
|
import { n as isSourceCandidateRequest, t as createSourceCandidateCollector } from "./source-candidates-CX2ozpKM.mjs";
|
|
@@ -22380,7 +22380,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
22380
22380
|
return collected;
|
|
22381
22381
|
}
|
|
22382
22382
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
22383
|
-
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].filter(([
|
|
22383
|
+
const viteCssResults = [...options.getViteProcessedCssAssetResults?.() ?? []].filter(([, css]) => css.length > 0);
|
|
22384
22384
|
if (viteCssResults.length === 0) return 0;
|
|
22385
22385
|
let injected = 0;
|
|
22386
22386
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -22393,7 +22393,13 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
22393
22393
|
for (const [sourceFile, sourceCss] of viteCssResults) {
|
|
22394
22394
|
if (normalizeOutputPathKey(sourceFile) === mainFileKey || options.opts.mainCssChunkMatcher(sourceFile, options.opts.appType)) continue;
|
|
22395
22395
|
const css = stripBundlerGeneratedCssMarkers(sourceCss).trim();
|
|
22396
|
-
if (css.length === 0
|
|
22396
|
+
if (css.length === 0) continue;
|
|
22397
|
+
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
22398
|
+
if (mergedLayerCss.merged) {
|
|
22399
|
+
nextCss = mergedLayerCss.css;
|
|
22400
|
+
continue;
|
|
22401
|
+
}
|
|
22402
|
+
if (nextCss.includes(css)) continue;
|
|
22397
22403
|
nextCss = appendCss(nextCss, css);
|
|
22398
22404
|
}
|
|
22399
22405
|
if (nextCss === originalSource) continue;
|
|
@@ -24209,6 +24215,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
24209
24215
|
if (!generated) return;
|
|
24210
24216
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
24211
24217
|
viteGeneratedCssByFile.set(file, generated.css);
|
|
24218
|
+
if (generated.css.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, generated.css);
|
|
24212
24219
|
markViteProcessedCssSource(file);
|
|
24213
24220
|
rememberTailwindRootCssModule(id);
|
|
24214
24221
|
recordGeneratorCandidates(runtime);
|
package/dist/vite.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_vite = require("./vite-
|
|
2
|
+
const require_vite = require("./vite-BgTPSkQS.js");
|
|
3
3
|
exports.WeappTailwindcss = require_vite.WeappTailwindcss;
|
|
4
4
|
exports.weappTailwindcss = require_vite.WeappTailwindcss;
|
package/dist/vite.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as WeappTailwindcss } from "./vite-
|
|
1
|
+
import { t as WeappTailwindcss } from "./vite-fFRpSvyz.mjs";
|
|
2
2
|
export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss };
|
|
@@ -3272,6 +3272,11 @@ const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?
|
|
|
3272
3272
|
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
3273
3273
|
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
3274
3274
|
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
3275
|
+
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
3276
|
+
["tailwindcss/base", "base"],
|
|
3277
|
+
["tailwindcss/components", "components"],
|
|
3278
|
+
["tailwindcss/utilities", "utilities"]
|
|
3279
|
+
]);
|
|
3275
3280
|
function parseImportRequest(params) {
|
|
3276
3281
|
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
3277
3282
|
}
|
|
@@ -3451,6 +3456,24 @@ function hasPreprocessorOnlySyntax(rawSource) {
|
|
|
3451
3456
|
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
3452
3457
|
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
3453
3458
|
}
|
|
3459
|
+
function normalizeTailwindV3CssEntrySource(rawSource) {
|
|
3460
|
+
try {
|
|
3461
|
+
const root = require_runtime_registry.postcss_default.parse(rawSource);
|
|
3462
|
+
let changed = false;
|
|
3463
|
+
root.walkAtRules("import", (node) => {
|
|
3464
|
+
const layer = TAILWIND_V3_SUBPATH_IMPORT_LAYERS.get(parseImportRequest(node.params) ?? "");
|
|
3465
|
+
if (!layer) return;
|
|
3466
|
+
node.replaceWith(require_runtime_registry.postcss_default.atRule({
|
|
3467
|
+
name: "tailwind",
|
|
3468
|
+
params: layer
|
|
3469
|
+
}));
|
|
3470
|
+
changed = true;
|
|
3471
|
+
});
|
|
3472
|
+
return changed ? root.toString() : rawSource;
|
|
3473
|
+
} catch {
|
|
3474
|
+
return rawSource;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3454
3477
|
function normalizeTailwindSourceDirectives(rawSource, options = {}) {
|
|
3455
3478
|
if (!options.importFallback) return rawSource;
|
|
3456
3479
|
try {
|
|
@@ -4332,14 +4355,14 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
4332
4355
|
css: rawSource
|
|
4333
4356
|
} : void 0;
|
|
4334
4357
|
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
4335
|
-
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ?
|
|
4358
|
+
const resolvedEntrySource = shouldResolveSourceSideCssEntry(rawSource) ? cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource : shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) ? sourceSideEntrySource ?? cssEntrySource : cssEntrySource ?? applyEntrySource ?? sourceSideEntrySource;
|
|
4336
4359
|
if (!resolvedEntrySource) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
4337
4360
|
if (cssEntrySource && !sourceSideEntrySource && !applyEntrySource && !hasTailwindRootDirectives(rawSource, { importFallback: true })) return generatorOptions?.config ? resolveTailwindV3Source(mergedSourceOptions) : resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
4338
4361
|
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, omitUndefined(mergedSourceOptions));
|
|
4339
4362
|
return resolveTailwindV3Source({
|
|
4340
4363
|
...mergedSourceOptions,
|
|
4341
4364
|
base: resolvedEntrySource.base,
|
|
4342
|
-
css: resolvedEntrySource.css,
|
|
4365
|
+
css: normalizeTailwindV3CssEntrySource(resolvedEntrySource.css),
|
|
4343
4366
|
...config ? { config } : {}
|
|
4344
4367
|
});
|
|
4345
4368
|
}
|
|
@@ -4686,6 +4709,71 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
4686
4709
|
}
|
|
4687
4710
|
}
|
|
4688
4711
|
//#endregion
|
|
4712
|
+
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
4713
|
+
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
4714
|
+
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
4715
|
+
const UTILITY_LAYER_INSERTION_RES = [
|
|
4716
|
+
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
4717
|
+
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
4718
|
+
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
4719
|
+
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
4720
|
+
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
4721
|
+
];
|
|
4722
|
+
function appendCss(base, extra) {
|
|
4723
|
+
if (!base) return extra;
|
|
4724
|
+
if (!extra) return base;
|
|
4725
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
4726
|
+
return `${base}\n${extra}`;
|
|
4727
|
+
}
|
|
4728
|
+
function wrapUserLayerComponentsCss(css) {
|
|
4729
|
+
return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
|
|
4730
|
+
}
|
|
4731
|
+
function extractMarkedUserLayerComponentsCss(css) {
|
|
4732
|
+
const layers = [];
|
|
4733
|
+
let rest = "";
|
|
4734
|
+
let cursor = 0;
|
|
4735
|
+
while (cursor < css.length) {
|
|
4736
|
+
const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
|
|
4737
|
+
if (startIndex === -1) {
|
|
4738
|
+
rest += css.slice(cursor);
|
|
4739
|
+
break;
|
|
4740
|
+
}
|
|
4741
|
+
rest += css.slice(cursor, startIndex);
|
|
4742
|
+
const contentStart = startIndex + 47;
|
|
4743
|
+
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
4744
|
+
if (endIndex === -1) {
|
|
4745
|
+
rest += css.slice(startIndex);
|
|
4746
|
+
break;
|
|
4747
|
+
}
|
|
4748
|
+
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
4749
|
+
if (layerCss) layers.push(layerCss);
|
|
4750
|
+
cursor = endIndex + 45;
|
|
4751
|
+
}
|
|
4752
|
+
return {
|
|
4753
|
+
layers,
|
|
4754
|
+
rest
|
|
4755
|
+
};
|
|
4756
|
+
}
|
|
4757
|
+
function findUtilityLayerInsertionIndex(css) {
|
|
4758
|
+
let index = -1;
|
|
4759
|
+
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
4760
|
+
const match = pattern.exec(css);
|
|
4761
|
+
if (!match) continue;
|
|
4762
|
+
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
4763
|
+
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
4764
|
+
}
|
|
4765
|
+
return index;
|
|
4766
|
+
}
|
|
4767
|
+
function reorderMarkedUserLayerComponentsCss(css) {
|
|
4768
|
+
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
4769
|
+
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
4770
|
+
if (layers.length === 0) return rest;
|
|
4771
|
+
const layerCss = layers.join("\n");
|
|
4772
|
+
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
4773
|
+
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
4774
|
+
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
4775
|
+
}
|
|
4776
|
+
//#endregion
|
|
4689
4777
|
//#region src/bundlers/shared/generator-css.ts
|
|
4690
4778
|
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
4691
4779
|
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
@@ -4759,6 +4847,9 @@ function createCssSourceOrderAppend(base, extra) {
|
|
|
4759
4847
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
4760
4848
|
return `${base}\n${extra}`;
|
|
4761
4849
|
}
|
|
4850
|
+
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
4851
|
+
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
4852
|
+
}
|
|
4762
4853
|
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
4763
4854
|
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
4764
4855
|
if (placeholderParts) return placeholderParts;
|
|
@@ -4766,6 +4857,84 @@ function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
|
4766
4857
|
if (exactParts) return exactParts;
|
|
4767
4858
|
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
4768
4859
|
}
|
|
4860
|
+
function splitUserCssLayerBlocks(source) {
|
|
4861
|
+
if (!source.includes("@layer")) return {
|
|
4862
|
+
layer: "",
|
|
4863
|
+
rest: source
|
|
4864
|
+
};
|
|
4865
|
+
try {
|
|
4866
|
+
const root = require_runtime_registry.postcss_default.parse(source);
|
|
4867
|
+
const layerRoot = require_runtime_registry.postcss_default.root();
|
|
4868
|
+
const restRoot = require_runtime_registry.postcss_default.root();
|
|
4869
|
+
for (const node of root.nodes) (node.type === "atrule" && node.name === "layer" && node.nodes?.length ? layerRoot : restRoot).append(node.clone());
|
|
4870
|
+
return {
|
|
4871
|
+
layer: layerRoot.toString(),
|
|
4872
|
+
rest: restRoot.toString()
|
|
4873
|
+
};
|
|
4874
|
+
} catch {
|
|
4875
|
+
return {
|
|
4876
|
+
layer: source,
|
|
4877
|
+
rest: ""
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
function hasUserCssLayerBlocks(source) {
|
|
4882
|
+
if (!source.includes("@layer")) return false;
|
|
4883
|
+
try {
|
|
4884
|
+
let hasLayerBlock = false;
|
|
4885
|
+
require_runtime_registry.postcss_default.parse(source).walkAtRules("layer", (node) => {
|
|
4886
|
+
if (node.nodes?.length) hasLayerBlock = true;
|
|
4887
|
+
});
|
|
4888
|
+
return hasLayerBlock;
|
|
4889
|
+
} catch {
|
|
4890
|
+
return true;
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
function collectUserLayerSelectors(source) {
|
|
4894
|
+
const selectors = /* @__PURE__ */ new Set();
|
|
4895
|
+
try {
|
|
4896
|
+
require_runtime_registry.postcss_default.parse(source).walkRules((rule) => {
|
|
4897
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
4898
|
+
const normalized = selector.trim();
|
|
4899
|
+
if (normalized) selectors.add(normalized);
|
|
4900
|
+
}
|
|
4901
|
+
});
|
|
4902
|
+
} catch {}
|
|
4903
|
+
return selectors;
|
|
4904
|
+
}
|
|
4905
|
+
function matchesUserLayerSelector(selector, userLayerSelector) {
|
|
4906
|
+
if (selector === userLayerSelector) return true;
|
|
4907
|
+
if (!selector.startsWith(userLayerSelector)) return false;
|
|
4908
|
+
const next = selector[userLayerSelector.length];
|
|
4909
|
+
return next === ":" || next === "[";
|
|
4910
|
+
}
|
|
4911
|
+
function extractGeneratedCssForUserLayerSelectors(css, userLayerSource) {
|
|
4912
|
+
const selectors = collectUserLayerSelectors(userLayerSource);
|
|
4913
|
+
if (selectors.size === 0) return {
|
|
4914
|
+
layer: "",
|
|
4915
|
+
rest: css
|
|
4916
|
+
};
|
|
4917
|
+
try {
|
|
4918
|
+
const root = require_runtime_registry.postcss_default.parse(css);
|
|
4919
|
+
const layerRoot = require_runtime_registry.postcss_default.root();
|
|
4920
|
+
const selectorList = [...selectors];
|
|
4921
|
+
root.walkRules((rule) => {
|
|
4922
|
+
if ((rule.selectors ?? [rule.selector]).some((selector) => selectorList.some((userSelector) => matchesUserLayerSelector(selector.trim(), userSelector)))) {
|
|
4923
|
+
layerRoot.append(rule.clone());
|
|
4924
|
+
rule.remove();
|
|
4925
|
+
}
|
|
4926
|
+
});
|
|
4927
|
+
return {
|
|
4928
|
+
layer: layerRoot.toString(),
|
|
4929
|
+
rest: root.toString()
|
|
4930
|
+
};
|
|
4931
|
+
} catch {
|
|
4932
|
+
return {
|
|
4933
|
+
layer: "",
|
|
4934
|
+
rest: css
|
|
4935
|
+
};
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
4769
4938
|
async function transformGeneratorUserCss(source, options) {
|
|
4770
4939
|
if (source.trim().length === 0) return "";
|
|
4771
4940
|
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
@@ -4894,7 +5063,7 @@ async function generateCssByGenerator(options) {
|
|
|
4894
5063
|
sources: generatedResults.flatMap((item) => item.sources)
|
|
4895
5064
|
};
|
|
4896
5065
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
4897
|
-
if (typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
5066
|
+
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(effectiveRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
4898
5067
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
4899
5068
|
return {
|
|
4900
5069
|
css: incrementalCss.trim().length > 0 ? createCssAppend(options.previousCss, finalizeMiniProgramGeneratorCss(incrementalCss, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: false })) : options.previousCss,
|
|
@@ -4916,9 +5085,14 @@ async function generateCssByGenerator(options) {
|
|
|
4916
5085
|
styleHandler,
|
|
4917
5086
|
importFallback: generatorOptions.importFallback
|
|
4918
5087
|
};
|
|
5088
|
+
const afterLayerParts = generated.target === "weapp" ? splitUserCssLayerBlocks(orderedExtraCss.after) : {
|
|
5089
|
+
layer: "",
|
|
5090
|
+
rest: orderedExtraCss.after
|
|
5091
|
+
};
|
|
4919
5092
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
4920
|
-
const
|
|
4921
|
-
|
|
5093
|
+
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
5094
|
+
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
5095
|
+
css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
4922
5096
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
4923
5097
|
hasSourceDirectives,
|
|
4924
5098
|
hasMatchedCssSourceFile
|
|
@@ -4927,6 +5101,7 @@ async function generateCssByGenerator(options) {
|
|
|
4927
5101
|
css = createCssSourceOrderAppend(css, userCss);
|
|
4928
5102
|
}
|
|
4929
5103
|
if (generated.target === "weapp") {
|
|
5104
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
4930
5105
|
css = await appendLegacyCompatCss(css, effectiveRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
4931
5106
|
css = await appendLegacyContainerCompatCss(css, effectiveRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
4932
5107
|
}
|
|
@@ -4939,7 +5114,27 @@ async function generateCssByGenerator(options) {
|
|
|
4939
5114
|
}
|
|
4940
5115
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
4941
5116
|
let css = stripTailwindBanner(generated.css);
|
|
4942
|
-
if (generated.target === "weapp")
|
|
5117
|
+
if (generated.target === "weapp") {
|
|
5118
|
+
css = inheritLegacyUnitConvertedDeclarations(css, effectiveRawSource);
|
|
5119
|
+
if (hasUserCssLayerBlocks(effectiveRawSource)) {
|
|
5120
|
+
const layerParts = splitUserCssLayerBlocks(effectiveRawSource);
|
|
5121
|
+
const layerUserCss = await transformGeneratorUserCss(layerParts.layer, {
|
|
5122
|
+
generatorTarget: generated.target,
|
|
5123
|
+
generatorStyleOptions,
|
|
5124
|
+
cssUserHandlerOptions,
|
|
5125
|
+
styleHandler,
|
|
5126
|
+
importFallback: generatorOptions.importFallback
|
|
5127
|
+
});
|
|
5128
|
+
const layerCss = layerUserCss.trim().length > 0 && !hasTailwindApplyDirective(layerUserCss) ? {
|
|
5129
|
+
layer: layerUserCss,
|
|
5130
|
+
rest: css
|
|
5131
|
+
} : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
|
|
5132
|
+
if (layerCss.layer.trim().length > 0) {
|
|
5133
|
+
css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
5134
|
+
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5135
|
+
}
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
4943
5138
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
4944
5139
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
4945
5140
|
hasSourceDirectives,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-C5U5_Hdc.js");
|
|
2
2
|
const require_v3_engine = require("./v3-engine-CHItlVq5.js");
|
|
3
3
|
const require_generator = require("./generator-CrU-Ghc1.js");
|
|
4
|
-
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-
|
|
4
|
+
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-FAOHZmzh.js");
|
|
5
5
|
const require_precheck = require("./precheck-D7gJSmJz.js");
|
|
6
6
|
const require_utils = require("./utils-D7Ygohep.js");
|
|
7
7
|
const require_tailwindcss = require("./tailwindcss-B-e2RiXr.js");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { b as ensureRuntimeClassSet, d as _defineProperty, f as init_defineProperty, i as pluginName, n as getCompilerContext, t as shouldSkipJsTransform, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-D7K12zeX.mjs";
|
|
2
2
|
import { B as createDebug, W as resolveTailwindcssOptions, l as getRuntimeClassSetSignature } from "./v3-engine-DcvCCHfs.mjs";
|
|
3
3
|
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Qw-tZ0Z2.mjs";
|
|
4
|
-
import { i as generateCssByGenerator,
|
|
4
|
+
import { i as generateCssByGenerator, r as emitHmrTiming, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-Boqi1QlB.mjs";
|
|
5
5
|
import { r as getGroupedEntries } from "./utils-DsaS975I.mjs";
|
|
6
6
|
import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C7dJHZ0G.mjs";
|
|
7
7
|
import { _ as stripRequestQuery, b as toAbsoluteOutputPath, d as resolvePluginDisabledState, g as isSourceStyleRequest, l as stripBundlerGeneratedCssMarkers, n as createBundleBuildState, o as pushConcurrentTaskFactories, r as updateBundleBuildState, t as buildBundleSnapshot, u as resolvePackageDir, y as resolveOutputSpecifier } from "./bundle-state-Bi-cQua6.mjs";
|
package/dist/webpack.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_webpack = require("./webpack-
|
|
2
|
+
const require_webpack = require("./webpack-BXSWVdXh.js");
|
|
3
3
|
exports.WeappTailwindcss = require_webpack.WeappTailwindcss;
|
|
4
4
|
exports.weappTailwindcss = require_webpack.WeappTailwindcss;
|
|
5
5
|
exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
|
package/dist/webpack.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as weappTailwindcssPackageDir, t as WeappTailwindcss } from "./webpack-
|
|
1
|
+
import { n as weappTailwindcssPackageDir, t as WeappTailwindcss } from "./webpack-Dx2AZpGU.mjs";
|
|
2
2
|
export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss, weappTailwindcssPackageDir };
|
package/package.json
CHANGED