@kubb/react-fabric 0.3.1 → 0.4.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 (62) hide show
  1. package/dist/{Fabric-D1uNzkRd.d.cts → Fabric-DECM64S6.d.cts} +1 -1
  2. package/dist/{Fabric-OfeFgFB2.d.ts → Fabric-DGhsnD3H.d.ts} +1 -4
  3. package/dist/{chunk-CUT6urMc.cjs → chunk-DWy1uDak.cjs} +9 -0
  4. package/dist/chunk-OzOGZVnI.js +38 -0
  5. package/dist/{devtools-BajE-eCd.cjs → devtools-Bu3zlaPp.cjs} +2 -2
  6. package/dist/{devtools-BajE-eCd.cjs.map → devtools-Bu3zlaPp.cjs.map} +1 -1
  7. package/dist/{devtools-wdFpV122.js → devtools-D6dZodXp.js} +1 -1
  8. package/dist/{devtools-wdFpV122.js.map → devtools-D6dZodXp.js.map} +1 -1
  9. package/dist/devtools.cjs +1 -1
  10. package/dist/devtools.js +1 -1
  11. package/dist/globals.d.cts +2 -2
  12. package/dist/globals.d.ts +2 -2
  13. package/dist/index.cjs +80 -114
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +15 -4
  16. package/dist/index.d.ts +27 -16
  17. package/dist/index.js +71 -57
  18. package/dist/index.js.map +1 -1
  19. package/dist/jsx-dev-runtime-CB2e_LA2.js +1352 -0
  20. package/dist/jsx-dev-runtime-CB2e_LA2.js.map +1 -0
  21. package/dist/jsx-dev-runtime-CB3pf-1W.cjs +1363 -0
  22. package/dist/jsx-dev-runtime-CB3pf-1W.cjs.map +1 -0
  23. package/dist/jsx-dev-runtime.cjs +9 -5
  24. package/dist/jsx-dev-runtime.cjs.map +1 -0
  25. package/dist/jsx-dev-runtime.d.cts +3 -3
  26. package/dist/jsx-dev-runtime.d.ts +3 -3
  27. package/dist/jsx-dev-runtime.js +9 -2
  28. package/dist/jsx-dev-runtime.js.map +1 -0
  29. package/dist/{jsx-namespace-kapEWb5o.d.cts → jsx-namespace-C5bbnidQ.d.cts} +2 -2
  30. package/dist/{jsx-namespace-BEUVmgyn.d.ts → jsx-namespace-eskZDKHk.d.ts} +2 -2
  31. package/dist/jsx-runtime-5qOQhPPb.js +252 -0
  32. package/dist/jsx-runtime-5qOQhPPb.js.map +1 -0
  33. package/dist/jsx-runtime-cOHyKGzA.cjs +263 -0
  34. package/dist/jsx-runtime-cOHyKGzA.cjs.map +1 -0
  35. package/dist/jsx-runtime.cjs +6 -8
  36. package/dist/jsx-runtime.d.cts +3 -3
  37. package/dist/jsx-runtime.d.ts +3 -3
  38. package/dist/jsx-runtime.js +6 -1
  39. package/dist/parsers.d.cts +1 -1
  40. package/dist/parsers.d.ts +1 -1
  41. package/dist/plugins.cjs +3 -2
  42. package/dist/plugins.d.cts +2 -2
  43. package/dist/plugins.d.ts +2 -2
  44. package/dist/plugins.js +3 -2
  45. package/dist/reactPlugin-BWBCDdIm.js +15598 -0
  46. package/dist/reactPlugin-BWBCDdIm.js.map +1 -0
  47. package/dist/{reactPlugin-DVGn6gSn.d.ts → reactPlugin-DAOLEVg9.d.ts} +2 -2
  48. package/dist/reactPlugin-DCT6yE8D.cjs +15640 -0
  49. package/dist/reactPlugin-DCT6yE8D.cjs.map +1 -0
  50. package/dist/{reactPlugin-heqDYGKi.d.cts → reactPlugin-DkhxnXP_.d.cts} +2 -2
  51. package/dist/{types-zrCju594.d.cts → types-C2T-S5lY.d.cts} +2 -2
  52. package/dist/{types-34ycUiHt.d.ts → types-rKVyNQC0.d.ts} +2 -2
  53. package/dist/types.d.cts +2 -2
  54. package/dist/types.d.ts +2 -2
  55. package/package.json +5 -5
  56. package/src/index.ts +12 -2
  57. package/dist/jsx-runtime-BhbaU98p.cjs +0 -2
  58. package/dist/jsx-runtime-Dm0btT2y.js +0 -4
  59. package/dist/reactPlugin-B7zzvM5n.js +0 -625
  60. package/dist/reactPlugin-B7zzvM5n.js.map +0 -1
  61. package/dist/reactPlugin-B9OmXm5F.cjs +0 -669
  62. package/dist/reactPlugin-B9OmXm5F.cjs.map +0 -1
@@ -1,625 +0,0 @@
1
- import { n as jsx } from "./jsx-runtime-Dm0btT2y.js";
2
- import { Component, createContext, createElement } from "react";
3
- import { onExit } from "signal-exit";
4
- import { createPlugin } from "@kubb/fabric-core/plugins";
5
- import process from "node:process";
6
- import { ConcurrentRoot, DefaultEventPriority, NoEventPriority } from "react-reconciler/constants.js";
7
- import Reconciler from "react-reconciler";
8
- import { createExport, createImport, print } from "@kubb/fabric-core/parsers/typescript";
9
-
10
- //#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
11
- function _typeof(o) {
12
- "@babel/helpers - typeof";
13
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
14
- return typeof o$1;
15
- } : function(o$1) {
16
- return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
17
- }, _typeof(o);
18
- }
19
-
20
- //#endregion
21
- //#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
22
- function toPrimitive(t, r) {
23
- if ("object" != _typeof(t) || !t) return t;
24
- var e = t[Symbol.toPrimitive];
25
- if (void 0 !== e) {
26
- var i = e.call(t, r || "default");
27
- if ("object" != _typeof(i)) return i;
28
- throw new TypeError("@@toPrimitive must return a primitive value.");
29
- }
30
- return ("string" === r ? String : Number)(t);
31
- }
32
-
33
- //#endregion
34
- //#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
35
- function toPropertyKey(t) {
36
- var i = toPrimitive(t, "string");
37
- return "symbol" == _typeof(i) ? i : i + "";
38
- }
39
-
40
- //#endregion
41
- //#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
42
- function _defineProperty(e, r, t) {
43
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
44
- value: t,
45
- enumerable: !0,
46
- configurable: !0,
47
- writable: !0
48
- }) : e[r] = t, e;
49
- }
50
-
51
- //#endregion
52
- //#region src/components/Root.tsx
53
- var ErrorBoundary = class extends Component {
54
- constructor(..._args) {
55
- super(..._args);
56
- _defineProperty(this, "state", { hasError: false });
57
- }
58
- static getDerivedStateFromError(_error) {
59
- return { hasError: true };
60
- }
61
- componentDidCatch(error) {
62
- if (error) this.props.onError(error);
63
- }
64
- render() {
65
- if (this.state.hasError) return null;
66
- return this.props.children;
67
- }
68
- };
69
- _defineProperty(ErrorBoundary, "displayName", "KubbErrorBoundary");
70
- const RootContext = createContext({ exit: () => {} });
71
- function Root({ onError, onExit: onExit$1, children }) {
72
- try {
73
- return /* @__PURE__ */ jsx(ErrorBoundary, {
74
- onError: (error) => {
75
- onError(error);
76
- },
77
- children: /* @__PURE__ */ jsx(RootContext.Provider, {
78
- value: { exit: onExit$1 },
79
- children
80
- })
81
- });
82
- } catch (_e) {
83
- return null;
84
- }
85
- }
86
- Root.Context = RootContext;
87
- Root.displayName = "KubbRoot";
88
-
89
- //#endregion
90
- //#region src/dom.ts
91
- const createNode = (nodeName) => {
92
- return {
93
- nodeName,
94
- attributes: /* @__PURE__ */ new Map(),
95
- childNodes: [],
96
- parentNode: void 0
97
- };
98
- };
99
- const appendChildNode = (node, childNode) => {
100
- if (childNode.parentNode) removeChildNode(childNode.parentNode, childNode);
101
- if (node.nodeName !== "#text") {
102
- childNode.parentNode = node;
103
- node.childNodes.push(childNode);
104
- }
105
- };
106
- const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
107
- if (newChildNode.parentNode) removeChildNode(newChildNode.parentNode, newChildNode);
108
- newChildNode.parentNode = node;
109
- const index = node.childNodes.indexOf(beforeChildNode);
110
- if (index >= 0) {
111
- node.childNodes.splice(index, 0, newChildNode);
112
- return;
113
- }
114
- node.childNodes.push(newChildNode);
115
- };
116
- const removeChildNode = (node, removeNode) => {
117
- removeNode.parentNode = void 0;
118
- const index = node.childNodes.indexOf(removeNode);
119
- if (index >= 0) node.childNodes.splice(index, 1);
120
- };
121
- const setAttribute = (node, key, value) => {
122
- node.attributes.set(key, value);
123
- };
124
- const createTextNode = (text) => {
125
- const node = {
126
- nodeName: "#text",
127
- nodeValue: text,
128
- parentNode: void 0
129
- };
130
- setTextNodeValue(node, text);
131
- return node;
132
- };
133
- const setTextNodeValue = (node, text) => {
134
- if (typeof text !== "string") text = String(text);
135
- node.nodeValue = text;
136
- };
137
- const nodeNames = new Set([
138
- "kubb-export",
139
- "kubb-file",
140
- "kubb-source",
141
- "kubb-import",
142
- "kubb-text",
143
- "kubb-root",
144
- "kubb-app",
145
- "br"
146
- ]);
147
-
148
- //#endregion
149
- //#region src/Renderer.ts
150
- let currentUpdatePriority = NoEventPriority;
151
- /**
152
- * @link https://www.npmjs.com/package/react-devtools-inline
153
- * @link https://github.com/nitin42/Making-a-custom-React-renderer/blob/master/part-one.md
154
- * @link https://github.com/facebook/react/tree/main/packages/react-reconciler#practical-examples
155
- * @link https://github.com/vadimdemedes/ink
156
- * @link https://github.com/pixijs/pixi-react/tree/main/packages
157
- * @link https://github.com/diegomura/react-pdf/blob/master/packages/reconciler/src/reconciler-31.ts
158
- */
159
- const Renderer = Reconciler({
160
- getRootHostContext: () => ({
161
- type: "kubb-root",
162
- isFile: false,
163
- isSource: false
164
- }),
165
- prepareForCommit: () => {
166
- return null;
167
- },
168
- preparePortalMount: () => null,
169
- clearContainer: () => false,
170
- resetAfterCommit(rootNode) {
171
- if (typeof rootNode.onRender === "function") rootNode.onRender();
172
- },
173
- getChildHostContext(parentHostContext, type) {
174
- return {
175
- isInsideText: type === "kubb-text",
176
- isFile: type === "kubb-file" || parentHostContext.isFile,
177
- isSource: type === "kubb-source" || parentHostContext.isSource,
178
- type
179
- };
180
- },
181
- shouldSetTextContent: () => false,
182
- createInstance(originalType, newProps, _root) {
183
- const node = createNode(originalType);
184
- for (const [key, value] of Object.entries(newProps)) {
185
- if (key === "children") continue;
186
- setAttribute(node, key, value);
187
- }
188
- return node;
189
- },
190
- createTextInstance(text, _root, hostContext) {
191
- if (hostContext.isFile && !hostContext.isSource) throw new Error(`[react] '${text}' should be part of <File.Source> component when using the <File/> component`);
192
- return createTextNode(text);
193
- },
194
- resetTextContent() {},
195
- hideTextInstance(node) {
196
- setTextNodeValue(node, "");
197
- },
198
- unhideTextInstance(node, text) {
199
- setTextNodeValue(node, text);
200
- },
201
- getPublicInstance: (instance) => instance,
202
- appendInitialChild: appendChildNode,
203
- appendChild: appendChildNode,
204
- insertBefore: insertBeforeNode,
205
- finalizeInitialChildren(_node, _type, _props, _rootNode$1) {
206
- return false;
207
- },
208
- supportsMutation: true,
209
- isPrimaryRenderer: true,
210
- supportsPersistence: false,
211
- supportsHydration: false,
212
- scheduleTimeout: setTimeout,
213
- cancelTimeout: clearTimeout,
214
- noTimeout: -1,
215
- beforeActiveInstanceBlur() {},
216
- afterActiveInstanceBlur() {},
217
- detachDeletedInstance() {},
218
- getInstanceFromNode: () => null,
219
- prepareScopeUpdate() {},
220
- getInstanceFromScope: () => null,
221
- appendChildToContainer: appendChildNode,
222
- insertInContainerBefore: insertBeforeNode,
223
- removeChildFromContainer(node, removeNode) {
224
- removeChildNode(node, removeNode);
225
- },
226
- commitMount() {},
227
- commitUpdate(node, _payload, _type, _oldProps, newProps) {
228
- const { props } = newProps;
229
- if (props) for (const [key, value] of Object.entries(props)) setAttribute(node, key, value);
230
- },
231
- commitTextUpdate(node, _oldText, newText) {
232
- setTextNodeValue(node, newText);
233
- },
234
- removeChild(node, removeNode) {
235
- removeChildNode(node, removeNode);
236
- },
237
- setCurrentUpdatePriority: (newPriority) => {
238
- currentUpdatePriority = newPriority;
239
- },
240
- getCurrentUpdatePriority: () => currentUpdatePriority,
241
- resolveUpdatePriority() {
242
- if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
243
- return DefaultEventPriority;
244
- },
245
- maySuspendCommit() {
246
- return false;
247
- },
248
- NotPendingTransition: void 0,
249
- HostTransitionContext: createContext(null),
250
- resetFormInstance() {},
251
- requestPostPaintCallback() {},
252
- shouldAttemptEagerTransition() {
253
- return false;
254
- },
255
- trackSchedulerEvent() {},
256
- resolveEventType() {
257
- return null;
258
- },
259
- resolveEventTimeStamp() {
260
- return -1.1;
261
- },
262
- preloadInstance() {
263
- return true;
264
- },
265
- startSuspendingCommit() {},
266
- suspendInstance() {},
267
- waitForCommitToBeReady() {
268
- return null;
269
- }
270
- });
271
-
272
- //#endregion
273
- //#region src/utils/squashExportNodes.ts
274
- function squashExportNodes(node) {
275
- const exports = /* @__PURE__ */ new Set();
276
- const walk = (current) => {
277
- for (const child of current.childNodes) {
278
- if (!child) continue;
279
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
280
- if (child.nodeName === "kubb-export") {
281
- var _child$attributes$get, _child$attributes$get2;
282
- exports.add({
283
- name: child.attributes.get("name"),
284
- path: child.attributes.get("path"),
285
- isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
286
- asAlias: (_child$attributes$get2 = child.attributes.get("asAlias")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false
287
- });
288
- }
289
- }
290
- };
291
- walk(node);
292
- return exports;
293
- }
294
-
295
- //#endregion
296
- //#region src/utils/squashImportNodes.ts
297
- function squashImportNodes(node) {
298
- const imports = /* @__PURE__ */ new Set();
299
- const walk = (current) => {
300
- for (const child of current.childNodes) {
301
- if (!child) continue;
302
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
303
- if (child.nodeName === "kubb-import") {
304
- var _child$attributes$get, _child$attributes$get2;
305
- imports.add({
306
- name: child.attributes.get("name"),
307
- path: child.attributes.get("path"),
308
- root: child.attributes.get("root"),
309
- isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
310
- isNameSpace: (_child$attributes$get2 = child.attributes.get("isNameSpace")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false
311
- });
312
- }
313
- }
314
- };
315
- walk(node);
316
- return imports;
317
- }
318
-
319
- //#endregion
320
- //#region src/utils/squashTextNodes.ts
321
- function squashTextNodes(node) {
322
- let text = "";
323
- const walk = (current) => {
324
- let content = "";
325
- for (const child of current.childNodes) {
326
- if (!child) continue;
327
- let nodeText = "";
328
- const getPrintText = (text$1) => {
329
- switch (child.nodeName) {
330
- case "kubb-import": return print(createImport({
331
- name: child.attributes.get("name"),
332
- path: child.attributes.get("path"),
333
- root: child.attributes.get("root"),
334
- isTypeOnly: child.attributes.get("isTypeOnly"),
335
- isNameSpace: child.attributes.get("isNameSpace")
336
- }));
337
- case "kubb-export":
338
- if (child.attributes.has("path")) return print(createExport({
339
- name: child.attributes.get("name"),
340
- path: child.attributes.get("path"),
341
- isTypeOnly: child.attributes.get("isTypeOnly"),
342
- asAlias: child.attributes.get("asAlias")
343
- }));
344
- return "";
345
- case "kubb-source": return text$1;
346
- default: return text$1;
347
- }
348
- };
349
- if (child.nodeName === "#text") nodeText = child.nodeValue;
350
- else {
351
- if (child.nodeName === "kubb-text" || child.nodeName === "kubb-file" || child.nodeName === "kubb-source") nodeText = walk(child);
352
- nodeText = getPrintText(nodeText);
353
- if (child.nodeName === "br") nodeText = "\n";
354
- if (!nodeNames.has(child.nodeName)) {
355
- const attributes = child.attributes;
356
- let attrString = "";
357
- const hasAttributes = attributes.size > 0;
358
- for (const [key, value] of attributes) attrString += typeof value === "string" ? ` ${key}="${value}"` : ` ${key}={${String(value)}}`;
359
- if (hasAttributes) nodeText = `<${child.nodeName}${attrString}>${walk(child)}</${child.nodeName}>`;
360
- else nodeText = `<${child.nodeName}>${walk(child)}</${child.nodeName}>`;
361
- }
362
- }
363
- content += nodeText;
364
- }
365
- return content;
366
- };
367
- text = walk(node);
368
- return text;
369
- }
370
-
371
- //#endregion
372
- //#region src/utils/squashSourceNodes.ts
373
- function squashSourceNodes(node, ignores) {
374
- const ignoreSet = new Set(ignores);
375
- const sources = /* @__PURE__ */ new Set();
376
- const walk = (current) => {
377
- for (const child of current.childNodes) {
378
- if (!child) continue;
379
- if (child.nodeName !== "#text" && ignoreSet.has(child.nodeName)) continue;
380
- if (child.nodeName === "kubb-source") {
381
- var _child$attributes$get, _child$attributes$get2, _child$attributes$get3;
382
- const value = squashTextNodes(child);
383
- sources.add({
384
- name: child.attributes.get("name"),
385
- isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
386
- isExportable: (_child$attributes$get2 = child.attributes.get("isExportable")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false,
387
- isIndexable: (_child$attributes$get3 = child.attributes.get("isIndexable")) !== null && _child$attributes$get3 !== void 0 ? _child$attributes$get3 : false,
388
- value: value.trim().replace(/^\s+|\s+$/g, "")
389
- });
390
- continue;
391
- }
392
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
393
- }
394
- };
395
- walk(node);
396
- return sources;
397
- }
398
-
399
- //#endregion
400
- //#region src/utils/processFiles.ts
401
- async function processFiles(node) {
402
- const collected = [];
403
- async function walk(current) {
404
- for (const child of current.childNodes) {
405
- if (!child) continue;
406
- if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && nodeNames.has(child.nodeName)) await walk(child);
407
- if (child.nodeName === "kubb-file") {
408
- if (child.attributes.has("baseName") && child.attributes.has("path")) {
409
- const sources = squashSourceNodes(child, ["kubb-export", "kubb-import"]);
410
- collected.push({
411
- baseName: child.attributes.get("baseName"),
412
- path: child.attributes.get("path"),
413
- meta: child.attributes.get("meta") || {},
414
- footer: child.attributes.get("footer"),
415
- banner: child.attributes.get("banner"),
416
- sources: [...sources],
417
- exports: [...squashExportNodes(child)],
418
- imports: [...squashImportNodes(child)]
419
- });
420
- }
421
- }
422
- }
423
- }
424
- await walk(node);
425
- return collected;
426
- }
427
-
428
- //#endregion
429
- //#region \0@oxc-project+runtime@0.96.0/helpers/checkPrivateRedeclaration.js
430
- function _checkPrivateRedeclaration(e, t) {
431
- if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
432
- }
433
-
434
- //#endregion
435
- //#region \0@oxc-project+runtime@0.96.0/helpers/classPrivateMethodInitSpec.js
436
- function _classPrivateMethodInitSpec(e, a) {
437
- _checkPrivateRedeclaration(e, a), a.add(e);
438
- }
439
-
440
- //#endregion
441
- //#region \0@oxc-project+runtime@0.96.0/helpers/classPrivateFieldInitSpec.js
442
- function _classPrivateFieldInitSpec(e, t, a) {
443
- _checkPrivateRedeclaration(e, t), t.set(e, a);
444
- }
445
-
446
- //#endregion
447
- //#region \0@oxc-project+runtime@0.96.0/helpers/assertClassBrand.js
448
- function _assertClassBrand(e, t, n) {
449
- if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
450
- throw new TypeError("Private element is not present on this object");
451
- }
452
-
453
- //#endregion
454
- //#region \0@oxc-project+runtime@0.96.0/helpers/classPrivateFieldGet2.js
455
- function _classPrivateFieldGet2(s, a) {
456
- return s.get(_assertClassBrand(s, a));
457
- }
458
-
459
- //#endregion
460
- //#region \0@oxc-project+runtime@0.96.0/helpers/classPrivateFieldSet2.js
461
- function _classPrivateFieldSet2(s, a, r) {
462
- return s.set(_assertClassBrand(s, a), r), r;
463
- }
464
-
465
- //#endregion
466
- //#region src/Runtime.tsx
467
- var _options = /* @__PURE__ */ new WeakMap();
468
- var _isUnmounted = /* @__PURE__ */ new WeakMap();
469
- var _container = /* @__PURE__ */ new WeakMap();
470
- var _rootNode = /* @__PURE__ */ new WeakMap();
471
- var _renderPromise = /* @__PURE__ */ new WeakMap();
472
- var _Runtime_brand = /* @__PURE__ */ new WeakSet();
473
- var Runtime = class {
474
- constructor(options) {
475
- _classPrivateMethodInitSpec(this, _Runtime_brand);
476
- _classPrivateFieldInitSpec(this, _options, void 0);
477
- _classPrivateFieldInitSpec(this, _isUnmounted, void 0);
478
- _defineProperty(this, "exitPromise", void 0);
479
- _classPrivateFieldInitSpec(this, _container, void 0);
480
- _classPrivateFieldInitSpec(this, _rootNode, void 0);
481
- _classPrivateFieldInitSpec(this, _renderPromise, Promise.resolve());
482
- _defineProperty(this, "resolveExitPromise", () => {});
483
- _defineProperty(this, "rejectExitPromise", () => {});
484
- _defineProperty(this, "unsubscribeExit", () => {});
485
- _defineProperty(this, "onRender", () => {
486
- const task = _classPrivateFieldGet2(_renderPromise, this).catch(() => {}).then(async () => {
487
- var _classPrivateFieldGet2$1, _classPrivateFieldGet3, _classPrivateFieldGet4, _classPrivateFieldGet5;
488
- if (_classPrivateFieldGet2(_isUnmounted, this)) return;
489
- const files = await processFiles(_classPrivateFieldGet2(_rootNode, this));
490
- await this.fileManager.add(...files);
491
- if (!((_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.debug) && !((_classPrivateFieldGet3 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.stdout)) return;
492
- const output = await _assertClassBrand(_Runtime_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this));
493
- if ((_classPrivateFieldGet4 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.debug) {
494
- console.log("Rendering:\n");
495
- console.log(output);
496
- }
497
- if (((_classPrivateFieldGet5 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.stdout) && process.env.NODE_ENV !== "test") {
498
- _classPrivateFieldGet2(_options, this).stdout.clearLine(0);
499
- _classPrivateFieldGet2(_options, this).stdout.cursorTo(0);
500
- _classPrivateFieldGet2(_options, this).stdout.write(output);
501
- }
502
- });
503
- _classPrivateFieldSet2(_renderPromise, this, task.catch((error) => {
504
- this.onError(error);
505
- throw error;
506
- }));
507
- return _classPrivateFieldGet2(_renderPromise, this);
508
- });
509
- _classPrivateFieldSet2(_options, this, options);
510
- _classPrivateFieldSet2(_rootNode, this, createNode("kubb-root"));
511
- _classPrivateFieldGet2(_rootNode, this).onRender = this.onRender;
512
- _classPrivateFieldGet2(_rootNode, this).onImmediateRender = this.onRender;
513
- _classPrivateFieldSet2(_isUnmounted, this, false);
514
- this.unmount.bind(this);
515
- const originalError = console.error;
516
- console.error = (data) => {
517
- const message = typeof data === "string" ? data : data === null || data === void 0 ? void 0 : data.message;
518
- if ((message === null || message === void 0 ? void 0 : message.match(/Encountered two children with the same key/gi)) || (message === null || message === void 0 ? void 0 : message.match(/React will try to recreat/gi)) || (message === null || message === void 0 ? void 0 : message.match(/Each child in a list should have a unique/gi)) || (message === null || message === void 0 ? void 0 : message.match(/The above error occurred in the <KubbErrorBoundary/gi)) || (message === null || message === void 0 ? void 0 : message.match(/A React Element from an older version of React was render/gi))) return;
519
- originalError(data);
520
- };
521
- const logRecoverableError = typeof reportError === "function" ? reportError : console.error;
522
- const rootTag = ConcurrentRoot;
523
- _classPrivateFieldSet2(_container, this, Renderer.createContainer(_classPrivateFieldGet2(_rootNode, this), rootTag, null, false, false, "id", logRecoverableError, logRecoverableError, logRecoverableError, null));
524
- this.unsubscribeExit = onExit((code) => {
525
- this.unmount(code);
526
- }, { alwaysLast: false }).bind(this);
527
- Renderer.injectIntoDevTools({
528
- bundleType: 1,
529
- version: "19.1.0",
530
- rendererPackageName: "kubb"
531
- });
532
- }
533
- get fileManager() {
534
- return _classPrivateFieldGet2(_options, this).fileManager;
535
- }
536
- onError(error) {
537
- if (process.env.NODE_ENV === "test") console.warn(error);
538
- throw error;
539
- }
540
- onExit(error) {
541
- this.unmount(error);
542
- }
543
- async render(node) {
544
- const element = /* @__PURE__ */ jsx(Root, {
545
- onExit: this.onExit.bind(this),
546
- onError: this.onError.bind(this),
547
- children: node
548
- });
549
- Renderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
550
- Renderer.flushSyncWork();
551
- await _classPrivateFieldGet2(_renderPromise, this);
552
- }
553
- async renderToString(node) {
554
- const element = /* @__PURE__ */ jsx(Root, {
555
- onExit: this.onExit.bind(this),
556
- onError: this.onError.bind(this),
557
- children: node
558
- });
559
- Renderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
560
- Renderer.flushSyncWork();
561
- await _classPrivateFieldGet2(_renderPromise, this);
562
- this.fileManager.clear();
563
- return _assertClassBrand(_Runtime_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this));
564
- }
565
- unmount(error) {
566
- var _classPrivateFieldGet6;
567
- if (_classPrivateFieldGet2(_isUnmounted, this)) return;
568
- if ((_classPrivateFieldGet6 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.debug) console.log("Unmount", error);
569
- this.onRender();
570
- this.unsubscribeExit();
571
- _classPrivateFieldSet2(_isUnmounted, this, true);
572
- Renderer.updateContainerSync(null, _classPrivateFieldGet2(_container, this), null, null);
573
- if (error instanceof Error) {
574
- this.rejectExitPromise(error);
575
- return;
576
- }
577
- this.resolveExitPromise();
578
- }
579
- async waitUntilExit() {
580
- if (!this.exitPromise) this.exitPromise = new Promise((resolve, reject) => {
581
- this.resolveExitPromise = resolve;
582
- this.rejectExitPromise = reject;
583
- });
584
- return this.exitPromise;
585
- }
586
- };
587
- async function _getOutput(node) {
588
- const text = squashTextNodes(node);
589
- const files = this.fileManager.files;
590
- if (!files.length) return text;
591
- const values = /* @__PURE__ */ new Set();
592
- for (const file of files) for (const source of file.sources) if (source === null || source === void 0 ? void 0 : source.value) values.add(source.value);
593
- return [...values].join("\n\n");
594
- }
595
-
596
- //#endregion
597
- //#region src/plugins/reactPlugin.ts
598
- const reactPlugin = createPlugin({
599
- name: "react",
600
- install() {},
601
- inject(ctx, options = {}) {
602
- const runtime = new Runtime({
603
- fileManager: ctx.fileManager,
604
- ...options
605
- });
606
- return {
607
- async render(App) {
608
- await runtime.render(createElement(App));
609
- await ctx.emit("start");
610
- },
611
- async renderToString(App) {
612
- await ctx.emit("start");
613
- return runtime.renderToString(createElement(App));
614
- },
615
- async waitUntilExit() {
616
- await runtime.waitUntilExit();
617
- await ctx.emit("end");
618
- }
619
- };
620
- }
621
- });
622
-
623
- //#endregion
624
- export { _classPrivateFieldInitSpec as a, _classPrivateFieldGet2 as i, Runtime as n, Root as o, _classPrivateFieldSet2 as r, RootContext as s, reactPlugin as t };
625
- //# sourceMappingURL=reactPlugin-B7zzvM5n.js.map