@kubb/renderer-jsx 5.0.0-beta.17 → 5.0.0-beta.19

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/index.js CHANGED
@@ -346,7 +346,7 @@ function Jsx({ children }) {
346
346
  Jsx.displayName = "Jsx";
347
347
  //#endregion
348
348
  //#region src/components/Root.tsx
349
- var import_react = require_react();
349
+ var import_react = /* @__PURE__ */ __toESM(require_react());
350
350
  var ErrorBoundary = class extends import_react.Component {
351
351
  state = { hasError: false };
352
352
  static displayName = "ErrorBoundary";
@@ -454,20 +454,29 @@ var import_constants = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
454
454
  * Name used for text-node entries in the virtual DOM.
455
455
  */
456
456
  const TEXT_NODE_NAME = "#text";
457
+ const KUBB_FILE = "kubb-file";
458
+ const KUBB_SOURCE = "kubb-source";
459
+ const KUBB_EXPORT = "kubb-export";
460
+ const KUBB_IMPORT = "kubb-import";
461
+ const KUBB_FUNCTION = "kubb-function";
462
+ const KUBB_ARROW_FUNCTION = "kubb-arrow-function";
463
+ const KUBB_CONST = "kubb-const";
464
+ const KUBB_TYPE = "kubb-type";
465
+ const KUBB_JSX = "kubb-jsx";
457
466
  /**
458
467
  * Set of all element names recognized by the Kubb renderer.
459
468
  * Used to distinguish Kubb-owned elements from unrecognized or text nodes during tree traversal.
460
469
  */
461
470
  const nodeNames = new Set([
462
- "kubb-export",
463
- "kubb-file",
464
- "kubb-source",
465
- "kubb-import",
466
- "kubb-function",
467
- "kubb-arrow-function",
468
- "kubb-const",
469
- "kubb-type",
470
- "kubb-jsx",
471
+ KUBB_EXPORT,
472
+ KUBB_FILE,
473
+ KUBB_SOURCE,
474
+ KUBB_IMPORT,
475
+ KUBB_FUNCTION,
476
+ KUBB_ARROW_FUNCTION,
477
+ KUBB_CONST,
478
+ KUBB_TYPE,
479
+ KUBB_JSX,
471
480
  "kubb-text",
472
481
  "kubb-root",
473
482
  "kubb-app",
@@ -484,7 +493,7 @@ const nodeNames = new Set([
484
493
  const createNode = (nodeName) => {
485
494
  return {
486
495
  nodeName,
487
- attributes: /* @__PURE__ */ new Map(),
496
+ attributes: Object.create(null),
488
497
  childNodes: [],
489
498
  parentNode: void 0
490
499
  };
@@ -532,26 +541,22 @@ const removeChildNode = (node, removeNode) => {
532
541
  * Set an attribute on `node`, storing it in the node's `attributes` map.
533
542
  */
534
543
  const setAttribute = (node, key, value) => {
535
- node.attributes.set(key, value);
544
+ node.attributes[key] = value;
536
545
  };
537
546
  /**
538
547
  * Create a new {@link TextNode} with the given text value.
539
548
  */
540
549
  const createTextNode = (text) => {
541
- const node = {
550
+ return {
542
551
  nodeName: TEXT_NODE_NAME,
543
552
  nodeValue: text,
544
553
  parentNode: void 0
545
554
  };
546
- setTextNodeValue(node, text);
547
- return node;
548
555
  };
549
556
  /**
550
557
  * Update the `nodeValue` of an existing {@link TextNode}.
551
- * Non-string values are coerced to strings via `String(text)`.
552
558
  */
553
559
  const setTextNodeValue = (node, text) => {
554
- if (typeof text !== "string") text = String(text);
555
560
  node.nodeValue = text;
556
561
  };
557
562
  //#endregion
@@ -17820,7 +17825,7 @@ const Renderer = (0, import_react_reconciler.default)({
17820
17825
  return false;
17821
17826
  },
17822
17827
  supportsMutation: true,
17823
- isPrimaryRenderer: true,
17828
+ isPrimaryRenderer: false,
17824
17829
  supportsPersistence: false,
17825
17830
  supportsHydration: false,
17826
17831
  scheduleTimeout: setTimeout,
@@ -17886,187 +17891,190 @@ const Renderer = (0, import_react_reconciler.default)({
17886
17891
  });
17887
17892
  //#endregion
17888
17893
  //#region src/utils.ts
17894
+ function toBool$1(val) {
17895
+ return val ?? false;
17896
+ }
17897
+ __name(toBool$1, "toBool");
17889
17898
  /**
17890
17899
  * Collect the text and nested AST-node children of a single kubb-* element.
17891
17900
  *
17892
- * `#text` children become raw {@link TextNode}s; nested `kubb-function`, `kubb-const`,
17901
+ * `#text` children become raw text nodes; nested `kubb-function`, `kubb-const`,
17893
17902
  * `kubb-type`, and similar elements are converted into their respective {@link CodeNode}s.
17894
- * Any unrecognized DOM elements are silently skipped.
17903
+ * Any unrecognized element names are silently skipped.
17895
17904
  */
17896
- function collectChildNodes(element) {
17905
+ function collectCodeNodes$1(element) {
17897
17906
  const result = [];
17898
17907
  for (const child of element.childNodes) {
17899
17908
  if (!child) continue;
17900
- if (child.nodeName === "#text") {
17901
- const text = child.nodeValue;
17902
- if (text && text.trim().length > 0) result.push(createText(text));
17903
- continue;
17904
- }
17905
- if (child.nodeName === "br") {
17906
- result.push(createBreak());
17907
- continue;
17908
- }
17909
- if (child.nodeName === "kubb-function") {
17910
- const attrs = child.attributes;
17911
- result.push(createFunction({
17912
- name: attrs.get("name"),
17913
- params: attrs.get("params"),
17914
- export: attrs.get("export"),
17915
- default: attrs.get("default"),
17916
- async: attrs.get("async"),
17917
- generics: attrs.get("generics"),
17918
- returnType: attrs.get("returnType"),
17919
- JSDoc: attrs.get("JSDoc"),
17920
- nodes: collectChildNodes(child)
17921
- }));
17922
- } else if (child.nodeName === "kubb-arrow-function") {
17923
- const attrs = child.attributes;
17924
- result.push(createArrowFunction({
17925
- name: attrs.get("name"),
17926
- params: attrs.get("params"),
17927
- export: attrs.get("export"),
17928
- default: attrs.get("default"),
17929
- async: attrs.get("async"),
17930
- generics: attrs.get("generics"),
17931
- returnType: attrs.get("returnType"),
17932
- singleLine: attrs.get("singleLine"),
17933
- JSDoc: attrs.get("JSDoc"),
17934
- nodes: collectChildNodes(child)
17935
- }));
17936
- } else if (child.nodeName === "kubb-const") {
17937
- const attrs = child.attributes;
17938
- result.push(createConst({
17939
- name: attrs.get("name"),
17940
- type: attrs.get("type"),
17941
- export: attrs.get("export"),
17942
- asConst: attrs.get("asConst"),
17943
- JSDoc: attrs.get("JSDoc"),
17944
- nodes: collectChildNodes(child)
17945
- }));
17946
- } else if (child.nodeName === "kubb-type") {
17947
- const attrs = child.attributes;
17948
- result.push(createType({
17949
- name: attrs.get("name"),
17950
- export: attrs.get("export"),
17951
- JSDoc: attrs.get("JSDoc"),
17952
- nodes: collectChildNodes(child)
17953
- }));
17954
- } else if (child.nodeName === "kubb-jsx") {
17955
- const textChild = child.childNodes[0];
17956
- const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17957
- if (value) result.push(createJsx(value));
17909
+ switch (child.nodeName) {
17910
+ case TEXT_NODE_NAME: {
17911
+ const text = child.nodeValue;
17912
+ if (text && text.trim()) result.push(createText(text));
17913
+ break;
17914
+ }
17915
+ case "br":
17916
+ result.push(createBreak());
17917
+ break;
17918
+ case KUBB_FUNCTION: {
17919
+ const attrs = child.attributes;
17920
+ result.push(createFunction({
17921
+ name: attrs["name"],
17922
+ params: attrs["params"],
17923
+ export: attrs["export"],
17924
+ default: attrs["default"],
17925
+ async: attrs["async"],
17926
+ generics: attrs["generics"],
17927
+ returnType: attrs["returnType"],
17928
+ JSDoc: attrs["JSDoc"],
17929
+ nodes: collectCodeNodes$1(child)
17930
+ }));
17931
+ break;
17932
+ }
17933
+ case KUBB_ARROW_FUNCTION: {
17934
+ const attrs = child.attributes;
17935
+ result.push(createArrowFunction({
17936
+ name: attrs["name"],
17937
+ params: attrs["params"],
17938
+ export: attrs["export"],
17939
+ default: attrs["default"],
17940
+ async: attrs["async"],
17941
+ generics: attrs["generics"],
17942
+ returnType: attrs["returnType"],
17943
+ singleLine: attrs["singleLine"],
17944
+ JSDoc: attrs["JSDoc"],
17945
+ nodes: collectCodeNodes$1(child)
17946
+ }));
17947
+ break;
17948
+ }
17949
+ case KUBB_CONST: {
17950
+ const attrs = child.attributes;
17951
+ result.push(createConst({
17952
+ name: attrs["name"],
17953
+ type: attrs["type"],
17954
+ export: attrs["export"],
17955
+ asConst: attrs["asConst"],
17956
+ JSDoc: attrs["JSDoc"],
17957
+ nodes: collectCodeNodes$1(child)
17958
+ }));
17959
+ break;
17960
+ }
17961
+ case KUBB_TYPE: {
17962
+ const attrs = child.attributes;
17963
+ result.push(createType({
17964
+ name: attrs["name"],
17965
+ export: attrs["export"],
17966
+ JSDoc: attrs["JSDoc"],
17967
+ nodes: collectCodeNodes$1(child)
17968
+ }));
17969
+ break;
17970
+ }
17971
+ case KUBB_JSX: {
17972
+ const textChild = child.childNodes[0];
17973
+ const value = textChild?.nodeName === "#text" ? textChild.nodeValue : "";
17974
+ if (value) result.push(createJsx(value));
17975
+ break;
17976
+ }
17958
17977
  }
17959
17978
  }
17960
17979
  return result;
17961
17980
  }
17981
+ __name(collectCodeNodes$1, "collectCodeNodes");
17962
17982
  /**
17963
- * Traverse `node` and collect all `<kubb-source>` elements into a `Set<SourceNode>`.
17964
- *
17965
- * Elements whose `nodeName` is in `ignores` are skipped entirely (including their subtrees).
17966
- * This is used to collect source blocks from a file node while excluding import/export subtrees.
17983
+ * Yields every {@link SourceNode}, {@link ExportNode}, and {@link ImportNode}
17984
+ * within a `<kubb-file>` subtree in a single tree walk.
17967
17985
  *
17968
- * @example Collect sources while ignoring export and import elements
17969
- * ```ts
17970
- * const sources = squashSourceNodes(fileElement, ['kubb-export', 'kubb-import'])
17971
- * ```
17986
+ * Import and export elements are leaf nodes. Once yielded, the walker does not
17987
+ * recurse into them, which also prevents source collection from descending into
17988
+ * their subtrees. Dispatch on `.kind` (`'Source'`, `'Export'`, `'Import'`) to
17989
+ * separate the results.
17972
17990
  */
17973
- function squashSourceNodes(node, ignores) {
17974
- const ignoreSet = new Set(ignores);
17975
- const sources = /* @__PURE__ */ new Set();
17976
- const walk = (current) => {
17977
- for (const child of current.childNodes) {
17978
- if (!child) continue;
17979
- if (child.nodeName !== "#text" && ignoreSet.has(child.nodeName)) continue;
17980
- if (child.nodeName === "kubb-source") {
17981
- const source = createSource({
17982
- name: child.attributes.get("name")?.toString(),
17983
- isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
17984
- isExportable: child.attributes.get("isExportable") ?? false,
17985
- isIndexable: child.attributes.get("isIndexable") ?? false,
17986
- nodes: collectChildNodes(child)
17987
- });
17988
- sources.add(source);
17989
- continue;
17990
- }
17991
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
17991
+ function* collectFileEntries(node) {
17992
+ for (const child of node.childNodes) {
17993
+ if (!child || child.nodeName === "#text") continue;
17994
+ if (child.nodeName === "kubb-source") {
17995
+ yield createSource({
17996
+ name: child.attributes["name"]?.toString(),
17997
+ isTypeOnly: toBool$1(child.attributes["isTypeOnly"]),
17998
+ isExportable: toBool$1(child.attributes["isExportable"]),
17999
+ isIndexable: toBool$1(child.attributes["isIndexable"]),
18000
+ nodes: collectCodeNodes$1(child)
18001
+ });
18002
+ continue;
17992
18003
  }
17993
- };
17994
- walk(node);
17995
- return sources;
18004
+ if (child.nodeName === "kubb-export") {
18005
+ yield createExport({
18006
+ name: child.attributes["name"],
18007
+ path: child.attributes["path"],
18008
+ isTypeOnly: toBool$1(child.attributes["isTypeOnly"]),
18009
+ asAlias: toBool$1(child.attributes["asAlias"])
18010
+ });
18011
+ continue;
18012
+ }
18013
+ if (child.nodeName === "kubb-import") {
18014
+ yield createImport({
18015
+ name: child.attributes["name"],
18016
+ path: child.attributes["path"],
18017
+ root: child.attributes["root"],
18018
+ isTypeOnly: toBool$1(child.attributes["isTypeOnly"]),
18019
+ isNameSpace: toBool$1(child.attributes["isNameSpace"])
18020
+ });
18021
+ continue;
18022
+ }
18023
+ if (nodeNames.has(child.nodeName)) yield* collectFileEntries(child);
18024
+ }
17996
18025
  }
17997
18026
  /**
17998
- * Traverse `node` and collect all `<kubb-export>` elements into a `Set<ExportNode>`.
18027
+ * Runs a single {@link collectFileEntries} pass over a `<kubb-file>` DOM element
18028
+ * and assembles the result into a {@link FileNode}, bucketing each yielded
18029
+ * node by its `.kind`.
17999
18030
  */
18000
- function squashExportNodes(node) {
18001
- const exports = /* @__PURE__ */ new Set();
18002
- const walk = (current) => {
18003
- for (const child of current.childNodes) {
18004
- if (!child) continue;
18005
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
18006
- if (child.nodeName === "kubb-export") exports.add(createExport({
18007
- name: child.attributes.get("name"),
18008
- path: child.attributes.get("path"),
18009
- isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
18010
- asAlias: child.attributes.get("asAlias") ?? false
18011
- }));
18031
+ function createFileNode(child) {
18032
+ const sources = [];
18033
+ const exports = [];
18034
+ const imports = [];
18035
+ for (const node of collectFileEntries(child)) {
18036
+ if (node.kind === "Source") {
18037
+ sources.push(node);
18038
+ continue;
18039
+ }
18040
+ if (node.kind === "Export") {
18041
+ exports.push(node);
18042
+ continue;
18012
18043
  }
18044
+ imports.push(node);
18045
+ }
18046
+ return {
18047
+ baseName: child.attributes["baseName"],
18048
+ path: child.attributes["path"],
18049
+ meta: child.attributes["meta"] || {},
18050
+ footer: child.attributes["footer"],
18051
+ banner: child.attributes["banner"],
18052
+ sources,
18053
+ exports,
18054
+ imports
18013
18055
  };
18014
- walk(node);
18015
- return exports;
18016
18056
  }
18017
18057
  /**
18018
- * Traverse `node` and collect all `<kubb-import>` elements into a `Set<ImportNode>`.
18058
+ * Yields each {@link FileNode} as it is encountered during the tree walk,
18059
+ * without collecting into an intermediate array. Callers can begin processing
18060
+ * each file before the rest of the tree is traversed.
18019
18061
  */
18020
- function squashImportNodes(node) {
18021
- const imports = /* @__PURE__ */ new Set();
18022
- const walk = (current) => {
18023
- for (const child of current.childNodes) {
18024
- if (!child) continue;
18025
- if (child.nodeName !== "#text" && nodeNames.has(child.nodeName)) walk(child);
18026
- if (child.nodeName === "kubb-import") imports.add(createImport({
18027
- name: child.attributes.get("name"),
18028
- path: child.attributes.get("path"),
18029
- root: child.attributes.get("root"),
18030
- isTypeOnly: child.attributes.get("isTypeOnly") ?? false,
18031
- isNameSpace: child.attributes.get("isNameSpace") ?? false
18032
- }));
18033
- }
18034
- };
18035
- walk(node);
18036
- return imports;
18062
+ function* streamFiles(node) {
18063
+ for (const child of node.childNodes) {
18064
+ if (!child) continue;
18065
+ if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && nodeNames.has(child.nodeName)) yield* streamFiles(child);
18066
+ if (child.nodeName === "kubb-file" && child.attributes["baseName"] !== void 0 && child.attributes["path"] !== void 0) yield createFileNode(child);
18067
+ }
18037
18068
  }
18038
18069
  /**
18039
18070
  * Walk the virtual DOM tree rooted at `node` and convert every `<kubb-file>` element
18040
18071
  * into a {@link FileNode}, collecting its source blocks, imports, and exports.
18041
18072
  *
18042
- * Returns the list of file nodes in document order. Nested files are supported
18073
+ * Returns the list of file nodes in document order. Nested files are supported;
18043
18074
  * the walker descends into non-file elements and recurses through them.
18044
18075
  */
18045
- function processFiles(node) {
18046
- const collected = [];
18047
- function walk(current) {
18048
- for (const child of current.childNodes) {
18049
- if (!child) continue;
18050
- if (child.nodeName !== "#text" && child.nodeName !== "kubb-file" && nodeNames.has(child.nodeName)) walk(child);
18051
- if (child.nodeName === "kubb-file") {
18052
- if (child.attributes.has("baseName") && child.attributes.has("path")) {
18053
- const sources = squashSourceNodes(child, ["kubb-export", "kubb-import"]);
18054
- collected.push({
18055
- baseName: child.attributes.get("baseName"),
18056
- path: child.attributes.get("path"),
18057
- meta: child.attributes.get("meta") || {},
18058
- footer: child.attributes.get("footer"),
18059
- banner: child.attributes.get("banner"),
18060
- sources: [...sources],
18061
- exports: [...squashExportNodes(child)],
18062
- imports: [...squashImportNodes(child)]
18063
- });
18064
- }
18065
- }
18066
- }
18067
- }
18068
- walk(node);
18069
- return collected;
18076
+ function collectFiles(node) {
18077
+ return [...streamFiles(node)];
18070
18078
  }
18071
18079
  //#endregion
18072
18080
  //#region src/Runtime.tsx
@@ -18091,7 +18099,7 @@ var Runtime = class {
18091
18099
  console.log(data);
18092
18100
  };
18093
18101
  const logRecoverableError = typeof reportError === "function" ? reportError : console.error;
18094
- const rootTag = import_constants.ConcurrentRoot;
18102
+ const rootTag = import_constants.LegacyRoot;
18095
18103
  this.#container = Renderer.createContainer(this.#rootNode, rootTag, null, false, false, "id", logRecoverableError, logRecoverableError, logRecoverableError, null);
18096
18104
  this.unsubscribeExit = onProcessExit((code) => {
18097
18105
  this.unmount(code);
@@ -18104,7 +18112,7 @@ var Runtime = class {
18104
18112
  onRender = () => {
18105
18113
  const task = this.#renderPromise.catch(() => {}).then(() => {
18106
18114
  if (this.#isUnmounted) return;
18107
- const files = processFiles(this.#rootNode);
18115
+ const files = collectFiles(this.#rootNode);
18108
18116
  this.nodes.push(...files);
18109
18117
  if (!this.#options?.debug) return;
18110
18118
  });
@@ -18151,21 +18159,234 @@ var Runtime = class {
18151
18159
  }
18152
18160
  };
18153
18161
  //#endregion
18162
+ //#region src/SyncRuntime.tsx
18163
+ /**
18164
+ * Walks `element`, resolving arrays, Fragments, and function components
18165
+ * transparently, then calls `onText` for primitive values and `onHost` for
18166
+ * every host element encountered. Pure function components are called
18167
+ * synchronously; hooks and class components are not supported.
18168
+ */
18169
+ function walkElement(element, onText, onHost) {
18170
+ if (element == null || typeof element === "boolean") return;
18171
+ if (typeof element === "string" || typeof element === "number" || typeof element === "bigint") {
18172
+ onText(String(element));
18173
+ return;
18174
+ }
18175
+ if (Array.isArray(element)) {
18176
+ for (const child of element) walkElement(child, onText, onHost);
18177
+ return;
18178
+ }
18179
+ if (typeof element === "object" && "$$typeof" in element) {
18180
+ const el = element;
18181
+ const { type } = el;
18182
+ const props = el.props;
18183
+ if (type === import_react.Fragment) {
18184
+ walkElement(props["children"], onText, onHost);
18185
+ return;
18186
+ }
18187
+ if (typeof type === "function") {
18188
+ walkElement(type(props), onText, onHost);
18189
+ return;
18190
+ }
18191
+ if (typeof type === "string") onHost(type, props);
18192
+ }
18193
+ }
18194
+ function toBool(val) {
18195
+ return val ?? false;
18196
+ }
18197
+ function collectCodeNodes(props) {
18198
+ const nodes = [];
18199
+ collectCode(props["children"], nodes);
18200
+ return nodes;
18201
+ }
18202
+ function collectCode(element, nodes) {
18203
+ walkElement(element, (text) => {
18204
+ if (text.trim()) nodes.push(createText(text));
18205
+ }, (type, props) => resolveCodeNode(type, props, nodes));
18206
+ }
18207
+ function resolveCodeNode(type, props, nodes) {
18208
+ if (type === "br") {
18209
+ nodes.push(createBreak());
18210
+ return;
18211
+ }
18212
+ if (type === "kubb-jsx") {
18213
+ let value = "";
18214
+ walkElement(props["children"], (t) => {
18215
+ value += t;
18216
+ }, () => {});
18217
+ if (value) nodes.push(createJsx(value));
18218
+ return;
18219
+ }
18220
+ if (type === "kubb-function") {
18221
+ nodes.push(createFunction({
18222
+ name: props["name"],
18223
+ params: props["params"],
18224
+ export: props["export"],
18225
+ default: props["default"],
18226
+ async: props["async"],
18227
+ generics: props["generics"],
18228
+ returnType: props["returnType"],
18229
+ JSDoc: props["JSDoc"],
18230
+ nodes: collectCodeNodes(props)
18231
+ }));
18232
+ return;
18233
+ }
18234
+ if (type === "kubb-arrow-function") {
18235
+ nodes.push(createArrowFunction({
18236
+ name: props["name"],
18237
+ params: props["params"],
18238
+ export: props["export"],
18239
+ default: props["default"],
18240
+ async: props["async"],
18241
+ generics: props["generics"],
18242
+ returnType: props["returnType"],
18243
+ singleLine: props["singleLine"],
18244
+ JSDoc: props["JSDoc"],
18245
+ nodes: collectCodeNodes(props)
18246
+ }));
18247
+ return;
18248
+ }
18249
+ if (type === "kubb-const") {
18250
+ nodes.push(createConst({
18251
+ name: props["name"],
18252
+ type: props["type"],
18253
+ export: props["export"],
18254
+ asConst: props["asConst"],
18255
+ JSDoc: props["JSDoc"],
18256
+ nodes: collectCodeNodes(props)
18257
+ }));
18258
+ return;
18259
+ }
18260
+ if (type === "kubb-type") {
18261
+ nodes.push(createType({
18262
+ name: props["name"],
18263
+ export: props["export"],
18264
+ JSDoc: props["JSDoc"],
18265
+ nodes: collectCodeNodes(props)
18266
+ }));
18267
+ return;
18268
+ }
18269
+ }
18270
+ function collectFileChildren(element) {
18271
+ const sources = [];
18272
+ const exports = [];
18273
+ const imports = [];
18274
+ walkElement(element, (text) => {
18275
+ if (text.trim()) throw new Error(`[react] '${text}' should be part of <File.Source> component when using the <File/> component`);
18276
+ }, (type, props) => {
18277
+ if (type === "kubb-source") {
18278
+ sources.push(createSource({
18279
+ name: props["name"]?.toString(),
18280
+ isTypeOnly: toBool(props["isTypeOnly"]),
18281
+ isExportable: toBool(props["isExportable"]),
18282
+ isIndexable: toBool(props["isIndexable"]),
18283
+ nodes: collectCodeNodes(props)
18284
+ }));
18285
+ return;
18286
+ }
18287
+ if (type === "kubb-export") {
18288
+ exports.push(createExport({
18289
+ name: props["name"],
18290
+ path: props["path"],
18291
+ isTypeOnly: toBool(props["isTypeOnly"]),
18292
+ asAlias: toBool(props["asAlias"])
18293
+ }));
18294
+ return;
18295
+ }
18296
+ if (type === "kubb-import") {
18297
+ imports.push(createImport({
18298
+ name: props["name"],
18299
+ path: props["path"],
18300
+ root: props["root"],
18301
+ isTypeOnly: toBool(props["isTypeOnly"]),
18302
+ isNameSpace: toBool(props["isNameSpace"])
18303
+ }));
18304
+ return;
18305
+ }
18306
+ const nested = collectFileChildren(props["children"]);
18307
+ sources.push(...nested.sources);
18308
+ exports.push(...nested.exports);
18309
+ imports.push(...nested.imports);
18310
+ });
18311
+ return {
18312
+ sources,
18313
+ exports,
18314
+ imports
18315
+ };
18316
+ }
18317
+ function* walkFiles(element) {
18318
+ const files = [];
18319
+ function onHost(type, props) {
18320
+ if (!(type === "kubb-file" && props["baseName"] !== void 0 && props["path"] !== void 0)) {
18321
+ walkElement(props["children"], () => {}, onHost);
18322
+ return;
18323
+ }
18324
+ const { sources, exports, imports } = collectFileChildren(props["children"]);
18325
+ files.push({
18326
+ baseName: props["baseName"],
18327
+ path: props["path"],
18328
+ meta: props["meta"] || {},
18329
+ footer: props["footer"],
18330
+ banner: props["banner"],
18331
+ sources,
18332
+ exports,
18333
+ imports
18334
+ });
18335
+ }
18336
+ walkElement(element, () => {}, onHost);
18337
+ yield* files;
18338
+ }
18339
+ /**
18340
+ * Synchronous JSX renderer that walks the element tree in a single pass,
18341
+ * producing {@link FileNode} objects directly without an intermediate virtual
18342
+ * DOM. No React fiber, scheduler, or work loop is involved.
18343
+ *
18344
+ * All components must be pure functions; hooks and class components are not
18345
+ * supported. Produces identical output to the React-backed {@link Runtime} at
18346
+ * approximately 2–4× the speed and a fraction of the allocations.
18347
+ */
18348
+ var SyncRuntime = class {
18349
+ /**
18350
+ * Accumulated {@link FileNode} results from every {@link render} call.
18351
+ */
18352
+ nodes = [];
18353
+ /**
18354
+ * Walks `element` synchronously, converts every `<kubb-file>` subtree into
18355
+ * a {@link FileNode} with no intermediate virtual DOM, and appends the results
18356
+ * to {@link nodes}.
18357
+ */
18358
+ render(element) {
18359
+ for (const file of walkFiles(element)) this.nodes.push(file);
18360
+ }
18361
+ /**
18362
+ * Walks `element` synchronously and yields each {@link FileNode} as it is
18363
+ * produced, without buffering into an intermediate array first. Callers can
18364
+ * begin processing each file before the rest of the element tree is traversed.
18365
+ *
18366
+ * @example
18367
+ * ```ts
18368
+ * for (const file of runtime.stream(element)) {
18369
+ * await writeFile(file)
18370
+ * }
18371
+ * ```
18372
+ */
18373
+ *stream(element) {
18374
+ yield* walkFiles(element);
18375
+ }
18376
+ };
18377
+ //#endregion
18154
18378
  //#region src/createRenderer.tsx
18155
18379
  /**
18156
- * A renderer factory for generators that produce JSX output.
18380
+ * Renderer factory for generators that produce JSX output.
18157
18381
  *
18158
- * Pass this as the `renderer` property of a `defineGenerator` call so that
18159
- * core can render the JSX element tree returned by your generator methods
18382
+ * Pass as the `renderer` property of `defineGenerator`. Core drives rendering
18160
18383
  * without a hard dependency on `@kubb/renderer-jsx`.
18161
18384
  *
18162
18385
  * @example
18163
18386
  * ```ts
18164
18387
  * import { jsxRenderer } from '@kubb/renderer-jsx'
18165
- * import { defineGenerator } from '@kubb/core'
18166
18388
  *
18167
18389
  * export const myGenerator = defineGenerator<PluginTs>({
18168
- * name: 'my-generator',
18169
18390
  * renderer: jsxRenderer,
18170
18391
  * schema(node, options) {
18171
18392
  * return <File baseName="output.ts" path="src/output.ts">...</File>
@@ -18187,7 +18408,48 @@ const jsxRenderer = () => {
18187
18408
  }
18188
18409
  };
18189
18410
  };
18411
+ /**
18412
+ * Lightweight renderer factory with no React fiber, scheduler, or work loop.
18413
+ *
18414
+ * Walks the JSX element tree in a single recursive pass. All components must be
18415
+ * pure functions; hooks and class components are not supported. Drop-in
18416
+ * replacement for {@link jsxRenderer} at approximately 2–4× the speed.
18417
+ *
18418
+ * @example Drop-in replacement
18419
+ * ```ts
18420
+ * import { jsxRendererSync } from '@kubb/renderer-jsx'
18421
+ *
18422
+ * export const myGenerator = defineGenerator<PluginTs>({
18423
+ * renderer: jsxRendererSync,
18424
+ * schema(node, options) {
18425
+ * return <File baseName="output.ts" path="src/output.ts">...</File>
18426
+ * },
18427
+ * })
18428
+ * ```
18429
+ *
18430
+ * @example Stream files as they are produced
18431
+ * ```ts
18432
+ * for await (const file of jsxRendererSync().stream(element)) {
18433
+ * await writeFile(file)
18434
+ * }
18435
+ * ```
18436
+ */
18437
+ const jsxRendererSync = () => {
18438
+ const runtime = new SyncRuntime();
18439
+ return {
18440
+ async render(element) {
18441
+ runtime.render(element);
18442
+ },
18443
+ get files() {
18444
+ return runtime.nodes;
18445
+ },
18446
+ stream(element) {
18447
+ return runtime.stream(element);
18448
+ },
18449
+ unmount(_error) {}
18450
+ };
18451
+ };
18190
18452
  //#endregion
18191
- export { Const, File, Function$1 as Function, Jsx, Root, Type, createContext, inject, jsxRenderer, provide, unprovide };
18453
+ export { Const, File, Function$1 as Function, Jsx, Root, Type, createContext, inject, jsxRenderer, jsxRendererSync, provide, unprovide };
18192
18454
 
18193
18455
  //# sourceMappingURL=index.js.map