weapp-tailwindcss 5.0.0-next.1 → 5.0.0-next.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/bundle-state-BRkhpjio.js +448 -0
- package/dist/bundle-state-BrtFgX-A.mjs +369 -0
- package/dist/bundlers/shared/cache.d.ts +6 -6
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
- package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
- package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
- package/dist/bundlers/shared/css-imports.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
- package/dist/bundlers/shared/generator-css.d.ts +12 -20
- package/dist/bundlers/shared/hmr-timing.d.ts +5 -0
- package/dist/bundlers/shared/style-requests.d.ts +2 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +4 -1
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
- package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +16 -2
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +4 -1
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +5 -3
- package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
- package/dist/bundlers/vite/source-candidates.d.ts +18 -0
- package/dist/bundlers/vite/source-scan.d.ts +9 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +5 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -1
- package/dist/cache/index.d.ts +6 -6
- package/dist/cache-B_9E7FxF.js +517 -0
- package/dist/cache-DEDxBMIw.mjs +443 -0
- package/dist/cli/context.d.ts +1 -14
- package/dist/cli/doctor/types.d.ts +11 -11
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli/vscode-entry.d.ts +3 -3
- package/dist/cli.js +126 -602
- package/dist/cli.mjs +135 -610
- package/dist/constants.d.ts +1 -2
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +3 -2
- package/dist/css-macro/postcss.mjs +3 -2
- package/dist/css-macro.d.ts +1 -0
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +33 -14
- package/dist/defaults.mjs +30 -15
- package/dist/escape.js +10 -2
- package/dist/escape.mjs +10 -2
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +10 -7
- package/dist/generator/types.d.ts +3 -2
- package/dist/generator-CahkD2vq.mjs +1469 -0
- package/dist/generator-Ck1Dd1V0.js +1568 -0
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +149 -47
- package/dist/gulp.mjs +144 -42
- package/dist/incremental-runtime-class-set-CBMefNHQ.js +1744 -0
- package/dist/incremental-runtime-class-set-DaS2yw5c.mjs +1687 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/js/precheck.d.ts +2 -2
- package/dist/lightningcss/style-handler/selector-transform.d.ts +1 -1
- package/dist/lightningcss/style-handler.d.ts +3 -3
- package/dist/logger-CZUxvJJD.mjs +2 -0
- package/dist/logger-EVNB9z7i.js +1 -0
- package/dist/postcss/config-directive.d.ts +1 -0
- package/dist/postcss/context.d.ts +9 -0
- package/dist/postcss/source-files.d.ts +8 -0
- package/dist/postcss/tailwind-version.d.ts +3 -0
- package/dist/postcss-BdcRlSpp.js +243 -0
- package/dist/postcss-Bs-RbNzK.js +5477 -0
- package/dist/postcss-xZDiTRII.mjs +234 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -274
- package/dist/postcss.mjs +1 -267
- package/dist/{recorder-rn_2v_nd.js → precheck-D5eEdqeH.js} +168 -304
- package/dist/{recorder-B_XyZ576.mjs → precheck-DtBGFS-n.mjs} +134 -269
- package/dist/presets.js +13 -11
- package/dist/presets.mjs +11 -9
- package/dist/reset.d.ts +1 -0
- package/dist/runtime-patch-CqB-A4zA.js +85 -0
- package/dist/runtime-patch-DGKsVkiG.mjs +71 -0
- package/dist/shared/mpx.d.ts +1 -0
- package/dist/source-scan-CIVTa3Cj.js +297 -0
- package/dist/source-scan-CJ0y0XBj.mjs +258 -0
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/runtime/cache.d.ts +3 -3
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +11 -12
- package/dist/tailwindcss/source-scan.d.ts +25 -0
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +14 -14
- package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/candidates.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v4-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +6 -3
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/tailwindcss-B78nj6n7.js +644 -0
- package/dist/tailwindcss-DGM8lHUj.mjs +593 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +45 -48
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +21 -23
- package/dist/types/user-defined-options/important.d.ts +31 -28
- package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
- package/dist/types/user-defined-options/matcher.d.ts +6 -6
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/utils/object.d.ts +9 -0
- package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
- package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
- package/dist/{vite-BHpAqldo.js → vite-BEj9JOOA.js} +1245 -876
- package/dist/{vite-C8JlHiyR.mjs → vite-C8S1wfyQ.mjs} +1208 -842
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +129 -15
- package/dist/weapp-tw-runtime-classset-loader.js +44 -6
- package/dist/webpack-Dm1IXTIh.js +778 -0
- package/dist/webpack-ZGIKKpFf.mjs +768 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +26 -39
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/css-imports-BbrbluP9.js +0 -177
- package/dist/css-imports-CSdPq_Sc.mjs +0 -128
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/generator-CZ-JXw6T.js +0 -492
- package/dist/generator-Dwxgra97.mjs +0 -399
- package/dist/generator-css-CnYjiMrD.js +0 -1084
- package/dist/generator-css-DhPFjSzK.mjs +0 -1057
- package/dist/js/syntax.d.ts +0 -10
- package/dist/loader-anchors-DvwgIYdA.mjs +0 -205
- package/dist/loader-anchors-cprm4Klq.js +0 -273
- package/dist/logger-BZ45DZJT.js +0 -1003
- package/dist/logger-BoVx1Dbt.mjs +0 -935
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/webpack-CABjKGGQ.mjs +0 -441
- package/dist/webpack-DNIJ0ysE.js +0 -456
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
- /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
- /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
package/dist/vite.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export * from './bundlers/vite/index';
|
|
2
|
-
export {
|
|
3
|
-
export { UnifiedViteWeappTailwindcssPlugin as weappTailwindcss } from './bundlers/vite/index';
|
|
2
|
+
export { WeappTailwindcss as weappTailwindcss } from './bundlers/vite/index';
|
|
4
3
|
export type { UserDefinedOptions } from './types';
|
package/dist/vite.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_vite = require("./vite-
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.weappTailwindcss = require_vite.UnifiedViteWeappTailwindcssPlugin;
|
|
2
|
+
const require_vite = require("./vite-BEj9JOOA.js");
|
|
3
|
+
exports.WeappTailwindcss = require_vite.WeappTailwindcss;
|
|
4
|
+
exports.weappTailwindcss = require_vite.WeappTailwindcss;
|
package/dist/vite.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
export {
|
|
1
|
+
import { t as WeappTailwindcss } from "./vite-C8S1wfyQ.mjs";
|
|
2
|
+
export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss };
|
|
@@ -2,31 +2,31 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const
|
|
5
|
+
const require_postcss = require("./postcss-Bs-RbNzK.js");
|
|
6
|
+
let node_buffer = require("node:buffer");
|
|
6
7
|
let node_process = require("node:process");
|
|
7
|
-
node_process =
|
|
8
|
+
node_process = require_postcss.__toESM(node_process);
|
|
8
9
|
let loader_utils = require("loader-utils");
|
|
9
|
-
loader_utils =
|
|
10
|
-
let node_buffer = require("node:buffer");
|
|
10
|
+
loader_utils = require_postcss.__toESM(loader_utils);
|
|
11
11
|
let node_util = require("node:util");
|
|
12
12
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
13
13
|
let node_path = require("node:path");
|
|
14
|
-
node_path =
|
|
14
|
+
node_path = require_postcss.__toESM(node_path);
|
|
15
15
|
//#region src/bundlers/shared/css-imports.ts
|
|
16
|
-
const tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
|
|
17
|
-
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
16
|
+
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
17
|
+
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
18
18
|
function normalizeTailwindcssSpecifier(specifier) {
|
|
19
|
-
if (specifier === "tailwindcss$"
|
|
19
|
+
if (specifier === "tailwindcss$" || specifier === "weapp-tailwindcss$") return specifier.slice(0, -1);
|
|
20
20
|
return specifier;
|
|
21
21
|
}
|
|
22
22
|
function getTailwindcssSubpath(specifier) {
|
|
23
|
-
if (specifier === "tailwindcss") return "index.css";
|
|
24
|
-
return specifier.
|
|
23
|
+
if (specifier === "tailwindcss" || specifier === "weapp-tailwindcss") return "index.css";
|
|
24
|
+
return specifier.replace(/^(?:tailwindcss|weapp-tailwindcss)\//, "");
|
|
25
25
|
}
|
|
26
26
|
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
27
27
|
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
28
28
|
if (!tailwindcssImportRE.test(normalized)) return null;
|
|
29
|
-
if (normalized === "tailwindcss") return options?.rootImport ?? "
|
|
29
|
+
if (normalized === "tailwindcss" || normalized === "weapp-tailwindcss") return options?.rootImport ?? (options?.join ?? node_path.default.join)(pkgDir, "index.css");
|
|
30
30
|
return (options?.join ?? node_path.default.join)(pkgDir, getTailwindcssSubpath(normalized));
|
|
31
31
|
}
|
|
32
32
|
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
@@ -40,6 +40,112 @@ function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
|
40
40
|
return hasReplacements ? rewritten : void 0;
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
|
+
//#region src/bundlers/shared/generator-css/markers.ts
|
|
44
|
+
const GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE = /\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/\s*/gi;
|
|
45
|
+
function stripGeneratorPlaceholderMarkers(css) {
|
|
46
|
+
return css.replace(GENERATOR_PLACEHOLDER_MARKER_GLOBAL_RE, "");
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/bundlers/shared/generator-css/directives.ts
|
|
50
|
+
const TAILWIND_ROOT_DIRECTIVE_NAMES = new Set([
|
|
51
|
+
"config",
|
|
52
|
+
"custom-variant",
|
|
53
|
+
"plugin",
|
|
54
|
+
"source",
|
|
55
|
+
"tailwind",
|
|
56
|
+
"theme",
|
|
57
|
+
"utility",
|
|
58
|
+
"variant"
|
|
59
|
+
]);
|
|
60
|
+
const TAILWIND_ROOT_DIRECTIVE_RE = /@(?:import\s+(?:url\(\s*)?["']?tailwindcss4?(?:\/[^"')\s]*)?|tailwind|config|custom-variant|plugin|source|theme|utility|variant)\b/;
|
|
61
|
+
const TAILWIND_EXTRACTABLE_DIRECTIVE_RE = /^\s*@(?:import|tailwind|config|source|reference|plugin)\b[\s\S]*?(?:;|$)/;
|
|
62
|
+
const TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE = /^\s*@(?:theme|utility|variant|custom-variant)\b[\s\S]*$/;
|
|
63
|
+
function parseImportRequest(params) {
|
|
64
|
+
return /^(?:url\(\s*)?(["']?)([^"')\s]+)\1\s*\)?/.exec(params.trim())?.[2];
|
|
65
|
+
}
|
|
66
|
+
function parseConfigRequest(params) {
|
|
67
|
+
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
68
|
+
}
|
|
69
|
+
function isPackageJsonImportRequest(request) {
|
|
70
|
+
return typeof request === "string" && request.startsWith("#");
|
|
71
|
+
}
|
|
72
|
+
function isWeappTailwindcssImportRequest(request) {
|
|
73
|
+
return request === "weapp-tailwindcss" || request?.startsWith("weapp-tailwindcss/");
|
|
74
|
+
}
|
|
75
|
+
function normalizeTailwindImportRequest(request, options = {}) {
|
|
76
|
+
if (options.importFallback && isWeappTailwindcssImportRequest(request)) return request.replace(/^weapp-tailwindcss/, "tailwindcss");
|
|
77
|
+
return request;
|
|
78
|
+
}
|
|
79
|
+
function replaceImportRequest(params, request, replacement) {
|
|
80
|
+
const index = params.indexOf(request);
|
|
81
|
+
if (index === -1) return params;
|
|
82
|
+
return `${params.slice(0, index)}${replacement}${params.slice(index + request.length)}`;
|
|
83
|
+
}
|
|
84
|
+
function normalizeTailwindDirectiveLine(line, options = {}) {
|
|
85
|
+
if (!options.importFallback || !line.trimStart().startsWith("@import")) return line;
|
|
86
|
+
const request = parseImportRequest(line.trimStart().replace(/^@import\b/, ""));
|
|
87
|
+
if (!isWeappTailwindcssImportRequest(request)) return line;
|
|
88
|
+
return replaceImportRequest(line, request, request.replace(/^weapp-tailwindcss/, "tailwindcss"));
|
|
89
|
+
}
|
|
90
|
+
function extractTailwindDirectiveLines(rawSource, options = {}) {
|
|
91
|
+
const directives = [];
|
|
92
|
+
const seenImports = /* @__PURE__ */ new Set();
|
|
93
|
+
for (const line of stripGeneratorPlaceholderMarkers(rawSource).split(/\r?\n/)) {
|
|
94
|
+
const trimmed = line.trim();
|
|
95
|
+
if (!trimmed || trimmed.startsWith("//")) continue;
|
|
96
|
+
const directive = TAILWIND_EXTRACTABLE_DIRECTIVE_RE.exec(line)?.[0] ?? TAILWIND_EXTRACTABLE_BLOCK_DIRECTIVE_RE.exec(line)?.[0];
|
|
97
|
+
if (!directive) continue;
|
|
98
|
+
const normalized = normalizeTailwindDirectiveLine(directive.trimEnd(), options);
|
|
99
|
+
const normalizedTrimmed = normalized.trim();
|
|
100
|
+
if (options.removeConfig && normalizedTrimmed.startsWith("@config")) continue;
|
|
101
|
+
const request = /^@import\b/.test(normalizedTrimmed) ? parseImportRequest(normalizedTrimmed.replace(/^@import\b/, "")) : void 0;
|
|
102
|
+
if (request && !isTailwindImportRequest(request) && !isPackageJsonImportRequest(request)) continue;
|
|
103
|
+
if (/^@import\b/.test(normalizedTrimmed) && !request) continue;
|
|
104
|
+
if (request && isTailwindImportRequest(request)) {
|
|
105
|
+
const key = normalizedTrimmed;
|
|
106
|
+
if (seenImports.has(key)) continue;
|
|
107
|
+
seenImports.add(key);
|
|
108
|
+
}
|
|
109
|
+
directives.push(normalized);
|
|
110
|
+
}
|
|
111
|
+
return directives;
|
|
112
|
+
}
|
|
113
|
+
function extractTailwindSourceForPostcssFallback(rawSource, options = {}) {
|
|
114
|
+
const directives = extractTailwindDirectiveLines(rawSource, options);
|
|
115
|
+
return directives.length > 0 ? directives.join("\n") : void 0;
|
|
116
|
+
}
|
|
117
|
+
function hasPreprocessorOnlySyntax(rawSource) {
|
|
118
|
+
return /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@[\w-]+\s*:|@(?:mixin|include|function|use|forward)\b)/.test(rawSource);
|
|
119
|
+
}
|
|
120
|
+
function normalizeTailwindSourceForGenerator(rawSource, options = {}) {
|
|
121
|
+
return hasPreprocessorOnlySyntax(rawSource) ? extractTailwindSourceForPostcssFallback(rawSource, options) ?? rawSource : rawSource;
|
|
122
|
+
}
|
|
123
|
+
function isTailwindImportRequest(request) {
|
|
124
|
+
return request === "tailwindcss" || request === "tailwindcss4" || request?.startsWith("tailwindcss/") || request?.startsWith("tailwindcss4/");
|
|
125
|
+
}
|
|
126
|
+
function isTailwindImportAtRule(node, options = {}) {
|
|
127
|
+
if (node.name === "tailwind") return true;
|
|
128
|
+
if (node.name !== "import") return false;
|
|
129
|
+
return isTailwindImportRequest(normalizeTailwindImportRequest(parseImportRequest(node.params), options));
|
|
130
|
+
}
|
|
131
|
+
function hasTailwindRootDirectives(rawSource, options = {}) {
|
|
132
|
+
if (!TAILWIND_ROOT_DIRECTIVE_RE.test(rawSource) && !(options.importFallback && rawSource.includes("weapp-tailwindcss"))) return false;
|
|
133
|
+
try {
|
|
134
|
+
const root = require_postcss.postcss_default.parse(rawSource);
|
|
135
|
+
let found = false;
|
|
136
|
+
root.walkAtRules((node) => {
|
|
137
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" ? parseConfigRequest(node.params) : void 0;
|
|
138
|
+
if (isTailwindImportAtRule(node, options) || isPackageJsonImportRequest(request) || TAILWIND_ROOT_DIRECTIVE_NAMES.has(node.name)) {
|
|
139
|
+
found = true;
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return found;
|
|
144
|
+
} catch {
|
|
145
|
+
return extractTailwindDirectiveLines(rawSource, options).length > 0;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
43
149
|
//#region src/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.ts
|
|
44
150
|
const getLoaderOptions = loader_utils.default.getOptions;
|
|
45
151
|
function joinPosixPath(base, subpath) {
|
|
@@ -47,7 +153,7 @@ function joinPosixPath(base, subpath) {
|
|
|
47
153
|
return `${base}/${subpath}`;
|
|
48
154
|
}
|
|
49
155
|
function applyCssImportRewrite(source, options) {
|
|
50
|
-
const rewriteOptions = options?.
|
|
156
|
+
const rewriteOptions = options?.tailwindcssImportRewrite;
|
|
51
157
|
const pkgDir = rewriteOptions?.pkgDir;
|
|
52
158
|
if (!pkgDir) return source;
|
|
53
159
|
return rewriteTailwindcssImportsInCode(source, (0, _weapp_tailwindcss_shared.ensurePosix)(pkgDir), {
|
|
@@ -59,15 +165,23 @@ function transformCssImportRewriteSource(source, options) {
|
|
|
59
165
|
const input = node_buffer.Buffer.isBuffer(source) ? source.toString("utf-8") : source;
|
|
60
166
|
const rewritten = applyCssImportRewrite(input, options);
|
|
61
167
|
if (rewritten === input) return source;
|
|
62
|
-
if (node_process.default.env
|
|
168
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"]) node_process.default.stdout.write(`[weapp-tw-css-import-rewrite-loader] rewritten import ${(0, node_util.inspect)({
|
|
63
169
|
before: input.slice(0, 80),
|
|
64
170
|
after: rewritten.slice(0, 80)
|
|
65
171
|
})}\n`);
|
|
66
172
|
return rewritten;
|
|
67
173
|
}
|
|
68
174
|
const WeappTwCssImportRewriteLoader = function(source) {
|
|
69
|
-
if (node_process.default.env
|
|
70
|
-
|
|
175
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"]) node_process.default.stdout.write(`[weapp-tw-css-import-rewrite-loader] executing for ${this.resourcePath}\n`);
|
|
176
|
+
const opt = getLoaderOptions(this);
|
|
177
|
+
const input = node_buffer.Buffer.isBuffer(source) ? source.toString("utf-8") : source;
|
|
178
|
+
const registerTask = typeof input === "string" && hasTailwindRootDirectives(input, { importFallback: true }) ? opt?.tailwindcssImportRewrite?.registerCssSource?.({
|
|
179
|
+
file: this.resourcePath,
|
|
180
|
+
css: normalizeTailwindSourceForGenerator(input, { importFallback: true })
|
|
181
|
+
}) : void 0;
|
|
182
|
+
const transform = () => transformCssImportRewriteSource(source, opt);
|
|
183
|
+
if (registerTask && typeof registerTask.then === "function") return Promise.resolve(registerTask).then(transform);
|
|
184
|
+
return transform();
|
|
71
185
|
};
|
|
72
186
|
//#endregion
|
|
73
187
|
exports.default = WeappTwCssImportRewriteLoader;
|
|
@@ -1,15 +1,53 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_postcss = require("./postcss-Bs-RbNzK.js");
|
|
2
|
+
let node_buffer = require("node:buffer");
|
|
2
3
|
let node_process = require("node:process");
|
|
3
|
-
node_process =
|
|
4
|
+
node_process = require_postcss.__toESM(node_process);
|
|
4
5
|
let loader_utils = require("loader-utils");
|
|
5
|
-
loader_utils =
|
|
6
|
+
loader_utils = require_postcss.__toESM(loader_utils);
|
|
7
|
+
//#region src/tailwindcss/remove-unsupported-css.ts
|
|
8
|
+
/**
|
|
9
|
+
* 移除小程序不支持的 cascade layer 语法,同时保留 layer 内的实际规则。
|
|
10
|
+
*/
|
|
11
|
+
function removeUnsupportedCascadeLayers(root) {
|
|
12
|
+
root.walkAtRules("layer", (atRule) => {
|
|
13
|
+
if (!atRule.nodes || atRule.nodes.length === 0) {
|
|
14
|
+
atRule.remove();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
atRule.replaceWith(...atRule.nodes);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
6
21
|
//#region src/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.ts
|
|
7
22
|
function isPromiseLike(value) {
|
|
8
23
|
return Boolean(value && typeof value.then === "function");
|
|
9
24
|
}
|
|
10
25
|
const getLoaderOptions = loader_utils.default.getOptions;
|
|
26
|
+
function normalizeRuntimeCssSource(source) {
|
|
27
|
+
if (node_buffer.Buffer.isBuffer(source)) {
|
|
28
|
+
const css = source.toString("utf8");
|
|
29
|
+
return shouldCleanRuntimeCss(css) ? node_buffer.Buffer.from(cleanRuntimeCss(css)) : source;
|
|
30
|
+
}
|
|
31
|
+
return shouldCleanRuntimeCss(source) ? cleanRuntimeCss(source) : source;
|
|
32
|
+
}
|
|
33
|
+
function shouldCleanRuntimeCss(css) {
|
|
34
|
+
return css.includes("@layer") || css.includes("@theme");
|
|
35
|
+
}
|
|
36
|
+
function cleanRuntimeCss(css) {
|
|
37
|
+
const root = require_postcss.postcss_default.parse(css);
|
|
38
|
+
removeUnsupportedCascadeLayers(root);
|
|
39
|
+
removeUnsupportedThemeKeyframes(root);
|
|
40
|
+
return root.toString();
|
|
41
|
+
}
|
|
42
|
+
function removeUnsupportedThemeKeyframes(root) {
|
|
43
|
+
root.walkAtRules("theme", (themeRule) => {
|
|
44
|
+
themeRule.walkAtRules((atRule) => {
|
|
45
|
+
if (atRule.name.startsWith("-") && atRule.name.endsWith("keyframes")) atRule.remove();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
11
49
|
const WeappTwRuntimeClassSetLoader = function(source) {
|
|
12
|
-
if (node_process.default.env
|
|
50
|
+
if (node_process.default.env["WEAPP_TW_LOADER_DEBUG"]) node_process.default.stdout.write(`[weapp-tw-runtime-classset-loader] executing for ${this.resourcePath}\n`);
|
|
13
51
|
const opt = getLoaderOptions(this);
|
|
14
52
|
const maybePromise = opt?.getClassSet?.();
|
|
15
53
|
const applyWatchDependencies = (dependencies) => {
|
|
@@ -25,10 +63,10 @@ const WeappTwRuntimeClassSetLoader = function(source) {
|
|
|
25
63
|
};
|
|
26
64
|
if (isPromiseLike(maybePromise)) return Promise.resolve(maybePromise).then(async () => {
|
|
27
65
|
await resolveWatchDependencies();
|
|
28
|
-
return source;
|
|
66
|
+
return normalizeRuntimeCssSource(source);
|
|
29
67
|
});
|
|
30
68
|
resolveWatchDependencies();
|
|
31
|
-
return source;
|
|
69
|
+
return normalizeRuntimeCssSource(source);
|
|
32
70
|
};
|
|
33
71
|
//#endregion
|
|
34
72
|
module.exports = WeappTwRuntimeClassSetLoader;
|