@kubb/react-fabric 0.2.19 → 0.3.1

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 (53) hide show
  1. package/dist/{Fabric-DX0joaWR.d.cts → Fabric-D1uNzkRd.d.cts} +4 -4
  2. package/dist/{Fabric-7g9iQC3E.d.ts → Fabric-OfeFgFB2.d.ts} +4 -4
  3. package/dist/{devtools-CLhxB1Hr.cjs → devtools-BajE-eCd.cjs} +1 -3
  4. package/dist/{devtools-CLhxB1Hr.cjs.map → devtools-BajE-eCd.cjs.map} +1 -1
  5. package/dist/devtools.cjs +1 -1
  6. package/dist/globals.d.cts +2 -2
  7. package/dist/globals.d.ts +2 -2
  8. package/dist/index.cjs +18 -22
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +3 -3
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +16 -17
  13. package/dist/index.js.map +1 -1
  14. package/dist/jsx-dev-runtime.cjs +0 -1
  15. package/dist/jsx-dev-runtime.d.cts +3 -3
  16. package/dist/jsx-dev-runtime.d.ts +3 -3
  17. package/dist/{jsx-namespace-ChOBBWsr.d.ts → jsx-namespace-BEUVmgyn.d.ts} +2 -2
  18. package/dist/{jsx-namespace-BrIMxQyM.d.cts → jsx-namespace-kapEWb5o.d.cts} +2 -2
  19. package/dist/jsx-runtime-BhbaU98p.cjs +2 -0
  20. package/dist/jsx-runtime.cjs +1 -3
  21. package/dist/jsx-runtime.d.cts +3 -3
  22. package/dist/jsx-runtime.d.ts +3 -3
  23. package/dist/parsers.d.cts +1 -2
  24. package/dist/parsers.d.ts +1 -2
  25. package/dist/plugins.cjs +2 -2
  26. package/dist/plugins.d.cts +2 -2
  27. package/dist/plugins.d.ts +2 -2
  28. package/dist/plugins.js +1 -1
  29. package/dist/{reactPlugin-BKFEDZfC.js → reactPlugin-B7zzvM5n.js} +136 -115
  30. package/dist/reactPlugin-B7zzvM5n.js.map +1 -0
  31. package/dist/{reactPlugin-CiFqRD0J.cjs → reactPlugin-B9OmXm5F.cjs} +136 -121
  32. package/dist/reactPlugin-B9OmXm5F.cjs.map +1 -0
  33. package/dist/{reactPlugin-CNdpw8pN.d.ts → reactPlugin-DVGn6gSn.d.ts} +2 -2
  34. package/dist/{reactPlugin-DvAUyVTQ.d.cts → reactPlugin-heqDYGKi.d.cts} +2 -2
  35. package/dist/{types-CGgYj2pZ.d.ts → types-34ycUiHt.d.ts} +3 -3
  36. package/dist/{types-Xd33VuKS.d.cts → types-zrCju594.d.cts} +3 -3
  37. package/dist/types.d.cts +2 -2
  38. package/dist/types.d.ts +2 -2
  39. package/package.json +2 -2
  40. package/src/Runtime.tsx +38 -58
  41. package/src/components/Indent.tsx +3 -3
  42. package/src/composables/useLifecycle.tsx +3 -1
  43. package/src/dom.ts +3 -3
  44. package/src/types.ts +1 -1
  45. package/src/utils/createJSDoc.ts +3 -4
  46. package/src/utils/processFiles.ts +15 -19
  47. package/src/utils/squashExportNodes.ts +21 -11
  48. package/src/utils/squashImportNodes.ts +22 -11
  49. package/src/utils/squashSourceNodes.ts +32 -28
  50. package/src/utils/squashTextNodes.ts +65 -56
  51. package/dist/jsx-runtime-CywUjp4I.cjs +0 -5
  52. package/dist/reactPlugin-BKFEDZfC.js.map +0 -1
  53. package/dist/reactPlugin-CiFqRD0J.cjs.map +0 -1
package/src/Runtime.tsx CHANGED
@@ -24,7 +24,6 @@ type Options = {
24
24
 
25
25
  export class Runtime {
26
26
  readonly #options: Options
27
- // Ignore last render after unmounting a tree to prevent empty output before exit
28
27
  #isUnmounted: boolean
29
28
 
30
29
  exitPromise?: Promise<void>
@@ -33,70 +32,42 @@ export class Runtime {
33
32
 
34
33
  constructor(options: Options) {
35
34
  this.#options = options
36
-
37
35
  this.#rootNode = createNode('kubb-root')
38
36
  this.#rootNode.onRender = this.onRender
39
37
  this.#rootNode.onImmediateRender = this.onRender
40
-
41
- // Ignore last render after unmounting a tree to prevent empty output before exit
42
38
  this.#isUnmounted = false
43
39
  this.unmount.bind(this)
44
40
 
41
+ // Intercept noisy React errors
45
42
  const originalError = console.error
46
43
  console.error = (data: string | Error) => {
47
44
  const message = typeof data === 'string' ? data : data?.message
48
-
49
- if (message?.match(/Encountered two children with the same key/gi)) {
50
- return
51
- }
52
- if (message?.match(/React will try to recreat/gi)) {
53
- return
54
- }
55
- if (message?.match(/Each child in a list should have a unique/gi)) {
45
+ if (
46
+ message?.match(/Encountered two children with the same key/gi) ||
47
+ message?.match(/React will try to recreat/gi) ||
48
+ message?.match(/Each child in a list should have a unique/gi) ||
49
+ message?.match(/The above error occurred in the <KubbErrorBoundary/gi) ||
50
+ message?.match(/A React Element from an older version of React was render/gi)
51
+ ) {
56
52
  return
57
53
  }
58
- if (message?.match(/The above error occurred in the <KubbErrorBoundary/gi)) {
59
- return
60
- }
61
-
62
- if (message?.match(/A React Element from an older version of React was render/gi)) {
63
- return
64
- }
65
-
66
54
  originalError(data)
67
55
  }
68
56
 
69
- // Report when an error was detected in a previous render
70
- // https://github.com/pmndrs/react-three-fiber/pull/2261
71
- const logRecoverableError =
72
- typeof reportError === 'function'
73
- ? // In modern browsers, reportError will dispatch an error event,
74
- // emulating an uncaught JavaScript error.
75
- reportError
76
- : // In older browsers and test environments, fallback to console.error.
77
- console.error
57
+ const logRecoverableError = typeof reportError === 'function' ? reportError : console.error
78
58
 
79
59
  const rootTag = ConcurrentRoot
80
- const hydrationCallbacks = null
81
- const isStrictMode = false
82
- const concurrentUpdatesByDefaultOverride = false
83
- const identifierPrefix = 'id'
84
- const onUncaughtError = logRecoverableError
85
- const onCaughtError = logRecoverableError
86
- const onRecoverableError = logRecoverableError
87
- const transitionCallbacks = null
88
-
89
60
  this.#container = Renderer.createContainer(
90
61
  this.#rootNode,
91
62
  rootTag,
92
- hydrationCallbacks,
93
- isStrictMode,
94
- concurrentUpdatesByDefaultOverride,
95
- identifierPrefix,
96
- onUncaughtError,
97
- onCaughtError,
98
- onRecoverableError,
99
- transitionCallbacks,
63
+ null,
64
+ false,
65
+ false,
66
+ 'id',
67
+ logRecoverableError,
68
+ logRecoverableError,
69
+ logRecoverableError,
70
+ null,
100
71
  )
101
72
 
102
73
  // Unmount when process exits
@@ -108,9 +79,9 @@ export class Runtime {
108
79
  ).bind(this)
109
80
 
110
81
  Renderer.injectIntoDevTools({
111
- bundleType: 1, // 0 for PROD, 1 for DEV
112
- version: '19.1.0', // should be React version and not Kubb's custom version
113
- rendererPackageName: 'kubb', // package name
82
+ bundleType: 1,
83
+ version: '19.1.0',
84
+ rendererPackageName: 'kubb',
114
85
  })
115
86
  }
116
87
 
@@ -122,6 +93,7 @@ export class Runtime {
122
93
  resolveExitPromise: () => void = () => {}
123
94
  rejectExitPromise: (reason?: Error) => void = () => {}
124
95
  unsubscribeExit: () => void = () => {}
96
+
125
97
  onRender: () => Promise<void> = () => {
126
98
  const previous = this.#renderPromise
127
99
 
@@ -143,7 +115,7 @@ export class Runtime {
143
115
  const output = await this.#getOutput(this.#rootNode)
144
116
 
145
117
  if (this.#options?.debug) {
146
- console.log('Rendering: \n')
118
+ console.log('Rendering:\n')
147
119
  console.log(output)
148
120
  }
149
121
 
@@ -161,6 +133,7 @@ export class Runtime {
161
133
 
162
134
  return this.#renderPromise
163
135
  }
136
+
164
137
  onError(error: Error): void {
165
138
  if (process.env.NODE_ENV === 'test') {
166
139
  console.warn(error)
@@ -168,6 +141,7 @@ export class Runtime {
168
141
 
169
142
  throw error
170
143
  }
144
+
171
145
  onExit(error?: Error): void {
172
146
  this.unmount(error)
173
147
  }
@@ -176,12 +150,20 @@ export class Runtime {
176
150
  const text = squashTextNodes(node)
177
151
  const files = this.fileManager.files
178
152
 
179
- return files.length
180
- ? [...files]
181
- .flatMap((file) => [...file.sources].map((item) => item.value))
182
- .filter(Boolean)
183
- .join('\n\n')
184
- : text
153
+ if (!files.length) {
154
+ return text
155
+ }
156
+
157
+ const values = new Set<string>()
158
+ for (const file of files) {
159
+ for (const source of file.sources) {
160
+ if (source?.value) {
161
+ values.add(source.value)
162
+ }
163
+ }
164
+ }
165
+
166
+ return [...values].join('\n\n')
185
167
  }
186
168
 
187
169
  async render(node: ReactNode): Promise<void> {
@@ -207,7 +189,6 @@ export class Runtime {
207
189
  Renderer.flushSyncWork()
208
190
 
209
191
  await this.#renderPromise
210
-
211
192
  this.fileManager.clear()
212
193
 
213
194
  return this.#getOutput(this.#rootNode)
@@ -231,7 +212,6 @@ export class Runtime {
231
212
 
232
213
  if (error instanceof Error) {
233
214
  this.rejectExitPromise(error)
234
-
235
215
  return
236
216
  }
237
217
 
@@ -14,13 +14,13 @@ type IndentProps = {
14
14
  export function Indent({ size = 2, children }: IndentProps) {
15
15
  if (!children) return null
16
16
 
17
- const filtered = React.Children.toArray(children).filter(Boolean)
17
+ const childrenArray = React.Children.toArray(children)
18
18
  const result: React.ReactNode[] = []
19
19
 
20
20
  let prevWasBr = false
21
21
  let brCount = 0
22
22
 
23
- filtered.forEach((child) => {
23
+ for (const child of childrenArray) {
24
24
  if (React.isValidElement(child) && child.type === 'br') {
25
25
  if (!prevWasBr || brCount < 2) {
26
26
  result.push(child)
@@ -32,7 +32,7 @@ export function Indent({ size = 2, children }: IndentProps) {
32
32
  brCount = 0
33
33
  result.push(child)
34
34
  }
35
- })
35
+ }
36
36
 
37
37
  return (
38
38
  <>
@@ -10,7 +10,9 @@ export function useLifecycle() {
10
10
 
11
11
  return {
12
12
  exit: () => {
13
- setTimeout(() => {
13
+ const timeout = setTimeout(() => {
14
+ clearTimeout(timeout)
15
+
14
16
  exit()
15
17
  }, 0)
16
18
  },
package/src/dom.ts CHANGED
@@ -3,7 +3,7 @@ import type { DOMElement, DOMNode, DOMNodeAttribute, ElementNames, TextNode } fr
3
3
  export const createNode = (nodeName: string): DOMElement => {
4
4
  const node: DOMElement = {
5
5
  nodeName: nodeName as DOMElement['nodeName'],
6
- attributes: {},
6
+ attributes: new Map(),
7
7
  childNodes: [],
8
8
  parentNode: undefined,
9
9
  }
@@ -49,7 +49,7 @@ export const removeChildNode = (node: DOMElement, removeNode: DOMNode): void =>
49
49
  }
50
50
 
51
51
  export const setAttribute = (node: DOMElement, key: string, value: DOMNodeAttribute): void => {
52
- node.attributes[key] = value
52
+ node.attributes.set(key, value)
53
53
  }
54
54
 
55
55
  export const createTextNode = (text: string): TextNode => {
@@ -72,4 +72,4 @@ export const setTextNodeValue = (node: TextNode, text: string): void => {
72
72
  node.nodeValue = text
73
73
  }
74
74
 
75
- export const nodeNames: Array<ElementNames> = ['kubb-export', 'kubb-file', 'kubb-source', 'kubb-import', 'kubb-text']
75
+ export const nodeNames = new Set<ElementNames>(['kubb-export', 'kubb-file', 'kubb-source', 'kubb-import', 'kubb-text', 'kubb-root', 'kubb-app', 'br'])
package/src/types.ts CHANGED
@@ -31,7 +31,7 @@ type OutputTransformer = (s: string, index: number) => string
31
31
 
32
32
  export type DOMElement = {
33
33
  nodeName: ElementNames
34
- attributes: Record<string, DOMNodeAttribute>
34
+ attributes: Map<string, DOMNodeAttribute>
35
35
  childNodes: DOMNode[]
36
36
  internal_transform?: OutputTransformer
37
37
 
@@ -1,9 +1,8 @@
1
1
  export function createJSDoc({ comments }: { comments: Array<string> }): string {
2
- const filteredComments = comments.filter(Boolean)
3
-
4
- if (!filteredComments.length) {
2
+ const filtered = comments.filter((c) => c.trim())
3
+ if (!filtered.length) {
5
4
  return ''
6
5
  }
7
6
 
8
- return `/**\n * ${filteredComments.join('\n * ')}\n */`
7
+ return `/**\n * ${filtered.join('\n * ')}\n */`
9
8
  }
@@ -1,6 +1,4 @@
1
1
  import type { KubbFile } from '@kubb/fabric-core/types'
2
- import type React from 'react'
3
- import type { File } from '../components/File.tsx'
4
2
  import { nodeNames } from '../dom.ts'
5
3
  import type { DOMElement } from '../types.ts'
6
4
  import { squashExportNodes } from './squashExportNodes.ts'
@@ -11,31 +9,29 @@ export async function processFiles(node: DOMElement): Promise<Array<KubbFile.Fil
11
9
  const collected: Array<KubbFile.File> = []
12
10
 
13
11
  async function walk(current: DOMElement) {
14
- for (const childNode of current.childNodes) {
15
- if (!childNode) {
12
+ for (const child of current.childNodes) {
13
+ if (!child) {
16
14
  continue
17
15
  }
18
16
 
19
- if (childNode.nodeName !== '#text' && childNode.nodeName !== 'kubb-file' && nodeNames.includes(childNode.nodeName)) {
20
- await walk(childNode)
17
+ if (child.nodeName !== '#text' && child.nodeName !== 'kubb-file' && nodeNames.has(child.nodeName)) {
18
+ await walk(child)
21
19
  }
22
20
 
23
- if (childNode.nodeName === 'kubb-file') {
24
- const attributes = childNode.attributes as React.ComponentProps<typeof File>
25
-
26
- if (attributes.baseName && attributes.path) {
27
- const sources = squashSourceNodes(childNode, ['kubb-export', 'kubb-import'])
21
+ if (child.nodeName === 'kubb-file') {
22
+ if (child.attributes.has('baseName') && child.attributes.has('path')) {
23
+ const sources = squashSourceNodes(child, ['kubb-export', 'kubb-import'])
28
24
 
29
25
  collected.push({
30
- baseName: attributes.baseName,
31
- path: attributes.path,
26
+ baseName: child.attributes.get('baseName'),
27
+ path: child.attributes.get('path'),
28
+ meta: child.attributes.get('meta') || {},
29
+ footer: child.attributes.get('footer'),
30
+ banner: child.attributes.get('banner'),
32
31
  sources: [...sources],
33
- exports: [...squashExportNodes(childNode)],
34
- imports: [...squashImportNodes(childNode)],
35
- meta: attributes.meta || {},
36
- footer: attributes.footer,
37
- banner: attributes.banner,
38
- })
32
+ exports: [...squashExportNodes(child)],
33
+ imports: [...squashImportNodes(child)],
34
+ } as KubbFile.File)
39
35
  }
40
36
  }
41
37
  }
@@ -1,22 +1,32 @@
1
1
  import type { KubbFile } from '@kubb/fabric-core/types'
2
- import type React from 'react'
3
- import type { File } from '../components/File.tsx'
2
+
4
3
  import { nodeNames } from '../dom.ts'
5
4
  import type { DOMElement } from '../types.ts'
6
5
 
7
6
  export function squashExportNodes(node: DOMElement): Set<KubbFile.ResolvedExport> {
8
- let exports = new Set<KubbFile.Export>()
7
+ const exports = new Set<KubbFile.ResolvedExport>()
9
8
 
10
- node.childNodes.filter(Boolean).forEach((childNode) => {
11
- if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
12
- exports = new Set([...exports, ...squashExportNodes(childNode)])
13
- }
9
+ const walk = (current: DOMElement): void => {
10
+ for (const child of current.childNodes) {
11
+ if (!child) {
12
+ continue
13
+ }
14
+
15
+ if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {
16
+ walk(child)
17
+ }
14
18
 
15
- if (childNode.nodeName === 'kubb-export') {
16
- const attributes = childNode.attributes as React.ComponentProps<typeof File.Export>
17
- exports.add(attributes)
19
+ if (child.nodeName === 'kubb-export') {
20
+ exports.add({
21
+ name: child.attributes.get('name'),
22
+ path: child.attributes.get('path'),
23
+ isTypeOnly: child.attributes.get('isTypeOnly') ?? false,
24
+ asAlias: child.attributes.get('asAlias') ?? false,
25
+ } as KubbFile.Export)
26
+ }
18
27
  }
19
- })
28
+ }
20
29
 
30
+ walk(node)
21
31
  return exports
22
32
  }
@@ -1,22 +1,33 @@
1
1
  import type { KubbFile } from '@kubb/fabric-core/types'
2
- import type React from 'react'
3
- import type { File } from '../components/File.tsx'
2
+
4
3
  import { nodeNames } from '../dom.ts'
5
4
  import type { DOMElement } from '../types.ts'
6
5
 
7
6
  export function squashImportNodes(node: DOMElement): Set<KubbFile.Import> {
8
- let imports = new Set<KubbFile.Import>()
7
+ const imports = new Set<KubbFile.Import>()
9
8
 
10
- node.childNodes.filter(Boolean).forEach((childNode) => {
11
- if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
12
- imports = new Set([...imports, ...squashImportNodes(childNode)])
13
- }
9
+ const walk = (current: DOMElement): void => {
10
+ for (const child of current.childNodes) {
11
+ if (!child) {
12
+ continue
13
+ }
14
+
15
+ if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {
16
+ walk(child)
17
+ }
14
18
 
15
- if (childNode.nodeName === 'kubb-import') {
16
- const attributes = childNode.attributes as React.ComponentProps<typeof File.Import>
17
- imports.add(attributes)
19
+ if (child.nodeName === 'kubb-import') {
20
+ imports.add({
21
+ name: child.attributes.get('name'),
22
+ path: child.attributes.get('path'),
23
+ root: child.attributes.get('root'),
24
+ isTypeOnly: child.attributes.get('isTypeOnly') ?? false,
25
+ isNameSpace: child.attributes.get('isNameSpace') ?? false,
26
+ } as KubbFile.Import)
27
+ }
18
28
  }
19
- })
29
+ }
20
30
 
31
+ walk(node)
21
32
  return imports
22
33
  }
@@ -1,39 +1,43 @@
1
1
  import type { KubbFile } from '@kubb/fabric-core/types'
2
- import type React from 'react'
3
- import type { File } from '../components/File.tsx'
2
+
4
3
  import { nodeNames } from '../dom.ts'
5
4
  import type { DOMElement, ElementNames } from '../types.ts'
6
5
  import { squashTextNodes } from './squashTextNodes.ts'
7
6
 
8
7
  export function squashSourceNodes(node: DOMElement, ignores: Array<ElementNames>): Set<KubbFile.Source> {
9
- let sources = new Set<KubbFile.Source>()
10
-
11
- for (const childNode of node.childNodes) {
12
- if (!childNode) {
13
- continue
14
- }
15
-
16
- if (childNode.nodeName !== '#text' && ignores.includes(childNode.nodeName)) {
17
- continue
18
- }
19
-
20
- if (childNode.nodeName === 'kubb-source') {
21
- const attributes = childNode.attributes as React.ComponentProps<typeof File.Source>
22
- const value = squashTextNodes(childNode)
23
-
24
- sources.add({
25
- ...attributes,
26
- // remove end enter
27
- value: value.trim().replace(/^\s+|\s+$/g, ''),
28
- })
29
-
30
- continue
31
- }
32
-
33
- if (childNode.nodeName !== '#text' && nodeNames.includes(childNode.nodeName)) {
34
- sources = new Set([...sources, ...squashSourceNodes(childNode, ignores)])
8
+ const ignoreSet = new Set(ignores)
9
+ const sources = new Set<KubbFile.Source>()
10
+
11
+ const walk = (current: DOMElement): void => {
12
+ for (const child of current.childNodes) {
13
+ if (!child) {
14
+ continue
15
+ }
16
+
17
+ if (child.nodeName !== '#text' && ignoreSet.has(child.nodeName)) {
18
+ continue
19
+ }
20
+
21
+ if (child.nodeName === 'kubb-source') {
22
+ const value = squashTextNodes(child)
23
+
24
+ sources.add({
25
+ name: child.attributes.get('name'),
26
+ isTypeOnly: child.attributes.get('isTypeOnly') ?? false,
27
+ isExportable: child.attributes.get('isExportable') ?? false,
28
+ isIndexable: child.attributes.get('isIndexable') ?? false,
29
+ // trim whitespace/newlines
30
+ value: value.trim().replace(/^\s+|\s+$/g, ''),
31
+ } as KubbFile.Source)
32
+ continue
33
+ }
34
+
35
+ if (child.nodeName !== '#text' && nodeNames.has(child.nodeName)) {
36
+ walk(child)
37
+ }
35
38
  }
36
39
  }
37
40
 
41
+ walk(node)
38
42
  return sources
39
43
  }
@@ -1,82 +1,91 @@
1
1
  import { createExport, createImport, print } from '@kubb/fabric-core/parsers/typescript'
2
2
 
3
- import type { File } from '../components/File.tsx'
4
3
  import { nodeNames } from '../dom.ts'
5
- import type { DOMElement } from '../types.ts'
4
+ import type { DOMElement, KubbFile } from '../types.ts'
6
5
 
7
6
  export function squashTextNodes(node: DOMElement): string {
8
7
  let text = ''
9
8
 
10
- for (const childNode of node.childNodes) {
11
- if (!childNode) {
12
- continue
13
- }
14
-
15
- let nodeText = ''
9
+ const walk = (current: DOMElement): string => {
10
+ let content = ''
16
11
 
17
- const getPrintText = (text: string): string => {
18
- if (childNode.nodeName === 'kubb-import') {
19
- const attributes = childNode.attributes as React.ComponentProps<typeof File.Import>
20
-
21
- return print([
22
- createImport({
23
- name: attributes.name,
24
- path: attributes.path,
25
- root: attributes.root,
26
- isTypeOnly: attributes.isTypeOnly,
27
- }),
28
- ])
12
+ for (const child of current.childNodes) {
13
+ if (!child) {
14
+ continue
29
15
  }
30
16
 
31
- if (childNode.nodeName === 'kubb-export') {
32
- const attributes = childNode.attributes as React.ComponentProps<typeof File.Export>
33
- if (attributes.path) {
34
- return print([
35
- createExport({
36
- name: attributes.name,
37
- path: attributes.path,
38
- isTypeOnly: attributes.isTypeOnly,
39
- asAlias: attributes.asAlias,
40
- }),
41
- ])
17
+ let nodeText = ''
18
+
19
+ const getPrintText = (text: string): string => {
20
+ switch (child.nodeName) {
21
+ case 'kubb-import': {
22
+ return print(
23
+ createImport({
24
+ name: child.attributes.get('name'),
25
+ path: child.attributes.get('path'),
26
+ root: child.attributes.get('root'),
27
+ isTypeOnly: child.attributes.get('isTypeOnly'),
28
+ isNameSpace: child.attributes.get('isNameSpace'),
29
+ } as KubbFile.Import),
30
+ )
31
+ }
32
+ case 'kubb-export': {
33
+ if (child.attributes.has('path')) {
34
+ return print(
35
+ createExport({
36
+ name: child.attributes.get('name'),
37
+ path: child.attributes.get('path'),
38
+ isTypeOnly: child.attributes.get('isTypeOnly'),
39
+ asAlias: child.attributes.get('asAlias'),
40
+ } as KubbFile.Export),
41
+ )
42
+ }
43
+ return ''
44
+ }
45
+ case 'kubb-source':
46
+ return text
47
+ default:
48
+ return text
42
49
  }
43
50
  }
44
51
 
45
- if (childNode.nodeName === 'kubb-source') {
46
- return text
47
- }
48
-
49
- return text
50
- }
52
+ if (child.nodeName === '#text') {
53
+ nodeText = child.nodeValue
54
+ } else {
55
+ if (child.nodeName === 'kubb-text' || child.nodeName === 'kubb-file' || child.nodeName === 'kubb-source') {
56
+ nodeText = walk(child)
57
+ }
51
58
 
52
- if (childNode.nodeName === '#text') {
53
- nodeText = childNode.nodeValue
54
- } else {
55
- if (['kubb-text', 'kubb-file', 'kubb-source'].includes(childNode.nodeName)) {
56
- nodeText = squashTextNodes(childNode)
57
- }
59
+ nodeText = getPrintText(nodeText)
58
60
 
59
- nodeText = getPrintText(nodeText)
61
+ if (child.nodeName === 'br') {
62
+ nodeText = '\n'
63
+ }
60
64
 
61
- if (childNode.nodeName === 'br') {
62
- nodeText = '\n'
63
- }
65
+ if (!nodeNames.has(child.nodeName)) {
66
+ const attributes = child.attributes
67
+ let attrString = ''
68
+ const hasAttributes = attributes.size > 0
64
69
 
65
- // no kubb element or br
66
- if (![...nodeNames, 'br'].includes(childNode.nodeName)) {
67
- const attributes = Object.entries(childNode.attributes).reduce((acc, [key, value]) => {
68
- if (typeof value === 'string') {
69
- return `${acc} ${key}="${value}"`
70
+ for (const [key, value] of attributes) {
71
+ attrString += typeof value === 'string' ? ` ${key}="${value}"` : ` ${key}={${String(value)}}`
70
72
  }
71
73
 
72
- return `${acc} ${key}={${value}}`
73
- }, '')
74
- nodeText = `<${childNode.nodeName}${attributes}>${squashTextNodes(childNode)}</${childNode.nodeName}>`
74
+ if (hasAttributes) {
75
+ nodeText = `<${child.nodeName}${attrString}>${walk(child)}</${child.nodeName}>`
76
+ } else {
77
+ nodeText = `<${child.nodeName}>${walk(child)}</${child.nodeName}>`
78
+ }
79
+ }
75
80
  }
81
+
82
+ content += nodeText
76
83
  }
77
84
 
78
- text += nodeText
85
+ return content
79
86
  }
80
87
 
88
+ text = walk(node)
89
+
81
90
  return text
82
91
  }
@@ -1,5 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- let react_jsx_dev_runtime = require("react/jsx-dev-runtime");
3
- react_jsx_dev_runtime = require_chunk.__toESM(react_jsx_dev_runtime);
4
- let react_jsx_runtime = require("react/jsx-runtime");
5
- react_jsx_runtime = require_chunk.__toESM(react_jsx_runtime);