@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.
Files changed (110) hide show
  1. package/dist/{Fabric-BoTE1-WX.d.cts → Fabric-BbVC650D.d.cts} +86 -15
  2. package/dist/{Fabric-CWquRFa2.d.ts → Fabric-eh92yS1R.d.ts} +86 -15
  3. package/dist/Root-BT59jU0W.js +931 -0
  4. package/dist/Root-BT59jU0W.js.map +1 -0
  5. package/dist/Root-SC_lWG_q.cjs +1057 -0
  6. package/dist/Root-SC_lWG_q.cjs.map +1 -0
  7. package/dist/{defaultParser-CFIT3sEE.cjs → defaultParser-2ym3KiZd.cjs} +3 -4
  8. package/dist/{defaultParser-CFIT3sEE.cjs.map → defaultParser-2ym3KiZd.cjs.map} +1 -1
  9. package/dist/{defaultParser-DZ2kzujH.js → defaultParser-DDFR9BTS.js} +2 -2
  10. package/dist/{defaultParser-DZ2kzujH.js.map → defaultParser-DDFR9BTS.js.map} +1 -1
  11. package/dist/{getRelativePath-y7WcYR5C.js → getRelativePath-COUEoqbz.js} +11 -2
  12. package/dist/getRelativePath-COUEoqbz.js.map +1 -0
  13. package/dist/{getRelativePath-BllDunh0.cjs → getRelativePath-jYLCpluV.cjs} +16 -1
  14. package/dist/getRelativePath-jYLCpluV.cjs.map +1 -0
  15. package/dist/index.cjs +129 -448
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +54 -90
  18. package/dist/index.d.ts +54 -90
  19. package/dist/index.js +92 -416
  20. package/dist/index.js.map +1 -1
  21. package/dist/parsers/typescript.cjs +7 -107
  22. package/dist/parsers/typescript.d.cts +1 -1
  23. package/dist/parsers/typescript.d.ts +1 -1
  24. package/dist/parsers/typescript.js +2 -101
  25. package/dist/parsers.cjs +7 -8
  26. package/dist/parsers.cjs.map +1 -1
  27. package/dist/parsers.d.cts +1 -1
  28. package/dist/parsers.d.ts +1 -1
  29. package/dist/parsers.js +3 -3
  30. package/dist/plugins.cjs +103 -9
  31. package/dist/plugins.cjs.map +1 -1
  32. package/dist/plugins.d.cts +32 -9
  33. package/dist/plugins.d.ts +32 -9
  34. package/dist/plugins.js +96 -3
  35. package/dist/plugins.js.map +1 -1
  36. package/dist/types-BI7rICUP.d.cts +31 -0
  37. package/dist/types-DpITKjSb.d.ts +32 -0
  38. package/dist/types.cjs +6 -0
  39. package/dist/types.cjs.map +1 -1
  40. package/dist/types.d.cts +4 -3
  41. package/dist/types.d.ts +4 -3
  42. package/dist/types.js +1 -1
  43. package/dist/types.js.map +1 -1
  44. package/dist/typescriptParser-DyosyI_A.js +101 -0
  45. package/dist/typescriptParser-DyosyI_A.js.map +1 -0
  46. package/dist/typescriptParser-qjzb2pIh.cjs +137 -0
  47. package/dist/typescriptParser-qjzb2pIh.cjs.map +1 -0
  48. package/dist/{TreeNode-DomNP5og.d.cts → useNodeTree-CmXKaRqq.d.cts} +10 -3
  49. package/dist/{TreeNode-C1VnIF0o.d.ts → useNodeTree-DUdlgys5.d.ts} +10 -3
  50. package/package.json +3 -2
  51. package/src/Fabric.ts +13 -5
  52. package/src/KubbFile.ts +3 -11
  53. package/src/components/App.ts +6 -5
  54. package/src/components/Br.ts +11 -0
  55. package/src/components/Const.ts +6 -5
  56. package/src/components/Dedent.ts +10 -0
  57. package/src/components/File.ts +21 -16
  58. package/src/components/Function.ts +17 -13
  59. package/src/components/Indent.ts +7 -0
  60. package/src/components/Root.ts +6 -5
  61. package/src/components/Type.ts +6 -5
  62. package/src/components/__snapshots__/arrow_function_with_generics.ts +3 -3
  63. package/src/components/__snapshots__/async_arrow_function.ts +3 -3
  64. package/src/components/__snapshots__/async_function.ts +2 -2
  65. package/src/components/__snapshots__/async_function_with_Promise_return_type.ts +2 -2
  66. package/src/components/__snapshots__/basic_arrow_function.ts +3 -3
  67. package/src/components/__snapshots__/basic_export.ts +1 -0
  68. package/src/components/__snapshots__/basic_function.ts +2 -2
  69. package/src/components/__snapshots__/basic_import.ts +1 -0
  70. package/src/components/__snapshots__/default_exported_arrow_function.ts +3 -3
  71. package/src/components/__snapshots__/default_exported_function.ts +2 -2
  72. package/src/components/__snapshots__/exported_arrow_function.ts +3 -3
  73. package/src/components/__snapshots__/exported_function.ts +2 -2
  74. package/src/components/__snapshots__/function_with_JSDoc.ts +2 -2
  75. package/src/components/__snapshots__/function_with_generics.ts +2 -2
  76. package/src/components/__snapshots__/function_with_parameters.ts +2 -2
  77. package/src/components/__snapshots__/function_with_return_type.ts +2 -2
  78. package/src/components/__snapshots__/matches_with_root_import.ts +1 -0
  79. package/src/components/__snapshots__/named_export.ts +1 -0
  80. package/src/components/__snapshots__/named_export_(object_advanced).ts +1 -0
  81. package/src/components/__snapshots__/named_import.ts +1 -0
  82. package/src/components/__snapshots__/named_import_(object).ts +1 -0
  83. package/src/components/__snapshots__/named_import_(object_advanced).ts +1 -0
  84. package/src/components/__snapshots__/named_typed_export.ts +1 -0
  85. package/src/components/__snapshots__/named_typed_import.ts +1 -0
  86. package/src/components/__snapshots__/typed_export.ts +1 -0
  87. package/src/components/__snapshots__/typed_import.ts +1 -0
  88. package/src/contexts/RenderContext.ts +13 -0
  89. package/src/createComponent.ts +34 -0
  90. package/src/index.ts +9 -9
  91. package/src/intrinsic.ts +143 -0
  92. package/src/plugins/fsxPlugin/Runtime.ts +96 -0
  93. package/src/plugins/fsxPlugin/fsxPlugin.ts +45 -0
  94. package/src/plugins/index.ts +1 -0
  95. package/src/types.ts +4 -1
  96. package/dist/TreeNode-CC3a0Bae.js +0 -447
  97. package/dist/TreeNode-CC3a0Bae.js.map +0 -1
  98. package/dist/TreeNode-CFchatCw.cjs +0 -494
  99. package/dist/TreeNode-CFchatCw.cjs.map +0 -1
  100. package/dist/defineParser-CVCxqqzB.cjs +0 -18
  101. package/dist/defineParser-CVCxqqzB.cjs.map +0 -1
  102. package/dist/defineParser-Lco7nlj0.js +0 -13
  103. package/dist/defineParser-Lco7nlj0.js.map +0 -1
  104. package/dist/getRelativePath-BllDunh0.cjs.map +0 -1
  105. package/dist/getRelativePath-y7WcYR5C.js.map +0 -1
  106. package/dist/parsers/typescript.cjs.map +0 -1
  107. package/dist/parsers/typescript.js.map +0 -1
  108. package/dist/types-DYepTJ6F.d.cts +0 -82
  109. package/dist/types-yNaQHNUB.d.ts +0 -83
  110. package/src/components/Text.ts +0 -27
package/dist/index.js CHANGED
@@ -1,89 +1,13 @@
1
1
  import { n as __name } from "./chunk-8X4u0d05.js";
2
- import { a as _assertClassBrand, c as createFile, i as _classPrivateFieldGet2, n as _defineProperty, o as _classPrivateFieldInitSpec, r as _classPrivateFieldSet2, s as _checkPrivateRedeclaration, t as TreeNode } from "./TreeNode-CC3a0Bae.js";
3
- import { n as trimExtName, t as getRelativePath } from "./getRelativePath-y7WcYR5C.js";
4
- import { t as defaultParser } from "./defaultParser-DZ2kzujH.js";
5
- import { orderBy } from "natural-orderby";
6
- import pLimit from "p-limit";
7
- import { EventEmitter } from "node:events";
2
+ import { _ as NodeTreeContext, a as renderIntrinsic, b as provide, c as TreeNode, f as AsyncEventEmitter, g as createFile, i as renderIndent, l as FileManager, n as createComponent, o as RenderContext, r as createIntrinsic, s as RootContext, t as Root, u as FileProcessor, v as createContext, x as unprovide, y as inject } from "./Root-BT59jU0W.js";
3
+ import { t as getRelativePath } from "./getRelativePath-COUEoqbz.js";
4
+ import { n as createImport, r as print, t as createExport } from "./typescriptParser-DyosyI_A.js";
8
5
 
9
- //#region src/context.ts
10
- /**
11
- * Context stack for tracking the current context values
12
- *
13
- * Note: This uses a global Map for simplicity in code generation scenarios.
14
- * For concurrent runtime execution, consider using AsyncLocalStorage or
15
- * instance-based context management.
16
- */
17
- const contextStack = /* @__PURE__ */ new Map();
18
- const contextDefaults = /* @__PURE__ */ new Map();
19
- /**
20
- * Provides a value to descendant components (Vue 3 style)
21
- *
22
- * @example
23
- * ```ts
24
- * const ThemeKey = Symbol('theme')
25
- * provide(ThemeKey, { color: 'blue' })
26
- * ```
27
- */
28
- function provide(key, value) {
29
- if (!contextStack.has(key)) contextStack.set(key, []);
30
- contextStack.get(key).push(value);
31
- }
32
- /**
33
- * Injects a value provided by an ancestor component (Vue 3 style)
34
- *
35
- * @example
36
- * ```ts
37
- * const theme = inject(ThemeKey, { color: 'default' })
38
- * ```
39
- */
40
- function inject(key, defaultValue) {
41
- const stack = contextStack.get(key);
42
- if (!stack || stack.length === 0) {
43
- if (defaultValue !== void 0) return defaultValue;
44
- const storedDefault = contextDefaults.get(key);
45
- if (storedDefault !== void 0) return storedDefault;
46
- throw new Error(`No value provided for key: ${key.toString()}`);
47
- }
48
- return stack[stack.length - 1];
49
- }
50
- /**
51
- * Unprovides a value (for cleanup)
52
- * @internal
53
- */
54
- function unprovide(key) {
55
- const stack = contextStack.get(key);
56
- if (stack && stack.length > 0) stack.pop();
57
- }
58
- /**
59
- * Creates a context key with a default value (React-style compatibility)
60
- *
61
- * @example
62
- * ```ts
63
- * const ThemeContext = createContext({ color: 'blue' })
64
- * // ThemeContext is now typed as Context<{ color: string }>
65
- * const theme = useContext(ThemeContext) // theme is { color: string }
66
- * ```
67
- */
68
- function createContext(defaultValue) {
69
- const key = Symbol("context");
70
- contextDefaults.set(key, defaultValue);
71
- return key;
72
- }
73
-
74
- //#endregion
75
6
  //#region src/composables/useContext.ts
76
7
  function useContext(key, defaultValue) {
77
8
  return inject(key, defaultValue);
78
9
  }
79
10
 
80
- //#endregion
81
- //#region src/contexts/NodeTreeContext.ts
82
- /**
83
- * Context for having the current NodeTree
84
- */
85
- const NodeTreeContext = createContext(null);
86
-
87
11
  //#endregion
88
12
  //#region src/composables/useNodeTree.ts
89
13
  function useNodeTree() {
@@ -105,290 +29,12 @@ const AppContext = createContext({
105
29
  //#region ../../node_modules/.pnpm/remeda@2.33.4/node_modules/remeda/dist/isFunction.js
106
30
  const e = (e$1) => typeof e$1 == `function`;
107
31
 
108
- //#endregion
109
- //#region src/utils/AsyncEventEmitter.ts
110
- var _emitter = /* @__PURE__ */ new WeakMap();
111
- var _mode = /* @__PURE__ */ new WeakMap();
112
- var AsyncEventEmitter = class {
113
- constructor({ maxListener = 100, mode = "sequential" } = {}) {
114
- _classPrivateFieldInitSpec(this, _emitter, new EventEmitter());
115
- _classPrivateFieldInitSpec(this, _mode, void 0);
116
- _classPrivateFieldGet2(_emitter, this).setMaxListeners(maxListener);
117
- _classPrivateFieldSet2(_mode, this, mode);
118
- }
119
- async emit(eventName, ...eventArgs) {
120
- const listeners = _classPrivateFieldGet2(_emitter, this).listeners(eventName);
121
- if (listeners.length === 0) return;
122
- const errors = [];
123
- if (_classPrivateFieldGet2(_mode, this) === "sequential") for (const listener of listeners) try {
124
- await listener(...eventArgs);
125
- } catch (err) {
126
- const error = err instanceof Error ? err : new Error(String(err));
127
- errors.push(error);
128
- }
129
- else {
130
- const promises = listeners.map(async (listener) => {
131
- try {
132
- await listener(...eventArgs);
133
- } catch (err) {
134
- const error = err instanceof Error ? err : new Error(String(err));
135
- errors.push(error);
136
- }
137
- });
138
- await Promise.all(promises);
139
- }
140
- if (errors.length === 1) throw errors[0];
141
- if (errors.length > 1) throw new AggregateError(errors, `Errors in async listeners for "${eventName}"`);
142
- }
143
- on(eventName, handler) {
144
- _classPrivateFieldGet2(_emitter, this).on(eventName, handler);
145
- }
146
- onOnce(eventName, handler) {
147
- const wrapper = (...args) => {
148
- this.off(eventName, wrapper);
149
- handler(...args);
150
- };
151
- this.on(eventName, wrapper);
152
- }
153
- off(eventName, handler) {
154
- _classPrivateFieldGet2(_emitter, this).off(eventName, handler);
155
- }
156
- removeAll() {
157
- _classPrivateFieldGet2(_emitter, this).removeAllListeners();
158
- }
159
- };
160
-
161
- //#endregion
162
- //#region src/FileProcessor.ts
163
- var _limit = /* @__PURE__ */ new WeakMap();
164
- var FileProcessor = class {
165
- constructor({ events = new AsyncEventEmitter() } = {}) {
166
- _classPrivateFieldInitSpec(this, _limit, pLimit(100));
167
- _defineProperty(this, "events", void 0);
168
- this.events = events;
169
- return this;
170
- }
171
- async parse(file, { parsers, extension } = {}) {
172
- const parseExtName = (extension === null || extension === void 0 ? void 0 : extension[file.extname]) || void 0;
173
- if (!parsers) {
174
- console.warn("No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.");
175
- return defaultParser.parse(file, { extname: parseExtName });
176
- }
177
- if (!file.extname) return defaultParser.parse(file, { extname: parseExtName });
178
- const parser = parsers.get(file.extname);
179
- if (!parser) return defaultParser.parse(file, { extname: parseExtName });
180
- return parser.parse(file, { extname: parseExtName });
181
- }
182
- async run(files, { parsers, mode = "sequential", dryRun, extension } = {}) {
183
- await this.events.emit("files:processing:start", files);
184
- const total = files.length;
185
- let processed = 0;
186
- const processOne = async (resolvedFile, index) => {
187
- await this.events.emit("file:processing:start", resolvedFile, index, total);
188
- const source = dryRun ? void 0 : await this.parse(resolvedFile, {
189
- extension,
190
- parsers
191
- });
192
- const currentProcessed = ++processed;
193
- const percentage = currentProcessed / total * 100;
194
- await this.events.emit("file:processing:update", {
195
- file: resolvedFile,
196
- source,
197
- processed: currentProcessed,
198
- percentage,
199
- total
200
- });
201
- await this.events.emit("file:processing:end", resolvedFile, index, total);
202
- };
203
- if (mode === "sequential") {
204
- async function* asyncFiles() {
205
- for (let index = 0; index < files.length; index++) yield [files[index], index];
206
- }
207
- for await (const [file, index] of asyncFiles()) if (file) await processOne(file, index);
208
- } else {
209
- const promises = files.map((resolvedFile, index) => _classPrivateFieldGet2(_limit, this).call(this, () => processOne(resolvedFile, index)));
210
- await Promise.all(promises);
211
- }
212
- await this.events.emit("files:processing:end", files);
213
- return files;
214
- }
215
- };
216
-
217
- //#endregion
218
- //#region src/utils/Cache.ts
219
- var _buffer = /* @__PURE__ */ new WeakMap();
220
- var Cache = class {
221
- constructor() {
222
- _classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
223
- }
224
- get(key) {
225
- var _this$buffer$get;
226
- return (_this$buffer$get = _classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
227
- }
228
- set(key, value) {
229
- _classPrivateFieldGet2(_buffer, this).set(key, value);
230
- }
231
- delete(key) {
232
- _classPrivateFieldGet2(_buffer, this).delete(key);
233
- }
234
- clear() {
235
- _classPrivateFieldGet2(_buffer, this).clear();
236
- }
237
- keys() {
238
- return [..._classPrivateFieldGet2(_buffer, this).keys()];
239
- }
240
- values() {
241
- return [..._classPrivateFieldGet2(_buffer, this).values()];
242
- }
243
- flush() {}
244
- };
245
-
246
- //#endregion
247
- //#region \0@oxc-project+runtime@0.107.0/helpers/classPrivateMethodInitSpec.js
248
- function _classPrivateMethodInitSpec(e$1, a) {
249
- _checkPrivateRedeclaration(e$1, a), a.add(e$1);
250
- }
251
-
252
- //#endregion
253
- //#region src/FileManager.ts
254
- function mergeFile(a, b) {
255
- return {
256
- ...a,
257
- sources: [...a.sources || [], ...b.sources || []],
258
- imports: [...a.imports || [], ...b.imports || []],
259
- exports: [...a.exports || [], ...b.exports || []]
260
- };
261
- }
262
- var _cache = /* @__PURE__ */ new WeakMap();
263
- var _filesCache = /* @__PURE__ */ new WeakMap();
264
- var _FileManager_brand = /* @__PURE__ */ new WeakSet();
265
- var FileManager = class {
266
- constructor({ events = new AsyncEventEmitter() } = {}) {
267
- _classPrivateMethodInitSpec(this, _FileManager_brand);
268
- _classPrivateFieldInitSpec(this, _cache, new Cache());
269
- _classPrivateFieldInitSpec(this, _filesCache, null);
270
- _defineProperty(this, "events", void 0);
271
- _defineProperty(this, "processor", void 0);
272
- this.processor = new FileProcessor({ events });
273
- this.events = events;
274
- return this;
275
- }
276
- add(...files) {
277
- const resolvedFiles = [];
278
- const mergedFiles = /* @__PURE__ */ new Map();
279
- files.forEach((file) => {
280
- const existing = mergedFiles.get(file.path);
281
- if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
282
- else mergedFiles.set(file.path, file);
283
- });
284
- for (let file of mergedFiles.values()) {
285
- file = _assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
286
- file = _assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
287
- const resolvedFile = createFile(file);
288
- _classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
289
- this.flush();
290
- resolvedFiles.push(resolvedFile);
291
- }
292
- this.events.emit("files:added", resolvedFiles);
293
- return resolvedFiles;
294
- }
295
- upsert(...files) {
296
- const resolvedFiles = [];
297
- const mergedFiles = /* @__PURE__ */ new Map();
298
- files.forEach((file) => {
299
- const existing = mergedFiles.get(file.path);
300
- if (existing) mergedFiles.set(file.path, mergeFile(existing, file));
301
- else mergedFiles.set(file.path, file);
302
- });
303
- for (let file of mergedFiles.values()) {
304
- const existing = _classPrivateFieldGet2(_cache, this).get(file.path);
305
- file = _assertClassBrand(_FileManager_brand, this, _resolveName).call(this, file);
306
- file = _assertClassBrand(_FileManager_brand, this, _resolvePath).call(this, file);
307
- const resolvedFile = createFile(existing ? mergeFile(existing, file) : file);
308
- _classPrivateFieldGet2(_cache, this).set(resolvedFile.path, resolvedFile);
309
- this.flush();
310
- resolvedFiles.push(resolvedFile);
311
- }
312
- this.events.emit("files:added", resolvedFiles);
313
- return resolvedFiles;
314
- }
315
- flush() {
316
- _classPrivateFieldSet2(_filesCache, this, null);
317
- _classPrivateFieldGet2(_cache, this).flush();
318
- }
319
- getByPath(path) {
320
- return _classPrivateFieldGet2(_cache, this).get(path);
321
- }
322
- deleteByPath(path) {
323
- _classPrivateFieldGet2(_cache, this).delete(path);
324
- _classPrivateFieldSet2(_filesCache, this, null);
325
- }
326
- clear() {
327
- _classPrivateFieldGet2(_cache, this).clear();
328
- _classPrivateFieldSet2(_filesCache, this, null);
329
- }
330
- get files() {
331
- if (_classPrivateFieldGet2(_filesCache, this)) return _classPrivateFieldGet2(_filesCache, this);
332
- const keys = orderBy(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => trimExtName(v).endsWith("index")]);
333
- const files = [];
334
- for (const key of keys) {
335
- const file = _classPrivateFieldGet2(_cache, this).get(key);
336
- if (file) files.push(file);
337
- }
338
- _classPrivateFieldSet2(_filesCache, this, files);
339
- return files;
340
- }
341
- async write(options) {
342
- await this.events.emit("files:writing:start", this.files);
343
- const resolvedFiles = await this.processor.run(this.files, options);
344
- this.clear();
345
- await this.events.emit("files:writing:end", resolvedFiles);
346
- return resolvedFiles;
347
- }
348
- };
349
- function _resolvePath(file) {
350
- this.events.emit("file:resolve:path", file);
351
- return file;
352
- }
353
- function _resolveName(file) {
354
- this.events.emit("file:resolve:name", file);
355
- return file;
356
- }
357
-
358
- //#endregion
359
- //#region src/contexts/RootContext.ts
360
- /**
361
- * Context providing root-level functionalities such as exit hook, tree node structure, and file management.
362
- * Define in the `render` helper of the runtime.
363
- */
364
- const RootContext = createContext({
365
- exit: () => {},
366
- treeNode: new TreeNode({
367
- type: "Root",
368
- props: {}
369
- }),
370
- fileManager: new FileManager()
371
- });
372
-
373
- //#endregion
374
- //#region src/components/Text.ts
375
- /**
376
- * Generates a text node from string or function returning string/array of strings.
377
- */
378
- function Text({ children }) {
379
- if (!children) return "";
380
- if (typeof children === "string") return children;
381
- const value = children();
382
- if (Array.isArray(value)) return value.join("\n");
383
- return value || "";
384
- }
385
-
386
32
  //#endregion
387
33
  //#region src/components/App.ts
388
34
  /**
389
35
  * App container containing the AppContext carrying `meta` and an `exit` hook.
390
36
  */
391
- function App({ children, ...props }) {
37
+ const App = createComponent("App", ({ children, ...props }) => {
392
38
  const { meta = {} } = props;
393
39
  const { exit } = useContext(RootContext);
394
40
  const nodeTree = useNodeTree();
@@ -400,10 +46,20 @@ function App({ children, ...props }) {
400
46
  exit,
401
47
  meta
402
48
  });
403
- return Text({ children });
404
- }
49
+ return children;
50
+ });
405
51
  App.displayName = "KubbApp";
406
52
 
53
+ //#endregion
54
+ //#region src/components/Br.ts
55
+ /**
56
+ * Generates a line break in the output.
57
+ */
58
+ const Br = createComponent("br", () => {
59
+ return createIntrinsic("br");
60
+ });
61
+ Br.displayName = "Br";
62
+
407
63
  //#endregion
408
64
  //#region src/utils/createJSDoc.ts
409
65
  /**
@@ -425,7 +81,7 @@ function createJSDoc({ comments }) {
425
81
  /**
426
82
  * Generates a TypeScript constant declaration.
427
83
  */
428
- function Const({ children, ...props }) {
84
+ const Const = createComponent("Const", ({ children, ...props }) => {
429
85
  const { name, export: canExport, type, JSDoc, asConst } = props;
430
86
  const nodeTree = useNodeTree();
431
87
  if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
@@ -442,10 +98,20 @@ function Const({ children, ...props }) {
442
98
  if (type) result += `: ${type}`;
443
99
  result += ` = ${children ? children : ""}`;
444
100
  if (asConst) result += " as const";
445
- return Text({ children: result });
446
- }
101
+ return result;
102
+ });
447
103
  Const.displayName = "KubbConst";
448
104
 
105
+ //#endregion
106
+ //#region src/components/Dedent.ts
107
+ /**
108
+ * Dedent component for reducing indentation level in rendered output.
109
+ */
110
+ const Dedent = createComponent("dedent", () => {
111
+ return createIntrinsic("dedent");
112
+ });
113
+ Dedent.displayName = "Dedent";
114
+
449
115
  //#endregion
450
116
  //#region src/contexts/FileContext.ts
451
117
  /**
@@ -478,7 +144,7 @@ function useFileManager() {
478
144
  /**
479
145
  * Adds files to the FileManager
480
146
  */
481
- function File({ children, ...props }) {
147
+ const File = createComponent("File", ({ children, ...props }) => {
482
148
  const { baseName, path, meta = {}, footer, banner } = props;
483
149
  const fileManager = useFileManager();
484
150
  const nodeTree = useNodeTree();
@@ -498,14 +164,14 @@ function File({ children, ...props }) {
498
164
  };
499
165
  const [resolvedFile] = fileManager.add(file);
500
166
  provide(FileContext, resolvedFile);
501
- return Text({ children });
502
- }
167
+ return children;
168
+ });
503
169
  /**
504
170
  * FileSource - for adding source code to a file
505
171
  *
506
172
  * Returns the provided children string so the fsx renderer can collect it.
507
173
  */
508
- function FileSource({ children, ...props }) {
174
+ const FileSource = createComponent("FileSource", ({ children, ...props }) => {
509
175
  const { name, isExportable, isIndexable, isTypeOnly } = props;
510
176
  const nodeTree = useNodeTree();
511
177
  const file = useFile();
@@ -513,21 +179,22 @@ function FileSource({ children, ...props }) {
513
179
  type: "FileSource",
514
180
  props
515
181
  }));
182
+ const value = renderIntrinsic(children);
516
183
  if (file) file.sources.push({
517
184
  name,
518
185
  isExportable,
519
186
  isIndexable,
520
187
  isTypeOnly,
521
- value: Text({ children })
188
+ value
522
189
  });
523
- return Text({ children });
524
- }
190
+ return value;
191
+ });
525
192
  /**
526
193
  * FileExport - for adding exports to a file
527
194
  *
528
195
  * No-op function used by renderers to record exports.
529
196
  */
530
- function FileExport(props) {
197
+ const FileExport = createComponent("FileExport", (props) => {
531
198
  const { name, path, isTypeOnly, asAlias } = props;
532
199
  const nodeTree = useNodeTree();
533
200
  const file = useFile();
@@ -541,14 +208,19 @@ function FileExport(props) {
541
208
  asAlias,
542
209
  isTypeOnly
543
210
  });
544
- return Text({ children: "" });
545
- }
211
+ return print(createExport({
212
+ name,
213
+ path,
214
+ isTypeOnly,
215
+ asAlias
216
+ }));
217
+ });
546
218
  /**
547
219
  * FileImport - for adding imports to a file
548
220
  *
549
221
  * No-op function used by renderers to record imports.
550
222
  */
551
- function FileImport(props) {
223
+ const FileImport = createComponent("FileImport", (props) => {
552
224
  const { name, path, root, isNameSpace, isTypeOnly } = props;
553
225
  const nodeTree = useNodeTree();
554
226
  const file = useFile();
@@ -563,18 +235,31 @@ function FileImport(props) {
563
235
  isNameSpace,
564
236
  isTypeOnly
565
237
  });
566
- return Text({ children: "" });
567
- }
238
+ return print(createImport({
239
+ name,
240
+ path,
241
+ root,
242
+ isNameSpace,
243
+ isTypeOnly
244
+ }));
245
+ });
568
246
  File.Source = FileSource;
569
247
  File.Import = FileImport;
570
248
  File.Export = FileExport;
571
249
 
250
+ //#endregion
251
+ //#region src/components/Indent.ts
252
+ const Indent = createComponent("indent", () => {
253
+ return createIntrinsic("indent");
254
+ });
255
+ Indent.displayName = "Indent";
256
+
572
257
  //#endregion
573
258
  //#region src/components/Function.ts
574
259
  /**
575
260
  * Generates a TypeScript function declaration.
576
261
  */
577
- function Function({ children, ...props }) {
262
+ const Function = createComponent("Function", ({ children, ...props }) => {
578
263
  const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc } = props;
579
264
  const nodeTree = useNodeTree();
580
265
  if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
@@ -599,11 +284,17 @@ function Function({ children, ...props }) {
599
284
  if (returnType && !async) parts.push(`: ${returnType}`);
600
285
  if (returnType && async) parts.push(`: Promise<${returnType}>`);
601
286
  parts.push(" {");
602
- if (children) return Text({ children: `${parts.join("")}
603
- ${children}
604
- }` });
605
- return Text({ children: `${parts.join("")}}` });
606
- }
287
+ if (children) return [
288
+ parts.join(""),
289
+ Br(),
290
+ Indent(),
291
+ children,
292
+ Br(),
293
+ Dedent(),
294
+ "}"
295
+ ];
296
+ return [parts.join(""), "}"];
297
+ });
607
298
  Function.displayName = "KubbFunction";
608
299
  /**
609
300
  * ArrowFunction
@@ -612,7 +303,7 @@ Function.displayName = "KubbFunction";
612
303
  * the same options as `Function`. Use `singleLine` to produce a one-line
613
304
  * arrow expression.
614
305
  */
615
- function ArrowFunction({ children, ...props }) {
306
+ const ArrowFunction = createComponent("ArrowFunction", ({ children, ...props }) => {
616
307
  const { name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine } = props;
617
308
  const nodeTree = useNodeTree();
618
309
  if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
@@ -638,44 +329,29 @@ function ArrowFunction({ children, ...props }) {
638
329
  if (returnType && async) parts.push(`: Promise<${returnType}>`);
639
330
  if (singleLine) {
640
331
  parts.push(` => ${children || ""}\n`);
641
- return Text({ children: parts.join("") });
642
- }
643
- if (children) return Text({ children: `${parts.join("")} => {
644
- ${children}
645
- }
646
- ` });
647
- return Text({ children: `${parts.join("")} => {}\n` });
648
- }
332
+ return parts.join("");
333
+ }
334
+ if (children) return [
335
+ parts.join(""),
336
+ " => {",
337
+ Br(),
338
+ Indent(),
339
+ children,
340
+ Br(),
341
+ Dedent(),
342
+ "}"
343
+ ];
344
+ return [parts.join(""), " => {}"];
345
+ });
649
346
  ArrowFunction.displayName = "KubbArrowFunction";
650
347
  Function.Arrow = ArrowFunction;
651
348
 
652
- //#endregion
653
- //#region src/components/Root.ts
654
- /**
655
- * This component provides the root behavior for the Fabric runtime.
656
- */
657
- function Root({ onError, onExit, treeNode, fileManager, children }) {
658
- provide(RootContext, {
659
- exit: onExit,
660
- treeNode,
661
- fileManager
662
- });
663
- provide(NodeTreeContext, treeNode);
664
- try {
665
- return Text({ children });
666
- } catch (e$1) {
667
- if (e$1 instanceof Error) onError === null || onError === void 0 || onError(e$1);
668
- return "";
669
- }
670
- }
671
- Root.displayName = "KubbRoot";
672
-
673
349
  //#endregion
674
350
  //#region src/components/Type.ts
675
351
  /**
676
352
  * Generates a TypeScript type declaration.
677
353
  */
678
- function Type({ children, ...props }) {
354
+ const Type = createComponent("Type", ({ children, ...props }) => {
679
355
  const { name, export: canExport, JSDoc } = props;
680
356
  const nodeTree = useNodeTree();
681
357
  if (nodeTree) provide(NodeTreeContext, nodeTree.addChild({
@@ -690,8 +366,8 @@ function Type({ children, ...props }) {
690
366
  }
691
367
  if (canExport) result += "export ";
692
368
  result += `type ${name} = ${children || ""}`;
693
- return Text({ children: result });
694
- }
369
+ return result;
370
+ });
695
371
  Type.displayName = "KubbType";
696
372
 
697
373
  //#endregion
@@ -791,5 +467,5 @@ function createFabric(config = { mode: "sequential" }) {
791
467
  }
792
468
 
793
469
  //#endregion
794
- export { App, AppContext, Const, File, FileContext, FileManager, FileProcessor, Function, NodeTreeContext, Root, RootContext, Text, TreeNode, Type, createContext, createFabric, createFile, createJSDoc, getRelativePath, inject, provide, unprovide, useApp, useContext, useFile, useFileManager, useLifecycle, useNodeTree };
470
+ export { App, AppContext, Br, Const, Dedent, File, FileContext, FileManager, FileProcessor, Function, Indent, NodeTreeContext, RenderContext, Root, RootContext, TreeNode, Type, createComponent, createContext, createFabric, createFile, createJSDoc, getRelativePath, inject, provide, renderIndent, renderIntrinsic, unprovide, useApp, useContext, useFile, useFileManager, useLifecycle, useNodeTree };
795
471
  //# sourceMappingURL=index.js.map