@vtj/coder 0.8.12 → 0.8.13
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 +8 -8
- package/dist/index.mjs +3 -3
- package/package.json +3 -3
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
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.
|
|
5
|
+
* @version 0.8.13
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const ee="0.8.
|
|
7
|
+
*/const ee="0.8.13";/**!
|
|
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.
|
|
11
|
+
* @version 0.8.13
|
|
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){const s=$(t)?t.value:e?JSON.stringify(t):t;return n?F(I(s)):I(s)}function w(t,e=[]){let n=t;for(const s of e)n=n.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);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]+)/,r=e.match(i);r&&r[2]&&(r[2].startsWith("{")||(e=e.replace(r[2],`{ return ${r[2]} }`))),e=e.replace("=>","")}return e}function se(t={}){return Object.entries(t).map(([e,n])=>`"${e}": ${u(n)}`)}function
|
|
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){const s=$(t)?t.value:e?JSON.stringify(t):t;return n?F(I(s)):I(s)}function w(t,e=[]){let n=t;for(const s of e)n=n.replace(new RegExp(`this.${s}.value`,"g"),`this.${s}`);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]+)/,r=e.match(i);r&&r[2]&&(r[2].startsWith("{")||(e=e.replace(r[2],`{ return ${r[2]} }`))),e=e.replace("=>","")}return e}function se(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(s=>"."+s):n}function re(t){let e="";for(var n in t)if(t.hasOwnProperty(n)){var s=t[n];e+=n+": "+s+";"}return e}class oe{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 s=n.pop(),i=n.join(".")+".",r=n.pop();if(s&&r){const o=this.dependencies.find(c=>c.library===r)?.package;o&&(this.imports[o]||(this.imports[o]=new Set)).add(s)}return{name:s,path:i,library:r}}return null}replaceLibraryPath(e){const{libraryRegex:n}=this;let s=e.value;for(const i of n){const r=e.value.match(i)||[];for(const o of r){const c=this.collectImport(o);if(c){const a=c.path.replace(/\$/g,"\\$");s=s.replace(new RegExp(a,"g"),"")}}}return s}walk(e){const n=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){for(let r of s)n(r);return}const i=Object.values(s);for(const r of i)$(r)?r.value=this.replaceLibraryPath(r):n(r)};n(e)}getLibraryMember(e=[]){let n=[...e];for(const s of Object.values(this.imports))n=n.concat(Array.from(s));return l.dedupArray(n)}collectContext(e,n){const s=new Set(n?.id?this.context[n.id]:[]),i=(e.directives||[]).find(c=>c.name==="vFor");let r=new Set(Array.from(s));if(i){const{item:c="item",index:a="index"}=i.iterator||{};r=new Set([c,a,...Array.from(r)])}const o=e.slot;if(o){const c=typeof o=="string"?[]:o.params||[],a=c.length?c:[`scope_${n?.id}`];r=new Set([...a,...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 n=(s,i)=>{this.collectContext(s,i),this.collectStyle(s),this.collectUrlSchema(s),this.collectBlockPlugin(s),Array.isArray(s.children)&&s.children.forEach(r=>n(r,s))};Array.isArray(e.nodes)&&e.nodes.forEach(s=>n(s))}}function ie(t={}){return Object.entries(t).map(([e,n])=>{const s=u(n,!1);return`${e}:${s}`})}function ce(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 ae(t=[]){const e=n=>n?`[${l.toArray(n).map(r=>r.replace(/\'|\"/gi,"")).join(",")}]`:void 0;return t.map(n=>typeof n=="string"?`${n}: {}`:($(n.default)&&!n.default.value&&(n.default.value="undefined"),`${n.name}: {
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
handler${U(r.handler.value)}
|
|
24
24
|
}`);return{computed:s,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
|
|
26
|
+
}`})}function M(t,e,n=[],s={},i){const r=[];let o={},c=[],a=[];return fe(t).forEach(f=>{const b=[];for(const p of f.children){let{id:O,name:m,invisible:C,from:h}=p;if(C)continue;const j=me(m,e,h);j&&c.push(j),D(h)&&a.push({id:h.id,name:m});const{props:g,events:N,handlers:G}=$e(p,O,p.props,p.events,s,n),B=be(p.directives).join(" "),d=p.children?ve(p.children,n,e,s,p):"";Object.assign(o,G);let v="";typeof d=="string"?v=d:(v=(d?.nodes||[]).join(`
|
|
27
27
|
`),Object.assign(o,d?.methods||{}),c=c.concat(d?.components||[]),a=a.concat(d?.importBlocks||[]));const R=Q(h)||z(h)?"component":m;b.push(m==="img"?`<${m} ${B} ${g} ${N} />`:`<${R} ${B} ${g} ${N}>${v?`
|
|
28
28
|
`+v.trim():""}</${R}>`)}const P=Se(f.slot,b.join(`
|
|
29
|
-
`),i?.id);r.push(P)}),{nodes:r,methods:o,components:l.dedupArray(c),importBlocks:l.dedupArray(a,"id")}}function fe(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,i=e.get(s);i?i.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function me(t,e,n){if(te.includes(t))return null;const s=e.get(t);if(s&&s.alias){const i=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${i}`}return D(n)||s?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}='{${se(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function de(t,e={},n=[]){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(Q(i)||z(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>he(r,o,n))}function ye(t,e,n,s){const i=
|
|
29
|
+
`),i?.id);r.push(P)}),{nodes:r,methods:o,components:l.dedupArray(c),importBlocks:l.dedupArray(a,"id")}}function fe(t=[]){const e=new Map;for(const n of t){const s=typeof n.slot=="string"?n.slot:n.slot?.name,i=e.get(s);i?i.children.push(n):e.set(s,{slot:n.slot,children:[n]})}return e}function me(t,e,n){if(te.includes(t))return null;const s=e.get(t);if(s&&s.alias){const i=s.parent?`${s.parent}.${s.alias}`:s.alias;return`${t}: ${i}`}return D(n)||s?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}='{${se(e).join(", ")}}'`:`:${t}='${JSON.stringify(e)}'`}function de(t,e={},n=[]){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(Q(i)||z(i))&&(e.is={type:"JSExpression",value:t.name}),Object.entries(e).map(([r,o])=>he(r,o,n))}function ye(t,e,n,s){const i=V(e.modifiers,!0);return s&&s.length>0?`@${t}${i.join("")}="(...args:any[]) => ${n}"`:`@${t}${i.join("")}="${n}"`}function ge(t,e={},n={}){const s={},i=Array.from(n[t]||new Set([])),r=i.length?`({${i.join(", ")}}, args)`:"";return{binders:Object.entries(e).map(([c,a])=>{const y=a.handler.value.startsWith("this."),f=y?F(a.handler.value):`${l.camelCase(c)}_${t}${r}`;return y||(s[f]=i.length?{type:"JSFunction",value:`{
|
|
30
30
|
return (${a.handler.value}).apply(this, args);
|
|
31
|
-
}`}:a.handler),ye(c,a,f,i)}),handlers:s}}function $e(t,e,n={},s={},i={},r){const{binders:o,handlers:c}=ge(e,s,i);return{props:de(t,n,r).join(" "),handlers:c,binders:o,events:o.join(" ")}}function be(t=[]){const e=[],{vIf:n,vShow:s,vModels:i,vFor:r}=je(t);if(n&&e.push(`v-if="${u(n.value)}"`),s&&e.push(`v-show="${u(s.value)}"`),i.forEach(o=>{const c=
|
|
31
|
+
}`}:a.handler),ye(c,a,f,i)}),handlers:s}}function $e(t,e,n={},s={},i={},r){const{binders:o,handlers:c}=ge(e,s,i);return{props:de(t,n,r).join(" "),handlers:c,binders:o,events:o.join(" ")}}function be(t=[]){const e=[],{vIf:n,vShow:s,vModels:i,vFor:r}=je(t);if(n&&e.push(`v-if="${u(n.value)}"`),s&&e.push(`v-show="${u(s.value)}"`),i.forEach(o=>{const c=V(o.modifiers,!0),a=o.arg?E(o.arg)?`:[${u(o.arg)}]`:`:${o.arg}`:"";e.push(`v-model${a}${c}="${u(o.value)}"`)}),r){const{item:o,index:c}={item:"item",index:"index",...r.iterator};e.push(`v-for="(${o}, ${c}) in ${u(r.value)}"`)}return e}function je(t=[]){const e=t.find(o=>l.camelCase(o.name)==="vIf"),n=t.find(o=>l.camelCase(o.name)==="vFor"),s=t.find(o=>l.camelCase(o.name)==="vShow"),i=t.find(o=>l.camelCase(o.name)==="vBind"),r=t.filter(o=>l.camelCase(o.name)==="vModel");return{vIf:e,vFor:n,vShow:s,vModels:r,vBind:i}}function ve(t,e,n,s,i){if(typeof t=="string")return t;if(E(t)){let r=u(t,!1);return r=w(r,e),r=F(r),`{{ ${r} }}`}return Array.isArray(t)?M(t,n,e,s,i):""}function Se(t,e,n){if(!t)return e;const s=typeof t=="string"?{name:t,params:[]}:{params:[],...t};return`<template ${`#${s.name}="${s.params?.length>0?`{${s.params?.join(",")}}`:`scope_${n}`}"`}>
|
|
32
32
|
${e}
|
|
33
33
|
</template>`}function we(t,e=[],n=[],s={}){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(s))(i[r]??(i[r]=[])).push(...Array.from(o));return Object.entries(i).filter(([r,o])=>!!o.length).map(([r,o])=>`import { ${l.dedupArray(o).join(",")}} from '${r}';`).concat(n)}function ke(t={}){const e=[];for(const[n,s]of Object.entries(t))e.push(`
|
|
34
34
|
${n} {
|
|
35
35
|
${re(s)}
|
|
36
36
|
}
|
|
37
37
|
`);return e.join(`
|
|
38
|
-
`)}function Pe(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Oe(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Ce(t,e){const{dsl:n}=t,s=Object.keys(n.computed||{}),i=S(n.lifeCycles,s),r=S(n.computed,s),o=ue(n.watch,s),c=pe(n.dataSources),{methods:a,nodes:y,components:f,importBlocks:b}=
|
|
38
|
+
`)}function Pe(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.defineUrlSchemaComponent('${s.url}');`)}),e}function Oe(t={}){const e=[];return Object.entries(t).forEach(([n,s])=>{e.push(`const ${n} = provider.definePluginComponent(${JSON.stringify(s)});`)}),e}function Ce(t,e){const{dsl:n}=t,s=Object.keys(n.computed||{}),i=S(n.lifeCycles,s),r=S(n.computed,s),o=ue(n.watch,s),c=pe(n.dataSources),{methods:a,nodes:y,components:f,importBlocks:b}=M(n.nodes||[],e,s,t.context),P=[...r,...o.computed],p=S({...a,...n.methods||{}},s),O=b.map(g=>`import ${g.name} from './${g.id}.vue';`),m=we(e,f,O,t.imports),C=Object.keys({...t.urlSchemas,...t.blockPlugins}),h=Pe(t.urlSchemas),j=Oe(t.blockPlugins);return{id:n.id,version:n.__VERSION__,name:n.name,state:ie(n.state).join(","),inject:ce(n.inject).join(","),props:ae(n.props).join(","),emits:le(n.emits).join(","),watch:o.watches.join(","),lifeCycles:i.join(","),computed:P.join(","),methods:[...c,...p].join(","),imports:m.join(`
|
|
39
39
|
`),components:f.join(","),returns:t.members.join(","),template:y.join(`
|
|
40
40
|
`),css:n.css||"",style:ke(t.style),urlSchemas:h.join(`
|
|
41
41
|
`),blockPlugins:j.join(`
|
package/dist/index.mjs
CHANGED
|
@@ -8,15 +8,15 @@ import * as U from "prettier/plugins/estree";
|
|
|
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.
|
|
11
|
+
* @version 0.8.13
|
|
12
12
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
13
13
|
*/
|
|
14
|
-
const Bt = "0.8.
|
|
14
|
+
const Bt = "0.8.13";
|
|
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.
|
|
19
|
+
* @version 0.8.13
|
|
20
20
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
21
21
|
*/
|
|
22
22
|
const et = [
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtj/coder",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"prettier": "~3.2.1",
|
|
8
|
-
"@vtj/
|
|
9
|
-
"@vtj/
|
|
8
|
+
"@vtj/base": "~0.8.2",
|
|
9
|
+
"@vtj/core": "~0.8.13"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@vtj/cli": "~0.8.4"
|
package/types/version.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) 2024, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/coder
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.8.
|
|
5
|
+
* @version 0.8.12
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
7
|
*/
|
|
8
|
-
export declare const version = "0.8.
|
|
8
|
+
export declare const version = "0.8.12";
|