weapp-tailwindcss 5.3.2 → 5.3.3

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 (50) hide show
  1. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +3 -0
  2. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
  3. package/dist/bundlers/vite/shared/framework-module-candidates.d.ts +15 -0
  4. package/dist/{context-Kvr3lLEC.js → context-4ittVpgt.js} +1 -1
  5. package/dist/{context-CB4Ef9U0.cjs → context-Ulhcd5lF.cjs} +3 -3
  6. package/dist/core.cjs +1 -1
  7. package/dist/core.js +1 -1
  8. package/dist/{gulp-vz36-uQP.js → gulp-8V2aiU52.js} +3 -3
  9. package/dist/{gulp-QJ_oz-06.cjs → gulp-CsssU4xB.cjs} +6 -6
  10. package/dist/gulp.cjs +1 -1
  11. package/dist/gulp.js +1 -1
  12. package/dist/{hmr-timing-HGlM4hX3.js → hmr-timing-CTpjCpQh.js} +42 -13
  13. package/dist/{hmr-timing-W3kro20F.cjs → hmr-timing-DyiiYupC.cjs} +2 -2
  14. package/dist/index.cjs +3 -3
  15. package/dist/index.js +3 -3
  16. package/dist/local-style-matcher-DRpFEu1s.cjs +34 -0
  17. package/dist/local-style-matcher-DsiI2wIc.js +17 -0
  18. package/dist/{options-CKZW99r4.cjs → options-BJrtIQbH.cjs} +3 -1
  19. package/dist/{pipeline-helpers-t95KPu4O.cjs → pipeline-helpers-Cda0Ox3K.cjs} +2 -2
  20. package/dist/presets.cjs +2 -2
  21. package/dist/presets.js +1 -1
  22. package/dist/rspack.cjs +2 -2
  23. package/dist/rspack.js +2 -2
  24. package/dist/{source-candidate-scan-signature-BHCPQVoD.js → source-candidate-scan-signature--r31NK5J.js} +2 -2
  25. package/dist/{source-candidate-scan-signature-BSad7bMQ.cjs → source-candidate-scan-signature-bJFr7L8T.cjs} +2 -2
  26. package/dist/{style-options-PCgz2ywM.cjs → style-options-DW30H5PV.cjs} +1 -1
  27. package/dist/{tailwindcss-jKzY37Sk.cjs → tailwindcss-CexDJBhx.cjs} +1 -1
  28. package/dist/{tailwindcss-BSEdWieh.js → tailwindcss-ChnpCv25.js} +3 -1
  29. package/dist/{component-local-style-CNhEhd2B.cjs → transform-BQjg2T2T.cjs} +201 -27
  30. package/dist/{component-local-style-C2wC8o9F.js → transform-Cp4KybBy.js} +207 -16
  31. package/dist/types/user-defined-options/important.d.ts +2 -0
  32. package/dist/uni-app-x/component-local-style.d.ts +6 -4
  33. package/dist/uni-app-x/local-style-matcher.d.ts +4 -0
  34. package/dist/uni-app-x/options.d.ts +2 -0
  35. package/dist/uni-app-x/style-asset/harmony-global.d.ts +2 -0
  36. package/dist/uni-app-x/transform.d.ts +2 -0
  37. package/dist/uni-app-x/vite/plugin-options.d.ts +1 -0
  38. package/dist/{v4-generation-core-BfeXEc6R.cjs → v4-generation-core-8YMXikPd.cjs} +42 -13
  39. package/dist/{vite-Dy6THt54.cjs → vite-CeyMHgzQ.cjs} +68 -15
  40. package/dist/{vite-CVr0vIgh.js → vite-kY-WXrd6.js} +121 -68
  41. package/dist/vite.cjs +1 -1
  42. package/dist/vite.js +1 -1
  43. package/dist/weapp-tw-css-import-rewrite-loader.cjs +4 -4
  44. package/dist/{webpack-DwtdWqwr.js → webpack-BN2kLWW_.js} +4 -4
  45. package/dist/{webpack-Cf5RnhXt.cjs → webpack-Bfj63Wt1.cjs} +8 -8
  46. package/dist/webpack.cjs +1 -1
  47. package/dist/webpack.js +1 -1
  48. package/package.json +3 -3
  49. package/dist/transform-CgohToUV.cjs +0 -200
  50. package/dist/transform-DSRPiBWz.js +0 -201
@@ -4,11 +4,11 @@ Object.defineProperties(exports, {
4
4
  });
5
5
  const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
6
6
  const require_generator = require("./generator-DKiYbTFR.cjs");
7
- const require_options = require("./options-CKZW99r4.cjs");
8
- const require_v4_generation_core = require("./v4-generation-core-BfeXEc6R.cjs");
9
- const require_style_options = require("./style-options-PCgz2ywM.cjs");
7
+ const require_options = require("./options-BJrtIQbH.cjs");
8
+ const require_v4_generation_core = require("./v4-generation-core-8YMXikPd.cjs");
9
+ const require_style_options = require("./style-options-DW30H5PV.cjs");
10
10
  const require_css_imports = require("./css-imports-BFMU7Hpd.cjs");
11
- const require_pipeline_helpers = require("./pipeline-helpers-t95KPu4O.cjs");
11
+ const require_pipeline_helpers = require("./pipeline-helpers-Cda0Ox3K.cjs");
12
12
  const require_runtime_registry = require("./runtime-registry-BlIjpImP.cjs");
13
13
  const require_watch_dependencies = require("./watch-dependencies-DLZDrWdH.cjs");
14
14
  let node_path = require("node:path");
@@ -1,12 +1,12 @@
1
1
  import { $ as hasTailwindSourceDirectives, B as stripMiniProgramCssSpecificityPlaceholders, D as resolveTailwindcssOptions, F as stripUnmatchedTailwindSourceMediaCloseFragments, I as finalizeMiniProgramCss, M as removeMiniProgramInteractiveSelectors, N as removeTailwindV4GeneratorAtRules, Ot as resolveSourceScanPath, P as stripTailwindSourceMediaFragments, Pt as getTailwindV4IncrementalGenerateCacheStats, Q as hasTailwindRootDirectives, R as pruneMiniProgramGeneratedCss, V as removeTailwindV4GeneratedUserCssArtifacts, X as hasTailwindApplyDirective, _ as upsertTailwindV4CssSource, et as normalizeTailwindConfigDirectives, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, it as removeTailwindSourceDirectives, j as isCommentOnlyCss, lt as hasTailwindGeneratedCss, o as resolveRuntimeBranch, rt as parseImportRequest, ut as hasTailwindGeneratedCssMarkers } from "./generator-EnTXLBlK.js";
2
2
  import { n as _defineProperty } from "./object-B-8IHefx.js";
3
- import { f as resolveSourceScanEntries, g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature } from "./tailwindcss-BSEdWieh.js";
3
+ import { f as resolveSourceScanEntries, g as resolveTailwindV4EntriesFromCssCached, l as getRuntimeClassSetSignature } from "./tailwindcss-ChnpCv25.js";
4
4
  import { r as getGroupedEntries } from "./utils-MVwpU07P.js";
5
- import { $ as getCompilationScopeDependencyRevision, A as annotateCssSourceTrace, C as stripRequestQuery, D as stripBundlerGeneratedCssMarkers, F as createRuntimeClassSetManager, H as buildRuntimeCompilationSnapshot, I as collectStrictEscapedRuntimeCandidates, J as createRuntimeAffectingSourceSignature, K as resetRuntimeCompilationBuildState, L as createEscapeFragments, M as createCssTokenSourceMap, N as isCssSourceTraceEnabled, O as finalizeMiniProgramCssStructure, P as processCachedTask, Q as AssetEmissionPlan, R as isPureLocalCssImportWrapper, S as isSourceStyleRequest, T as hasBundlerGeneratedCssMarker, U as createRuntimeCompilationAffectingSignature, V as finalizeCompilerShadowRun, W as createRuntimeCompilationBuildState, X as beginCompilerShadowRun, Y as disposeCompilerOwner, _ as captureResolvedFrameworkPostcssOptions, at as isSourceCandidateRequest, c as collectRawSourceClassSelectors, ct as resolveSourceCandidateScanFiles, h as removeGeneratedSelectorCompatCss, it as createSourceCandidateStore, j as createCssSourceTraceCacheSignature, l as pushConcurrentTaskFactories, m as scoreTailwindV4CssSourceFileMatch, n as emitHmrTiming, nt as createCompilationDependencyChanges, q as updateRuntimeCompilationBuildState, r as generateTailwindV4Css, tt as recordCompilationDependencyChanges, u as resolveTaskConcurrency, v as collectFrameworkPostcssOptionsFromLoaderEntries, x as hasMiniProgramTailwindV4PreflightReset, y as createCssSourceOrderAppend } from "./hmr-timing-HGlM4hX3.js";
5
+ import { $ as getCompilationScopeDependencyRevision, A as annotateCssSourceTrace, C as stripRequestQuery, D as stripBundlerGeneratedCssMarkers, F as createRuntimeClassSetManager, H as buildRuntimeCompilationSnapshot, I as collectStrictEscapedRuntimeCandidates, J as createRuntimeAffectingSourceSignature, K as resetRuntimeCompilationBuildState, L as createEscapeFragments, M as createCssTokenSourceMap, N as isCssSourceTraceEnabled, O as finalizeMiniProgramCssStructure, P as processCachedTask, Q as AssetEmissionPlan, R as isPureLocalCssImportWrapper, S as isSourceStyleRequest, T as hasBundlerGeneratedCssMarker, U as createRuntimeCompilationAffectingSignature, V as finalizeCompilerShadowRun, W as createRuntimeCompilationBuildState, X as beginCompilerShadowRun, Y as disposeCompilerOwner, _ as captureResolvedFrameworkPostcssOptions, at as isSourceCandidateRequest, c as collectRawSourceClassSelectors, ct as resolveSourceCandidateScanFiles, h as removeGeneratedSelectorCompatCss, it as createSourceCandidateStore, j as createCssSourceTraceCacheSignature, l as pushConcurrentTaskFactories, m as scoreTailwindV4CssSourceFileMatch, n as emitHmrTiming, nt as createCompilationDependencyChanges, q as updateRuntimeCompilationBuildState, r as generateTailwindV4Css, tt as recordCompilationDependencyChanges, u as resolveTaskConcurrency, v as collectFrameworkPostcssOptionsFromLoaderEntries, x as hasMiniProgramTailwindV4PreflightReset, y as createCssSourceOrderAppend } from "./hmr-timing-CTpjCpQh.js";
6
6
  import { _ as md5Hash, m as createDebug } from "./wxml-B7OAVpXJ.js";
7
- import { d as refreshTailwindRuntimeState, i as pluginName, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, r as resolveStyleOptionsFromContext, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-Kvr3lLEC.js";
7
+ import { d as refreshTailwindRuntimeState, i as pluginName, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, r as resolveStyleOptionsFromContext, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-4ittVpgt.js";
8
8
  import { getDefaultCssPreflight } from "./defaults.js";
9
- import { S as resolveWebpackFrameworkProfile, a as createCandidateSignature, b as webpackStyleInjectorDelegates, d as classifyRuntimeEntry, f as resolvePackageDir, g as toAbsoluteOutputPath, h as resolveOutputSpecifier, p as resolvePluginDisabledState, r as createScopedGeneratorRuntime, t as createSourceCandidateScanSignature, v as createBuiltinWebpackStyleInjectorPlugin } from "./source-candidate-scan-signature-BHCPQVoD.js";
9
+ import { S as resolveWebpackFrameworkProfile, a as createCandidateSignature, b as webpackStyleInjectorDelegates, d as classifyRuntimeEntry, f as resolvePackageDir, g as toAbsoluteOutputPath, h as resolveOutputSpecifier, p as resolvePluginDisabledState, r as createScopedGeneratorRuntime, t as createSourceCandidateScanSignature, v as createBuiltinWebpackStyleInjectorPlugin } from "./source-candidate-scan-signature--r31NK5J.js";
10
10
  import Module, { createRequire } from "node:module";
11
11
  import fs from "node:fs";
12
12
  import path from "node:path";
@@ -1,16 +1,16 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
2
2
  const require_generator = require("./generator-DKiYbTFR.cjs");
3
3
  const require_object = require("./object-DbHtAXRk.cjs");
4
- const require_options = require("./options-CKZW99r4.cjs");
4
+ const require_options = require("./options-BJrtIQbH.cjs");
5
5
  const require_utils = require("./utils-CuKLf1Zv.cjs");
6
- const require_v4_generation_core = require("./v4-generation-core-BfeXEc6R.cjs");
6
+ const require_v4_generation_core = require("./v4-generation-core-8YMXikPd.cjs");
7
7
  const require_wxml = require("./wxml-CQmBCjOR.cjs");
8
- const require_hmr_timing = require("./hmr-timing-W3kro20F.cjs");
9
- const require_context = require("./context-CB4Ef9U0.cjs");
10
- const require_tailwindcss = require("./tailwindcss-jKzY37Sk.cjs");
11
- const require_style_options = require("./style-options-PCgz2ywM.cjs");
12
- const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BSad7bMQ.cjs");
13
- const require_pipeline_helpers = require("./pipeline-helpers-t95KPu4O.cjs");
8
+ const require_hmr_timing = require("./hmr-timing-DyiiYupC.cjs");
9
+ const require_context = require("./context-Ulhcd5lF.cjs");
10
+ const require_tailwindcss = require("./tailwindcss-CexDJBhx.cjs");
11
+ const require_style_options = require("./style-options-DW30H5PV.cjs");
12
+ const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-bJFr7L8T.cjs");
13
+ const require_pipeline_helpers = require("./pipeline-helpers-Cda0Ox3K.cjs");
14
14
  const require_css_loader_runtime = require("./css-loader-runtime-CSv0lKqV.cjs");
15
15
  const require_runtime_registry = require("./runtime-registry-BlIjpImP.cjs");
16
16
  let node_fs = require("node:fs");
package/dist/webpack.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_webpack = require("./webpack-Cf5RnhXt.cjs");
2
+ const require_webpack = require("./webpack-Bfj63Wt1.cjs");
3
3
  exports.WeappTailwindcss = require_webpack.WeappTailwindcss;
4
4
  exports.weappTailwindcss = require_webpack.WeappTailwindcss;
5
5
  exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
package/dist/webpack.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as weappTailwindcssPackageDir, t as WeappTailwindcss } from "./webpack-DwtdWqwr.js";
1
+ import { n as weappTailwindcssPackageDir, t as WeappTailwindcss } from "./webpack-BN2kLWW_.js";
2
2
  export { WeappTailwindcss, WeappTailwindcss as weappTailwindcss, weappTailwindcssPackageDir };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
3
  "type": "module",
4
- "version": "5.3.2",
4
+ "version": "5.3.3",
5
5
  "description": "Bring Tailwind CSS to every platform! 把 Tailwind CSS 的原子化开发体验带到全端!",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -212,10 +212,10 @@
212
212
  "semver": "~7.8.5",
213
213
  "yaml": "^2.9.0",
214
214
  "@weapp-tailwindcss/logger": "2.0.2",
215
- "@weapp-tailwindcss/postcss": "3.2.11",
216
215
  "tailwindcss-config": "2.0.3",
217
- "weapp-style-injector": "1.0.3",
218
216
  "@weapp-tailwindcss/shared": "2.0.2",
217
+ "@weapp-tailwindcss/postcss": "3.2.11",
218
+ "weapp-style-injector": "1.0.3",
219
219
  "@weapp-tailwindcss/reset": "0.1.3"
220
220
  },
221
221
  "devDependencies": {
@@ -1,200 +0,0 @@
1
- const require_wxml = require("./wxml-CQmBCjOR.cjs");
2
- const require_component_local_style = require("./component-local-style-CNhEhd2B.cjs");
3
- let _vue_compiler_dom = require("@vue/compiler-dom");
4
- //#region src/uni-app-x/transform.ts
5
- function traverse(node, visitor) {
6
- visitor(node);
7
- if (Array.isArray(node.children)) {
8
- for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
9
- }
10
- }
11
- function updateStaticAttribute(ms, prop, offset, content = prop.value?.content) {
12
- if (!prop.value) return;
13
- const start = offset + prop.value.loc.start.offset + 1;
14
- const end = offset + prop.value.loc.end.offset - 1;
15
- if (start < end) ms.update(start, end, require_wxml.replaceWxml(content ?? ""));
16
- }
17
- function updateStaticAttributeWithLocalStyle(ms, prop, offset, collector, deep, content = prop.value?.content) {
18
- if (!prop.value) return;
19
- const start = offset + prop.value.loc.start.offset + 1;
20
- const end = offset + prop.value.loc.end.offset - 1;
21
- if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? "", { deep }));
22
- }
23
- function updateDirectiveExpression(ms, prop, offset, jsHandler, runtimeSet) {
24
- if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
25
- const expression = prop.exp.content;
26
- const start = offset + prop.exp.loc.start.offset;
27
- const end = offset + prop.exp.loc.end.offset;
28
- if (start >= end) return;
29
- const generated = require_wxml.generateCode(expression, {
30
- jsHandler,
31
- runtimeSet,
32
- wrapExpression: true
33
- });
34
- ms.update(start, end, generated);
35
- }
36
- function updateDirectiveExpressionWithLocalStyle(ms, prop, offset, jsHandler, collector, deep, runtimeSet) {
37
- if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
38
- const expression = prop.exp.content;
39
- const start = offset + prop.exp.loc.start.offset;
40
- const end = offset + prop.exp.loc.end.offset;
41
- if (start >= end) return;
42
- collector.collectRuntimeClasses(expression, {
43
- deep,
44
- wrapExpression: true
45
- });
46
- const generated = require_wxml.generateCode(expression, {
47
- jsHandler,
48
- runtimeSet,
49
- wrapExpression: true
50
- });
51
- ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
52
- }
53
- function shouldEnableLocalStyle(id, options) {
54
- if (options.enableComponentLocalStyle && require_component_local_style.shouldEnableComponentLocalStyle(id)) return true;
55
- if (options.enablePageLocalStyle && require_component_local_style.shouldEnablePageLocalStyle(id)) return true;
56
- return false;
57
- }
58
- function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
59
- const lowerName = attrName.toLowerCase();
60
- const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
61
- const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
62
- return {
63
- shouldHandleDefault,
64
- shouldHandleCustom,
65
- shouldHandle: shouldHandleDefault || shouldHandleCustom
66
- };
67
- }
68
- const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
69
- const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
70
- const SFC_BLOCK_RE = /<(template|script|style)\b([^>]*)>/gi;
71
- const SCRIPT_SETUP_RE = /(?:^|\s)setup(?:\s|=|$)/;
72
- const STYLE_SCOPED_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
73
- function findSfcBlockEnd(code, type, contentStart) {
74
- const closeTag = new RegExp(`<\\/${type}\\s*>`, "gi");
75
- if (type !== "template") {
76
- const match = closeTag.exec(code.slice(contentStart));
77
- return match ? {
78
- blockEnd: contentStart + match.index + match[0].length,
79
- contentEnd: contentStart + match.index
80
- } : void 0;
81
- }
82
- const tag = new RegExp(`<\\/?${type}\\b[^>]*>`, "gi");
83
- tag.lastIndex = contentStart;
84
- let depth = 1;
85
- let match = tag.exec(code);
86
- while (match) {
87
- if (match[0].startsWith("</")) depth -= 1;
88
- else if (!match[0].trimEnd().endsWith("/>")) depth += 1;
89
- if (depth === 0) return {
90
- blockEnd: tag.lastIndex,
91
- contentEnd: match.index
92
- };
93
- match = tag.exec(code);
94
- }
95
- }
96
- function parseSfc(code) {
97
- const descriptor = {
98
- errors: [],
99
- styles: []
100
- };
101
- for (const match of code.matchAll(SFC_BLOCK_RE)) {
102
- const type = match[1];
103
- const attrs = match[2] ?? "";
104
- const contentStart = (match.index ?? 0) + match[0].length;
105
- const blockBoundary = findSfcBlockEnd(code, type, contentStart);
106
- if (!blockBoundary) {
107
- descriptor.errors.push(/* @__PURE__ */ new Error(`未闭合的 ${type} SFC 块`));
108
- continue;
109
- }
110
- const { contentEnd } = blockBoundary;
111
- const content = code.slice(contentStart, contentEnd);
112
- const block = {
113
- content,
114
- start: contentStart,
115
- end: contentEnd,
116
- attrs
117
- };
118
- if (type === "template" && !descriptor.template) {
119
- try {
120
- descriptor.template = {
121
- ...block,
122
- ast: (0, _vue_compiler_dom.parse)(content)
123
- };
124
- } catch (error) {
125
- descriptor.errors.push(error);
126
- descriptor.template = block;
127
- }
128
- continue;
129
- }
130
- if (type === "script") {
131
- if (SCRIPT_SETUP_RE.test(attrs)) descriptor.scriptSetup ?? (descriptor.scriptSetup = block);
132
- else descriptor.script ?? (descriptor.script = block);
133
- continue;
134
- }
135
- if (type === "style") descriptor.styles.push(block);
136
- }
137
- return descriptor;
138
- }
139
- function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
140
- if (!UVUE_NVUE_RE.test(id)) return;
141
- const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
142
- const matchCustomAttribute = require_wxml.createAttributeMatcher(customAttributesEntities);
143
- const ms = new require_wxml.MagicString(code);
144
- const descriptor = parseSfc(code);
145
- const localStyleCollector = shouldEnableLocalStyle(id, options) ? new require_component_local_style.UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
146
- if (descriptor.errors.length === 0) {
147
- if (descriptor.template?.ast) {
148
- const templateOffset = descriptor.template.start;
149
- traverse(descriptor.template.ast, (node) => {
150
- if (node.type !== _vue_compiler_dom.NodeTypes.ELEMENT) return;
151
- const tag = node.tag;
152
- for (const prop of node.props) if (prop.type === _vue_compiler_dom.NodeTypes.ATTRIBUTE) {
153
- const { shouldHandle, shouldHandleCustom, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
154
- if (!shouldHandle) continue;
155
- if (localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, templateOffset, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom);
156
- else updateStaticAttribute(ms, prop, templateOffset);
157
- if (shouldHandleDefault) continue;
158
- } else if (prop.type === _vue_compiler_dom.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
159
- const attrName = prop.arg.content;
160
- const { shouldHandle, shouldHandleCustom } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
161
- if (!shouldHandle) continue;
162
- if (localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, templateOffset, jsHandler, localStyleCollector, options.webCustomAttributeDeep === true && shouldHandleCustom, runtimeSet);
163
- else updateDirectiveExpression(ms, prop, templateOffset, jsHandler, runtimeSet);
164
- }
165
- });
166
- }
167
- if (descriptor.script) {
168
- localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
169
- const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
170
- ms.update(descriptor.script.start, descriptor.script.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
171
- }
172
- if (descriptor.scriptSetup) {
173
- localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
174
- const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
175
- ms.update(descriptor.scriptSetup.start, descriptor.scriptSetup.end, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
176
- }
177
- if (localStyleCollector?.hasStyles()) {
178
- const scopedStyle = descriptor.styles.findLast((style) => STYLE_SCOPED_RE.test(style.attrs));
179
- if (scopedStyle && options.onWebLocalStyleRules) options.onWebLocalStyleRules(localStyleCollector.toStyleRules());
180
- else if (scopedStyle) {
181
- const separator = scopedStyle.content.endsWith("\n") ? "" : "\n";
182
- ms.appendLeft(scopedStyle.end, `${separator}${localStyleCollector.toStyleRules()}`);
183
- } else ms.append(`\n${localStyleCollector.toStyleBlock()}`);
184
- }
185
- }
186
- const result = {
187
- code: ms.toString(),
188
- map: null
189
- };
190
- Object.defineProperty(result, "map", {
191
- configurable: true,
192
- enumerable: true,
193
- get() {
194
- return ms.generateMap();
195
- }
196
- });
197
- return result;
198
- }
199
- //#endregion
200
- exports.transformUVue = transformUVue;
@@ -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 };