@mun-ui/react 0.0.0-stage → 0.2.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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/dist/advanced.d.ts +7 -0
  3. package/dist/advanced.d.ts.map +1 -0
  4. package/dist/advanced.js +6 -0
  5. package/dist/advanced.js.map +1 -0
  6. package/dist/continuous-corners.d.ts +4 -0
  7. package/dist/continuous-corners.d.ts.map +1 -0
  8. package/dist/continuous-corners.js +54 -0
  9. package/dist/continuous-corners.js.map +1 -0
  10. package/dist/controls.d.ts +7 -0
  11. package/dist/controls.d.ts.map +1 -0
  12. package/dist/controls.js +6 -0
  13. package/dist/controls.js.map +1 -0
  14. package/dist/index.d.ts +12 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +8 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/interop.d.ts +23 -0
  19. package/dist/interop.d.ts.map +1 -0
  20. package/dist/interop.js +75 -0
  21. package/dist/interop.js.map +1 -0
  22. package/dist/legacy/builder.d.ts +6 -0
  23. package/dist/legacy/builder.d.ts.map +1 -0
  24. package/dist/legacy/builder.js +13 -0
  25. package/dist/legacy/builder.js.map +1 -0
  26. package/dist/legacy/closures.d.ts +3 -0
  27. package/dist/legacy/closures.d.ts.map +1 -0
  28. package/dist/legacy/closures.js +3 -0
  29. package/dist/legacy/closures.js.map +1 -0
  30. package/dist/legacy/collections.d.ts +53 -0
  31. package/dist/legacy/collections.d.ts.map +1 -0
  32. package/dist/legacy/collections.js +154 -0
  33. package/dist/legacy/collections.js.map +1 -0
  34. package/dist/legacy/compiler/ast.d.ts +84 -0
  35. package/dist/legacy/compiler/ast.d.ts.map +1 -0
  36. package/dist/legacy/compiler/ast.js +697 -0
  37. package/dist/legacy/compiler/ast.js.map +1 -0
  38. package/dist/legacy/compiler/builder-transform.d.ts +2 -0
  39. package/dist/legacy/compiler/builder-transform.d.ts.map +1 -0
  40. package/dist/legacy/compiler/builder-transform.js +422 -0
  41. package/dist/legacy/compiler/builder-transform.js.map +1 -0
  42. package/dist/legacy/compiler/errors.d.ts +5 -0
  43. package/dist/legacy/compiler/errors.d.ts.map +1 -0
  44. package/dist/legacy/compiler/errors.js +7 -0
  45. package/dist/legacy/compiler/errors.js.map +1 -0
  46. package/dist/legacy/compiler/index.d.ts +15 -0
  47. package/dist/legacy/compiler/index.d.ts.map +1 -0
  48. package/dist/legacy/compiler/index.js +10 -0
  49. package/dist/legacy/compiler/index.js.map +1 -0
  50. package/dist/legacy/compiler/language-service.d.ts +26 -0
  51. package/dist/legacy/compiler/language-service.d.ts.map +1 -0
  52. package/dist/legacy/compiler/language-service.js +35 -0
  53. package/dist/legacy/compiler/language-service.js.map +1 -0
  54. package/dist/legacy/compiler/language-tools.d.ts +12 -0
  55. package/dist/legacy/compiler/language-tools.d.ts.map +1 -0
  56. package/dist/legacy/compiler/language-tools.js +44 -0
  57. package/dist/legacy/compiler/language-tools.js.map +1 -0
  58. package/dist/legacy/compiler/source-map.d.ts +36 -0
  59. package/dist/legacy/compiler/source-map.d.ts.map +1 -0
  60. package/dist/legacy/compiler/source-map.js +188 -0
  61. package/dist/legacy/compiler/source-map.js.map +1 -0
  62. package/dist/legacy/compiler/struct-transform.d.ts +18 -0
  63. package/dist/legacy/compiler/struct-transform.d.ts.map +1 -0
  64. package/dist/legacy/compiler/struct-transform.js +268 -0
  65. package/dist/legacy/compiler/struct-transform.js.map +1 -0
  66. package/dist/legacy/compiler/swc-transform.d.ts +7 -0
  67. package/dist/legacy/compiler/swc-transform.d.ts.map +1 -0
  68. package/dist/legacy/compiler/swc-transform.js +33 -0
  69. package/dist/legacy/compiler/swc-transform.js.map +1 -0
  70. package/dist/legacy/compiler/typescript-language-service.d.ts +12 -0
  71. package/dist/legacy/compiler/typescript-language-service.d.ts.map +1 -0
  72. package/dist/legacy/compiler/typescript-language-service.js +185 -0
  73. package/dist/legacy/compiler/typescript-language-service.js.map +1 -0
  74. package/dist/legacy/compiler/vite-builder.d.ts +11 -0
  75. package/dist/legacy/compiler/vite-builder.d.ts.map +1 -0
  76. package/dist/legacy/compiler/vite-builder.js +40 -0
  77. package/dist/legacy/compiler/vite-builder.js.map +1 -0
  78. package/dist/legacy/controls.d.ts +59 -0
  79. package/dist/legacy/controls.d.ts.map +1 -0
  80. package/dist/legacy/controls.js +119 -0
  81. package/dist/legacy/controls.js.map +1 -0
  82. package/dist/legacy/coordinate.d.ts +17 -0
  83. package/dist/legacy/coordinate.d.ts.map +1 -0
  84. package/dist/legacy/coordinate.js +17 -0
  85. package/dist/legacy/coordinate.js.map +1 -0
  86. package/dist/legacy/elements.d.ts +98 -0
  87. package/dist/legacy/elements.d.ts.map +1 -0
  88. package/dist/legacy/elements.js +367 -0
  89. package/dist/legacy/elements.js.map +1 -0
  90. package/dist/legacy/experimental.d.ts +19 -0
  91. package/dist/legacy/experimental.d.ts.map +1 -0
  92. package/dist/legacy/experimental.js +16 -0
  93. package/dist/legacy/experimental.js.map +1 -0
  94. package/dist/legacy/index.d.ts +27 -0
  95. package/dist/legacy/index.d.ts.map +1 -0
  96. package/dist/legacy/index.js +13 -0
  97. package/dist/legacy/index.js.map +1 -0
  98. package/dist/legacy/jsx-dev-runtime.d.ts +3 -0
  99. package/dist/legacy/jsx-dev-runtime.d.ts.map +1 -0
  100. package/dist/legacy/jsx-dev-runtime.js +2 -0
  101. package/dist/legacy/jsx-dev-runtime.js.map +1 -0
  102. package/dist/legacy/jsx-runtime.d.ts +61 -0
  103. package/dist/legacy/jsx-runtime.d.ts.map +1 -0
  104. package/dist/legacy/jsx-runtime.js +56 -0
  105. package/dist/legacy/jsx-runtime.js.map +1 -0
  106. package/dist/legacy/layout-engine.d.ts +15 -0
  107. package/dist/legacy/layout-engine.d.ts.map +1 -0
  108. package/dist/legacy/layout-engine.js +11 -0
  109. package/dist/legacy/layout-engine.js.map +1 -0
  110. package/dist/legacy/layout.d.ts +19 -0
  111. package/dist/legacy/layout.d.ts.map +1 -0
  112. package/dist/legacy/layout.js +102 -0
  113. package/dist/legacy/layout.js.map +1 -0
  114. package/dist/legacy/modifiers.d.ts +12 -0
  115. package/dist/legacy/modifiers.d.ts.map +1 -0
  116. package/dist/legacy/modifiers.js +242 -0
  117. package/dist/legacy/modifiers.js.map +1 -0
  118. package/dist/legacy/presentation.d.ts +40 -0
  119. package/dist/legacy/presentation.d.ts.map +1 -0
  120. package/dist/legacy/presentation.js +449 -0
  121. package/dist/legacy/presentation.js.map +1 -0
  122. package/dist/legacy/react-types.d.ts +9 -0
  123. package/dist/legacy/react-types.d.ts.map +1 -0
  124. package/dist/legacy/react-types.js +2 -0
  125. package/dist/legacy/react-types.js.map +1 -0
  126. package/dist/legacy/runtime/arrays.d.ts +5 -0
  127. package/dist/legacy/runtime/arrays.d.ts.map +1 -0
  128. package/dist/legacy/runtime/arrays.js +27 -0
  129. package/dist/legacy/runtime/arrays.js.map +1 -0
  130. package/dist/legacy/runtime/coordinate-runtime.d.ts +10 -0
  131. package/dist/legacy/runtime/coordinate-runtime.d.ts.map +1 -0
  132. package/dist/legacy/runtime/coordinate-runtime.js +7 -0
  133. package/dist/legacy/runtime/coordinate-runtime.js.map +1 -0
  134. package/dist/legacy/runtime/jsx-node.d.ts +9 -0
  135. package/dist/legacy/runtime/jsx-node.d.ts.map +1 -0
  136. package/dist/legacy/runtime/jsx-node.js +10 -0
  137. package/dist/legacy/runtime/jsx-node.js.map +1 -0
  138. package/dist/legacy/runtime/layout-observer.d.ts +4 -0
  139. package/dist/legacy/runtime/layout-observer.d.ts.map +1 -0
  140. package/dist/legacy/runtime/layout-observer.js +22 -0
  141. package/dist/legacy/runtime/layout-observer.js.map +1 -0
  142. package/dist/legacy/runtime/modifier-pipeline.d.ts +10 -0
  143. package/dist/legacy/runtime/modifier-pipeline.d.ts.map +1 -0
  144. package/dist/legacy/runtime/modifier-pipeline.js +17 -0
  145. package/dist/legacy/runtime/modifier-pipeline.js.map +1 -0
  146. package/dist/legacy/runtime/renderer.d.ts +24 -0
  147. package/dist/legacy/runtime/renderer.d.ts.map +1 -0
  148. package/dist/legacy/runtime/renderer.js +94 -0
  149. package/dist/legacy/runtime/renderer.js.map +1 -0
  150. package/dist/legacy/runtime/view-graph.d.ts +22 -0
  151. package/dist/legacy/runtime/view-graph.d.ts.map +1 -0
  152. package/dist/legacy/runtime/view-graph.js +70 -0
  153. package/dist/legacy/runtime/view-graph.js.map +1 -0
  154. package/dist/legacy/runtime/view-storage.d.ts +14 -0
  155. package/dist/legacy/runtime/view-storage.d.ts.map +1 -0
  156. package/dist/legacy/runtime/view-storage.js +15 -0
  157. package/dist/legacy/runtime/view-storage.js.map +1 -0
  158. package/dist/legacy/state.d.ts +8 -0
  159. package/dist/legacy/state.d.ts.map +1 -0
  160. package/dist/legacy/state.js +23 -0
  161. package/dist/legacy/state.js.map +1 -0
  162. package/dist/legacy/types.d.ts +111 -0
  163. package/dist/legacy/types.d.ts.map +1 -0
  164. package/dist/legacy/types.js +2 -0
  165. package/dist/legacy/types.js.map +1 -0
  166. package/dist/legacy/view-system.d.ts +111 -0
  167. package/dist/legacy/view-system.d.ts.map +1 -0
  168. package/dist/legacy/view-system.js +421 -0
  169. package/dist/legacy/view-system.js.map +1 -0
  170. package/dist/legacy/view.d.ts +15 -0
  171. package/dist/legacy/view.d.ts.map +1 -0
  172. package/dist/legacy/view.js +30 -0
  173. package/dist/legacy/view.js.map +1 -0
  174. package/dist/legacy/vite.d.ts +32 -0
  175. package/dist/legacy/vite.d.ts.map +1 -0
  176. package/dist/legacy/vite.js +540 -0
  177. package/dist/legacy/vite.js.map +1 -0
  178. package/dist/presentation.d.ts +7 -0
  179. package/dist/presentation.d.ts.map +1 -0
  180. package/dist/presentation.js +6 -0
  181. package/dist/presentation.js.map +1 -0
  182. package/dist/renderer.d.ts +34 -0
  183. package/dist/renderer.d.ts.map +1 -0
  184. package/dist/renderer.js +1513 -0
  185. package/dist/renderer.js.map +1 -0
  186. package/dist/views.d.ts +7 -0
  187. package/dist/views.d.ts.map +1 -0
  188. package/dist/views.js +6 -0
  189. package/dist/views.js.map +1 -0
  190. package/package.json +79 -3
  191. package/README.md +0 -3
@@ -0,0 +1,697 @@
1
+ import { munSyntaxError } from './errors.js';
2
+ const closeFor = {
3
+ '(': ')',
4
+ '{': '}',
5
+ '[': ']',
6
+ };
7
+ function isIdentifierStart(char) {
8
+ return !!char && /[A-Za-z_$]/.test(char);
9
+ }
10
+ function isIdentifierPart(char) {
11
+ return !!char && /[A-Za-z0-9_$]/.test(char);
12
+ }
13
+ function skipQuoted(source, index, quote) {
14
+ for (let i = index + 1; i < source.length; i += 1) {
15
+ if (source[i] === '\\') {
16
+ i += 1;
17
+ continue;
18
+ }
19
+ if (source[i] === quote)
20
+ return i + 1;
21
+ }
22
+ throw munSyntaxError(`Unclosed ${quote} string in Mun AST`, index);
23
+ }
24
+ function skipTemplate(source, index) {
25
+ for (let i = index + 1; i < source.length; i += 1) {
26
+ if (source[i] === '\\') {
27
+ i += 1;
28
+ continue;
29
+ }
30
+ if (source[i] === '`')
31
+ return i + 1;
32
+ if (source[i] === '$' && source[i + 1] === '{') {
33
+ i = findMatching(source, i + 1, '{');
34
+ }
35
+ }
36
+ throw munSyntaxError('Unclosed template literal in Mun AST', index);
37
+ }
38
+ function previousSignificant(source, index) {
39
+ for (let i = index - 1; i >= 0; i -= 1) {
40
+ if (!/\s/.test(source[i]))
41
+ return source[i];
42
+ }
43
+ return undefined;
44
+ }
45
+ function regexCanStartAfter(source, index) {
46
+ const previous = previousSignificant(source, index);
47
+ if (previous === undefined || '([{=,:;!?&|+-*%^~<>'.includes(previous))
48
+ return true;
49
+ let end = index;
50
+ while (end > 0 && /\s/.test(source[end - 1]))
51
+ end -= 1;
52
+ let start = end;
53
+ while (start > 0 && isIdentifierPart(source[start - 1]))
54
+ start -= 1;
55
+ return ['case', 'delete', 'do', 'else', 'in', 'instanceof', 'of', 'return', 'throw', 'typeof', 'void', 'yield']
56
+ .includes(source.slice(start, end));
57
+ }
58
+ function skipRegex(source, index) {
59
+ let inClass = false;
60
+ for (let i = index + 1; i < source.length; i += 1) {
61
+ const char = source[i];
62
+ if (char === '\\') {
63
+ i += 1;
64
+ continue;
65
+ }
66
+ if (char === '[')
67
+ inClass = true;
68
+ if (char === ']')
69
+ inClass = false;
70
+ if (char === '/' && !inClass) {
71
+ i += 1;
72
+ while (/[A-Za-z]/.test(source[i] ?? ''))
73
+ i += 1;
74
+ return i;
75
+ }
76
+ if (char === '\n' || char === '\r')
77
+ break;
78
+ }
79
+ return index + 1;
80
+ }
81
+ function skipTrivia(source, index) {
82
+ let i = index;
83
+ while (i < source.length && /\s/.test(source[i]))
84
+ i += 1;
85
+ return i;
86
+ }
87
+ function findMatching(source, openIndex, open) {
88
+ const close = closeFor[open];
89
+ let depth = 0;
90
+ for (let i = openIndex; i < source.length; i += 1) {
91
+ const char = source[i];
92
+ const next = source[i + 1];
93
+ if (char === "'" || char === '"') {
94
+ i = skipQuoted(source, i, char) - 1;
95
+ continue;
96
+ }
97
+ if (char === '`') {
98
+ i = skipTemplate(source, i) - 1;
99
+ continue;
100
+ }
101
+ if (char === '/' && next === '/') {
102
+ const end = source.indexOf('\n', i + 2);
103
+ i = (end < 0 ? source.length : end) - 1;
104
+ continue;
105
+ }
106
+ if (char === '/' && next === '*') {
107
+ const end = source.indexOf('*/', i + 2);
108
+ if (end < 0)
109
+ throw munSyntaxError('Unclosed block comment in Mun AST', i);
110
+ i = end + 1;
111
+ continue;
112
+ }
113
+ if (char === '/' && regexCanStartAfter(source, i)) {
114
+ i = skipRegex(source, i) - 1;
115
+ continue;
116
+ }
117
+ if (char === open)
118
+ depth += 1;
119
+ if (char === close && --depth === 0)
120
+ return i;
121
+ }
122
+ throw munSyntaxError(`Unclosed ${open} block in Mun AST`, openIndex);
123
+ }
124
+ function nextWord(source, index) {
125
+ const start = skipTrivia(source, index);
126
+ const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(start));
127
+ return match?.[0];
128
+ }
129
+ function lineBreakIsBoundary(source, index) {
130
+ const previous = previousSignificant(source, index);
131
+ const nextIndex = skipTrivia(source, index + 1);
132
+ const next = source[nextIndex];
133
+ if (previous === undefined || next === undefined)
134
+ return true;
135
+ if (nextWord(source, index + 1) === 'else')
136
+ return false;
137
+ if (',([{.=:+-*/%!&|?<>'.includes(previous))
138
+ return false;
139
+ if ('.),]}:;'.includes(next))
140
+ return false;
141
+ return true;
142
+ }
143
+ function splitTopLevel(source, separators, baseOffset) {
144
+ const parts = [];
145
+ let start = 0;
146
+ let parens = 0;
147
+ let brackets = 0;
148
+ let braces = 0;
149
+ for (let i = 0; i < source.length; i += 1) {
150
+ const char = source[i];
151
+ const next = source[i + 1];
152
+ if (char === "'" || char === '"') {
153
+ i = skipQuoted(source, i, char) - 1;
154
+ continue;
155
+ }
156
+ if (char === '`') {
157
+ i = skipTemplate(source, i) - 1;
158
+ continue;
159
+ }
160
+ if (char === '/' && next === '/') {
161
+ const end = source.indexOf('\n', i + 2);
162
+ i = (end < 0 ? source.length : end) - 1;
163
+ continue;
164
+ }
165
+ if (char === '/' && next === '*') {
166
+ const end = source.indexOf('*/', i + 2);
167
+ if (end < 0)
168
+ throw munSyntaxError('Unclosed block comment in Mun AST', i);
169
+ i = end + 1;
170
+ continue;
171
+ }
172
+ if (char === '/' && regexCanStartAfter(source, i)) {
173
+ i = skipRegex(source, i) - 1;
174
+ continue;
175
+ }
176
+ if (char === '(')
177
+ parens += 1;
178
+ else if (char === ')')
179
+ parens -= 1;
180
+ else if (char === '[')
181
+ brackets += 1;
182
+ else if (char === ']')
183
+ brackets -= 1;
184
+ else if (char === '{')
185
+ braces += 1;
186
+ else if (char === '}')
187
+ braces -= 1;
188
+ const topLevel = parens === 0 && brackets === 0 && braces === 0;
189
+ if (topLevel && separators.includes(char)) {
190
+ parts.push({ source: source.slice(start, i), start: baseOffset + start, end: baseOffset + i });
191
+ start = i + 1;
192
+ continue;
193
+ }
194
+ if (topLevel && char === '\n' && lineBreakIsBoundary(source, i)) {
195
+ parts.push({ source: source.slice(start, i), start: baseOffset + start, end: baseOffset + i });
196
+ start = i + 1;
197
+ }
198
+ }
199
+ parts.push({ source: source.slice(start), start: baseOffset + start, end: baseOffset + source.length });
200
+ return parts.filter(part => part.source.trim().length > 0);
201
+ }
202
+ function trimSlice(slice) {
203
+ const leading = slice.source.search(/\S|$/);
204
+ const trimmed = slice.source.trimEnd();
205
+ return {
206
+ source: trimmed.slice(leading),
207
+ start: slice.start + leading,
208
+ end: slice.start + leading + trimmed.slice(leading).length,
209
+ };
210
+ }
211
+ function raw(slice) {
212
+ const value = trimSlice(slice);
213
+ return { kind: 'raw', source: value.source, range: { start: value.start, end: value.end } };
214
+ }
215
+ function parseClosure(slice) {
216
+ const value = trimSlice(slice);
217
+ if (value.source[0] !== '{')
218
+ return undefined;
219
+ const close = findMatching(value.source, 0, '{');
220
+ if (close !== value.source.length - 1)
221
+ return undefined;
222
+ const inner = value.source.slice(1, close);
223
+ const innerOffset = value.start + 1;
224
+ const parameterMatch = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\s+in\s+([\s\S]*)$/.exec(inner);
225
+ const bodySource = parameterMatch?.[2] ?? inner;
226
+ const bodyOffset = parameterMatch ? innerOffset + (parameterMatch[0].length - parameterMatch[2].length) : innerOffset;
227
+ return {
228
+ kind: 'closure',
229
+ parameter: parameterMatch?.[1],
230
+ bodySource,
231
+ body: parseMunBuilder(bodySource, bodyOffset),
232
+ range: { start: value.start, end: value.end },
233
+ };
234
+ }
235
+ function topLevelColon(source) {
236
+ let parens = 0;
237
+ let brackets = 0;
238
+ let braces = 0;
239
+ for (let i = 0; i < source.length; i += 1) {
240
+ const char = source[i];
241
+ const next = source[i + 1];
242
+ if (char === "'" || char === '"') {
243
+ i = skipQuoted(source, i, char) - 1;
244
+ continue;
245
+ }
246
+ if (char === '`') {
247
+ i = skipTemplate(source, i) - 1;
248
+ continue;
249
+ }
250
+ if (char === '/' && next === '/') {
251
+ const end = source.indexOf('\n', i + 2);
252
+ i = (end < 0 ? source.length : end) - 1;
253
+ continue;
254
+ }
255
+ if (char === '/' && next === '*') {
256
+ const end = source.indexOf('*/', i + 2);
257
+ if (end < 0)
258
+ return -1;
259
+ i = end + 1;
260
+ continue;
261
+ }
262
+ if (char === '(')
263
+ parens += 1;
264
+ else if (char === ')')
265
+ parens -= 1;
266
+ else if (char === '[')
267
+ brackets += 1;
268
+ else if (char === ']')
269
+ brackets -= 1;
270
+ else if (char === '{')
271
+ braces += 1;
272
+ else if (char === '}')
273
+ braces -= 1;
274
+ else if (char === ':' && parens === 0 && brackets === 0 && braces === 0)
275
+ return i;
276
+ }
277
+ return -1;
278
+ }
279
+ function parseArgument(slice) {
280
+ const value = trimSlice(slice);
281
+ const colon = topLevelColon(value.source);
282
+ const label = colon < 0 ? undefined : value.source.slice(0, colon).trim();
283
+ if (label && !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(label))
284
+ return { value: raw(value), range: { start: value.start, end: value.end } };
285
+ const valueStart = colon < 0 ? value.start : value.start + colon + 1;
286
+ const valueSlice = { source: colon < 0 ? value.source : value.source.slice(colon + 1), start: valueStart, end: value.end };
287
+ const closure = label ? parseClosure(valueSlice) : undefined;
288
+ return {
289
+ label,
290
+ value: closure ?? raw(valueSlice),
291
+ range: { start: value.start, end: value.end },
292
+ };
293
+ }
294
+ function parseCall(slice) {
295
+ const value = trimSlice(slice);
296
+ const identifier = /^([A-Za-z_$][A-Za-z0-9_$]*)/.exec(value.source);
297
+ if (!identifier)
298
+ return undefined;
299
+ const open = skipTrivia(value.source, identifier[0].length);
300
+ if (value.source[open] !== '(')
301
+ return undefined;
302
+ const close = findMatching(value.source, open, '(');
303
+ const afterClose = skipTrivia(value.source, close + 1);
304
+ let trailing;
305
+ let end = close + 1;
306
+ if (value.source[afterClose] === '{') {
307
+ const blockClose = findMatching(value.source, afterClose, '{');
308
+ if (skipTrivia(value.source, blockClose + 1) !== value.source.length)
309
+ return undefined;
310
+ trailing = parseClosure({ source: value.source.slice(afterClose, blockClose + 1), start: value.start + afterClose, end: value.start + blockClose + 1 });
311
+ end = blockClose + 1;
312
+ }
313
+ if (skipTrivia(value.source, end) !== value.source.length)
314
+ return undefined;
315
+ const argsSource = value.source.slice(open + 1, close);
316
+ const argsOffset = value.start + open + 1;
317
+ return {
318
+ kind: 'call',
319
+ callee: identifier[1],
320
+ arguments: splitTopLevel(argsSource, ',', argsOffset).map(parseArgument),
321
+ trailing,
322
+ range: { start: value.start, end: value.end },
323
+ };
324
+ }
325
+ function parseConditional(slice) {
326
+ const value = trimSlice(slice);
327
+ if (!/^if\b/.test(value.source))
328
+ return undefined;
329
+ const open = value.source.indexOf('(');
330
+ if (open < 0)
331
+ return undefined;
332
+ const close = findMatching(value.source, open, '(');
333
+ const thenOpen = skipTrivia(value.source, close + 1);
334
+ if (value.source[thenOpen] !== '{')
335
+ return undefined;
336
+ const thenClose = findMatching(value.source, thenOpen, '{');
337
+ const afterThen = skipTrivia(value.source, thenClose + 1);
338
+ const conditionSlice = { source: value.source.slice(open + 1, close), start: value.start + open + 1, end: value.start + close };
339
+ const thenSource = value.source.slice(thenOpen + 1, thenClose);
340
+ const thenOffset = value.start + thenOpen + 1;
341
+ let otherwise;
342
+ let end = thenClose + 1;
343
+ if (value.source.slice(afterThen, afterThen + 4) === 'else') {
344
+ const elseStart = skipTrivia(value.source, afterThen + 4);
345
+ const rest = { source: value.source.slice(elseStart), start: value.start + elseStart, end: value.end };
346
+ otherwise = /^if\b/.test(rest.source) ? parseConditional(rest) : undefined;
347
+ if (!otherwise && rest.source[0] === '{') {
348
+ const elseClose = findMatching(rest.source, 0, '{');
349
+ if (skipTrivia(rest.source, elseClose + 1) !== rest.source.length)
350
+ return undefined;
351
+ otherwise = parseMunBuilder(rest.source.slice(1, elseClose), rest.start + 1);
352
+ end = elseStart + elseClose + 1;
353
+ }
354
+ else if (otherwise) {
355
+ end = otherwise.range.end - value.start;
356
+ }
357
+ }
358
+ if (skipTrivia(value.source, end) !== value.source.length)
359
+ return undefined;
360
+ return {
361
+ kind: 'conditional',
362
+ condition: raw(conditionSlice),
363
+ then: parseMunBuilder(thenSource, thenOffset),
364
+ otherwise,
365
+ range: { start: value.start, end: value.end },
366
+ };
367
+ }
368
+ function parseNode(slice) {
369
+ return parseConditional(slice) ?? parseCall(slice) ?? raw(slice);
370
+ }
371
+ /** Keep a top-level line comment from swallowing the comma synthesized by lowering. */
372
+ function protectLineComment(source) {
373
+ let parens = 0;
374
+ let brackets = 0;
375
+ let braces = 0;
376
+ for (let i = 0; i < source.length; i += 1) {
377
+ const char = source[i];
378
+ const next = source[i + 1];
379
+ if (char === "'" || char === '"') {
380
+ i = skipQuoted(source, i, char) - 1;
381
+ continue;
382
+ }
383
+ if (char === '`') {
384
+ i = skipTemplate(source, i) - 1;
385
+ continue;
386
+ }
387
+ if (char === '/' && next === '/' && parens === 0 && brackets === 0 && braces === 0) {
388
+ if (!source.slice(0, i).trim())
389
+ return '';
390
+ return `${source.slice(0, i)}/*${source.slice(i + 2)}*/`;
391
+ }
392
+ if (char === '/' && next === '*') {
393
+ const end = source.indexOf('*/', i + 2);
394
+ if (end < 0)
395
+ throw munSyntaxError('Unclosed block comment in Mun AST', i);
396
+ i = end + 1;
397
+ continue;
398
+ }
399
+ if (char === '/' && regexCanStartAfter(source, i)) {
400
+ i = skipRegex(source, i) - 1;
401
+ continue;
402
+ }
403
+ if (char === '(')
404
+ parens += 1;
405
+ else if (char === ')')
406
+ parens -= 1;
407
+ else if (char === '[')
408
+ brackets += 1;
409
+ else if (char === ']')
410
+ brackets -= 1;
411
+ else if (char === '{')
412
+ braces += 1;
413
+ else if (char === '}')
414
+ braces -= 1;
415
+ }
416
+ return source;
417
+ }
418
+ /** Parse the Mun builder subset while retaining opaque TypeScript expressions verbatim. */
419
+ export function parseMunBuilder(source, baseOffset = 0) {
420
+ return {
421
+ kind: 'program',
422
+ source,
423
+ range: { start: baseOffset, end: baseOffset + source.length },
424
+ statements: splitTopLevel(source, ',;', baseOffset).map(parseNode),
425
+ };
426
+ }
427
+ function findStructKeyword(source, start) {
428
+ for (let index = start; index < source.length; index += 1) {
429
+ const char = source[index];
430
+ if (char === "'" || char === '"') {
431
+ index = skipQuoted(source, index, char) - 1;
432
+ continue;
433
+ }
434
+ if (char === '`') {
435
+ index = skipTemplate(source, index) - 1;
436
+ continue;
437
+ }
438
+ if (char === '/' && source[index + 1] === '/') {
439
+ const newline = source.indexOf('\n', index + 2);
440
+ index = (newline < 0 ? source.length : newline) - 1;
441
+ continue;
442
+ }
443
+ if (char === '/' && source[index + 1] === '*') {
444
+ const end = source.indexOf('*/', index + 2);
445
+ if (end < 0)
446
+ throw munSyntaxError('Unclosed block comment in Mun AST', index);
447
+ index = end + 1;
448
+ continue;
449
+ }
450
+ if (source.startsWith('struct', index)) {
451
+ const before = source[index - 1];
452
+ const after = source[index + 6];
453
+ if (!(before && isIdentifierPart(before)) && !(after && isIdentifierPart(after)))
454
+ return index;
455
+ }
456
+ }
457
+ return -1;
458
+ }
459
+ function identifierAt(source, index) {
460
+ const match = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(source.slice(index));
461
+ return match ? { name: match[0], end: index + match[0].length } : undefined;
462
+ }
463
+ function findGenericEnd(source, openIndex) {
464
+ let depth = 0;
465
+ for (let i = openIndex; i < source.length; i += 1) {
466
+ const char = source[i];
467
+ if (char === "'" || char === '"') {
468
+ i = skipQuoted(source, i, char) - 1;
469
+ continue;
470
+ }
471
+ if (char === '`') {
472
+ i = skipTemplate(source, i) - 1;
473
+ continue;
474
+ }
475
+ if (char === '<')
476
+ depth += 1;
477
+ if (char === '>' && --depth === 0)
478
+ return i;
479
+ }
480
+ throw munSyntaxError('Unclosed generic parameter list in Mun AST', openIndex);
481
+ }
482
+ function findMemberEnd(source, start) {
483
+ let parens = 0;
484
+ let brackets = 0;
485
+ let braces = 0;
486
+ for (let i = start; i < source.length; i += 1) {
487
+ const char = source[i];
488
+ const next = source[i + 1];
489
+ if (char === "'" || char === '"') {
490
+ i = skipQuoted(source, i, char) - 1;
491
+ continue;
492
+ }
493
+ if (char === '`') {
494
+ i = skipTemplate(source, i) - 1;
495
+ continue;
496
+ }
497
+ if (char === '/' && next === '/') {
498
+ const end = source.indexOf('\n', i + 2);
499
+ if (parens === 0 && brackets === 0 && braces === 0)
500
+ return end < 0 ? source.length : end;
501
+ i = (end < 0 ? source.length : end) - 1;
502
+ continue;
503
+ }
504
+ if (char === '/' && next === '*') {
505
+ const end = source.indexOf('*/', i + 2);
506
+ if (end < 0)
507
+ throw munSyntaxError('Unclosed block comment in Mun AST', i);
508
+ i = end + 1;
509
+ continue;
510
+ }
511
+ if (char === '(')
512
+ parens += 1;
513
+ else if (char === ')')
514
+ parens -= 1;
515
+ else if (char === '[')
516
+ brackets += 1;
517
+ else if (char === ']')
518
+ brackets -= 1;
519
+ else if (char === '{')
520
+ braces += 1;
521
+ else if (char === '}') {
522
+ if (braces > 0)
523
+ braces -= 1;
524
+ else if (parens === 0 && brackets === 0)
525
+ return i;
526
+ }
527
+ if (parens === 0 && brackets === 0 && braces === 0 && (char === ';' || char === '\n'))
528
+ return i;
529
+ }
530
+ return source.length;
531
+ }
532
+ function parseStructMembers(source, baseOffset) {
533
+ const fields = [];
534
+ const initializers = [];
535
+ let index = 0;
536
+ while (index < source.length) {
537
+ index = skipTrivia(source, index);
538
+ if (index >= source.length)
539
+ break;
540
+ const init = /^init\b/.exec(source.slice(index));
541
+ if (init) {
542
+ const open = skipTrivia(source, index + init[0].length);
543
+ if (source[open] === '(') {
544
+ const close = findMatching(source, open, '(');
545
+ const blockOpen = skipTrivia(source, close + 1);
546
+ if (source[blockOpen] === '{') {
547
+ const blockClose = findMatching(source, blockOpen, '{');
548
+ initializers.push({
549
+ parametersSource: source.slice(open + 1, close),
550
+ bodySource: source.slice(blockOpen + 1, blockClose),
551
+ range: { start: baseOffset + index, end: baseOffset + blockClose + 1 },
552
+ parametersRange: { start: baseOffset + open + 1, end: baseOffset + close },
553
+ bodyRange: { start: baseOffset + blockOpen + 1, end: baseOffset + blockClose },
554
+ });
555
+ index = blockClose + 1;
556
+ continue;
557
+ }
558
+ }
559
+ }
560
+ const field = /^(?:(@State|@Binding)\s+)?(?:let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?::\s*([\s\S]*?))?(?:\s*=\s*([\s\S]*))?$/.exec(source.slice(index, findMemberEnd(source, index)).trim());
561
+ const end = findMemberEnd(source, index);
562
+ if (field && field[2] !== 'body') {
563
+ const declaration = source.slice(index, end).trim();
564
+ const leading = source.slice(index, end).search(/\S|$/);
565
+ const fieldStart = baseOffset + index + Math.max(0, leading);
566
+ fields.push({
567
+ name: field[2],
568
+ kind: field[1] === '@State' ? 'state' : field[1] === '@Binding' ? 'binding' : 'stored',
569
+ type: field[3]?.trim(),
570
+ initializer: field[4]?.trim(),
571
+ range: { start: fieldStart, end: fieldStart + declaration.length },
572
+ });
573
+ index = end + (source[end] === ';' || source[end] === '\n' ? 1 : 0);
574
+ continue;
575
+ }
576
+ // `var body: some View { ... }` is a member too, but its block is the
577
+ // separately recorded body expression and must not become a stored field.
578
+ if (/^var\s+body\b/.test(source.slice(index, end).trim())) {
579
+ const bodyOpen = source.indexOf('{', index);
580
+ if (bodyOpen >= 0 && bodyOpen < end) {
581
+ index = end + (source[end] === ';' || source[end] === '\n' ? 1 : 0);
582
+ continue;
583
+ }
584
+ }
585
+ index = Math.max(index + 1, end + 1);
586
+ }
587
+ return { fields, initializers };
588
+ }
589
+ /** Parse struct View declarations without interpreting TypeScript expressions inside them. */
590
+ export function parseMunStructs(source, baseOffset = 0) {
591
+ const declarations = [];
592
+ let cursor = 0;
593
+ while (cursor < source.length) {
594
+ const index = findStructKeyword(source, cursor);
595
+ if (index < 0)
596
+ break;
597
+ const nameStart = skipTrivia(source, index + 6);
598
+ const identifier = identifierAt(source, nameStart);
599
+ if (!identifier) {
600
+ cursor = index + 6;
601
+ continue;
602
+ }
603
+ let headerEnd = skipTrivia(source, identifier.end);
604
+ let genericParameters;
605
+ if (source[headerEnd] === '<') {
606
+ const genericEnd = findGenericEnd(source, headerEnd);
607
+ genericParameters = source.slice(headerEnd + 1, genericEnd).trim();
608
+ headerEnd = skipTrivia(source, genericEnd + 1);
609
+ }
610
+ const brace = source.indexOf('{', headerEnd);
611
+ if (brace < 0)
612
+ throw munSyntaxError(`Missing body for struct ${identifier.name}`, headerEnd + baseOffset);
613
+ const close = findMatching(source, brace, '{');
614
+ const bodySource = source.slice(brace + 1, close);
615
+ const bodyMatch = /\bvar\s+body\s*:[^{]+\{/.exec(bodySource);
616
+ if (!bodyMatch)
617
+ throw munSyntaxError(`struct ${identifier.name} must declare var body`, index + baseOffset);
618
+ const bodyOpen = bodySource.indexOf('{', bodyMatch.index + bodyMatch[0].length - 1);
619
+ const bodyClose = findMatching(bodySource, bodyOpen, '{');
620
+ const bodyExpressionSource = bodySource.slice(bodyOpen + 1, bodyClose);
621
+ const members = parseStructMembers(bodySource, baseOffset + brace + 1);
622
+ declarations.push({
623
+ kind: 'struct',
624
+ name: identifier.name,
625
+ genericParameters,
626
+ source: source.slice(index, close + 1),
627
+ bodySource,
628
+ bodyExpressionSource,
629
+ range: { start: baseOffset + index, end: baseOffset + close + 1 },
630
+ bodyRange: { start: baseOffset + brace + 1, end: baseOffset + close },
631
+ bodyExpressionRange: {
632
+ start: baseOffset + brace + 1 + bodyOpen + 1,
633
+ end: baseOffset + brace + 1 + bodyClose,
634
+ },
635
+ fields: members.fields,
636
+ initializers: members.initializers,
637
+ });
638
+ cursor = close + 1;
639
+ }
640
+ return declarations;
641
+ }
642
+ function lowerClosure(value, lowering) {
643
+ return lowering.closure(value.bodySource, value.parameter);
644
+ }
645
+ function lowerArgument(argument, lowering) {
646
+ const value = argument.value.kind === 'closure'
647
+ ? lowerClosure(argument.value, lowering)
648
+ : lowering.transformRaw(argument.value.source);
649
+ return argument.label ? `${argument.label}: ${value}` : value;
650
+ }
651
+ function lowerCall(node, lowering) {
652
+ const values = node.arguments.map(argument => lowerArgument(argument, lowering));
653
+ const labeled = node.arguments.some(argument => argument.label);
654
+ let argumentsSource = values.join(', ');
655
+ if (labeled) {
656
+ const positional = node.arguments.flatMap((argument, index) => argument.label ? [] : [values[index]]);
657
+ const named = node.arguments.flatMap((argument, index) => argument.label ? [values[index]] : []);
658
+ const object = `namedArguments({ ${named.join(', ')} })`;
659
+ argumentsSource = positional.length > 0 ? `${positional.join(', ')}, ${object}` : object;
660
+ }
661
+ if (node.trailing) {
662
+ const trailing = lowerClosure(node.trailing, lowering);
663
+ argumentsSource = argumentsSource ? `${argumentsSource}, ${trailing}` : trailing;
664
+ }
665
+ return `${node.callee}(${argumentsSource})`;
666
+ }
667
+ function lowerProgram(program, lowering) {
668
+ return program.statements.map(node => {
669
+ if (node.kind === 'raw')
670
+ return lowering.transformRaw(protectLineComment(node.source));
671
+ if (node.kind === 'call')
672
+ return lowerCall(node, lowering);
673
+ const thenBranch = lowerProgram(node.then, lowering).join(', ');
674
+ let elseBranch = '[]';
675
+ if (node.otherwise) {
676
+ elseBranch = 'kind' in node.otherwise && node.otherwise.kind === 'conditional'
677
+ ? lowerConditional(node.otherwise, lowering)
678
+ : `[${lowerProgram(node.otherwise, lowering).join(', ')}]`;
679
+ }
680
+ return `(${lowering.transformRaw(node.condition.source)} ? [${thenBranch}] : ${elseBranch})`;
681
+ });
682
+ }
683
+ function lowerConditional(node, lowering) {
684
+ const thenBranch = lowerProgram(node.then, lowering).join(', ');
685
+ let elseBranch = '[]';
686
+ if (node.otherwise) {
687
+ elseBranch = 'kind' in node.otherwise && node.otherwise.kind === 'conditional'
688
+ ? lowerConditional(node.otherwise, lowering)
689
+ : `[${lowerProgram(node.otherwise, lowering).join(', ')}]`;
690
+ }
691
+ return `(${lowering.transformRaw(node.condition.source)} ? [${thenBranch}] : ${elseBranch})`;
692
+ }
693
+ /** Lower a parsed builder program to normalized child expressions. */
694
+ export function lowerMunBuilderAst(program, lowering) {
695
+ return lowerProgram(program, lowering);
696
+ }
697
+ //# sourceMappingURL=ast.js.map