@vtj/coder 0.10.1-alpha.0 → 0.10.1-alpha.2

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,22 +2,22 @@
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.1-alpha.0
5
+ * @version 0.10.1-alpha.2
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const se="0.10.1-alpha.0";/**!
7
+ */const se="0.10.1-alpha.2";/**!
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.1-alpha.0
11
+ * @version 0.10.1-alpha.2
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
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 T(t,e){return e?t:await N.format(t,{parser:"vue",...B,plugins:[ne,L,U,D]})}async function M(t,e){return e?t:await N.format(t,{parser:"babel-ts",...B,plugins:[L,U]})}async function I(t,e){return e?t:N.format(t,{parser:"scss",...B,plugins:[D]})}function j(t){return t&&t.type==="JSExpression"}function _(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function S(t){return j(t)||_(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=E(r,s),n?V(J(r)):J(r)}function E(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 ae(t=[],e=[]){return t.filter(n=>!e.includes(n))}class ce{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 a=this.dependencies.find(c=>c.library===i)?.package;a&&(this.imports[a]||(this.imports[a]=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 a of i){const c=this.collectImport(a);if(c){const p=c.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"];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(c=>c.name==="vFor");let i=new Set(Array.from(s));if(r){const{item:c="item",index:p="index"}=r.iterator||{};i=new Set([c,p,...Array.from(i)])}const a=e.slot;if(a){const c=typeof a=="string"?[]:a.params||[],p=c.length?c:[`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 le(t={}){return Object.entries(t).map(([e,n])=>{const s=m(n,!1);return`${e}:${s}`})}function ue(t=[]){return t.map(e=>`${e.name}: {
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 T(t,e){return e?t:await N.format(t,{parser:"vue",...B,plugins:[ne,L,U,D]})}async function M(t,e){return e?t:await N.format(t,{parser:"babel-ts",...B,plugins:[L,U]})}async function I(t,e){return e?t:N.format(t,{parser:"scss",...B,plugins:[D]})}function j(t){return t&&t.type==="JSExpression"}function _(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function S(t){return j(t)||_(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=E(r,s),n?V(J(r)):J(r)}function E(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}',
15
15
  default: ${m(e.default,!0,!1)}
16
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}: {}`:(S(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
17
17
  type:${e(n.type)},
18
18
  required: ${m(!!n.required,!0,!1)},
19
19
  default: ${m(n.default,!0,!1)}
20
- }`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function x(t={},e=[]){return Object.entries(t).map(([n,s])=>{let r=H(m(s,!1,!1));return r=E(r,e),r.startsWith("async")?`async ${n}${r.replace(/^async/,"")}`:`${n}${r}`})}function me(t=[],e=[]){const n=t.reduce((i,a)=>(a.id&&_(a.source)&&(i[`watcher_${a.id}`]=a.source),i),{}),s=x(n,e),r=t.map(i=>`watcher_${i.id}: {
20
+ }`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function x(t={},e=[]){return Object.entries(t).map(([n,s])=>{let r=H(m(s,!1,!1));return r=E(r,e),r.startsWith("async")?`async ${n}${r.replace(/^async/,"")}`:`${n}${r}`})}function me(t=[],e=[]){const n=t.reduce((i,c)=>(c.id&&_(c.source)&&(i[`watcher_${c.id}`]=c.source),i),{}),s=x(n,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)}
@@ -26,21 +26,21 @@
26
26
  return await mock.apply(this, args);
27
27
  }`}else{const n=_(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
28
28
  return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
29
- }`}})}const q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,n=[],s={},r){const i=[];let a={},c=[];const p=[];let o=[];return ye(t).forEach(l=>{const h=[];for(const y of l.children){let{id:v,name:g,invisible:F,from:$}=y;if(F)continue;const k=ge(g,e,$);k&&c.push(k),G($)&&o.push({id:$.id,name:g});const{props:w,events:C,handlers:P}=Se(y,v,y.props,y.events,s,n),R=ke(y.directives,n,p).join(" "),b=y.children?Ce(y.children,n,e,s,y):"";Object.assign(a,P);let O="";typeof b=="string"?O=b:(O=(b?.nodes||[]).join(`
30
- `),Object.assign(a,b?.methods||{}),c=c.concat(b?.components||[]),o=o.concat(b?.importBlocks||[]));const W=$==="@dcloudio/uni-h5"?f.kebabCase(g):X($)||Y($)?"component":g;h.push(g==="img"?`<${g} ${R} ${w} ${C} />`:`<${W} ${R} ${w} ${C}>${O?`
31
- `+O.trim():""}</${W}>`)}const d=Pe(l.slot,h.join(`
32
- `),r?.id);i.push(d)}),{nodes:i,methods:a,directives:de(p),components:f.dedupArray(c),importBlocks:f.dedupArray(o,"id")}}function de(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ye(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,r=e.get(s);r?r.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function ge(t,e,n){if(re.includes(t))return null;const s=e.get(t);if(s&&s.alias){const r=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${r}`}return G(n)||s?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,n=[]){return t==="style"?"":t==="__class"&&S(e)?`:class="${m({...e,value:E(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:S(e)?`:${t}="${m({...e,value:E(e.value,n)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function ve(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,delete e.style)}const r=t.from;return(X(r)||Y(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,a])=>$e(i,a,n))}function be(t,e,n,s,r){const i=Q(e.modifiers,!0);return r?`@${t}${i.join("")}="${n}"`:s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function je(t,e={},n={}){const s={},r=Array.from(n[t]||new Set([])),i=r.length?`({${r.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([c,p])=>{const o=p.handler.value.startsWith("this."),u=o?V(p.handler.value):`${f.camelCase(c)}_${t}${i}`;return o||(s[u]=r.length?{type:"JSFunction",value:`{
29
+ }`}})}const q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,n=[],s={},r){const i=[];let c={},a=[];const p=[];let o=[];return ye(t).forEach(u=>{const h=[];for(const y of u.children){let{id:v,name:g,invisible:F,from:$}=y;if(F)continue;const k=ge(g,e,$);k&&a.push(k),G($)&&o.push({id:$.id,name:g});const{props:w,events:C,handlers:P}=Se(y,v,y.props,y.events,s,n),R=ke(y.directives,n,p).join(" "),b=y.children?Ce(y.children,n,e,s,y):"";Object.assign(c,P);let O="";typeof b=="string"?O=b:(O=(b?.nodes||[]).join(`
30
+ `),Object.assign(c,b?.methods||{}),a=a.concat(b?.components||[]),o=o.concat(b?.importBlocks||[]));const W=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes($)?f.kebabCase(g):X($)||Y($)?"component":g;h.push(g==="img"?`<${g} ${R} ${w} ${C} />`:`<${W} ${R} ${w} ${C}>${O?`
31
+ `+O.trim():""}</${W}>`)}const d=Pe(u.slot,h.join(`
32
+ `),r?.id);i.push(d)}),{nodes:i,methods:c,directives:de(p),components:f.dedupArray(a),importBlocks:f.dedupArray(o,"id")}}function de(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ye(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,r=e.get(s);r?r.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function ge(t,e,n){if(re.includes(t))return null;const s=e.get(t);if(s&&s.alias){const r=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${r}`}return G(n)||s?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,n=[]){return t==="style"?"":t==="__class"&&S(e)?`:class="${m({...e,value:E(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:S(e)?`:${t}="${m({...e,value:E(e.value,n)})}"`:f.isPlainObject(e)?`:${t}='{${ie(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function ve(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,delete e.style)}const r=t.from;return(X(r)||Y(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,c])=>$e(i,c,n))}function be(t,e,n,s,r){const i=Q(e.modifiers,!0);return r?`@${t}${i.join("")}="${n}"`:s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function je(t,e={},n={}){const s={},r=Array.from(n[t]||new Set([])),i=r.length?`({${r.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,p])=>{const o=p.handler.value.startsWith("this."),l=o?V(p.handler.value):`${f.camelCase(a)}_${t}${i}`;return o||(s[l]=r.length?{type:"JSFunction",value:`{
33
33
  return (${p.handler.value}).apply(this, args);
34
- }`}:p.handler),be(c,p,u,r,o)}),handlers:s}}function Se(t,e,n={},s={},r={},i){const{binders:a,handlers:c}=je(e,s,r);return{props:ve(t,n,i).join(" "),handlers:c,binders:a,events:a.join(" ")}}function ke(t=[],e=[],n=[]){const s=[],{vIf:r,vShow:i,vModels:a,vFor:c,vBind:p,vHtml:o,customDirectives:u}=we(t);if(r&&s.push(`v-if="${m(r.value,!0,!0,e)}"`),i&&s.push(`v-show="${m(i.value,!0,!0,e)}"`),p&&s.push(`v-bind="${m(p.value,!0,!0,e)}"`),a.forEach(l=>{const h=Q(l.modifiers,!0),d=l.arg?j(l.arg)?`:[${m(l.arg,!0,!0,e)}]`:`:${l.arg}`:"";s.push(`v-model${d}${h}="${m(l.value,!0,!0,e)}"`)}),c){const{item:l,index:h}={item:"item",index:"index",...c.iterator};s.push(`v-for="(${l}, ${h}) in ${m(c.value,!0,!0,e)}"`)}return o&&s.push(`v-html="${m(o.value,!0,!0,e)}"`),u&&u.length&&u.forEach(l=>{if(!l.name)return;let h="",d="";j(l.name)?(d=m(l.name,!0,!0,e),n.push(d)):d=l.name;const y=d?.startsWith("v")?f.kebabCase(d):f.kebabCase("v-"+d);if(h+=y,l.arg&&(j(l.arg)?h+=`:[${m(l.name,!0,!0,e)}]`:h+=`:${l.arg}`),l.modifiers){const v=Object.keys(l.modifiers);v.length&&(h+=v.map(g=>"."+g))}l.value?s.push(`${h}="${m(l.value,!0,!0,e)}"`):s.push(h)}),s}function we(t=[]){const e=t.filter(o=>q.includes(o.name)),n=t.filter(o=>!q.includes(o.name)),s=e.find(o=>f.camelCase(o.name)==="vIf"),r=e.find(o=>f.camelCase(o.name)==="vFor"),i=e.find(o=>f.camelCase(o.name)==="vShow"),a=e.find(o=>f.camelCase(o.name)==="vBind"),c=e.find(o=>f.camelCase(o.name)==="vHtml"),p=e.filter(o=>f.camelCase(o.name)==="vModel");return{vIf:s,vFor:r,vShow:i,vModels:p,vBind:a,vHtml:c,customDirectives:n}}function Ce(t,e,n,s,r){return typeof t=="string"?t:j(t)?`{{ ${m(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,n,e,s,r):""}function Pe(t,e,n){if(!t)return e;const s=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${s.name}="${s.params?.length>0?`{${s.params?.join(",")}}`:`scope_${n}`}"`}>
34
+ }`}:p.handler),be(a,p,l,r,o)}),handlers:s}}function Se(t,e,n={},s={},r={},i){const{binders:c,handlers:a}=je(e,s,r);return{props:ve(t,n,i).join(" "),handlers:a,binders:c,events:c.join(" ")}}function ke(t=[],e=[],n=[]){const s=[],{vIf:r,vShow:i,vModels:c,vFor:a,vBind:p,vHtml:o,customDirectives:l}=we(t);if(r&&s.push(`v-if="${m(r.value,!0,!0,e)}"`),i&&s.push(`v-show="${m(i.value,!0,!0,e)}"`),p&&s.push(`v-bind="${m(p.value,!0,!0,e)}"`),c.forEach(u=>{const h=Q(u.modifiers,!0),d=u.arg?j(u.arg)?`:[${m(u.arg,!0,!0,e)}]`:`:${u.arg}`:"";s.push(`v-model${d}${h}="${m(u.value,!0,!0,e)}"`)}),a){const{item:u,index:h}={item:"item",index:"index",...a.iterator};s.push(`v-for="(${u}, ${h}) in ${m(a.value,!0,!0,e)}"`)}return o&&s.push(`v-html="${m(o.value,!0,!0,e)}"`),l&&l.length&&l.forEach(u=>{if(!u.name)return;let h="",d="";j(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&&(j(u.arg)?h+=`:[${m(u.name,!0,!0,e)}]`:h+=`:${u.arg}`),u.modifiers){const v=Object.keys(u.modifiers);v.length&&(h+=v.map(g=>"."+g))}u.value?s.push(`${h}="${m(u.value,!0,!0,e)}"`):s.push(h)}),s}function we(t=[]){const e=t.filter(o=>q.includes(o.name)),n=t.filter(o=>!q.includes(o.name)),s=e.find(o=>f.camelCase(o.name)==="vIf"),r=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:s,vFor:r,vShow:i,vModels:p,vBind:c,vHtml:a,customDirectives:n}}function Ce(t,e,n,s,r){return typeof t=="string"?t:j(t)?`{{ ${m(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,n,e,s,r):""}function Pe(t,e,n){if(!t)return e;const s=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${s.name}="${s.params?.length>0?`{${s.params?.join(",")}}`:`scope_${n}`}"`}>
35
35
  ${e}
36
- </template>`}function Oe(t,e=[],n=[],s={},r="web"){const i=["@dcloudio/uni-h5","uni-h5"],a={vue:["defineComponent","reactive"]},c=[];for(const o of e){const u=t.get(o.split(":")[0]);if(u&&u.package){const l=a[u.package]??(a[u.package]=[]),h=u.parent||(u.alias||"").split(".")[0]||u.name;l.push(h),r==="uniapp"&&i.includes(u.package)&&c.push(h)}}for(const[o,u]of Object.entries(s))(a[o]??(a[o]=[])).push(...Array.from(u)),r==="uniapp"&&i.includes(o)&&c.push(...Array.from(u));return{imports:Object.entries(a).filter(([o,u])=>r==="uniapp"?!i.includes(o)&&!!u.length:!!u.length).map(([o,u])=>`import { ${f.dedupArray(u).join(",")}} from '${o}';`).concat(n),uniComponents:c}}function xe(t={}){const e=[];for(const[n,s]of Object.entries(t))e.push(`
36
+ </template>`}function Oe(t,e=[],n=[],s={},r="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),r==="uniapp"&&i.includes(l.package)&&a.push(h)}}for(const[o,l]of Object.entries(s))(c[o]??(c[o]=[])).push(...Array.from(l)),r==="uniapp"&&i.includes(o)&&a.push(...Array.from(l));return{imports:Object.entries(c).filter(([o,l])=>r==="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,s]of Object.entries(t))e.push(`
37
37
  ${n} {
38
38
  ${oe(s)}
39
39
  }
40
40
  `);return e.join(`
41
- `)}function _e(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Ee(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Ae(t,e,n="web"){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=x(s.lifeCycles,r),a=x(s.computed,r),c=me(s.watch,r),p=he(s.dataSources),{methods:o,nodes:u,components:l,importBlocks:h,directives:d}=z(s.nodes||[],e,r,t.context),y=[...a,...c.computed],v=x({...o,...s.methods||{}},r),g=h.map(P=>`import ${P.name} from './${P.id}.vue';`);let{imports:F,uniComponents:$}=Oe(e,l,g,t.imports,n);const k=Object.keys({...t.urlSchemas,...t.blockPlugins}),w=_e(t.urlSchemas),C=Ee(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:le(s.state).join(","),inject:ue(s.inject).join(","),props:pe(s.props).join(","),emits:fe(s.emits).join(","),watch:c.watches.join(","),lifeCycles:i.join(","),computed:y.join(","),methods:[...p,...v].join(","),imports:`
41
+ `)}function _e(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Ee(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Ae(t,e,n="web"){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=x(s.lifeCycles,r),c=x(s.computed,r),a=me(s.watch,r),p=he(s.dataSources),{methods:o,nodes:l,components:u,importBlocks:h,directives:d}=z(s.nodes||[],e,r,t.context),y=[...c,...a.computed],v=x({...o,...s.methods||{}},r),g=h.map(P=>`import ${P.name} from './${P.id}.vue';`);let{imports:F,uniComponents:$}=Oe(e,u,g,t.imports,n);const k=Object.keys({...t.urlSchemas,...t.blockPlugins}),w=_e(t.urlSchemas),C=Ee(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ue(s.state).join(","),inject:le(s.inject).join(","),props:pe(s.props).join(","),emits:fe(s.emits).join(","),watch:a.watches.join(","),lifeCycles:i.join(","),computed:y.join(","),methods:[...p,...v].join(","),imports:`
42
42
  `+F.join(`
43
- `),components:ae(l,$).join(","),directives:d.join(","),returns:t.members.join(","),template:u.join(`
43
+ `),components:ce(u,$).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
46
  `),asyncComponents:k.join(","),uniComponents:$}}const Fe=`
@@ -86,7 +86,7 @@ export default defineComponent({
86
86
  <%= css %>
87
87
  <%= style %>
88
88
  </style>
89
- `,Ne=f.template(Fe),Be=f.template(Ie);async function Te(t,e=new Map,n=[],s="web",r){const i=new ce(f.cloneDeep(t),n),a=Ae(i,e,s),c=Ne(a),p=Be({template:a.template,css:await I(a.css,r),script:await M(c,r),style:await I(a.style,r)});return await T(p,r).catch(o=>(o.content=p,Promise.reject(o)))}async function Re(t){const e=`
89
+ `,Ne=f.template(Fe),Be=f.template(Ie);async function Te(t,e=new Map,n=[],s="web",r){const i=new ae(f.cloneDeep(t),n),c=Ae(i,e,s),a=Ne(c),p=Be({template:c.template,css:await I(c.css,r),script:await M(a,r),style:await I(c.style,r)});return await T(p,r).catch(o=>(o.content=p,Promise.reject(o)))}async function Re(t){const e=`
90
90
  <template>
91
91
  <div>
92
92
  <h3>源码模式页面</h3>
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.1-alpha.0
11
+ * @version 0.10.1-alpha.2
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Je = "0.10.1-alpha.0";
14
+ const Je = "0.10.1-alpha.2";
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.1-alpha.0
19
+ * @version 0.10.1-alpha.2
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, n = !0, s = []) {
92
+ function f(t, e = !0, s = !0, n = []) {
93
93
  let r = k(t) ? t.value : e ? JSON.stringify(t) : t;
94
- return r = A(r, s), n ? q(J(r)) : J(r);
94
+ return r = A(r, n), s ? q(J(r)) : J(r);
95
95
  }
96
96
  function A(t, e = []) {
97
- let n = t;
98
- for (const s of e)
99
- n = n.replace(
100
- new RegExp(`this.${s}.value`, "g"),
101
- `this.${s}`
97
+ let s = t;
98
+ for (const n of e)
99
+ s = s.replace(
100
+ new RegExp(`this.${n}.value`, "g"),
101
+ `this.${n}`
102
102
  );
103
- return n;
103
+ return s;
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, n]) => `"${e}": ${f(n)}`);
119
+ return Object.entries(t).map(([e, s]) => `"${e}": ${f(s)}`);
120
120
  }
121
121
  function z(t = {}, e = !1) {
122
- const n = Object.keys(t);
123
- return e ? n.map((s) => "." + s) : n;
122
+ const s = Object.keys(t);
123
+ return e ? s.map((n) => "." + n) : s;
124
124
  }
125
125
  function ce(t) {
126
126
  let e = "";
127
- for (var n in t)
128
- if (t.hasOwnProperty(n)) {
129
- var s = t[n];
130
- e += n + ": " + s + ";";
127
+ for (var s in t)
128
+ if (t.hasOwnProperty(s)) {
129
+ var n = t[s];
130
+ e += s + ": " + n + ";";
131
131
  }
132
132
  return e;
133
133
  }
134
134
  function ae(t = [], e = []) {
135
- return t.filter((n) => !e.includes(n));
135
+ return t.filter((s) => !e.includes(s));
136
136
  }
137
- class le {
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();
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();
140
140
  }
141
141
  /**
142
142
  * { 'element-plus': ['ElButton', 'ElInput' ...] }
@@ -157,17 +157,17 @@ class le {
157
157
  * @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
158
158
  */
159
159
  collectImport(e) {
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) {
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) {
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(s);
167
+ c && (this.imports[c] || (this.imports[c] = /* @__PURE__ */ new Set())).add(n);
168
168
  }
169
169
  return {
170
- name: s,
170
+ name: n,
171
171
  path: r,
172
172
  library: i
173
173
  };
@@ -176,52 +176,52 @@ class le {
176
176
  }
177
177
  // 代码中包含依赖库的引用,需要从代码中移除
178
178
  replaceLibraryPath(e) {
179
- const { libraryRegex: n } = this;
180
- let s = e.value;
181
- for (const r of n) {
179
+ const { libraryRegex: s } = this;
180
+ let n = e.value;
181
+ for (const r of s) {
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
- s = s.replace(new RegExp(p, "g"), "");
187
+ n = n.replace(new RegExp(p, "g"), "");
188
188
  }
189
189
  }
190
190
  }
191
- return s;
191
+ return n;
192
192
  }
193
193
  walk(e) {
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);
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);
199
199
  return;
200
200
  }
201
- const r = Object.values(s);
201
+ const r = Object.values(n);
202
202
  for (const i of r)
203
- k(i) ? i.value = this.replaceLibraryPath(i) : n(i);
203
+ k(i) ? i.value = this.replaceLibraryPath(i) : s(i);
204
204
  };
205
- n(e);
205
+ s(e);
206
206
  }
207
207
  getLibraryMember(e = []) {
208
- let n = [...e];
209
- const s = { ...this.imports };
210
- delete s["uni-h5"], delete s["@dcloudio/uni-h5"];
211
- for (const r of Object.values(s))
212
- n = n.concat(Array.from(r));
213
- return S(n);
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);
214
214
  }
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));
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));
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_${n?.id}`];
224
+ const a = typeof c == "string" ? [] : c.params || [], p = a.length ? a : [`scope_${s?.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 le {
236
236
  typeof e.from == "object" && e.from.type === "Plugin" && (this.blockPlugins[e.name] = e.from);
237
237
  }
238
238
  walkNodes(e) {
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));
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));
241
241
  };
242
- Array.isArray(e.nodes) && e.nodes.forEach((s) => n(s));
242
+ Array.isArray(e.nodes) && e.nodes.forEach((n) => s(n));
243
243
  }
244
244
  }
245
- function ue(t = {}) {
246
- return Object.entries(t).map(([e, n]) => {
247
- const s = f(n, !1);
248
- return `${e}:${s}`;
245
+ function le(t = {}) {
246
+ return Object.entries(t).map(([e, s]) => {
247
+ const n = f(s, !1);
248
+ return `${e}:${n}`;
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 = (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)}
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)}
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 E(t = {}, e = []) {
269
- return Object.entries(t).map(([n, s]) => {
270
- let r = Q(f(s, !1, !1));
271
- return r = A(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
269
+ return Object.entries(t).map(([s, n]) => {
270
+ let r = Q(f(n, !1, !1));
271
+ return r = A(r, e), r.startsWith("async") ? `async ${s}${r.replace(/^async/, "")}` : `${s}${r}`;
272
272
  });
273
273
  }
274
274
  function he(t = [], e = []) {
275
- const n = t.reduce(
275
+ const s = t.reduce(
276
276
  (i, c) => (c.id && _(c.source) && (i[`watcher_${c.id}`] = c.source), i),
277
277
  {}
278
- ), s = E(n, e), r = t.map((i) => `watcher_${i.id}: {
278
+ ), n = E(s, 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: s,
284
+ computed: n,
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 n = _(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
291
+ const s = _(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
292
292
  return `async ${e.name}(...args:any[]) {
293
- const mock = this.provider.createMock(${n})
293
+ const mock = this.provider.createMock(${s})
294
294
  return await mock.apply(this, args);
295
295
  }`;
296
296
  } else {
297
- const n = _(e.transform) && e.transform.value || "(res) => res";
297
+ const s = _(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(${n});
299
+ return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
300
300
  }`;
301
301
  }
302
302
  });
@@ -309,14 +309,14 @@ const L = [
309
309
  "vBind",
310
310
  "vHtml"
311
311
  ];
312
- function G(t, e, n = [], s = {}, r) {
312
+ function G(t, e, s = [], n = {}, r) {
313
313
  const i = [];
314
314
  let c = {}, a = [];
315
315
  const p = [];
316
316
  let o = [];
317
- return ge(t).forEach((l) => {
317
+ return ge(t).forEach((u) => {
318
318
  const m = [];
319
- for (const d of l.children) {
319
+ for (const d of u.children) {
320
320
  let { id: v, name: y, invisible: F, from: g } = d;
321
321
  if (F)
322
322
  continue;
@@ -327,30 +327,32 @@ function G(t, e, n = [], s = {}, r) {
327
327
  v,
328
328
  d.props,
329
329
  d.events,
330
- s,
331
- n
330
+ n,
331
+ s
332
332
  ), R = we(
333
333
  d.directives,
334
- n,
334
+ s,
335
335
  p
336
336
  ).join(" "), b = d.children ? Pe(
337
337
  d.children,
338
- n,
339
- e,
340
338
  s,
339
+ e,
340
+ n,
341
341
  d
342
342
  ) : "";
343
343
  Object.assign(c, x);
344
344
  let O = "";
345
345
  typeof b == "string" ? O = b : (O = (b?.nodes || []).join(`
346
346
  `), Object.assign(c, b?.methods || {}), a = a.concat(b?.components || []), o = o.concat(b?.importBlocks || []));
347
- const T = g === "@dcloudio/uni-h5" ? I(y) : Y(g) || Z(g) ? "component" : y;
347
+ const T = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
348
+ g
349
+ ) ? I(y) : Y(g) || Z(g) ? "component" : y;
348
350
  m.push(
349
351
  y === "img" ? `<${y} ${R} ${C} ${P} />` : `<${T} ${R} ${C} ${P}>${O ? `
350
352
  ` + O.trim() : ""}</${T}>`
351
353
  );
352
354
  }
353
- const h = xe(l.slot, m.join(`
355
+ const h = xe(u.slot, m.join(`
354
356
  `), r?.id);
355
357
  i.push(h);
356
358
  }), {
@@ -366,20 +368,20 @@ function ye(t) {
366
368
  }
367
369
  function ge(t = []) {
368
370
  const e = /* @__PURE__ */ new Map();
369
- for (const n of t) {
370
- const s = typeof n.slot == "string" ? n.slot : n.slot?.name, r = e.get(s);
371
- r ? r.children.push(n) : e.set(s, { slot: n.slot, children: [n] });
371
+ for (const s of t) {
372
+ const n = typeof s.slot == "string" ? s.slot : s.slot?.name, r = e.get(n);
373
+ r ? r.children.push(s) : e.set(n, { slot: s.slot, children: [s] });
372
374
  }
373
375
  return e;
374
376
  }
375
- function $e(t, e, n) {
377
+ function $e(t, e, s) {
376
378
  if (re.includes(t)) return null;
377
- const s = e.get(t);
378
- if (s && s.alias) {
379
- const r = s.parent ? `${s.parent}.${s.alias}` : s.alias;
379
+ const n = e.get(t);
380
+ if (n && n.alias) {
381
+ const r = n.parent ? `${n.parent}.${n.alias}` : n.alias;
380
382
  return `${t}: ${r}`;
381
383
  }
382
- return X(n) || s ? t : null;
384
+ return X(s) || n ? t : null;
383
385
  }
384
386
  function X(t) {
385
387
  return !!t && typeof t == "object" && t.type === "Schema";
@@ -390,18 +392,18 @@ function Y(t) {
390
392
  function Z(t) {
391
393
  return typeof t == "object" && t.type === "Plugin";
392
394
  }
393
- function ve(t, e, n = []) {
395
+ function ve(t, e, s = []) {
394
396
  return t === "style" ? "" : t === "__class" && k(e) ? `:class="${f({
395
397
  ...e,
396
- value: A(e.value, n)
398
+ value: A(e.value, s)
397
399
  })}"` : typeof e == "string" ? `${t}="${e}"` : k(e) ? `:${t}="${f({
398
400
  ...e,
399
- value: A(e.value, n)
401
+ value: A(e.value, s)
400
402
  })}"` : te(e) ? `:${t}='{${oe(
401
403
  e
402
404
  ).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
403
405
  }
404
- function be(t, e = {}, n = []) {
406
+ function be(t, e = {}, s = []) {
405
407
  if (!!Object.keys(e.style || {}).length) {
406
408
  const i = `${t.name}_${t.id}`;
407
409
  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);
@@ -410,75 +412,75 @@ function be(t, e = {}, n = []) {
410
412
  return (Y(r) || Z(r)) && (e.is = {
411
413
  type: "JSExpression",
412
414
  value: t.name
413
- }), Object.entries(e).map(([i, c]) => ve(i, c, n));
415
+ }), Object.entries(e).map(([i, c]) => ve(i, c, s));
414
416
  }
415
- function je(t, e, n, s, r) {
417
+ function je(t, e, s, n, r) {
416
418
  const i = z(e.modifiers, !0);
417
- return r ? `@${t}${i.join("")}="${n}"` : s && s.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${n}"` : `@${t}${i.join("")}="${n}"`;
419
+ return r ? `@${t}${i.join("")}="${s}"` : n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${s}"` : `@${t}${i.join("")}="${s}"`;
418
420
  }
419
- function Se(t, e = {}, n = {}) {
420
- const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
421
+ function Se(t, e = {}, s = {}) {
422
+ const n = {}, r = Array.from(s[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
421
423
  return {
422
424
  binders: Object.entries(e).map(([a, p]) => {
423
- const o = p.handler.value.startsWith("this."), u = o ? q(p.handler.value) : `${$(a)}_${t}${i}`;
424
- return o || (s[u] = r.length ? {
425
+ const o = p.handler.value.startsWith("this."), l = o ? q(p.handler.value) : `${$(a)}_${t}${i}`;
426
+ return o || (n[l] = r.length ? {
425
427
  type: "JSFunction",
426
428
  value: `{
427
429
  return (${p.handler.value}).apply(this, args);
428
430
  }`
429
- } : p.handler), je(a, p, u, r, o);
431
+ } : p.handler), je(a, p, l, r, o);
430
432
  }),
431
- handlers: s
433
+ handlers: n
432
434
  };
433
435
  }
434
- function ke(t, e, n = {}, s = {}, r = {}, i) {
435
- const { binders: c, handlers: a } = Se(e, s, r);
436
+ function ke(t, e, s = {}, n = {}, r = {}, i) {
437
+ const { binders: c, handlers: a } = Se(e, n, r);
436
438
  return {
437
- props: be(t, n, i).join(" "),
439
+ props: be(t, s, i).join(" "),
438
440
  handlers: a,
439
441
  binders: c,
440
442
  events: c.join(" ")
441
443
  };
442
444
  }
443
- function we(t = [], e = [], n = []) {
444
- const s = [], { vIf: r, vShow: i, vModels: c, vFor: a, vBind: p, vHtml: o, customDirectives: u } = Ce(t);
445
- if (r && s.push(`v-if="${f(r.value, !0, !0, e)}"`), i && s.push(
445
+ function we(t = [], e = [], s = []) {
446
+ const n = [], { vIf: r, vShow: i, vModels: c, vFor: a, vBind: p, vHtml: o, customDirectives: l } = Ce(t);
447
+ if (r && n.push(`v-if="${f(r.value, !0, !0, e)}"`), i && n.push(
446
448
  `v-show="${f(i.value, !0, !0, e)}"`
447
- ), p && s.push(
449
+ ), p && n.push(
448
450
  `v-bind="${f(p.value, !0, !0, e)}"`
449
- ), c.forEach((l) => {
450
- const m = z(l.modifiers, !0), h = l.arg ? j(l.arg) ? `:[${f(l.arg, !0, !0, e)}]` : `:${l.arg}` : "";
451
- s.push(
452
- `v-model${h}${m}="${f(l.value, !0, !0, e)}"`
451
+ ), c.forEach((u) => {
452
+ const m = z(u.modifiers, !0), h = u.arg ? j(u.arg) ? `:[${f(u.arg, !0, !0, e)}]` : `:${u.arg}` : "";
453
+ n.push(
454
+ `v-model${h}${m}="${f(u.value, !0, !0, e)}"`
453
455
  );
454
456
  }), a) {
455
- const { item: l, index: m } = { item: "item", index: "index", ...a.iterator };
456
- s.push(
457
- `v-for="(${l}, ${m}) in ${f(a.value, !0, !0, e)}"`
457
+ const { item: u, index: m } = { item: "item", index: "index", ...a.iterator };
458
+ n.push(
459
+ `v-for="(${u}, ${m}) in ${f(a.value, !0, !0, e)}"`
458
460
  );
459
461
  }
460
- return o && s.push(
462
+ return o && n.push(
461
463
  `v-html="${f(o.value, !0, !0, e)}"`
462
- ), u && u.length && u.forEach((l) => {
463
- if (!l.name) return;
464
+ ), l && l.length && l.forEach((u) => {
465
+ if (!u.name) return;
464
466
  let m = "", h = "";
465
- j(l.name) ? (h = f(l.name, !0, !0, e), n.push(h)) : h = l.name;
467
+ j(u.name) ? (h = f(u.name, !0, !0, e), s.push(h)) : h = u.name;
466
468
  const d = h?.startsWith("v") ? I(h) : I("v-" + h);
467
- if (m += d, l.arg && (j(l.arg) ? m += `:[${f(l.name, !0, !0, e)}]` : m += `:${l.arg}`), l.modifiers) {
468
- const v = Object.keys(l.modifiers);
469
+ if (m += d, u.arg && (j(u.arg) ? m += `:[${f(u.name, !0, !0, e)}]` : m += `:${u.arg}`), u.modifiers) {
470
+ const v = Object.keys(u.modifiers);
469
471
  v.length && (m += v.map((y) => "." + y));
470
472
  }
471
- l.value ? s.push(
472
- `${m}="${f(l.value, !0, !0, e)}"`
473
- ) : s.push(m);
474
- }), s;
473
+ u.value ? n.push(
474
+ `${m}="${f(u.value, !0, !0, e)}"`
475
+ ) : n.push(m);
476
+ }), n;
475
477
  }
476
478
  function Ce(t = []) {
477
479
  const e = t.filter(
478
480
  (o) => L.includes(o.name)
479
- ), n = t.filter(
481
+ ), s = t.filter(
480
482
  (o) => !L.includes(o.name)
481
- ), s = e.find(
483
+ ), n = e.find(
482
484
  (o) => $(o.name) === "vIf"
483
485
  ), r = e.find(
484
486
  (o) => $(o.name) === "vFor"
@@ -492,51 +494,56 @@ function Ce(t = []) {
492
494
  (o) => $(o.name) === "vModel"
493
495
  );
494
496
  return {
495
- vIf: s,
497
+ vIf: n,
496
498
  vFor: r,
497
499
  vShow: i,
498
500
  vModels: p,
499
501
  vBind: c,
500
502
  vHtml: a,
501
- customDirectives: n
503
+ customDirectives: s
502
504
  };
503
505
  }
504
- function Pe(t, e, n, s, r) {
505
- return typeof t == "string" ? t : j(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? G(t, n, e, s, r) : "";
506
+ function Pe(t, e, s, n, r) {
507
+ return typeof t == "string" ? t : j(t) ? `{{ ${f(t, !1, !0, e)} }}` : Array.isArray(t) ? G(t, s, e, n, r) : "";
506
508
  }
507
- function xe(t, e, n) {
509
+ function xe(t, e, s) {
508
510
  if (!t) return e;
509
- const s = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
510
- return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
511
+ const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
512
+ return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${s}`}"`}>
511
513
  ${e}
512
514
  </template>`;
513
515
  }
514
- function Oe(t, e = [], n = [], s = {}, r = "web") {
515
- const i = ["@dcloudio/uni-h5", "uni-h5"], c = {
516
+ function Oe(t, e = [], s = [], n = {}, r = "web") {
517
+ const i = [
518
+ "@dcloudio/uni-h5",
519
+ "uni-h5",
520
+ "@dcloudio/uni-ui",
521
+ "uni-ui"
522
+ ], c = {
516
523
  vue: ["defineComponent", "reactive"]
517
524
  }, a = [];
518
525
  for (const o of e) {
519
- const u = t.get(o.split(":")[0]);
520
- if (u && u.package) {
521
- const l = c[u.package] ?? (c[u.package] = []), m = u.parent || (u.alias || "").split(".")[0] || u.name;
522
- l.push(m), r === "uniapp" && i.includes(u.package) && a.push(m);
526
+ const l = t.get(o.split(":")[0]);
527
+ if (l && l.package) {
528
+ const u = c[l.package] ?? (c[l.package] = []), m = l.parent || (l.alias || "").split(".")[0] || l.name;
529
+ u.push(m), r === "uniapp" && i.includes(l.package) && a.push(m);
523
530
  }
524
531
  }
525
- for (const [o, u] of Object.entries(s))
526
- (c[o] ?? (c[o] = [])).push(...Array.from(u)), r === "uniapp" && i.includes(o) && a.push(...Array.from(u));
532
+ for (const [o, l] of Object.entries(n))
533
+ (c[o] ?? (c[o] = [])).push(...Array.from(l)), r === "uniapp" && i.includes(o) && a.push(...Array.from(l));
527
534
  return {
528
- imports: Object.entries(c).filter(([o, u]) => r === "uniapp" ? !i.includes(o) && !!u.length : !!u.length).map(([o, u]) => `import { ${S(u).join(
535
+ imports: Object.entries(c).filter(([o, l]) => r === "uniapp" ? !i.includes(o) && !!l.length : !!l.length).map(([o, l]) => `import { ${S(l).join(
529
536
  ","
530
- )}} from '${o}';`).concat(n),
537
+ )}} from '${o}';`).concat(s),
531
538
  uniComponents: a
532
539
  };
533
540
  }
534
541
  function Ee(t = {}) {
535
542
  const e = [];
536
- for (const [n, s] of Object.entries(t))
543
+ for (const [s, n] of Object.entries(t))
537
544
  e.push(`
538
- ${n} {
539
- ${ce(s)}
545
+ ${s} {
546
+ ${ce(n)}
540
547
  }
541
548
  `);
542
549
  return e.join(`
@@ -544,52 +551,52 @@ function Ee(t = {}) {
544
551
  }
545
552
  function _e(t = {}) {
546
553
  const e = [];
547
- return Object.entries(t).forEach(([n, s]) => {
554
+ return Object.entries(t).forEach(([s, n]) => {
548
555
  e.push(
549
- `const ${n} = provider.defineUrlSchemaComponent('${s.url}');`
556
+ `const ${s} = provider.defineUrlSchemaComponent('${n.url}');`
550
557
  );
551
558
  }), e;
552
559
  }
553
560
  function Ae(t = {}) {
554
561
  const e = [];
555
- return Object.entries(t).forEach(([n, s]) => {
562
+ return Object.entries(t).forEach(([s, n]) => {
556
563
  e.push(
557
- `const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`
564
+ `const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`
558
565
  );
559
566
  }), e;
560
567
  }
561
- function Fe(t, e, n = "web") {
562
- const { dsl: s } = t, r = Object.keys(s.computed || {}), i = E(s.lifeCycles, r), c = E(s.computed, r), a = he(s.watch, r), p = de(s.dataSources), { methods: o, nodes: u, components: l, importBlocks: m, directives: h } = G(
563
- s.nodes || [],
568
+ function Fe(t, e, s = "web") {
569
+ const { dsl: n } = t, r = Object.keys(n.computed || {}), i = E(n.lifeCycles, r), c = E(n.computed, r), a = he(n.watch, r), p = de(n.dataSources), { methods: o, nodes: l, components: u, importBlocks: m, directives: h } = G(
570
+ n.nodes || [],
564
571
  e,
565
572
  r,
566
573
  t.context
567
574
  ), d = [...c, ...a.computed], v = E(
568
575
  {
569
576
  ...o,
570
- ...s.methods || {}
577
+ ...n.methods || {}
571
578
  },
572
579
  r
573
580
  ), y = m.map((x) => `import ${x.name} from './${x.id}.vue';`);
574
581
  let { imports: F, uniComponents: g } = Oe(
575
582
  e,
576
- l,
583
+ u,
577
584
  y,
578
585
  t.imports,
579
- n
586
+ s
580
587
  );
581
588
  const w = Object.keys({
582
589
  ...t.urlSchemas,
583
590
  ...t.blockPlugins
584
591
  }), C = _e(t.urlSchemas), P = Ae(t.blockPlugins);
585
592
  return {
586
- id: s.id,
587
- version: s.__VERSION__,
588
- name: s.name,
589
- state: ue(s.state).join(","),
590
- inject: pe(s.inject).join(","),
591
- props: fe(s.props).join(","),
592
- emits: me(s.emits).join(","),
593
+ id: n.id,
594
+ version: n.__VERSION__,
595
+ name: n.name,
596
+ state: le(n.state).join(","),
597
+ inject: pe(n.inject).join(","),
598
+ props: fe(n.props).join(","),
599
+ emits: me(n.emits).join(","),
593
600
  watch: a.watches.join(","),
594
601
  lifeCycles: i.join(","),
595
602
  computed: d.join(","),
@@ -597,12 +604,12 @@ function Fe(t, e, n = "web") {
597
604
  imports: `
598
605
  ` + F.join(`
599
606
  `),
600
- components: ae(l, g).join(","),
607
+ components: ae(u, g).join(","),
601
608
  directives: h.join(","),
602
609
  returns: t.members.join(","),
603
- template: u.join(`
610
+ template: l.join(`
604
611
  `),
605
- css: s.css || "",
612
+ css: n.css || "",
606
613
  style: Ee(t.style),
607
614
  urlSchemas: C.join(`
608
615
  `),
@@ -656,8 +663,8 @@ export default defineComponent({
656
663
  <%= style %>
657
664
  </style>
658
665
  `, Ne = U(Ie), Re = U(Be);
659
- async function Le(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
660
- const i = new le(ne(t), n), c = Fe(i, e, s), a = Ne(c), p = Re({
666
+ async function Le(t, e = /* @__PURE__ */ new Map(), s = [], n = "web", r) {
667
+ const i = new ue(ne(t), s), c = Fe(i, e, n), a = Ne(c), p = Re({
661
668
  template: c.template,
662
669
  css: await W(c.css, r),
663
670
  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.1-alpha.0",
4
+ "version": "0.10.1-alpha.2",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "prettier": "~3.4.0",
8
8
  "@vtj/base": "~0.10.0",
9
- "@vtj/core": "~0.10.1-alpha.0"
9
+ "@vtj/core": "~0.10.1-alpha.2"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@vtj/cli": "~0.10.0"
@@ -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.0
5
+ * @version 0.10.1-alpha.1
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.10.0";
8
+ export declare const version = "0.10.1-alpha.1";