@vtj/coder 0.12.6 → 0.12.8

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,15 +2,15 @@
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.6
5
+ * @version 0.12.8
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const re="0.12.6";/**!
7
+ */const re="0.12.8";/**!
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.6
11
+ * @version 0.12.8
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 M(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 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,r=[]){let s=v(t)?t.value.trim().replace(/\"/g,"'").replace(/;$/,""):e?JSON.stringify(t):t;return s=k(s,r),n?V(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 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}: {
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}: {}`:(v(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
@@ -26,24 +26,24 @@
26
26
  return await mock.apply(this, args);
27
27
  }`}else{const n=A(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 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:$,invisible:N,from:g}=y;if(N)continue;const w=$e($,e,g);w&&a.push(w),G(g)&&o.push({id:g.id,name:$});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(g)?f.kebabCase($):X(g)||Y(g)?"component":$;h.push(de.includes(x)?`<${x} ${W} ${C} ${P} />`:`<${x} ${W} ${C} ${P}>${_?`
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
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?V(p.handler.value):`${f.camelCase(a)}_${t}${i}`;return o||(r[l]=s.length?{type:"JSFunction",value:`{
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
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($=>"."+$))}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}`}"`}>
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}`}"`}>
35
35
  ${e}
36
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
37
  ${n} {
38
38
  ${oe(r)}
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),$=h.map(O=>`import ${O.name} from './${O.id}.vue';`);let{imports:N,uniComponents:g}=_e(e,u,$,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:`
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
42
  `+N.join(`
43
- `),components:ce(u,g).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
43
+ `),components:ce(u,$).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
44
44
  `),css:r.css||"",style:xe(t.style),urlSchemas:C.join(`
45
45
  `),blockPlugins:P.join(`
46
- `),asyncComponents:w.join(","),uniComponents:g,renderer:n==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
46
+ `),asyncComponents:w.join(","),uniComponents:$,renderer:n==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
47
47
  // @ts-nocheck
48
48
 
49
49
  <%= imports %>
@@ -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 M(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=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=`
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=M;exports.vueFormatter=R;
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;
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.12.6
11
+ * @version 0.12.8
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Le = "0.12.6";
14
+ const Le = "0.12.8";
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.6
19
+ * @version 0.12.8
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const re = [
@@ -53,7 +53,7 @@ const T = {
53
53
  useTabs: !1,
54
54
  vueIndentScriptAndStyle: !0
55
55
  };
56
- async function M(t, e) {
56
+ async function q(t, e) {
57
57
  return e ? t : await B(t, {
58
58
  parser: "vue",
59
59
  ...T,
@@ -88,7 +88,7 @@ function N(t) {
88
88
  function $(t) {
89
89
  return S(t) || N(t);
90
90
  }
91
- function q(t) {
91
+ function M(t) {
92
92
  return t.replace(new RegExp("this.", "g"), "");
93
93
  }
94
94
  function J(t) {
@@ -96,7 +96,7 @@ function J(t) {
96
96
  }
97
97
  function f(t, e = !0, n = !0, s = []) {
98
98
  let r = $(t) ? t.value.trim().replace(/\"/g, "'").replace(/;$/, "") : e ? JSON.stringify(t) : t;
99
- return r = k(r, s), n ? q(J(r)) : J(r);
99
+ return r = k(r, s), n ? M(J(r)) : J(r);
100
100
  }
101
101
  function k(t, e = []) {
102
102
  let n = t;
@@ -337,11 +337,11 @@ function X(t, e, n = [], s = {}, r) {
337
337
  return $e(t).forEach((u) => {
338
338
  const m = [];
339
339
  for (const d of u.children) {
340
- let { id: b, name: g, invisible: F, from: y } = d;
340
+ let { id: b, name: y, invisible: F, from: g } = d;
341
341
  if (F)
342
342
  continue;
343
- const C = ve(g, e, y);
344
- C && a.push(C), z(y) && o.push({ id: y.id, name: g });
343
+ const C = ve(y, e, g);
344
+ C && a.push(C), z(g) && o.push({ id: g.id, name: y });
345
345
  const { props: P, events: O, handlers: x } = we(
346
346
  d,
347
347
  b,
@@ -365,8 +365,8 @@ function X(t, e, n = [], s = {}, r) {
365
365
  typeof j == "string" ? E = j : (E = (j?.nodes || []).join(`
366
366
  `), Object.assign(c, j?.methods || {}), a = a.concat(j?.components || []), o = o.concat(j?.importBlocks || []));
367
367
  const _ = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
368
- y
369
- ) ? I(g) : Y(y) || Z(y) ? "component" : g;
368
+ g || e.get(y)?.package
369
+ ) ? I(y) : Y(g) || Z(g) ? "component" : y;
370
370
  m.push(
371
371
  ye.includes(_) ? `<${_} ${R} ${P} ${O} />` : `<${_} ${R} ${P} ${O}>${E ? `
372
372
  ` + E.trim() : ""}</${_}>`
@@ -445,7 +445,7 @@ function ke(t, e = {}, n = {}) {
445
445
  const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
446
446
  return {
447
447
  binders: Object.entries(e).map(([a, p]) => {
448
- const o = p.handler.value.startsWith("this."), l = o ? q(p.handler.value) : `${v(a)}_${t}${i}`;
448
+ const o = p.handler.value.startsWith("this."), l = o ? M(p.handler.value) : `${v(a)}_${t}${i}`;
449
449
  return o || (s[l] = r.length ? {
450
450
  type: "JSFunction",
451
451
  value: `{
@@ -491,7 +491,7 @@ function Ce(t = [], e = [], n = []) {
491
491
  const d = h?.startsWith("v") ? I(h) : I("v-" + h);
492
492
  if (m += d, u.arg && (S(u.arg) ? m += `:[${f(u.name, !0, !0, e)}]` : m += `:${u.arg}`), u.modifiers) {
493
493
  const b = Object.keys(u.modifiers);
494
- b.length && (m += b.map((g) => "." + g));
494
+ b.length && (m += b.map((y) => "." + y));
495
495
  }
496
496
  u.value ? s.push(
497
497
  `${m}="${f(u.value, !0, !0, e)}"`
@@ -600,11 +600,11 @@ function Fe(t, e, n = "web") {
600
600
  ...s.methods || {}
601
601
  },
602
602
  r
603
- ), g = m.map((x) => `import ${x.name} from './${x.id}.vue';`);
604
- let { imports: F, uniComponents: y } = Ee(
603
+ ), y = m.map((x) => `import ${x.name} from './${x.id}.vue';`);
604
+ let { imports: F, uniComponents: g } = Ee(
605
605
  e,
606
606
  u,
607
- g,
607
+ y,
608
608
  t.imports,
609
609
  n
610
610
  );
@@ -627,7 +627,7 @@ function Fe(t, e, n = "web") {
627
627
  imports: `
628
628
  ` + F.join(`
629
629
  `),
630
- components: ae(u, y).join(","),
630
+ components: ae(u, g).join(","),
631
631
  directives: h.join(","),
632
632
  returns: t.members.join(","),
633
633
  template: l.join(`
@@ -639,7 +639,7 @@ function Fe(t, e, n = "web") {
639
639
  blockPlugins: O.join(`
640
640
  `),
641
641
  asyncComponents: C.join(","),
642
- uniComponents: y,
642
+ uniComponents: g,
643
643
  renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
644
644
  };
645
645
  }
@@ -694,7 +694,7 @@ async function Ue(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
694
694
  script: await ie(a, r),
695
695
  style: await W(c.style, r)
696
696
  });
697
- return await M(p, r).catch((o) => (o.content = p, Promise.reject(o)));
697
+ return await q(p, r).catch((o) => (o.content = p, Promise.reject(o)));
698
698
  }
699
699
  async function De(t) {
700
700
  const e = `
@@ -709,7 +709,7 @@ async function De(t) {
709
709
  <style scoped lang="scss">
710
710
  </style>
711
711
  `;
712
- return await M(e);
712
+ return await q(e);
713
713
  }
714
714
  export {
715
715
  Le as VTJ_CODER_VERSION,
@@ -717,5 +717,5 @@ export {
717
717
  W as cssFormatter,
718
718
  Ue as generator,
719
719
  ie as tsFormatter,
720
- M as vueFormatter
720
+ q as vueFormatter
721
721
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.12.6",
4
+ "version": "0.12.8",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "prettier": "~3.5.0",
25
25
  "@vtj/base": "~0.12.0",
26
- "@vtj/core": "~0.12.6"
26
+ "@vtj/core": "~0.12.8"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@vtj/cli": "~0.12.1"
@@ -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.5
5
+ * @version 0.12.7
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.5";
8
+ export declare const version = "0.12.7";