@vtj/coder 0.8.99 → 0.8.101

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,42 +1,42 @@
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),J=k(X),T=k(Y),q=k(Z);/**!
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);/**!
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.8.99
5
+ * @version 0.8.101
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
- */const ee="0.8.99";/**!
7
+ */const ee="0.8.101";/**!
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.8.99
11
+ * @version 0.8.101
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 L(t,e){return e?t:await x.format(t,{parser:"vue",..._,plugins:[K,J,q,T]})}async function ne(t,e){return e?t:await x.format(t,{parser:"babel-ts",..._,plugins:[J,q]})}async function W(t,e){return e?t:x.format(t,{parser:"scss",..._,plugins:[T]})}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 F(t){return t.replace(new RegExp("this.","g"),"")}function I(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=b(i,r),n?F(I(i)):I(i)}function b(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 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}: {
14
14
  from: '${e.from||e.name}',
15
15
  default: ${u(e.default,!0,!1)}
16
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
17
  type:${e(n.type)},
18
18
  required: ${u(!!n.required,!0,!1)},
19
19
  default: ${u(n.default,!0,!1)}
20
- }`))}function le(t=[]){return t.map(e=>`'${typeof e=="string"?e:e.name}'`)}function w(t={},e=[]){return Object.entries(t).map(([n,r])=>{let i=U(u(r,!1,!1));return i=b(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=w(n,e),i=t.map(s=>`watcher_${s.id}: {
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
21
  deep: ${s.deep},
22
22
  immediate:${s.immediate},
23
23
  handler${U(s.handler.value)}
24
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
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(m=>{const j=[];for(const p of m.children){let{id:O,name:h,invisible:C,from:d}=p;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:N,handlers:G}=$e(p,O,p.props,p.events,r,n),B=be(p.directives,n).join(" "),y=p.children?ve(p.children,n,e,r,p):"";Object.assign(o,G);let S="";typeof y=="string"?S=y:(S=(y?.nodes||[]).join(`
27
- `),Object.assign(o,y?.methods||{}),a=a.concat(y?.components||[]),c=c.concat(y?.importBlocks||[]));const R=z(d)||Q(d)?"component":h;j.push(h==="img"?`<${h} ${B} ${g} ${N} />`:`<${R} ${B} ${g} ${N}>${S?`
28
- `+S.trim():""}</${R}>`)}const P=Se(m.slot,j.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 z(t){return typeof t=="object"&&t.type==="UrlSchema"}function Q(t){return typeof t=="object"&&t.type==="Plugin"}function he(t,e,n=[]){return t==="style"?"":t==="__class"&&$(e)?`:class="${u({...e,value:b(e.value,n)})}"`:typeof e=="string"?`${t}="${e}"`:$(e)?`:${t}="${u({...e,value:b(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(z(i)||Q(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 f=c.handler.value.startsWith("this."),m=f?F(c.handler.value):`${l.camelCase(a)}_${t}${s}`;return f||(r[m]=i.length?{type:"JSFunction",value:`{
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=z(d)||Q(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 z(t){return typeof t=="object"&&t.type==="UrlSchema"}function Q(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(z(i)||Q(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
30
  return (${c.handler.value}).apply(this, args);
31
- }`}:c.handler),ye(a,c,m,i,f)}),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}=je(t);if(r&&n.push(`v-if="${u(r.value,!0,!0,e)}"`),i&&n.push(`v-show="${u(i.value,!0,!0,e)}"`),s.forEach(a=>{const c=V(a.modifiers,!0),f=a.arg?E(a.arg)?`:[${u(a.arg,!0,!0,e)}]`:`:${a.arg}`:"";n.push(`v-model${f}${c}="${u(a.value,!0,!0,e)}"`)}),o){const{item:a,index:c}={item:"item",index:"index",...o.iterator};n.push(`v-for="(${a}, ${c}) in ${u(o.value,!0,!0,e)}"`)}return n}function je(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 ve(t,e,n,r,i){if(typeof t=="string")return t;if(E(t)){let s=u(t,!1);return s=b(s,e),s=F(s),`{{ ${s} }}`}return 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}`}"`}>
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}`}"`}>
32
32
  ${e}
33
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
34
  ${n} {
35
35
  ${se(r)}
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=w(n.lifeCycles,r),s=w(n.computed,r),o=ue(n.watch,r),a=pe(n.dataSources),{methods:c,nodes:f,components:m,importBlocks:j}=M(n.nodes||[],e,r,t.context),P=[...s,...o.computed],p=w({...c,...n.methods||{}},r),O=j.map(g=>`import ${g.name} from './${g.id}.vue';`),h=we(e,m,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,...p].join(","),imports:h.join(`
39
- `),components:m.join(","),returns:t.members.join(","),template:f.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:h.join(`
39
+ `),components:f.join(","),returns:t.members.join(","),template:p.join(`
40
40
  `),css:n.css||"",style:ke(t.style),urlSchemas:d.join(`
41
41
  `),blockPlugins:v.join(`
42
42
  `),asyncComponents:C.join(",")}}const xe=`
@@ -79,7 +79,7 @@ export default defineComponent({
79
79
  <%= css %>
80
80
  <%= style %>
81
81
  </style>
82
- `,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 W(s.css,r),script:await ne(o,r),style:await W(s.style,r)});return await L(a,r).catch(c=>(c.content=a,c))}async function Ne(t){const e=`
82
+ `,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,c))}async function Ne(t){const e=`
83
83
  <template>
84
84
  <div>
85
85
  <h3>源码模式页面</h3>
@@ -90,4 +90,4 @@ export default defineComponent({
90
90
  <\/script>
91
91
  <style scoped lang="scss">
92
92
  </style>
93
- `;return await L(e)}exports.VTJ_CODER_VERSION=ee;exports.createEmptyPage=Ne;exports.generator=Fe;
93
+ `;return await q(e)}exports.VTJ_CODER_VERSION=ee;exports.createEmptyPage=Ne;exports.generator=Fe;
package/dist/index.mjs CHANGED
@@ -1,22 +1,22 @@
1
- import { mitt as X, dedupArray as k, toArray as Y, camelCase as y, isPlainObject as Z, template as J, cloneDeep as K } from "@vtj/base";
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
2
  import { format as C } from "prettier/standalone";
3
3
  import * as tt from "prettier/plugins/html";
4
- import * as L from "prettier/plugins/babel";
5
- import * as T from "prettier/plugins/postcss";
6
- import * as U from "prettier/plugins/estree";
4
+ import * as J from "prettier/plugins/babel";
5
+ import * as L from "prettier/plugins/postcss";
6
+ import * as T from "prettier/plugins/estree";
7
7
  /**!
8
8
  * Copyright (c) 2024, VTJ.PRO All rights reserved.
9
9
  * @name @vtj/coder
10
10
  * @author CHC chenhuachun1549@dingtalk.com
11
- * @version 0.8.99
11
+ * @version 0.8.101
12
12
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
13
13
  */
14
- const Bt = "0.8.99";
14
+ const Bt = "0.8.101";
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.8.99
19
+ * @version 0.8.101
20
20
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
21
21
  */
22
22
  const et = [
@@ -53,25 +53,25 @@ const E = {
53
53
  useTabs: !1,
54
54
  vueIndentScriptAndStyle: !0
55
55
  };
56
- async function V(e, t) {
56
+ async function U(e, t) {
57
57
  return t ? e : await C(e, {
58
58
  parser: "vue",
59
59
  ...E,
60
- plugins: [tt, L, U, T]
60
+ plugins: [tt, J, T, L]
61
61
  });
62
62
  }
63
63
  async function nt(e, t) {
64
64
  return t ? e : await C(e, {
65
65
  parser: "babel-ts",
66
66
  ...E,
67
- plugins: [L, U]
67
+ plugins: [J, T]
68
68
  });
69
69
  }
70
- async function W(e, t) {
70
+ async function R(e, t) {
71
71
  return t ? e : C(e, {
72
72
  parser: "scss",
73
73
  ...E,
74
- plugins: [T]
74
+ plugins: [L]
75
75
  });
76
76
  }
77
77
  function _(e) {
@@ -83,17 +83,17 @@ function A(e) {
83
83
  function $(e) {
84
84
  return _(e) || A(e);
85
85
  }
86
- function F(e) {
86
+ function V(e) {
87
87
  return e.replace(new RegExp("this.", "g"), "");
88
88
  }
89
- function I(e) {
89
+ function W(e) {
90
90
  return e.replace(/this\.context\??\./g, "");
91
91
  }
92
92
  function l(e, t = !0, n = !0, s = []) {
93
93
  let i = $(e) ? e.value : t ? JSON.stringify(e) : e;
94
- return i = v(i, s), n ? F(I(i)) : I(i);
94
+ return i = k(i, s), n ? V(W(i)) : W(i);
95
95
  }
96
- function v(e, t = []) {
96
+ function k(e, t = []) {
97
97
  let n = e;
98
98
  for (const s of t)
99
99
  n = n.replace(
@@ -205,7 +205,7 @@ class it {
205
205
  let n = [...t];
206
206
  for (const s of Object.values(this.imports))
207
207
  n = n.concat(Array.from(s));
208
- return k(n);
208
+ return w(n);
209
209
  }
210
210
  collectContext(t, n) {
211
211
  const s = new Set(n?.id ? this.context[n.id] : []), i = (t.directives || []).find((c) => c.name === "vFor");
@@ -260,17 +260,17 @@ function at(e = []) {
260
260
  function lt(e = []) {
261
261
  return e.map((t) => `'${typeof t == "string" ? t : t.name}'`);
262
262
  }
263
- function w(e = {}, t = []) {
263
+ function S(e = {}, t = []) {
264
264
  return Object.entries(e).map(([n, s]) => {
265
265
  let i = q(l(s, !1, !1));
266
- return i = v(i, t), i.startsWith("async") ? `async ${n}${i.replace(/^async/, "")}` : `${n}${i}`;
266
+ return i = k(i, t), i.startsWith("async") ? `async ${n}${i.replace(/^async/, "")}` : `${n}${i}`;
267
267
  });
268
268
  }
269
269
  function ut(e = [], t = []) {
270
270
  const n = e.reduce(
271
271
  (r, o) => (o.id && A(o.source) && (r[`watcher_${o.id}`] = o.source), r),
272
272
  {}
273
- ), s = w(n, t), i = e.map((r) => `watcher_${r.id}: {
273
+ ), s = S(n, t), i = e.map((r) => `watcher_${r.id}: {
274
274
  deep: ${r.deep},
275
275
  immediate:${r.immediate},
276
276
  handler${q(r.handler.value)}
@@ -291,48 +291,48 @@ function pt(e = {}) {
291
291
  function D(e, t, n = [], s = {}, i) {
292
292
  const r = [];
293
293
  let o = {}, c = [], a = [];
294
- return ft(e).forEach((f) => {
295
- const b = [];
296
- for (const u of f.children) {
297
- let { id: x, name: m, invisible: O, from: h } = u;
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
298
  if (O)
299
299
  continue;
300
- const j = mt(m, t, h);
301
- j && c.push(j), Q(h) && a.push({ id: h.id, name: m });
302
- const { props: g, events: N, handlers: H } = $t(
303
- u,
300
+ const b = mt(m, t, h);
301
+ b && c.push(b), Q(h) && a.push({ id: h.id, name: m });
302
+ const { props: g, events: F, handlers: H } = $t(
303
+ f,
304
304
  x,
305
- u.props,
306
- u.events,
305
+ f.props,
306
+ f.events,
307
307
  s,
308
308
  n
309
- ), B = vt(u.directives, n).join(
309
+ ), N = vt(f.directives, n).join(
310
310
  " "
311
- ), d = u.children ? jt(
312
- u.children,
311
+ ), d = f.children ? jt(
312
+ f.children,
313
313
  n,
314
314
  t,
315
315
  s,
316
- u
316
+ f
317
317
  ) : "";
318
318
  Object.assign(o, H);
319
- let S = "";
320
- typeof d == "string" ? S = d : (S = (d?.nodes || []).join(`
319
+ let j = "";
320
+ typeof d == "string" ? j = d : (j = (d?.nodes || []).join(`
321
321
  `), Object.assign(o, d?.methods || {}), c = c.concat(d?.components || []), a = a.concat(d?.importBlocks || []));
322
- const R = z(h) || G(h) ? "component" : m;
323
- b.push(
324
- m === "img" ? `<${m} ${B} ${g} ${N} />` : `<${R} ${B} ${g} ${N}>${S ? `
325
- ` + S.trim() : ""}</${R}>`
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}>`
326
326
  );
327
327
  }
328
- const P = St(f.slot, b.join(`
328
+ const P = St(p.slot, v.join(`
329
329
  `), i?.id);
330
330
  r.push(P);
331
331
  }), {
332
332
  nodes: r,
333
333
  methods: o,
334
- components: k(c),
335
- importBlocks: k(a, "id")
334
+ components: w(c),
335
+ importBlocks: w(a, "id")
336
336
  };
337
337
  }
338
338
  function ft(e = []) {
@@ -364,10 +364,10 @@ function G(e) {
364
364
  function ht(e, t, n = []) {
365
365
  return e === "style" ? "" : e === "__class" && $(t) ? `:class="${l({
366
366
  ...t,
367
- value: v(t.value, n)
367
+ value: k(t.value, n)
368
368
  })}"` : typeof t == "string" ? `${e}="${t}"` : $(t) ? `:${e}="${l({
369
369
  ...t,
370
- value: v(t.value, n)
370
+ value: k(t.value, n)
371
371
  })}"` : Z(t) ? `:${e}='{${st(
372
372
  t
373
373
  ).join(", ")}}'` : `:${e}='${JSON.stringify(t)}'`;
@@ -391,13 +391,13 @@ function gt(e, t = {}, n = {}) {
391
391
  const s = {}, i = Array.from(n[e] || /* @__PURE__ */ new Set([])), r = i.length ? `({${i.join(", ")}}, args)` : "";
392
392
  return {
393
393
  binders: Object.entries(t).map(([c, a]) => {
394
- const p = a.handler.value.startsWith("this."), f = p ? F(a.handler.value) : `${y(c)}_${e}${r}`;
395
- return p || (s[f] = i.length ? {
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 ? {
396
396
  type: "JSFunction",
397
397
  value: `{
398
398
  return (${a.handler.value}).apply(this, args);
399
399
  }`
400
- } : a.handler), yt(c, a, f, i, p);
400
+ } : a.handler), yt(c, a, p, i, u);
401
401
  }),
402
402
  handlers: s
403
403
  };
@@ -412,18 +412,20 @@ function $t(e, t, n = {}, s = {}, i = {}, r) {
412
412
  };
413
413
  }
414
414
  function vt(e = [], t = []) {
415
- const n = [], { vIf: s, vShow: i, vModels: r, vFor: o } = bt(e);
415
+ const n = [], { vIf: s, vShow: i, vModels: r, vFor: o, vBind: c } = bt(e);
416
416
  if (s && n.push(`v-if="${l(s.value, !0, !0, t)}"`), i && n.push(
417
417
  `v-show="${l(i.value, !0, !0, t)}"`
418
- ), r.forEach((c) => {
419
- const a = M(c.modifiers, !0), p = c.arg ? _(c.arg) ? `:[${l(c.arg, !0, !0, t)}]` : `:${c.arg}` : "";
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}` : "";
420
422
  n.push(
421
- `v-model${p}${a}="${l(c.value, !0, !0, t)}"`
423
+ `v-model${p}${u}="${l(a.value, !0, !0, t)}"`
422
424
  );
423
425
  }), o) {
424
- const { item: c, index: a } = { item: "item", index: "index", ...o.iterator };
426
+ const { item: a, index: u } = { item: "item", index: "index", ...o.iterator };
425
427
  n.push(
426
- `v-for="(${c}, ${a}) in ${l(o.value, !0, !0, t)}"`
428
+ `v-for="(${a}, ${u}) in ${l(o.value, !0, !0, t)}"`
427
429
  );
428
430
  }
429
431
  return n;
@@ -439,13 +441,7 @@ function bt(e = []) {
439
441
  };
440
442
  }
441
443
  function jt(e, t, n, s, i) {
442
- if (typeof e == "string")
443
- return e;
444
- if (_(e)) {
445
- let r = l(e, !1);
446
- return r = v(r, t), r = F(r), `{{ ${r} }}`;
447
- }
448
- return Array.isArray(e) ? D(e, n, t, s, i) : "";
444
+ return typeof e == "string" ? e : _(e) ? `{{ ${l(e, !1, !0, t)} }}` : Array.isArray(e) ? D(e, n, t, s, i) : "";
449
445
  }
450
446
  function St(e, t, n) {
451
447
  if (!e) return t;
@@ -464,7 +460,7 @@ function wt(e, t = [], n = [], s = {}) {
464
460
  }
465
461
  for (const [r, o] of Object.entries(s))
466
462
  (i[r] ?? (i[r] = [])).push(...Array.from(o));
467
- return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${k(o).join(
463
+ return Object.entries(i).filter(([r, o]) => !!o.length).map(([r, o]) => `import { ${w(o).join(
468
464
  ","
469
465
  )}} from '${r}';`).concat(n);
470
466
  }
@@ -496,26 +492,26 @@ function xt(e = {}) {
496
492
  }), t;
497
493
  }
498
494
  function Ot(e, t) {
499
- const { dsl: n } = e, s = Object.keys(n.computed || {}), i = w(n.lifeCycles, s), r = w(n.computed, s), o = ut(n.watch, s), c = pt(n.dataSources), { methods: a, nodes: p, components: f, importBlocks: b } = D(
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 } = D(
500
496
  n.nodes || [],
501
497
  t,
502
498
  s,
503
499
  e.context
504
- ), P = [...r, ...o.computed], u = w(
500
+ ), P = [...r, ...o.computed], f = S(
505
501
  {
506
502
  ...a,
507
503
  ...n.methods || {}
508
504
  },
509
505
  s
510
- ), x = b.map((g) => `import ${g.name} from './${g.id}.vue';`), m = wt(
506
+ ), x = v.map((g) => `import ${g.name} from './${g.id}.vue';`), m = wt(
511
507
  t,
512
- f,
508
+ p,
513
509
  x,
514
510
  e.imports
515
511
  ), O = Object.keys({
516
512
  ...e.urlSchemas,
517
513
  ...e.blockPlugins
518
- }), h = Pt(e.urlSchemas), j = xt(e.blockPlugins);
514
+ }), h = Pt(e.urlSchemas), b = xt(e.blockPlugins);
519
515
  return {
520
516
  id: n.id,
521
517
  version: n.__VERSION__,
@@ -527,18 +523,18 @@ function Ot(e, t) {
527
523
  watch: o.watches.join(","),
528
524
  lifeCycles: i.join(","),
529
525
  computed: P.join(","),
530
- methods: [...c, ...u].join(","),
526
+ methods: [...c, ...f].join(","),
531
527
  imports: m.join(`
532
528
  `),
533
- components: f.join(","),
529
+ components: p.join(","),
534
530
  returns: e.members.join(","),
535
- template: p.join(`
531
+ template: u.join(`
536
532
  `),
537
533
  css: n.css || "",
538
534
  style: kt(e.style),
539
535
  urlSchemas: h.join(`
540
536
  `),
541
- blockPlugins: j.join(`
537
+ blockPlugins: b.join(`
542
538
  `),
543
539
  asyncComponents: O.join(",")
544
540
  };
@@ -583,15 +579,15 @@ export default defineComponent({
583
579
  <%= css %>
584
580
  <%= style %>
585
581
  </style>
586
- `, _t = J(Ct), At = J(Et);
582
+ `, _t = I(Ct), At = I(Et);
587
583
  async function Rt(e, t = /* @__PURE__ */ new Map(), n = [], s) {
588
584
  const i = new it(K(e), n), r = Ot(i, t), o = _t(r), c = At({
589
585
  template: r.template,
590
- css: await W(r.css, s),
586
+ css: await R(r.css, s),
591
587
  script: await nt(o, s),
592
- style: await W(r.style, s)
588
+ style: await R(r.style, s)
593
589
  });
594
- return await V(c, s).catch((a) => (a.content = c, a));
590
+ return await U(c, s).catch((a) => (a.content = c, a));
595
591
  }
596
592
  async function Wt(e) {
597
593
  const t = `
@@ -606,7 +602,7 @@ async function Wt(e) {
606
602
  <style scoped lang="scss">
607
603
  </style>
608
604
  `;
609
- return await V(t);
605
+ return await U(t);
610
606
  }
611
607
  export {
612
608
  Bt as VTJ_CODER_VERSION,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@vtj/coder",
3
3
  "private": false,
4
- "version": "0.8.99",
4
+ "version": "0.8.101",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "prettier": "~3.3.0",
8
- "@vtj/base": "~0.8.10",
9
- "@vtj/core": "~0.8.99"
8
+ "@vtj/core": "~0.8.101",
9
+ "@vtj/base": "~0.8.10"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@vtj/cli": "~0.8.24"
@@ -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.8.98
5
+ * @version 0.8.100
6
6
  * @license <a href="https://vtj.pro/license.html">MIT License</a>
7
7
  */
8
- export declare const version = "0.8.98";
8
+ export declare const version = "0.8.100";