@vtj/coder 0.12.59 → 0.12.60

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,51 +1,51 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@vtj/base"),T=require("prettier/standalone"),K=require("prettier/plugins/html"),ee=require("prettier/plugins/babel"),te=require("prettier/plugins/postcss"),ne=require("prettier/plugins/estree");function F(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const se=F(K),L=F(ee),U=F(te),V=F(ne);/**!
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@vtj/base"),D=require("prettier/standalone"),K=require("prettier/plugins/html"),ee=require("prettier/plugins/babel"),te=require("prettier/plugins/postcss"),se=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 ne=F(K),q=F(ee),M=F(te),U=F(se);/**!
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.59
5
+ * @version 0.12.60
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const re="0.12.59";/**!
7
+ */const re="0.12.60";/**!
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.59
11
+ * @version 0.12.60
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
- */const ie=["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,L,V,U]})}async function M(t,e){if(e)return t;try{return(await T.format(t,{parser:"babel-ts",...B,plugins:[L,V]})).replace(/;\n$/gi,"")}catch(n){return console.warn(n),t}}async function N(t,e){return e?t:T.format(t,{parser:"scss",...B,plugins:[U]})}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 H(t){return t.replace(new RegExp("this.","g"),"")}function D(t){return t.replace(/this\.context\??\./g,"")}function d(t,e=!0,n=!0,s=[]){let r=b(t)?t.value.trim().replace(/\"/g,"'").replace(/;$/,""):e?JSON.stringify(t):t;return r=w(r,s),n?H(D(r)):D(r)}function w(t,e=[]){let n=t;for(const s of e)n=n.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);return n}function Q(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 oe(t={}){return Object.entries(t).map(([e,n])=>`"${e}": ${d(n)}`)}function z(t={},e=!1){const n=Object.keys(t);return e?n.map(s=>"."+s):n}function ce(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))}function J(t){return m.base64(JSON.stringify(t))}class le{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 o=this.dependencies.find(c=>c.library===i)?.package;o&&(this.imports[o]||(this.imports[o]=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 o of i){const c=this.collectImport(o);if(c){const f=c.path.replace(/\$/g,"\\$");s=s.replace(new RegExp(f,"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)b(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 m.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: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_${n?.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 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=d(n,!1);return`${e}:${s}`})}function pe(t=[]){return t.map(e=>`${e.name}: {
13
+ */const ie=["slot","template","component","img","div","p","h1","h2","h3","span","a"];f.mitt();const T={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 B(t,e){return e?t:await D.format(t,{parser:"vue",...T,plugins:[ne,q,U,M]})}async function V(t,e){if(e)return t;try{return(await D.format(t,{parser:"babel-ts",...T,plugins:[q,U]})).replace(/;\n$/gi,"")}catch(s){return console.warn(s),t}}async function N(t,e){return e?t:D.format(t,{parser:"scss",...T,plugins:[M]})}function k(t){return t&&t.type==="JSExpression"}function I(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function j(t){return k(t)||I(t)}function H(t){return t.replace(new RegExp("this.","g"),"")}function R(t){return t.replace(/this\.context\??\./g,"")}function d(t,e=!0,s=!0,n=[]){let r=j(t)?t.value.trim().replace(/\"/g,"'").replace(/;$/,""):e?JSON.stringify(t):t;return r=w(r,n),s?H(R(r)):R(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 Q(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 oe(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${d(s)}`)}function z(t={},e=!1){const s=Object.keys(t);return e?s.map(n=>"."+n):s}function ae(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))}function W(t){return f.base64(JSON.stringify(t))}class le{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){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 m=a.path.replace(/\$/g,"\\$");n=n.replace(new RegExp(m,"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)j(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 f.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:m="index"}=r.iterator||{};i=new Set([a,m,...Array.from(i)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],m=a.length?a:[`scope_${s?.id}`];i=new Set([...m,...Array.from(i)])}this.context[e.id]=i}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&!j(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 ue(t={}){return Object.entries(t).map(([e,s])=>{const n=d(s,!1);return`${e}:${n}`})}function pe(t=[]){return t.map(e=>`${e.name}: {
14
14
  from: '${e.from||e.name}',
15
15
  default: ${d(e.default,!0,!1)}
16
- }`)}function fe(t=[]){const e=n=>n?`[${m.toArray(n).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:(b(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
17
- type:${e(n.type)},
18
- required: ${d(!!n.required,!0,!1)},
19
- default: ${d(n.default,!0,!1)}
20
- }`))}function me(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function A(t={},e=[]){return Object.entries(t).map(([n,s])=>{let r=Q(d(s,!1,!1));return r=w(r,e),r.startsWith("async")?`async ${n}${r.replace(/^async/,"")}`:`${n}${r}`})}function he(t=[],e=[]){const n=t.reduce((i,o)=>(o.id&&I(o.source)&&(i[`watcher_${o.id}`]=o.source),i),{}),s=A(n,e),r=t.map(i=>`watcher_${i.id}: {
16
+ }`)}function fe(t=[]){const e=s=>s?`[${f.toArray(s).map(i=>i.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(j(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
17
+ type:${e(s.type)},
18
+ required: ${d(!!s.required,!0,!1)},
19
+ default: ${d(s.default,!0,!1)}
20
+ }`))}function me(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function A(t={},e=[]){return Object.entries(t).map(([s,n])=>{let r=Q(d(n,!1,!1));return r=w(r,e),r.startsWith("async")?`async ${s}${r.replace(/^async/,"")}`:`${s}${r}`})}function he(t=[],e=[]){const s=t.reduce((i,o)=>(o.id&&I(o.source)&&(i[`watcher_${o.id}`]=o.source),i),{}),n=A(s,e),r=t.map(i=>`watcher_${i.id}: {
21
21
  deep: ${i.deep},
22
22
  immediate:${i.immediate},
23
23
  handler${Q(i.handler.value)}
24
- }`);return{computed:s,watches:r}}function de(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const n=I(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args) {
25
- // DataSource: ${J(e)}
26
- const mock = this.provider.createMock(${n});
24
+ }`);return{computed:n,watches:r}}function de(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const s=I(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args) {
25
+ // DataSource: ${W(e)}
26
+ const mock = this.provider.createMock(${s});
27
27
  return await mock.apply(this, args);
28
- }`}else{const n=I(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args) {
29
- // DataSource: ${J(e)}
30
- return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
31
- }`}})}const ye=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function G(t,e,n=[],s={},r){const i=[];let o={},c=[];const f=[];let l=[];return ve(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=$e($,e,v);C&&c.push(C),X(v)&&l.push({id:v.id,name:$});const{props:P,events:O,handlers:E}=we(h,y,h.props,h.events,s,n),W=Ce(h.directives,n,f).join(" "),S=h.children?Oe(h.children,n,e,s,h):"";Object.assign(o,E);let _="";typeof S=="string"?_=S:(_=(S?.nodes||[]).join(`
32
- `),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($):Y(v)||Z(v)?"component":$;g.push(ye.includes(x)?`<${x} ${W} ${P} ${O} />`:`<${x} ${W} ${P} ${O}>${_?`
33
- `+_.trim():""}</${x}>`)}const p=Ee(a.slot,g.join(`
34
- `),r?.id);i.push(p)}),{nodes:i,methods:o,directives:ge(f),components:m.dedupArray(c),importBlocks:m.dedupArray(l,"id")}}function ge(t){return m.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ve(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 $e(t,e,n){if(ie.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 X(n)||s?t:null}function X(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function Y(t){return typeof t=="object"&&t.type==="UrlSchema"}function Z(t){return typeof t=="object"&&t.type==="Plugin"}function be(t,e,n=[]){return t==="style"?b(e)?`:style="${d({...e,value:w(e.value,n)})}"`:"":t==="__class"&&b(e)?`:class="${d({...e,value:w(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:b(e)?`:${t}="${d({...e,value:w(e.value,n)})}"`:m.isPlainObject(e)?`:${t}='{${oe(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function je(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,b(e.style)||delete e.style}const r=t.from;return(Y(r)||Z(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,o])=>be(i,o,n))}function Se(t,e,n,s,r){const i=z(e.modifiers,!0);return r?`@${t}${i.join("")}="${n}"`:s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function ke(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,f])=>{const l=f.handler.value.startsWith("this."),u=l?H(f.handler.value):`${m.camelCase(c)}_${t}${i}`;return l||(s[u]=r.length?{type:"JSFunction",value:`{
35
- return (${f.handler.value}).apply(this, args);
36
- }`}:f.handler),Se(c,f,u,r,l)}),handlers:s}}function we(t,e,n={},s={},r={},i){const{binders:o,handlers:c}=ke(e,s,r);return{props:je(t,n,i).join(" "),handlers:c,binders:o,events:o.join(" ")}}function Ce(t=[],e=[],n=[]){const s=[],{vIf:r,vElse:i,vElseIf:o,vShow:c,vModels:f,vFor:l,vBind:u,vHtml:a,customDirectives:g}=Pe(t);if(r&&s.push(`v-if="${d(r.value,!0,!0,e)}"`),o&&s.push(`v-else-if="${d(o.value,!0,!0,e)}"`),i&&s.push("v-else"),c&&s.push(`v-show="${d(c.value,!0,!0,e)}"`),u&&s.push(`v-bind="${d(u.value,!0,!0,e)}"`),f.forEach(p=>{const h=z(p.modifiers,!0),y=p.arg?k(p.arg)?`:[${d(p.arg,!0,!0,e)}]`:`:${p.arg}`:"";s.push(`v-model${y}${h}="${d(p.value,!0,!0,e)}"`)}),l){const{item:p,index:h}={item:"item",index:"index",...l.iterator};s.push(`v-for="(${p}, ${h}) in ${d(l.value,!0,!0,e)}"`)}return a&&s.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),n.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?s.push(`${h}="${d(p.value,!0,!0,e)}"`):s.push(h)}),s}function Pe(t=[]){const e=t.filter(a=>q.includes(a.name)),n=t.filter(a=>!q.includes(a.name)),s=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:s,vElseIf:r,vElse:i,vFor:o,vShow:c,vModels:u,vBind:f,vHtml:l,customDirectives:n}}function Oe(t,e,n,s,r){return typeof t=="string"?t:k(t)?`{{ ${d(t,!1,!0,e)} }}`:Array.isArray(t)?G(t,n,e,s,r):""}function Ee(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}`}"`}>
28
+ }`}else{const s=I(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args) {
29
+ // DataSource: ${W(e)}
30
+ return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
31
+ }`}})}const ge=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],J=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function G(t,e,s=[],n={},r){const i=[];let o={},a=[];const m=[];let u=[];return ve(t).forEach(c=>{const v=[];for(const h of c.children){let{id:g,name:$,invisible:b,from:y}=h;if(b)continue;const C=$e($,e,y);C&&a.push(C),X(y)&&u.push({id:y.id,name:$});const{props:P,events:O,handlers:E}=we(h,g,h.props,h.events,n,s),L=Ce(h.directives,s,m).join(" "),S=h.children?Oe(h.children,s,e,n,h):"";Object.assign(o,E);let x="";typeof S=="string"?x=S:(x=(S?.nodes||[]).join(`
32
+ `),Object.assign(o,S?.methods||{}),a=a.concat(S?.components||[]),u=u.concat(S?.importBlocks||[]));const _=["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(y||e.get($)?.package)?f.kebabCase($):Y(y)||Z(y)?"component":$;v.push(ge.includes(_)?`<${_} ${L} ${P} ${O} />`:`<${_} ${L} ${P} ${O}>${x?`
33
+ `+x.trim():""}</${_}>`)}const p=Ee(c.slot,v.join(`
34
+ `),r?.id);i.push(p)}),{nodes:i,methods:o,directives:ye(m),components:f.dedupArray(a),importBlocks:f.dedupArray(u,"id")}}function ye(t){return f.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function ve(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 $e(t,e,s){if(ie.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 X(s)||n?t:null}function X(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function Y(t){return typeof t=="object"&&t.type==="UrlSchema"}function Z(t){return typeof t=="object"&&t.type==="Plugin"}function be(t,e,s=[]){return t==="style"?j(e)?`:style="${d({...e,value:w(e.value,s)})}"`:"":t==="__class"&&j(e)?`:class="${d({...e,value:w(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:j(e)?`:${t}="${d({...e,value:w(e.value,s)})}"`:f.isPlainObject(e)?`:${t}='{${oe(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function je(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,j(e.style)||delete e.style}const r=t.from;return(Y(r)||Z(r))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([i,o])=>be(i,o,s))}function Se(t,e,s,n,r){const i=z(e.modifiers,!0);return r?`@${t}${i.join("")}="${s}"`:n&&n.length>0?`@${t}${i.join("")}="(...args:any[]) => ${s}"`:`@${t}${i.join("")}="${s}"`}function ke(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,m])=>{const u=m.handler.value.startsWith("this."),l=u?H(m.handler.value):`${f.camelCase(a)}_${t}${i}`;return u||(n[l]=r.length?{type:"JSFunction",value:`{
35
+ return (${m.handler.value}).apply(this, args);
36
+ }`}:m.handler),Se(a,m,l,r,u)}),handlers:n}}function we(t,e,s={},n={},r={},i){const{binders:o,handlers:a}=ke(e,n,r);return{props:je(t,s,i).join(" "),handlers:a,binders:o,events:o.join(" ")}}function Ce(t=[],e=[],s=[]){const n=[],{vIf:r,vElse:i,vElseIf:o,vShow:a,vModels:m,vFor:u,vBind:l,vHtml:c,customDirectives:v}=Pe(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)}"`),l&&n.push(`v-bind="${d(l.value,!0,!0,e)}"`),m.forEach(p=>{const h=z(p.modifiers,!0),g=p.arg?k(p.arg)?`:[${d(p.arg,!0,!0,e)}]`:`:${p.arg}`:"";n.push(`v-model${g}${h}="${d(p.value,!0,!0,e)}"`)}),u){const{item:p,index:h}={item:"item",index:"index",...u.iterator};n.push(`v-for="(${p}, ${h}) in ${d(u.value,!0,!0,e)}"`)}return c&&n.push(`v-html="${d(c.value,!0,!0,e)}"`),v&&v.length&&v.forEach(p=>{if(!p.name)return;let h="",g="";k(p.name)?(g=d(p.name,!0,!0,e),s.push(g)):g=p.name;const $=g?.startsWith("v")?f.kebabCase(g):f.kebabCase("v-"+g);if(h+=$,p.arg&&(k(p.arg)?h+=`:[${d(p.name,!0,!0,e)}]`:h+=`:${p.arg}`),p.modifiers){const b=Object.keys(p.modifiers);b.length&&(h+=b.map(y=>"."+y))}p.value?n.push(`${h}="${d(p.value,!0,!0,e)}"`):n.push(h)}),n}function Pe(t=[]){const e=t.filter(c=>J.includes(c.name)),s=t.filter(c=>!J.includes(c.name)),n=e.find(c=>f.camelCase(c.name)==="vIf"),r=e.find(c=>f.camelCase(c.name)==="vElseIf"),i=e.find(c=>f.camelCase(c.name)==="vElse"),o=e.find(c=>f.camelCase(c.name)==="vFor"),a=e.find(c=>f.camelCase(c.name)==="vShow"),m=e.find(c=>f.camelCase(c.name)==="vBind"),u=e.find(c=>f.camelCase(c.name)==="vHtml"),l=e.filter(c=>f.camelCase(c.name)==="vModel");return{vIf:n,vElseIf:r,vElse:i,vFor:o,vShow:a,vModels:l,vBind:m,vHtml:u,customDirectives:s}}function Oe(t,e,s,n,r){return typeof t=="string"?t:k(t)?`{{ ${d(t,!1,!0,e)} }}`:Array.isArray(t)?G(t,s,e,n,r):""}function Ee(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}`}"`}>
37
37
  ${e}
38
- </template>`}function _e(t,e=[],n=[],s={},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(s))(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(n),uniComponents:c}}function xe(t={}){const e=[];for(const[n,s]of Object.entries(t))e.push(`
39
- ${n} {
40
- ${ce(s)}
38
+ </template>`}function xe(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 u of e){const l=t.get(u.split(":")[0]);if(l&&l.package){const c=o[l.package]??(o[l.package]=[]),v=l.parent||(l.alias||"").split(".")[0]||l.name;c.push(v),r==="uniapp"&&i.includes(l.package)&&a.push(v)}}for(const[u,l]of Object.entries(n))(o[u]??(o[u]=[])).push(...Array.from(l)),r==="uniapp"&&i.includes(u)&&a.push(...Array.from(l));return{imports:Object.entries(o).filter(([u,l])=>r==="uniapp"?!i.includes(u)&&!!l.length:!!l.length).map(([u,l])=>`import { ${f.dedupArray(l).join(",")}} from '${u}';`).concat(s),uniComponents:a}}function _e(t={}){const e=[];for(const[s,n]of Object.entries(t))e.push(`
39
+ ${s} {
40
+ ${ae(n)}
41
41
  }
42
42
  `);return e.join(`
43
- `)}function Ae(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Ie(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Fe(t,e,n="web"){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=A(s.lifeCycles,r),o=A(s.computed,r),c=he(s.watch,r),f=de(s.dataSources),{methods:l,nodes:u,components:a,importBlocks:g,directives:p}=G(s.nodes||[],e,r,t.context),h=[...o,...c.computed],y=A({...l,...s.methods||{}},r),$=g.map(E=>`import ${E.name} from './${E.id}.vue';`);let{imports:j,uniComponents:v}=_e(e,a,$,t.imports,n);const C=Object.keys({...t.urlSchemas,...t.blockPlugins}),P=Ae(t.urlSchemas),O=Ie(t.blockPlugins);return{id:s.id,version:s.__VERSION__,name:s.name,state:ue(s.state).join(","),inject:pe(s.inject).join(","),props:fe(s.props).join(","),emits:me(s.emits).join(","),watch:c.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...f,...y].join(","),imports:`
44
- `+j.join(`
45
- `),components:ae(a,v).join(","),directives:p.join(","),returns:t.members.join(","),template:u.join(`
46
- `),css:s.css||"",style:xe(t.style),urlSchemas:P.join(`
43
+ `)}function Ae(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${n.url}');`)}),e}function Ie(t={}){const e=[];return Object.entries(t).forEach(([s,n])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`)}),e}function Fe(t,e,s="web"){const{dsl:n}=t,r=Object.keys(n.computed||{}),i=A(n.lifeCycles,r),o=A(n.computed,r),a=he(n.watch,r),m=de(n.dataSources),{methods:u,nodes:l,components:c,importBlocks:v,directives:p}=G(n.nodes||[],e,r,t.context),h=[...o,...a.computed],g=A({...u,...n.methods||{}},r),$=v.map(E=>`import ${E.name} from './${E.id}.vue';`);let{imports:b,uniComponents:y}=xe(e,c,$,t.imports,s);const C=Object.keys({...t.urlSchemas,...t.blockPlugins}),P=Ae(t.urlSchemas),O=Ie(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:ue(n.state).join(","),inject:pe(n.inject).join(","),props:fe(n.props).join(","),emits:me(n.emits).join(","),watch:a.watches.join(","),lifeCycles:i.join(","),computed:h.join(","),methods:[...m,...g].join(","),imports:`
44
+ `+b.join(`
45
+ `),components:ce(c,y).join(","),directives:p.join(","),returns:t.members.join(","),template:l.join(`
46
+ `),css:n.css||"",style:_e(t.style),urlSchemas:P.join(`
47
47
  `),blockPlugins:O.join(`
48
- `),asyncComponents:C.join(","),uniComponents:v,renderer:n==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
48
+ `),asyncComponents:C.join(","),uniComponents:y,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Ne=`
49
49
  // @ts-nocheck
50
50
 
51
51
  <%= imports %>
@@ -77,18 +77,18 @@ export default defineComponent({
77
77
  <% if(methods) { %> methods: { <%= methods %> }, <% } %>
78
78
  <% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
79
79
  });
80
- `.replace(/(\n|\r|\t)/g,""),Te=`
80
+ `.replace(/(\n|\r|\t)/g,""),De=`
81
81
  <template>
82
82
  <%= template %>
83
83
  </template>
84
- <script lang="ts">
84
+ <script lang="<%= scriptLang %>">
85
85
  <%= script %>
86
86
  <\/script>
87
- <style lang="scss" scoped>
87
+ <style lang="<%= styleLang %>" scoped>
88
88
  <%= css %>
89
89
  <%= style %>
90
90
  </style>
91
- `,Be=m.template(Ne),Re=m.template(Te);async function We(t,e=new Map,n=[],s="web",r){const i=new le(m.cloneDeep(t),n),o=Fe(i,e,s),c=Be(o),f=Re({template:o.template,css:await N(o.css,r),script:await M(c,r),style:await N(o.style,r)});return await R(f,r).catch(l=>(l.content=f,Promise.reject(l)))}async function De(t){const e=`
91
+ `,Te=f.template(Ne),Be=f.template(De);async function Le(t,e=new Map,s=[],n="web",r){const i=t,o=typeof i.dsl=="object"&&arguments.length===1?i:{dsl:t,componentMap:e,dependencies:s,platform:n,formatterDisabled:r},{dsl:a,componentMap:m=new Map,dependencies:u=[],platform:l="web",formatterDisabled:c=!1,ts:v=!0,scss:p=!1}=o,h=new le(f.cloneDeep(a),u),g=Fe(h,m,l),$=Te(g),b=Be({template:g.template,css:await N(g.css,c),script:await V($,c),style:await N(g.style,c),scriptLang:v?"ts":"js",styleLang:p?"scss":"css"});return await B(b,c).catch(y=>(y.content=b,Promise.reject(y)))}async function Re(t){const e=`
92
92
  <template>
93
93
  <div>
94
94
  <h3>源码模式页面</h3>
@@ -99,4 +99,4 @@ export default defineComponent({
99
99
  <\/script>
100
100
  <style scoped lang="scss">
101
101
  </style>
102
- `;return await R(e)}exports.VTJ_CODER_VERSION=re;exports.createEmptyPage=De;exports.cssFormatter=N;exports.generator=We;exports.tsFormatter=M;exports.vueFormatter=R;
102
+ `;return await B(e)}exports.VTJ_CODER_VERSION=re;exports.createEmptyPage=Re;exports.cssFormatter=N;exports.generator=Le;exports.tsFormatter=V;exports.vueFormatter=B;
package/dist/index.mjs CHANGED
@@ -1,22 +1,22 @@
1
- import { mitt as ee, base64 as te, dedupArray as C, toArray as ne, kebabCase as F, camelCase as v, isPlainObject as se, template as U, cloneDeep as re } from "@vtj/base";
1
+ import { mitt as ee, base64 as te, dedupArray as C, toArray as se, kebabCase as F, camelCase as b, isPlainObject as ne, template as U, cloneDeep as re } from "@vtj/base";
2
2
  import { format as B } from "prettier/standalone";
3
3
  import * as ie from "prettier/plugins/html";
4
- import * as V from "prettier/plugins/babel";
5
- import * as H from "prettier/plugins/postcss";
6
- import * as q from "prettier/plugins/estree";
4
+ import * as M from "prettier/plugins/babel";
5
+ import * as V from "prettier/plugins/postcss";
6
+ import * as H from "prettier/plugins/estree";
7
7
  /**!
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.59
11
+ * @version 0.12.60
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Ue = "0.12.59";
14
+ const Ue = "0.12.60";
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.59
19
+ * @version 0.12.60
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const oe = [
@@ -33,7 +33,7 @@ const oe = [
33
33
  "a"
34
34
  ];
35
35
  ee();
36
- const T = {
36
+ const D = {
37
37
  arrowParens: "always",
38
38
  bracketSpacing: !0,
39
39
  bracketSameLine: !0,
@@ -53,11 +53,11 @@ 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
- ...T,
60
- plugins: [ie, V, q, H]
59
+ ...D,
60
+ plugins: [ie, M, H, V]
61
61
  });
62
62
  }
63
63
  async function ce(t, e) {
@@ -65,18 +65,18 @@ async function ce(t, e) {
65
65
  try {
66
66
  return (await B(t, {
67
67
  parser: "babel-ts",
68
- ...T,
69
- plugins: [V, q]
68
+ ...D,
69
+ plugins: [M, H]
70
70
  })).replace(/;\n$/gi, "");
71
- } catch (n) {
72
- return console.warn(n), t;
71
+ } catch (s) {
72
+ return console.warn(s), t;
73
73
  }
74
74
  }
75
- async function W(t, e) {
75
+ async function L(t, e) {
76
76
  return e ? t : B(t, {
77
77
  parser: "scss",
78
- ...T,
79
- plugins: [H]
78
+ ...D,
79
+ plugins: [V]
80
80
  });
81
81
  }
82
82
  function k(t) {
@@ -85,27 +85,27 @@ function k(t) {
85
85
  function N(t) {
86
86
  return typeof t == "object" && t && t.type === "JSFunction";
87
87
  }
88
- function b(t) {
88
+ function j(t) {
89
89
  return k(t) || N(t);
90
90
  }
91
91
  function Q(t) {
92
92
  return t.replace(new RegExp("this.", "g"), "");
93
93
  }
94
- function J(t) {
94
+ function R(t) {
95
95
  return t.replace(/this\.context\??\./g, "");
96
96
  }
97
- function h(t, e = !0, n = !0, s = []) {
98
- let r = b(t) ? t.value.trim().replace(/\"/g, "'").replace(/;$/, "") : e ? JSON.stringify(t) : t;
99
- return r = w(r, s), n ? Q(J(r)) : J(r);
97
+ function h(t, e = !0, s = !0, n = []) {
98
+ let r = j(t) ? t.value.trim().replace(/\"/g, "'").replace(/;$/, "") : e ? JSON.stringify(t) : t;
99
+ return r = w(r, n), s ? Q(R(r)) : R(r);
100
100
  }
101
101
  function w(t, e = []) {
102
- let n = t;
103
- for (const s of e)
104
- n = n.replace(
105
- new RegExp(`this.${s}.value`, "g"),
106
- `this.${s}`
102
+ let s = t;
103
+ for (const n of e)
104
+ s = s.replace(
105
+ new RegExp(`this.${n}.value`, "g"),
106
+ `this.${n}`
107
107
  );
108
- return n;
108
+ return s;
109
109
  }
110
110
  function G(t) {
111
111
  let e = t.trim().replace(/;$/, "");
@@ -121,30 +121,30 @@ function G(t) {
121
121
  return e;
122
122
  }
123
123
  function ae(t = {}) {
124
- return Object.entries(t).map(([e, n]) => `"${e}": ${h(n)}`);
124
+ return Object.entries(t).map(([e, s]) => `"${e}": ${h(s)}`);
125
125
  }
126
126
  function X(t = {}, e = !1) {
127
- const n = Object.keys(t);
128
- return e ? n.map((s) => "." + s) : n;
127
+ const s = Object.keys(t);
128
+ return e ? s.map((n) => "." + n) : s;
129
129
  }
130
130
  function le(t) {
131
131
  let e = "";
132
- for (var n in t)
133
- if (t.hasOwnProperty(n)) {
134
- var s = t[n];
135
- e += n + ": " + s + ";";
132
+ for (var s in t)
133
+ if (t.hasOwnProperty(s)) {
134
+ var n = t[s];
135
+ e += s + ": " + n + ";";
136
136
  }
137
137
  return e;
138
138
  }
139
139
  function ue(t = [], e = []) {
140
- return t.filter((n) => !e.includes(n));
140
+ return t.filter((s) => !e.includes(s));
141
141
  }
142
- function D(t) {
142
+ function W(t) {
143
143
  return te(JSON.stringify(t));
144
144
  }
145
145
  class pe {
146
- constructor(e, n) {
147
- this.dsl = e, this.dependencies = n, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
146
+ constructor(e, s) {
147
+ this.dsl = e, this.dependencies = s, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
148
148
  }
149
149
  /**
150
150
  * { 'element-plus': ['ElButton', 'ElInput' ...] }
@@ -165,17 +165,17 @@ class pe {
165
165
  * @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
166
166
  */
167
167
  collectImport(e) {
168
- const n = e.split(".");
169
- if (n.length === 4) {
170
- const s = n.pop(), r = n.join(".") + ".", i = n.pop();
171
- if (s && i) {
168
+ const s = e.split(".");
169
+ if (s.length === 4) {
170
+ const n = s.pop(), r = s.join(".") + ".", i = s.pop();
171
+ if (n && i) {
172
172
  const o = this.dependencies.find(
173
173
  (c) => c.library === i
174
174
  )?.package;
175
- o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(s);
175
+ o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(n);
176
176
  }
177
177
  return {
178
- name: s,
178
+ name: n,
179
179
  path: r,
180
180
  library: i
181
181
  };
@@ -184,58 +184,58 @@ class pe {
184
184
  }
185
185
  // 代码中包含依赖库的引用,需要从代码中移除
186
186
  replaceLibraryPath(e) {
187
- const { libraryRegex: n } = this;
188
- let s = e.value;
189
- for (const r of n) {
187
+ const { libraryRegex: s } = this;
188
+ let n = e.value;
189
+ for (const r of s) {
190
190
  const i = e.value?.match(r) || [];
191
191
  for (const o of i) {
192
192
  const c = this.collectImport(o);
193
193
  if (c) {
194
194
  const f = c.path.replace(/\$/g, "\\$");
195
- s = s.replace(new RegExp(f, "g"), "");
195
+ n = n.replace(new RegExp(f, "g"), "");
196
196
  }
197
197
  }
198
198
  }
199
- return s;
199
+ return n;
200
200
  }
201
201
  walk(e) {
202
- const n = (s) => {
203
- if (!s || typeof s != "object") return;
204
- if (Array.isArray(s)) {
205
- for (let i of s)
206
- n(i);
202
+ const s = (n) => {
203
+ if (!n || typeof n != "object") return;
204
+ if (Array.isArray(n)) {
205
+ for (let i of n)
206
+ s(i);
207
207
  return;
208
208
  }
209
- const r = Object.values(s);
209
+ const r = Object.values(n);
210
210
  for (const i of r)
211
- b(i) ? i.value = this.replaceLibraryPath(i) : n(i);
211
+ j(i) ? i.value = this.replaceLibraryPath(i) : s(i);
212
212
  };
213
- n(e);
213
+ s(e);
214
214
  }
215
215
  getLibraryMember(e = []) {
216
- let n = [...e];
217
- const s = { ...this.imports };
218
- delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
219
- for (const r of Object.values(s))
220
- n = n.concat(Array.from(r));
221
- return C(n);
216
+ let s = [...e];
217
+ const n = { ...this.imports };
218
+ delete n["uni-h5"], delete n["@dcloudio/uni-h5"], delete n["uni-ui"], delete n["@dcloudio/uni-ui"];
219
+ for (const r of Object.values(n))
220
+ s = s.concat(Array.from(r));
221
+ return C(s);
222
222
  }
223
- collectContext(e, n) {
224
- const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((c) => c.name === "vFor");
225
- let i = new Set(Array.from(s));
223
+ collectContext(e, s) {
224
+ const n = new Set(s?.id ? this.context[s.id] : []), r = (e.directives || []).find((c) => c.name === "vFor");
225
+ let i = new Set(Array.from(n));
226
226
  if (r) {
227
227
  const { item: c = "item", index: f = "index" } = r.iterator || {};
228
228
  i = /* @__PURE__ */ new Set([c, f, ...Array.from(i)]);
229
229
  }
230
230
  const o = e.slot;
231
231
  if (o) {
232
- const c = typeof o == "string" ? [] : o.params || [], f = c.length ? c : [`scope_${n?.id}`];
232
+ const c = typeof o == "string" ? [] : o.params || [], f = c.length ? c : [`scope_${s?.id}`];
233
233
  i = /* @__PURE__ */ new Set([...f, ...Array.from(i)]);
234
234
  }
235
235
  this.context[e.id] = i;
236
236
  }
237
237
  collectStyle(e) {
238
- e.id && e.props?.style && Object.keys(e.props.style).length && !b(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
238
+ e.id && e.props?.style && Object.keys(e.props.style).length && !j(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
239
239
  }
240
240
  collectUrlSchema(e) {
241
241
  typeof e.from == "object" && e.from.type === "UrlSchema" && (this.urlSchemas[e.name] = e.from);
@@ -244,16 +244,16 @@ class pe {
244
244
  typeof e.from == "object" && e.from.type === "Plugin" && (this.blockPlugins[e.name] = e.from);
245
245
  }
246
246
  walkNodes(e) {
247
- const n = (s, r) => {
248
- this.collectContext(s, r), this.collectStyle(s), this.collectUrlSchema(s), this.collectBlockPlugin(s), Array.isArray(s.children) && s.children.forEach((i) => n(i, s));
247
+ const s = (n, r) => {
248
+ this.collectContext(n, r), this.collectStyle(n), this.collectUrlSchema(n), this.collectBlockPlugin(n), Array.isArray(n.children) && n.children.forEach((i) => s(i, n));
249
249
  };
250
- Array.isArray(e.nodes) && e.nodes.forEach((s) => n(s));
250
+ Array.isArray(e.nodes) && e.nodes.forEach((n) => s(n));
251
251
  }
252
252
  }
253
253
  function fe(t = {}) {
254
- return Object.entries(t).map(([e, n]) => {
255
- const s = h(n, !1);
256
- return `${e}:${s}`;
254
+ return Object.entries(t).map(([e, s]) => {
255
+ const n = h(s, !1);
256
+ return `${e}:${n}`;
257
257
  });
258
258
  }
259
259
  function me(t = []) {
@@ -263,50 +263,50 @@ function me(t = []) {
263
263
  }`);
264
264
  }
265
265
  function he(t = []) {
266
- const e = (n) => n ? `[${ne(n).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
267
- return t.map((n) => typeof n == "string" ? `${n}: {}` : (b(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
268
- type:${e(n.type)},
269
- required: ${h(!!n.required, !0, !1)},
270
- default: ${h(n.default, !0, !1)}
266
+ const e = (s) => s ? `[${se(s).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
267
+ return t.map((s) => typeof s == "string" ? `${s}: {}` : (j(s.default) && !s.default.value && (s.default.value = "undefined"), `${s.name}: {
268
+ type:${e(s.type)},
269
+ required: ${h(!!s.required, !0, !1)},
270
+ default: ${h(s.default, !0, !1)}
271
271
  }`));
272
272
  }
273
273
  function de(t = []) {
274
274
  return t.map((e) => `'${typeof e == "string" ? e : e.name}'`);
275
275
  }
276
276
  function A(t = {}, e = []) {
277
- return Object.entries(t).map(([n, s]) => {
278
- let r = G(h(s, !1, !1));
279
- return r = w(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
277
+ return Object.entries(t).map(([s, n]) => {
278
+ let r = G(h(n, !1, !1));
279
+ return r = w(r, e), r.startsWith("async") ? `async ${s}${r.replace(/^async/, "")}` : `${s}${r}`;
280
280
  });
281
281
  }
282
- function ye(t = [], e = []) {
283
- const n = t.reduce(
282
+ function ge(t = [], e = []) {
283
+ const s = t.reduce(
284
284
  (i, o) => (o.id && N(o.source) && (i[`watcher_${o.id}`] = o.source), i),
285
285
  {}
286
- ), s = A(n, e), r = t.map((i) => `watcher_${i.id}: {
286
+ ), n = A(s, e), r = t.map((i) => `watcher_${i.id}: {
287
287
  deep: ${i.deep},
288
288
  immediate:${i.immediate},
289
289
  handler${G(i.handler.value)}
290
290
  }`);
291
291
  return {
292
- computed: s,
292
+ computed: n,
293
293
  watches: r
294
294
  };
295
295
  }
296
- function ge(t = {}) {
296
+ function ye(t = {}) {
297
297
  return Object.values(t).map((e) => {
298
298
  if (e.type === "mock") {
299
- const n = N(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
299
+ const s = N(e.mockTemplate) && e.mockTemplate.value || "(params) => ({})";
300
300
  return `async ${e.name}(...args) {
301
- // DataSource: ${D(e)}
302
- const mock = this.provider.createMock(${n});
301
+ // DataSource: ${W(e)}
302
+ const mock = this.provider.createMock(${s});
303
303
  return await mock.apply(this, args);
304
304
  }`;
305
305
  } else {
306
- const n = N(e.transform) && e.transform.value || "(res) => res";
306
+ const s = N(e.transform) && e.transform.value || "(res) => res";
307
307
  return `async ${e.name}(...args) {
308
- // DataSource: ${D(e)}
309
- return await this.provider.apis['${e.ref}'].apply(this, args).then(${n});
308
+ // DataSource: ${W(e)}
309
+ return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
310
310
  }`;
311
311
  }
312
312
  });
@@ -326,7 +326,7 @@ const $e = [
326
326
  "source",
327
327
  "track",
328
328
  "wbr"
329
- ], L = [
329
+ ], J = [
330
330
  "vIf",
331
331
  "vElseIf",
332
332
  "vElse",
@@ -336,46 +336,46 @@ const $e = [
336
336
  "vBind",
337
337
  "vHtml"
338
338
  ];
339
- function z(t, e, n = [], s = {}, r) {
339
+ function z(t, e, s = [], n = {}, r) {
340
340
  const i = [];
341
341
  let o = {}, c = [];
342
342
  const f = [];
343
- let l = [];
343
+ let u = [];
344
344
  return be(t).forEach((a) => {
345
345
  const y = [];
346
346
  for (const m of a.children) {
347
- let { id: d, name: $, invisible: j, from: g } = m;
348
- if (j)
347
+ let { id: d, name: $, invisible: v, from: g } = m;
348
+ if (v)
349
349
  continue;
350
350
  const E = je($, e, g);
351
- E && c.push(E), Y(g) && l.push({ id: g.id, name: $ });
352
- const { props: P, events: O, handlers: x } = Ee(
351
+ E && c.push(E), Y(g) && u.push({ id: g.id, name: $ });
352
+ const { props: O, events: P, handlers: x } = Ee(
353
353
  m,
354
354
  d,
355
355
  m.props,
356
356
  m.events,
357
- s,
358
- n
359
- ), R = Pe(
360
- m.directives,
361
357
  n,
358
+ s
359
+ ), T = Oe(
360
+ m.directives,
361
+ s,
362
362
  f
363
363
  ).join(" "), S = m.children ? xe(
364
364
  m.children,
365
- n,
366
- e,
367
365
  s,
366
+ e,
367
+ n,
368
368
  m
369
369
  ) : "";
370
370
  Object.assign(o, x);
371
371
  let _ = "";
372
372
  typeof S == "string" ? _ = S : (_ = (S?.nodes || []).join(`
373
- `), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), l = l.concat(S?.importBlocks || []));
373
+ `), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), u = u.concat(S?.importBlocks || []));
374
374
  const I = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
375
375
  g || e.get($)?.package
376
376
  ) ? F($) : Z(g) || K(g) ? "component" : $;
377
377
  y.push(
378
- $e.includes(I) ? `<${I} ${R} ${P} ${O} />` : `<${I} ${R} ${P} ${O}>${_ ? `
378
+ $e.includes(I) ? `<${I} ${T} ${O} ${P} />` : `<${I} ${T} ${O} ${P}>${_ ? `
379
379
  ` + _.trim() : ""}</${I}>`
380
380
  );
381
381
  }
@@ -387,7 +387,7 @@ function z(t, e, n = [], s = {}, r) {
387
387
  methods: o,
388
388
  directives: ve(f),
389
389
  components: C(c),
390
- importBlocks: C(l, "id")
390
+ importBlocks: C(u, "id")
391
391
  };
392
392
  }
393
393
  function ve(t) {
@@ -395,20 +395,20 @@ function ve(t) {
395
395
  }
396
396
  function be(t = []) {
397
397
  const e = /* @__PURE__ */ new Map();
398
- for (const n of t) {
399
- const s = typeof n.slot == "string" ? n.slot : n.slot?.name, r = e.get(s);
400
- r ? r.children.push(n) : e.set(s, { slot: n.slot, children: [n] });
398
+ for (const s of t) {
399
+ const n = typeof s.slot == "string" ? s.slot : s.slot?.name, r = e.get(n);
400
+ r ? r.children.push(s) : e.set(n, { slot: s.slot, children: [s] });
401
401
  }
402
402
  return e;
403
403
  }
404
- function je(t, e, n) {
404
+ function je(t, e, s) {
405
405
  if (oe.includes(t)) return null;
406
- const s = e.get(t);
407
- if (s && s.alias) {
408
- const r = s.parent ? `${s.parent}.${s.alias}` : s.alias;
406
+ const n = e.get(t);
407
+ if (n && n.alias) {
408
+ const r = n.parent ? `${n.parent}.${n.alias}` : n.alias;
409
409
  return `${t}: ${r}`;
410
410
  }
411
- return Y(n) || s ? t : null;
411
+ return Y(s) || n ? t : null;
412
412
  }
413
413
  function Y(t) {
414
414
  return !!t && typeof t == "object" && t.type === "Schema";
@@ -419,149 +419,149 @@ function Z(t) {
419
419
  function K(t) {
420
420
  return typeof t == "object" && t.type === "Plugin";
421
421
  }
422
- function Se(t, e, n = []) {
423
- return t === "style" ? b(e) ? `:style="${h({
422
+ function Se(t, e, s = []) {
423
+ return t === "style" ? j(e) ? `:style="${h({
424
424
  ...e,
425
- value: w(e.value, n)
426
- })}"` : "" : t === "__class" && b(e) ? `:class="${h({
425
+ value: w(e.value, s)
426
+ })}"` : "" : t === "__class" && j(e) ? `:class="${h({
427
427
  ...e,
428
- value: w(e.value, n)
429
- })}"` : typeof e == "string" ? `${t}="${e}"` : b(e) ? `:${t}="${h({
428
+ value: w(e.value, s)
429
+ })}"` : typeof e == "string" ? `${t}="${e}"` : j(e) ? `:${t}="${h({
430
430
  ...e,
431
- value: w(e.value, n)
432
- })}"` : se(e) ? `:${t}='{${ae(
431
+ value: w(e.value, s)
432
+ })}"` : ne(e) ? `:${t}='{${ae(
433
433
  e
434
434
  ).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
435
435
  }
436
- function ke(t, e = {}, n = []) {
436
+ function ke(t, e = {}, s = []) {
437
437
  if (!!Object.keys(e.style || {}).length) {
438
438
  const i = `${t.name}_${t.id}`;
439
- 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;
439
+ e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : e.class = i, j(e.style) || delete e.style;
440
440
  }
441
441
  const r = t.from;
442
442
  return (Z(r) || K(r)) && (e.is = {
443
443
  type: "JSExpression",
444
444
  value: t.name
445
- }), Object.entries(e).map(([i, o]) => Se(i, o, n));
445
+ }), Object.entries(e).map(([i, o]) => Se(i, o, s));
446
446
  }
447
- function we(t, e, n, s, r) {
447
+ function we(t, e, s, n, r) {
448
448
  const i = X(e.modifiers, !0);
449
- return r ? `@${t}${i.join("")}="${n}"` : s && s.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${n}"` : `@${t}${i.join("")}="${n}"`;
449
+ return r ? `@${t}${i.join("")}="${s}"` : n && n.length > 0 ? `@${t}${i.join("")}="(...args:any[]) => ${s}"` : `@${t}${i.join("")}="${s}"`;
450
450
  }
451
- function Ce(t, e = {}, n = {}) {
452
- const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
451
+ function Ce(t, e = {}, s = {}) {
452
+ const n = {}, r = Array.from(s[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
453
453
  return {
454
454
  binders: Object.entries(e).map(([c, f]) => {
455
- const l = f.handler.value.startsWith("this."), u = l ? Q(f.handler.value) : `${v(c)}_${t}${i}`;
456
- return l || (s[u] = r.length ? {
455
+ const u = f.handler.value.startsWith("this."), l = u ? Q(f.handler.value) : `${b(c)}_${t}${i}`;
456
+ return u || (n[l] = r.length ? {
457
457
  type: "JSFunction",
458
458
  value: `{
459
459
  return (${f.handler.value}).apply(this, args);
460
460
  }`
461
- } : f.handler), we(c, f, u, r, l);
461
+ } : f.handler), we(c, f, l, r, u);
462
462
  }),
463
- handlers: s
463
+ handlers: n
464
464
  };
465
465
  }
466
- function Ee(t, e, n = {}, s = {}, r = {}, i) {
467
- const { binders: o, handlers: c } = Ce(e, s, r);
466
+ function Ee(t, e, s = {}, n = {}, r = {}, i) {
467
+ const { binders: o, handlers: c } = Ce(e, n, r);
468
468
  return {
469
- props: ke(t, n, i).join(" "),
469
+ props: ke(t, s, i).join(" "),
470
470
  handlers: c,
471
471
  binders: o,
472
472
  events: o.join(" ")
473
473
  };
474
474
  }
475
- function Pe(t = [], e = [], n = []) {
476
- const s = [], {
475
+ function Oe(t = [], e = [], s = []) {
476
+ const n = [], {
477
477
  vIf: r,
478
478
  vElse: i,
479
479
  vElseIf: o,
480
480
  vShow: c,
481
481
  vModels: f,
482
- vFor: l,
483
- vBind: u,
482
+ vFor: u,
483
+ vBind: l,
484
484
  vHtml: a,
485
485
  customDirectives: y
486
- } = Oe(t);
487
- if (r && s.push(`v-if="${h(r.value, !0, !0, e)}"`), o && s.push(
486
+ } = Pe(t);
487
+ if (r && n.push(`v-if="${h(r.value, !0, !0, e)}"`), o && n.push(
488
488
  `v-else-if="${h(o.value, !0, !0, e)}"`
489
- ), i && s.push("v-else"), c && s.push(
489
+ ), i && n.push("v-else"), c && n.push(
490
490
  `v-show="${h(c.value, !0, !0, e)}"`
491
- ), u && s.push(
492
- `v-bind="${h(u.value, !0, !0, e)}"`
491
+ ), l && n.push(
492
+ `v-bind="${h(l.value, !0, !0, e)}"`
493
493
  ), f.forEach((p) => {
494
494
  const m = X(p.modifiers, !0), d = p.arg ? k(p.arg) ? `:[${h(p.arg, !0, !0, e)}]` : `:${p.arg}` : "";
495
- s.push(
495
+ n.push(
496
496
  `v-model${d}${m}="${h(p.value, !0, !0, e)}"`
497
497
  );
498
- }), l) {
499
- const { item: p, index: m } = { item: "item", index: "index", ...l.iterator };
500
- s.push(
501
- `v-for="(${p}, ${m}) in ${h(l.value, !0, !0, e)}"`
498
+ }), u) {
499
+ const { item: p, index: m } = { item: "item", index: "index", ...u.iterator };
500
+ n.push(
501
+ `v-for="(${p}, ${m}) in ${h(u.value, !0, !0, e)}"`
502
502
  );
503
503
  }
504
- return a && s.push(
504
+ return a && n.push(
505
505
  `v-html="${h(a.value, !0, !0, e)}"`
506
506
  ), y && y.length && y.forEach((p) => {
507
507
  if (!p.name) return;
508
508
  let m = "", d = "";
509
- k(p.name) ? (d = h(p.name, !0, !0, e), n.push(d)) : d = p.name;
509
+ k(p.name) ? (d = h(p.name, !0, !0, e), s.push(d)) : d = p.name;
510
510
  const $ = d?.startsWith("v") ? F(d) : F("v-" + d);
511
511
  if (m += $, p.arg && (k(p.arg) ? m += `:[${h(p.name, !0, !0, e)}]` : m += `:${p.arg}`), p.modifiers) {
512
- const j = Object.keys(p.modifiers);
513
- j.length && (m += j.map((g) => "." + g));
512
+ const v = Object.keys(p.modifiers);
513
+ v.length && (m += v.map((g) => "." + g));
514
514
  }
515
- p.value ? s.push(
515
+ p.value ? n.push(
516
516
  `${m}="${h(p.value, !0, !0, e)}"`
517
- ) : s.push(m);
518
- }), s;
517
+ ) : n.push(m);
518
+ }), n;
519
519
  }
520
- function Oe(t = []) {
520
+ function Pe(t = []) {
521
521
  const e = t.filter(
522
- (a) => L.includes(a.name)
523
- ), n = t.filter(
524
- (a) => !L.includes(a.name)
525
- ), s = e.find(
526
- (a) => v(a.name) === "vIf"
522
+ (a) => J.includes(a.name)
523
+ ), s = t.filter(
524
+ (a) => !J.includes(a.name)
525
+ ), n = e.find(
526
+ (a) => b(a.name) === "vIf"
527
527
  ), r = e.find(
528
- (a) => v(a.name) === "vElseIf"
528
+ (a) => b(a.name) === "vElseIf"
529
529
  ), i = e.find(
530
- (a) => v(a.name) === "vElse"
530
+ (a) => b(a.name) === "vElse"
531
531
  ), o = e.find(
532
- (a) => v(a.name) === "vFor"
532
+ (a) => b(a.name) === "vFor"
533
533
  ), c = e.find(
534
- (a) => v(a.name) === "vShow"
534
+ (a) => b(a.name) === "vShow"
535
535
  ), f = e.find(
536
- (a) => v(a.name) === "vBind"
537
- ), l = e.find(
538
- (a) => v(a.name) === "vHtml"
539
- ), u = e.filter(
540
- (a) => v(a.name) === "vModel"
536
+ (a) => b(a.name) === "vBind"
537
+ ), u = e.find(
538
+ (a) => b(a.name) === "vHtml"
539
+ ), l = e.filter(
540
+ (a) => b(a.name) === "vModel"
541
541
  );
542
542
  return {
543
- vIf: s,
543
+ vIf: n,
544
544
  vElseIf: r,
545
545
  vElse: i,
546
546
  vFor: o,
547
547
  vShow: c,
548
- vModels: u,
548
+ vModels: l,
549
549
  vBind: f,
550
- vHtml: l,
551
- customDirectives: n
550
+ vHtml: u,
551
+ customDirectives: s
552
552
  };
553
553
  }
554
- function xe(t, e, n, s, r) {
555
- return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, n, e, s, r) : "";
554
+ function xe(t, e, s, n, r) {
555
+ return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? z(t, s, e, n, r) : "";
556
556
  }
557
- function _e(t, e, n) {
557
+ function _e(t, e, s) {
558
558
  if (!t) return e;
559
- const s = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
560
- return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
559
+ const n = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
560
+ return `<template ${`#${n.name}="${n.params?.length > 0 ? `{${n.params?.join(",")}}` : `scope_${s}`}"`}>
561
561
  ${e}
562
562
  </template>`;
563
563
  }
564
- function Ie(t, e = [], n = [], s = {}, r = "web") {
564
+ function Ie(t, e = [], s = [], n = {}, r = "web") {
565
565
  const i = [
566
566
  "@dcloudio/uni-h5",
567
567
  "uni-h5",
@@ -570,28 +570,28 @@ function Ie(t, e = [], n = [], s = {}, r = "web") {
570
570
  ], o = {
571
571
  vue: ["defineComponent", "reactive"]
572
572
  }, c = [];
573
- for (const l of e) {
574
- const u = t.get(l.split(":")[0]);
575
- if (u && u.package) {
576
- const a = o[u.package] ?? (o[u.package] = []), y = u.parent || (u.alias || "").split(".")[0] || u.name;
577
- a.push(y), r === "uniapp" && i.includes(u.package) && c.push(y);
573
+ for (const u of e) {
574
+ const l = t.get(u.split(":")[0]);
575
+ if (l && l.package) {
576
+ const a = o[l.package] ?? (o[l.package] = []), y = l.parent || (l.alias || "").split(".")[0] || l.name;
577
+ a.push(y), r === "uniapp" && i.includes(l.package) && c.push(y);
578
578
  }
579
579
  }
580
- for (const [l, u] of Object.entries(s))
581
- (o[l] ?? (o[l] = [])).push(...Array.from(u)), r === "uniapp" && i.includes(l) && c.push(...Array.from(u));
580
+ for (const [u, l] of Object.entries(n))
581
+ (o[u] ?? (o[u] = [])).push(...Array.from(l)), r === "uniapp" && i.includes(u) && c.push(...Array.from(l));
582
582
  return {
583
- imports: Object.entries(o).filter(([l, u]) => r === "uniapp" ? !i.includes(l) && !!u.length : !!u.length).map(([l, u]) => `import { ${C(u).join(
583
+ imports: Object.entries(o).filter(([u, l]) => r === "uniapp" ? !i.includes(u) && !!l.length : !!l.length).map(([u, l]) => `import { ${C(l).join(
584
584
  ","
585
- )}} from '${l}';`).concat(n),
585
+ )}} from '${u}';`).concat(s),
586
586
  uniComponents: c
587
587
  };
588
588
  }
589
589
  function Ae(t = {}) {
590
590
  const e = [];
591
- for (const [n, s] of Object.entries(t))
591
+ for (const [s, n] of Object.entries(t))
592
592
  e.push(`
593
- ${n} {
594
- ${le(s)}
593
+ ${s} {
594
+ ${le(n)}
595
595
  }
596
596
  `);
597
597
  return e.join(`
@@ -599,76 +599,76 @@ function Ae(t = {}) {
599
599
  }
600
600
  function Ne(t = {}) {
601
601
  const e = [];
602
- return Object.entries(t).forEach(([n, s]) => {
602
+ return Object.entries(t).forEach(([s, n]) => {
603
603
  e.push(
604
- `const ${n} = provider.defineUrlSchemaComponent('${s.url}');`
604
+ `const ${s} = provider.defineUrlSchemaComponent('${n.url}');`
605
605
  );
606
606
  }), e;
607
607
  }
608
608
  function Fe(t = {}) {
609
609
  const e = [];
610
- return Object.entries(t).forEach(([n, s]) => {
610
+ return Object.entries(t).forEach(([s, n]) => {
611
611
  e.push(
612
- `const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`
612
+ `const ${s} = provider.definePluginComponent(${JSON.stringify(n)});`
613
613
  );
614
614
  }), e;
615
615
  }
616
- function Be(t, e, n = "web") {
617
- const { dsl: s } = t, r = Object.keys(s.computed || {}), i = A(s.lifeCycles, r), o = A(s.computed, r), c = ye(s.watch, r), f = ge(s.dataSources), { methods: l, nodes: u, components: a, importBlocks: y, directives: p } = z(
618
- s.nodes || [],
616
+ function Be(t, e, s = "web") {
617
+ const { dsl: n } = t, r = Object.keys(n.computed || {}), i = A(n.lifeCycles, r), o = A(n.computed, r), c = ge(n.watch, r), f = ye(n.dataSources), { methods: u, nodes: l, components: a, importBlocks: y, directives: p } = z(
618
+ n.nodes || [],
619
619
  e,
620
620
  r,
621
621
  t.context
622
622
  ), m = [...o, ...c.computed], d = A(
623
623
  {
624
- ...l,
625
- ...s.methods || {}
624
+ ...u,
625
+ ...n.methods || {}
626
626
  },
627
627
  r
628
628
  ), $ = y.map((x) => `import ${x.name} from './${x.id}.vue';`);
629
- let { imports: j, uniComponents: g } = Ie(
629
+ let { imports: v, uniComponents: g } = Ie(
630
630
  e,
631
631
  a,
632
632
  $,
633
633
  t.imports,
634
- n
634
+ s
635
635
  );
636
636
  const E = Object.keys({
637
637
  ...t.urlSchemas,
638
638
  ...t.blockPlugins
639
- }), P = Ne(t.urlSchemas), O = Fe(t.blockPlugins);
639
+ }), O = Ne(t.urlSchemas), P = Fe(t.blockPlugins);
640
640
  return {
641
- id: s.id,
642
- version: s.__VERSION__,
643
- name: s.name,
644
- state: fe(s.state).join(","),
645
- inject: me(s.inject).join(","),
646
- props: he(s.props).join(","),
647
- emits: de(s.emits).join(","),
641
+ id: n.id,
642
+ version: n.__VERSION__,
643
+ name: n.name,
644
+ state: fe(n.state).join(","),
645
+ inject: me(n.inject).join(","),
646
+ props: he(n.props).join(","),
647
+ emits: de(n.emits).join(","),
648
648
  watch: c.watches.join(","),
649
649
  lifeCycles: i.join(","),
650
650
  computed: m.join(","),
651
651
  methods: [...f, ...d].join(","),
652
652
  imports: `
653
- ` + j.join(`
653
+ ` + v.join(`
654
654
  `),
655
655
  components: ue(a, g).join(","),
656
656
  directives: p.join(","),
657
657
  returns: t.members.join(","),
658
- template: u.join(`
658
+ template: l.join(`
659
659
  `),
660
- css: s.css || "",
660
+ css: n.css || "",
661
661
  style: Ae(t.style),
662
- urlSchemas: P.join(`
662
+ urlSchemas: O.join(`
663
663
  `),
664
- blockPlugins: O.join(`
664
+ blockPlugins: P.join(`
665
665
  `),
666
666
  asyncComponents: E.join(","),
667
667
  uniComponents: g,
668
- renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
668
+ renderer: s === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
669
669
  };
670
670
  }
671
- const Te = `
671
+ const De = `
672
672
  // @ts-nocheck
673
673
 
674
674
  <%= imports %>
@@ -700,28 +700,44 @@ export default defineComponent({
700
700
  <% if(methods) { %> methods: { <%= methods %> }, <% } %>
701
701
  <% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
702
702
  });
703
- `.replace(/(\n|\r|\t)/g, ""), Re = `
703
+ `.replace(/(\n|\r|\t)/g, ""), Te = `
704
704
  <template>
705
705
  <%= template %>
706
706
  </template>
707
- <script lang="ts">
707
+ <script lang="<%= scriptLang %>">
708
708
  <%= script %>
709
709
  <\/script>
710
- <style lang="scss" scoped>
710
+ <style lang="<%= styleLang %>" scoped>
711
711
  <%= css %>
712
712
  <%= style %>
713
713
  </style>
714
- `, We = U(Te), Je = U(Re);
715
- async function Ve(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
716
- const i = new pe(re(t), n), o = Be(i, e, s), c = We(o), f = Je({
717
- template: o.template,
718
- css: await W(o.css, r),
719
- script: await ce(c, r),
720
- style: await W(o.style, r)
714
+ `, Le = U(De), Re = U(Te);
715
+ async function Me(t, e = /* @__PURE__ */ new Map(), s = [], n = "web", r) {
716
+ const i = t, o = typeof i.dsl == "object" && arguments.length === 1 ? i : {
717
+ dsl: t,
718
+ componentMap: e,
719
+ dependencies: s,
720
+ platform: n,
721
+ formatterDisabled: r
722
+ }, {
723
+ dsl: c,
724
+ componentMap: f = /* @__PURE__ */ new Map(),
725
+ dependencies: u = [],
726
+ platform: l = "web",
727
+ formatterDisabled: a = !1,
728
+ ts: y = !0,
729
+ scss: p = !1
730
+ } = o, m = new pe(re(c), u), d = Be(m, f, l), $ = Le(d), v = Re({
731
+ template: d.template,
732
+ css: await L(d.css, a),
733
+ script: await ce($, a),
734
+ style: await L(d.style, a),
735
+ scriptLang: y ? "ts" : "js",
736
+ styleLang: p ? "scss" : "css"
721
737
  });
722
- return await M(f, r).catch((l) => (l.content = f, Promise.reject(l)));
738
+ return await q(v, a).catch((g) => (g.content = v, Promise.reject(g)));
723
739
  }
724
- async function He(t) {
740
+ async function Ve(t) {
725
741
  const e = `
726
742
  <template>
727
743
  <div>
@@ -734,13 +750,13 @@ async function He(t) {
734
750
  <style scoped lang="scss">
735
751
  </style>
736
752
  `;
737
- return await M(e);
753
+ return await q(e);
738
754
  }
739
755
  export {
740
756
  Ue as VTJ_CODER_VERSION,
741
- He as createEmptyPage,
742
- W as cssFormatter,
743
- Ve as generator,
757
+ Ve as createEmptyPage,
758
+ L as cssFormatter,
759
+ Me as generator,
744
760
  ce as tsFormatter,
745
- M as vueFormatter
761
+ q as vueFormatter
746
762
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.12.59",
4
+ "version": "0.12.60",
5
5
  "type": "module",
6
6
  "keywords": [
7
7
  "低代码引擎",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "prettier": "~3.6.0",
25
25
  "@vtj/base": "~0.12.2",
26
- "@vtj/core": "~0.12.59"
26
+ "@vtj/core": "~0.12.60"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@vtj/cli": "~0.12.8"
@@ -6,5 +6,14 @@ import { BlockSchema, MaterialDescription, Dependencie, PageFile, PlatformType }
6
6
  * 3. Parser 解析 dsl,提取 token
7
7
  * 4. Compiled token 注入模板生成代码文件字符串
8
8
  */
9
- export declare function generator(dsl: BlockSchema, componentMap?: Map<string, MaterialDescription>, dependencies?: Dependencie[], platform?: PlatformType, formatterDisabled?: boolean): Promise<string>;
9
+ export interface GeneratorOptions {
10
+ dsl: BlockSchema;
11
+ componentMap?: Map<string, MaterialDescription>;
12
+ dependencies?: Dependencie[];
13
+ platform?: PlatformType;
14
+ formatterDisabled?: boolean;
15
+ ts?: boolean;
16
+ scss?: boolean;
17
+ }
18
+ export declare function generator(_dsl: BlockSchema | GeneratorOptions, _componentMap?: Map<string, MaterialDescription>, _dependencies?: Dependencie[], _platform?: PlatformType, _formatterDisabled?: boolean): Promise<string>;
10
19
  export declare function createEmptyPage(file: PageFile): Promise<string>;
@@ -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.58
5
+ * @version 0.12.59
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.12.58";
8
+ export declare const version = "0.12.59";