@vtj/coder 0.12.10 → 0.12.11
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 +33 -33
- package/dist/index.mjs +196 -176
- package/package.json +3 -3
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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.
|
|
5
|
+
* @version 0.12.11
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const ne="0.12.11";/**!
|
|
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.
|
|
11
|
+
* @version 0.12.11
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const
|
|
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
|
-
default: ${
|
|
16
|
-
}`)}function pe(t=[]){const e=
|
|
17
|
-
type:${e(
|
|
18
|
-
required: ${
|
|
19
|
-
default: ${
|
|
20
|
-
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function
|
|
15
|
+
default: ${d(e.default,!0,!1)}
|
|
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}: {
|
|
17
|
+
type:${e(s.type)},
|
|
18
|
+
required: ${d(!!s.required,!0,!1)},
|
|
19
|
+
default: ${d(s.default,!0,!1)}
|
|
20
|
+
}`))}function fe(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function A(t={},e=[]){return Object.entries(t).map(([s,n])=>{let r=H(d(n,!1,!1));return r=w(r,e),r.startsWith("async")?`async ${s}${r.replace(/^async/,"")}`:`${s}${r}`})}function me(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${H(i.handler.value)}
|
|
24
|
-
}`);return{computed:
|
|
25
|
-
const mock = this.provider.createMock(${
|
|
24
|
+
}`);return{computed:n,watches:r}}function he(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:any[]) {
|
|
25
|
+
const mock = this.provider.createMock(${s})
|
|
26
26
|
return await mock.apply(this, args);
|
|
27
|
-
}`}else{const
|
|
28
|
-
return await this.provider.apis['${e.ref}'].apply(this, args).then(${
|
|
29
|
-
}`}})}const de=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],q=["vIf","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,
|
|
30
|
-
`),Object.assign(
|
|
31
|
-
`+_.trim():""}</${x}>`)}const
|
|
32
|
-
`),
|
|
33
|
-
return (${
|
|
34
|
-
}`}:
|
|
27
|
+
}`}else{const s=I(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
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"],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
|
+
return (${f.handler.value}).apply(this, args);
|
|
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
|
|
37
|
-
${
|
|
38
|
-
${oe(
|
|
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
|
+
${s} {
|
|
38
|
+
${oe(n)}
|
|
39
39
|
}
|
|
40
40
|
`);return e.join(`
|
|
41
|
-
`)}function
|
|
42
|
-
`+
|
|
43
|
-
`),components:ce(
|
|
44
|
-
`),css:
|
|
45
|
-
`),blockPlugins:
|
|
46
|
-
`),asyncComponents:
|
|
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
|
+
`+j.join(`
|
|
43
|
+
`),components:ce(a,v).join(","),directives:p.join(","),returns:t.members.join(","),template:u.join(`
|
|
44
|
+
`),css:n.css||"",style:_e(t.style),urlSchemas:P.join(`
|
|
45
|
+
`),blockPlugins:O.join(`
|
|
46
|
+
`),asyncComponents:C.join(","),uniComponents:v,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const Fe=`
|
|
47
47
|
// @ts-nocheck
|
|
48
48
|
|
|
49
49
|
<%= imports %>
|
|
@@ -75,7 +75,7 @@ export default defineComponent({
|
|
|
75
75
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
76
76
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
77
77
|
});
|
|
78
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
78
|
+
`.replace(/(\n|\r|\t)/g,""),Ne=`
|
|
79
79
|
<template>
|
|
80
80
|
<%= template %>
|
|
81
81
|
</template>
|
|
@@ -86,7 +86,7 @@ export default defineComponent({
|
|
|
86
86
|
<%= css %>
|
|
87
87
|
<%= style %>
|
|
88
88
|
</style>
|
|
89
|
-
`,Te=
|
|
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>
|
|
@@ -97,4 +97,4 @@ export default defineComponent({
|
|
|
97
97
|
<\/script>
|
|
98
98
|
<style scoped lang="scss">
|
|
99
99
|
</style>
|
|
100
|
-
`;return await R(e)}exports.VTJ_CODER_VERSION=
|
|
100
|
+
`;return await R(e)}exports.VTJ_CODER_VERSION=ne;exports.createEmptyPage=We;exports.cssFormatter=N;exports.generator=Re;exports.tsFormatter=V;exports.vueFormatter=R;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mitt as K, dedupArray as
|
|
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.
|
|
11
|
+
* @version 0.12.11
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Le = "0.12.
|
|
14
|
+
const Le = "0.12.11";
|
|
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.
|
|
19
|
+
* @version 0.12.11
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const re = [
|
|
@@ -79,14 +79,14 @@ async function W(t, e) {
|
|
|
79
79
|
plugins: [V]
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
|
-
function
|
|
82
|
+
function k(t) {
|
|
83
83
|
return t && t.type === "JSExpression";
|
|
84
84
|
}
|
|
85
85
|
function N(t) {
|
|
86
86
|
return typeof t == "object" && t && t.type === "JSFunction";
|
|
87
87
|
}
|
|
88
|
-
function
|
|
89
|
-
return
|
|
88
|
+
function b(t) {
|
|
89
|
+
return k(t) || N(t);
|
|
90
90
|
}
|
|
91
91
|
function M(t) {
|
|
92
92
|
return t.replace(new RegExp("this.", "g"), "");
|
|
@@ -94,11 +94,11 @@ function M(t) {
|
|
|
94
94
|
function J(t) {
|
|
95
95
|
return t.replace(/this\.context\??\./g, "");
|
|
96
96
|
}
|
|
97
|
-
function
|
|
98
|
-
let r =
|
|
99
|
-
return r =
|
|
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 ? M(J(r)) : J(r);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function w(t, e = []) {
|
|
102
102
|
let n = t;
|
|
103
103
|
for (const s of e)
|
|
104
104
|
n = n.replace(
|
|
@@ -121,7 +121,7 @@ function Q(t) {
|
|
|
121
121
|
return e;
|
|
122
122
|
}
|
|
123
123
|
function oe(t = {}) {
|
|
124
|
-
return Object.entries(t).map(([e, n]) => `"${e}": ${
|
|
124
|
+
return Object.entries(t).map(([e, n]) => `"${e}": ${h(n)}`);
|
|
125
125
|
}
|
|
126
126
|
function G(t = {}, e = !1) {
|
|
127
127
|
const n = Object.keys(t);
|
|
@@ -139,7 +139,7 @@ function ce(t) {
|
|
|
139
139
|
function ae(t = [], e = []) {
|
|
140
140
|
return t.filter((n) => !e.includes(n));
|
|
141
141
|
}
|
|
142
|
-
class
|
|
142
|
+
class le {
|
|
143
143
|
constructor(e, n) {
|
|
144
144
|
this.dsl = e, this.dependencies = n, this.libraryRegex = this.collectLibrary(), this.walk(e), this.walkNodes(e), this.members = this.getLibraryMember();
|
|
145
145
|
}
|
|
@@ -166,10 +166,10 @@ class ue {
|
|
|
166
166
|
if (n.length === 4) {
|
|
167
167
|
const s = n.pop(), r = n.join(".") + ".", i = n.pop();
|
|
168
168
|
if (s && i) {
|
|
169
|
-
const
|
|
170
|
-
(
|
|
169
|
+
const o = this.dependencies.find(
|
|
170
|
+
(c) => c.library === i
|
|
171
171
|
)?.package;
|
|
172
|
-
|
|
172
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(s);
|
|
173
173
|
}
|
|
174
174
|
return {
|
|
175
175
|
name: s,
|
|
@@ -185,11 +185,11 @@ class ue {
|
|
|
185
185
|
let s = e.value;
|
|
186
186
|
for (const r of n) {
|
|
187
187
|
const i = e.value?.match(r) || [];
|
|
188
|
-
for (const
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
const
|
|
192
|
-
s = s.replace(new RegExp(
|
|
188
|
+
for (const o of i) {
|
|
189
|
+
const c = this.collectImport(o);
|
|
190
|
+
if (c) {
|
|
191
|
+
const f = c.path.replace(/\$/g, "\\$");
|
|
192
|
+
s = s.replace(new RegExp(f, "g"), "");
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
@@ -205,7 +205,7 @@ class ue {
|
|
|
205
205
|
}
|
|
206
206
|
const r = Object.values(s);
|
|
207
207
|
for (const i of r)
|
|
208
|
-
|
|
208
|
+
b(i) ? i.value = this.replaceLibraryPath(i) : n(i);
|
|
209
209
|
};
|
|
210
210
|
n(e);
|
|
211
211
|
}
|
|
@@ -215,24 +215,24 @@ class ue {
|
|
|
215
215
|
delete s["uni-h5"], delete s["@dcloudio/uni-h5"], delete s["uni-ui"], delete s["@dcloudio/uni-ui"];
|
|
216
216
|
for (const r of Object.values(s))
|
|
217
217
|
n = n.concat(Array.from(r));
|
|
218
|
-
return
|
|
218
|
+
return C(n);
|
|
219
219
|
}
|
|
220
220
|
collectContext(e, n) {
|
|
221
|
-
const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((
|
|
221
|
+
const s = new Set(n?.id ? this.context[n.id] : []), r = (e.directives || []).find((c) => c.name === "vFor");
|
|
222
222
|
let i = new Set(Array.from(s));
|
|
223
223
|
if (r) {
|
|
224
|
-
const { item:
|
|
225
|
-
i = /* @__PURE__ */ new Set([
|
|
224
|
+
const { item: c = "item", index: f = "index" } = r.iterator || {};
|
|
225
|
+
i = /* @__PURE__ */ new Set([c, f, ...Array.from(i)]);
|
|
226
226
|
}
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
const
|
|
230
|
-
i = /* @__PURE__ */ new Set([...
|
|
227
|
+
const o = e.slot;
|
|
228
|
+
if (o) {
|
|
229
|
+
const c = typeof o == "string" ? [] : o.params || [], f = c.length ? c : [`scope_${n?.id}`];
|
|
230
|
+
i = /* @__PURE__ */ new Set([...f, ...Array.from(i)]);
|
|
231
231
|
}
|
|
232
232
|
this.context[e.id] = i;
|
|
233
233
|
}
|
|
234
234
|
collectStyle(e) {
|
|
235
|
-
e.id && e.props?.style && Object.keys(e.props.style).length &&
|
|
235
|
+
e.id && e.props?.style && Object.keys(e.props.style).length && !b(e.props.style) && (this.style[`.${e.name}_${e.id}`] = e.props.style);
|
|
236
236
|
}
|
|
237
237
|
collectUrlSchema(e) {
|
|
238
238
|
typeof e.from == "object" && e.from.type === "UrlSchema" && (this.urlSchemas[e.name] = e.from);
|
|
@@ -247,24 +247,24 @@ class ue {
|
|
|
247
247
|
Array.isArray(e.nodes) && e.nodes.forEach((s) => n(s));
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
function
|
|
250
|
+
function ue(t = {}) {
|
|
251
251
|
return Object.entries(t).map(([e, n]) => {
|
|
252
|
-
const s =
|
|
252
|
+
const s = h(n, !1);
|
|
253
253
|
return `${e}:${s}`;
|
|
254
254
|
});
|
|
255
255
|
}
|
|
256
256
|
function pe(t = []) {
|
|
257
257
|
return t.map((e) => `${e.name}: {
|
|
258
258
|
from: '${e.from || e.name}',
|
|
259
|
-
default: ${
|
|
259
|
+
default: ${h(e.default, !0, !1)}
|
|
260
260
|
}`);
|
|
261
261
|
}
|
|
262
262
|
function fe(t = []) {
|
|
263
263
|
const e = (n) => n ? `[${ee(n).map((i) => i.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
264
|
-
return t.map((n) => typeof n == "string" ? `${n}: {}` : (
|
|
264
|
+
return t.map((n) => typeof n == "string" ? `${n}: {}` : (b(n.default) && !n.default.value && (n.default.value = "undefined"), `${n.name}: {
|
|
265
265
|
type:${e(n.type)},
|
|
266
|
-
required: ${
|
|
267
|
-
default: ${
|
|
266
|
+
required: ${h(!!n.required, !0, !1)},
|
|
267
|
+
default: ${h(n.default, !0, !1)}
|
|
268
268
|
}`));
|
|
269
269
|
}
|
|
270
270
|
function me(t = []) {
|
|
@@ -272,13 +272,13 @@ function me(t = []) {
|
|
|
272
272
|
}
|
|
273
273
|
function A(t = {}, e = []) {
|
|
274
274
|
return Object.entries(t).map(([n, s]) => {
|
|
275
|
-
let r = Q(
|
|
276
|
-
return r =
|
|
275
|
+
let r = Q(h(s, !1, !1));
|
|
276
|
+
return r = w(r, e), r.startsWith("async") ? `async ${n}${r.replace(/^async/, "")}` : `${n}${r}`;
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
279
|
function he(t = [], e = []) {
|
|
280
280
|
const n = t.reduce(
|
|
281
|
-
(i,
|
|
281
|
+
(i, o) => (o.id && N(o.source) && (i[`watcher_${o.id}`] = o.source), i),
|
|
282
282
|
{}
|
|
283
283
|
), s = A(n, e), r = t.map((i) => `watcher_${i.id}: {
|
|
284
284
|
deep: ${i.deep},
|
|
@@ -323,6 +323,8 @@ const ye = [
|
|
|
323
323
|
"wbr"
|
|
324
324
|
], L = [
|
|
325
325
|
"vIf",
|
|
326
|
+
"vElseIf",
|
|
327
|
+
"vElse",
|
|
326
328
|
"vShow",
|
|
327
329
|
"vModel",
|
|
328
330
|
"vFor",
|
|
@@ -331,60 +333,60 @@ const ye = [
|
|
|
331
333
|
];
|
|
332
334
|
function X(t, e, n = [], s = {}, r) {
|
|
333
335
|
const i = [];
|
|
334
|
-
let
|
|
335
|
-
const
|
|
336
|
-
let
|
|
337
|
-
return $e(t).forEach((
|
|
338
|
-
const
|
|
339
|
-
for (const
|
|
340
|
-
let { id:
|
|
341
|
-
if (
|
|
336
|
+
let o = {}, c = [];
|
|
337
|
+
const f = [];
|
|
338
|
+
let l = [];
|
|
339
|
+
return $e(t).forEach((a) => {
|
|
340
|
+
const y = [];
|
|
341
|
+
for (const m of a.children) {
|
|
342
|
+
let { id: d, name: $, invisible: j, from: g } = m;
|
|
343
|
+
if (j)
|
|
342
344
|
continue;
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
+
const E = ve($, e, g);
|
|
346
|
+
E && c.push(E), z(g) && l.push({ id: g.id, name: $ });
|
|
345
347
|
const { props: P, events: O, handlers: x } = we(
|
|
348
|
+
m,
|
|
346
349
|
d,
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
d.events,
|
|
350
|
+
m.props,
|
|
351
|
+
m.events,
|
|
350
352
|
s,
|
|
351
353
|
n
|
|
352
354
|
), R = Ce(
|
|
353
|
-
|
|
355
|
+
m.directives,
|
|
354
356
|
n,
|
|
355
|
-
|
|
356
|
-
).join(" "),
|
|
357
|
-
|
|
357
|
+
f
|
|
358
|
+
).join(" "), S = m.children ? Pe(
|
|
359
|
+
m.children,
|
|
358
360
|
n,
|
|
359
361
|
e,
|
|
360
362
|
s,
|
|
361
|
-
|
|
363
|
+
m
|
|
362
364
|
) : "";
|
|
363
|
-
Object.assign(
|
|
364
|
-
let
|
|
365
|
-
typeof
|
|
366
|
-
`), Object.assign(
|
|
367
|
-
const
|
|
368
|
-
g || e.get(
|
|
369
|
-
) ?
|
|
370
|
-
|
|
371
|
-
ye.includes(
|
|
372
|
-
` +
|
|
365
|
+
Object.assign(o, x);
|
|
366
|
+
let _ = "";
|
|
367
|
+
typeof S == "string" ? _ = S : (_ = (S?.nodes || []).join(`
|
|
368
|
+
`), Object.assign(o, S?.methods || {}), c = c.concat(S?.components || []), l = l.concat(S?.importBlocks || []));
|
|
369
|
+
const I = ["@dcloudio/uni-h5", "@dcloudio/uni-ui"].includes(
|
|
370
|
+
g || e.get($)?.package
|
|
371
|
+
) ? F($) : Y(g) || Z(g) ? "component" : $;
|
|
372
|
+
y.push(
|
|
373
|
+
ye.includes(I) ? `<${I} ${R} ${P} ${O} />` : `<${I} ${R} ${P} ${O}>${_ ? `
|
|
374
|
+
` + _.trim() : ""}</${I}>`
|
|
373
375
|
);
|
|
374
376
|
}
|
|
375
|
-
const
|
|
377
|
+
const p = Oe(a.slot, y.join(`
|
|
376
378
|
`), r?.id);
|
|
377
|
-
i.push(
|
|
379
|
+
i.push(p);
|
|
378
380
|
}), {
|
|
379
381
|
nodes: i,
|
|
380
|
-
methods:
|
|
381
|
-
directives: ge(
|
|
382
|
-
components:
|
|
383
|
-
importBlocks:
|
|
382
|
+
methods: o,
|
|
383
|
+
directives: ge(f),
|
|
384
|
+
components: C(c),
|
|
385
|
+
importBlocks: C(l, "id")
|
|
384
386
|
};
|
|
385
387
|
}
|
|
386
388
|
function ge(t) {
|
|
387
|
-
return
|
|
389
|
+
return C(t).map((e) => `${e.startsWith("v") ? e.substring(1) : e}:${e}`);
|
|
388
390
|
}
|
|
389
391
|
function $e(t = []) {
|
|
390
392
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -413,15 +415,15 @@ function Z(t) {
|
|
|
413
415
|
return typeof t == "object" && t.type === "Plugin";
|
|
414
416
|
}
|
|
415
417
|
function be(t, e, n = []) {
|
|
416
|
-
return t === "style" ?
|
|
418
|
+
return t === "style" ? b(e) ? `:style="${h({
|
|
417
419
|
...e,
|
|
418
|
-
value:
|
|
419
|
-
})}"` : "" : t === "__class" &&
|
|
420
|
+
value: w(e.value, n)
|
|
421
|
+
})}"` : "" : t === "__class" && b(e) ? `:class="${h({
|
|
420
422
|
...e,
|
|
421
|
-
value:
|
|
422
|
-
})}"` : typeof e == "string" ? `${t}="${e}"` :
|
|
423
|
+
value: w(e.value, n)
|
|
424
|
+
})}"` : typeof e == "string" ? `${t}="${e}"` : b(e) ? `:${t}="${h({
|
|
423
425
|
...e,
|
|
424
|
-
value:
|
|
426
|
+
value: w(e.value, n)
|
|
425
427
|
})}"` : te(e) ? `:${t}='{${oe(
|
|
426
428
|
e
|
|
427
429
|
).join(", ")}}'` : `:${t}='${JSON.stringify(e)}'`;
|
|
@@ -429,13 +431,13 @@ function be(t, e, n = []) {
|
|
|
429
431
|
function je(t, e = {}, n = []) {
|
|
430
432
|
if (!!Object.keys(e.style || {}).length) {
|
|
431
433
|
const i = `${t.name}_${t.id}`;
|
|
432
|
-
e.class ? typeof e.class == "string" ? e.class = [e.class, i].join(" ") : (e.__class = e.class, e.class = i) : e.class = i,
|
|
434
|
+
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;
|
|
433
435
|
}
|
|
434
436
|
const r = t.from;
|
|
435
437
|
return (Y(r) || Z(r)) && (e.is = {
|
|
436
438
|
type: "JSExpression",
|
|
437
439
|
value: t.name
|
|
438
|
-
}), Object.entries(e).map(([i,
|
|
440
|
+
}), Object.entries(e).map(([i, o]) => be(i, o, n));
|
|
439
441
|
}
|
|
440
442
|
function Se(t, e, n, s, r) {
|
|
441
443
|
const i = G(e.modifiers, !0);
|
|
@@ -444,121 +446,139 @@ function Se(t, e, n, s, r) {
|
|
|
444
446
|
function ke(t, e = {}, n = {}) {
|
|
445
447
|
const s = {}, r = Array.from(n[t] || /* @__PURE__ */ new Set([])), i = r.length ? `({${r.join(", ")}}, args)` : "";
|
|
446
448
|
return {
|
|
447
|
-
binders: Object.entries(e).map(([
|
|
448
|
-
const
|
|
449
|
-
return
|
|
449
|
+
binders: Object.entries(e).map(([c, f]) => {
|
|
450
|
+
const l = f.handler.value.startsWith("this."), u = l ? M(f.handler.value) : `${v(c)}_${t}${i}`;
|
|
451
|
+
return l || (s[u] = r.length ? {
|
|
450
452
|
type: "JSFunction",
|
|
451
453
|
value: `{
|
|
452
|
-
return (${
|
|
454
|
+
return (${f.handler.value}).apply(this, args);
|
|
453
455
|
}`
|
|
454
|
-
} :
|
|
456
|
+
} : f.handler), Se(c, f, u, r, l);
|
|
455
457
|
}),
|
|
456
458
|
handlers: s
|
|
457
459
|
};
|
|
458
460
|
}
|
|
459
461
|
function we(t, e, n = {}, s = {}, r = {}, i) {
|
|
460
|
-
const { binders:
|
|
462
|
+
const { binders: o, handlers: c } = ke(e, s, r);
|
|
461
463
|
return {
|
|
462
464
|
props: je(t, n, i).join(" "),
|
|
463
|
-
handlers:
|
|
464
|
-
binders:
|
|
465
|
-
events:
|
|
465
|
+
handlers: c,
|
|
466
|
+
binders: o,
|
|
467
|
+
events: o.join(" ")
|
|
466
468
|
};
|
|
467
469
|
}
|
|
468
470
|
function Ce(t = [], e = [], n = []) {
|
|
469
|
-
const s = [], {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
471
|
+
const s = [], {
|
|
472
|
+
vIf: r,
|
|
473
|
+
vElse: i,
|
|
474
|
+
vElseIf: o,
|
|
475
|
+
vShow: c,
|
|
476
|
+
vModels: f,
|
|
477
|
+
vFor: l,
|
|
478
|
+
vBind: u,
|
|
479
|
+
vHtml: a,
|
|
480
|
+
customDirectives: y
|
|
481
|
+
} = Ee(t);
|
|
482
|
+
if (r && s.push(`v-if="${h(r.value, !0, !0, e)}"`), o && s.push(
|
|
483
|
+
`v-else-if="${h(o.value, !0, !0, e)}"`
|
|
484
|
+
), i && s.push("v-else"), c && s.push(
|
|
485
|
+
`v-show="${h(c.value, !0, !0, e)}"`
|
|
486
|
+
), u && s.push(
|
|
487
|
+
`v-bind="${h(u.value, !0, !0, e)}"`
|
|
488
|
+
), f.forEach((p) => {
|
|
489
|
+
const m = G(p.modifiers, !0), d = p.arg ? k(p.arg) ? `:[${h(p.arg, !0, !0, e)}]` : `:${p.arg}` : "";
|
|
476
490
|
s.push(
|
|
477
|
-
`v-model${
|
|
491
|
+
`v-model${d}${m}="${h(p.value, !0, !0, e)}"`
|
|
478
492
|
);
|
|
479
|
-
}),
|
|
480
|
-
const { item:
|
|
493
|
+
}), l) {
|
|
494
|
+
const { item: p, index: m } = { item: "item", index: "index", ...l.iterator };
|
|
481
495
|
s.push(
|
|
482
|
-
`v-for="(${
|
|
496
|
+
`v-for="(${p}, ${m}) in ${h(l.value, !0, !0, e)}"`
|
|
483
497
|
);
|
|
484
498
|
}
|
|
485
|
-
return
|
|
486
|
-
`v-html="${
|
|
487
|
-
),
|
|
488
|
-
if (!
|
|
489
|
-
let m = "",
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
if (m +=
|
|
493
|
-
const
|
|
494
|
-
|
|
499
|
+
return a && s.push(
|
|
500
|
+
`v-html="${h(a.value, !0, !0, e)}"`
|
|
501
|
+
), y && y.length && y.forEach((p) => {
|
|
502
|
+
if (!p.name) return;
|
|
503
|
+
let m = "", d = "";
|
|
504
|
+
k(p.name) ? (d = h(p.name, !0, !0, e), n.push(d)) : d = p.name;
|
|
505
|
+
const $ = d?.startsWith("v") ? F(d) : F("v-" + d);
|
|
506
|
+
if (m += $, p.arg && (k(p.arg) ? m += `:[${h(p.name, !0, !0, e)}]` : m += `:${p.arg}`), p.modifiers) {
|
|
507
|
+
const j = Object.keys(p.modifiers);
|
|
508
|
+
j.length && (m += j.map((g) => "." + g));
|
|
495
509
|
}
|
|
496
|
-
|
|
497
|
-
`${m}="${
|
|
510
|
+
p.value ? s.push(
|
|
511
|
+
`${m}="${h(p.value, !0, !0, e)}"`
|
|
498
512
|
) : s.push(m);
|
|
499
513
|
}), s;
|
|
500
514
|
}
|
|
501
|
-
function
|
|
515
|
+
function Ee(t = []) {
|
|
502
516
|
const e = t.filter(
|
|
503
|
-
(
|
|
517
|
+
(a) => L.includes(a.name)
|
|
504
518
|
), n = t.filter(
|
|
505
|
-
(
|
|
519
|
+
(a) => !L.includes(a.name)
|
|
506
520
|
), s = e.find(
|
|
507
|
-
(
|
|
521
|
+
(a) => v(a.name) === "vIf"
|
|
508
522
|
), r = e.find(
|
|
509
|
-
(
|
|
523
|
+
(a) => v(a.name) === "vElseIf"
|
|
510
524
|
), i = e.find(
|
|
511
|
-
(
|
|
525
|
+
(a) => v(a.name) === "vElse"
|
|
526
|
+
), o = e.find(
|
|
527
|
+
(a) => v(a.name) === "vFor"
|
|
512
528
|
), c = e.find(
|
|
513
|
-
(
|
|
514
|
-
),
|
|
515
|
-
(
|
|
516
|
-
),
|
|
517
|
-
(
|
|
529
|
+
(a) => v(a.name) === "vShow"
|
|
530
|
+
), f = e.find(
|
|
531
|
+
(a) => v(a.name) === "vBind"
|
|
532
|
+
), l = e.find(
|
|
533
|
+
(a) => v(a.name) === "vHtml"
|
|
534
|
+
), u = e.filter(
|
|
535
|
+
(a) => v(a.name) === "vModel"
|
|
518
536
|
);
|
|
519
537
|
return {
|
|
520
538
|
vIf: s,
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
539
|
+
vElseIf: r,
|
|
540
|
+
vElse: i,
|
|
541
|
+
vFor: o,
|
|
542
|
+
vShow: c,
|
|
543
|
+
vModels: u,
|
|
544
|
+
vBind: f,
|
|
545
|
+
vHtml: l,
|
|
526
546
|
customDirectives: n
|
|
527
547
|
};
|
|
528
548
|
}
|
|
529
|
-
function
|
|
530
|
-
return typeof t == "string" ? t :
|
|
549
|
+
function Pe(t, e, n, s, r) {
|
|
550
|
+
return typeof t == "string" ? t : k(t) ? `{{ ${h(t, !1, !0, e)} }}` : Array.isArray(t) ? X(t, n, e, s, r) : "";
|
|
531
551
|
}
|
|
532
|
-
function
|
|
552
|
+
function Oe(t, e, n) {
|
|
533
553
|
if (!t) return e;
|
|
534
554
|
const s = typeof t == "string" ? { name: t, params: [] } : { params: [], ...t };
|
|
535
555
|
return `<template ${`#${s.name}="${s.params?.length > 0 ? `{${s.params?.join(",")}}` : `scope_${n}`}"`}>
|
|
536
556
|
${e}
|
|
537
557
|
</template>`;
|
|
538
558
|
}
|
|
539
|
-
function
|
|
559
|
+
function xe(t, e = [], n = [], s = {}, r = "web") {
|
|
540
560
|
const i = [
|
|
541
561
|
"@dcloudio/uni-h5",
|
|
542
562
|
"uni-h5",
|
|
543
563
|
"@dcloudio/uni-ui",
|
|
544
564
|
"uni-ui"
|
|
545
|
-
],
|
|
565
|
+
], o = {
|
|
546
566
|
vue: ["defineComponent", "reactive"]
|
|
547
|
-
},
|
|
548
|
-
for (const
|
|
549
|
-
const
|
|
550
|
-
if (
|
|
551
|
-
const
|
|
552
|
-
|
|
567
|
+
}, c = [];
|
|
568
|
+
for (const l of e) {
|
|
569
|
+
const u = t.get(l.split(":")[0]);
|
|
570
|
+
if (u && u.package) {
|
|
571
|
+
const a = o[u.package] ?? (o[u.package] = []), y = u.parent || (u.alias || "").split(".")[0] || u.name;
|
|
572
|
+
a.push(y), r === "uniapp" && i.includes(u.package) && c.push(y);
|
|
553
573
|
}
|
|
554
574
|
}
|
|
555
|
-
for (const [
|
|
556
|
-
(
|
|
575
|
+
for (const [l, u] of Object.entries(s))
|
|
576
|
+
(o[l] ?? (o[l] = [])).push(...Array.from(u)), r === "uniapp" && i.includes(l) && c.push(...Array.from(u));
|
|
557
577
|
return {
|
|
558
|
-
imports: Object.entries(
|
|
578
|
+
imports: Object.entries(o).filter(([l, u]) => r === "uniapp" ? !i.includes(l) && !!u.length : !!u.length).map(([l, u]) => `import { ${C(u).join(
|
|
559
579
|
","
|
|
560
|
-
)}} from '${
|
|
561
|
-
uniComponents:
|
|
580
|
+
)}} from '${l}';`).concat(n),
|
|
581
|
+
uniComponents: c
|
|
562
582
|
};
|
|
563
583
|
}
|
|
564
584
|
function _e(t = {}) {
|
|
@@ -572,7 +592,7 @@ function _e(t = {}) {
|
|
|
572
592
|
return e.join(`
|
|
573
593
|
`);
|
|
574
594
|
}
|
|
575
|
-
function
|
|
595
|
+
function Ie(t = {}) {
|
|
576
596
|
const e = [];
|
|
577
597
|
return Object.entries(t).forEach(([n, s]) => {
|
|
578
598
|
e.push(
|
|
@@ -580,7 +600,7 @@ function Ae(t = {}) {
|
|
|
580
600
|
);
|
|
581
601
|
}), e;
|
|
582
602
|
}
|
|
583
|
-
function
|
|
603
|
+
function Ae(t = {}) {
|
|
584
604
|
const e = [];
|
|
585
605
|
return Object.entries(t).forEach(([n, s]) => {
|
|
586
606
|
e.push(
|
|
@@ -588,49 +608,49 @@ function Ne(t = {}) {
|
|
|
588
608
|
);
|
|
589
609
|
}), e;
|
|
590
610
|
}
|
|
591
|
-
function
|
|
592
|
-
const { dsl: s } = t, r = Object.keys(s.computed || {}), i = A(s.lifeCycles, r),
|
|
611
|
+
function Ne(t, e, n = "web") {
|
|
612
|
+
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: y, directives: p } = X(
|
|
593
613
|
s.nodes || [],
|
|
594
614
|
e,
|
|
595
615
|
r,
|
|
596
616
|
t.context
|
|
597
|
-
),
|
|
617
|
+
), m = [...o, ...c.computed], d = A(
|
|
598
618
|
{
|
|
599
|
-
...
|
|
619
|
+
...l,
|
|
600
620
|
...s.methods || {}
|
|
601
621
|
},
|
|
602
622
|
r
|
|
603
|
-
),
|
|
604
|
-
let { imports:
|
|
623
|
+
), $ = y.map((x) => `import ${x.name} from './${x.id}.vue';`);
|
|
624
|
+
let { imports: j, uniComponents: g } = xe(
|
|
605
625
|
e,
|
|
606
|
-
|
|
607
|
-
|
|
626
|
+
a,
|
|
627
|
+
$,
|
|
608
628
|
t.imports,
|
|
609
629
|
n
|
|
610
630
|
);
|
|
611
|
-
const
|
|
631
|
+
const E = Object.keys({
|
|
612
632
|
...t.urlSchemas,
|
|
613
633
|
...t.blockPlugins
|
|
614
|
-
}), P =
|
|
634
|
+
}), P = Ie(t.urlSchemas), O = Ae(t.blockPlugins);
|
|
615
635
|
return {
|
|
616
636
|
id: s.id,
|
|
617
637
|
version: s.__VERSION__,
|
|
618
638
|
name: s.name,
|
|
619
|
-
state:
|
|
639
|
+
state: ue(s.state).join(","),
|
|
620
640
|
inject: pe(s.inject).join(","),
|
|
621
641
|
props: fe(s.props).join(","),
|
|
622
642
|
emits: me(s.emits).join(","),
|
|
623
|
-
watch:
|
|
643
|
+
watch: c.watches.join(","),
|
|
624
644
|
lifeCycles: i.join(","),
|
|
625
|
-
computed:
|
|
626
|
-
methods: [...
|
|
645
|
+
computed: m.join(","),
|
|
646
|
+
methods: [...f, ...d].join(","),
|
|
627
647
|
imports: `
|
|
628
|
-
` +
|
|
648
|
+
` + j.join(`
|
|
629
649
|
`),
|
|
630
|
-
components: ae(
|
|
631
|
-
directives:
|
|
650
|
+
components: ae(a, g).join(","),
|
|
651
|
+
directives: p.join(","),
|
|
632
652
|
returns: t.members.join(","),
|
|
633
|
-
template:
|
|
653
|
+
template: u.join(`
|
|
634
654
|
`),
|
|
635
655
|
css: s.css || "",
|
|
636
656
|
style: _e(t.style),
|
|
@@ -638,12 +658,12 @@ function Fe(t, e, n = "web") {
|
|
|
638
658
|
`),
|
|
639
659
|
blockPlugins: O.join(`
|
|
640
660
|
`),
|
|
641
|
-
asyncComponents:
|
|
661
|
+
asyncComponents: E.join(","),
|
|
642
662
|
uniComponents: g,
|
|
643
663
|
renderer: n === "uniapp" ? "@vtj/uni-app" : "@vtj/renderer"
|
|
644
664
|
};
|
|
645
665
|
}
|
|
646
|
-
const
|
|
666
|
+
const Fe = `
|
|
647
667
|
// @ts-nocheck
|
|
648
668
|
|
|
649
669
|
<%= imports %>
|
|
@@ -686,15 +706,15 @@ export default defineComponent({
|
|
|
686
706
|
<%= css %>
|
|
687
707
|
<%= style %>
|
|
688
708
|
</style>
|
|
689
|
-
`, Te = U(
|
|
709
|
+
`, Te = U(Fe), Re = U(Be);
|
|
690
710
|
async function Ue(t, e = /* @__PURE__ */ new Map(), n = [], s = "web", r) {
|
|
691
|
-
const i = new
|
|
692
|
-
template:
|
|
693
|
-
css: await W(
|
|
694
|
-
script: await ie(
|
|
695
|
-
style: await W(
|
|
711
|
+
const i = new le(ne(t), n), o = Ne(i, e, s), c = Te(o), f = Re({
|
|
712
|
+
template: o.template,
|
|
713
|
+
css: await W(o.css, r),
|
|
714
|
+
script: await ie(c, r),
|
|
715
|
+
style: await W(o.style, r)
|
|
696
716
|
});
|
|
697
|
-
return await q(
|
|
717
|
+
return await q(f, r).catch((l) => (l.content = f, Promise.reject(l)));
|
|
698
718
|
}
|
|
699
719
|
async function De(t) {
|
|
700
720
|
const e = `
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"低代码引擎",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"prettier": "~3.5.0",
|
|
25
25
|
"@vtj/base": "~0.12.0",
|
|
26
|
-
"@vtj/core": "~0.12.
|
|
26
|
+
"@vtj/core": "~0.12.11"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@vtj/cli": "~0.12.
|
|
29
|
+
"@vtj/cli": "~0.12.2"
|
|
30
30
|
},
|
|
31
31
|
"exports": {
|
|
32
32
|
".": {
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.12.
|
|
5
|
+
* @version 0.12.10
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.12.
|
|
8
|
+
export declare const version = "0.12.10";
|