@vtj/coder 0.12.13 → 0.12.14

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,16 +1,16 @@
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),q=F(K),D=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.13
5
+ * @version 0.12.14
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const ne="0.12.13";/**!
7
+ */const ne="0.12.14";/**!
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.13
11
+ * @version 0.12.14
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"];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,q,U,D]})}async function V(t,e){if(e)return t;try{return(await T.format(t,{parser:"babel-ts",...B,plugins:[q,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:[D]})}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 ae(t=[],e=[]){return t.filter(s=>!e.includes(s))}class ce{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(a=>a.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){console.log("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 a=this.collectImport(o);if(a){const f=a.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(a=>a.name==="vFor");let i=new Set(Array.from(n));if(r){const{item:a="item",index:f="index"}=r.iterator||{};i=new Set([a,f,...Array.from(i)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],f=a.length?a:[`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}: {
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
15
  default: ${d(e.default,!0,!1)}
16
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}: {
@@ -26,21 +26,21 @@
26
26
  return await mock.apply(this, args);
27
27
  }`}else{const s=I(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(${s});
29
- }`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],L=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,s=[],n={},r){const i=[];let o={},a=[];const f=[];let l=[];return ge(t).forEach(c=>{const g=[];for(const h of c.children){let{id:y,name:$,invisible:j,from:v}=h;if(j)continue;const C=ve($,e,v);C&&a.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||{}),a=a.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(c.slot,g.join(`
32
- `),r?.id);i.push(p)}),{nodes:i,methods:o,directives:ye(f),components:m.dedupArray(a),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(([a,f])=>{const l=f.handler.value.startsWith("this."),u=l?M(f.handler.value):`${m.camelCase(a)}_${t}${i}`;return l||(n[u]=r.length?{type:"JSFunction",value:`{
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
33
  return (${f.handler.value}).apply(this, args);
34
- }`}:f.handler),je(a,f,u,r,l)}),handlers:n}}function ke(t,e,s={},n={},r={},i){const{binders:o,handlers:a}=Se(e,n,r);return{props:be(t,s,i).join(" "),handlers:a,binders:o,events:o.join(" ")}}function we(t=[],e=[],s=[]){const n=[],{vIf:r,vElse:i,vElseIf:o,vShow:a,vModels:f,vFor:l,vBind:u,vHtml:c,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"),a&&n.push(`v-show="${d(a.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 c&&n.push(`v-html="${d(c.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(c=>L.includes(c.name)),s=t.filter(c=>!L.includes(c.name)),n=e.find(c=>m.camelCase(c.name)==="vIf"),r=e.find(c=>m.camelCase(c.name)==="vElseIf"),i=e.find(c=>m.camelCase(c.name)==="vElse"),o=e.find(c=>m.camelCase(c.name)==="vFor"),a=e.find(c=>m.camelCase(c.name)==="vShow"),f=e.find(c=>m.camelCase(c.name)==="vBind"),l=e.find(c=>m.camelCase(c.name)==="vHtml"),u=e.filter(c=>m.camelCase(c.name)==="vModel");return{vIf:n,vElseIf:r,vElse:i,vFor:o,vShow:a,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}`}"`}>
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 Ee(t,e=[],s=[],n={},r="web"){const i=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],o={vue:["defineComponent","reactive"]},a=[];for(const l of e){const u=t.get(l.split(":")[0]);if(u&&u.package){const c=o[u.package]??(o[u.package]=[]),g=u.parent||(u.alias||"").split(".")[0]||u.name;c.push(g),r==="uniapp"&&i.includes(u.package)&&a.push(g)}}for(const[l,u]of Object.entries(n))(o[l]??(o[l]=[])).push(...Array.from(u)),r==="uniapp"&&i.includes(l)&&a.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:a}}function _e(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
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
37
  ${s} {
38
38
  ${oe(n)}
39
39
  }
40
40
  `);return e.join(`
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),a=me(n.watch,r),f=he(n.dataSources),{methods:l,nodes:u,components:c,importBlocks:g,directives:p}=z(n.nodes||[],e,r,t.context),h=[...o,...a.computed],y=A({...l,...n.methods||{}},r),$=g.map(E=>`import ${E.name} from './${E.id}.vue';`);let{imports:j,uniComponents:v}=Ee(e,c,$,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:a.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...f,...y].join(","),imports:`
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
42
  `+j.join(`
43
- `),components:ae(c,v).join(","),directives:p.join(","),returns:t.members.join(","),template:u.join(`
43
+ `),components:ce(a,v).join(","),directives:p.join(","),returns:t.members.join(","),template:u.join(`
44
44
  `),css:n.css||"",style:_e(t.style),urlSchemas:P.join(`
45
45
  `),blockPlugins:O.join(`
46
46
  `),asyncComponents:C.join(","),uniComponents:v,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Fe=`
@@ -86,7 +86,7 @@ export default defineComponent({
86
86
  <%= css %>
87
87
  <%= style %>
88
88
  </style>
89
- `,Te=m.template(Fe),Be=m.template(Ne);async function Re(t,e=new Map,s=[],n="web",r){const i=new ce(m.cloneDeep(t),s),o=Ie(i,e,n),a=Te(o),f=Be({template:o.template,css:await N(o.css,r),script:await V(a,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=`
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>
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { mitt as K, dedupArray as P, toArray as ee, kebabCase as F, 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.13
11
+ * @version 0.12.14
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Le = "0.12.13";
14
+ const Le = "0.12.14";
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.13
19
+ * @version 0.12.14
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const re = [
@@ -181,7 +181,6 @@ class le {
181
181
  }
182
182
  // 代码中包含依赖库的引用,需要从代码中移除
183
183
  replaceLibraryPath(e) {
184
- console.log("replaceLibraryPath", e);
185
184
  const { libraryRegex: n } = this;
186
185
  let s = e.value;
187
186
  for (const r of n) {
@@ -216,7 +215,7 @@ class le {
216
215
  delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
217
216
  for (const r of Object.values(s))
218
217
  n = n.concat(Array.from(r));
219
- return P(n);
218
+ return C(n);
220
219
  }
221
220
  collectContext(e, n) {
222
221
  const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((c) => c.name === "vFor");
@@ -343,20 +342,20 @@ function X(t, e, n = [], s = {}, r) {
343
342
  let { id: d, name: $, invisible: j, from: g } = m;
344
343
  if (j)
345
344
  continue;
346
- const C = ve($, e, g);
347
- C && c.push(C), z(g) && l.push({ id: g.id, name: $ });
348
- const { props: E, events: O, handlers: x } = we(
345
+ const E = ve($, e, g);
346
+ E && c.push(E), z(g) && l.push({ id: g.id, name: $ });
347
+ const { props: P, events: O, handlers: x } = we(
349
348
  m,
350
349
  d,
351
350
  m.props,
352
351
  m.events,
353
352
  s,
354
353
  n
355
- ), R = Pe(
354
+ ), R = Ce(
356
355
  m.directives,
357
356
  n,
358
357
  f
359
- ).join(" "), S = m.children ? Ee(
358
+ ).join(" "), S = m.children ? Pe(
360
359
  m.children,
361
360
  n,
362
361
  e,
@@ -371,7 +370,7 @@ function X(t, e, n = [], s = {}, r) {
371
370
  g || e.get($)?.package
372
371
  ) ? F($) : Y(g) || Z(g) ? "component" : $;
373
372
  y.push(
374
- ye.includes(I) ? `<${I} ${R} ${E} ${O} />` : `<${I} ${R} ${E} ${O}>${_ ? `
373
+ ye.includes(I) ? `<${I} ${R} ${P} ${O} />` : `<${I} ${R} ${P} ${O}>${_ ? `
375
374
  ` + _.trim() : ""}</${I}>`
376
375
  );
377
376
  }
@@ -382,12 +381,12 @@ function X(t, e, n = [], s = {}, r) {
382
381
  nodes: i,
383
382
  methods: o,
384
383
  directives: ge(f),
385
- components: P(c),
386
- importBlocks: P(l, "id")
384
+ components: C(c),
385
+ importBlocks: C(l, "id")
387
386
  };
388
387
  }
389
388
  function ge(t) {
390
- return P(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}`);
391
390
  }
392
391
  function $e(t = []) {
393
392
  const e = /* @__PURE__ */ new Map();
@@ -468,7 +467,7 @@ function we(t, e, n = {}, s = {}, r = {}, i) {
468
467
  events: o.join(" ")
469
468
  };
470
469
  }
471
- function Pe(t = [], e = [], n = []) {
470
+ function Ce(t = [], e = [], n = []) {
472
471
  const s = [], {
473
472
  vIf: r,
474
473
  vElse: i,
@@ -479,7 +478,7 @@ function Pe(t = [], e = [], n = []) {
479
478
  vBind: u,
480
479
  vHtml: a,
481
480
  customDirectives: y
482
- } = Ce(t);
481
+ } = Ee(t);
483
482
  if (r && s.push(`v-if="${h(r.value, !0, !0, e)}"`), o && s.push(
484
483
  `v-else-if="${h(o.value, !0, !0, e)}"`
485
484
  ), i && s.push("v-else"), c && s.push(
@@ -513,7 +512,7 @@ function Pe(t = [], e = [], n = []) {
513
512
  ) : s.push(m);
514
513
  }), s;
515
514
  }
516
- function Ce(t = []) {
515
+ function Ee(t = []) {
517
516
  const e = t.filter(
518
517
  (a) => L.includes(a.name)
519
518
  ), n = t.filter(
@@ -547,7 +546,7 @@ function Ce(t = []) {
547
546
  customDirectives: n
548
547
  };
549
548
  }
550
- function Ee(t, e, n, s, r) {
549
+ function Pe(t, e, n, s, r) {
551
550
  return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? X(t, n, e, s, r) : "";
552
551
  }
553
552
  function Oe(t, e, n) {
@@ -576,7 +575,7 @@ function xe(t, e = [], n = [], s = {}, r = "web") {
576
575
  for (const [l, u] of Object.entries(s))
577
576
  (o[l] ?? (o[l] = [])).push(...Array.from(u)), r === "uniapp" && i.includes(l) && c.push(...Array.from(u));
578
577
  return {
579
- imports: Object.entries(o).filter(([l, u]) => r === "uniapp" ? !i.includes(l) && !!u.length : !!u.length).map(([l, u]) => `import { ${P(u).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(
580
579
  ","
581
580
  )}} from '${l}';`).concat(n),
582
581
  uniComponents: c
@@ -629,10 +628,10 @@ function Ne(t, e, n = "web") {
629
628
  t.imports,
630
629
  n
631
630
  );
632
- const C = Object.keys({
631
+ const E = Object.keys({
633
632
  ...t.urlSchemas,
634
633
  ...t.blockPlugins
635
- }), E = Ie(t.urlSchemas), O = Ae(t.blockPlugins);
634
+ }), P = Ie(t.urlSchemas), O = Ae(t.blockPlugins);
636
635
  return {
637
636
  id: s.id,
638
637
  version: s.__VERSION__,
@@ -655,11 +654,11 @@ function Ne(t, e, n = "web") {
655
654
  `),
656
655
  css: s.css || "",
657
656
  style: _e(t.style),
658
- urlSchemas: E.join(`
657
+ urlSchemas: P.join(`
659
658
  `),
660
659
  blockPlugins: O.join(`
661
660
  `),
662
- asyncComponents: C.join(","),
661
+ asyncComponents: E.join(","),
663
662
  uniComponents: g,
664
663
  renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
665
664
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.12.13",
4
+ "version": "0.12.14",
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.13"
26
+ "@vtj/core": "~0.12.14"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@vtj/cli": "~0.12.2"
@@ -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.12
5
+ * @version 0.12.13
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.12";
8
+ export declare const version = "0.12.13";