@vtj/coder 0.19.21 → 0.19.23-alpha.0
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 +57 -57
- package/dist/index.mjs +564 -515
- package/package.json +3 -3
- package/types/generator.d.ts +3 -2
- package/types/parser/composition/index.d.ts +1 -1
- package/types/parser/index.d.ts +1 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@vtj/base"),H=require("prettier/standalone"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("@vtj/base"),H=require("prettier/standalone"),Ae=require("prettier/plugins/html"),Oe=require("prettier/plugins/babel"),Pe=require("prettier/plugins/postcss"),xe=require("prettier/plugins/estree");function F(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const 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 Ee=F(Ae),Y=F(Oe),K=F(Pe),ee=F(xe);/**!
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.19.
|
|
5
|
+
* @version 0.19.23-alpha.0
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
7
|
+
*/const Be="0.19.23-alpha.0";/**!
|
|
8
8
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
9
9
|
* @name @vtj/core
|
|
10
10
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
11
|
-
* @version 0.19.
|
|
11
|
+
* @version 0.19.23-alpha.0
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
|
-
*/const
|
|
13
|
+
*/const Me=["slot","template","component","img","div","p","h1","h2","h3","span","a"];b.mitt();function Ne(t){return(t||"").trim().replace(/\\/g,"/").replace(/^\/+|\/+$/g,"").replace(/\.vue$/i,"")}function te(t){return Ne(t.filePath)||t.id}function J(t,e="web"){const s=te(t);return t.type==="block"?`src/components/${s}.vue`:e==="uniapp"?`src/pages/${s}.vue`:`src/views/${s}.vue`}function se(t){return`@/components/${te(t)}.vue`}function ne(t=[]){const e=[];for(const s of t)s.dir||e.push(s),s.children?.length&&e.push(...ne(s.children));return e}function Te(t){const e=new Map,s=new Map,r=new Map,n=new Map;for(const o of t.blocks||[]){const c=J(o,t.platform).toLowerCase();e.set(o.id,o),r.set(c,o.id),s.set(se(o).toLowerCase(),o.id)}for(const o of ne(t.pages))e.set(o.id,o),n.set(J(o,t.platform).toLowerCase(),o.id);return{byId:e,blockIdByImportPath:s,blockIdBySourcePath:r,pageIdBySourcePath:n}}const G={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,removeBlankLines:!0};async function V(t,e){return e?t:await H.format(t,{parser:"vue",...G,plugins:[Ee,Y,ee,K]})}async function re(t,e){if(e)return t;try{return(await H.format(t,{parser:"babel-ts",...G,plugins:[Y,ee]})).replace(/;\n$/gi,"")}catch(s){return console.warn(s),t}}async function W(t,e){return e?t:H.format(t,{parser:"scss",...G,plugins:[K]})}function N(t){return t&&t.type==="JSExpression"}function R(t){return typeof t=="object"&&t&&t.type==="JSFunction"}function k(t){return N(t)||R(t)}function oe(t){return t.replace(new RegExp("this.","g"),"")}function q(t){return t.replace(/this\.context\??\./g,"")}function y(t,e=!0,s=!0,r=[],n=!0){let o=t;return k(t)?(o=t.value.trim().replace(/;$/,""),n&&(o=o.replace(/\"/g,"'"))):o=e?JSON.stringify(o):t,o=T(o,r),s?oe(q(o)):q(o)}function T(t="",e=[]){let s=t;for(const r of e)s=s.replace(new RegExp(`this.${r}.value`,"g"),`this.${r}`);return s}function ce(t){let e=t.trim().replace(/;$/,"");if(e=/^\((\(|async|function)/.test(e)?e.substring(1,e.length-1):e,e.startsWith("{"))return e;if(e.startsWith("async function"))e=e.replace(/^async function/,"async");else if(e.startsWith("function"))e=e.replace(/^function/,"");else{const n=/^(async\s)?\([\w]*\)\s+\=\>\s([\w\W]+)/,o=e.match(n);o&&o[2]&&(o[2].startsWith("{")||(e=e.replace(o[2],`{ return ${o[2]} }`))),e=e.replace("=>","")}return e}function Re(t={}){return Object.entries(t).map(([e,s])=>`"${e}": ${y(s)}`)}function ae(t={},e=!1){const s=Object.keys(t);return e?s.map(r=>"."+r):s}function Le(t){let e="";for(var s in t)if(t.hasOwnProperty(s)){var r=t[s];e+=s+": "+r+";"}return e}function De(t=[],e=[]){return t.filter(s=>!e.includes(s))}function Q(t){return b.base64(JSON.stringify(t))}class Ue{constructor(e,s){this.dsl=e,this.dependencies=s,this.collectEasycom(),this.libraryRegex=this.collectLibrary(),this.walk(e),this.walkNodes(e),this.members=this.getLibraryMember()}imports={};context={};style={};members=[];urlSchemas={};blockPlugins={};easycomPackages=new Set;libraryRegex=[];collectEasycom(){for(const e of this.dependencies)e.easycom?.key&&e.easycom?.value&&e.package&&this.easycomPackages.add(e.package)}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(),n=s.join(".")+".",o=s.pop();if(r&&o){const c=this.dependencies.find(a=>a.library===o)?.package;c&&!this.easycomPackages.has(c)&&(this.imports[c]||(this.imports[c]=new Set)).add(r)}return{name:r,path:n,library:o}}return null}replaceLibraryPath(e){const{libraryRegex:s}=this;let r=e.value;for(const n of s){const o=e.value?.match(n)||[];for(const c of o){const a=this.collectImport(c);if(a){const l=a.path.replace(/\$/g,"\\$");r=r.replace(new RegExp(l,"g"),"")}}}return r}walk(e){const s=r=>{if(!r||typeof r!="object")return;if(Array.isArray(r)){for(let o of r)s(o);return}const n=Object.values(r);for(const o of n)k(o)?o.value=this.replaceLibraryPath(o):s(o)};s(e)}getLibraryMember(e=[]){let s=[...e];const r={...this.imports};delete r["uni-h5"],delete r["@dcloudio/uni-h5"],delete r["uni-ui"],delete r["@dcloudio/uni-ui"];for(const n of Object.values(r))s=s.concat(Array.from(n));return b.dedupArray(s)}collectContext(e,s){const r=new Set(s?.id?this.context[s.id]:[]),n=(e.directives||[]).find(a=>a.name==="vFor");let o=new Set(Array.from(r));if(n){const{item:a="item",index:l="index"}=n.iterator||{};o=new Set([a,l,...Array.from(o)])}const c=e.slot;if(c){const a=typeof c=="string"?[]:c.params||[],l=a.length?a:[`scope_${s?.id}`];o=new Set([...l,...Array.from(o)])}this.context[e.id]=o}collectStyle(e){e.id&&e.props?.style&&Object.keys(e.props.style).length&&!k(e.props.style)&&(this.style[`.${e.name}_${e.id}`]=e.props.style)}collectUrlSchema(e){typeof e.from=="object"&&e.from.type==="UrlSchema"&&(this.urlSchemas[e.name]=e.from)}collectBlockPlugin(e){typeof e.from=="object"&&e.from.type==="Plugin"&&(this.blockPlugins[e.name]=e.from)}walkNodes(e){const s=(r,n)=>{this.collectContext(r,n),this.collectStyle(r),this.collectUrlSchema(r),this.collectBlockPlugin(r),Array.isArray(r.children)&&r.children.forEach(o=>s(o,r))};Array.isArray(e.nodes)&&e.nodes.forEach(r=>s(r))}}function Fe(t={}){return Object.entries(t).map(([e,s])=>{const r=y(s,!1,!0,[],!1);return`${e}:${r}`})}function Je(t=[]){return t.map(e=>`${e.name}: {
|
|
14
14
|
from: '${e.from||e.name}',
|
|
15
15
|
default: ${y(e.default,!0,!1,[],!1)}
|
|
16
|
-
}`)}function
|
|
16
|
+
}`)}function ie(t=[]){const e=s=>s?`[${b.toArray(s).map(o=>o.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(s=>typeof s=="string"?`${s}: {}`:(k(s.default)&&!s.default.value&&(s.default.value="undefined"),`${s.name}: {
|
|
17
17
|
type:${e(s.type)},
|
|
18
18
|
required: ${y(!!s.required,!0,!1,[],!1)},
|
|
19
19
|
default: ${s.default?y(s.default,!0,!1,[],!1):"undefined"}
|
|
20
|
-
}`))}function
|
|
21
|
-
deep: ${
|
|
22
|
-
immediate:${
|
|
23
|
-
handler${
|
|
24
|
-
}`:null).filter(
|
|
25
|
-
// DataSource: ${
|
|
20
|
+
}`))}function le(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function U(t={},e=[]){return Object.entries(t).map(([s,r])=>{let n=ce(y(r,!1,!1,[],!1));return n=T(n,e)?.trim(),n.startsWith("async")?`async ${s}${n.replace(/^async/,"")}`:n.startsWith("(")||n.startsWith("{")?`${s}${n}`:null}).filter(s=>!!s)}function We(t=[],e=[]){const s=t.reduce((o,c)=>(c.id&&R(c.source)&&(o[`watcher_${c.id}`]=c.source),o),{}),r=U(s,e),n=t.map(o=>o.handler&&o.handler.value?`watcher_${o.id}: {
|
|
21
|
+
deep: ${o.deep},
|
|
22
|
+
immediate:${o.immediate},
|
|
23
|
+
handler${ce(o.handler.value)}
|
|
24
|
+
}`:null).filter(o=>!!o);return{computed:r,watches:n}}function qe(t={}){return Object.values(t).map(e=>{if(e.type==="mock"){const s=R(e.mockTemplate)&&e.mockTemplate.value||"(params) => ({})";return`async ${e.name}(...args) {
|
|
25
|
+
// DataSource: ${Q(e)}
|
|
26
26
|
const mock = this.provider.createMock(${s});
|
|
27
27
|
return await mock.apply(this, args);
|
|
28
|
-
}`}else{const s=
|
|
29
|
-
// DataSource: ${
|
|
28
|
+
}`}else{const s=R(e.transform)&&e.transform.value||"(res) => res";return`async ${e.name}(...args) {
|
|
29
|
+
// DataSource: ${Q(e)}
|
|
30
30
|
return await this.provider.apis['${e.ref}'].apply(this, args).then(${s});
|
|
31
|
-
}`}})}const
|
|
32
|
-
`),Object.assign(
|
|
33
|
-
`+
|
|
34
|
-
`),
|
|
31
|
+
}`}})}const He=["img","input","br","hr","area","base","col","embed","link","meta","param","source","track","wbr"],X=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"];function z(t,e,s=[],r={},n,o=new Set){const c=[];let a={},l=[];const m=[];let p=[];return Ve(t).forEach(u=>{const f=[];for(const g of u.children){let{id:O,name:h,invisible:v,from:d}=g;if(v)continue;const S=ze(h,e,d);S&&l.push(S),ue(d)&&p.push({id:d.id,name:h});const{props:j,events:I}=Ke(g,O,g.props,g.events,r,s),C=et(g.directives,s,m).join(" "),$=g.children?nt(g.children,s,e,r,g,o):"";let P="";typeof $=="string"?P=$:(P=($?.nodes||[]).join(`
|
|
32
|
+
`),Object.assign(a,$?.methods||{}),l=l.concat($?.components||[]),p=p.concat($?.importBlocks||[]));const L=d||e.get(h)?.package,x=o.has(L)||["@dcloudio/uni-h5","@dcloudio/uni-ui"].includes(L)?b.kebabCase(h):pe(d)||fe(d)?"component":h;f.push(He.includes(x)?`<${x} ${C} ${j} ${I} />`:`<${x} ${C} ${j} ${I}>${P?`
|
|
33
|
+
`+P.trim():""}</${x}>`)}const _=rt(u.slot,f.join(`
|
|
34
|
+
`),n?.id);c.push(_)}),{nodes:c,methods:a,directives:Ge(m),components:b.dedupArray(l),importBlocks:b.dedupArray(p,"id")}}function Ge(t){return b.dedupArray(t).map(e=>`${e.startsWith("v")?e.substring(1):e}:${e}`)}function Ve(t=[]){const e=new Map;for(const s of t){const r=typeof s.slot=="string"?s.slot:s.slot?.name,n=e.get(r);n?n.children.push(s):e.set(r,{slot:s.slot,children:[s]})}return e}function ze(t,e,s){if(Me.includes(t))return null;const r=e.get(t);if(r&&r.alias){const n=r.parent?`${r.parent}.${r.alias}`:r.alias;return`${t}: ${n}`}return ue(s)||r?t:null}function ue(t){return!!t&&typeof t=="object"&&t.type==="Schema"}function pe(t){return typeof t=="object"&&t.type==="UrlSchema"}function fe(t){return typeof t=="object"&&t.type==="Plugin"}function Ze(t,e,s=[]){return t==="style"?k(e)?`:style="${y({...e,value:T(e.value,s)})}"`:"":t==="__class"&&k(e)?`:class="${y({...e,value:T(e.value,s)})}"`:typeof e=="string"?`${t}="${e}"`:k(e)?`:${t}="${y({...e,value:T(e.value,s)})}"`:b.isPlainObject(e)?`:${t}='{${Re(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function Qe(t,e={},s=[]){if(!!Object.keys(e.style||{}).length){const o=`${t.name}_${t.id}`;e.class?typeof e.class=="string"?e.class=[e.class,o].join(" "):(e.__class=e.class,e.class=o):e.class=o,k(e.style)||delete e.style}const n=t.from;return(pe(n)||fe(n))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([o,c])=>Ze(o,c,s))}function Xe(t,e,s){const r=ae(e.modifiers,!0);return`@${t}${r.join("")}="${s}"`}function Ye(t,e={},s={}){const r={};return{binders:Object.entries(e).map(([o,c])=>{const a=oe(q(c.handler.value)).replace(/\"/g,"'");return Xe(o,c,a)}),handlers:r}}function Ke(t,e,s={},r={},n={},o){const{binders:c,handlers:a}=Ye(e,r,n);return{props:Qe(t,s,o).join(" "),handlers:a,binders:c,events:c.join(" ")}}function et(t=[],e=[],s=[]){const r=[],{vIf:n,vElse:o,vElseIf:c,vShow:a,vModels:l,vFor:m,vBind:p,vHtml:i,customDirectives:u}=tt(t);if(n&&r.push(`v-if="${y(n.value,!0,!0,e)}"`),c&&r.push(`v-else-if="${y(c.value,!0,!0,e)}"`),o&&r.push("v-else"),a&&r.push(`v-show="${y(a.value,!0,!0,e)}"`),p&&r.push(`v-bind="${y(p.value,!0,!0,e)}"`),l.forEach(f=>{const _=ae(f.modifiers,!0),g=f.arg?N(f.arg)?`:[${y(f.arg,!0,!0,e)}]`:`:${f.arg}`:"";r.push(`v-model${g}${_}="${y(f.value,!0,!0,e)}"`)}),m){const{item:f,index:_}={item:"item",index:"index",...m.iterator};r.push(`v-for="(${f}, ${_}) in ${y(m.value,!0,!0,e)}"`)}return i&&r.push(`v-html="${y(i.value,!0,!0,e)}"`),u&&u.length&&u.forEach(f=>{if(!f.name)return;let _="",g="";N(f.name)?(g=y(f.name,!0,!0,e),s.push(g)):g=f.name;const O=g?.startsWith("v")?b.kebabCase(g):b.kebabCase("v-"+g);if(_+=O,f.arg&&(N(f.arg)?_+=`:[${y(f.name,!0,!0,e)}]`:_+=`:${f.arg}`),f.modifiers){const h=Object.keys(f.modifiers);h.length&&(_+=h.map(v=>"."+v))}f.value?r.push(`${_}="${y(f.value,!0,!0,e)}"`):r.push(_)}),r}function tt(t=[]){const e=t.filter(i=>X.includes(i.name)),s=t.filter(i=>!X.includes(i.name)),r=e.find(i=>b.camelCase(i.name)==="vIf"),n=e.find(i=>b.camelCase(i.name)==="vElseIf"),o=e.find(i=>b.camelCase(i.name)==="vElse"),c=e.find(i=>b.camelCase(i.name)==="vFor"),a=e.find(i=>b.camelCase(i.name)==="vShow"),l=e.find(i=>b.camelCase(i.name)==="vBind"),m=e.find(i=>b.camelCase(i.name)==="vHtml"),p=e.filter(i=>b.camelCase(i.name)==="vModel");return{vIf:r,vElseIf:n,vElse:o,vFor:c,vShow:a,vModels:p,vBind:l,vHtml:m,customDirectives:s}}function st(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function nt(t,e,s,r,n,o=new Set){return typeof t=="string"?st(t):N(t)?`{{ ${y(t,!1,!0,e)} }}`:Array.isArray(t)?z(t,s,e,r,n,o):""}function rt(t,e,s){if(!t)return e;const r=typeof t=="string"?{name:t,params:[],scope:""}:{params:[],scope:"",...t};return`<template ${`#${r.name}="${r.scope?r.scope:r.params?.length>0?`{${r.params?.join(",")}}`:`scope_${s}`}"`}>
|
|
35
35
|
${e}
|
|
36
|
-
</template>`}function
|
|
36
|
+
</template>`}function ot(t,e=[],s=[],r={},n="web",o=new Set){const c=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],a={vue:["defineComponent","reactive"]},l=[];for(const p of e){const i=t.get(p.split(":")[0]);if(i&&i.package){if(o.has(i.package))continue;const u=a[i.package]??(a[i.package]=[]),f=i.parent||(i.alias||"").split(".")[0]||i.name;u.push(f),n==="uniapp"&&c.includes(i.package)&&l.push(f)}}for(const[p,i]of Object.entries(r))(a[p]??(a[p]=[])).push(...Array.from(i)),n==="uniapp"&&c.includes(p)&&l.push(...Array.from(i));return{imports:Object.entries(a).filter(([p,i])=>n==="uniapp"?!c.includes(p)&&!!i.length:!!i.length).map(([p,i])=>`import { ${b.dedupArray(i).join(",")}} from '${p}';`).concat(s),uniComponents:l}}function me(t={}){const e=[];for(const[s,r]of Object.entries(t))e.push(`
|
|
37
37
|
${s} {
|
|
38
|
-
${
|
|
38
|
+
${Le(r)}
|
|
39
39
|
}
|
|
40
40
|
`);return e.join(`
|
|
41
|
-
`)}function
|
|
42
|
-
`+
|
|
43
|
-
`),components:
|
|
44
|
-
`),css:n.css||"",style:
|
|
45
|
-
`),blockPlugins
|
|
46
|
-
`),asyncComponents:
|
|
47
|
-
const mock = __provider.createMock(${
|
|
41
|
+
`)}function de(t={}){const e=[];return Object.entries(t).forEach(([s,r])=>{e.push(`const ${s} = provider.defineUrlSchemaComponent('${r.url}');`)}),e}function he(t={}){const e=[];return Object.entries(t).forEach(([s,r])=>{e.push(`const ${s} = provider.definePluginComponent(${JSON.stringify(r)});`)}),e}function ct(t,e,s="web",r){const{dsl:n}=t,o=Object.keys(n.computed||{}),c=U(n.lifeCycles,o),a=U(n.computed,o),l=We(n.watch,o),m=qe(n.dataSources),{methods:p,nodes:i,components:u,importBlocks:f,directives:_}=z(n.nodes||[],e,o,t.context,void 0,t.easycomPackages),g=[...a,...l.computed],O=U({...p,...n.methods||{}},o),h=f.map(C=>{const $=r?.(C.id)||`./${C.id}.vue`;return`import ${C.name} from '${$}';`});let{imports:v,uniComponents:d}=ot(e,u,h,t.imports,s,t.easycomPackages);const S=Object.keys({...t.urlSchemas,...t.blockPlugins}),j=de(t.urlSchemas),I=he(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:Fe(n.state).join(","),inject:Je(n.inject).join(","),props:ie(n.props).join(","),emits:le(n.emits).join(","),expose:n.expose&&n.expose.length?JSON.stringify(n.expose||[]):"",watch:l.watches.join(","),lifeCycles:c.join(","),computed:g.join(","),methods:[...m,...O].join(","),imports:`
|
|
42
|
+
`+v.join(`
|
|
43
|
+
`),components:De(u,d).join(","),directives:_.join(","),returns:t.members.join(","),template:i.join(`
|
|
44
|
+
`),css:n.css||"",style:me(t.style),urlSchemas:j.join(`
|
|
45
|
+
`),blockPlugins:I.join(`
|
|
46
|
+
`),asyncComponents:S.join(","),uniComponents:d,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer"}}const B={state:{composable:null,from:"self",declare:null,replace:"__state"},$uni:{composable:null,from:"self",declare:null,replace:"uni"},$getApp:{composable:null,from:"self",declare:null,replace:"getApp"},$emit:{composable:null,from:"vue",declare:null,replace:"__emit"},$props:{composable:null,from:"vue",declare:null,replace:"__props"},$attrs:{composable:"useAttrs",from:"vue",declare:"const __attrs = useAttrs();",replace:"__attrs"},$slots:{composable:"useSlots",from:"vue",declare:"const __slots = useSlots();",replace:"__slots"},$nextTick:{composable:"nextTick",from:"vue",declare:null,replace:"nextTick"},$watch:{composable:"watch",from:"vue",declare:null,replace:"watch"},$refs:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$refs"},$el:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$el"},$root:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$root"},$parent:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$parent"},$options:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$options"},$forceUpdate:{composable:"getCurrentInstance",from:"vue",declare:"const __instance = getCurrentInstance();",replace:"__instance.proxy.$forceUpdate"},$router:{composable:"useRouter",from:"vue-router",declare:"const __router = useRouter();",replace:"__router"},$route:{composable:"useRoute",from:"vue-router",declare:"const __route = useRoute();",replace:"__route"},$i18n:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n"},$t:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.t"},$n:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.n"},$d:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.d"},$rt:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.rt"},$te:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.te"},$tm:{composable:"useI18n",from:"vue-i18n",declare:"const __i18n = useI18n();",replace:"__i18n.tm"},$provider:{composable:"useStore",from:"__renderer__",declare:null,replace:"__provider"},$store:{composable:"useStore",from:"__renderer__",declare:"const __store = useStore();",replace:"__store"},$pinia:{composable:"usePinia",from:"__renderer__",declare:"const __pinia = usePinia();",replace:"__pinia"},$request:{composable:"useRequest",from:"__renderer__",declare:"const __request = useRequest();",replace:"__request"},$libs:{composable:"useLibs",from:"__renderer__",declare:"const __libs = useLibs();",replace:"__libs"},$access:{composable:"useAccess",from:"__renderer__",declare:"const __access = useAccess();",replace:"__access"},$apis:{composable:"useApis",from:"__renderer__",declare:"const __apis = useApis();",replace:"__apis"}},Z={"element-plus":{$loading:{composable:"ElLoading",from:"element-plus",declare:null,replace:"ElLoading.service"},$message:{composable:"ElMessage",from:"element-plus",declare:null,replace:"ElMessage"},$notify:{composable:"ElNotification",from:"element-plus",declare:null,replace:"ElNotification"},$messageBox:{composable:"ElMessageBox",from:"element-plus",declare:null,replace:"ElMessageBox"},$msgbox:{composable:"ElMessageBox",from:"element-plus",declare:null,replace:"ElMessageBox"},$confirm:{composable:"ElMessageBox",from:"element-plus",declare:null,replace:"ElMessageBox.confirm"},$prompt:{composable:"ElMessageBox",from:"element-plus",declare:null,replace:"ElMessageBox.prompt"}},"ant-design-vue":{$confirm:{composable:"Modal",from:"ant-design-vue",declare:null,replace:"Modal.confirm"},$message:{composable:"message",from:"ant-design-vue",declare:null,replace:"message"},$notification:{composable:"notification",from:"ant-design-vue",declare:null,replace:"notification"},$info:{composable:"message",from:"ant-design-vue",declare:null,replace:"message.info"},$success:{composable:"message",from:"ant-design-vue",declare:null,replace:"message.success"},$warning:{composable:"message",from:"ant-design-vue",declare:null,replace:"message.warning"},$error:{composable:"message",from:"ant-design-vue",declare:null,replace:"message.error"}}},ge=Object.keys(Z);function ve(t){for(const[,e]of t)if(ge.includes(e.package))return e.package;return null}function $e(t){const e=t?Z[t]??{}:{};return{...B,...e}}function at(t,e=B){const s=new Set,r=/this\.\$(\w+)\b/g,n=o=>{if(o&&typeof o=="object"){if(Array.isArray(o)){for(const c of o)n(c);return}if(k(o)&&o.value){let c;for(r.lastIndex=0;(c=r.exec(o.value))!==null;){const a="$"+c[1];a in e&&s.add(a)}return}for(const c of Object.values(o))n(c)}};return n(t.refs),n(t.reactives),n(t.state),n(t.computed),n(t.methods),n(t.watch),n(t.lifeCycles),n(t.inject),n(t.composables),n(t.provide),n(t.dataSources),n(t.setup),n(t.nodes),s}function it(t,e=B){const s=[];for(const r of t){const n=e[r];n&&n.declare&&!s.includes(n.declare)&&s.push(n.declare)}return s}function lt(t,e=B){const s={};for(const r of t){const n=e[r];if(n&&n.composable){const o=s[n.from]??(s[n.from]=[]);o.includes(n.composable)||o.push(n.composable)}}return s}function ut(t,e=B){const s=new Set(Object.keys(t.refs??{})),r=new Set(Object.keys(t.reactives??{})),o=Object.keys(t.state??{}).length>0;o&&r.add("__state");const c=new Set(Object.keys(t.computed??{})),a=new Set(Object.keys(t.methods??{})),l=new Set;for(const u of t.props??[])b.isString(u)?l.add(u):l.add(u.name);const m=new Set;for(const u of t.composables??[])if(u.destructure&&u.destructure.length>0)for(const f of u.destructure)m.add(f);else u.name&&m.add(u.name);const p=new Set;for(const u of t.inject??[])u.name&&p.add(u.name);const i=new Set;for(const[,u]of Object.entries(t.dataSources??{}))u.name&&i.add(u.name);return{refs:s,reactives:r,computed:c,methods:a,props:l,composables:m,injects:p,dataSources:i,hasState:o,effectiveApiMap:e}}function w(t,e,s="script"){if(!t)return t;let r=t;for(const[n,o]of Object.entries(e.effectiveApiMap)){const c=n.replace(/\$/g,"\\$"),a=new RegExp(`this\\.${c}\\b`,"g");r=r.replace(a,o.replace)}return r=r.replace(/this\.([A-Za-z_$][\w$]*)\.value\b/g,(n,o)=>e.refs.has(o)||e.computed.has(o)?s==="script"?`${o}.value`:o:n),r=r.replace(/this\.([A-Za-z_$][\w$]*)/g,(n,o)=>e.refs.has(o)||e.computed.has(o)?s==="script"?`${o}.value`:o:o==="state"?"__state":e.reactives.has(o)||e.methods.has(o)||e.composables.has(o)||e.injects.has(o)||e.dataSources.has(o)?o:e.props.has(o)?s==="script"?`__props.${o}`:o:n),r}function M(t){let e=t.trim().replace(/;$/,"");return/^\((\(|async|function)/.test(e)&&(e=e.substring(1,e.length-1).trim()),e}function pt(t={},e){return Object.entries(t).map(([s,r])=>{let n;return k(r)?n=w(r.value||"undefined",e,"script"):n=JSON.stringify(r),`const ${s} = ref(${n});`})}function ft(t={},e){return Object.entries(t).map(([s,r])=>{let n;return k(r)?n=w(r.value||"{}",e,"script"):n=JSON.stringify(r??{}),`const ${s} = reactive(${n});`})}function mt(t={},e){const s=Object.entries(t);return s.length===0?"":`const __state = reactive({ ${s.map(([n,o])=>{let c;return k(o)?c=w(o.value||"undefined",e,"script"):c=JSON.stringify(o),`${n}: ${c}`}).join(", ")} });`}function dt(t=[],e){const s=[],r={},n=new Set;for(const o of t){if(!o||!o.composable)continue;let c="";if(k(o.composable)?c=o.composable.value||"":typeof o.composable=="string"&&(c=o.composable),!c||c==="useProvider")continue;if(o.name){if(n.has(o.name))continue;n.add(o.name)}const l=(o.args??[]).map(m=>k(m)?w(m.value||"",e,"script"):JSON.stringify(m)).join(", ");o.destructure&&o.destructure.length>0?s.push(`const { ${o.destructure.join(", ")} } = ${c}(${l});`):o.name?s.push(`const ${o.name} = ${c}(${l});`):s.push(`${c}(${l});`)}return{statements:s,imports:r}}function ht(t=[],e){return t.map(s=>{const r=k(s.from)?w(s.from.value||`'${s.name}'`,e,"script"):`'${s.from||s.name}'`;let n="undefined";return s.default!==void 0&&s.default!==null&&(k(s.default)?n=w(s.default.value||"undefined",e,"script"):n=JSON.stringify(s.default)),`const ${s.name} = inject(${r}, ${n});`})}function gt(t={},e){return Object.entries(t).map(([s,r])=>{if(!r||!r.value)return null;const n=w(r.value,e,"script"),o=M(n);return`const ${s} = computed(${o});`}).filter(s=>!!s)}function vt(t={},e){return Object.entries(t).map(([s,r])=>{if(!r||!r.value)return null;const n=w(r.value,e,"script"),o=M(n);return`const ${s} = ${o};`}).filter(s=>!!s)}function $t(t={},e){return Object.values(t).map(s=>{if(!s||!s.name)return null;if(s.type==="mock"){const r=s.mockTemplate&&s.mockTemplate.value?s.mockTemplate.value:"(params) => ({})",n=e?w(r,e,"script"):r;return`const ${s.name} = async (...args) => {
|
|
47
|
+
const mock = __provider.createMock(${n});
|
|
48
48
|
return await mock.apply(null, args);
|
|
49
|
-
};`}else{const
|
|
50
|
-
return await __provider.apis['${s.ref}'].apply(null, args).then(${
|
|
51
|
-
};`}}).filter(s=>!!s)}function
|
|
52
|
-
${
|
|
53
|
-
`)}const
|
|
54
|
-
|
|
55
|
-
`),props:
|
|
56
|
-
`),injects
|
|
57
|
-
`),composables
|
|
58
|
-
`),state:
|
|
59
|
-
`),reactives:
|
|
60
|
-
`),computed:
|
|
61
|
-
`),methods:
|
|
62
|
-
`),dataSources:
|
|
63
|
-
`),watch:
|
|
64
|
-
`),provide:
|
|
65
|
-
`),createdStatements:
|
|
66
|
-
`),template:
|
|
67
|
-
`),css:n.css||"",style:
|
|
68
|
-
`),blockPlugins:
|
|
69
|
-
`),uniComponents:
|
|
70
|
-
`)}}const
|
|
49
|
+
};`}else{const r=s.transform&&s.transform.value?s.transform.value:"(res) => res",n=e?w(r,e,"script"):r;return`const ${s.name} = async (...args) => {
|
|
50
|
+
return await __provider.apis['${s.ref}'].apply(null, args).then(${n});
|
|
51
|
+
};`}}).filter(s=>!!s)}function bt(t=[],e){return t.map(s=>{if(!s||!s.handler||!s.handler.value)return null;const r=s.source&&s.source.value?w(s.source.value,e,"script"):"() => null",n=M(r),o=w(s.handler.value,e,"script"),c=M(o),a=[];s.deep&&a.push("deep: true"),s.immediate&&a.push("immediate: true"),s.flush&&a.push(`flush: '${s.flush}'`);const l=a.length>0?`, { ${a.join(", ")} }`:"";return`watch(${n}, ${c}${l});`}).filter(s=>!!s)}function _t(t={},e){return Object.entries(t).map(([s,r])=>{let n;if(R(r)){const o=w(r.value||"",e,"script");n=M(o)}else k(r)?n=w(r.value||"undefined",e,"script"):n=JSON.stringify(r);return`provide('${s}', ${n});`})}function be(t){let e=t.trim().replace(/;$/,"");/^\((\(|async|function)/.test(e)&&(e=e.substring(1,e.length-1).trim());const s=e.match(/^(?:async\s+)?\([^)]*\)\s*=>\s*([\s\S]+)$/);if(s){let n=s[1].trim();return n.startsWith("{")&&n.endsWith("}")?n=n.slice(1,-1).trim():n=n.replace(/;$/,"")+";",n}const r=e.match(/^(?:async\s+)?function\s*\w*\s*\([^)]*\)\s*\{([\s\S]*)\}$/);return r?r[1].trim():e}function yt(t,e){if(!t||!t.value)return"";const s=w(t.value,e,"script");return be(s)}function St(t={},e){const s=[];for(const r of["beforeCreate","created"]){const n=t[r];if(n&&n.value){const o=w(n.value,e,"script"),c=be(o);c&&s.push(`// ${r}
|
|
52
|
+
${c}`)}}return s.join(`
|
|
53
|
+
`)}const jt={beforeMount:"onBeforeMount",mounted:"onMounted",beforeUpdate:"onBeforeUpdate",updated:"onUpdated",beforeUnmount:"onBeforeUnmount",unmounted:"onUnmounted",errorCaptured:"onErrorCaptured",renderTracked:"onRenderTracked",renderTriggered:"onRenderTriggered",activated:"onActivated",deactivated:"onDeactivated"},kt=new Set(["onBeforeMount","onMounted","onBeforeUpdate","onUpdated","onBeforeUnmount","onUnmounted","onErrorCaptured","onRenderTracked","onRenderTriggered","onActivated","onDeactivated"]),wt=new Set(["onLoad","onShow","onReady","onHide","onUnload","onResize","onPullDownRefresh","onReachBottom","onTabItemTap","onShareAppMessage","onPageScroll","onNavigationBarButtonTap","onBackPress","onNavigationBarSearchInputChanged","onNavigationBarSearchInputConfirmed","onNavigationBarSearchInputClicked","onShareTimeline","onAddToFavorites"]);function It(t={},e){const s=[],r=new Set,n=new Set;for(const[o,c]of Object.entries(t)){if(!c||!c.value||o==="created"||o==="beforeCreate")continue;const a=jt[o]||o;if(kt.has(a)){const l=w(c.value,e,"script"),m=M(l);s.push(`${a}(${m});`),r.add(a)}else if(wt.has(a)){const l=w(c.value,e,"script"),m=M(l);s.push(`${a}(${m});`),n.add(a)}}return{statements:s,usedHooks:r,usedUniHooks:n}}function Ct(t){const{componentMap:e,components:s,importBlocks:r,collectImports:n,platform:o,vueImports:c,composableImports:a,globalApiImports:l,uniHookImports:m,easycomPackages:p}=t,i=["@dcloudio/uni-h5","uni-h5","@dcloudio/uni-ui","uni-ui"],u={vue:[...c]},f=[],_=[],g={};for(const h of s){const v=h.split(":")[0],d=e.get(v);if(!d||!d.package||d.parent||p.has(d.package))continue;const S=u[d.package]??(u[d.package]=[]),j=(d.alias||"").split(".")[0]||d.name,I=v,C=j!==I?`${j} as ${I}`:j;S.push(C),g[j]=I,o==="uniapp"&&i.includes(d.package)&&f.push(j)}for(const h of s){const v=h.split(":")[0],d=e.get(v);if(!d||!d.package||!d.parent||p.has(d.package))continue;const S=d.parent,j=g[S]??S,I=d.alias||"";_.push(`const ${v} = ${j}.${I};`),g[S]||((u[d.package]??(u[d.package]=[])).push(S),g[S]=S)}for(const[h,v]of Object.entries(n))(u[h]??(u[h]=[])).push(...Array.from(v)),o==="uniapp"&&i.includes(h)&&f.push(...Array.from(v));for(const[h,v]of Object.entries(a))(u[h]??(u[h]=[])).push(...v);for(const[h,v]of Object.entries(l))(u[h]??(u[h]=[])).push(...v);return o==="uniapp"&&m.length>0&&(u["@dcloudio/uni-app"]??(u["@dcloudio/uni-app"]=[])).push(...m),{imports:Object.entries(u).filter(([h,v])=>o==="uniapp"?!i.includes(h)&&!!v.length:!!v.length).map(([h,v])=>`import { ${b.dedupArray(v).join(",")}} from '${h}';`).concat(r),uniComponents:f,componentDeclarations:_}}function At(t,e=B,s=new Set,r=new Set){const n=Object.entries(e),o=c=>{if(c==null||typeof c!="object")return c;if(Array.isArray(c))return c.map(o);if(k(c)&&typeof c.value=="string"){let l=c.value;for(const[m,p]of n){const i=m.replace(/\$/g,"\\$"),u=new RegExp(`this\\.${i}\\b`,"g");l=l.replace(u,p.replace)}return l=l.replace(/this\.([A-Za-z_$][\w$]*)\.value\b/g,(m,p)=>s.has(p)||r.has(p)?p:m),{...c,value:l}}const a={};for(const[l,m]of Object.entries(c))a[l]=o(m);return a};return t.map(o)}function Ot(t,e,s=[],r={},n,o=B,c=new Set,a=new Set,l=new Set){const m=At(t,o,c,a);return z(m,e,s,r,n,l)}function Pt(t,e,s="web",r){const{dsl:n}=t,o=ve(e),c=$e(o),a=ut(n,c),l=at(n,c),m=it(l,c),p=lt(l,c),i=p.__renderer__||[];delete p.__renderer__;const u=Ot(n.nodes||[],e,Object.keys(n.computed||{}),t.context,void 0,c,a.refs,a.computed,t.easycomPackages),f=u.importBlocks.map(A=>`import ${A.name} from '${r?.(A.id)||`./${A.id}.vue`}';`),_=pt(n.refs||{},a),g=ft(n.reactives||{},a),O=mt(n.state||{},a),h=gt(n.computed||{},a),v={...u.methods||{},...n.methods||{}},d=vt(v,a),S=$t(n.dataSources||{},a),j=bt(n.watch||[],a),I=ht(n.inject||[],a),C=_t(n.provide||{},a),$=dt(n.composables||[],a),P=new Set;for(const A of n.composables||[])if(A.destructure&&A.destructure.length>0)for(const D of A.destructure)P.add(D);else A.name&&P.add(A.name);const L=m.filter(A=>{const D=A.match(/^const\s+(\w+)\s*=/);return!(D&&P.has(D[1]))}),x=It(n.lifeCycles||{},a),_e=St(n.lifeCycles||{},a),ye=yt(n.setup,a),E=new Set;_.length>0&&E.add("ref"),(g.length>0||O)&&E.add("reactive"),h.length>0&&E.add("computed"),j.length>0&&E.add("watch"),I.length>0&&E.add("inject"),C.length>0&&E.add("provide");for(const A of x.usedHooks)E.add(A);const Se=s==="uniapp"?Array.from(x.usedUniHooks):[],{imports:je,uniComponents:ke,componentDeclarations:we}=Ct({componentMap:e,components:u.components,importBlocks:f,collectImports:t.imports,platform:s,vueImports:Array.from(E),composableImports:$.imports,globalApiImports:p,uniHookImports:Se,easycomPackages:t.easycomPackages}),Ie=de(t.urlSchemas),Ce=he(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,imports:`
|
|
54
|
+
`+je.join(`
|
|
55
|
+
`),props:ie(n.props).join(","),emits:le(n.emits).join(","),needsProps:l.has("$props"),needsEmit:l.has("$emit"),expose:n.expose&&n.expose.length?`{ ${n.expose.join(", ")} }`:"",globalApiDeclares:L.join(`
|
|
56
|
+
`),injects:I.join(`
|
|
57
|
+
`),composables:$.statements.join(`
|
|
58
|
+
`),state:O,refs:_.join(`
|
|
59
|
+
`),reactives:g.join(`
|
|
60
|
+
`),computed:h.join(`
|
|
61
|
+
`),methods:d.join(`
|
|
62
|
+
`),dataSources:S.join(`
|
|
63
|
+
`),watch:j.join(`
|
|
64
|
+
`),provide:C.join(`
|
|
65
|
+
`),createdStatements:_e,setupStatements:ye,lifeCycles:x.statements.join(`
|
|
66
|
+
`),template:u.nodes.join(`
|
|
67
|
+
`),css:n.css||"",style:me(t.style),urlSchemas:Ie.join(`
|
|
68
|
+
`),blockPlugins:Ce.join(`
|
|
69
|
+
`),uniComponents:ke,renderer:s==="uniapp"?"@vtj/uni-app":"@vtj/renderer",rendererImports:["useProvider",...i].join(", "),componentDeclarations:we.join(`
|
|
70
|
+
`)}}const xt=`
|
|
71
71
|
// @ts-nocheck
|
|
72
72
|
import { useProvider } from '<%= renderer %>';
|
|
73
73
|
<%= imports %>
|
|
@@ -99,7 +99,7 @@ export default defineComponent({
|
|
|
99
99
|
<% if(methods) { %> methods: { <%= methods %> }, <% } %>
|
|
100
100
|
<% if(watch) { %> watch: { <%= watch %> }, <% } %> <%= lifeCycles %>
|
|
101
101
|
});
|
|
102
|
-
`,
|
|
102
|
+
`,Et=`
|
|
103
103
|
<template>
|
|
104
104
|
<%= template %>
|
|
105
105
|
</template>
|
|
@@ -110,7 +110,7 @@ export default defineComponent({
|
|
|
110
110
|
<%= css %>
|
|
111
111
|
<%= style %>
|
|
112
112
|
</style>
|
|
113
|
-
`,
|
|
113
|
+
`,Bt=`// @ts-nocheck
|
|
114
114
|
import { <%= rendererImports %> } from '<%= renderer %>';<%= imports %>
|
|
115
115
|
<% if(componentDeclarations) { %><%= componentDeclarations %><% } %>
|
|
116
116
|
<% if(props) { %>const __props = defineProps({ <%= props %> });<% } else if(needsProps) { %>const __props = defineProps();<% } %>
|
|
@@ -133,21 +133,21 @@ const __provider = useProvider({ id: '<%= id %>', version: '<%= version %>' });
|
|
|
133
133
|
<%= provide %>
|
|
134
134
|
<%= lifeCycles %>
|
|
135
135
|
<% if(expose) { %>defineExpose(<%= expose %>);<% } %>
|
|
136
|
-
`,
|
|
136
|
+
`,Mt=b.template(xt),Nt=b.template(Bt),Tt=b.template(Et);async function Rt(t,e=new Map,s=[],r="web",n){const o=t,c=typeof o.dsl=="object"&&arguments.length===1?o:{dsl:t,componentMap:e,dependencies:s,platform:r,formatterDisabled:n},{dsl:a,componentMap:l=new Map,dependencies:m=[],platform:p="web",formatterDisabled:i=!1,ts:u=!0,scss:f=!1,project:_}=c,g=_?Te(_):null,O=g?$=>{const P=g.byId.get($);return P?.type==="block"?se(P):`./${$}.vue`}:void 0,h=new Ue(b.cloneDeep(a),m),v=a.apiMode==="composition";let d,S,j,I;if(v){const $=Pt(h,l,p,O);I=Nt($),d=$.template||`
|
|
137
137
|
<!--组件模版内容-->
|
|
138
|
-
`,
|
|
138
|
+
`,S=$.css,j=$.style}else{const $=ct(h,l,p,O);I=Mt($),d=$.template||`
|
|
139
139
|
<!--组件模版内容-->
|
|
140
|
-
`,
|
|
140
|
+
`,S=$.css,j=$.style}const C=Tt({template:d,css:await W(S,i)||`
|
|
141
141
|
/* 组件样式内容 */
|
|
142
|
-
`,script:await
|
|
142
|
+
`,script:await re(I,i),style:await W(j,i),scriptLang:u?"ts":"js",styleLang:f?"scss":"css",scriptSetup:v});return await V(C,i).catch($=>($.content=C,Promise.reject($)))}async function Lt(t,e="web"){const s=`
|
|
143
143
|
<template>
|
|
144
144
|
<div>
|
|
145
145
|
<h3>源码模式页面</h3>
|
|
146
|
-
<div
|
|
146
|
+
<div>文件路径:/${J(t,e)}</div>
|
|
147
147
|
</div>
|
|
148
148
|
</template>
|
|
149
149
|
<script lang="ts" setup>
|
|
150
150
|
<\/script>
|
|
151
151
|
<style scoped lang="scss">
|
|
152
152
|
</style>
|
|
153
|
-
`;return await
|
|
153
|
+
`;return await V(s)}exports.GLOBAL_API_MAP=B;exports.UI_GLOBAL_API_MAPS=Z;exports.UI_PACKAGES=ge;exports.VTJ_CODER_VERSION=Be;exports.buildEffectiveApiMap=$e;exports.createEmptyPage=Lt;exports.cssFormatter=W;exports.detectUIPackage=ve;exports.generator=Rt;exports.tsFormatter=re;exports.vueFormatter=V;
|