weapp-tailwindcss 5.0.2 → 5.0.4
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.en.md +9 -0
- package/README.md +5 -133
- package/dist/{auto-dPpsm6FB.js → auto-BZ4n4Icc.js} +1 -1
- package/dist/{bundle-state-DY3eq4Gz.mjs → bundle-state-C-p9eFz1.mjs} +1 -1
- package/dist/{bundle-state-Bvj01pW7.js → bundle-state-D3RZHkXz.js} +2 -2
- package/dist/{chunk-C5U5_Hdc.js → chunk-D6vf50IK.js} +0 -14
- package/dist/cli.js +4 -4
- package/dist/cli.mjs +4 -4
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/{defaults-zKUH2mDe.js → defaults-C5w9OOrj.js} +1 -1
- package/dist/defaults.js +1 -1
- package/dist/{generator-Bd1LntD3.js → generator-DaPOkJ7W.js} +2 -2
- package/dist/generator.js +2 -2
- package/dist/gulp.js +6 -6
- package/dist/gulp.mjs +2 -2
- package/dist/{incremental-runtime-class-set-Bl18sFqt.js → incremental-runtime-class-set-BYV0yQdp.js} +5 -4
- package/dist/{incremental-runtime-class-set-CAEuUesH.mjs → incremental-runtime-class-set-Dt-FUQB5.mjs} +2 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +2 -2
- package/dist/{postcss-DfnqZ4Bm.js → postcss-Du8hY-MN.js} +3 -3
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss.js +1 -1
- package/dist/{precheck-Bj5ReSOU.js → precheck-DgpVCvYk.js} +9 -34
- package/dist/{precheck-CUr1DYyy.mjs → precheck-lfenbOTF.mjs} +9 -34
- package/dist/presets.js +4 -4
- package/dist/reset.js +1 -1
- package/dist/{source-candidates-DQxvGPSw.js → source-candidates-B4NvId_j.js} +2 -2
- package/dist/{tailwindcss-jvoYizzX.js → tailwindcss-26ZFr5kv.js} +3 -3
- package/dist/transform-Crn84vTL.js +257 -0
- package/dist/transform-FAxHXVZp.mjs +255 -0
- package/dist/{utils-D7Ygohep.js → utils-nta4tfFs.js} +1 -1
- package/dist/{v3-engine-CmIF_gsq.js → v3-engine-CBahpuIg.js} +2 -2
- package/dist/vite-DS4H5d0f.mjs +2616 -0
- package/dist/vite-tjYalmVX.js +2629 -0
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -0
- package/dist/{webpack-vk2uqSnK.js → webpack-0BwLOE_f.js} +8 -9
- package/dist/{webpack-CChDqRrl.mjs → webpack-CA-40WU9.mjs} +4 -5
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +5 -5
- package/dist/vite-D1ZdgbWa.js +0 -24750
- package/dist/vite-jBTi5CwO.mjs +0 -24736
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { c as createAttributeMatcher, d as _defineProperty, f as isClassContextLiteralPath, l as analyzeSource, m as babelParse, p as replaceWxml, s as generateCode, u as JsTokenUpdater } from "./precheck-lfenbOTF.mjs";
|
|
2
|
+
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
3
|
+
import MagicString from "magic-string";
|
|
4
|
+
import { NodeTypes } from "@vue/compiler-dom";
|
|
5
|
+
import { parse } from "@vue/compiler-sfc";
|
|
6
|
+
//#region src/uni-app-x/component-local-style.ts
|
|
7
|
+
const EXPRESSION_WRAPPER_PREFIX = "(\n";
|
|
8
|
+
const EXPRESSION_WRAPPER_SUFFIX = "\n)";
|
|
9
|
+
const COMPONENT_RE = /(?:^|[/\\])components(?:[/\\].+)?\.(?:uvue|nvue)$/;
|
|
10
|
+
function createStableHash(input) {
|
|
11
|
+
let hash = 2166136261;
|
|
12
|
+
for (let i = 0; i < input.length; i++) {
|
|
13
|
+
hash ^= input.charCodeAt(i);
|
|
14
|
+
hash = Math.imul(hash, 16777619);
|
|
15
|
+
}
|
|
16
|
+
return (hash >>> 0).toString(36);
|
|
17
|
+
}
|
|
18
|
+
function extractLiteralValue(path) {
|
|
19
|
+
if (path.isStringLiteral()) return {
|
|
20
|
+
literal: path.node.value,
|
|
21
|
+
offset: 1
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
literal: typeof path.node.value === "string" ? path.node.value : path.node.value.raw,
|
|
25
|
+
offset: 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function createAlias(fileId, utility, index) {
|
|
29
|
+
return `wtu-${createStableHash(`${fileId}:${utility}`)}-${index.toString(36)}`;
|
|
30
|
+
}
|
|
31
|
+
function isRuntimeCandidate(candidate, runtimeSet) {
|
|
32
|
+
if (!runtimeSet || runtimeSet.size === 0) return false;
|
|
33
|
+
return runtimeSet.has(candidate) || runtimeSet.has(replaceWxml(candidate));
|
|
34
|
+
}
|
|
35
|
+
function shouldEnableComponentLocalStyle(id) {
|
|
36
|
+
return COMPONENT_RE.test(id);
|
|
37
|
+
}
|
|
38
|
+
var UniAppXComponentLocalStyleCollector = class {
|
|
39
|
+
constructor(fileId, runtimeSet) {
|
|
40
|
+
this.fileId = fileId;
|
|
41
|
+
this.runtimeSet = runtimeSet;
|
|
42
|
+
_defineProperty(this, "aliasByUtility", /* @__PURE__ */ new Map());
|
|
43
|
+
_defineProperty(this, "aliasByLookup", /* @__PURE__ */ new Map());
|
|
44
|
+
}
|
|
45
|
+
ensureAlias(utility) {
|
|
46
|
+
const cached = this.aliasByUtility.get(utility);
|
|
47
|
+
if (cached) return cached;
|
|
48
|
+
const alias = createAlias(this.fileId, utility, this.aliasByUtility.size);
|
|
49
|
+
this.aliasByUtility.set(utility, alias);
|
|
50
|
+
this.aliasByLookup.set(utility, alias);
|
|
51
|
+
this.aliasByLookup.set(replaceWxml(utility), alias);
|
|
52
|
+
return alias;
|
|
53
|
+
}
|
|
54
|
+
rewriteLiteral(literal, shouldInclude) {
|
|
55
|
+
const candidates = splitCandidateTokens(literal);
|
|
56
|
+
if (candidates.length === 0) return literal;
|
|
57
|
+
let rewritten = literal;
|
|
58
|
+
for (const candidate of candidates) {
|
|
59
|
+
if (!shouldInclude(candidate)) continue;
|
|
60
|
+
rewritten = rewritten.replace(candidate, this.ensureAlias(candidate));
|
|
61
|
+
}
|
|
62
|
+
return rewritten;
|
|
63
|
+
}
|
|
64
|
+
collectAndRewriteStaticClass(literal) {
|
|
65
|
+
return this.rewriteLiteral(literal, (candidate) => isRuntimeCandidate(candidate, this.runtimeSet));
|
|
66
|
+
}
|
|
67
|
+
collectRuntimeClasses(rawSource, options = {}) {
|
|
68
|
+
const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
69
|
+
try {
|
|
70
|
+
const analysis = analyzeSource(babelParse(wrapped, {
|
|
71
|
+
plugins: ["typescript"],
|
|
72
|
+
sourceType: options.wrapExpression ? "module" : "unambiguous"
|
|
73
|
+
}), {}, void 0, false);
|
|
74
|
+
for (const path of analysis.targetPaths) {
|
|
75
|
+
const { literal } = extractLiteralValue(path);
|
|
76
|
+
const candidates = splitCandidateTokens(literal);
|
|
77
|
+
const classContext = options.wrapExpression || isClassContextLiteralPath(path);
|
|
78
|
+
for (const candidate of candidates) {
|
|
79
|
+
if (!candidate || !classContext && !isRuntimeCandidate(candidate, this.runtimeSet)) continue;
|
|
80
|
+
if (isRuntimeCandidate(candidate, this.runtimeSet)) this.ensureAlias(candidate);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch {}
|
|
84
|
+
}
|
|
85
|
+
rewriteTransformedCode(rawSource, options = {}) {
|
|
86
|
+
if (this.aliasByLookup.size === 0) return rawSource;
|
|
87
|
+
const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
88
|
+
try {
|
|
89
|
+
const analysis = analyzeSource(babelParse(wrapped, {
|
|
90
|
+
plugins: ["typescript"],
|
|
91
|
+
sourceType: options.wrapExpression ? "module" : "unambiguous"
|
|
92
|
+
}), {}, void 0, false);
|
|
93
|
+
if (analysis.targetPaths.length === 0) return rawSource;
|
|
94
|
+
const updater = new JsTokenUpdater();
|
|
95
|
+
for (const path of analysis.targetPaths) {
|
|
96
|
+
const { literal, offset } = extractLiteralValue(path);
|
|
97
|
+
const candidates = splitCandidateTokens(literal);
|
|
98
|
+
if (candidates.length === 0) continue;
|
|
99
|
+
let rewritten = literal;
|
|
100
|
+
let mutated = false;
|
|
101
|
+
for (const candidate of candidates) {
|
|
102
|
+
const alias = this.aliasByLookup.get(candidate);
|
|
103
|
+
if (!alias) continue;
|
|
104
|
+
const replaced = rewritten.replace(candidate, alias);
|
|
105
|
+
if (replaced !== rewritten) {
|
|
106
|
+
rewritten = replaced;
|
|
107
|
+
mutated = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (!mutated || typeof path.node.start !== "number" || typeof path.node.end !== "number") continue;
|
|
111
|
+
updater.addToken({
|
|
112
|
+
start: path.node.start + offset,
|
|
113
|
+
end: path.node.end - offset,
|
|
114
|
+
value: rewritten,
|
|
115
|
+
path
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (updater.length === 0) return rawSource;
|
|
119
|
+
const ms = new MagicString(wrapped);
|
|
120
|
+
updater.updateMagicString(ms);
|
|
121
|
+
if (options.wrapExpression) {
|
|
122
|
+
ms.remove(0, 2);
|
|
123
|
+
ms.remove(wrapped.length - 2, wrapped.length);
|
|
124
|
+
}
|
|
125
|
+
return ms.toString();
|
|
126
|
+
} catch {
|
|
127
|
+
return rawSource;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
hasStyles() {
|
|
131
|
+
return this.aliasByUtility.size > 0;
|
|
132
|
+
}
|
|
133
|
+
toStyleBlock() {
|
|
134
|
+
if (!this.hasStyles()) return "";
|
|
135
|
+
const lines = ["<style scoped>"];
|
|
136
|
+
for (const [utility, alias] of this.aliasByUtility) {
|
|
137
|
+
lines.push(`.${alias} {`);
|
|
138
|
+
lines.push(` @apply ${utility};`);
|
|
139
|
+
lines.push("}");
|
|
140
|
+
}
|
|
141
|
+
lines.push("</style>");
|
|
142
|
+
return `${lines.join("\n")}\n`;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/uni-app-x/transform.ts
|
|
147
|
+
function traverse(node, visitor) {
|
|
148
|
+
visitor(node);
|
|
149
|
+
if (Array.isArray(node.children)) {
|
|
150
|
+
for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function updateStaticAttribute(ms, prop, content = prop.value?.content) {
|
|
154
|
+
if (!prop.value) return;
|
|
155
|
+
const start = prop.value.loc.start.offset + 1;
|
|
156
|
+
const end = prop.value.loc.end.offset - 1;
|
|
157
|
+
if (start < end) ms.update(start, end, replaceWxml(content ?? ""));
|
|
158
|
+
}
|
|
159
|
+
function updateStaticAttributeWithLocalStyle(ms, prop, collector, content = prop.value?.content) {
|
|
160
|
+
if (!prop.value) return;
|
|
161
|
+
const start = prop.value.loc.start.offset + 1;
|
|
162
|
+
const end = prop.value.loc.end.offset - 1;
|
|
163
|
+
if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? ""));
|
|
164
|
+
}
|
|
165
|
+
function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
166
|
+
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
|
|
167
|
+
const expression = prop.exp.content;
|
|
168
|
+
const start = prop.exp.loc.start.offset;
|
|
169
|
+
const end = prop.exp.loc.end.offset;
|
|
170
|
+
if (start >= end) return;
|
|
171
|
+
const generated = generateCode(expression, {
|
|
172
|
+
jsHandler,
|
|
173
|
+
runtimeSet,
|
|
174
|
+
wrapExpression: true
|
|
175
|
+
});
|
|
176
|
+
ms.update(start, end, generated);
|
|
177
|
+
}
|
|
178
|
+
function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet) {
|
|
179
|
+
if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
|
|
180
|
+
const expression = prop.exp.content;
|
|
181
|
+
const start = prop.exp.loc.start.offset;
|
|
182
|
+
const end = prop.exp.loc.end.offset;
|
|
183
|
+
if (start >= end) return;
|
|
184
|
+
collector.collectRuntimeClasses(expression, { wrapExpression: true });
|
|
185
|
+
const generated = generateCode(expression, {
|
|
186
|
+
jsHandler,
|
|
187
|
+
runtimeSet,
|
|
188
|
+
wrapExpression: true
|
|
189
|
+
});
|
|
190
|
+
ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
|
|
191
|
+
}
|
|
192
|
+
function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
|
|
193
|
+
const lowerName = attrName.toLowerCase();
|
|
194
|
+
const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
|
|
195
|
+
const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
|
|
196
|
+
return {
|
|
197
|
+
shouldHandleDefault,
|
|
198
|
+
shouldHandleCustom,
|
|
199
|
+
shouldHandle: shouldHandleDefault || shouldHandleCustom
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
|
|
203
|
+
const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
|
|
204
|
+
function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
205
|
+
if (!UVUE_NVUE_RE.test(id)) return;
|
|
206
|
+
const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
|
|
207
|
+
const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
|
|
208
|
+
const ms = new MagicString(code);
|
|
209
|
+
const { descriptor, errors } = parse(code);
|
|
210
|
+
const localStyleCollector = options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
|
|
211
|
+
if (errors.length === 0) {
|
|
212
|
+
if (descriptor.template?.ast) traverse(descriptor.template.ast, (node) => {
|
|
213
|
+
if (node.type !== NodeTypes.ELEMENT) return;
|
|
214
|
+
const tag = node.tag;
|
|
215
|
+
for (const prop of node.props) if (prop.type === NodeTypes.ATTRIBUTE) {
|
|
216
|
+
const { shouldHandle, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
|
|
217
|
+
if (!shouldHandle) continue;
|
|
218
|
+
if (shouldHandleDefault && localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, localStyleCollector);
|
|
219
|
+
else updateStaticAttribute(ms, prop);
|
|
220
|
+
if (shouldHandleDefault) continue;
|
|
221
|
+
} else if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
|
|
222
|
+
const attrName = prop.arg.content;
|
|
223
|
+
const { shouldHandle } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
|
|
224
|
+
if (!shouldHandle) continue;
|
|
225
|
+
if (attrName.toLowerCase() === "class" && localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, localStyleCollector, runtimeSet);
|
|
226
|
+
else updateDirectiveExpression(ms, prop, jsHandler, runtimeSet);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
if (descriptor.script) {
|
|
230
|
+
localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
|
|
231
|
+
const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
|
|
232
|
+
ms.update(descriptor.script.loc.start.offset, descriptor.script.loc.end.offset, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
|
|
233
|
+
}
|
|
234
|
+
if (descriptor.scriptSetup) {
|
|
235
|
+
localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
|
|
236
|
+
const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
|
|
237
|
+
ms.update(descriptor.scriptSetup.loc.start.offset, descriptor.scriptSetup.loc.end.offset, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
|
|
238
|
+
}
|
|
239
|
+
if (localStyleCollector?.hasStyles()) ms.append(`\n${localStyleCollector.toStyleBlock()}`);
|
|
240
|
+
}
|
|
241
|
+
const result = {
|
|
242
|
+
code: ms.toString(),
|
|
243
|
+
map: null
|
|
244
|
+
};
|
|
245
|
+
Object.defineProperty(result, "map", {
|
|
246
|
+
configurable: true,
|
|
247
|
+
enumerable: true,
|
|
248
|
+
get() {
|
|
249
|
+
return ms.generateMap();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
//#endregion
|
|
255
|
+
export { transformUVue };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-
|
|
2
|
-
const require_auto = require("./auto-
|
|
1
|
+
const require_chunk = require("./chunk-D6vf50IK.js");
|
|
2
|
+
const require_auto = require("./auto-BZ4n4Icc.js");
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
node_fs = require_chunk.__toESM(node_fs);
|
|
5
5
|
let node_module = require("node:module");
|