sia-reactor 0.0.2 → 0.0.4

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/utils.d.ts CHANGED
@@ -1,11 +1,498 @@
1
- export { d as deepClone, a as deleteAny, g as getAny, b as getTrailPaths, c as getTrailRecords, i as inAny, e as inBoolArrOpt, f as isArr, h as isDef, j as isIter, k as isObj, l as isStrictObj, m as mergeObjs, n as nuke, p as parseAnyObj, o as parseEvOpts, s as setAny } from './index-DBfVdpnb.js';
2
- import { CamelCase, TitleCase, NoCamelCase } from './types.js';
1
+ type Primitive = string | number | boolean | bigint | symbol | null | undefined;
3
2
 
4
- declare function capitalize<T extends string>(word?: T): TitleCase<T>;
5
- declare function camelize<T extends string>(str?: T, { source }?: RegExp, { preserveInnerCase: pIC, upperFirst: uF }?: {
6
- preserveInnerCase?: boolean | undefined;
7
- upperFirst?: boolean | undefined;
8
- }): CamelCase<T>;
9
- declare function uncamelize<T extends string, S extends string = " ">(str: T, separator?: S): NoCamelCase<T, S>;
3
+ type NoTraverse =
4
+ | Primitive
5
+ | Function
6
+ | Date
7
+ | Error
8
+ | RegExp
9
+ | Promise<any>
10
+ | Map<any, any>
11
+ | WeakMap<any, any>
12
+ | Set<any>
13
+ | WeakSet<any>
14
+ | HTMLElement
15
+ | Element
16
+ | Node
17
+ | EventTarget
18
+ | Window
19
+ | Document
20
+ | DOMTokenList
21
+ | AbortSignal
22
+ | Inert<unknown>;
10
23
 
11
- export { camelize, capitalize, uncamelize };
24
+ type Paths<T, S extends string = ".", D extends number = RDepth> = [D] extends [0]
25
+ ? never // Circuit Breaker Triggered
26
+ : T extends NoTraverse
27
+ ? never
28
+ : T extends readonly (infer U)[]
29
+ ? `${Extract<keyof T, number>}` | `${Extract<keyof T, number>}${S}${Paths<U, S, RPrev[D]>}`
30
+ : {
31
+ [K in keyof T & (string | number)]: T[K] extends Primitive
32
+ ? `${K}`
33
+ : `${K}` | `${K}${S}${Paths<T[K], S, RPrev[D]>}`;
34
+ }[keyof T & (string | number)];
35
+ type WildPaths<T, S extends string = "."> = "*" | Paths<T, S>;
36
+ type ChildPaths<T, P extends WildPaths<T>, S extends string = "."> = P extends "*"
37
+ ? Paths<T, S>
38
+ : P | Extract<Paths<T, S>, `${P}${S}${string}`>;
39
+
40
+ type PathKey<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
41
+ ? keyof T & (string | number) // Or: DeepKeys<T>
42
+ : PathLeaf<P, S>; // Loose since reactor just slices strings
43
+ type StrictPathKey<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
44
+ ? keyof T & (string | number) // Or: DeepKeys<T>
45
+ : P extends `${infer K}${S}${infer Rest}`
46
+ ? K extends keyof T
47
+ ? StrictPathKey<T[K], Rest, S>
48
+ : never
49
+ : P extends keyof T
50
+ ? P
51
+ : never; // Strict since it returns existing keys only
52
+
53
+ type PathValue<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
54
+ ? any // Or: DeepValues<T>
55
+ : P extends `${infer K}${S}${infer Rest}`
56
+ ? K extends keyof T
57
+ ? PathValue<T[K], Rest, S>
58
+ : never
59
+ : P extends keyof T
60
+ ? T[P]
61
+ : never;
62
+
63
+ type PathBranchValue<T, P extends string = Paths<T>, S extends string = "."> = P extends "*"
64
+ ? any // Or: DeepValues<T>
65
+ : P extends `${string}${S}${string}`
66
+ ? PathValue<T, PathBranch<P, S>, S>
67
+ : T;
68
+
69
+ type Unflatten<T extends object, S extends string = "."> = UnionToIntersection<
70
+ {
71
+ [K in keyof T & string]: UnflattenKey<K, T[K], S>;
72
+ }[keyof T & string]
73
+ >; // Turns dotted keys into nested objects while preserving value types
74
+ type UnflattenKey<
75
+ K extends string,
76
+ V,
77
+ S extends string,
78
+ > = K extends `${infer Head}${S}${infer Tail}`
79
+ ? { [P in Head]: UnflattenKey<Tail, V, S> }
80
+ : { [P in K]: V };
81
+
82
+ // Helpers
83
+ type PathLeaf<
84
+ P extends string,
85
+ S extends string = ".",
86
+ > = P extends `${infer _Head}${S}${infer Tail}` ? PathLeaf<Tail, S> : P;
87
+
88
+ type PathBranch<
89
+ P extends string,
90
+ S extends string = ".",
91
+ > = P extends `${infer Head}${S}${infer Tail}`
92
+ ? Tail extends `${string}${S}${string}`
93
+ ? `${Head}${S}${PathBranch<Tail, S>}`
94
+ : Head
95
+ : never;
96
+
97
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
98
+ k: infer I,
99
+ ) => void
100
+ ? I
101
+ : never;
102
+
103
+ // --- "It's not that deep" WARRIORS ---
104
+ type DeepKeys<T, D extends number = RDepth> = [D] extends [0]
105
+ ? never
106
+ : T extends NoTraverse
107
+ ? never
108
+ : T extends readonly any[]
109
+ ? DeepKeys<T[number], RPrev[D]>
110
+ : {
111
+ [K in keyof T & (string | number)]: K | DeepKeys<T[K], RPrev[D]>;
112
+ }[keyof T & (string | number)];
113
+
114
+ type DeepMerge<T1, T2, D extends number = RDepth> = [D] extends [0]
115
+ ? never
116
+ : T2 extends object
117
+ ? T1 extends object
118
+ ? {
119
+ [K in keyof T1 | keyof T2]: K extends keyof T2
120
+ ? K extends keyof T1
121
+ ? DeepMerge<T1[K], T2[K], RPrev[D]>
122
+ : T2[K]
123
+ : K extends keyof T1
124
+ ? T1[K]
125
+ : never;
126
+ }
127
+ : T2
128
+ : T2;
129
+
130
+ type DeepPartial<T, D extends number = RDepth> = [D] extends [0]
131
+ ? never
132
+ : T extends Function
133
+ ? T
134
+ : T extends Array<infer U>
135
+ ? Array<DeepPartial<U, RPrev[D]>>
136
+ : T extends ReadonlyArray<infer U>
137
+ ? ReadonlyArray<DeepPartial<U, RPrev[D]>>
138
+ : T extends object
139
+ ? { [P in keyof T]?: DeepPartial<T[P], RPrev[D]> }
140
+ : T;
141
+
142
+ type DeepRequired<T, D extends number = RDepth> = [D] extends [0]
143
+ ? never
144
+ : T extends Function
145
+ ? T
146
+ : T extends Array<infer U>
147
+ ? Array<DeepRequired<U, RPrev[D]>>
148
+ : T extends ReadonlyArray<infer U>
149
+ ? ReadonlyArray<DeepRequired<U, RPrev[D]>>
150
+ : T extends object
151
+ ? { [P in keyof T]-?: DeepRequired<T[P], RPrev[D]> }
152
+ : T;
153
+
154
+ // --- RECURSION LIMITERS ---
155
+ type RDepth = 10; // current limit for state trees, observed ts max - 19; limit needed cuz of ts bundlers
156
+ // This tuple maps a number to the number below it (Index 4 contains 3) allowing `RPrev[D]` to subtract 1 from our depth.
157
+ type RPrev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];
158
+
159
+ declare const methods: readonly ["tick", "stall", "nostall", "get", "gonce", "noget", "set", "sonce", "noset", "delete", "donce", "nodelete", "watch", "wonce", "nowatch", "on", "once", "off", "cascade", "snapshot", "reset", "destroy"];
160
+ type Method = (typeof methods)[number];
161
+ type Prefix<P extends ReactivePrefs | undefined> = P extends {
162
+ prefix?: infer X extends string;
163
+ } ? X : "";
164
+ type Suffix<P extends ReactivePrefs | undefined> = P extends {
165
+ suffix?: infer X extends string;
166
+ } ? X : "";
167
+ type Whitelist<P extends ReactivePrefs | undefined> = P extends {
168
+ whitelist?: infer W extends readonly Method[];
169
+ } ? W[number] : never;
170
+ type ReactiveMethodMap<T extends object, P extends ReactivePrefs | undefined> = {
171
+ [K in Method as [Prefix<P>, Suffix<P>] extends ["", ""] ? (P extends {
172
+ whitelist: readonly Method[];
173
+ } ? (K extends Whitelist<P> ? never : K) : K) : P extends {
174
+ whitelist: readonly Method[];
175
+ } ? (K extends Whitelist<P> ? `${Prefix<P>}${K}${Suffix<P>}` : K) : `${Prefix<P>}${K}${Suffix<P>}`]: Pick<Reactor<T>, Method>[K];
176
+ };
177
+ interface ReactivePrefs {
178
+ prefix?: string;
179
+ suffix?: string;
180
+ whitelist?: readonly Method[];
181
+ }
182
+ type Reactive<T extends object, P extends ReactivePrefs | undefined = undefined> = T & ReactiveMethodMap<T, P> & {
183
+ __Reactor__: Reactor<T>;
184
+ };
185
+ declare function reactive<T extends object, const P extends ReactivePrefs | undefined = undefined>(target: T | Reactor<T>, options?: ReactorOptions<T>, prefs?: P): Reactive<T, P>;
186
+ declare function inert<T extends object>(target: T): Inert<T>;
187
+ declare function live<T extends object>(target: T): Live<T>;
188
+ declare function isInert<T extends object>(target: T): target is Inert<T>;
189
+ declare function intent<T extends object>(target: T): Intent<T>;
190
+ declare function state<T extends object>(target: T): State<T>;
191
+ declare function isIntent<T extends object>(target: T): target is Intent<T>;
192
+ declare function volatile<T extends object>(target: T): Volatile<T>;
193
+ declare function stable<T extends object>(target: T): Stable<T>;
194
+ declare function isVolatile<T extends object>(target: T): target is Volatile<T>;
195
+ declare function getVersion<T extends object>(target: T): number;
196
+ declare function getSnapshotVersion<T extends object>(target: T): number;
197
+
198
+ // ===========================================================================
199
+ // CORE MARKERS & STATE WRAPPERS
200
+ // ===========================================================================
201
+
202
+ type Inert<T> = T & { [INERTIA]?: true };
203
+ type Live<T> = T extends Inert<infer U> ? U : T;
204
+
205
+ type Intent<T> = T & { [REJECTABLE]?: true };
206
+ type State<T> = T extends Intent<infer U> ? U : T;
207
+
208
+ type Volatile<T> = T & { [INDIFFABLE]?: true };
209
+ type Stable<T> = T extends Volatile<infer U> ? U : T;
210
+
211
+
212
+ // ===========================================================================
213
+ // EVENT SYSTEM & PAYLOADS
214
+ // ===========================================================================
215
+
216
+ interface Target<T, P extends WildPaths<T> = WildPaths<T>> {
217
+ path: P;
218
+ value: PathValue<T, P>;
219
+ oldValue?: PathValue<T, P>;
220
+ key: PathKey<T, P>;
221
+ object: PathBranchValue<T, P>;
222
+ }
223
+
224
+ // Discriminated Payload Type (Creates the IDE magic)
225
+ type Payload<T, P extends WildPaths<T> = WildPaths<T>> =
226
+ | DirectPayload<T, P>
227
+ | UpdatePayload<T, P>;
228
+
229
+ interface BasePayload<T, P extends WildPaths<T> = WildPaths<T>> {
230
+ currentTarget: Target<T, P>; // use this to survive shape changes from nesting
231
+ root: T;
232
+ terminated?: boolean; // for mediators to signal operation termination but doesn't stop the chain
233
+ rejectable: boolean;
234
+ }
235
+ interface DirectPayload<T, P extends WildPaths<T> = WildPaths<T>> extends BasePayload<T, P> {
236
+ type: "init" | "get" | "set" | "delete"; // init during `immediate: true` sync
237
+ target: Target<T, P>;
238
+ }
239
+ interface UpdatePayload<T, P extends WildPaths<T> = WildPaths<T>> extends BasePayload<T, P> {
240
+ type: "update";
241
+ target: Target<T, ChildPaths<T, P>>; // Target is strictly one of the child paths!
242
+ }
243
+
244
+ // Discriminated Event Type (Creates the IDE magic)
245
+ type REvent<T, P extends WildPaths<T> = WildPaths<T>> =
246
+ | (Omit<ReactorEvent<T, P>, OverrideEvProp> &
247
+ DirectPayload<T, P> &
248
+ OverrideEvPart<DirectPayload<T, P>>)
249
+ | (Omit<ReactorEvent<T, P>, OverrideEvProp> &
250
+ UpdatePayload<T, P> &
251
+ OverrideEvPart<UpdatePayload<T, P>>);
252
+
253
+ type OverrideEvProp = "type" | "target" | "value" | "oldValue" | "path";
254
+ interface OverrideEvPart<PL extends { target: { path: any; value: any; oldValue?: any } }> {
255
+ path: PL["target"]["path"];
256
+ value: PL["target"]["value"];
257
+ oldValue: PL["target"]["oldValue"];
258
+ }
259
+
260
+ // ===========================================================================
261
+ // REACTIVITY CALLBACKS (The Handlers)
262
+ // ===========================================================================
263
+
264
+ type Getter<T, P extends WildPaths<T> = WildPaths<T>> = (
265
+ value: PathValue<T, P>,
266
+ payload: Payload<T, P>,
267
+ ) => PathValue<T, P> | undefined;
268
+
269
+ type Setter<T, P extends WildPaths<T> = WildPaths<T>> = (
270
+ value: PathValue<T, P>,
271
+ terminated: boolean,
272
+ payload: Payload<T, P>,
273
+ ) => PathValue<T, P> | typeof TERMINATOR | undefined;
274
+
275
+ type Deleter<T, P extends WildPaths<T> = WildPaths<T>> = (
276
+ terminated: boolean,
277
+ payload: Payload<T, P>,
278
+ ) => typeof TERMINATOR | undefined;
279
+
280
+ type Watcher<T, P extends WildPaths<T> = WildPaths<T>> = (
281
+ value: PathValue<T, P>,
282
+ payload: Payload<T, P>,
283
+ ) => void;
284
+
285
+ type Listener<T, P extends WildPaths<T> = WildPaths<T>> = (event: REvent<T, P>) => void;
286
+
287
+ // ===========================================================================
288
+ // ENGINE RECORDS (Internal Storage)
289
+ // ===========================================================================
290
+
291
+ type GetterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
292
+ cb: Getter<T, P>;
293
+ clup: () => ReturnType<Reactor<T>["noget"]>;
294
+ sclup?: () => void;
295
+ } & SyncOptionsTuple;
296
+
297
+ type SetterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
298
+ cb: Setter<T, P>;
299
+ clup: () => ReturnType<Reactor<T>["noset"]>;
300
+ sclup?: () => void;
301
+ } & SyncOptionsTuple;
302
+
303
+ type DeleterRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
304
+ cb: Deleter<T, P>;
305
+ clup: () => ReturnType<Reactor<T>["nodelete"]>;
306
+ sclup?: () => void;
307
+ } & SyncOptionsTuple;
308
+
309
+ type WatcherRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
310
+ cb: Watcher<T, P>;
311
+ clup: () => ReturnType<Reactor<T>["nowatch"]>;
312
+ sclup?: () => void;
313
+ } & SyncOptionsTuple;
314
+
315
+ type ListenerRecord<T extends object, P extends WildPaths<T> = WildPaths<T>> = {
316
+ cb: Listener<T, P>;
317
+ clup: () => ReturnType<Reactor<T>["off"]>;
318
+ sclup?: () => void;
319
+ } & ListenerOptionsTuple;
320
+
321
+ // ===========================================================================
322
+ // CONFIGURATION OPTIONS
323
+ // ===========================================================================
324
+
325
+ interface SyncOptionsTuple {
326
+ lazy?: boolean;
327
+ once?: boolean;
328
+ signal?: AbortSignal;
329
+ immediate?: boolean | "auto";
330
+ } // "*" path apart from listener's should not use `immediate`
331
+ type SyncOptions = boolean | SyncOptionsTuple;
332
+
333
+ interface ListenerOptionsTuple extends Omit<SyncOptionsTuple, "lazy"> {
334
+ capture?: boolean;
335
+ depth?: number;
336
+ }
337
+ type ListenerOptions = boolean | ListenerOptionsTuple;
338
+
339
+ // "almighty" mediation, (mediator|listener) for desired path, equality checks eg: `object.is()`
340
+ interface ReactorOptions<T extends object, P extends Paths<T> = Paths<T>> {
341
+ get?: (
342
+ object: PathBranchValue<T, P>,
343
+ key: PathKey<T, P>,
344
+ value: PathValue<T, P>,
345
+ receiver: Reactive<T>,
346
+ path: Paths<T> | Paths<T>[],
347
+ ) => PathValue<T, P> | undefined;
348
+ set?: (
349
+ object: PathBranchValue<T, P>,
350
+ key: PathKey<T, P>,
351
+ value: PathValue<T, P>,
352
+ oldValue: PathValue<T, P>,
353
+ receiver: Reactive<T>,
354
+ path: Paths<T> | Paths<T>[],
355
+ ) => PathValue<T, P> | typeof TERMINATOR | undefined;
356
+ delete?: (
357
+ object: PathBranchValue<T, P>,
358
+ key: PathKey<T, P>,
359
+ oldValue: PathValue<T, P>,
360
+ receiver: Reactive<T>,
361
+ path: Paths<T> | Paths<T>[],
362
+ ) => typeof TERMINATOR | undefined;
363
+ debug?: boolean;
364
+ crossRealms?: boolean; // needed for object type detection if using across realms e.g, iframes or other environments
365
+ smartCloning?: boolean; // one-time set for structural sharing, needs `.referenceTracking: true`
366
+ eventBubbling?: boolean; // default true, set to false to prevent bubbling (not recommended if you want power)
367
+ lineageTracing?: boolean; // one-time set for tree walking to search for refs on property access, needs `.referenceTracking = true`
368
+ batchingFunction?: (cb: () => void) => void; // one-time set for listener's notifications, e.g: `queueMicrotask`, `unstable_batchedUpdates` from ReactDOM
369
+ referenceTracking?: boolean; // one-time set to activate
370
+ } // debating making use of the Reflect API opt-in
371
+
372
+ declare function isDef(val: any): boolean;
373
+ declare function isArr<T = unknown>(obj: any): obj is T[];
374
+ declare function isObj<T extends object = object>(obj: any, checkArr?: boolean): obj is T;
375
+ declare function isStrictObj<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
376
+ declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
377
+ declare function inBoolArrOpt(opt: any, str: string): boolean;
378
+ declare function setAny<T extends object, const S extends string = ".">(target: T, key: Paths<T, S>, value: PathValue<T, typeof key, S>, separator?: S, keyFunc?: (p: string) => string): void;
379
+ declare function getAny<T extends object, const S extends string = ".">(source: T, key: Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): PathValue<T, typeof key, S> | undefined;
380
+ declare function deleteAny<T extends object, const S extends string = ".">(target: T, key: Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): void;
381
+ declare function inAny<T extends object, const S extends string = ".">(source: T, key: string | Paths<T, S>, separator?: S, keyFunc?: (p: string) => string): boolean;
382
+ declare function parseAnyObj<T extends Record<string, any>, const S extends string = ".">(obj: T, separator?: S, keyFunc?: (p: string) => string, visited?: WeakSet<WeakKey>): Unflatten<T, S>;
383
+ declare function parseEvOpts<T extends object>(options: T | boolean | undefined, opts: (keyof T)[] | readonly (keyof T)[], boolOpt?: keyof T, result?: T): T;
384
+ declare function mergeObjs<T1 extends object, T2 extends object>(o1: T1, o2: T2): DeepMerge<T1, T2>;
385
+ declare function mergeObjs<T1 extends object>(o1: T1): T1;
386
+ declare function mergeObjs<T2 extends object>(o1: undefined | null, o2: T2): T2;
387
+ declare function getTrailPaths<T>(path: WildPaths<T>, reverse?: boolean): WildPaths<T>[];
388
+ declare function getTrailRecords<T extends object>(obj: T, path: WildPaths<T>): [WildPaths<T>, PathValue<T, WildPaths<T>>, PathValue<T, WildPaths<T>>][];
389
+ declare function deepClone<T>(obj: T, crossRealms?: boolean, visited?: WeakMap<WeakKey, any>): T;
390
+ declare function nuke(target: any): void;
391
+
392
+ declare const INERTIA: unique symbol;
393
+ declare const REJECTABLE: unique symbol;
394
+ declare const INDIFFABLE: unique symbol;
395
+ declare const TERMINATOR: unique symbol;
396
+ declare class ReactorEvent<T, P extends WildPaths<T> = WildPaths<T>> {
397
+ static readonly NONE = 0;
398
+ static readonly CAPTURING_PHASE = 1;
399
+ static readonly AT_TARGET = 2;
400
+ static readonly BUBBLING_PHASE = 3;
401
+ eventPhase: number;
402
+ type: Payload<T, P>["type"];
403
+ currentTarget: Payload<T, P>["currentTarget"];
404
+ readonly staticType: Payload<T, P>["type"];
405
+ readonly target: Payload<T, P>["target"];
406
+ readonly root: Payload<T, P>["root"];
407
+ readonly path: Payload<T, P>["target"]["path"];
408
+ readonly value: Payload<T, P>["target"]["value"];
409
+ readonly oldValue: Payload<T, P>["target"]["oldValue"];
410
+ readonly rejectable: boolean;
411
+ readonly bubbles: boolean;
412
+ protected _propagationStopped: boolean;
413
+ protected _immediatePropagationStopped: boolean;
414
+ protected _resolved: string;
415
+ protected _rejected: string;
416
+ protected _warn: (...args: any[]) => void;
417
+ constructor(payload: Payload<T, P>, bubbles?: boolean, canWarn?: boolean);
418
+ get propagationStopped(): boolean;
419
+ stopPropagation(): void;
420
+ get immediatePropagationStopped(): boolean;
421
+ stopImmediatePropagation(): void;
422
+ get resolved(): string;
423
+ resolve(message?: string): void;
424
+ get rejected(): string;
425
+ reject(reason?: string): void;
426
+ composedPath(): WildPaths<T>[];
427
+ get canWarn(): boolean;
428
+ }
429
+ declare class Reactor<T extends object> {
430
+ protected getters?: Map<WildPaths<T>, Array<GetterRecord<T>>>;
431
+ protected setters?: Map<WildPaths<T>, Array<SetterRecord<T>>>;
432
+ protected deleters?: Map<WildPaths<T>, Array<DeleterRecord<T>>>;
433
+ protected watchers?: Map<WildPaths<T>, Array<WatcherRecord<T>>>;
434
+ protected listeners?: Map<WildPaths<T>, Array<ListenerRecord<T>>>;
435
+ protected lineage?: WeakMap<object, (object | string)[]>;
436
+ protected queue?: Set<() => void>;
437
+ protected batch?: Map<Paths<T>, Payload<T>>;
438
+ protected proxyCache: WeakMap<object, any>;
439
+ protected snapshotCache?: WeakMap<object, any>;
440
+ protected log: (...args: any[]) => void;
441
+ config: Omit<ReactorOptions<T>, "debug" | "referenceTracking" | "lineageTracing" | "smartCloning">;
442
+ core: T;
443
+ protected isLogging: boolean;
444
+ protected isTracing: boolean;
445
+ protected isTracking: boolean;
446
+ protected isSCloning: boolean;
447
+ protected isBatching: boolean;
448
+ constructor(obj?: T, options?: ReactorOptions<T>);
449
+ protected proxied<O extends object>(obj: O, rejectable?: boolean, indiffable?: boolean, parent?: object, key?: string, path?: string): O;
450
+ protected trace(target: object, path: string, paths?: string[], visited?: WeakSet<object>): Paths<T>[];
451
+ protected link(target: any, parent: object, key: string, typecheck?: boolean, es?: (object | string)[]): void;
452
+ protected unlink(target: any, parent: object, key: string): void;
453
+ protected stamp(target: any, typecheck?: boolean): void;
454
+ protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "get", cords: GetterRecord<T>[]): PathValue<T, P>;
455
+ protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "set", cords: SetterRecord<T>[]): PathValue<T, P>;
456
+ protected mediate<P extends WildPaths<T>>(path: WildPaths<T>, payload: Payload<T, P>, type: "delete", cords: DeleterRecord<T>[]): PathValue<T, P>;
457
+ protected notify<P extends Paths<T>>(path: P, payload: Payload<T, P>): void;
458
+ protected schedule<P extends Paths<T>>(path: P, payload: Payload<T, P>): void;
459
+ protected initBatching(): void;
460
+ protected flush(): void;
461
+ protected wave(path: Paths<T>, payload: Payload<T>): void;
462
+ protected fire([path, object, value]: ReturnType<typeof getTrailRecords<T>>[number], e: REvent<T>, isCapture: boolean, cords?: ListenerRecord<T>[] | undefined): void;
463
+ tick(paths?: Paths<T> | Iterable<Paths<T>>): void;
464
+ stall(task: () => any): void;
465
+ nostall(task: () => any): boolean | undefined;
466
+ protected bind<Cb>(cord: GetterRecord<T> | SetterRecord<T> | DeleterRecord<T> | WatcherRecord<T> | ListenerRecord<T>, signal?: AbortSignal): Cb;
467
+ protected clone(obj: any, raw: boolean, visited?: WeakMap<WeakKey, any>): any;
468
+ getDepth(p: string, d?: number): number;
469
+ protected getContext<P extends WildPaths<T>>(path: P): Target<T, P>;
470
+ protected syncAdd<P extends WildPaths<T>>(key: "get" | "set" | "delete" | "watch", path: P, cb: any, opts: SyncOptions | undefined, onImmediate?: (immediate: boolean | "auto") => void): () => boolean | undefined;
471
+ protected syncDrop<P extends WildPaths<T>>(store: Map<WildPaths<T>, any[]> | undefined, path: P, cb: any): boolean | undefined;
472
+ get<P extends WildPaths<T>>(path: P, cb: Getter<T, P>, opts?: SyncOptions): Reactor<T>["noget"];
473
+ gonce<P extends WildPaths<T>>(path: P, cb: Getter<T, P>, opts?: SyncOptions): Reactor<T>["noget"];
474
+ noget<P extends WildPaths<T>>(path: P, cb: Getter<T, P>): boolean | undefined;
475
+ set<P extends WildPaths<T>>(path: P, cb: Setter<T, P>, opts?: SyncOptions): Reactor<T>["noset"];
476
+ sonce<P extends WildPaths<T>>(path: P, cb: Setter<T, P>, opts?: SyncOptions): Reactor<T>["noset"];
477
+ noset<P extends WildPaths<T>>(path: P, cb: Setter<T, P>): boolean | undefined;
478
+ delete<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>, opts?: SyncOptions): Reactor<T>["nodelete"];
479
+ donce<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>, opts?: SyncOptions): Reactor<T>["nodelete"];
480
+ nodelete<P extends WildPaths<T>>(path: P, cb: Deleter<T, P>): boolean | undefined;
481
+ watch<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>, opts?: SyncOptions): Reactor<T>["nowatch"];
482
+ wonce<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>, opts?: SyncOptions): Reactor<T>["nowatch"];
483
+ nowatch<P extends WildPaths<T>>(path: P, cb: Watcher<T, P>): boolean | undefined;
484
+ on<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): Reactor<T>["off"];
485
+ once<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): Reactor<T>["off"];
486
+ off<P extends WildPaths<T>>(path: P, cb: Listener<T, P>, options?: ListenerOptions): boolean | undefined;
487
+ snapshot(raw?: boolean, branch?: T): T;
488
+ cascade({ type, currentTarget: { path, value: news, oldValue: olds } }: ReactorEvent<T>, objSafe?: boolean): void;
489
+ reset(): void;
490
+ destroy(): void;
491
+ get canLog(): boolean;
492
+ set canLog(value: boolean);
493
+ get canTrackReferences(): boolean;
494
+ get canTraceLineage(): boolean;
495
+ get canSmartClone(): boolean;
496
+ }
497
+
498
+ export { live as $, type StrictPathKey as A, type SyncOptions as B, type ChildPaths as C, type DeepKeys as D, type SyncOptionsTuple as E, type Target as F, type Getter as G, type UnionToIntersection as H, type Inert as I, type UpdatePayload as J, type WatcherRecord as K, type Listener as L, type WildPaths as M, getSnapshotVersion as N, getVersion as O, type PathBranch as P, inert as Q, type REvent as R, type Setter as S, TERMINATOR as T, type Unflatten as U, type Volatile as V, type Watcher as W, intent as X, isInert as Y, isIntent as Z, isVolatile as _, type DeepMerge as a, methods as a0, reactive as a1, stable as a2, state as a3, volatile as a4, type DeepPartial as b, type DeepRequired as c, type Deleter as d, deepClone, deleteAny, type DeleterRecord as e, type DirectPayload as f, type GetterRecord as g, getAny, getTrailPaths, getTrailRecords, type Intent as h, type ListenerOptions as i, inAny, inBoolArrOpt, isArr, isDef, isIter, isObj, isStrictObj, type ListenerOptionsTuple as j, type ListenerRecord as k, type Live as l, type PathBranchValue as m, mergeObjs, type PathKey as n, nuke, type PathLeaf as o, type PathValue as p, parseAnyObj, parseEvOpts, type Paths as q, type Payload as r, type Reactive as s, setAny, type ReactivePrefs as t, Reactor as u, ReactorEvent as v, type ReactorOptions as w, type SetterRecord as x, type Stable as y, type State as z };
@@ -0,0 +1 @@
1
+ "use strict";var sia=(()=>{var h=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var s in t)h(e,s,{get:t[s],enumerable:!0})},B=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of I(t))!M.call(e,i)&&i!==s&&h(e,i,{get:()=>t[i],enumerable:!(r=U(t,i))||r.enumerable});return e};var C=e=>B(h({},"__esModule",{value:!0}),e);var $={};v($,{deepClone:()=>O,deleteAny:()=>N,getAny:()=>W,getTrailPaths:()=>D,getTrailRecords:()=>V,inAny:()=>R,inBoolArrOpt:()=>A,isArr:()=>d,isDef:()=>P,isIter:()=>j,isObj:()=>f,isStrictObj:()=>b,mergeObjs:()=>S,nuke:()=>E,parseAnyObj:()=>p,parseEvOpts:()=>w,setAny:()=>x});var y=/^([^\[\]]+)\[(\d+)\]$/;function P(e){return e!==void 0}function d(e){return Array.isArray(e)}function f(e,t=!0){return typeof e=="object"&&e!==null&&(t?!Array.isArray(e):!0)}function b(e,t=!1,s=!0){return(s?f(e,!1):!0)&&(t?Object.prototype.toString.call(e)==="[object Object]":e.constructor===Object)}function j(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function A(e,t){return e?.includes?.(t)??e}function x(e,t,s,r=".",i){var c,u;if(!t.includes(r))return void(e[i?i(t):t]=s);let n=t.split(r),o=e;for(let a=0;a<n.length;a++){let l=i?i(n[a]):n[a],m=l.includes("[")&&l.match(y);if(m){let[,T,g]=m;d(o[T])||(o[T]=[]),a===n.length-1?o[T][Number(g)]=s:((c=o[T])[u=Number(g)]||(c[u]={}),o=o[T][Number(g)])}else a===n.length-1?o[l]=s:(o[l]||(o[l]={}),o=o[l])}}function W(e,t,s=".",r){if(!t.includes(s))return e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return;n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return;n=n[c]}}return n}function N(e,t,s=".",r){if(!t.includes(s))return void delete e[r?r(t):t];let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return;o===i.length-1?delete n[a][Number(l)]:n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return;o===i.length-1?delete n[c]:n=n[c]}}}function R(e,t,s=".",r){if(!t.includes(s))return t in e;let i=t.split(s),n=e;for(let o=0;o<i.length;o++){let c=r?r(i[o]):i[o],u=c.includes("[")&&c.match(y);if(u){let[,a,l]=u;if(!d(n[a])||!(a in n))return!1;if(o===i.length-1)return!0;n=n[a][Number(l)]}else{if(!f(n)||!(c in n))return!1;if(o===i.length-1)return!0;n=n[c]}}return!0}function p(e,t=".",s=i=>i,r=new WeakSet){if(!f(e)||r.has(e))return e;r.add(e);let i={};return Object.keys(e).forEach(n=>n.includes(t)?x(i,n,p(e[n],t,s,r),t,s):i[n]=f(e[n])?p(e[n],t,s,r):e[n]),i}function w(e,t,s=t[0],r={}){return Object.assign(r,typeof e=="boolean"?{[s]:e}:e),r}function S(e={},t={}){let s={...e||{},...t||{}};return Object.keys(s).forEach(r=>f(e?.[r])&&f(t?.[r])&&(s[r]=S(e[r],t[r]))),s}function D(e,t=!0){let s=e.split("."),r=["*"],i="";for(let n=0;n<s.length;n++)i+=(n===0?"":".")+s[n],r.push(i);return t?r.reverse():r}function V(e,t){let s=t.split("."),r=[["*",e,e]],i="",n=e;for(let o=0;o<s.length;o++)i+=(o===0?"":".")+s[o],r.push([i,n,n=n?.[s[o]]]);return r}function O(e,t,s=new WeakMap){if(!(b(e,t)||d(e))||s.has(e))return e;let r=d(e)?[]:{};s.set(e,r);let i=Object.keys(e);for(let n=0;n<i.length;n++)r[i[n]]=O(e[i[n]],t,s);return r}function E(e){let t=e;for(;t&&t!==Object.prototype;){for(let s of Object.getOwnPropertyNames(t)){if(s==="constructor")continue;let r=Object.getOwnPropertyDescriptor(t,s);typeof r?.value!="function"&&(r?.get||r?.set||(t[s]=null))}t=Object.getPrototypeOf(t)}}return C($);})();
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- import{a as n,b as p,c as o,d as l,e as C,f as T,g as c,h as m,i as g,j as u,k as x,l as f,m as z,n as A,o as d,p as y,q as w}from"./chunk-5BPIJBLB.js";function O(e=""){return e.replace(/^(\s*)([a-z])/i,(a,s,r)=>s+r.toUpperCase())}function S(e="",{source:a}=/[\s_-]+/,{preserveInnerCase:s=!0,upperFirst:r=!1}={}){return(s?e:e.toLowerCase()).replace(new RegExp(a+"(\\w)","g"),(t,i)=>i.toUpperCase()).replace(/^\w/,t=>t[r?"toUpperCase":"toLowerCase"]())}function b(e,a=" "){return e.replace(/([a-z])([A-Z])/g,`$1${a}$2`).toLowerCase()}export{S as camelize,O as capitalize,y as deepClone,g as deleteAny,m as getAny,A as getTrailPaths,d as getTrailRecords,u as inAny,T as inBoolArrOpt,p as isArr,n as isDef,C as isIter,o as isObj,l as isStrictObj,z as mergeObjs,w as nuke,x as parseAnyObj,f as parseEvOpts,c as setAny,b as uncamelize};
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q}from"./chunk-N5UMAYCJ.js";export{p as deepClone,i as deleteAny,h as getAny,n as getTrailPaths,o as getTrailRecords,j as inAny,f as inBoolArrOpt,b as isArr,a as isDef,e as isIter,c as isObj,d as isStrictObj,m as mergeObjs,q as nuke,k as parseAnyObj,l as parseEvOpts,g as setAny};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sia-reactor",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "The Programmable Data DOM. A high-performance State Intent Architecture (S.I.A.) Engine with zero-allocation loops, event propagation, and structural sharing.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -15,28 +15,27 @@
15
15
  "type": "module",
16
16
  "main": "./dist/index.cjs",
17
17
  "module": "./dist/index.js",
18
+ "browser": "./dist/index.global.js",
19
+ "unpkg": "./dist/index.global.js",
18
20
  "types": "./dist/index.d.ts",
19
21
  "sideEffects": false,
20
22
  "exports": {
21
23
  ".": {
22
24
  "types": "./dist/index.d.ts",
23
25
  "import": "./dist/index.js",
24
- "require": "./dist/index.cjs"
26
+ "require": "./dist/index.cjs",
27
+ "default": "./dist/index.js"
25
28
  },
26
29
  "./utils": {
27
30
  "types": "./dist/utils.d.ts",
28
31
  "import": "./dist/utils.js",
29
- "require": "./dist/utils.cjs"
30
- },
31
- "./types": {
32
- "types": "./dist/types.d.ts",
33
- "import": "./dist/types.js",
34
- "require": "./dist/types.cjs"
32
+ "require": "./dist/utils.cjs",
33
+ "default": "./dist/utils.js"
35
34
  }
36
35
  },
37
36
  "scripts": {
38
- "build": "tsup src/index.ts src/utils.ts src/types.ts --format cjs,esm --dts --clean --minify",
39
- "dev": "tsup src/index.ts src/utils.ts src/types.ts --format cjs,esm --dts --watch --minify"
37
+ "build": "tsup src/index.ts src/utils.ts src/types.ts --format cjs,esm,iife --global-name sia --dts --clean --minify",
38
+ "dev": "tsup src/index.ts src/utils.ts src/types.ts --format cjs,esm,iife --global-name sia --dts --watch --minify"
40
39
  },
41
40
  "files": [
42
41
  "dist",
@@ -1 +0,0 @@
1
- var p=/^([^\[\]]+)\[(\d+)\]$/;function O(e){return e!==void 0}function d(e){return Array.isArray(e)}function f(e,n=!0){return typeof e=="object"&&e!==null&&(n?!Array.isArray(e):!0)}function x(e,n=!1,s=!0){return(s?f(e,!1):!0)&&(n?Object.prototype.toString.call(e)==="[object Object]":e.constructor===Object)}function P(e){return e!=null&&typeof e[Symbol.iterator]=="function"}function j(e,n){return e?.includes?.(n)??e}function b(e,n,s,r=".",o){var a,u;if(!n.includes(r))return void(e[o?o(n):n]=s);let t=n.split(r),i=e;for(let c=0;c<t.length;c++){let l=o?o(t[c]):t[c],h=l.includes("[")&&l.match(p);if(h){let[,T,y]=h;d(i[T])||(i[T]=[]),c===t.length-1?i[T][Number(y)]=s:((a=i[T])[u=Number(y)]||(a[u]={}),i=i[T][Number(y)])}else c===t.length-1?i[l]=s:(i[l]||(i[l]={}),i=i[l])}}function W(e,n,s=".",r){if(!n.includes(s))return e[r?r(n):n];let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let a=r?r(o[i]):o[i],u=a.includes("[")&&a.match(p);if(u){let[,c,l]=u;if(!d(t[c])||!(c in t))return;t=t[c][Number(l)]}else{if(!f(t)||!(a in t))return;t=t[a]}}return t}function A(e,n,s=".",r){if(!n.includes(s))return void delete e[r?r(n):n];let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let a=r?r(o[i]):o[i],u=a.includes("[")&&a.match(p);if(u){let[,c,l]=u;if(!d(t[c])||!(c in t))return;i===o.length-1?delete t[c][Number(l)]:t=t[c][Number(l)]}else{if(!f(t)||!(a in t))return;i===o.length-1?delete t[a]:t=t[a]}}}function N(e,n,s=".",r){if(!n.includes(s))return n in e;let o=n.split(s),t=e;for(let i=0;i<o.length;i++){let a=r?r(o[i]):o[i],u=a.includes("[")&&a.match(p);if(u){let[,c,l]=u;if(!d(t[c])||!(c in t))return!1;if(i===o.length-1)return!0;t=t[c][Number(l)]}else{if(!f(t)||!(a in t))return!1;if(i===o.length-1)return!0;t=t[a]}}return!0}function g(e,n=".",s=o=>o,r=new WeakSet){if(!f(e)||r.has(e))return e;r.add(e);let o={};return Object.keys(e).forEach(t=>t.includes(n)?b(o,t,g(e[t],n,s,r),n,s):o[t]=f(e[t])?g(e[t],n,s,r):e[t]),o}function w(e,n,s=n[0],r={}){return Object.assign(r,typeof e=="boolean"?{[s]:e}:e),r}function S(e={},n={}){let s={...e||{},...n||{}};return Object.keys(s).forEach(r=>f(e?.[r])&&f(n?.[r])&&(s[r]=S(e[r],n[r]))),s}function R(e,n=!0){let s=e.split("."),r=["*"],o="";for(let t=0;t<s.length;t++)o+=(t===0?"":".")+s[t],r.push(o);return n?r.reverse():r}function V(e,n){let s=n.split("."),r=[["*",e,e]],o="",t=e;for(let i=0;i<s.length;i++)o+=(i===0?"":".")+s[i],r.push([o,t,t=t?.[s[i]]]);return r}function m(e,n,s=new WeakMap){if(!(x(e,n)||d(e))||s.has(e))return e;let r=d(e)?[]:{};s.set(e,r);let o=Object.keys(e);for(let t=0;t<o.length;t++)r[o[t]]=m(e[o[t]],n,s);return r}function D(e){let n=e;for(;n&&n!==Object.prototype;){for(let s of Object.getOwnPropertyNames(n)){if(s==="constructor")continue;let r=Object.getOwnPropertyDescriptor(n,s);typeof r?.value!="function"&&(r?.get||r?.set||(n[s]=null))}n=Object.getPrototypeOf(n)}}export{O as a,d as b,f as c,x as d,P as e,j as f,b as g,W as h,A as i,N as j,g as k,w as l,S as m,R as n,V as o,m as p,D as q};