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.
Files changed (46) hide show
  1. package/README.en.md +9 -0
  2. package/README.md +5 -133
  3. package/dist/{auto-dPpsm6FB.js → auto-BZ4n4Icc.js} +1 -1
  4. package/dist/{bundle-state-DY3eq4Gz.mjs → bundle-state-C-p9eFz1.mjs} +1 -1
  5. package/dist/{bundle-state-Bvj01pW7.js → bundle-state-D3RZHkXz.js} +2 -2
  6. package/dist/{chunk-C5U5_Hdc.js → chunk-D6vf50IK.js} +0 -14
  7. package/dist/cli.js +4 -4
  8. package/dist/cli.mjs +4 -4
  9. package/dist/core.js +1 -1
  10. package/dist/core.mjs +1 -1
  11. package/dist/css-macro.js +3 -3
  12. package/dist/{defaults-zKUH2mDe.js → defaults-C5w9OOrj.js} +1 -1
  13. package/dist/defaults.js +1 -1
  14. package/dist/{generator-Bd1LntD3.js → generator-DaPOkJ7W.js} +2 -2
  15. package/dist/generator.js +2 -2
  16. package/dist/gulp.js +6 -6
  17. package/dist/gulp.mjs +2 -2
  18. package/dist/{incremental-runtime-class-set-Bl18sFqt.js → incremental-runtime-class-set-BYV0yQdp.js} +5 -4
  19. package/dist/{incremental-runtime-class-set-CAEuUesH.mjs → incremental-runtime-class-set-Dt-FUQB5.mjs} +2 -1
  20. package/dist/index.js +4 -4
  21. package/dist/index.mjs +2 -2
  22. package/dist/{postcss-DfnqZ4Bm.js → postcss-Du8hY-MN.js} +3 -3
  23. package/dist/postcss-html-transform.js +1 -1
  24. package/dist/postcss.js +1 -1
  25. package/dist/{precheck-Bj5ReSOU.js → precheck-DgpVCvYk.js} +9 -34
  26. package/dist/{precheck-CUr1DYyy.mjs → precheck-lfenbOTF.mjs} +9 -34
  27. package/dist/presets.js +4 -4
  28. package/dist/reset.js +1 -1
  29. package/dist/{source-candidates-DQxvGPSw.js → source-candidates-B4NvId_j.js} +2 -2
  30. package/dist/{tailwindcss-jvoYizzX.js → tailwindcss-26ZFr5kv.js} +3 -3
  31. package/dist/transform-Crn84vTL.js +257 -0
  32. package/dist/transform-FAxHXVZp.mjs +255 -0
  33. package/dist/{utils-D7Ygohep.js → utils-nta4tfFs.js} +1 -1
  34. package/dist/{v3-engine-CmIF_gsq.js → v3-engine-CBahpuIg.js} +2 -2
  35. package/dist/vite-DS4H5d0f.mjs +2616 -0
  36. package/dist/vite-tjYalmVX.js +2629 -0
  37. package/dist/vite.js +1 -1
  38. package/dist/vite.mjs +1 -1
  39. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -0
  40. package/dist/{webpack-vk2uqSnK.js → webpack-0BwLOE_f.js} +8 -9
  41. package/dist/{webpack-CChDqRrl.mjs → webpack-CA-40WU9.mjs} +4 -5
  42. package/dist/webpack.js +1 -1
  43. package/dist/webpack.mjs +1 -1
  44. package/package.json +5 -5
  45. package/dist/vite-D1ZdgbWa.js +0 -24750
  46. package/dist/vite-jBTi5CwO.mjs +0 -24736
@@ -2,14 +2,13 @@ import { G as createTailwindV4Engine$1, c as getRuntimeClassSetCacheEntry, ct as
2
2
  import { a as resolveDefaultCssPreflight, i as getDefaultOptions, o as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, s as HARD_PARSE_CACHE_MAX_ENTRIES } from "./defaults-8xrgzxFY.mjs";
3
3
  import { i as isMap, n as defuOverrideArray } from "./utils-DsaS975I.mjs";
4
4
  import { i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssPatcherFromContext } from "./tailwindcss-D5RogwtV.mjs";
5
- import { createRequire } from "node:module";
6
5
  import { splitCandidateTokens } from "tailwindcss-patch";
7
6
  import process from "node:process";
8
7
  import path from "node:path";
9
8
  import { logger, pc } from "@weapp-tailwindcss/logger";
10
9
  import { rm } from "node:fs/promises";
11
10
  import { createStyleHandler } from "@weapp-tailwindcss/postcss";
12
- import { Buffer as Buffer$1 } from "node:buffer";
11
+ import { Buffer } from "node:buffer";
13
12
  import { LRUCache } from "lru-cache";
14
13
  import { md5 as md5Hash } from "@weapp-tailwindcss/shared/node";
15
14
  import { MappingChars2String, escape } from "@weapp-core/escape";
@@ -18,11 +17,6 @@ import { parse, parseExpression } from "@babel/parser";
18
17
  import MagicString from "magic-string";
19
18
  import { jsStringEscape } from "@ast-core/escape";
20
19
  import * as t from "@babel/types";
21
- //#region \0rolldown/runtime.js
22
- var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
23
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
24
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
25
- //#endregion
26
20
  //#region src/cache/index.ts
27
21
  function isProcessResult(value) {
28
22
  return typeof value === "object" && value !== null && "result" in value;
@@ -484,13 +478,13 @@ function normalizeOptionsValue(rawValue, stack = /* @__PURE__ */ new WeakSet())
484
478
  source: rawValue.source,
485
479
  flags: rawValue.flags
486
480
  };
487
- if (typeof Buffer$1 !== "undefined" && Buffer$1.isBuffer(rawValue)) return encodeTaggedValue("Buffer", rawValue.toString("base64"));
481
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(rawValue)) return encodeTaggedValue("Buffer", rawValue.toString("base64"));
488
482
  if (ArrayBuffer.isView(rawValue)) {
489
483
  const view = rawValue;
490
- const buffer = Buffer$1.from(view.buffer, view.byteOffset, view.byteLength);
484
+ const buffer = Buffer.from(view.buffer, view.byteOffset, view.byteLength);
491
485
  return encodeTaggedValue(view.constructor?.name ?? "ArrayBufferView", buffer.toString("base64"));
492
486
  }
493
- if (rawValue instanceof ArrayBuffer) return encodeTaggedValue("ArrayBuffer", Buffer$1.from(rawValue).toString("base64"));
487
+ if (rawValue instanceof ArrayBuffer) return encodeTaggedValue("ArrayBuffer", Buffer.from(rawValue).toString("base64"));
494
488
  if (rawValue instanceof Set) return withCircularGuard(rawValue, stack, () => {
495
489
  const normalizedEntries = Array.from(rawValue, (element) => createComparableNormalizedValue(element, stack));
496
490
  normalizedEntries.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
@@ -1229,7 +1223,7 @@ function walkEvalExpression(path, options, updater, handler) {
1229
1223
  }
1230
1224
  }
1231
1225
  //#endregion
1232
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
1226
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/typeof.js
1233
1227
  function _typeof(o) {
1234
1228
  "@babel/helpers - typeof";
1235
1229
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -1238,9 +1232,8 @@ function _typeof(o) {
1238
1232
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1239
1233
  }, _typeof(o);
1240
1234
  }
1241
- var init_typeof = __esmMin((() => {}));
1242
1235
  //#endregion
1243
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
1236
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPrimitive.js
1244
1237
  function toPrimitive(t, r) {
1245
1238
  if ("object" != _typeof(t) || !t) return t;
1246
1239
  var e = t[Symbol.toPrimitive];
@@ -1251,21 +1244,14 @@ function toPrimitive(t, r) {
1251
1244
  }
1252
1245
  return ("string" === r ? String : Number)(t);
1253
1246
  }
1254
- var init_toPrimitive = __esmMin((() => {
1255
- init_typeof();
1256
- }));
1257
1247
  //#endregion
1258
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
1248
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/toPropertyKey.js
1259
1249
  function toPropertyKey(t) {
1260
1250
  var i = toPrimitive(t, "string");
1261
1251
  return "symbol" == _typeof(i) ? i : i + "";
1262
1252
  }
1263
- var init_toPropertyKey = __esmMin((() => {
1264
- init_typeof();
1265
- init_toPrimitive();
1266
- }));
1267
1253
  //#endregion
1268
- //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
1254
+ //#region \0@oxc-project+runtime@0.134.0/helpers/esm/defineProperty.js
1269
1255
  function _defineProperty(e, r, t) {
1270
1256
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1271
1257
  value: t,
@@ -1274,12 +1260,8 @@ function _defineProperty(e, r, t) {
1274
1260
  writable: !0
1275
1261
  }) : e[r] = t, e;
1276
1262
  }
1277
- var init_defineProperty = __esmMin((() => {
1278
- init_toPropertyKey();
1279
- }));
1280
1263
  //#endregion
1281
1264
  //#region src/js/JsTokenUpdater.ts
1282
- init_defineProperty();
1283
1265
  /**
1284
1266
  * Lightweight helper that batches updates to {@link MagicString}.
1285
1267
  * It keeps the transformation logic out of the traversal code and makes
@@ -1318,7 +1300,6 @@ var JsTokenUpdater = class {
1318
1300
  };
1319
1301
  //#endregion
1320
1302
  //#region src/js/module-graph/ignored-exports.ts
1321
- init_defineProperty();
1322
1303
  var IgnoredExportsTracker = class {
1323
1304
  constructor(options) {
1324
1305
  this.options = options;
@@ -1439,7 +1420,6 @@ var IgnoredExportsTracker = class {
1439
1420
  };
1440
1421
  //#endregion
1441
1422
  //#region src/js/ModuleGraph.ts
1442
- init_defineProperty();
1443
1423
  var JsModuleGraph = class {
1444
1424
  constructor(entry, graphOptions) {
1445
1425
  _defineProperty(this, "modules", /* @__PURE__ */ new Map());
@@ -1614,7 +1594,6 @@ function maybeAddImportToken(imports, arg) {
1614
1594
  }
1615
1595
  //#endregion
1616
1596
  //#region src/js/NodePathWalker.ts
1617
- init_defineProperty();
1618
1597
  const EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS = [];
1619
1598
  const EMPTY_IMPORT_TOKENS = /* @__PURE__ */ new Set();
1620
1599
  function NOOP_STRING_PATH_CALLBACK() {}
@@ -2333,7 +2312,6 @@ var BinTrieFlags;
2333
2312
  })(BinTrieFlags || (BinTrieFlags = {}));
2334
2313
  //#endregion
2335
2314
  //#region ../../node_modules/.pnpm/entities@8.0.0/node_modules/entities/dist/decode.js
2336
- init_defineProperty();
2337
2315
  var CharCodes$1;
2338
2316
  (function(CharCodes) {
2339
2317
  CharCodes[CharCodes["NUM"] = 35] = "NUM";
@@ -2704,7 +2682,6 @@ function determineBranch(decodeTree, current, nodeIndex, char) {
2704
2682
  }
2705
2683
  //#endregion
2706
2684
  //#region ../../node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/Tokenizer.js
2707
- init_defineProperty();
2708
2685
  var CharCodes;
2709
2686
  (function(CharCodes) {
2710
2687
  CharCodes[CharCodes["Tab"] = 9] = "Tab";
@@ -3647,7 +3624,6 @@ var Tokenizer$1 = class {
3647
3624
  };
3648
3625
  //#endregion
3649
3626
  //#region ../../node_modules/.pnpm/htmlparser2@12.0.0/node_modules/htmlparser2/dist/Parser.js
3650
- init_defineProperty();
3651
3627
  const { fromCodePoint } = String;
3652
3628
  const formTags = new Set([
3653
3629
  "input",
@@ -4257,7 +4233,6 @@ function isAllWhitespace(value) {
4257
4233
  }
4258
4234
  //#endregion
4259
4235
  //#region src/wxml/Tokenizer.ts
4260
- init_defineProperty();
4261
4236
  var Tokenizer = class {
4262
4237
  constructor() {
4263
4238
  _defineProperty(this, "state", void 0);
@@ -4713,4 +4688,4 @@ function shouldSkipJsTransform(rawSource, options) {
4713
4688
  return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
4714
4689
  }
4715
4690
  //#endregion
4716
- export { __esmMin as C, __commonJSMin as S, toCustomAttributesEntities as _, vitePluginName as a, ensureRuntimeClassSet as b, createAttributeMatcher as c, _defineProperty as d, init_defineProperty as f, traverse as g, babelParse as h, pluginName as i, analyzeSource as l, replaceWxml as m, getCompilerContext as n, Parser as o, isClassContextLiteralPath as p, resolveStyleOptionsFromContext as r, generateCode as s, shouldSkipJsTransform as t, JsTokenUpdater as u, collectRuntimeClassSet as v, __require as w, refreshTailwindRuntimeState as x, createTailwindRuntimeReadyPromise as y };
4691
+ export { collectRuntimeClassSet as _, vitePluginName as a, refreshTailwindRuntimeState as b, createAttributeMatcher as c, _defineProperty as d, isClassContextLiteralPath as f, toCustomAttributesEntities as g, traverse as h, pluginName as i, analyzeSource as l, babelParse as m, getCompilerContext as n, Parser as o, replaceWxml as p, resolveStyleOptionsFromContext as r, generateCode as s, shouldSkipJsTransform as t, JsTokenUpdater as u, createTailwindRuntimeReadyPromise as v, ensureRuntimeClassSet as y };
package/dist/presets.js CHANGED
@@ -1,8 +1,8 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chunk = require("./chunk-C5U5_Hdc.js");
3
- const require_v3_engine = require("./v3-engine-CmIF_gsq.js");
4
- const require_utils = require("./utils-D7Ygohep.js");
5
- const require_tailwindcss = require("./tailwindcss-jvoYizzX.js");
2
+ const require_chunk = require("./chunk-D6vf50IK.js");
3
+ const require_v3_engine = require("./v3-engine-CBahpuIg.js");
4
+ const require_utils = require("./utils-nta4tfFs.js");
5
+ const require_tailwindcss = require("./tailwindcss-26ZFr5kv.js");
6
6
  require("./logger-TlKT3xmR.js");
7
7
  let node_process = require("node:process");
8
8
  node_process = require_chunk.__toESM(node_process);
package/dist/reset.js CHANGED
@@ -2,7 +2,7 @@ Object.defineProperties(exports, {
2
2
  __esModule: { value: true },
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
- const require_chunk = require("./chunk-C5U5_Hdc.js");
5
+ const require_chunk = require("./chunk-D6vf50IK.js");
6
6
  let _weapp_tailwindcss_reset = require("@weapp-tailwindcss/reset");
7
7
  _weapp_tailwindcss_reset = require_chunk.__toESM(_weapp_tailwindcss_reset);
8
8
  Object.defineProperty(exports, "default", {
@@ -1,5 +1,5 @@
1
- const require_chunk = require("./chunk-C5U5_Hdc.js");
2
- const require_v3_engine = require("./v3-engine-CmIF_gsq.js");
1
+ const require_chunk = require("./chunk-D6vf50IK.js");
2
+ const require_v3_engine = require("./v3-engine-CBahpuIg.js");
3
3
  let node_module = require("node:module");
4
4
  let tailwindcss_patch = require("tailwindcss-patch");
5
5
  let node_path = require("node:path");
@@ -1,6 +1,6 @@
1
- const require_chunk = require("./chunk-C5U5_Hdc.js");
2
- const require_v3_engine = require("./v3-engine-CmIF_gsq.js");
3
- require("./utils-D7Ygohep.js");
1
+ const require_chunk = require("./chunk-D6vf50IK.js");
2
+ const require_v3_engine = require("./v3-engine-CBahpuIg.js");
3
+ require("./utils-nta4tfFs.js");
4
4
  let node_fs = require("node:fs");
5
5
  let node_module = require("node:module");
6
6
  let node_process = require("node:process");
@@ -0,0 +1,257 @@
1
+ const require_chunk = require("./chunk-D6vf50IK.js");
2
+ const require_precheck = require("./precheck-DgpVCvYk.js");
3
+ let tailwindcss_patch = require("tailwindcss-patch");
4
+ let magic_string = require("magic-string");
5
+ magic_string = require_chunk.__toESM(magic_string);
6
+ let _vue_compiler_dom = require("@vue/compiler-dom");
7
+ let _vue_compiler_sfc = require("@vue/compiler-sfc");
8
+ //#region src/uni-app-x/component-local-style.ts
9
+ const EXPRESSION_WRAPPER_PREFIX = "(\n";
10
+ const EXPRESSION_WRAPPER_SUFFIX = "\n)";
11
+ const COMPONENT_RE = /(?:^|[/\\])components(?:[/\\].+)?\.(?:uvue|nvue)$/;
12
+ function createStableHash(input) {
13
+ let hash = 2166136261;
14
+ for (let i = 0; i < input.length; i++) {
15
+ hash ^= input.charCodeAt(i);
16
+ hash = Math.imul(hash, 16777619);
17
+ }
18
+ return (hash >>> 0).toString(36);
19
+ }
20
+ function extractLiteralValue(path) {
21
+ if (path.isStringLiteral()) return {
22
+ literal: path.node.value,
23
+ offset: 1
24
+ };
25
+ return {
26
+ literal: typeof path.node.value === "string" ? path.node.value : path.node.value.raw,
27
+ offset: 0
28
+ };
29
+ }
30
+ function createAlias(fileId, utility, index) {
31
+ return `wtu-${createStableHash(`${fileId}:${utility}`)}-${index.toString(36)}`;
32
+ }
33
+ function isRuntimeCandidate(candidate, runtimeSet) {
34
+ if (!runtimeSet || runtimeSet.size === 0) return false;
35
+ return runtimeSet.has(candidate) || runtimeSet.has(require_precheck.replaceWxml(candidate));
36
+ }
37
+ function shouldEnableComponentLocalStyle(id) {
38
+ return COMPONENT_RE.test(id);
39
+ }
40
+ var UniAppXComponentLocalStyleCollector = class {
41
+ constructor(fileId, runtimeSet) {
42
+ this.fileId = fileId;
43
+ this.runtimeSet = runtimeSet;
44
+ require_precheck._defineProperty(this, "aliasByUtility", /* @__PURE__ */ new Map());
45
+ require_precheck._defineProperty(this, "aliasByLookup", /* @__PURE__ */ new Map());
46
+ }
47
+ ensureAlias(utility) {
48
+ const cached = this.aliasByUtility.get(utility);
49
+ if (cached) return cached;
50
+ const alias = createAlias(this.fileId, utility, this.aliasByUtility.size);
51
+ this.aliasByUtility.set(utility, alias);
52
+ this.aliasByLookup.set(utility, alias);
53
+ this.aliasByLookup.set(require_precheck.replaceWxml(utility), alias);
54
+ return alias;
55
+ }
56
+ rewriteLiteral(literal, shouldInclude) {
57
+ const candidates = (0, tailwindcss_patch.splitCandidateTokens)(literal);
58
+ if (candidates.length === 0) return literal;
59
+ let rewritten = literal;
60
+ for (const candidate of candidates) {
61
+ if (!shouldInclude(candidate)) continue;
62
+ rewritten = rewritten.replace(candidate, this.ensureAlias(candidate));
63
+ }
64
+ return rewritten;
65
+ }
66
+ collectAndRewriteStaticClass(literal) {
67
+ return this.rewriteLiteral(literal, (candidate) => isRuntimeCandidate(candidate, this.runtimeSet));
68
+ }
69
+ collectRuntimeClasses(rawSource, options = {}) {
70
+ const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
71
+ try {
72
+ const analysis = require_precheck.analyzeSource(require_precheck.babelParse(wrapped, {
73
+ plugins: ["typescript"],
74
+ sourceType: options.wrapExpression ? "module" : "unambiguous"
75
+ }), {}, void 0, false);
76
+ for (const path of analysis.targetPaths) {
77
+ const { literal } = extractLiteralValue(path);
78
+ const candidates = (0, tailwindcss_patch.splitCandidateTokens)(literal);
79
+ const classContext = options.wrapExpression || require_precheck.isClassContextLiteralPath(path);
80
+ for (const candidate of candidates) {
81
+ if (!candidate || !classContext && !isRuntimeCandidate(candidate, this.runtimeSet)) continue;
82
+ if (isRuntimeCandidate(candidate, this.runtimeSet)) this.ensureAlias(candidate);
83
+ }
84
+ }
85
+ } catch {}
86
+ }
87
+ rewriteTransformedCode(rawSource, options = {}) {
88
+ if (this.aliasByLookup.size === 0) return rawSource;
89
+ const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
90
+ try {
91
+ const analysis = require_precheck.analyzeSource(require_precheck.babelParse(wrapped, {
92
+ plugins: ["typescript"],
93
+ sourceType: options.wrapExpression ? "module" : "unambiguous"
94
+ }), {}, void 0, false);
95
+ if (analysis.targetPaths.length === 0) return rawSource;
96
+ const updater = new require_precheck.JsTokenUpdater();
97
+ for (const path of analysis.targetPaths) {
98
+ const { literal, offset } = extractLiteralValue(path);
99
+ const candidates = (0, tailwindcss_patch.splitCandidateTokens)(literal);
100
+ if (candidates.length === 0) continue;
101
+ let rewritten = literal;
102
+ let mutated = false;
103
+ for (const candidate of candidates) {
104
+ const alias = this.aliasByLookup.get(candidate);
105
+ if (!alias) continue;
106
+ const replaced = rewritten.replace(candidate, alias);
107
+ if (replaced !== rewritten) {
108
+ rewritten = replaced;
109
+ mutated = true;
110
+ }
111
+ }
112
+ if (!mutated || typeof path.node.start !== "number" || typeof path.node.end !== "number") continue;
113
+ updater.addToken({
114
+ start: path.node.start + offset,
115
+ end: path.node.end - offset,
116
+ value: rewritten,
117
+ path
118
+ });
119
+ }
120
+ if (updater.length === 0) return rawSource;
121
+ const ms = new magic_string.default(wrapped);
122
+ updater.updateMagicString(ms);
123
+ if (options.wrapExpression) {
124
+ ms.remove(0, 2);
125
+ ms.remove(wrapped.length - 2, wrapped.length);
126
+ }
127
+ return ms.toString();
128
+ } catch {
129
+ return rawSource;
130
+ }
131
+ }
132
+ hasStyles() {
133
+ return this.aliasByUtility.size > 0;
134
+ }
135
+ toStyleBlock() {
136
+ if (!this.hasStyles()) return "";
137
+ const lines = ["<style scoped>"];
138
+ for (const [utility, alias] of this.aliasByUtility) {
139
+ lines.push(`.${alias} {`);
140
+ lines.push(` @apply ${utility};`);
141
+ lines.push("}");
142
+ }
143
+ lines.push("</style>");
144
+ return `${lines.join("\n")}\n`;
145
+ }
146
+ };
147
+ //#endregion
148
+ //#region src/uni-app-x/transform.ts
149
+ function traverse(node, visitor) {
150
+ visitor(node);
151
+ if (Array.isArray(node.children)) {
152
+ for (const child of node.children) if (child && typeof child === "object" && "type" in child) traverse(child, visitor);
153
+ }
154
+ }
155
+ function updateStaticAttribute(ms, prop, content = prop.value?.content) {
156
+ if (!prop.value) return;
157
+ const start = prop.value.loc.start.offset + 1;
158
+ const end = prop.value.loc.end.offset - 1;
159
+ if (start < end) ms.update(start, end, require_precheck.replaceWxml(content ?? ""));
160
+ }
161
+ function updateStaticAttributeWithLocalStyle(ms, prop, collector, content = prop.value?.content) {
162
+ if (!prop.value) return;
163
+ const start = prop.value.loc.start.offset + 1;
164
+ const end = prop.value.loc.end.offset - 1;
165
+ if (start < end) ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? ""));
166
+ }
167
+ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
168
+ if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
169
+ const expression = prop.exp.content;
170
+ const start = prop.exp.loc.start.offset;
171
+ const end = prop.exp.loc.end.offset;
172
+ if (start >= end) return;
173
+ const generated = require_precheck.generateCode(expression, {
174
+ jsHandler,
175
+ runtimeSet,
176
+ wrapExpression: true
177
+ });
178
+ ms.update(start, end, generated);
179
+ }
180
+ function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet) {
181
+ if (prop.exp?.type !== _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION) return;
182
+ const expression = prop.exp.content;
183
+ const start = prop.exp.loc.start.offset;
184
+ const end = prop.exp.loc.end.offset;
185
+ if (start >= end) return;
186
+ collector.collectRuntimeClasses(expression, { wrapExpression: true });
187
+ const generated = require_precheck.generateCode(expression, {
188
+ jsHandler,
189
+ runtimeSet,
190
+ wrapExpression: true
191
+ });
192
+ ms.update(start, end, collector.rewriteTransformedCode(generated, { wrapExpression: true }));
193
+ }
194
+ function shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute) {
195
+ const lowerName = attrName.toLowerCase();
196
+ const shouldHandleDefault = !disabledDefaultTemplateHandler && lowerName === "class";
197
+ const shouldHandleCustom = matchCustomAttribute?.(tag, attrName) ?? false;
198
+ return {
199
+ shouldHandleDefault,
200
+ shouldHandleCustom,
201
+ shouldHandle: shouldHandleDefault || shouldHandleCustom
202
+ };
203
+ }
204
+ const defaultCreateJsHandlerOptions = { babelParserOptions: { plugins: ["typescript"] } };
205
+ const UVUE_NVUE_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
206
+ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
207
+ if (!UVUE_NVUE_RE.test(id)) return;
208
+ const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
209
+ const matchCustomAttribute = require_precheck.createAttributeMatcher(customAttributesEntities);
210
+ const ms = new magic_string.default(code);
211
+ const { descriptor, errors } = (0, _vue_compiler_sfc.parse)(code);
212
+ const localStyleCollector = options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
213
+ if (errors.length === 0) {
214
+ if (descriptor.template?.ast) traverse(descriptor.template.ast, (node) => {
215
+ if (node.type !== _vue_compiler_dom.NodeTypes.ELEMENT) return;
216
+ const tag = node.tag;
217
+ for (const prop of node.props) if (prop.type === _vue_compiler_dom.NodeTypes.ATTRIBUTE) {
218
+ const { shouldHandle, shouldHandleDefault } = shouldHandleAttribute(tag, prop.name, disabledDefaultTemplateHandler, matchCustomAttribute);
219
+ if (!shouldHandle) continue;
220
+ if (shouldHandleDefault && localStyleCollector) updateStaticAttributeWithLocalStyle(ms, prop, localStyleCollector);
221
+ else updateStaticAttribute(ms, prop);
222
+ if (shouldHandleDefault) continue;
223
+ } else if (prop.type === _vue_compiler_dom.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === _vue_compiler_dom.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic) {
224
+ const attrName = prop.arg.content;
225
+ const { shouldHandle } = shouldHandleAttribute(tag, attrName, disabledDefaultTemplateHandler, matchCustomAttribute);
226
+ if (!shouldHandle) continue;
227
+ if (attrName.toLowerCase() === "class" && localStyleCollector) updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, localStyleCollector, runtimeSet);
228
+ else updateDirectiveExpression(ms, prop, jsHandler, runtimeSet);
229
+ }
230
+ });
231
+ if (descriptor.script) {
232
+ localStyleCollector?.collectRuntimeClasses(descriptor.script.content);
233
+ const { code } = jsHandler(descriptor.script.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
234
+ ms.update(descriptor.script.loc.start.offset, descriptor.script.loc.end.offset, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
235
+ }
236
+ if (descriptor.scriptSetup) {
237
+ localStyleCollector?.collectRuntimeClasses(descriptor.scriptSetup.content);
238
+ const { code } = jsHandler(descriptor.scriptSetup.content, runtimeSet ?? /* @__PURE__ */ new Set(), defaultCreateJsHandlerOptions);
239
+ ms.update(descriptor.scriptSetup.loc.start.offset, descriptor.scriptSetup.loc.end.offset, localStyleCollector ? localStyleCollector.rewriteTransformedCode(code) : code);
240
+ }
241
+ if (localStyleCollector?.hasStyles()) ms.append(`\n${localStyleCollector.toStyleBlock()}`);
242
+ }
243
+ const result = {
244
+ code: ms.toString(),
245
+ map: null
246
+ };
247
+ Object.defineProperty(result, "map", {
248
+ configurable: true,
249
+ enumerable: true,
250
+ get() {
251
+ return ms.generateMap();
252
+ }
253
+ });
254
+ return result;
255
+ }
256
+ //#endregion
257
+ exports.transformUVue = transformUVue;