@luna-park/plugin 1.0.9 → 1.1.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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("node:fs"),p=require("./index-DmZsz62R.cjs"),f=require("typescript"),U=require("path"),q=require("fs");function j(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,n.get?n:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const m=j(f),O=j(U),J=j(q);function T(t,e={}){if(typeof t!="object"||t===null)return JSON.stringify(t);const o={};for(const n of["default","description","name","target","promise","optional","example","enum"])t[n]&&(o[n]=t[n]);if(t.type===p.i.array)return S(`LogicType.${t.type}`,[T(t.items,e),d(o)]);if(t.type===p.i.interface)return S(`LogicType.${t.type}`,[JSON.stringify(t.className),d(o)]);if(t.type===p.i.union)return S(`LogicType.${t.type}`,[`[${t.elements.map(n=>T(n,e)).join(", ")}]`,d(o)]);if(t.type===p.i.function)return S(`LogicType.${t.type}`,[T(t.inputs,e),T(t.output,e),d(o)]);if(t.type===p.i.object)return S(`LogicType.${t.type}`,[d(p.ot(t.properties,({value:n})=>T(n,e)),!0),d(o)]);if(t.type===p.i.type){const n=t.target.at(-1),i=d(o);return i!=="{}"?n:`{ ...${n}, ${i.slice(1,-1)} }`}return S(`LogicType.${t.type}`,[d(o)])}function S(t,e){const o=e.findLastIndex(n=>n!=="{}");return`${t}(${e.slice(0,o+1).join(", ")})`}function d(t,e){return`{${Object.entries(t).map(([o,n])=>`${P(o)}: ${e?n:JSON.stringify(n)}`).join(", ")}}`}function P(t){return/^[a-zA-Z]+$/.test(t)?t:JSON.stringify(t)}function V(t,e){const o=[],n=t.components.default;Object.keys(t.types);for(const r of["properties","slots","models","emits"])n[r]&&Object.keys(n[r]).length&&o.push({key:r,value:Object.entries(n[r]).map(([l,s])=>`${P(l)}: ${T(s,{})}`).join(`,
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("node:fs"),p=require("./index-4fa4mAH8.cjs"),f=require("typescript"),U=require("path"),q=require("fs");function j(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,n.get?n:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const m=j(f),O=j(U),J=j(q);function T(t,e={}){if(typeof t!="object"||t===null)return JSON.stringify(t);const o={};for(const n of["default","description","name","target","promise","optional","example","enum"])t[n]&&(o[n]=t[n]);if(t.type===p.i.array)return S(`LogicType.${t.type}`,[T(t.items,e),d(o)]);if(t.type===p.i.interface)return S(`LogicType.${t.type}`,[JSON.stringify(t.className),d(o)]);if(t.type===p.i.union)return S(`LogicType.${t.type}`,[`[${t.elements.map(n=>T(n,e)).join(", ")}]`,d(o)]);if(t.type===p.i.function)return S(`LogicType.${t.type}`,[T(t.inputs,e),T(t.output,e),d(o)]);if(t.type===p.i.object)return S(`LogicType.${t.type}`,[d(p.ot(t.properties,({value:n})=>T(n,e)),!0),d(o)]);if(t.type===p.i.type){const n=t.target.at(-1),i=d(o);return i!=="{}"?n:`{ ...${n}, ${i.slice(1,-1)} }`}return S(`LogicType.${t.type}`,[d(o)])}function S(t,e){const o=e.findLastIndex(n=>n!=="{}");return`${t}(${e.slice(0,o+1).join(", ")})`}function d(t,e){return`{${Object.entries(t).map(([o,n])=>`${P(o)}: ${e?n:JSON.stringify(n)}`).join(", ")}}`}function P(t){return/^[a-zA-Z]+$/.test(t)?t:JSON.stringify(t)}function V(t,e){const o=[],n=t.components.default;Object.keys(t.types);for(const r of["properties","slots","models","emits"])n[r]&&Object.keys(n[r]).length&&o.push({key:r,value:Object.entries(n[r]).map(([l,s])=>`${P(l)}: ${T(s,{})}`).join(`,
2
2
  `)});const i=Object.entries(t.types).map(([r,l])=>`const ${r} = ${T(l,{})};`).join(`
3
3
 
4
4
  `);return`import { LogicType, type TComponent } from "@luna-park/plugin";
@@ -13,4 +13,4 @@ export const ${e.name.toLocaleLowerCase()}: TComponent = {
13
13
  ${l}
14
14
  }`).join(`,
15
15
  `)}
16
- }`}function h(t,e){const o={description:x(t.getDocumentationComment(e))||void 0};for(const n of t.getJsDocTags()){if(n.name==="param"){o.params||(o.params={});let i=x(n.text?.slice(1)).trim();i.startsWith("- ")&&(i=i.slice(2));const r=n.text[0]?.text;o.params[r]=i;continue}o[n.name]=x(n.text)}return p.F(o)}function x(t=[]){return t.map(e=>e.text).join("")}function w(t,e){const o=e.checker.getPropertiesOfType(t),n={};return o.forEach(i=>{const r=A(e.checker.getTypeOfSymbol(i)).type,s=e.checker.getSignaturesOfType(r,m.SignatureKind.Call)[0]?.parameters?.[0];if(s){const c=e.checker.getTypeOfSymbol(s);n[i.name]={type:e.typeToString(c)},e.extractType(c)}else n[i.name]={type:"{}"}}),n}function N(t,e){const o=e.checker.getPropertiesOfType(t),n={},i={};return o.forEach(r=>{if(["onVnode","ref_"].some(s=>r.name.startsWith(s))||["ref","class","style","key"].includes(r.name))return;const l=e.checker.getTypeOfSymbol(r);if(e.extractType(l),W(r.name)){i[H(r.name)]=L(l,r,e);return}n[r.name]=L(l,r,e)}),{emits:i,props:n}}function v(t){return t.models=Object.keys(t.properties??{}).reduce((e,o)=>(t.emits?.[`update:${o}`]&&(e[o]=t.properties[o],delete t.properties[o],delete t.emits[`update:${o}`]),e),{}),t}function A(t){if(t.isUnion()){const e=t.types.filter(o=>o.flags!==m.TypeFlags.Undefined);if(e.length===1)return{optional:!0,type:e[0]}}return{type:t}}function L(t,e,o){const n=A(t);return p.F({description:h(e,o.checker).description,optional:n.optional,type:o.typeToString(n.type)})}function W(t){return/^on[A-Z]/.test(t)}function H(t){return t=t.slice(2),t.charAt(0).toLowerCase()+t.slice(1)}function K(t,e){return Object.fromEntries((t.getTypeParameters()??[]).map(o=>{let n="unknown";const i=o.getDefault();i&&(n=e.typeToString(i));const r=o.getConstraint();return r&&(n=e.typeToString(r)),[o.symbol.name,n]}))}function Q(t,e){const o=new Map,n=t.getExportsOfModule(e);for(const i of n){let r=i;for(;r.flags&m.SymbolFlags.Alias;)r=t.getAliasedSymbol(r);o.set(i.name,r)}return o}function k(t,e){let o=t.getFullyQualifiedName(e);return o.includes('".')&&(o=o.split('".').pop()),o.includes(").")&&(o=o.split(").").pop()),o}function F(t,e){for(const[o,n]of Object.entries(e))t=t.replace(new RegExp(`\\b${o}\\b`,"g"),n);return t}function R(t){const e=[];return t.members.forEach(n=>{const i=n.name.getText();if(n.initializer){let r;m.isStringLiteral(n.initializer)?r=`"${n.initializer.text}"`:m.isNumericLiteral(n.initializer)?r=n.initializer.text:r=n.initializer.getText(),e.push(`${i} = ${r}`)}else e.push(i)}),`{ ${e.join(", ")} }`}function $(t){if(t.getFlags()&(f.TypeFlags.StringLike|f.TypeFlags.NumberLike|f.TypeFlags.BooleanLike|f.TypeFlags.ESSymbolLike|f.TypeFlags.Void|f.TypeFlags.Undefined|f.TypeFlags.Null|f.TypeFlags.Any|f.TypeFlags.Unknown|f.TypeFlags.Never))return!1;const o=t.getSymbol();if(!o)return!0;const n=o.declarations?.[0];if(!n)return!0;const i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith("/@vue/"))}const E=f.TypeFormatFlags.WriteArrowStyleSignature|f.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType;class D{constructor(e){this.program=e,this.checker=e.getTypeChecker()}checker;index;cache=new Set;result;get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw new Error(`Cannot find file ${e}`);const o=this.checker.getSymbolAtLocation(this.index);if(!o)throw new Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};const n=this.index.statements.find(i=>f.isExportAssignment(i));if(n){const r=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];r&&this.exportFunction("default",r)}return this.exportModule(o),this.result}exportModule(e){const o=Q(this.checker,e);for(const[n,i]of o.entries()){let r=this.checker.getTypeOfSymbol(i);if(r.symbol&&r.symbol.flags&f.SymbolFlags.Module){const s=r.symbol.exports?.get("default");s&&(r=this.checker.getTypeOfSymbol(s))}const l=r.symbol||r.aliasSymbol;if(l?.flags&f.SymbolFlags.Function){const s=this.checker.getTypeOfSymbol(l),c=this.checker.getSignaturesOfType(s,f.SignatureKind.Call)[0];if(c){const a=k(this.checker,l);this.exportFunction(a,c)}}else if(this.typeToString(r).includes("DefineComponent<"))try{this.exportComponent(n,r)}catch(c){console.error(`Fail to export component ${n}`),console.error(c)}}}exportComponent(e,o){const n=o.getConstructSignatures()[0];if(!n)return;const i=this.checker.getReturnTypeOfSignature(n),r={},l=this.checker.getPropertyOfType(i,"$props");if(l){const c=this.checker.getTypeOfSymbol(l),a=N(c,this);r.properties=a.props,r.emits=a.emits}const s=this.checker.getPropertyOfType(i,"$slots");if(s){const c=this.checker.getTypeOfSymbol(s);r.slots=w(c,this)}this.result.components[e]=v(r)}exportFunction(e,o){const n=h(o,this.checker),i=K(o,this),r=o.getParameters().map(s=>{const c=s.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(s);this.extractType(a,c);const u=s.valueDeclaration?.initializer?.getText();return p.F({default:u,description:n.params?.[s.name],name:s.name,optional:!!c.questionToken||u!==void 0||void 0,type:F(this.typeToString(a),i)})});if(r.some(s=>s.name?.startsWith("__VLS_"))){const s={},c=r.findIndex(y=>y.name==="__VLS_props"),a=o.getParameters()[c];if(a){const y=this.checker.getTypeOfSymbol(a),b=N(y,this);s.properties=b.props,s.emits=b.emits,Object.values(s.properties).forEach(C=>{C.type=F(C.type,i)})}const u=r.findIndex(y=>y.name==="__VLS_slots"),g=o.getParameters()[u];if(g){const y=this.checker.getTypeOfSymbol(g);s.slots=w(y,this),Object.values(s.slots).forEach(b=>{b.type=F(b.type,i)})}this.result.components[e]=v(s);return}const l=this.checker.getReturnTypeOfSignature(o);this.extractType(l),this.result.functions[e]=p.F({description:n.description,parameters:r,return:{description:n.returns,type:F(this.typeToString(l),i)}})}extractType(e,o=this.index){if(this.cache.has(e))return;this.cache.add(e);const n=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(n?.flags&f.SymbolFlags.Enum)&&e.types.forEach(i=>{this.extractType(i,o)}),n){if(this.checker.getFullyQualifiedName(n).includes("/@vue/"))return;const i=k(this.checker,n);if(n.flags&f.SymbolFlags.Enum){const r=n.valueDeclaration||n.declarations?.[0];if(r&&f.isEnumDeclaration(r)){const l=k(this.checker,n);this.result.types[l]=p.F({...h(n,this.checker),type:R(r)})}return}if(n.flags&f.SymbolFlags.Namespace){const r=n;this.exportModule(r)}if(n.flags&f.SymbolFlags.TypeAlias){const r=n.valueDeclaration||n.declarations?.[0];if(!r)return;const l=Object.fromEntries((r?.typeParameters??[]).map(s=>{let c="unknown";const a=s.default;if(a){const g=this.checker.getTypeFromTypeNode(a);c=this.typeToString(g)}const u=s.constraint;if(u){const g=this.checker.getTypeFromTypeNode(u);c=this.typeToString(g)}return[s.symbol.name,c]}));this.result.types[i]={...h(n,this.checker),type:F(this.typeToString(e,E|f.TypeFormatFlags.InTypeAlias),l)}}if(n.flags&f.SymbolFlags.Interface&&$(e)){const r=n.getDeclarations()[0];if(r){const l=this.checker.getPropertiesOfType(e),s={};l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);this.extractType(a,r),s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional)||void 0,type:this.typeToString(a)}}),this.result.types[i]={...h(n,this.checker),type:s}}}if(n.flags&f.SymbolFlags.TypeLiteral){const r=k(this.checker,e.aliasSymbol||e.symbol),l=this.checker.getPropertiesOfType(e),s={};if(["Promise","Partial","Pick","Omit","Required"].includes(r)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(c=>!$(c)))return;l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional),type:this.typeToString(a)}}),r!=="__type"&&(this.result.types[r]={...h(n,this.checker),type:s})}}if(e.flags&f.TypeFlags.Object){const i=e;if($(e)&&this.checker.getPropertiesOfType(e).forEach(l=>{const s=this.checker.getTypeOfSymbol(l);this.extractType(s,o)}),i.objectFlags&f.ObjectFlags.Reference){const r=i;this.checker.getTypeArguments(r).forEach(s=>{this.extractType(s,o)})}}}typeToString(e,o=E){return this.checker.typeToString(e,void 0,o)}}function M(t,e="unknown"){const o={components:{},functions:{},types:{}};for(const[s,c]of Object.entries(t.types))o.types[s]=n(c,s);for(const[s,c]of Object.entries(t.functions))o.functions[s]=i(c,s);for(const[s,c]of Object.entries(t.components))o.components[s]=r(c,s);return o;function n(s,c=""){if(typeof s.type=="string"){if(s.type==="{}")return p.u.void();const a={...l(p.ot$1(s.type)),...p.F({description:s.description,name:c?.split(".").pop()||void 0,optional:s.optional})};if(s.default)switch(a.type){case p.i.boolean:a.default=s.default==="true";break;case p.i.number:a.default=Number(s.default);break;case p.i.string:a.default=s.default;break}return a.type===p.i.object&&!Object.keys(a.properties).length&&(a.customizable=!0),a}else{const a=p.u.object(p.ot(s.type,({key:u,value:g})=>n(g,u)),p.F({description:s.description,name:c?.split(".").pop(),optional:s.optional}));return Object.keys(a.properties).length||(a.customizable=!0),a}}function i(s,c=""){return{...p.F({description:s.description,name:c?.split(".").pop()}),parameters:(s.parameters??[]).map(a=>n(a,a.name)),return:n(s.return,"result")}}function r(s,c=""){return{...p.F({name:c?.split(".").pop()}),emits:p.ot(s.emits,({value:a})=>n(a)),models:p.ot(s.models,({value:a})=>n(a)),properties:p.ot(s.properties,({key:a,value:u})=>n(u,a)),slots:p.ot(s.slots,({value:a})=>n(a))}}function l(s,c=""){return p.d(s,u=>{if(u.type===p.i.interface)return{...a(u.className,c),description:u.description,name:u.name,optional:u.optional}});function a(u,g=""){let y=`${g}${u}`;for(;!t.types[y]&&y.indexOf(".")!==-1;)y=y.substring(y.indexOf(".")+1);return t.types[y]?p.u.type(["packages",e,...y.split(".")]):p.u.interface(u)}}}function Z(t){for(;;){const e=O.join(t,"tsconfig.json");if(J.existsSync(e))return e;const o=O.dirname(t);if(o===t)return;t=o}}function B(t){const e=m.readConfigFile(t,m.sys.readFile);if(e.error)throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);return m.parseJsonConfigFileContent(e.config,m.sys,O.dirname(t))}function G(t,e){const o=O.join(process.cwd(),"__temp__.ts"),n=m.createCompilerHost(e),i=m.resolveModuleName(t,o,e,n);if(i.resolvedModule)return i.resolvedModule.resolvedFileName}function z(t){const e=Z(t);if(!e)throw new Error(`Could not find tsconfig.json for: ${t}`);const n=B(e).options,i=G(t,n);if(!i)throw new Error(`Could not resolve module: ${t}`);const r=m.createCompilerHost(n),l=m.createProgram({host:r,options:n,rootNames:[i]}),s=l.getSourceFile(i);if(!s)throw new Error(`Could not get source file for: ${i}`);return{program:l,sourceFile:s}}const _=I.promises;async function X(t,e){const o=t.split("/").pop().split(".")[0],{program:n,sourceFile:i}=z(t),l=new D(n).get(i.fileName),s=M(l,o);if(s.components.default){const c=V(s,{name:o,path:t});await _.mkdir(e.split("/").slice(0,-1).join("/"),{recursive:!0}),await _.writeFile(e,c)}}exports.CTypeExport=D;exports.extractFile=X;exports.generateNodes=M;exports.getSourceFile=z;
16
+ }`}function h(t,e){const o={description:x(t.getDocumentationComment(e))||void 0};for(const n of t.getJsDocTags()){if(n.name==="param"){o.params||(o.params={});let i=x(n.text?.slice(1)).trim();i.startsWith("- ")&&(i=i.slice(2));const r=n.text[0]?.text;o.params[r]=i;continue}o[n.name]=x(n.text)}return p.F(o)}function x(t=[]){return t.map(e=>e.text).join("")}function w(t,e){const o=e.checker.getPropertiesOfType(t),n={};return o.forEach(i=>{const r=A(e.checker.getTypeOfSymbol(i)).type,s=e.checker.getSignaturesOfType(r,m.SignatureKind.Call)[0]?.parameters?.[0];if(s){const c=e.checker.getTypeOfSymbol(s);n[i.name]={type:e.typeToString(c)},e.extractType(c)}else n[i.name]={type:"{}"}}),n}function N(t,e){const o=e.checker.getPropertiesOfType(t),n={},i={};return o.forEach(r=>{if(["onVnode","ref_"].some(s=>r.name.startsWith(s))||["ref","class","style","key"].includes(r.name))return;const l=e.checker.getTypeOfSymbol(r);if(e.extractType(l),W(r.name)){i[H(r.name)]=L(l,r,e);return}n[r.name]=L(l,r,e)}),{emits:i,props:n}}function v(t){return t.models=Object.keys(t.properties??{}).reduce((e,o)=>(t.emits?.[`update:${o}`]&&(e[o]=t.properties[o],delete t.properties[o],delete t.emits[`update:${o}`]),e),{}),t}function A(t){if(t.isUnion()){const e=t.types.filter(o=>o.flags!==m.TypeFlags.Undefined);if(e.length===1)return{optional:!0,type:e[0]}}return{type:t}}function L(t,e,o){const n=A(t);return p.F({description:h(e,o.checker).description,optional:n.optional,type:o.typeToString(n.type)})}function W(t){return/^on[A-Z]/.test(t)}function H(t){return t=t.slice(2),t.charAt(0).toLowerCase()+t.slice(1)}function K(t,e){return Object.fromEntries((t.getTypeParameters()??[]).map(o=>{let n="unknown";const i=o.getDefault();i&&(n=e.typeToString(i));const r=o.getConstraint();return r&&(n=e.typeToString(r)),[o.symbol.name,n]}))}function Q(t,e){const o=new Map,n=t.getExportsOfModule(e);for(const i of n){let r=i;for(;r.flags&m.SymbolFlags.Alias;)r=t.getAliasedSymbol(r);o.set(i.name,r)}return o}function k(t,e){let o=t.getFullyQualifiedName(e);return o.includes('".')&&(o=o.split('".').pop()),o.includes(").")&&(o=o.split(").").pop()),o}function F(t,e){for(const[o,n]of Object.entries(e))t=t.replace(new RegExp(`\\b${o}\\b`,"g"),n);return t}function R(t){const e=[];return t.members.forEach(n=>{const i=n.name.getText();if(n.initializer){let r;m.isStringLiteral(n.initializer)?r=`"${n.initializer.text}"`:m.isNumericLiteral(n.initializer)?r=n.initializer.text:r=n.initializer.getText(),e.push(`${i} = ${r}`)}else e.push(i)}),`{ ${e.join(", ")} }`}function $(t){if(t.getFlags()&(f.TypeFlags.StringLike|f.TypeFlags.NumberLike|f.TypeFlags.BooleanLike|f.TypeFlags.ESSymbolLike|f.TypeFlags.Void|f.TypeFlags.Undefined|f.TypeFlags.Null|f.TypeFlags.Any|f.TypeFlags.Unknown|f.TypeFlags.Never))return!1;const o=t.getSymbol();if(!o)return!0;const n=o.declarations?.[0];if(!n)return!0;const i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith("/@vue/"))}const E=f.TypeFormatFlags.WriteArrowStyleSignature|f.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType;class D{constructor(e){this.program=e,this.checker=e.getTypeChecker()}checker;index;cache=new Set;result;get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw new Error(`Cannot find file ${e}`);const o=this.checker.getSymbolAtLocation(this.index);if(!o)throw new Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};const n=this.index.statements.find(i=>f.isExportAssignment(i));if(n){const r=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];r&&this.exportFunction("default",r)}return this.exportModule(o),this.result}exportModule(e){const o=Q(this.checker,e);for(const[n,i]of o.entries()){let r=this.checker.getTypeOfSymbol(i);if(r.symbol&&r.symbol.flags&f.SymbolFlags.Module){const s=r.symbol.exports?.get("default");s&&(r=this.checker.getTypeOfSymbol(s))}const l=r.symbol||r.aliasSymbol;if(l?.flags&f.SymbolFlags.Function){const s=this.checker.getTypeOfSymbol(l),c=this.checker.getSignaturesOfType(s,f.SignatureKind.Call)[0];if(c){const a=k(this.checker,l);this.exportFunction(a,c)}}else if(this.typeToString(r).includes("DefineComponent<"))try{this.exportComponent(n,r)}catch(c){console.error(`Fail to export component ${n}`),console.error(c)}}}exportComponent(e,o){const n=o.getConstructSignatures()[0];if(!n)return;const i=this.checker.getReturnTypeOfSignature(n),r={},l=this.checker.getPropertyOfType(i,"$props");if(l){const c=this.checker.getTypeOfSymbol(l),a=N(c,this);r.properties=a.props,r.emits=a.emits}const s=this.checker.getPropertyOfType(i,"$slots");if(s){const c=this.checker.getTypeOfSymbol(s);r.slots=w(c,this)}this.result.components[e]=v(r)}exportFunction(e,o){const n=h(o,this.checker),i=K(o,this),r=o.getParameters().map(s=>{const c=s.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(s);this.extractType(a,c);const u=s.valueDeclaration?.initializer?.getText();return p.F({default:u,description:n.params?.[s.name],name:s.name,optional:!!c.questionToken||u!==void 0||void 0,type:F(this.typeToString(a),i)})});if(r.some(s=>s.name?.startsWith("__VLS_"))){const s={},c=r.findIndex(y=>y.name==="__VLS_props"),a=o.getParameters()[c];if(a){const y=this.checker.getTypeOfSymbol(a),b=N(y,this);s.properties=b.props,s.emits=b.emits,Object.values(s.properties).forEach(C=>{C.type=F(C.type,i)})}const u=r.findIndex(y=>y.name==="__VLS_slots"),g=o.getParameters()[u];if(g){const y=this.checker.getTypeOfSymbol(g);s.slots=w(y,this),Object.values(s.slots).forEach(b=>{b.type=F(b.type,i)})}this.result.components[e]=v(s);return}const l=this.checker.getReturnTypeOfSignature(o);this.extractType(l),this.result.functions[e]=p.F({description:n.description,parameters:r,return:{description:n.returns,type:F(this.typeToString(l),i)}})}extractType(e,o=this.index){if(this.cache.has(e))return;this.cache.add(e);const n=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(n?.flags&f.SymbolFlags.Enum)&&e.types.forEach(i=>{this.extractType(i,o)}),n){if(this.checker.getFullyQualifiedName(n).includes("/@vue/"))return;const i=k(this.checker,n);if(n.flags&f.SymbolFlags.Enum){const r=n.valueDeclaration||n.declarations?.[0];if(r&&f.isEnumDeclaration(r)){const l=k(this.checker,n);this.result.types[l]=p.F({...h(n,this.checker),type:R(r)})}return}if(n.flags&f.SymbolFlags.Namespace){const r=n;this.exportModule(r)}if(n.flags&f.SymbolFlags.TypeAlias){const r=n.valueDeclaration||n.declarations?.[0];if(!r)return;const l=Object.fromEntries((r?.typeParameters??[]).map(s=>{let c="unknown";const a=s.default;if(a){const g=this.checker.getTypeFromTypeNode(a);c=this.typeToString(g)}const u=s.constraint;if(u){const g=this.checker.getTypeFromTypeNode(u);c=this.typeToString(g)}return[s.symbol.name,c]}));this.result.types[i]={...h(n,this.checker),type:F(this.typeToString(e,E|f.TypeFormatFlags.InTypeAlias),l)}}if(n.flags&f.SymbolFlags.Interface&&$(e)){const r=n.getDeclarations()[0];if(r){const l=this.checker.getPropertiesOfType(e),s={};l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);this.extractType(a,r),s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional)||void 0,type:this.typeToString(a)}}),this.result.types[i]={...h(n,this.checker),type:s}}}if(n.flags&f.SymbolFlags.TypeLiteral){const r=k(this.checker,e.aliasSymbol||e.symbol),l=this.checker.getPropertiesOfType(e),s={};if(["Promise","Partial","Pick","Omit","Required"].includes(r)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(c=>!$(c)))return;l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional),type:this.typeToString(a)}}),r!=="__type"&&(this.result.types[r]={...h(n,this.checker),type:s})}}if(e.flags&f.TypeFlags.Object){const i=e;if($(e)&&this.checker.getPropertiesOfType(e).forEach(l=>{const s=this.checker.getTypeOfSymbol(l);this.extractType(s,o)}),i.objectFlags&f.ObjectFlags.Reference){const r=i;this.checker.getTypeArguments(r).forEach(s=>{this.extractType(s,o)})}}}typeToString(e,o=E){return this.checker.typeToString(e,void 0,o)}}function M(t,e="unknown"){const o={components:{},functions:{},types:{}};for(const[s,c]of Object.entries(t.types))o.types[s]=n(c,s);for(const[s,c]of Object.entries(t.functions))o.functions[s]=i(c,s);for(const[s,c]of Object.entries(t.components))o.components[s]=r(c,s);return o;function n(s,c=""){if(typeof s.type=="string"){if(s.type==="{}")return p.u.void();const a={...l(p.ot$1(s.type)),...p.F({description:s.description,name:c?.split(".").pop()||void 0,optional:s.optional})};if(s.default)switch(a.type){case p.i.boolean:a.default=s.default==="true";break;case p.i.number:a.default=Number(s.default);break;case p.i.string:a.default=s.default;break}return a.type===p.i.object&&!Object.keys(a.properties).length&&(a.customizable=!0),a}else{const a=p.u.object(p.ot(s.type,({key:u,value:g})=>n(g,u)),p.F({description:s.description,name:c?.split(".").pop(),optional:s.optional}));return Object.keys(a.properties).length||(a.customizable=!0),a}}function i(s,c=""){return{...p.F({description:s.description,name:c?.split(".").pop()}),parameters:(s.parameters??[]).map(a=>n(a,a.name)),return:n(s.return,"result")}}function r(s,c=""){return{...p.F({name:c?.split(".").pop()}),emits:p.ot(s.emits,({value:a})=>n(a)),models:p.ot(s.models,({value:a})=>n(a)),properties:p.ot(s.properties,({key:a,value:u})=>n(u,a)),slots:p.ot(s.slots,({value:a})=>n(a))}}function l(s,c=""){return p.m(s,u=>{if(u.type===p.i.interface)return{...a(u.className,c),description:u.description,name:u.name,optional:u.optional}});function a(u,g=""){let y=`${g}${u}`;for(;!t.types[y]&&y.indexOf(".")!==-1;)y=y.substring(y.indexOf(".")+1);return t.types[y]?p.u.type(["packages",e,...y.split(".")]):p.u.interface(u)}}}function Z(t){for(;;){const e=O.join(t,"tsconfig.json");if(J.existsSync(e))return e;const o=O.dirname(t);if(o===t)return;t=o}}function B(t){const e=m.readConfigFile(t,m.sys.readFile);if(e.error)throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);return m.parseJsonConfigFileContent(e.config,m.sys,O.dirname(t))}function G(t,e){const o=O.join(process.cwd(),"__temp__.ts"),n=m.createCompilerHost(e),i=m.resolveModuleName(t,o,e,n);if(i.resolvedModule)return i.resolvedModule.resolvedFileName}function z(t){const e=Z(t);if(!e)throw new Error(`Could not find tsconfig.json for: ${t}`);const n=B(e).options,i=G(t,n);if(!i)throw new Error(`Could not resolve module: ${t}`);const r=m.createCompilerHost(n),l=m.createProgram({host:r,options:n,rootNames:[i]}),s=l.getSourceFile(i);if(!s)throw new Error(`Could not get source file for: ${i}`);return{program:l,sourceFile:s}}const _=I.promises;async function X(t,e){const o=t.split("/").pop().split(".")[0],{program:n,sourceFile:i}=z(t),l=new D(n).get(i.fileName),s=M(l,o);if(s.components.default){const c=V(s,{name:o,path:t});await _.mkdir(e.split("/").slice(0,-1).join("/"),{recursive:!0}),await _.writeFile(e,c)}}exports.CTypeExport=D;exports.extractFile=X;exports.generateNodes=M;exports.getSourceFile=z;
package/dist/extractor.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import M from "node:fs";
2
- import { i as m, o as F, F as d, u as x, a as I, d as U } from "./index-CxGB_fZK.js";
2
+ import { i as m, o as F, F as d, u as x, a as I, m as U } from "./index-QMG2c0JW.js";
3
3
  import * as y from "typescript";
4
4
  import p from "typescript";
5
5
  import * as j from "path";
@@ -1,5 +1,5 @@
1
- "use strict";function W(e){if(typeof e!="object")return e;try{return JSON.parse(JSON.stringify(e))}catch{return structuredClone(e)}}function y(e,n){return e?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,n({key:r,value:o})])):{}}function g(e,n){return e?Object.fromEntries(Object.entries(e).filter(([r,o])=>n({key:r,value:o}))):{}}function E(e){e=W(e);for(const r in e)n(e,r);function n(r,o){if(typeof r[o]=="object"){for(const i in r[o])n(r[o],i);Object.keys(r[o]).length===0&&delete r[o]}}return e}var f=(e=>(e.exec="exec",e.number="number",e.string="string",e.boolean="boolean",e.object="object",e.record="record",e.array="array",e.interface="interface",e.type="type",e.function="function",e.union="union",e.unknown="unknown",e.undefined="undefined",e.void="void",e))(f||{});const t={type:(e,n={})=>({...n,type:"type",target:e}),array:(e,n={})=>({...n,type:"array",items:e}),boolean:(e={})=>({...e,type:"boolean"}),exec:(e={})=>({...e,type:"exec"}),function:(e={type:"object",properties:{}},n={type:"void"},r={})=>({...r,type:"function",inputs:e,output:n}),interface:(e,n={})=>({...n,type:"interface",className:typeof e=="string"?e:e.name}),number:(e={})=>({...e,type:"number"}),object:(e={},n={})=>({...n,type:"object",properties:e}),record:(e,n,r={})=>({...r,type:"record",key:e,value:n}),string:(e={})=>({...e,type:"string"}),undefined:(e={})=>({...e,type:"undefined"}),union:(e,n={})=>({...n,type:"union",elements:e}),unknown:(e={})=>({...e,type:"unknown"}),void:(e={})=>({...e,type:"void"})},h={omit(e,n){return{...e,properties:g(e.properties,({key:r})=>!n.includes(r))}},partial(e,n=!1){return{...e,properties:y(e.properties,({value:r})=>({...r,optional:!n||!r.required}))}},pick(e,n){return{...e,properties:g(e.properties,({key:r})=>n.includes(r))}},promise(e){return{...e,promise:!0}},required(e){return{...e,properties:y(e.properties,({value:n})=>({...n,optional:!1}))}}};var v=(e=>(e.function="function",e.macro="macro",e.operation="operation",e))(v||{}),O=(e=>(e.Frontend="frontend",e.Backend="backend",e.Desktop="desktop",e.Shared="shared",e))(O||{});function F(e){return e}function b(e){const n=[];for(e=e.replaceAll(/ +/g," "),e=e.replaceAll(/\s*\n\s*/g,`
1
+ "use strict";function W(e){if(typeof e!="object")return e;try{return JSON.parse(JSON.stringify(e))}catch{return structuredClone(e)}}function y(e,n){return e?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,n({key:r,value:o})])):{}}function g(e,n){return e?Object.fromEntries(Object.entries(e).filter(([r,o])=>n({key:r,value:o}))):{}}function E(e){e=W(e);for(const r in e)n(e,r);function n(r,o){if(typeof r[o]=="object"){for(const i in r[o])n(r[o],i);Object.keys(r[o]).length===0&&delete r[o]}}return e}var f=(e=>(e.exec="exec",e.number="number",e.string="string",e.boolean="boolean",e.object="object",e.record="record",e.array="array",e.interface="interface",e.type="type",e.function="function",e.union="union",e.unknown="unknown",e.undefined="undefined",e.void="void",e))(f||{});const t={type:(e,n={})=>({...n,type:"type",target:e}),array:(e,n={})=>({...n,type:"array",items:e}),boolean:(e={})=>({...e,type:"boolean"}),exec:(e={})=>({...e,type:"exec"}),function:(e={type:"object",properties:{}},n={type:"void"},r={})=>({...r,type:"function",inputs:e,output:n}),interface:(e,n={})=>({...n,type:"interface",className:typeof e=="string"?e:e.name}),number:(e={})=>({...e,type:"number"}),object:(e={},n={})=>({...n,type:"object",properties:e}),record:(e,n,r={})=>({...r,type:"record",key:e,value:n}),string:(e={})=>({...e,type:"string"}),undefined:(e={})=>({...e,type:"undefined"}),union:(e,n={})=>({...n,type:"union",elements:e}),unknown:(e={})=>({...e,type:"unknown"}),void:(e={})=>({...e,type:"void"})},h={omit(e,n){return{...e,properties:g(e.properties,({key:r})=>!n.includes(r))}},partial(e,n=!1){return{...e,properties:y(e.properties,({value:r})=>({...r,optional:!n||!r.required}))}},pick(e,n){return{...e,properties:g(e.properties,({key:r})=>n.includes(r))}},promise(e){return{...e,promise:!0}},required(e){return{...e,properties:y(e.properties,({value:n})=>({...n,optional:!1}))}}};var v=(e=>(e.function="function",e.macro="macro",e.operation="operation",e))(v||{}),O=(e=>(e.Frontend="frontend",e.Backend="backend",e.Desktop="desktop",e.Shared="shared",e))(O||{});function J(e){return e}function b(e){const n=[];for(e=e.replaceAll(/ +/g," "),e=e.replaceAll(/\s*\n\s*/g,`
2
2
  `);e.length;){if([" ",`
3
- `].includes(e[0])){e=e.slice(1);continue}if(e.startsWith("/*")){const i=e.indexOf("*/");n.push(e.slice(0,i+2)),e=e.slice(i+2);continue}const r=e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];if(r){e=e.slice(r.length),n.push(r);continue}const o=e.match(/^([0-9]+)/)?.[0];if(o){e=e.slice(o.length),n.push(o);continue}if(e[0]===">"&&n.at(-1)==="="){n.pop(),n.push("=>"),e=e.slice(1);continue}n.push(e[0]),e=e.slice(1)}return n}const N=[["(",")"],["[","]"],["{","}"],["<",">"],["'","'"],['"','"']];function j(e){return m(l(e,";"))}function p(e,n,r=1){const o=[];for(N.find(i=>i[1]===n)?.[0];e.length&&(e[0],!(e[0]===n&&(r--,r<=0)));){const i=d(e);if(o.push(i),r===0&&typeof i=="object"&&i.type==="wrap"&&i.style.endsWith(n))break}return e.shift(),o}function J(e,n){for(;e.length;){if(e[0]===n){e.shift();break}e.shift()}}function l(e,n){const r=[[]];for(;e.length;){if(e[0]===n){r.push([]),e.shift();continue}r.at(-1).push(d(e))}return r.filter(o=>o.length)}function d(e){let n=e.shift(),r=!1;if(n==="export"){if(r=!0,n=e.shift(),n==="=")return{type:"export",content:e.shift()};if(n==="as")return J(e,";"),d(e)}if(n==="declare"&&(n=e.shift()),n==="namespace"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:n,content:i,export:r}}if(n==="function"){const o=e.shift(),i=e.shift(),s={name:o,type:n};i==="<"&&(s.template=p(e,">"),e.shift());const u=l(p(e,")",0),",");return s.export=r,s.params=u,e[0]===":"&&(e.shift(),s.returns=p(e,";")),e.unshift(";"),s}if(n==="interface"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:"interface",content:i}}if(n==="type"&&/^[A-Za-z0-9]*$/.test(e[0])){const o=e.shift(),i=e.shift(),s={name:o,type:n};return i==="<"&&(s.template=p(e,">"),e.shift()),s.content=p(e,";"),e.unshift(";"),s}if(n==="enum"){const o=e.shift();e.shift();const i=p(e,"}");e.unshift(";");const s=Object.fromEntries(i.join("").split(",").filter(u=>u.trim()).map(u=>{if(u.includes("=")){const[x,z]=u.split("=");return[JSON.parse(z),x]}return[o,o]}));return{name:o,type:"enum",options:s}}if(typeof n=="string"&&n.startsWith("/*"))return{type:"comment",content:Z(n)};for(const o of N)if(n===o[0])return{type:"wrap",content:l(p(e,o[1]),";").map(i=>l(i,",")).map(i=>l(i,"|")),style:o.join("")};return n}function m(e){return Array.isArray(e)?e.length===1?m(e[0]):e.map(n=>m(n)):typeof e=="object"&&e!==null?y(e,({value:n})=>m(n)):e}function Z(e){return e=e.trim(),e.startsWith("/**")&&e.endsWith("*/")?(e=e.slice(3,-2).split(`
3
+ `].includes(e[0])){e=e.slice(1);continue}if(e.startsWith("/*")){const i=e.indexOf("*/");n.push(e.slice(0,i+2)),e=e.slice(i+2);continue}const r=e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];if(r){e=e.slice(r.length),n.push(r);continue}const o=e.match(/^([0-9]+)/)?.[0];if(o){e=e.slice(o.length),n.push(o);continue}if(e[0]===">"&&n.at(-1)==="="){n.pop(),n.push("=>"),e=e.slice(1);continue}n.push(e[0]),e=e.slice(1)}return n}const N=[["(",")"],["[","]"],["{","}"],["<",">"],["'","'"],['"','"']];function j(e){return m(l(e,";"))}function p(e,n,r=1){const o=[];for(N.find(i=>i[1]===n)?.[0];e.length&&(e[0],!(e[0]===n&&(r--,r<=0)));){const i=d(e);if(o.push(i),r===0&&typeof i=="object"&&i.type==="wrap"&&i.style.endsWith(n))break}return e.shift(),o}function Z(e,n){for(;e.length;){if(e[0]===n){e.shift();break}e.shift()}}function l(e,n){const r=[[]];for(;e.length;){if(e[0]===n){r.push([]),e.shift();continue}r.at(-1).push(d(e))}return r.filter(o=>o.length)}function d(e){let n=e.shift(),r=!1;if(n==="export"){if(r=!0,n=e.shift(),n==="=")return{type:"export",content:e.shift()};if(n==="as")return Z(e,";"),d(e)}if(n==="declare"&&(n=e.shift()),n==="namespace"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:n,content:i,export:r}}if(n==="function"){const o=e.shift(),i=e.shift(),s={name:o,type:n};i==="<"&&(s.template=p(e,">"),e.shift());const u=l(p(e,")",0),",");return s.export=r,s.params=u,e[0]===":"&&(e.shift(),s.returns=p(e,";")),e.unshift(";"),s}if(n==="interface"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:"interface",content:i}}if(n==="type"&&/^[A-Za-z0-9]*$/.test(e[0])){const o=e.shift(),i=e.shift(),s={name:o,type:n};return i==="<"&&(s.template=p(e,">"),e.shift()),s.content=p(e,";"),e.unshift(";"),s}if(n==="enum"){const o=e.shift();e.shift();const i=p(e,"}");e.unshift(";");const s=Object.fromEntries(i.join("").split(",").filter(u=>u.trim()).map(u=>{if(u.includes("=")){const[x,z]=u.split("=");return[JSON.parse(z),x]}return[o,o]}));return{name:o,type:"enum",options:s}}if(typeof n=="string"&&n.startsWith("/*"))return{type:"comment",content:q(n)};for(const o of N)if(n===o[0])return{type:"wrap",content:l(p(e,o[1]),";").map(i=>l(i,",")).map(i=>l(i,"|")),style:o.join("")};return n}function m(e){return Array.isArray(e)?e.length===1?m(e[0]):e.map(n=>m(n)):typeof e=="object"&&e!==null?y(e,({value:n})=>m(n)):e}function q(e){return e=e.trim(),e.startsWith("/**")&&e.endsWith("*/")?(e=e.slice(3,-2).split(`
4
4
  `).map(n=>{const r=n.trim();return r.startsWith("* ")?r.slice(2):r}).join(`
5
- `).trim(),e.trim()):e}function k(e){e.elements.find(i=>[f.undefined,f.void].includes(i.type))&&(e.optional=!0,e.elements=e.elements.filter(i=>![f.undefined,f.void].includes(i.type)));const n=e.elements.filter(i=>i.type===f.union);if(n.length>0){e.elements=e.elements.filter(i=>i.type!==f.union);for(const i of n)e.elements.push(...i.elements)}const r=e.elements.filter(i=>i.type===f.string);if(r.length>1){const i=[];let s=!1;for(const u of r)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.string),s?e.elements.push(t.string()):e.elements.push(t.string({enum:i}))}const o=e.elements.filter(i=>i.type===f.number);if(o.length>1){const i=[];let s=!1;for(const u of o)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.number),s?e.elements.push(t.number()):e.elements.push(t.number({enum:i}))}if(e.elements.length===1){const i=e.elements[0];return i.optional=e.optional,i}return e.elements.length===0?t.void():e}function A(e){return e.className==="Array"?t.array(e.options.template[0]):e.className==="keyof"?t.string():e.className==="Record"?t.object({}):e.className==="PropertyKey"?t.union([t.string(),t.number()]):["Promise","Partial","Required"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0]):["Omit","Pick"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0],e.options.template[1]?.enum):e}function c(e,n={}){if(typeof e=="string")return e==="string"?t.string(n):e==="number"?t.number(n):e==="boolean"?t.boolean(n):e==="undefined"?t.void(n):["unknown","any"].includes(e)?t.unknown(n):["undefined","null"].includes(e)?t.undefined(n):A(t.interface(e,n));if(Array.isArray(e)){if(e[0]==="readonly"&&e.shift(),e.length===1)return c(e[0],n);if(e.includes("|"))return k(t.union(w(e,r=>r==="|").map(r=>c(r)),n));if(e.includes("&"))return k(t.union(w(e,r=>r==="&").map(r=>c(r)),n));if(e.at(-1)?.type==="wrap"&&e.at(-1).style==="[]")return t.array(c(e.slice(0,-1)),n);if(e[0]==="import"&&e[2]===".")return c(e.slice(3),n);if(e.length===2&&e[1].type==="wrap"&&e[1].style==="<>"){let r=e[1].content;return Array.isArray(r)||(r=[r]),Array.isArray(r[0])||(r.some(o=>o.type==="wrap"&&o.style==="[]")||r.some(o=>o.type==="wrap"&&o.style==="<>")||r.includes("&")||r.includes("|")?r=[r]:r=r.map(o=>[o])),r=r.map(o=>c(o)),A(t.interface(e[0],{...n,options:{template:r}}))}if(e.length===3&&e[1]==="=>"){const r=!e[0].content.length||Array.isArray(e[0].content[0])?e[0].content:[e[0].content];return t.function(t.object(Object.fromEntries(r.map(o=>[o[0],c(o.slice(2))]))),c(e[2]))}return c(e[0],n)}if(typeof e=="object"&&e!==null&&e.type==="wrap"){if(["''",'""'].includes(e.style))return t.string({...n,enum:[e.content]});if(e.style==="{}"){const r=!e.content.length||Array.isArray(e.content[0])?e.content:[e.content];return t.object(Object.fromEntries(r.filter(o=>typeof o[0]=="string").map(o=>[o[0],o[1]==="?"?c(o.slice(3),{optional:!0}):c(o.slice(2))])),n)}if(e.style==="[]")return e.content[1]===":"?t.array(c(e.content.slice(2)),n):t.array(c(e.content),n);if(e.style==="()")return c(e.content,n)}return console.log("Unknown element"),console.log(e),t.unknown()}function w(e,n){const r=[[]];for(const o of e)n(o)?r.push([]):r[r.length-1].push(o);return r}function q(e){try{if(/^[A-Za-z]+\??:/.test(e)){const[,n,r,o]=e.match(/([A-Za-z]+)(\??):(.*)/),i=c(j(b(o)));return i.name=n,r==="?"&&(i.optional=!0),i}return c(j(b(e)))}catch(n){return console.error("Failed to parse type",e),console.error(n),t.unknown()}}function a(e,n){if(e=n(e)||e,e.type===f.object)for(const r in e.properties)e.properties[r]=a(e.properties[r],n);if(e.type===f.array&&(e.items=a(e.items,n)),e.type===f.function&&(e.inputs=a(e.inputs,n),e.output=a(e.output,n)),e.type===f.union)for(const r in e.elements)e.elements[r]=a(e.elements[r],n);return e}exports.F=E;exports.J=O;exports.T=F;exports._=v;exports.d=a;exports.i=f;exports.ot=y;exports.ot$1=q;exports.u=t;exports.x=h;
5
+ `).trim(),e.trim()):e}function k(e){e.elements.find(i=>[f.undefined,f.void].includes(i.type))&&(e.optional=!0,e.elements=e.elements.filter(i=>![f.undefined,f.void].includes(i.type)));const n=e.elements.filter(i=>i.type===f.union);if(n.length>0){e.elements=e.elements.filter(i=>i.type!==f.union);for(const i of n)e.elements.push(...i.elements)}const r=e.elements.filter(i=>i.type===f.string);if(r.length>1){const i=[];let s=!1;for(const u of r)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.string),s?e.elements.push(t.string()):e.elements.push(t.string({enum:i}))}const o=e.elements.filter(i=>i.type===f.number);if(o.length>1){const i=[];let s=!1;for(const u of o)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.number),s?e.elements.push(t.number()):e.elements.push(t.number({enum:i}))}if(e.elements.length===1){const i=e.elements[0];return i.optional=e.optional,i}return e.elements.length===0?t.void():e}function A(e){return e.className==="Array"?t.array(e.options.template[0]):e.className==="keyof"?t.string():e.className==="Record"?t.object({}):e.className==="PropertyKey"?t.union([t.string(),t.number()]):["Promise","Partial","Required"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0]):["Omit","Pick"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0],e.options.template[1]?.enum):e}function c(e,n={}){if(typeof e=="string")return e==="string"?t.string(n):e==="number"?t.number(n):e==="boolean"?t.boolean(n):e==="undefined"?t.void(n):["unknown","any"].includes(e)?t.unknown(n):["undefined","null"].includes(e)?t.undefined(n):A(t.interface(e,n));if(Array.isArray(e)){if(e[0]==="readonly"&&e.shift(),e.length===1)return c(e[0],n);if(e.includes("|"))return k(t.union(w(e,r=>r==="|").map(r=>c(r)),n));if(e.includes("&"))return k(t.union(w(e,r=>r==="&").map(r=>c(r)),n));if(e.at(-1)?.type==="wrap"&&e.at(-1).style==="[]")return t.array(c(e.slice(0,-1)),n);if(e[0]==="import"&&e[2]===".")return c(e.slice(3),n);if(e.length===2&&e[1].type==="wrap"&&e[1].style==="<>"){let r=e[1].content;return Array.isArray(r)||(r=[r]),Array.isArray(r[0])||(r.some(o=>o.type==="wrap"&&o.style==="[]")||r.some(o=>o.type==="wrap"&&o.style==="<>")||r.includes("&")||r.includes("|")?r=[r]:r=r.map(o=>[o])),r=r.map(o=>c(o)),A(t.interface(e[0],{...n,options:{template:r}}))}if(e.length===3&&e[1]==="=>"){const r=!e[0].content.length||Array.isArray(e[0].content[0])?e[0].content:[e[0].content];return t.function(t.object(Object.fromEntries(r.map(o=>[o[0],c(o.slice(2))]))),c(e[2]))}return c(e[0],n)}if(typeof e=="object"&&e!==null&&e.type==="wrap"){if(["''",'""'].includes(e.style))return t.string({...n,enum:[e.content]});if(e.style==="{}"){const r=!e.content.length||Array.isArray(e.content[0])?e.content:[e.content];return t.object(Object.fromEntries(r.filter(o=>typeof o[0]=="string").map(o=>[o[0],o[1]==="?"?c(o.slice(3),{optional:!0}):c(o.slice(2))])),n)}if(e.style==="[]")return e.content[1]===":"?t.array(c(e.content.slice(2)),n):t.array(c(e.content),n);if(e.style==="()")return c(e.content,n)}return console.log("Unknown element"),console.log(e),t.unknown()}function w(e,n){const r=[[]];for(const o of e)n(o)?r.push([]):r[r.length-1].push(o);return r}function F(e){try{if(/^[A-Za-z]+\??:/.test(e)){const[,n,r,o]=e.match(/([A-Za-z]+)(\??):(.*)/),i=c(j(b(o)));return i.name=n,r==="?"&&(i.optional=!0),i}return c(j(b(e)))}catch(n){return console.error("Failed to parse type",e),console.error(n),t.unknown()}}function a(e,n){if(e=n(e)||e,e.type===f.object)for(const r in e.properties)e.properties[r]=a(e.properties[r],n);if(e.type===f.array&&(e.items=a(e.items,n)),e.type===f.function&&(e.inputs=a(e.inputs,n),e.output=a(e.output,n)),e.type===f.union)for(const r in e.elements)e.elements[r]=a(e.elements[r],n);return e}exports.F=E;exports.J=O;exports.T=J;exports._=v;exports.i=f;exports.m=a;exports.ot=y;exports.ot$1=F;exports.u=t;exports.x=h;
@@ -17,7 +17,7 @@ function d(e, n) {
17
17
  Object.entries(e).filter(([r, o]) => n({ key: r, value: o }))
18
18
  ) : {};
19
19
  }
20
- function Z(e) {
20
+ function q(e) {
21
21
  e = x(e);
22
22
  for (const r in e)
23
23
  n(e, r);
@@ -123,7 +123,7 @@ const t = {
123
123
  }
124
124
  };
125
125
  var z = /* @__PURE__ */ ((e) => (e.function = "function", e.macro = "macro", e.operation = "operation", e))(z || {}), W = /* @__PURE__ */ ((e) => (e.Frontend = "frontend", e.Backend = "backend", e.Desktop = "desktop", e.Shared = "shared", e))(W || {});
126
- function q(e) {
126
+ function J(e) {
127
127
  return e;
128
128
  }
129
129
  function b(e) {
@@ -243,7 +243,7 @@ function h(e) {
243
243
  return { name: o, type: "enum", options: s };
244
244
  }
245
245
  if (typeof n == "string" && n.startsWith("/*"))
246
- return { type: "comment", content: F(n) };
246
+ return { type: "comment", content: Z(n) };
247
247
  for (const o of v)
248
248
  if (n === o[0])
249
249
  return {
@@ -256,7 +256,7 @@ function h(e) {
256
256
  function m(e) {
257
257
  return Array.isArray(e) ? e.length === 1 ? m(e[0]) : e.map((n) => m(n)) : typeof e == "object" && e !== null ? y(e, ({ value: n }) => m(n)) : e;
258
258
  }
259
- function F(e) {
259
+ function Z(e) {
260
260
  return e = e.trim(), e.startsWith("/**") && e.endsWith("*/") ? (e = e.slice(3, -2).split(`
261
261
  `).map((n) => {
262
262
  const r = n.trim();
@@ -360,7 +360,7 @@ function w(e, n) {
360
360
  n(o) ? r.push([]) : r[r.length - 1].push(o);
361
361
  return r;
362
362
  }
363
- function J(e) {
363
+ function L(e) {
364
364
  try {
365
365
  if (/^[A-Za-z]+\??:/.test(e)) {
366
366
  const [, n, r, o] = e.match(/([A-Za-z]+)(\??):(.*)/), i = c(j(b(o)));
@@ -381,13 +381,13 @@ function l(e, n) {
381
381
  return e;
382
382
  }
383
383
  export {
384
- Z as F,
384
+ q as F,
385
385
  W as J,
386
- q as T,
386
+ J as T,
387
387
  z as _,
388
- J as a,
389
- l as d,
388
+ L as a,
390
389
  f as i,
390
+ l as m,
391
391
  y as o,
392
392
  t as u,
393
393
  g as x
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-DmZsz62R.cjs");var n=(i=>(i.Color="color",i.FontSize="font-size",i.FontWeight="font-weight",i.FontFamily="font-family",i.Length="length",i.Time="time",i))(n||{});function e(i){return i}async function r(i,o){return typeof i=="function"?i({app:o.app,config:o.config,internal:o.internal,mode:o.mode||"editor"}):i}exports.ELogicScope=t.J;exports.ELogicType=t._;exports.EVarType=t.i;exports.LogicType=t.u;exports.LogicUtil=t.x;exports.makeLogicNode=t.T;exports.ETokenType=n;exports.getPluginParam=r;exports.makePlugin=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-4fa4mAH8.cjs");var n=(i=>(i.Color="color",i.FontSize="font-size",i.FontWeight="font-weight",i.FontFamily="font-family",i.Length="length",i.Time="time",i))(n||{});function e(i){return i}async function r(i,o){return typeof i=="function"?i({app:o.app,config:o.config,internal:o.internal,mode:o.mode||"editor"}):i}exports.ELogicScope=t.J;exports.ELogicType=t._;exports.EVarType=t.i;exports.LogicType=t.u;exports.LogicUtil=t.x;exports.makeLogicNode=t.T;exports.ETokenType=n;exports.getPluginParam=r;exports.makePlugin=e;
package/dist/index.d.ts CHANGED
@@ -350,16 +350,19 @@ declare type TCanvasExport = {
350
350
  };
351
351
 
352
352
  export declare type TComponent<TProps extends Record<string, TSchema> = Record<string, TSchema>> = {
353
+ build?: {
354
+ import?: Array<{
355
+ name: string;
356
+ target: string;
357
+ }>;
358
+ name?: string;
359
+ };
353
360
  component: Component;
354
361
  documentation?: {
355
362
  description?: string;
356
363
  link?: string;
357
364
  };
358
365
  emits?: Record<string, TSchema>;
359
- import?: Array<{
360
- name: string;
361
- target: string;
362
- }>;
363
366
  models?: Record<string, TSchema>;
364
367
  name: string;
365
368
  properties?: TProps;
@@ -477,7 +480,7 @@ declare type TExportNodeResult = {
477
480
  types: Record<string, TSchema>;
478
481
  };
479
482
 
480
- declare type TFileExport = (TFolderExport | TComponentExport | TConfigExport | TCronExport | TDatabaseExport | TRouteExport | TScriptExport | TStoreExport | TTextExport | TTypeExport | TMediaExport) & {
483
+ export declare type TFileExport = (TFolderExport | TComponentExport | TConfigExport | TCronExport | TDatabaseExport | TRouteExport | TScriptExport | TStoreExport | TTextExport | TTypeExport | TMediaExport) & {
481
484
  isEditing?: boolean;
482
485
  };
483
486
 
@@ -772,8 +775,9 @@ export declare type TPlugin<TConfig extends TSchema = TSchema, TInternal = unkno
772
775
  editor?: {
773
776
  components?: TOption<TEnv<TConfig, TInternal>, Array<TComponent>>;
774
777
  nodes?: TOption<TEnv<TConfig, TInternal>, Array<TLogicNode>>;
778
+ templates?: TOption<TEnv<TConfig, TInternal>, Array<TTemplate>>;
775
779
  tokens?: TOption<TEnv<TConfig, TInternal>, Array<TToken>>;
776
- wrapper?: TOption<TEnv<TConfig, TInternal>, Component>;
780
+ wrapper?: TOption<TEnv<TConfig, TInternal>, TComponent>;
777
781
  };
778
782
  icon: string;
779
783
  id: string;
@@ -852,6 +856,12 @@ declare interface TString {
852
856
  static: string;
853
857
  }
854
858
 
859
+ export declare type TTemplate = {
860
+ name: string;
861
+ preview?: string;
862
+ template: TFileExport;
863
+ };
864
+
855
865
  declare type TTextExport = {
856
866
  name: string;
857
867
  type: EElementType.Text;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { J as e, _ as f, i as g, u as l, x as m, T as u } from "./index-CxGB_fZK.js";
1
+ import { J as e, _ as f, i as g, u as l, x as m, T as u } from "./index-QMG2c0JW.js";
2
2
  var t = /* @__PURE__ */ ((i) => (i.Color = "color", i.FontSize = "font-size", i.FontWeight = "font-weight", i.FontFamily = "font-family", i.Length = "length", i.Time = "time", i))(t || {});
3
3
  function n(i) {
4
4
  return i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luna-park/plugin",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "private": false,
5
5
  "description": "Plugin helper for Luna Park.",
6
6
  "homepage": "https://luna-park.app",
@@ -35,21 +35,21 @@
35
35
  "dist/**"
36
36
  ],
37
37
  "devDependencies": {
38
- "@fastify/cors": "^11.1.0",
38
+ "@fastify/cors": "^11.2.0",
39
39
  "@fastify/static": "^8.3.0",
40
40
  "@fortawesome/fontawesome-svg-core": "^7.1.0",
41
41
  "@luna-park/eslint-config": "^1.0.2",
42
- "@microsoft/api-extractor": "^7.55.0",
43
- "@vitest/ui": "^4.0.12",
42
+ "@microsoft/api-extractor": "^7.55.2",
43
+ "@vitest/ui": "^4.0.15",
44
44
  "eslint": "^9.39.1",
45
45
  "fastify": "^5.6.2",
46
46
  "rimraf": "^6.1.2",
47
47
  "typescript": "^5.9.3",
48
- "typescript-eslint": "^8.47.0",
48
+ "typescript-eslint": "^8.49.0",
49
49
  "unplugin-dts": "1.0.0-beta.6",
50
- "vite": "^7.2.4",
51
- "vitest": "^4.0.12",
52
- "vue": "^3.5.24",
50
+ "vite": "^7.2.7",
51
+ "vitest": "^4.0.15",
52
+ "vue": "^3.5.25",
53
53
  "@luna-park/utils": "^2.0.0",
54
54
  "@luna-park/logicnodes": "^2.0.0",
55
55
  "@luna-park/shared": "^1.0.0"