weapp-tailwindcss 5.3.2 → 5.3.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.
Files changed (52) hide show
  1. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +3 -0
  2. package/dist/bundlers/shared/style-requests.d.ts +1 -0
  3. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
  4. package/dist/bundlers/vite/shared/framework-module-candidates.d.ts +15 -0
  5. package/dist/{context-Kvr3lLEC.js → context-4ittVpgt.js} +1 -1
  6. package/dist/{context-CB4Ef9U0.cjs → context-Ulhcd5lF.cjs} +3 -3
  7. package/dist/core.cjs +1 -1
  8. package/dist/core.js +1 -1
  9. package/dist/{gulp-QJ_oz-06.cjs → gulp-CDIXMhIO.cjs} +6 -6
  10. package/dist/{gulp-vz36-uQP.js → gulp-DwtrU4V1.js} +3 -3
  11. package/dist/gulp.cjs +1 -1
  12. package/dist/gulp.js +1 -1
  13. package/dist/{hmr-timing-W3kro20F.cjs → hmr-timing-DcFB_kwB.cjs} +2 -2
  14. package/dist/{hmr-timing-HGlM4hX3.js → hmr-timing-utmOgn6p.js} +57 -14
  15. package/dist/index.cjs +3 -3
  16. package/dist/index.js +3 -3
  17. package/dist/local-style-matcher-DRpFEu1s.cjs +34 -0
  18. package/dist/local-style-matcher-DsiI2wIc.js +17 -0
  19. package/dist/{options-CKZW99r4.cjs → options-BJrtIQbH.cjs} +3 -1
  20. package/dist/{pipeline-helpers-t95KPu4O.cjs → pipeline-helpers-kB7Mn2Jy.cjs} +2 -2
  21. package/dist/presets.cjs +2 -2
  22. package/dist/presets.js +1 -1
  23. package/dist/rspack.cjs +2 -2
  24. package/dist/rspack.js +2 -2
  25. package/dist/{source-candidate-scan-signature-BSad7bMQ.cjs → source-candidate-scan-signature-C1r5mHSi.cjs} +2 -2
  26. package/dist/{source-candidate-scan-signature-BHCPQVoD.js → source-candidate-scan-signature-CDrLxVKu.js} +2 -2
  27. package/dist/{style-options-PCgz2ywM.cjs → style-options-DW30H5PV.cjs} +1 -1
  28. package/dist/{tailwindcss-jKzY37Sk.cjs → tailwindcss-CexDJBhx.cjs} +1 -1
  29. package/dist/{tailwindcss-BSEdWieh.js → tailwindcss-ChnpCv25.js} +3 -1
  30. package/dist/{component-local-style-CNhEhd2B.cjs → transform-BQjg2T2T.cjs} +201 -27
  31. package/dist/{component-local-style-C2wC8o9F.js → transform-Cp4KybBy.js} +207 -16
  32. package/dist/types/user-defined-options/important.d.ts +2 -0
  33. package/dist/uni-app-x/component-local-style.d.ts +6 -4
  34. package/dist/uni-app-x/local-style-matcher.d.ts +4 -0
  35. package/dist/uni-app-x/options.d.ts +2 -0
  36. package/dist/uni-app-x/style-asset/harmony-global.d.ts +2 -0
  37. package/dist/uni-app-x/transform.d.ts +2 -0
  38. package/dist/uni-app-x/vite/plugin-options.d.ts +1 -0
  39. package/dist/uni-app-x/vite/style-request.d.ts +0 -1
  40. package/dist/{v4-generation-core-BfeXEc6R.cjs → v4-generation-core-OVshPBGo.cjs} +62 -13
  41. package/dist/{vite-CVr0vIgh.js → vite-D1a6OfVn.js} +130 -91
  42. package/dist/{vite-Dy6THt54.cjs → vite-cXJPnKXp.cjs} +77 -38
  43. package/dist/vite.cjs +1 -1
  44. package/dist/vite.js +1 -1
  45. package/dist/weapp-tw-css-import-rewrite-loader.cjs +4 -4
  46. package/dist/{webpack-Cf5RnhXt.cjs → webpack-DOhCcN_2.cjs} +8 -8
  47. package/dist/{webpack-DwtdWqwr.js → webpack-DQAbh1Z7.js} +4 -4
  48. package/dist/webpack.cjs +1 -1
  49. package/dist/webpack.js +1 -1
  50. package/package.json +2 -2
  51. package/dist/transform-CgohToUV.cjs +0 -200
  52. package/dist/transform-DSRPiBWz.js +0 -201
@@ -1,201 +0,0 @@
1
- import { n as generateCode, p as replaceWxml, r as createAttributeMatcher } from "./wxml-B7OAVpXJ.js";
2
- import { n as shouldEnableComponentLocalStyle, r as shouldEnablePageLocalStyle, t as UniAppXComponentLocalStyleCollector } from "./component-local-style-C2wC8o9F.js";
3
- import MagicString from "magic-string";
4
- import { NodeTypes, parse } from "@vue/compiler-dom";
5
- //#region src/uni-app-x/transform.ts
6
- function traverse(node, visitor) {
7
- visitor(node);
8
- if (Array.isArray(node.children)) {
9
- for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
10
- }
11
- }
12
- function updateStaticAttribute(ms, prop, offset, content = prop.value?.content) {
13
- if (!prop.value) return;
14
- const start = offset + prop.value.loc.start.offset + 1;
15
- const end = offset + prop.value.loc.end.offset - 1;
16
- if (start < end) ms.update(start, end, replaceWxml(content ?? ""));
17
- }
18
- function updateStaticAttributeWithLocalStyle(ms, prop, offset, collector, deep, content = prop.value?.content) {
19
- if (!prop.value) return;
20
- const start = offset + prop.value.loc.start.offset + 1;
21
- const end = offset + prop.value.loc.end.offset - 1;
22
- if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? "", { deep }));
23
- }
24
- function updateDirectiveExpression(ms, prop, offset, jsHandler, runtimeSet) {
25
- if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
26
- const expression = prop.exp.content;
27
- const start = offset + prop.exp.loc.start.offset;
28
- const end = offset + prop.exp.loc.end.offset;
29
- if (start >= end) return;
30
- const generated = generateCode(expression, {
31
- jsHandler,
32
- runtimeSet,
33
- wrapExpression: true
34
- });
35
- ms.update(start, end, generated);
36
- }
37
- function updateDirectiveExpressionWithLocalStyle(ms, prop, offset, jsHandler, collector, deep, runtimeSet) {
38
- if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) return;
39
- const expression = prop.exp.content;
40
- const start = offset + prop.exp.loc.start.offset;
41
- const end = offset + prop.exp.loc.end.offset;
42
- if (start >= end) return;
43
- collector.collectRuntimeClasses(expression, {
44
- deep,
45
- wrapExpression: true
46
- });
47
- const generated = generateCode(expression, {
48
- jsHandler,
49
- runtimeSet,
50
- wrapExpression: true
51
- });
52
- ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
53
- }
54
- function shouldEnableLocalStyle(id, options) {
55
- if (options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id)) return true;
56
- if (options.enablePageLocalStyle && shouldEnablePageLocalStyle(id)) return true;
57
- return false;
58
- }
59
- function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
60
- const lowerName = attrName.toLowerCase();
61
- const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
62
- const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
63
- return {
64
- shouldHandleDefault,
65
- shouldHandleCustom,
66
- shouldHandle: shouldHandleDefault || shouldHandleCustom
67
- };
68
- }
69
- const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
70
- const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
71
- const SFC_BLOCK_RE = /<(template|script|style)\b([^>]*)>/gi;
72
- const SCRIPT_SETUP_RE = /(?:^|\s)setup(?:\s|=|$)/;
73
- const STYLE_SCOPED_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
74
- function findSfcBlockEnd(code, type, contentStart) {
75
- const closeTag = new RegExp(`<\\/${type}\\s*>`, "gi");
76
- if (type !== "template") {
77
- const match = closeTag.exec(code.slice(contentStart));
78
- return match ? {
79
- blockEnd: contentStart + match.index + match[0].length,
80
- contentEnd: contentStart + match.index
81
- } : void 0;
82
- }
83
- const tag = new RegExp(`<\\/?${type}\\b[^>]*>`, "gi");
84
- tag.lastIndex = contentStart;
85
- let depth = 1;
86
- let match = tag.exec(code);
87
- while (match) {
88
- if (match[0].startsWith("</")) depth -= 1;
89
- else if (!match[0].trimEnd().endsWith("/>")) depth += 1;
90
- if (depth === 0) return {
91
- blockEnd: tag.lastIndex,
92
- contentEnd: match.index
93
- };
94
- match = tag.exec(code);
95
- }
96
- }
97
- function parseSfc(code) {
98
- const descriptor = {
99
- errors: [],
100
- styles: []
101
- };
102
- for (const match of code.matchAll(SFC_BLOCK_RE)) {
103
- const type = match[1];
104
- const attrs = match[2] ?? "";
105
- const contentStart = (match.index ?? 0) + match[0].length;
106
- const blockBoundary = findSfcBlockEnd(code, type, contentStart);
107
- if (!blockBoundary) {
108
- descriptor.errors.push(/* @__PURE__ */ new Error(`未闭合的 ${type} SFC 块`));
109
- continue;
110
- }
111
- const { contentEnd } = blockBoundary;
112
- const content = code.slice(contentStart, contentEnd);
113
- const block = {
114
- content,
115
- start: contentStart,
116
- end: contentEnd,
117
- attrs
118
- };
119
- if (type === "template" && !descriptor.template) {
120
- try {
121
- descriptor.template = {
122
- ...block,
123
- ast: parse(content)
124
- };
125
- } catch (error) {
126
- descriptor.errors.push(error);
127
- descriptor.template = block;
128
- }
129
- continue;
130
- }
131
- if (type === "script") {
132
- if (SCRIPT_SETUP_RE.test(attrs)) descriptor.scriptSetup ?? (descriptor.scriptSetup = block);
133
- else descriptor.script ?? (descriptor.script = block);
134
- continue;
135
- }
136
- if (type === "style") descriptor.styles.push(block);
137
- }
138
- return descriptor;
139
- }
140
- function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
141
- if (!UVUE_NVUE_RE.test(id)) return;
142
- const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
143
- const matchCustomAttribute = createAttributeMatcher(customAttributesEntities);
144
- const ms = new MagicString(code);
145
- const descriptor = parseSfc(code);
146
- const localStyleCollector = shouldEnableLocalStyle(id, options) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
147
- if (descriptor.errors.length === 0) {
148
- if (descriptor.template?.ast) {
149
- const templateOffset = descriptor.template.start;
150
- traverse(descriptor.template.ast, (node) => {
151
- if (node.type !== NodeTypes.ELEMENT) return;
152
- const tag = node.tag;
153
- for (const prop of node.props) if (prop.type === NodeTypes.ATTRIBUTE) {
154
- const { shouldHandle, shouldHandleCustom, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
155
- if (!shouldHandle) continue;
156
- if (localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, templateOffset, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom);
157
- else updateStaticAttribute(ms, prop, templateOffset);
158
- if (shouldHandleDefault) continue;
159
- } else if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
160
- const attrName = prop.arg.content;
161
- const { shouldHandle, shouldHandleCustom } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
162
- if (!shouldHandle) continue;
163
- if (localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, templateOffset, jsHandler, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom, runtimeSet);
164
- else updateDirectiveExpression(ms, prop, templateOffset, jsHandler, runtimeSet);
165
- }
166
- });
167
- }
168
- if (descriptor.script) {
169
- localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
170
- const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
171
- ms.update(descriptor.script.start, descriptor.script.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
172
- }
173
- if (descriptor.scriptSetup) {
174
- localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
175
- const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
176
- ms.update(descriptor.scriptSetup.start, descriptor.scriptSetup.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
177
- }
178
- if (localStyleCollector?.hasStyles()) {
179
- const scopedStyle = descriptor.styles.findLast((style) => STYLE_SCOPED_RE.test(style.attrs));
180
- if (scopedStyle && options.onWebLocalStyleRules) options.onWebLocalStyleRules(localStyleCollector.toStyleRules());
181
- else if (scopedStyle) {
182
- const separator = scopedStyle.content.endsWith("\n") ? "" : "\n";
183
- ms.appendLeft(scopedStyle.end, `${separator}${localStyleCollector.toStyleRules()}`);
184
- } else ms.append(`\n${localStyleCollector.toStyleBlock()}`);
185
- }
186
- }
187
- const result = {
188
- code: ms.toString(),
189
- map: null
190
- };
191
- Object.defineProperty(result, "map", {
192
- configurable: true,
193
- enumerable: true,
194
- get() {
195
- return ms.generateMap();
196
- }
197
- });
198
- return result;
199
- }
200
- //#endregion
201
- export { transformUVue };