@calmdown/pyxis 1.0.0-rc.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.
package/dist/core.d.ts ADDED
@@ -0,0 +1,737 @@
1
+ //#region src/support/types.d.ts
2
+ /**
3
+ * Puts `T` into a union with `null` and `undefined`.
4
+ */
5
+ type Nil<T> = T | null | undefined;
6
+ /**
7
+ * Converts the union `U` into an intersection type.
8
+ */
9
+ type Intersection<U, TEmpty = {}> = [U] extends [never] ? TEmpty : (U extends any ? (u: U) => void : never) extends ((i: infer I) => void) ? I : never;
10
+ /**
11
+ * A type describing any map of intrinsic elements and their props.
12
+ */
13
+ type ElementsType = { readonly [_ in string]?: any; };
14
+ /**
15
+ * A type describing any props of a Component.
16
+ */
17
+ type PropsType = { readonly [_ in string]?: any; };
18
+ /**
19
+ * A symbol to include in props typings containing the original Node type.
20
+ * @deprecated **Type only, does not exist at runtime!**
21
+ */
22
+ declare const S_NODE_TYPE: unique symbol;
23
+ /**
24
+ * Infers the specific Node type from its props typings.
25
+ */
26
+ type NodeType<P> = P extends {
27
+ readonly [S_NODE_TYPE]?: infer N;
28
+ } ? N : unknown;
29
+ /**
30
+ * A tuple of up to 2 arguments.
31
+ */
32
+ type ArgsMax2<A0 = any, A1 = any> = [a0?: A0, a1?: A1];
33
+ /**
34
+ * Describes a callback with up to two stored arguments.
35
+ */
36
+ interface Callback<TArgs extends ArgsMax2 = ArgsMax2, TReturn = void> {}
37
+ //#endregion
38
+ //#region src/data/Dependency.d.ts
39
+ /**
40
+ * A dependency callback of an Atom. The callback will be run whenever the relevant Atom changes.
41
+ */
42
+ interface Dependency<TArgs extends ArgsMax2 = ArgsMax2> extends Callback<TArgs> {}
43
+ interface DependencyList<TArgs extends ArgsMax2 = ArgsMax2> {}
44
+ declare function bind(lifecycle: Lifecycle, target: DependencyList, block: () => void): void;
45
+ //#endregion
46
+ //#region src/data/Lifecycle.d.ts
47
+ interface Lifecycle extends DependencyList {
48
+ /** whether this Lifecycle is currently mounted or not */
49
+ mounted: boolean;
50
+ }
51
+ interface MountBlock {
52
+ (): (() => void) | void;
53
+ }
54
+ interface UnmountBlock {
55
+ (): void;
56
+ }
57
+ /**
58
+ * Registers a callback to run just after the current Component has mounted.
59
+ *
60
+ * If a teardown callback is returned, it will be run just before the Component unmounts (equivalent
61
+ * to adding a separate `unmounted` block).
62
+ * @see {@link unmounted}
63
+ */
64
+ declare function mounted(block: MountBlock, lifecycle?: Lifecycle): void;
65
+ /**
66
+ * Registers a callback to run once the current Component is just about to unmount.
67
+ * @see {@link mounted}
68
+ */
69
+ declare function unmounted(block: UnmountBlock, lifecycle?: Lifecycle): void;
70
+ /**
71
+ * Gets the Lifecycle of the calling component.
72
+ */
73
+ declare function getLifecycle(): Lifecycle;
74
+ /**
75
+ * Runs a block of code with the provided Lifecycle. Calls to `getLifecycle` within the block will
76
+ * return the specified object.
77
+ * @see {@link getLifecycle}
78
+ */
79
+ declare function withLifecycle<TArgs extends [arg?: any], TReturn>(lifecycle: Lifecycle, block: (...args: TArgs) => TReturn, ...args: TArgs): TReturn;
80
+ //#endregion
81
+ //#region src/data/Atom.d.ts
82
+ /**
83
+ * Pyxis Atom type guard marker.
84
+ */
85
+ declare const S_ATOM: unique symbol;
86
+ /** Contract for Atoms where they need to be read. */
87
+ interface ReadonlyAtom<out T> extends DependencyList {
88
+ /** Pyxis Atom type guard marker. */
89
+ readonly [S_ATOM]: true;
90
+ /**
91
+ * Gets the value of this Atom. Only use this method when the target is guaranteed to be an
92
+ * Atom, otherwise it is recommended to use the `read` or `peek` functions.
93
+ *
94
+ * This method does *not* report access, thus within effects it is analogous to `peek`.
95
+ * @see {@link read}
96
+ * @see {@link peek}
97
+ */
98
+ get: () => T;
99
+ }
100
+ /**
101
+ * Holds any single value, managing reactions to its changes. Use the `read`, `write` functions to
102
+ * access its value.
103
+ * @see {@link read}
104
+ * @see {@link write}
105
+ */
106
+ interface Atom<T = unknown> extends ReadonlyAtom<T> {
107
+ /**
108
+ * Sets the value of this Atom. Does nothing if this Atom is readonly. Only use this method when
109
+ * the target is guaranteed to be an Atom, otherwise it is recommended to use the `write` or
110
+ * `update` functions.
111
+ *
112
+ * This method does *not* send out any change notifications to observers!
113
+ * @returns Boolean indicating whether the value of this Atom changed.
114
+ * @see {@link write}
115
+ * @see {@link update}
116
+ */
117
+ set: (value: T) => boolean;
118
+ }
119
+ /**
120
+ * Union of the given type or an Atom of that type. Use the `read`, `peek`, `write`, `update` or
121
+ * `isAtom` functions to interact with such values.
122
+ * @see {@link read}
123
+ * @see {@link peek}
124
+ * @see {@link write}
125
+ * @see {@link update}
126
+ * @see {@link isAtom}
127
+ */
128
+ type MaybeAtom<T> = Atom<T> | T;
129
+ /**
130
+ * Union of the given type or the ReadAtom contract of that type. Use the `read`, `peek` or `isAtom`
131
+ * functions to interact with such values.
132
+ * @see {@link read}
133
+ * @see {@link peek}
134
+ * @see {@link isAtom}
135
+ */
136
+ type MaybeReadonlyAtom<T> = ReadonlyAtom<T> | T;
137
+ /**
138
+ * Creates an empty Atom; i.e. value set to `undefined`.
139
+ */
140
+ declare function atomOf<T>(): Atom<T | undefined>;
141
+ /**
142
+ * Creates an Atom initialized to the provided value. If the provided value is already an Atom, it
143
+ * is returned as-is.
144
+ * @see {@link isAtom}
145
+ */
146
+ declare function atomOf<T>(initialValue: MaybeAtom<T>, lifecycle?: Lifecycle, devId?: string): Atom<T>;
147
+ /**
148
+ * Atom type guard, checks if the provided input is an Atom.
149
+ */
150
+ declare function isAtom<T = unknown>(input: Nil<MaybeAtom<T>>): input is Atom<T>;
151
+ declare function isAtom<T = unknown>(input: Nil<MaybeReadonlyAtom<T>>): input is ReadonlyAtom<T>;
152
+ declare function isAtom<T = unknown>(input: unknown): input is Atom<T>;
153
+ /**
154
+ * Checks if the provided input is an Atom and reads its value. Non-atom inputs are returned as-is.
155
+ * Reports read access when inside an effect.
156
+ * @see {@link isAtom}
157
+ * @see {@link write}
158
+ * @see {@link peek}
159
+ * @see {@link update}
160
+ */
161
+ declare function read<A>(input: A): A extends MaybeReadonlyAtom<infer T> ? T : never;
162
+ /**
163
+ * Checks if the provided input is an Atom and reads its value. Non-atom inputs are returned as-is.
164
+ * Does NOT report read access when inside an effect.
165
+ * @see {@link isAtom}
166
+ * @see {@link read}
167
+ * @see {@link write}
168
+ * @see {@link update}
169
+ */
170
+ declare function peek<A>(input: A): A extends MaybeReadonlyAtom<infer T> ? T : never;
171
+ /**
172
+ * Checks if the provided input is an Atom, writes its value and returns the new value.
173
+ *
174
+ * Non-atom inputs are never modified in any way. Instead the provided new value is discarded and
175
+ * the input is returned as-is.
176
+ * @see {@link isAtom}
177
+ * @see {@link read}
178
+ * @see {@link write}
179
+ * @see {@link update}
180
+ */
181
+ declare function write<A>(input: A, value: A extends Atom<infer T> ? T : never, force?: boolean): A extends MaybeAtom<infer T> ? T : never;
182
+ /**
183
+ * Checks if the provided input is an Atom, updates its value using the provided transform function
184
+ * and returns the new value.
185
+ *
186
+ * Non-atom inputs are never modified in any way and the input is returned as-is.
187
+ * @see {@link isAtom}
188
+ * @see {@link read}
189
+ * @see {@link peek}
190
+ * @see {@link write}
191
+ */
192
+ declare function update<A>(input: A, transform: A extends Atom<infer T> ? (value: T) => T : never, force?: boolean): A extends MaybeAtom<infer T> ? T : never;
193
+ //#endregion
194
+ //#region src/Component.d.ts
195
+ /**
196
+ * Represents a Pyxis Component function responsible for setting up a view model and returning a
197
+ * chunk of JSX to be rendered.
198
+ */
199
+ interface Component<TProps extends PropsType = {}> {
200
+ (props: TProps): JsxResult;
201
+ }
202
+ type PropsOf<T> = T extends Component<infer TProps> ? TProps : unknown;
203
+ /**
204
+ * Represents a template function returning a chunk of JSX to be rendered with specific input data.
205
+ */
206
+ interface DataTemplate<TData> {
207
+ (data: TData): JsxResult;
208
+ }
209
+ declare function component<TPropsArg extends [{}]>(block: (...args: TPropsArg) => JsxResult, devId?: string): (...args: [props: JsxProps<TPropsArg[0]>]) => JsxResult;
210
+ /**
211
+ * Infers the props object for use with JSX. Because Pyxis always supplies components with child
212
+ * arrays (or tuples), the type needs to be adjusted to reflect the internal mechanics.
213
+ */
214
+ type JsxProps<T> = { readonly [K in keyof T]: K extends "children" ? JsxChildrenProp<T[K]> : T[K]; } & ("children" extends keyof T ? {} : {
215
+ readonly children?: [];
216
+ });
217
+ /**
218
+ * When typing children as a single value tuple, it becomes unusable in 'react-jsx' mode. TS rejects
219
+ * valid uses of such components with the error: "This JSX tag's children prop expects type '[T]'
220
+ * which requires multiple children, but only a single child was provided."
221
+ *
222
+ * Likely related to the fact that single children are passed to jsx() factory without wrapping
223
+ * arrays.
224
+ *
225
+ * This utility type unwraps single value tuples, avoiding the problem.
226
+ */
227
+ type JsxChildrenProp<T> = T extends readonly [any, any, ...any[]] ? T extends readonly [...infer C] ? readonly [...C] : T : T extends readonly [infer SC] ? SC : T extends readonly (infer C)[] ? readonly C[] | C : T;
228
+ /**
229
+ * Primitive types accepted to render as text.
230
+ */
231
+ type JsxText = MaybeReadonlyAtom<Nil<string | number | boolean | bigint>>;
232
+ /**
233
+ * Describes the objects returned by JSX factories.
234
+ *
235
+ * Pyxis uses very lightweight factories returning the props object directly,
236
+ * adding a few extra props:
237
+ *
238
+ * - S_COMPONENT ... hidden, contains a reference to the ComponentHandler function
239
+ * - S_TAG_NAME ... hidden, specifies the tag name, only populated for native elements
240
+ * - children ... always present and always an array, empty array for childless components
241
+ */
242
+ interface JsxObject {
243
+ [propName: string]: unknown;
244
+ readonly children: readonly unknown[];
245
+ }
246
+ /**
247
+ * Union of all admissible values within JSX.
248
+ */
249
+ type JsxResult = JsxObject | JsxText;
250
+ /**
251
+ * The type of JSX elements accepted as individual children by common components.
252
+ */
253
+ type JsxChildren = JsxResult | readonly JsxChildren[];
254
+ /**
255
+ * Utility type adding the standard `children` prop to the given props type.
256
+ */
257
+ type WithChildren<T extends PropsType> = T & {
258
+ children?: JsxChildren;
259
+ };
260
+ //#endregion
261
+ //#region src/component/Fragment.d.ts
262
+ interface FragmentProps {
263
+ children?: Nil<JsxResult>[];
264
+ }
265
+ /**
266
+ * The built-in Fragment Component wrapping multiple Components.
267
+ */
268
+ declare function Fragment(props: JsxProps<FragmentProps>): JsxResult;
269
+ //#endregion
270
+ //#region src/data/ListDelta.d.ts
271
+ declare enum ChangeKind {
272
+ Change = 1,
273
+ Insert = 2,
274
+ Remove = 3,
275
+ Clear = 4
276
+ }
277
+ interface ListDelta<T> {
278
+ readonly changes: ListChange<T>[];
279
+ lengthChange: number;
280
+ }
281
+ type ListChange<T> = ListItemChanged<T> | ListItemInserted<T> | ListItemRemoved<T> | ListCleared;
282
+ interface ListItemChanged<T> {
283
+ kind: ChangeKind.Change;
284
+ index: number;
285
+ oldItem: T;
286
+ newItem: T;
287
+ }
288
+ interface ListItemInserted<T> {
289
+ kind: ChangeKind.Insert;
290
+ index: number;
291
+ newItem: T;
292
+ }
293
+ interface ListItemRemoved<T> {
294
+ kind: ChangeKind.Remove;
295
+ index: number;
296
+ oldItem: T;
297
+ }
298
+ interface ListCleared {
299
+ kind: ChangeKind.Clear;
300
+ index: number;
301
+ }
302
+ interface Equals<T> {
303
+ (item0: T, item1: T): boolean;
304
+ }
305
+ //#endregion
306
+ //#region src/data/List.d.ts
307
+ interface ReadonlyList<T> extends Iterable<T>, DependencyList {
308
+ /**
309
+ * Gets the size of this List.
310
+ * Reactive in effects and derivations.
311
+ */
312
+ size(): number;
313
+ /**
314
+ * Gets the item at the specified index. Return undefined when outside of the List's bounds.
315
+ * Reactive in effects and derivations.
316
+ */
317
+ get(index: number): T | undefined;
318
+ /**
319
+ * Gets a set of changes made to this List within the current tick. Returns null when no changes
320
+ * were made.
321
+ * Reactive in effects and derivations.
322
+ */
323
+ delta(): ListDelta<T> | null;
324
+ /**
325
+ * Gets the underlying array of items. The array is read-only, attempts to mutate this array
326
+ * will cause observers to go out of sync.
327
+ * Reactive in effects and derivations.
328
+ */
329
+ raw(): readonly T[];
330
+ /**
331
+ * Runs the provided callback for each item of this List.
332
+ * Reactive in effects and derivations.
333
+ */
334
+ forEach(callback: (item: T, index: number) => void, thisArg?: any): void;
335
+ }
336
+ interface List<T> extends ReadonlyList<T> {
337
+ /**
338
+ * Sets the item at the specified index to a new value.
339
+ * Observers are notified of this mutation.
340
+ * @throws RangeError when index is out of bounds.
341
+ */
342
+ set(index: number, item: T): void;
343
+ /**
344
+ * Removes all items from this List.
345
+ * Observers are notified of this mutation.
346
+ */
347
+ clear(): void;
348
+ /**
349
+ * Inserts a new item at the specified index.
350
+ * Observers are notified of this mutation.
351
+ * @throws RangeError when index is out of bounds.
352
+ */
353
+ insertAt(index: number, item: T): void;
354
+ /**
355
+ * Inserts a new item at the start of this List.
356
+ * Observers are notified of this mutation.
357
+ */
358
+ insertFirst(item: T): void;
359
+ /**
360
+ * Inserts a new item at the end of this List.
361
+ * Observers are notified of this mutation.
362
+ */
363
+ insertLast(item: T): void;
364
+ /**
365
+ * Attempts to find and remove the first matching item from this List.
366
+ * Observers are notified of this mutation.
367
+ * @returns true if an item was found and removed, false otherwise.
368
+ */
369
+ remove(item: T): boolean;
370
+ /**
371
+ * Removes the item at the specified index.
372
+ * Observers are notified of this mutation.
373
+ * @returns the removed item.
374
+ * @throws RangeError when index is out of bounds.
375
+ */
376
+ removeAt(index: number): T;
377
+ /**
378
+ * Attempts to remove the first item of this List.
379
+ * Observers are notified of this mutation.
380
+ * @returns the removed item, or undefined if the List is empty.
381
+ */
382
+ removeFirst(): T | undefined;
383
+ /**
384
+ * Attempts to remove the last item of this List.
385
+ * Observers are notified of this mutation.
386
+ * @returns the removed item, or undefined if the List is empty.
387
+ */
388
+ removeLast(): T | undefined;
389
+ }
390
+ /**
391
+ * Creates an empty List. This List emits deltas with each mutation which can be observed by
392
+ * Components to efficiently update the rendered state.
393
+ */
394
+ declare function listOf<T>(): List<T>;
395
+ declare function listOf<T>(source: Nil<never>, lifecycle?: Lifecycle, devId?: string): List<T>;
396
+ /**
397
+ * Creates a List initialized with items copied from the provided Iterable. This List emits deltas
398
+ * with each mutation which can be observed by Components to efficiently update the rendered state.
399
+ */
400
+ declare function listOf<T>(source: Iterable<T>, lifecycle?: Lifecycle, devId?: string): List<T>;
401
+ /**
402
+ * Synchronizes the provided List with the given data source. After this operation, the list will
403
+ * contain an exact copy of the source.
404
+ *
405
+ * Note: This function is separated instead of being a List method since the underlying diff
406
+ * algorithm (Myers) is a relatively large chunk of code which would otherwise always get included
407
+ * into bundled builds. This way, tools like Terser can eliminate the extra code when unused.
408
+ */
409
+ declare function sync<T>(list: List<T>, source: readonly T[], eq?: Equals<T>): void;
410
+ //#endregion
411
+ //#region src/data/ProxyAtom.d.ts
412
+ interface ProxyAtom<T> extends Atom<T> {
413
+ /**
414
+ * Binds this ProxyAtom to a new value. If it is an Atom, the proxy will mirror it, otherwise it
415
+ * will be a read-only atom with a static value until rebound.
416
+ */
417
+ use(value: MaybeAtom<T>): void;
418
+ }
419
+ /**
420
+ * Creates a ProxyAtom bound to the provided initial value. If it is an Atom, the proxy will mirror
421
+ * it, otherwise it will be a read-only atom with a static value until rebound.
422
+ */
423
+ declare function proxyOf<T>(initialValue: MaybeAtom<T>, lifecycle?: Lifecycle): ProxyAtom<T>;
424
+ type Proxied<T, P extends readonly (keyof T)[]> = {
425
+ readonly proxied: T;
426
+ } & { readonly [K in P[number]]: ProxyAtom<T[K] extends MaybeAtom<infer V> ? V : T[K]>; };
427
+ //#endregion
428
+ //#region src/component/Iterator.d.ts
429
+ interface RemountIteratorProps<T> {
430
+ source: ReadonlyList<T>;
431
+ proxy?: never;
432
+ children: [template: DataTemplate<T>];
433
+ }
434
+ interface ProxyIteratorProps<T, P extends readonly (keyof T)[]> {
435
+ source: ReadonlyList<T>;
436
+ proxy: P;
437
+ children: [template: DataTemplate<Proxied<T, P>>];
438
+ }
439
+ /**
440
+ * The built-in Iterator Component efficiently rendering collections of items
441
+ * based on updates from a Pyxis `list`.
442
+ */
443
+ declare function Iterator<T>(props: JsxProps<RemountIteratorProps<T>>): JsxResult;
444
+ declare function Iterator<T, P extends readonly (keyof T)[]>(props: JsxProps<ProxyIteratorProps<T, P>>): JsxResult;
445
+ //#endregion
446
+ //#region src/data/Scheduler.d.ts
447
+ /**
448
+ * A function able to schedule a callback to be executed at a later time, e.g. `queueMicrotask`.
449
+ * The function must guarantee that the callback will be eventually executed.
450
+ */
451
+ interface TickFn {
452
+ (onTick: () => void): void;
453
+ }
454
+ /**
455
+ * Runs a block of code on the next tick of the scheduler, synchronized with other updates. If a
456
+ * tick is not currently pending, a new one is scheduled.
457
+ */
458
+ declare function tick(block: () => void, lifecycle?: Lifecycle): void;
459
+ /**
460
+ * Runs a block of code after the next tick of the scheduler, once all regular updates finished.
461
+ * If a tick is not currently pending, a new one is scheduled.
462
+ */
463
+ declare function tock(block: () => void, lifecycle?: Lifecycle): void;
464
+ //#endregion
465
+ //#region src/Adapter.d.ts
466
+ interface Adapter<TNode, TIntrinsicElements extends ElementsType = ElementsType> {
467
+ /**
468
+ * Carries information about the available intrinsic elements when using this Adapter.
469
+ * @deprecated **Type only, does not exist at runtime!**
470
+ */
471
+ readonly $elements?: TIntrinsicElements;
472
+ /**
473
+ * A function able to schedule a callback to be executed at a later time, e.g. `queueMicrotask`.
474
+ * The function must guarantee that the callback will be eventually executed.
475
+ */
476
+ readonly tick: TickFn;
477
+ /**
478
+ * Creates a native (intrinsic) element node by its name.
479
+ */
480
+ readonly element: (name: string) => TNode;
481
+ /**
482
+ * Creates or updates a text node. In both cases the node is returned.
483
+ */
484
+ readonly text: (value: string, node: TNode | null) => TNode;
485
+ /**
486
+ * Creates a marker node used to preserve a position within the node tree.
487
+ */
488
+ readonly marker: (comment?: string) => TNode;
489
+ /**
490
+ * Creates a batch to which nodes can be inserted "offline," without causing any updates. The
491
+ * batch is later inserted all at once using the `insert` function, causing only a single
492
+ * update.
493
+ *
494
+ * Adapters may omit this function when batching is not supported.
495
+ */
496
+ readonly batch?: () => TNode;
497
+ /**
498
+ * Inserts the given `node` as a child of the `parent`. If `before` is provided, the child will
499
+ * be inserted just before the referenced node, otherwise the child is inserted as the new last
500
+ * child.
501
+ */
502
+ readonly insert: (node: TNode, parent: TNode, before: TNode | null) => void;
503
+ /**
504
+ * Removes a node from the hierarchy.
505
+ */
506
+ readonly remove: (node: TNode) => void;
507
+ /**
508
+ * Sets a named property of the given node.
509
+ */
510
+ readonly set: (node: TNode, prop: string, value: any) => void;
511
+ }
512
+ interface Extension<TNode, TExtensionKey extends string = string, TIntrinsicElements extends ElementsType = ElementsType, TExtendedIntrinsicElements extends ElementsType = ElementsType> {
513
+ /**
514
+ * Infers prop types to decorate existing types with extensions.
515
+ * Type only, this call signature does not exist at runtime!
516
+ */
517
+ (extensionKey: TExtensionKey, intrinsicElements: TIntrinsicElements): TExtendedIntrinsicElements;
518
+ /**
519
+ * Sets a named extension property of the given node.
520
+ */
521
+ readonly set: (node: TNode, prop: string, value: any, group: MountingGroup<TNode>) => void;
522
+ }
523
+ type ExtensionsType<TNode> = { [_ in string]?: Extension<TNode>; };
524
+ type ExtensionProps<TExtensionKey extends string, TProps extends PropsType> = Intersection<{ [TPropKey in keyof TProps]-?: TPropKey extends string ? { readonly [_ in `${TExtensionKey}:${TPropKey}`]?: TProps[TPropKey]; } : never; }[keyof TProps]>;
525
+ //#endregion
526
+ //#region src/Renderer.d.ts
527
+ interface Renderer<TNode, TIntrinsicElements extends ElementsType = ElementsType> {
528
+ /**
529
+ * Carries information about the available intrinsic elements when using this Renderer.
530
+ * @deprecated **Type only, does not exist at runtime!**
531
+ */
532
+ readonly $elements?: TIntrinsicElements;
533
+ mount: (root: TNode, jsx: JsxResult) => void;
534
+ unmount: () => void;
535
+ }
536
+ type ElementsOf<TRenderer> = TRenderer extends {
537
+ readonly $elements?: infer TElements;
538
+ } ? TElements : {};
539
+ interface MountingGroup<TNode> extends Lifecycle, Hierarchy<TNode> {
540
+ readonly $isGroup: true;
541
+ readonly $isNative?: never;
542
+ /** the Adapter rendering this MountingGroup */
543
+ readonly adapter: Adapter<TNode>;
544
+ }
545
+ interface NativeNode<TNode> extends Hierarchy<TNode> {
546
+ readonly $isNative: true;
547
+ readonly $isGroup?: never;
548
+ readonly $nn: TNode;
549
+ }
550
+ interface Hierarchy<TNode> {}
551
+ type HNode<TNode> = MountingGroup<TNode> | NativeNode<TNode>;
552
+ /**
553
+ * Creates a sub-group within the provided MountingGroup. Needed whenever a subtree needs to mount
554
+ * or unmount dynamically.
555
+ */
556
+ declare function fork<TNode>(hParent: HNode<TNode>, hBefore?: HNode<TNode> | null): MountingGroup<TNode>;
557
+ /**
558
+ * Adds a HNode to the hierarchy.
559
+ */
560
+ declare function track<TNode>(hNode: HNode<TNode>, hParent: HNode<TNode>, hBefore?: HNode<TNode> | null): void;
561
+ /**
562
+ * Removes a HNode from the tracking hierarchy.
563
+ */
564
+ declare function untrack<TNode>(hNode: HNode<TNode>): void;
565
+ /**
566
+ * Mounts a MountingGroup to the specified location in the node tree. If the group is already
567
+ * mounted (i.e. its native nodes are already rendered somewhere), it is moved to the new location
568
+ * without re-mounting Pyxis components.
569
+ *
570
+ * Note that for successfully moving a group within the tree, you should first `untrack` the group,
571
+ * then re-`track` it to the new location and only then call `mount` to commit the move.
572
+ * @see {@link track}
573
+ * @see {@link untrack}
574
+ */
575
+ declare function mount<TNode>(jsx: any, hGroup: MountingGroup<TNode>, nUsedParent: TNode, nRealParent: TNode, nBefore: TNode | null, isBatch: boolean): void;
576
+ /**
577
+ * Unmounts the contents of a MountingGroup from the node tree. The group itself, though empty,
578
+ * remains usable and can be remounted later.
579
+ */
580
+ declare function unmount<TNode>(group: MountingGroup<TNode>): void;
581
+ /**
582
+ * Mounts components described by the JsxResult to the specified location in the node tree.
583
+ */
584
+ declare function mountJsx<TNode>(jsx: any, hParent: HNode<TNode>, nUsedParent: TNode, nRealParent: TNode, nBefore: TNode | null, isBatch: boolean): void;
585
+ /**
586
+ * Inserts a native node and adds it to the tracking hierarchy. Necessary to preserve render order.
587
+ * Should only be called by component handlers!
588
+ */
589
+ declare function insert<TNode>(nNode: TNode, children: any, hParent: HNode<TNode>, nUsedParent: TNode, nBefore: TNode | null, isBatch: boolean): void;
590
+ //#endregion
591
+ //#region src/component/Native.d.ts
592
+ declare function Native<TNode>(jsx: JsxObject, hParent: HNode<TNode>, nUsedParent: TNode, _nRealParent: TNode, nBefore: TNode | null, isBatch: boolean): void;
593
+ //#endregion
594
+ //#region src/component/Show.d.ts
595
+ interface ShowProps {
596
+ when?: MaybeAtom<boolean>;
597
+ children: JsxChildren;
598
+ }
599
+ interface ShowDataProps<T> {
600
+ when?: MaybeAtom<boolean>;
601
+ proxy?: never;
602
+ data: MaybeAtom<T>;
603
+ children: [template: DataTemplate<T> | ReadonlyAtom<Nil<DataTemplate<T>>>];
604
+ }
605
+ interface ShowProxyDataProps<T, P extends readonly (keyof T)[]> {
606
+ when?: MaybeAtom<boolean>;
607
+ proxy: P;
608
+ data: MaybeAtom<T>;
609
+ children: [template: DataTemplate<Proxied<T, P>> | ReadonlyAtom<Nil<DataTemplate<Proxied<T, P>>>>];
610
+ }
611
+ /**
612
+ * The built-in Show Component dynamically mounting and unmounting a Template
613
+ * based on a reactive condition result.
614
+ */
615
+ declare function Show(props: JsxProps<ShowProps>): JsxResult;
616
+ declare function Show<T>(props: JsxProps<ShowDataProps<T>>): JsxResult;
617
+ declare function Show<T, P extends readonly (keyof T)[]>(props: JsxProps<ShowProxyDataProps<T, P>>): JsxResult;
618
+ //#endregion
619
+ //#region src/data/Context.d.ts
620
+ /**
621
+ * Describes a Context distributing data throughout the Component hierarchy.
622
+ * @see {@link createContext}
623
+ */
624
+ interface Context<T> {
625
+ /**
626
+ * A fake property kept for TypeScript to properly type-check Context compatibility.
627
+ * @deprecated **Type only, does not exist at runtime!**
628
+ */
629
+ readonly $contract?: (value: T) => void;
630
+ }
631
+ /**
632
+ * Creates a typed Context that can be used to propagate observable data throughout entire component
633
+ * trees without "prop drilling."
634
+ * @see {@link context}
635
+ */
636
+ declare function createContext<T>(devId?: string): Context<T>;
637
+ interface ContextAtom<T> extends Atom<T> {
638
+ $dep?: Nil<Dependency>;
639
+ $ancestor?: Nil<Atom<T>>;
640
+ $value?: T;
641
+ }
642
+ /**
643
+ * Gets a consumer Atom for the given Context. This atom will be read-only.
644
+ * @see {@link host}
645
+ */
646
+ declare function consumerOf<T>(context: Context<T>): Atom<T> | null;
647
+ /**
648
+ * Marks the current component as a host for the given context. Returns a mutable ContextAtom;
649
+ * Values written to it will be propagated to any descendant component that consumes the context via
650
+ * `consumerOf(context)`.
651
+ * @see {@link consumerOf}
652
+ */
653
+ declare function host<T>(context: Context<T>, defaultValue?: T, devId?: string): ContextAtom<T>;
654
+ //#endregion
655
+ //#region src/data/Effect.d.ts
656
+ interface EffectBlock {
657
+ (): (() => void) | void;
658
+ }
659
+ interface Effect<T> {}
660
+ /**
661
+ * Creates an Effect - a block of logic executed each time any of the Atoms accessed within it
662
+ * change. The block is first synchronously executed when the Effect is created.
663
+ *
664
+ * If a teardown callback is returned, it will be run before the next effect re-run, or on component
665
+ * unmount.
666
+ */
667
+ declare function effect(block: EffectBlock, lifecycle?: Lifecycle): void;
668
+ //#endregion
669
+ //#region src/data/Derivation.d.ts
670
+ /**
671
+ * Holds a value derived from values of other Atoms, managing reactions to their changes.
672
+ * Derivations are read-only. Use the `read` function to access its value.
673
+ * @see {@link read}
674
+ */
675
+ interface Derivation<T = unknown> extends Atom<T>, Effect<T> {}
676
+ /**
677
+ * Creates a Derivation - an Atom with its value computed from other Atoms. The block runs once
678
+ * eagerly to compute the initial value, then re-runs within scheduler ticks whenever its source
679
+ * Atoms change. Observers are only notified if the new value differs from the previous.
680
+ */
681
+ declare function derived<T>(block: () => T, lifecycle?: Lifecycle): Derivation<T>;
682
+ //#endregion
683
+ //#region src/extension/RefExtension.d.ts
684
+ interface RefExtensionType {
685
+ <TExtensionKey extends string, TElements extends ElementsType>(extensionKey: TExtensionKey, elements: TElements): { [TElementName in keyof TElements]: TElements[TElementName] & ExtensionProps<TExtensionKey, {
686
+ readonly atom?: Atom<NodeType<TElements[TElementName]> | null>;
687
+ readonly call?: RefFn<NodeType<TElements[TElementName]>>;
688
+ }>; };
689
+ set: (node: any, prop: string, value: any, group?: MountingGroup<any>) => void;
690
+ }
691
+ interface RefFn<TNode> {
692
+ (node: TNode | null): void;
693
+ }
694
+ /**
695
+ * Extension adding direct reference access to any element. Recommended prefix:
696
+ * `"ref"`
697
+ *
698
+ * References can be stored into atoms:
699
+ * ```tsx
700
+ * const wrapperRef = atomOf<HTMLDivElement>();
701
+ * <div ref:atom={wrapperRef} />
702
+ * ```
703
+ * or handled with a custom callback:
704
+ * ```tsx
705
+ * const onWrapperRef = (node: HTMLDivElement) => { ... };
706
+ * <div ref:call={onWrapperRef} />
707
+ * ```
708
+ */
709
+ declare const RefExtension: RefExtensionType;
710
+ //#endregion
711
+ //#region src/support/text.d.ts
712
+ /**
713
+ * A template literal tag that automatically wraps each substitution in a `read` call.
714
+ * @see {@link read}
715
+ */
716
+ declare function reads(strings: TemplateStringsArray, ...values: JsxText[]): string;
717
+ /**
718
+ * A template literal tag that automatically wraps each substitution in a `peek` call.
719
+ * @see {@link peek}
720
+ */
721
+ declare function peeks(strings: TemplateStringsArray, ...values: JsxText[]): string;
722
+ //#endregion
723
+ //#region src/Builder.d.ts
724
+ interface PyxisBuilder<TNode, TIntrinsicElements extends ElementsType> {
725
+ build: () => Renderer<TNode, TIntrinsicElements>;
726
+ extend: <TExtensionKey extends string, TExtendedIntrinsicElements extends ElementsType>(extensionKey: TExtensionKey, extension: (extensionKey: TExtensionKey, intrinsicElements: TIntrinsicElements) => TExtendedIntrinsicElements) => PyxisBuilder<TNode, TExtendedIntrinsicElements>;
727
+ }
728
+ declare function pyxis<TNode, TIntrinsicElements extends ElementsType>(adapter: Adapter<TNode, TIntrinsicElements>): PyxisBuilder<TNode, TIntrinsicElements>;
729
+ //#endregion
730
+ //#region src/jsx.d.ts
731
+ declare function jsx(tagName: string, props: PropsType, key?: any): JsxResult;
732
+ declare function jsx<TProps extends PropsType>(component: Component<TProps>, props: TProps, key?: any): JsxResult;
733
+ declare function jsxs(tagName: string, props: PropsType, key?: any): JsxResult;
734
+ declare function jsxs<TProps extends PropsType>(component: Component<TProps>, props: TProps, key?: any): JsxResult;
735
+ //#endregion
736
+ export { type Adapter, type Atom, ChangeKind, type Component, type Context, type DataTemplate, type Derivation, type EffectBlock, type ElementsOf, type ElementsType, type Equals, type Extension, type ExtensionProps, type ExtensionsType, Fragment, type FragmentProps, type HNode, type Intersection, Iterator, type JsxChildren, type JsxChildrenProp, type JsxObject, type JsxProps, type JsxResult, type JsxText, type Lifecycle, type List, type ListChange, type ListCleared, type ListDelta, type ListItemChanged, type ListItemInserted, type ListItemRemoved, type MaybeAtom, type MaybeReadonlyAtom, type MountBlock, type MountingGroup, Native, type Nil, type NodeType, type PropsOf, type PropsType, type Proxied, type ProxyAtom, type ProxyIteratorProps, type PyxisBuilder, type ReadonlyAtom, type ReadonlyList, RefExtension, type RefExtensionType, type RefFn, type RemountIteratorProps, type Renderer, type S_ATOM, type S_NODE_TYPE, Show, type ShowProps, type TickFn, type UnmountBlock, type WithChildren, atomOf, bind, component, consumerOf, createContext, derived, effect, fork, getLifecycle, host, insert, isAtom, jsx, jsxs, listOf, mount, mountJsx, mounted, peek, peeks, proxyOf, pyxis, read, reads, sync, tick, tock, track, unmount, unmounted, untrack, update, withLifecycle, write };
737
+ //# sourceMappingURL=core.d.ts.map