@kubb/react-fabric 0.11.3 → 0.11.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.
- package/dist/{Fabric-DbJhvsCq.d.ts → Fabric-8pppnIg0.d.ts} +1 -1
- package/dist/Renderer-7rMwyODQ.cjs +4 -0
- package/dist/{reactPlugin-B8F6jVb5.cjs → Renderer-CRT9gs-h.cjs} +131 -604
- package/dist/Renderer-CRT9gs-h.cjs.map +1 -0
- package/dist/{reactPlugin-CAtVV84d.js → Renderer-CgXqdVqV.js} +124 -590
- package/dist/Renderer-CgXqdVqV.js.map +1 -0
- package/dist/Renderer-D_r5OSso.js +4 -0
- package/dist/{TreeNode-tc-jO4rk.d.ts → TreeNode-B5YhdIi1.d.ts} +2 -2
- package/dist/devtools-Cz49mTX5.js +102 -0
- package/dist/devtools-Cz49mTX5.js.map +1 -0
- package/dist/devtools-msRXXQfJ.cjs +109 -0
- package/dist/devtools-msRXXQfJ.cjs.map +1 -0
- package/dist/devtools.cjs +1 -1
- package/dist/devtools.js +1 -1
- package/dist/globals.d.ts +2 -2
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.cts +2 -2
- package/dist/jsx-dev-runtime.d.ts +5 -5
- package/dist/{jsx-namespace-bLrscF7g.d.ts → jsx-namespace-CfIw-cgT.d.ts} +2 -2
- package/dist/jsx-runtime.d.cts +2 -2
- package/dist/jsx-runtime.d.ts +5 -5
- package/dist/parsers.d.ts +1 -1
- package/dist/plugins.cjs +2 -1
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.js +2 -1
- package/dist/{reactPlugin-BHE3X6-B.d.ts → reactPlugin-0E3yLJvd.d.ts} +2 -2
- package/dist/reactPlugin-BJ_35CCS.cjs +499 -0
- package/dist/reactPlugin-BJ_35CCS.cjs.map +1 -0
- package/dist/reactPlugin-E8nSWNDp.js +469 -0
- package/dist/reactPlugin-E8nSWNDp.js.map +1 -0
- package/dist/{types-BKXB0ewg.d.ts → types-BKiEQWrZ.d.ts} +3 -3
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/Runtime.tsx +0 -6
- package/src/devtools.ts +91 -69
- package/dist/devtools-8_UKWDTl.js +0 -93
- package/dist/devtools-8_UKWDTl.js.map +0 -1
- package/dist/devtools-BOpUJhc_.cjs +0 -100
- package/dist/devtools-BOpUJhc_.cjs.map +0 -1
- package/dist/reactPlugin-B8F6jVb5.cjs.map +0 -1
- package/dist/reactPlugin-CAtVV84d.js.map +0 -1
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-BrXtsOCC.cjs');
|
|
2
|
+
const require_react$1 = require('./react-CWV4qQg2.cjs');
|
|
3
|
+
const require_jsx_runtime = require('./jsx-runtime-Cq39dA50.cjs');
|
|
4
|
+
const require_Renderer = require('./Renderer-CRT9gs-h.cjs');
|
|
5
|
+
let _kubb_fabric_core = require("@kubb/fabric-core");
|
|
6
|
+
let signal_exit = require("signal-exit");
|
|
7
|
+
let _kubb_fabric_core_plugins = require("@kubb/fabric-core/plugins");
|
|
8
|
+
let node_process = require("node:process");
|
|
9
|
+
node_process = require_chunk.__toESM(node_process);
|
|
10
|
+
let _kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
|
|
11
|
+
|
|
12
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/typeof.js
|
|
13
|
+
function _typeof(o) {
|
|
14
|
+
"@babel/helpers - typeof";
|
|
15
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
16
|
+
return typeof o$1;
|
|
17
|
+
} : function(o$1) {
|
|
18
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
19
|
+
}, _typeof(o);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPrimitive.js
|
|
24
|
+
function toPrimitive(t, r) {
|
|
25
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
26
|
+
var e = t[Symbol.toPrimitive];
|
|
27
|
+
if (void 0 !== e) {
|
|
28
|
+
var i = e.call(t, r || "default");
|
|
29
|
+
if ("object" != _typeof(i)) return i;
|
|
30
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
31
|
+
}
|
|
32
|
+
return ("string" === r ? String : Number)(t);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/toPropertyKey.js
|
|
37
|
+
function toPropertyKey(t) {
|
|
38
|
+
var i = toPrimitive(t, "string");
|
|
39
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/defineProperty.js
|
|
44
|
+
function _defineProperty(e, r, t) {
|
|
45
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
46
|
+
value: t,
|
|
47
|
+
enumerable: !0,
|
|
48
|
+
configurable: !0,
|
|
49
|
+
writable: !0
|
|
50
|
+
}) : e[r] = t, e;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/components/Root.tsx
|
|
55
|
+
var import_react = /* @__PURE__ */ require_chunk.__toESM(require_react$1.require_react());
|
|
56
|
+
var ErrorBoundary = class extends import_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
|
+
/**
|
|
74
|
+
* This component provides the root behavior for the Fabric runtime.
|
|
75
|
+
*/
|
|
76
|
+
function Root({ onError, onExit: onExit$1, treeNode, fileManager, children }) {
|
|
77
|
+
(0, _kubb_fabric_core.provide)(_kubb_fabric_core.RootContext, {
|
|
78
|
+
exit: onExit$1,
|
|
79
|
+
treeNode,
|
|
80
|
+
fileManager
|
|
81
|
+
});
|
|
82
|
+
(0, _kubb_fabric_core.provide)(_kubb_fabric_core.NodeTreeContext, treeNode);
|
|
83
|
+
return /* @__PURE__ */ require_jsx_runtime.jsx(ErrorBoundary, {
|
|
84
|
+
onError: (error) => {
|
|
85
|
+
onError(error);
|
|
86
|
+
},
|
|
87
|
+
children
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
Root.displayName = "KubbRoot";
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/squashExportNodes.ts
|
|
94
|
+
function squashExportNodes(node) {
|
|
95
|
+
const exports$1 = /* @__PURE__ */ new Set();
|
|
96
|
+
const walk = (current) => {
|
|
97
|
+
for (const child of current.childNodes) {
|
|
98
|
+
if (!child) continue;
|
|
99
|
+
if (child.nodeName !== "#text" && require_Renderer.nodeNames.has(child.nodeName)) walk(child);
|
|
100
|
+
if (child.nodeName === "kubb-export") {
|
|
101
|
+
var _child$attributes$get, _child$attributes$get2;
|
|
102
|
+
exports$1.add({
|
|
103
|
+
name: child.attributes.get("name"),
|
|
104
|
+
path: child.attributes.get("path"),
|
|
105
|
+
isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
|
|
106
|
+
asAlias: (_child$attributes$get2 = child.attributes.get("asAlias")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
walk(node);
|
|
112
|
+
return exports$1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/utils/squashImportNodes.ts
|
|
117
|
+
function squashImportNodes(node) {
|
|
118
|
+
const imports = /* @__PURE__ */ new Set();
|
|
119
|
+
const walk = (current) => {
|
|
120
|
+
for (const child of current.childNodes) {
|
|
121
|
+
if (!child) continue;
|
|
122
|
+
if (child.nodeName !== "#text" && require_Renderer.nodeNames.has(child.nodeName)) walk(child);
|
|
123
|
+
if (child.nodeName === "kubb-import") {
|
|
124
|
+
var _child$attributes$get, _child$attributes$get2;
|
|
125
|
+
imports.add({
|
|
126
|
+
name: child.attributes.get("name"),
|
|
127
|
+
path: child.attributes.get("path"),
|
|
128
|
+
root: child.attributes.get("root"),
|
|
129
|
+
isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
|
|
130
|
+
isNameSpace: (_child$attributes$get2 = child.attributes.get("isNameSpace")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
walk(node);
|
|
136
|
+
return imports;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/utils/squashTextNodes.ts
|
|
141
|
+
function squashTextNodes(node) {
|
|
142
|
+
let text = "";
|
|
143
|
+
const walk = (current) => {
|
|
144
|
+
let content = "";
|
|
145
|
+
for (const child of current.childNodes) {
|
|
146
|
+
if (!child) continue;
|
|
147
|
+
let nodeText = "";
|
|
148
|
+
const getPrintText = (text$1) => {
|
|
149
|
+
switch (child.nodeName) {
|
|
150
|
+
case "kubb-import": return (0, _kubb_fabric_core_parsers_typescript.print)((0, _kubb_fabric_core_parsers_typescript.createImport)({
|
|
151
|
+
name: child.attributes.get("name"),
|
|
152
|
+
path: child.attributes.get("path"),
|
|
153
|
+
root: child.attributes.get("root"),
|
|
154
|
+
isTypeOnly: child.attributes.get("isTypeOnly"),
|
|
155
|
+
isNameSpace: child.attributes.get("isNameSpace")
|
|
156
|
+
}));
|
|
157
|
+
case "kubb-export":
|
|
158
|
+
if (child.attributes.has("path")) return (0, _kubb_fabric_core_parsers_typescript.print)((0, _kubb_fabric_core_parsers_typescript.createExport)({
|
|
159
|
+
name: child.attributes.get("name"),
|
|
160
|
+
path: child.attributes.get("path"),
|
|
161
|
+
isTypeOnly: child.attributes.get("isTypeOnly"),
|
|
162
|
+
asAlias: child.attributes.get("asAlias")
|
|
163
|
+
}));
|
|
164
|
+
return "";
|
|
165
|
+
case "kubb-source": return text$1;
|
|
166
|
+
default: return text$1;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
if (child.nodeName === "#text") nodeText = child.nodeValue;
|
|
170
|
+
else {
|
|
171
|
+
if (child.nodeName === "kubb-text" || child.nodeName === "kubb-file" || child.nodeName === "kubb-source") nodeText = walk(child);
|
|
172
|
+
nodeText = getPrintText(nodeText);
|
|
173
|
+
if (child.nodeName === "br") nodeText = "\n";
|
|
174
|
+
if (!require_Renderer.nodeNames.has(child.nodeName)) {
|
|
175
|
+
const attributes = child.attributes;
|
|
176
|
+
let attrString = "";
|
|
177
|
+
const hasAttributes = attributes.size > 0;
|
|
178
|
+
for (const [key, value] of attributes) attrString += typeof value === "string" ? ` ${key}="${value}"` : ` ${key}={${String(value)}}`;
|
|
179
|
+
if (hasAttributes) nodeText = `<${child.nodeName}${attrString}>${walk(child)}</${child.nodeName}>`;
|
|
180
|
+
else nodeText = `<${child.nodeName}>${walk(child)}</${child.nodeName}>`;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
content += nodeText;
|
|
184
|
+
}
|
|
185
|
+
return content;
|
|
186
|
+
};
|
|
187
|
+
text = walk(node);
|
|
188
|
+
return text;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/utils/squashSourceNodes.ts
|
|
193
|
+
function squashSourceNodes(node, ignores) {
|
|
194
|
+
const ignoreSet = new Set(ignores);
|
|
195
|
+
const sources = /* @__PURE__ */ new Set();
|
|
196
|
+
const walk = (current) => {
|
|
197
|
+
for (const child of current.childNodes) {
|
|
198
|
+
if (!child) continue;
|
|
199
|
+
if (child.nodeName !== "#text" && ignoreSet.has(child.nodeName)) continue;
|
|
200
|
+
if (child.nodeName === "kubb-source") {
|
|
201
|
+
var _child$attributes$get, _child$attributes$get2, _child$attributes$get3;
|
|
202
|
+
const value = squashTextNodes(child);
|
|
203
|
+
sources.add({
|
|
204
|
+
name: child.attributes.get("name"),
|
|
205
|
+
isTypeOnly: (_child$attributes$get = child.attributes.get("isTypeOnly")) !== null && _child$attributes$get !== void 0 ? _child$attributes$get : false,
|
|
206
|
+
isExportable: (_child$attributes$get2 = child.attributes.get("isExportable")) !== null && _child$attributes$get2 !== void 0 ? _child$attributes$get2 : false,
|
|
207
|
+
isIndexable: (_child$attributes$get3 = child.attributes.get("isIndexable")) !== null && _child$attributes$get3 !== void 0 ? _child$attributes$get3 : false,
|
|
208
|
+
value: value.trim().replace(/^\s+|\s+$/g, "")
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (child.nodeName !== "#text" && require_Renderer.nodeNames.has(child.nodeName)) walk(child);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
walk(node);
|
|
216
|
+
return sources;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/utils/processFiles.ts
|
|
221
|
+
async function processFiles(node) {
|
|
222
|
+
const collected = [];
|
|
223
|
+
async function walk(current) {
|
|
224
|
+
for (const child of current.childNodes) {
|
|
225
|
+
if (!child) continue;
|
|
226
|
+
if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && require_Renderer.nodeNames.has(child.nodeName)) await walk(child);
|
|
227
|
+
if (child.nodeName === "kubb-file") {
|
|
228
|
+
if (child.attributes.has("baseName") && child.attributes.has("path")) {
|
|
229
|
+
const sources = squashSourceNodes(child, ["kubb-export", "kubb-import"]);
|
|
230
|
+
collected.push({
|
|
231
|
+
baseName: child.attributes.get("baseName"),
|
|
232
|
+
path: child.attributes.get("path"),
|
|
233
|
+
meta: child.attributes.get("meta") || {},
|
|
234
|
+
footer: child.attributes.get("footer"),
|
|
235
|
+
banner: child.attributes.get("banner"),
|
|
236
|
+
sources: [...sources],
|
|
237
|
+
exports: [...squashExportNodes(child)],
|
|
238
|
+
imports: [...squashImportNodes(child)]
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
await walk(node);
|
|
245
|
+
return collected;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/checkPrivateRedeclaration.js
|
|
250
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
251
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
//#endregion
|
|
255
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/classPrivateMethodInitSpec.js
|
|
256
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
257
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/classPrivateFieldInitSpec.js
|
|
262
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
263
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
//#endregion
|
|
267
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/assertClassBrand.js
|
|
268
|
+
function _assertClassBrand(e, t, n) {
|
|
269
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
270
|
+
throw new TypeError("Private element is not present on this object");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/classPrivateFieldGet2.js
|
|
275
|
+
function _classPrivateFieldGet2(s, a) {
|
|
276
|
+
return s.get(_assertClassBrand(s, a));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region \0@oxc-project+runtime@0.103.0/helpers/classPrivateFieldSet2.js
|
|
281
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
282
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/Runtime.tsx
|
|
287
|
+
var import_constants = require_Renderer.require_constants();
|
|
288
|
+
var _options = /* @__PURE__ */ new WeakMap();
|
|
289
|
+
var _isUnmounted = /* @__PURE__ */ new WeakMap();
|
|
290
|
+
var _renderError = /* @__PURE__ */ new WeakMap();
|
|
291
|
+
var _container = /* @__PURE__ */ new WeakMap();
|
|
292
|
+
var _rootNode = /* @__PURE__ */ new WeakMap();
|
|
293
|
+
var _renderPromise = /* @__PURE__ */ new WeakMap();
|
|
294
|
+
var _Runtime_brand = /* @__PURE__ */ new WeakSet();
|
|
295
|
+
var Runtime = class {
|
|
296
|
+
constructor(options) {
|
|
297
|
+
_classPrivateMethodInitSpec(this, _Runtime_brand);
|
|
298
|
+
_classPrivateFieldInitSpec(this, _options, void 0);
|
|
299
|
+
_classPrivateFieldInitSpec(this, _isUnmounted, void 0);
|
|
300
|
+
_classPrivateFieldInitSpec(this, _renderError, void 0);
|
|
301
|
+
_defineProperty(this, "exitPromise", void 0);
|
|
302
|
+
_classPrivateFieldInitSpec(this, _container, void 0);
|
|
303
|
+
_classPrivateFieldInitSpec(this, _rootNode, void 0);
|
|
304
|
+
_classPrivateFieldInitSpec(this, _renderPromise, Promise.resolve());
|
|
305
|
+
_defineProperty(this, "resolveExitPromise", () => {});
|
|
306
|
+
_defineProperty(this, "rejectExitPromise", () => {});
|
|
307
|
+
_defineProperty(this, "unsubscribeExit", () => {});
|
|
308
|
+
_defineProperty(this, "onRender", () => {
|
|
309
|
+
const task = _classPrivateFieldGet2(_renderPromise, this).catch(() => {}).then(async () => {
|
|
310
|
+
var _classPrivateFieldGet2$1, _classPrivateFieldGet3, _classPrivateFieldGet4, _classPrivateFieldGet5;
|
|
311
|
+
if (_classPrivateFieldGet2(_isUnmounted, this)) return;
|
|
312
|
+
const files = await processFiles(_classPrivateFieldGet2(_rootNode, this));
|
|
313
|
+
await this.fileManager.add(...files);
|
|
314
|
+
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;
|
|
315
|
+
const output = await _assertClassBrand(_Runtime_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this));
|
|
316
|
+
if ((_classPrivateFieldGet4 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.debug) {
|
|
317
|
+
console.log("Rendering:\n");
|
|
318
|
+
console.log(output);
|
|
319
|
+
}
|
|
320
|
+
if (((_classPrivateFieldGet5 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.stdout) && node_process.default.env.NODE_ENV !== "test") {
|
|
321
|
+
_classPrivateFieldGet2(_options, this).stdout.clearLine(0);
|
|
322
|
+
_classPrivateFieldGet2(_options, this).stdout.cursorTo(0);
|
|
323
|
+
_classPrivateFieldGet2(_options, this).stdout.write(output);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
_classPrivateFieldSet2(_renderPromise, this, task.catch((error) => {
|
|
327
|
+
this.onError(error);
|
|
328
|
+
}));
|
|
329
|
+
return _classPrivateFieldGet2(_renderPromise, this);
|
|
330
|
+
});
|
|
331
|
+
_classPrivateFieldSet2(_options, this, options);
|
|
332
|
+
_classPrivateFieldSet2(_rootNode, this, require_Renderer.createNode("kubb-root"));
|
|
333
|
+
_classPrivateFieldGet2(_rootNode, this).onRender = this.onRender;
|
|
334
|
+
_classPrivateFieldGet2(_rootNode, this).onImmediateRender = this.onRender;
|
|
335
|
+
_classPrivateFieldSet2(_isUnmounted, this, false);
|
|
336
|
+
this.unmount.bind(this);
|
|
337
|
+
console.error = (data) => {
|
|
338
|
+
const message = typeof data === "string" ? data : data === null || data === void 0 ? void 0 : data.message;
|
|
339
|
+
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;
|
|
340
|
+
console.log(data);
|
|
341
|
+
};
|
|
342
|
+
const logRecoverableError = typeof reportError === "function" ? reportError : console.error;
|
|
343
|
+
const rootTag = import_constants.ConcurrentRoot;
|
|
344
|
+
_classPrivateFieldSet2(_container, this, require_Renderer.Renderer.createContainer(_classPrivateFieldGet2(_rootNode, this), rootTag, null, false, false, "id", logRecoverableError, logRecoverableError, logRecoverableError, null));
|
|
345
|
+
this.unsubscribeExit = (0, signal_exit.onExit)((code) => {
|
|
346
|
+
this.unmount(code);
|
|
347
|
+
}, { alwaysLast: false }).bind(this);
|
|
348
|
+
}
|
|
349
|
+
get fileManager() {
|
|
350
|
+
return _classPrivateFieldGet2(_options, this).fileManager;
|
|
351
|
+
}
|
|
352
|
+
onError(error) {
|
|
353
|
+
if (node_process.default.env.NODE_ENV === "test") console.warn(error);
|
|
354
|
+
_classPrivateFieldSet2(_renderError, this, error);
|
|
355
|
+
}
|
|
356
|
+
onExit(error) {
|
|
357
|
+
this.unmount(error);
|
|
358
|
+
}
|
|
359
|
+
async render(node) {
|
|
360
|
+
const treeNode = new _kubb_fabric_core.TreeNode({
|
|
361
|
+
type: "Root",
|
|
362
|
+
props: {}
|
|
363
|
+
});
|
|
364
|
+
const props = {
|
|
365
|
+
fileManager: this.fileManager,
|
|
366
|
+
treeNode,
|
|
367
|
+
onExit: this.onExit.bind(this),
|
|
368
|
+
onError: this.onError.bind(this)
|
|
369
|
+
};
|
|
370
|
+
treeNode.data.props = props;
|
|
371
|
+
const element = /* @__PURE__ */ require_jsx_runtime.jsx(Root, {
|
|
372
|
+
...props,
|
|
373
|
+
children: node
|
|
374
|
+
});
|
|
375
|
+
require_Renderer.Renderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
|
|
376
|
+
require_Renderer.Renderer.flushSyncWork();
|
|
377
|
+
await _classPrivateFieldGet2(_renderPromise, this);
|
|
378
|
+
if (_classPrivateFieldGet2(_renderError, this)) {
|
|
379
|
+
const error = _classPrivateFieldGet2(_renderError, this);
|
|
380
|
+
_classPrivateFieldSet2(_renderError, this, void 0);
|
|
381
|
+
throw error;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async renderToString(node) {
|
|
385
|
+
const treeNode = new _kubb_fabric_core.TreeNode({
|
|
386
|
+
type: "Root",
|
|
387
|
+
props: {}
|
|
388
|
+
});
|
|
389
|
+
const props = {
|
|
390
|
+
fileManager: this.fileManager,
|
|
391
|
+
treeNode,
|
|
392
|
+
onExit: this.onExit.bind(this),
|
|
393
|
+
onError: this.onError.bind(this)
|
|
394
|
+
};
|
|
395
|
+
treeNode.data.props = props;
|
|
396
|
+
const element = /* @__PURE__ */ require_jsx_runtime.jsx(Root, {
|
|
397
|
+
...props,
|
|
398
|
+
children: node
|
|
399
|
+
});
|
|
400
|
+
require_Renderer.Renderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
|
|
401
|
+
require_Renderer.Renderer.flushSyncWork();
|
|
402
|
+
await _classPrivateFieldGet2(_renderPromise, this);
|
|
403
|
+
this.fileManager.clear();
|
|
404
|
+
if (_classPrivateFieldGet2(_renderError, this)) {
|
|
405
|
+
const error = _classPrivateFieldGet2(_renderError, this);
|
|
406
|
+
_classPrivateFieldSet2(_renderError, this, void 0);
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
return _assertClassBrand(_Runtime_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this));
|
|
410
|
+
}
|
|
411
|
+
unmount(error) {
|
|
412
|
+
var _classPrivateFieldGet6;
|
|
413
|
+
if (_classPrivateFieldGet2(_isUnmounted, this)) return;
|
|
414
|
+
if ((_classPrivateFieldGet6 = _classPrivateFieldGet2(_options, this)) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.debug) console.log("Unmount", error);
|
|
415
|
+
this.onRender();
|
|
416
|
+
this.unsubscribeExit();
|
|
417
|
+
_classPrivateFieldSet2(_isUnmounted, this, true);
|
|
418
|
+
require_Renderer.Renderer.updateContainerSync(null, _classPrivateFieldGet2(_container, this), null, null);
|
|
419
|
+
if (error instanceof Error) {
|
|
420
|
+
this.rejectExitPromise(error);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
this.resolveExitPromise();
|
|
424
|
+
}
|
|
425
|
+
async waitUntilExit() {
|
|
426
|
+
if (!this.exitPromise) this.exitPromise = new Promise((resolve, reject) => {
|
|
427
|
+
this.resolveExitPromise = resolve;
|
|
428
|
+
this.rejectExitPromise = reject;
|
|
429
|
+
});
|
|
430
|
+
return this.exitPromise;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
async function _getOutput(node) {
|
|
434
|
+
const text = squashTextNodes(node);
|
|
435
|
+
const files = this.fileManager.files;
|
|
436
|
+
if (!files.length) return text;
|
|
437
|
+
const values = /* @__PURE__ */ new Set();
|
|
438
|
+
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);
|
|
439
|
+
return [...values].join("\n\n");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/plugins/reactPlugin.ts
|
|
444
|
+
const reactPlugin = (0, _kubb_fabric_core_plugins.definePlugin)({
|
|
445
|
+
name: "react",
|
|
446
|
+
install() {},
|
|
447
|
+
inject(ctx, options = {}) {
|
|
448
|
+
const runtime = new Runtime({
|
|
449
|
+
fileManager: ctx.fileManager,
|
|
450
|
+
...options
|
|
451
|
+
});
|
|
452
|
+
return {
|
|
453
|
+
async render(App) {
|
|
454
|
+
await ctx.emit("lifecycle:start");
|
|
455
|
+
await runtime.render((0, import_react.createElement)(App));
|
|
456
|
+
},
|
|
457
|
+
async renderToString(App) {
|
|
458
|
+
await ctx.emit("lifecycle:start");
|
|
459
|
+
return runtime.renderToString((0, import_react.createElement)(App));
|
|
460
|
+
},
|
|
461
|
+
async waitUntilExit() {
|
|
462
|
+
await runtime.waitUntilExit();
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
//#endregion
|
|
469
|
+
Object.defineProperty(exports, 'Runtime', {
|
|
470
|
+
enumerable: true,
|
|
471
|
+
get: function () {
|
|
472
|
+
return Runtime;
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
Object.defineProperty(exports, '_classPrivateFieldGet2', {
|
|
476
|
+
enumerable: true,
|
|
477
|
+
get: function () {
|
|
478
|
+
return _classPrivateFieldGet2;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
Object.defineProperty(exports, '_classPrivateFieldInitSpec', {
|
|
482
|
+
enumerable: true,
|
|
483
|
+
get: function () {
|
|
484
|
+
return _classPrivateFieldInitSpec;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
Object.defineProperty(exports, '_classPrivateFieldSet2', {
|
|
488
|
+
enumerable: true,
|
|
489
|
+
get: function () {
|
|
490
|
+
return _classPrivateFieldSet2;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
Object.defineProperty(exports, 'reactPlugin', {
|
|
494
|
+
enumerable: true,
|
|
495
|
+
get: function () {
|
|
496
|
+
return reactPlugin;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
//# sourceMappingURL=reactPlugin-BJ_35CCS.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactPlugin-BJ_35CCS.cjs","names":["Component","RootContext","onExit","NodeTreeContext","exports","nodeNames","nodeNames","text","nodeNames","nodeNames","collected: Array<KubbFile.File>","nodeNames","process","createNode","ConcurrentRoot","Renderer","TreeNode"],"sources":["../src/components/Root.tsx","../src/utils/squashExportNodes.ts","../src/utils/squashImportNodes.ts","../src/utils/squashTextNodes.ts","../src/utils/squashSourceNodes.ts","../src/utils/processFiles.ts","../src/Runtime.tsx","../src/plugins/reactPlugin.ts"],"sourcesContent":["import { type FileManager, NodeTreeContext, provide, RootContext, type TreeNode } from '@kubb/fabric-core'\nimport { Component } from 'react'\n\nimport type { ComponentNode, KubbNode } from '../types.ts'\n\ntype ErrorBoundaryProps = {\n onError: (error: Error) => void\n children?: KubbNode\n}\n\nclass ErrorBoundary extends Component<{\n onError: ErrorBoundaryProps['onError']\n children?: KubbNode\n}> {\n state = { hasError: false }\n\n static displayName = 'KubbErrorBoundary'\n static getDerivedStateFromError(_error: Error) {\n return { hasError: true }\n }\n\n componentDidCatch(error: Error) {\n if (error) {\n this.props.onError(error)\n }\n }\n\n render() {\n if (this.state.hasError) {\n return null\n }\n return this.props.children\n }\n}\n\nexport type RootProps = {\n /**\n * Exit (unmount) the whole app.\n */\n onExit: (error?: Error) => void\n /**\n * Error hook receiving runtime exceptions.\n */\n onError: (error: Error) => void\n /**\n * TreeNode representing the tree structure of the app.\n */\n treeNode: TreeNode<ComponentNode>\n /**\n * FileManager instance for managing files within the app.\n */\n fileManager: FileManager\n /**\n * Children nodes.\n */\n children?: KubbNode\n}\n\n/**\n * This component provides the root behavior for the Fabric runtime.\n */\nexport function Root({ onError, onExit, treeNode, fileManager, children }: RootProps) {\n provide(RootContext, { exit: onExit, treeNode, fileManager })\n provide(NodeTreeContext, treeNode)\n\n return (\n <ErrorBoundary\n onError={(error) => {\n onError(error)\n }}\n >\n {children}\n </ErrorBoundary>\n )\n}\n\nRoot.displayName = 'KubbRoot'\n","import type { KubbFile } from '@kubb/fabric-core/types'\n\nimport { nodeNames } from '../dom.ts'\nimport type { DOMElement } from '../types.ts'\n\nexport function squashExportNodes(node: DOMElement): Set<KubbFile.ResolvedExport> {\n const exports = new Set<KubbFile.ResolvedExport>()\n\n const walk = (current: DOMElement): void => {\n for (const child of current.childNodes) {\n if (!child) {\n continue\n }\n\n if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {\n walk(child)\n }\n\n if (child.nodeName === 'kubb-export') {\n exports.add({\n name: child.attributes.get('name'),\n path: child.attributes.get('path'),\n isTypeOnly: child.attributes.get('isTypeOnly') ?? false,\n asAlias: child.attributes.get('asAlias') ?? false,\n } as KubbFile.Export)\n }\n }\n }\n\n walk(node)\n return exports\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\n\nimport { nodeNames } from '../dom.ts'\nimport type { DOMElement } from '../types.ts'\n\nexport function squashImportNodes(node: DOMElement): Set<KubbFile.Import> {\n const imports = new Set<KubbFile.Import>()\n\n const walk = (current: DOMElement): void => {\n for (const child of current.childNodes) {\n if (!child) {\n continue\n }\n\n if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {\n walk(child)\n }\n\n if (child.nodeName === 'kubb-import') {\n imports.add({\n name: child.attributes.get('name'),\n path: child.attributes.get('path'),\n root: child.attributes.get('root'),\n isTypeOnly: child.attributes.get('isTypeOnly') ?? false,\n isNameSpace: child.attributes.get('isNameSpace') ?? false,\n } as KubbFile.Import)\n }\n }\n }\n\n walk(node)\n return imports\n}\n","import { createExport, createImport, print } from '@kubb/fabric-core/parsers/typescript'\n\nimport { nodeNames } from '../dom.ts'\nimport type { DOMElement, KubbFile } from '../types.ts'\n\nexport function squashTextNodes(node: DOMElement): string {\n let text = ''\n\n const walk = (current: DOMElement): string => {\n let content = ''\n\n for (const child of current.childNodes) {\n if (!child) {\n continue\n }\n\n let nodeText = ''\n\n const getPrintText = (text: string): string => {\n switch (child.nodeName) {\n case 'kubb-import': {\n return print(\n createImport({\n name: child.attributes.get('name'),\n path: child.attributes.get('path'),\n root: child.attributes.get('root'),\n isTypeOnly: child.attributes.get('isTypeOnly'),\n isNameSpace: child.attributes.get('isNameSpace'),\n } as KubbFile.Import),\n )\n }\n case 'kubb-export': {\n if (child.attributes.has('path')) {\n return print(\n createExport({\n name: child.attributes.get('name'),\n path: child.attributes.get('path'),\n isTypeOnly: child.attributes.get('isTypeOnly'),\n asAlias: child.attributes.get('asAlias'),\n } as KubbFile.Export),\n )\n }\n return ''\n }\n case 'kubb-source':\n return text\n default:\n return text\n }\n }\n\n if (child.nodeName === '#text') {\n nodeText = child.nodeValue\n } else {\n if (child.nodeName === 'kubb-text' || child.nodeName === 'kubb-file' || child.nodeName === 'kubb-source') {\n nodeText = walk(child)\n }\n\n nodeText = getPrintText(nodeText)\n\n if (child.nodeName === 'br') {\n nodeText = '\\n'\n }\n\n if (!nodeNames.has(child.nodeName)) {\n const attributes = child.attributes\n let attrString = ''\n const hasAttributes = attributes.size > 0\n\n for (const [key, value] of attributes) {\n attrString += typeof value === 'string' ? ` ${key}=\"${value}\"` : ` ${key}={${String(value)}}`\n }\n\n if (hasAttributes) {\n nodeText = `<${child.nodeName}${attrString}>${walk(child)}</${child.nodeName}>`\n } else {\n nodeText = `<${child.nodeName}>${walk(child)}</${child.nodeName}>`\n }\n }\n }\n\n content += nodeText\n }\n\n return content\n }\n\n text = walk(node)\n\n return text\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\n\nimport { nodeNames } from '../dom.ts'\nimport type { DOMElement, ElementNames } from '../types.ts'\nimport { squashTextNodes } from './squashTextNodes.ts'\n\nexport function squashSourceNodes(node: DOMElement, ignores: Array<ElementNames>): Set<KubbFile.Source> {\n const ignoreSet = new Set(ignores)\n const sources = new Set<KubbFile.Source>()\n\n const walk = (current: DOMElement): void => {\n for (const child of current.childNodes) {\n if (!child) {\n continue\n }\n\n if (child.nodeName !== '#text' && ignoreSet.has(child.nodeName)) {\n continue\n }\n\n if (child.nodeName === 'kubb-source') {\n const value = squashTextNodes(child)\n\n sources.add({\n name: child.attributes.get('name'),\n isTypeOnly: child.attributes.get('isTypeOnly') ?? false,\n isExportable: child.attributes.get('isExportable') ?? false,\n isIndexable: child.attributes.get('isIndexable') ?? false,\n // trim whitespace/newlines\n value: value.trim().replace(/^\\s+|\\s+$/g, ''),\n } as KubbFile.Source)\n continue\n }\n\n if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {\n walk(child)\n }\n }\n }\n\n walk(node)\n return sources\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { nodeNames } from '../dom.ts'\nimport type { DOMElement } from '../types.ts'\nimport { squashExportNodes } from './squashExportNodes.ts'\nimport { squashImportNodes } from './squashImportNodes.ts'\nimport { squashSourceNodes } from './squashSourceNodes.ts'\n\nexport async function processFiles(node: DOMElement): Promise<Array<KubbFile.File>> {\n const collected: Array<KubbFile.File> = []\n\n async function walk(current: DOMElement) {\n for (const child of current.childNodes) {\n if (!child) {\n continue\n }\n\n if (child.nodeName !== '#text' && child.nodeName !== 'kubb-file' && nodeNames.has(child.nodeName)) {\n await walk(child)\n }\n\n if (child.nodeName === 'kubb-file') {\n if (child.attributes.has('baseName') && child.attributes.has('path')) {\n const sources = squashSourceNodes(child, ['kubb-export', 'kubb-import'])\n\n collected.push({\n baseName: child.attributes.get('baseName'),\n path: child.attributes.get('path'),\n meta: child.attributes.get('meta') || {},\n footer: child.attributes.get('footer'),\n banner: child.attributes.get('banner'),\n sources: [...sources],\n exports: [...squashExportNodes(child)],\n imports: [...squashImportNodes(child)],\n } as KubbFile.File)\n }\n }\n }\n }\n\n await walk(node)\n\n return collected\n}\n","import process from 'node:process'\nimport { type FileManager, TreeNode } from '@kubb/fabric-core'\nimport type { ReactNode } from 'react'\nimport { ConcurrentRoot } from 'react-reconciler/constants.js'\nimport { onExit } from 'signal-exit'\nimport { Root } from './components/Root.tsx'\nimport { createNode } from './dom.ts'\nimport type { FiberRoot } from './Renderer.ts'\nimport { Renderer } from './Renderer.ts'\nimport type { ComponentNode, DOMElement } from './types.ts'\nimport { processFiles } from './utils/processFiles.ts'\nimport { squashTextNodes } from './utils/squashTextNodes.ts'\n\ntype Options = {\n fileManager: FileManager\n stdout?: NodeJS.WriteStream\n stdin?: NodeJS.ReadStream\n stderr?: NodeJS.WriteStream\n /**\n * Set this to true to always see the result of the render in the console(line per render)\n */\n debug?: boolean\n}\n\nexport class Runtime {\n readonly #options: Options\n #isUnmounted: boolean\n #renderError?: Error\n\n exitPromise?: Promise<void>\n readonly #container: FiberRoot\n readonly #rootNode: DOMElement\n\n constructor(options: Options) {\n this.#options = options\n this.#rootNode = createNode('kubb-root')\n this.#rootNode.onRender = this.onRender\n this.#rootNode.onImmediateRender = this.onRender\n this.#isUnmounted = false\n this.unmount.bind(this)\n\n // Intercept noisy React errors\n console.error = (data: string | Error) => {\n const message = typeof data === 'string' ? data : data?.message\n if (\n message?.match(/Encountered two children with the same key/gi) ||\n message?.match(/React will try to recreat/gi) ||\n message?.match(/Each child in a list should have a unique/gi) ||\n message?.match(/The above error occurred in the <KubbErrorBoundary/gi) ||\n message?.match(/A React Element from an older version of React was render/gi)\n ) {\n return\n }\n console.log(data)\n }\n\n const logRecoverableError = typeof reportError === 'function' ? reportError : console.error\n\n const rootTag = ConcurrentRoot\n this.#container = Renderer.createContainer(\n this.#rootNode,\n rootTag,\n null,\n false,\n false,\n 'id',\n logRecoverableError,\n logRecoverableError,\n logRecoverableError,\n null,\n )\n\n // Unmount when process exits\n this.unsubscribeExit = onExit(\n (code) => {\n this.unmount(code)\n },\n { alwaysLast: false },\n ).bind(this)\n }\n\n get fileManager() {\n return this.#options.fileManager\n }\n\n #renderPromise: Promise<void> = Promise.resolve()\n resolveExitPromise: () => void = () => {}\n rejectExitPromise: (reason?: Error) => void = () => {}\n unsubscribeExit: () => void = () => {}\n\n onRender: () => Promise<void> = () => {\n const previous = this.#renderPromise\n\n const task = previous\n .catch(() => {})\n .then(async () => {\n if (this.#isUnmounted) {\n return\n }\n\n const files = await processFiles(this.#rootNode)\n\n await this.fileManager.add(...files)\n\n if (!this.#options?.debug && !this.#options?.stdout) {\n return\n }\n\n const output = await this.#getOutput(this.#rootNode)\n\n if (this.#options?.debug) {\n console.log('Rendering:\\n')\n console.log(output)\n }\n\n if (this.#options?.stdout && process.env.NODE_ENV !== 'test') {\n this.#options.stdout.clearLine(0)\n this.#options.stdout.cursorTo(0)\n this.#options.stdout.write(output)\n }\n })\n\n this.#renderPromise = task.catch((error) => {\n this.onError(error as Error)\n })\n\n return this.#renderPromise\n }\n\n onError(error: Error): void {\n if (process.env.NODE_ENV === 'test') {\n console.warn(error)\n }\n\n // Store the error to be thrown after render completes\n this.#renderError = error\n }\n\n onExit(error?: Error): void {\n this.unmount(error)\n }\n\n async #getOutput(node: DOMElement): Promise<string> {\n const text = squashTextNodes(node)\n const files = this.fileManager.files\n\n if (!files.length) {\n return text\n }\n\n const values = new Set<string>()\n for (const file of files) {\n for (const source of file.sources) {\n if (source?.value) {\n values.add(source.value)\n }\n }\n }\n\n return [...values].join('\\n\\n')\n }\n\n async render(node: ReactNode): Promise<void> {\n const treeNode = new TreeNode<ComponentNode>({ type: 'Root', props: {} })\n const props = {\n fileManager: this.fileManager,\n treeNode,\n onExit: this.onExit.bind(this),\n onError: this.onError.bind(this),\n }\n treeNode.data.props = props\n\n const element = <Root {...props}>{node}</Root>\n\n Renderer.updateContainerSync(element, this.#container, null, null)\n Renderer.flushSyncWork()\n await this.#renderPromise\n\n // Throw any errors that occurred during rendering\n if (this.#renderError) {\n const error = this.#renderError\n this.#renderError = undefined\n throw error\n }\n }\n\n async renderToString(node: ReactNode): Promise<string> {\n const treeNode = new TreeNode<ComponentNode>({ type: 'Root', props: {} })\n const props = {\n fileManager: this.fileManager,\n treeNode,\n onExit: this.onExit.bind(this),\n onError: this.onError.bind(this),\n }\n treeNode.data.props = props\n\n const element = <Root {...props}>{node}</Root>\n\n Renderer.updateContainerSync(element, this.#container, null, null)\n Renderer.flushSyncWork()\n\n await this.#renderPromise\n this.fileManager.clear()\n\n // Throw any errors that occurred during rendering\n if (this.#renderError) {\n const error = this.#renderError\n this.#renderError = undefined\n throw error\n }\n\n return this.#getOutput(this.#rootNode)\n }\n\n unmount(error?: Error | number | null): void {\n if (this.#isUnmounted) {\n return\n }\n\n if (this.#options?.debug) {\n console.log('Unmount', error)\n }\n\n this.onRender()\n this.unsubscribeExit()\n\n this.#isUnmounted = true\n\n Renderer.updateContainerSync(null, this.#container, null, null)\n\n if (error instanceof Error) {\n this.rejectExitPromise(error)\n return\n }\n\n this.resolveExitPromise()\n }\n\n async waitUntilExit(): Promise<void> {\n if (!this.exitPromise) {\n this.exitPromise = new Promise((resolve, reject) => {\n this.resolveExitPromise = resolve\n this.rejectExitPromise = reject\n })\n }\n\n return this.exitPromise\n }\n}\n","import { definePlugin } from '@kubb/fabric-core/plugins'\nimport { createElement, type ElementType } from 'react'\nimport { Runtime } from '../Runtime.tsx'\n\nexport type Options = {\n stdout?: NodeJS.WriteStream\n stdin?: NodeJS.ReadStream\n stderr?: NodeJS.WriteStream\n /**\n * Set this to true to always see the result of the render in the console(line per render)\n */\n debug?: boolean\n}\n\ntype ExtendOptions = {\n render(App: ElementType): Promise<void>\n renderToString(App: ElementType): Promise<string>\n waitUntilExit(): Promise<void>\n}\n\ndeclare global {\n namespace Kubb {\n interface Fabric {\n render(App: ElementType): Promise<void>\n renderToString(App: ElementType): Promise<string>\n waitUntilExit(): Promise<void>\n }\n }\n}\n\nexport const reactPlugin = definePlugin<Options, ExtendOptions>({\n name: 'react',\n install() {},\n inject(ctx, options = {}) {\n const runtime = new Runtime({ fileManager: ctx.fileManager, ...options })\n\n return {\n async render(App) {\n await ctx.emit('lifecycle:start')\n await runtime.render(createElement(App))\n },\n async renderToString(App) {\n await ctx.emit('lifecycle:start')\n return runtime.renderToString(createElement(App))\n },\n async waitUntilExit() {\n await runtime.waitUntilExit()\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,IAAM,gBAAN,cAA4BA,uBAGzB;;;wBACD,SAAQ,EAAE,UAAU,OAAO;;CAG3B,OAAO,yBAAyB,QAAe;AAC7C,SAAO,EAAE,UAAU,MAAM;;CAG3B,kBAAkB,OAAc;AAC9B,MAAI,MACF,MAAK,MAAM,QAAQ,MAAM;;CAI7B,SAAS;AACP,MAAI,KAAK,MAAM,SACb,QAAO;AAET,SAAO,KAAK,MAAM;;;+BAfb,eAAc;;;;AA6CvB,SAAgB,KAAK,EAAE,SAAS,kBAAQ,UAAU,aAAa,YAAuB;AACpF,gCAAQC,+BAAa;EAAE,MAAMC;EAAQ;EAAU;EAAa,CAAC;AAC7D,gCAAQC,mCAAiB,SAAS;AAElC,QACE,wCAAC;EACC,UAAU,UAAU;AAClB,WAAQ,MAAM;;EAGf;GACa;;AAIpB,KAAK,cAAc;;;;ACvEnB,SAAgB,kBAAkB,MAAgD;CAChF,MAAMC,4BAAU,IAAI,KAA8B;CAElD,MAAM,QAAQ,YAA8B;AAC1C,OAAK,MAAM,SAAS,QAAQ,YAAY;AACtC,OAAI,CAAC,MACH;AAGF,OAAI,MAAM,aAAa,WAAWC,2BAAU,IAAI,MAAM,SAAS,CAC7D,MAAK,MAAM;AAGb,OAAI,MAA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