@luna-park/plugin 1.1.0 → 1.2.1

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