@vtj/coder 0.10.9 → 0.10.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,13 +2,13 @@
2
2
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/coder
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.10.9
5
+ * @version 0.10.11
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const se="0.10.9";/**!
7
+ */const se="0.10.11";/**!
8
8
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
9
9
  * @name @vtj/core
10
10
  * @author CHC chenhuachun1549@dingtalk.com
11
- * @version 0.10.9
11
+ * @version 0.10.11
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */const re=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const B={arrowParens:"always",bracketSpacing:!0,bracketSameLine:!0,endOfLine:"lf",htmlWhitespaceSensitivity:"css",insertPragma:!1,jsxBracketSameLine:!0,jsxSingleQuote:!0,printWidth:80,proseWrap:"preserve",quoteProps:"as-needed",requirePragma:!1,semi:!0,singleQuote:!0,tabWidth:2,trailingComma:"none",useTabs:!1,vueIndentScriptAndStyle:!0};async function R(t,e){return e?t:await T.format(t,{parser:"vue",...B,plugins:[ne,D,U,L]})}async function M(t,e){return e?t:await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})}async function I(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[L]})}function j(t){return t&&t.type==="JSExpression"}function E(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function S(t){return j(t)||E(t)}function V(t){return t.replace(new RegExp("this.","g"),"")}function J(t){return t.replace(/this\.context\??\./g,"")}function m(t,e=!0,n=!0,s=[]){let r=S(t)?t.value:e?JSON.stringify(t):t;return r=A(r,s),n?V(J(r)):J(r)}function A(t,e=[]){let n=t;for(const s of e)n=n.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);return n}function H(t){let e=t.trim();if(e=/^\((\(|async|function)/.test(e)?e.substring(1,e.length-1):e,e.startsWith("{"))return e;if(e.startsWith("async function"))e=e.replace(/^async function/,"async");else if(e.startsWith("function"))e=e.replace(/^function/,"");else{const r=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,i=e.match(r);i&&i[2]&&(i[2].startsWith("{")||(e=e.replace(i[2],`{ return ${i[2]} }`))),e=e.replace("=>","")}return e}function ie(t={}){return Object.entries(t).map(([e,n])=>`"${e}": ${m(n)}`)}function Q(t={},e=!1){const n=Object.keys(t);return e?n.map(s=>"."+s):n}function oe(t){let e="";for(var n in t)if(t.hasOwnProperty(n)){var s=t[n];e+=n+": "+s+";"}return e}function ce(t=[],e=[]){return t.filter(n=>!e.includes(n))}class ae{constructor(e,n){this.dsl=e,this.dependencies=n,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};style={};members=[];urlSchemas={};blockPlugins={};libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const n=e.split(".");if(n.length===4){const s=n.pop(),r=n.join(".")+".",i=n.pop();if(s&&i){const c=this.dependencies.find(a=>a.library===i)?.package;c&&(this.imports[c]||(this.imports[c]=new Set)).add(s)}return{name:s,path:r,library:i}}return null}replaceLibraryPath(e){const{libraryRegex:n}=this;let s=e.value;for(const r of n){const i=e.value?.match(r)||[];for(const c of i){const a=this.collectImport(c);if(a){const p=a.path.replace(/\$/g,"\\$");s=s.replace(new RegExp(p,"g"),"")}}}return s}walk(e){const n=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){for(let i of s)n(i);return}const r=Object.values(s);for(const i of r)S(i)?i.value=this.replaceLibraryPath(i):n(i)};n(e)}getLibraryMember(e=[]){let n=[...e];const s={...this.imports};delete s["uni-h5"],delete s["@dcloudio/uni-h5"],delete s["uni-ui"],delete s["@dcloudio/uni-ui"];for(const r of Object.values(s))n=n.concat(Array.from(r));return f.dedupArray(n)}collectContext(e,n){const s=new Set(n?.id?this.context[n.id]:[]),r=(e.directives||[]).find(a=>a.name==="vFor");let i=new Set(Array.from(s));if(r){const{item:a="item",index:p="index"}=r.iterator||{};i=new Set([a,p,...Array.from(i)])}const c=e.slot;if(c){const a=typeof c=="string"?[]:c.params||[],p=a.length?a:[`scope_${n?.id}`];i=new Set([...p,...Array.from(i)])}this.context[e.id]=i}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}collectUrlSchema(e){typeof e.from=="object"&&e.from.type==="UrlSchema"&&(this.urlSchemas[e.name]=e.from)}collectBlockPlugin(e){typeof e.from=="object"&&e.from.type==="Plugin"&&(this.blockPlugins[e.name]=e.from)}walkNodes(e){const n=(s,r)=>{this.collectContext(s,r),this.collectStyle(s),this.collectUrlSchema(s),this.collectBlockPlugin(s),Array.isArray(s.children)&&s.children.forEach(i=>n(i,s))};Array.isArray(e.nodes)&&e.nodes.forEach(s=>n(s))}}function ue(t={}){return Object.entries(t).map(([e,n])=>{const s=m(n,!1);return`${e}:${s}`})}function le(t=[]){return t.map(e=>`${e.name}: {
14
14
  from: '${e.from||e.name}',
@@ -43,11 +43,11 @@
43
43
  `),components:ce(u,g).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
44
44
  `),css:s.css||"",style:xe(t.style),urlSchemas:w.join(`
45
45
  `),blockPlugins:C.join(`
46
- `),asyncComponents:k.join(","),uniComponents:g}}const Ne=`
46
+ `),asyncComponents:k.join(","),uniComponents:g,renderer:n==="uniapp"?"@vtj/uniapp":"@vtj/renderer"}}const Ne=`
47
47
  // @ts-nocheck
48
48
 
49
49
  <%= imports %>
50
- import { useProvider } from '@vtj/renderer';
50
+ import { useProvider } from '<%= renderer %>';
51
51
  export default defineComponent({
52
52
  name: '<%= name %>',
53
53
  <% if(inject) { %> inject: { <%= inject %>}, <% } %>
package/dist/index.mjs CHANGED
@@ -8,15 +8,15 @@ import * as H from "prettier/plugins/estree";
8
8
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
9
9
  * @name @vtj/coder
10
10
  * @author CHC chenhuachun1549@dingtalk.com
11
- * @version 0.10.9
11
+ * @version 0.10.11
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Le = "0.10.9";
14
+ const Le = "0.10.11";
15
15
  /**!
16
16
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
17
17
  * @name @vtj/core
18
18
  * @author CHC chenhuachun1549@dingtalk.com
19
- * @version 0.10.9
19
+ * @version 0.10.11
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const re = [
@@ -89,18 +89,18 @@ function q(t) {
89
89
  function J(t) {
90
90
  return t.replace(/this\.context\??\./g, "");
91
91
  }
92
- function f(t, e = !0, s = !0, n = []) {
92
+ function f(t, e = !0, n = !0, s = []) {
93
93
  let r = k(t) ? t.value : e ? JSON.stringify(t) : t;
94
- return r = N(r, n), s ? q(J(r)) : J(r);
94
+ return r = N(r, s), n ? q(J(r)) : J(r);
95
95
  }
96
96
  function N(t, e = []) {
97
- let s = t;
98
- for (const n of e)
99
- s = s.replace(
100
- new RegExp(`this.${n}.value`, "g"),
101
- `this.${n}`
97
+ let n = t;
98
+ for (const s of e)
99
+ n = n.replace(
100
+ new RegExp(`this.${s}.value`, "g"),
101
+ `this.${s}`
102
102
  );
103
- return s;
103
+ return n;
104
104
  }
105
105
  function Q(t) {
106
106
  let e = t.trim();
@@ -116,27 +116,27 @@ function Q(t) {
116
116
  return e;
117
117
  }
118
118
  function oe(t = {}) {
119
- return Object.entries(t).map(([e, s]) => `"${e}": ${f(s)}`);
119
+ return Object.entries(t).map(([e, n]) => `"${e}": ${f(n)}`);
120
120
  }
121
121
  function G(t = {}, e = !1) {
122
- const s = Object.keys(t);
123
- return e ? s.map((n) => "." + n) : s;
122
+ const n = Object.keys(t);
123
+ return e ? n.map((s) => "." + s) : n;
124
124
  }
125
125
  function ce(t) {
126
126
  let e = "";
127
- for (var s in t)
128
- if (t.hasOwnProperty(s)) {
129
- var n = t[s];
130
- e += s + ": " + n + ";";
127
+ for (var n in t)
128
+ if (t.hasOwnProperty(n)) {
129
+ var s = t[n];
130
+ e += n + ": " + s + ";";
131
131
  }
132
132
  return e;
133
133
  }
134
134
  function ae(t = [], e = []) {
135
- return t.filter((s) => !e.includes(s));
135
+ return t.filter((n) => !e.includes(n));
136
136
  }
137
137
  class ue {
138
- constructor(e, s) {
139
- this.dsl = e, this.dependencies = s, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
138
+ constructor(e, n) {
139
+ this.dsl = e, this.dependencies = n, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
140
140
  }
141
141
  /**
142
142
  * { 'element-plus': ['ElButton', 'ElInput' ...] }
@@ -157,17 +157,17 @@ class ue {
157
157
  * @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
158
158
  */
159
159
  collectImport(e) {
160
- const s = e.split(".");
161
- if (s.length === 4) {
162
- const n = s.pop(), r = s.join(".") + ".", i = s.pop();
163
- if (n && i) {
160
+ const n = e.split(".");
161
+ if (n.length === 4) {
162
+ const s = n.pop(), r = n.join(".") + ".", i = n.pop();
163
+ if (s && i) {
164
164
  const c = this.dependencies.find(
165
165
  (a) => a.library === i
166
166
  )?.package;
167
- c && (this.imports[c] || (this.imports[c] = /* @__PURE__ */ new Set())).add(n);
167
+ c && (this.imports[c] || (this.imports[c] = /* @__PURE__ */ new Set())).add(s);
168
168
  }
169
169
  return {
170
- name: n,
170
+ name: s,
171
171
  path: r,
172
172
  library: i
173
173
  };
@@ -176,52 +176,52 @@ class ue {
176
176
  }
177
177
  // 代码中包含依赖库的引用,需要从代码中移除
178
178
  replaceLibraryPath(e) {
179
- const { libraryRegex: s } = this;
180
- let n = e.value;
181
- for (const r of s) {
179
+ const { libraryRegex: n } = this;
180
+ let s = e.value;
181
+ for (const r of n) {
182
182
  const i = e.value?.match(r) || [];
183
183
  for (const c of i) {
184
184
  const a = this.collectImport(c);
185
185
  if (a) {
186
186
  const p = a.path.replace(/\$/g, "\\$");
187
- n = n.replace(new RegExp(p, "g"), "");
187
+ s = s.replace(new RegExp(p, "g"), "");
188
188
  }
189
189
  }
190
190
  }
191
- return n;
191
+ return s;
192
192
  }
193
193
  walk(e) {
194
- const s = (n) => {
195
- if (!n || typeof n != "object") return;
196
- if (Array.isArray(n)) {
197
- for (let i of n)
198
- s(i);
194
+ const n = (s) => {
195
+ if (!s || typeof s != "object") return;
196
+ if (Array.isArray(s)) {
197
+ for (let i of s)
198
+ n(i);
199
199
  return;
200
200
  }
201
- const r = Object.values(n);
201
+ const r = Object.values(s);
202
202
  for (const i of r)
203
- k(i) ? i.value = this.replaceLibraryPath(i) : s(i);
203
+ k(i) ? i.value = this.replaceLibraryPath(i) : n(i);
204
204
  };
205
- s(e);
205
+ n(e);
206
206
  }
207
207
  getLibraryMember(e = []) {
208
- let s = [...e];
209
- const n = { ...this.imports };
210
- delete n["uni-h5"], delete n["@dcloudio/uni-h5"], delete n["uni-ui"], delete n["@dcloudio/uni-ui"];
211
- for (const r of Object.values(n))
212
- s = s.concat(Array.from(r));
213
- return S(s);
208
+ let n = [...e];
209
+ const s = { ...this.imports };
210
+ delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
211
+ for (const r of Object.values(s))
212
+ n = n.concat(Array.from(r));
213
+ return S(n);
214
214
  }
215
- collectContext(e, s) {
216
- const n = new Set(s?.id ? this.context[s.id] : []), r = (e.directives || []).find((a) => a.name === "vFor");
217
- let i = new Set(Array.from(n));
215
+ collectContext(e, n) {
216
+ const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((a) => a.name === "vFor");
217
+ let i = new Set(Array.from(s));
218
218
  if (r) {
219
219
  const { item: a = "item", index: p = "index" } = r.iterator || {};
220
220
  i = /* @__PURE__ */ new Set([a, p, ...Array.from(i)]);
221
221
  }
222
222
  const c = e.slot;
223
223
  if (c) {
224
- const a = typeof c == "string" ? [] : c.params || [], p = a.length ? a : [`scope_${s?.id}`];
224
+ const a = typeof c == "string" ? [] : c.params || [], p = a.length ? a : [`scope_${n?.id}`];
225
225
  i = /* @__PURE__ */ new Set([...p, ...Array.from(i)]);
226
226
  }
227
227
  this.context[e.id] = i;
@@ -236,16 +236,16 @@ class ue {
236
236
  typeof e.from == "object" && e.from.type === "Plugin" && (this.blockPlugins[e.name] = e.from);
237
237
  }
238
238
  walkNodes(e) {
239
- const s = (n, r) => {
240
- this.collectContext(n, r), this.collectStyle(n), this.collectUrlSchema(n), this.collectBlockPlugin(n), Array.isArray(n.children) && n.children.forEach((i) => s(i, n));
239
+ const n = (s, r) => {
240
+ this.collectContext(s, r), this.collectStyle(s), this.collectUrlSchema(s), this.collectBlockPlugin(s), Array.isArray(s.children) && s.children.forEach((i) => n(i, s));
241
241
  };
242
- Array.isArray(e.nodes) && e.nodes.forEach((n) => s(n));
242
+ Array.isArray(e.nodes) && e.nodes.forEach((s) => n(s));
243
243
  }
244
244
  }
245
245
  function le(t = {}) {
246
- return Object.entries(t).map(([e, s]) => {
247
- const n = f(s, !1);
248
- return `${e}:${n}`;
246
+ return Object.entries(t).map(([e, n]) => {
247
+ const s = f(n, !1);
248
+ return `${e}:${s}`;
249
249
  });
250
250
  }
251
251
  function pe(t = []) {
@@ -255,48 +255,48 @@ function pe(t = []) {
255
255
  }`);
256
256
  }
257
257
  function fe(t = []) {
258
- const e = (s) => s ? `[${ee(s).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
259
- return t.map((s) => typeof s == "string" ? `${s}: {}` : (k(s.default) && !s.default.value && (s.default.value = "undefined"), `${s.name}: {
260
- type:${e(s.type)},
261
- required: ${f(!!s.required, !0, !1)},
262
- default: ${f(s.default, !0, !1)}
258
+ const e = (n) => n ? `[${ee(n).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
259
+ return t.map((n) => typeof n == "string" ? `${n}: {}` : (k(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
260
+ type:${e(n.type)},
261
+ required: ${f(!!n.required, !0, !1)},
262
+ default: ${f(n.default, !0, !1)}
263
263
  }`));
264
264
  }
265
265
  function me(t = []) {
266
266
  return t.map((e) => `'${typeof e == "string" ? e : e.name}'`);
267
267
  }
268
268
  function _(t = {}, e = []) {
269
- return Object.entries(t).map(([s, n]) => {
270
- let r = Q(f(n, !1, !1));
271
- return r = N(r, e), r.startsWith("async") ? `async ${s}${r.replace(/^async/, "")}` : `${s}${r}`;
269
+ return Object.entries(t).map(([n, s]) => {
270
+ let r = Q(f(s, !1, !1));
271
+ return r = N(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
272
272
  });
273
273
  }
274
274
  function he(t = [], e = []) {
275
- const s = t.reduce(
275
+ const n = t.reduce(
276
276
  (i, c) => (c.id && A(c.source) && (i[`watcher_${c.id}`] = c.source), i),
277
277
  {}
278
- ), n = _(s, e), r = t.map((i) => `watcher_${i.id}: {
278
+ ), s = _(n, e), r = t.map((i) => `watcher_${i.id}: {
279
279
  deep: ${i.deep},
280
280
  immediate:${i.immediate},
281
281
  handler${Q(i.handler.value)}
282
282
  }`);
283
283
  return {
284
- computed: n,
284
+ computed: s,
285
285
  watches: r
286
286
  };
287
287
  }
288
288
  function de(t = {}) {
289
289
  return Object.values(t).map((e) => {
290
290
  if (e.type === "mock") {
291
- const s = A(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
291
+ const n = A(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
292
292
  return `async ${e.name}(...args:any[]) {
293
- const mock = this.provider.createMock(${s})
293
+ const mock = this.provider.createMock(${n})
294
294
  return await mock.apply(this, args);
295
295
  }`;
296
296
  } else {
297
- const s = A(e.transform) && e.transform.value || "(res) => res";
297
+ const n = A(e.transform) && e.transform.value || "(res) => res";
298
298
  return `async ${e.name}(...args:any[]) {
299
- return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
299
+ return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
300
300
  }`;
301
301
  }
302
302
  });
@@ -324,7 +324,7 @@ const ye = [
324
324
  "vBind",
325
325
  "vHtml"
326
326
  ];
327
- function z(t, e, s = [], n = {}, r) {
327
+ function z(t, e, n = [], s = {}, r) {
328
328
  const i = [];
329
329
  let c = {}, a = [];
330
330
  const p = [];
@@ -342,17 +342,17 @@ function z(t, e, s = [], n = {}, r) {
342
342
  v,
343
343
  d.props,
344
344
  d.events,
345
- n,
346
- s
345
+ s,
346
+ n
347
347
  ), T = Ce(
348
348
  d.directives,
349
- s,
349
+ n,
350
350
  p
351
351
  ).join(" "), b = d.children ? Oe(
352
352
  d.children,
353
- s,
354
- e,
355
353
  n,
354
+ e,
355
+ s,
356
356
  d
357
357
  ) : "";
358
358
  Object.assign(c, O);
@@ -383,20 +383,20 @@ function ge(t) {
383
383
  }
384
384
  function $e(t = []) {
385
385
  const e = /* @__PURE__ */ new Map();
386
- for (const s of t) {
387
- const n = typeof s.slot == "string" ? s.slot : s.slot?.name, r = e.get(n);
388
- r ? r.children.push(s) : e.set(n, { slot: s.slot, children: [s] });
386
+ for (const n of t) {
387
+ const s = typeof n.slot == "string" ? n.slot : n.slot?.name, r = e.get(s);
388
+ r ? r.children.push(n) : e.set(s, { slot: n.slot, children: [n] });
389
389
  }
390
390
  return e;
391
391
  }
392
- function ve(t, e, s) {
392
+ function ve(t, e, n) {
393
393
  if (re.includes(t)) return null;
394
- const n = e.get(t);
395
- if (n && n.alias) {
396
- const r = n.parent ? `${n.parent}.${n.alias}` : n.alias;
394
+ const s = e.get(t);
395
+ if (s && s.alias) {
396
+ const r = s.parent ? `${s.parent}.${s.alias}` : s.alias;
397
397
  return `${t}: ${r}`;
398
398
  }
399
- return X(s) || n ? t : null;
399
+ return X(n) || s ? t : null;
400
400
  }
401
401
  function X(t) {
402
402
  return !!t && typeof t == "object" && t.type === "Schema";
@@ -407,18 +407,18 @@ function Y(t) {
407
407
  function Z(t) {
408
408
  return typeof t == "object" && t.type === "Plugin";
409
409
  }
410
- function be(t, e, s = []) {
410
+ function be(t, e, n = []) {
411
411
  return t === "style" ? "" : t === "__class" && k(e) ? `:class="${f({
412
412
  ...e,
413
- value: N(e.value, s)
413
+ value: N(e.value, n)
414
414
  })}"` : typeof e == "string" ? `${t}="${e}"` : k(e) ? `:${t}="${f({
415
415
  ...e,
416
- value: N(e.value, s)
416
+ value: N(e.value, n)
417
417
  })}"` : te(e) ? `:${t}='{${oe(
418
418
  e
419
419
  ).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
420
420
  }
421
- function je(t, e = {}, s = []) {
421
+ function je(t, e = {}, n = []) {
422
422
  if (!!Object.keys(e.style || {}).length) {
423
423
  const i = `${t.name}_${t.id}`;
424
424
  e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : (e.class = i, delete e.style);
@@ -427,75 +427,75 @@ function je(t, e = {}, s = []) {
427
427
  return (Y(r) || Z(r)) && (e.is = {
428
428
  type: "JSExpression",
429
429
  value: t.name
430
- }), Object.entries(e).map(([i, c]) => be(i, c, s));
430
+ }), Object.entries(e).map(([i, c]) => be(i, c, n));
431
431
  }
432
- function Se(t, e, s, n, r) {
432
+ function Se(t, e, n, s, r) {
433
433
  const i = G(e.modifiers, !0);
434
- return r ? `@${t}${i.join("")}="${s}"` : n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${s}"` : `@${t}${i.join("")}="${s}"`;
434
+ return r ? `@${t}${i.join("")}="${n}"` : s && s.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${n}"` : `@${t}${i.join("")}="${n}"`;
435
435
  }
436
- function ke(t, e = {}, s = {}) {
437
- const n = {}, r = Array.from(s[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
436
+ function ke(t, e = {}, n = {}) {
437
+ const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
438
438
  return {
439
439
  binders: Object.entries(e).map(([a, p]) => {
440
440
  const o = p.handler.value.startsWith("this."), l = o ? q(p.handler.value) : `${$(a)}_${t}${i}`;
441
- return o || (n[l] = r.length ? {
441
+ return o || (s[l] = r.length ? {
442
442
  type: "JSFunction",
443
443
  value: `{
444
444
  return (${p.handler.value}).apply(this, args);
445
445
  }`
446
446
  } : p.handler), Se(a, p, l, r, o);
447
447
  }),
448
- handlers: n
448
+ handlers: s
449
449
  };
450
450
  }
451
- function we(t, e, s = {}, n = {}, r = {}, i) {
452
- const { binders: c, handlers: a } = ke(e, n, r);
451
+ function we(t, e, n = {}, s = {}, r = {}, i) {
452
+ const { binders: c, handlers: a } = ke(e, s, r);
453
453
  return {
454
- props: je(t, s, i).join(" "),
454
+ props: je(t, n, i).join(" "),
455
455
  handlers: a,
456
456
  binders: c,
457
457
  events: c.join(" ")
458
458
  };
459
459
  }
460
- function Ce(t = [], e = [], s = []) {
461
- const n = [], { vIf: r, vShow: i, vModels: c, vFor: a, vBind: p, vHtml: o, customDirectives: l } = Pe(t);
462
- if (r && n.push(`v-if="${f(r.value, !0, !0, e)}"`), i && n.push(
460
+ function Ce(t = [], e = [], n = []) {
461
+ const s = [], { vIf: r, vShow: i, vModels: c, vFor: a, vBind: p, vHtml: o, customDirectives: l } = Pe(t);
462
+ if (r && s.push(`v-if="${f(r.value, !0, !0, e)}"`), i && s.push(
463
463
  `v-show="${f(i.value, !0, !0, e)}"`
464
- ), p && n.push(
464
+ ), p && s.push(
465
465
  `v-bind="${f(p.value, !0, !0, e)}"`
466
466
  ), c.forEach((u) => {
467
467
  const m = G(u.modifiers, !0), h = u.arg ? j(u.arg) ? `:[${f(u.arg, !0, !0, e)}]` : `:${u.arg}` : "";
468
- n.push(
468
+ s.push(
469
469
  `v-model${h}${m}="${f(u.value, !0, !0, e)}"`
470
470
  );
471
471
  }), a) {
472
472
  const { item: u, index: m } = { item: "item", index: "index", ...a.iterator };
473
- n.push(
473
+ s.push(
474
474
  `v-for="(${u}, ${m}) in ${f(a.value, !0, !0, e)}"`
475
475
  );
476
476
  }
477
- return o && n.push(
477
+ return o && s.push(
478
478
  `v-html="${f(o.value, !0, !0, e)}"`
479
479
  ), l && l.length && l.forEach((u) => {
480
480
  if (!u.name) return;
481
481
  let m = "", h = "";
482
- j(u.name) ? (h = f(u.name, !0, !0, e), s.push(h)) : h = u.name;
482
+ j(u.name) ? (h = f(u.name, !0, !0, e), n.push(h)) : h = u.name;
483
483
  const d = h?.startsWith("v") ? I(h) : I("v-" + h);
484
484
  if (m += d, u.arg && (j(u.arg) ? m += `:[${f(u.name, !0, !0, e)}]` : m += `:${u.arg}`), u.modifiers) {
485
485
  const v = Object.keys(u.modifiers);
486
486
  v.length && (m += v.map((g) => "." + g));
487
487
  }
488
- u.value ? n.push(
488
+ u.value ? s.push(
489
489
  `${m}="${f(u.value, !0, !0, e)}"`
490
- ) : n.push(m);
491
- }), n;
490
+ ) : s.push(m);
491
+ }), s;
492
492
  }
493
493
  function Pe(t = []) {
494
494
  const e = t.filter(
495
495
  (o) => L.includes(o.name)
496
- ), s = t.filter(
496
+ ), n = t.filter(
497
497
  (o) => !L.includes(o.name)
498
- ), n = e.find(
498
+ ), s = e.find(
499
499
  (o) => $(o.name) === "vIf"
500
500
  ), r = e.find(
501
501
  (o) => $(o.name) === "vFor"
@@ -509,26 +509,26 @@ function Pe(t = []) {
509
509
  (o) => $(o.name) === "vModel"
510
510
  );
511
511
  return {
512
- vIf: n,
512
+ vIf: s,
513
513
  vFor: r,
514
514
  vShow: i,
515
515
  vModels: p,
516
516
  vBind: c,
517
517
  vHtml: a,
518
- customDirectives: s
518
+ customDirectives: n
519
519
  };
520
520
  }
521
- function Oe(t, e, s, n, r) {
522
- return typeof t == "string" ? t : j(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, s, e, n, r) : "";
521
+ function Oe(t, e, n, s, r) {
522
+ return typeof t == "string" ? t : j(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, n, e, s, r) : "";
523
523
  }
524
- function xe(t, e, s) {
524
+ function xe(t, e, n) {
525
525
  if (!t) return e;
526
- const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
527
- return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${s}`}"`}>
526
+ const s = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
527
+ return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
528
528
  ${e}
529
529
  </template>`;
530
530
  }
531
- function Ee(t, e = [], s = [], n = {}, r = "web") {
531
+ function Ee(t, e = [], n = [], s = {}, r = "web") {
532
532
  const i = [
533
533
  "@dcloudio/uni-h5",
534
534
  "uni-h5",
@@ -544,21 +544,21 @@ function Ee(t, e = [], s = [], n = {}, r = "web") {
544
544
  u.push(m), r === "uniapp" && i.includes(l.package) && a.push(m);
545
545
  }
546
546
  }
547
- for (const [o, l] of Object.entries(n))
547
+ for (const [o, l] of Object.entries(s))
548
548
  (c[o] ?? (c[o] = [])).push(...Array.from(l)), r === "uniapp" && i.includes(o) && a.push(...Array.from(l));
549
549
  return {
550
550
  imports: Object.entries(c).filter(([o, l]) => r === "uniapp" ? !i.includes(o) && !!l.length : !!l.length).map(([o, l]) => `import { ${S(l).join(
551
551
  ","
552
- )}} from '${o}';`).concat(s),
552
+ )}} from '${o}';`).concat(n),
553
553
  uniComponents: a
554
554
  };
555
555
  }
556
556
  function _e(t = {}) {
557
557
  const e = [];
558
- for (const [s, n] of Object.entries(t))
558
+ for (const [n, s] of Object.entries(t))
559
559
  e.push(`
560
- ${s} {
561
- ${ce(n)}
560
+ ${n} {
561
+ ${ce(s)}
562
562
  }
563
563
  `);
564
564
  return e.join(`
@@ -566,30 +566,30 @@ function _e(t = {}) {
566
566
  }
567
567
  function Ae(t = {}) {
568
568
  const e = [];
569
- return Object.entries(t).forEach(([s, n]) => {
569
+ return Object.entries(t).forEach(([n, s]) => {
570
570
  e.push(
571
- `const ${s} = provider.defineUrlSchemaComponent('${n.url}');`
571
+ `const ${n} = provider.defineUrlSchemaComponent('${s.url}');`
572
572
  );
573
573
  }), e;
574
574
  }
575
575
  function Ne(t = {}) {
576
576
  const e = [];
577
- return Object.entries(t).forEach(([s, n]) => {
577
+ return Object.entries(t).forEach(([n, s]) => {
578
578
  e.push(
579
- `const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`
579
+ `const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`
580
580
  );
581
581
  }), e;
582
582
  }
583
- function Fe(t, e, s = "web") {
584
- const { dsl: n } = t, r = Object.keys(n.computed || {}), i = _(n.lifeCycles, r), c = _(n.computed, r), a = he(n.watch, r), p = de(n.dataSources), { methods: o, nodes: l, components: u, importBlocks: m, directives: h } = z(
585
- n.nodes || [],
583
+ function Fe(t, e, n = "web") {
584
+ const { dsl: s } = t, r = Object.keys(s.computed || {}), i = _(s.lifeCycles, r), c = _(s.computed, r), a = he(s.watch, r), p = de(s.dataSources), { methods: o, nodes: l, components: u, importBlocks: m, directives: h } = z(
585
+ s.nodes || [],
586
586
  e,
587
587
  r,
588
588
  t.context
589
589
  ), d = [...c, ...a.computed], v = _(
590
590
  {
591
591
  ...o,
592
- ...n.methods || {}
592
+ ...s.methods || {}
593
593
  },
594
594
  r
595
595
  ), g = m.map((O) => `import ${O.name} from './${O.id}.vue';`);
@@ -598,20 +598,20 @@ function Fe(t, e, s = "web") {
598
598
  u,
599
599
  g,
600
600
  t.imports,
601
- s
601
+ n
602
602
  );
603
603
  const w = Object.keys({
604
604
  ...t.urlSchemas,
605
605
  ...t.blockPlugins
606
606
  }), C = Ae(t.urlSchemas), P = Ne(t.blockPlugins);
607
607
  return {
608
- id: n.id,
609
- version: n.__VERSION__,
610
- name: n.name,
611
- state: le(n.state).join(","),
612
- inject: pe(n.inject).join(","),
613
- props: fe(n.props).join(","),
614
- emits: me(n.emits).join(","),
608
+ id: s.id,
609
+ version: s.__VERSION__,
610
+ name: s.name,
611
+ state: le(s.state).join(","),
612
+ inject: pe(s.inject).join(","),
613
+ props: fe(s.props).join(","),
614
+ emits: me(s.emits).join(","),
615
615
  watch: a.watches.join(","),
616
616
  lifeCycles: i.join(","),
617
617
  computed: d.join(","),
@@ -624,21 +624,22 @@ function Fe(t, e, s = "web") {
624
624
  returns: t.members.join(","),
625
625
  template: l.join(`
626
626
  `),
627
- css: n.css || "",
627
+ css: s.css || "",
628
628
  style: _e(t.style),
629
629
  urlSchemas: C.join(`
630
630
  `),
631
631
  blockPlugins: P.join(`
632
632
  `),
633
633
  asyncComponents: w.join(","),
634
- uniComponents: y
634
+ uniComponents: y,
635
+ renderer: n === "uniapp" ? "@vtj/uniapp" : "@vtj/renderer"
635
636
  };
636
637
  }
637
638
  const Ie = `
638
639
  // @ts-nocheck
639
640
 
640
641
  <%= imports %>
641
- import { useProvider } from '@vtj/renderer';
642
+ import { useProvider } from '<%= renderer %>';
642
643
  export default defineComponent({
643
644
  name: '<%= name %>',
644
645
  <% if(inject) { %> inject: { <%= inject %>}, <% } %>
@@ -678,8 +679,8 @@ export default defineComponent({
678
679
  <%= style %>
679
680
  </style>
680
681
  `, Re = U(Ie), Te = U(Be);
681
- async function Ue(t, e = /* @__PURE__ */ new Map(), s = [], n = "web", r) {
682
- const i = new ue(ne(t), s), c = Fe(i, e, n), a = Re(c), p = Te({
682
+ async function Ue(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
683
+ const i = new ue(ne(t), n), c = Fe(i, e, s), a = Re(c), p = Te({
683
684
  template: c.template,
684
685
  css: await W(c.css, r),
685
686
  script: await ie(a, r),
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.10.9",
4
+ "version": "0.10.11",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "prettier": "~3.5.0",
8
8
  "@vtj/base": "~0.10.1",
9
- "@vtj/core": "~0.10.9"
9
+ "@vtj/core": "~0.10.11"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@vtj/cli": "~0.10.2"
@@ -23,5 +23,6 @@ export interface Token {
23
23
  blockPlugins: string;
24
24
  asyncComponents: string;
25
25
  uniComponents: string[];
26
+ renderer: string;
26
27
  }
27
28
  export declare function parser(collecter: Collecter, componentMap: Map<string, MaterialDescription>, platform?: PlatformType): Token;
@@ -2,7 +2,7 @@
2
2
  * Copyright (c) 2025, VTJ.PRO All rights reserved.
3
3
  * @name @vtj/coder
4
4
  * @author CHC chenhuachun1549@dingtalk.com
5
- * @version 0.10.8
5
+ * @version 0.10.10
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.10.8";
8
+ export declare const version = "0.10.10";