sia-reactor 0.0.21 → 0.0.23
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/README.md +115 -89
- package/dist/{TimeTravelOverlay-DxqJL0Zk.d.ts → TimeTravelOverlay-Dglcwpg-.d.ts} +9 -8
- package/dist/{TimeTravelOverlay-CJv-S_Km.d.cts → TimeTravelOverlay-OjklzuCD.d.cts} +9 -8
- package/dist/adapters/react.cjs +74 -91
- package/dist/adapters/react.d.cts +23 -22
- package/dist/adapters/react.d.ts +23 -22
- package/dist/adapters/react.js +3 -3
- package/dist/adapters/vanilla.cjs +74 -91
- package/dist/adapters/vanilla.d.cts +4 -4
- package/dist/adapters/vanilla.d.ts +4 -4
- package/dist/adapters/vanilla.js +3 -3
- package/dist/{chunk-TFLYCXK4.js → chunk-5JNWC7Z4.js} +14 -13
- package/dist/{chunk-DP74DVRT.js → chunk-MKL3JUPO.js} +55 -15
- package/dist/{chunk-2WBPGSRL.js → chunk-MSTHQVNK.js} +61 -78
- package/dist/{index-Oie9hhE8.d.cts → index-m0aAWxhX.d.cts} +330 -218
- package/dist/{index-Oie9hhE8.d.ts → index-m0aAWxhX.d.ts} +330 -218
- package/dist/index.cjs +69 -89
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -4
- package/dist/{plugins.cjs → modules.cjs} +464 -195
- package/dist/modules.d.cts +52 -0
- package/dist/modules.d.ts +52 -0
- package/dist/modules.js +619 -0
- package/dist/super.d.ts +642 -298
- package/dist/super.global.js +481 -210
- package/dist/timeTravel-DExvNb04.d.ts +352 -0
- package/dist/timeTravel-DctvcHVt.d.cts +352 -0
- package/dist/utils.cjs +59 -14
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +7 -1
- package/package.json +6 -6
- package/dist/plugins.d.cts +0 -112
- package/dist/plugins.d.ts +0 -112
- package/dist/plugins.js +0 -370
- package/dist/timeTravel-B1vedDQc.d.ts +0 -76
- package/dist/timeTravel-WpgWmKu-.d.cts +0 -76
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { a as REvent, c as ReactorModuleId, P as Paths, B as BaseReactorModule, R as Reactor } from './index-m0aAWxhX.cjs';
|
|
2
|
+
|
|
3
|
+
type JSONReplacer = ((this: any, key: string, value: any) => any) | (number | string)[] | null;
|
|
4
|
+
type JSONReviver = ((this: any, key: string, value: any) => any) | undefined;
|
|
5
|
+
interface StorageAdapterConfig {
|
|
6
|
+
debug: boolean;
|
|
7
|
+
/** Optional `JSON.stringify()` like replacer to be used where applicable. */
|
|
8
|
+
replacer?: JSONReplacer;
|
|
9
|
+
/** Optional `JSON.parse()` like reviver to be used where applicable. */
|
|
10
|
+
reviver?: JSONReviver;
|
|
11
|
+
}
|
|
12
|
+
interface CookieOptions {
|
|
13
|
+
/** Cookie path scope, defaults to root for maximum accessibility. */
|
|
14
|
+
path: string;
|
|
15
|
+
/** Optional cookie domain scope, e.g. ".example.com". */
|
|
16
|
+
domain?: string;
|
|
17
|
+
/** Cookie Secure attribute, defaults to `false` but should be `true` in production for HTTPS sites. */
|
|
18
|
+
secure: boolean;
|
|
19
|
+
/** Cookie SameSite attribute for CSRF protection, defaults to "Lax" for a balance of security and usability. */
|
|
20
|
+
sameSite: "Strict" | "Lax" | "None";
|
|
21
|
+
/** Optional cookie lifetime in seconds, e.g. 604800 for a week. */
|
|
22
|
+
maxAge?: number;
|
|
23
|
+
/** Optional absolute cookie expiry date, e.g. (new Date()).setDate(new Date().getDate() + 7), "Wed, 21 Oct 2023 07:28:00 GMT" (UTC Format). */
|
|
24
|
+
expires?: string | Date;
|
|
25
|
+
}
|
|
26
|
+
interface CookieAdapterConfig extends StorageAdapterConfig, CookieOptions {
|
|
27
|
+
}
|
|
28
|
+
interface MemoryAdapterConfig extends StorageAdapterConfig {
|
|
29
|
+
/** stored as strings to mimic local constraints */
|
|
30
|
+
store: Map<string, string>;
|
|
31
|
+
}
|
|
32
|
+
interface IndexedDBAdapterConfig extends StorageAdapterConfig, IDBTransactionOptions {
|
|
33
|
+
/** The name of the IndexedDB database to be created or retrieved. */
|
|
34
|
+
dbName: string;
|
|
35
|
+
/** Database version tag to use during creation or retrieval. */
|
|
36
|
+
version: number;
|
|
37
|
+
/** First store is default during operations if none provided */
|
|
38
|
+
stores: string[];
|
|
39
|
+
/** return a preffered instance or `throw` to prevent accessing the database */
|
|
40
|
+
onidb: () => any;
|
|
41
|
+
/** Called when the database request needs to be upgraded */
|
|
42
|
+
onupgradeneeded: (database: IDBDatabase, event: IDBVersionChangeEvent) => void;
|
|
43
|
+
/** Called when the database version changes */
|
|
44
|
+
onversionchange: (database: IDBDatabase, event: IDBVersionChangeEvent) => void;
|
|
45
|
+
/** Called when the database request is successful */
|
|
46
|
+
onsuccess: (database: IDBDatabase, event: Event) => void;
|
|
47
|
+
/** Called when the database request fails */
|
|
48
|
+
onerror: (error: DOMException | null, event: Event) => any;
|
|
49
|
+
/** Called when the database request is blocked */
|
|
50
|
+
onblocked: (event: IDBVersionChangeEvent) => void;
|
|
51
|
+
}
|
|
52
|
+
interface StorageAdapterConstructor<Config extends StorageAdapterConfig = StorageAdapterConfig> {
|
|
53
|
+
new (config?: Config): StorageAdapter<Config>;
|
|
54
|
+
}
|
|
55
|
+
interface AsyncStorageAdapterConstructor<Config extends StorageAdapterConfig = StorageAdapterConfig> {
|
|
56
|
+
new (config?: Config): AsyncStorageAdapter<Config>;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Abstract base class for storage adapters, defines the interface and common functionality.
|
|
60
|
+
* @typeParam Config Configuration object type for the adapter.
|
|
61
|
+
*/
|
|
62
|
+
declare abstract class BaseStorageAdapter<Config extends StorageAdapterConfig = StorageAdapterConfig> {
|
|
63
|
+
readonly name: string;
|
|
64
|
+
config: Config;
|
|
65
|
+
protected warn: (act?: string, mssg?: string, key?: string, store?: string) => false | void;
|
|
66
|
+
constructor(config?: Config);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Abstract base class for storage adapters, defines the interface and common functionality.
|
|
70
|
+
* Extend this class to implement specific synchronous storage mechanisms (e.g., LocalStorage).
|
|
71
|
+
* @typeParam Config Configuration object type for the adapter.
|
|
72
|
+
*/
|
|
73
|
+
declare abstract class StorageAdapter<Config extends StorageAdapterConfig = StorageAdapterConfig> extends BaseStorageAdapter<Config> {
|
|
74
|
+
readonly name: string;
|
|
75
|
+
abstract get(key: string): any;
|
|
76
|
+
abstract set(key: string, value: any): boolean;
|
|
77
|
+
abstract remove(key: string): boolean;
|
|
78
|
+
abstract clear(): boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Abstract base class for asynchronous storage adapters, defines the interface and common functionality.
|
|
82
|
+
* Extend this class to implement specific asynchronous storage mechanisms (e.g., IndexedDB).
|
|
83
|
+
* @typeParam Config Configuration object type for the adapter.
|
|
84
|
+
*/
|
|
85
|
+
declare abstract class AsyncStorageAdapter<Config extends StorageAdapterConfig = StorageAdapterConfig> extends BaseStorageAdapter<Config> {
|
|
86
|
+
readonly name: string;
|
|
87
|
+
abstract get(key: string): Promise<any>;
|
|
88
|
+
abstract set(key: string, value: any): Promise<boolean>;
|
|
89
|
+
abstract remove(key: string): Promise<boolean>;
|
|
90
|
+
abstract clear(): Promise<boolean>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* - The LocalStorage Adapter (~5MB per origin, browser-dependent).
|
|
94
|
+
* - Provides aN implementation of the `StorageAdapter` interface using the browser's `localStorage`.
|
|
95
|
+
* Handles JSON serialization and deserialization, and includes error handling for unsupported environments.
|
|
96
|
+
*/
|
|
97
|
+
declare class LocalStorageAdapter extends StorageAdapter {
|
|
98
|
+
readonly name: string;
|
|
99
|
+
/**
|
|
100
|
+
* Reads and parses a value from localStorage.
|
|
101
|
+
* @param key Storage key.
|
|
102
|
+
* @returns Parsed value, or `undefined` when missing/unreadable.
|
|
103
|
+
*/
|
|
104
|
+
get(key: string, reviver?: JSONReviver): any;
|
|
105
|
+
/**
|
|
106
|
+
* Serializes and writes a value to localStorage.
|
|
107
|
+
* @param key Storage key.
|
|
108
|
+
* @param value Value to serialize.
|
|
109
|
+
* @returns `true` when write succeeds, else `false`.
|
|
110
|
+
*/
|
|
111
|
+
set(key: string, value: any, replacer?: JSONReplacer | undefined): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Removes a single key from localStorage.
|
|
114
|
+
* @param key Storage key.
|
|
115
|
+
* @returns `true` when removal succeeds, else `false`.
|
|
116
|
+
*/
|
|
117
|
+
remove(key: string): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Clears all localStorage entries for the current origin.
|
|
120
|
+
* @returns `true` when clear succeeds, else `false`.
|
|
121
|
+
*/
|
|
122
|
+
clear(): boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* - The SessionStorage Adapter (~5MB per origin per tab, browser-dependent).
|
|
126
|
+
* - Provides an implementation of the `StorageAdapter` interface using the browser's `sessionStorage`.
|
|
127
|
+
* Handles JSON serialization and deserialization, and includes error handling for unsupported environments.
|
|
128
|
+
*/
|
|
129
|
+
declare class SessionStorageAdapter extends StorageAdapter {
|
|
130
|
+
readonly name: string;
|
|
131
|
+
/**
|
|
132
|
+
* Reads and parses a value from sessionStorage.
|
|
133
|
+
* @param key Storage key.
|
|
134
|
+
* @returns Parsed value, or `undefined` when missing/unreadable.
|
|
135
|
+
*/
|
|
136
|
+
get(key: string, reviver?: JSONReviver): any;
|
|
137
|
+
/**
|
|
138
|
+
* Serializes and writes a value to sessionStorage.
|
|
139
|
+
* @param key Storage key.
|
|
140
|
+
* @param value Value to serialize.
|
|
141
|
+
* @returns `true` when write succeeds, else `false`.
|
|
142
|
+
*/
|
|
143
|
+
set(key: string, value: any, replacer?: JSONReplacer | undefined): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Removes a single key from sessionStorage.
|
|
146
|
+
* @param key Storage key.
|
|
147
|
+
* @returns `true` when removal succeeds, else `false`.
|
|
148
|
+
*/
|
|
149
|
+
remove(key: string): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Clears all sessionStorage entries for the current tab session.
|
|
152
|
+
* @returns `true` when clear succeeds, else `false`.
|
|
153
|
+
*/
|
|
154
|
+
clear(): boolean;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* - The Memory Storage Adapter (RAM-bound; no fixed browser quota).
|
|
158
|
+
* - Provides an implementation of the `StorageAdapter` interface using an in-memory `Map`.
|
|
159
|
+
* Useful for testing or non-persistent storage needs, mimics the API and behavior of LocalStorage.
|
|
160
|
+
*/
|
|
161
|
+
declare class MemoryAdapter extends StorageAdapter<MemoryAdapterConfig> {
|
|
162
|
+
readonly name: string;
|
|
163
|
+
constructor(build?: Partial<MemoryAdapterConfig>);
|
|
164
|
+
/**
|
|
165
|
+
* Reads and parses a value from memory storage.
|
|
166
|
+
* @param key Storage key.
|
|
167
|
+
* @returns Parsed value, or `undefined` when missing/unreadable.
|
|
168
|
+
*/
|
|
169
|
+
get(key: string, reviver?: JSONReviver): any;
|
|
170
|
+
/**
|
|
171
|
+
* Serializes and writes a value to memory storage.
|
|
172
|
+
* @param key Storage key.
|
|
173
|
+
* @param value Value to serialize.
|
|
174
|
+
* @returns `true` when write succeeds, else `false`.
|
|
175
|
+
*/
|
|
176
|
+
set(key: string, value: any, replacer?: JSONReplacer | undefined): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Removes a single key from memory storage.
|
|
179
|
+
* @param key Storage key.
|
|
180
|
+
* @returns `true` when removal succeeds, else `false`.
|
|
181
|
+
*/
|
|
182
|
+
remove(key: string): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Clears all entries from memory storage.
|
|
185
|
+
* @returns `true` when clear succeeds, else `false`.
|
|
186
|
+
*/
|
|
187
|
+
clear(): boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* - The Cookie Storage Adapter (~4KB per cookie; practical total payload budget often ~30KB).
|
|
191
|
+
* - Provides an implementation of the `StorageAdapter` interface using `document.cookie`.
|
|
192
|
+
* Handles JSON serialization/deserialization and URL-safe key/value encoding.
|
|
193
|
+
*/
|
|
194
|
+
declare class CookieAdapter extends StorageAdapter<CookieAdapterConfig> {
|
|
195
|
+
readonly name: string;
|
|
196
|
+
protected deets: (opts?: Partial<CookieOptions>, _d?: string | undefined, _m?: number | undefined, _e?: string | Date | undefined) => string;
|
|
197
|
+
constructor(build?: Partial<CookieAdapterConfig>);
|
|
198
|
+
/**
|
|
199
|
+
* Reads and parses a cookie visible to the current page scope.
|
|
200
|
+
* @param key Cookie key.
|
|
201
|
+
* @returns Parsed value, or `undefined` when missing/unreadable.
|
|
202
|
+
*/
|
|
203
|
+
get(key: string, reviver?: JSONReviver): any;
|
|
204
|
+
/**
|
|
205
|
+
* Writes a cookie with optional per-call scope/lifetime overrides.
|
|
206
|
+
* @param key Cookie key.
|
|
207
|
+
* @param value Value to serialize.
|
|
208
|
+
* @param opts Optional per-call cookie options.
|
|
209
|
+
* @returns `true` when write succeeds, else `false`.
|
|
210
|
+
*/
|
|
211
|
+
set(key: string, value: any, opts?: Partial<CookieOptions>, replacer?: JSONReplacer | undefined): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Removes a cookie key using matching scope attributes.
|
|
214
|
+
* @param key Cookie key.
|
|
215
|
+
* @param opts Optional per-call scope overrides.
|
|
216
|
+
* @returns `true` when removal succeeds, else `false`.
|
|
217
|
+
*/
|
|
218
|
+
remove(key: string, opts?: Partial<CookieOptions>): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Attempts to remove all visible cookie keys for the given scope.
|
|
221
|
+
* @param opts Optional per-call scope overrides.
|
|
222
|
+
* @returns `true` when clear succeeds, else `false`.
|
|
223
|
+
*/
|
|
224
|
+
clear(opts?: Partial<CookieOptions>): boolean;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* - The IndexedDB Adapter (quota-managed; typically tens of MB to GB).
|
|
228
|
+
* - Provides an implementation of the `AsyncStorageAdapter` interface using the IndexedDB database.
|
|
229
|
+
* Handles database connection management, object store setup, and includes error handling for unsupported environments and common issues, requires snapshots(non-proxies) for persistence.
|
|
230
|
+
*/
|
|
231
|
+
declare class IndexedDBAdapter extends AsyncStorageAdapter<IndexedDBAdapterConfig> {
|
|
232
|
+
readonly name: string;
|
|
233
|
+
protected db?: IDBDatabase;
|
|
234
|
+
constructor(build?: Partial<IndexedDBAdapterConfig>);
|
|
235
|
+
/**
|
|
236
|
+
* Returns a connected IndexedDB instance, opening it when needed.
|
|
237
|
+
* @returns Connected database handle.
|
|
238
|
+
*/
|
|
239
|
+
idb(): Promise<IDBDatabase>;
|
|
240
|
+
/**
|
|
241
|
+
* Reads a value by key from an object store.
|
|
242
|
+
* @param key Record key.
|
|
243
|
+
* @param store Optional object-store override.
|
|
244
|
+
* @returns Stored value, or `undefined` when missing/unreadable.
|
|
245
|
+
*/
|
|
246
|
+
get(key: string, store?: string, options?: Partial<IDBTransactionOptions>): Promise<any>;
|
|
247
|
+
/**
|
|
248
|
+
* Writes a value by key into an object store.
|
|
249
|
+
* @param key Record key.
|
|
250
|
+
* @param value Value to store.
|
|
251
|
+
* @param store Optional object-store override.
|
|
252
|
+
* @returns `true` when write succeeds, else `false`.
|
|
253
|
+
*/
|
|
254
|
+
set(key: string, value: any, store?: string, options?: Partial<IDBTransactionOptions>): Promise<boolean>;
|
|
255
|
+
/**
|
|
256
|
+
* Deletes a value by key from an object store.
|
|
257
|
+
* @param key Record key.
|
|
258
|
+
* @param store Optional object-store override.
|
|
259
|
+
* @returns `true` when delete succeeds, else `false`.
|
|
260
|
+
*/
|
|
261
|
+
remove(key: string, store?: string, options?: Partial<IDBTransactionOptions>): Promise<boolean>;
|
|
262
|
+
/**
|
|
263
|
+
* Clears one or more object stores.
|
|
264
|
+
* @param stores Store name or list of store names to clear.
|
|
265
|
+
* @returns `true` when all clears succeed, else `false`.
|
|
266
|
+
*/
|
|
267
|
+
clear(stores?: string | string[], options?: Partial<IDBTransactionOptions>): Promise<boolean>;
|
|
268
|
+
}
|
|
269
|
+
declare const COOKIE_ADAPTER_BUILD: Partial<CookieAdapterConfig>;
|
|
270
|
+
declare const INDEXED_DB_ADAPTER_BUILD: Partial<IndexedDBAdapterConfig>;
|
|
271
|
+
|
|
272
|
+
/** The DNA of a specific moment in time, Records the 'Desire' (Intent) or the 'Fact' (State). */
|
|
273
|
+
interface HistoryEntry {
|
|
274
|
+
/** The surgical address in the Reactor */
|
|
275
|
+
path: string;
|
|
276
|
+
/** The data payload at that moment */
|
|
277
|
+
value: any;
|
|
278
|
+
/** The "Undo" antidote (Previous value), if applicable */
|
|
279
|
+
oldValue: any;
|
|
280
|
+
/** Was it a 'set' or a 'delete' surgery? */
|
|
281
|
+
type: REvent<any, any>["staticType"];
|
|
282
|
+
/** Did the Power Line disapprove?; why? */
|
|
283
|
+
rejected?: string;
|
|
284
|
+
/** Did the key for the value exist on its parent object? */
|
|
285
|
+
hadKey?: boolean;
|
|
286
|
+
/** For chronological re-enactment */
|
|
287
|
+
deltat: number;
|
|
288
|
+
/** For multi-reactor management, identifies who the entry belongs to */
|
|
289
|
+
rid: ReactorModuleId;
|
|
290
|
+
}
|
|
291
|
+
interface TimeTravelConfig<T extends object = any> {
|
|
292
|
+
/** Specific paths only, no "*"; instead don't pass anything */
|
|
293
|
+
paths: Paths<T>[];
|
|
294
|
+
/** Maximum number of history entries to keep (Memory Cap), you lose replaying Sessions or the Genesis */
|
|
295
|
+
maxHistoryLength: number;
|
|
296
|
+
/** Max delay between events during playback (ms) */
|
|
297
|
+
maxPlaybackDelay: number;
|
|
298
|
+
}
|
|
299
|
+
interface TimeTravelState {
|
|
300
|
+
/** The "Genesis" snapshot (Raw Data) */
|
|
301
|
+
initialState: {
|
|
302
|
+
[rid: ReactorModuleId]: any;
|
|
303
|
+
};
|
|
304
|
+
/** The "Timeline" of mutations (Chronological Log) */
|
|
305
|
+
history: HistoryEntry[];
|
|
306
|
+
/** The manual playhead (Index in the Timeline) */
|
|
307
|
+
currentFrame: number;
|
|
308
|
+
/** Whether playback is currently paused (Automatic Replay) */
|
|
309
|
+
paused: boolean;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* - The Flight Recorder (Black Box).
|
|
313
|
+
* - Implements S.I.A. logic to allow playback, teleportation, redos and undos.
|
|
314
|
+
* Allows history from single or multiple reactors to be recorded and replayed in a synchronized manner, even if they have different shapes.
|
|
315
|
+
* If paired with async persistence, `use()` or `setup()` this module after hydration where applicable to avoid recording restore waves.
|
|
316
|
+
*/
|
|
317
|
+
declare class TimeTravelModule<T extends object = any> extends BaseReactorModule<T, TimeTravelConfig<T>, TimeTravelState> {
|
|
318
|
+
static readonly moduleName: string;
|
|
319
|
+
protected lastTimestamp: number;
|
|
320
|
+
protected playbackTimeoutId: number;
|
|
321
|
+
constructor(config?: Partial<TimeTravelConfig<T>>, rtr?: Reactor<T>);
|
|
322
|
+
wire(): void;
|
|
323
|
+
protected onAttach(rtr: Reactor<any>, rid: ReactorModuleId): void;
|
|
324
|
+
protected handlePaths({ value: paths, oldValue: prevs }: REvent<TimeTravelConfig<T>, "paths">): void;
|
|
325
|
+
/** Chronicling the lifecycle of the system, Captures the essence of every mutation wave that bubbles up. */
|
|
326
|
+
protected record(e: REvent<any, any>, rid?: ReactorModuleId): void;
|
|
327
|
+
/** Clears timeline history and resets playhead/genesis to the current reactor state. */
|
|
328
|
+
clear(): void;
|
|
329
|
+
/** Instant state reconstruction (Teleport). Glides through deltas natively. */
|
|
330
|
+
jumpTo(index?: number, keepShield?: boolean): void;
|
|
331
|
+
/** Step through time, Moves the playhead and teleports the state. */
|
|
332
|
+
step(stride?: number, forward?: boolean): void;
|
|
333
|
+
/** Step back in time, Moves the playhead backward and teleports the state. */
|
|
334
|
+
undo: () => void;
|
|
335
|
+
/** Step forward in time, Restores previously undone actions. */
|
|
336
|
+
redo: () => void;
|
|
337
|
+
/** Core automove engine. Replays or rewinds the "Story" by respecting time gaps. */
|
|
338
|
+
automove(forward?: boolean): Promise<void>;
|
|
339
|
+
/** Start chronological re-enactment of the session. */
|
|
340
|
+
play: () => Promise<void>;
|
|
341
|
+
/** Start reverse chronological re-enactment of the session. */
|
|
342
|
+
rewind: () => Promise<void>;
|
|
343
|
+
/** Pauses the live VCR playback. */
|
|
344
|
+
pause: () => void;
|
|
345
|
+
/** Exports the current session as a JSON string. */
|
|
346
|
+
export(replacer?: JSONReplacer, space?: string | number): string;
|
|
347
|
+
/** Imports a session from a JSON string, allowing you to replay or analyze past states. */
|
|
348
|
+
import(json: string, reviver?: JSONReviver): void;
|
|
349
|
+
}
|
|
350
|
+
declare const TIME_TRAVEL_MODULE_BUILD: Partial<TimeTravelConfig>;
|
|
351
|
+
|
|
352
|
+
export { AsyncStorageAdapter as A, BaseStorageAdapter as B, COOKIE_ADAPTER_BUILD as C, type HistoryEntry as H, INDEXED_DB_ADAPTER_BUILD as I, type JSONReplacer as J, LocalStorageAdapter as L, MemoryAdapter as M, StorageAdapter as S, TIME_TRAVEL_MODULE_BUILD as T, type StorageAdapterConstructor as a, type AsyncStorageAdapterConstructor as b, CookieAdapter as c, type CookieAdapterConfig as d, type CookieOptions as e, IndexedDBAdapter as f, type IndexedDBAdapterConfig as g, type JSONReviver as h, type MemoryAdapterConfig as i, SessionStorageAdapter as j, type StorageAdapterConfig as k, type TimeTravelConfig as l, TimeTravelModule as m, type TimeTravelState as n };
|
package/dist/utils.cjs
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/ts/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
+
arrRegex: () => arrRegex,
|
|
23
24
|
assignEl: () => assignEl,
|
|
24
25
|
bindAllMethods: () => bindAllMethods,
|
|
25
26
|
canHandle: () => canHandle,
|
|
@@ -28,6 +29,8 @@ __export(utils_exports, {
|
|
|
28
29
|
createEl: () => createEl,
|
|
29
30
|
deepClone: () => deepClone,
|
|
30
31
|
deleteAny: () => deleteAny,
|
|
32
|
+
fanout: () => fanout,
|
|
33
|
+
fanoutOptsArr: () => fanoutOptsArr,
|
|
31
34
|
formatKeyForDisplay: () => formatKeyForDisplay,
|
|
32
35
|
formatKeyShortcutsForDisplay: () => formatKeyShortcutsForDisplay,
|
|
33
36
|
getAny: () => getAny,
|
|
@@ -59,16 +62,18 @@ module.exports = __toCommonJS(utils_exports);
|
|
|
59
62
|
var CTX = {
|
|
60
63
|
/** Flag indicating whether the application is running in development mode. */
|
|
61
64
|
isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
|
|
62
|
-
/**
|
|
65
|
+
/** Flag indicating whether a cascade is currently ongoing so reactors can allow all writes. */
|
|
66
|
+
isCascading: false,
|
|
67
|
+
/** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
|
|
63
68
|
autotracker: null
|
|
64
69
|
};
|
|
70
|
+
var INERTIA = /* @__PURE__ */ Symbol.for("S.I.A_INERTIA");
|
|
65
71
|
var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
|
|
66
72
|
var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
|
|
67
|
-
var EVT_WARN = console.warn.bind(console, "[S.I.A Event]");
|
|
68
73
|
var NIL = Object.freeze({});
|
|
69
74
|
|
|
70
75
|
// src/ts/utils/obj.ts
|
|
71
|
-
var
|
|
76
|
+
var arrRegex = /^([^\[\]]+)\[(\d+)\]$/;
|
|
72
77
|
function isObj(obj, arraycheck = true) {
|
|
73
78
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
74
79
|
}
|
|
@@ -76,7 +81,7 @@ function isPOJO(obj, config = NIL, typecheck = true) {
|
|
|
76
81
|
return (typecheck ? isObj(obj, false) : true) && (config.crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
|
|
77
82
|
}
|
|
78
83
|
function canHandle(obj, config = NIL, typecheck = true) {
|
|
79
|
-
if (typecheck && !isObj(obj, false)) return false;
|
|
84
|
+
if (typecheck && !isObj(obj, false) || obj[INERTIA]) return false;
|
|
80
85
|
if (Array.isArray(obj) || !config.preserveContext && isPOJO(obj, config, false)) return true;
|
|
81
86
|
if (config.preserveContext) return !(obj instanceof Map) && !(obj instanceof Set) && !(obj instanceof WeakMap) && !(obj instanceof WeakSet) && !(obj instanceof Error) && !(obj instanceof Number) && !(obj instanceof Date) && !(obj instanceof String) && !(obj instanceof RegExp) && !(obj instanceof ArrayBuffer) && !(obj instanceof Promise);
|
|
82
87
|
return false;
|
|
@@ -87,7 +92,7 @@ function getAny(source, key, separator = ".", keyFunc) {
|
|
|
87
92
|
const keys = key.split(separator);
|
|
88
93
|
let currObj = source;
|
|
89
94
|
for (let i = 0, len = keys.length; i < len; i++) {
|
|
90
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
95
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
91
96
|
if (match) {
|
|
92
97
|
const [, key3, iStr] = match;
|
|
93
98
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return void 0;
|
|
@@ -104,7 +109,7 @@ function setAny(target, key, value, separator = ".", keyFunc) {
|
|
|
104
109
|
if (!key.includes(separator)) return void (target[keyFunc ? keyFunc(key) : key] = value);
|
|
105
110
|
const keys = key.split(separator);
|
|
106
111
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
107
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
112
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
108
113
|
if (match) {
|
|
109
114
|
const [, key3, iStr] = match;
|
|
110
115
|
if (!Array.isArray(currObj[key3])) currObj[key3] = [];
|
|
@@ -125,7 +130,7 @@ function deleteAny(target, key, separator = ".", keyFunc) {
|
|
|
125
130
|
if (!key.includes(separator)) return void delete target[keyFunc ? keyFunc(key) : key];
|
|
126
131
|
const keys = key.split(separator);
|
|
127
132
|
for (let currObj = target, i = 0, len = keys.length; i < len; i++) {
|
|
128
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
133
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
129
134
|
if (match) {
|
|
130
135
|
const [, key3, iStr] = match;
|
|
131
136
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return;
|
|
@@ -143,7 +148,7 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
143
148
|
if (!key.includes(separator)) return key in source;
|
|
144
149
|
const keys = key.split(separator);
|
|
145
150
|
for (let currObj = source, i = 0, len = keys.length; i < len; i++) {
|
|
146
|
-
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(
|
|
151
|
+
const key2 = keyFunc ? keyFunc(keys[i]) : keys[i], match = key2.includes("[") && key2.match(arrRegex);
|
|
147
152
|
if (match) {
|
|
148
153
|
const [, key3, iStr] = match;
|
|
149
154
|
if (!Array.isArray(currObj[key3]) || !(key3 in currObj)) return false;
|
|
@@ -160,16 +165,48 @@ function inAny(source, key, separator = ".", keyFunc) {
|
|
|
160
165
|
function parseAnyObj(obj, separator = ".", keyFunc = (p) => p, seen = /* @__PURE__ */ new WeakSet()) {
|
|
161
166
|
if (!isObj(obj) || seen.has(obj)) return obj;
|
|
162
167
|
seen.add(obj);
|
|
163
|
-
const result = {};
|
|
164
|
-
|
|
168
|
+
const result = {}, keys = Object.keys(obj);
|
|
169
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
170
|
+
const k = keys[i];
|
|
171
|
+
k === "*" || k.includes(separator) ? setAny(result, k, parseAnyObj(obj[k], separator, keyFunc, seen), separator, keyFunc) : result[k] = isObj(obj[k]) ? parseAnyObj(obj[k], separator, keyFunc, seen) : obj[k];
|
|
172
|
+
}
|
|
165
173
|
return result;
|
|
166
174
|
}
|
|
167
175
|
function parseEvtOpts(options, opts, boolOpt = opts[0], result = {}) {
|
|
168
176
|
return Object.assign(result, "boolean" === typeof options ? { [boolOpt]: options } : options), result;
|
|
169
177
|
}
|
|
170
|
-
function
|
|
171
|
-
const
|
|
172
|
-
|
|
178
|
+
function fanout(a, b, c, d) {
|
|
179
|
+
const isEvPd = !!a?.target, isPath = !isEvPd && "string" === typeof b, [state, path, olds, news, opts, type] = isEvPd ? [a.root, a.currentTarget.path, a.currentTarget.oldValue, a.currentTarget.value, b || NIL, a.type] : isPath ? [a, b, getAny(a, b), c, d || NIL, void 0] : [void 0, void 0, a, b, c || NIL, void 0], target = isEvPd ? getAny(a.root, a.currentTarget.path) : isPath ? getAny(state, path) : olds;
|
|
180
|
+
if (isEvPd && type !== "set" && type !== "delete" || !target || !canHandle(news, opts)) return;
|
|
181
|
+
const prev = CTX.isCascading;
|
|
182
|
+
CTX.isCascading = isEvPd;
|
|
183
|
+
try {
|
|
184
|
+
const walk = (target2, obj, depth = isEvPd ? 1 : Infinity, keys = Object.keys(obj)) => {
|
|
185
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
186
|
+
const val = obj[keys[i]];
|
|
187
|
+
try {
|
|
188
|
+
if ((opts.atomic ?? true) && Array.isArray(val)) target2[keys[i]] = val, target2[keys[i]].length = target2[keys[i]].length;
|
|
189
|
+
else depth > 1 && canHandle(val, opts) ? walk(target2[keys[i]] ||= {}, val, depth - 1) : target2[keys[i]] = val;
|
|
190
|
+
} catch (e) {
|
|
191
|
+
if (e instanceof RangeError) throw e;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
if ((opts.atomic ?? true) && Array.isArray(news) && isPath) setAny(state, path, news), getAny(state, path).length = news.length;
|
|
196
|
+
else walk(target, opts.merge ? mergeObjs(olds, news, opts) : news, opts.depth === true ? Infinity : opts.depth);
|
|
197
|
+
} finally {
|
|
198
|
+
CTX.isCascading = prev;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
var fanoutOptsArr = ["merge", "depth", "atomic"];
|
|
202
|
+
function mergeObjs(o1, o2, config, pojocheck = true) {
|
|
203
|
+
if (pojocheck && (!isPOJO(o1 || NIL, config) || !isPOJO(o2 || NIL, config))) return o2;
|
|
204
|
+
const merged = { ...o1 ||= {}, ...o2 ||= {} }, keys = Object.keys(merged);
|
|
205
|
+
for (let i = 0, len = keys.length; i < len; i++) {
|
|
206
|
+
const o1C = o1[keys[i]], o2C = o2[keys[i]];
|
|
207
|
+
if (isPOJO(o1C, config) && isPOJO(o2C, config)) merged[keys[i]] = mergeObjs(o1C, o2C, config, false);
|
|
208
|
+
}
|
|
209
|
+
return merged;
|
|
173
210
|
}
|
|
174
211
|
function getTrailRecords(obj, path, reverse = false) {
|
|
175
212
|
const parts = path.split("."), chain = [["*", obj, obj]];
|
|
@@ -184,7 +221,12 @@ function deepClone(obj, config = NIL, seen = /* @__PURE__ */ new WeakMap()) {
|
|
|
184
221
|
const clone = config.preserveContext ? Object.create(Object.getPrototypeOf(obj)) : Array.isArray(obj) ? [] : {};
|
|
185
222
|
seen.set(obj, clone);
|
|
186
223
|
const keys = config.preserveContext ? Reflect.ownKeys(obj) : Object.keys(obj);
|
|
187
|
-
for (let i = 0, len = keys.length; i < len; i++)
|
|
224
|
+
for (let i = 0, len = keys.length; i < len; i++)
|
|
225
|
+
try {
|
|
226
|
+
clone[keys[i]] = deepClone(obj[keys[i]], config, seen);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
if (e instanceof RangeError) throw e;
|
|
229
|
+
}
|
|
188
230
|
return clone;
|
|
189
231
|
}
|
|
190
232
|
function nuke(target) {
|
|
@@ -342,6 +384,7 @@ function assignEl(el, props, dataset, styles) {
|
|
|
342
384
|
}
|
|
343
385
|
// Annotate the CommonJS export names for ESM import in node:
|
|
344
386
|
0 && (module.exports = {
|
|
387
|
+
arrRegex,
|
|
345
388
|
assignEl,
|
|
346
389
|
bindAllMethods,
|
|
347
390
|
canHandle,
|
|
@@ -350,6 +393,8 @@ function assignEl(el, props, dataset, styles) {
|
|
|
350
393
|
createEl,
|
|
351
394
|
deepClone,
|
|
352
395
|
deleteAny,
|
|
396
|
+
fanout,
|
|
397
|
+
fanoutOptsArr,
|
|
353
398
|
formatKeyForDisplay,
|
|
354
399
|
formatKeyShortcutsForDisplay,
|
|
355
400
|
getAny,
|
package/dist/utils.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { F as FanoutTuple, e as arrRegex, f as canHandle, g as deepClone, h as deleteAny, i as fanout, j as fanoutOptsArr, k as getAny, l as getTrailRecords, m as inAny, n as isObj, o as isPOJO, p as mergeObjs, q as nuke, r as parseAnyObj, s as parseEvtOpts, t as setAny } from './index-m0aAWxhX.cjs';
|
|
2
2
|
|
|
3
3
|
declare function clamp(min: number | undefined, val: number, max?: number): number;
|
|
4
4
|
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { F as FanoutTuple, e as arrRegex, f as canHandle, g as deepClone, h as deleteAny, i as fanout, j as fanoutOptsArr, k as getAny, l as getTrailRecords, m as inAny, n as isObj, o as isPOJO, p as mergeObjs, q as nuke, r as parseAnyObj, s as parseEvtOpts, t as setAny } from './index-m0aAWxhX.js';
|
|
2
2
|
|
|
3
3
|
declare function clamp(min: number | undefined, val: number, max?: number): number;
|
|
4
4
|
|
package/dist/utils.js
CHANGED
|
@@ -22,9 +22,12 @@ import {
|
|
|
22
22
|
setTimeout
|
|
23
23
|
} from "./chunk-P37ADJMM.js";
|
|
24
24
|
import {
|
|
25
|
+
arrRegex,
|
|
25
26
|
canHandle,
|
|
26
27
|
deepClone,
|
|
27
28
|
deleteAny,
|
|
29
|
+
fanout,
|
|
30
|
+
fanoutOptsArr,
|
|
28
31
|
getAny,
|
|
29
32
|
getTrailRecords,
|
|
30
33
|
inAny,
|
|
@@ -35,8 +38,9 @@ import {
|
|
|
35
38
|
parseAnyObj,
|
|
36
39
|
parseEvtOpts,
|
|
37
40
|
setAny
|
|
38
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-MKL3JUPO.js";
|
|
39
42
|
export {
|
|
43
|
+
arrRegex,
|
|
40
44
|
assignEl,
|
|
41
45
|
bindAllMethods,
|
|
42
46
|
canHandle,
|
|
@@ -45,6 +49,8 @@ export {
|
|
|
45
49
|
createEl,
|
|
46
50
|
deepClone,
|
|
47
51
|
deleteAny,
|
|
52
|
+
fanout,
|
|
53
|
+
fanoutOptsArr,
|
|
48
54
|
formatKeyForDisplay,
|
|
49
55
|
formatKeyShortcutsForDisplay,
|
|
50
56
|
getAny,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sia-reactor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
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",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"require": "./dist/utils.cjs",
|
|
34
34
|
"default": "./dist/utils.js"
|
|
35
35
|
},
|
|
36
|
-
"./
|
|
37
|
-
"types": "./dist/
|
|
38
|
-
"import": "./dist/
|
|
39
|
-
"require": "./dist/
|
|
40
|
-
"default": "./dist/
|
|
36
|
+
"./modules": {
|
|
37
|
+
"types": "./dist/modules.d.ts",
|
|
38
|
+
"import": "./dist/modules.js",
|
|
39
|
+
"require": "./dist/modules.cjs",
|
|
40
|
+
"default": "./dist/modules.js"
|
|
41
41
|
},
|
|
42
42
|
"./adapters/vanilla": {
|
|
43
43
|
"types": "./dist/adapters/vanilla.d.ts",
|