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