@luna-park/plugin 1.2.0 → 1.3.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/README.md +6 -6
- package/bin/preview.js +1 -1
- package/dist/chunk-rCEYsGS8.cjs +1 -0
- package/dist/dist-BUZt4gnZ.js +421 -0
- package/dist/dist-BkSFkjuo.cjs +5 -0
- package/dist/extractor.cjs +9 -11
- package/dist/extractor.d.ts +21 -19
- package/dist/extractor.js +483 -548
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +738 -235
- package/dist/index.js +2960 -34
- package/dist/plugin.css +2 -0
- package/dist/preview.cjs +1 -1
- package/dist/preview.js +27 -37
- package/package.json +25 -23
- package/dist/index-CWrYVK_G.cjs +0 -5
- package/dist/index-Dv9uuje9.js +0 -410
package/dist/plugin.css
ADDED
package/dist/preview.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunk-rCEYsGS8.cjs`);let t=require(`path`),n=require(`fs`),r=require(`@fastify/cors`);r=e.n(r);let i=require(`@fastify/static`);i=e.n(i);let a=require(`fastify`);a=e.n(a);function o(e,t){return e.replace(/\bimport\s+(.*?)\s+from\s+['"]([^.'/][^'"]*)['"];/g,(e,n,r)=>t.includes(r)?e:`import ${n} from 'https://esm.sh/${r}';`).replace(/\bimport\s+['"]([^.'/][^'"]*)['"];/g,(e,n)=>t.includes(n)?e:`import 'https://esm.sh/${n}';`)}async function s(e){let s=(0,a.default)({logger:!1});s.register(r.default,{origin:[`https://luna-park.app`,/localhost:[0-9]+/,/127\.0\.0\.1:[0-9]+/]}),s.addHook(`onRequest`,async(r,i)=>{let a=r.url===`/`?`/index.js`:r.url,s=(0,t.join)(e.dist,a);if(!(0,n.existsSync)(s)&&!(0,t.extname)(r.url)&&(s=(0,t.join)(e.dist,`index.js`)),(0,n.existsSync)(s)&&(0,t.extname)(s)===`.js`){let t=o((0,n.readFileSync)(s,`utf-8`),e.externals).replaceAll(`process.env.NODE_ENV`,JSON.stringify(`development`));return i.type(`application/javascript`).send(t),i}}),s.register(i.default,{prefix:`/`,root:e.dist}),await s.listen({host:`127.0.0.1`,port:e.port}),console.log(`Preview server started at http://127.0.0.1:${e.port}`)}exports.startPreviewServer=s;
|
package/dist/preview.js
CHANGED
|
@@ -1,39 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
/import\s+(.*?)\s+from\s+['"]([^.'/][^'"]*)['"]/g,
|
|
9
|
-
(e, s, i) => r.includes(i) ? e : `import ${s} from 'https://esm.sh/${i}'`
|
|
10
|
-
).replace(
|
|
11
|
-
/import\s+['"]([^.'/][^'"]*)['"]/g,
|
|
12
|
-
(e, s) => r.includes(s) ? e : `import 'https://esm.sh/${s}'`
|
|
13
|
-
);
|
|
1
|
+
import { extname, join } from "path";
|
|
2
|
+
import { existsSync, readFileSync } from "fs";
|
|
3
|
+
import fastifyCors from "@fastify/cors";
|
|
4
|
+
import fastifyStatic from "@fastify/static";
|
|
5
|
+
import Fastify from "fastify";
|
|
6
|
+
function transformImports(e, n) {
|
|
7
|
+
return e.replace(/\bimport\s+(.*?)\s+from\s+['"]([^.'/][^'"]*)['"];/g, (e, r, i) => n.includes(i) ? e : `import ${r} from 'https://esm.sh/${i}';`).replace(/\bimport\s+['"]([^.'/][^'"]*)['"];/g, (e, r) => n.includes(r) ? e : `import 'https://esm.sh/${r}';`);
|
|
14
8
|
}
|
|
15
|
-
async function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
root: t.dist
|
|
35
|
-
}), await r.listen({ host: "127.0.0.1", port: t.port }), console.log(`Preview server started at http://127.0.0.1:${t.port}`);
|
|
9
|
+
async function startPreviewServer(c) {
|
|
10
|
+
let l = Fastify({ logger: !1 });
|
|
11
|
+
l.register(fastifyCors, { origin: [
|
|
12
|
+
"https://luna-park.app",
|
|
13
|
+
/localhost:[0-9]+/,
|
|
14
|
+
/127\.0\.0\.1:[0-9]+/
|
|
15
|
+
] }), l.addHook("onRequest", async (a, o) => {
|
|
16
|
+
let s = a.url === "/" ? "/index.js" : a.url, l = join(c.dist, s);
|
|
17
|
+
if (!existsSync(l) && !extname(a.url) && (l = join(c.dist, "index.js")), existsSync(l) && extname(l) === ".js") {
|
|
18
|
+
let e = transformImports(readFileSync(l, "utf-8"), c.externals).replaceAll("process.env.NODE_ENV", JSON.stringify("development"));
|
|
19
|
+
return o.type("application/javascript").send(e), o;
|
|
20
|
+
}
|
|
21
|
+
}), l.register(fastifyStatic, {
|
|
22
|
+
prefix: "/",
|
|
23
|
+
root: c.dist
|
|
24
|
+
}), await l.listen({
|
|
25
|
+
host: "127.0.0.1",
|
|
26
|
+
port: c.port
|
|
27
|
+
}), console.log(`Preview server started at http://127.0.0.1:${c.port}`);
|
|
36
28
|
}
|
|
37
|
-
export {
|
|
38
|
-
w as startPreviewServer
|
|
39
|
-
};
|
|
29
|
+
export { startPreviewServer };
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luna-park/plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Plugin helper for Luna Park.",
|
|
6
6
|
"homepage": "https://luna-park.app",
|
|
7
|
-
"bin": {
|
|
8
|
-
"luna-preview": "./bin/preview.js"
|
|
9
|
-
},
|
|
10
7
|
"repository": {
|
|
11
8
|
"type": "git",
|
|
12
9
|
"url": "https://github.com/lunapark/lunapark"
|
|
@@ -26,42 +23,47 @@
|
|
|
26
23
|
"types": "./dist/extractor.d.ts",
|
|
27
24
|
"require": "./dist/extractor.cjs",
|
|
28
25
|
"import": "./dist/extractor.js"
|
|
29
|
-
}
|
|
26
|
+
},
|
|
27
|
+
"./index.css": "./dist/plugin.css"
|
|
30
28
|
},
|
|
31
29
|
"main": "./dist/index.umd.cjs",
|
|
32
30
|
"module": "./dist/index.js",
|
|
33
31
|
"types": "./dist/index.d.ts",
|
|
32
|
+
"bin": {
|
|
33
|
+
"luna-preview": "./bin/preview.js"
|
|
34
|
+
},
|
|
34
35
|
"files": [
|
|
35
36
|
"dist/**"
|
|
36
37
|
],
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@fastify/cors": "^11.2.0",
|
|
39
|
-
"@fastify/static": "^
|
|
40
|
-
"@fortawesome/fontawesome-svg-core": "^7.
|
|
41
|
-
"@luna-park/eslint-config": "^1.
|
|
42
|
-
"@microsoft/api-extractor": "^7.
|
|
43
|
-
"@
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
40
|
+
"@fastify/static": "^9.0.0",
|
|
41
|
+
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
42
|
+
"@luna-park/eslint-config": "^1.2.1",
|
|
43
|
+
"@microsoft/api-extractor": "^7.57.3",
|
|
44
|
+
"@vitejs/plugin-vue": "^6.0.4",
|
|
45
|
+
"@vitest/ui": "^4.0.18",
|
|
46
|
+
"eslint": "^10.0.1",
|
|
47
|
+
"fastify": "^5.7.4",
|
|
48
|
+
"rimraf": "^6.1.3",
|
|
47
49
|
"typescript": "^5.9.3",
|
|
48
|
-
"typescript-eslint": "^8.
|
|
50
|
+
"typescript-eslint": "^8.56.0",
|
|
49
51
|
"unplugin-dts": "1.0.0-beta.6",
|
|
50
|
-
"vite": "^7.
|
|
51
|
-
"vitest": "^4.0.
|
|
52
|
-
"vue": "^3.5.
|
|
52
|
+
"vite": "^7.3.1",
|
|
53
|
+
"vitest": "^4.0.18",
|
|
54
|
+
"vue": "^3.5.28",
|
|
53
55
|
"@luna-park/logicnodes": "^2.0.0",
|
|
54
56
|
"@luna-park/shared": "^1.0.0",
|
|
55
57
|
"@luna-park/utils": "^2.0.0"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
|
-
"@fastify/cors": "^11.
|
|
59
|
-
"@fastify/static": "^
|
|
60
|
-
"@fortawesome/fontawesome-svg-core": "^7.
|
|
61
|
-
"fastify": "^5.
|
|
60
|
+
"@fastify/cors": "^11.2.0",
|
|
61
|
+
"@fastify/static": "^9.0.0",
|
|
62
|
+
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
63
|
+
"fastify": "^5.7.4",
|
|
62
64
|
"typescript": "^5.9.3",
|
|
63
|
-
"vite": "^7.
|
|
64
|
-
"vue": "^3.5.
|
|
65
|
+
"vite": "^7.3.1",
|
|
66
|
+
"vue": "^3.5.28"
|
|
65
67
|
},
|
|
66
68
|
"scripts": {
|
|
67
69
|
"build": "rimraf dist && vite build",
|
package/dist/index-CWrYVK_G.cjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";function E(e){if(typeof e!="object")return e;try{return JSON.parse(JSON.stringify(e))}catch{return structuredClone(e)}}function h(e){if(Array.isArray(e))return e.map(h);if(typeof e!="object")return e;const n={};for(const[r,o]of Object.entries(e)){if(typeof o=="function"){n[r]=o;continue}n[r]=h(o)}return n}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 J(e){e=E(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"})},d={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 O=(e=>(e.function="function",e.macro="macro",e.operation="operation",e))(O||{}),N=(e=>(e.Frontend="frontend",e.Backend="backend",e.Desktop="desktop",e.Shared="shared",e))(N||{});function Z(e){return e}function j(e){const n=[];for(e=e.replaceAll(/ +/g," "),e=e.replaceAll(/\s*\n\s*/g,`
|
|
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 x=[["(",")"],["[","]"],["{","}"],["<",">"],["'","'"],['"','"']];function k(e){return m(a(e,";"))}function p(e,n,r=1){const o=[];for(x.find(i=>i[1]===n)?.[0];e.length&&(e[0],!(e[0]===n&&(r--,r<=0)));){const i=b(e);if(o.push(i),r===0&&typeof i=="object"&&i.type==="wrap"&&i.style.endsWith(n))break}return e.shift(),o}function q(e,n){for(;e.length;){if(e[0]===n){e.shift();break}e.shift()}}function a(e,n){const r=[[]];for(;e.length;){if(e[0]===n){r.push([]),e.shift();continue}r.at(-1).push(b(e))}return r.filter(o=>o.length)}function b(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 q(e,";"),b(e)}if(n==="declare"&&(n=e.shift()),n==="namespace"){const o=e.shift();e.shift();const i=a(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=a(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=a(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[z,W]=u.split("=");return[JSON.parse(W),z]}return[o,o]}));return{name:o,type:"enum",options:s}}if(typeof n=="string"&&n.startsWith("/*"))return{type:"comment",content:F(n)};for(const o of x)if(n===o[0])return{type:"wrap",content:a(p(e,o[1]),";").map(i=>a(i,",")).map(i=>a(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 F(e){return e=e.trim(),e.startsWith("/**")&&e.endsWith("*/")?(e=e.slice(3,-2).split(`
|
|
4
|
-
`).map(n=>{const r=n.trim();return r.startsWith("* ")?r.slice(2):r}).join(`
|
|
5
|
-
`).trim(),e.trim()):e}function A(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 w(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)?d[e.className.toLocaleLowerCase()](e.options.template[0]):["Omit","Pick"].includes(e.className)?d[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):w(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 A(t.union(v(e,r=>r==="|").map(r=>c(r)),n));if(e.includes("&"))return A(t.union(v(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)),w(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 v(e,n){const r=[[]];for(const o of e)n(o)?r.push([]):r[r.length-1].push(o);return r}function L(e){try{if(/^[A-Za-z]+\??:/.test(e)){const[,n,r,o]=e.match(/([A-Za-z]+)(\??):(.*)/),i=c(k(j(o)));return i.name=n,r==="?"&&(i.optional=!0),i}return c(k(j(e)))}catch(n){return console.error("Failed to parse type",e),console.error(n),t.unknown()}}function l(e,n){if(e=n(e)||e,e.type===f.object)for(const r in e.properties)e.properties[r]=l(e.properties[r],n);if(e.type===f.array&&(e.items=l(e.items,n)),e.type===f.function&&(e.inputs=l(e.inputs,n),e.output=l(e.output,n)),e.type===f.union)for(const r in e.elements)e.elements[r]=l(e.elements[r],n);return e}exports.F=J;exports.J=N;exports.T=Z;exports._=O;exports.i=f;exports.m=l;exports.ot=y;exports.ot$1=L;exports.u=t;exports.x=d;exports.y=h;
|
package/dist/index-Dv9uuje9.js
DELETED
|
@@ -1,410 +0,0 @@
|
|
|
1
|
-
function z(e) {
|
|
2
|
-
if (typeof e != "object")
|
|
3
|
-
return e;
|
|
4
|
-
try {
|
|
5
|
-
return JSON.parse(JSON.stringify(e));
|
|
6
|
-
} catch {
|
|
7
|
-
return structuredClone(e);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function d(e) {
|
|
11
|
-
if (Array.isArray(e))
|
|
12
|
-
return e.map(d);
|
|
13
|
-
if (typeof e != "object")
|
|
14
|
-
return e;
|
|
15
|
-
const n = {};
|
|
16
|
-
for (const [r, o] of Object.entries(e)) {
|
|
17
|
-
if (typeof o == "function") {
|
|
18
|
-
n[r] = o;
|
|
19
|
-
continue;
|
|
20
|
-
}
|
|
21
|
-
n[r] = d(o);
|
|
22
|
-
}
|
|
23
|
-
return n;
|
|
24
|
-
}
|
|
25
|
-
function y(e, n) {
|
|
26
|
-
return e ? Object.fromEntries(
|
|
27
|
-
Object.entries(e).map(([r, o]) => [r, n({ key: r, value: o })])
|
|
28
|
-
) : {};
|
|
29
|
-
}
|
|
30
|
-
function b(e, n) {
|
|
31
|
-
return e ? Object.fromEntries(
|
|
32
|
-
Object.entries(e).filter(([r, o]) => n({ key: r, value: o }))
|
|
33
|
-
) : {};
|
|
34
|
-
}
|
|
35
|
-
function J(e) {
|
|
36
|
-
e = z(e);
|
|
37
|
-
for (const r in e)
|
|
38
|
-
n(e, r);
|
|
39
|
-
function n(r, o) {
|
|
40
|
-
if (typeof r[o] == "object") {
|
|
41
|
-
for (const i in r[o])
|
|
42
|
-
n(r[o], i);
|
|
43
|
-
Object.keys(r[o]).length === 0 && delete r[o];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return e;
|
|
47
|
-
}
|
|
48
|
-
var f = /* @__PURE__ */ ((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 || {});
|
|
49
|
-
const t = {
|
|
50
|
-
type: (e, n = {}) => ({ ...n, type: "type", target: e }),
|
|
51
|
-
array: (e, n = {}) => ({ ...n, type: "array", items: e }),
|
|
52
|
-
boolean: (e = {}) => ({
|
|
53
|
-
...e,
|
|
54
|
-
type: "boolean"
|
|
55
|
-
/* boolean */
|
|
56
|
-
}),
|
|
57
|
-
exec: (e = {}) => ({
|
|
58
|
-
...e,
|
|
59
|
-
type: "exec"
|
|
60
|
-
/* exec */
|
|
61
|
-
}),
|
|
62
|
-
function: (e = { type: "object", properties: {} }, n = {
|
|
63
|
-
type: "void"
|
|
64
|
-
/* void */
|
|
65
|
-
}, r = {}) => ({ ...r, type: "function", inputs: e, output: n }),
|
|
66
|
-
interface: (e, n = {}) => ({
|
|
67
|
-
...n,
|
|
68
|
-
type: "interface",
|
|
69
|
-
className: typeof e == "string" ? e : e.name
|
|
70
|
-
}),
|
|
71
|
-
number: (e = {}) => ({
|
|
72
|
-
...e,
|
|
73
|
-
type: "number"
|
|
74
|
-
/* number */
|
|
75
|
-
}),
|
|
76
|
-
object: (e = {}, n = {}) => ({ ...n, type: "object", properties: e }),
|
|
77
|
-
record: (e, n, r = {}) => ({ ...r, type: "record", key: e, value: n }),
|
|
78
|
-
string: (e = {}) => ({
|
|
79
|
-
...e,
|
|
80
|
-
type: "string"
|
|
81
|
-
/* string */
|
|
82
|
-
}),
|
|
83
|
-
undefined: (e = {}) => ({
|
|
84
|
-
...e,
|
|
85
|
-
type: "undefined"
|
|
86
|
-
/* undefined */
|
|
87
|
-
}),
|
|
88
|
-
union: (e, n = {}) => ({ ...n, type: "union", elements: e }),
|
|
89
|
-
unknown: (e = {}) => ({
|
|
90
|
-
...e,
|
|
91
|
-
type: "unknown"
|
|
92
|
-
/* unknown */
|
|
93
|
-
}),
|
|
94
|
-
void: (e = {}) => ({
|
|
95
|
-
...e,
|
|
96
|
-
type: "void"
|
|
97
|
-
/* void */
|
|
98
|
-
})
|
|
99
|
-
}, g = {
|
|
100
|
-
omit(e, n) {
|
|
101
|
-
return {
|
|
102
|
-
...e,
|
|
103
|
-
properties: b(
|
|
104
|
-
e.properties,
|
|
105
|
-
({ key: r }) => !n.includes(r)
|
|
106
|
-
)
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
partial(e, n = !1) {
|
|
110
|
-
return {
|
|
111
|
-
...e,
|
|
112
|
-
properties: y(
|
|
113
|
-
e.properties,
|
|
114
|
-
({ value: r }) => ({ ...r, optional: !n || !r.required })
|
|
115
|
-
)
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
pick(e, n) {
|
|
119
|
-
return {
|
|
120
|
-
...e,
|
|
121
|
-
properties: b(
|
|
122
|
-
e.properties,
|
|
123
|
-
({ key: r }) => n.includes(r)
|
|
124
|
-
)
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
promise(e) {
|
|
128
|
-
return { ...e, promise: !0 };
|
|
129
|
-
},
|
|
130
|
-
required(e) {
|
|
131
|
-
return {
|
|
132
|
-
...e,
|
|
133
|
-
properties: y(
|
|
134
|
-
e.properties,
|
|
135
|
-
({ value: n }) => ({ ...n, optional: !1 })
|
|
136
|
-
)
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
var W = /* @__PURE__ */ ((e) => (e.function = "function", e.macro = "macro", e.operation = "operation", e))(W || {}), E = /* @__PURE__ */ ((e) => (e.Frontend = "frontend", e.Backend = "backend", e.Desktop = "desktop", e.Shared = "shared", e))(E || {});
|
|
141
|
-
function L(e) {
|
|
142
|
-
return e;
|
|
143
|
-
}
|
|
144
|
-
function j(e) {
|
|
145
|
-
const n = [];
|
|
146
|
-
for (e = e.replaceAll(/ +/g, " "), e = e.replaceAll(/\s*\n\s*/g, `
|
|
147
|
-
`); e.length; ) {
|
|
148
|
-
if ([" ", `
|
|
149
|
-
`].includes(e[0])) {
|
|
150
|
-
e = e.slice(1);
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
if (e.startsWith("/*")) {
|
|
154
|
-
const i = e.indexOf("*/");
|
|
155
|
-
n.push(e.slice(0, i + 2)), e = e.slice(i + 2);
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
const r = e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];
|
|
159
|
-
if (r) {
|
|
160
|
-
e = e.slice(r.length), n.push(r);
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const o = e.match(/^([0-9]+)/)?.[0];
|
|
164
|
-
if (o) {
|
|
165
|
-
e = e.slice(o.length), n.push(o);
|
|
166
|
-
continue;
|
|
167
|
-
}
|
|
168
|
-
if (e[0] === ">" && n.at(-1) === "=") {
|
|
169
|
-
n.pop(), n.push("=>"), e = e.slice(1);
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
n.push(e[0]), e = e.slice(1);
|
|
173
|
-
}
|
|
174
|
-
return n;
|
|
175
|
-
}
|
|
176
|
-
const O = [
|
|
177
|
-
["(", ")"],
|
|
178
|
-
["[", "]"],
|
|
179
|
-
["{", "}"],
|
|
180
|
-
["<", ">"],
|
|
181
|
-
["'", "'"],
|
|
182
|
-
['"', '"']
|
|
183
|
-
];
|
|
184
|
-
function k(e) {
|
|
185
|
-
return m(a(e, ";"));
|
|
186
|
-
}
|
|
187
|
-
function p(e, n, r = 1) {
|
|
188
|
-
const o = [];
|
|
189
|
-
for (O.find((i) => i[1] === n)?.[0]; e.length && (e[0], !(e[0] === n && (r--, r <= 0))); ) {
|
|
190
|
-
const i = h(e);
|
|
191
|
-
if (o.push(i), r === 0 && typeof i == "object" && i.type === "wrap" && i.style.endsWith(n))
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
return e.shift(), o;
|
|
195
|
-
}
|
|
196
|
-
function Z(e, n) {
|
|
197
|
-
for (; e.length; ) {
|
|
198
|
-
if (e[0] === n) {
|
|
199
|
-
e.shift();
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
e.shift();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
function a(e, n) {
|
|
206
|
-
const r = [[]];
|
|
207
|
-
for (; e.length; ) {
|
|
208
|
-
if (e[0] === n) {
|
|
209
|
-
r.push([]), e.shift();
|
|
210
|
-
continue;
|
|
211
|
-
}
|
|
212
|
-
r.at(-1).push(h(e));
|
|
213
|
-
}
|
|
214
|
-
return r.filter((o) => o.length);
|
|
215
|
-
}
|
|
216
|
-
function h(e) {
|
|
217
|
-
let n = e.shift(), r = !1;
|
|
218
|
-
if (n === "export") {
|
|
219
|
-
if (r = !0, n = e.shift(), n === "=")
|
|
220
|
-
return { type: "export", content: e.shift() };
|
|
221
|
-
if (n === "as")
|
|
222
|
-
return Z(e, ";"), h(e);
|
|
223
|
-
}
|
|
224
|
-
if (n === "declare" && (n = e.shift()), n === "namespace") {
|
|
225
|
-
const o = e.shift();
|
|
226
|
-
e.shift();
|
|
227
|
-
const i = a(p(e, "}", 0), ";");
|
|
228
|
-
return e.unshift(";"), { name: o, type: n, content: i, export: r };
|
|
229
|
-
}
|
|
230
|
-
if (n === "function") {
|
|
231
|
-
const o = e.shift(), i = e.shift(), s = { name: o, type: n };
|
|
232
|
-
i === "<" && (s.template = p(e, ">"), e.shift());
|
|
233
|
-
const u = a(p(e, ")", 0), ",");
|
|
234
|
-
return s.export = r, s.params = u, e[0] === ":" && (e.shift(), s.returns = p(e, ";")), e.unshift(";"), s;
|
|
235
|
-
}
|
|
236
|
-
if (n === "interface") {
|
|
237
|
-
const o = e.shift();
|
|
238
|
-
e.shift();
|
|
239
|
-
const i = a(p(e, "}", 0), ";");
|
|
240
|
-
return e.unshift(";"), { name: o, type: "interface", content: i };
|
|
241
|
-
}
|
|
242
|
-
if (n === "type" && /^[A-Za-z0-9]*$/.test(e[0])) {
|
|
243
|
-
const o = e.shift(), i = e.shift(), s = { name: o, type: n };
|
|
244
|
-
return i === "<" && (s.template = p(e, ">"), e.shift()), s.content = p(e, ";"), e.unshift(";"), s;
|
|
245
|
-
}
|
|
246
|
-
if (n === "enum") {
|
|
247
|
-
const o = e.shift();
|
|
248
|
-
e.shift();
|
|
249
|
-
const i = p(e, "}");
|
|
250
|
-
e.unshift(";");
|
|
251
|
-
const s = Object.fromEntries(i.join("").split(",").filter((u) => u.trim()).map((u) => {
|
|
252
|
-
if (u.includes("=")) {
|
|
253
|
-
const [N, x] = u.split("=");
|
|
254
|
-
return [JSON.parse(x), N];
|
|
255
|
-
}
|
|
256
|
-
return [o, o];
|
|
257
|
-
}));
|
|
258
|
-
return { name: o, type: "enum", options: s };
|
|
259
|
-
}
|
|
260
|
-
if (typeof n == "string" && n.startsWith("/*"))
|
|
261
|
-
return { type: "comment", content: q(n) };
|
|
262
|
-
for (const o of O)
|
|
263
|
-
if (n === o[0])
|
|
264
|
-
return {
|
|
265
|
-
type: "wrap",
|
|
266
|
-
content: a(p(e, o[1]), ";").map((i) => a(i, ",")).map((i) => a(i, "|")),
|
|
267
|
-
style: o.join("")
|
|
268
|
-
};
|
|
269
|
-
return n;
|
|
270
|
-
}
|
|
271
|
-
function m(e) {
|
|
272
|
-
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;
|
|
273
|
-
}
|
|
274
|
-
function q(e) {
|
|
275
|
-
return e = e.trim(), e.startsWith("/**") && e.endsWith("*/") ? (e = e.slice(3, -2).split(`
|
|
276
|
-
`).map((n) => {
|
|
277
|
-
const r = n.trim();
|
|
278
|
-
return r.startsWith("* ") ? r.slice(2) : r;
|
|
279
|
-
}).join(`
|
|
280
|
-
`).trim(), e.trim()) : e;
|
|
281
|
-
}
|
|
282
|
-
function A(e) {
|
|
283
|
-
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)));
|
|
284
|
-
const n = e.elements.filter((i) => i.type === f.union);
|
|
285
|
-
if (n.length > 0) {
|
|
286
|
-
e.elements = e.elements.filter((i) => i.type !== f.union);
|
|
287
|
-
for (const i of n)
|
|
288
|
-
e.elements.push(...i.elements);
|
|
289
|
-
}
|
|
290
|
-
const r = e.elements.filter((i) => i.type === f.string);
|
|
291
|
-
if (r.length > 1) {
|
|
292
|
-
const i = [];
|
|
293
|
-
let s = !1;
|
|
294
|
-
for (const u of r)
|
|
295
|
-
u.enum ? i.push(...u.enum) : s = !0;
|
|
296
|
-
e.elements = e.elements.filter((u) => u.type !== f.string), s ? e.elements.push(t.string()) : e.elements.push(t.string({ enum: i }));
|
|
297
|
-
}
|
|
298
|
-
const o = e.elements.filter((i) => i.type === f.number);
|
|
299
|
-
if (o.length > 1) {
|
|
300
|
-
const i = [];
|
|
301
|
-
let s = !1;
|
|
302
|
-
for (const u of o)
|
|
303
|
-
u.enum ? i.push(...u.enum) : s = !0;
|
|
304
|
-
e.elements = e.elements.filter((u) => u.type !== f.number), s ? e.elements.push(t.number()) : e.elements.push(t.number({ enum: i }));
|
|
305
|
-
}
|
|
306
|
-
if (e.elements.length === 1) {
|
|
307
|
-
const i = e.elements[0];
|
|
308
|
-
return i.optional = e.optional, i;
|
|
309
|
-
}
|
|
310
|
-
return e.elements.length === 0 ? t.void() : e;
|
|
311
|
-
}
|
|
312
|
-
function w(e) {
|
|
313
|
-
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([
|
|
314
|
-
t.string(),
|
|
315
|
-
t.number()
|
|
316
|
-
]) : ["Promise", "Partial", "Required"].includes(e.className) ? g[e.className.toLocaleLowerCase()](e.options.template[0]) : ["Omit", "Pick"].includes(e.className) ? g[e.className.toLocaleLowerCase()](e.options.template[0], e.options.template[1]?.enum) : e;
|
|
317
|
-
}
|
|
318
|
-
function c(e, n = {}) {
|
|
319
|
-
if (typeof e == "string")
|
|
320
|
-
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) : w(t.interface(e, n));
|
|
321
|
-
if (Array.isArray(e)) {
|
|
322
|
-
if (e[0] === "readonly" && e.shift(), e.length === 1)
|
|
323
|
-
return c(e[0], n);
|
|
324
|
-
if (e.includes("|"))
|
|
325
|
-
return A(t.union(
|
|
326
|
-
v(e, (r) => r === "|").map((r) => c(r)),
|
|
327
|
-
n
|
|
328
|
-
));
|
|
329
|
-
if (e.includes("&"))
|
|
330
|
-
return A(t.union(
|
|
331
|
-
v(e, (r) => r === "&").map((r) => c(r)),
|
|
332
|
-
n
|
|
333
|
-
));
|
|
334
|
-
if (e.at(-1)?.type === "wrap" && e.at(-1).style === "[]")
|
|
335
|
-
return t.array(c(e.slice(0, -1)), n);
|
|
336
|
-
if (e[0] === "import" && e[2] === ".")
|
|
337
|
-
return c(e.slice(3), n);
|
|
338
|
-
if (e.length === 2 && e[1].type === "wrap" && e[1].style === "<>") {
|
|
339
|
-
let r = e[1].content;
|
|
340
|
-
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)), w(t.interface(e[0], { ...n, options: { template: r } }));
|
|
341
|
-
}
|
|
342
|
-
if (e.length === 3 && e[1] === "=>") {
|
|
343
|
-
const r = !e[0].content.length || Array.isArray(e[0].content[0]) ? e[0].content : [e[0].content];
|
|
344
|
-
return t.function(
|
|
345
|
-
t.object(
|
|
346
|
-
Object.fromEntries(r.map((o) => [o[0], c(o.slice(2))]))
|
|
347
|
-
),
|
|
348
|
-
c(e[2])
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
return c(e[0], n);
|
|
352
|
-
}
|
|
353
|
-
if (typeof e == "object" && e !== null && e.type === "wrap") {
|
|
354
|
-
if (["''", '""'].includes(e.style))
|
|
355
|
-
return t.string({ ...n, enum: [e.content] });
|
|
356
|
-
if (e.style === "{}") {
|
|
357
|
-
const r = !e.content.length || Array.isArray(e.content[0]) ? e.content : [e.content];
|
|
358
|
-
return t.object(
|
|
359
|
-
Object.fromEntries(
|
|
360
|
-
r.filter((o) => typeof o[0] == "string").map((o) => [o[0], o[1] === "?" ? c(o.slice(3), { optional: !0 }) : c(o.slice(2))])
|
|
361
|
-
),
|
|
362
|
-
n
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
if (e.style === "[]")
|
|
366
|
-
return e.content[1] === ":" ? t.array(c(e.content.slice(2)), n) : t.array(c(e.content), n);
|
|
367
|
-
if (e.style === "()")
|
|
368
|
-
return c(e.content, n);
|
|
369
|
-
}
|
|
370
|
-
return console.log("Unknown element"), console.log(e), t.unknown();
|
|
371
|
-
}
|
|
372
|
-
function v(e, n) {
|
|
373
|
-
const r = [[]];
|
|
374
|
-
for (const o of e)
|
|
375
|
-
n(o) ? r.push([]) : r[r.length - 1].push(o);
|
|
376
|
-
return r;
|
|
377
|
-
}
|
|
378
|
-
function P(e) {
|
|
379
|
-
try {
|
|
380
|
-
if (/^[A-Za-z]+\??:/.test(e)) {
|
|
381
|
-
const [, n, r, o] = e.match(/([A-Za-z]+)(\??):(.*)/), i = c(k(j(o)));
|
|
382
|
-
return i.name = n, r === "?" && (i.optional = !0), i;
|
|
383
|
-
}
|
|
384
|
-
return c(k(j(e)));
|
|
385
|
-
} catch (n) {
|
|
386
|
-
return console.error("Failed to parse type", e), console.error(n), t.unknown();
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
function l(e, n) {
|
|
390
|
-
if (e = n(e) || e, e.type === f.object)
|
|
391
|
-
for (const r in e.properties)
|
|
392
|
-
e.properties[r] = l(e.properties[r], n);
|
|
393
|
-
if (e.type === f.array && (e.items = l(e.items, n)), e.type === f.function && (e.inputs = l(e.inputs, n), e.output = l(e.output, n)), e.type === f.union)
|
|
394
|
-
for (const r in e.elements)
|
|
395
|
-
e.elements[r] = l(e.elements[r], n);
|
|
396
|
-
return e;
|
|
397
|
-
}
|
|
398
|
-
export {
|
|
399
|
-
J as F,
|
|
400
|
-
E as J,
|
|
401
|
-
L as T,
|
|
402
|
-
W as _,
|
|
403
|
-
P as a,
|
|
404
|
-
f as i,
|
|
405
|
-
l as m,
|
|
406
|
-
y as o,
|
|
407
|
-
t as u,
|
|
408
|
-
g as x,
|
|
409
|
-
d as y
|
|
410
|
-
};
|