@kubb/fabric-core 0.1.3 → 0.1.5

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 (56) hide show
  1. package/dist/{App-DUFbq4lD.d.ts → App-9ie0H1SF.d.ts} +24 -24
  2. package/dist/{App-DoQNlnGL.d.cts → App-KqAHuAyU.d.cts} +24 -24
  3. package/dist/createParser-B_RpW6sx.js +17 -0
  4. package/dist/createParser-B_RpW6sx.js.map +1 -0
  5. package/dist/createParser-DZB5qExa.cjs +29 -0
  6. package/dist/createParser-DZB5qExa.cjs.map +1 -0
  7. package/dist/defaultParser-Dl-OrbH1.cjs +20 -0
  8. package/dist/defaultParser-Dl-OrbH1.cjs.map +1 -0
  9. package/dist/defaultParser-vwyTb1XT.js +15 -0
  10. package/dist/defaultParser-vwyTb1XT.js.map +1 -0
  11. package/dist/index-BpPNNyhl.d.ts +18 -0
  12. package/dist/index-DLITiDO5.d.cts +18 -0
  13. package/dist/index.cjs +39 -68
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +3 -14
  16. package/dist/index.d.ts +3 -14
  17. package/dist/index.js +33 -62
  18. package/dist/index.js.map +1 -1
  19. package/dist/parsers/typescript.cjs +2 -1
  20. package/dist/parsers/typescript.d.cts +2 -2
  21. package/dist/parsers/typescript.d.ts +2 -2
  22. package/dist/parsers/typescript.js +2 -1
  23. package/dist/parsers.cjs +19 -6
  24. package/dist/parsers.cjs.map +1 -0
  25. package/dist/parsers.d.cts +2 -2
  26. package/dist/parsers.d.ts +2 -2
  27. package/dist/parsers.js +16 -3
  28. package/dist/parsers.js.map +1 -0
  29. package/dist/plugins.cjs +8 -6
  30. package/dist/plugins.cjs.map +1 -1
  31. package/dist/plugins.d.cts +19 -8
  32. package/dist/plugins.d.ts +19 -8
  33. package/dist/plugins.js +8 -6
  34. package/dist/plugins.js.map +1 -1
  35. package/dist/types.d.cts +2 -2
  36. package/dist/types.d.ts +2 -2
  37. package/dist/{typescriptParser-BBGeFKlP.js → typescriptParser-CrzOv_Aw.js} +3 -17
  38. package/dist/typescriptParser-CrzOv_Aw.js.map +1 -0
  39. package/dist/{typescriptParser-C9WJrwRd.d.ts → typescriptParser-Dk1rwKyJ.d.ts} +2 -2
  40. package/dist/{typescriptParser-DOD1_QTe.d.cts → typescriptParser-Du4RIToQ.d.cts} +2 -2
  41. package/dist/{typescriptParser-BBbbmG5W.cjs → typescriptParser-JawJ8wET.cjs} +5 -31
  42. package/dist/{typescriptParser-BBGeFKlP.js.map → typescriptParser-JawJ8wET.cjs.map} +1 -1
  43. package/package.json +1 -1
  44. package/src/App.ts +26 -14
  45. package/src/FileProcessor.ts +13 -12
  46. package/src/createApp.ts +1 -13
  47. package/src/defineApp.ts +24 -34
  48. package/src/plugins/fsPlugin.ts +35 -13
  49. package/src/plugins/types.ts +3 -3
  50. package/dist/defineApp-C6WnoREI.d.ts +0 -14
  51. package/dist/defineApp-D1-njmtr.d.cts +0 -14
  52. package/dist/tsxParser-C741ZKCN.js +0 -26
  53. package/dist/tsxParser-C741ZKCN.js.map +0 -1
  54. package/dist/tsxParser-HDf_3TMc.cjs +0 -37
  55. package/dist/tsxParser-HDf_3TMc.cjs.map +0 -1
  56. package/dist/typescriptParser-BBbbmG5W.cjs.map +0 -1
@@ -116,37 +116,37 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
116
116
  };
117
117
  //#endregion
118
118
  //#region src/plugins/types.d.ts
119
- type Plugin<TOptions$1 = any[], TAppExtension$1 extends Record<string, any> = {}> = {
119
+ type Plugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = {
120
120
  name: string;
121
121
  type: 'plugin';
122
- scope?: 'write' | 'read' | (string & {});
123
- install: Install<TOptions$1> | Promise<Install<TOptions$1>>;
122
+ install: Install<TOptions> | Promise<Install<TOptions>>;
124
123
  /**
125
124
  * Runtime app overrides or extensions.
126
125
  * Merged into the app instance after install.
126
+ * This cannot be async
127
127
  */
128
- override?: Override<TOptions$1, TAppExtension$1>;
128
+ inject?: Inject<TOptions, TAppExtension$1>;
129
129
  };
130
- type UserPlugin<TOptions$1 = any[], TAppExtension$1 extends Record<string, any> = {}> = Omit<Plugin<TOptions$1, TAppExtension$1>, 'type'>;
130
+ type UserPlugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = Omit<Plugin<TOptions, TAppExtension$1>, 'type'>;
131
131
  //#endregion
132
132
  //#region src/parsers/types.d.ts
133
133
  type PrintOptions = {
134
134
  extname?: Extname;
135
135
  };
136
- type Parser<TOptions$1 = any[], TMeta$1 extends object = any> = {
136
+ type Parser<TOptions = any[], TMeta$1 extends object = any> = {
137
137
  name: string;
138
138
  type: 'parser';
139
139
  /**
140
140
  * Undefined is being used for the defaultParser
141
141
  */
142
142
  extNames: Array<Extname> | undefined;
143
- install: Install<TOptions$1>;
143
+ install: Install<TOptions>;
144
144
  /**
145
145
  * Convert a file to string
146
146
  */
147
147
  parse(file: ResolvedFile<TMeta$1>, options: PrintOptions): Promise<string>;
148
148
  };
149
- type UserParser<TOptions$1 = any[], TMeta$1 extends object = any> = Omit<Parser<TOptions$1, TMeta$1>, 'type'>;
149
+ type UserParser<TOptions = any[], TMeta$1 extends object = any> = Omit<Parser<TOptions, TMeta$1>, 'type'>;
150
150
  //#endregion
151
151
  //#region src/utils/AsyncEventEmitter.d.ts
152
152
  declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
@@ -208,20 +208,21 @@ declare class FileManager {
208
208
  }
209
209
  //#endregion
210
210
  //#region src/App.d.ts
211
+ declare global {
212
+ namespace Kubb {
213
+ interface App {}
214
+ }
215
+ }
211
216
  type Component = any;
212
217
  type AppEvents = {
213
218
  /**
214
219
  * Called in the beginning of the app lifecycle.
215
220
  */
216
- start: [{
217
- app: App;
218
- }];
221
+ start: [];
219
222
  /**
220
223
  * Called in the end of the app lifecycle.
221
224
  */
222
- end: [{
223
- app: App;
224
- }];
225
+ end: [];
225
226
  /**
226
227
  * Called when being rendered
227
228
  */
@@ -268,25 +269,24 @@ type AppEvents = {
268
269
  files: ResolvedFile[];
269
270
  }];
270
271
  };
271
- type AppContext<TOptions$1 = unknown> = {
272
- options?: TOptions$1;
272
+ type AppContext<TOptions = unknown> = {
273
+ options?: TOptions;
273
274
  events: AsyncEventEmitter<AppEvents>;
274
275
  fileManager: FileManager;
275
276
  installedPlugins: Set<Plugin>;
276
277
  installedParsers: Set<Parser>;
277
278
  };
278
- type Install<TOptions$1 = any[] | object | undefined> = TOptions$1 extends any[] ? (app: App, context: AppContext, ...options: TOptions$1) => void : TOptions$1 extends object ? (app: App, context: AppContext, options?: TOptions$1) => void : (app: App, context: AppContext) => void;
279
- type Override<TOptions$1 = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions$1 extends any[] ? (app: App, context: AppContext, ...options: TOptions$1) => Partial<TAppExtension$1> : TOptions$1 extends object ? (app: App, context: AppContext, options?: TOptions$1) => Partial<TAppExtension$1> : (app: App, context: AppContext) => Partial<TAppExtension$1>;
280
- interface App {
281
- _component: Component;
282
- render(): Promise<void>;
283
- renderToString(): Promise<string>;
279
+ type Install<TOptions = any[] | object | undefined> = TOptions extends any[] ? (app: App, ...options: TOptions) => void : TOptions extends object ? (app: App, options?: TOptions) => void : (app: App) => void;
280
+ type Inject<TOptions = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions extends any[] ? (app: App, ...options: TOptions) => Partial<TAppExtension$1> : TOptions extends object ? (app: App, options?: TOptions) => Partial<TAppExtension$1> : (app: App) => Partial<TAppExtension$1>;
281
+ interface App<TOptions = unknown> extends Kubb.App {
282
+ context: AppContext<TOptions>;
284
283
  files: Array<ResolvedFile>;
285
284
  use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): this & TAppExtension;
286
285
  use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): this & TAppExtension;
286
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): Promise<this & TAppExtension>;
287
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): Promise<this & TAppExtension>;
287
288
  addFile(...files: Array<File>): Promise<void>;
288
- waitUntilExit(): Promise<void>;
289
289
  }
290
290
  //#endregion
291
291
  export { FileProcessor as a, Plugin as c, File as d, KubbFile_d_exports as f, FileManager as i, UserPlugin as l, AppContext as n, Parser as o, ResolvedFile as p, Component as r, UserParser as s, App as t, Extname as u };
292
- //# sourceMappingURL=App-DUFbq4lD.d.ts.map
292
+ //# sourceMappingURL=App-9ie0H1SF.d.ts.map
@@ -116,37 +116,37 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
116
116
  };
117
117
  //#endregion
118
118
  //#region src/plugins/types.d.ts
119
- type Plugin<TOptions$1 = any[], TAppExtension$1 extends Record<string, any> = {}> = {
119
+ type Plugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = {
120
120
  name: string;
121
121
  type: 'plugin';
122
- scope?: 'write' | 'read' | (string & {});
123
- install: Install<TOptions$1> | Promise<Install<TOptions$1>>;
122
+ install: Install<TOptions> | Promise<Install<TOptions>>;
124
123
  /**
125
124
  * Runtime app overrides or extensions.
126
125
  * Merged into the app instance after install.
126
+ * This cannot be async
127
127
  */
128
- override?: Override<TOptions$1, TAppExtension$1>;
128
+ inject?: Inject<TOptions, TAppExtension$1>;
129
129
  };
130
- type UserPlugin<TOptions$1 = any[], TAppExtension$1 extends Record<string, any> = {}> = Omit<Plugin<TOptions$1, TAppExtension$1>, 'type'>;
130
+ type UserPlugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = Omit<Plugin<TOptions, TAppExtension$1>, 'type'>;
131
131
  //#endregion
132
132
  //#region src/parsers/types.d.ts
133
133
  type PrintOptions = {
134
134
  extname?: Extname;
135
135
  };
136
- type Parser<TOptions$1 = any[], TMeta$1 extends object = any> = {
136
+ type Parser<TOptions = any[], TMeta$1 extends object = any> = {
137
137
  name: string;
138
138
  type: 'parser';
139
139
  /**
140
140
  * Undefined is being used for the defaultParser
141
141
  */
142
142
  extNames: Array<Extname> | undefined;
143
- install: Install<TOptions$1>;
143
+ install: Install<TOptions>;
144
144
  /**
145
145
  * Convert a file to string
146
146
  */
147
147
  parse(file: ResolvedFile<TMeta$1>, options: PrintOptions): Promise<string>;
148
148
  };
149
- type UserParser<TOptions$1 = any[], TMeta$1 extends object = any> = Omit<Parser<TOptions$1, TMeta$1>, 'type'>;
149
+ type UserParser<TOptions = any[], TMeta$1 extends object = any> = Omit<Parser<TOptions, TMeta$1>, 'type'>;
150
150
  //#endregion
151
151
  //#region src/utils/AsyncEventEmitter.d.ts
152
152
  declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
@@ -208,20 +208,21 @@ declare class FileManager {
208
208
  }
209
209
  //#endregion
210
210
  //#region src/App.d.ts
211
+ declare global {
212
+ namespace Kubb {
213
+ interface App {}
214
+ }
215
+ }
211
216
  type Component = any;
212
217
  type AppEvents = {
213
218
  /**
214
219
  * Called in the beginning of the app lifecycle.
215
220
  */
216
- start: [{
217
- app: App;
218
- }];
221
+ start: [];
219
222
  /**
220
223
  * Called in the end of the app lifecycle.
221
224
  */
222
- end: [{
223
- app: App;
224
- }];
225
+ end: [];
225
226
  /**
226
227
  * Called when being rendered
227
228
  */
@@ -268,25 +269,24 @@ type AppEvents = {
268
269
  files: ResolvedFile[];
269
270
  }];
270
271
  };
271
- type AppContext<TOptions$1 = unknown> = {
272
- options?: TOptions$1;
272
+ type AppContext<TOptions = unknown> = {
273
+ options?: TOptions;
273
274
  events: AsyncEventEmitter<AppEvents>;
274
275
  fileManager: FileManager;
275
276
  installedPlugins: Set<Plugin>;
276
277
  installedParsers: Set<Parser>;
277
278
  };
278
- type Install<TOptions$1 = any[] | object | undefined> = TOptions$1 extends any[] ? (app: App, context: AppContext, ...options: TOptions$1) => void : TOptions$1 extends object ? (app: App, context: AppContext, options?: TOptions$1) => void : (app: App, context: AppContext) => void;
279
- type Override<TOptions$1 = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions$1 extends any[] ? (app: App, context: AppContext, ...options: TOptions$1) => Partial<TAppExtension$1> : TOptions$1 extends object ? (app: App, context: AppContext, options?: TOptions$1) => Partial<TAppExtension$1> : (app: App, context: AppContext) => Partial<TAppExtension$1>;
280
- interface App {
281
- _component: Component;
282
- render(): Promise<void>;
283
- renderToString(): Promise<string>;
279
+ type Install<TOptions = any[] | object | undefined> = TOptions extends any[] ? (app: App, ...options: TOptions) => void : TOptions extends object ? (app: App, options?: TOptions) => void : (app: App) => void;
280
+ type Inject<TOptions = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions extends any[] ? (app: App, ...options: TOptions) => Partial<TAppExtension$1> : TOptions extends object ? (app: App, options?: TOptions) => Partial<TAppExtension$1> : (app: App) => Partial<TAppExtension$1>;
281
+ interface App<TOptions = unknown> extends Kubb.App {
282
+ context: AppContext<TOptions>;
284
283
  files: Array<ResolvedFile>;
285
284
  use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): this & TAppExtension;
286
285
  use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): this & TAppExtension;
286
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): Promise<this & TAppExtension>;
287
+ use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): Promise<this & TAppExtension>;
287
288
  addFile(...files: Array<File>): Promise<void>;
288
- waitUntilExit(): Promise<void>;
289
289
  }
290
290
  //#endregion
291
291
  export { FileProcessor as a, Plugin as c, File as d, KubbFile_d_exports as f, FileManager as i, UserPlugin as l, AppContext as n, Parser as o, ResolvedFile as p, Component as r, UserParser as s, App as t, Extname as u };
292
- //# sourceMappingURL=App-DoQNlnGL.d.cts.map
292
+ //# sourceMappingURL=App-KqAHuAyU.d.cts.map
@@ -0,0 +1,17 @@
1
+ //#region src/utils/trimExtName.ts
2
+ function trimExtName(text) {
3
+ return text.replace(/\.[^/.]+$/, "");
4
+ }
5
+
6
+ //#endregion
7
+ //#region src/parsers/createParser.ts
8
+ function createParser(parser) {
9
+ return {
10
+ type: "parser",
11
+ ...parser
12
+ };
13
+ }
14
+
15
+ //#endregion
16
+ export { trimExtName as n, createParser as t };
17
+ //# sourceMappingURL=createParser-B_RpW6sx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createParser-B_RpW6sx.js","names":[],"sources":["../src/utils/trimExtName.ts","../src/parsers/createParser.ts"],"sourcesContent":["export function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import type { Parser, UserParser } from './types.ts'\n\nexport function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\n}\n"],"mappings":";AAAA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;;;;;ACCtC,SAAgB,aAA2D,QAA8D;AACvI,QAAO;EACL,MAAM;EACN,GAAG;EACJ"}
@@ -0,0 +1,29 @@
1
+
2
+ //#region src/utils/trimExtName.ts
3
+ function trimExtName(text) {
4
+ return text.replace(/\.[^/.]+$/, "");
5
+ }
6
+
7
+ //#endregion
8
+ //#region src/parsers/createParser.ts
9
+ function createParser(parser) {
10
+ return {
11
+ type: "parser",
12
+ ...parser
13
+ };
14
+ }
15
+
16
+ //#endregion
17
+ Object.defineProperty(exports, 'createParser', {
18
+ enumerable: true,
19
+ get: function () {
20
+ return createParser;
21
+ }
22
+ });
23
+ Object.defineProperty(exports, 'trimExtName', {
24
+ enumerable: true,
25
+ get: function () {
26
+ return trimExtName;
27
+ }
28
+ });
29
+ //# sourceMappingURL=createParser-DZB5qExa.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createParser-DZB5qExa.cjs","names":[],"sources":["../src/utils/trimExtName.ts","../src/parsers/createParser.ts"],"sourcesContent":["export function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import type { Parser, UserParser } from './types.ts'\n\nexport function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\n}\n"],"mappings":";;AAAA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;;;;;ACCtC,SAAgB,aAA2D,QAA8D;AACvI,QAAO;EACL,MAAM;EACN,GAAG;EACJ"}
@@ -0,0 +1,20 @@
1
+ const require_createParser = require('./createParser-DZB5qExa.cjs');
2
+
3
+ //#region src/parsers/defaultParser.ts
4
+ const defaultParser = require_createParser.createParser({
5
+ name: "default",
6
+ extNames: [".json"],
7
+ install() {},
8
+ async parse(file) {
9
+ return file.sources.map((item) => item.value).join("\n\n");
10
+ }
11
+ });
12
+
13
+ //#endregion
14
+ Object.defineProperty(exports, 'defaultParser', {
15
+ enumerable: true,
16
+ get: function () {
17
+ return defaultParser;
18
+ }
19
+ });
20
+ //# sourceMappingURL=defaultParser-Dl-OrbH1.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultParser-Dl-OrbH1.cjs","names":["createParser"],"sources":["../src/parsers/defaultParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\n\nexport const defaultParser = createParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgBA,kCAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { t as createParser } from "./createParser-B_RpW6sx.js";
2
+
3
+ //#region src/parsers/defaultParser.ts
4
+ const defaultParser = createParser({
5
+ name: "default",
6
+ extNames: [".json"],
7
+ install() {},
8
+ async parse(file) {
9
+ return file.sources.map((item) => item.value).join("\n\n");
10
+ }
11
+ });
12
+
13
+ //#endregion
14
+ export { defaultParser as t };
15
+ //# sourceMappingURL=defaultParser-vwyTb1XT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultParser-vwyTb1XT.js","names":[],"sources":["../src/parsers/defaultParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\n\nexport const defaultParser = createParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgB,aAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { d as File, p as ResolvedFile, r as Component, t as App } from "./App-9ie0H1SF.js";
2
+
3
+ //#region src/defineApp.d.ts
4
+ type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
5
+ type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
6
+ declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
7
+ //#endregion
8
+ //#region src/createApp.d.ts
9
+ declare const createApp: DefineApp<unknown>;
10
+ //#endregion
11
+ //#region src/createFile.d.ts
12
+ /**
13
+ * Helper to create a file with name and id set
14
+ */
15
+ declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
16
+ //#endregion
17
+ export { defineApp as i, createApp as n, DefineApp as r, createFile as t };
18
+ //# sourceMappingURL=index-BpPNNyhl.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { d as File, p as ResolvedFile, r as Component, t as App } from "./App-KqAHuAyU.cjs";
2
+
3
+ //#region src/defineApp.d.ts
4
+ type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
5
+ type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
6
+ declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
7
+ //#endregion
8
+ //#region src/createApp.d.ts
9
+ declare const createApp: DefineApp<unknown>;
10
+ //#endregion
11
+ //#region src/createFile.d.ts
12
+ /**
13
+ * Helper to create a file with name and id set
14
+ */
15
+ declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
16
+ //#endregion
17
+ export { defineApp as i, createApp as n, DefineApp as r, createFile as t };
18
+ //# sourceMappingURL=index-DLITiDO5.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- const require_typescriptParser = require('./typescriptParser-BBbbmG5W.cjs');
3
- const require_tsxParser = require('./tsxParser-HDf_3TMc.cjs');
2
+ const require_createParser = require('./createParser-DZB5qExa.cjs');
3
+ const require_defaultParser = require('./defaultParser-Dl-OrbH1.cjs');
4
4
  let natural_orderby = require("natural-orderby");
5
5
  natural_orderby = require_chunk.__toESM(natural_orderby);
6
6
  let node_crypto = require("node:crypto");
@@ -151,7 +151,7 @@ function createFile(file) {
151
151
  return {
152
152
  ...file,
153
153
  id: hashObject({ path: file.path }),
154
- name: require_typescriptParser.trimExtName(file.baseName),
154
+ name: require_createParser.trimExtName(file.baseName),
155
155
  extname,
156
156
  imports,
157
157
  exports: exports$1,
@@ -190,12 +190,6 @@ var AsyncEventEmitter = class {
190
190
  }
191
191
  };
192
192
 
193
- //#endregion
194
- //#region \0@oxc-project+runtime@0.95.0/helpers/classPrivateMethodInitSpec.js
195
- function _classPrivateMethodInitSpec(e, a) {
196
- _checkPrivateRedeclaration(e, a), a.add(e);
197
- }
198
-
199
193
  //#endregion
200
194
  //#region \0@oxc-project+runtime@0.95.0/helpers/typeof.js
201
195
  function _typeof(o) {
@@ -241,24 +235,25 @@ function _defineProperty(e, r, t) {
241
235
  //#endregion
242
236
  //#region src/FileProcessor.ts
243
237
  var _limit = /* @__PURE__ */ new WeakMap();
244
- var _FileProcessor_brand = /* @__PURE__ */ new WeakSet();
245
238
  var FileProcessor = class {
246
239
  constructor({ events = new AsyncEventEmitter() } = {}) {
247
- _classPrivateMethodInitSpec(this, _FileProcessor_brand);
248
240
  _classPrivateFieldInitSpec(this, _limit, (0, p_limit.default)(100));
249
241
  _defineProperty(this, "events", void 0);
250
242
  this.events = events;
251
243
  return this;
252
244
  }
253
- async parse(file, { parsers = _get_defaultParser.call(_assertClassBrand(_FileProcessor_brand, this)), extension } = {}) {
254
- const extname = node_path.default.extname(file.path);
245
+ async parse(file, { parsers = /* @__PURE__ */ new Set(), extension } = {}) {
255
246
  const parseExtName = (extension === null || extension === void 0 ? void 0 : extension[file.extname]) || void 0;
256
- if (!extname) return require_tsxParser.defaultParser.parse(file, { extname: parseExtName });
257
- const parser = [...parsers].find((item) => {
247
+ if (!file.extname) return require_defaultParser.defaultParser.parse(file, { extname: parseExtName });
248
+ let parser;
249
+ for (const item of parsers) {
258
250
  var _item$extNames;
259
- return (_item$extNames = item.extNames) === null || _item$extNames === void 0 ? void 0 : _item$extNames.includes(extname);
260
- });
261
- if (!parser) return require_tsxParser.defaultParser.parse(file, { extname: parseExtName });
251
+ if ((_item$extNames = item.extNames) === null || _item$extNames === void 0 ? void 0 : _item$extNames.includes(file.extname)) {
252
+ parser = item;
253
+ break;
254
+ }
255
+ }
256
+ if (!parser) return require_defaultParser.defaultParser.parse(file, { extname: parseExtName });
262
257
  return parser.parse(file, { extname: parseExtName });
263
258
  }
264
259
  async run(files, { parsers, dryRun, extension } = {}) {
@@ -276,11 +271,14 @@ var FileProcessor = class {
276
271
  extension,
277
272
  parsers
278
273
  });
274
+ const nextProcessed = processed + 1;
275
+ const percentage = nextProcessed / total * 100;
276
+ processed = nextProcessed;
279
277
  await this.events.emit("process:progress", {
280
278
  file: resolvedFile,
281
279
  source,
282
280
  processed,
283
- percentage: processed / total * 100,
281
+ percentage,
284
282
  total
285
283
  });
286
284
  }
@@ -296,13 +294,6 @@ var FileProcessor = class {
296
294
  return files;
297
295
  }
298
296
  };
299
- function _get_defaultParser() {
300
- return new Set([
301
- require_typescriptParser.typescriptParser,
302
- require_tsxParser.tsxParser,
303
- require_tsxParser.defaultParser
304
- ]);
305
- }
306
297
 
307
298
  //#endregion
308
299
  //#region src/FileManager.ts
@@ -342,17 +333,17 @@ var FileManager = class {
342
333
  flush() {
343
334
  _classPrivateFieldGet2(_cache, this).flush();
344
335
  }
345
- getByPath(path$2) {
346
- return _classPrivateFieldGet2(_cache, this).get(path$2);
336
+ getByPath(path$1) {
337
+ return _classPrivateFieldGet2(_cache, this).get(path$1);
347
338
  }
348
- deleteByPath(path$2) {
349
- _classPrivateFieldGet2(_cache, this).delete(path$2);
339
+ deleteByPath(path$1) {
340
+ _classPrivateFieldGet2(_cache, this).delete(path$1);
350
341
  }
351
342
  clear() {
352
343
  _classPrivateFieldGet2(_cache, this).clear();
353
344
  }
354
345
  get files() {
355
- return (0, natural_orderby.orderBy)(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => require_typescriptParser.trimExtName(v).endsWith("index")]).map((key) => _classPrivateFieldGet2(_cache, this).get(key)).filter(Boolean);
346
+ return (0, natural_orderby.orderBy)(_classPrivateFieldGet2(_cache, this).keys(), [(v) => v.length, (v) => require_createParser.trimExtName(v).endsWith("index")]).map((key) => _classPrivateFieldGet2(_cache, this).get(key)).filter(Boolean);
356
347
  }
357
348
  async write(options) {
358
349
  return this.processor.run(this.files, options);
@@ -362,43 +353,33 @@ var FileManager = class {
362
353
  //#endregion
363
354
  //#region src/defineApp.ts
364
355
  function defineApp(instance) {
365
- function createApp$1(rootComponent, options) {
356
+ function createApp$1(options) {
366
357
  const events = new AsyncEventEmitter();
367
358
  const installedPlugins = /* @__PURE__ */ new Set();
368
359
  const installedParsers = /* @__PURE__ */ new Set();
369
360
  const fileManager = new FileManager({ events });
370
- const context = {
371
- events,
372
- options,
373
- fileManager,
374
- installedPlugins,
375
- installedParsers
376
- };
377
- const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context);
378
361
  const app = {
379
- _component: rootComponent,
380
- async render() {
381
- if ((0, remeda.isPromise)(render)) await render();
382
- else render();
383
- },
384
- async renderToString() {
385
- return renderToString();
362
+ context: {
363
+ events,
364
+ options,
365
+ fileManager,
366
+ installedPlugins,
367
+ installedParsers
386
368
  },
387
369
  get files() {
388
370
  return fileManager.files;
389
371
  },
390
- waitUntilExit,
391
372
  async addFile(...newFiles) {
392
373
  await fileManager.add(...newFiles);
393
374
  },
394
- use(pluginOrParser, ...options$1) {
395
- const args = Array.isArray(options$1) ? options$1 : [options$1[0]];
375
+ async use(pluginOrParser, ...options$1) {
376
+ const args = options$1;
396
377
  if (pluginOrParser.type === "plugin") {
397
378
  if (installedPlugins.has(pluginOrParser)) console.warn("Plugin has already been applied to target app.");
398
379
  else installedPlugins.add(pluginOrParser);
399
- if (pluginOrParser.override && (0, remeda.isFunction)(pluginOrParser.override)) {
400
- const overrider = pluginOrParser.override;
401
- const extraApp = overrider(app, context, ...args);
380
+ if (pluginOrParser.inject && (0, remeda.isFunction)(pluginOrParser.inject)) {
381
+ const injecter = pluginOrParser.inject;
382
+ const extraApp = injecter(app, ...args);
402
383
  Object.assign(app, extraApp);
403
384
  }
404
385
  }
@@ -406,12 +387,14 @@ function defineApp(instance) {
406
387
  else installedParsers.add(pluginOrParser);
407
388
  if (pluginOrParser && (0, remeda.isFunction)(pluginOrParser.install)) {
408
389
  const installer = pluginOrParser.install;
409
- installer(app, context, ...args);
390
+ await installer(app, ...args);
410
391
  }
411
392
  return app;
412
393
  }
413
394
  };
414
- events.emit("start", { app });
395
+ events.emit("start");
396
+ if (instance) instance(app);
397
+ events.emit("end");
415
398
  return app;
416
399
  }
417
400
  return createApp$1;
@@ -419,19 +402,7 @@ function defineApp(instance) {
419
402
 
420
403
  //#endregion
421
404
  //#region src/createApp.ts
422
- const createApp = defineApp(() => {
423
- return {
424
- async render() {
425
- throw new Error("Method not implemented");
426
- },
427
- async renderToString() {
428
- throw new Error("Method not implemented");
429
- },
430
- async waitUntilExit() {
431
- throw new Error("Method not implemented");
432
- }
433
- };
434
- });
405
+ const createApp = defineApp();
435
406
 
436
407
  //#endregion
437
408
  exports.FileManager = FileManager;