@vtj/coder 0.9.30 → 0.10.1-alpha.0

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