@vue-jsx-vapor/macros 2.3.0 → 2.3.1

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 (80) hide show
  1. package/dist/api.cjs +6 -13
  2. package/dist/api.d.cts +8 -4
  3. package/dist/api.d.ts +8 -4
  4. package/dist/api.js +3 -14
  5. package/dist/astro.cjs +14 -18
  6. package/dist/astro.d.cts +4 -3
  7. package/dist/astro.d.ts +4 -3
  8. package/dist/astro.js +13 -17
  9. package/dist/chunk-BCwAaXi7.cjs +31 -0
  10. package/dist/core-B1Tt-ieP.cjs +438 -0
  11. package/dist/core-cHgZBgtA.js +377 -0
  12. package/dist/esbuild.cjs +12 -14
  13. package/dist/esbuild.d.cts +6 -5
  14. package/dist/esbuild.d.ts +6 -5
  15. package/dist/esbuild.js +9 -11
  16. package/dist/index.cjs +8 -12
  17. package/dist/index.d.cts +5 -5
  18. package/dist/index.d.ts +5 -5
  19. package/dist/index.js +6 -12
  20. package/dist/nuxt.cjs +23 -26
  21. package/dist/nuxt.d.cts +6 -5
  22. package/dist/nuxt.d.ts +6 -5
  23. package/dist/nuxt.js +19 -23
  24. package/dist/options-CNIhAQHD.cjs +27 -0
  25. package/dist/options-pbSvpKdV.js +20 -0
  26. package/dist/options.cjs +2 -5
  27. package/dist/options.d-B3WOiT_L.d.cts +26 -0
  28. package/dist/options.d-DtyRfe-9.d.ts +26 -0
  29. package/dist/options.d.cts +2 -23
  30. package/dist/options.d.ts +2 -23
  31. package/dist/options.js +3 -6
  32. package/dist/raw-3ZelnSQR.cjs +62 -0
  33. package/dist/raw-9SXDNxBH.js +55 -0
  34. package/dist/raw.cjs +5 -9
  35. package/dist/raw.d.cts +5 -4
  36. package/dist/raw.d.ts +5 -4
  37. package/dist/raw.js +5 -8
  38. package/dist/rolldown.cjs +12 -14
  39. package/dist/rolldown.d.cts +4 -3
  40. package/dist/rolldown.d.ts +4 -3
  41. package/dist/rolldown.js +9 -11
  42. package/dist/rollup.cjs +12 -14
  43. package/dist/rollup.d.cts +6 -5
  44. package/dist/rollup.d.ts +6 -5
  45. package/dist/rollup.js +9 -11
  46. package/dist/rspack.cjs +12 -14
  47. package/dist/rspack.d.cts +4 -3
  48. package/dist/rspack.d.ts +4 -3
  49. package/dist/rspack.js +9 -11
  50. package/dist/src-BfZoaRPY.js +9 -0
  51. package/dist/src-DwQLomPw.cjs +16 -0
  52. package/dist/vite-C5QxH0B9.cjs +13 -0
  53. package/dist/vite-DPLCEtsm.js +7 -0
  54. package/dist/vite.cjs +8 -12
  55. package/dist/vite.d.cts +6 -5
  56. package/dist/vite.d.ts +6 -5
  57. package/dist/vite.js +7 -10
  58. package/dist/volar.cjs +220 -371
  59. package/dist/volar.d.cts +5 -4
  60. package/dist/volar.d.ts +5 -4
  61. package/dist/volar.js +217 -369
  62. package/dist/webpack-1cYmRdvx.js +7 -0
  63. package/dist/webpack-B-EPKx0G.cjs +13 -0
  64. package/dist/webpack.cjs +8 -12
  65. package/dist/webpack.d.cts +6 -5
  66. package/dist/webpack.d.ts +6 -5
  67. package/dist/webpack.js +7 -10
  68. package/package.json +3 -3
  69. package/dist/chunk-53TNKVYD.cjs +0 -29
  70. package/dist/chunk-AUE5EAQA.js +0 -12
  71. package/dist/chunk-DANY2WQD.js +0 -29
  72. package/dist/chunk-E5WGUCGE.js +0 -68
  73. package/dist/chunk-HBVQYNJJ.js +0 -10
  74. package/dist/chunk-KUKYWPEK.cjs +0 -10
  75. package/dist/chunk-L26STXZK.cjs +0 -12
  76. package/dist/chunk-PWA6BBMQ.cjs +0 -10
  77. package/dist/chunk-SMWNQXL7.js +0 -585
  78. package/dist/chunk-UAWFIGPX.cjs +0 -68
  79. package/dist/chunk-ZQ4GVJKX.cjs +0 -585
  80. package/dist/chunk-ZXJQCFZZ.js +0 -10
@@ -1,585 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/helper/use-model.ts?raw
2
- var use_model_default = 'import { customRef, watchSyncEffect } from "vue";\nexport function useModel(props, name, options = {}) {\n const res = customRef((track, trigger) => {\n let localValue = options && options.default;\n let prevEmittedValue;\n watchSyncEffect(() => {\n const propValue = props[name];\n if (!Object.is(prevEmittedValue, propValue)) {\n localValue = propValue;\n trigger();\n }\n });\n return {\n get() {\n track();\n return options.get ? options.get(localValue) : localValue;\n },\n set(value) {\n if (Object.is(value, localValue)) return;\n localValue = value;\n trigger();\n const emittedValue = prevEmittedValue = options.set ? options.set(value) : value;\n for (const emit of [props[`onUpdate:${name}`]].flat()) {\n if (typeof emit === "function") emit(emittedValue);\n }\n }\n };\n });\n res[Symbol.iterator] = () => {\n let i = 0;\n return {\n next() {\n if (i < 2) {\n return {\n value: i++ ? props[`${name}Modifiers`] || {} : res,\n done: false\n };\n } else {\n return { done: true };\n }\n }\n };\n };\n return res;\n}\n';
3
-
4
- // src/core/helper/with-defaults.ts?raw
5
- var with_defaults_default = "function resolveDefaultProps(paths) {\n const result = {};\n for (const path of Object.keys(paths)) {\n const segments = path.split(/[.?[\\]]/).filter(Boolean);\n let current = result;\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n if (i === segments.length - 1) {\n current[segment] = paths[path];\n } else {\n if (!current[segment]) {\n current[segment] = Number.isNaN(Number(segments[i + 1])) ? {} : [];\n }\n current = current[segment];\n }\n }\n }\n return result;\n}\nexport function createPropsDefaultProxy(props, defaults) {\n const defaultProps = resolveDefaultProps(defaults);\n const result = {};\n for (const key of [\n .../* @__PURE__ */ new Set([...Object.keys(props), ...Object.keys(defaultProps)])\n ]) {\n Object.defineProperty(result, key, {\n enumerable: true,\n get: () => props[key] === void 0 ? defaultProps[key] : props[key]\n });\n }\n return result;\n}\n";
6
-
7
- // src/core/helper/index.ts
8
- var helperPrefix = "vue-jsx-vapor/macros";
9
- var useModelHelperId = `${helperPrefix}/use-model`;
10
- var withDefaultsHelperId = `${helperPrefix}/with-defaults`;
11
-
12
- // src/core/restructure.ts
13
-
14
-
15
-
16
- var _common = require('@vue-macros/common');
17
- var _compilersfc = require('@vue/compiler-sfc');
18
- function restructure(s, node, options = {}) {
19
- let index = 0;
20
- const propList = [];
21
- for (const param of node.params) {
22
- const path = `${_common.HELPER_PREFIX}props${index++ || ""}`;
23
- const props = getProps(param, path, s, [], options);
24
- if (props) {
25
- const hasDefaultValue = props.some((i) => i.defaultValue);
26
- s.overwrite(param.start, param.end, path);
27
- propList.push(
28
- ...hasDefaultValue ? props.map((i) => ({
29
- ...i,
30
- path: i.path.replace(_common.HELPER_PREFIX, `${_common.HELPER_PREFIX}default_`)
31
- })) : props
32
- );
33
- }
34
- }
35
- if (propList.length) {
36
- const defaultValues = {};
37
- const rests = [];
38
- for (const prop of propList) {
39
- if (prop.defaultValue) {
40
- const basePath = prop.path.split(/\.|\[/)[0];
41
- (defaultValues[basePath] ??= []).push(prop);
42
- }
43
- if (prop.isRest) {
44
- rests.push(prop);
45
- }
46
- }
47
- for (const [path, values] of Object.entries(defaultValues)) {
48
- const createPropsDefaultProxy = _common.importHelperFn.call(void 0,
49
- s,
50
- 0,
51
- "createPropsDefaultProxy",
52
- void 0,
53
- _nullishCoalesce(options.withDefaultsFrom, () => ( withDefaultsHelperId))
54
- );
55
- const resolvedPath = path.replace(
56
- `${_common.HELPER_PREFIX}default_`,
57
- _common.HELPER_PREFIX
58
- );
59
- const resolvedValues = values.map(
60
- (i) => `'${i.path.replace(path, "")}${i.value}': ${i.defaultValue}`
61
- ).join(", ");
62
- prependFunctionalNode(
63
- node,
64
- s,
65
- `
66
- const ${path} = ${createPropsDefaultProxy}(${resolvedPath}, {${resolvedValues}})`
67
- );
68
- }
69
- for (const [index2, rest] of rests.entries()) {
70
- prependFunctionalNode(
71
- node,
72
- s,
73
- _nullishCoalesce(_optionalChain([options, 'access', _ => _.generateRestProps, 'optionalCall', _2 => _2(rest.name, index2, rests)]), () => ( `
74
- const ${rest.name} = ${_common.importHelperFn.call(void 0,
75
- s,
76
- 0,
77
- "createPropsRestProxy"
78
- )}(${rest.path}, [${rest.value}])`))
79
- );
80
- }
81
- _compilersfc.walkIdentifiers.call(void 0,
82
- node.body,
83
- (id, parent) => {
84
- const prop = propList.find((i) => i.name === id.name);
85
- if (prop && !prop.isRest) {
86
- s.overwrite(
87
- id.start,
88
- id.end,
89
- `${_optionalChain([parent, 'optionalAccess', _3 => _3.type]) === "ObjectProperty" && parent.shorthand ? `${id.name}: ` : ""}${prop.path}${prop.value}`
90
- );
91
- }
92
- },
93
- false
94
- );
95
- }
96
- return propList;
97
- }
98
- function getProps(node, path = "", s, props = [], options) {
99
- const properties = node.type === "ObjectPattern" ? node.properties : node.type === "ArrayPattern" ? node.elements : [];
100
- if (!properties.length) return;
101
- const propNames = [];
102
- properties.forEach((prop, index) => {
103
- if (_optionalChain([prop, 'optionalAccess', _4 => _4.type]) === "Identifier") {
104
- props.push({ name: prop.name, path, value: `[${index}]` });
105
- propNames.push(`'${prop.name}'`);
106
- } else if (_optionalChain([prop, 'optionalAccess', _5 => _5.type]) === "AssignmentPattern" && prop.left.type === "Identifier") {
107
- props.push({
108
- path,
109
- name: prop.left.name,
110
- value: `[${index}]`,
111
- defaultValue: s.slice(prop.right.start, prop.right.end)
112
- });
113
- propNames.push(`'${prop.left.name}'`);
114
- } else if (_optionalChain([prop, 'optionalAccess', _6 => _6.type]) === "ObjectProperty" && prop.key.type === "Identifier") {
115
- if (prop.value.type === "AssignmentPattern" && prop.value.left.type === "Identifier") {
116
- props.push({
117
- path,
118
- name: prop.value.left.name,
119
- value: `.${prop.key.name}`,
120
- defaultValue: s.slice(prop.value.right.start, prop.value.right.end),
121
- isRequired: prop.value.right.type === "TSNonNullExpression"
122
- });
123
- } else if (!getProps(prop.value, `${path}.${prop.key.name}`, s, props, options)) {
124
- props.push({
125
- path,
126
- name: prop.value.type === "Identifier" ? prop.value.name : prop.key.name,
127
- value: `.${prop.key.name}`
128
- });
129
- }
130
- propNames.push(`'${prop.key.name}'`);
131
- } else if (_optionalChain([prop, 'optionalAccess', _7 => _7.type]) === "RestElement" && prop.argument.type === "Identifier" && !prop.argument.name.startsWith(`${_common.HELPER_PREFIX}props`)) {
132
- props.push({
133
- path,
134
- name: prop.argument.name,
135
- value: propNames.join(", "),
136
- isRest: true
137
- });
138
- } else if (prop) {
139
- getProps(prop, `${path}[${index}]`, s, props, options);
140
- }
141
- });
142
- return props.length ? props : void 0;
143
- }
144
- function prependFunctionalNode(node, s, result) {
145
- const isBlockStatement = node.body.type === "BlockStatement";
146
- const start = _optionalChain([node, 'access', _8 => _8.body, 'access', _9 => _9.extra, 'optionalAccess', _10 => _10.parenthesized]) ? node.body.extra.parenStart : node.body.start;
147
- s.appendRight(
148
- start + (isBlockStatement ? 1 : 0),
149
- `${result};${!isBlockStatement ? "return " : ""}`
150
- );
151
- if (!isBlockStatement) {
152
- s.appendLeft(start, "{");
153
- s.appendRight(node.end, "}");
154
- }
155
- }
156
-
157
- // src/core/index.ts
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
- // src/core/define-component/index.ts
168
-
169
-
170
-
171
- // src/core/define-component/await.ts
172
-
173
-
174
-
175
-
176
- var isFunctionType = (node) => {
177
- return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
178
- };
179
- function transformAwait(root, s) {
180
- if (root.body.type !== "BlockStatement") return;
181
- let hasAwait = false;
182
- for (const node of root.body.body) {
183
- if (node.type === "VariableDeclaration" && !node.declare || node.type.endsWith("Statement")) {
184
- const scope = [root.body.body];
185
- _common.walkAST.call(void 0, node, {
186
- enter(child, parent) {
187
- if (isFunctionType(child)) {
188
- this.skip();
189
- }
190
- if (child.type === "BlockStatement") {
191
- scope.push(child.body);
192
- }
193
- if (child.type === "AwaitExpression") {
194
- hasAwait = true;
195
- const currentScope = scope.at(-1);
196
- const needsSemi = !!_optionalChain([currentScope, 'optionalAccess', _11 => _11.some, 'call', _12 => _12((n, i) => {
197
- return (scope.length === 1 || i > 0) && n.type === "ExpressionStatement" && n.start === child.start;
198
- })]);
199
- processAwait(
200
- s,
201
- child,
202
- needsSemi,
203
- parent.type === "ExpressionStatement"
204
- );
205
- }
206
- },
207
- leave(node2) {
208
- if (node2.type === "BlockStatement") scope.pop();
209
- }
210
- });
211
- }
212
- }
213
- if (hasAwait) {
214
- s.prependLeft(root.body.start + 1, `
215
- let __temp, __restore
216
- `);
217
- }
218
- }
219
- function processAwait(s, node, needSemi, isStatement) {
220
- const argumentStart = node.argument.extra && node.argument.extra.parenthesized ? node.argument.extra.parenStart : node.argument.start;
221
- const argumentStr = s.slice(argumentStart, node.argument.end);
222
- const containsNestedAwait = /\bawait\b/.test(argumentStr);
223
- s.overwrite(
224
- node.start,
225
- argumentStart,
226
- `${needSemi ? `;` : ``}(
227
- ([__temp,__restore] = ${_common.importHelperFn.call(void 0,
228
- s,
229
- 0,
230
- `withAsyncContext`
231
- )}(${containsNestedAwait ? `async ` : ``}() => `
232
- );
233
- s.appendLeft(
234
- node.end,
235
- `)),
236
- ${isStatement ? `` : `__temp = `}await __temp,
237
- __restore()${isStatement ? `` : `,
238
- __temp`}
239
- )`
240
- );
241
- }
242
-
243
- // src/core/define-component/return.ts
244
- function transformReturn(root, s) {
245
- const node = root.body.type === "BlockStatement" ? _optionalChain([root, 'access', _13 => _13.body, 'access', _14 => _14.body, 'access', _15 => _15.find, 'call', _16 => _16((node2) => node2.type === "ReturnStatement"), 'optionalAccess', _17 => _17.argument]) : root.body;
246
- if (!node || isFunctionalNode(node)) return;
247
- s.appendRight(
248
- _optionalChain([node, 'access', _18 => _18.extra, 'optionalAccess', _19 => _19.parenthesized]) ? node.extra.parenStart : node.start,
249
- "() => "
250
- );
251
- }
252
-
253
- // src/core/define-component/index.ts
254
- function transformDefineComponent(root, propsName, map, s, autoReturnFunction = false) {
255
- if (!map.defineComponent) return;
256
- const defineComponentName = s.sliceNode(map.defineComponent.callee);
257
- if (defineComponentName && !["defineComponent", "defineVaporComponent"].includes(defineComponentName)) {
258
- _common.importHelperFn.call(void 0, s, 0, "defineComponent", defineComponentName);
259
- }
260
- let hasRestProp = false;
261
- const props = {};
262
- if (root.params[0]) {
263
- if (root.params[0].type === "Identifier") {
264
- getWalkedIds(root, propsName).forEach((id) => props[id] = null);
265
- } else {
266
- const restructuredProps = restructure(s, root, {
267
- generateRestProps: (restPropsName, index, list) => {
268
- if (index === list.length - 1) {
269
- hasRestProp = true;
270
- const useAttrs = _common.importHelperFn.call(void 0, s, 0, "useAttrs");
271
- return `const ${restPropsName} = ${useAttrs}()`;
272
- }
273
- }
274
- });
275
- for (const prop of restructuredProps) {
276
- if (prop.path.endsWith("props") && !prop.isRest) {
277
- props[prop.name] = prop.isRequired ? "{ required: true }" : null;
278
- }
279
- }
280
- }
281
- }
282
- for (const { expression, isRequired } of map.defineModel || []) {
283
- const modelOptions = _optionalChain([expression, 'access', _20 => _20.arguments, 'access', _21 => _21[0], 'optionalAccess', _22 => _22.type]) === "ObjectExpression" ? expression.arguments[0] : _optionalChain([expression, 'access', _23 => _23.arguments, 'access', _24 => _24[1], 'optionalAccess', _25 => _25.type]) === "ObjectExpression" ? expression.arguments[1] : void 0;
284
- const options = {};
285
- if (isRequired) options.required = true;
286
- for (const prop of _optionalChain([modelOptions, 'optionalAccess', _26 => _26.properties]) || []) {
287
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && ["validator", "type", "required"].includes(prop.key.name)) {
288
- options[prop.key.name] = s.sliceNode(prop.value);
289
- }
290
- }
291
- const propName = _optionalChain([expression, 'access', _27 => _27.arguments, 'access', _28 => _28[0], 'optionalAccess', _29 => _29.type]) === "StringLiteral" ? expression.arguments[0].value : "modelValue";
292
- props[propName] = Object.keys(options).length ? `{ ${Object.entries(options).map(([key, value]) => `${key}: ${value}`).join(", ")} }` : null;
293
- props[`onUpdate:${propName}`] = null;
294
- props[`${propName === "modelValue" ? "model" : propName}Modifiers`] = null;
295
- }
296
- const propsString = Object.entries(props).map(([key, value]) => `'${key}': ${value}`).join(", ");
297
- if (propsString) {
298
- const argument = map.defineComponent.arguments[1];
299
- if (!argument) {
300
- s.appendRight(
301
- root.end,
302
- `, {${hasRestProp ? "inheritAttrs: false," : ""} props: { ${propsString} } }`
303
- );
304
- } else if (argument.type === "ObjectExpression") {
305
- prependObjectExpression(argument, "props", `{ ${propsString} }`, s);
306
- if (hasRestProp) {
307
- prependObjectExpression(argument, "inheritAttrs", "false", s);
308
- }
309
- }
310
- }
311
- transformAwait(root, s);
312
- if (autoReturnFunction) {
313
- transformReturn(root, s);
314
- }
315
- }
316
- function prependObjectExpression(argument, name, value, s) {
317
- if (!_optionalChain([argument, 'access', _30 => _30.properties, 'optionalAccess', _31 => _31.find, 'call', _32 => _32(
318
- (prop) => prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === name
319
- )])) {
320
- s.appendRight(argument.start + 1, `${name}: ${value},`);
321
- }
322
- }
323
- function getWalkedIds(root, propsName) {
324
- const walkedIds = /* @__PURE__ */ new Set();
325
- _compilersfc.walkIdentifiers.call(void 0,
326
- root.body,
327
- (id, parent) => {
328
- if (id.name === propsName && (_optionalChain([parent, 'optionalAccess', _33 => _33.type]) === "MemberExpression" || _optionalChain([parent, 'optionalAccess', _34 => _34.type]) === "OptionalMemberExpression")) {
329
- const prop = parent.property.type === "Identifier" ? parent.property.name : parent.property.type === "StringLiteral" ? parent.property.value : "";
330
- if (prop) walkedIds.add(prop);
331
- }
332
- },
333
- false
334
- );
335
- return walkedIds;
336
- }
337
-
338
- // src/core/define-expose.ts
339
-
340
- function transformDefineExpose(node, s, version) {
341
- s.overwriteNode(node.callee, ";");
342
- s.appendRight(
343
- _optionalChain([node, 'access', _35 => _35.arguments, 'access', _36 => _36[0], 'optionalAccess', _37 => _37.start]) || node.end - 1,
344
- version >= 3.6 ? `${_common.importHelperFn.call(void 0, s, 0, "currentInstance")}.exposed = ` : `${_common.importHelperFn.call(void 0, s, 0, "getCurrentInstance")}().exposed = `
345
- );
346
- }
347
-
348
- // src/core/define-model.ts
349
-
350
- function transformDefineModel(node, propsName, s) {
351
- s.overwriteNode(
352
- node.callee,
353
- _common.importHelperFn.call(void 0, s, 0, "useModel", void 0, useModelHelperId)
354
- );
355
- s.appendRight(
356
- _optionalChain([node, 'access', _38 => _38.arguments, 'access', _39 => _39[0], 'optionalAccess', _40 => _40.start]) || node.end - 1,
357
- `${propsName}, ${_optionalChain([node, 'access', _41 => _41.arguments, 'access', _42 => _42[0], 'optionalAccess', _43 => _43.type]) !== "StringLiteral" ? `'modelValue',` : ""}`
358
- );
359
- }
360
-
361
- // src/core/define-slots.ts
362
-
363
- function transformDefineSlots(node, s) {
364
- s.overwrite(
365
- node.start,
366
- _optionalChain([node, 'access', _44 => _44.arguments, 'access', _45 => _45[0], 'optionalAccess', _46 => _46.start]) && node.arguments[0].start - 1 || _optionalChain([node, 'access', _47 => _47.typeArguments, 'optionalAccess', _48 => _48.end]) || node.callee.end,
367
- `Object.assign`
368
- );
369
- const slots = `${_common.importHelperFn.call(void 0, s, 0, "useSlots")}()`;
370
- s.appendLeft(node.end - 1, `${node.arguments[0] ? "," : "{}, "}${slots}`);
371
- }
372
-
373
- // src/core/define-style.ts
374
-
375
- var _hashsum = require('hash-sum'); var _hashsum2 = _interopRequireDefault(_hashsum);
376
- function transformDefineStyle(defineStyle, index, root, s, importMap) {
377
- const { expression, lang, isDeclaration } = defineStyle;
378
- if (_optionalChain([expression, 'access', _49 => _49.arguments, 'access', _50 => _50[0], 'optionalAccess', _51 => _51.type]) !== "TemplateLiteral") return;
379
- let css = s.sliceNode(expression.arguments[0]).slice(1, -1);
380
- const scopeId = _hashsum2.default.call(void 0, css);
381
- const vars = /* @__PURE__ */ new Map();
382
- expression.arguments[0].expressions.forEach((exp) => {
383
- const cssVar = s.sliceNode(exp);
384
- const cssVarId = toCssVarId(cssVar, `--${scopeId}-`);
385
- s.overwrite(exp.start - 2, exp.end + 1, `var(${cssVarId})`);
386
- vars.set(cssVarId, cssVar);
387
- });
388
- let returnExpression = root && getReturnStatement(root);
389
- if (isFunctionalNode(returnExpression)) {
390
- returnExpression = getReturnStatement(returnExpression);
391
- }
392
- if (vars.size && returnExpression) {
393
- const children = returnExpression.type === "JSXElement" ? [returnExpression] : returnExpression.type === "JSXFragment" ? returnExpression.children : [];
394
- const varString = Array.from(vars.entries()).map(([key, value]) => `'${key}': ${value}`).join(", ");
395
- for (const child of children) {
396
- if (child.type === "JSXElement") {
397
- s.appendRight(
398
- child.openingElement.name.end,
399
- ` {...{style:{${varString}}}}`
400
- );
401
- }
402
- }
403
- }
404
- let scoped = !!root;
405
- if (_optionalChain([expression, 'access', _52 => _52.arguments, 'access', _53 => _53[1], 'optionalAccess', _54 => _54.type]) === "ObjectExpression") {
406
- for (const prop of expression.arguments[1].properties) {
407
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "scoped" && prop.value.type === "BooleanLiteral") {
408
- scoped = prop.value.value;
409
- }
410
- }
411
- }
412
- if (scoped && returnExpression) {
413
- _common.walkAST.call(void 0, returnExpression, {
414
- enter(node) {
415
- if (node.type === "JSXElement" && s.sliceNode(node.openingElement.name) !== "template") {
416
- s.appendRight(node.openingElement.name.end, ` data-v-${scopeId}=""`);
417
- }
418
- }
419
- });
420
- }
421
- css = s.sliceNode(expression.arguments[0]).slice(1, -1).replaceAll(/\/\/(.*)(?=\n)/g, "/*$1*/");
422
- const module = isDeclaration ? "module." : "";
423
- const importId = `${helperPrefix}/define-style/${index}?scopeId=${scopeId}&scoped=${scoped}&lang.${module}${lang}`;
424
- importMap.set(importId, css);
425
- s.appendLeft(
426
- 0,
427
- isDeclaration ? `import style${index} from "${importId}";` : `import "${importId}";`
428
- );
429
- s.overwriteNode(expression, isDeclaration ? `style${index}` : "");
430
- }
431
- function getReturnStatement(root) {
432
- if (root.body.type === "BlockStatement") {
433
- const returnStatement = root.body.body.find(
434
- (node) => node.type === "ReturnStatement"
435
- );
436
- if (returnStatement) {
437
- return returnStatement.argument;
438
- }
439
- } else {
440
- return root.body;
441
- }
442
- }
443
- function toCssVarId(name, prefix = "") {
444
- return prefix + name.replaceAll(/\W/g, (searchValue, replaceValue) => {
445
- return searchValue === "." ? "-" : name.charCodeAt(replaceValue).toString();
446
- });
447
- }
448
-
449
- // src/core/index.ts
450
- function transformJsxMacros(code, id, importMap, options) {
451
- const s = new (0, _common.MagicStringAST)(code);
452
- const ast = _common.babelParse.call(void 0, s.original, _common.getLang.call(void 0, id));
453
- const rootMap = getRootMap(ast, s, options);
454
- let defineStyleIndex = 0;
455
- for (const [root, map] of rootMap) {
456
- _optionalChain([map, 'access', _55 => _55.defineStyle, 'optionalAccess', _56 => _56.forEach, 'call', _57 => _57((defineStyle) => {
457
- transformDefineStyle(defineStyle, defineStyleIndex++, root, s, importMap);
458
- })]);
459
- if (root === void 0) continue;
460
- let propsName = `${_common.HELPER_PREFIX}props`;
461
- if (root.params[0]) {
462
- if (root.params[0].type === "Identifier") {
463
- propsName = root.params[0].name;
464
- } else if (root.params[0].type === "ObjectPattern") {
465
- const lastProp = root.params[0].properties.at(-1);
466
- if (!map.defineComponent && _optionalChain([lastProp, 'optionalAccess', _58 => _58.type]) === "RestElement" && lastProp.argument.type === "Identifier") {
467
- propsName = lastProp.argument.name;
468
- } else {
469
- s.appendRight(
470
- _optionalChain([root, 'access', _59 => _59.params, 'access', _60 => _60[0], 'access', _61 => _61.extra, 'optionalAccess', _62 => _62.trailingComma]) ? _optionalChain([root, 'access', _63 => _63.params, 'access', _64 => _64[0], 'access', _65 => _65.extra, 'optionalAccess', _66 => _66.trailingComma]) + 1 : _optionalChain([lastProp, 'optionalAccess', _67 => _67.end]) || root.params[0].end - 1,
471
- `${!_optionalChain([root, 'access', _68 => _68.params, 'access', _69 => _69[0], 'access', _70 => _70.extra, 'optionalAccess', _71 => _71.trailingComma]) && root.params[0].properties.length ? "," : ""} ...${_common.HELPER_PREFIX}props`
472
- );
473
- }
474
- }
475
- } else {
476
- s.appendRight(getParamsStart(root, s.original), propsName);
477
- }
478
- if (map.defineComponent) {
479
- transformDefineComponent(
480
- root,
481
- propsName,
482
- map,
483
- s,
484
- _optionalChain([options, 'access', _72 => _72.defineComponent, 'optionalAccess', _73 => _73.autoReturnFunction])
485
- );
486
- }
487
- if (_optionalChain([map, 'access', _74 => _74.defineModel, 'optionalAccess', _75 => _75.length])) {
488
- map.defineModel.forEach(({ expression }) => {
489
- transformDefineModel(expression, propsName, s);
490
- });
491
- }
492
- if (map.defineSlots) {
493
- transformDefineSlots(map.defineSlots, s);
494
- }
495
- if (map.defineExpose) {
496
- transformDefineExpose(map.defineExpose, s, options.version);
497
- }
498
- }
499
- return _common.generateTransform.call(void 0, s, id);
500
- }
501
- function getRootMap(ast, s, options) {
502
- const parents = [];
503
- const rootMap = /* @__PURE__ */ new Map();
504
- _common.walkAST.call(void 0, ast, {
505
- enter(node, parent) {
506
- parents.unshift(parent);
507
- const root = isFunctionalNode(parents[1]) ? parents[1] : void 0;
508
- if (root && _optionalChain([parents, 'access', _76 => _76[2], 'optionalAccess', _77 => _77.type]) === "CallExpression" && options.defineComponent.alias.includes(s.sliceNode(parents[2].callee))) {
509
- if (!rootMap.has(root)) rootMap.set(root, {});
510
- if (!rootMap.get(root).defineComponent) {
511
- rootMap.get(root).defineComponent = parents[2];
512
- }
513
- }
514
- const expression = node.type === "VariableDeclaration" ? _optionalChain([node, 'access', _78 => _78.declarations, 'access', _79 => _79[0], 'access', _80 => _80.init, 'optionalAccess', _81 => _81.type]) === "CallExpression" && s.sliceNode(node.declarations[0].init.callee) === "$" ? node.declarations[0].init.arguments[0] : node.declarations[0].init : node.type === "ExpressionStatement" ? node.expression : void 0;
515
- if (!expression) return;
516
- const macroExpression = getMacroExpression(expression, options);
517
- if (!macroExpression) return;
518
- if (!rootMap.has(root)) rootMap.set(root, {});
519
- const macroName = s.sliceNode(
520
- macroExpression.callee.type === "MemberExpression" ? macroExpression.callee.object : macroExpression.callee
521
- );
522
- if (macroName) {
523
- if (options.defineModel.alias.includes(macroName)) {
524
- ;
525
- (rootMap.get(root).defineModel ??= []).push({
526
- expression: macroExpression,
527
- isRequired: expression.type === "TSNonNullExpression"
528
- });
529
- } else if (options.defineStyle.alias.includes(macroName)) {
530
- const lang = macroExpression.callee.type === "MemberExpression" && macroExpression.callee.property.type === "Identifier" ? macroExpression.callee.property.name : "css";
531
- (rootMap.get(root).defineStyle ??= []).push({
532
- expression: macroExpression,
533
- isDeclaration: node.type === "VariableDeclaration",
534
- lang
535
- });
536
- } else if (options.defineSlots.alias.includes(macroName)) {
537
- rootMap.get(root).defineSlots = macroExpression;
538
- } else if (options.defineExpose.alias.includes(macroName)) {
539
- rootMap.get(root).defineExpose = macroExpression;
540
- }
541
- }
542
- },
543
- leave() {
544
- parents.shift();
545
- }
546
- });
547
- return rootMap;
548
- }
549
- function isFunctionalNode(node) {
550
- return !!(node && (node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration" || node.type === "FunctionExpression"));
551
- }
552
- function getMacroExpression(node, options) {
553
- if (node.type === "TSNonNullExpression") {
554
- node = node.expression;
555
- }
556
- if (node.type === "CallExpression") {
557
- if (node.callee.type === "MemberExpression" && node.callee.object.type === "Identifier" && node.callee.object.name === "defineStyle") {
558
- return node;
559
- } else if (node.callee.type === "Identifier" && [
560
- ...options.defineComponent.alias,
561
- ...options.defineSlots.alias,
562
- ...options.defineModel.alias,
563
- ...options.defineExpose.alias,
564
- ...options.defineStyle.alias
565
- ].includes(node.callee.name)) {
566
- return node;
567
- }
568
- }
569
- }
570
- function getParamsStart(node, code) {
571
- return node.params[0] ? node.params[0].start : node.start + (_optionalChain([code, 'access', _82 => _82.slice, 'call', _83 => _83(node.start, node.body.start), 'access', _84 => _84.match, 'call', _85 => _85(/\(\s*\)/), 'optionalAccess', _86 => _86.index]) || 0) + 1;
572
- }
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
- exports.use_model_default = use_model_default; exports.with_defaults_default = with_defaults_default; exports.helperPrefix = helperPrefix; exports.useModelHelperId = useModelHelperId; exports.withDefaultsHelperId = withDefaultsHelperId; exports.restructure = restructure; exports.transformJsxMacros = transformJsxMacros; exports.isFunctionalNode = isFunctionalNode; exports.getMacroExpression = getMacroExpression; exports.getParamsStart = getParamsStart;
@@ -1,10 +0,0 @@
1
- import {
2
- index_default
3
- } from "./chunk-AUE5EAQA.js";
4
-
5
- // src/vite.ts
6
- var vite_default = index_default.vite;
7
-
8
- export {
9
- vite_default
10
- };