@alloy-js/core 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (228) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/babel.config.cjs +4 -1
  3. package/dist/src/binder.d.ts +20 -13
  4. package/dist/src/binder.d.ts.map +1 -1
  5. package/dist/src/binder.js +33 -15
  6. package/dist/src/binder.js.map +1 -1
  7. package/dist/src/code.d.ts +2 -2
  8. package/dist/src/code.d.ts.map +1 -1
  9. package/dist/src/code.js +4 -4
  10. package/dist/src/code.js.map +1 -1
  11. package/dist/src/components/Block.d.ts +25 -0
  12. package/dist/src/components/Block.d.ts.map +1 -0
  13. package/dist/src/components/Block.js +25 -0
  14. package/dist/src/components/Block.js.map +1 -0
  15. package/dist/src/components/Declaration.d.ts +1 -1
  16. package/dist/src/components/Declaration.d.ts.map +1 -1
  17. package/dist/src/components/Declaration.js +4 -0
  18. package/dist/src/components/Declaration.js.map +1 -1
  19. package/dist/src/components/For.d.ts +44 -0
  20. package/dist/src/components/For.d.ts.map +1 -0
  21. package/dist/src/components/For.js +41 -0
  22. package/dist/src/components/For.js.map +1 -0
  23. package/dist/src/components/Indent.d.ts +6 -10
  24. package/dist/src/components/Indent.d.ts.map +1 -1
  25. package/dist/src/components/Indent.js +7 -18
  26. package/dist/src/components/Indent.js.map +1 -1
  27. package/dist/src/components/List.d.ts +38 -0
  28. package/dist/src/components/List.d.ts.map +1 -0
  29. package/dist/src/components/List.js +40 -0
  30. package/dist/src/components/List.js.map +1 -0
  31. package/dist/src/components/MemberDeclaration.d.ts +1 -1
  32. package/dist/src/components/MemberDeclaration.d.ts.map +1 -1
  33. package/dist/src/components/MemberDeclaration.js.map +1 -1
  34. package/dist/src/components/MemberName.d.ts +1 -1
  35. package/dist/src/components/MemberName.d.ts.map +1 -1
  36. package/dist/src/components/MemberName.js +1 -1
  37. package/dist/src/components/MemberName.js.map +1 -1
  38. package/dist/src/components/MemberScope.d.ts +1 -1
  39. package/dist/src/components/MemberScope.d.ts.map +1 -1
  40. package/dist/src/components/MemberScope.js.map +1 -1
  41. package/dist/src/components/Name.d.ts +1 -1
  42. package/dist/src/components/Name.d.ts.map +1 -1
  43. package/dist/src/components/Name.js +1 -1
  44. package/dist/src/components/Name.js.map +1 -1
  45. package/dist/src/components/Output.d.ts +3 -2
  46. package/dist/src/components/Output.d.ts.map +1 -1
  47. package/dist/src/components/Output.js +12 -2
  48. package/dist/src/components/Output.js.map +1 -1
  49. package/dist/src/components/Scope.d.ts +1 -1
  50. package/dist/src/components/Scope.d.ts.map +1 -1
  51. package/dist/src/components/Scope.js.map +1 -1
  52. package/dist/src/components/Show.d.ts +8 -0
  53. package/dist/src/components/Show.d.ts.map +1 -0
  54. package/dist/src/components/Show.js +4 -0
  55. package/dist/src/components/Show.js.map +1 -0
  56. package/dist/src/components/SourceDirectory.d.ts +2 -2
  57. package/dist/src/components/SourceDirectory.d.ts.map +1 -1
  58. package/dist/src/components/SourceDirectory.js +1 -0
  59. package/dist/src/components/SourceDirectory.js.map +1 -1
  60. package/dist/src/components/SourceFile.d.ts +4 -8
  61. package/dist/src/components/SourceFile.d.ts.map +1 -1
  62. package/dist/src/components/SourceFile.js +6 -13
  63. package/dist/src/components/SourceFile.js.map +1 -1
  64. package/dist/src/components/StatementList.d.ts +9 -0
  65. package/dist/src/components/StatementList.d.ts.map +1 -0
  66. package/dist/src/components/StatementList.js +17 -0
  67. package/dist/src/components/StatementList.js.map +1 -0
  68. package/dist/src/components/Switch.d.ts +41 -0
  69. package/dist/src/components/Switch.d.ts.map +1 -0
  70. package/dist/src/components/Switch.js +41 -0
  71. package/dist/src/components/Switch.js.map +1 -0
  72. package/dist/src/components/Wrap.d.ts +20 -0
  73. package/dist/src/components/Wrap.d.ts.map +1 -0
  74. package/dist/src/components/Wrap.js +15 -0
  75. package/dist/src/components/Wrap.js.map +1 -0
  76. package/dist/src/components/index.d.ts +8 -1
  77. package/dist/src/components/index.d.ts.map +1 -1
  78. package/dist/src/components/index.js +7 -0
  79. package/dist/src/components/index.js.map +1 -1
  80. package/dist/src/components/stc/index.d.ts +89 -18
  81. package/dist/src/components/stc/index.d.ts.map +1 -1
  82. package/dist/src/components/stc/index.js +17 -1
  83. package/dist/src/components/stc/index.js.map +1 -1
  84. package/dist/src/context/index.d.ts +0 -1
  85. package/dist/src/context/index.d.ts.map +1 -1
  86. package/dist/src/context/index.js +0 -1
  87. package/dist/src/context/index.js.map +1 -1
  88. package/dist/src/context/member-declaration.d.ts +1 -0
  89. package/dist/src/context/member-declaration.d.ts.map +1 -1
  90. package/dist/src/context/member-declaration.js +4 -1
  91. package/dist/src/context/member-declaration.js.map +1 -1
  92. package/dist/src/context.d.ts.map +1 -1
  93. package/dist/src/context.js +3 -3
  94. package/dist/src/context.js.map +1 -1
  95. package/dist/src/index.browser.d.ts +3 -0
  96. package/dist/src/index.browser.d.ts.map +1 -0
  97. package/dist/src/index.browser.js +3 -0
  98. package/dist/src/index.browser.js.map +1 -0
  99. package/dist/src/index.d.ts +2 -0
  100. package/dist/src/index.d.ts.map +1 -1
  101. package/dist/src/index.js +2 -0
  102. package/dist/src/index.js.map +1 -1
  103. package/dist/src/jsx-runtime.d.ts +151 -7
  104. package/dist/src/jsx-runtime.d.ts.map +1 -1
  105. package/dist/src/jsx-runtime.js +113 -12
  106. package/dist/src/jsx-runtime.js.map +1 -1
  107. package/dist/src/render.d.ts +107 -132
  108. package/dist/src/render.d.ts.map +1 -1
  109. package/dist/src/render.js +272 -178
  110. package/dist/src/render.js.map +1 -1
  111. package/dist/src/stc.d.ts +14 -0
  112. package/dist/src/stc.d.ts.map +1 -0
  113. package/dist/src/stc.js +52 -0
  114. package/dist/src/stc.js.map +1 -0
  115. package/dist/src/tap.d.ts +19 -0
  116. package/dist/src/tap.d.ts.map +1 -0
  117. package/dist/src/tap.js +39 -0
  118. package/dist/src/tap.js.map +1 -0
  119. package/dist/src/utils.d.ts +22 -15
  120. package/dist/src/utils.d.ts.map +1 -1
  121. package/dist/src/utils.js +95 -59
  122. package/dist/src/utils.js.map +1 -1
  123. package/dist/test/browser-build.test.d.ts +2 -0
  124. package/dist/test/browser-build.test.d.ts.map +1 -0
  125. package/dist/test/components/block.test.d.ts +2 -0
  126. package/dist/test/components/block.test.d.ts.map +1 -0
  127. package/dist/test/components/declaration.test.d.ts +2 -0
  128. package/dist/test/components/declaration.test.d.ts.map +1 -0
  129. package/dist/test/components/list.test.d.ts +2 -0
  130. package/dist/test/components/list.test.d.ts.map +1 -0
  131. package/dist/test/components/wrap.test.d.ts +2 -0
  132. package/dist/test/components/wrap.test.d.ts.map +1 -0
  133. package/dist/test/control-flow/for.test.d.ts +2 -0
  134. package/dist/test/control-flow/for.test.d.ts.map +1 -0
  135. package/dist/test/control-flow/match.test.d.ts +2 -0
  136. package/dist/test/control-flow/match.test.d.ts.map +1 -0
  137. package/dist/test/control-flow/show.test.d.ts +2 -0
  138. package/dist/test/control-flow/show.test.d.ts.map +1 -0
  139. package/dist/test/reactivity/cleanup.test.d.ts +2 -0
  140. package/dist/test/reactivity/cleanup.test.d.ts.map +1 -0
  141. package/dist/test/reactivity/memo.test.d.ts +2 -0
  142. package/dist/test/reactivity/memo.test.d.ts.map +1 -0
  143. package/dist/test/reactivity/untrack.test.d.ts +2 -0
  144. package/dist/test/reactivity/untrack.test.d.ts.map +1 -0
  145. package/dist/test/rendering/formatting.test.d.ts +2 -0
  146. package/dist/test/rendering/formatting.test.d.ts.map +1 -0
  147. package/dist/test/rendering/memoization.test.d.ts +2 -0
  148. package/dist/test/rendering/memoization.test.d.ts.map +1 -0
  149. package/dist/test/split-props.test.d.ts +2 -0
  150. package/dist/test/split-props.test.d.ts.map +1 -0
  151. package/dist/test/stc.test.d.ts.map +1 -1
  152. package/dist/test/utils.test.d.ts.map +1 -1
  153. package/dist/testing/extend-expect.js +4 -4
  154. package/dist/testing/extend-expect.js.map +1 -1
  155. package/dist/testing/render.d.ts +2 -3
  156. package/dist/testing/render.d.ts.map +1 -1
  157. package/dist/testing/render.js +2 -4
  158. package/dist/testing/render.js.map +1 -1
  159. package/dist/tsconfig.tsbuildinfo +1 -1
  160. package/package.json +8 -9
  161. package/src/binder.ts +60 -50
  162. package/src/code.ts +17 -12
  163. package/src/components/Block.tsx +44 -0
  164. package/src/components/Declaration.tsx +10 -4
  165. package/src/components/For.tsx +81 -0
  166. package/src/components/Indent.tsx +20 -27
  167. package/src/components/List.tsx +94 -0
  168. package/src/components/MemberDeclaration.tsx +9 -6
  169. package/src/components/MemberScope.tsx +4 -2
  170. package/src/components/Output.tsx +27 -14
  171. package/src/components/Scope.tsx +4 -2
  172. package/src/components/Show.tsx +11 -0
  173. package/src/components/SourceDirectory.tsx +6 -2
  174. package/src/components/SourceFile.tsx +13 -17
  175. package/src/components/StatementList.tsx +16 -0
  176. package/src/components/Switch.tsx +62 -0
  177. package/src/components/Wrap.tsx +29 -0
  178. package/src/components/index.tsx +8 -1
  179. package/src/components/stc/index.ts +18 -1
  180. package/src/context/index.ts +0 -1
  181. package/src/context/member-declaration.ts +9 -1
  182. package/src/context.ts +2 -3
  183. package/src/index.browser.ts +2 -0
  184. package/src/index.ts +2 -0
  185. package/src/jsx-runtime.ts +265 -23
  186. package/src/render.ts +382 -200
  187. package/src/stc.ts +95 -0
  188. package/src/tap.ts +69 -0
  189. package/src/utils.ts +162 -95
  190. package/temp/api.json +8042 -1886
  191. package/test/browser-build.test.ts +91 -0
  192. package/test/children.test.tsx +8 -10
  193. package/test/components/block.test.tsx +48 -0
  194. package/test/components/declaration.test.tsx +37 -0
  195. package/test/components/list.test.tsx +91 -0
  196. package/test/components/slot.test.tsx +31 -25
  197. package/test/components/source-file.test.tsx +11 -31
  198. package/test/components/wrap.test.tsx +42 -0
  199. package/test/control-flow/for.test.tsx +194 -0
  200. package/test/control-flow/match.test.tsx +49 -0
  201. package/test/control-flow/show.test.tsx +25 -0
  202. package/test/name-policy.test.tsx +5 -5
  203. package/test/reactivity/cleanup.test.tsx +91 -0
  204. package/test/reactivity/memo.test.tsx +17 -0
  205. package/test/reactivity/ref-rendering.test.tsx +3 -8
  206. package/test/reactivity/test.test.tsx +7 -6
  207. package/test/reactivity/untrack.test.ts +33 -0
  208. package/test/rendering/basic.test.tsx +25 -47
  209. package/test/rendering/code.test.tsx +3 -3
  210. package/test/rendering/formatting.test.tsx +487 -0
  211. package/test/rendering/indent.test.tsx +42 -529
  212. package/test/rendering/memoization.test.tsx +30 -0
  213. package/test/split-props.test.ts +87 -0
  214. package/test/stc.test.tsx +29 -8
  215. package/test/symbols.test.ts +132 -3
  216. package/test/utils.test.tsx +129 -20
  217. package/testing/extend-expect.ts +14 -4
  218. package/testing/render.ts +2 -4
  219. package/testing/vitest.d.ts +6 -1
  220. package/vitest.config.ts +1 -1
  221. package/dist/src/context/indent.d.ts +0 -5
  222. package/dist/src/context/indent.d.ts.map +0 -1
  223. package/dist/src/context/indent.js +0 -8
  224. package/dist/src/context/indent.js.map +0 -1
  225. package/dist/test/rendering/linebreaks.test.d.ts +0 -2
  226. package/dist/test/rendering/linebreaks.test.d.ts.map +0 -1
  227. package/src/context/indent.ts +0 -17
  228. package/test/rendering/linebreaks.test.tsx +0 -72
@@ -1,14 +1,18 @@
1
1
  // Much of the implementations in this file are inspired by vuerx-js
2
2
  // See: https://github.com/ryansolid/vuerx-jsx.
3
3
  import {
4
+ isReactive,
4
5
  pauseTracking,
6
+ proxyRefs,
5
7
  Ref,
6
8
  resetTracking,
7
9
  shallowRef,
8
10
  stop,
11
+ toRefs,
9
12
  effect as vueEffect,
10
13
  } from "@vue/reactivity";
11
14
  import { Refkey } from "./refkey.js";
15
+ import { RenderedTextTree } from "./render.js";
12
16
 
13
17
  if ((globalThis as any).ALLOY) {
14
18
  throw new Error(
@@ -31,6 +35,11 @@ export interface Context {
31
35
  // store random info about the node
32
36
  meta?: Record<string, any>;
33
37
 
38
+ /**
39
+ * A cache of RenderTextTree nodes created within this context,
40
+ * indexed by the component or function which created them.
41
+ */
42
+ elementCache: ElementCache;
34
43
  /**
35
44
  * When this context was created by a component, this will
36
45
  * be the component that created it.
@@ -43,21 +52,35 @@ export function getContext() {
43
52
  return globalContext;
44
53
  }
45
54
 
46
- export function root<T>(
47
- fn: (d: Disposable) => T,
48
- componentOwner?: ComponentCreator<any>,
49
- ): T {
50
- globalContext = {
51
- componentOwner,
55
+ export function getElementCache() {
56
+ return getContext()!.elementCache;
57
+ }
58
+
59
+ export type ElementCacheKey =
60
+ | ComponentCreator
61
+ | (() => unknown)
62
+ | CustomContext;
63
+ export type ElementCache = Map<ElementCacheKey, RenderedTextTree>;
64
+
65
+ export interface RootOptions {
66
+ componentOwner?: ComponentCreator<any>;
67
+ }
68
+
69
+ export function root<T>(fn: (d: Disposable) => T, options?: RootOptions): T {
70
+ const context: Context = {
71
+ componentOwner: options?.componentOwner,
52
72
  disposables: [],
53
73
  owner: globalContext,
54
74
  context: {},
75
+ elementCache: new Map(),
55
76
  };
77
+
78
+ globalContext = context;
56
79
  let ret;
57
80
  try {
58
81
  ret = untrack(() =>
59
82
  fn(() => {
60
- for (const d of globalContext!.disposables) {
83
+ for (const d of context!.disposables) {
61
84
  d();
62
85
  }
63
86
  }),
@@ -83,28 +106,31 @@ export function memo<T>(fn: () => T, equal?: boolean): () => T {
83
106
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
84
107
  (!equal || prev !== res) && (o.value = res);
85
108
  return res;
86
- });
109
+ }, undefined as T);
87
110
  return () => o.value;
88
111
  }
89
112
 
90
113
  export function effect<T>(fn: (prev?: T) => T, current?: T) {
91
- const context = {
92
- src: "effect",
114
+ const context: Context = {
93
115
  context: {},
94
116
  disposables: [] as (() => void)[],
95
117
  owner: globalContext,
96
- } as any;
118
+ elementCache: new Map(),
119
+ };
97
120
 
98
121
  const cleanupFn = (final: boolean) => {
99
122
  const d = context.disposables;
100
123
  context.disposables = [];
101
124
  for (let k = 0, len = d.length; k < len; k++) d[k]();
125
+
102
126
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
103
127
  final && stop(c);
104
128
  };
105
129
 
130
+ onCleanup(() => cleanupFn(true));
106
131
  const c = vueEffect(() => {
107
132
  cleanupFn(false);
133
+
108
134
  const oldContext = globalContext;
109
135
  globalContext = context;
110
136
  try {
@@ -112,41 +138,90 @@ export function effect<T>(fn: (prev?: T) => T, current?: T) {
112
138
  } finally {
113
139
  globalContext = oldContext;
114
140
  }
115
- });
116
-
117
- cleanup(() => cleanupFn(true));
141
+ }, {});
118
142
  }
119
143
 
120
- function cleanup(fn: Disposable) {
144
+ /**
145
+ * Register a cleanup function which is called when the current reactive scope
146
+ * is recalculated or disposed. This is useful to clean up any side effects
147
+ * created in the reactive scope.
148
+ *
149
+ * @remarks
150
+ *
151
+ * When onCleanup is called inside a component definition, the provided function
152
+ * is called when the component is removed from the tree. This can be useful to
153
+ * clean up any side effects created as a result of rendering the component. For
154
+ * example, if rendering a component creates a symbol, `onCleanup` can be used
155
+ * to remove the symbol when the component is removed from the tree.
156
+ *
157
+ * When onCleanup is called inside a memo or effect, the function is called when
158
+ * the effect is refreshed (e.g. when a memo or computed recalculates) or
159
+ * disposed (e.g. it is no longer needed because it is attached to a component
160
+ * which was removed).
161
+ */
162
+ export function onCleanup(fn: Disposable) {
121
163
  if (globalContext != null) {
122
164
  globalContext.disposables.push(fn);
123
165
  }
124
166
  }
125
167
 
168
+ /**
169
+ * Create a custom reactive context for the children returned by
170
+ * the provided context.
171
+ */
172
+ export interface CustomContext {
173
+ [CUSTOM_CONTEXT_SYM]: true;
174
+ useCustomContext: (useCb: CustomContextChildrenCallback) => void;
175
+ }
176
+
177
+ export type CustomContextChildrenCallback = (child: Children) => void;
178
+ const CUSTOM_CONTEXT_SYM = Symbol();
179
+
180
+ export function createCustomContext(
181
+ useCallback: (useChildren: CustomContextChildrenCallback) => void,
182
+ ): CustomContext {
183
+ return {
184
+ [CUSTOM_CONTEXT_SYM]: true,
185
+ useCustomContext(useCb: (children: Children) => void): void {
186
+ useCallback(useCb);
187
+ },
188
+ };
189
+ }
190
+
191
+ export function isCustomContext(child: Children): child is CustomContext {
192
+ return (
193
+ typeof child === "object" &&
194
+ child !== null &&
195
+ Object.hasOwn(child, CUSTOM_CONTEXT_SYM)
196
+ );
197
+ }
198
+
126
199
  export type Child =
127
200
  | string
128
201
  | boolean
129
202
  | number
130
203
  | undefined
131
204
  | null
132
- | (() => Child | Children)
133
- | Child[]
205
+ | void
206
+ | (() => Children)
134
207
  | Ref
135
- | Refkey;
208
+ | Refkey
209
+ | CustomContext
210
+ | IntrinsicElement;
136
211
 
137
- export type Children = Child | Child[];
138
- export type Props = Record<string, unknown>;
212
+ export type Children = Child | Children[];
213
+ export type Props = Record<string, any>;
139
214
 
140
215
  export interface ComponentDefinition<TProps = Props> {
141
- (props: TProps): Child | Children;
216
+ (props: TProps): Children;
142
217
  }
143
218
  export interface Component<TProps = Props> {
144
- (props: TProps): Child | Children;
219
+ (props: TProps): Children;
145
220
  tag?: symbol;
146
221
  }
147
222
  export interface ComponentCreator<TProps = Props> {
148
223
  component: Component<TProps>;
149
- (): Child | Children;
224
+ (): Children;
150
225
  props: Props;
151
226
  tag?: symbol;
152
227
  }
@@ -212,6 +287,51 @@ export function isComponentCreator(item: unknown): item is ComponentCreator {
212
287
  return typeof item === "function" && (item as any).component;
213
288
  }
214
289
 
290
+ /**
291
+ * This namespace is predominantly for interop with React tooling in VSCode
292
+ * and controls the type of JSX elements, components, and the like.
293
+ */
294
+ // eslint-disable-next-line @typescript-eslint/no-namespace
295
+ export namespace JSX {
296
+ export interface IntrinsicElements {
297
+ group: { shouldBreak?: boolean; id?: symbol; children: Children };
298
+ line: {};
299
+ br: {};
300
+ hardline: {};
301
+ hbr: {};
302
+ softline: {};
303
+ sbr: {};
304
+ literalline: {};
305
+ lbr: {};
306
+ indent: { children: Children };
307
+ fill: { children: Children };
308
+ breakParent: {};
309
+ ifBreak: { children: Children; flatContents?: Children; groupId?: symbol };
310
+ lineSuffix: { children: Children };
311
+ lineSuffixBoundary: {};
312
+ dedent: { children: Children };
313
+ align:
314
+ | { children: Children; width: number }
315
+ | { children: Children; string: string };
316
+ markAsRoot: { children: Children };
317
+ dedentToRoot: { children: Children };
318
+ }
319
+ export type ElementType = string | ComponentDefinition<any>;
320
+ export type Element = Children;
321
+ export interface ElementChildrenAttribute {
322
+ children: {};
323
+ }
324
+ export interface ElementAttributesProperty {
325
+ props: {};
326
+ }
327
+ }
328
+
329
+ export function jsx(type: Component<any>, props: Record<string, unknown>) {
330
+ return createComponent(type, props);
331
+ }
332
+
333
+ export const jsxs = jsx;
334
+
215
335
  export function createComponent<TProps extends Props = Props>(
216
336
  C: Component<TProps>,
217
337
  props: TProps,
@@ -234,6 +354,73 @@ export function taggedComponent<TProps = Props>(
234
354
  return component;
235
355
  }
236
356
 
357
+ export const intrinsicElementKey = Symbol();
358
+
359
+ export type IndentIntrinsicElement = IntrinsicElementBase<"indent">;
360
+ export type BrIntrinsicElement = IntrinsicElementBase<"br">;
361
+ export type LineIntrinsicElement = IntrinsicElementBase<"line">;
362
+ export type HbrIntrinsicElement = IntrinsicElementBase<"hbr">;
363
+ export type HardlineIntrinsicElement = IntrinsicElementBase<"hardline">;
364
+ export type SbrIntrinsicElement = IntrinsicElementBase<"sbr">;
365
+ export type SoftlineIntrinsicElement = IntrinsicElementBase<"softline">;
366
+ export type GroupIntrinsicElement = IntrinsicElementBase<"group">;
367
+ export type AlignIntrinsicElement = IntrinsicElementBase<"align">;
368
+ export type FillIntrinsicElement = IntrinsicElementBase<"fill">;
369
+ export type BreakParentIntrinsicElement = IntrinsicElementBase<"breakParent">;
370
+ export type LineSuffixIntrinsicElement = IntrinsicElementBase<"lineSuffix">;
371
+ export type LineSuffixBoundaryIntrinsicElement =
372
+ IntrinsicElementBase<"lineSuffixBoundary">;
373
+ export type DedentIntrinsicElement = IntrinsicElementBase<"dedent">;
374
+ export type DedentToRootIntrinsicElement = IntrinsicElementBase<"dedentToRoot">;
375
+ export type MarkAsRootIntrinsicElement = IntrinsicElementBase<"markAsRoot">;
376
+ export type LiterallineIntrinsicElement = IntrinsicElementBase<"literalline">;
377
+ export type LbrIntrinsicElement = IntrinsicElementBase<"lbr">;
378
+ export type IfBreakIntrinsicElement = IntrinsicElementBase<"ifBreak">;
379
+
380
+ export type IntrinsicElement =
381
+ | IndentIntrinsicElement
382
+ | BrIntrinsicElement
383
+ | LineIntrinsicElement
384
+ | HbrIntrinsicElement
385
+ | HardlineIntrinsicElement
386
+ | SbrIntrinsicElement
387
+ | SoftlineIntrinsicElement
388
+ | GroupIntrinsicElement
389
+ | AlignIntrinsicElement
390
+ | FillIntrinsicElement
391
+ | BreakParentIntrinsicElement
392
+ | LineSuffixIntrinsicElement
393
+ | LineSuffixBoundaryIntrinsicElement
394
+ | DedentIntrinsicElement
395
+ | LiterallineIntrinsicElement
396
+ | LbrIntrinsicElement
397
+ | DedentToRootIntrinsicElement
398
+ | MarkAsRootIntrinsicElement
399
+ | IfBreakIntrinsicElement;
400
+
401
+ export interface IntrinsicElementBase<
402
+ TKey extends keyof JSX.IntrinsicElements = keyof JSX.IntrinsicElements,
403
+ > {
404
+ [intrinsicElementKey]: true;
405
+ name: TKey;
406
+ props: JSX.IntrinsicElements[TKey];
407
+ }
408
+ export function createIntrinsic<TKey extends keyof JSX.IntrinsicElements>(
409
+ name: TKey,
410
+ props: JSX.IntrinsicElements[TKey],
411
+ ): IntrinsicElementBase<TKey> {
412
+ return {
413
+ [intrinsicElementKey]: true,
414
+ name,
415
+ props,
416
+ };
417
+ }
418
+
419
+ export function isIntrinsicElement(type: unknown): type is IntrinsicElement {
420
+ return (
421
+ typeof type === "object" && type !== null && intrinsicElementKey in type
422
+ );
423
+ }
237
424
  export function mergeProps<T, U>(source: T, source1: U): T & U;
238
425
  export function mergeProps<T, U, V>(
239
426
  source: T,
@@ -272,6 +459,61 @@ export function mergeProps(...sources: any): any {
272
459
  return target;
273
460
  }
274
461
 
462
+ export type SplitProps<T, K extends (readonly (keyof T)[])[]> = [
463
+ ...{
464
+ [P in keyof K]: P extends `${number}` ?
465
+ Pick<T, Extract<K[P], readonly (keyof T)[]>[number]>
466
+ : never;
467
+ },
468
+ { [P in keyof T as Exclude<P, K[number][number]>]: T[P] },
469
+ ];
470
+
471
+ export function splitProps<
472
+ T extends Record<any, any>,
473
+ K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]],
474
+ >(props: T, ...keys: K): SplitProps<T, K> {
475
+ if (isReactive(props)) {
476
+ const refs = untrack(() => toRefs(props));
477
+ const remainingKeys = new Set(Object.keys(refs));
478
+
479
+ const result: any = keys.map((keySet) => {
480
+ const resultSet: any = {};
481
+ for (const key of keySet) {
482
+ resultSet[key] = refs[key];
483
+ remainingKeys.delete(key as string);
484
+ }
485
+ return proxyRefs(resultSet);
486
+ });
487
+
488
+ const remaining: any = {};
489
+ for (const key of remainingKeys) {
490
+ remaining[key] = refs[key];
491
+ }
492
+
493
+ return [...result, proxyRefs(remaining)] as any;
494
+ }
495
+
496
+ const descriptors = Object.getOwnPropertyDescriptors(props);
497
+ const remainingKeys = new Set(Object.keys(descriptors));
498
+ const result: any = keys.map((keySet) => {
499
+ const resultSet: any = {};
500
+ for (const key of keySet) {
501
+ if (key in descriptors) {
502
+ Object.defineProperty(resultSet, key, descriptors[key]);
503
+ remainingKeys.delete(key as string);
504
+ }
505
+ }
506
+ return resultSet;
507
+ });
508
+
509
+ const remaining: any = {};
510
+ for (const key of remainingKeys) {
511
+ Object.defineProperty(remaining, key, descriptors[key]);
512
+ }
513
+
514
+ return [...result, remaining] as any;
515
+ }
516
+
275
517
  function shouldDebug() {
276
518
  return typeof process !== "undefined" && !!process.env?.ALLOY_DEBUG;
277
519
  }