weapp-tailwindcss 5.0.5 → 5.0.7
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/{bundle-state-Cso_ceUo.js → bundle-state-BzwPS-UI.js} +2 -1
- package/dist/{bundle-state-DEyxCR4f.mjs → bundle-state-ChcOKb9w.mjs} +2 -1
- package/dist/bundlers/gulp/index.d.ts +3 -4
- package/dist/bundlers/gulp/module-graph.d.ts +2 -0
- package/dist/bundlers/gulp/runtime-snapshot.d.ts +5 -0
- package/dist/bundlers/gulp/vinyl-transform.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/css-source-trace.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/directives/fallback.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +56 -0
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +27 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +26 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +4 -32
- package/dist/bundlers/vite/css-finalizer.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/css-config-directives.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +14 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +11 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/style-matching.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/subpackages.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +68 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +4 -62
- package/dist/bundlers/vite/incremental-runtime-class-set/entries.d.ts +4 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +2 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +13 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +17 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/scan-root.d.ts +10 -0
- package/dist/bundlers/vite/source-candidates/script.d.ts +7 -0
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +1 -0
- package/dist/bundlers/vite/source-candidates.d.ts +8 -3
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +20 -0
- package/dist/bundlers/vite/source-scan/dependencies.d.ts +2 -0
- package/dist/bundlers/vite/source-scan.d.ts +2 -12
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -20
- package/dist/cli.js +69 -69
- package/dist/cli.mjs +69 -69
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{defaults-BPUuNYcD.js → defaults-Boc26eel.js} +1 -0
- package/dist/{defaults-8xrgzxFY.mjs → defaults-DH0ZQRhy.mjs} +1 -0
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-AD-eX8Tr.js → generator-6yF8wjxR.js} +1 -1
- package/dist/{generator-DVWLNO0n.mjs → generator-BON6M1bL.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp-_7p1Z2vc.js +473 -0
- package/dist/gulp-oE-Byqk6.mjs +463 -0
- package/dist/gulp.js +4 -414
- package/dist/gulp.mjs +1 -406
- package/dist/{incremental-runtime-class-set-vOetpdWs.js → hmr-timing-BKQNRxHr.js} +1257 -459
- package/dist/{incremental-runtime-class-set-xf49kky6.mjs → hmr-timing-BVTGf5ch.mjs} +1221 -477
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/dist/{postcss-Cbi6RFpf.js → postcss-BTIunhWl.js} +7 -7
- package/dist/{postcss-hSUxK7oR.mjs → postcss-BtmrrZ31.mjs} +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-Bsn_LMmo.mjs → precheck-CZjr87m_.mjs} +19 -5
- package/dist/{precheck-b8Y8qZg0.js → precheck-fhIkzCSU.js} +19 -5
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/tailwindcss/source-scan/inline-source.d.ts +7 -0
- package/dist/tailwindcss/source-scan.d.ts +2 -7
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +3 -0
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +10 -0
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +6 -0
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/{tailwindcss-AWaPVF2B.mjs → tailwindcss-bbQUg25J.mjs} +2 -2
- package/dist/{tailwindcss-CpQ6X4l6.js → tailwindcss-vswd1gc3.js} +2 -2
- package/dist/{transform-BkGtbxb1.js → transform-CReJxxh_.js} +11 -2
- package/dist/{transform-DumSZmTh.mjs → transform-DEsFlG9k.mjs} +11 -2
- package/dist/types/typedoc-tailwindcss-patch.d.ts +4 -2
- package/dist/types/user-defined-options/general.d.ts +5 -0
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/harmony.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +16 -0
- package/dist/uni-app-x/style-asset.d.ts +20 -0
- package/dist/uni-app-x/transform.d.ts +1 -0
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v3-engine-CM0TRa8V.js → v3-engine-CEMXFegG.js} +714 -663
- package/dist/{v3-engine-Cczrkzqt.mjs → v3-engine-CdIwmHuc.mjs} +758 -707
- package/dist/{vite-CTuHPC91.js → vite-0jFbh9hx.js} +1797 -386
- package/dist/{vite-DLXDMHON.mjs → vite-C7BGAlCE.mjs} +1779 -369
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +1169 -1002
- package/dist/{webpack-DJFw08SK.mjs → webpack-Dx6_eg5k.mjs} +96 -36
- package/dist/{webpack-BBHJYKqB.js → webpack-aEuDoYfQ.js} +105 -44
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -5
- package/dist/source-candidates-BsWYoIPN.mjs +0 -355
- package/dist/source-candidates-o2ZrKWzu.js +0 -374
|
@@ -20,9 +20,9 @@ let node_url = require("node:url");
|
|
|
20
20
|
let debug = require("debug");
|
|
21
21
|
debug = require_watch_dependencies.__toESM(debug);
|
|
22
22
|
let node_fs_promises = require("node:fs/promises");
|
|
23
|
+
require("micromatch");
|
|
23
24
|
require("fast-glob");
|
|
24
25
|
let tailwindcss_config = require("tailwindcss-config");
|
|
25
|
-
require("micromatch");
|
|
26
26
|
let _weapp_core_escape = require("@weapp-core/escape");
|
|
27
27
|
require("magic-string");
|
|
28
28
|
let _babel_traverse = require("@babel/traverse");
|
|
@@ -63,66 +63,6 @@ function createBundlerGeneratedCssMarker(bundler, file) {
|
|
|
63
63
|
return `/*! weapp-tailwindcss ${bundler}-generated-css:${encodeURIComponent(file)} */`;
|
|
64
64
|
}
|
|
65
65
|
//#endregion
|
|
66
|
-
//#region src/uni-app-x/options.ts
|
|
67
|
-
const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
|
|
68
|
-
enabled: true,
|
|
69
|
-
onlyWhenStyleIsolationVersion2: true
|
|
70
|
-
};
|
|
71
|
-
const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
|
|
72
|
-
enabled: false,
|
|
73
|
-
onlyWhenStyleIsolationVersion2: true
|
|
74
|
-
};
|
|
75
|
-
function isBooleanUniAppXShortcut(option) {
|
|
76
|
-
return option === true || option === false || option === void 0;
|
|
77
|
-
}
|
|
78
|
-
function resolveComponentLocalStyles(option) {
|
|
79
|
-
if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
80
|
-
const componentLocalStyles = option.componentLocalStyles;
|
|
81
|
-
if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
82
|
-
if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
83
|
-
return {
|
|
84
|
-
enabled: componentLocalStyles.enabled !== false,
|
|
85
|
-
onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
function resolveUniAppXOptions(option) {
|
|
89
|
-
if (typeof option === "object" && option) return {
|
|
90
|
-
enabled: option.enabled !== false,
|
|
91
|
-
componentLocalStyles: resolveComponentLocalStyles(option),
|
|
92
|
-
uvueUnsupported: option.uvueUnsupported ?? "warn"
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
enabled: Boolean(option),
|
|
96
|
-
componentLocalStyles: resolveComponentLocalStyles(option),
|
|
97
|
-
uvueUnsupported: "warn"
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
function isUniAppXEnabled(option) {
|
|
101
|
-
return resolveUniAppXOptions(option).enabled;
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
104
|
-
//#region src/context/style-options.ts
|
|
105
|
-
function resolveStyleOptionsFromContext(ctx) {
|
|
106
|
-
const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
|
|
107
|
-
return {
|
|
108
|
-
cssPreflight: ctx.cssPreflight,
|
|
109
|
-
cssPreflightRange: ctx.cssPreflightRange,
|
|
110
|
-
cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
|
|
111
|
-
cssSelectorReplacement: ctx.cssSelectorReplacement,
|
|
112
|
-
rem2rpx: ctx.rem2rpx,
|
|
113
|
-
cssRemoveProperty: ctx.cssRemoveProperty,
|
|
114
|
-
cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
|
|
115
|
-
cssPresetEnv: ctx.cssPresetEnv,
|
|
116
|
-
autoprefixer: ctx.autoprefixer,
|
|
117
|
-
cssCalc: ctx.cssCalc,
|
|
118
|
-
uniAppX: resolvedUniAppXOptions.enabled,
|
|
119
|
-
platform: ctx.platform,
|
|
120
|
-
px2rpx: ctx.px2rpx,
|
|
121
|
-
unitsToPx: ctx.unitsToPx,
|
|
122
|
-
unitConversion: ctx.unitConversion
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
//#endregion
|
|
126
66
|
//#region src/css-macro/constants.ts
|
|
127
67
|
const queryKey = "weapp-tw-platform";
|
|
128
68
|
const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
|
|
@@ -465,6 +405,169 @@ async function transformCssMacroCss(css, options) {
|
|
|
465
405
|
return compileCssMacroConditionalComments(result, options);
|
|
466
406
|
}
|
|
467
407
|
//#endregion
|
|
408
|
+
//#region src/utils/object.ts
|
|
409
|
+
function definedEntries(value) {
|
|
410
|
+
return Object.entries(value).filter(([, item]) => item !== void 0);
|
|
411
|
+
}
|
|
412
|
+
function omitUndefined(value) {
|
|
413
|
+
return Object.fromEntries(definedEntries(value));
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/tailwindcss/v3-engine/generator/content.ts
|
|
417
|
+
function isLegacyContentObject$1(value) {
|
|
418
|
+
return typeof value === "object" && value !== null && "files" in value;
|
|
419
|
+
}
|
|
420
|
+
function createRawContentEntries(candidates, sources) {
|
|
421
|
+
const entries = [];
|
|
422
|
+
const candidateContent = [...candidates].join(" ");
|
|
423
|
+
if (candidateContent.length > 0) entries.push({
|
|
424
|
+
raw: candidateContent,
|
|
425
|
+
extension: "html"
|
|
426
|
+
});
|
|
427
|
+
for (const source of sources) entries.push({
|
|
428
|
+
raw: source.content,
|
|
429
|
+
extension: source.extension ?? "html"
|
|
430
|
+
});
|
|
431
|
+
return entries;
|
|
432
|
+
}
|
|
433
|
+
function createChangedContentEntries(candidates, sources) {
|
|
434
|
+
return createRawContentEntries(candidates, sources).map((entry) => ({
|
|
435
|
+
content: entry.raw,
|
|
436
|
+
extension: entry.extension
|
|
437
|
+
}));
|
|
438
|
+
}
|
|
439
|
+
function collectCandidates$1(candidates) {
|
|
440
|
+
return new Set(candidates ?? []);
|
|
441
|
+
}
|
|
442
|
+
function collectApplyCandidatesFromCss(css) {
|
|
443
|
+
if (!css.includes("@apply")) return [];
|
|
444
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
445
|
+
try {
|
|
446
|
+
require_watch_dependencies.postcss_default.parse(css).walkAtRules("apply", (rule) => {
|
|
447
|
+
for (const candidate of rule.params.split(/\s+/)) {
|
|
448
|
+
const normalized = candidate.replace(/!important$/, "").trim();
|
|
449
|
+
if (normalized) candidates.add(normalized);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
} catch {}
|
|
453
|
+
return [...candidates];
|
|
454
|
+
}
|
|
455
|
+
function isTailwindCandidateLayer(params) {
|
|
456
|
+
return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
|
|
457
|
+
}
|
|
458
|
+
function extractClassCandidatesFromSelector(selector, candidates) {
|
|
459
|
+
for (let index = 0; index < selector.length; index++) {
|
|
460
|
+
if (selector[index] !== ".") continue;
|
|
461
|
+
let candidate = "";
|
|
462
|
+
let escaped = false;
|
|
463
|
+
for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
|
|
464
|
+
const char = selector[tokenIndex];
|
|
465
|
+
if (escaped) {
|
|
466
|
+
candidate += char;
|
|
467
|
+
escaped = false;
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
if (char === "\\") {
|
|
471
|
+
escaped = true;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (char && /[\w-]/.test(char)) {
|
|
475
|
+
candidate += char;
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
if (candidate) candidates.add(candidate);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function collectLayerCandidatesFromCss(css) {
|
|
484
|
+
if (!css.includes("@layer")) return [];
|
|
485
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
486
|
+
try {
|
|
487
|
+
require_watch_dependencies.postcss_default.parse(css).walkAtRules("layer", (layer) => {
|
|
488
|
+
if (!isTailwindCandidateLayer(layer.params)) return;
|
|
489
|
+
layer.walkRules((rule) => {
|
|
490
|
+
extractClassCandidatesFromSelector(rule.selector, candidates);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
} catch {}
|
|
494
|
+
return [...candidates];
|
|
495
|
+
}
|
|
496
|
+
function mergeGenerateCandidates(source, options) {
|
|
497
|
+
return collectCandidates$1([
|
|
498
|
+
...collectLayerCandidatesFromCss(source.css),
|
|
499
|
+
...collectApplyCandidatesFromCss(source.css),
|
|
500
|
+
...collectCandidates$1(options.candidates)
|
|
501
|
+
]);
|
|
502
|
+
}
|
|
503
|
+
function mergeContent(content, rawEntries) {
|
|
504
|
+
if (isLegacyContentObject$1(content)) return {
|
|
505
|
+
...content,
|
|
506
|
+
relative: content.relative ?? true,
|
|
507
|
+
files: [...[].concat(content.files ?? []), ...rawEntries]
|
|
508
|
+
};
|
|
509
|
+
return {
|
|
510
|
+
relative: true,
|
|
511
|
+
files: [...[].concat(content ?? []), ...rawEntries]
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function normalizeConfigObject(config) {
|
|
515
|
+
if (!config || typeof config !== "object") return config;
|
|
516
|
+
const maybeDefault = config.default;
|
|
517
|
+
if (maybeDefault && typeof maybeDefault === "object") return maybeDefault;
|
|
518
|
+
return config;
|
|
519
|
+
}
|
|
520
|
+
function hasExplicitContentInput(options) {
|
|
521
|
+
return options.candidates !== void 0 || options.sources !== void 0;
|
|
522
|
+
}
|
|
523
|
+
function createExplicitContentConfig(rawEntries) {
|
|
524
|
+
return {
|
|
525
|
+
relative: true,
|
|
526
|
+
files: rawEntries
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function createTailwindConfig(source, options) {
|
|
530
|
+
const config = { ...normalizeConfigObject(source.configObject) ?? {} };
|
|
531
|
+
const rawEntries = createRawContentEntries(mergeGenerateCandidates(source, options), options.sources ?? []);
|
|
532
|
+
config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
|
|
533
|
+
return config;
|
|
534
|
+
}
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/tailwindcss/v3-engine/generator/cache-key.ts
|
|
537
|
+
function createStableJson$2(value) {
|
|
538
|
+
if (value === void 0) return "undefined";
|
|
539
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
540
|
+
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$2(item)).join(",")}]`;
|
|
541
|
+
return `{${Object.keys(value).sort().map((key) => {
|
|
542
|
+
const record = value;
|
|
543
|
+
return `${JSON.stringify(key)}:${createStableJson$2(record[key])}`;
|
|
544
|
+
}).join(",")}}`;
|
|
545
|
+
}
|
|
546
|
+
function createDependencyFingerprint$1(files) {
|
|
547
|
+
return files.map((file) => {
|
|
548
|
+
try {
|
|
549
|
+
const stat = node_fs.default.statSync(file);
|
|
550
|
+
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
551
|
+
} catch {
|
|
552
|
+
return `${file}:missing`;
|
|
553
|
+
}
|
|
554
|
+
}).join("|");
|
|
555
|
+
}
|
|
556
|
+
function createIncrementalGenerateCacheKey$1(source, target, styleOptions, bareArbitraryValues) {
|
|
557
|
+
return [
|
|
558
|
+
source.packageName,
|
|
559
|
+
source.postcssPlugin,
|
|
560
|
+
source.cwd,
|
|
561
|
+
source.config ?? "config:missing",
|
|
562
|
+
createDependencyFingerprint$1(source.dependencies),
|
|
563
|
+
source.css,
|
|
564
|
+
createStableJson$2(normalizeConfigObject(source.configObject)?.content),
|
|
565
|
+
target,
|
|
566
|
+
createStableJson$2(styleOptions),
|
|
567
|
+
createStableJson$2(bareArbitraryValues)
|
|
568
|
+
].join("\0");
|
|
569
|
+
}
|
|
570
|
+
//#endregion
|
|
468
571
|
//#region src/context/workspace.ts
|
|
469
572
|
function findWorkspaceRoot(startDir) {
|
|
470
573
|
if (!startDir) return;
|
|
@@ -487,14 +590,6 @@ function findNearestPackageRoot(startDir) {
|
|
|
487
590
|
}
|
|
488
591
|
}
|
|
489
592
|
//#endregion
|
|
490
|
-
//#region src/utils/object.ts
|
|
491
|
-
function definedEntries(value) {
|
|
492
|
-
return Object.entries(value).filter(([, item]) => item !== void 0);
|
|
493
|
-
}
|
|
494
|
-
function omitUndefined(value) {
|
|
495
|
-
return Object.fromEntries(definedEntries(value));
|
|
496
|
-
}
|
|
497
|
-
//#endregion
|
|
498
593
|
//#region src/utils/options.ts
|
|
499
594
|
function resolveBooleanObjectOption(value, enabledValue) {
|
|
500
595
|
if (!value) return false;
|
|
@@ -665,7 +760,7 @@ function createTailwindcssPatcher(options) {
|
|
|
665
760
|
const resolvedTailwindOptions = resolvedOptions.tailwindcss;
|
|
666
761
|
if (resolvedTailwindOptions) {
|
|
667
762
|
const existingResolve = resolvedTailwindOptions.resolve ?? {};
|
|
668
|
-
const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths, ...resolvePaths] : resolvePaths;
|
|
763
|
+
const sourcePaths = Array.isArray(existingResolve.paths) && existingResolve.paths.length > 0 ? [...existingResolve.paths ?? [], ...resolvePaths] : resolvePaths;
|
|
669
764
|
resolvedTailwindOptions.resolve = {
|
|
670
765
|
...existingResolve,
|
|
671
766
|
paths: [...new Set(sourcePaths)]
|
|
@@ -727,104 +822,8 @@ function createDebug(prefix) {
|
|
|
727
822
|
return debug$3;
|
|
728
823
|
}
|
|
729
824
|
//#endregion
|
|
730
|
-
//#region src/tailwindcss/source-scan.ts
|
|
731
|
-
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
732
|
-
"html",
|
|
733
|
-
"wxml",
|
|
734
|
-
"axml",
|
|
735
|
-
"jxml",
|
|
736
|
-
"ksml",
|
|
737
|
-
"ttml",
|
|
738
|
-
"qml",
|
|
739
|
-
"tyml",
|
|
740
|
-
"xhsml",
|
|
741
|
-
"swan",
|
|
742
|
-
"vue",
|
|
743
|
-
"mpx",
|
|
744
|
-
"js",
|
|
745
|
-
"jsx",
|
|
746
|
-
"ts",
|
|
747
|
-
"tsx"
|
|
748
|
-
];
|
|
749
|
-
const FULL_SOURCE_SCAN_EXTENSIONS = [
|
|
750
|
-
"js",
|
|
751
|
-
"jsx",
|
|
752
|
-
"mjs",
|
|
753
|
-
"cjs",
|
|
754
|
-
"ts",
|
|
755
|
-
"tsx",
|
|
756
|
-
"mts",
|
|
757
|
-
"cts",
|
|
758
|
-
"vue",
|
|
759
|
-
"uvue",
|
|
760
|
-
"nvue",
|
|
761
|
-
"svelte",
|
|
762
|
-
"mpx",
|
|
763
|
-
"html",
|
|
764
|
-
"wxml",
|
|
765
|
-
"axml",
|
|
766
|
-
"jxml",
|
|
767
|
-
"ksml",
|
|
768
|
-
"ttml",
|
|
769
|
-
"qml",
|
|
770
|
-
"tyml",
|
|
771
|
-
"xhsml",
|
|
772
|
-
"swan",
|
|
773
|
-
"css",
|
|
774
|
-
"wxss",
|
|
775
|
-
"acss",
|
|
776
|
-
"jxss",
|
|
777
|
-
"ttss",
|
|
778
|
-
"qss",
|
|
779
|
-
"tyss",
|
|
780
|
-
"scss",
|
|
781
|
-
"sass",
|
|
782
|
-
"less",
|
|
783
|
-
"styl",
|
|
784
|
-
"stylus"
|
|
785
|
-
];
|
|
786
|
-
function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
|
|
787
|
-
return `**/*.{${extensions.join(",")}}`;
|
|
788
|
-
}
|
|
789
|
-
const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
|
|
790
|
-
new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
|
|
791
|
-
function resolveTailwindV4CssSourceBase(source, fallbackBase) {
|
|
792
|
-
if (typeof source.base === "string" && source.base.length > 0) return source.base;
|
|
793
|
-
if (typeof source.file === "string" && source.file.length > 0) return node_path.default.dirname(source.file);
|
|
794
|
-
return fallbackBase;
|
|
795
|
-
}
|
|
825
|
+
//#region src/tailwindcss/source-scan/inline-source.ts
|
|
796
826
|
const NUMERICAL_RANGE_RE = /^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/;
|
|
797
|
-
function parseConfigParam$1(params) {
|
|
798
|
-
const value = params.trim();
|
|
799
|
-
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
800
|
-
}
|
|
801
|
-
function isLegacyContentObject$1(value) {
|
|
802
|
-
return typeof value === "object" && value !== null && "files" in value;
|
|
803
|
-
}
|
|
804
|
-
function normalizeGlobPattern(pattern) {
|
|
805
|
-
return pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
806
|
-
}
|
|
807
|
-
function hasGlobMagic(value) {
|
|
808
|
-
return /[*?[\]{}()!+@]/.test(value);
|
|
809
|
-
}
|
|
810
|
-
function splitStaticGlobPrefix(pattern) {
|
|
811
|
-
const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
|
|
812
|
-
const prefix = [];
|
|
813
|
-
const rest = [];
|
|
814
|
-
let reachedGlob = false;
|
|
815
|
-
for (const segment of segments) {
|
|
816
|
-
if (!reachedGlob && segment && !hasGlobMagic(segment)) {
|
|
817
|
-
prefix.push(segment);
|
|
818
|
-
continue;
|
|
819
|
-
}
|
|
820
|
-
reachedGlob = true;
|
|
821
|
-
rest.push(segment);
|
|
822
|
-
}
|
|
823
|
-
return {
|
|
824
|
-
prefix,
|
|
825
|
-
rest
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
827
|
function segmentTopLevel(input, separator, options = {}) {
|
|
829
828
|
const parts = [];
|
|
830
829
|
const stack = [];
|
|
@@ -951,6 +950,104 @@ function collectCssInlineSourceCandidates(root) {
|
|
|
951
950
|
excluded
|
|
952
951
|
};
|
|
953
952
|
}
|
|
953
|
+
//#endregion
|
|
954
|
+
//#region src/tailwindcss/source-scan.ts
|
|
955
|
+
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
956
|
+
"html",
|
|
957
|
+
"wxml",
|
|
958
|
+
"axml",
|
|
959
|
+
"jxml",
|
|
960
|
+
"ksml",
|
|
961
|
+
"ttml",
|
|
962
|
+
"qml",
|
|
963
|
+
"tyml",
|
|
964
|
+
"xhsml",
|
|
965
|
+
"swan",
|
|
966
|
+
"vue",
|
|
967
|
+
"mpx",
|
|
968
|
+
"js",
|
|
969
|
+
"jsx",
|
|
970
|
+
"ts",
|
|
971
|
+
"tsx"
|
|
972
|
+
];
|
|
973
|
+
const FULL_SOURCE_SCAN_EXTENSIONS = [
|
|
974
|
+
"js",
|
|
975
|
+
"jsx",
|
|
976
|
+
"mjs",
|
|
977
|
+
"cjs",
|
|
978
|
+
"ts",
|
|
979
|
+
"tsx",
|
|
980
|
+
"mts",
|
|
981
|
+
"cts",
|
|
982
|
+
"vue",
|
|
983
|
+
"uvue",
|
|
984
|
+
"nvue",
|
|
985
|
+
"svelte",
|
|
986
|
+
"mpx",
|
|
987
|
+
"html",
|
|
988
|
+
"wxml",
|
|
989
|
+
"axml",
|
|
990
|
+
"jxml",
|
|
991
|
+
"ksml",
|
|
992
|
+
"ttml",
|
|
993
|
+
"qml",
|
|
994
|
+
"tyml",
|
|
995
|
+
"xhsml",
|
|
996
|
+
"swan",
|
|
997
|
+
"css",
|
|
998
|
+
"wxss",
|
|
999
|
+
"acss",
|
|
1000
|
+
"jxss",
|
|
1001
|
+
"ttss",
|
|
1002
|
+
"qss",
|
|
1003
|
+
"tyss",
|
|
1004
|
+
"scss",
|
|
1005
|
+
"sass",
|
|
1006
|
+
"less",
|
|
1007
|
+
"styl",
|
|
1008
|
+
"stylus"
|
|
1009
|
+
];
|
|
1010
|
+
function createSourceScanPattern(extensions = DEFAULT_SOURCE_SCAN_EXTENSIONS) {
|
|
1011
|
+
return `**/*.{${extensions.join(",")}}`;
|
|
1012
|
+
}
|
|
1013
|
+
const FULL_SOURCE_SCAN_PATTERN = createSourceScanPattern(FULL_SOURCE_SCAN_EXTENSIONS);
|
|
1014
|
+
new RegExp(`\\.(?:${FULL_SOURCE_SCAN_EXTENSIONS.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})$`);
|
|
1015
|
+
function resolveTailwindV4CssSourceBase(source, fallbackBase) {
|
|
1016
|
+
if (typeof source.base === "string" && source.base.length > 0) return source.base;
|
|
1017
|
+
if (typeof source.file === "string" && source.file.length > 0) return node_path.default.dirname(source.file);
|
|
1018
|
+
return fallbackBase;
|
|
1019
|
+
}
|
|
1020
|
+
function parseConfigParam$1(params) {
|
|
1021
|
+
const value = params.trim();
|
|
1022
|
+
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
1023
|
+
}
|
|
1024
|
+
function isLegacyContentObject(value) {
|
|
1025
|
+
return typeof value === "object" && value !== null && "files" in value;
|
|
1026
|
+
}
|
|
1027
|
+
function normalizeGlobPattern(pattern) {
|
|
1028
|
+
return pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
1029
|
+
}
|
|
1030
|
+
function hasGlobMagic(value) {
|
|
1031
|
+
return /[*?[\]{}()!+@]/.test(value);
|
|
1032
|
+
}
|
|
1033
|
+
function splitStaticGlobPrefix(pattern) {
|
|
1034
|
+
const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
|
|
1035
|
+
const prefix = [];
|
|
1036
|
+
const rest = [];
|
|
1037
|
+
let reachedGlob = false;
|
|
1038
|
+
for (const segment of segments) {
|
|
1039
|
+
if (!reachedGlob && segment && !hasGlobMagic(segment)) {
|
|
1040
|
+
prefix.push(segment);
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
reachedGlob = true;
|
|
1044
|
+
rest.push(segment);
|
|
1045
|
+
}
|
|
1046
|
+
return {
|
|
1047
|
+
prefix,
|
|
1048
|
+
rest
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
954
1051
|
function normalizeLegacyContentEntries(content, base, options = {}) {
|
|
955
1052
|
if (typeof content === "string") {
|
|
956
1053
|
const negated = content.startsWith("!");
|
|
@@ -961,7 +1058,7 @@ function normalizeLegacyContentEntries(content, base, options = {}) {
|
|
|
961
1058
|
}];
|
|
962
1059
|
}
|
|
963
1060
|
if (Array.isArray(content)) return content.flatMap((item) => normalizeLegacyContentEntries(item, base, options));
|
|
964
|
-
if (isLegacyContentObject
|
|
1061
|
+
if (isLegacyContentObject(content)) return normalizeLegacyContentEntries(content.files, content.relative && options.relativeBase ? options.relativeBase : base, options);
|
|
965
1062
|
return [];
|
|
966
1063
|
}
|
|
967
1064
|
async function pathExistsAsDirectory(file) {
|
|
@@ -1029,40 +1126,6 @@ function filterUnsupportedMiniProgramTailwindV4Candidates(candidates) {
|
|
|
1029
1126
|
return new Set([...candidates].filter((candidate) => !isUnsupportedMiniProgramTailwindV4Candidate(candidate)));
|
|
1030
1127
|
}
|
|
1031
1128
|
//#endregion
|
|
1032
|
-
//#region src/tailwindcss/v4-engine/miniprogram.ts
|
|
1033
|
-
const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
1034
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
1035
|
-
cssRemoveHoverPseudoClass: true,
|
|
1036
|
-
isMainChunk: true,
|
|
1037
|
-
majorVersion: 4
|
|
1038
|
-
});
|
|
1039
|
-
const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
|
|
1040
|
-
function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
1041
|
-
return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
|
|
1042
|
-
try {
|
|
1043
|
-
return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
|
|
1044
|
-
} catch {
|
|
1045
|
-
return match;
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
}
|
|
1049
|
-
async function transformTailwindV4CssToWeapp(css, options) {
|
|
1050
|
-
const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
|
|
1051
|
-
const result = await defaultStyleHandler$1(protectedCss.css, {
|
|
1052
|
-
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
1053
|
-
cssRemoveHoverPseudoClass: true,
|
|
1054
|
-
isMainChunk: true,
|
|
1055
|
-
majorVersion: 4,
|
|
1056
|
-
...options
|
|
1057
|
-
});
|
|
1058
|
-
const pruneOptions = { preserveConditionalComments: hasCssMacroStyleOptions(options) };
|
|
1059
|
-
return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
|
|
1060
|
-
}
|
|
1061
|
-
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
1062
|
-
if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
|
|
1063
|
-
return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
|
|
1064
|
-
}
|
|
1065
|
-
//#endregion
|
|
1066
1129
|
//#region src/tailwindcss/v4-engine/tailwind-v3-default-colors.ts
|
|
1067
1130
|
const TAILWIND_V3_COLOR_STEPS = [
|
|
1068
1131
|
"50",
|
|
@@ -1794,40 +1857,7 @@ function createTailwindV4DefaultColorThemeCss() {
|
|
|
1794
1857
|
].join("\n");
|
|
1795
1858
|
}
|
|
1796
1859
|
//#endregion
|
|
1797
|
-
//#region src/tailwindcss/v4-engine/generator.ts
|
|
1798
|
-
const incrementalGenerateCache$1 = /* @__PURE__ */ new Map();
|
|
1799
|
-
const incrementalGenerateTaskCache = /* @__PURE__ */ new Map();
|
|
1800
|
-
const BARE_RPX_TEXT_CANDIDATE_RE = /(^|:)text-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$/u;
|
|
1801
|
-
const RPX_TEXT_LENGTH_SELECTOR_RE = /text-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]/g;
|
|
1802
|
-
const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
|
|
1803
|
-
"**/.git/**",
|
|
1804
|
-
"**/.hg/**",
|
|
1805
|
-
"**/.jj/**",
|
|
1806
|
-
"**/.next/**",
|
|
1807
|
-
"**/.parcel-cache/**",
|
|
1808
|
-
"**/.pnpm-store/**",
|
|
1809
|
-
"**/.svelte-kit/**",
|
|
1810
|
-
"**/.svn/**",
|
|
1811
|
-
"**/.turbo/**",
|
|
1812
|
-
"**/.venv/**",
|
|
1813
|
-
"**/.vercel/**",
|
|
1814
|
-
"**/.yarn/**",
|
|
1815
|
-
"**/__pycache__/**",
|
|
1816
|
-
"**/node_modules/**",
|
|
1817
|
-
"**/venv/**",
|
|
1818
|
-
"**/*.less",
|
|
1819
|
-
"**/*.lock",
|
|
1820
|
-
"**/*.sass",
|
|
1821
|
-
"**/*.scss",
|
|
1822
|
-
"**/*.styl",
|
|
1823
|
-
"**/*.log",
|
|
1824
|
-
"**/package-lock.json",
|
|
1825
|
-
"**/pnpm-lock.yaml",
|
|
1826
|
-
"**/bun.lockb",
|
|
1827
|
-
"**/.gitignore",
|
|
1828
|
-
"**/.env",
|
|
1829
|
-
"**/.env.*"
|
|
1830
|
-
];
|
|
1860
|
+
//#region src/tailwindcss/v4-engine/generator/css-compat.ts
|
|
1831
1861
|
function findLeadingImportInsertionIndex(css) {
|
|
1832
1862
|
const importPattern = /(?:^|\n)\s*@import\b[^;]*;/g;
|
|
1833
1863
|
let insertionIndex = 0;
|
|
@@ -1844,24 +1874,89 @@ function applyMiniProgramTailwindV4DefaultColorCss(css) {
|
|
|
1844
1874
|
if (insertionIndex === 0) return `${themeCss}\n${css}`;
|
|
1845
1875
|
return `${css.slice(0, insertionIndex)}\n${themeCss}\n${css.slice(insertionIndex)}`;
|
|
1846
1876
|
}
|
|
1847
|
-
function
|
|
1848
|
-
|
|
1877
|
+
function parseCssImportSpecifier$3(params) {
|
|
1878
|
+
const value = params.trim();
|
|
1879
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
1880
|
+
if (quoted) return quoted[2];
|
|
1881
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
1882
|
+
return url?.[2] ?? url?.[3];
|
|
1849
1883
|
}
|
|
1850
|
-
function
|
|
1851
|
-
|
|
1852
|
-
return
|
|
1884
|
+
function isTailwindCssPreflightImport(params) {
|
|
1885
|
+
const specifier = parseCssImportSpecifier$3(params);
|
|
1886
|
+
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
1853
1887
|
}
|
|
1854
|
-
function
|
|
1855
|
-
return
|
|
1888
|
+
function hasImportLayerOption(params) {
|
|
1889
|
+
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
1856
1890
|
}
|
|
1857
|
-
function
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
}
|
|
1891
|
+
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
1892
|
+
if (!css.includes("preflight")) return css;
|
|
1893
|
+
let root;
|
|
1894
|
+
try {
|
|
1895
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
1896
|
+
} catch {
|
|
1897
|
+
return css;
|
|
1898
|
+
}
|
|
1899
|
+
let changed = false;
|
|
1900
|
+
root.walkAtRules("import", (rule) => {
|
|
1901
|
+
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
1902
|
+
rule.remove();
|
|
1903
|
+
changed = true;
|
|
1904
|
+
}
|
|
1905
|
+
});
|
|
1906
|
+
return changed ? root.toString() : css;
|
|
1907
|
+
}
|
|
1908
|
+
function hasThemeParent(rule) {
|
|
1909
|
+
let parent = rule.parent;
|
|
1910
|
+
while (parent) {
|
|
1911
|
+
if (parent.type === "atrule" && parent.name === "theme") return true;
|
|
1912
|
+
parent = parent.parent;
|
|
1913
|
+
}
|
|
1914
|
+
return false;
|
|
1915
|
+
}
|
|
1916
|
+
function isVendorPrefixedKeyframes(rule) {
|
|
1917
|
+
return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
|
|
1918
|
+
}
|
|
1919
|
+
function removeUnsupportedThemeVendorKeyframes(css) {
|
|
1920
|
+
if (!css.includes("@theme") || !css.includes("@-")) return css;
|
|
1921
|
+
let root;
|
|
1922
|
+
try {
|
|
1923
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
1924
|
+
} catch {
|
|
1925
|
+
return css;
|
|
1926
|
+
}
|
|
1927
|
+
let changed = false;
|
|
1928
|
+
root.walkAtRules((rule) => {
|
|
1929
|
+
if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
|
|
1930
|
+
rule.remove();
|
|
1931
|
+
changed = true;
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
return changed ? root.toString() : css;
|
|
1935
|
+
}
|
|
1936
|
+
function createCompatibleSource(source, target, tailwindcssV3Compatibility) {
|
|
1937
|
+
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1938
|
+
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1939
|
+
const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss);
|
|
1940
|
+
return compatibleSourceCss === source.css ? source : {
|
|
1941
|
+
...source,
|
|
1942
|
+
css: compatibleSourceCss
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
//#endregion
|
|
1946
|
+
//#region src/tailwindcss/v4-engine/generator/rpx-candidates.ts
|
|
1947
|
+
const BARE_RPX_TEXT_CANDIDATE_RE = /(^|:)text-\[([-+]?(?:\d+|\d*\.\d+)rpx)\](.*)$/u;
|
|
1948
|
+
const RPX_TEXT_LENGTH_SELECTOR_RE = /text-\\\[length\\:((?:\\[.+-]|[+\-.\d])+rpx)\\\]/g;
|
|
1949
|
+
function normalizeRpxTextCandidate(candidate) {
|
|
1950
|
+
return candidate.replace(BARE_RPX_TEXT_CANDIDATE_RE, "$1text-[length:$2]$3");
|
|
1951
|
+
}
|
|
1952
|
+
function normalizeRpxTextCandidates(candidates) {
|
|
1953
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
1954
|
+
const restoreCandidates = /* @__PURE__ */ new Map();
|
|
1955
|
+
for (const candidate of candidates) {
|
|
1956
|
+
const normalizedCandidate = normalizeRpxTextCandidate(candidate);
|
|
1957
|
+
normalized.add(normalizedCandidate);
|
|
1958
|
+
if (normalizedCandidate !== candidate) restoreCandidates.set(normalizedCandidate, candidate);
|
|
1959
|
+
}
|
|
1865
1960
|
return {
|
|
1866
1961
|
candidates: normalized,
|
|
1867
1962
|
restoreCandidates
|
|
@@ -1883,16 +1978,162 @@ function restoreRpxTextCssSelectors(css, restoreCandidates) {
|
|
|
1883
1978
|
return restoredValues.has(normalizeCssEscapedRpxSelectorValue(value)) ? `text-\\[${value}\\]` : match;
|
|
1884
1979
|
});
|
|
1885
1980
|
}
|
|
1886
|
-
|
|
1981
|
+
//#endregion
|
|
1982
|
+
//#region src/tailwindcss/v4-engine/generator/scan-sources.ts
|
|
1983
|
+
const TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS = [
|
|
1984
|
+
"**/.git/**",
|
|
1985
|
+
"**/.hg/**",
|
|
1986
|
+
"**/.jj/**",
|
|
1987
|
+
"**/.next/**",
|
|
1988
|
+
"**/.parcel-cache/**",
|
|
1989
|
+
"**/.pnpm-store/**",
|
|
1990
|
+
"**/.svelte-kit/**",
|
|
1991
|
+
"**/.svn/**",
|
|
1992
|
+
"**/.turbo/**",
|
|
1993
|
+
"**/.venv/**",
|
|
1994
|
+
"**/.vercel/**",
|
|
1995
|
+
"**/.yarn/**",
|
|
1996
|
+
"**/__pycache__/**",
|
|
1997
|
+
"**/node_modules/**",
|
|
1998
|
+
"**/venv/**",
|
|
1999
|
+
"**/*.less",
|
|
2000
|
+
"**/*.lock",
|
|
2001
|
+
"**/*.sass",
|
|
2002
|
+
"**/*.scss",
|
|
2003
|
+
"**/*.styl",
|
|
2004
|
+
"**/*.log",
|
|
2005
|
+
"**/package-lock.json",
|
|
2006
|
+
"**/pnpm-lock.yaml",
|
|
2007
|
+
"**/bun.lockb",
|
|
2008
|
+
"**/.gitignore",
|
|
2009
|
+
"**/.env",
|
|
2010
|
+
"**/.env.*"
|
|
2011
|
+
];
|
|
2012
|
+
function parseImportSourceParam$1(params) {
|
|
2013
|
+
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
2014
|
+
if (!match) return;
|
|
2015
|
+
return {
|
|
2016
|
+
none: match[1] === "none",
|
|
2017
|
+
sourcePath: match[3]
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
2020
|
+
function parseCssImportSpecifier$2(params) {
|
|
2021
|
+
const value = params.trim();
|
|
2022
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
2023
|
+
if (quoted) return quoted[2];
|
|
2024
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
2025
|
+
return url?.[2] ?? url?.[3];
|
|
2026
|
+
}
|
|
2027
|
+
function isTailwindCssImport$1(params) {
|
|
2028
|
+
const specifier = parseCssImportSpecifier$2(params);
|
|
2029
|
+
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
2030
|
+
}
|
|
2031
|
+
function resolveSourceBase$1(base, sourcePath) {
|
|
2032
|
+
return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
|
|
2033
|
+
}
|
|
2034
|
+
function createDefaultIgnoredScanSources(base) {
|
|
2035
|
+
return TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS.map((pattern) => ({
|
|
2036
|
+
base,
|
|
2037
|
+
pattern,
|
|
2038
|
+
negated: true
|
|
2039
|
+
}));
|
|
2040
|
+
}
|
|
2041
|
+
function normalizeCssDefinedScanSources(base, entries) {
|
|
2042
|
+
return entries.length > 0 && entries.every((entry) => entry.negated) ? [{
|
|
2043
|
+
base,
|
|
2044
|
+
pattern: "**/*",
|
|
2045
|
+
negated: false
|
|
2046
|
+
}, ...entries] : entries;
|
|
2047
|
+
}
|
|
2048
|
+
async function resolveCssDefinedScanSources(source) {
|
|
2049
|
+
let importSourceBase;
|
|
2050
|
+
let hasSourceNone = false;
|
|
2051
|
+
const from = source.dependencies[0];
|
|
2052
|
+
let root;
|
|
2053
|
+
try {
|
|
2054
|
+
root = require_watch_dependencies.postcss_default.parse(source.css, { from });
|
|
2055
|
+
} catch {
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
root.walkAtRules((rule) => {
|
|
2059
|
+
if (rule.name === "import") {
|
|
2060
|
+
if (!isTailwindCssImport$1(rule.params)) return;
|
|
2061
|
+
const sourceParam = parseImportSourceParam$1(rule.params);
|
|
2062
|
+
if (sourceParam?.none) hasSourceNone = true;
|
|
2063
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase$1(source.base, sourceParam.sourcePath);
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
const sourcePatterns = await resolveCssSourceEntries(root, source.base, "**/*");
|
|
2067
|
+
if (!importSourceBase) {
|
|
2068
|
+
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
2069
|
+
if (hasSourceNone) return false;
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
return [
|
|
2073
|
+
await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"),
|
|
2074
|
+
...sourcePatterns,
|
|
2075
|
+
...createDefaultIgnoredScanSources(importSourceBase)
|
|
2076
|
+
];
|
|
2077
|
+
}
|
|
2078
|
+
async function resolveScanSources(source, scanSources) {
|
|
2079
|
+
if (scanSources !== true) return scanSources;
|
|
2080
|
+
return await resolveCssDefinedScanSources(source) ?? false;
|
|
2081
|
+
}
|
|
2082
|
+
//#endregion
|
|
2083
|
+
//#region src/tailwindcss/v4-engine/miniprogram.ts
|
|
2084
|
+
const defaultStyleHandler$1 = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
2085
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
2086
|
+
cssRemoveHoverPseudoClass: true,
|
|
2087
|
+
isMainChunk: true,
|
|
2088
|
+
majorVersion: 4
|
|
2089
|
+
});
|
|
2090
|
+
const CSS_DECLARATION_URL_RE = /(:\s*)url\(([^\n\r"';[\]{}]*[[\]{}][^\n\r;]*)\)(?=\s*;)/g;
|
|
2091
|
+
function normalizeTailwindV4GeneratedUrlValues(css) {
|
|
2092
|
+
return css.replace(CSS_DECLARATION_URL_RE, (match, prefix, urlValue) => {
|
|
2093
|
+
try {
|
|
2094
|
+
return `${prefix}url("${urlValue.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"")}")`;
|
|
2095
|
+
} catch {
|
|
2096
|
+
return match;
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
async function transformTailwindV4CssToWeapp(css, options) {
|
|
2101
|
+
const protectedCss = (0, _weapp_tailwindcss_postcss.protectDynamicColorMixAlpha)(normalizeTailwindV4GeneratedUrlValues(hasCssMacroStyleOptions(options) ? await transformCssMacroCss(css, options) : css), { customPropertyValues: options && "customPropertyValues" in options ? options.customPropertyValues : void 0 });
|
|
2102
|
+
const result = await defaultStyleHandler$1(protectedCss.css, {
|
|
2103
|
+
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
2104
|
+
cssRemoveHoverPseudoClass: true,
|
|
2105
|
+
isMainChunk: true,
|
|
2106
|
+
majorVersion: 4,
|
|
2107
|
+
...options
|
|
2108
|
+
});
|
|
2109
|
+
const pruneOptions = { preserveConditionalComments: hasCssMacroStyleOptions(options) };
|
|
2110
|
+
return (0, _weapp_tailwindcss_postcss.pruneMiniProgramGeneratedCss)(protectedCss.restore(result.css), pruneOptions);
|
|
2111
|
+
}
|
|
2112
|
+
async function transformTailwindV4CssByTarget(css, target, options) {
|
|
2113
|
+
if (target === "weapp") return transformTailwindV4CssToWeapp(css, options);
|
|
2114
|
+
return hasCssMacroStyleOptions(options) ? transformCssMacroCss(css, options) : css;
|
|
2115
|
+
}
|
|
2116
|
+
//#endregion
|
|
2117
|
+
//#region src/tailwindcss/v4-engine/generator.ts
|
|
2118
|
+
const incrementalGenerateCache$1 = /* @__PURE__ */ new Map();
|
|
2119
|
+
const incrementalGenerateTaskCache = /* @__PURE__ */ new Map();
|
|
2120
|
+
function collectCandidates(candidates) {
|
|
2121
|
+
return new Set(candidates ?? []);
|
|
2122
|
+
}
|
|
2123
|
+
function hasRemovedCandidates$1(previousCandidates, nextCandidates) {
|
|
2124
|
+
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
2125
|
+
return false;
|
|
2126
|
+
}
|
|
2127
|
+
function createStableJson$1(value) {
|
|
1887
2128
|
if (value === void 0) return "undefined";
|
|
1888
2129
|
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
1889
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$
|
|
2130
|
+
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
|
|
1890
2131
|
return `{${Object.keys(value).sort().map((key) => {
|
|
1891
2132
|
const record = value;
|
|
1892
|
-
return `${JSON.stringify(key)}:${createStableJson$
|
|
2133
|
+
return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
|
|
1893
2134
|
}).join(",")}}`;
|
|
1894
2135
|
}
|
|
1895
|
-
function createDependencyFingerprint
|
|
2136
|
+
function createDependencyFingerprint(files) {
|
|
1896
2137
|
return files.map((file) => {
|
|
1897
2138
|
try {
|
|
1898
2139
|
const stat = node_fs.default.statSync(file);
|
|
@@ -1902,16 +2143,16 @@ function createDependencyFingerprint$1(files) {
|
|
|
1902
2143
|
}
|
|
1903
2144
|
}).join("|");
|
|
1904
2145
|
}
|
|
1905
|
-
function createIncrementalGenerateCacheKey
|
|
2146
|
+
function createIncrementalGenerateCacheKey(source, target, styleOptions, tailwindcssV3Compatibility) {
|
|
1906
2147
|
return [
|
|
1907
2148
|
source.projectRoot,
|
|
1908
2149
|
source.base,
|
|
1909
|
-
createStableJson$
|
|
2150
|
+
createStableJson$1(source.baseFallbacks),
|
|
1910
2151
|
source.css,
|
|
1911
|
-
createDependencyFingerprint
|
|
2152
|
+
createDependencyFingerprint(source.dependencies),
|
|
1912
2153
|
target,
|
|
1913
|
-
createStableJson$
|
|
1914
|
-
createStableJson$
|
|
2154
|
+
createStableJson$1(styleOptions),
|
|
2155
|
+
createStableJson$1(tailwindcssV3Compatibility)
|
|
1915
2156
|
].join("\0");
|
|
1916
2157
|
}
|
|
1917
2158
|
function createIncrementalGenerateTaskCacheKey(cacheKey, requestedCandidates, scanSources) {
|
|
@@ -1939,17 +2180,8 @@ function createIncrementalDesignSystemPromise(source, cacheKey) {
|
|
|
1939
2180
|
});
|
|
1940
2181
|
return promise;
|
|
1941
2182
|
}
|
|
1942
|
-
function createCompatibleSource(source, target, tailwindcssV3Compatibility) {
|
|
1943
|
-
const shouldApplyTailwindV3Compatibility = tailwindcssV3Compatibility ?? target === "weapp";
|
|
1944
|
-
const filteredSourceCss = target === "weapp" ? removeUnlayeredTailwindV4PreflightImports(source.css) : source.css;
|
|
1945
|
-
const compatibleSourceCss = removeUnsupportedThemeVendorKeyframes(shouldApplyTailwindV3Compatibility ? applyTailwindV3CompatibilityCss(filteredSourceCss) : target === "weapp" ? applyMiniProgramTailwindV4DefaultColorCss(filteredSourceCss) : filteredSourceCss);
|
|
1946
|
-
return compatibleSourceCss === source.css ? source : {
|
|
1947
|
-
...source,
|
|
1948
|
-
css: compatibleSourceCss
|
|
1949
|
-
};
|
|
1950
|
-
}
|
|
1951
2183
|
function resolveTargetCandidates(candidates, target) {
|
|
1952
|
-
const collected = collectCandidates
|
|
2184
|
+
const collected = collectCandidates(candidates);
|
|
1953
2185
|
return target === "weapp" ? filterUnsupportedMiniProgramTailwindV4Candidates(collected) : collected;
|
|
1954
2186
|
}
|
|
1955
2187
|
function collectSeenCandidates(generated, requestedCandidates) {
|
|
@@ -1981,7 +2213,7 @@ function mergeCustomPropertyValues(target, css) {
|
|
|
1981
2213
|
for (const [prop, value] of collectCustomPropertyValues(css)) target.set(prop, value);
|
|
1982
2214
|
}
|
|
1983
2215
|
function seedIncrementalGenerateCache(options) {
|
|
1984
|
-
const cacheKey = createIncrementalGenerateCacheKey
|
|
2216
|
+
const cacheKey = createIncrementalGenerateCacheKey(options.compatibleSource, options.target, options.styleOptions, options.tailwindcssV3Compatibility);
|
|
1985
2217
|
const customPropertyValues = collectCustomPropertyValues(options.compatibleSource.css);
|
|
1986
2218
|
mergeCustomPropertyValues(customPropertyValues, options.generated.css);
|
|
1987
2219
|
incrementalGenerateCache$1.set(cacheKey, {
|
|
@@ -1997,136 +2229,14 @@ function seedIncrementalGenerateCache(options) {
|
|
|
1997
2229
|
target: options.generated.target
|
|
1998
2230
|
});
|
|
1999
2231
|
}
|
|
2000
|
-
function parseImportSourceParam$1(params) {
|
|
2001
|
-
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
2002
|
-
if (!match) return;
|
|
2003
|
-
return {
|
|
2004
|
-
none: match[1] === "none",
|
|
2005
|
-
sourcePath: match[3]
|
|
2006
|
-
};
|
|
2007
|
-
}
|
|
2008
|
-
function isTailwindCssImport$1(params) {
|
|
2009
|
-
const specifier = parseCssImportSpecifier$2(params);
|
|
2010
|
-
return specifier === "tailwindcss" || specifier?.startsWith("tailwindcss/") || specifier?.replaceAll("\\", "/").endsWith("/tailwindcss/index.css");
|
|
2011
|
-
}
|
|
2012
|
-
function parseCssImportSpecifier$2(params) {
|
|
2013
|
-
const value = params.trim();
|
|
2014
|
-
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
2015
|
-
if (quoted) return quoted[2];
|
|
2016
|
-
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
2017
|
-
return url?.[2] ?? url?.[3];
|
|
2018
|
-
}
|
|
2019
|
-
function isTailwindCssPreflightImport(params) {
|
|
2020
|
-
const specifier = parseCssImportSpecifier$2(params);
|
|
2021
|
-
return specifier === "tailwindcss/preflight.css" || specifier === "tailwindcss/preflight";
|
|
2022
|
-
}
|
|
2023
|
-
function hasImportLayerOption(params) {
|
|
2024
|
-
return /\blayer(?:\s*\(|\s*$)/.test(params);
|
|
2025
|
-
}
|
|
2026
|
-
function removeUnlayeredTailwindV4PreflightImports(css) {
|
|
2027
|
-
if (!css.includes("preflight")) return css;
|
|
2028
|
-
let root;
|
|
2029
|
-
try {
|
|
2030
|
-
root = require_watch_dependencies.postcss_default.parse(css);
|
|
2031
|
-
} catch {
|
|
2032
|
-
return css;
|
|
2033
|
-
}
|
|
2034
|
-
let changed = false;
|
|
2035
|
-
root.walkAtRules("import", (rule) => {
|
|
2036
|
-
if (isTailwindCssPreflightImport(rule.params) && !hasImportLayerOption(rule.params)) {
|
|
2037
|
-
rule.remove();
|
|
2038
|
-
changed = true;
|
|
2039
|
-
}
|
|
2040
|
-
});
|
|
2041
|
-
return changed ? root.toString() : css;
|
|
2042
|
-
}
|
|
2043
|
-
function resolveSourceBase$1(base, sourcePath) {
|
|
2044
|
-
return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
|
|
2045
|
-
}
|
|
2046
|
-
function createDefaultIgnoredScanSources(base) {
|
|
2047
|
-
return TAILWIND_V4_DEFAULT_IGNORED_SOURCE_PATTERNS.map((pattern) => ({
|
|
2048
|
-
base,
|
|
2049
|
-
pattern,
|
|
2050
|
-
negated: true
|
|
2051
|
-
}));
|
|
2052
|
-
}
|
|
2053
|
-
function normalizeCssDefinedScanSources(base, entries) {
|
|
2054
|
-
return entries.length > 0 && entries.every((entry) => entry.negated) ? [{
|
|
2055
|
-
base,
|
|
2056
|
-
pattern: "**/*",
|
|
2057
|
-
negated: false
|
|
2058
|
-
}, ...entries] : entries;
|
|
2059
|
-
}
|
|
2060
|
-
async function resolveCssDefinedScanSources(source) {
|
|
2061
|
-
let importSourceBase;
|
|
2062
|
-
let hasSourceNone = false;
|
|
2063
|
-
const from = source.dependencies[0];
|
|
2064
|
-
let root;
|
|
2065
|
-
try {
|
|
2066
|
-
root = require_watch_dependencies.postcss_default.parse(source.css, { from });
|
|
2067
|
-
} catch {
|
|
2068
|
-
return;
|
|
2069
|
-
}
|
|
2070
|
-
root.walkAtRules((rule) => {
|
|
2071
|
-
if (rule.name === "import") {
|
|
2072
|
-
if (!isTailwindCssImport$1(rule.params)) return;
|
|
2073
|
-
const sourceParam = parseImportSourceParam$1(rule.params);
|
|
2074
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
2075
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase$1(source.base, sourceParam.sourcePath);
|
|
2076
|
-
}
|
|
2077
|
-
});
|
|
2078
|
-
const sourcePatterns = await resolveCssSourceEntries(root, source.base, "**/*");
|
|
2079
|
-
if (!importSourceBase) {
|
|
2080
|
-
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
2081
|
-
if (hasSourceNone) return false;
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
return [
|
|
2085
|
-
await resolveTailwindSourceEntry(".", importSourceBase, false, "**/*"),
|
|
2086
|
-
...sourcePatterns,
|
|
2087
|
-
...createDefaultIgnoredScanSources(importSourceBase)
|
|
2088
|
-
];
|
|
2089
|
-
}
|
|
2090
|
-
async function resolveScanSources(source, scanSources) {
|
|
2091
|
-
if (scanSources !== true) return scanSources;
|
|
2092
|
-
return await resolveCssDefinedScanSources(source) ?? false;
|
|
2093
|
-
}
|
|
2094
|
-
function hasThemeParent(rule) {
|
|
2095
|
-
let parent = rule.parent;
|
|
2096
|
-
while (parent) {
|
|
2097
|
-
if (parent.type === "atrule" && parent.name === "theme") return true;
|
|
2098
|
-
parent = parent.parent;
|
|
2099
|
-
}
|
|
2100
|
-
return false;
|
|
2101
|
-
}
|
|
2102
|
-
function isVendorPrefixedKeyframes(rule) {
|
|
2103
|
-
return rule.name.startsWith("-") && rule.name.endsWith("keyframes");
|
|
2104
|
-
}
|
|
2105
|
-
function removeUnsupportedThemeVendorKeyframes(css) {
|
|
2106
|
-
if (!css.includes("@theme") || !css.includes("@-")) return css;
|
|
2107
|
-
let root;
|
|
2108
|
-
try {
|
|
2109
|
-
root = require_watch_dependencies.postcss_default.parse(css);
|
|
2110
|
-
} catch {
|
|
2111
|
-
return css;
|
|
2112
|
-
}
|
|
2113
|
-
let changed = false;
|
|
2114
|
-
root.walkAtRules((rule) => {
|
|
2115
|
-
if (isVendorPrefixedKeyframes(rule) && hasThemeParent(rule)) {
|
|
2116
|
-
rule.remove();
|
|
2117
|
-
changed = true;
|
|
2118
|
-
}
|
|
2119
|
-
});
|
|
2120
|
-
return changed ? root.toString() : css;
|
|
2121
|
-
}
|
|
2122
2232
|
function createTailwindV4Engine(source) {
|
|
2123
2233
|
async function generateOnce(generateSource, options = {}) {
|
|
2124
2234
|
const { scanSources = true, styleOptions, tailwindcssV3Compatibility, target = "weapp", ...patchOptions } = options;
|
|
2125
2235
|
const resolvedStyleOptions = resolveStyleOptions$1(generateSource, styleOptions);
|
|
2126
2236
|
const engine = (0, tailwindcss_patch.createTailwindV4Engine)(createCompatibleSource(generateSource, target, tailwindcssV3Compatibility));
|
|
2127
2237
|
const resolvedScanSources = await resolveScanSources(generateSource, scanSources);
|
|
2128
|
-
const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await (0, tailwindcss_patch.extractRawCandidates)(resolvedScanSources, { bareArbitraryValues: patchOptions.bareArbitraryValues })) : void 0;
|
|
2129
|
-
const normalizedCandidates = normalizeRpxTextCandidates(resolveTargetCandidates(new Set([...collectCandidates
|
|
2238
|
+
const filesystemCandidates = Array.isArray(resolvedScanSources) ? new Set(await (0, tailwindcss_patch.extractRawCandidates)(resolvedScanSources, { ...patchOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: patchOptions.bareArbitraryValues } })) : void 0;
|
|
2239
|
+
const normalizedCandidates = normalizeRpxTextCandidates(resolveTargetCandidates(new Set([...collectCandidates(patchOptions.candidates), ...filesystemCandidates ?? []]), target));
|
|
2130
2240
|
const result = await engine.generate(omitUndefined({
|
|
2131
2241
|
scanSources: false,
|
|
2132
2242
|
...patchOptions,
|
|
@@ -2149,7 +2259,7 @@ function createTailwindV4Engine(source) {
|
|
|
2149
2259
|
const requestedCandidates = resolveTargetCandidates(options.candidates, target);
|
|
2150
2260
|
const styleOptions = resolveStyleOptions$1(source, options.styleOptions);
|
|
2151
2261
|
if ((options.sources?.length ?? 0) > 0 || options.bareArbitraryValues !== void 0 || Array.isArray(options.scanSources)) return generateOnce(source, options);
|
|
2152
|
-
const cacheKey = createIncrementalGenerateCacheKey
|
|
2262
|
+
const cacheKey = createIncrementalGenerateCacheKey(compatibleSource, target, styleOptions, options.tailwindcssV3Compatibility);
|
|
2153
2263
|
if (options.scanSources === true) return runIncrementalGenerateTask(cacheKey, requestedCandidates, options.scanSources, async () => {
|
|
2154
2264
|
const generated = await generateOnce(source, options);
|
|
2155
2265
|
seedIncrementalGenerateCache({
|
|
@@ -2332,102 +2442,54 @@ function stripGeneratorPlaceholderMarkers(css) {
|
|
|
2332
2442
|
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
2333
2443
|
}
|
|
2334
2444
|
function hasTailwindGeneratedCss(rawSource) {
|
|
2335
|
-
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
2336
|
-
}
|
|
2337
|
-
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
2338
|
-
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2339
|
-
}
|
|
2340
|
-
//#endregion
|
|
2341
|
-
//#region src/bundlers/shared/generator-css/directives.ts
|
|
2342
|
-
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
2343
|
-
"config",
|
|
2344
|
-
"custom-variant",
|
|
2345
|
-
"layer",
|
|
2346
|
-
"plugin",
|
|
2347
|
-
"reference",
|
|
2348
|
-
"source",
|
|
2349
|
-
"tailwind",
|
|
2350
|
-
"theme",
|
|
2351
|
-
"utility",
|
|
2352
|
-
"variant"
|
|
2353
|
-
]);
|
|
2354
|
-
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
2355
|
-
"config",
|
|
2356
|
-
"custom-variant",
|
|
2357
|
-
"plugin",
|
|
2358
|
-
"source",
|
|
2359
|
-
"tailwind",
|
|
2360
|
-
"theme",
|
|
2361
|
-
"utility",
|
|
2362
|
-
"variant"
|
|
2363
|
-
]);
|
|
2364
|
-
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
2445
|
+
return TAILWIND_V4_BANNER_RE.test(rawSource);
|
|
2446
|
+
}
|
|
2447
|
+
function hasTailwindGeneratedCssMarkers(rawSource) {
|
|
2448
|
+
return TAILWIND_GENERATED_CSS_MARKER_RE.test(rawSource) || GENERATOR_PLACEHOLDER_MARKER_RE.test(rawSource);
|
|
2449
|
+
}
|
|
2450
|
+
//#endregion
|
|
2451
|
+
//#region src/bundlers/shared/generator-css/directives/fallback.ts
|
|
2365
2452
|
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|use|forward|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
2366
2453
|
const TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE = /^\s*@layer\s[^;{]+;\s*$/;
|
|
2367
|
-
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant)\b[\s\S]*\{/;
|
|
2368
|
-
|
|
2369
|
-
["tailwindcss/base", "base"],
|
|
2370
|
-
["tailwindcss/components", "components"],
|
|
2371
|
-
["tailwindcss/utilities", "utilities"]
|
|
2372
|
-
]);
|
|
2373
|
-
function parseImportRequest(params) {
|
|
2454
|
+
const TAILWIND_EXTRACTABLE_BLOCK_START_RE = /^\s*@(?:layer|theme|utility|variant|custom-variant|plugin)\b[\s\S]*\{/;
|
|
2455
|
+
function parseImportRequest$1(params) {
|
|
2374
2456
|
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
2375
2457
|
}
|
|
2376
|
-
function parseConfigRequest(params) {
|
|
2458
|
+
function parseConfigRequest$1(params) {
|
|
2377
2459
|
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
2378
2460
|
}
|
|
2379
|
-
function isPackageJsonImportRequest$
|
|
2461
|
+
function isPackageJsonImportRequest$2(request) {
|
|
2380
2462
|
return typeof request === "string" && request.startsWith("#");
|
|
2381
2463
|
}
|
|
2382
|
-
function isWeappTailwindcssImportRequest(request) {
|
|
2464
|
+
function isWeappTailwindcssImportRequest$1(request) {
|
|
2383
2465
|
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
2384
2466
|
}
|
|
2385
|
-
function
|
|
2386
|
-
|
|
2467
|
+
function isTailwindImportRequest$1(request) {
|
|
2468
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
2469
|
+
}
|
|
2470
|
+
function normalizeTailwindImportRequest$1(request, options = {}) {
|
|
2471
|
+
if (options.importFallback && isWeappTailwindcssImportRequest$1(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
2387
2472
|
return request;
|
|
2388
2473
|
}
|
|
2389
|
-
function replaceImportRequest(params, request, replacement) {
|
|
2474
|
+
function replaceImportRequest$1(params, request, replacement) {
|
|
2390
2475
|
const index = params.indexOf(request);
|
|
2391
2476
|
if (index === -1) return params;
|
|
2392
2477
|
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
2393
2478
|
}
|
|
2394
|
-
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
2395
|
-
if (!options.importFallback) return false;
|
|
2396
|
-
let changed = false;
|
|
2397
|
-
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
2398
|
-
root.walkAtRules("import", (node) => {
|
|
2399
|
-
const request = parseImportRequest(node.params);
|
|
2400
|
-
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2401
|
-
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
2402
|
-
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
2403
|
-
const normalizedKey = normalizedParams.trim();
|
|
2404
|
-
if (seenCanonicalImports.has(normalizedKey)) {
|
|
2405
|
-
node.remove();
|
|
2406
|
-
changed = true;
|
|
2407
|
-
return;
|
|
2408
|
-
}
|
|
2409
|
-
seenCanonicalImports.add(normalizedKey);
|
|
2410
|
-
if (normalizedParams !== node.params) {
|
|
2411
|
-
node.params = normalizedParams;
|
|
2412
|
-
changed = true;
|
|
2413
|
-
}
|
|
2414
|
-
});
|
|
2415
|
-
return changed;
|
|
2416
|
-
}
|
|
2417
2479
|
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
2418
2480
|
const trimmed = line.trimStart();
|
|
2419
2481
|
if (/^@(?:use|forward)\b/.test(trimmed)) {
|
|
2420
|
-
const request = parseImportRequest(trimmed.replace(/^@(?:use|forward)\b/, ""));
|
|
2421
|
-
if (isTailwindImportRequest(request) || options.importFallback && isWeappTailwindcssImportRequest(request)) {
|
|
2422
|
-
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2423
|
-
return replaceImportRequest(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
|
|
2482
|
+
const request = parseImportRequest$1(trimmed.replace(/^@(?:use|forward)\b/, ""));
|
|
2483
|
+
if (isTailwindImportRequest$1(request) || options.importFallback && isWeappTailwindcssImportRequest$1(request)) {
|
|
2484
|
+
const normalizedRequest = normalizeTailwindImportRequest$1(request, options);
|
|
2485
|
+
return replaceImportRequest$1(line.replace(/^(\s*)@(?:use|forward)\b/, "$1@import"), request, normalizedRequest);
|
|
2424
2486
|
}
|
|
2425
2487
|
return line;
|
|
2426
2488
|
}
|
|
2427
2489
|
if (!options.importFallback || !trimmed.startsWith("@import")) return line;
|
|
2428
|
-
const request = parseImportRequest(trimmed.replace(/^@import\b/, ""));
|
|
2429
|
-
if (!request || !isWeappTailwindcssImportRequest(request)) return line;
|
|
2430
|
-
return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
2490
|
+
const request = parseImportRequest$1(trimmed.replace(/^@import\b/, ""));
|
|
2491
|
+
if (!request || !isWeappTailwindcssImportRequest$1(request)) return line;
|
|
2492
|
+
return replaceImportRequest$1(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
2431
2493
|
}
|
|
2432
2494
|
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
2433
2495
|
const directives = [];
|
|
@@ -2437,13 +2499,14 @@ function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
|
2437
2499
|
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
2438
2500
|
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_LAYER_STATEMENT_RE.exec(line)?.[0];
|
|
2439
2501
|
if (!directive) continue;
|
|
2502
|
+
if (TAILWIND_EXTRACTABLE_BLOCK_START_RE.test(directive)) continue;
|
|
2440
2503
|
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
2441
2504
|
const normalizedTrimmed = normalized.trim();
|
|
2442
2505
|
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
2443
|
-
const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
|
|
2444
|
-
if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest$
|
|
2506
|
+
const request = /^@(?:import|use|forward)\b/.test(normalizedTrimmed) ? parseImportRequest$1(normalizedTrimmed.replace(/^@(?:import|use|forward)\b/, "")) : void 0;
|
|
2507
|
+
if (request && !isTailwindImportRequest$1(request) && !isPackageJsonImportRequest$2(request)) continue;
|
|
2445
2508
|
if (/^@(?:import|use|forward)\b/.test(normalizedTrimmed) && !request) continue;
|
|
2446
|
-
if (request && isTailwindImportRequest(request)) {
|
|
2509
|
+
if (request && isTailwindImportRequest$1(request)) {
|
|
2447
2510
|
const key = normalizedTrimmed;
|
|
2448
2511
|
if (seenImports.has(key)) continue;
|
|
2449
2512
|
seenImports.add(key);
|
|
@@ -2539,10 +2602,84 @@ function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
|
2539
2602
|
function extractConfigRequestFromSource(rawSource) {
|
|
2540
2603
|
for (const line of rawSource.split(/\r?\n/)) {
|
|
2541
2604
|
const match = /^\s*@config\b([\s\S]*?)(?:;|$)/.exec(line);
|
|
2542
|
-
const request = match ? parseConfigRequest(match[1] ?? "") : void 0;
|
|
2605
|
+
const request = match ? parseConfigRequest$1(match[1] ?? "") : void 0;
|
|
2543
2606
|
if (request) return request;
|
|
2544
2607
|
}
|
|
2545
2608
|
}
|
|
2609
|
+
//#endregion
|
|
2610
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
2611
|
+
const TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES = new Set([
|
|
2612
|
+
"config",
|
|
2613
|
+
"custom-variant",
|
|
2614
|
+
"layer",
|
|
2615
|
+
"plugin",
|
|
2616
|
+
"reference",
|
|
2617
|
+
"source",
|
|
2618
|
+
"tailwind",
|
|
2619
|
+
"theme",
|
|
2620
|
+
"utility",
|
|
2621
|
+
"variant"
|
|
2622
|
+
]);
|
|
2623
|
+
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
2624
|
+
"config",
|
|
2625
|
+
"custom-variant",
|
|
2626
|
+
"plugin",
|
|
2627
|
+
"source",
|
|
2628
|
+
"tailwind",
|
|
2629
|
+
"theme",
|
|
2630
|
+
"utility",
|
|
2631
|
+
"variant"
|
|
2632
|
+
]);
|
|
2633
|
+
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|(?:use|forward)\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
2634
|
+
const TAILWIND_V3_SUBPATH_IMPORT_LAYERS = new Map([
|
|
2635
|
+
["tailwindcss/base", "base"],
|
|
2636
|
+
["tailwindcss/components", "components"],
|
|
2637
|
+
["tailwindcss/utilities", "utilities"]
|
|
2638
|
+
]);
|
|
2639
|
+
function parseImportRequest(params) {
|
|
2640
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
2641
|
+
}
|
|
2642
|
+
function parseConfigRequest(params) {
|
|
2643
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
2644
|
+
}
|
|
2645
|
+
function isPackageJsonImportRequest$1(request) {
|
|
2646
|
+
return typeof request === "string" && request.startsWith("#");
|
|
2647
|
+
}
|
|
2648
|
+
function isWeappTailwindcssImportRequest(request) {
|
|
2649
|
+
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
2650
|
+
}
|
|
2651
|
+
function normalizeTailwindImportRequest(request, options = {}) {
|
|
2652
|
+
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
2653
|
+
return request;
|
|
2654
|
+
}
|
|
2655
|
+
function replaceImportRequest(params, request, replacement) {
|
|
2656
|
+
const index = params.indexOf(request);
|
|
2657
|
+
if (index === -1) return params;
|
|
2658
|
+
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
2659
|
+
}
|
|
2660
|
+
function normalizeTailwindImportAtRules(root, options = {}) {
|
|
2661
|
+
if (!options.importFallback) return false;
|
|
2662
|
+
let changed = false;
|
|
2663
|
+
const seenCanonicalImports = /* @__PURE__ */ new Set();
|
|
2664
|
+
root.walkAtRules("import", (node) => {
|
|
2665
|
+
const request = parseImportRequest(node.params);
|
|
2666
|
+
const normalizedRequest = normalizeTailwindImportRequest(request, options);
|
|
2667
|
+
if (!normalizedRequest || !isTailwindImportRequest(normalizedRequest)) return;
|
|
2668
|
+
const normalizedParams = request && normalizedRequest !== request ? replaceImportRequest(node.params, request, normalizedRequest) : node.params;
|
|
2669
|
+
const normalizedKey = normalizedParams.trim();
|
|
2670
|
+
if (seenCanonicalImports.has(normalizedKey)) {
|
|
2671
|
+
node.remove();
|
|
2672
|
+
changed = true;
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
seenCanonicalImports.add(normalizedKey);
|
|
2676
|
+
if (normalizedParams !== node.params) {
|
|
2677
|
+
node.params = normalizedParams;
|
|
2678
|
+
changed = true;
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2681
|
+
return changed;
|
|
2682
|
+
}
|
|
2546
2683
|
function resolveConfigPath$1(base, configPath) {
|
|
2547
2684
|
if (node_path.default.isAbsolute(configPath) || isPackageJsonImportRequest$1(configPath)) return node_path.default.isAbsolute(configPath) ? configPath : void 0;
|
|
2548
2685
|
return node_path.default.resolve(base, configPath);
|
|
@@ -3116,7 +3253,7 @@ function readStaticConfigContent(configPath) {
|
|
|
3116
3253
|
return parseStaticContentValue(source, contentProperty.start)?.value;
|
|
3117
3254
|
}
|
|
3118
3255
|
//#endregion
|
|
3119
|
-
//#region src/bundlers/vite/source-scan.ts
|
|
3256
|
+
//#region src/bundlers/vite/source-scan/css-entries.ts
|
|
3120
3257
|
const VITE_SOURCE_CANDIDATE_PATTERN = FULL_SOURCE_SCAN_PATTERN;
|
|
3121
3258
|
function parseImportSourceParam(params) {
|
|
3122
3259
|
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
@@ -3280,6 +3417,40 @@ async function ensureTailwindcssRuntimePatch(twPatcher, options = {}) {
|
|
|
3280
3417
|
return task;
|
|
3281
3418
|
}
|
|
3282
3419
|
//#endregion
|
|
3420
|
+
//#region src/tailwindcss/v3-engine/generator/runtime-ready.ts
|
|
3421
|
+
const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
|
|
3422
|
+
function createRuntimeReadyCacheKey(source, rootPath) {
|
|
3423
|
+
return [
|
|
3424
|
+
source.packageName,
|
|
3425
|
+
source.postcssPlugin,
|
|
3426
|
+
rootPath ?? "missing",
|
|
3427
|
+
source.config ?? "config:missing",
|
|
3428
|
+
source.cwd
|
|
3429
|
+
].join("\0");
|
|
3430
|
+
}
|
|
3431
|
+
function createRuntimeReadyPromise(source) {
|
|
3432
|
+
const patcher = createTailwindcssPatcher({
|
|
3433
|
+
basedir: source.cwd,
|
|
3434
|
+
supportCustomLengthUnitsPatch: true,
|
|
3435
|
+
tailwindcss: {
|
|
3436
|
+
...source.config === void 0 ? {} : { config: source.config },
|
|
3437
|
+
cwd: source.cwd,
|
|
3438
|
+
packageName: source.packageName,
|
|
3439
|
+
postcssPlugin: source.postcssPlugin,
|
|
3440
|
+
version: 3
|
|
3441
|
+
}
|
|
3442
|
+
});
|
|
3443
|
+
const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
|
|
3444
|
+
const cached = runtimeReadyPromiseCache.get(cacheKey);
|
|
3445
|
+
if (cached) return cached;
|
|
3446
|
+
const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
|
|
3447
|
+
runtimeReadyPromiseCache.delete(cacheKey);
|
|
3448
|
+
throw error;
|
|
3449
|
+
});
|
|
3450
|
+
runtimeReadyPromiseCache.set(cacheKey, task);
|
|
3451
|
+
return task;
|
|
3452
|
+
}
|
|
3453
|
+
//#endregion
|
|
3283
3454
|
//#region src/tailwindcss/v3-engine/miniprogram.ts
|
|
3284
3455
|
const defaultStyleHandler = (0, _weapp_tailwindcss_postcss.createStyleHandler)({
|
|
3285
3456
|
cssChildCombinatorReplaceValue: ["view", "text"],
|
|
@@ -3361,33 +3532,7 @@ async function transformTailwindV3CssByTarget(css, target, options) {
|
|
|
3361
3532
|
}
|
|
3362
3533
|
//#endregion
|
|
3363
3534
|
//#region src/tailwindcss/v3-engine/generator.ts
|
|
3364
|
-
const runtimeReadyPromiseCache = /* @__PURE__ */ new Map();
|
|
3365
3535
|
const incrementalGenerateCache = /* @__PURE__ */ new Map();
|
|
3366
|
-
function isLegacyContentObject(value) {
|
|
3367
|
-
return typeof value === "object" && value !== null && "files" in value;
|
|
3368
|
-
}
|
|
3369
|
-
function createRawContentEntries(candidates, sources) {
|
|
3370
|
-
const entries = [];
|
|
3371
|
-
const candidateContent = [...candidates].join(" ");
|
|
3372
|
-
if (candidateContent.length > 0) entries.push({
|
|
3373
|
-
raw: candidateContent,
|
|
3374
|
-
extension: "html"
|
|
3375
|
-
});
|
|
3376
|
-
for (const source of sources) entries.push({
|
|
3377
|
-
raw: source.content,
|
|
3378
|
-
extension: source.extension ?? "html"
|
|
3379
|
-
});
|
|
3380
|
-
return entries;
|
|
3381
|
-
}
|
|
3382
|
-
function createChangedContentEntries(candidates, sources) {
|
|
3383
|
-
return createRawContentEntries(candidates, sources).map((entry) => ({
|
|
3384
|
-
content: entry.raw,
|
|
3385
|
-
extension: entry.extension
|
|
3386
|
-
}));
|
|
3387
|
-
}
|
|
3388
|
-
function collectCandidates(candidates) {
|
|
3389
|
-
return new Set(candidates ?? []);
|
|
3390
|
-
}
|
|
3391
3536
|
function normalizeBareArbitraryValueCandidate(candidate, bareArbitraryValues) {
|
|
3392
3537
|
return (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)?.canonicalCandidate ?? candidate;
|
|
3393
3538
|
}
|
|
@@ -3402,139 +3547,46 @@ function normalizeBareArbitraryValueCandidates(candidates, bareArbitraryValues)
|
|
|
3402
3547
|
return {
|
|
3403
3548
|
candidates: normalized,
|
|
3404
3549
|
restoreCandidates
|
|
3405
|
-
};
|
|
3406
|
-
}
|
|
3407
|
-
async function collectSourceBareArbitraryValueCandidates(sources, bareArbitraryValues) {
|
|
3408
|
-
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return [];
|
|
3409
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
3410
|
-
for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", { bareArbitraryValues })) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
|
|
3411
|
-
return [...candidates];
|
|
3412
|
-
}
|
|
3413
|
-
function escapeCssClassSelector(className) {
|
|
3414
|
-
return className.replace(/[^\w-]/g, (char) => `\\${char}`);
|
|
3415
|
-
}
|
|
3416
|
-
function restoreBareArbitraryValueCssSelectors(css, originalCandidates, bareArbitraryValues, escapeClassName) {
|
|
3417
|
-
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return css;
|
|
3418
|
-
let restored = css;
|
|
3419
|
-
for (const originalCandidate of originalCandidates) {
|
|
3420
|
-
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3421
|
-
if (canonical) restored = restored.split(`.${escapeClassName(canonical)}`).join(`.${escapeCssClassSelector(originalCandidate)}`);
|
|
3422
|
-
}
|
|
3423
|
-
return restored;
|
|
3424
|
-
}
|
|
3425
|
-
function restoreBareArbitraryValueClassSet(classSet, originalCandidates, bareArbitraryValues) {
|
|
3426
|
-
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return new Set(classSet);
|
|
3427
|
-
const restored = new Set(classSet);
|
|
3428
|
-
for (const originalCandidate of originalCandidates) {
|
|
3429
|
-
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3430
|
-
if (canonical && restored.has(canonical)) {
|
|
3431
|
-
restored.delete(canonical);
|
|
3432
|
-
restored.add(originalCandidate);
|
|
3433
|
-
}
|
|
3434
|
-
}
|
|
3435
|
-
return restored;
|
|
3436
|
-
}
|
|
3437
|
-
function collectGeneratedCandidates(context, candidates, restoreCandidates) {
|
|
3438
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
3439
|
-
for (const candidate of candidates) if (context.classCache.has(candidate)) classSet.add(restoreCandidates.get(candidate) ?? candidate);
|
|
3440
|
-
return classSet;
|
|
3441
|
-
}
|
|
3442
|
-
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
3443
|
-
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
3444
|
-
return false;
|
|
3445
|
-
}
|
|
3446
|
-
function collectApplyCandidatesFromCss(css) {
|
|
3447
|
-
if (!css.includes("@apply")) return [];
|
|
3448
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
3449
|
-
try {
|
|
3450
|
-
require_watch_dependencies.postcss_default.parse(css).walkAtRules("apply", (rule) => {
|
|
3451
|
-
for (const candidate of rule.params.split(/\s+/)) {
|
|
3452
|
-
const normalized = candidate.replace(/!important$/, "").trim();
|
|
3453
|
-
if (normalized) candidates.add(normalized);
|
|
3454
|
-
}
|
|
3455
|
-
});
|
|
3456
|
-
} catch {}
|
|
3457
|
-
return [...candidates];
|
|
3458
|
-
}
|
|
3459
|
-
function isTailwindCandidateLayer(params) {
|
|
3460
|
-
return params.split(/[,\s]+/).some((layer) => layer === "components" || layer === "utilities");
|
|
3461
|
-
}
|
|
3462
|
-
function extractClassCandidatesFromSelector(selector, candidates) {
|
|
3463
|
-
for (let index = 0; index < selector.length; index++) {
|
|
3464
|
-
if (selector[index] !== ".") continue;
|
|
3465
|
-
let candidate = "";
|
|
3466
|
-
let escaped = false;
|
|
3467
|
-
for (let tokenIndex = index + 1; tokenIndex < selector.length; tokenIndex++) {
|
|
3468
|
-
const char = selector[tokenIndex];
|
|
3469
|
-
if (escaped) {
|
|
3470
|
-
candidate += char;
|
|
3471
|
-
escaped = false;
|
|
3472
|
-
continue;
|
|
3473
|
-
}
|
|
3474
|
-
if (char === "\\") {
|
|
3475
|
-
escaped = true;
|
|
3476
|
-
continue;
|
|
3477
|
-
}
|
|
3478
|
-
if (char && /[\w-]/.test(char)) {
|
|
3479
|
-
candidate += char;
|
|
3480
|
-
continue;
|
|
3481
|
-
}
|
|
3482
|
-
break;
|
|
3483
|
-
}
|
|
3484
|
-
if (candidate) candidates.add(candidate);
|
|
3485
|
-
}
|
|
3550
|
+
};
|
|
3486
3551
|
}
|
|
3487
|
-
function
|
|
3488
|
-
if (!
|
|
3552
|
+
async function collectSourceBareArbitraryValueCandidates(sources, bareArbitraryValues) {
|
|
3553
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return [];
|
|
3489
3554
|
const candidates = /* @__PURE__ */ new Set();
|
|
3490
|
-
|
|
3491
|
-
require_watch_dependencies.postcss_default.parse(css).walkAtRules("layer", (layer) => {
|
|
3492
|
-
if (!isTailwindCandidateLayer(layer.params)) return;
|
|
3493
|
-
layer.walkRules((rule) => {
|
|
3494
|
-
extractClassCandidatesFromSelector(rule.selector, candidates);
|
|
3495
|
-
});
|
|
3496
|
-
});
|
|
3497
|
-
} catch {}
|
|
3555
|
+
for (const source of sources ?? []) for (const candidate of await (0, tailwindcss_patch.extractSourceCandidates)(source.content, source.extension ?? "html", omitUndefined({ bareArbitraryValues }))) if ((0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(candidate, bareArbitraryValues)) candidates.add(candidate);
|
|
3498
3556
|
return [...candidates];
|
|
3499
3557
|
}
|
|
3500
|
-
function
|
|
3501
|
-
return
|
|
3502
|
-
...collectLayerCandidatesFromCss(source.css),
|
|
3503
|
-
...collectApplyCandidatesFromCss(source.css),
|
|
3504
|
-
...collectCandidates(options.candidates)
|
|
3505
|
-
]);
|
|
3506
|
-
}
|
|
3507
|
-
function mergeContent(content, rawEntries) {
|
|
3508
|
-
if (isLegacyContentObject(content)) return {
|
|
3509
|
-
...content,
|
|
3510
|
-
relative: content.relative ?? true,
|
|
3511
|
-
files: [...[].concat(content.files ?? []), ...rawEntries]
|
|
3512
|
-
};
|
|
3513
|
-
return {
|
|
3514
|
-
relative: true,
|
|
3515
|
-
files: [...[].concat(content ?? []), ...rawEntries]
|
|
3516
|
-
};
|
|
3558
|
+
function escapeCssClassSelector(className) {
|
|
3559
|
+
return className.replace(/[^\w-]/g, (char) => `\\${char}`);
|
|
3517
3560
|
}
|
|
3518
|
-
function
|
|
3519
|
-
if (!
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3561
|
+
function restoreBareArbitraryValueCssSelectors(css, originalCandidates, bareArbitraryValues, escapeClassName) {
|
|
3562
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return css;
|
|
3563
|
+
let restored = css;
|
|
3564
|
+
for (const originalCandidate of originalCandidates) {
|
|
3565
|
+
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3566
|
+
if (canonical) restored = restored.split(`.${escapeClassName(canonical)}`).join(`.${escapeCssClassSelector(originalCandidate)}`);
|
|
3567
|
+
}
|
|
3568
|
+
return restored;
|
|
3523
3569
|
}
|
|
3524
|
-
function
|
|
3525
|
-
|
|
3570
|
+
function restoreBareArbitraryValueClassSet(classSet, originalCandidates, bareArbitraryValues) {
|
|
3571
|
+
if (!(0, tailwindcss_patch.isBareArbitraryValuesEnabled)(bareArbitraryValues)) return new Set(classSet);
|
|
3572
|
+
const restored = new Set(classSet);
|
|
3573
|
+
for (const originalCandidate of originalCandidates) {
|
|
3574
|
+
const canonical = (0, tailwindcss_patch.resolveBareArbitraryValueCandidate)(originalCandidate, bareArbitraryValues)?.canonicalCandidate;
|
|
3575
|
+
if (canonical && restored.has(canonical)) {
|
|
3576
|
+
restored.delete(canonical);
|
|
3577
|
+
restored.add(originalCandidate);
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
return restored;
|
|
3526
3581
|
}
|
|
3527
|
-
function
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
};
|
|
3582
|
+
function collectGeneratedCandidates(context, candidates, restoreCandidates) {
|
|
3583
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
3584
|
+
for (const candidate of candidates) if (context.classCache.has(candidate)) classSet.add(restoreCandidates.get(candidate) ?? candidate);
|
|
3585
|
+
return classSet;
|
|
3532
3586
|
}
|
|
3533
|
-
function
|
|
3534
|
-
const
|
|
3535
|
-
|
|
3536
|
-
config.content = hasExplicitContentInput(options) ? createExplicitContentConfig(rawEntries) : mergeContent(config.content, rawEntries);
|
|
3537
|
-
return config;
|
|
3587
|
+
function hasRemovedCandidates(previousCandidates, nextCandidates) {
|
|
3588
|
+
for (const candidate of previousCandidates) if (!nextCandidates.has(candidate)) return true;
|
|
3589
|
+
return false;
|
|
3538
3590
|
}
|
|
3539
3591
|
function shouldAutoEnableCssMacro(source) {
|
|
3540
3592
|
return hasCssMacroTailwindPlugin(normalizeConfigObject(source.configObject)?.plugins);
|
|
@@ -3575,48 +3627,6 @@ function loadTailwindV3Internals(source) {
|
|
|
3575
3627
|
validateConfig: validateConfigModule["validateConfig"]
|
|
3576
3628
|
};
|
|
3577
3629
|
}
|
|
3578
|
-
function createStableJson$1(value) {
|
|
3579
|
-
if (value === void 0) return "undefined";
|
|
3580
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
3581
|
-
if (Array.isArray(value)) return `[${value.map((item) => createStableJson$1(item)).join(",")}]`;
|
|
3582
|
-
return `{${Object.keys(value).sort().map((key) => {
|
|
3583
|
-
const record = value;
|
|
3584
|
-
return `${JSON.stringify(key)}:${createStableJson$1(record[key])}`;
|
|
3585
|
-
}).join(",")}}`;
|
|
3586
|
-
}
|
|
3587
|
-
function createDependencyFingerprint(files) {
|
|
3588
|
-
return files.map((file) => {
|
|
3589
|
-
try {
|
|
3590
|
-
const stat = node_fs.default.statSync(file);
|
|
3591
|
-
return `${file}:${stat.size}:${stat.mtimeMs}`;
|
|
3592
|
-
} catch {
|
|
3593
|
-
return `${file}:missing`;
|
|
3594
|
-
}
|
|
3595
|
-
}).join("|");
|
|
3596
|
-
}
|
|
3597
|
-
function createIncrementalGenerateCacheKey(source, target, styleOptions, bareArbitraryValues) {
|
|
3598
|
-
return [
|
|
3599
|
-
source.packageName,
|
|
3600
|
-
source.postcssPlugin,
|
|
3601
|
-
source.cwd,
|
|
3602
|
-
source.config ?? "config:missing",
|
|
3603
|
-
createDependencyFingerprint(source.dependencies),
|
|
3604
|
-
source.css,
|
|
3605
|
-
createStableJson$1(normalizeConfigObject(source.configObject)?.content),
|
|
3606
|
-
target,
|
|
3607
|
-
createStableJson$1(styleOptions),
|
|
3608
|
-
createStableJson$1(bareArbitraryValues)
|
|
3609
|
-
].join("\0");
|
|
3610
|
-
}
|
|
3611
|
-
function createRuntimeReadyCacheKey(source, rootPath) {
|
|
3612
|
-
return [
|
|
3613
|
-
source.packageName,
|
|
3614
|
-
source.postcssPlugin,
|
|
3615
|
-
rootPath ?? "missing",
|
|
3616
|
-
source.config ?? "config:missing",
|
|
3617
|
-
source.cwd
|
|
3618
|
-
].join("\0");
|
|
3619
|
-
}
|
|
3620
3630
|
function isDirectUtilitiesOnlyCss(css) {
|
|
3621
3631
|
return css.replace(/\s+/g, "") === "@tailwindutilities;";
|
|
3622
3632
|
}
|
|
@@ -3649,28 +3659,6 @@ function appendUtilityRules(root, context, rules) {
|
|
|
3649
3659
|
function appendDirectUtilityRules(root, context) {
|
|
3650
3660
|
appendUtilityRules(root, context, [...context.ruleCache]);
|
|
3651
3661
|
}
|
|
3652
|
-
function createRuntimeReadyPromise(source) {
|
|
3653
|
-
const patcher = createTailwindcssPatcher({
|
|
3654
|
-
basedir: source.cwd,
|
|
3655
|
-
supportCustomLengthUnitsPatch: true,
|
|
3656
|
-
tailwindcss: {
|
|
3657
|
-
...source.config === void 0 ? {} : { config: source.config },
|
|
3658
|
-
cwd: source.cwd,
|
|
3659
|
-
packageName: source.packageName,
|
|
3660
|
-
postcssPlugin: source.postcssPlugin,
|
|
3661
|
-
version: 3
|
|
3662
|
-
}
|
|
3663
|
-
});
|
|
3664
|
-
const cacheKey = createRuntimeReadyCacheKey(source, patcher.packageInfo?.rootPath);
|
|
3665
|
-
const cached = runtimeReadyPromiseCache.get(cacheKey);
|
|
3666
|
-
if (cached) return cached;
|
|
3667
|
-
const task = ensureTailwindcssRuntimePatch(patcher, { clearRequireCache: true }).catch((error) => {
|
|
3668
|
-
runtimeReadyPromiseCache.delete(cacheKey);
|
|
3669
|
-
throw error;
|
|
3670
|
-
});
|
|
3671
|
-
runtimeReadyPromiseCache.set(cacheKey, task);
|
|
3672
|
-
return task;
|
|
3673
|
-
}
|
|
3674
3662
|
function createTailwindV3Engine(source) {
|
|
3675
3663
|
const runtimeReadyPromise = createRuntimeReadyPromise(source);
|
|
3676
3664
|
let tailwindInternals;
|
|
@@ -3756,7 +3744,7 @@ function createTailwindV3Engine(source) {
|
|
|
3756
3744
|
const requestedCandidates = mergeGenerateCandidates(source, options);
|
|
3757
3745
|
if (requestedCandidates.size === 0) return generateOnce(source, options);
|
|
3758
3746
|
const styleOptions = resolveStyleOptions(source, options.styleOptions);
|
|
3759
|
-
const cacheKey = createIncrementalGenerateCacheKey(source, target, styleOptions, options.bareArbitraryValues);
|
|
3747
|
+
const cacheKey = createIncrementalGenerateCacheKey$1(source, target, styleOptions, options.bareArbitraryValues);
|
|
3760
3748
|
const cached = incrementalGenerateCache.get(cacheKey);
|
|
3761
3749
|
if (cached) {
|
|
3762
3750
|
if (hasRemovedCandidates(cached.seenCandidates, requestedCandidates)) {
|
|
@@ -3915,63 +3903,220 @@ function resolveTailwindV3SourceOptionsFromPatcher(patcher) {
|
|
|
3915
3903
|
function resolveTailwindV3SourceFromPatcher(patcher) {
|
|
3916
3904
|
return resolveTailwindV3Source(resolveTailwindV3SourceOptionsFromPatcher(patcher));
|
|
3917
3905
|
}
|
|
3918
|
-
//#endregion
|
|
3919
|
-
//#region src/generator/options.ts
|
|
3920
|
-
const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
|
|
3921
|
-
const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
|
|
3922
|
-
const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
|
|
3923
|
-
function getEnvValue(key) {
|
|
3924
|
-
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
3906
|
+
//#endregion
|
|
3907
|
+
//#region src/generator/options.ts
|
|
3908
|
+
const explicitGeneratorTargetEnvKeys = ["WEAPP_TW_TARGET", "WEAPP_TAILWINDCSS_TARGET"];
|
|
3909
|
+
const uniWebPlatformEnvKeys = ["UNI_PLATFORM", "UNI_UTS_PLATFORM"];
|
|
3910
|
+
const mpxWebPlatformEnvKeys = ["MPX_CLI_MODE", "MPX_CURRENT_TARGET_MODE"];
|
|
3911
|
+
function getEnvValue(key) {
|
|
3912
|
+
return typeof node_process.default === "undefined" ? void 0 : node_process.default.env[key];
|
|
3913
|
+
}
|
|
3914
|
+
function normalizeGeneratorTargetValue(value) {
|
|
3915
|
+
return value === "weapp" || value === "web" || value === "tailwind" ? value : void 0;
|
|
3916
|
+
}
|
|
3917
|
+
function isUniWebPlatform(value) {
|
|
3918
|
+
const normalized = value?.trim().toLowerCase();
|
|
3919
|
+
return normalized === "h5" || normalized?.startsWith("web") === true;
|
|
3920
|
+
}
|
|
3921
|
+
function isUniAppWebViewPlatform(value) {
|
|
3922
|
+
const normalized = value?.trim().toLowerCase();
|
|
3923
|
+
return normalized === "app" || normalized === "app-plus";
|
|
3924
|
+
}
|
|
3925
|
+
function isUniNativeAppPlatform(value) {
|
|
3926
|
+
return (value?.trim().toLowerCase())?.startsWith("app-") === true;
|
|
3927
|
+
}
|
|
3928
|
+
function isMpxWebPlatform(value) {
|
|
3929
|
+
return value?.trim().toLowerCase() === "web";
|
|
3930
|
+
}
|
|
3931
|
+
function inferGeneratorTargetFromEnv() {
|
|
3932
|
+
for (const key of explicitGeneratorTargetEnvKeys) {
|
|
3933
|
+
const target = normalizeGeneratorTargetValue(getEnvValue(key));
|
|
3934
|
+
if (target !== void 0) return target;
|
|
3935
|
+
}
|
|
3936
|
+
if (uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5") return "web";
|
|
3937
|
+
return "weapp";
|
|
3938
|
+
}
|
|
3939
|
+
function normalizeWeappTailwindcssGeneratorOptions(options) {
|
|
3940
|
+
const target = options?.target ?? inferGeneratorTargetFromEnv();
|
|
3941
|
+
if (options == null) return {
|
|
3942
|
+
target,
|
|
3943
|
+
importFallback: true,
|
|
3944
|
+
tailwindcssV3Compatibility: target === "weapp",
|
|
3945
|
+
bareArbitraryValues: void 0
|
|
3946
|
+
};
|
|
3947
|
+
return {
|
|
3948
|
+
target,
|
|
3949
|
+
config: options.config,
|
|
3950
|
+
styleOptions: options.styleOptions,
|
|
3951
|
+
importFallback: options.importFallback ?? true,
|
|
3952
|
+
tailwindcssV3Compatibility: options.tailwindcssV3Compatibility ?? target === "weapp",
|
|
3953
|
+
bareArbitraryValues: options.bareArbitraryValues
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
//#endregion
|
|
3957
|
+
//#region src/generator/index.ts
|
|
3958
|
+
function isTailwindV3Source(source) {
|
|
3959
|
+
return "version" in source && source.version === 3;
|
|
3960
|
+
}
|
|
3961
|
+
function createWeappTailwindcssGenerator(source) {
|
|
3962
|
+
return isTailwindV3Source(source) ? createTailwindV3Engine(source) : createTailwindV4Engine(source);
|
|
3963
|
+
}
|
|
3964
|
+
//#endregion
|
|
3965
|
+
//#region src/uni-app-x/options.ts
|
|
3966
|
+
const DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS = {
|
|
3967
|
+
enabled: true,
|
|
3968
|
+
onlyWhenStyleIsolationVersion2: true
|
|
3969
|
+
};
|
|
3970
|
+
const DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS = {
|
|
3971
|
+
enabled: false,
|
|
3972
|
+
onlyWhenStyleIsolationVersion2: true
|
|
3973
|
+
};
|
|
3974
|
+
function isBooleanUniAppXShortcut(option) {
|
|
3975
|
+
return option === true || option === false || option === void 0;
|
|
3976
|
+
}
|
|
3977
|
+
function resolveComponentLocalStyles(option) {
|
|
3978
|
+
if (isBooleanUniAppXShortcut(option)) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
3979
|
+
const componentLocalStyles = option.componentLocalStyles;
|
|
3980
|
+
if (componentLocalStyles === false) return DISABLED_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
3981
|
+
if (componentLocalStyles === true || componentLocalStyles === void 0) return DEFAULT_COMPONENT_LOCAL_STYLES_OPTIONS;
|
|
3982
|
+
return {
|
|
3983
|
+
enabled: componentLocalStyles.enabled !== false,
|
|
3984
|
+
onlyWhenStyleIsolationVersion2: componentLocalStyles.onlyWhenStyleIsolationVersion2 !== false
|
|
3985
|
+
};
|
|
3986
|
+
}
|
|
3987
|
+
function resolveUniAppXOptions(option) {
|
|
3988
|
+
if (typeof option === "object" && option) return {
|
|
3989
|
+
enabled: option.enabled !== false,
|
|
3990
|
+
componentLocalStyles: resolveComponentLocalStyles(option),
|
|
3991
|
+
uvueUnsupported: option.uvueUnsupported ?? "warn"
|
|
3992
|
+
};
|
|
3993
|
+
return {
|
|
3994
|
+
enabled: Boolean(option),
|
|
3995
|
+
componentLocalStyles: resolveComponentLocalStyles(option),
|
|
3996
|
+
uvueUnsupported: "warn"
|
|
3997
|
+
};
|
|
3998
|
+
}
|
|
3999
|
+
function isUniAppXEnabled(option) {
|
|
4000
|
+
return resolveUniAppXOptions(option).enabled;
|
|
4001
|
+
}
|
|
4002
|
+
//#endregion
|
|
4003
|
+
//#region src/context/style-options.ts
|
|
4004
|
+
function resolveStyleOptionsFromContext(ctx) {
|
|
4005
|
+
const resolvedUniAppXOptions = resolveUniAppXOptions(ctx.uniAppX);
|
|
4006
|
+
return {
|
|
4007
|
+
cssPreflight: ctx.cssPreflight,
|
|
4008
|
+
cssPreflightRange: ctx.cssPreflightRange,
|
|
4009
|
+
cssChildCombinatorReplaceValue: ctx.cssChildCombinatorReplaceValue,
|
|
4010
|
+
cssSelectorReplacement: ctx.cssSelectorReplacement,
|
|
4011
|
+
rem2rpx: ctx.rem2rpx,
|
|
4012
|
+
cssRemoveProperty: ctx.cssRemoveProperty,
|
|
4013
|
+
cssRemoveHoverPseudoClass: ctx.cssRemoveHoverPseudoClass,
|
|
4014
|
+
cssPresetEnv: ctx.cssPresetEnv,
|
|
4015
|
+
autoprefixer: ctx.autoprefixer,
|
|
4016
|
+
cssCalc: ctx.cssCalc,
|
|
4017
|
+
uniAppX: resolvedUniAppXOptions.enabled,
|
|
4018
|
+
platform: ctx.platform,
|
|
4019
|
+
px2rpx: ctx.px2rpx,
|
|
4020
|
+
unitsToPx: ctx.unitsToPx,
|
|
4021
|
+
unitConversion: ctx.unitConversion
|
|
4022
|
+
};
|
|
4023
|
+
}
|
|
4024
|
+
//#endregion
|
|
4025
|
+
//#region src/bundlers/shared/generator-css/generation-helpers.ts
|
|
4026
|
+
function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
|
|
4027
|
+
if (target !== "weapp") return css;
|
|
4028
|
+
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
4029
|
+
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
4030
|
+
isTailwindcssV4: majorVersion === 4,
|
|
4031
|
+
preservePseudoContentInit: majorVersion === 3
|
|
4032
|
+
});
|
|
4033
|
+
}
|
|
4034
|
+
function shouldInjectMiniProgramPreflightForGeneratorCss(opts, options) {
|
|
4035
|
+
if (options.cssHandlerOptions.uniAppX === true && options.cssHandlerOptions.uniAppXCssTarget === "uvue") return false;
|
|
4036
|
+
if (!options.isolateCurrentCssCandidates) return true;
|
|
4037
|
+
return isUniAppXEnabled(opts.uniAppX) && Boolean(options.localImports?.trim());
|
|
3925
4038
|
}
|
|
3926
|
-
function
|
|
3927
|
-
|
|
4039
|
+
function mergeScopedRuntimeWithCurrentRuntime(scopedRuntime, runtime, options) {
|
|
4040
|
+
if (options.isolateCssSource && options.currentCssCandidates?.length) return new Set([...scopedRuntime, ...options.currentCssCandidates]);
|
|
4041
|
+
if (runtime.size === 0 || !options.cssHandlerOptions.isMainChunk || options.matchedCssSourceFile || options.isolateCssSource && scopedRuntime.size === 0) return scopedRuntime;
|
|
4042
|
+
return new Set([...scopedRuntime, ...runtime]);
|
|
3928
4043
|
}
|
|
3929
|
-
function
|
|
3930
|
-
|
|
3931
|
-
return normalized === "h5" || normalized?.startsWith("web") === true;
|
|
4044
|
+
function shouldIsolateScopedCssSource(source, sourceEntries) {
|
|
4045
|
+
return Boolean(source.__weappTailwindcssMeta?.matchedCssSourceFile) || sourceEntries !== void 0 && sourceEntries.length > 0;
|
|
3932
4046
|
}
|
|
3933
|
-
function
|
|
3934
|
-
|
|
3935
|
-
return normalized === "app" || normalized === "app-plus";
|
|
4047
|
+
function shouldIsolateCurrentTailwindV4CssCandidates(majorVersion, cssHandlerOptions, options) {
|
|
4048
|
+
return majorVersion === 4 && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(options.rawSource) && !hasTailwindRootDirectives(options.rawSource) && !options.hasGeneratedCss && !options.hasGeneratedMarkers;
|
|
3936
4049
|
}
|
|
3937
|
-
function
|
|
3938
|
-
|
|
4050
|
+
function shouldScanTailwindV4Sources(majorVersion, target, generatorRuntime, isolateCssSource) {
|
|
4051
|
+
if (majorVersion !== 4) return false;
|
|
4052
|
+
if (target === "web") return true;
|
|
4053
|
+
if (isolateCssSource) return false;
|
|
4054
|
+
return generatorRuntime.size === 0;
|
|
3939
4055
|
}
|
|
3940
|
-
function
|
|
3941
|
-
return
|
|
4056
|
+
function shouldAppendWebBundleCssFallback(target, options) {
|
|
4057
|
+
return target === "web" && !options.hasMatchedCssSourceFile && !options.hasSourceDirectives;
|
|
3942
4058
|
}
|
|
3943
|
-
function
|
|
3944
|
-
|
|
3945
|
-
const target = normalizeGeneratorTargetValue(getEnvValue(key));
|
|
3946
|
-
if (target !== void 0) return target;
|
|
3947
|
-
}
|
|
3948
|
-
if (uniWebPlatformEnvKeys.some((key) => isUniWebPlatform(getEnvValue(key))) || isUniAppWebViewPlatform(getEnvValue("UNI_PLATFORM")) && !isUniNativeAppPlatform(getEnvValue("UNI_UTS_PLATFORM")) || mpxWebPlatformEnvKeys.some((key) => isMpxWebPlatform(getEnvValue(key))) || getEnvValue("TARO_ENV") === "h5") return "web";
|
|
3949
|
-
return "weapp";
|
|
4059
|
+
function isEmptyCssSourceOrderParts(parts) {
|
|
4060
|
+
return parts.before.trim().length === 0 && parts.after.trim().length === 0;
|
|
3950
4061
|
}
|
|
3951
|
-
function
|
|
3952
|
-
const
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
importFallback: true,
|
|
3956
|
-
tailwindcssV3Compatibility: target === "weapp",
|
|
3957
|
-
bareArbitraryValues: void 0
|
|
4062
|
+
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
4063
|
+
const preflightStyleOptions = {
|
|
4064
|
+
cssPreflight: opts.cssPreflight,
|
|
4065
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
3958
4066
|
};
|
|
3959
4067
|
return {
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
4068
|
+
...resolveStyleOptionsFromContext(opts),
|
|
4069
|
+
atRules: opts.atRules,
|
|
4070
|
+
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
4071
|
+
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
4072
|
+
...cssHandlerOptions,
|
|
4073
|
+
...preflightStyleOptions,
|
|
4074
|
+
...generatorStyleOptions
|
|
3966
4075
|
};
|
|
3967
4076
|
}
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
4077
|
+
function createCssSourceOrderAppend$1(base, extra) {
|
|
4078
|
+
if (!base) return extra;
|
|
4079
|
+
if (!extra) return base;
|
|
4080
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
4081
|
+
return `${base}\n${extra}`;
|
|
3972
4082
|
}
|
|
3973
|
-
function
|
|
3974
|
-
return
|
|
4083
|
+
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
4084
|
+
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
4085
|
+
}
|
|
4086
|
+
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
4087
|
+
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
4088
|
+
if (placeholderParts) return placeholderParts;
|
|
4089
|
+
const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
|
|
4090
|
+
if (exactParts) return exactParts;
|
|
4091
|
+
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
4092
|
+
}
|
|
4093
|
+
function shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, options) {
|
|
4094
|
+
const hasApplyDirectives = hasTailwindApplyDirective(options.rawSource);
|
|
4095
|
+
return options.hasGeneratedCss || options.hasGeneratedMarkers || options.hasSourceDirectives || majorVersion === 4 && hasApplyDirectives || cssHandlerOptions.isMainChunk;
|
|
4096
|
+
}
|
|
4097
|
+
function createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates) {
|
|
4098
|
+
return isolateCurrentCssCandidates ? new Set(currentCssCandidates) : currentCssCandidates.length > 0 ? new Set([...runtime, ...currentCssCandidates]) : runtime;
|
|
4099
|
+
}
|
|
4100
|
+
function mergeGeneratorResults(generatedResults) {
|
|
4101
|
+
const firstGenerated = generatedResults[0];
|
|
4102
|
+
if (!firstGenerated) return;
|
|
4103
|
+
if (generatedResults.length === 1) return firstGenerated;
|
|
4104
|
+
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
4105
|
+
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
4106
|
+
return {
|
|
4107
|
+
...firstGenerated,
|
|
4108
|
+
css: generatedResults.map((item) => item.css).join("\n"),
|
|
4109
|
+
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
4110
|
+
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
4111
|
+
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
4112
|
+
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
4113
|
+
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
4114
|
+
sources: generatedResults.flatMap((item) => item.sources)
|
|
4115
|
+
};
|
|
4116
|
+
}
|
|
4117
|
+
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
4118
|
+
function isSupportedGeneratorMajorVersion(majorVersion) {
|
|
4119
|
+
return SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0);
|
|
3975
4120
|
}
|
|
3976
4121
|
//#endregion
|
|
3977
4122
|
//#region src/wxml/shared.ts
|
|
@@ -4375,13 +4520,6 @@ function isPathWithinRoot$1(file, root) {
|
|
|
4375
4520
|
const relative = node_path.default.relative(root, file);
|
|
4376
4521
|
return Boolean(relative) && !relative.startsWith("..") && !node_path.default.isAbsolute(relative);
|
|
4377
4522
|
}
|
|
4378
|
-
function countCommonSuffixSegments(a, b) {
|
|
4379
|
-
const aSegments = a.split("/").filter(Boolean);
|
|
4380
|
-
const bSegments = b.split("/").filter(Boolean);
|
|
4381
|
-
let count = 0;
|
|
4382
|
-
while (count < aSegments.length && count < bSegments.length && aSegments[aSegments.length - 1 - count] === bSegments[bSegments.length - 1 - count]) count++;
|
|
4383
|
-
return count;
|
|
4384
|
-
}
|
|
4385
4523
|
function collectOutputMatchBases(file, sourceOptions) {
|
|
4386
4524
|
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
4387
4525
|
const roots = [
|
|
@@ -4416,7 +4554,7 @@ function isMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
|
4416
4554
|
const normalizedRoot = node_path.default.resolve(root);
|
|
4417
4555
|
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
4418
4556
|
}
|
|
4419
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)
|
|
4557
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
4420
4558
|
return false;
|
|
4421
4559
|
}
|
|
4422
4560
|
function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
@@ -4434,13 +4572,9 @@ function scoreMatchingSourceStyleFile(file, sourceFile, sourceOptions) {
|
|
|
4434
4572
|
if (isPathWithinRoot$1(normalizedSourceFile, normalizedRoot)) addSourceBase(node_path.default.relative(normalizedRoot, normalizedSourceFile));
|
|
4435
4573
|
}
|
|
4436
4574
|
let bestScore = 0;
|
|
4437
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases)
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
4441
|
-
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4442
|
-
else if (commonSuffixSegments >= 2) bestScore = Math.max(bestScore, 100 + commonSuffixSegments);
|
|
4443
|
-
}
|
|
4575
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
4576
|
+
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
4577
|
+
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
4444
4578
|
return bestScore;
|
|
4445
4579
|
}
|
|
4446
4580
|
function collectMatchedConfiguredSourceFiles(file, sourceOptions) {
|
|
@@ -4599,7 +4733,7 @@ function canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) {
|
|
|
4599
4733
|
return true;
|
|
4600
4734
|
}
|
|
4601
4735
|
function shouldResolveSourceSideCssEntry(rawSource) {
|
|
4602
|
-
return rawSource.includes("@apply") || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
4736
|
+
return rawSource.includes("@apply") || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindGeneratedCss(rawSource) || hasTailwindGeneratedCssMarkers(rawSource);
|
|
4603
4737
|
}
|
|
4604
4738
|
function shouldPreferTailwindV3SourceSideEntry(rawSource, sourceSideEntrySource) {
|
|
4605
4739
|
return Boolean(sourceSideEntrySource) && !hasTailwindSourceDirectives(rawSource, { importFallback: true });
|
|
@@ -4644,17 +4778,6 @@ function collectCssSourceMatchBases(file, roots) {
|
|
|
4644
4778
|
} else for (const root of resolvedRoots) addBase(node_path.default.resolve(root, normalizedFile));
|
|
4645
4779
|
return bases;
|
|
4646
4780
|
}
|
|
4647
|
-
function hasMatchingCssSourceBase(outputBases, sourceBases) {
|
|
4648
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase || outputBase.endsWith(`/${sourceBase}`) || sourceBase.endsWith(`/${outputBase}`)) return true;
|
|
4649
|
-
return false;
|
|
4650
|
-
}
|
|
4651
|
-
function isMatchingTailwindV4CssSourceFile(file, cssSourceFile, sourceOptions) {
|
|
4652
|
-
return hasMatchingCssSourceBase(collectCssSourceMatchBases(file, [
|
|
4653
|
-
sourceOptions.outputRoot,
|
|
4654
|
-
sourceOptions.projectRoot,
|
|
4655
|
-
sourceOptions.cwd
|
|
4656
|
-
]), collectCssSourceMatchBases(cssSourceFile, [sourceOptions.projectRoot, sourceOptions.cwd]));
|
|
4657
|
-
}
|
|
4658
4781
|
function scoreTailwindV4CssSourceFileMatch(file, cssSourceFile, sourceOptions) {
|
|
4659
4782
|
const outputBases = collectCssSourceMatchBases(file, [
|
|
4660
4783
|
sourceOptions.outputRoot,
|
|
@@ -4741,12 +4864,29 @@ async function resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOpt
|
|
|
4741
4864
|
if (!cssSources?.length) return;
|
|
4742
4865
|
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
4743
4866
|
const sourceFile = resolvePostcssSourceFile(cssHandlerOptions);
|
|
4744
|
-
const
|
|
4745
|
-
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return
|
|
4746
|
-
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4867
|
+
const matches = cssSources.map((cssSource, index) => {
|
|
4868
|
+
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) return;
|
|
4869
|
+
if (sourceFile && typeof cssSource.file === "string" && node_path.default.resolve(sourceFile) === node_path.default.resolve(cssSource.file)) return {
|
|
4870
|
+
cssSource,
|
|
4871
|
+
index,
|
|
4872
|
+
score: 1e6
|
|
4873
|
+
};
|
|
4874
|
+
if (typeof cssSource.file === "string") {
|
|
4875
|
+
const pathScore = scoreTailwindV4CssSourceFileMatch(file, cssSource.file, sourceOptions);
|
|
4876
|
+
if (pathScore > 0) return {
|
|
4877
|
+
cssSource,
|
|
4878
|
+
index,
|
|
4879
|
+
score: pathScore
|
|
4880
|
+
};
|
|
4881
|
+
}
|
|
4882
|
+
if (normalizeCssSourceForCompare(cssSource.css) === normalizedRawSource) return {
|
|
4883
|
+
cssSource,
|
|
4884
|
+
index,
|
|
4885
|
+
score: 1
|
|
4886
|
+
};
|
|
4887
|
+
}).filter((match) => Boolean(match)).sort((a, b) => b.score - a.score || a.index - b.index);
|
|
4888
|
+
const bestScore = matches[0]?.score;
|
|
4889
|
+
const matchingSource = bestScore && matches.filter((match) => match.score === bestScore).length === 1 ? matches[0]?.cssSource : void 0;
|
|
4750
4890
|
if (!matchingSource) return;
|
|
4751
4891
|
return resolveSingleTailwindV4CssSource(matchingSource, sourceOptions, { matched: true });
|
|
4752
4892
|
}
|
|
@@ -4818,7 +4958,10 @@ function createTailwindV4CssSourceResolver(sourceOptions, generatorOptions) {
|
|
|
4818
4958
|
async function resolveTailwindV4SourceSideEntrySource(resolvedEntrySource, sourceOptions, generatorOptions, file) {
|
|
4819
4959
|
if (!resolvedEntrySource) return;
|
|
4820
4960
|
const resolvedSourceOptions = omitUndefined(sourceOptions);
|
|
4821
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file,
|
|
4961
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, {
|
|
4962
|
+
...resolvedSourceOptions,
|
|
4963
|
+
sourceFile: resolvedEntrySource.file
|
|
4964
|
+
});
|
|
4822
4965
|
const css = createTailwindV4ApplyReferenceSource(normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config), resolvedSourceOptions);
|
|
4823
4966
|
return withMatchedSourceSideMetadata(await resolveTailwindV4Source(createSingleTailwindV4SourceOptions(resolvedSourceOptions, {
|
|
4824
4967
|
base: resolvedEntrySource.base,
|
|
@@ -4849,7 +4992,25 @@ function withMatchedSourceSideMetadata(source, resolvedEntrySource) {
|
|
|
4849
4992
|
}
|
|
4850
4993
|
function createTailwindV4ApplyReferenceSource(css, sourceOptions) {
|
|
4851
4994
|
if (!hasTailwindApplyDirective(css) || hasTailwindRootDirectives(css)) return css;
|
|
4852
|
-
|
|
4995
|
+
const utilities = collectTailwindApplyUtilities(css);
|
|
4996
|
+
return [
|
|
4997
|
+
`@import "${sourceOptions.packageName ?? "tailwindcss"}" source(none);`,
|
|
4998
|
+
utilities.length > 0 ? `@source inline(${JSON.stringify(utilities.join(" "))});` : void 0,
|
|
4999
|
+
css
|
|
5000
|
+
].filter(Boolean).join("\n");
|
|
5001
|
+
}
|
|
5002
|
+
function collectTailwindApplyUtilities(css) {
|
|
5003
|
+
let root;
|
|
5004
|
+
try {
|
|
5005
|
+
root = require_watch_dependencies.postcss_default.parse(css);
|
|
5006
|
+
} catch {
|
|
5007
|
+
return [];
|
|
5008
|
+
}
|
|
5009
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
5010
|
+
root.walkAtRules("apply", (rule) => {
|
|
5011
|
+
for (const utility of (0, tailwindcss_patch.splitCandidateTokens)(rule.params)) utilities.add(utility);
|
|
5012
|
+
});
|
|
5013
|
+
return [...utilities].sort();
|
|
4853
5014
|
}
|
|
4854
5015
|
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions, selectionOptions) {
|
|
4855
5016
|
const base = resolveCssSourceBase(file, cssHandlerOptions);
|
|
@@ -4962,11 +5123,15 @@ async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, fi
|
|
|
4962
5123
|
return resolved ? [resolved] : [];
|
|
4963
5124
|
}
|
|
4964
5125
|
const matchedCssEntrySource = sourceOptions ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
5126
|
+
if (matchedCssEntrySource) return [generatorOptions?.config ? {
|
|
5127
|
+
...matchedCssEntrySource,
|
|
5128
|
+
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
5129
|
+
} : matchedCssEntrySource];
|
|
5130
|
+
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
5131
|
+
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
4965
5132
|
const matchedCssSource = await resolveMatchingTailwindV4CssSource(rawSource, file, cssHandlerOptions, sourceOptions);
|
|
4966
5133
|
const candidateMatchedCssSource = await resolveCandidateMatchedTailwindV4CssSource(rawSource, cssHandlerOptions, sourceOptions, selectionOptions);
|
|
4967
|
-
const sourceSideCssSource = await resolveTailwindV4SourceSideEntrySource((shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder")) && (sourceOptions.cssEntries?.length ?? 0) <= 1) && canResolveSourceSideCssEntry(file, cssHandlerOptions, sourceOptions) ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0, sourceOptions, generatorOptions, file);
|
|
4968
5134
|
const preferredCssEntrySource = matchedCssEntrySource ?? matchedCssSource ?? candidateMatchedCssSource;
|
|
4969
|
-
if (sourceSideCssSource) return [sourceSideCssSource];
|
|
4970
5135
|
if (preferredCssEntrySource) return [generatorOptions?.config ? {
|
|
4971
5136
|
...preferredCssEntrySource,
|
|
4972
5137
|
css: prependConfigDirective(preferredCssEntrySource.css, generatorOptions.config)
|
|
@@ -5144,6 +5309,27 @@ function resolveLegacyCompatCssSource(rawSource) {
|
|
|
5144
5309
|
setLimitedCacheValue(legacyCompatSourceCache, rawSource, resolved);
|
|
5145
5310
|
return resolved;
|
|
5146
5311
|
}
|
|
5312
|
+
function removeMiniProgramContainerCompatCss(css) {
|
|
5313
|
+
try {
|
|
5314
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5315
|
+
let removed = false;
|
|
5316
|
+
root.walkRules((rule) => {
|
|
5317
|
+
if (rule.selectors?.length === 1 && rule.selectors[0] === ".container") {
|
|
5318
|
+
rule.remove();
|
|
5319
|
+
removed = true;
|
|
5320
|
+
}
|
|
5321
|
+
});
|
|
5322
|
+
root.walkAtRules((atRule) => {
|
|
5323
|
+
if (atRule.nodes && atRule.nodes.length === 0) {
|
|
5324
|
+
atRule.remove();
|
|
5325
|
+
removed = true;
|
|
5326
|
+
}
|
|
5327
|
+
});
|
|
5328
|
+
return removed ? root.toString() : css;
|
|
5329
|
+
} catch {
|
|
5330
|
+
return css;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5147
5333
|
function hasContainerConfigToken(rawSource) {
|
|
5148
5334
|
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
5149
5335
|
}
|
|
@@ -5172,7 +5358,8 @@ function hasConfiguredContainerCompatSources(sources) {
|
|
|
5172
5358
|
return sources.some((source) => hasConfiguredContainerCompatSource(source));
|
|
5173
5359
|
}
|
|
5174
5360
|
async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
5175
|
-
const
|
|
5361
|
+
const resolvedCompatSource = resolveLegacyCompatCssSource(rawSource);
|
|
5362
|
+
const compatSource = removeGeneratedSelectorCompatCss(generatorTarget === "weapp" ? removeMiniProgramContainerCompatCss(resolvedCompatSource) : resolvedCompatSource, css);
|
|
5176
5363
|
if (compatSource.trim().length === 0) return css;
|
|
5177
5364
|
if (generatorTarget !== "weapp") return createCssAppend(css, compatSource);
|
|
5178
5365
|
const styleOptions = {
|
|
@@ -5190,6 +5377,7 @@ async function appendLegacyCompatCss(css, rawSource, generatorTarget, styleHandl
|
|
|
5190
5377
|
return createCssAppend(css, cleanedCompatCss);
|
|
5191
5378
|
}
|
|
5192
5379
|
async function appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generatorTarget, styleHandler, cssHandlerOptions, generatorStyleOptions) {
|
|
5380
|
+
if (generatorTarget === "weapp") return css;
|
|
5193
5381
|
const compatSource = resolveLegacyCompatCssSource(rawSource);
|
|
5194
5382
|
const shouldAppendContainer = runtime.has("container") || hasConfiguredContainerCompat(rawSource, file, cssHandlerOptions) || configuredContainerCompat || collectGeneratedSelectors(compatSource).has(".container");
|
|
5195
5383
|
if (generatorTarget !== "weapp" || !shouldAppendContainer || collectGeneratedSelectors(css).has(".container")) return css;
|
|
@@ -5252,98 +5440,106 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
5252
5440
|
}
|
|
5253
5441
|
}
|
|
5254
5442
|
//#endregion
|
|
5255
|
-
//#region src/bundlers/shared/generator-css/
|
|
5256
|
-
const
|
|
5257
|
-
|
|
5258
|
-
const UTILITY_LAYER_INSERTION_RES = [
|
|
5259
|
-
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
5260
|
-
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
5261
|
-
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
5262
|
-
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
5263
|
-
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
5264
|
-
];
|
|
5265
|
-
function appendCss(base, extra) {
|
|
5443
|
+
//#region src/bundlers/shared/generator-css/local-imports.ts
|
|
5444
|
+
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
5445
|
+
function createCssSourceOrderAppend(base, extra) {
|
|
5266
5446
|
if (!base) return extra;
|
|
5267
5447
|
if (!extra) return base;
|
|
5268
5448
|
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
5269
5449
|
return `${base}\n${extra}`;
|
|
5270
5450
|
}
|
|
5271
|
-
function
|
|
5272
|
-
return
|
|
5451
|
+
function isLocalImportRequest(request) {
|
|
5452
|
+
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
5273
5453
|
}
|
|
5274
|
-
function
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
rest += css.slice(cursor, startIndex);
|
|
5285
|
-
const contentStart = startIndex + 47;
|
|
5286
|
-
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
5287
|
-
if (endIndex === -1) {
|
|
5288
|
-
rest += css.slice(startIndex);
|
|
5289
|
-
break;
|
|
5454
|
+
function isPureLocalCssImportWrapper(css) {
|
|
5455
|
+
let hasImport = false;
|
|
5456
|
+
try {
|
|
5457
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5458
|
+
for (const node of root.nodes) {
|
|
5459
|
+
if (node.type === "comment") continue;
|
|
5460
|
+
if (node.type !== "atrule" || node.name !== "import") return false;
|
|
5461
|
+
const request = parseImportRequest(node.params);
|
|
5462
|
+
if (!request || !isLocalImportRequest(request)) return false;
|
|
5463
|
+
hasImport = true;
|
|
5290
5464
|
}
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
cursor = endIndex + 45;
|
|
5294
|
-
}
|
|
5295
|
-
return {
|
|
5296
|
-
layers,
|
|
5297
|
-
rest
|
|
5298
|
-
};
|
|
5299
|
-
}
|
|
5300
|
-
function findUtilityLayerInsertionIndex(css) {
|
|
5301
|
-
let index = -1;
|
|
5302
|
-
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
5303
|
-
const match = pattern.exec(css);
|
|
5304
|
-
if (!match) continue;
|
|
5305
|
-
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
5306
|
-
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
5465
|
+
} catch {
|
|
5466
|
+
return false;
|
|
5307
5467
|
}
|
|
5308
|
-
return
|
|
5309
|
-
}
|
|
5310
|
-
function reorderMarkedUserLayerComponentsCss(css) {
|
|
5311
|
-
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
5312
|
-
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
5313
|
-
if (layers.length === 0) return rest;
|
|
5314
|
-
const layerCss = layers.join("\n");
|
|
5315
|
-
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
5316
|
-
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
5317
|
-
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
5318
|
-
}
|
|
5319
|
-
//#endregion
|
|
5320
|
-
//#region src/bundlers/shared/generator-css.ts
|
|
5321
|
-
const SUPPORTED_GENERATOR_MAJOR_VERSIONS = new Set([3, 4]);
|
|
5322
|
-
const REMOTE_IMPORT_RE = /^(?:https?:)?\/\//i;
|
|
5323
|
-
function finalizeMiniProgramGeneratorCss(css, target, majorVersion, cssPreflight, options = {}) {
|
|
5324
|
-
if (target !== "weapp") return css;
|
|
5325
|
-
return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, {
|
|
5326
|
-
cssPreflight: majorVersion === 4 && options.injectPreflight !== false ? cssPreflight : void 0,
|
|
5327
|
-
isTailwindcssV4: majorVersion === 4,
|
|
5328
|
-
preservePseudoContentInit: majorVersion === 3
|
|
5329
|
-
});
|
|
5468
|
+
return hasImport;
|
|
5330
5469
|
}
|
|
5331
|
-
function
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5470
|
+
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
5471
|
+
let hasLocalImport = false;
|
|
5472
|
+
let hasTailwindDirective = false;
|
|
5473
|
+
try {
|
|
5474
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5475
|
+
for (const node of root.nodes) {
|
|
5476
|
+
if (node.type === "comment") continue;
|
|
5477
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
5478
|
+
const request = parseImportRequest(node.params);
|
|
5479
|
+
if (!request || !isLocalImportRequest(request)) return;
|
|
5480
|
+
hasLocalImport = true;
|
|
5481
|
+
continue;
|
|
5482
|
+
}
|
|
5483
|
+
if (node.type === "atrule" && node.name === "source") {
|
|
5484
|
+
hasTailwindDirective = true;
|
|
5485
|
+
continue;
|
|
5486
|
+
}
|
|
5487
|
+
return;
|
|
5488
|
+
}
|
|
5489
|
+
} catch {
|
|
5490
|
+
return;
|
|
5491
|
+
}
|
|
5492
|
+
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
|
|
5335
5493
|
}
|
|
5336
|
-
function
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5494
|
+
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
5495
|
+
try {
|
|
5496
|
+
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5497
|
+
root.walkAtRules("import", (atRule) => {
|
|
5498
|
+
const request = parseImportRequest(atRule.params);
|
|
5499
|
+
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
5500
|
+
});
|
|
5501
|
+
return root.toString();
|
|
5502
|
+
} catch {
|
|
5503
|
+
return css;
|
|
5504
|
+
}
|
|
5340
5505
|
}
|
|
5341
|
-
function
|
|
5342
|
-
|
|
5506
|
+
function splitLocalCssImports(source) {
|
|
5507
|
+
try {
|
|
5508
|
+
const root = require_watch_dependencies.postcss_default.parse(source);
|
|
5509
|
+
const importRoot = require_watch_dependencies.postcss_default.root();
|
|
5510
|
+
let changed = false;
|
|
5511
|
+
for (const node of [...root.nodes]) {
|
|
5512
|
+
if (node.type !== "atrule" || node.name !== "import") continue;
|
|
5513
|
+
const request = parseImportRequest(node.params);
|
|
5514
|
+
if (!request || !isLocalImportRequest(request)) continue;
|
|
5515
|
+
importRoot.append(node.clone());
|
|
5516
|
+
node.remove();
|
|
5517
|
+
changed = true;
|
|
5518
|
+
}
|
|
5519
|
+
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
5520
|
+
return changed ? {
|
|
5521
|
+
imports,
|
|
5522
|
+
source: root.toString()
|
|
5523
|
+
} : void 0;
|
|
5524
|
+
} catch {
|
|
5525
|
+
return;
|
|
5526
|
+
}
|
|
5343
5527
|
}
|
|
5344
|
-
function
|
|
5345
|
-
|
|
5528
|
+
function restoreLocalCssImports(css, imports) {
|
|
5529
|
+
if (!imports?.trim()) return css;
|
|
5530
|
+
return createCssSourceOrderAppend(imports, css);
|
|
5346
5531
|
}
|
|
5532
|
+
//#endregion
|
|
5533
|
+
//#region src/bundlers/shared/generator-css/user-css.ts
|
|
5534
|
+
const TAILWIND_V4_GENERATOR_AT_RULES = new Set([
|
|
5535
|
+
"config",
|
|
5536
|
+
"custom-variant",
|
|
5537
|
+
"plugin",
|
|
5538
|
+
"source",
|
|
5539
|
+
"theme",
|
|
5540
|
+
"utility",
|
|
5541
|
+
"variant"
|
|
5542
|
+
]);
|
|
5347
5543
|
function removeTailwindApplyAtRules(source) {
|
|
5348
5544
|
if (!source.includes("@apply")) return source;
|
|
5349
5545
|
try {
|
|
@@ -5361,33 +5557,25 @@ function removeTailwindApplyAtRules(source) {
|
|
|
5361
5557
|
return source;
|
|
5362
5558
|
}
|
|
5363
5559
|
}
|
|
5364
|
-
function
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
5384
|
-
...cssHandlerOptions,
|
|
5385
|
-
...preflightStyleOptions,
|
|
5386
|
-
...generatorStyleOptions
|
|
5387
|
-
};
|
|
5388
|
-
}
|
|
5389
|
-
function isLocalImportRequest(request) {
|
|
5390
|
-
return request.length > 0 && !request.startsWith("#") && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
5560
|
+
function removeTailwindV4GeneratorAtRules(source) {
|
|
5561
|
+
try {
|
|
5562
|
+
const root = require_watch_dependencies.postcss_default.parse(source);
|
|
5563
|
+
let changed = false;
|
|
5564
|
+
root.walkAtRules((rule) => {
|
|
5565
|
+
if (!TAILWIND_V4_GENERATOR_AT_RULES.has(rule.name)) return;
|
|
5566
|
+
rule.remove();
|
|
5567
|
+
changed = true;
|
|
5568
|
+
});
|
|
5569
|
+
root.walk((node) => {
|
|
5570
|
+
if ("nodes" in node && node.nodes?.length === 0) {
|
|
5571
|
+
node.remove();
|
|
5572
|
+
changed = true;
|
|
5573
|
+
}
|
|
5574
|
+
});
|
|
5575
|
+
return changed ? root.toString() : source;
|
|
5576
|
+
} catch {
|
|
5577
|
+
return source;
|
|
5578
|
+
}
|
|
5391
5579
|
}
|
|
5392
5580
|
function isCommentOnlyCss(source) {
|
|
5393
5581
|
try {
|
|
@@ -5398,7 +5586,19 @@ function isCommentOnlyCss(source) {
|
|
|
5398
5586
|
}
|
|
5399
5587
|
}
|
|
5400
5588
|
function stripTailwindSourceMediaFragments(source) {
|
|
5401
|
-
|
|
5589
|
+
let removedSourceMediaStart = false;
|
|
5590
|
+
return source.split(/\r?\n/).filter((line) => {
|
|
5591
|
+
if (/^\s*@media\s+source\([^)]*\)\s*\{\s*$/.test(line)) {
|
|
5592
|
+
removedSourceMediaStart = true;
|
|
5593
|
+
return false;
|
|
5594
|
+
}
|
|
5595
|
+
if (/^\s*\}\s*\/\*\s*source\([^)]*\)\s*\*\/\s*$/.test(line)) return false;
|
|
5596
|
+
if (removedSourceMediaStart && /^\s*\}\s*$/.test(line)) {
|
|
5597
|
+
removedSourceMediaStart = false;
|
|
5598
|
+
return false;
|
|
5599
|
+
}
|
|
5600
|
+
return true;
|
|
5601
|
+
}).join("\n").replace(/\}[^\S\r\n]*(?=@(?:config|source)\b)/g, "");
|
|
5402
5602
|
}
|
|
5403
5603
|
function stripLeadingTailwindSourceMediaCloseFragment(source) {
|
|
5404
5604
|
return source.replace(/^\s*\}\s*(?:\n|$)/, "");
|
|
@@ -5411,22 +5611,6 @@ function stripUnmatchedTailwindSourceMediaCloseFragments(source) {
|
|
|
5411
5611
|
return stripLeadingTailwindSourceMediaCloseFragment(source).replace(/\s*\}\s*$/, "");
|
|
5412
5612
|
}
|
|
5413
5613
|
}
|
|
5414
|
-
function createCssSourceOrderAppend(base, extra) {
|
|
5415
|
-
if (!base) return extra;
|
|
5416
|
-
if (!extra) return base;
|
|
5417
|
-
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
5418
|
-
return `${base}\n${extra}`;
|
|
5419
|
-
}
|
|
5420
|
-
function shouldFinalizeMarkedUserLayerComponentsCss(file) {
|
|
5421
|
-
return !/\.(?:vue|svelte|astro|scss|sass|less|styl)(?:[?#].*)?$/i.test(file);
|
|
5422
|
-
}
|
|
5423
|
-
function splitRawSourceByGeneratedCssOrder(rawSource, rawTailwindCss) {
|
|
5424
|
-
const placeholderParts = splitGeneratorPlaceholderCssBySourceOrder(rawSource, rawTailwindCss);
|
|
5425
|
-
if (placeholderParts) return placeholderParts;
|
|
5426
|
-
const exactParts = splitTailwindV4GeneratedCssBySourceOrder(rawSource, rawTailwindCss);
|
|
5427
|
-
if (exactParts) return exactParts;
|
|
5428
|
-
return splitTailwindGeneratedCssByBanner(rawSource);
|
|
5429
|
-
}
|
|
5430
5614
|
function splitUserCssLayerBlocks(source) {
|
|
5431
5615
|
if (!source.includes("@layer")) return {
|
|
5432
5616
|
layer: "",
|
|
@@ -5566,7 +5750,7 @@ function shouldFilterApplyOnlyGeneratedCss(majorVersion, target, source, options
|
|
|
5566
5750
|
}
|
|
5567
5751
|
async function transformGeneratorUserCss(source, options) {
|
|
5568
5752
|
if (source.trim().length === 0) return "";
|
|
5569
|
-
const cleanedSource = removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source)), { importFallback: options.importFallback });
|
|
5753
|
+
const cleanedSource = removeTailwindSourceDirectives(removeTailwindV4GeneratorAtRules(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(source))), { importFallback: options.importFallback });
|
|
5570
5754
|
if (cleanedSource.trim().length === 0) return "";
|
|
5571
5755
|
const userSource = stripUnmatchedTailwindSourceMediaCloseFragments(removeTailwindApplyAtRules(removeTailwindSourceDirectives(stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(options.generatorTarget === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedSource) : cleanedSource)), { importFallback: options.importFallback })));
|
|
5572
5756
|
if (userSource.trim().length === 0) return "";
|
|
@@ -5578,84 +5762,73 @@ async function transformGeneratorUserCss(source, options) {
|
|
|
5578
5762
|
});
|
|
5579
5763
|
return (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(css);
|
|
5580
5764
|
}
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
return
|
|
5765
|
+
//#endregion
|
|
5766
|
+
//#region src/bundlers/shared/generator-css/user-layer-order.ts
|
|
5767
|
+
const USER_LAYER_COMPONENTS_START = "/*! weapp-tailwindcss layer components start */";
|
|
5768
|
+
const USER_LAYER_COMPONENTS_END = "/*! weapp-tailwindcss layer components end */";
|
|
5769
|
+
const UTILITY_LAYER_INSERTION_RES = [
|
|
5770
|
+
/(^|\n)\.(?:fixed|absolute|relative|sticky|static)\s*\{/,
|
|
5771
|
+
/(^|\n)\.(?:block|inline-block|inline|flex|inline-flex|grid|hidden)\s*\{/,
|
|
5772
|
+
/(^|\n)\.(?:m|mx|my|mt|mr|mb|ml|p|px|py|pt|pr|pb|pl)-/,
|
|
5773
|
+
/(^|\n)\.(?:w|h|min-w|min-h|max-w|max-h)-/,
|
|
5774
|
+
/(^|\n)\.(?:bg|text|border|rounded|shadow|opacity|transition|transform|translate|scale|rotate|gap|items|justify|content)-/
|
|
5775
|
+
];
|
|
5776
|
+
function appendCss(base, extra) {
|
|
5777
|
+
if (!base) return extra;
|
|
5778
|
+
if (!extra) return base;
|
|
5779
|
+
if (/\s$/.test(base) || /^\s/.test(extra)) return `${base}${extra}`;
|
|
5780
|
+
return `${base}\n${extra}`;
|
|
5596
5781
|
}
|
|
5597
|
-
function
|
|
5598
|
-
|
|
5599
|
-
let hasTailwindDirective = false;
|
|
5600
|
-
try {
|
|
5601
|
-
const root = require_watch_dependencies.postcss_default.parse(css);
|
|
5602
|
-
for (const node of root.nodes) {
|
|
5603
|
-
if (node.type === "comment") continue;
|
|
5604
|
-
if (node.type === "atrule" && node.name === "import") {
|
|
5605
|
-
const request = parseImportRequest(node.params);
|
|
5606
|
-
if (!request || !isLocalImportRequest(request)) return;
|
|
5607
|
-
hasLocalImport = true;
|
|
5608
|
-
continue;
|
|
5609
|
-
}
|
|
5610
|
-
if (node.type === "atrule" && node.name === "source") {
|
|
5611
|
-
hasTailwindDirective = true;
|
|
5612
|
-
continue;
|
|
5613
|
-
}
|
|
5614
|
-
return;
|
|
5615
|
-
}
|
|
5616
|
-
} catch {
|
|
5617
|
-
return;
|
|
5618
|
-
}
|
|
5619
|
-
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
|
|
5782
|
+
function wrapUserLayerComponentsCss(css) {
|
|
5783
|
+
return css.trim().length > 0 ? `${USER_LAYER_COMPONENTS_START}\n${css}\n${USER_LAYER_COMPONENTS_END}` : css;
|
|
5620
5784
|
}
|
|
5621
|
-
function
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
|
|
5625
|
-
|
|
5626
|
-
|
|
5627
|
-
|
|
5628
|
-
|
|
5629
|
-
|
|
5630
|
-
|
|
5785
|
+
function extractMarkedUserLayerComponentsCss(css) {
|
|
5786
|
+
const layers = [];
|
|
5787
|
+
let rest = "";
|
|
5788
|
+
let cursor = 0;
|
|
5789
|
+
while (cursor < css.length) {
|
|
5790
|
+
const startIndex = css.indexOf(USER_LAYER_COMPONENTS_START, cursor);
|
|
5791
|
+
if (startIndex === -1) {
|
|
5792
|
+
rest += css.slice(cursor);
|
|
5793
|
+
break;
|
|
5794
|
+
}
|
|
5795
|
+
rest += css.slice(cursor, startIndex);
|
|
5796
|
+
const contentStart = startIndex + 47;
|
|
5797
|
+
const endIndex = css.indexOf(USER_LAYER_COMPONENTS_END, contentStart);
|
|
5798
|
+
if (endIndex === -1) {
|
|
5799
|
+
rest += css.slice(startIndex);
|
|
5800
|
+
break;
|
|
5801
|
+
}
|
|
5802
|
+
const layerCss = css.slice(contentStart, endIndex).trim();
|
|
5803
|
+
if (layerCss) layers.push(layerCss);
|
|
5804
|
+
cursor = endIndex + 45;
|
|
5631
5805
|
}
|
|
5806
|
+
return {
|
|
5807
|
+
layers,
|
|
5808
|
+
rest
|
|
5809
|
+
};
|
|
5632
5810
|
}
|
|
5633
|
-
function
|
|
5634
|
-
|
|
5635
|
-
|
|
5636
|
-
const
|
|
5637
|
-
|
|
5638
|
-
|
|
5639
|
-
|
|
5640
|
-
const request = parseImportRequest(node.params);
|
|
5641
|
-
if (!request || !isLocalImportRequest(request)) continue;
|
|
5642
|
-
importRoot.append(node.clone());
|
|
5643
|
-
node.remove();
|
|
5644
|
-
changed = true;
|
|
5645
|
-
}
|
|
5646
|
-
const imports = importRoot.nodes.filter((node) => node.type === "atrule" && node.name === "import").map((node) => `@import ${node.params};`).join("\n");
|
|
5647
|
-
return changed ? {
|
|
5648
|
-
imports,
|
|
5649
|
-
source: root.toString()
|
|
5650
|
-
} : void 0;
|
|
5651
|
-
} catch {
|
|
5652
|
-
return;
|
|
5811
|
+
function findUtilityLayerInsertionIndex(css) {
|
|
5812
|
+
let index = -1;
|
|
5813
|
+
for (const pattern of UTILITY_LAYER_INSERTION_RES) {
|
|
5814
|
+
const match = pattern.exec(css);
|
|
5815
|
+
if (!match) continue;
|
|
5816
|
+
const nextIndex = match.index + (match[1]?.length ?? 0);
|
|
5817
|
+
index = index === -1 ? nextIndex : Math.min(index, nextIndex);
|
|
5653
5818
|
}
|
|
5819
|
+
return index;
|
|
5654
5820
|
}
|
|
5655
|
-
function
|
|
5656
|
-
if (!
|
|
5657
|
-
|
|
5821
|
+
function reorderMarkedUserLayerComponentsCss(css) {
|
|
5822
|
+
if (!css.includes(USER_LAYER_COMPONENTS_START)) return css;
|
|
5823
|
+
const { layers, rest } = extractMarkedUserLayerComponentsCss(css);
|
|
5824
|
+
if (layers.length === 0) return rest;
|
|
5825
|
+
const layerCss = layers.join("\n");
|
|
5826
|
+
const insertionIndex = findUtilityLayerInsertionIndex(rest);
|
|
5827
|
+
if (insertionIndex === -1) return appendCss(rest, layerCss);
|
|
5828
|
+
return appendCss(appendCss(rest.slice(0, insertionIndex), layerCss), rest.slice(insertionIndex));
|
|
5658
5829
|
}
|
|
5830
|
+
//#endregion
|
|
5831
|
+
//#region src/bundlers/shared/generator-css.ts
|
|
5659
5832
|
async function generateCssByGenerator(options) {
|
|
5660
5833
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, getSourceCandidatesForEntries, styleHandler, debug } = options;
|
|
5661
5834
|
const generatorOptions = {
|
|
@@ -5666,6 +5839,7 @@ async function generateCssByGenerator(options) {
|
|
|
5666
5839
|
const effectiveRawSource = stripUnmatchedTailwindSourceMediaCloseFragments(stripTailwindSourceMediaFragments(normalizeTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })));
|
|
5667
5840
|
const localImportParts = splitLocalCssImports(effectiveRawSource);
|
|
5668
5841
|
const generatorRawSource = localImportParts?.source ?? effectiveRawSource;
|
|
5842
|
+
const userCssRawSource = majorVersion === 4 ? removeTailwindV4GeneratorAtRules(generatorRawSource) : generatorRawSource;
|
|
5669
5843
|
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(effectiveRawSource);
|
|
5670
5844
|
if (cleanedLocalImportWrapper !== void 0) return {
|
|
5671
5845
|
css: generatorOptions.target === "weapp" ? (0, _weapp_tailwindcss_postcss.removeUnsupportedMiniProgramAtRules)(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
@@ -5677,8 +5851,13 @@ async function generateCssByGenerator(options) {
|
|
|
5677
5851
|
const hasGeneratedCss = hasTailwindGeneratedCss(generatorRawSource);
|
|
5678
5852
|
const hasSourceDirectives = hasTailwindSourceDirectives(generatorRawSource, { importFallback: generatorOptions.importFallback });
|
|
5679
5853
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(generatorRawSource);
|
|
5680
|
-
const shouldGenerateCurrentCss =
|
|
5681
|
-
|
|
5854
|
+
const shouldGenerateCurrentCss = shouldUseGeneratorForCurrentCss(majorVersion, cssHandlerOptions, {
|
|
5855
|
+
hasGeneratedCss,
|
|
5856
|
+
hasGeneratedMarkers,
|
|
5857
|
+
hasSourceDirectives,
|
|
5858
|
+
rawSource: generatorRawSource
|
|
5859
|
+
});
|
|
5860
|
+
if (!isSupportedGeneratorMajorVersion(majorVersion) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
5682
5861
|
try {
|
|
5683
5862
|
await runtimeState.readyPromise;
|
|
5684
5863
|
const currentCssCandidates = majorVersion === 4 ? await (0, tailwindcss_patch.extractSourceCandidates)(generatorRawSource, "css", { ...generatorOptions.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: generatorOptions.bareArbitraryValues } }) : [];
|
|
@@ -5687,7 +5866,7 @@ async function generateCssByGenerator(options) {
|
|
|
5687
5866
|
hasGeneratedMarkers,
|
|
5688
5867
|
rawSource: generatorRawSource
|
|
5689
5868
|
});
|
|
5690
|
-
const runtimeWithCurrentCss =
|
|
5869
|
+
const runtimeWithCurrentCss = createRuntimeWithCurrentCssCandidates(runtime, currentCssCandidates, isolateCurrentCssCandidates);
|
|
5691
5870
|
const sources = await resolveGeneratorSources(majorVersion, runtimeState, generatorRawSource, file, cssHandlerOptions, generatorOptions, {
|
|
5692
5871
|
cssEntries: opts.cssEntries,
|
|
5693
5872
|
getSourceCandidatesForEntries,
|
|
@@ -5695,12 +5874,13 @@ async function generateCssByGenerator(options) {
|
|
|
5695
5874
|
});
|
|
5696
5875
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
5697
5876
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
5698
|
-
const
|
|
5877
|
+
const generated = mergeGeneratorResults((await Promise.all(sources.map(async (source) => {
|
|
5699
5878
|
const generator = createWeappTailwindcssGenerator(source);
|
|
5700
5879
|
const sourceEntries = getSourceCandidatesForEntries && (majorVersion === 3 || majorVersion === 4) ? await resolveGeneratorSourceEntries(source, runtimeState) : void 0;
|
|
5701
5880
|
const scopedRuntime = sourceEntries ? getSourceCandidatesForEntries?.(sourceEntries) : void 0;
|
|
5702
5881
|
const isolateCssSource = shouldIsolateScopedCssSource(source, sourceEntries);
|
|
5703
|
-
const
|
|
5882
|
+
const sourceMetadata = source.__weappTailwindcssMeta;
|
|
5883
|
+
const matchedCssSourceFile = Boolean(sourceMetadata?.matchedCssSourceFile);
|
|
5704
5884
|
if (options.deferEmptyScopedCssSource && isolateCssSource && scopedRuntime?.size === 0 && currentCssCandidates.length === 0 && !cssHandlerOptions.isMainChunk) {
|
|
5705
5885
|
debug("defer empty scoped css source generation: %s", file);
|
|
5706
5886
|
return;
|
|
@@ -5722,21 +5902,8 @@ async function generateCssByGenerator(options) {
|
|
|
5722
5902
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
5723
5903
|
target: generatorOptions.target
|
|
5724
5904
|
});
|
|
5725
|
-
}))).filter((item) => Boolean(item));
|
|
5726
|
-
|
|
5727
|
-
if (!firstGenerated) return;
|
|
5728
|
-
const incrementalCssResults = generatedResults.map((item) => item.incrementalCss).filter((css) => typeof css === "string");
|
|
5729
|
-
const incrementalRawCssResults = generatedResults.map((item) => item.incrementalRawCss).filter((css) => typeof css === "string");
|
|
5730
|
-
const generated = generatedResults.length === 1 ? firstGenerated : {
|
|
5731
|
-
...firstGenerated,
|
|
5732
|
-
css: generatedResults.map((item) => item.css).join("\n"),
|
|
5733
|
-
rawCss: generatedResults.map((item) => item.rawCss).join("\n"),
|
|
5734
|
-
incrementalCss: incrementalCssResults.length === generatedResults.length ? incrementalCssResults.filter(Boolean).join("\n") : void 0,
|
|
5735
|
-
incrementalRawCss: incrementalRawCssResults.length === generatedResults.length ? incrementalRawCssResults.filter(Boolean).join("\n") : void 0,
|
|
5736
|
-
classSet: new Set(generatedResults.flatMap((item) => [...item.classSet])),
|
|
5737
|
-
dependencies: [...new Set(generatedResults.flatMap((item) => item.dependencies))],
|
|
5738
|
-
sources: generatedResults.flatMap((item) => item.sources)
|
|
5739
|
-
};
|
|
5905
|
+
}))).filter((item) => Boolean(item)));
|
|
5906
|
+
if (!generated) return;
|
|
5740
5907
|
debug("tailwind generator result: %s rawBytes=%d cssBytes=%d candidates=%d", file, generated.rawCss.length, generated.css.length, generated.classSet.size);
|
|
5741
5908
|
if ((generated.target !== "weapp" || !hasUserCssLayerBlocks(generatorRawSource)) && typeof options.previousCss === "string" && typeof generated.incrementalCss === "string") {
|
|
5742
5909
|
const incrementalCss = stripTailwindBanner(generated.incrementalCss);
|
|
@@ -5754,7 +5921,7 @@ async function generateCssByGenerator(options) {
|
|
|
5754
5921
|
});
|
|
5755
5922
|
const generatedCss = shouldFilterApplyOnlyCss ? filterApplyOnlyGeneratedCss(stripTailwindBanner(generated.css), generatorRawSource) : stripTailwindBanner(generated.css);
|
|
5756
5923
|
const hasMatchedCssSourceFile = sources.some((source) => source.__weappTailwindcssMeta?.matchedCssSourceFile);
|
|
5757
|
-
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(
|
|
5924
|
+
const orderedExtraCss = hasMatchedCssSourceFile ? splitTailwindV4GeneratedCssBySourceOrder(userCssRawSource, generated.rawCss) : splitRawSourceByGeneratedCssOrder(userCssRawSource, generated.rawCss);
|
|
5758
5925
|
const shouldAppendMatchedCssSourceCompat = !hasMatchedCssSourceFile || orderedExtraCss !== void 0;
|
|
5759
5926
|
if (orderedExtraCss) {
|
|
5760
5927
|
let css = generatedCss;
|
|
@@ -5773,19 +5940,19 @@ async function generateCssByGenerator(options) {
|
|
|
5773
5940
|
const beforeUserCss = await transformGeneratorUserCss(orderedExtraCss.before, userCssOptions);
|
|
5774
5941
|
const afterLayerUserCss = await transformGeneratorUserCss(afterLayerParts.layer, userCssOptions);
|
|
5775
5942
|
const afterUserCss = await transformGeneratorUserCss(afterLayerParts.rest, userCssOptions);
|
|
5776
|
-
css = createCssSourceOrderAppend(createCssSourceOrderAppend(createCssSourceOrderAppend(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
5943
|
+
css = createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(createCssSourceOrderAppend$1(beforeUserCss, generated.target === "weapp" ? wrapUserLayerComponentsCss(afterLayerUserCss) : afterLayerUserCss), css), afterUserCss);
|
|
5777
5944
|
if (isEmptyCssSourceOrderParts(orderedExtraCss) && shouldAppendWebBundleCssFallback(generated.target, {
|
|
5778
5945
|
hasSourceDirectives,
|
|
5779
5946
|
hasMatchedCssSourceFile
|
|
5780
5947
|
})) {
|
|
5781
|
-
const userCss = await transformGeneratorUserCss(
|
|
5782
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
5948
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, userCssOptions);
|
|
5949
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5783
5950
|
}
|
|
5784
5951
|
if (generated.target === "weapp" && shouldAppendMatchedCssSourceCompat) {
|
|
5785
5952
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5786
5953
|
if (!shouldFilterApplyOnlyCss) {
|
|
5787
|
-
css = await appendLegacyCompatCss(css,
|
|
5788
|
-
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css,
|
|
5954
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5955
|
+
if (!isolateCurrentCssCandidates) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5789
5956
|
}
|
|
5790
5957
|
} else if (generated.target === "weapp" && shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5791
5958
|
return {
|
|
@@ -5817,37 +5984,37 @@ async function generateCssByGenerator(options) {
|
|
|
5817
5984
|
rest: css
|
|
5818
5985
|
} : extractGeneratedCssForUserLayerSelectors(css, layerParts.layer);
|
|
5819
5986
|
if (layerCss.layer.trim().length > 0) {
|
|
5820
|
-
css = createCssSourceOrderAppend(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
5987
|
+
css = createCssSourceOrderAppend$1(wrapUserLayerComponentsCss(layerCss.layer), layerCss.rest);
|
|
5821
5988
|
if (shouldFinalizeMarkedUserLayerComponentsCss(file)) css = reorderMarkedUserLayerComponentsCss(css);
|
|
5822
5989
|
}
|
|
5823
5990
|
}
|
|
5824
5991
|
}
|
|
5825
5992
|
if (hasMatchedCssSourceFile || generated.target === "web") {
|
|
5826
5993
|
if (hasMatchedCssSourceFile && generated.target === "weapp" && !hasGeneratedCss && !hasGeneratedMarkers) {
|
|
5827
|
-
const userCss = await transformGeneratorUserCss(
|
|
5994
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
5828
5995
|
generatorTarget: generated.target,
|
|
5829
5996
|
generatorStyleOptions,
|
|
5830
5997
|
cssUserHandlerOptions,
|
|
5831
5998
|
styleHandler,
|
|
5832
5999
|
importFallback: generatorOptions.importFallback
|
|
5833
6000
|
});
|
|
5834
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
6001
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5835
6002
|
}
|
|
5836
6003
|
if (hasMatchedCssSourceFile && generated.target === "weapp") {
|
|
5837
|
-
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css,
|
|
6004
|
+
if (!isolateCurrentCssCandidates && !shouldFilterApplyOnlyCss) css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5838
6005
|
}
|
|
5839
6006
|
if (shouldAppendWebBundleCssFallback(generated.target, {
|
|
5840
6007
|
hasSourceDirectives,
|
|
5841
6008
|
hasMatchedCssSourceFile
|
|
5842
6009
|
})) {
|
|
5843
|
-
const userCss = await transformGeneratorUserCss(
|
|
6010
|
+
const userCss = await transformGeneratorUserCss(userCssRawSource, {
|
|
5844
6011
|
generatorTarget: generated.target,
|
|
5845
6012
|
generatorStyleOptions,
|
|
5846
6013
|
cssUserHandlerOptions,
|
|
5847
6014
|
styleHandler,
|
|
5848
6015
|
importFallback: generatorOptions.importFallback
|
|
5849
6016
|
});
|
|
5850
|
-
css = createCssSourceOrderAppend(css, userCss);
|
|
6017
|
+
css = createCssSourceOrderAppend$1(css, userCss);
|
|
5851
6018
|
}
|
|
5852
6019
|
return {
|
|
5853
6020
|
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|
|
@@ -5861,8 +6028,8 @@ async function generateCssByGenerator(options) {
|
|
|
5861
6028
|
};
|
|
5862
6029
|
}
|
|
5863
6030
|
if (!shouldFilterApplyOnlyCss) {
|
|
5864
|
-
css = await appendLegacyCompatCss(css,
|
|
5865
|
-
css = await appendLegacyContainerCompatCss(css,
|
|
6031
|
+
css = await appendLegacyCompatCss(css, userCssRawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
6032
|
+
css = await appendLegacyContainerCompatCss(css, userCssRawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
5866
6033
|
}
|
|
5867
6034
|
return {
|
|
5868
6035
|
css: restoreLocalCssImports(finalizeMiniProgramGeneratorCss(css, generated.target, majorVersion, opts.cssPreflight, { injectPreflight: shouldInjectMiniProgramPreflightForGeneratorCss(opts, {
|