@vtj/coder 0.9.1 → 0.9.2

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