@kubb/fabric-core 0.11.7 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Fabric-BoTE1-WX.d.cts → Fabric-BbVC650D.d.cts} +86 -15
- package/dist/{Fabric-CWquRFa2.d.ts → Fabric-eh92yS1R.d.ts} +86 -15
- package/dist/Root-BT59jU0W.js +931 -0
- package/dist/Root-BT59jU0W.js.map +1 -0
- package/dist/Root-SC_lWG_q.cjs +1057 -0
- package/dist/Root-SC_lWG_q.cjs.map +1 -0
- package/dist/{defaultParser-CFIT3sEE.cjs → defaultParser-2ym3KiZd.cjs} +3 -4
- package/dist/{defaultParser-CFIT3sEE.cjs.map → defaultParser-2ym3KiZd.cjs.map} +1 -1
- package/dist/{defaultParser-DZ2kzujH.js → defaultParser-DDFR9BTS.js} +2 -2
- package/dist/{defaultParser-DZ2kzujH.js.map → defaultParser-DDFR9BTS.js.map} +1 -1
- package/dist/{getRelativePath-y7WcYR5C.js → getRelativePath-COUEoqbz.js} +11 -2
- package/dist/getRelativePath-COUEoqbz.js.map +1 -0
- package/dist/{getRelativePath-BllDunh0.cjs → getRelativePath-jYLCpluV.cjs} +16 -1
- package/dist/getRelativePath-jYLCpluV.cjs.map +1 -0
- package/dist/index.cjs +129 -448
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -90
- package/dist/index.d.ts +54 -90
- package/dist/index.js +92 -416
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.cjs +7 -107
- package/dist/parsers/typescript.d.cts +1 -1
- package/dist/parsers/typescript.d.ts +1 -1
- package/dist/parsers/typescript.js +2 -101
- package/dist/parsers.cjs +7 -8
- package/dist/parsers.cjs.map +1 -1
- package/dist/parsers.d.cts +1 -1
- package/dist/parsers.d.ts +1 -1
- package/dist/parsers.js +3 -3
- package/dist/plugins.cjs +103 -9
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +32 -9
- package/dist/plugins.d.ts +32 -9
- package/dist/plugins.js +96 -3
- package/dist/plugins.js.map +1 -1
- package/dist/types-BI7rICUP.d.cts +31 -0
- package/dist/types-DpITKjSb.d.ts +32 -0
- package/dist/types.cjs +6 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +4 -3
- package/dist/types.d.ts +4 -3
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/typescriptParser-DyosyI_A.js +101 -0
- package/dist/typescriptParser-DyosyI_A.js.map +1 -0
- package/dist/typescriptParser-qjzb2pIh.cjs +137 -0
- package/dist/typescriptParser-qjzb2pIh.cjs.map +1 -0
- package/dist/{TreeNode-DomNP5og.d.cts → useNodeTree-CmXKaRqq.d.cts} +10 -3
- package/dist/{TreeNode-C1VnIF0o.d.ts → useNodeTree-DUdlgys5.d.ts} +10 -3
- package/package.json +3 -2
- package/src/Fabric.ts +13 -5
- package/src/KubbFile.ts +3 -11
- package/src/components/App.ts +6 -5
- package/src/components/Br.ts +11 -0
- package/src/components/Const.ts +6 -5
- package/src/components/Dedent.ts +10 -0
- package/src/components/File.ts +21 -16
- package/src/components/Function.ts +17 -13
- package/src/components/Indent.ts +7 -0
- package/src/components/Root.ts +6 -5
- package/src/components/Type.ts +6 -5
- package/src/components/__snapshots__/arrow_function_with_generics.ts +3 -3
- package/src/components/__snapshots__/async_arrow_function.ts +3 -3
- package/src/components/__snapshots__/async_function.ts +2 -2
- package/src/components/__snapshots__/async_function_with_Promise_return_type.ts +2 -2
- package/src/components/__snapshots__/basic_arrow_function.ts +3 -3
- package/src/components/__snapshots__/basic_export.ts +1 -0
- package/src/components/__snapshots__/basic_function.ts +2 -2
- package/src/components/__snapshots__/basic_import.ts +1 -0
- package/src/components/__snapshots__/default_exported_arrow_function.ts +3 -3
- package/src/components/__snapshots__/default_exported_function.ts +2 -2
- package/src/components/__snapshots__/exported_arrow_function.ts +3 -3
- package/src/components/__snapshots__/exported_function.ts +2 -2
- package/src/components/__snapshots__/function_with_JSDoc.ts +2 -2
- package/src/components/__snapshots__/function_with_generics.ts +2 -2
- package/src/components/__snapshots__/function_with_parameters.ts +2 -2
- package/src/components/__snapshots__/function_with_return_type.ts +2 -2
- package/src/components/__snapshots__/matches_with_root_import.ts +1 -0
- package/src/components/__snapshots__/named_export.ts +1 -0
- package/src/components/__snapshots__/named_export_(object_advanced).ts +1 -0
- package/src/components/__snapshots__/named_import.ts +1 -0
- package/src/components/__snapshots__/named_import_(object).ts +1 -0
- package/src/components/__snapshots__/named_import_(object_advanced).ts +1 -0
- package/src/components/__snapshots__/named_typed_export.ts +1 -0
- package/src/components/__snapshots__/named_typed_import.ts +1 -0
- package/src/components/__snapshots__/typed_export.ts +1 -0
- package/src/components/__snapshots__/typed_import.ts +1 -0
- package/src/contexts/RenderContext.ts +13 -0
- package/src/createComponent.ts +34 -0
- package/src/index.ts +9 -9
- package/src/intrinsic.ts +143 -0
- package/src/plugins/fsxPlugin/Runtime.ts +96 -0
- package/src/plugins/fsxPlugin/fsxPlugin.ts +45 -0
- package/src/plugins/index.ts +1 -0
- package/src/types.ts +4 -1
- package/dist/TreeNode-CC3a0Bae.js +0 -447
- package/dist/TreeNode-CC3a0Bae.js.map +0 -1
- package/dist/TreeNode-CFchatCw.cjs +0 -494
- package/dist/TreeNode-CFchatCw.cjs.map +0 -1
- package/dist/defineParser-CVCxqqzB.cjs +0 -18
- package/dist/defineParser-CVCxqqzB.cjs.map +0 -1
- package/dist/defineParser-Lco7nlj0.js +0 -13
- package/dist/defineParser-Lco7nlj0.js.map +0 -1
- package/dist/getRelativePath-BllDunh0.cjs.map +0 -1
- package/dist/getRelativePath-y7WcYR5C.js.map +0 -1
- package/dist/parsers/typescript.cjs.map +0 -1
- package/dist/parsers/typescript.js.map +0 -1
- package/dist/types-DYepTJ6F.d.cts +0 -82
- package/dist/types-yNaQHNUB.d.ts +0 -83
- package/src/components/Text.ts +0 -27
|
@@ -0,0 +1,931 @@
|
|
|
1
|
+
import { n as __name } from "./chunk-8X4u0d05.js";
|
|
2
|
+
import { r as trimExtName } from "./getRelativePath-COUEoqbz.js";
|
|
3
|
+
import { t as defaultParser } from "./defaultParser-DDFR9BTS.js";
|
|
4
|
+
import { orderBy } from "natural-orderby";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import pLimit from "p-limit";
|
|
8
|
+
import { EventEmitter } from "node:events";
|
|
9
|
+
|
|
10
|
+
//#region src/context.ts
|
|
11
|
+
/**
|
|
12
|
+
* Context stack for tracking the current context values
|
|
13
|
+
*
|
|
14
|
+
* Note: This uses a global Map for simplicity in code generation scenarios.
|
|
15
|
+
* For concurrent runtime execution, consider using AsyncLocalStorage or
|
|
16
|
+
* instance-based context management.
|
|
17
|
+
*/
|
|
18
|
+
const contextStack = /* @__PURE__ */ new Map();
|
|
19
|
+
const contextDefaults = /* @__PURE__ */ new Map();
|
|
20
|
+
/**
|
|
21
|
+
* Provides a value to descendant components (Vue 3 style)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const ThemeKey = Symbol('theme')
|
|
26
|
+
* provide(ThemeKey, { color: 'blue' })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function provide(key, value) {
|
|
30
|
+
if (!contextStack.has(key)) contextStack.set(key, []);
|
|
31
|
+
contextStack.get(key).push(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Injects a value provided by an ancestor component (Vue 3 style)
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const theme = inject(ThemeKey, { color: 'default' })
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function inject(key, defaultValue) {
|
|
42
|
+
const stack = contextStack.get(key);
|
|
43
|
+
if (!stack || stack.length === 0) {
|
|
44
|
+
if (defaultValue !== void 0) return defaultValue;
|
|
45
|
+
const storedDefault = contextDefaults.get(key);
|
|
46
|
+
if (storedDefault !== void 0) return storedDefault;
|
|
47
|
+
throw new Error(`No value provided for key: ${key.toString()}`);
|
|
48
|
+
}
|
|
49
|
+
return stack[stack.length - 1];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Unprovides a value (for cleanup)
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
function unprovide(key) {
|
|
56
|
+
const stack = contextStack.get(key);
|
|
57
|
+
if (stack && stack.length > 0) stack.pop();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Creates a context key with a default value (React-style compatibility)
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* const ThemeContext = createContext({ color: 'blue' })
|
|
65
|
+
* // ThemeContext is now typed as Context<{ color: string }>
|
|
66
|
+
* const theme = useContext(ThemeContext) // theme is { color: string }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
function createContext(defaultValue) {
|
|
70
|
+
const key = Symbol("context");
|
|
71
|
+
contextDefaults.set(key, defaultValue);
|
|
72
|
+
return key;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/contexts/NodeTreeContext.ts
|
|
77
|
+
/**
|
|
78
|
+
* Context for having the current NodeTree
|
|
79
|
+
*/
|
|
80
|
+
const NodeTreeContext = createContext(null);
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/utilityEvaluators-D7O7U3FY.js
|
|
84
|
+
const t$2 = {
|
|
85
|
+
done: !1,
|
|
86
|
+
hasNext: !1
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/pipe-CRsqNjLF.js
|
|
91
|
+
function t$1(e, ...t$3) {
|
|
92
|
+
let a = e;
|
|
93
|
+
let o = t$3.map((e$1) => `lazy` in e$1 ? r$1(e$1) : void 0);
|
|
94
|
+
let s = 0;
|
|
95
|
+
for (; s < t$3.length;) {
|
|
96
|
+
if (o[s] === void 0 || !i(a)) {
|
|
97
|
+
let e$2 = t$3[s];
|
|
98
|
+
a = e$2(a), s += 1;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
let e$1 = [];
|
|
102
|
+
for (let n$2 = s; n$2 < t$3.length; n$2++) {
|
|
103
|
+
let t$4 = o[n$2];
|
|
104
|
+
if (t$4 === void 0 || (e$1.push(t$4), t$4.isSingle)) break;
|
|
105
|
+
}
|
|
106
|
+
let r$2 = [];
|
|
107
|
+
for (let t$4 of a) if (n$1(t$4, r$2, e$1)) break;
|
|
108
|
+
let { isSingle: c } = e$1.at(-1);
|
|
109
|
+
a = c ? r$2[0] : r$2, s += e$1.length;
|
|
110
|
+
}
|
|
111
|
+
return a;
|
|
112
|
+
}
|
|
113
|
+
__name(t$1, "t");
|
|
114
|
+
function n$1(t$3, r$2, i$1) {
|
|
115
|
+
if (i$1.length === 0) return r$2.push(t$3), !1;
|
|
116
|
+
let a = t$3;
|
|
117
|
+
let o = t$2;
|
|
118
|
+
let s = !1;
|
|
119
|
+
for (let [e, t$4] of i$1.entries()) {
|
|
120
|
+
let { index: c, items: l } = t$4;
|
|
121
|
+
if (l.push(a), o = t$4(a, c, l), t$4.index += 1, o.hasNext) {
|
|
122
|
+
var _o$hasMany;
|
|
123
|
+
if ((_o$hasMany = o.hasMany) !== null && _o$hasMany !== void 0 ? _o$hasMany : !1) {
|
|
124
|
+
for (let t$5 of o.next) if (n$1(t$5, r$2, i$1.slice(e + 1))) return !0;
|
|
125
|
+
return s;
|
|
126
|
+
}
|
|
127
|
+
a = o.next;
|
|
128
|
+
}
|
|
129
|
+
if (!o.hasNext) break;
|
|
130
|
+
o.done && (s = !0);
|
|
131
|
+
}
|
|
132
|
+
return o.hasNext && r$2.push(a), s;
|
|
133
|
+
}
|
|
134
|
+
__name(n$1, "n");
|
|
135
|
+
function r$1(e) {
|
|
136
|
+
var _t$single;
|
|
137
|
+
let { lazy: t$3, lazyArgs: n$2 } = e;
|
|
138
|
+
let r$2 = t$3(...n$2);
|
|
139
|
+
return Object.assign(r$2, {
|
|
140
|
+
isSingle: (_t$single = t$3.single) !== null && _t$single !== void 0 ? _t$single : !1,
|
|
141
|
+
index: 0,
|
|
142
|
+
items: []
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
__name(r$1, "r");
|
|
146
|
+
function i(e) {
|
|
147
|
+
return typeof e == `string` || typeof e == `object` && !!e && Symbol.iterator in e;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/purryFromLazy-C1RBdBlx.js
|
|
152
|
+
function t(t$3, n$2) {
|
|
153
|
+
let r$2 = n$2.length - t$3.length;
|
|
154
|
+
if (r$2 === 1) {
|
|
155
|
+
let [r$3, ...i$1] = n$2;
|
|
156
|
+
return t$1(r$3, {
|
|
157
|
+
lazy: t$3,
|
|
158
|
+
lazyArgs: i$1
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (r$2 === 0) {
|
|
162
|
+
let r$3 = {
|
|
163
|
+
lazy: t$3,
|
|
164
|
+
lazyArgs: n$2
|
|
165
|
+
};
|
|
166
|
+
return Object.assign((t$4) => t$1(t$4, r$3), r$3);
|
|
167
|
+
}
|
|
168
|
+
throw Error(`Wrong number of arguments`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/uniqueBy.js
|
|
173
|
+
function n(...e) {
|
|
174
|
+
return t(r, e);
|
|
175
|
+
}
|
|
176
|
+
function r(t$3) {
|
|
177
|
+
let n$2 = t$3;
|
|
178
|
+
let r$2 = /* @__PURE__ */ new Set();
|
|
179
|
+
return (t$4, i$1, a) => {
|
|
180
|
+
let o = n$2(t$4, i$1, a);
|
|
181
|
+
return r$2.has(o) ? t$2 : (r$2.add(o), {
|
|
182
|
+
done: !1,
|
|
183
|
+
hasNext: !0,
|
|
184
|
+
next: t$4
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/createFile.ts
|
|
191
|
+
function combineSources(sources) {
|
|
192
|
+
return n(sources, (obj) => {
|
|
193
|
+
var _ref;
|
|
194
|
+
var _obj$name;
|
|
195
|
+
var _obj$isExportable;
|
|
196
|
+
var _obj$isTypeOnly;
|
|
197
|
+
return `${(_ref = (_obj$name = obj.name) !== null && _obj$name !== void 0 ? _obj$name : obj.value) !== null && _ref !== void 0 ? _ref : ""}:${(_obj$isExportable = obj.isExportable) !== null && _obj$isExportable !== void 0 ? _obj$isExportable : false}:${(_obj$isTypeOnly = obj.isTypeOnly) !== null && _obj$isTypeOnly !== void 0 ? _obj$isTypeOnly : false}`;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
function combineExports(exports) {
|
|
201
|
+
const sorted = orderBy(exports, [
|
|
202
|
+
(v) => !!Array.isArray(v.name),
|
|
203
|
+
(v) => !v.isTypeOnly,
|
|
204
|
+
(v) => v.path,
|
|
205
|
+
(v) => !!v.name,
|
|
206
|
+
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
207
|
+
]);
|
|
208
|
+
const prev = [];
|
|
209
|
+
const pathMap = /* @__PURE__ */ new Map();
|
|
210
|
+
const uniqueMap = /* @__PURE__ */ new Map();
|
|
211
|
+
const pathNameTypeTrueMap = /* @__PURE__ */ new Map();
|
|
212
|
+
for (const curr of sorted) {
|
|
213
|
+
const name = curr.name;
|
|
214
|
+
const pathKey = curr.path;
|
|
215
|
+
const prevByPath = pathMap.get(pathKey);
|
|
216
|
+
const nameKey = Array.isArray(name) ? JSON.stringify(name) : name || "";
|
|
217
|
+
const pathNameTypeKey = `${pathKey}:${nameKey}:${curr.isTypeOnly}`;
|
|
218
|
+
const pathNameKey = `${pathKey}:${nameKey}`;
|
|
219
|
+
if (pathNameTypeTrueMap.get(pathNameKey)) continue;
|
|
220
|
+
const uniqueKey = `${pathNameTypeKey}:${curr.asAlias || ""}`;
|
|
221
|
+
if (uniqueMap.get(uniqueKey) || Array.isArray(name) && !name.length || (prevByPath === null || prevByPath === void 0 ? void 0 : prevByPath.asAlias) && !curr.asAlias) continue;
|
|
222
|
+
if (!prevByPath) {
|
|
223
|
+
const newItem = {
|
|
224
|
+
...curr,
|
|
225
|
+
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
226
|
+
};
|
|
227
|
+
prev.push(newItem);
|
|
228
|
+
pathMap.set(pathKey, newItem);
|
|
229
|
+
uniqueMap.set(uniqueKey, newItem);
|
|
230
|
+
if (newItem.isTypeOnly) pathNameTypeTrueMap.set(pathNameKey, newItem);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
234
|
+
prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])];
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
prev.push(curr);
|
|
238
|
+
uniqueMap.set(uniqueKey, curr);
|
|
239
|
+
if (curr.isTypeOnly) pathNameTypeTrueMap.set(pathNameKey, curr);
|
|
240
|
+
}
|
|
241
|
+
return prev;
|
|
242
|
+
}
|
|
243
|
+
function combineImports(imports, exports, source) {
|
|
244
|
+
const exportedNameLookup = /* @__PURE__ */ new Set();
|
|
245
|
+
for (const item of exports) {
|
|
246
|
+
const { name } = item;
|
|
247
|
+
if (!name) continue;
|
|
248
|
+
if (Array.isArray(name)) {
|
|
249
|
+
for (const value of name) if (value) exportedNameLookup.add(value);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
exportedNameLookup.add(name);
|
|
253
|
+
}
|
|
254
|
+
const usageCache = /* @__PURE__ */ new Map();
|
|
255
|
+
const hasImportInSource = (importName) => {
|
|
256
|
+
if (!source) return true;
|
|
257
|
+
const cached = usageCache.get(importName);
|
|
258
|
+
if (cached !== void 0) return cached;
|
|
259
|
+
const isUsed = source.includes(importName) || exportedNameLookup.has(importName);
|
|
260
|
+
usageCache.set(importName, isUsed);
|
|
261
|
+
return isUsed;
|
|
262
|
+
};
|
|
263
|
+
const sorted = orderBy(imports, [
|
|
264
|
+
(v) => !!Array.isArray(v.name),
|
|
265
|
+
(v) => !v.isTypeOnly,
|
|
266
|
+
(v) => v.path,
|
|
267
|
+
(v) => !!v.name,
|
|
268
|
+
(v) => Array.isArray(v.name) ? orderBy(v.name) : v.name
|
|
269
|
+
]);
|
|
270
|
+
const prev = [];
|
|
271
|
+
const pathTypeMap = /* @__PURE__ */ new Map();
|
|
272
|
+
const uniqueMap = /* @__PURE__ */ new Map();
|
|
273
|
+
const pathNameTypeTrueMap = /* @__PURE__ */ new Map();
|
|
274
|
+
for (const curr of sorted) {
|
|
275
|
+
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
276
|
+
if (curr.path === curr.root) continue;
|
|
277
|
+
if (Array.isArray(name)) name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
|
|
278
|
+
const pathTypeKey = `${curr.path}:${curr.isTypeOnly}`;
|
|
279
|
+
const prevByPath = pathTypeMap.get(pathTypeKey);
|
|
280
|
+
const nameKey = Array.isArray(name) ? JSON.stringify(name) : name || "";
|
|
281
|
+
const pathNameTypeKey = `${curr.path}:${nameKey}:${curr.isTypeOnly}`;
|
|
282
|
+
const uniquePrev = uniqueMap.get(pathNameTypeKey);
|
|
283
|
+
const pathNameKey = `${curr.path}:${nameKey}`;
|
|
284
|
+
if (pathNameTypeTrueMap.get(pathNameKey)) continue;
|
|
285
|
+
if (uniquePrev || Array.isArray(name) && !name.length) continue;
|
|
286
|
+
if (!prevByPath) {
|
|
287
|
+
const newItem = {
|
|
288
|
+
...curr,
|
|
289
|
+
name
|
|
290
|
+
};
|
|
291
|
+
prev.push(newItem);
|
|
292
|
+
pathTypeMap.set(pathTypeKey, newItem);
|
|
293
|
+
uniqueMap.set(pathNameTypeKey, newItem);
|
|
294
|
+
if (newItem.isTypeOnly) pathNameTypeTrueMap.set(pathNameKey, newItem);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
298
|
+
prevByPath.name = [...new Set([...prevByPath.name, ...name])];
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (!Array.isArray(name) && name && !hasImportInSource(name)) continue;
|
|
302
|
+
prev.push(curr);
|
|
303
|
+
uniqueMap.set(pathNameTypeKey, curr);
|
|
304
|
+
if (curr.isTypeOnly) pathNameTypeTrueMap.set(pathNameKey, curr);
|
|
305
|
+
}
|
|
306
|
+
return prev;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Helper to create a file with name and id set
|
|
310
|
+
*/
|
|
311
|
+
function createFile(file) {
|
|
312
|
+
var _file$exports;
|
|
313
|
+
var _file$imports;
|
|
314
|
+
var _file$sources;
|
|
315
|
+
const extname = path.extname(file.baseName);
|
|
316
|
+
if (!extname) throw new Error(`No extname found for ${file.baseName}`);
|
|
317
|
+
const source = file.sources.map((item) => item.value).join("\n\n");
|
|
318
|
+
const exports = ((_file$exports = file.exports) === null || _file$exports === void 0 ? void 0 : _file$exports.length) ? combineExports(file.exports) : [];
|
|
319
|
+
const imports = ((_file$imports = file.imports) === null || _file$imports === void 0 ? void 0 : _file$imports.length) && source ? combineImports(file.imports, exports, source) : [];
|
|
320
|
+
const sources = ((_file$sources = file.sources) === null || _file$sources === void 0 ? void 0 : _file$sources.length) ? combineSources(file.sources) : [];
|
|
321
|
+
return {
|
|
322
|
+
...file,
|
|
323
|
+
id: createHash("sha256").update(file.path).digest("hex"),
|
|
324
|
+
name: trimExtName(file.baseName),
|
|
325
|
+
extname,
|
|
326
|
+
imports,
|
|
327
|
+
exports,
|
|
328
|
+
sources,
|
|
329
|
+
meta: file.meta || {}
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/checkPrivateRedeclaration.js
|
|
335
|
+
function _checkPrivateRedeclaration(e, t$3) {
|
|
336
|
+
if (t$3.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
//#endregion
|
|
340
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/classPrivateFieldInitSpec.js
|
|
341
|
+
function _classPrivateFieldInitSpec(e, t$3, a) {
|
|
342
|
+
_checkPrivateRedeclaration(e, t$3), t$3.set(e, a);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/assertClassBrand.js
|
|
347
|
+
function _assertClassBrand(e, t$3, n$2) {
|
|
348
|
+
if ("function" == typeof e ? e === t$3 : e.has(t$3)) return arguments.length < 3 ? t$3 : n$2;
|
|
349
|
+
throw new TypeError("Private element is not present on this object");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/classPrivateFieldGet2.js
|
|
354
|
+
function _classPrivateFieldGet2(s, a) {
|
|
355
|
+
return s.get(_assertClassBrand(s, a));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/classPrivateFieldSet2.js
|
|
360
|
+
function _classPrivateFieldSet2(s, a, r$2) {
|
|
361
|
+
return s.set(_assertClassBrand(s, a), r$2), r$2;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
//#endregion
|
|
365
|
+
//#region src/utils/AsyncEventEmitter.ts
|
|
366
|
+
var _emitter = /* @__PURE__ */ new WeakMap();
|
|
367
|
+
var _mode = /* @__PURE__ */ new WeakMap();
|
|
368
|
+
var AsyncEventEmitter = class {
|
|
369
|
+
constructor({ maxListener = 100, mode = "sequential" } = {}) {
|
|
370
|
+
_classPrivateFieldInitSpec(this, _emitter, new EventEmitter());
|
|
371
|
+
_classPrivateFieldInitSpec(this, _mode, void 0);
|
|
372
|
+
_classPrivateFieldGet2(_emitter, this).setMaxListeners(maxListener);
|
|
373
|
+
_classPrivateFieldSet2(_mode, this, mode);
|
|
374
|
+
}
|
|
375
|
+
async emit(eventName, ...eventArgs) {
|
|
376
|
+
const listeners = _classPrivateFieldGet2(_emitter, this).listeners(eventName);
|
|
377
|
+
if (listeners.length === 0) return;
|
|
378
|
+
const errors = [];
|
|
379
|
+
if (_classPrivateFieldGet2(_mode, this) === "sequential") for (const listener of listeners) try {
|
|
380
|
+
await listener(...eventArgs);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
383
|
+
errors.push(error);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
const promises = listeners.map(async (listener) => {
|
|
387
|
+
try {
|
|
388
|
+
await listener(...eventArgs);
|
|
389
|
+
} catch (err) {
|
|
390
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
391
|
+
errors.push(error);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
await Promise.all(promises);
|
|
395
|
+
}
|
|
396
|
+
if (errors.length === 1) throw errors[0];
|
|
397
|
+
if (errors.length > 1) throw new AggregateError(errors, `Errors in async listeners for "${eventName}"`);
|
|
398
|
+
}
|
|
399
|
+
on(eventName, handler) {
|
|
400
|
+
_classPrivateFieldGet2(_emitter, this).on(eventName, handler);
|
|
401
|
+
}
|
|
402
|
+
onOnce(eventName, handler) {
|
|
403
|
+
const wrapper = (...args) => {
|
|
404
|
+
this.off(eventName, wrapper);
|
|
405
|
+
handler(...args);
|
|
406
|
+
};
|
|
407
|
+
this.on(eventName, wrapper);
|
|
408
|
+
}
|
|
409
|
+
off(eventName, handler) {
|
|
410
|
+
_classPrivateFieldGet2(_emitter, this).off(eventName, handler);
|
|
411
|
+
}
|
|
412
|
+
removeAll() {
|
|
413
|
+
_classPrivateFieldGet2(_emitter, this).removeAllListeners();
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/typeof.js
|
|
419
|
+
function _typeof(o) {
|
|
420
|
+
"@babel/helpers - typeof";
|
|
421
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
422
|
+
return typeof o$1;
|
|
423
|
+
} : function(o$1) {
|
|
424
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
425
|
+
}, _typeof(o);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/toPrimitive.js
|
|
430
|
+
function toPrimitive(t$3, r$2) {
|
|
431
|
+
if ("object" != _typeof(t$3) || !t$3) return t$3;
|
|
432
|
+
var e = t$3[Symbol.toPrimitive];
|
|
433
|
+
if (void 0 !== e) {
|
|
434
|
+
var i$1 = e.call(t$3, r$2 || "default");
|
|
435
|
+
if ("object" != _typeof(i$1)) return i$1;
|
|
436
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
437
|
+
}
|
|
438
|
+
return ("string" === r$2 ? String : Number)(t$3);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
//#endregion
|
|
442
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/toPropertyKey.js
|
|
443
|
+
function toPropertyKey(t$3) {
|
|
444
|
+
var i$1 = toPrimitive(t$3, "string");
|
|
445
|
+
return "symbol" == _typeof(i$1) ? i$1 : i$1 + "";
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/defineProperty.js
|
|
450
|
+
function _defineProperty(e, r$2, t$3) {
|
|
451
|
+
return (r$2 = toPropertyKey(r$2)) in e ? Object.defineProperty(e, r$2, {
|
|
452
|
+
value: t$3,
|
|
453
|
+
enumerable: !0,
|
|
454
|
+
configurable: !0,
|
|
455
|
+
writable: !0
|
|
456
|
+
}) : e[r$2] = t$3, e;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//#endregion
|
|
460
|
+
//#region src/FileProcessor.ts
|
|
461
|
+
var _limit = /* @__PURE__ */ new WeakMap();
|
|
462
|
+
var FileProcessor = class {
|
|
463
|
+
constructor({ events = new AsyncEventEmitter() } = {}) {
|
|
464
|
+
_classPrivateFieldInitSpec(this, _limit, pLimit(100));
|
|
465
|
+
_defineProperty(this, "events", void 0);
|
|
466
|
+
this.events = events;
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
async parse(file, { parsers, extension } = {}) {
|
|
470
|
+
const parseExtName = (extension === null || extension === void 0 ? void 0 : extension[file.extname]) || void 0;
|
|
471
|
+
if (!parsers) {
|
|
472
|
+
console.warn("No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.");
|
|
473
|
+
return defaultParser.parse(file, { extname: parseExtName });
|
|
474
|
+
}
|
|
475
|
+
if (!file.extname) return defaultParser.parse(file, { extname: parseExtName });
|
|
476
|
+
const parser = parsers.get(file.extname);
|
|
477
|
+
if (!parser) return defaultParser.parse(file, { extname: parseExtName });
|
|
478
|
+
return parser.parse(file, { extname: parseExtName });
|
|
479
|
+
}
|
|
480
|
+
async run(files, { parsers, mode = "sequential", dryRun, extension } = {}) {
|
|
481
|
+
await this.events.emit("files:processing:start", files);
|
|
482
|
+
const total = files.length;
|
|
483
|
+
let processed = 0;
|
|
484
|
+
const processOne = async (resolvedFile, index) => {
|
|
485
|
+
await this.events.emit("file:processing:start", resolvedFile, index, total);
|
|
486
|
+
const source = dryRun ? void 0 : await this.parse(resolvedFile, {
|
|
487
|
+
extension,
|
|
488
|
+
parsers
|
|
489
|
+
});
|
|
490
|
+
const currentProcessed = ++processed;
|
|
491
|
+
const percentage = currentProcessed / total * 100;
|
|
492
|
+
await this.events.emit("file:processing:update", {
|
|
493
|
+
file: resolvedFile,
|
|
494
|
+
source,
|
|
495
|
+
processed: currentProcessed,
|
|
496
|
+
percentage,
|
|
497
|
+
total
|
|
498
|
+
});
|
|
499
|
+
await this.events.emit("file:processing:end", resolvedFile, index, total);
|
|
500
|
+
};
|
|
501
|
+
if (mode === "sequential") {
|
|
502
|
+
async function* asyncFiles() {
|
|
503
|
+
for (let index = 0; index < files.length; index++) yield [files[index], index];
|
|
504
|
+
}
|
|
505
|
+
for await (const [file, index] of asyncFiles()) if (file) await processOne(file, index);
|
|
506
|
+
} else {
|
|
507
|
+
const promises = files.map((resolvedFile, index) => _classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
|
|
508
|
+
await Promise.all(promises);
|
|
509
|
+
}
|
|
510
|
+
await this.events.emit("files:processing:end", files);
|
|
511
|
+
return files;
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/utils/Cache.ts
|
|
517
|
+
var _buffer = /* @__PURE__ */ new WeakMap();
|
|
518
|
+
var Cache = class {
|
|
519
|
+
constructor() {
|
|
520
|
+
_classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
|
|
521
|
+
}
|
|
522
|
+
get(key) {
|
|
523
|
+
var _this$buffer$get;
|
|
524
|
+
return (_this$buffer$get = _classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
|
|
525
|
+
}
|
|
526
|
+
set(key, value) {
|
|
527
|
+
_classPrivateFieldGet2(_buffer, this).set(key, value);
|
|
528
|
+
}
|
|
529
|
+
delete(key) {
|
|
530
|
+
_classPrivateFieldGet2(_buffer, this).delete(key);
|
|
531
|
+
}
|
|
532
|
+
clear() {
|
|
533
|
+
_classPrivateFieldGet2(_buffer, this).clear();
|
|
534
|
+
}
|
|
535
|
+
keys() {
|
|
536
|
+
return [..._classPrivateFieldGet2(_buffer, this).keys()];
|
|
537
|
+
}
|
|
538
|
+
values() {
|
|
539
|
+
return [..._classPrivateFieldGet2(_buffer, this).values()];
|
|
540
|
+
}
|
|
541
|
+
flush() {}
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region \0@oxc-project+runtime@0.107.0/helpers/classPrivateMethodInitSpec.js
|
|
546
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
547
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/FileManager.ts
|
|
552
|
+
function mergeFile(a, b) {
|
|
553
|
+
return {
|
|
554
|
+
...a,
|
|
555
|
+
sources: [...a.sources || [], ...b.sources || []],
|
|
556
|
+
imports: [...a.imports || [], ...b.imports || []],
|
|
557
|
+
exports: [...a.exports || [], ...b.exports || []]
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
var _cache = /* @__PURE__ */ new WeakMap();
|
|
561
|
+
var _filesCache = /* @__PURE__ */ new WeakMap();
|
|
562
|
+
var _FileManager_brand = /* @__PURE__ */ new WeakSet();
|
|
563
|
+
var FileManager = class {
|
|
564
|
+
constructor({ events = new AsyncEventEmitter() } = {}) {
|
|
565
|
+
_classPrivateMethodInitSpec(this, _FileManager_brand);
|
|
566
|
+
_classPrivateFieldInitSpec(this, _cache, new Cache());
|
|
567
|
+
_classPrivateFieldInitSpec(this, _filesCache, null);
|
|
568
|
+
_defineProperty(this, "events", void 0);
|
|
569
|
+
_defineProperty(this, "processor", void 0);
|
|
570
|
+
this.processor = new FileProcessor({ events });
|
|
571
|
+
this.events = events;
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
574
|
+
add(...files) {
|
|
575
|
+
const resolvedFiles = [];
|
|
576
|
+
const mergedFiles = /* @__PURE__ */ new Map();
|
|
577
|
+
files.forEach((file) => {
|
|
578
|
+
const existing = mergedFiles.get(file.path);
|
|
579
|
+
if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
|
|
580
|
+
else mergedFiles.set(file.path, file);
|
|
581
|
+
});
|
|
582
|
+
for (let file of mergedFiles.values()) {
|
|
583
|
+
file = _assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
|
|
584
|
+
file = _assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
|
|
585
|
+
const resolvedFile = createFile(file);
|
|
586
|
+
_classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
|
|
587
|
+
this.flush();
|
|
588
|
+
resolvedFiles.push(resolvedFile);
|
|
589
|
+
}
|
|
590
|
+
this.events.emit("files:added", resolvedFiles);
|
|
591
|
+
return resolvedFiles;
|
|
592
|
+
}
|
|
593
|
+
upsert(...files) {
|
|
594
|
+
const resolvedFiles = [];
|
|
595
|
+
const mergedFiles = /* @__PURE__ */ new Map();
|
|
596
|
+
files.forEach((file) => {
|
|
597
|
+
const existing = mergedFiles.get(file.path);
|
|
598
|
+
if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
|
|
599
|
+
else mergedFiles.set(file.path, file);
|
|
600
|
+
});
|
|
601
|
+
for (let file of mergedFiles.values()) {
|
|
602
|
+
const existing = _classPrivateFieldGet2(_cache, this).get(file.path);
|
|
603
|
+
file = _assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
|
|
604
|
+
file = _assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
|
|
605
|
+
const resolvedFile = createFile(existing ? mergeFile(existing, file) : file);
|
|
606
|
+
_classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
|
|
607
|
+
this.flush();
|
|
608
|
+
resolvedFiles.push(resolvedFile);
|
|
609
|
+
}
|
|
610
|
+
this.events.emit("files:added", resolvedFiles);
|
|
611
|
+
return resolvedFiles;
|
|
612
|
+
}
|
|
613
|
+
flush() {
|
|
614
|
+
_classPrivateFieldSet2(_filesCache, this, null);
|
|
615
|
+
_classPrivateFieldGet2(_cache, this).flush();
|
|
616
|
+
}
|
|
617
|
+
getByPath(path$1) {
|
|
618
|
+
return _classPrivateFieldGet2(_cache, this).get(path$1);
|
|
619
|
+
}
|
|
620
|
+
deleteByPath(path$1) {
|
|
621
|
+
_classPrivateFieldGet2(_cache, this).delete(path$1);
|
|
622
|
+
_classPrivateFieldSet2(_filesCache, this, null);
|
|
623
|
+
}
|
|
624
|
+
clear() {
|
|
625
|
+
_classPrivateFieldGet2(_cache, this).clear();
|
|
626
|
+
_classPrivateFieldSet2(_filesCache, this, null);
|
|
627
|
+
}
|
|
628
|
+
get files() {
|
|
629
|
+
if (_classPrivateFieldGet2(_filesCache, this)) return _classPrivateFieldGet2(_filesCache, this);
|
|
630
|
+
const keys = orderBy(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => trimExtName(v).endsWith("index")]);
|
|
631
|
+
const files = [];
|
|
632
|
+
for (const key of keys) {
|
|
633
|
+
const file = _classPrivateFieldGet2(_cache, this).get(key);
|
|
634
|
+
if (file) files.push(file);
|
|
635
|
+
}
|
|
636
|
+
_classPrivateFieldSet2(_filesCache, this, files);
|
|
637
|
+
return files;
|
|
638
|
+
}
|
|
639
|
+
async write(options) {
|
|
640
|
+
await this.events.emit("files:writing:start", this.files);
|
|
641
|
+
const resolvedFiles = await this.processor.run(this.files, options);
|
|
642
|
+
this.clear();
|
|
643
|
+
await this.events.emit("files:writing:end", resolvedFiles);
|
|
644
|
+
return resolvedFiles;
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
function _resolvePath(file) {
|
|
648
|
+
this.events.emit("file:resolve:path", file);
|
|
649
|
+
return file;
|
|
650
|
+
}
|
|
651
|
+
function _resolveName(file) {
|
|
652
|
+
this.events.emit("file:resolve:name", file);
|
|
653
|
+
return file;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region src/utils/TreeNode.ts
|
|
658
|
+
var _childrenMap = /* @__PURE__ */ new WeakMap();
|
|
659
|
+
var _cachedLeaves = /* @__PURE__ */ new WeakMap();
|
|
660
|
+
var TreeNode = class TreeNode {
|
|
661
|
+
constructor(data, parent) {
|
|
662
|
+
_defineProperty(this, "data", void 0);
|
|
663
|
+
_defineProperty(this, "parent", void 0);
|
|
664
|
+
_defineProperty(this, "children", []);
|
|
665
|
+
_classPrivateFieldInitSpec(this, _childrenMap, /* @__PURE__ */ new Map());
|
|
666
|
+
_classPrivateFieldInitSpec(this, _cachedLeaves, void 0);
|
|
667
|
+
this.data = data;
|
|
668
|
+
this.parent = parent;
|
|
669
|
+
}
|
|
670
|
+
addChild(data) {
|
|
671
|
+
const child = new TreeNode(data, this);
|
|
672
|
+
this.children.push(child);
|
|
673
|
+
if (typeof data === "object" && data !== null && "name" in data) _classPrivateFieldGet2(_childrenMap, this).set(data.name, child);
|
|
674
|
+
_classPrivateFieldSet2(_cachedLeaves, this, void 0);
|
|
675
|
+
return child;
|
|
676
|
+
}
|
|
677
|
+
getChildByName(name) {
|
|
678
|
+
return _classPrivateFieldGet2(_childrenMap, this).get(name);
|
|
679
|
+
}
|
|
680
|
+
get leaves() {
|
|
681
|
+
if (_classPrivateFieldGet2(_cachedLeaves, this)) return _classPrivateFieldGet2(_cachedLeaves, this);
|
|
682
|
+
if (this.children.length === 0) return [this];
|
|
683
|
+
const result = [];
|
|
684
|
+
const stack = [...this.children];
|
|
685
|
+
const visited = /* @__PURE__ */ new Set();
|
|
686
|
+
while (stack.length > 0) {
|
|
687
|
+
const node = stack.pop();
|
|
688
|
+
if (visited.has(node)) continue;
|
|
689
|
+
visited.add(node);
|
|
690
|
+
if (node.children.length > 0) stack.push(...node.children);
|
|
691
|
+
else result.push(node);
|
|
692
|
+
}
|
|
693
|
+
_classPrivateFieldSet2(_cachedLeaves, this, result);
|
|
694
|
+
return result;
|
|
695
|
+
}
|
|
696
|
+
forEach(callback) {
|
|
697
|
+
const stack = [this];
|
|
698
|
+
for (let i$1 = 0; i$1 < stack.length; i$1++) {
|
|
699
|
+
const node = stack[i$1];
|
|
700
|
+
callback(node);
|
|
701
|
+
if (node.children.length > 0) stack.push(...node.children);
|
|
702
|
+
}
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
705
|
+
findDeep(predicate) {
|
|
706
|
+
for (const leaf of this.leaves) if (predicate(leaf)) return leaf;
|
|
707
|
+
}
|
|
708
|
+
static toGraph(root) {
|
|
709
|
+
const nodes = [];
|
|
710
|
+
const edges = [];
|
|
711
|
+
const stack = [root];
|
|
712
|
+
for (let i$1 = 0; i$1 < stack.length; i$1++) {
|
|
713
|
+
const node = stack[i$1];
|
|
714
|
+
nodes.push({
|
|
715
|
+
id: node.data.path,
|
|
716
|
+
label: node.data.name
|
|
717
|
+
});
|
|
718
|
+
const children = node.children;
|
|
719
|
+
if (children.length > 0) for (let j = 0, len = children.length; j < len; j++) {
|
|
720
|
+
const child = children[j];
|
|
721
|
+
edges.push({
|
|
722
|
+
from: node.data.path,
|
|
723
|
+
to: child.data.path
|
|
724
|
+
});
|
|
725
|
+
stack.push(child);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return {
|
|
729
|
+
nodes,
|
|
730
|
+
edges
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
static fromFiles(files, rootFolder = "") {
|
|
734
|
+
const normalizePath = (p) => p.replace(/\\/g, "/");
|
|
735
|
+
const normalizedRoot = normalizePath(rootFolder);
|
|
736
|
+
const rootPrefix = normalizedRoot.endsWith("/") ? normalizedRoot : `${normalizedRoot}/`;
|
|
737
|
+
const normalizedPaths = /* @__PURE__ */ new Map();
|
|
738
|
+
const filteredFiles = [];
|
|
739
|
+
for (const file of files) {
|
|
740
|
+
var _normalizedPaths$get;
|
|
741
|
+
const filePath = (_normalizedPaths$get = normalizedPaths.get(file)) !== null && _normalizedPaths$get !== void 0 ? _normalizedPaths$get : normalizePath(file.path);
|
|
742
|
+
normalizedPaths.set(file, filePath);
|
|
743
|
+
if (!filePath.endsWith(".json") && (!rootFolder || filePath.startsWith(rootPrefix))) filteredFiles.push(file);
|
|
744
|
+
}
|
|
745
|
+
if (filteredFiles.length === 0) return null;
|
|
746
|
+
const treeNode = new TreeNode({
|
|
747
|
+
name: rootFolder || "",
|
|
748
|
+
path: rootFolder || "",
|
|
749
|
+
file: void 0
|
|
750
|
+
});
|
|
751
|
+
for (const file of filteredFiles) {
|
|
752
|
+
const parts = normalizedPaths.get(file).slice(rootPrefix.length).split("/");
|
|
753
|
+
let current = treeNode;
|
|
754
|
+
let currentPath = rootFolder;
|
|
755
|
+
for (const [index, part] of parts.entries()) {
|
|
756
|
+
const isLast = index === parts.length - 1;
|
|
757
|
+
currentPath += (currentPath.endsWith("/") ? "" : "/") + part;
|
|
758
|
+
let next = current.getChildByName(part);
|
|
759
|
+
if (!next) next = current.addChild({
|
|
760
|
+
name: part,
|
|
761
|
+
path: currentPath,
|
|
762
|
+
file: isLast ? file : void 0
|
|
763
|
+
});
|
|
764
|
+
current = next;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return treeNode;
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
//#endregion
|
|
772
|
+
//#region src/contexts/RootContext.ts
|
|
773
|
+
/**
|
|
774
|
+
* Context providing root-level functionalities such as exit hook, tree node structure, and file management.
|
|
775
|
+
* Define in the `render` helper of the runtime.
|
|
776
|
+
*/
|
|
777
|
+
const RootContext = createContext({
|
|
778
|
+
exit: () => {},
|
|
779
|
+
treeNode: new TreeNode({
|
|
780
|
+
type: "Root",
|
|
781
|
+
props: {}
|
|
782
|
+
}),
|
|
783
|
+
fileManager: new FileManager()
|
|
784
|
+
});
|
|
785
|
+
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region src/contexts/RenderContext.ts
|
|
788
|
+
/**
|
|
789
|
+
* Provides a context for tracking rendering state such as indentation and line length.
|
|
790
|
+
*/
|
|
791
|
+
const RenderContext = createContext({
|
|
792
|
+
indentLevel: 0,
|
|
793
|
+
indentSize: 2,
|
|
794
|
+
currentLineLength: 0,
|
|
795
|
+
shouldBreak: false
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region src/intrinsic.ts
|
|
800
|
+
function isFabricElement(value) {
|
|
801
|
+
return typeof value === "function" && "type" in value && "component" in value;
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Type guard to check if a value is an intrinsic element
|
|
805
|
+
*/
|
|
806
|
+
function isIntrinsic(value) {
|
|
807
|
+
return value && typeof value === "object" && value.__intrinsic === true;
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Render a single intrinsic node
|
|
811
|
+
*/
|
|
812
|
+
function renderIntrinsicNode(node, renderContext) {
|
|
813
|
+
switch (node.type) {
|
|
814
|
+
case "br":
|
|
815
|
+
renderContext.currentLineLength = 0;
|
|
816
|
+
return "\n";
|
|
817
|
+
case "indent":
|
|
818
|
+
renderContext.indentLevel++;
|
|
819
|
+
return "";
|
|
820
|
+
case "dedent":
|
|
821
|
+
renderContext.indentLevel = Math.max(0, renderContext.indentLevel - 1);
|
|
822
|
+
return "";
|
|
823
|
+
default: return "";
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Helper: render a plain string while applying current indentation at the
|
|
828
|
+
* start of each logical line. This ensures `${indent}` intrinsics affect
|
|
829
|
+
* subsequent string content.
|
|
830
|
+
*/
|
|
831
|
+
function renderIndent(content, renderContext) {
|
|
832
|
+
if (content.length === 0) return "";
|
|
833
|
+
const indentStr = " ".repeat(renderContext.indentLevel * renderContext.indentSize);
|
|
834
|
+
const lines = content.split("\n");
|
|
835
|
+
let out = "";
|
|
836
|
+
for (const [i$1, line] of lines.entries()) {
|
|
837
|
+
if (renderContext.currentLineLength === 0 && line.length > 0) {
|
|
838
|
+
out += indentStr + line;
|
|
839
|
+
renderContext.currentLineLength = indentStr.length + line.length;
|
|
840
|
+
} else {
|
|
841
|
+
out += line;
|
|
842
|
+
renderContext.currentLineLength += line.length;
|
|
843
|
+
}
|
|
844
|
+
if (i$1 !== lines.length - 1) {
|
|
845
|
+
out += "\n";
|
|
846
|
+
renderContext.currentLineLength = 0;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return out;
|
|
850
|
+
}
|
|
851
|
+
function renderIntrinsic(children, context) {
|
|
852
|
+
const renderContext = context || inject(RenderContext);
|
|
853
|
+
provide(RenderContext, renderContext);
|
|
854
|
+
if (!children) return "";
|
|
855
|
+
if (isFabricElement(children)) try {
|
|
856
|
+
return renderIntrinsic(children());
|
|
857
|
+
} catch {
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
if (Array.isArray(children)) return children.map((child) => renderIntrinsic(child)).join("");
|
|
861
|
+
if (isIntrinsic(children)) return renderIntrinsicNode(children, renderContext);
|
|
862
|
+
if (typeof children === "function") return renderIntrinsic(children());
|
|
863
|
+
if (typeof children === "string") return renderIndent(children, renderContext);
|
|
864
|
+
if (typeof children === "number") return renderIndent(String(children), renderContext);
|
|
865
|
+
if (typeof children === "boolean") return renderIndent(children ? "true" : "false", renderContext);
|
|
866
|
+
try {
|
|
867
|
+
return renderIndent(children, renderContext);
|
|
868
|
+
} catch {
|
|
869
|
+
return "";
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Create an intrinsic element
|
|
874
|
+
*/
|
|
875
|
+
function createIntrinsic(type) {
|
|
876
|
+
return {
|
|
877
|
+
type,
|
|
878
|
+
__intrinsic: true
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/createComponent.ts
|
|
884
|
+
function createComponent(type, Component) {
|
|
885
|
+
return (...args) => {
|
|
886
|
+
const fn = (() => renderIntrinsic(Component(args[0])));
|
|
887
|
+
fn.component = Component;
|
|
888
|
+
fn.props = args[0];
|
|
889
|
+
fn.type = type;
|
|
890
|
+
fn.children = (...children) => {
|
|
891
|
+
var _args$;
|
|
892
|
+
const propsWithChildren = {
|
|
893
|
+
...(_args$ = args[0]) !== null && _args$ !== void 0 ? _args$ : {},
|
|
894
|
+
children() {
|
|
895
|
+
return renderIntrinsic(children);
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
const fnChild = (() => renderIntrinsic(Component(propsWithChildren)));
|
|
899
|
+
fnChild.component = Component;
|
|
900
|
+
fnChild.props = args[0];
|
|
901
|
+
fnChild.type = type;
|
|
902
|
+
return fnChild;
|
|
903
|
+
};
|
|
904
|
+
return fn;
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
//#endregion
|
|
909
|
+
//#region src/components/Root.ts
|
|
910
|
+
/**
|
|
911
|
+
* This component provides the root behavior for the Fabric runtime.
|
|
912
|
+
*/
|
|
913
|
+
const Root = createComponent("Root", ({ onError, onExit, treeNode, fileManager, children }) => {
|
|
914
|
+
provide(RootContext, {
|
|
915
|
+
exit: onExit,
|
|
916
|
+
treeNode,
|
|
917
|
+
fileManager
|
|
918
|
+
});
|
|
919
|
+
provide(NodeTreeContext, treeNode);
|
|
920
|
+
try {
|
|
921
|
+
return children;
|
|
922
|
+
} catch (e) {
|
|
923
|
+
if (e instanceof Error) onError === null || onError === void 0 || onError(e);
|
|
924
|
+
return "";
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
Root.displayName = "KubbRoot";
|
|
928
|
+
|
|
929
|
+
//#endregion
|
|
930
|
+
export { NodeTreeContext as _, renderIntrinsic as a, provide as b, TreeNode as c, _defineProperty as d, AsyncEventEmitter as f, createFile as g, _classPrivateFieldInitSpec as h, renderIndent as i, FileManager as l, _classPrivateFieldGet2 as m, createComponent as n, RenderContext as o, _classPrivateFieldSet2 as p, createIntrinsic as r, RootContext as s, Root as t, FileProcessor as u, createContext as v, unprovide as x, inject as y };
|
|
931
|
+
//# sourceMappingURL=Root-BT59jU0W.js.map
|