weapp-tailwindcss 5.0.0-next.24 → 5.0.0-next.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-CqyEtds4.js +115 -0
- package/dist/auto-CsWz6lsU.mjs +78 -0
- package/dist/{bundle-state-CP_BWXfx.mjs → bundle-state-CWcrb3mH.mjs} +1 -2
- package/dist/{bundle-state-DXFq2nEo.js → bundle-state-uCtqRm0p.js} +2 -3
- package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
- package/dist/cli.js +167 -6
- package/dist/cli.mjs +166 -5
- package/dist/context/runtime-package-replacements.d.ts +2 -0
- package/dist/context/style-options.d.ts +3 -0
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/auto.d.ts +10 -0
- package/dist/css-macro/constants.d.ts +5 -2
- package/dist/css-macro/postcss.d.ts +1 -0
- package/dist/css-macro/postcss.js +7 -47
- package/dist/css-macro/postcss.mjs +2 -47
- package/dist/css-macro.js +15 -6
- package/dist/css-macro.mjs +15 -6
- package/dist/{defaults-C6sIKXgC.mjs → defaults-B-1EEhdL.mjs} +2 -1
- package/dist/{defaults-D3cFX6Cq.js → defaults-C10hYUch.js} +2 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-BcH28HU-.js → generator-BH6a0xuB.js} +1 -1
- package/dist/{generator-DdEgn8nG.mjs → generator-iI_265gt.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp.js +5 -5
- package/dist/gulp.mjs +5 -5
- package/dist/{incremental-runtime-class-set-Bux7viee.mjs → incremental-runtime-class-set-ECHyKwUL.mjs} +4 -16
- package/dist/{incremental-runtime-class-set-CWdfLHON.js → incremental-runtime-class-set-mY0v1k-Y.js} +4 -16
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -4
- package/dist/index.mjs +6 -5
- package/dist/postcss-BwW8zO24.js +192 -0
- package/dist/postcss-BzaRjBL0.mjs +169 -0
- package/dist/{postcss-cD5PXmMU.js → postcss-DEEAZ8J5.js} +2 -2
- package/dist/{postcss-nk5bhdoV.mjs → postcss-DJoU--Z-.mjs} +2 -2
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/precheck-BI8oBeUg.mjs +4692 -0
- package/dist/{precheck-DtYqujIx.js → precheck-DLJg0_pu.js} +2070 -34
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/uni-app-x.d.ts +1 -0
- package/dist/presets.js +19 -5
- package/dist/presets.mjs +18 -6
- package/dist/{source-candidates-B7wmEa-G.mjs → source-candidates-DkScNh9A.mjs} +1 -1
- package/dist/{source-candidates-lHtAHLQq.js → source-candidates-mfvC9gMc.js} +1 -1
- package/dist/{tailwindcss-BtUBeOes.js → tailwindcss-Cm93idme.js} +17 -26
- package/dist/{tailwindcss-DO-VVR5k.mjs → tailwindcss-DFa5Yes8.mjs} +17 -26
- package/dist/types/index.d.ts +1 -1
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +2 -1
- package/dist/types/user-defined-options/important.d.ts +3 -1
- package/dist/unocss/index.d.ts +2 -0
- package/dist/utils/options.d.ts +2 -0
- package/dist/utils/regex.d.ts +1 -0
- package/dist/{v3-engine-vHlppqaZ.js → v3-engine-CGsbY81C.js} +67 -19
- package/dist/{v3-engine-CXqgQZUc.mjs → v3-engine-CPJ9uGyr.mjs} +56 -20
- package/dist/{vite-BkNDGBZ2.js → vite-BM_ksf1q.js} +140 -21
- package/dist/{vite-BthAm8kt.mjs → vite-CqEF-Wx5.mjs} +140 -21
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +327 -73
- package/dist/weapp-tw-runtime-classset-loader.js +1 -4
- package/dist/{webpack-prCus5xn.js → webpack-CfcuDhQ8.js} +10 -7
- package/dist/{webpack-hPc8wUAi.mjs → webpack-D--XZMBB.mjs} +11 -8
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +14 -14
- package/dist/constants-BG12WAKw.mjs +0 -44
- package/dist/constants-BeeyfJ9k.js +0 -73
- package/dist/precheck-DreRGvYH.mjs +0 -2668
- /package/dist/{logger-EVNB9z7i.js → logger-Cdzl3p8j.js} +0 -0
- /package/dist/{logger-CZUxvJJD.mjs → logger-Dr7IvyH2.mjs} +0 -0
- /package/dist/{utils-CGBVVNm6.mjs → utils-B2SJgA1L.mjs} +0 -0
- /package/dist/{utils-4ODFyoqD.js → utils-CSA174-I.js} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
const require_postcss = require("./postcss-BwW8zO24.js");
|
|
3
|
+
let postcss = require("postcss");
|
|
4
|
+
postcss = require_chunk.__toESM(postcss);
|
|
5
|
+
//#region src/css-macro/auto.ts
|
|
6
|
+
const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
|
|
7
|
+
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
8
|
+
function markCssMacroPlugin(value) {
|
|
9
|
+
Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
|
|
10
|
+
configurable: false,
|
|
11
|
+
enumerable: false,
|
|
12
|
+
value: true
|
|
13
|
+
});
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
function isCssMacroTailwindPlugin(value) {
|
|
17
|
+
return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
|
|
18
|
+
}
|
|
19
|
+
function hasCssMacroTailwindPlugin(plugins) {
|
|
20
|
+
if (!plugins) return false;
|
|
21
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
|
|
22
|
+
if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function parseCssPluginRequest(params) {
|
|
26
|
+
const value = params.trim();
|
|
27
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
28
|
+
if (quoted) return quoted[2];
|
|
29
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
30
|
+
return url?.[2] ?? url?.[3];
|
|
31
|
+
}
|
|
32
|
+
function isCssMacroPluginRequest(request) {
|
|
33
|
+
return request === "weapp-tailwindcss/css-macro";
|
|
34
|
+
}
|
|
35
|
+
function hasCssMacroTailwindV4Directive(css) {
|
|
36
|
+
if (!css?.includes("css-macro")) return false;
|
|
37
|
+
try {
|
|
38
|
+
let found = false;
|
|
39
|
+
postcss.default.parse(css).walkAtRules("plugin", (rule) => {
|
|
40
|
+
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
41
|
+
});
|
|
42
|
+
return found;
|
|
43
|
+
} catch {
|
|
44
|
+
return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function isCssMacroPostcssPlugin(plugin) {
|
|
48
|
+
if (plugin === require_postcss.creator) return true;
|
|
49
|
+
return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
|
|
50
|
+
}
|
|
51
|
+
function withCssMacroPostcssPlugins(plugins) {
|
|
52
|
+
const macroPlugin = require_postcss.creator();
|
|
53
|
+
if (!plugins) return [macroPlugin];
|
|
54
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
|
|
55
|
+
if (typeof plugins === "object") {
|
|
56
|
+
const values = Object.values(plugins).filter(Boolean);
|
|
57
|
+
if (values.some(isCssMacroPostcssPlugin)) return values;
|
|
58
|
+
return [...values, macroPlugin];
|
|
59
|
+
}
|
|
60
|
+
return [macroPlugin];
|
|
61
|
+
}
|
|
62
|
+
function withCssMacroStyleOptions(options) {
|
|
63
|
+
const postcssOptions = options?.postcssOptions;
|
|
64
|
+
return {
|
|
65
|
+
...options,
|
|
66
|
+
[CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
|
|
67
|
+
postcssOptions: {
|
|
68
|
+
...postcssOptions,
|
|
69
|
+
plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function hasCssMacroStyleOptions(options) {
|
|
74
|
+
return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
|
|
75
|
+
}
|
|
76
|
+
async function transformCssMacroCss(css) {
|
|
77
|
+
return (await (0, postcss.default)([require_postcss.creator()]).process(css, { from: void 0 })).css;
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
Object.defineProperty(exports, "hasCssMacroStyleOptions", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function() {
|
|
83
|
+
return hasCssMacroStyleOptions;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, "hasCssMacroTailwindPlugin", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function() {
|
|
89
|
+
return hasCssMacroTailwindPlugin;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "hasCssMacroTailwindV4Directive", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return hasCssMacroTailwindV4Directive;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "markCssMacroPlugin", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return markCssMacroPlugin;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "transformCssMacroCss", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return transformCssMacroCss;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(exports, "withCssMacroStyleOptions", {
|
|
111
|
+
enumerable: true,
|
|
112
|
+
get: function() {
|
|
113
|
+
return withCssMacroStyleOptions;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { n as creator } from "./postcss-BzaRjBL0.mjs";
|
|
2
|
+
import postcss from "postcss";
|
|
3
|
+
//#region src/css-macro/auto.ts
|
|
4
|
+
const CSS_MACRO_PLUGIN_MARKER = "__weappTailwindcssCssMacro";
|
|
5
|
+
const CSS_MACRO_STYLE_OPTIONS_MARKER = "__weappTailwindcssCssMacroEnabled";
|
|
6
|
+
function markCssMacroPlugin(value) {
|
|
7
|
+
Object.defineProperty(value, CSS_MACRO_PLUGIN_MARKER, {
|
|
8
|
+
configurable: false,
|
|
9
|
+
enumerable: false,
|
|
10
|
+
value: true
|
|
11
|
+
});
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function isCssMacroTailwindPlugin(value) {
|
|
15
|
+
return Boolean(value && (typeof value === "function" || typeof value === "object") && value["__weappTailwindcssCssMacro"] === true);
|
|
16
|
+
}
|
|
17
|
+
function hasCssMacroTailwindPlugin(plugins) {
|
|
18
|
+
if (!plugins) return false;
|
|
19
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroTailwindPlugin);
|
|
20
|
+
if (typeof plugins === "object") return Object.values(plugins).some(isCssMacroTailwindPlugin);
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
function parseCssPluginRequest(params) {
|
|
24
|
+
const value = params.trim();
|
|
25
|
+
const quoted = /^(['"])(.*?)\1/.exec(value);
|
|
26
|
+
if (quoted) return quoted[2];
|
|
27
|
+
const url = /^url\(\s*(?:(['"])(.*?)\1|([^'")\s]+))\s*\)/.exec(value);
|
|
28
|
+
return url?.[2] ?? url?.[3];
|
|
29
|
+
}
|
|
30
|
+
function isCssMacroPluginRequest(request) {
|
|
31
|
+
return request === "weapp-tailwindcss/css-macro";
|
|
32
|
+
}
|
|
33
|
+
function hasCssMacroTailwindV4Directive(css) {
|
|
34
|
+
if (!css?.includes("css-macro")) return false;
|
|
35
|
+
try {
|
|
36
|
+
let found = false;
|
|
37
|
+
postcss.parse(css).walkAtRules("plugin", (rule) => {
|
|
38
|
+
if (isCssMacroPluginRequest(parseCssPluginRequest(rule.params))) found = true;
|
|
39
|
+
});
|
|
40
|
+
return found;
|
|
41
|
+
} catch {
|
|
42
|
+
return /@plugin\s+(?:url\(\s*)?["']weapp-tailwindcss\/css-macro["']/.test(css);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isCssMacroPostcssPlugin(plugin) {
|
|
46
|
+
if (plugin === creator) return true;
|
|
47
|
+
return Boolean(plugin && (typeof plugin === "function" || typeof plugin === "object") && plugin.postcssPlugin === "postcss-weapp-tw-css-macro-plugin");
|
|
48
|
+
}
|
|
49
|
+
function withCssMacroPostcssPlugins(plugins) {
|
|
50
|
+
const macroPlugin = creator();
|
|
51
|
+
if (!plugins) return [macroPlugin];
|
|
52
|
+
if (Array.isArray(plugins)) return plugins.some(isCssMacroPostcssPlugin) ? plugins : [...plugins, macroPlugin];
|
|
53
|
+
if (typeof plugins === "object") {
|
|
54
|
+
const values = Object.values(plugins).filter(Boolean);
|
|
55
|
+
if (values.some(isCssMacroPostcssPlugin)) return values;
|
|
56
|
+
return [...values, macroPlugin];
|
|
57
|
+
}
|
|
58
|
+
return [macroPlugin];
|
|
59
|
+
}
|
|
60
|
+
function withCssMacroStyleOptions(options) {
|
|
61
|
+
const postcssOptions = options?.postcssOptions;
|
|
62
|
+
return {
|
|
63
|
+
...options,
|
|
64
|
+
[CSS_MACRO_STYLE_OPTIONS_MARKER]: true,
|
|
65
|
+
postcssOptions: {
|
|
66
|
+
...postcssOptions,
|
|
67
|
+
plugins: withCssMacroPostcssPlugins(postcssOptions?.plugins)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function hasCssMacroStyleOptions(options) {
|
|
72
|
+
return Boolean(options?.[CSS_MACRO_STYLE_OPTIONS_MARKER]);
|
|
73
|
+
}
|
|
74
|
+
async function transformCssMacroCss(css) {
|
|
75
|
+
return (await postcss([creator()]).process(css, { from: void 0 })).css;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { transformCssMacroCss as a, markCssMacroPlugin as i, hasCssMacroTailwindPlugin as n, withCssMacroStyleOptions as o, hasCssMacroTailwindV4Directive as r, hasCssMacroStyleOptions as t };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as traverse, m as babelParse, o as Parser } from "./precheck-BI8oBeUg.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import process from "node:process";
|
|
5
5
|
import { cleanUrl, ensurePosix } from "@weapp-tailwindcss/shared";
|
|
6
6
|
import { Buffer } from "node:buffer";
|
|
7
|
-
import { Parser } from "htmlparser2";
|
|
8
7
|
//#region src/bundlers/shared/module-graph.ts
|
|
9
8
|
const QUERY_HASH_RE = /[?#].*$/u;
|
|
10
9
|
const PROTOCOL_RE = /^[a-z][a-z+.-]*:/iu;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const require_precheck = require("./precheck-
|
|
2
|
+
const require_precheck = require("./precheck-DLJg0_pu.js");
|
|
3
3
|
let node_module = require("node:module");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_chunk.__toESM(node_path);
|
|
@@ -7,7 +7,6 @@ let node_process = require("node:process");
|
|
|
7
7
|
node_process = require_chunk.__toESM(node_process);
|
|
8
8
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
9
9
|
let node_buffer = require("node:buffer");
|
|
10
|
-
let htmlparser2 = require("htmlparser2");
|
|
11
10
|
//#region src/bundlers/shared/module-graph.ts
|
|
12
11
|
const QUERY_HASH_RE = /[?#].*$/u;
|
|
13
12
|
const PROTOCOL_RE = /^[a-z][a-z+.-]*:/iu;
|
|
@@ -220,7 +219,7 @@ const CSS_WHITESPACE_RE = /\s+/g;
|
|
|
220
219
|
function createHtmlRuntimeAffectingSignature(source) {
|
|
221
220
|
try {
|
|
222
221
|
const parts = [];
|
|
223
|
-
const parser = new
|
|
222
|
+
const parser = new require_precheck.Parser({
|
|
224
223
|
onattribute(name, value) {
|
|
225
224
|
parts.push(`a:${name}=${value}`);
|
|
226
225
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
interface ViteServeCssGenerationOptions {
|
|
3
|
+
generateCss: (id: string, code: string, hookContext?: {
|
|
4
|
+
addWatchFile?: (id: string) => void;
|
|
5
|
+
}) => Promise<string | undefined> | string | undefined;
|
|
6
|
+
getCommand: () => string | undefined;
|
|
7
|
+
onTailwindRootCss?: ((id: string, code: string) => Promise<void> | void) | undefined;
|
|
8
|
+
shouldGenerate: () => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function createViteServeCssGenerationPlugins(options: ViteServeCssGenerationOptions): Plugin[];
|
|
11
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -46,13 +46,11 @@ require("tailwindcss-config");
|
|
|
46
46
|
let _babel_traverse = require("@babel/traverse");
|
|
47
47
|
_babel_traverse = __toESM(_babel_traverse);
|
|
48
48
|
let _babel_parser = require("@babel/parser");
|
|
49
|
-
let _weapp_core_regex = require("@weapp-core/regex");
|
|
50
49
|
let magic_string = require("magic-string");
|
|
51
50
|
magic_string = __toESM(magic_string);
|
|
52
51
|
let _ast_core_escape = require("@ast-core/escape");
|
|
53
52
|
let _weapp_tailwindcss_shared_extractors = require("@weapp-tailwindcss/shared/extractors");
|
|
54
53
|
require("@babel/types");
|
|
55
|
-
require("htmlparser2");
|
|
56
54
|
//#region src/js/babel/cache-options.ts
|
|
57
55
|
const DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH = 5e4;
|
|
58
56
|
const HARD_PARSE_CACHE_MAX_ENTRIES = 1024;
|
|
@@ -73,6 +71,163 @@ function createDebug(prefix) {
|
|
|
73
71
|
return debug$4;
|
|
74
72
|
}
|
|
75
73
|
//#endregion
|
|
74
|
+
//#region src/css-macro/constants.ts
|
|
75
|
+
const queryKey = "weapp-tw-platform";
|
|
76
|
+
const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
|
|
77
|
+
const WHITESPACE_RE = /\s+/g;
|
|
78
|
+
const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
|
|
79
|
+
function normalComment(text) {
|
|
80
|
+
if (typeof text === "string") {
|
|
81
|
+
const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
82
|
+
if (normalized.includes("\\")) return normalized;
|
|
83
|
+
return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
84
|
+
}
|
|
85
|
+
return text;
|
|
86
|
+
}
|
|
87
|
+
function ifdef(text) {
|
|
88
|
+
return {
|
|
89
|
+
start: `#ifdef ${normalComment(text)}`,
|
|
90
|
+
end: `#endif`
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function ifndef(text) {
|
|
94
|
+
return {
|
|
95
|
+
start: `#ifndef ${normalComment(text)}`,
|
|
96
|
+
end: `#endif`
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
|
|
100
|
+
function matchCustomPropertyFromValue(str, cb) {
|
|
101
|
+
let index = 0;
|
|
102
|
+
QUERY_KEY_REGEX.lastIndex = 0;
|
|
103
|
+
let arr = QUERY_KEY_REGEX.exec(str);
|
|
104
|
+
while (arr !== null) {
|
|
105
|
+
cb(arr, index);
|
|
106
|
+
index++;
|
|
107
|
+
arr = QUERY_KEY_REGEX.exec(str);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function parseConditionalAtRuleParam(params) {
|
|
111
|
+
const value = params.trim();
|
|
112
|
+
const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
|
|
113
|
+
if (!quoted) return value;
|
|
114
|
+
return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/css-macro/postcss.ts
|
|
118
|
+
const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
|
|
119
|
+
const CONDITIONAL_COMMENT_SPACING = " ";
|
|
120
|
+
const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
|
|
121
|
+
const creator = () => {
|
|
122
|
+
return {
|
|
123
|
+
postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
|
|
124
|
+
prepare() {
|
|
125
|
+
function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
|
|
126
|
+
const hasPreviousNode = Boolean(atRule.prev());
|
|
127
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
128
|
+
const startComment = helper.comment({
|
|
129
|
+
raws: {
|
|
130
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
131
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
132
|
+
},
|
|
133
|
+
text: comment.start
|
|
134
|
+
});
|
|
135
|
+
const endComment = helper.comment({
|
|
136
|
+
raws: {
|
|
137
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
138
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
139
|
+
},
|
|
140
|
+
text: comment.end
|
|
141
|
+
});
|
|
142
|
+
const nextNodes = [
|
|
143
|
+
startComment,
|
|
144
|
+
...clonedNodes,
|
|
145
|
+
endComment
|
|
146
|
+
];
|
|
147
|
+
atRule.replaceWith(nextNodes);
|
|
148
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
149
|
+
startComment.raws["after"] = "\n";
|
|
150
|
+
if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
|
|
151
|
+
endComment.raws.before = "\n";
|
|
152
|
+
endComment.raws["after"] = "\n";
|
|
153
|
+
const nextNode = endComment?.next();
|
|
154
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
155
|
+
}
|
|
156
|
+
function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
|
|
157
|
+
if (atRule.parent?.type !== "rule") return false;
|
|
158
|
+
const parentRule = atRule.parent;
|
|
159
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
160
|
+
const conditionalRule = parentRule.clone();
|
|
161
|
+
conditionalRule.removeAll();
|
|
162
|
+
conditionalRule.append(...clonedNodes);
|
|
163
|
+
const startComment = helper.comment({
|
|
164
|
+
raws: {
|
|
165
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
166
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
167
|
+
},
|
|
168
|
+
text: comment.start
|
|
169
|
+
});
|
|
170
|
+
const endComment = helper.comment({
|
|
171
|
+
raws: {
|
|
172
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
173
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
174
|
+
},
|
|
175
|
+
text: comment.end
|
|
176
|
+
});
|
|
177
|
+
const nextNodes = [
|
|
178
|
+
startComment,
|
|
179
|
+
conditionalRule,
|
|
180
|
+
endComment
|
|
181
|
+
];
|
|
182
|
+
const hasPreviousNode = Boolean(parentRule.prev());
|
|
183
|
+
atRule.remove();
|
|
184
|
+
if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
|
|
185
|
+
else parentRule.after(nextNodes);
|
|
186
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
187
|
+
startComment.raws["after"] = "\n";
|
|
188
|
+
conditionalRule.raws.before = "\n";
|
|
189
|
+
endComment.raws.before = "\n";
|
|
190
|
+
endComment.raws["after"] = "\n";
|
|
191
|
+
const nextNode = endComment.next();
|
|
192
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
AtRule(atRule, helper) {
|
|
197
|
+
if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
|
|
198
|
+
const text = parseConditionalAtRuleParam(atRule.params);
|
|
199
|
+
const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
|
|
200
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
201
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (atRule.name === "media") {
|
|
205
|
+
const values = [];
|
|
206
|
+
matchCustomPropertyFromValue(atRule.params, (arr) => {
|
|
207
|
+
const value = arr[1];
|
|
208
|
+
if (value) values.push(value);
|
|
209
|
+
});
|
|
210
|
+
if (values.length > 0) {
|
|
211
|
+
const isNegative = atRule.params.includes("not");
|
|
212
|
+
const text = values.join(" ");
|
|
213
|
+
const comment = isNegative ? ifndef(text) : ifdef(text);
|
|
214
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
215
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
CommentExit(comment) {
|
|
220
|
+
if (IFDEF_ENDIF_RE.test(comment.text)) {
|
|
221
|
+
comment.raws.left = CONDITIONAL_COMMENT_SPACING;
|
|
222
|
+
comment.raws.right = CONDITIONAL_COMMENT_SPACING;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
creator.postcss = true;
|
|
230
|
+
//#endregion
|
|
76
231
|
//#region src/tailwindcss/source-scan.ts
|
|
77
232
|
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
78
233
|
"html",
|
|
@@ -533,15 +688,18 @@ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolde
|
|
|
533
688
|
const globalCacheHolder = globalThis;
|
|
534
689
|
globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
535
690
|
//#endregion
|
|
536
|
-
//#region src/constants.ts
|
|
537
|
-
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
538
|
-
//#endregion
|
|
539
691
|
//#region src/babel/index.ts
|
|
540
692
|
function _interopDefaultCompat(e) {
|
|
541
693
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
542
694
|
}
|
|
543
695
|
const traverse = _interopDefaultCompat(_babel_traverse.default);
|
|
544
696
|
//#endregion
|
|
697
|
+
//#region src/utils/regex.ts
|
|
698
|
+
function escapeStringRegexp(str) {
|
|
699
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
700
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
701
|
+
}
|
|
702
|
+
//#endregion
|
|
545
703
|
//#region src/utils/nameMatcher.ts
|
|
546
704
|
const NEVER_MATCH_NAME$1 = () => false;
|
|
547
705
|
const GLOBAL_FLAG_REGEXP = /g/g;
|
|
@@ -553,7 +711,7 @@ function buildFuzzyMatcher(fuzzyStrings) {
|
|
|
553
711
|
return (value) => value.includes(needle);
|
|
554
712
|
}
|
|
555
713
|
const unique = [...new Set(fuzzyStrings)];
|
|
556
|
-
const pattern = new RegExp(unique.map(
|
|
714
|
+
const pattern = new RegExp(unique.map(escapeStringRegexp).join("|"));
|
|
557
715
|
return (value) => pattern.test(value);
|
|
558
716
|
}
|
|
559
717
|
function normaliseRegex(regex) {
|
|
@@ -2106,6 +2264,9 @@ var Tokenizer = class {
|
|
|
2106
2264
|
};
|
|
2107
2265
|
new Tokenizer();
|
|
2108
2266
|
//#endregion
|
|
2267
|
+
//#region src/constants.ts
|
|
2268
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
2269
|
+
//#endregion
|
|
2109
2270
|
//#region src/cli/context.ts
|
|
2110
2271
|
function formatOutputPath(target, baseDir) {
|
|
2111
2272
|
const root = baseDir ?? node_process.default.cwd();
|
package/dist/cli.mjs
CHANGED
|
@@ -18,12 +18,10 @@ import "fast-glob";
|
|
|
18
18
|
import "tailwindcss-config";
|
|
19
19
|
import _babelTraverse from "@babel/traverse";
|
|
20
20
|
import { parse } from "@babel/parser";
|
|
21
|
-
import { escapeStringRegexp } from "@weapp-core/regex";
|
|
22
21
|
import MagicString from "magic-string";
|
|
23
22
|
import { jsStringEscape } from "@ast-core/escape";
|
|
24
23
|
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
25
24
|
import "@babel/types";
|
|
26
|
-
import "htmlparser2";
|
|
27
25
|
//#region src/js/babel/cache-options.ts
|
|
28
26
|
const DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH = 5e4;
|
|
29
27
|
const HARD_PARSE_CACHE_MAX_ENTRIES = 1024;
|
|
@@ -44,6 +42,163 @@ function createDebug(prefix) {
|
|
|
44
42
|
return debug;
|
|
45
43
|
}
|
|
46
44
|
//#endregion
|
|
45
|
+
//#region src/css-macro/constants.ts
|
|
46
|
+
const queryKey = "weapp-tw-platform";
|
|
47
|
+
const UNESCAPED_UNDERSCORE_RE = /(?<!\\)_/g;
|
|
48
|
+
const WHITESPACE_RE = /\s+/g;
|
|
49
|
+
const LOGICAL_OPERATOR_RE = /\s*(\|\||&&)\s*/g;
|
|
50
|
+
function normalComment(text) {
|
|
51
|
+
if (typeof text === "string") {
|
|
52
|
+
const normalized = text.replaceAll(UNESCAPED_UNDERSCORE_RE, " ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
53
|
+
if (normalized.includes("\\")) return normalized;
|
|
54
|
+
return normalized.replaceAll(LOGICAL_OPERATOR_RE, " $1 ").replaceAll(WHITESPACE_RE, " ").trim();
|
|
55
|
+
}
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
function ifdef(text) {
|
|
59
|
+
return {
|
|
60
|
+
start: `#ifdef ${normalComment(text)}`,
|
|
61
|
+
end: `#endif`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function ifndef(text) {
|
|
65
|
+
return {
|
|
66
|
+
start: `#ifndef ${normalComment(text)}`,
|
|
67
|
+
end: `#endif`
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const QUERY_KEY_REGEX = new RegExp(`\\(\\s*${queryKey}\\s*:\\s*"([^)]*)"\\)`, "g");
|
|
71
|
+
function matchCustomPropertyFromValue(str, cb) {
|
|
72
|
+
let index = 0;
|
|
73
|
+
QUERY_KEY_REGEX.lastIndex = 0;
|
|
74
|
+
let arr = QUERY_KEY_REGEX.exec(str);
|
|
75
|
+
while (arr !== null) {
|
|
76
|
+
cb(arr, index);
|
|
77
|
+
index++;
|
|
78
|
+
arr = QUERY_KEY_REGEX.exec(str);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function parseConditionalAtRuleParam(params) {
|
|
82
|
+
const value = params.trim();
|
|
83
|
+
const quoted = /^(['"])((?:\\.|(?!\1).)*)\1/.exec(value);
|
|
84
|
+
if (!quoted) return value;
|
|
85
|
+
return quoted[2]?.replaceAll(/\\(["'\\])/g, "$1") ?? "";
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/css-macro/postcss.ts
|
|
89
|
+
const IFDEF_ENDIF_RE = /#(?:ifn?def|endif)/;
|
|
90
|
+
const CONDITIONAL_COMMENT_SPACING = " ";
|
|
91
|
+
const CSS_MACRO_POSTCSS_PLUGIN_NAME = "postcss-weapp-tw-css-macro-plugin";
|
|
92
|
+
const creator = () => {
|
|
93
|
+
return {
|
|
94
|
+
postcssPlugin: CSS_MACRO_POSTCSS_PLUGIN_NAME,
|
|
95
|
+
prepare() {
|
|
96
|
+
function replaceAtRuleWithConditionalComments(atRule, helper, comment) {
|
|
97
|
+
const hasPreviousNode = Boolean(atRule.prev());
|
|
98
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
99
|
+
const startComment = helper.comment({
|
|
100
|
+
raws: {
|
|
101
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
102
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
103
|
+
},
|
|
104
|
+
text: comment.start
|
|
105
|
+
});
|
|
106
|
+
const endComment = helper.comment({
|
|
107
|
+
raws: {
|
|
108
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
109
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
110
|
+
},
|
|
111
|
+
text: comment.end
|
|
112
|
+
});
|
|
113
|
+
const nextNodes = [
|
|
114
|
+
startComment,
|
|
115
|
+
...clonedNodes,
|
|
116
|
+
endComment
|
|
117
|
+
];
|
|
118
|
+
atRule.replaceWith(nextNodes);
|
|
119
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
120
|
+
startComment.raws["after"] = "\n";
|
|
121
|
+
if (clonedNodes[0]) clonedNodes[0].raws.before = "\n";
|
|
122
|
+
endComment.raws.before = "\n";
|
|
123
|
+
endComment.raws["after"] = "\n";
|
|
124
|
+
const nextNode = endComment?.next();
|
|
125
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
126
|
+
}
|
|
127
|
+
function replaceNestedAtRuleWithConditionalRule(atRule, helper, comment) {
|
|
128
|
+
if (atRule.parent?.type !== "rule") return false;
|
|
129
|
+
const parentRule = atRule.parent;
|
|
130
|
+
const clonedNodes = (atRule.nodes ?? []).map((node) => node.clone());
|
|
131
|
+
const conditionalRule = parentRule.clone();
|
|
132
|
+
conditionalRule.removeAll();
|
|
133
|
+
conditionalRule.append(...clonedNodes);
|
|
134
|
+
const startComment = helper.comment({
|
|
135
|
+
raws: {
|
|
136
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
137
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
138
|
+
},
|
|
139
|
+
text: comment.start
|
|
140
|
+
});
|
|
141
|
+
const endComment = helper.comment({
|
|
142
|
+
raws: {
|
|
143
|
+
left: CONDITIONAL_COMMENT_SPACING,
|
|
144
|
+
right: CONDITIONAL_COMMENT_SPACING
|
|
145
|
+
},
|
|
146
|
+
text: comment.end
|
|
147
|
+
});
|
|
148
|
+
const nextNodes = [
|
|
149
|
+
startComment,
|
|
150
|
+
conditionalRule,
|
|
151
|
+
endComment
|
|
152
|
+
];
|
|
153
|
+
const hasPreviousNode = Boolean(parentRule.prev());
|
|
154
|
+
atRule.remove();
|
|
155
|
+
if ((parentRule.nodes?.length ?? 0) === 0) parentRule.replaceWith(nextNodes);
|
|
156
|
+
else parentRule.after(nextNodes);
|
|
157
|
+
startComment.raws.before = hasPreviousNode ? "\n" : "";
|
|
158
|
+
startComment.raws["after"] = "\n";
|
|
159
|
+
conditionalRule.raws.before = "\n";
|
|
160
|
+
endComment.raws.before = "\n";
|
|
161
|
+
endComment.raws["after"] = "\n";
|
|
162
|
+
const nextNode = endComment.next();
|
|
163
|
+
if (nextNode) nextNode.raws.before = "\n";
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
AtRule(atRule, helper) {
|
|
168
|
+
if (atRule.name === "weapp-tw-ifdef" || atRule.name === "weapp-tw-ifndef") {
|
|
169
|
+
const text = parseConditionalAtRuleParam(atRule.params);
|
|
170
|
+
const comment = atRule.name === "weapp-tw-ifndef" ? ifndef(text) : ifdef(text);
|
|
171
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
172
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (atRule.name === "media") {
|
|
176
|
+
const values = [];
|
|
177
|
+
matchCustomPropertyFromValue(atRule.params, (arr) => {
|
|
178
|
+
const value = arr[1];
|
|
179
|
+
if (value) values.push(value);
|
|
180
|
+
});
|
|
181
|
+
if (values.length > 0) {
|
|
182
|
+
const isNegative = atRule.params.includes("not");
|
|
183
|
+
const text = values.join(" ");
|
|
184
|
+
const comment = isNegative ? ifndef(text) : ifdef(text);
|
|
185
|
+
if (replaceNestedAtRuleWithConditionalRule(atRule, helper, comment)) return;
|
|
186
|
+
replaceAtRuleWithConditionalComments(atRule, helper, comment);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
CommentExit(comment) {
|
|
191
|
+
if (IFDEF_ENDIF_RE.test(comment.text)) {
|
|
192
|
+
comment.raws.left = CONDITIONAL_COMMENT_SPACING;
|
|
193
|
+
comment.raws.right = CONDITIONAL_COMMENT_SPACING;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
creator.postcss = true;
|
|
201
|
+
//#endregion
|
|
47
202
|
//#region src/tailwindcss/source-scan.ts
|
|
48
203
|
const DEFAULT_SOURCE_SCAN_EXTENSIONS = [
|
|
49
204
|
"html",
|
|
@@ -504,15 +659,18 @@ runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ ?? (runtimeLogDedupeHolde
|
|
|
504
659
|
const globalCacheHolder = globalThis;
|
|
505
660
|
globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ ?? (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map());
|
|
506
661
|
//#endregion
|
|
507
|
-
//#region src/constants.ts
|
|
508
|
-
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
509
|
-
//#endregion
|
|
510
662
|
//#region src/babel/index.ts
|
|
511
663
|
function _interopDefaultCompat(e) {
|
|
512
664
|
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
513
665
|
}
|
|
514
666
|
const traverse = _interopDefaultCompat(_babelTraverse);
|
|
515
667
|
//#endregion
|
|
668
|
+
//#region src/utils/regex.ts
|
|
669
|
+
function escapeStringRegexp(str) {
|
|
670
|
+
if (typeof str !== "string") throw new TypeError("Expected a string");
|
|
671
|
+
return str.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&").replaceAll("-", "\\x2d");
|
|
672
|
+
}
|
|
673
|
+
//#endregion
|
|
516
674
|
//#region src/utils/nameMatcher.ts
|
|
517
675
|
const NEVER_MATCH_NAME$1 = () => false;
|
|
518
676
|
const GLOBAL_FLAG_REGEXP = /g/g;
|
|
@@ -2077,6 +2235,9 @@ var Tokenizer = class {
|
|
|
2077
2235
|
};
|
|
2078
2236
|
new Tokenizer();
|
|
2079
2237
|
//#endregion
|
|
2238
|
+
//#region src/constants.ts
|
|
2239
|
+
const WEAPP_TW_REQUIRED_NODE_VERSION_RANGE = "^20.19.0 || >=22.12.0";
|
|
2240
|
+
//#endregion
|
|
2080
2241
|
//#region src/cli/context.ts
|
|
2081
2242
|
function formatOutputPath(target, baseDir) {
|
|
2082
2243
|
const root = baseDir ?? process.cwd();
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./chunk-8l464Juk.js");
|
|
3
|
-
const require_precheck = require("./precheck-
|
|
3
|
+
const require_precheck = require("./precheck-DLJg0_pu.js");
|
|
4
4
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
5
5
|
//#region src/core.ts
|
|
6
6
|
const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|