@vtj/coder 0.7.14 → 0.7.16
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 -24
- package/dist/index.mjs +327 -289
- 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,45 @@
|
|
|
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"),_=require("prettier/standalone"),Q=require("prettier/plugins/html"),z=require("prettier/plugins/babel"),G=require("prettier/plugins/postcss"),H=require("prettier/plugins/estree");function S(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const r=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,r.get?r:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const U=S(Q),T=S(z),q=S(G),B=S(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.16
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const X="0.7.16";/**!
|
|
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.16
|
|
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 _.format(t,{parser:"vue",...x,plugins:[U,T,B,q]})}async function Z(t,e){return e?t:await _.format(t,{parser:"babel-ts",...x,plugins:[T,B]})}async function W(t,e){return e?t:_.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 v(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,s=!0){const r=v(t)?t.value:e?JSON.stringify(t):t;return s?A(I(r)):I(r)}function j(t,e=[]){let s=t;for(const r of e)s=s.replace(new RegExp(`this.${r}.value`,"g"),`this.${r}`);return s}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,s])=>`"${e}": ${u(s)}`)}function M(t={},e=!1){const s=Object.keys(t);return e?s.map(r=>"."+r):s}function ee(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var r=t[s];e+=s+": "+r+";"}return e}class te{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=[];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 r=s.pop(),i=s.join(".")+".",n=s.pop();if(r&&n){const o=this.dependencies.find(a=>a.library===n)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(r)}return{name:r,path:i,library:n}}return null}replaceLibraryPath(e){const{libraryRegex:s}=this;let r=e.value;for(const i of s){const n=e.value.match(i)||[];for(const o of n){const a=this.collectImport(o);if(a){const c=a.path.replace(/\$/g,"\\$");r=r.replace(new RegExp(c,"g"),"")}}}return r}walk(e){const s=r=>{if(!r||typeof r!="object")return;if(Array.isArray(r)){for(let n of r)s(n);return}const i=Object.values(r);for(const n of i)v(n)?n.value=this.replaceLibraryPath(n):s(n)};s(e)}getLibraryMember(e=[]){let s=[...e];for(const r of Object.values(this.imports))s=s.concat(Array.from(r));return l.dedupArray(s)}collectContext(e,s){const r=new Set(s?.id?this.context[s.id]:[]),i=(e.directives||[]).find(a=>a.name==="vFor");let n=new Set(Array.from(r));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_${s?.id}`];n=new Set([...c,...Array.from(n)])}this.context[e.id]=n}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}walkNodes(e){const s=(r,i)=>{this.collectContext(r,i),this.collectStyle(r),Array.isArray(r.children)&&r.children.forEach(n=>s(n,r))};Array.isArray(e.nodes)&&e.nodes.forEach(r=>s(r))}}function se(t={}){return Object.entries(t).map(([e,s])=>{const r=u(s,!1);return`${e}:${r}`})}function re(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=
|
|
17
|
-
type:${e(
|
|
18
|
-
required: ${
|
|
19
|
-
default: ${u(
|
|
20
|
-
}`)}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${
|
|
24
|
-
}`);return{computed:
|
|
25
|
-
return await this.provider.apis.${e.ref}.apply(this, args).then(${
|
|
26
|
-
}`})}function
|
|
27
|
-
`),Object.assign(o,d?.methods||{}),a=a.concat(d?.components||[]),c=c.concat(d?.importBlocks||[])),
|
|
28
|
-
|
|
16
|
+
}`)}function ne(t=[]){const e=s=>s?`[${l.toArray(s).map(n=>n.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:`${s.name}: {
|
|
17
|
+
type:${e(s.type)},
|
|
18
|
+
required: ${s.required},
|
|
19
|
+
default: ${u(s.default,!0,!1)}
|
|
20
|
+
}`)}function ie(t=[]){return t.map(e=>`'${e}'`)}function b(t={},e=[]){return Object.entries(t).map(([s,r])=>{let i=L(u(r,!1,!1));return i=j(i,e),i.startsWith("async")?`async ${s}${i.replace(/^async/,"")}`:`${s}${i}`})}function oe(t=[],e=[]){const s=t.reduce((n,o)=>(o.id&&P(o.source)&&(n[`watcher_${o.id}`]=o.source),n),{}),r=b(s,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:r,watches:i}}function ae(t={}){return Object.values(t).map(e=>{const s=P(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args:any[]) {
|
|
25
|
+
return await this.provider.apis.${e.ref}.apply(this, args).then(${s});
|
|
26
|
+
}`})}function V(t,e,s=[],r={},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:k}=p;if(g)continue;const E=le(m,e,k);E&&a.push(E),ue(k)&&c.push({id:k.id,name:m});const{props:F,events:N,handlers:D}=he(p,O,p.props,p.events,r,s),R=ye(p.directives).join(" "),d=p.children?$e(p.children,s,e,r,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}>
|
|
30
|
+
`)}const w=be(f.slot,y.join(`
|
|
31
|
+
`),i?.id);n.push(w)}),{nodes:n,methods:o,components:l.dedupArray(a),importBlocks:l.dedupArray(c,"id")}}function ce(t=[]){const e=new Map;for(const s of t){const r=typeof s.slot=="string"?s.slot:s.slot?.name,i=e.get(r);i?i.children.push(s):e.set(r,{slot:s.slot,children:[s]})}return e}function le(t,e,s){if(Y.includes(t))return null;const r=e.get(t);if(r&&r.alias){const i=r.parent?`${r.parent}.${r.alias}`:r.alias;return`${t}: ${i}`}return s||r?t:null}function ue(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function pe(t,e,s=[]){return t==="style"?"":t==="__class"&&v(e)?`:class="${u({...e,value:j(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:v(e)?`:${t}="${u({...e,value:j(e.value,s)})}"`:l.isPlainObject(e)?`:${t}='{${K(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function fe(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,delete e.style)}return Object.entries(e).map(([i,n])=>pe(i,n,s))}function me(t,e,s,r){const i=M(e.modifiers,!0);return r&&r.length>0?`@${t}${i.join("")}="(...args:any[]) => ${s}"`:`@${t}${i.join("")}="${s}"`}function de(t,e={},s={}){const r={},i=Array.from(s[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||(r[f]=i.length?{type:"JSFunction",value:`{
|
|
29
32
|
return (${c.handler.value}).apply(this, args);
|
|
30
|
-
}`}:c.handler),
|
|
33
|
+
}`}:c.handler),me(a,c,f,i)}),handlers:r}}function he(t,e,s={},r={},i={},n){const{binders:o,handlers:a}=de(e,r,i);return{props:fe(t,s,n).join(" "),handlers:a,binders:o,events:o.join(" ")}}function ye(t=[]){const e=[],{vIf:s,vShow:r,vModels:i,vFor:n}=ge(t);if(s&&e.push(`v-if="${u(s.value)}"`),r&&e.push(`v-show="${u(r.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"),s=t.find(o=>l.camelCase(o.name)==="vFor"),r=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:s,vShow:r,vModels:n,vBind:i}}function $e(t,e,s,r,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,s,e,r,i):""}function be(t,e,s){if(!t)return e;const r=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${r.name}="${r.params?.length>0?`{${r.params?.join(",")}}`:`scope_${s}`}"`}>
|
|
31
34
|
${e}
|
|
32
|
-
</template>`}function
|
|
35
|
+
</template>`}function ve(t,e=[],s=[],r={}){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(r))(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(s)}function je(t={}){const e=[];for(const[s,r]of Object.entries(t))e.push(`
|
|
36
|
+
${s} {
|
|
37
|
+
${ee(r)}
|
|
38
|
+
}
|
|
39
|
+
`);return e.join(`
|
|
40
|
+
`)}function Se(t,e){const{dsl:s}=t,r=Object.keys(s.computed||{}),i=b(s.lifeCycles,r),n=b(s.computed,r),o=oe(s.watch,r),a=ae(s.dataSources),{methods:c,nodes:h,components:f,importBlocks:y}=V(s.nodes||[],e,r,t.context),w=[...n,...o.computed],p=b({...c,...s.methods||{}},r),O=y.map(g=>`import ${g.name} from './${g.id}.vue';`),m=ve(e,f,O,t.imports);return{id:s.id,version:s.__VERSION__,name:s.name,state:se(s.state).join(","),inject:re(s.inject).join(","),props:ne(s.props).join(","),emits:ie(s.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:w.join(","),methods:[...a,...p].join(","),imports:m.join(`
|
|
33
41
|
`),components:f.join(","),returns:t.members.join(","),template:h.join(`
|
|
34
|
-
`),css:
|
|
42
|
+
`),css:s.css||"",style:je(t.style)}}const we=`
|
|
35
43
|
<%= imports %>
|
|
36
44
|
import { useProvider } from '@vtj/renderer';
|
|
37
45
|
export default defineComponent({
|
|
@@ -57,7 +65,7 @@ export default defineComponent({
|
|
|
57
65
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
58
66
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
59
67
|
});
|
|
60
|
-
`.replace(/(\n|\r|\t)/g,""),
|
|
68
|
+
`.replace(/(\n|\r|\t)/g,""),Oe=`
|
|
61
69
|
<template>
|
|
62
70
|
<%= template %>
|
|
63
71
|
</template>
|
|
@@ -66,8 +74,9 @@ export default defineComponent({
|
|
|
66
74
|
<\/script>
|
|
67
75
|
<style lang="scss" scoped>
|
|
68
76
|
<%= css %>
|
|
77
|
+
<%= style %>
|
|
69
78
|
</style>
|
|
70
|
-
`,
|
|
79
|
+
`,ke=l.template(we),_e=l.template(Oe);async function xe(t,e=new Map,s=[],r){const i=new te(l.cloneDeep(t),s),n=Se(i,e),o=ke(n),a=_e({template:n.template,css:await W(n.css,r),script:await Z(o,r),style:await W(n.style,r)});return await J(a,r)}async function Ce(t){const e=`
|
|
71
80
|
<template>
|
|
72
81
|
<div>
|
|
73
82
|
<h3>源码模式页面</h3>
|
|
@@ -78,4 +87,4 @@ export default defineComponent({
|
|
|
78
87
|
<\/script>
|
|
79
88
|
<style scoped lang="scss">
|
|
80
89
|
</style>
|
|
81
|
-
`;return await
|
|
90
|
+
`;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 h, 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.16
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const Pt = "0.7.16";
|
|
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.16
|
|
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,451 @@ 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 && Object.keys(t.props.style).length && (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 } = dt(
|
|
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}>
|
|
317
|
+
`
|
|
301
318
|
);
|
|
302
319
|
}
|
|
303
|
-
const
|
|
320
|
+
const S = vt(p.slot, y.join(`
|
|
304
321
|
`), i?.id);
|
|
305
|
-
|
|
322
|
+
n.push(S);
|
|
306
323
|
}), {
|
|
307
|
-
nodes:
|
|
324
|
+
nodes: n,
|
|
308
325
|
methods: o,
|
|
309
|
-
components:
|
|
310
|
-
importBlocks:
|
|
326
|
+
components: j(a),
|
|
327
|
+
importBlocks: j(c, "id")
|
|
311
328
|
};
|
|
312
329
|
}
|
|
313
|
-
function
|
|
314
|
-
const
|
|
315
|
-
for (const
|
|
316
|
-
const
|
|
317
|
-
i ? i.children.push(
|
|
330
|
+
function ct(e = []) {
|
|
331
|
+
const t = /* @__PURE__ */ new Map();
|
|
332
|
+
for (const s of e) {
|
|
333
|
+
const r = typeof s.slot == "string" ? s.slot : s.slot?.name, i = t.get(r);
|
|
334
|
+
i ? i.children.push(s) : t.set(r, { slot: s.slot, children: [s] });
|
|
318
335
|
}
|
|
319
|
-
return
|
|
336
|
+
return t;
|
|
320
337
|
}
|
|
321
|
-
function
|
|
322
|
-
if (
|
|
338
|
+
function lt(e, t, s) {
|
|
339
|
+
if (Y.includes(e))
|
|
323
340
|
return null;
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
const i =
|
|
327
|
-
return `${
|
|
341
|
+
const r = t.get(e);
|
|
342
|
+
if (r && r.alias) {
|
|
343
|
+
const i = r.parent ? `${r.parent}.${r.alias}` : r.alias;
|
|
344
|
+
return `${e}: ${i}`;
|
|
328
345
|
}
|
|
329
|
-
return
|
|
330
|
-
}
|
|
331
|
-
function
|
|
332
|
-
return !!
|
|
333
|
-
}
|
|
334
|
-
function
|
|
335
|
-
return
|
|
336
|
-
...
|
|
337
|
-
value:
|
|
338
|
-
})}"` :
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
|
|
346
|
+
return s || r ? e : null;
|
|
347
|
+
}
|
|
348
|
+
function ut(e) {
|
|
349
|
+
return !!e && typeof e == "object" && e.type === "Schema";
|
|
350
|
+
}
|
|
351
|
+
function pt(e, t, s = []) {
|
|
352
|
+
return e === "style" ? "" : e === "__class" && b(t) ? `:class="${l({
|
|
353
|
+
...t,
|
|
354
|
+
value: w(t.value, s)
|
|
355
|
+
})}"` : typeof t == "string" ? `${e}="${t}"` : b(t) ? `:${e}="${l({
|
|
356
|
+
...t,
|
|
357
|
+
value: w(t.value, s)
|
|
358
|
+
})}"` : H(t) ? `:${e}='{${K(
|
|
359
|
+
t
|
|
360
|
+
).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
|
|
361
|
+
}
|
|
362
|
+
function ft(e, t = {}, s = []) {
|
|
363
|
+
if (!!Object.keys(t.style || {}).length) {
|
|
364
|
+
const i = `${e.name}_${e.id}`;
|
|
365
|
+
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);
|
|
366
|
+
}
|
|
367
|
+
return Object.entries(t).map(([i, n]) => pt(i, n, s));
|
|
344
368
|
}
|
|
345
|
-
function
|
|
346
|
-
const i =
|
|
347
|
-
return
|
|
369
|
+
function mt(e, t, s, r) {
|
|
370
|
+
const i = M(t.modifiers, !0);
|
|
371
|
+
return r && r.length > 0 ? `@${e}${i.join("")}="(...args:any[]) => ${s}"` : `@${e}${i.join("")}="${s}"`;
|
|
348
372
|
}
|
|
349
|
-
function
|
|
350
|
-
const
|
|
373
|
+
function ht(e, t = {}, s = {}) {
|
|
374
|
+
const r = {}, i = Array.from(s[e] || /* @__PURE__ */ new Set([])), n = i.length ? `({${i.join(", ")}}, args)` : "";
|
|
351
375
|
return {
|
|
352
|
-
binders: Object.entries(
|
|
353
|
-
const
|
|
354
|
-
return
|
|
376
|
+
binders: Object.entries(t).map(([a, c]) => {
|
|
377
|
+
const d = c.handler.value.startsWith("this."), p = d ? E(c.handler.value) : `${h(a)}_handler_${e}${n}`;
|
|
378
|
+
return d || (r[p] = i.length ? {
|
|
355
379
|
type: "JSFunction",
|
|
356
380
|
value: `{
|
|
357
381
|
return (${c.handler.value}).apply(this, args);
|
|
358
382
|
}`
|
|
359
|
-
} : c.handler),
|
|
383
|
+
} : c.handler), mt(a, c, p, i);
|
|
360
384
|
}),
|
|
361
|
-
handlers:
|
|
385
|
+
handlers: r
|
|
362
386
|
};
|
|
363
387
|
}
|
|
364
|
-
function
|
|
365
|
-
const { binders:
|
|
388
|
+
function dt(e, t, s = {}, r = {}, i = {}, n) {
|
|
389
|
+
const { binders: o, handlers: a } = ht(t, r, i);
|
|
366
390
|
return {
|
|
367
|
-
props:
|
|
368
|
-
handlers:
|
|
369
|
-
binders:
|
|
370
|
-
events:
|
|
391
|
+
props: ft(e, s, n).join(" "),
|
|
392
|
+
handlers: a,
|
|
393
|
+
binders: o,
|
|
394
|
+
events: o.join(" ")
|
|
371
395
|
};
|
|
372
396
|
}
|
|
373
|
-
function
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
const a =
|
|
377
|
-
|
|
378
|
-
}),
|
|
379
|
-
const { item: o, index: a } = { item: "item", index: "index", ...
|
|
380
|
-
|
|
397
|
+
function yt(e = []) {
|
|
398
|
+
const t = [], { vIf: s, vShow: r, vModels: i, vFor: n } = $t(e);
|
|
399
|
+
if (s && t.push(`v-if="${l(s.value)}"`), r && t.push(`v-show="${l(r.value)}"`), i.forEach((o) => {
|
|
400
|
+
const a = M(o.modifiers, !0), c = o.arg ? _(o.arg) ? `:[${l(o.arg)}]` : `:${o.arg}` : "";
|
|
401
|
+
t.push(`v-model${c}${a}="${l(o.value)}"`);
|
|
402
|
+
}), n) {
|
|
403
|
+
const { item: o, index: a } = { item: "item", index: "index", ...n.iterator };
|
|
404
|
+
t.push(`v-for="(${o}, ${a}) in ${l(n.value)}"`);
|
|
381
405
|
}
|
|
382
|
-
return
|
|
406
|
+
return t;
|
|
383
407
|
}
|
|
384
|
-
function $e
|
|
385
|
-
const
|
|
408
|
+
function $t(e = []) {
|
|
409
|
+
const t = e.find((o) => h(o.name) === "vIf"), s = e.find((o) => h(o.name) === "vFor"), r = e.find((o) => h(o.name) === "vShow"), i = e.find((o) => h(o.name) === "vBind"), n = e.filter((o) => h(o.name) === "vModel");
|
|
386
410
|
return {
|
|
387
|
-
vIf:
|
|
388
|
-
vFor:
|
|
389
|
-
vShow:
|
|
390
|
-
vModels:
|
|
411
|
+
vIf: t,
|
|
412
|
+
vFor: s,
|
|
413
|
+
vShow: r,
|
|
414
|
+
vModels: n,
|
|
391
415
|
vBind: i
|
|
392
416
|
};
|
|
393
417
|
}
|
|
394
|
-
function
|
|
395
|
-
if (typeof
|
|
396
|
-
return
|
|
397
|
-
if (
|
|
398
|
-
let
|
|
399
|
-
return
|
|
418
|
+
function gt(e, t, s, r, i) {
|
|
419
|
+
if (typeof e == "string")
|
|
420
|
+
return e;
|
|
421
|
+
if (_(e)) {
|
|
422
|
+
let n = l(e, !1);
|
|
423
|
+
return n = w(n, t), n = E(n), `{{ ${n} }}`;
|
|
400
424
|
}
|
|
401
|
-
return Array.isArray(
|
|
425
|
+
return Array.isArray(e) ? D(e, s, t, r, i) : "";
|
|
402
426
|
}
|
|
403
|
-
function
|
|
404
|
-
if (!
|
|
405
|
-
return
|
|
406
|
-
const
|
|
407
|
-
return `<template ${`#${
|
|
408
|
-
${
|
|
427
|
+
function vt(e, t, s) {
|
|
428
|
+
if (!e)
|
|
429
|
+
return t;
|
|
430
|
+
const r = typeof e == "string" ? { name: e, params: [] } : { params: [], ...e };
|
|
431
|
+
return `<template ${`#${r.name}="${r.params?.length > 0 ? `{${r.params?.join(",")}}` : `scope_${s}`}"`}>
|
|
432
|
+
${t}
|
|
409
433
|
</template>`;
|
|
410
434
|
}
|
|
411
|
-
function
|
|
435
|
+
function jt(e, t = [], s = [], r = {}) {
|
|
412
436
|
const i = {
|
|
413
437
|
vue: ["defineComponent", "reactive"]
|
|
414
438
|
};
|
|
415
|
-
for (const
|
|
416
|
-
const o =
|
|
439
|
+
for (const n of t) {
|
|
440
|
+
const o = e.get(n.split(":")[0]);
|
|
417
441
|
o && o.package && (i[o.package] ?? (i[o.package] = [])).push(o.parent || (o.alias || "").split(".")[0] || o.name);
|
|
418
442
|
}
|
|
419
|
-
for (const [
|
|
420
|
-
(i[
|
|
421
|
-
return Object.entries(i).filter(([
|
|
443
|
+
for (const [n, o] of Object.entries(r))
|
|
444
|
+
(i[n] ?? (i[n] = [])).push(...Array.from(o));
|
|
445
|
+
return Object.entries(i).filter(([n, o]) => !!o.length).map(([n, o]) => `import { ${j(o).join(
|
|
422
446
|
","
|
|
423
|
-
)}} from '${
|
|
424
|
-
}
|
|
425
|
-
function
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
447
|
+
)}} from '${n}';`).concat(s);
|
|
448
|
+
}
|
|
449
|
+
function bt(e = {}) {
|
|
450
|
+
const t = [];
|
|
451
|
+
for (const [s, r] of Object.entries(e))
|
|
452
|
+
t.push(`
|
|
453
|
+
${s} {
|
|
454
|
+
${tt(r)}
|
|
455
|
+
}
|
|
456
|
+
`);
|
|
457
|
+
return t.join(`
|
|
458
|
+
`);
|
|
459
|
+
}
|
|
460
|
+
function wt(e, t) {
|
|
461
|
+
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: d, components: p, importBlocks: y } = D(
|
|
462
|
+
s.nodes || [],
|
|
463
|
+
t,
|
|
464
|
+
r,
|
|
465
|
+
e.context
|
|
466
|
+
), S = [...n, ...o.computed], u = v(
|
|
432
467
|
{
|
|
433
468
|
...c,
|
|
434
|
-
...
|
|
469
|
+
...s.methods || {}
|
|
435
470
|
},
|
|
436
|
-
|
|
437
|
-
),
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
471
|
+
r
|
|
472
|
+
), x = y.map(($) => `import ${$.name} from './${$.id}.vue';`), f = jt(
|
|
473
|
+
t,
|
|
474
|
+
p,
|
|
475
|
+
x,
|
|
476
|
+
e.imports
|
|
442
477
|
);
|
|
443
478
|
return {
|
|
444
|
-
id:
|
|
445
|
-
version:
|
|
446
|
-
name:
|
|
447
|
-
state:
|
|
448
|
-
inject:
|
|
449
|
-
props:
|
|
450
|
-
emits:
|
|
479
|
+
id: s.id,
|
|
480
|
+
version: s.__VERSION__,
|
|
481
|
+
name: s.name,
|
|
482
|
+
state: st(s.state).join(","),
|
|
483
|
+
inject: rt(s.inject).join(","),
|
|
484
|
+
props: nt(s.props).join(","),
|
|
485
|
+
emits: it(s.emits).join(","),
|
|
451
486
|
watch: o.watches.join(","),
|
|
452
487
|
lifeCycles: i.join(","),
|
|
453
|
-
computed:
|
|
488
|
+
computed: S.join(","),
|
|
454
489
|
methods: [...a, ...u].join(","),
|
|
455
490
|
imports: f.join(`
|
|
456
491
|
`),
|
|
457
|
-
components:
|
|
458
|
-
returns:
|
|
459
|
-
template:
|
|
492
|
+
components: p.join(","),
|
|
493
|
+
returns: e.members.join(","),
|
|
494
|
+
template: d.join(`
|
|
460
495
|
`),
|
|
461
|
-
css:
|
|
496
|
+
css: s.css || "",
|
|
497
|
+
style: bt(e.style)
|
|
462
498
|
};
|
|
463
499
|
}
|
|
464
|
-
const
|
|
500
|
+
const St = `
|
|
465
501
|
<%= imports %>
|
|
466
502
|
import { useProvider } from '@vtj/renderer';
|
|
467
503
|
export default defineComponent({
|
|
@@ -487,7 +523,7 @@ export default defineComponent({
|
|
|
487
523
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
488
524
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
489
525
|
});
|
|
490
|
-
`.replace(/(\n|\r|\t)/g, ""),
|
|
526
|
+
`.replace(/(\n|\r|\t)/g, ""), xt = `
|
|
491
527
|
<template>
|
|
492
528
|
<%= template %>
|
|
493
529
|
</template>
|
|
@@ -496,22 +532,24 @@ export default defineComponent({
|
|
|
496
532
|
<\/script>
|
|
497
533
|
<style lang="scss" scoped>
|
|
498
534
|
<%= css %>
|
|
535
|
+
<%= style %>
|
|
499
536
|
</style>
|
|
500
|
-
`,
|
|
501
|
-
async function
|
|
502
|
-
const i = new
|
|
503
|
-
template:
|
|
504
|
-
css: await
|
|
505
|
-
script: await
|
|
537
|
+
`, kt = B(St), Ot = B(xt);
|
|
538
|
+
async function Et(e, t = /* @__PURE__ */ new Map(), s = [], r) {
|
|
539
|
+
const i = new et(U(e), s), n = wt(i, t), o = kt(n), a = Ot({
|
|
540
|
+
template: n.template,
|
|
541
|
+
css: await W(n.css, r),
|
|
542
|
+
script: await Z(o, r),
|
|
543
|
+
style: await W(n.style, r)
|
|
506
544
|
});
|
|
507
|
-
return await
|
|
545
|
+
return await V(a, r);
|
|
508
546
|
}
|
|
509
|
-
async function
|
|
510
|
-
const
|
|
547
|
+
async function At(e) {
|
|
548
|
+
const t = `
|
|
511
549
|
<template>
|
|
512
550
|
<div>
|
|
513
551
|
<h3>源码模式页面</h3>
|
|
514
|
-
<div>文件路径:/.vtj/vue/${
|
|
552
|
+
<div>文件路径:/.vtj/vue/${e.id}.vue</div>
|
|
515
553
|
</div>
|
|
516
554
|
</template>
|
|
517
555
|
<script lang="ts" setup>
|
|
@@ -519,10 +557,10 @@ async function Pe(t) {
|
|
|
519
557
|
<style scoped lang="scss">
|
|
520
558
|
</style>
|
|
521
559
|
`;
|
|
522
|
-
return await
|
|
560
|
+
return await V(t);
|
|
523
561
|
}
|
|
524
562
|
export {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
563
|
+
Pt as VTJ_CODER_VERSION,
|
|
564
|
+
At as createEmptyPage,
|
|
565
|
+
Et as generator
|
|
528
566
|
};
|
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.16",
|
|
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.16",
|
|
15
15
|
"prettier": "~3.2.1"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@vtj/cli": "^0.7.
|
|
18
|
+
"@vtj/cli": "^0.7.12"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist",
|
|
32
32
|
"types"
|
|
33
33
|
],
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "019f5b44f569449f1590ef591c56986d076a8335",
|
|
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.16
|
|
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.16";
|