tiny-essentials 1.18.1 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +17 -3
  2. package/dist/node_modules/firebase-functions/lib/common/trace.cjs +0 -1
  3. package/dist/node_modules/firebase-functions/lib/logger/index.cjs +1 -0
  4. package/dist/v1/ColorSafeStringify.min.js +1 -1
  5. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  6. package/dist/v1/TinyBasicsEs.js +13 -6
  7. package/dist/v1/TinyBasicsEs.min.js +1 -1
  8. package/dist/v1/TinyClipboard.min.js +1 -1
  9. package/dist/v1/TinyColorConverter.js +617 -0
  10. package/dist/v1/TinyColorConverter.min.js +1 -0
  11. package/dist/v1/TinyDomReadyManager.min.js +1 -1
  12. package/dist/v1/TinyDragger.min.js +1 -1
  13. package/dist/v1/TinyEssentials.js +2635 -482
  14. package/dist/v1/TinyEssentials.min.js +1 -1
  15. package/dist/v1/TinyEvents.js +402 -0
  16. package/dist/v1/TinyEvents.min.js +1 -0
  17. package/dist/v1/TinyHtml.min.js +1 -1
  18. package/dist/v1/TinyLocalStorage.js +1292 -0
  19. package/dist/v1/TinyLocalStorage.min.js +1 -0
  20. package/dist/v1/TinyNotifications.min.js +1 -1
  21. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  22. package/dist/v1/TinyPromiseQueue.min.js +1 -1
  23. package/dist/v1/TinyRateLimiter.js +2 -1
  24. package/dist/v1/TinyRateLimiter.min.js +1 -1
  25. package/dist/v1/TinySmartScroller.js +570 -52
  26. package/dist/v1/TinySmartScroller.min.js +1 -1
  27. package/dist/v1/TinyTextRangeEditor.min.js +1 -1
  28. package/dist/v1/TinyTimeout.js +233 -0
  29. package/dist/v1/TinyTimeout.min.js +1 -0
  30. package/dist/v1/TinyToastNotify.min.js +1 -1
  31. package/dist/v1/TinyUploadClicker.js +1457 -106
  32. package/dist/v1/TinyUploadClicker.min.js +1 -1
  33. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  34. package/dist/v1/basics/html.cjs +13 -6
  35. package/dist/v1/basics/html.d.mts +12 -4
  36. package/dist/v1/basics/html.mjs +13 -6
  37. package/dist/v1/build/TinyColorConverter.cjs +7 -0
  38. package/dist/v1/build/TinyColorConverter.d.mts +3 -0
  39. package/dist/v1/build/TinyColorConverter.mjs +2 -0
  40. package/dist/v1/build/TinyEvents.cjs +7 -0
  41. package/dist/v1/build/TinyEvents.d.mts +3 -0
  42. package/dist/v1/build/TinyEvents.mjs +2 -0
  43. package/dist/v1/build/TinyLocalStorage.cjs +7 -0
  44. package/dist/v1/build/TinyLocalStorage.d.mts +3 -0
  45. package/dist/v1/build/TinyLocalStorage.mjs +2 -0
  46. package/dist/v1/build/TinyTimeout.cjs +7 -0
  47. package/dist/v1/build/TinyTimeout.d.mts +3 -0
  48. package/dist/v1/build/TinyTimeout.mjs +2 -0
  49. package/dist/v1/index.cjs +8 -0
  50. package/dist/v1/index.d.mts +5 -1
  51. package/dist/v1/index.mjs +5 -1
  52. package/dist/v1/libs/TinyColorConverter.cjs +578 -0
  53. package/dist/v1/libs/TinyColorConverter.d.mts +396 -0
  54. package/dist/v1/libs/TinyColorConverter.mjs +520 -0
  55. package/dist/v1/libs/TinyEvents.cjs +363 -0
  56. package/dist/v1/libs/TinyEvents.d.mts +160 -0
  57. package/dist/v1/libs/TinyEvents.mjs +328 -0
  58. package/dist/v1/libs/TinyLocalStorage.cjs +847 -0
  59. package/dist/v1/libs/TinyLocalStorage.d.mts +407 -0
  60. package/dist/v1/libs/TinyLocalStorage.mjs +740 -0
  61. package/dist/v1/libs/TinySmartScroller.cjs +207 -52
  62. package/dist/v1/libs/TinySmartScroller.d.mts +164 -16
  63. package/dist/v1/libs/TinySmartScroller.mjs +181 -52
  64. package/dist/v1/libs/TinyTimeout.cjs +194 -0
  65. package/dist/v1/libs/TinyTimeout.d.mts +89 -0
  66. package/dist/v1/libs/TinyTimeout.mjs +179 -0
  67. package/dist/v1/libs/TinyUploadClicker.cjs +1 -0
  68. package/docs/v1/README.md +4 -0
  69. package/docs/v1/libs/TinyColorConverter.md +220 -0
  70. package/docs/v1/libs/TinyEvents.md +199 -0
  71. package/docs/v1/libs/TinyLocalStorage.md +350 -0
  72. package/docs/v1/libs/TinyRateLimiter.md +0 -3
  73. package/docs/v1/libs/TinyTimeout.md +190 -0
  74. package/package.json +28 -5
@@ -0,0 +1,407 @@
1
+ export default TinyLocalStorage;
2
+ /**
3
+ * A function that encodes a value into a serializable JSON-compatible format.
4
+ */
5
+ export type EncodeFn = (value: any, encodeSpecialJson: encodeSpecialJson) => any;
6
+ /**
7
+ * An object that defines how to check and decode a specific serialized type.
8
+ */
9
+ export type DecodeFn = {
10
+ /**
11
+ * - Checks if the value matches the custom encoded structure.
12
+ */
13
+ check: (value: any) => any;
14
+ /**
15
+ * - Decodes the structure back into its original form.
16
+ */
17
+ decode: (value: any, decodeSpecialJson: decodeSpecialJson) => any;
18
+ };
19
+ /**
20
+ * Encodes extended JSON-compatible structures recursively.
21
+ */
22
+ export type encodeSpecialJson = (value: any) => any;
23
+ /**
24
+ * Decodes extended JSON-compatible structures recursively.
25
+ */
26
+ export type decodeSpecialJson = (value: any) => any;
27
+ /**
28
+ * Represents a value that can be safely stored and restored using JSON in `localStorage`,
29
+ * including structures like arrays, plain objects, Map and Set.
30
+ *
31
+ * - `Record<string|number|symbol, any>` → plain object (e.g., `{ key: value }`)
32
+ * - `any[]` → array of any JSON-serializable values
33
+ * - `Map<string|number|symbol, any>` → converted to `{ __map__: true, data: [[k, v], ...] }`
34
+ * - `Set<any>` → converted to `{ __set__: true, data: [v1, v2, ...] }`
35
+ *
36
+ * These conversions allow complex structures to be restored after JSON serialization.
37
+ */
38
+ export type LocalStorageJsonValue = (Record<string | number | symbol, any> | any[] | Map<string | number | symbol, any> | Set<any>);
39
+ /**
40
+ * A function that encodes a value into a serializable JSON-compatible format.
41
+ *
42
+ * @callback EncodeFn
43
+ * @param {any} value - The value to encode.
44
+ * @param {encodeSpecialJson} encodeSpecialJson - Recursive encoder helper.
45
+ * @returns {any} The encoded value.
46
+ */
47
+ /**
48
+ * An object that defines how to check and decode a specific serialized type.
49
+ *
50
+ * @typedef {Object} DecodeFn
51
+ * @property {(value: any) => any} check - Checks if the value matches the custom encoded structure.
52
+ * @property {(value: any, decodeSpecialJson: decodeSpecialJson) => any} decode - Decodes the structure back into its original form.
53
+ */
54
+ /**
55
+ * Encodes extended JSON-compatible structures recursively.
56
+ * @callback encodeSpecialJson
57
+ * @param {any} value
58
+ * @returns {any}
59
+ */
60
+ /**
61
+ * Decodes extended JSON-compatible structures recursively.
62
+ * @callback decodeSpecialJson
63
+ * @param {any} value
64
+ * @returns {any}
65
+ */
66
+ /**
67
+ * Represents a value that can be safely stored and restored using JSON in `localStorage`,
68
+ * including structures like arrays, plain objects, Map and Set.
69
+ *
70
+ * - `Record<string|number|symbol, any>` → plain object (e.g., `{ key: value }`)
71
+ * - `any[]` → array of any JSON-serializable values
72
+ * - `Map<string|number|symbol, any>` → converted to `{ __map__: true, data: [[k, v], ...] }`
73
+ * - `Set<any>` → converted to `{ __set__: true, data: [v1, v2, ...] }`
74
+ *
75
+ * These conversions allow complex structures to be restored after JSON serialization.
76
+ *
77
+ * @typedef {(Record<string|number|symbol, any> | any[] | Map<string|number|symbol, any> | Set<any>)} LocalStorageJsonValue
78
+ */
79
+ /**
80
+ * A powerful wrapper for Web Storage (`localStorage` or `sessionStorage`) that supports
81
+ * type-safe methods and full JSON-like structure encoding and decoding.
82
+ *
83
+ * `TinyLocalStorage` allows storing and retrieving complex types such as:
84
+ * - `Map`, `Set`
85
+ * - `Date`, `RegExp`
86
+ * - `BigInt`, `Symbol`
87
+ * - `undefined`, `null`
88
+ * - Plain objects and arrays
89
+ *
90
+ * Includes:
91
+ * - Type-specific `set` and `get` methods (`setDate`, `getBool`, etc.)
92
+ * - `getValue()` to retrieve any structure regardless of type
93
+ * - Auto-encoding/decoding with support for custom types via `registerJsonType`
94
+ * - Built-in event system (`TinyEvents`) to listen for changes
95
+ * - Optional fallback values on decoding errors
96
+ *
97
+ * Supports registering and unregistering custom types via:
98
+ * - `registerJsonType(...)`
99
+ * - `deleteJsonType(...)`
100
+ *
101
+ * This class is suitable for applications that require structured persistence in the browser.
102
+ */
103
+ declare class TinyLocalStorage {
104
+ /**
105
+ * Registers a new JSON-serializable type with its encoder and decoder.
106
+ *
107
+ * @param {any} type - The type or primitive type name (e.g. `"bigint"`, `"symbol"`, etc).
108
+ * @param {EncodeFn} encodeFn - The function that encodes the value.
109
+ * @param {DecodeFn} decodeFn - An object with `check` and `decode` methods for restoring the value.
110
+ */
111
+ static registerJsonType(type: any, encodeFn: EncodeFn, decodeFn: DecodeFn): void;
112
+ /**
113
+ * Removes a previously registered custom type from the encoding/decoding system.
114
+ *
115
+ * @param {string} type - The primitive name or constructor reference used in registration.
116
+ */
117
+ static deleteJsonType(type: string): void;
118
+ static encodeSpecialJson(value: any): any;
119
+ static decodeSpecialJson(value: any): any;
120
+ /**
121
+ * Enables or disables throwing an error when the maximum number of listeners is exceeded.
122
+ *
123
+ * @param {boolean} shouldThrow - If true, an error will be thrown when the max is exceeded.
124
+ */
125
+ setThrowOnMaxListeners(shouldThrow: boolean): void;
126
+ /**
127
+ * Checks whether an error will be thrown when the max listener limit is exceeded.
128
+ *
129
+ * @returns {boolean} True if an error will be thrown, false if only a warning is shown.
130
+ */
131
+ getThrowOnMaxListeners(): boolean;
132
+ /**
133
+ * Adds a listener to the beginning of the listeners array for the specified event.
134
+ *
135
+ * @param {string} event - Event name.
136
+ * @param {handler} handler - The callback function.
137
+ */
138
+ prependListener(event: string, handler: import("./TinyEvents.mjs").handler): void;
139
+ /**
140
+ * Adds a one-time listener to the beginning of the listeners array for the specified event.
141
+ *
142
+ * @param {string} event - Event name.
143
+ * @param {handler} handler - The callback function.
144
+ * @returns {handler} - The wrapped handler used internally.
145
+ */
146
+ prependListenerOnce(event: string, handler: import("./TinyEvents.mjs").handler): import("./TinyEvents.mjs").handler;
147
+ /**
148
+ * Adds a event listener.
149
+ *
150
+ * @param {string} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
151
+ * @param {handler} handler - Callback function to be called when event fires.
152
+ */
153
+ appendListener(event: string, handler: import("./TinyEvents.mjs").handler): void;
154
+ /**
155
+ * Registers an event listener that runs only once, then is removed.
156
+ *
157
+ * @param {string} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
158
+ * @param {handler} handler - The callback function to run on event.
159
+ * @returns {handler} - The wrapped version of the handler.
160
+ */
161
+ appendListenerOnce(event: string, handler: import("./TinyEvents.mjs").handler): import("./TinyEvents.mjs").handler;
162
+ /**
163
+ * Adds a event listener.
164
+ *
165
+ * @param {string} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
166
+ * @param {handler} handler - Callback function to be called when event fires.
167
+ */
168
+ on(event: string, handler: import("./TinyEvents.mjs").handler): void;
169
+ /**
170
+ * Registers an event listener that runs only once, then is removed.
171
+ *
172
+ * @param {string} event - Event name, such as 'onScrollBoundary' or 'onAutoScroll'.
173
+ * @param {handler} handler - The callback function to run on event.
174
+ * @returns {handler} - The wrapped version of the handler.
175
+ */
176
+ once(event: string, handler: import("./TinyEvents.mjs").handler): import("./TinyEvents.mjs").handler;
177
+ /**
178
+ * Removes a previously registered event listener.
179
+ *
180
+ * @param {string} event - The name of the event to remove the handler from.
181
+ * @param {handler} handler - The specific callback function to remove.
182
+ */
183
+ off(event: string, handler: import("./TinyEvents.mjs").handler): void;
184
+ /**
185
+ * Removes all event listeners of a specific type from the element.
186
+ *
187
+ * @param {string} event - The event type to remove (e.g. 'onScrollBoundary').
188
+ */
189
+ offAll(event: string): void;
190
+ /**
191
+ * Removes all event listeners of all types from the element.
192
+ */
193
+ offAllTypes(): void;
194
+ /**
195
+ * Returns the number of listeners for a given event.
196
+ *
197
+ * @param {string} event - The name of the event.
198
+ * @returns {number} Number of listeners for the event.
199
+ */
200
+ listenerCount(event: string): number;
201
+ /**
202
+ * Returns a copy of the array of listeners for the specified event.
203
+ *
204
+ * @param {string} event - The name of the event.
205
+ * @returns {handler[]} Array of listener functions.
206
+ */
207
+ listeners(event: string): import("./TinyEvents.mjs").handler[];
208
+ /**
209
+ * Returns a copy of the array of listeners for the specified event.
210
+ *
211
+ * @param {string} event - The name of the event.
212
+ * @returns {handler[]} Array of listener functions.
213
+ */
214
+ onceListeners(event: string): import("./TinyEvents.mjs").handler[];
215
+ /**
216
+ * Returns a copy of the internal listeners array for the specified event,
217
+ * including wrapper functions like those used by `.once()`.
218
+ * @param {string | symbol} event - The event name.
219
+ * @returns {handler[]} An array of raw listener functions.
220
+ */
221
+ allListeners(event: string | symbol): import("./TinyEvents.mjs").handler[];
222
+ /**
223
+ * Returns an array of event names for which there are registered listeners.
224
+ *
225
+ * @returns {string[]} Array of registered event names.
226
+ */
227
+ eventNames(): string[];
228
+ /**
229
+ * Emits an event, triggering all registered handlers for that event.
230
+ *
231
+ * @param {string} event - The event name to emit.
232
+ * @param {...any} payload - Optional data to pass to each handler.
233
+ * @returns {boolean} True if any listeners were called, false otherwise.
234
+ */
235
+ emit(event: string, ...payload: any[]): boolean;
236
+ /**
237
+ * Sets the maximum number of listeners per event before a warning is shown.
238
+ *
239
+ * @param {number} n - The maximum number of listeners.
240
+ */
241
+ setMaxListeners(n: number): void;
242
+ /**
243
+ * Gets the maximum number of listeners allowed per event.
244
+ *
245
+ * @returns {number} The maximum number of listeners.
246
+ */
247
+ getMaxListeners(): number;
248
+ /**
249
+ * Defines a custom storage interface (e.g. `sessionStorage`).
250
+ *
251
+ * @param {Storage} localstorage - A valid Storage object (localStorage or sessionStorage).
252
+ */
253
+ setLocalStorage(localstorage: Storage): void;
254
+ /**
255
+ * Checks if `localStorage` is supported by the current environment.
256
+ *
257
+ * @returns {boolean} True if `localStorage` exists, false otherwise.
258
+ */
259
+ localStorageExists(): boolean;
260
+ /**
261
+ * Stores a JSON-compatible value in `localStorage`.
262
+ *
263
+ * Automatically serializes nested `Map` and `Set` instances.
264
+ *
265
+ * @param {string} name - The key under which to store the data.
266
+ * @param {LocalStorageJsonValue} data - The data to be serialized and stored.
267
+ */
268
+ setJson(name: string, data: LocalStorageJsonValue): void;
269
+ /**
270
+ * Retrieves and parses a JSON value from `localStorage`.
271
+ *
272
+ * Automatically restores nested `Map` and `Set` instances.
273
+ *
274
+ * @param {string} name - The key to retrieve.
275
+ * @param {'array'|'obj'|'map'|'set'|'null'} [defaultData] - Default fallback format if value is invalid.
276
+ * @returns {LocalStorageJsonValue|null} The parsed object or fallback.
277
+ */
278
+ getJson(name: string, defaultData?: "array" | "obj" | "map" | "set" | "null"): LocalStorageJsonValue | null;
279
+ /**
280
+ * Stores a Date in localStorage.
281
+ * @param {string} name
282
+ * @param {Date} data
283
+ */
284
+ setDate(name: string, data: Date): void;
285
+ /**
286
+ * Retrieves a Date from localStorage.
287
+ * @param {string} name
288
+ * @returns {Date|null}
289
+ */
290
+ getDate(name: string): Date | null;
291
+ /**
292
+ * Stores a RegExp in localStorage.
293
+ * @param {string} name
294
+ * @param {RegExp} data
295
+ */
296
+ setRegExp(name: string, data: RegExp): void;
297
+ /**
298
+ * Retrieves a RegExp from localStorage.
299
+ * @param {string} name
300
+ * @returns {RegExp|null}
301
+ */
302
+ getRegExp(name: string): RegExp | null;
303
+ /**
304
+ * Stores a BigInt in localStorage.
305
+ * @param {string} name
306
+ * @param {bigint} data
307
+ */
308
+ setBigInt(name: string, data: bigint): void;
309
+ /**
310
+ * Retrieves a BigInt from localStorage.
311
+ * @param {string} name
312
+ * @returns {bigint|null}
313
+ */
314
+ getBigInt(name: string): bigint | null;
315
+ /**
316
+ * Stores a Symbol in localStorage.
317
+ * Only global symbols (`Symbol.for`) will preserve the key.
318
+ * @param {string} name
319
+ * @param {symbol} data
320
+ */
321
+ setSymbol(name: string, data: symbol): void;
322
+ /**
323
+ * Retrieves a Symbol from localStorage.
324
+ * @param {string} name
325
+ * @returns {symbol|null}
326
+ */
327
+ getSymbol(name: string): symbol | null;
328
+ /**
329
+ * Retrieves a value from `localStorage`.
330
+ *
331
+ * @param {string} name - The key to retrieve.
332
+ * @returns {any} The stored value or null if not found.
333
+ */
334
+ getValue(name: string): any;
335
+ /**
336
+ * Stores a raw string value in `localStorage`.
337
+ *
338
+ * @param {string} name - The key to use.
339
+ * @param {any} data - The data to store.
340
+ */
341
+ setItem(name: string, data: any): void;
342
+ /**
343
+ * Retrieves a raw string value from `localStorage`.
344
+ *
345
+ * @param {string} name - The key to retrieve.
346
+ * @returns {string|null} The stored value or null if not found.
347
+ */
348
+ getItem(name: string): string | null;
349
+ /**
350
+ * Stores a string in `localStorage`, ensuring the data is a valid string.
351
+ *
352
+ * @param {string} name - The key to store the string under.
353
+ * @param {string} data - The string to store.
354
+ */
355
+ setString(name: string, data: string): void;
356
+ /**
357
+ * Retrieves a string value from `localStorage`.
358
+ *
359
+ * @param {string} name - The key to retrieve.
360
+ * @returns {string|null} The string if valid, or null.
361
+ */
362
+ getString(name: string): string | null;
363
+ /**
364
+ * Stores a number value in `localStorage`.
365
+ *
366
+ * @param {string} name - The key to use.
367
+ * @param {number} data - The number to store.
368
+ */
369
+ setNumber(name: string, data: number): void;
370
+ /**
371
+ * Retrieves a number from `localStorage`.
372
+ *
373
+ * @param {string} name - The key to retrieve.
374
+ * @returns {number|null} The number or null if invalid.
375
+ */
376
+ getNumber(name: string): number | null;
377
+ /**
378
+ * Stores a boolean value in `localStorage`.
379
+ *
380
+ * @param {string} name - The key to use.
381
+ * @param {boolean} data - The boolean value to store.
382
+ */
383
+ setBool(name: string, data: boolean): void;
384
+ /**
385
+ * Retrieves a boolean value from `localStorage`.
386
+ *
387
+ * @param {string} name - The key to retrieve.
388
+ * @returns {boolean|null} The boolean or null if invalid.
389
+ */
390
+ getBool(name: string): boolean | null;
391
+ /**
392
+ * Removes a value from `localStorage`.
393
+ *
394
+ * @param {string} name - The key to remove.
395
+ */
396
+ removeItem(name: string): void;
397
+ /**
398
+ * Clears all data from `localStorage`.
399
+ */
400
+ clearLocalStorage(): void;
401
+ /**
402
+ * Destroys the storage instance by removing the storage event listener.
403
+ */
404
+ destroy(): void;
405
+ #private;
406
+ }
407
+ //# sourceMappingURL=TinyLocalStorage.d.mts.map