@vtj/coder 0.7.14 → 0.7.15
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 +28 -20
- package/dist/index.mjs +325 -288
- package/package.json +5 -5
- package/types/collecter.d.ts +2 -0
- package/types/formatters.d.ts +1 -0
- package/types/parser/index.d.ts +1 -0
- package/types/parser/style.d.ts +1 -0
- package/types/utils.d.ts +1 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,37 +1,44 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@vtj/base"),k=require("prettier/standalone"),Q=require("prettier/plugins/html"),z=require("prettier/plugins/babel"),G=require("prettier/plugins/postcss"),H=require("prettier/plugins/estree");function w(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,s.get?s:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const U=w(Q),T=w(z),q=w(G),B=w(H);/**!
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.7.
|
|
5
|
+
* @version 0.7.15
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const X="0.7.15";/**!
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.7.
|
|
11
|
+
* @version 0.7.15
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const
|
|
13
|
+
*/const Y=["slot","template","component","img","div","p","h1","h2","h3","span","a"];l.mitt();const x={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 J(t,e){return e?t:await k.format(t,{parser:"vue",...x,plugins:[U,T,B,q]})}async function Z(t,e){return e?t:await k.format(t,{parser:"babel-ts",...x,plugins:[T,B]})}async function W(t,e){return e?t:k.format(t,{parser:"scss",...x,plugins:[q]})}function C(t){return t&&t.type==="JSExpression"}function P(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function b(t){return C(t)||P(t)}function A(t){return t.replace(new RegExp("this.","g"),"")}function I(t){return t.replace(/this\.context\??\./g,"")}function u(t,e=!0,r=!0){const s=b(t)?t.value:e?JSON.stringify(t):t;return r?A(I(s)):I(s)}function j(t,e=[]){let r=t;for(const s of e)r=r.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);return r}function L(t){let e=t.trim();if(e=/^\((\(|async|function)/.test(e)?e.substring(1,e.length-1):e,e.startsWith("{"))return e;if(e.startsWith("async function"))e=e.replace(/^async function/,"async");else if(e.startsWith("function"))e=e.replace(/^function/,"");else{const i=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,n=e.match(i);n&&n[2]&&(n[2].startsWith("{")||(e=e.replace(n[2],`{ return ${n[2]} }`))),e=e.replace("=>","")}return e}function K(t={}){return Object.entries(t).map(([e,r])=>`"${e}": ${u(r)}`)}function M(t={},e=!1){const r=Object.keys(t);return e?r.map(s=>"."+s):r}function ee(t){let e="";for(var r in t)if(t.hasOwnProperty(r)){var s=t[r];e+=r+": "+s+";"}return e}class te{constructor(e,r){this.dsl=e,this.dependencies=r,this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};style={};members=[];libraryRegex=[];collectLibrary(){return this.dependencies.filter(e=>!!e.library).map(e=>new RegExp(`(this.\\$libs.${e.library}.([\\w]+))`,"g"))}collectImport(e){const r=e.split(".");if(r.length===4){const s=r.pop(),i=r.join(".")+".",n=r.pop();if(s&&n){const o=this.dependencies.find(a=>a.library===n)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(s)}return{name:s,path:i,library:n}}return null}replaceLibraryPath(e){const{libraryRegex:r}=this;let s=e.value;for(const i of r){const n=e.value.match(i)||[];for(const o of n){const a=this.collectImport(o);if(a){const c=a.path.replace(/\$/g,"\\$");s=s.replace(new RegExp(c,"g"),"")}}}return s}walk(e){const r=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){for(let n of s)r(n);return}const i=Object.values(s);for(const n of i)b(n)?n.value=this.replaceLibraryPath(n):r(n)};r(e)}getLibraryMember(e=[]){let r=[...e];for(const s of Object.values(this.imports))r=r.concat(Array.from(s));return l.dedupArray(r)}collectContext(e,r){const s=new Set(r?.id?this.context[r.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let n=new Set(Array.from(s));if(i){const{item:a="item",index:c="index"}=i.iterator||{};n=new Set([a,c,...Array.from(n)])}const o=e.slot;if(o){const a=typeof o=="string"?[]:o.params||[],c=a.length?a:[`scope_${r?.id}`];n=new Set([...c,...Array.from(n)])}this.context[e.id]=n}collectStyle(e){e.id&&e.props?.style&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}walkNodes(e){const r=(s,i)=>{this.collectContext(s,i),this.collectStyle(s),Array.isArray(s.children)&&s.children.forEach(n=>r(n,s))};Array.isArray(e.nodes)&&e.nodes.forEach(s=>r(s))}}function re(t={}){return Object.entries(t).map(([e,r])=>{const s=u(r,!1);return`${e}:${s}`})}function se(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${u(e.default,!0,!1)}
|
|
16
|
-
}`)}function ne(t=[]){const e=r=>r?`[${
|
|
16
|
+
}`)}function ne(t=[]){const e=r=>r?`[${l.toArray(r).map(n=>n.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(r=>typeof r=="string"?`${r}: {}`:`${r.name}: {
|
|
17
17
|
type:${e(r.type)},
|
|
18
18
|
required: ${r.required},
|
|
19
19
|
default: ${u(r.default,!0,!1)}
|
|
20
|
-
}`)}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${
|
|
24
|
-
}`);return{computed:
|
|
20
|
+
}`)}function ie(t=[]){return t.map(e=>`'${e}'`)}function v(t={},e=[]){return Object.entries(t).map(([r,s])=>{let i=L(u(s,!1,!1));return i=j(i,e),i.startsWith("async")?`async ${r}${i.replace(/^async/,"")}`:`${r}${i}`})}function oe(t=[],e=[]){const r=t.reduce((n,o)=>(o.id&&P(o.source)&&(n[`watcher_${o.id}`]=o.source),n),{}),s=v(r,e),i=t.map(n=>`watcher_${n.id}: {
|
|
21
|
+
deep: ${n.deep},
|
|
22
|
+
immediate:${n.immediate},
|
|
23
|
+
handler${L(n.handler.value)}
|
|
24
|
+
}`);return{computed:s,watches:i}}function ae(t={}){return Object.values(t).map(e=>{const r=P(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
25
25
|
return await this.provider.apis.${e.ref}.apply(this, args).then(${r});
|
|
26
|
-
}`})}function
|
|
27
|
-
`),Object.assign(o,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),
|
|
28
|
-
|
|
26
|
+
}`})}function V(t,e,r=[],s={},i){const n=[];let o={},a=[],c=[];return ce(t).forEach(f=>{const y=[];for(const p of f.children){let{id:O,name:m,invisible:g,from:_}=p;if(g)continue;const E=le(m,e,_);E&&a.push(E),ue(_)&&c.push({id:_.id,name:m});const{props:F,events:N,handlers:D}=he(p,O,p.props,p.events,s,r),R=ye(p.directives).join(" "),d=p.children?$e(p.children,r,e,s,p):"";Object.assign(o,D);let $="";typeof d=="string"?$=d:($=(d?.nodes||[]).join(`
|
|
27
|
+
`),Object.assign(o,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),y.push(m==="img"?`<${m} ${R} ${F} ${N} />
|
|
28
|
+
`:`<${m} ${R} ${F} ${N}>${$?`
|
|
29
|
+
`+$.trim():""}</${m}>`)}const S=ve(f.slot,y.join(`
|
|
30
|
+
`),i?.id);n.push(S)}),{nodes:n,methods:o,components:l.dedupArray(a),importBlocks:l.dedupArray(c,"id")}}function ce(t=[]){const e=new Map;for(const r of t){const s=typeof r.slot=="string"?r.slot:r.slot?.name,i=e.get(s);i?i.children.push(r):e.set(s,{slot:r.slot,children:[r]})}return e}function le(t,e,r){if(Y.includes(t))return null;const s=e.get(t);if(s&&s.alias){const i=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${i}`}return r||s?t:null}function ue(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function pe(t,e,r=[]){return t==="style"?"":t==="__class"&&b(e)?`:class="${u({...e,value:j(e.value,r)})}"`:typeof e=="string"?`${t}="${e}"`:b(e)?`:${t}="${u({...e,value:j(e.value,r)})}"`:l.isPlainObject(e)?`:${t}='{${K(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function fe(t,e={},r=[]){if(!!Object.keys(e.style||{}).length){const i=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,i].join(" "):(e.__class=e.class,e.class=i):(e.class=i,delete e.style)}return Object.entries(e).map(([i,n])=>pe(i,n,r))}function me(t,e,r,s){const i=M(e.modifiers,!0);return s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${r}"`:`@${t}${i.join("")}="${r}"`}function de(t,e={},r={}){const s={},i=Array.from(r[t]||new Set([])),n=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([a,c])=>{const h=c.handler.value.startsWith("this."),f=h?A(c.handler.value):`${l.camelCase(a)}_handler_${t}${n}`;return h||(s[f]=i.length?{type:"JSFunction",value:`{
|
|
29
31
|
return (${c.handler.value}).apply(this, args);
|
|
30
|
-
}`}:c.handler),
|
|
32
|
+
}`}:c.handler),me(a,c,f,i)}),handlers:s}}function he(t,e,r={},s={},i={},n){const{binders:o,handlers:a}=de(e,s,i);return{props:fe(t,r,n).join(" "),handlers:a,binders:o,events:o.join(" ")}}function ye(t=[]){const e=[],{vIf:r,vShow:s,vModels:i,vFor:n}=ge(t);if(r&&e.push(`v-if="${u(r.value)}"`),s&&e.push(`v-show="${u(s.value)}"`),i.forEach(o=>{const a=M(o.modifiers,!0),c=o.arg?C(o.arg)?`:[${u(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${c}${a}="${u(o.value)}"`)}),n){const{item:o,index:a}={item:"item",index:"index",...n.iterator};e.push(`v-for="(${o}, ${a}) in ${u(n.value)}"`)}return e}function ge(t=[]){const e=t.find(o=>l.camelCase(o.name)==="vIf"),r=t.find(o=>l.camelCase(o.name)==="vFor"),s=t.find(o=>l.camelCase(o.name)==="vShow"),i=t.find(o=>l.camelCase(o.name)==="vBind"),n=t.filter(o=>l.camelCase(o.name)==="vModel");return{vIf:e,vFor:r,vShow:s,vModels:n,vBind:i}}function $e(t,e,r,s,i){if(typeof t=="string")return t;if(C(t)){let n=u(t,!1);return n=j(n,e),n=A(n),`{{ ${n} }}`}return Array.isArray(t)?V(t,r,e,s,i):""}function ve(t,e,r){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_${r}`}"`}>
|
|
31
33
|
${e}
|
|
32
|
-
</template>`}function be(t,e=[],r=[],
|
|
34
|
+
</template>`}function be(t,e=[],r=[],s={}){const i={vue:["defineComponent","reactive"]};for(const n of e){const o=t.get(n.split(":")[0]);o&&o.package&&(i[o.package]??(i[o.package]=[])).push(o.parent||(o.alias||"").split(".")[0]||o.name)}for(const[n,o]of Object.entries(s))(i[n]??(i[n]=[])).push(...Array.from(o));return Object.entries(i).filter(([n,o])=>!!o.length).map(([n,o])=>`import { ${l.dedupArray(o).join(",")}} from '${n}';`).concat(r)}function je(t={}){const e=[];for(const[r,s]of Object.entries(t))e.push(`
|
|
35
|
+
${r} {
|
|
36
|
+
${ee(s)}
|
|
37
|
+
}
|
|
38
|
+
`);return e.join(`
|
|
39
|
+
`)}function we(t,e){const{dsl:r}=t,s=Object.keys(r.computed||{}),i=v(r.lifeCycles,s),n=v(r.computed,s),o=oe(r.watch,s),a=ae(r.dataSources),{methods:c,nodes:h,components:f,importBlocks:y}=V(r.nodes||[],e,s,t.context),S=[...n,...o.computed],p=v({...c,...r.methods||{}},s),O=y.map(g=>`import ${g.name} from './${g.id}.vue';`),m=be(e,f,O,t.imports);return{id:r.id,version:r.__VERSION__,name:r.name,state:re(r.state).join(","),inject:se(r.inject).join(","),props:ne(r.props).join(","),emits:ie(r.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:S.join(","),methods:[...a,...p].join(","),imports:m.join(`
|
|
33
40
|
`),components:f.join(","),returns:t.members.join(","),template:h.join(`
|
|
34
|
-
`),css:r.css||""}}const
|
|
41
|
+
`),css:r.css||"",style:je(t.style)}}const Se=`
|
|
35
42
|
<%= imports %>
|
|
36
43
|
import { useProvider } from '@vtj/renderer';
|
|
37
44
|
export default defineComponent({
|
|
@@ -57,7 +64,7 @@ export default defineComponent({
|
|
|
57
64
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
58
65
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
59
66
|
});
|
|
60
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
67
|
+
`.replace(/(\n|\r|\t)/g,""),Oe=`
|
|
61
68
|
<template>
|
|
62
69
|
<%= template %>
|
|
63
70
|
</template>
|
|
@@ -66,8 +73,9 @@ export default defineComponent({
|
|
|
66
73
|
<\/script>
|
|
67
74
|
<style lang="scss" scoped>
|
|
68
75
|
<%= css %>
|
|
76
|
+
<%= style %>
|
|
69
77
|
</style>
|
|
70
|
-
`,
|
|
78
|
+
`,_e=l.template(Se),ke=l.template(Oe);async function xe(t,e=new Map,r=[],s){const i=new te(l.cloneDeep(t),r),n=we(i,e),o=_e(n),a=ke({template:n.template,css:await W(n.css,s),script:await Z(o,s),style:await W(n.style,s)});return await J(a,s)}async function Ce(t){const e=`
|
|
71
79
|
<template>
|
|
72
80
|
<div>
|
|
73
81
|
<h3>源码模式页面</h3>
|
|
@@ -78,4 +86,4 @@ export default defineComponent({
|
|
|
78
86
|
<\/script>
|
|
79
87
|
<style scoped lang="scss">
|
|
80
88
|
</style>
|
|
81
|
-
`;return await
|
|
89
|
+
`;return await J(e)}exports.VTJ_CODER_VERSION=X;exports.createEmptyPage=Ce;exports.generator=xe;
|
package/dist/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { mitt as
|
|
2
|
-
import { format as
|
|
3
|
-
import * as
|
|
4
|
-
import * as
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
1
|
+
import { mitt as z, dedupArray as j, toArray as G, camelCase as d, isPlainObject as H, template as B, cloneDeep as U } from "@vtj/base";
|
|
2
|
+
import { format as O } from "prettier/standalone";
|
|
3
|
+
import * as X from "prettier/plugins/html";
|
|
4
|
+
import * as J from "prettier/plugins/babel";
|
|
5
|
+
import * as L from "prettier/plugins/postcss";
|
|
6
|
+
import * as T from "prettier/plugins/estree";
|
|
7
7
|
/**!
|
|
8
8
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/coder
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.7.
|
|
11
|
+
* @version 0.7.15
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const Pt = "0.7.15";
|
|
15
15
|
/**!
|
|
16
16
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
17
17
|
* @name @vtj/core
|
|
18
18
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
19
|
-
* @version 0.7.
|
|
19
|
+
* @version 0.7.15
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const Y = [
|
|
23
23
|
"slot",
|
|
24
24
|
"template",
|
|
25
25
|
"component",
|
|
@@ -32,8 +32,8 @@ const X = [
|
|
|
32
32
|
"span",
|
|
33
33
|
"a"
|
|
34
34
|
];
|
|
35
|
-
|
|
36
|
-
const
|
|
35
|
+
z();
|
|
36
|
+
const C = {
|
|
37
37
|
arrowParens: "always",
|
|
38
38
|
bracketSpacing: !0,
|
|
39
39
|
bracketSameLine: !0,
|
|
@@ -53,415 +53,450 @@ const k = {
|
|
|
53
53
|
useTabs: !1,
|
|
54
54
|
vueIndentScriptAndStyle: !0
|
|
55
55
|
};
|
|
56
|
-
async function
|
|
57
|
-
return
|
|
58
|
-
parser: "
|
|
59
|
-
...
|
|
60
|
-
plugins: [
|
|
56
|
+
async function V(e, t) {
|
|
57
|
+
return t ? e : await O(e, {
|
|
58
|
+
parser: "vue",
|
|
59
|
+
...C,
|
|
60
|
+
plugins: [X, J, T, L]
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
64
|
-
return
|
|
63
|
+
async function Z(e, t) {
|
|
64
|
+
return t ? e : await O(e, {
|
|
65
65
|
parser: "babel-ts",
|
|
66
|
-
...
|
|
67
|
-
plugins: [
|
|
66
|
+
...C,
|
|
67
|
+
plugins: [J, T]
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
-
async function
|
|
71
|
-
return
|
|
70
|
+
async function W(e, t) {
|
|
71
|
+
return t ? e : O(e, {
|
|
72
72
|
parser: "scss",
|
|
73
|
-
...
|
|
74
|
-
plugins: [
|
|
73
|
+
...C,
|
|
74
|
+
plugins: [L]
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
return
|
|
77
|
+
function _(e) {
|
|
78
|
+
return e && e.type === "JSExpression";
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
return typeof
|
|
80
|
+
function P(e) {
|
|
81
|
+
return typeof e == "object" && e && e.type === "JSFunction";
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
83
|
+
function b(e) {
|
|
84
|
+
return _(e) || P(e);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return
|
|
86
|
+
function E(e) {
|
|
87
|
+
return e.replace(new RegExp("this.", "g"), "");
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
89
|
+
function I(e) {
|
|
90
|
+
return e.replace(/this\.context\??\./g, "");
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
return
|
|
92
|
+
function l(e, t = !0, s = !0) {
|
|
93
|
+
const r = b(e) ? e.value : t ? JSON.stringify(e) : e;
|
|
94
|
+
return s ? E(I(r)) : I(r);
|
|
95
95
|
}
|
|
96
|
-
function
|
|
97
|
-
let
|
|
98
|
-
for (const
|
|
99
|
-
|
|
100
|
-
new RegExp(`this.${
|
|
101
|
-
`this.${
|
|
96
|
+
function w(e, t = []) {
|
|
97
|
+
let s = e;
|
|
98
|
+
for (const r of t)
|
|
99
|
+
s = s.replace(
|
|
100
|
+
new RegExp(`this.${r}.value`, "g"),
|
|
101
|
+
`this.${r}`
|
|
102
102
|
);
|
|
103
|
-
return
|
|
103
|
+
return s;
|
|
104
104
|
}
|
|
105
|
-
function
|
|
106
|
-
let
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
else if (
|
|
112
|
-
|
|
105
|
+
function q(e) {
|
|
106
|
+
let t = e.trim();
|
|
107
|
+
if (t = /^\((\(|async|function)/.test(t) ? t.substring(1, t.length - 1) : t, t.startsWith("{"))
|
|
108
|
+
return t;
|
|
109
|
+
if (t.startsWith("async function"))
|
|
110
|
+
t = t.replace(/^async function/, "async");
|
|
111
|
+
else if (t.startsWith("function"))
|
|
112
|
+
t = t.replace(/^function/, "");
|
|
113
113
|
else {
|
|
114
|
-
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,
|
|
115
|
-
|
|
114
|
+
const i = /^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/, n = t.match(i);
|
|
115
|
+
n && n[2] && (n[2].startsWith("{") || (t = t.replace(n[2], `{ return ${n[2]} }`))), t = t.replace("=>", "");
|
|
116
116
|
}
|
|
117
|
-
return
|
|
117
|
+
return t;
|
|
118
118
|
}
|
|
119
|
-
function K(
|
|
120
|
-
return Object.entries(
|
|
119
|
+
function K(e = {}) {
|
|
120
|
+
return Object.entries(e).map(([t, s]) => `"${t}": ${l(s)}`);
|
|
121
121
|
}
|
|
122
|
-
function
|
|
123
|
-
const
|
|
124
|
-
return
|
|
122
|
+
function M(e = {}, t = !1) {
|
|
123
|
+
const s = Object.keys(e);
|
|
124
|
+
return t ? s.map((r) => "." + r) : s;
|
|
125
125
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
function tt(e) {
|
|
127
|
+
let t = "";
|
|
128
|
+
for (var s in e)
|
|
129
|
+
if (e.hasOwnProperty(s)) {
|
|
130
|
+
var r = e[s];
|
|
131
|
+
t += s + ": " + r + ";";
|
|
132
|
+
}
|
|
133
|
+
return t;
|
|
134
|
+
}
|
|
135
|
+
class et {
|
|
136
|
+
constructor(t, s) {
|
|
137
|
+
this.dsl = t, this.dependencies = s, this.libraryRegex = this.collectLibrary(), this.walk(t), this.walkNodes(t), this.members = this.getLibraryMember();
|
|
129
138
|
}
|
|
130
139
|
/**
|
|
131
140
|
* { 'element-plus': ['ElButton', 'ElInput' ...] }
|
|
132
141
|
*/
|
|
133
142
|
imports = {};
|
|
134
143
|
context = {};
|
|
144
|
+
style = {};
|
|
135
145
|
members = [];
|
|
136
146
|
libraryRegex = [];
|
|
137
147
|
collectLibrary() {
|
|
138
|
-
return this.dependencies.filter((
|
|
148
|
+
return this.dependencies.filter((t) => !!t.library).map((t) => new RegExp(`(this.\\$libs.${t.library}.([\\w]+))`, "g"));
|
|
139
149
|
}
|
|
140
150
|
/**
|
|
141
151
|
* 收集 import 信息
|
|
142
152
|
* @param regexMatchItem ex: this.$libs.ElementPlus.ElButton
|
|
143
153
|
* @returns ex: { name: 'ElButton', path: 'this.$libs.ElementPlus.', library: 'ElementPlus' }
|
|
144
154
|
*/
|
|
145
|
-
collectImport(
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
155
|
+
collectImport(t) {
|
|
156
|
+
const s = t.split(".");
|
|
157
|
+
if (s.length === 4) {
|
|
158
|
+
const r = s.pop(), i = s.join(".") + ".", n = s.pop();
|
|
159
|
+
if (r && n) {
|
|
150
160
|
const o = this.dependencies.find(
|
|
151
|
-
(a) => a.library ===
|
|
161
|
+
(a) => a.library === n
|
|
152
162
|
)?.package;
|
|
153
|
-
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(
|
|
163
|
+
o && (this.imports[o] || (this.imports[o] = /* @__PURE__ */ new Set())).add(r);
|
|
154
164
|
}
|
|
155
165
|
return {
|
|
156
|
-
name:
|
|
166
|
+
name: r,
|
|
157
167
|
path: i,
|
|
158
|
-
library:
|
|
168
|
+
library: n
|
|
159
169
|
};
|
|
160
170
|
}
|
|
161
171
|
return null;
|
|
162
172
|
}
|
|
163
173
|
// 代码中包含依赖库的引用,需要从代码中移除
|
|
164
|
-
replaceLibraryPath(
|
|
165
|
-
const { libraryRegex:
|
|
166
|
-
let
|
|
167
|
-
for (const i of
|
|
168
|
-
const
|
|
169
|
-
for (const o of
|
|
174
|
+
replaceLibraryPath(t) {
|
|
175
|
+
const { libraryRegex: s } = this;
|
|
176
|
+
let r = t.value;
|
|
177
|
+
for (const i of s) {
|
|
178
|
+
const n = t.value.match(i) || [];
|
|
179
|
+
for (const o of n) {
|
|
170
180
|
const a = this.collectImport(o);
|
|
171
181
|
if (a) {
|
|
172
182
|
const c = a.path.replace(/\$/g, "\\$");
|
|
173
|
-
|
|
183
|
+
r = r.replace(new RegExp(c, "g"), "");
|
|
174
184
|
}
|
|
175
185
|
}
|
|
176
186
|
}
|
|
177
|
-
return
|
|
187
|
+
return r;
|
|
178
188
|
}
|
|
179
|
-
walk(
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
189
|
+
walk(t) {
|
|
190
|
+
const s = (r) => {
|
|
191
|
+
if (!r || typeof r != "object")
|
|
182
192
|
return;
|
|
183
|
-
if (Array.isArray(
|
|
184
|
-
for (let
|
|
185
|
-
|
|
193
|
+
if (Array.isArray(r)) {
|
|
194
|
+
for (let n of r)
|
|
195
|
+
s(n);
|
|
186
196
|
return;
|
|
187
197
|
}
|
|
188
|
-
const i = Object.values(
|
|
189
|
-
for (const
|
|
190
|
-
|
|
198
|
+
const i = Object.values(r);
|
|
199
|
+
for (const n of i)
|
|
200
|
+
b(n) ? n.value = this.replaceLibraryPath(n) : s(n);
|
|
191
201
|
};
|
|
192
|
-
|
|
202
|
+
s(t);
|
|
193
203
|
}
|
|
194
|
-
getLibraryMember(
|
|
195
|
-
let
|
|
196
|
-
for (const
|
|
197
|
-
|
|
198
|
-
return
|
|
204
|
+
getLibraryMember(t = []) {
|
|
205
|
+
let s = [...t];
|
|
206
|
+
for (const r of Object.values(this.imports))
|
|
207
|
+
s = s.concat(Array.from(r));
|
|
208
|
+
return j(s);
|
|
199
209
|
}
|
|
200
|
-
collectContext(
|
|
201
|
-
const
|
|
202
|
-
let
|
|
210
|
+
collectContext(t, s) {
|
|
211
|
+
const r = new Set(s?.id ? this.context[s.id] : []), i = (t.directives || []).find((a) => a.name === "vFor");
|
|
212
|
+
let n = new Set(Array.from(r));
|
|
203
213
|
if (i) {
|
|
204
214
|
const { item: a = "item", index: c = "index" } = i.iterator || {};
|
|
205
|
-
|
|
215
|
+
n = /* @__PURE__ */ new Set([a, c, ...Array.from(n)]);
|
|
206
216
|
}
|
|
207
|
-
const o =
|
|
217
|
+
const o = t.slot;
|
|
208
218
|
if (o) {
|
|
209
|
-
const a = typeof o == "string" ? [] : o.params || [], c = a.length ? a : [`scope_${
|
|
210
|
-
|
|
219
|
+
const a = typeof o == "string" ? [] : o.params || [], c = a.length ? a : [`scope_${s?.id}`];
|
|
220
|
+
n = /* @__PURE__ */ new Set([...c, ...Array.from(n)]);
|
|
211
221
|
}
|
|
212
|
-
this.context[
|
|
222
|
+
this.context[t.id] = n;
|
|
223
|
+
}
|
|
224
|
+
collectStyle(t) {
|
|
225
|
+
t.id && t.props?.style && (this.style[`.${t.name}_${t.id}`] = t.props.style);
|
|
213
226
|
}
|
|
214
|
-
walkNodes(
|
|
215
|
-
const
|
|
216
|
-
this.collectContext(
|
|
227
|
+
walkNodes(t) {
|
|
228
|
+
const s = (r, i) => {
|
|
229
|
+
this.collectContext(r, i), this.collectStyle(r), Array.isArray(r.children) && r.children.forEach((n) => s(n, r));
|
|
217
230
|
};
|
|
218
|
-
Array.isArray(
|
|
231
|
+
Array.isArray(t.nodes) && t.nodes.forEach((r) => s(r));
|
|
219
232
|
}
|
|
220
233
|
}
|
|
221
|
-
function
|
|
222
|
-
return Object.entries(
|
|
223
|
-
const
|
|
224
|
-
return `${
|
|
234
|
+
function st(e = {}) {
|
|
235
|
+
return Object.entries(e).map(([t, s]) => {
|
|
236
|
+
const r = l(s, !1);
|
|
237
|
+
return `${t}:${r}`;
|
|
225
238
|
});
|
|
226
239
|
}
|
|
227
|
-
function
|
|
228
|
-
return
|
|
229
|
-
from: '${
|
|
230
|
-
default: ${
|
|
240
|
+
function rt(e = []) {
|
|
241
|
+
return e.map((t) => `${t.name}: {
|
|
242
|
+
from: '${t.from || t.name}',
|
|
243
|
+
default: ${l(t.default, !0, !1)}
|
|
231
244
|
}`);
|
|
232
245
|
}
|
|
233
|
-
function
|
|
234
|
-
const
|
|
235
|
-
return
|
|
236
|
-
type:${
|
|
237
|
-
required: ${
|
|
238
|
-
default: ${
|
|
246
|
+
function nt(e = []) {
|
|
247
|
+
const t = (s) => s ? `[${G(s).map((n) => n.replace(/\'|\"/gi, "")).join(",")}]` : void 0;
|
|
248
|
+
return e.map((s) => typeof s == "string" ? `${s}: {}` : `${s.name}: {
|
|
249
|
+
type:${t(s.type)},
|
|
250
|
+
required: ${s.required},
|
|
251
|
+
default: ${l(s.default, !0, !1)}
|
|
239
252
|
}`);
|
|
240
253
|
}
|
|
241
|
-
function
|
|
242
|
-
return
|
|
254
|
+
function it(e = []) {
|
|
255
|
+
return e.map((t) => `'${t}'`);
|
|
243
256
|
}
|
|
244
|
-
function
|
|
245
|
-
return Object.entries(
|
|
246
|
-
let i =
|
|
247
|
-
return i =
|
|
257
|
+
function v(e = {}, t = []) {
|
|
258
|
+
return Object.entries(e).map(([s, r]) => {
|
|
259
|
+
let i = q(l(r, !1, !1));
|
|
260
|
+
return i = w(i, t), i.startsWith("async") ? `async ${s}${i.replace(/^async/, "")}` : `${s}${i}`;
|
|
248
261
|
});
|
|
249
262
|
}
|
|
250
|
-
function
|
|
251
|
-
const
|
|
252
|
-
(
|
|
263
|
+
function ot(e = [], t = []) {
|
|
264
|
+
const s = e.reduce(
|
|
265
|
+
(n, o) => (o.id && P(o.source) && (n[`watcher_${o.id}`] = o.source), n),
|
|
253
266
|
{}
|
|
254
|
-
),
|
|
255
|
-
deep: ${
|
|
256
|
-
immediate:${
|
|
257
|
-
handler${
|
|
267
|
+
), r = v(s, t), i = e.map((n) => `watcher_${n.id}: {
|
|
268
|
+
deep: ${n.deep},
|
|
269
|
+
immediate:${n.immediate},
|
|
270
|
+
handler${q(n.handler.value)}
|
|
258
271
|
}`);
|
|
259
272
|
return {
|
|
260
|
-
computed:
|
|
273
|
+
computed: r,
|
|
261
274
|
watches: i
|
|
262
275
|
};
|
|
263
276
|
}
|
|
264
|
-
function
|
|
265
|
-
return Object.values(
|
|
266
|
-
const
|
|
267
|
-
return `async ${
|
|
268
|
-
return await this.provider.apis.${
|
|
277
|
+
function at(e = {}) {
|
|
278
|
+
return Object.values(e).map((t) => {
|
|
279
|
+
const s = P(t.transform) && t.transform.value || "(res) => res";
|
|
280
|
+
return `async ${t.name}(...args:any[]) {
|
|
281
|
+
return await this.provider.apis.${t.ref}.apply(this, args).then(${s});
|
|
269
282
|
}`;
|
|
270
283
|
});
|
|
271
284
|
}
|
|
272
|
-
function
|
|
273
|
-
const
|
|
285
|
+
function D(e, t, s = [], r = {}, i) {
|
|
286
|
+
const n = [];
|
|
274
287
|
let o = {}, a = [], c = [];
|
|
275
|
-
return
|
|
276
|
-
const
|
|
277
|
-
for (const u of
|
|
278
|
-
let { id:
|
|
279
|
-
if (
|
|
288
|
+
return ct(e).forEach((p) => {
|
|
289
|
+
const y = [];
|
|
290
|
+
for (const u of p.children) {
|
|
291
|
+
let { id: x, name: f, invisible: $, from: k } = u;
|
|
292
|
+
if ($)
|
|
280
293
|
continue;
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
const { props: F, events: N, handlers:
|
|
284
|
-
|
|
294
|
+
const A = lt(f, t, k);
|
|
295
|
+
A && a.push(A), ut(k) && c.push({ id: k.id, name: f });
|
|
296
|
+
const { props: F, events: N, handlers: Q } = ht(
|
|
297
|
+
u,
|
|
298
|
+
x,
|
|
285
299
|
u.props,
|
|
286
300
|
u.events,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
), R =
|
|
301
|
+
r,
|
|
302
|
+
s
|
|
303
|
+
), R = yt(u.directives).join(" "), m = u.children ? gt(
|
|
290
304
|
u.children,
|
|
305
|
+
s,
|
|
306
|
+
t,
|
|
291
307
|
r,
|
|
292
|
-
e,
|
|
293
|
-
n,
|
|
294
308
|
u
|
|
295
309
|
) : "";
|
|
296
|
-
Object.assign(o,
|
|
297
|
-
let
|
|
298
|
-
typeof m == "string" ?
|
|
299
|
-
`), Object.assign(o, m?.methods || {}), a = a.concat(m?.components || []), c = c.concat(m?.importBlocks || [])),
|
|
300
|
-
f === "img" ? `<${f} ${R} ${F} ${N}
|
|
310
|
+
Object.assign(o, Q);
|
|
311
|
+
let g = "";
|
|
312
|
+
typeof m == "string" ? g = m : (g = (m?.nodes || []).join(`
|
|
313
|
+
`), Object.assign(o, m?.methods || {}), a = a.concat(m?.components || []), c = c.concat(m?.importBlocks || [])), y.push(
|
|
314
|
+
f === "img" ? `<${f} ${R} ${F} ${N} />
|
|
315
|
+
` : `<${f} ${R} ${F} ${N}>${g ? `
|
|
316
|
+
` + g.trim() : ""}</${f}>`
|
|
301
317
|
);
|
|
302
318
|
}
|
|
303
|
-
const
|
|
319
|
+
const S = vt(p.slot, y.join(`
|
|
304
320
|
`), i?.id);
|
|
305
|
-
|
|
321
|
+
n.push(S);
|
|
306
322
|
}), {
|
|
307
|
-
nodes:
|
|
323
|
+
nodes: n,
|
|
308
324
|
methods: o,
|
|
309
|
-
components:
|
|
310
|
-
importBlocks:
|
|
325
|
+
components: j(a),
|
|
326
|
+
importBlocks: j(c, "id")
|
|
311
327
|
};
|
|
312
328
|
}
|
|
313
|
-
function
|
|
314
|
-
const
|
|
315
|
-
for (const
|
|
316
|
-
const
|
|
317
|
-
i ? i.children.push(
|
|
329
|
+
function ct(e = []) {
|
|
330
|
+
const t = /* @__PURE__ */ new Map();
|
|
331
|
+
for (const s of e) {
|
|
332
|
+
const r = typeof s.slot == "string" ? s.slot : s.slot?.name, i = t.get(r);
|
|
333
|
+
i ? i.children.push(s) : t.set(r, { slot: s.slot, children: [s] });
|
|
318
334
|
}
|
|
319
|
-
return
|
|
335
|
+
return t;
|
|
320
336
|
}
|
|
321
|
-
function
|
|
322
|
-
if (
|
|
337
|
+
function lt(e, t, s) {
|
|
338
|
+
if (Y.includes(e))
|
|
323
339
|
return null;
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
const i =
|
|
327
|
-
return `${
|
|
340
|
+
const r = t.get(e);
|
|
341
|
+
if (r && r.alias) {
|
|
342
|
+
const i = r.parent ? `${r.parent}.${r.alias}` : r.alias;
|
|
343
|
+
return `${e}: ${i}`;
|
|
328
344
|
}
|
|
329
|
-
return
|
|
330
|
-
}
|
|
331
|
-
function
|
|
332
|
-
return !!
|
|
333
|
-
}
|
|
334
|
-
function
|
|
335
|
-
return
|
|
336
|
-
...
|
|
337
|
-
value:
|
|
338
|
-
})}"` :
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
345
|
+
return s || r ? e : null;
|
|
346
|
+
}
|
|
347
|
+
function ut(e) {
|
|
348
|
+
return !!e && typeof e == "object" && e.type === "Schema";
|
|
349
|
+
}
|
|
350
|
+
function pt(e, t, s = []) {
|
|
351
|
+
return e === "style" ? "" : e === "__class" && b(t) ? `:class="${l({
|
|
352
|
+
...t,
|
|
353
|
+
value: w(t.value, s)
|
|
354
|
+
})}"` : typeof t == "string" ? `${e}="${t}"` : b(t) ? `:${e}="${l({
|
|
355
|
+
...t,
|
|
356
|
+
value: w(t.value, s)
|
|
357
|
+
})}"` : H(t) ? `:${e}='{${K(
|
|
358
|
+
t
|
|
359
|
+
).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
|
|
360
|
+
}
|
|
361
|
+
function ft(e, t = {}, s = []) {
|
|
362
|
+
if (!!Object.keys(t.style || {}).length) {
|
|
363
|
+
const i = `${e.name}_${e.id}`;
|
|
364
|
+
t.class ? typeof t.class == "string" ? t.class = [t.class, i].join(" ") : (t.__class = t.class, t.class = i) : (t.class = i, delete t.style);
|
|
365
|
+
}
|
|
366
|
+
return Object.entries(t).map(([i, n]) => pt(i, n, s));
|
|
344
367
|
}
|
|
345
|
-
function
|
|
346
|
-
const i =
|
|
347
|
-
return
|
|
368
|
+
function mt(e, t, s, r) {
|
|
369
|
+
const i = M(t.modifiers, !0);
|
|
370
|
+
return r && r.length > 0 ? `@${e}${i.join("")}="(...args:any[]) => ${s}"` : `@${e}${i.join("")}="${s}"`;
|
|
348
371
|
}
|
|
349
|
-
function
|
|
350
|
-
const
|
|
372
|
+
function dt(e, t = {}, s = {}) {
|
|
373
|
+
const r = {}, i = Array.from(s[e] || /* @__PURE__ */ new Set([])), n = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
351
374
|
return {
|
|
352
|
-
binders: Object.entries(
|
|
353
|
-
const h = c.handler.value.startsWith("this."),
|
|
354
|
-
return h || (
|
|
375
|
+
binders: Object.entries(t).map(([a, c]) => {
|
|
376
|
+
const h = c.handler.value.startsWith("this."), p = h ? E(c.handler.value) : `${d(a)}_handler_${e}${n}`;
|
|
377
|
+
return h || (r[p] = i.length ? {
|
|
355
378
|
type: "JSFunction",
|
|
356
379
|
value: `{
|
|
357
380
|
return (${c.handler.value}).apply(this, args);
|
|
358
381
|
}`
|
|
359
|
-
} : c.handler),
|
|
382
|
+
} : c.handler), mt(a, c, p, i);
|
|
360
383
|
}),
|
|
361
|
-
handlers:
|
|
384
|
+
handlers: r
|
|
362
385
|
};
|
|
363
386
|
}
|
|
364
|
-
function
|
|
365
|
-
const { binders:
|
|
387
|
+
function ht(e, t, s = {}, r = {}, i = {}, n) {
|
|
388
|
+
const { binders: o, handlers: a } = dt(t, r, i);
|
|
366
389
|
return {
|
|
367
|
-
props:
|
|
368
|
-
handlers:
|
|
369
|
-
binders:
|
|
370
|
-
events:
|
|
390
|
+
props: ft(e, s, n).join(" "),
|
|
391
|
+
handlers: a,
|
|
392
|
+
binders: o,
|
|
393
|
+
events: o.join(" ")
|
|
371
394
|
};
|
|
372
395
|
}
|
|
373
|
-
function
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const a =
|
|
377
|
-
|
|
378
|
-
}),
|
|
379
|
-
const { item: o, index: a } = { item: "item", index: "index", ...
|
|
380
|
-
|
|
396
|
+
function yt(e = []) {
|
|
397
|
+
const t = [], { vIf: s, vShow: r, vModels: i, vFor: n } = $t(e);
|
|
398
|
+
if (s && t.push(`v-if="${l(s.value)}"`), r && t.push(`v-show="${l(r.value)}"`), i.forEach((o) => {
|
|
399
|
+
const a = M(o.modifiers, !0), c = o.arg ? _(o.arg) ? `:[${l(o.arg)}]` : `:${o.arg}` : "";
|
|
400
|
+
t.push(`v-model${c}${a}="${l(o.value)}"`);
|
|
401
|
+
}), n) {
|
|
402
|
+
const { item: o, index: a } = { item: "item", index: "index", ...n.iterator };
|
|
403
|
+
t.push(`v-for="(${o}, ${a}) in ${l(n.value)}"`);
|
|
381
404
|
}
|
|
382
|
-
return
|
|
405
|
+
return t;
|
|
383
406
|
}
|
|
384
|
-
function $e
|
|
385
|
-
const
|
|
407
|
+
function $t(e = []) {
|
|
408
|
+
const t = e.find((o) => d(o.name) === "vIf"), s = e.find((o) => d(o.name) === "vFor"), r = e.find((o) => d(o.name) === "vShow"), i = e.find((o) => d(o.name) === "vBind"), n = e.filter((o) => d(o.name) === "vModel");
|
|
386
409
|
return {
|
|
387
|
-
vIf:
|
|
388
|
-
vFor:
|
|
389
|
-
vShow:
|
|
390
|
-
vModels:
|
|
410
|
+
vIf: t,
|
|
411
|
+
vFor: s,
|
|
412
|
+
vShow: r,
|
|
413
|
+
vModels: n,
|
|
391
414
|
vBind: i
|
|
392
415
|
};
|
|
393
416
|
}
|
|
394
|
-
function
|
|
395
|
-
if (typeof
|
|
396
|
-
return
|
|
397
|
-
if (
|
|
398
|
-
let
|
|
399
|
-
return
|
|
417
|
+
function gt(e, t, s, r, i) {
|
|
418
|
+
if (typeof e == "string")
|
|
419
|
+
return e;
|
|
420
|
+
if (_(e)) {
|
|
421
|
+
let n = l(e, !1);
|
|
422
|
+
return n = w(n, t), n = E(n), `{{ ${n} }}`;
|
|
400
423
|
}
|
|
401
|
-
return Array.isArray(
|
|
424
|
+
return Array.isArray(e) ? D(e, s, t, r, i) : "";
|
|
402
425
|
}
|
|
403
|
-
function
|
|
404
|
-
if (!
|
|
405
|
-
return
|
|
406
|
-
const
|
|
407
|
-
return `<template ${`#${
|
|
408
|
-
${
|
|
426
|
+
function vt(e, t, s) {
|
|
427
|
+
if (!e)
|
|
428
|
+
return t;
|
|
429
|
+
const r = typeof e == "string" ? { name: e, params: [] } : { params: [], ...e };
|
|
430
|
+
return `<template ${`#${r.name}="${r.params?.length > 0 ? `{${r.params?.join(",")}}` : `scope_${s}`}"`}>
|
|
431
|
+
${t}
|
|
409
432
|
</template>`;
|
|
410
433
|
}
|
|
411
|
-
function
|
|
434
|
+
function jt(e, t = [], s = [], r = {}) {
|
|
412
435
|
const i = {
|
|
413
436
|
vue: ["defineComponent", "reactive"]
|
|
414
437
|
};
|
|
415
|
-
for (const
|
|
416
|
-
const o =
|
|
438
|
+
for (const n of t) {
|
|
439
|
+
const o = e.get(n.split(":")[0]);
|
|
417
440
|
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
418
441
|
}
|
|
419
|
-
for (const [
|
|
420
|
-
(i[
|
|
421
|
-
return Object.entries(i).filter(([
|
|
442
|
+
for (const [n, o] of Object.entries(r))
|
|
443
|
+
(i[n] ?? (i[n] = [])).push(...Array.from(o));
|
|
444
|
+
return Object.entries(i).filter(([n, o]) => !!o.length).map(([n, o]) => `import { ${j(o).join(
|
|
422
445
|
","
|
|
423
|
-
)}} from '${
|
|
424
|
-
}
|
|
425
|
-
function
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
446
|
+
)}} from '${n}';`).concat(s);
|
|
447
|
+
}
|
|
448
|
+
function bt(e = {}) {
|
|
449
|
+
const t = [];
|
|
450
|
+
for (const [s, r] of Object.entries(e))
|
|
451
|
+
t.push(`
|
|
452
|
+
${s} {
|
|
453
|
+
${tt(r)}
|
|
454
|
+
}
|
|
455
|
+
`);
|
|
456
|
+
return t.join(`
|
|
457
|
+
`);
|
|
458
|
+
}
|
|
459
|
+
function wt(e, t) {
|
|
460
|
+
const { dsl: s } = e, r = Object.keys(s.computed || {}), i = v(s.lifeCycles, r), n = v(s.computed, r), o = ot(s.watch, r), a = at(s.dataSources), { methods: c, nodes: h, components: p, importBlocks: y } = D(
|
|
461
|
+
s.nodes || [],
|
|
462
|
+
t,
|
|
463
|
+
r,
|
|
464
|
+
e.context
|
|
465
|
+
), S = [...n, ...o.computed], u = v(
|
|
432
466
|
{
|
|
433
467
|
...c,
|
|
434
|
-
...
|
|
468
|
+
...s.methods || {}
|
|
435
469
|
},
|
|
436
|
-
|
|
437
|
-
),
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
470
|
+
r
|
|
471
|
+
), x = y.map(($) => `import ${$.name} from './${$.id}.vue';`), f = jt(
|
|
472
|
+
t,
|
|
473
|
+
p,
|
|
474
|
+
x,
|
|
475
|
+
e.imports
|
|
442
476
|
);
|
|
443
477
|
return {
|
|
444
|
-
id:
|
|
445
|
-
version:
|
|
446
|
-
name:
|
|
447
|
-
state:
|
|
448
|
-
inject:
|
|
449
|
-
props:
|
|
450
|
-
emits:
|
|
478
|
+
id: s.id,
|
|
479
|
+
version: s.__VERSION__,
|
|
480
|
+
name: s.name,
|
|
481
|
+
state: st(s.state).join(","),
|
|
482
|
+
inject: rt(s.inject).join(","),
|
|
483
|
+
props: nt(s.props).join(","),
|
|
484
|
+
emits: it(s.emits).join(","),
|
|
451
485
|
watch: o.watches.join(","),
|
|
452
486
|
lifeCycles: i.join(","),
|
|
453
|
-
computed:
|
|
487
|
+
computed: S.join(","),
|
|
454
488
|
methods: [...a, ...u].join(","),
|
|
455
489
|
imports: f.join(`
|
|
456
490
|
`),
|
|
457
|
-
components:
|
|
458
|
-
returns:
|
|
491
|
+
components: p.join(","),
|
|
492
|
+
returns: e.members.join(","),
|
|
459
493
|
template: h.join(`
|
|
460
494
|
`),
|
|
461
|
-
css:
|
|
495
|
+
css: s.css || "",
|
|
496
|
+
style: bt(e.style)
|
|
462
497
|
};
|
|
463
498
|
}
|
|
464
|
-
const
|
|
499
|
+
const St = `
|
|
465
500
|
<%= imports %>
|
|
466
501
|
import { useProvider } from '@vtj/renderer';
|
|
467
502
|
export default defineComponent({
|
|
@@ -487,7 +522,7 @@ export default defineComponent({
|
|
|
487
522
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
488
523
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
489
524
|
});
|
|
490
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
525
|
+
`.replace(/(\n|\r|\t)/g, ""), xt = `
|
|
491
526
|
<template>
|
|
492
527
|
<%= template %>
|
|
493
528
|
</template>
|
|
@@ -496,22 +531,24 @@ export default defineComponent({
|
|
|
496
531
|
<\/script>
|
|
497
532
|
<style lang="scss" scoped>
|
|
498
533
|
<%= css %>
|
|
534
|
+
<%= style %>
|
|
499
535
|
</style>
|
|
500
|
-
`,
|
|
501
|
-
async function
|
|
502
|
-
const i = new
|
|
503
|
-
template:
|
|
504
|
-
css: await
|
|
505
|
-
script: await
|
|
536
|
+
`, kt = B(St), Ot = B(xt);
|
|
537
|
+
async function Et(e, t = /* @__PURE__ */ new Map(), s = [], r) {
|
|
538
|
+
const i = new et(U(e), s), n = wt(i, t), o = kt(n), a = Ot({
|
|
539
|
+
template: n.template,
|
|
540
|
+
css: await W(n.css, r),
|
|
541
|
+
script: await Z(o, r),
|
|
542
|
+
style: await W(n.style, r)
|
|
506
543
|
});
|
|
507
|
-
return await
|
|
544
|
+
return await V(a, r);
|
|
508
545
|
}
|
|
509
|
-
async function
|
|
510
|
-
const
|
|
546
|
+
async function At(e) {
|
|
547
|
+
const t = `
|
|
511
548
|
<template>
|
|
512
549
|
<div>
|
|
513
550
|
<h3>源码模式页面</h3>
|
|
514
|
-
<div>文件路径:/.vtj/vue/${
|
|
551
|
+
<div>文件路径:/.vtj/vue/${e.id}.vue</div>
|
|
515
552
|
</div>
|
|
516
553
|
</template>
|
|
517
554
|
<script lang="ts" setup>
|
|
@@ -519,10 +556,10 @@ async function Pe(t) {
|
|
|
519
556
|
<style scoped lang="scss">
|
|
520
557
|
</style>
|
|
521
558
|
`;
|
|
522
|
-
return await
|
|
559
|
+
return await V(t);
|
|
523
560
|
}
|
|
524
561
|
export {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
562
|
+
Pt as VTJ_CODER_VERSION,
|
|
563
|
+
At as createEmptyPage,
|
|
564
|
+
Et as generator
|
|
528
565
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.7.
|
|
4
|
+
"version": "0.7.15",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "vue-tsc && vite build",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"coverage": "vitest run --coverage"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@vtj/base": "^0.7.
|
|
14
|
-
"@vtj/core": "^0.7.
|
|
13
|
+
"@vtj/base": "^0.7.6",
|
|
14
|
+
"@vtj/core": "^0.7.15",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.7.
|
|
18
|
+
"@vtj/cli": "^0.7.11"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "cbb81a983f9271342f987a2507923ef7c2e55369",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|
package/types/collecter.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare class Collecter {
|
|
|
7
7
|
*/
|
|
8
8
|
imports: Record<string, Set<string>>;
|
|
9
9
|
context: Record<string, Set<string>>;
|
|
10
|
+
style: Record<string, Record<string, any>>;
|
|
10
11
|
members: string[];
|
|
11
12
|
private libraryRegex;
|
|
12
13
|
constructor(dsl: BlockSchema, dependencies: Dependencie[]);
|
|
@@ -21,5 +22,6 @@ export declare class Collecter {
|
|
|
21
22
|
private walk;
|
|
22
23
|
private getLibraryMember;
|
|
23
24
|
private collectContext;
|
|
25
|
+
private collectStyle;
|
|
24
26
|
private walkNodes;
|
|
25
27
|
}
|
package/types/formatters.d.ts
CHANGED
package/types/parser/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseStyle(style?: Record<string, Record<string, any>>): string;
|
package/types/utils.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare function replaceComputedValue(content: string, keys?: string[]):
|
|
|
10
10
|
export declare function replaceFunctionTag(content: string): string;
|
|
11
11
|
export declare function parsePlainObjectValue(obj?: Record<string, any>): string[];
|
|
12
12
|
export declare function getModifiers(modifiers?: Record<string, boolean>, isToString?: boolean): string[];
|
|
13
|
+
export declare function jsonToStyle(json: Record<string, any>): string;
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.7.
|
|
5
|
+
* @version 0.7.14
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.7.
|
|
8
|
+
export declare const version = "0.7.14";
|