@vtj/coder 0.10.0 → 0.10.1-alpha.0

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.0
5
+ * @version 0.10.1-alpha.0
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const se="0.10.0";/**!
7
+ */const se="0.10.1-alpha.0";/**!
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.0
11
+ * @version 0.10.1-alpha.0
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 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"];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}: {
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}: {
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,c)=>(c.id&&_(c.source)&&(i[`watcher_${c.id}`]=c.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,a)=>(a.id&&_(a.source)&&(i[`watcher_${a.id}`]=a.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 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"?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:`{
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:`{
33
33
  return (${p.handler.value}).apply(this, args);
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}`}"`}>
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}`}"`}>
35
35
  ${e}
36
- </template>`}function Oe(t,e=[],n=[],s={},r="web"){const i=["@dcloudio/uni-h5","uni-h5"],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(`
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(`
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),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:`
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:`
42
42
  `+F.join(`
43
- `),components:ce(u,$).join(","),directives:d.join(","),returns:t.members.join(","),template:l.join(`
43
+ `),components:ae(l,$).join(","),directives:d.join(","),returns:t.members.join(","),template:u.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 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=`
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=`
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.0
11
+ * @version 0.10.1-alpha.0
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Je = "0.10.0";
14
+ const Je = "0.10.1-alpha.0";
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.0
19
+ * @version 0.10.1-alpha.0
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const re = [
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.10.0",
4
+ "version": "0.10.1-alpha.0",
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.0"
9
+ "@vtj/core": "~0.10.1-alpha.0"
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.9.30
5
+ * @version 0.10.0
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.9.30";
8
+ export declare const version = "0.10.0";