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