@vtj/coder 0.12.10 → 0.12.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
@@ -1,49 +1,49 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),T=require("prettier/standalone"),Z=require("prettier/plugins/html"),K=require("prettier/plugins/babel"),ee=require("prettier/plugins/postcss"),te=require("prettier/plugins/estree");function F(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const ne=F(Z),D=F(K),L=F(ee),U=F(te);/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@vtj/base"),T=require("prettier/standalone"),Z=require("prettier/plugins/html"),K=require("prettier/plugins/babel"),ee=require("prettier/plugins/postcss"),te=require("prettier/plugins/estree");function F(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const se=F(Z),D=F(K),L=F(ee),U=F(te);/**!
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.12.10
5
+ * @version 0.12.11
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const re="0.12.10";/**!
7
+ */const ne="0.12.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.12.10
11
+ * @version 0.12.11
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
- */const se=["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 V(t,e){if(e)return t;try{return(await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})).replace(/;\n$/gi,"")}catch(n){return console.warn(n),t}}async function I(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[L]})}function S(t){return t&&t.type==="JSExpression"}function A(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function v(t){return S(t)||A(t)}function M(t){return t.replace(new RegExp("this.","g"),"")}function J(t){return t.replace(/this\.context\??\./g,"")}function m(t,e=!0,n=!0,r=[]){let s=v(t)?t.value.trim().replace(/\"/g,"'").replace(/;$/,""):e?JSON.stringify(t):t;return s=k(s,r),n?M(J(s)):J(s)}function k(t,e=[]){let n=t;for(const r of e)n=n.replace(new RegExp(`this.${r}.value`,"g"),`this.${r}`);return n}function H(t){let e=t.trim().replace(/;$/,"");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 s=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,i=e.match(s);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(r=>"."+r):n}function oe(t){let e="";for(var n in t)if(t.hasOwnProperty(n)){var r=t[n];e+=n+": "+r+";"}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 r=n.pop(),s=n.join(".")+".",i=n.pop();if(r&&i){const c=this.dependencies.find(a=>a.library===i)?.package;c&&(this.imports[c]||(this.imports[c]=new Set)).add(r)}return{name:r,path:s,library:i}}return null}replaceLibraryPath(e){const{libraryRegex:n}=this;let r=e.value;for(const s of n){const i=e.value?.match(s)||[];for(const c of i){const a=this.collectImport(c);if(a){const p=a.path.replace(/\$/g,"\\$");r=r.replace(new RegExp(p,"g"),"")}}}return r}walk(e){const n=r=>{if(!r||typeof r!="object")return;if(Array.isArray(r)){for(let i of r)n(i);return}const s=Object.values(r);for(const i of s)v(i)?i.value=this.replaceLibraryPath(i):n(i)};n(e)}getLibraryMember(e=[]){let n=[...e];const r={...this.imports};delete r["uni-h5"],delete r["@dcloudio/uni-h5"],delete r["uni-ui"],delete r["@dcloudio/uni-ui"];for(const s of Object.values(r))n=n.concat(Array.from(s));return f.dedupArray(n)}collectContext(e,n){const r=new Set(n?.id?this.context[n.id]:[]),s=(e.directives||[]).find(a=>a.name==="vFor");let i=new Set(Array.from(r));if(s){const{item:a="item",index:p="index"}=s.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&&!v(e.props.style)&&(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=(r,s)=>{this.collectContext(r,s),this.collectStyle(r),this.collectUrlSchema(r),this.collectBlockPlugin(r),Array.isArray(r.children)&&r.children.forEach(i=>n(i,r))};Array.isArray(e.nodes)&&e.nodes.forEach(r=>n(r))}}function ue(t={}){return Object.entries(t).map(([e,n])=>{const r=m(n,!1);return`${e}:${r}`})}function le(t=[]){return t.map(e=>`${e.name}: {
13
+ */const re=["slot","template","component","img","div","p","h1","h2","h3","span","a"];m.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:[se,D,U,L]})}async function V(t,e){if(e)return t;try{return(await T.format(t,{parser:"babel-ts",...B,plugins:[D,U]})).replace(/;\n$/gi,"")}catch(s){return console.warn(s),t}}async function N(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[L]})}function k(t){return t&&t.type==="JSExpression"}function I(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function b(t){return k(t)||I(t)}function M(t){return t.replace(new RegExp("this.","g"),"")}function J(t){return t.replace(/this\.context\??\./g,"")}function d(t,e=!0,s=!0,n=[]){let r=b(t)?t.value.trim().replace(/\"/g,"'").replace(/;$/,""):e?JSON.stringify(t):t;return r=w(r,n),s?M(J(r)):J(r)}function w(t,e=[]){let s=t;for(const n of e)s=s.replace(new RegExp(`this.${n}.value`,"g"),`this.${n}`);return s}function H(t){let e=t.trim().replace(/;$/,"");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,s])=>`"${e}": ${d(s)}`)}function Q(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function oe(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var n=t[s];e+=s+": "+n+";"}return e}function ce(t=[],e=[]){return t.filter(s=>!e.includes(s))}class ae{constructor(e,s){this.dsl=e,this.dependencies=s,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 s=e.split(".");if(s.length===4){const n=s.pop(),r=s.join(".")+".",i=s.pop();if(n&&i){const o=this.dependencies.find(c=>c.library===i)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(n)}return{name:n,path:r,library:i}}return null}replaceLibraryPath(e){const{libraryRegex:s}=this;let n=e.value;for(const r of s){const i=e.value?.match(r)||[];for(const o of i){const c=this.collectImport(o);if(c){const f=c.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(f,"g"),"")}}}return n}walk(e){const s=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){for(let i of n)s(i);return}const r=Object.values(n);for(const i of r)b(i)?i.value=this.replaceLibraryPath(i):s(i)};s(e)}getLibraryMember(e=[]){let s=[...e];const n={...this.imports};delete n["uni-h5"],delete n["@dcloudio/uni-h5"],delete n["uni-ui"],delete n["@dcloudio/uni-ui"];for(const r of Object.values(n))s=s.concat(Array.from(r));return m.dedupArray(s)}collectContext(e,s){const n=new Set(s?.id?this.context[s.id]:[]),r=(e.directives||[]).find(c=>c.name==="vFor");let i=new Set(Array.from(n));if(r){const{item:c="item",index:f="index"}=r.iterator||{};i=new Set([c,f,...Array.from(i)])}const o=e.slot;if(o){const c=typeof o=="string"?[]:o.params||[],f=c.length?c:[`scope_${s?.id}`];i=new Set([...f,...Array.from(i)])}this.context[e.id]=i}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&!b(e.props.style)&&(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 s=(n,r)=>{this.collectContext(n,r),this.collectStyle(n),this.collectUrlSchema(n),this.collectBlockPlugin(n),Array.isArray(n.children)&&n.children.forEach(i=>s(i,n))};Array.isArray(e.nodes)&&e.nodes.forEach(n=>s(n))}}function le(t={}){return Object.entries(t).map(([e,s])=>{const n=d(s,!1);return`${e}:${n}`})}function ue(t=[]){return t.map(e=>`${e.name}: {
14
14
  from: '${e.from||e.name}',
15
- default: ${m(e.default,!0,!1)}
16
- }`)}function pe(t=[]){const e=n=>n?`[${f.toArray(n).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:(v(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
17
- type:${e(n.type)},
18
- required: ${m(!!n.required,!0,!1)},
19
- default: ${m(n.default,!0,!1)}
20
- }`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function E(t={},e=[]){return Object.entries(t).map(([n,r])=>{let s=H(m(r,!1,!1));return s=k(s,e),s.startsWith("async")?`async ${n}${s.replace(/^async/,"")}`:`${n}${s}`})}function me(t=[],e=[]){const n=t.reduce((i,c)=>(c.id&&A(c.source)&&(i[`watcher_${c.id}`]=c.source),i),{}),r=E(n,e),s=t.map(i=>`watcher_${i.id}: {
15
+ default: ${d(e.default,!0,!1)}
16
+ }`)}function pe(t=[]){const e=s=>s?`[${m.toArray(s).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(b(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
17
+ type:${e(s.type)},
18
+ required: ${d(!!s.required,!0,!1)},
19
+ default: ${d(s.default,!0,!1)}
20
+ }`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function A(t={},e=[]){return Object.entries(t).map(([s,n])=>{let r=H(d(n,!1,!1));return r=w(r,e),r.startsWith("async")?`async ${s}${r.replace(/^async/,"")}`:`${s}${r}`})}function me(t=[],e=[]){const s=t.reduce((i,o)=>(o.id&&I(o.source)&&(i[`watcher_${o.id}`]=o.source),i),{}),n=A(s,e),r=t.map(i=>`watcher_${i.id}: {
21
21
  deep: ${i.deep},
22
22
  immediate:${i.immediate},
23
23
  handler${H(i.handler.value)}
24
- }`);return{computed:r,watches:s}}function he(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const n=A(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args:any[]) {
25
- const mock = this.provider.createMock(${n})
24
+ }`);return{computed:n,watches:r}}function he(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const s=I(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args:any[]) {
25
+ const mock = this.provider.createMock(${s})
26
26
  return await mock.apply(this, args);
27
- }`}else{const n=A(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
28
- return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
29
- }`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,n=[],r={},s){const i=[];let c={},a=[];const p=[];let o=[];return ge(t).forEach(u=>{const h=[];for(const y of u.children){let{id:b,name:g,invisible:N,from:$}=y;if(N)continue;const w=$e(g,e,$);w&&a.push(w),G($)&&o.push({id:$.id,name:g});const{props:C,events:P,handlers:O}=ke(y,b,y.props,y.events,r,n),W=we(y.directives,n,p).join(" "),j=y.children?Pe(y.children,n,e,r,y):"";Object.assign(c,O);let _="";typeof j=="string"?_=j:(_=(j?.nodes||[]).join(`
30
- `),Object.assign(c,j?.methods||{}),a=a.concat(j?.components||[]),o=o.concat(j?.importBlocks||[]));const x=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes($||e.get(g)?.package)?f.kebabCase(g):X($)||Y($)?"component":g;h.push(de.includes(x)?`<${x} ${W} ${C} ${P} />`:`<${x} ${W} ${C} ${P}>${_?`
31
- `+_.trim():""}</${x}>`)}const d=Oe(u.slot,h.join(`
32
- `),s?.id);i.push(d)}),{nodes:i,methods:c,directives:ye(p),components:f.dedupArray(a),importBlocks:f.dedupArray(o,"id")}}function ye(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ge(t=[]){const e=new Map;for(const n of t){const r=typeof n.slot=="string"?n.slot:n.slot?.name,s=e.get(r);s?s.children.push(n):e.set(r,{slot:n.slot,children:[n]})}return e}function $e(t,e,n){if(se.includes(t))return null;const r=e.get(t);if(r&&r.alias){const s=r.parent?`${r.parent}.${r.alias}`:r.alias;return`${t}: ${s}`}return G(n)||r?t:null}function G(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function X(t){return typeof t=="object"&&t.type==="UrlSchema"}function Y(t){return typeof t=="object"&&t.type==="Plugin"}function ve(t,e,n=[]){return t==="style"?v(e)?`:style="${m({...e,value:k(e.value,n)})}"`:"":t==="__class"&&v(e)?`:class="${m({...e,value:k(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:v(e)?`:${t}="${m({...e,value:k(e.value,n)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function be(t,e={},n=[]){if(!!Object.keys(e.style||{}).length){const i=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,i].join(" "):(e.__class=e.class,e.class=i):e.class=i,v(e.style)||delete e.style}const s=t.from;return(X(s)||Y(s))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,c])=>ve(i,c,n))}function je(t,e,n,r,s){const i=Q(e.modifiers,!0);return s?`@${t}${i.join("")}="${n}"`:r&&r.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function Se(t,e={},n={}){const r={},s=Array.from(n[t]||new Set([])),i=s.length?`({${s.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,p])=>{const o=p.handler.value.startsWith("this."),l=o?M(p.handler.value):`${f.camelCase(a)}_${t}${i}`;return o||(r[l]=s.length?{type:"JSFunction",value:`{
33
- return (${p.handler.value}).apply(this, args);
34
- }`}:p.handler),je(a,p,l,s,o)}),handlers:r}}function ke(t,e,n={},r={},s={},i){const{binders:c,handlers:a}=Se(e,r,s);return{props:be(t,n,i).join(" "),handlers:a,binders:c,events:c.join(" ")}}function we(t=[],e=[],n=[]){const r=[],{vIf:s,vShow:i,vModels:c,vFor:a,vBind:p,vHtml:o,customDirectives:l}=Ce(t);if(s&&r.push(`v-if="${m(s.value,!0,!0,e)}"`),i&&r.push(`v-show="${m(i.value,!0,!0,e)}"`),p&&r.push(`v-bind="${m(p.value,!0,!0,e)}"`),c.forEach(u=>{const h=Q(u.modifiers,!0),d=u.arg?S(u.arg)?`:[${m(u.arg,!0,!0,e)}]`:`:${u.arg}`:"";r.push(`v-model${d}${h}="${m(u.value,!0,!0,e)}"`)}),a){const{item:u,index:h}={item:"item",index:"index",...a.iterator};r.push(`v-for="(${u}, ${h}) in ${m(a.value,!0,!0,e)}"`)}return o&&r.push(`v-html="${m(o.value,!0,!0,e)}"`),l&&l.length&&l.forEach(u=>{if(!u.name)return;let h="",d="";S(u.name)?(d=m(u.name,!0,!0,e),n.push(d)):d=u.name;const y=d?.startsWith("v")?f.kebabCase(d):f.kebabCase("v-"+d);if(h+=y,u.arg&&(S(u.arg)?h+=`:[${m(u.name,!0,!0,e)}]`:h+=`:${u.arg}`),u.modifiers){const b=Object.keys(u.modifiers);b.length&&(h+=b.map(g=>"."+g))}u.value?r.push(`${h}="${m(u.value,!0,!0,e)}"`):r.push(h)}),r}function Ce(t=[]){const e=t.filter(o=>q.includes(o.name)),n=t.filter(o=>!q.includes(o.name)),r=e.find(o=>f.camelCase(o.name)==="vIf"),s=e.find(o=>f.camelCase(o.name)==="vFor"),i=e.find(o=>f.camelCase(o.name)==="vShow"),c=e.find(o=>f.camelCase(o.name)==="vBind"),a=e.find(o=>f.camelCase(o.name)==="vHtml"),p=e.filter(o=>f.camelCase(o.name)==="vModel");return{vIf:r,vFor:s,vShow:i,vModels:p,vBind:c,vHtml:a,customDirectives:n}}function Pe(t,e,n,r,s){return typeof t=="string"?t:S(t)?`{{ ${m(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,n,e,r,s):""}function Oe(t,e,n){if(!t)return e;const r=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${r.name}="${r.params?.length>0?`{${r.params?.join(",")}}`:`scope_${n}`}"`}>
27
+ }`}else{const s=I(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
28
+ return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
29
+ }`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,s=[],n={},r){const i=[];let o={},c=[];const f=[];let l=[];return ge(t).forEach(a=>{const g=[];for(const h of a.children){let{id:y,name:$,invisible:j,from:v}=h;if(j)continue;const C=ve($,e,v);C&&c.push(C),G(v)&&l.push({id:v.id,name:$});const{props:P,events:O,handlers:E}=ke(h,y,h.props,h.events,n,s),W=we(h.directives,s,f).join(" "),S=h.children?Pe(h.children,s,e,n,h):"";Object.assign(o,E);let _="";typeof S=="string"?_=S:(_=(S?.nodes||[]).join(`
30
+ `),Object.assign(o,S?.methods||{}),c=c.concat(S?.components||[]),l=l.concat(S?.importBlocks||[]));const x=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(v||e.get($)?.package)?m.kebabCase($):X(v)||Y(v)?"component":$;g.push(de.includes(x)?`<${x} ${W} ${P} ${O} />`:`<${x} ${W} ${P} ${O}>${_?`
31
+ `+_.trim():""}</${x}>`)}const p=Oe(a.slot,g.join(`
32
+ `),r?.id);i.push(p)}),{nodes:i,methods:o,directives:ye(f),components:m.dedupArray(c),importBlocks:m.dedupArray(l,"id")}}function ye(t){return m.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ge(t=[]){const e=new Map;for(const s of t){const n=typeof s.slot=="string"?s.slot:s.slot?.name,r=e.get(n);r?r.children.push(s):e.set(n,{slot:s.slot,children:[s]})}return e}function ve(t,e,s){if(re.includes(t))return null;const n=e.get(t);if(n&&n.alias){const r=n.parent?`${n.parent}.${n.alias}`:n.alias;return`${t}: ${r}`}return G(s)||n?t:null}function G(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function X(t){return typeof t=="object"&&t.type==="UrlSchema"}function Y(t){return typeof t=="object"&&t.type==="Plugin"}function $e(t,e,s=[]){return t==="style"?b(e)?`:style="${d({...e,value:w(e.value,s)})}"`:"":t==="__class"&&b(e)?`:class="${d({...e,value:w(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:b(e)?`:${t}="${d({...e,value:w(e.value,s)})}"`:m.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function be(t,e={},s=[]){if(!!Object.keys(e.style||{}).length){const i=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,i].join(" "):(e.__class=e.class,e.class=i):e.class=i,b(e.style)||delete e.style}const r=t.from;return(X(r)||Y(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,o])=>$e(i,o,s))}function je(t,e,s,n,r){const i=Q(e.modifiers,!0);return r?`@${t}${i.join("")}="${s}"`:n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${s}"`:`@${t}${i.join("")}="${s}"`}function Se(t,e={},s={}){const n={},r=Array.from(s[t]||new Set([])),i=r.length?`({${r.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([c,f])=>{const l=f.handler.value.startsWith("this."),u=l?M(f.handler.value):`${m.camelCase(c)}_${t}${i}`;return l||(n[u]=r.length?{type:"JSFunction",value:`{
33
+ return (${f.handler.value}).apply(this, args);
34
+ }`}:f.handler),je(c,f,u,r,l)}),handlers:n}}function ke(t,e,s={},n={},r={},i){const{binders:o,handlers:c}=Se(e,n,r);return{props:be(t,s,i).join(" "),handlers:c,binders:o,events:o.join(" ")}}function we(t=[],e=[],s=[]){const n=[],{vIf:r,vElse:i,vElseIf:o,vShow:c,vModels:f,vFor:l,vBind:u,vHtml:a,customDirectives:g}=Ce(t);if(r&&n.push(`v-if="${d(r.value,!0,!0,e)}"`),o&&n.push(`v-else-if="${d(o.value,!0,!0,e)}"`),i&&n.push("v-else"),c&&n.push(`v-show="${d(c.value,!0,!0,e)}"`),u&&n.push(`v-bind="${d(u.value,!0,!0,e)}"`),f.forEach(p=>{const h=Q(p.modifiers,!0),y=p.arg?k(p.arg)?`:[${d(p.arg,!0,!0,e)}]`:`:${p.arg}`:"";n.push(`v-model${y}${h}="${d(p.value,!0,!0,e)}"`)}),l){const{item:p,index:h}={item:"item",index:"index",...l.iterator};n.push(`v-for="(${p}, ${h}) in ${d(l.value,!0,!0,e)}"`)}return a&&n.push(`v-html="${d(a.value,!0,!0,e)}"`),g&&g.length&&g.forEach(p=>{if(!p.name)return;let h="",y="";k(p.name)?(y=d(p.name,!0,!0,e),s.push(y)):y=p.name;const $=y?.startsWith("v")?m.kebabCase(y):m.kebabCase("v-"+y);if(h+=$,p.arg&&(k(p.arg)?h+=`:[${d(p.name,!0,!0,e)}]`:h+=`:${p.arg}`),p.modifiers){const j=Object.keys(p.modifiers);j.length&&(h+=j.map(v=>"."+v))}p.value?n.push(`${h}="${d(p.value,!0,!0,e)}"`):n.push(h)}),n}function Ce(t=[]){const e=t.filter(a=>q.includes(a.name)),s=t.filter(a=>!q.includes(a.name)),n=e.find(a=>m.camelCase(a.name)==="vIf"),r=e.find(a=>m.camelCase(a.name)==="vElseIf"),i=e.find(a=>m.camelCase(a.name)==="vElse"),o=e.find(a=>m.camelCase(a.name)==="vFor"),c=e.find(a=>m.camelCase(a.name)==="vShow"),f=e.find(a=>m.camelCase(a.name)==="vBind"),l=e.find(a=>m.camelCase(a.name)==="vHtml"),u=e.filter(a=>m.camelCase(a.name)==="vModel");return{vIf:n,vElseIf:r,vElse:i,vFor:o,vShow:c,vModels:u,vBind:f,vHtml:l,customDirectives:s}}function Pe(t,e,s,n,r){return typeof t=="string"?t:k(t)?`{{ ${d(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,s,e,n,r):""}function Oe(t,e,s){if(!t)return e;const n=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${n.name}="${n.params?.length>0?`{${n.params?.join(",")}}`:`scope_${s}`}"`}>
35
35
  ${e}
36
- </template>`}function _e(t,e=[],n=[],r={},s="web"){const i=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],c={vue:["defineComponent","reactive"]},a=[];for(const o of e){const l=t.get(o.split(":")[0]);if(l&&l.package){const u=c[l.package]??(c[l.package]=[]),h=l.parent||(l.alias||"").split(".")[0]||l.name;u.push(h),s==="uniapp"&&i.includes(l.package)&&a.push(h)}}for(const[o,l]of Object.entries(r))(c[o]??(c[o]=[])).push(...Array.from(l)),s==="uniapp"&&i.includes(o)&&a.push(...Array.from(l));return{imports:Object.entries(c).filter(([o,l])=>s==="uniapp"?!i.includes(o)&&!!l.length:!!l.length).map(([o,l])=>`import { ${f.dedupArray(l).join(",")}} from '${o}';`).concat(n),uniComponents:a}}function xe(t={}){const e=[];for(const[n,r]of Object.entries(t))e.push(`
37
- ${n} {
38
- ${oe(r)}
36
+ </template>`}function Ee(t,e=[],s=[],n={},r="web"){const i=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],o={vue:["defineComponent","reactive"]},c=[];for(const l of e){const u=t.get(l.split(":")[0]);if(u&&u.package){const a=o[u.package]??(o[u.package]=[]),g=u.parent||(u.alias||"").split(".")[0]||u.name;a.push(g),r==="uniapp"&&i.includes(u.package)&&c.push(g)}}for(const[l,u]of Object.entries(n))(o[l]??(o[l]=[])).push(...Array.from(u)),r==="uniapp"&&i.includes(l)&&c.push(...Array.from(u));return{imports:Object.entries(o).filter(([l,u])=>r==="uniapp"?!i.includes(l)&&!!u.length:!!u.length).map(([l,u])=>`import { ${m.dedupArray(u).join(",")}} from '${l}';`).concat(s),uniComponents:c}}function _e(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
37
+ ${s} {
38
+ ${oe(n)}
39
39
  }
40
40
  `);return e.join(`
41
- `)}function Ee(t={}){const e=[];return Object.entries(t).forEach(([n,r])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${r.url}');`)}),e}function Ae(t={}){const e=[];return Object.entries(t).forEach(([n,r])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(r)});`)}),e}function Fe(t,e,n="web"){const{dsl:r}=t,s=Object.keys(r.computed||{}),i=E(r.lifeCycles,s),c=E(r.computed,s),a=me(r.watch,s),p=he(r.dataSources),{methods:o,nodes:l,components:u,importBlocks:h,directives:d}=z(r.nodes||[],e,s,t.context),y=[...c,...a.computed],b=E({...o,...r.methods||{}},s),g=h.map(O=>`import ${O.name} from './${O.id}.vue';`);let{imports:N,uniComponents:$}=_e(e,u,g,t.imports,n);const w=Object.keys({...t.urlSchemas,...t.blockPlugins}),C=Ee(t.urlSchemas),P=Ae(t.blockPlugins);return{id:r.id,version:r.__VERSION__,name:r.name,state:ue(r.state).join(","),inject:le(r.inject).join(","),props:pe(r.props).join(","),emits:fe(r.emits).join(","),watch:a.watches.join(","),lifeCycles:i.join(","),computed:y.join(","),methods:[...p,...b].join(","),imports:`
42
- `+N.join(`
43
- `),components:ce(u,$).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
44
- `),css:r.css||"",style:xe(t.style),urlSchemas:C.join(`
45
- `),blockPlugins:P.join(`
46
- `),asyncComponents:w.join(","),uniComponents:$,renderer:n==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
41
+ `)}function xe(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function Ae(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Ie(t,e,s="web"){const{dsl:n}=t,r=Object.keys(n.computed||{}),i=A(n.lifeCycles,r),o=A(n.computed,r),c=me(n.watch,r),f=he(n.dataSources),{methods:l,nodes:u,components:a,importBlocks:g,directives:p}=z(n.nodes||[],e,r,t.context),h=[...o,...c.computed],y=A({...l,...n.methods||{}},r),$=g.map(E=>`import ${E.name} from './${E.id}.vue';`);let{imports:j,uniComponents:v}=Ee(e,a,$,t.imports,s);const C=Object.keys({...t.urlSchemas,...t.blockPlugins}),P=xe(t.urlSchemas),O=Ae(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:le(n.state).join(","),inject:ue(n.inject).join(","),props:pe(n.props).join(","),emits:fe(n.emits).join(","),watch:c.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...f,...y].join(","),imports:`
42
+ `+j.join(`
43
+ `),components:ce(a,v).join(","),directives:p.join(","),returns:t.members.join(","),template:u.join(`
44
+ `),css:n.css||"",style:_e(t.style),urlSchemas:P.join(`
45
+ `),blockPlugins:O.join(`
46
+ `),asyncComponents:C.join(","),uniComponents:v,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Fe=`
47
47
  // @ts-nocheck
48
48
 
49
49
  <%= imports %>
@@ -75,7 +75,7 @@ export default defineComponent({
75
75
  <% if(methods) { %> methods: { <%= methods %> }, <% } %>
76
76
  <% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
77
77
  });
78
- `.replace(/(\n|\r|\t)/g,""),Ie=`
78
+ `.replace(/(\n|\r|\t)/g,""),Ne=`
79
79
  <template>
80
80
  <%= template %>
81
81
  </template>
@@ -86,7 +86,7 @@ export default defineComponent({
86
86
  <%= css %>
87
87
  <%= style %>
88
88
  </style>
89
- `,Te=f.template(Ne),Be=f.template(Ie);async function Re(t,e=new Map,n=[],r="web",s){const i=new ae(f.cloneDeep(t),n),c=Fe(i,e,r),a=Te(c),p=Be({template:c.template,css:await I(c.css,s),script:await V(a,s),style:await I(c.style,s)});return await R(p,s).catch(o=>(o.content=p,Promise.reject(o)))}async function We(t){const e=`
89
+ `,Te=m.template(Fe),Be=m.template(Ne);async function Re(t,e=new Map,s=[],n="web",r){const i=new ae(m.cloneDeep(t),s),o=Ie(i,e,n),c=Te(o),f=Be({template:o.template,css:await N(o.css,r),script:await V(c,r),style:await N(o.style,r)});return await R(f,r).catch(l=>(l.content=f,Promise.reject(l)))}async function We(t){const e=`
90
90
  <template>
91
91
  <div>
92
92
  <h3>源码模式页面</h3>
@@ -97,4 +97,4 @@ export default defineComponent({
97
97
  <\/script>
98
98
  <style scoped lang="scss">
99
99
  </style>
100
- `;return await R(e)}exports.VTJ_CODER_VERSION=re;exports.createEmptyPage=We;exports.cssFormatter=I;exports.generator=Re;exports.tsFormatter=V;exports.vueFormatter=R;
100
+ `;return await R(e)}exports.VTJ_CODER_VERSION=ne;exports.createEmptyPage=We;exports.cssFormatter=N;exports.generator=Re;exports.tsFormatter=V;exports.vueFormatter=R;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { mitt as K, dedupArray as w, toArray as ee, kebabCase as I, camelCase as v, isPlainObject as te, template as U, cloneDeep as ne } from "@vtj/base";
1
+ import { mitt as K, dedupArray as C, toArray as ee, kebabCase as F, camelCase as v, isPlainObject as te, template as U, cloneDeep as ne } from "@vtj/base";
2
2
  import { format as B } from "prettier/standalone";
3
3
  import * as se from "prettier/plugins/html";
4
4
  import * as D from "prettier/plugins/babel";
@@ -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.12.10
11
+ * @version 0.12.11
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Le = "0.12.10";
14
+ const Le = "0.12.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.12.10
19
+ * @version 0.12.11
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const re = [
@@ -79,14 +79,14 @@ async function W(t, e) {
79
79
  plugins: [V]
80
80
  });
81
81
  }
82
- function S(t) {
82
+ function k(t) {
83
83
  return t && t.type === "JSExpression";
84
84
  }
85
85
  function N(t) {
86
86
  return typeof t == "object" && t && t.type === "JSFunction";
87
87
  }
88
- function $(t) {
89
- return S(t) || N(t);
88
+ function b(t) {
89
+ return k(t) || N(t);
90
90
  }
91
91
  function M(t) {
92
92
  return t.replace(new RegExp("this.", "g"), "");
@@ -94,11 +94,11 @@ function M(t) {
94
94
  function J(t) {
95
95
  return t.replace(/this\.context\??\./g, "");
96
96
  }
97
- function f(t, e = !0, n = !0, s = []) {
98
- let r = $(t) ? t.value.trim().replace(/\"/g, "'").replace(/;$/, "") : e ? JSON.stringify(t) : t;
99
- return r = k(r, s), n ? M(J(r)) : J(r);
97
+ function h(t, e = !0, n = !0, s = []) {
98
+ let r = b(t) ? t.value.trim().replace(/\"/g, "'").replace(/;$/, "") : e ? JSON.stringify(t) : t;
99
+ return r = w(r, s), n ? M(J(r)) : J(r);
100
100
  }
101
- function k(t, e = []) {
101
+ function w(t, e = []) {
102
102
  let n = t;
103
103
  for (const s of e)
104
104
  n = n.replace(
@@ -121,7 +121,7 @@ function Q(t) {
121
121
  return e;
122
122
  }
123
123
  function oe(t = {}) {
124
- return Object.entries(t).map(([e, n]) => `"${e}": ${f(n)}`);
124
+ return Object.entries(t).map(([e, n]) => `"${e}": ${h(n)}`);
125
125
  }
126
126
  function G(t = {}, e = !1) {
127
127
  const n = Object.keys(t);
@@ -139,7 +139,7 @@ function ce(t) {
139
139
  function ae(t = [], e = []) {
140
140
  return t.filter((n) => !e.includes(n));
141
141
  }
142
- class ue {
142
+ class le {
143
143
  constructor(e, n) {
144
144
  this.dsl = e, this.dependencies = n, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
145
145
  }
@@ -166,10 +166,10 @@ class ue {
166
166
  if (n.length === 4) {
167
167
  const s = n.pop(), r = n.join(".") + ".", i = n.pop();
168
168
  if (s && i) {
169
- const c = this.dependencies.find(
170
- (a) => a.library === i
169
+ const o = this.dependencies.find(
170
+ (c) => c.library === i
171
171
  )?.package;
172
- c && (this.imports[c] || (this.imports[c] = /* @__PURE__ */ new Set())).add(s);
172
+ o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(s);
173
173
  }
174
174
  return {
175
175
  name: s,
@@ -185,11 +185,11 @@ class ue {
185
185
  let s = e.value;
186
186
  for (const r of n) {
187
187
  const i = e.value?.match(r) || [];
188
- for (const c of i) {
189
- const a = this.collectImport(c);
190
- if (a) {
191
- const p = a.path.replace(/\$/g, "\\$");
192
- s = s.replace(new RegExp(p, "g"), "");
188
+ for (const o of i) {
189
+ const c = this.collectImport(o);
190
+ if (c) {
191
+ const f = c.path.replace(/\$/g, "\\$");
192
+ s = s.replace(new RegExp(f, "g"), "");
193
193
  }
194
194
  }
195
195
  }
@@ -205,7 +205,7 @@ class ue {
205
205
  }
206
206
  const r = Object.values(s);
207
207
  for (const i of r)
208
- $(i) ? i.value = this.replaceLibraryPath(i) : n(i);
208
+ b(i) ? i.value = this.replaceLibraryPath(i) : n(i);
209
209
  };
210
210
  n(e);
211
211
  }
@@ -215,24 +215,24 @@ class ue {
215
215
  delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
216
216
  for (const r of Object.values(s))
217
217
  n = n.concat(Array.from(r));
218
- return w(n);
218
+ return C(n);
219
219
  }
220
220
  collectContext(e, n) {
221
- const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((a) => a.name === "vFor");
221
+ const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((c) => c.name === "vFor");
222
222
  let i = new Set(Array.from(s));
223
223
  if (r) {
224
- const { item: a = "item", index: p = "index" } = r.iterator || {};
225
- i = /* @__PURE__ */ new Set([a, p, ...Array.from(i)]);
224
+ const { item: c = "item", index: f = "index" } = r.iterator || {};
225
+ i = /* @__PURE__ */ new Set([c, f, ...Array.from(i)]);
226
226
  }
227
- const c = e.slot;
228
- if (c) {
229
- const a = typeof c == "string" ? [] : c.params || [], p = a.length ? a : [`scope_${n?.id}`];
230
- i = /* @__PURE__ */ new Set([...p, ...Array.from(i)]);
227
+ const o = e.slot;
228
+ if (o) {
229
+ const c = typeof o == "string" ? [] : o.params || [], f = c.length ? c : [`scope_${n?.id}`];
230
+ i = /* @__PURE__ */ new Set([...f, ...Array.from(i)]);
231
231
  }
232
232
  this.context[e.id] = i;
233
233
  }
234
234
  collectStyle(e) {
235
- e.id && e.props?.style && Object.keys(e.props.style).length && !$(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
235
+ e.id && e.props?.style && Object.keys(e.props.style).length && !b(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
236
236
  }
237
237
  collectUrlSchema(e) {
238
238
  typeof e.from == "object" && e.from.type === "UrlSchema" && (this.urlSchemas[e.name] = e.from);
@@ -247,24 +247,24 @@ class ue {
247
247
  Array.isArray(e.nodes) && e.nodes.forEach((s) => n(s));
248
248
  }
249
249
  }
250
- function le(t = {}) {
250
+ function ue(t = {}) {
251
251
  return Object.entries(t).map(([e, n]) => {
252
- const s = f(n, !1);
252
+ const s = h(n, !1);
253
253
  return `${e}:${s}`;
254
254
  });
255
255
  }
256
256
  function pe(t = []) {
257
257
  return t.map((e) => `${e.name}: {
258
258
  from: '${e.from || e.name}',
259
- default: ${f(e.default, !0, !1)}
259
+ default: ${h(e.default, !0, !1)}
260
260
  }`);
261
261
  }
262
262
  function fe(t = []) {
263
263
  const e = (n) => n ? `[${ee(n).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
264
- return t.map((n) => typeof n == "string" ? `${n}: {}` : ($(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
264
+ return t.map((n) => typeof n == "string" ? `${n}: {}` : (b(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
265
265
  type:${e(n.type)},
266
- required: ${f(!!n.required, !0, !1)},
267
- default: ${f(n.default, !0, !1)}
266
+ required: ${h(!!n.required, !0, !1)},
267
+ default: ${h(n.default, !0, !1)}
268
268
  }`));
269
269
  }
270
270
  function me(t = []) {
@@ -272,13 +272,13 @@ function me(t = []) {
272
272
  }
273
273
  function A(t = {}, e = []) {
274
274
  return Object.entries(t).map(([n, s]) => {
275
- let r = Q(f(s, !1, !1));
276
- return r = k(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
275
+ let r = Q(h(s, !1, !1));
276
+ return r = w(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
277
277
  });
278
278
  }
279
279
  function he(t = [], e = []) {
280
280
  const n = t.reduce(
281
- (i, c) => (c.id && N(c.source) && (i[`watcher_${c.id}`] = c.source), i),
281
+ (i, o) => (o.id && N(o.source) && (i[`watcher_${o.id}`] = o.source), i),
282
282
  {}
283
283
  ), s = A(n, e), r = t.map((i) => `watcher_${i.id}: {
284
284
  deep: ${i.deep},
@@ -323,6 +323,8 @@ const ye = [
323
323
  "wbr"
324
324
  ], L = [
325
325
  "vIf",
326
+ "vElseIf",
327
+ "vElse",
326
328
  "vShow",
327
329
  "vModel",
328
330
  "vFor",
@@ -331,60 +333,60 @@ const ye = [
331
333
  ];
332
334
  function X(t, e, n = [], s = {}, r) {
333
335
  const i = [];
334
- let c = {}, a = [];
335
- const p = [];
336
- let o = [];
337
- return $e(t).forEach((u) => {
338
- const m = [];
339
- for (const d of u.children) {
340
- let { id: b, name: y, invisible: F, from: g } = d;
341
- if (F)
336
+ let o = {}, c = [];
337
+ const f = [];
338
+ let l = [];
339
+ return $e(t).forEach((a) => {
340
+ const y = [];
341
+ for (const m of a.children) {
342
+ let { id: d, name: $, invisible: j, from: g } = m;
343
+ if (j)
342
344
  continue;
343
- const C = ve(y, e, g);
344
- C && a.push(C), z(g) && o.push({ id: g.id, name: y });
345
+ const E = ve($, e, g);
346
+ E && c.push(E), z(g) && l.push({ id: g.id, name: $ });
345
347
  const { props: P, events: O, handlers: x } = we(
348
+ m,
346
349
  d,
347
- b,
348
- d.props,
349
- d.events,
350
+ m.props,
351
+ m.events,
350
352
  s,
351
353
  n
352
354
  ), R = Ce(
353
- d.directives,
355
+ m.directives,
354
356
  n,
355
- p
356
- ).join(" "), j = d.children ? Oe(
357
- d.children,
357
+ f
358
+ ).join(" "), S = m.children ? Pe(
359
+ m.children,
358
360
  n,
359
361
  e,
360
362
  s,
361
- d
363
+ m
362
364
  ) : "";
363
- Object.assign(c, x);
364
- let E = "";
365
- typeof j == "string" ? E = j : (E = (j?.nodes || []).join(`
366
- `), Object.assign(c, j?.methods || {}), a = a.concat(j?.components || []), o = o.concat(j?.importBlocks || []));
367
- const _ = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
368
- g || e.get(y)?.package
369
- ) ? I(y) : Y(g) || Z(g) ? "component" : y;
370
- m.push(
371
- ye.includes(_) ? `<${_} ${R} ${P} ${O} />` : `<${_} ${R} ${P} ${O}>${E ? `
372
- ` + E.trim() : ""}</${_}>`
365
+ Object.assign(o, x);
366
+ let _ = "";
367
+ typeof S == "string" ? _ = S : (_ = (S?.nodes || []).join(`
368
+ `), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), l = l.concat(S?.importBlocks || []));
369
+ const I = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
370
+ g || e.get($)?.package
371
+ ) ? F($) : Y(g) || Z(g) ? "component" : $;
372
+ y.push(
373
+ ye.includes(I) ? `<${I} ${R} ${P} ${O} />` : `<${I} ${R} ${P} ${O}>${_ ? `
374
+ ` + _.trim() : ""}</${I}>`
373
375
  );
374
376
  }
375
- const h = xe(u.slot, m.join(`
377
+ const p = Oe(a.slot, y.join(`
376
378
  `), r?.id);
377
- i.push(h);
379
+ i.push(p);
378
380
  }), {
379
381
  nodes: i,
380
- methods: c,
381
- directives: ge(p),
382
- components: w(a),
383
- importBlocks: w(o, "id")
382
+ methods: o,
383
+ directives: ge(f),
384
+ components: C(c),
385
+ importBlocks: C(l, "id")
384
386
  };
385
387
  }
386
388
  function ge(t) {
387
- return w(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
389
+ return C(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
388
390
  }
389
391
  function $e(t = []) {
390
392
  const e = /* @__PURE__ */ new Map();
@@ -413,15 +415,15 @@ function Z(t) {
413
415
  return typeof t == "object" && t.type === "Plugin";
414
416
  }
415
417
  function be(t, e, n = []) {
416
- return t === "style" ? $(e) ? `:style="${f({
418
+ return t === "style" ? b(e) ? `:style="${h({
417
419
  ...e,
418
- value: k(e.value, n)
419
- })}"` : "" : t === "__class" && $(e) ? `:class="${f({
420
+ value: w(e.value, n)
421
+ })}"` : "" : t === "__class" && b(e) ? `:class="${h({
420
422
  ...e,
421
- value: k(e.value, n)
422
- })}"` : typeof e == "string" ? `${t}="${e}"` : $(e) ? `:${t}="${f({
423
+ value: w(e.value, n)
424
+ })}"` : typeof e == "string" ? `${t}="${e}"` : b(e) ? `:${t}="${h({
423
425
  ...e,
424
- value: k(e.value, n)
426
+ value: w(e.value, n)
425
427
  })}"` : te(e) ? `:${t}='{${oe(
426
428
  e
427
429
  ).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
@@ -429,13 +431,13 @@ function be(t, e, n = []) {
429
431
  function je(t, e = {}, n = []) {
430
432
  if (!!Object.keys(e.style || {}).length) {
431
433
  const i = `${t.name}_${t.id}`;
432
- e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : e.class = i, $(e.style) || delete e.style;
434
+ e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : e.class = i, b(e.style) || delete e.style;
433
435
  }
434
436
  const r = t.from;
435
437
  return (Y(r) || Z(r)) && (e.is = {
436
438
  type: "JSExpression",
437
439
  value: t.name
438
- }), Object.entries(e).map(([i, c]) => be(i, c, n));
440
+ }), Object.entries(e).map(([i, o]) => be(i, o, n));
439
441
  }
440
442
  function Se(t, e, n, s, r) {
441
443
  const i = G(e.modifiers, !0);
@@ -444,121 +446,139 @@ function Se(t, e, n, s, r) {
444
446
  function ke(t, e = {}, n = {}) {
445
447
  const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
446
448
  return {
447
- binders: Object.entries(e).map(([a, p]) => {
448
- const o = p.handler.value.startsWith("this."), l = o ? M(p.handler.value) : `${v(a)}_${t}${i}`;
449
- return o || (s[l] = r.length ? {
449
+ binders: Object.entries(e).map(([c, f]) => {
450
+ const l = f.handler.value.startsWith("this."), u = l ? M(f.handler.value) : `${v(c)}_${t}${i}`;
451
+ return l || (s[u] = r.length ? {
450
452
  type: "JSFunction",
451
453
  value: `{
452
- return (${p.handler.value}).apply(this, args);
454
+ return (${f.handler.value}).apply(this, args);
453
455
  }`
454
- } : p.handler), Se(a, p, l, r, o);
456
+ } : f.handler), Se(c, f, u, r, l);
455
457
  }),
456
458
  handlers: s
457
459
  };
458
460
  }
459
461
  function we(t, e, n = {}, s = {}, r = {}, i) {
460
- const { binders: c, handlers: a } = ke(e, s, r);
462
+ const { binders: o, handlers: c } = ke(e, s, r);
461
463
  return {
462
464
  props: je(t, n, i).join(" "),
463
- handlers: a,
464
- binders: c,
465
- events: c.join(" ")
465
+ handlers: c,
466
+ binders: o,
467
+ events: o.join(" ")
466
468
  };
467
469
  }
468
470
  function Ce(t = [], e = [], n = []) {
469
- const s = [], { vIf: r, vShow: i, vModels: c, vFor: a, vBind: p, vHtml: o, customDirectives: l } = Pe(t);
470
- if (r && s.push(`v-if="${f(r.value, !0, !0, e)}"`), i && s.push(
471
- `v-show="${f(i.value, !0, !0, e)}"`
472
- ), p && s.push(
473
- `v-bind="${f(p.value, !0, !0, e)}"`
474
- ), c.forEach((u) => {
475
- const m = G(u.modifiers, !0), h = u.arg ? S(u.arg) ? `:[${f(u.arg, !0, !0, e)}]` : `:${u.arg}` : "";
471
+ const s = [], {
472
+ vIf: r,
473
+ vElse: i,
474
+ vElseIf: o,
475
+ vShow: c,
476
+ vModels: f,
477
+ vFor: l,
478
+ vBind: u,
479
+ vHtml: a,
480
+ customDirectives: y
481
+ } = Ee(t);
482
+ if (r && s.push(`v-if="${h(r.value, !0, !0, e)}"`), o && s.push(
483
+ `v-else-if="${h(o.value, !0, !0, e)}"`
484
+ ), i && s.push("v-else"), c && s.push(
485
+ `v-show="${h(c.value, !0, !0, e)}"`
486
+ ), u && s.push(
487
+ `v-bind="${h(u.value, !0, !0, e)}"`
488
+ ), f.forEach((p) => {
489
+ const m = G(p.modifiers, !0), d = p.arg ? k(p.arg) ? `:[${h(p.arg, !0, !0, e)}]` : `:${p.arg}` : "";
476
490
  s.push(
477
- `v-model${h}${m}="${f(u.value, !0, !0, e)}"`
491
+ `v-model${d}${m}="${h(p.value, !0, !0, e)}"`
478
492
  );
479
- }), a) {
480
- const { item: u, index: m } = { item: "item", index: "index", ...a.iterator };
493
+ }), l) {
494
+ const { item: p, index: m } = { item: "item", index: "index", ...l.iterator };
481
495
  s.push(
482
- `v-for="(${u}, ${m}) in ${f(a.value, !0, !0, e)}"`
496
+ `v-for="(${p}, ${m}) in ${h(l.value, !0, !0, e)}"`
483
497
  );
484
498
  }
485
- return o && s.push(
486
- `v-html="${f(o.value, !0, !0, e)}"`
487
- ), l && l.length && l.forEach((u) => {
488
- if (!u.name) return;
489
- let m = "", h = "";
490
- S(u.name) ? (h = f(u.name, !0, !0, e), n.push(h)) : h = u.name;
491
- const d = h?.startsWith("v") ? I(h) : I("v-" + h);
492
- if (m += d, u.arg && (S(u.arg) ? m += `:[${f(u.name, !0, !0, e)}]` : m += `:${u.arg}`), u.modifiers) {
493
- const b = Object.keys(u.modifiers);
494
- b.length && (m += b.map((y) => "." + y));
499
+ return a && s.push(
500
+ `v-html="${h(a.value, !0, !0, e)}"`
501
+ ), y && y.length && y.forEach((p) => {
502
+ if (!p.name) return;
503
+ let m = "", d = "";
504
+ k(p.name) ? (d = h(p.name, !0, !0, e), n.push(d)) : d = p.name;
505
+ const $ = d?.startsWith("v") ? F(d) : F("v-" + d);
506
+ if (m += $, p.arg && (k(p.arg) ? m += `:[${h(p.name, !0, !0, e)}]` : m += `:${p.arg}`), p.modifiers) {
507
+ const j = Object.keys(p.modifiers);
508
+ j.length && (m += j.map((g) => "." + g));
495
509
  }
496
- u.value ? s.push(
497
- `${m}="${f(u.value, !0, !0, e)}"`
510
+ p.value ? s.push(
511
+ `${m}="${h(p.value, !0, !0, e)}"`
498
512
  ) : s.push(m);
499
513
  }), s;
500
514
  }
501
- function Pe(t = []) {
515
+ function Ee(t = []) {
502
516
  const e = t.filter(
503
- (o) => L.includes(o.name)
517
+ (a) => L.includes(a.name)
504
518
  ), n = t.filter(
505
- (o) => !L.includes(o.name)
519
+ (a) => !L.includes(a.name)
506
520
  ), s = e.find(
507
- (o) => v(o.name) === "vIf"
521
+ (a) => v(a.name) === "vIf"
508
522
  ), r = e.find(
509
- (o) => v(o.name) === "vFor"
523
+ (a) => v(a.name) === "vElseIf"
510
524
  ), i = e.find(
511
- (o) => v(o.name) === "vShow"
525
+ (a) => v(a.name) === "vElse"
526
+ ), o = e.find(
527
+ (a) => v(a.name) === "vFor"
512
528
  ), c = e.find(
513
- (o) => v(o.name) === "vBind"
514
- ), a = e.find(
515
- (o) => v(o.name) === "vHtml"
516
- ), p = e.filter(
517
- (o) => v(o.name) === "vModel"
529
+ (a) => v(a.name) === "vShow"
530
+ ), f = e.find(
531
+ (a) => v(a.name) === "vBind"
532
+ ), l = e.find(
533
+ (a) => v(a.name) === "vHtml"
534
+ ), u = e.filter(
535
+ (a) => v(a.name) === "vModel"
518
536
  );
519
537
  return {
520
538
  vIf: s,
521
- vFor: r,
522
- vShow: i,
523
- vModels: p,
524
- vBind: c,
525
- vHtml: a,
539
+ vElseIf: r,
540
+ vElse: i,
541
+ vFor: o,
542
+ vShow: c,
543
+ vModels: u,
544
+ vBind: f,
545
+ vHtml: l,
526
546
  customDirectives: n
527
547
  };
528
548
  }
529
- function Oe(t, e, n, s, r) {
530
- return typeof t == "string" ? t : S(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? X(t, n, e, s, r) : "";
549
+ function Pe(t, e, n, s, r) {
550
+ return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? X(t, n, e, s, r) : "";
531
551
  }
532
- function xe(t, e, n) {
552
+ function Oe(t, e, n) {
533
553
  if (!t) return e;
534
554
  const s = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
535
555
  return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
536
556
  ${e}
537
557
  </template>`;
538
558
  }
539
- function Ee(t, e = [], n = [], s = {}, r = "web") {
559
+ function xe(t, e = [], n = [], s = {}, r = "web") {
540
560
  const i = [
541
561
  "@dcloudio/uni-h5",
542
562
  "uni-h5",
543
563
  "@dcloudio/uni-ui",
544
564
  "uni-ui"
545
- ], c = {
565
+ ], o = {
546
566
  vue: ["defineComponent", "reactive"]
547
- }, a = [];
548
- for (const o of e) {
549
- const l = t.get(o.split(":")[0]);
550
- if (l && l.package) {
551
- const u = c[l.package] ?? (c[l.package] = []), m = l.parent || (l.alias || "").split(".")[0] || l.name;
552
- u.push(m), r === "uniapp" && i.includes(l.package) && a.push(m);
567
+ }, c = [];
568
+ for (const l of e) {
569
+ const u = t.get(l.split(":")[0]);
570
+ if (u && u.package) {
571
+ const a = o[u.package] ?? (o[u.package] = []), y = u.parent || (u.alias || "").split(".")[0] || u.name;
572
+ a.push(y), r === "uniapp" && i.includes(u.package) && c.push(y);
553
573
  }
554
574
  }
555
- for (const [o, l] of Object.entries(s))
556
- (c[o] ?? (c[o] = [])).push(...Array.from(l)), r === "uniapp" && i.includes(o) && a.push(...Array.from(l));
575
+ for (const [l, u] of Object.entries(s))
576
+ (o[l] ?? (o[l] = [])).push(...Array.from(u)), r === "uniapp" && i.includes(l) && c.push(...Array.from(u));
557
577
  return {
558
- imports: Object.entries(c).filter(([o, l]) => r === "uniapp" ? !i.includes(o) && !!l.length : !!l.length).map(([o, l]) => `import { ${w(l).join(
578
+ imports: Object.entries(o).filter(([l, u]) => r === "uniapp" ? !i.includes(l) && !!u.length : !!u.length).map(([l, u]) => `import { ${C(u).join(
559
579
  ","
560
- )}} from '${o}';`).concat(n),
561
- uniComponents: a
580
+ )}} from '${l}';`).concat(n),
581
+ uniComponents: c
562
582
  };
563
583
  }
564
584
  function _e(t = {}) {
@@ -572,7 +592,7 @@ function _e(t = {}) {
572
592
  return e.join(`
573
593
  `);
574
594
  }
575
- function Ae(t = {}) {
595
+ function Ie(t = {}) {
576
596
  const e = [];
577
597
  return Object.entries(t).forEach(([n, s]) => {
578
598
  e.push(
@@ -580,7 +600,7 @@ function Ae(t = {}) {
580
600
  );
581
601
  }), e;
582
602
  }
583
- function Ne(t = {}) {
603
+ function Ae(t = {}) {
584
604
  const e = [];
585
605
  return Object.entries(t).forEach(([n, s]) => {
586
606
  e.push(
@@ -588,49 +608,49 @@ function Ne(t = {}) {
588
608
  );
589
609
  }), e;
590
610
  }
591
- function Fe(t, e, n = "web") {
592
- const { dsl: s } = t, r = Object.keys(s.computed || {}), i = A(s.lifeCycles, r), c = A(s.computed, r), a = he(s.watch, r), p = de(s.dataSources), { methods: o, nodes: l, components: u, importBlocks: m, directives: h } = X(
611
+ function Ne(t, e, n = "web") {
612
+ const { dsl: s } = t, r = Object.keys(s.computed || {}), i = A(s.lifeCycles, r), o = A(s.computed, r), c = he(s.watch, r), f = de(s.dataSources), { methods: l, nodes: u, components: a, importBlocks: y, directives: p } = X(
593
613
  s.nodes || [],
594
614
  e,
595
615
  r,
596
616
  t.context
597
- ), d = [...c, ...a.computed], b = A(
617
+ ), m = [...o, ...c.computed], d = A(
598
618
  {
599
- ...o,
619
+ ...l,
600
620
  ...s.methods || {}
601
621
  },
602
622
  r
603
- ), y = m.map((x) => `import ${x.name} from './${x.id}.vue';`);
604
- let { imports: F, uniComponents: g } = Ee(
623
+ ), $ = y.map((x) => `import ${x.name} from './${x.id}.vue';`);
624
+ let { imports: j, uniComponents: g } = xe(
605
625
  e,
606
- u,
607
- y,
626
+ a,
627
+ $,
608
628
  t.imports,
609
629
  n
610
630
  );
611
- const C = Object.keys({
631
+ const E = Object.keys({
612
632
  ...t.urlSchemas,
613
633
  ...t.blockPlugins
614
- }), P = Ae(t.urlSchemas), O = Ne(t.blockPlugins);
634
+ }), P = Ie(t.urlSchemas), O = Ae(t.blockPlugins);
615
635
  return {
616
636
  id: s.id,
617
637
  version: s.__VERSION__,
618
638
  name: s.name,
619
- state: le(s.state).join(","),
639
+ state: ue(s.state).join(","),
620
640
  inject: pe(s.inject).join(","),
621
641
  props: fe(s.props).join(","),
622
642
  emits: me(s.emits).join(","),
623
- watch: a.watches.join(","),
643
+ watch: c.watches.join(","),
624
644
  lifeCycles: i.join(","),
625
- computed: d.join(","),
626
- methods: [...p, ...b].join(","),
645
+ computed: m.join(","),
646
+ methods: [...f, ...d].join(","),
627
647
  imports: `
628
- ` + F.join(`
648
+ ` + j.join(`
629
649
  `),
630
- components: ae(u, g).join(","),
631
- directives: h.join(","),
650
+ components: ae(a, g).join(","),
651
+ directives: p.join(","),
632
652
  returns: t.members.join(","),
633
- template: l.join(`
653
+ template: u.join(`
634
654
  `),
635
655
  css: s.css || "",
636
656
  style: _e(t.style),
@@ -638,12 +658,12 @@ function Fe(t, e, n = "web") {
638
658
  `),
639
659
  blockPlugins: O.join(`
640
660
  `),
641
- asyncComponents: C.join(","),
661
+ asyncComponents: E.join(","),
642
662
  uniComponents: g,
643
663
  renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
644
664
  };
645
665
  }
646
- const Ie = `
666
+ const Fe = `
647
667
  // @ts-nocheck
648
668
 
649
669
  <%= imports %>
@@ -686,15 +706,15 @@ export default defineComponent({
686
706
  <%= css %>
687
707
  <%= style %>
688
708
  </style>
689
- `, Te = U(Ie), Re = U(Be);
709
+ `, Te = U(Fe), Re = U(Be);
690
710
  async function Ue(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
691
- const i = new ue(ne(t), n), c = Fe(i, e, s), a = Te(c), p = Re({
692
- template: c.template,
693
- css: await W(c.css, r),
694
- script: await ie(a, r),
695
- style: await W(c.style, r)
711
+ const i = new le(ne(t), n), o = Ne(i, e, s), c = Te(o), f = Re({
712
+ template: o.template,
713
+ css: await W(o.css, r),
714
+ script: await ie(c, r),
715
+ style: await W(o.style, r)
696
716
  });
697
- return await q(p, r).catch((o) => (o.content = p, Promise.reject(o)));
717
+ return await q(f, r).catch((l) => (l.content = f, Promise.reject(l)));
698
718
  }
699
719
  async function De(t) {
700
720
  const e = `
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.12.10",
4
+ "version": "0.12.11",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -23,10 +23,10 @@
23
23
  "dependencies": {
24
24
  "prettier": "~3.5.0",
25
25
  "@vtj/base": "~0.12.0",
26
- "@vtj/core": "~0.12.10"
26
+ "@vtj/core": "~0.12.11"
27
27
  },
28
28
  "devDependencies": {
29
- "@vtj/cli": "~0.12.1"
29
+ "@vtj/cli": "~0.12.2"
30
30
  },
31
31
  "exports": {
32
32
  ".": {
@@ -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.12.9
5
+ * @version 0.12.10
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.9";
8
+ export declare const version = "0.12.10";