atomaric 0.0.69 → 0.0.70

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/build/atomaric.js CHANGED
@@ -1,10 +1,10 @@
1
1
  let k = () => {
2
2
  throw "call configureAtomaric() before all!";
3
3
  };
4
- const L = {}, Ae = (t) => {
5
- L.useSyncExternalStore = k = t.useSyncExternalStore, L.keyPathSeparator = t.keyPathSeparator, L.securifyKeyLevel = t.securifyKeyLevel, L.securifyValueLevel = t.securifyValueLevel;
6
- }, ne = (t) => k(t.subscribe, t.get), oe = (t) => t.set, Se = (t) => t.setDeferred, xe = (t) => t.get, be = (t) => t.do, De = (t) => [ne(t), oe(t)], $e = (t, e) => new de(t, e);
7
- class E {
4
+ const M = {}, Se = (t) => {
5
+ M.useSyncExternalStore = k = t.useSyncExternalStore, M.keyPathSeparator = t.keyPathSeparator, M.securifyKeyLevel = t.securifyKeyLevel, M.securifyValueLevel = t.securifyValueLevel;
6
+ }, ne = (t) => k(t.subscribe, t.get), oe = (t) => t.set, xe = (t) => t.setDeferred, be = (t) => t.get, De = (t) => t.do, $e = (t) => [ne(t), oe(t)], Me = (t, e) => new pe(t, e);
7
+ class _ {
8
8
  constructor(e) {
9
9
  if (e)
10
10
  return new Proxy(this, {
@@ -14,33 +14,33 @@ class E {
14
14
  }
15
15
  const ce = (t, e) => {
16
16
  const n = (s, o, i) => new Proxy(s, {
17
- get: (u, f, y) => {
18
- const d = i === 0 && e.get != null ? e.get(u, f, y) : u[f];
17
+ get: (l, h, p) => {
18
+ const d = i === 0 && e.get != null ? e.get(l, h, p) : l[h];
19
19
  return typeof d == "object" && d !== null ? n(
20
20
  Array.isArray(d) ? d.slice(0) : { ...d },
21
- o.concat(Array.isArray(u) ? +f : f),
21
+ o.concat(Array.isArray(l) ? +h : h),
22
22
  i + 1
23
23
  ) : d;
24
24
  },
25
- set: (u, f, y) => (e.onSet(u, o, f, y, u[f]) && (u[f] = y), !0)
25
+ set: (l, h, p) => (e.onSet(l, o, h, p, l[h]) && (l[h] = p), !0)
26
26
  });
27
27
  return n(t, [], 0);
28
28
  };
29
- class O extends E {
29
+ class O extends _ {
30
30
  constructor() {
31
31
  super(...arguments), this.updateValue = (e, n) => {
32
32
  const s = Array.isArray(e) ? e.slice(0) : { ...e };
33
33
  let o = !1;
34
34
  const i = ce(e, {
35
- onSet: (u, f, y, d, g) => {
36
- if (d === g) return !0;
37
- let A = s;
35
+ onSet: (l, h, p, d, y) => {
36
+ if (d === y) return !0;
37
+ let S = s;
38
38
  o = !0;
39
- for (const l of f) {
40
- const h = A[l];
41
- A = A[l] = Array.isArray(h) ? h.slice(0) : { ...h };
39
+ for (const f of h) {
40
+ const m = S[f];
41
+ S = S[f] = Array.isArray(m) ? m.slice(0) : { ...m };
42
42
  }
43
- return A[y] = d, !0;
43
+ return S[p] = d, !0;
44
44
  }
45
45
  });
46
46
  return n(i), o ? s : e;
@@ -66,27 +66,43 @@ class ie extends O {
66
66
  const i = this.atom.get().slice(0);
67
67
  i.splice(o, 1), this.atom.set(i);
68
68
  }, this.toggle = (s, o) => {
69
- const i = this.atom.get().slice(), u = i.indexOf(s);
70
- u < 0 ? o ? i.unshift(s) : i.push(s) : i.splice(u, 1), this.atom.set(i);
69
+ const i = this.atom.get().slice(), l = i.indexOf(s);
70
+ l < 0 ? o ? i.unshift(s) : i.push(s) : i.splice(l, 1), this.atom.set(i);
71
71
  };
72
72
  }
73
73
  }
74
74
  const ae = (t) => t;
75
- class ue extends E {
75
+ class ue extends _ {
76
76
  constructor(e, n) {
77
77
  super(n), this.atom = e, this.toggle = () => {
78
78
  this.atom.set(!this.atom.get());
79
79
  };
80
80
  }
81
81
  }
82
- class le extends E {
82
+ class le extends _ {
83
+ constructor(e, n) {
84
+ super(n), this.atom = e, this.setValue = (s, o) => {
85
+ const i = new Map(this.atom.get());
86
+ i.set(s, o), this.atom.set(i);
87
+ }, this.delete = (s) => {
88
+ const o = new Map(this.atom.get());
89
+ o.delete(s), this.atom.set(o);
90
+ }, this.toggle = (s, o) => {
91
+ const i = new Map(this.atom.get());
92
+ i.has(s) ? i.delete(s) : i.set(s, o), this.atom.set(i);
93
+ }, this.clear = () => {
94
+ this.atom.set(/* @__PURE__ */ new Map());
95
+ }, this.atom = e;
96
+ }
97
+ }
98
+ class fe extends _ {
83
99
  constructor(e, n) {
84
100
  super(n), this.atom = e, this.increment = (s) => {
85
101
  this.atom.set(+this.atom.get() + (s ?? 1));
86
102
  };
87
103
  }
88
104
  }
89
- class fe extends O {
105
+ class he extends O {
90
106
  constructor(e, n) {
91
107
  super(n), this.atom = e, this.setPartial = (s) => this.atom.set((o) => ({
92
108
  ...o,
@@ -94,36 +110,36 @@ class fe extends O {
94
110
  })), this.update = (s) => {
95
111
  const o = this.atom.get(), i = this.updateValue(o, s);
96
112
  i !== o && this.atom.set(i);
97
- }, this.setDeepPartial = (s, o, i, u = L.keyPathSeparator || ".") => {
98
- if (!u) return;
99
- if (s.includes(u)) {
100
- let d = s.split(u);
101
- const g = d[d.length - 1];
113
+ }, this.setDeepPartial = (s, o, i, l = M.keyPathSeparator || ".") => {
114
+ if (!l) return;
115
+ if (s.includes(l)) {
116
+ let d = s.split(l);
117
+ const y = d[d.length - 1];
102
118
  d = d.slice(0, -1);
103
- const A = { ...this.atom.get() };
104
- let l = A, h = i;
105
- for (const p of d) {
106
- h = h == null ? void 0 : h[Array.isArray(h) ? "0" : p];
107
- const x = l[Z(l, p)] ?? (Array.isArray(h) ? [] : {});
108
- if (x == null || typeof x != "object") {
119
+ const S = { ...this.atom.get() };
120
+ let f = S, m = i;
121
+ for (const w of d) {
122
+ m = m == null ? void 0 : m[Array.isArray(m) ? "0" : w];
123
+ const D = f[Z(f, w)] ?? (Array.isArray(m) ? [] : {});
124
+ if (D == null || typeof D != "object") {
109
125
  if (i == null) throw "Incorrect path for setDeepPartial";
110
- const S = typeof o == "function" ? o(void 0) : o;
111
- this.atom.get()[s] !== S && this.setPartial({ [s]: S });
126
+ const b = typeof o == "function" ? o(void 0) : o;
127
+ this.atom.get()[s] !== b && this.setPartial({ [s]: b });
112
128
  return;
113
129
  }
114
- l = l[Z(l, p)] = Array.isArray(x) ? [...x] : { ...x };
130
+ f = f[Z(f, w)] = Array.isArray(D) ? [...D] : { ...D };
115
131
  }
116
- const z = l[g];
117
- l[g] = typeof o == "function" ? o(l[g]) : o, z !== l[g] && this.atom.set(A);
132
+ const E = f[y];
133
+ f[y] = typeof o == "function" ? o(f[y]) : o, E !== f[y] && this.atom.set(S);
118
134
  return;
119
135
  }
120
- const f = this.atom.get()[s], y = typeof o == "function" ? o(f) : o;
121
- y !== f && this.setPartial({ [s]: y });
136
+ const h = this.atom.get()[s], p = typeof o == "function" ? o(h) : o;
137
+ p !== h && this.setPartial({ [s]: p });
122
138
  };
123
139
  }
124
140
  }
125
141
  const Z = (t, e) => Array.isArray(t) ? `${+e}` : e;
126
- class he extends E {
142
+ class me extends _ {
127
143
  constructor(e, n) {
128
144
  super(n), this.atom = e, this.add = (s) => {
129
145
  this.atom.set(new Set(this.atom.get()).add(s));
@@ -138,168 +154,188 @@ class he extends E {
138
154
  }, this.atom = e;
139
155
  }
140
156
  }
141
- const me = (t, e, n) => {
157
+ const de = (t, e, n) => {
142
158
  const s = typeof n == "object" && n != null && "do" in n ? n.do(
143
- (i, u) => e.set(i, u),
159
+ (i, l) => e.set(i, l),
144
160
  () => e.get(),
145
161
  e,
146
- (i, u, f) => e.setDeferred(i, u, f)
162
+ (i, l, h) => e.setDeferred(i, l, h)
147
163
  ) : null, o = {};
148
- return s && Object.keys(s).forEach((i) => Object.defineProperty(o, i, { get: () => s[i] })), typeof t == "number" ? new le(e, s) : typeof t == "boolean" ? new ue(e, s) : Array.isArray(t) ? new ie(e, s) : t instanceof Set ? new he(e, s) : t instanceof Object ? new fe(e, s) : new E(s);
164
+ return s && Object.keys(s).forEach((i) => Object.defineProperty(o, i, { get: () => s[i] })), typeof t == "number" ? new fe(e, s) : typeof t == "boolean" ? new ue(e, s) : Array.isArray(t) ? new ie(e, s) : t instanceof Set ? new me(e, s) : t instanceof Map ? new le(e, s) : t instanceof Object ? new he(e, s) : new _(s);
149
165
  };
150
- class de {
166
+ class pe {
151
167
  constructor(e, n) {
152
168
  e = typeof e == "function" ? e() : e;
153
- const s = (r) => d = r, o = () => d, i = /* @__PURE__ */ new Set(), u = (r) => r(l());
154
- let f = !0, y = !1, d = e, g, A = () => {
155
- }, l = () => o(), h = null, z = () => {
156
- const r = me(e, p, n);
157
- return z = () => r, r;
169
+ const s = (r) => d = r, o = () => d, i = /* @__PURE__ */ new Set(), l = (r) => r(f());
170
+ let h = !0, p = !1, d = e, y, S = () => {
171
+ }, f = () => o(), m = null, E = () => {
172
+ const r = de(e, w, n);
173
+ return E = () => r, r;
158
174
  };
159
- const p = new Proxy(this, {
160
- get: (r, m) => m === "do" ? z() : r[m],
161
- set: ye
162
- }), x = () => {
163
- f = !0, y !== !0 && A(l()), y = !1;
175
+ const w = new Proxy(this, {
176
+ get: (r, a) => a === "do" ? E() : r[a],
177
+ set: ge
178
+ }), D = () => {
179
+ h = !0, p !== !0 && S(f()), p = !1;
164
180
  try {
165
- W.postMessage({ key: a, value: o() });
181
+ v.postMessage({ key: u, value: o() });
166
182
  } catch {
167
183
  }
168
- }, S = (r, m) => {
169
- const D = typeof r == "function" ? r(l()) : r;
170
- D !== l() && (s(D), y = m, f && (f = !1, i.forEach(u), queueMicrotask(x)));
184
+ }, b = (r, a) => {
185
+ const g = typeof r == "function" ? r(f()) : r;
186
+ g !== f() && (s(g), p = a, h && (h = !1, i.forEach(l), queueMicrotask(D)));
171
187
  };
172
- this.set = (r, m) => S(r, m), this.get = () => l(), this.initialValue = e, this.isInitialValue = () => e === o(), this.subscribe = (r) => (i.add(r), () => {
188
+ this.set = (r, a) => b(r, a), this.get = () => f(), this.initialValue = e, this.isInitialValue = () => e === o(), this.subscribe = (r) => (i.add(r), () => {
173
189
  i.delete(r);
174
190
  }), this.reset = () => {
175
- S(e, !0);
191
+ b(e, !0);
176
192
  };
177
- const re = (r, m) => {
178
- S(r, m), g = void 0;
193
+ const re = (r, a) => {
194
+ b(r, a), y = void 0;
179
195
  };
180
- if (this.setDeferred = (r, m = 500, D, $ = !0) => {
181
- $ && g === void 0 && S(r, D), clearTimeout(g), g = setTimeout(re, m, r, D);
182
- }, n == null) return p;
183
- let w = null, j = null, M = !0, v = !0, B = !1, b = 0, T = 0, Q = -1, V = e instanceof Set ? (r) => new Set(r) : (r) => r, C = e instanceof Set ? (r) => {
196
+ if (this.setDeferred = (r, a = 500, g, x = !0) => {
197
+ x && y === void 0 && b(r, g), clearTimeout(y), y = setTimeout(re, a, r, g);
198
+ }, n == null) return w;
199
+ let A = null, V = null, U = !0, q = !0, J = !1, $ = 0, T = 0, K = -1, L = e instanceof Set ? (r) => new Set(r) : e instanceof Map ? (r) => {
200
+ if (!r || typeof r != "object") return /* @__PURE__ */ new Map();
201
+ const a = /* @__PURE__ */ new Map();
202
+ for (const g in r)
203
+ try {
204
+ a.set(JSON.parse(g), r[g]);
205
+ } catch {
206
+ }
207
+ return a;
208
+ } : (r) => r, j = e instanceof Set ? (r) => {
184
209
  if (r instanceof Set) return Array.from(r);
185
210
  throw console.error(r), "The value is not Set instance";
211
+ } : e instanceof Map ? (r) => {
212
+ if (r instanceof Map) {
213
+ const a = {};
214
+ return r.forEach((g, x) => {
215
+ try {
216
+ a[JSON.stringify(x)] = g;
217
+ } catch {
218
+ }
219
+ }), a;
220
+ }
221
+ throw console.error(r), "The value is not Set instance";
186
222
  } : (r) => r;
187
223
  if (typeof n == "string")
188
- w = n;
224
+ A = n;
189
225
  else if ("storeKey" in n)
190
- M = n.warnOnDuplicateStoreKey ?? M, v = n.listenStorageChanges ?? v, w = n.storeKey, V = n.unzipValue ?? V, C = n.zipValue ?? C, B = n.unchangable ?? B, b = n.securifyKeyLevel ?? L.securifyKeyLevel ?? b, T = n.securifyValueLevel ?? L.securifyValueLevel ?? T, j = n.exp ?? j;
191
- else return p;
192
- const F = b ? I(w, b) : w, a = `${T ? H : P}${F}`;
193
- if (b) {
194
- const r = `${P}${w}`;
195
- r in c && (c[a] = c[r], delete c[r]);
226
+ U = n.warnOnDuplicateStoreKey ?? U, q = n.listenStorageChanges ?? q, A = n.storeKey, L = n.unzipValue ?? L, j = n.zipValue ?? j, J = n.unchangable ?? J, $ = n.securifyKeyLevel ?? M.securifyKeyLevel ?? $, T = n.securifyValueLevel ?? M.securifyValueLevel ?? T, V = n.exp ?? V;
227
+ else return w;
228
+ const B = $ ? C(A, $) : A, u = `${T ? H : I}${B}`;
229
+ if ($) {
230
+ const r = `${I}${A}`;
231
+ r in c && (c[u] = c[r], delete c[r]);
196
232
  } else {
197
- const r = `${P}${I(w, b)}`;
198
- r in c && (c[a] = c[r], delete c[r]);
233
+ const r = `${I}${C(A, $)}`;
234
+ r in c && (c[u] = c[r], delete c[r]);
199
235
  }
200
- const N = j === null || !(j(p, a in c) instanceof Date) ? (r) => I([C(r)], 0) : (r) => (h ?? (h = {}), h.exp = j(p, a in c).getTime(), h.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(Q), clearTimeout(ee[a]), Q = setTimeout(() => this.reset(), h.exp - Date.now())), h.exp = Math.trunc(h.exp / 1e3), I([C(r), h], 0));
236
+ const F = V === null || !(V(w, u in c) instanceof Date) ? (r) => C([j(r)], 0) : (r) => (m ?? (m = {}), m.exp = V(w, u in c).getTime(), m.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(K), clearTimeout(ee[u]), K = setTimeout(() => this.reset(), m.exp - Date.now())), m.exp = Math.trunc(m.exp / 1e3), C([j(r), m], 0));
201
237
  if (T) {
202
- const r = `${P}${F}`, m = C, D = V;
203
- if (C = ($) => {
238
+ const r = `${I}${B}`, a = j, g = L;
239
+ if (j = (x) => {
204
240
  try {
205
- return I([m($)], T);
241
+ return C([a(x)], T);
206
242
  } catch {
207
- return delete c[a], "";
243
+ return delete c[u], "";
208
244
  }
209
245
  }, r in c) {
210
- const $ = `${P}${I(w, b)}`;
246
+ const x = `${I}${C(A, $)}`;
211
247
  try {
212
- c[$] = N(V(R(c[r], 0)[0])), delete c[r];
248
+ c[x] = F(L(z(c[r], 0)[0])), delete c[r];
213
249
  } catch {
214
250
  }
215
251
  }
216
- V = ($) => {
252
+ L = (x) => {
217
253
  try {
218
- return D(R($, T)[0]);
254
+ return g(z(x, T)[0]);
219
255
  } catch {
220
- return delete c[a], "";
256
+ return delete c[u], "";
221
257
  }
222
258
  };
223
- } else delete c[`${H}${F}`];
224
- const K = (r) => {
225
- const m = R(r, 0);
226
- return h = m[1], V(m[0]);
259
+ } else delete c[`${H}${B}`];
260
+ const X = (r) => {
261
+ const a = z(r, 0);
262
+ return m = a[1], L(a[0]);
227
263
  };
228
- let X = !0;
229
- if (J[a] = p, c[`atom/${w}`] && (c[a] || (c[a] = `[${c[`atom/${w}`]}]`), delete c[`atom/${w}`]), l = () => {
230
- if (l = o, X) {
231
- X = !1;
264
+ let Y = !0;
265
+ if (G[u] = w, c[`atom/${A}`] && (c[u] || (c[u] = `[${c[`atom/${A}`]}]`), delete c[`atom/${A}`]), f = () => {
266
+ if (f = o, Y) {
267
+ Y = !1;
232
268
  try {
233
- s(a in c ? K(c[a]) : e);
269
+ s(u in c ? X(c[u]) : e);
234
270
  } catch {
235
- console.warn("Invalid json value", c[a]);
271
+ console.warn("Invalid json value", c[u]);
236
272
  }
237
273
  }
238
274
  return o();
239
- }, A = (r) => {
275
+ }, S = (r) => {
240
276
  if (r === e) {
241
277
  this.reset();
242
278
  return;
243
279
  }
244
- c[a] = N(r);
280
+ c[u] = F(r);
245
281
  }, this.reset = () => {
246
- delete c[a], S(e, !0);
247
- }, M && _[a] !== void 0 && console.warn("Duplicate Atom key", w), v)
248
- if (B) {
249
- let r = !1, m;
250
- q[a] = this, _[a] = () => {
251
- clearTimeout(m), m = setTimeout(() => r = !1, 10), !r && (r = !0, c[a] = N(o()));
282
+ delete c[u], b(e, !0);
283
+ }, U && P[u] !== void 0 && console.warn("Duplicate Atom key", A), q)
284
+ if (J) {
285
+ let r = !1, a;
286
+ N[u] = this, P[u] = () => {
287
+ clearTimeout(a), a = setTimeout(() => r = !1, 10), !r && (r = !0, c[u] = F(o()));
252
288
  };
253
289
  } else
254
- _[a] = (r) => {
290
+ P[u] = (r) => {
255
291
  if (r.newValue === null) {
256
292
  this.reset();
257
293
  return;
258
294
  }
259
295
  try {
260
- S(K(r.newValue));
296
+ b(X(r.newValue));
261
297
  } catch {
262
298
  console.warn("Invalid json value", r.newValue);
263
299
  }
264
300
  };
265
- return p;
301
+ return w;
266
302
  }
267
303
  }
268
- let W;
304
+ let v;
269
305
  try {
270
- W = new BroadcastChannel("updateHere"), W.addEventListener("message", (t) => {
306
+ v = new BroadcastChannel("updateHere"), v.addEventListener("message", (t) => {
271
307
  var e;
272
- (e = q[t.data.key]) == null || e.set(t.data.value, !0);
308
+ (e = N[t.data.key]) == null || e.set(t.data.value, !0);
273
309
  });
274
310
  } catch {
275
311
  }
276
- const c = localStorage, _ = {}, q = {}, ye = (t, e) => {
312
+ const c = localStorage, P = {}, N = {}, ge = (t, e) => {
277
313
  throw `${e} is readonly property`;
278
314
  };
279
315
  window.addEventListener("storage", (t) => {
280
316
  var e;
281
- t.key === null || t.newValue === t.oldValue || (e = _[t.key]) == null || e.call(_, t);
317
+ t.key === null || t.newValue === t.oldValue || (e = P[t.key]) == null || e.call(P, t);
282
318
  });
283
- const ge = c.setItem.bind(c), pe = c.removeItem.bind(c);
319
+ const ye = c.setItem.bind(c), we = c.removeItem.bind(c);
284
320
  c.setItem = (t, e) => {
285
- q[t] === void 0 && ge.call(c, t, e);
321
+ N[t] === void 0 && ye.call(c, t, e);
286
322
  };
287
323
  c.removeItem = (t) => {
288
- q[t] === void 0 && pe.call(c, t);
324
+ N[t] === void 0 && we.call(c, t);
289
325
  };
290
- const we = /"exp":\s*(\d+)/, P = "atom\\", H = "atom`s\\", J = {}, ee = {}, te = /[a-z]/gi, U = 5, G = {};
326
+ const Ae = /"exp":\s*(\d+)/, I = "atom\\", H = "atom`s\\", G = {}, ee = {}, te = /[a-z]/gi, R = 5, Q = {};
291
327
  for (let t = 54; t < 80; t++) {
292
328
  if (t === 68 || t === 72 || t === 55) continue;
293
329
  const e = String.fromCharCode(t + 43).toUpperCase(), n = String.fromCharCode(t + 43).toLowerCase();
294
- G[e] = n, G[n] = e;
330
+ Q[e] = n, Q[n] = e;
295
331
  }
296
- const se = (t) => G[t] ?? t, I = /* @__PURE__ */ (() => {
332
+ const se = (t) => Q[t] ?? t, C = /* @__PURE__ */ (() => {
297
333
  const t = [
298
334
  (e) => JSON.stringify(e),
299
335
  (e) => btoa(encodeURI(t[0](e))),
300
336
  (e) => {
301
337
  const n = t[1](e);
302
- return `${n.slice(0, U)}${n.slice(U).replace(te, se)}`;
338
+ return `${n.slice(0, R)}${n.slice(R).replace(te, se)}`;
303
339
  },
304
340
  (e) => btoa(t[2](e))
305
341
  ];
@@ -311,12 +347,12 @@ const se = (t) => G[t] ?? t, I = /* @__PURE__ */ (() => {
311
347
  return t[0](e);
312
348
  }
313
349
  };
314
- })(), R = /* @__PURE__ */ (() => {
350
+ })(), z = /* @__PURE__ */ (() => {
315
351
  const t = [
316
352
  (e) => JSON.parse(e),
317
353
  (e) => t[0](decodeURI(atob(e))),
318
354
  (e) => t[1](
319
- `${e.slice(0, U)}${e.slice(U).replace(te, se)}`
355
+ `${e.slice(0, R)}${e.slice(R).replace(te, se)}`
320
356
  ),
321
357
  (e) => t[2](atob(e))
322
358
  ];
@@ -332,29 +368,30 @@ const se = (t) => G[t] ?? t, I = /* @__PURE__ */ (() => {
332
368
  setTimeout(() => {
333
369
  Object.keys(c).forEach((t) => {
334
370
  var s;
335
- if (typeof c[t] != "string" || !t.startsWith(P) && !t.startsWith(H)) return;
336
- const e = +((s = c[t].match(we)) == null ? void 0 : s[1]);
371
+ if (typeof c[t] != "string" || !t.startsWith(I) && !t.startsWith(H)) return;
372
+ const e = +((s = c[t].match(Ae)) == null ? void 0 : s[1]);
337
373
  if (!e || e * 1e3 - Date.now() > 24 * 60 * 60 * 1e3) return;
338
- const n = R(c[t], 0);
374
+ const n = z(c[t], 0);
339
375
  !Array.isArray(n) || n[1] == null || !("exp" in n[1]) || n[1].exp !== e || (ee[t] = setTimeout(() => {
340
- J[t] ? J[t].reset() : delete c[t];
376
+ G[t] ? G[t].reset() : delete c[t];
341
377
  }, e * 1e3 - Date.now()));
342
378
  });
343
379
  }, 1e3);
344
380
  export {
345
- de as Atom,
381
+ pe as Atom,
346
382
  ie as AtomArrayDoActions,
347
383
  ue as AtomBooleanDoActions,
348
- le as AtomNumberDoActions,
349
- fe as AtomObjectDoActions,
350
- he as AtomSetDoActions,
351
- $e as atom,
352
- Ae as configureAtomaric,
353
- L as configuredOptions,
354
- De as useAtom,
355
- be as useAtomDo,
356
- xe as useAtomGet,
384
+ le as AtomMapDoActions,
385
+ fe as AtomNumberDoActions,
386
+ he as AtomObjectDoActions,
387
+ me as AtomSetDoActions,
388
+ Me as atom,
389
+ Se as configureAtomaric,
390
+ M as configuredOptions,
391
+ $e as useAtom,
392
+ De as useAtomDo,
393
+ be as useAtomGet,
357
394
  oe as useAtomSet,
358
- Se as useAtomSetDeferred,
395
+ xe as useAtomSetDeferred,
359
396
  ne as useAtomValue
360
397
  };
@@ -1 +1 @@
1
- (function(l,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(l=typeof globalThis<"u"?globalThis:l||self,j(l.atomaric={}))})(this,function(l){"use strict";let j=()=>{throw"call configureAtomaric() before all!"};const D={},he=t=>{D.useSyncExternalStore=j=t.useSyncExternalStore,D.keyPathSeparator=t.keyPathSeparator,D.securifyKeyLevel=t.securifyKeyLevel,D.securifyValueLevel=t.securifyValueLevel},X=t=>j(t.subscribe,t.get),Y=t=>t.set,me=t=>t.setDeferred,de=t=>t.get,Ae=t=>t.do,ye=t=>[X(t),Y(t)],ge=(t,e)=>new ne(t,e);class z{constructor(e){if(e)return new Proxy(this,{get:(n,s)=>s in this?n[s]:e[s]})}}const we=(t,e)=>{const n=(s,o,c)=>new Proxy(s,{get:(a,h,y)=>{const A=c===0&&e.get!=null?e.get(a,h,y):a[h];return typeof A=="object"&&A!==null?n(Array.isArray(A)?A.slice(0):{...A},o.concat(Array.isArray(a)?+h:h),c+1):A},set:(a,h,y)=>(e.onSet(a,o,h,y,a[h])&&(a[h]=y),!0)});return n(t,[],0)};class Z extends z{constructor(){super(...arguments),this.updateValue=(e,n)=>{const s=Array.isArray(e)?e.slice(0):{...e};let o=!1;const c=we(e,{onSet:(a,h,y,A,g)=>{if(A===g)return!0;let S=s;o=!0;for(const f of h){const m=S[f];S=S[f]=Array.isArray(m)?m.slice(0):{...m}}return S[y]=A,!0}});return n(c),o?s:e}}}class k extends Z{constructor(e,n){super(n),this.atom=e,this.push=(...s)=>{this.atom.set(this.atom.get().concat(s))},this.unshift=(...s)=>{this.atom.set(s.concat(this.atom.get()))},this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.filter=s=>{this.atom.set(this.atom.get().filter(s??pe))},this.add=s=>{this.atom.get().includes(s)||this.atom.set(this.atom.get().concat([s]))},this.remove=s=>{const o=this.atom.get().indexOf(s);if(o<0)return;const c=this.atom.get().slice(0);c.splice(o,1),this.atom.set(c)},this.toggle=(s,o)=>{const c=this.atom.get().slice(),a=c.indexOf(s);a<0?o?c.unshift(s):c.push(s):c.splice(a,1),this.atom.set(c)}}}const pe=t=>t;class O extends z{constructor(e,n){super(n),this.atom=e,this.toggle=()=>{this.atom.set(!this.atom.get())}}}class ee extends z{constructor(e,n){super(n),this.atom=e,this.increment=s=>{this.atom.set(+this.atom.get()+(s??1))}}}class te extends Z{constructor(e,n){super(n),this.atom=e,this.setPartial=s=>this.atom.set(o=>({...o,...typeof s=="function"?s(this.atom.get()):s})),this.update=s=>{const o=this.atom.get(),c=this.updateValue(o,s);c!==o&&this.atom.set(c)},this.setDeepPartial=(s,o,c,a=D.keyPathSeparator||".")=>{if(!a)return;if(s.includes(a)){let A=s.split(a);const g=A[A.length-1];A=A.slice(0,-1);const S={...this.atom.get()};let f=S,m=c;for(const w of A){m=m==null?void 0:m[Array.isArray(m)?"0":w];const x=f[se(f,w)]??(Array.isArray(m)?[]:{});if(x==null||typeof x!="object"){if(c==null)throw"Incorrect path for setDeepPartial";const b=typeof o=="function"?o(void 0):o;this.atom.get()[s]!==b&&this.setPartial({[s]:b});return}f=f[se(f,w)]=Array.isArray(x)?[...x]:{...x}}const v=f[g];f[g]=typeof o=="function"?o(f[g]):o,v!==f[g]&&this.atom.set(S);return}const h=this.atom.get()[s],y=typeof o=="function"?o(h):o;y!==h&&this.setPartial({[s]:y})}}}const se=(t,e)=>Array.isArray(t)?`${+e}`:e;class re extends z{constructor(e,n){super(n),this.atom=e,this.add=s=>{this.atom.set(new Set(this.atom.get()).add(s))},this.delete=s=>{const o=new Set(this.atom.get());o.delete(s),this.atom.set(o)},this.toggle=s=>{const o=new Set(this.atom.get());o.has(s)?o.delete(s):o.add(s),this.atom.set(o)},this.clear=()=>{this.atom.set(new Set)},this.atom=e}}const Se=(t,e,n)=>{const s=typeof n=="object"&&n!=null&&"do"in n?n.do((c,a)=>e.set(c,a),()=>e.get(),e,(c,a,h)=>e.setDeferred(c,a,h)):null,o={};return s&&Object.keys(s).forEach(c=>Object.defineProperty(o,c,{get:()=>s[c]})),typeof t=="number"?new ee(e,s):typeof t=="boolean"?new O(e,s):Array.isArray(t)?new k(e,s):t instanceof Set?new re(e,s):t instanceof Object?new te(e,s):new z(s)};class ne{constructor(e,n){e=typeof e=="function"?e():e;const s=r=>A=r,o=()=>A,c=new Set,a=r=>r(f());let h=!0,y=!1,A=e,g,S=()=>{},f=()=>o(),m=null,v=()=>{const r=Se(e,w,n);return v=()=>r,r};const w=new Proxy(this,{get:(r,d)=>d==="do"?v():r[d],set:be}),x=()=>{h=!0,y!==!0&&S(f()),y=!1;try{B.postMessage({key:u,value:o()})}catch{}},b=(r,d)=>{const T=typeof r=="function"?r(f()):r;T!==f()&&(s(T),y=d,h&&(h=!1,c.forEach(a),queueMicrotask(x)))};this.set=(r,d)=>b(r,d),this.get=()=>f(),this.initialValue=e,this.isInitialValue=()=>e===o(),this.subscribe=r=>(c.add(r),()=>{c.delete(r)}),this.reset=()=>{b(e,!0)};const Te=(r,d)=>{b(r,d),g=void 0};if(this.setDeferred=(r,d=500,T,V=!0)=>{V&&g===void 0&&b(r,T),clearTimeout(g),g=setTimeout(Te,d,r,T)},n==null)return w;let p=null,R=null,G=!0,H=!0,J=!1,$=0,I=0,ue=-1,_=e instanceof Set?r=>new Set(r):r=>r,E=e instanceof Set?r=>{if(r instanceof Set)return Array.from(r);throw console.error(r),"The value is not Set instance"}:r=>r;if(typeof n=="string")p=n;else if("storeKey"in n)G=n.warnOnDuplicateStoreKey??G,H=n.listenStorageChanges??H,p=n.storeKey,_=n.unzipValue??_,E=n.zipValue??E,J=n.unchangable??J,$=n.securifyKeyLevel??D.securifyKeyLevel??$,I=n.securifyValueLevel??D.securifyValueLevel??I,R=n.exp??R;else return w;const Q=$?C(p,$):p,u=`${I?N:P}${Q}`;if($){const r=`${P}${p}`;r in i&&(i[u]=i[r],delete i[r])}else{const r=`${P}${C(p,$)}`;r in i&&(i[u]=i[r],delete i[r])}const K=R===null||!(R(w,u in i)instanceof Date)?r=>C([E(r)],0):r=>(m??(m={}),m.exp=R(w,u in i).getTime(),m.exp-Date.now()<24*60*60*1e3&&(clearTimeout(ue),clearTimeout(oe[u]),ue=setTimeout(()=>this.reset(),m.exp-Date.now())),m.exp=Math.trunc(m.exp/1e3),C([E(r),m],0));if(I){const r=`${P}${Q}`,d=E,T=_;if(E=V=>{try{return C([d(V)],I)}catch{return delete i[u],""}},r in i){const V=`${P}${C(p,$)}`;try{i[V]=K(_(q(i[r],0)[0])),delete i[r]}catch{}}_=V=>{try{return T(q(V,I)[0])}catch{return delete i[u],""}}}else delete i[`${N}${Q}`];const ae=r=>{const d=q(r,0);return m=d[1],_(d[0])};let le=!0;if(F[u]=w,i[`atom/${p}`]&&(i[u]||(i[u]=`[${i[`atom/${p}`]}]`),delete i[`atom/${p}`]),f=()=>{if(f=o,le){le=!1;try{s(u in i?ae(i[u]):e)}catch{console.warn("Invalid json value",i[u])}}return o()},S=r=>{if(r===e){this.reset();return}i[u]=K(r)},this.reset=()=>{delete i[u],b(e,!0)},G&&L[u]!==void 0&&console.warn("Duplicate Atom key",p),H)if(J){let r=!1,d;M[u]=this,L[u]=()=>{clearTimeout(d),d=setTimeout(()=>r=!1,10),!r&&(r=!0,i[u]=K(o()))}}else L[u]=r=>{if(r.newValue===null){this.reset();return}try{b(ae(r.newValue))}catch{console.warn("Invalid json value",r.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=M[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const i=localStorage,L={},M={},be=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=L[t.key])==null||e.call(L,t)});const De=i.setItem.bind(i),xe=i.removeItem.bind(i);i.setItem=(t,e)=>{M[t]===void 0&&De.call(i,t,e)},i.removeItem=t=>{M[t]===void 0&&xe.call(i,t)};const $e=/"exp":\s*(\d+)/,P="atom\\",N="atom`s\\",F={},oe={},ie=/[a-z]/gi,U=5,W={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),n=String.fromCharCode(t+43).toLowerCase();W[e]=n,W[n]=e}const ce=t=>W[t]??t,C=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const n=t[1](e);return`${n.slice(0,U)}${n.slice(U).replace(ie,ce)}`},e=>btoa(t[2](e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})(),q=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,U)}${e.slice(U).replace(ie,ce)}`),e=>t[2](atob(e))];return(e,n)=>{try{return t[n](e)}catch(s){if(n===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(i).forEach(t=>{var s;if(typeof i[t]!="string"||!t.startsWith(P)&&!t.startsWith(N))return;const e=+((s=i[t].match($e))==null?void 0:s[1]);if(!e||e*1e3-Date.now()>24*60*60*1e3)return;const n=q(i[t],0);!Array.isArray(n)||n[1]==null||!("exp"in n[1])||n[1].exp!==e||(oe[t]=setTimeout(()=>{F[t]?F[t].reset():delete i[t]},e*1e3-Date.now()))})},1e3),l.Atom=ne,l.AtomArrayDoActions=k,l.AtomBooleanDoActions=O,l.AtomNumberDoActions=ee,l.AtomObjectDoActions=te,l.AtomSetDoActions=re,l.atom=ge,l.configureAtomaric=he,l.configuredOptions=D,l.useAtom=ye,l.useAtomDo=Ae,l.useAtomGet=de,l.useAtomSet=Y,l.useAtomSetDeferred=me,l.useAtomValue=X,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(l=typeof globalThis<"u"?globalThis:l||self,j(l.atomaric={}))})(this,function(l){"use strict";let j=()=>{throw"call configureAtomaric() before all!"};const $={},me=t=>{$.useSyncExternalStore=j=t.useSyncExternalStore,$.keyPathSeparator=t.keyPathSeparator,$.securifyKeyLevel=t.securifyKeyLevel,$.securifyValueLevel=t.securifyValueLevel},Y=t=>j(t.subscribe,t.get),Z=t=>t.set,de=t=>t.setDeferred,Ae=t=>t.get,ge=t=>t.do,ye=t=>[Y(t),Z(t)],pe=(t,e)=>new ce(t,e);class L{constructor(e){if(e)return new Proxy(this,{get:(r,s)=>s in this?r[s]:e[s]})}}const we=(t,e)=>{const r=(s,o,i)=>new Proxy(s,{get:(f,m,g)=>{const A=i===0&&e.get!=null?e.get(f,m,g):f[m];return typeof A=="object"&&A!==null?r(Array.isArray(A)?A.slice(0):{...A},o.concat(Array.isArray(f)?+m:m),i+1):A},set:(f,m,g)=>(e.onSet(f,o,m,g,f[m])&&(f[m]=g),!0)});return r(t,[],0)};class k extends L{constructor(){super(...arguments),this.updateValue=(e,r)=>{const s=Array.isArray(e)?e.slice(0):{...e};let o=!1;const i=we(e,{onSet:(f,m,g,A,p)=>{if(A===p)return!0;let b=s;o=!0;for(const h of m){const d=b[h];b=b[h]=Array.isArray(d)?d.slice(0):{...d}}return b[g]=A,!0}});return r(i),o?s:e}}}class O extends k{constructor(e,r){super(r),this.atom=e,this.push=(...s)=>{this.atom.set(this.atom.get().concat(s))},this.unshift=(...s)=>{this.atom.set(s.concat(this.atom.get()))},this.update=s=>{const o=this.atom.get(),i=this.updateValue(o,s);i!==o&&this.atom.set(i)},this.filter=s=>{this.atom.set(this.atom.get().filter(s??Se))},this.add=s=>{this.atom.get().includes(s)||this.atom.set(this.atom.get().concat([s]))},this.remove=s=>{const o=this.atom.get().indexOf(s);if(o<0)return;const i=this.atom.get().slice(0);i.splice(o,1),this.atom.set(i)},this.toggle=(s,o)=>{const i=this.atom.get().slice(),f=i.indexOf(s);f<0?o?i.unshift(s):i.push(s):i.splice(f,1),this.atom.set(i)}}}const Se=t=>t;class ee extends L{constructor(e,r){super(r),this.atom=e,this.toggle=()=>{this.atom.set(!this.atom.get())}}}class te extends L{constructor(e,r){super(r),this.atom=e,this.setValue=(s,o)=>{const i=new Map(this.atom.get());i.set(s,o),this.atom.set(i)},this.delete=s=>{const o=new Map(this.atom.get());o.delete(s),this.atom.set(o)},this.toggle=(s,o)=>{const i=new Map(this.atom.get());i.has(s)?i.delete(s):i.set(s,o),this.atom.set(i)},this.clear=()=>{this.atom.set(new Map)},this.atom=e}}class se extends L{constructor(e,r){super(r),this.atom=e,this.increment=s=>{this.atom.set(+this.atom.get()+(s??1))}}}class ne extends k{constructor(e,r){super(r),this.atom=e,this.setPartial=s=>this.atom.set(o=>({...o,...typeof s=="function"?s(this.atom.get()):s})),this.update=s=>{const o=this.atom.get(),i=this.updateValue(o,s);i!==o&&this.atom.set(i)},this.setDeepPartial=(s,o,i,f=$.keyPathSeparator||".")=>{if(!f)return;if(s.includes(f)){let A=s.split(f);const p=A[A.length-1];A=A.slice(0,-1);const b={...this.atom.get()};let h=b,d=i;for(const w of A){d=d==null?void 0:d[Array.isArray(d)?"0":w];const M=h[re(h,w)]??(Array.isArray(d)?[]:{});if(M==null||typeof M!="object"){if(i==null)throw"Incorrect path for setDeepPartial";const x=typeof o=="function"?o(void 0):o;this.atom.get()[s]!==x&&this.setPartial({[s]:x});return}h=h[re(h,w)]=Array.isArray(M)?[...M]:{...M}}const q=h[p];h[p]=typeof o=="function"?o(h[p]):o,q!==h[p]&&this.atom.set(b);return}const m=this.atom.get()[s],g=typeof o=="function"?o(m):o;g!==m&&this.setPartial({[s]:g})}}}const re=(t,e)=>Array.isArray(t)?`${+e}`:e;class oe extends L{constructor(e,r){super(r),this.atom=e,this.add=s=>{this.atom.set(new Set(this.atom.get()).add(s))},this.delete=s=>{const o=new Set(this.atom.get());o.delete(s),this.atom.set(o)},this.toggle=s=>{const o=new Set(this.atom.get());o.has(s)?o.delete(s):o.add(s),this.atom.set(o)},this.clear=()=>{this.atom.set(new Set)},this.atom=e}}const be=(t,e,r)=>{const s=typeof r=="object"&&r!=null&&"do"in r?r.do((i,f)=>e.set(i,f),()=>e.get(),e,(i,f,m)=>e.setDeferred(i,f,m)):null,o={};return s&&Object.keys(s).forEach(i=>Object.defineProperty(o,i,{get:()=>s[i]})),typeof t=="number"?new se(e,s):typeof t=="boolean"?new ee(e,s):Array.isArray(t)?new O(e,s):t instanceof Set?new oe(e,s):t instanceof Map?new te(e,s):t instanceof Object?new ne(e,s):new L(s)};class ce{constructor(e,r){e=typeof e=="function"?e():e;const s=n=>A=n,o=()=>A,i=new Set,f=n=>n(h());let m=!0,g=!1,A=e,p,b=()=>{},h=()=>o(),d=null,q=()=>{const n=be(e,w,r);return q=()=>n,n};const w=new Proxy(this,{get:(n,a)=>a==="do"?q():n[a],set:De}),M=()=>{m=!0,g!==!0&&b(h()),g=!1;try{B.postMessage({key:u,value:o()})}catch{}},x=(n,a)=>{const y=typeof n=="function"?n(h()):n;y!==h()&&(s(y),g=a,m&&(m=!1,i.forEach(f),queueMicrotask(M)))};this.set=(n,a)=>x(n,a),this.get=()=>h(),this.initialValue=e,this.isInitialValue=()=>e===o(),this.subscribe=n=>(i.add(n),()=>{i.delete(n)}),this.reset=()=>{x(e,!0)};const Te=(n,a)=>{x(n,a),p=void 0};if(this.setDeferred=(n,a=500,y,D=!0)=>{D&&p===void 0&&x(n,y),clearTimeout(p),p=setTimeout(Te,a,n,y)},r==null)return w;let S=null,z=null,W=!0,G=!0,H=!1,T=0,_=0,le=-1,V=e instanceof Set?n=>new Set(n):e instanceof Map?n=>{if(!n||typeof n!="object")return new Map;const a=new Map;for(const y in n)try{a.set(JSON.parse(y),n[y])}catch{}return a}:n=>n,E=e instanceof Set?n=>{if(n instanceof Set)return Array.from(n);throw console.error(n),"The value is not Set instance"}:e instanceof Map?n=>{if(n instanceof Map){const a={};return n.forEach((y,D)=>{try{a[JSON.stringify(D)]=y}catch{}}),a}throw console.error(n),"The value is not Set instance"}:n=>n;if(typeof r=="string")S=r;else if("storeKey"in r)W=r.warnOnDuplicateStoreKey??W,G=r.listenStorageChanges??G,S=r.storeKey,V=r.unzipValue??V,E=r.zipValue??E,H=r.unchangable??H,T=r.securifyKeyLevel??$.securifyKeyLevel??T,_=r.securifyValueLevel??$.securifyValueLevel??_,z=r.exp??z;else return w;const Q=T?I(S,T):S,u=`${_?J:C}${Q}`;if(T){const n=`${C}${S}`;n in c&&(c[u]=c[n],delete c[n])}else{const n=`${C}${I(S,T)}`;n in c&&(c[u]=c[n],delete c[n])}const K=z===null||!(z(w,u in c)instanceof Date)?n=>I([E(n)],0):n=>(d??(d={}),d.exp=z(w,u in c).getTime(),d.exp-Date.now()<24*60*60*1e3&&(clearTimeout(le),clearTimeout(ie[u]),le=setTimeout(()=>this.reset(),d.exp-Date.now())),d.exp=Math.trunc(d.exp/1e3),I([E(n),d],0));if(_){const n=`${C}${Q}`,a=E,y=V;if(E=D=>{try{return I([a(D)],_)}catch{return delete c[u],""}},n in c){const D=`${C}${I(S,T)}`;try{c[D]=K(V(U(c[n],0)[0])),delete c[n]}catch{}}V=D=>{try{return y(U(D,_)[0])}catch{return delete c[u],""}}}else delete c[`${J}${Q}`];const fe=n=>{const a=U(n,0);return d=a[1],V(a[0])};let he=!0;if(v[u]=w,c[`atom/${S}`]&&(c[u]||(c[u]=`[${c[`atom/${S}`]}]`),delete c[`atom/${S}`]),h=()=>{if(h=o,he){he=!1;try{s(u in c?fe(c[u]):e)}catch{console.warn("Invalid json value",c[u])}}return o()},b=n=>{if(n===e){this.reset();return}c[u]=K(n)},this.reset=()=>{delete c[u],x(e,!0)},W&&P[u]!==void 0&&console.warn("Duplicate Atom key",S),G)if(H){let n=!1,a;N[u]=this,P[u]=()=>{clearTimeout(a),a=setTimeout(()=>n=!1,10),!n&&(n=!0,c[u]=K(o()))}}else P[u]=n=>{if(n.newValue===null){this.reset();return}try{x(fe(n.newValue))}catch{console.warn("Invalid json value",n.newValue)}};return w}}let B;try{B=new BroadcastChannel("updateHere"),B.addEventListener("message",t=>{var e;(e=N[t.data.key])==null||e.set(t.data.value,!0)})}catch{}const c=localStorage,P={},N={},De=(t,e)=>{throw`${e} is readonly property`};window.addEventListener("storage",t=>{var e;t.key===null||t.newValue===t.oldValue||(e=P[t.key])==null||e.call(P,t)});const xe=c.setItem.bind(c),$e=c.removeItem.bind(c);c.setItem=(t,e)=>{N[t]===void 0&&xe.call(c,t,e)},c.removeItem=t=>{N[t]===void 0&&$e.call(c,t)};const Me=/"exp":\s*(\d+)/,C="atom\\",J="atom`s\\",v={},ie={},ae=/[a-z]/gi,R=5,F={};for(let t=54;t<80;t++){if(t===68||t===72||t===55)continue;const e=String.fromCharCode(t+43).toUpperCase(),r=String.fromCharCode(t+43).toLowerCase();F[e]=r,F[r]=e}const ue=t=>F[t]??t,I=(()=>{const t=[e=>JSON.stringify(e),e=>btoa(encodeURI(t[0](e))),e=>{const r=t[1](e);return`${r.slice(0,R)}${r.slice(R).replace(ae,ue)}`},e=>btoa(t[2](e))];return(e,r)=>{try{return t[r](e)}catch(s){if(r===0)throw s;return t[0](e)}}})(),U=(()=>{const t=[e=>JSON.parse(e),e=>t[0](decodeURI(atob(e))),e=>t[1](`${e.slice(0,R)}${e.slice(R).replace(ae,ue)}`),e=>t[2](atob(e))];return(e,r)=>{try{return t[r](e)}catch(s){if(r===0)throw s;return t[0](e)}}})();setTimeout(()=>{Object.keys(c).forEach(t=>{var s;if(typeof c[t]!="string"||!t.startsWith(C)&&!t.startsWith(J))return;const e=+((s=c[t].match(Me))==null?void 0:s[1]);if(!e||e*1e3-Date.now()>24*60*60*1e3)return;const r=U(c[t],0);!Array.isArray(r)||r[1]==null||!("exp"in r[1])||r[1].exp!==e||(ie[t]=setTimeout(()=>{v[t]?v[t].reset():delete c[t]},e*1e3-Date.now()))})},1e3),l.Atom=ce,l.AtomArrayDoActions=O,l.AtomBooleanDoActions=ee,l.AtomMapDoActions=te,l.AtomNumberDoActions=se,l.AtomObjectDoActions=ne,l.AtomSetDoActions=oe,l.atom=pe,l.configureAtomaric=me,l.configuredOptions=$,l.useAtom=ye,l.useAtomDo=ge,l.useAtomGet=Ae,l.useAtomSet=Z,l.useAtomSetDeferred=de,l.useAtomValue=Y,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "atomaric",
3
3
  "description": "Manage your project state",
4
- "version": "0.0.69",
4
+ "version": "0.0.70",
5
5
  "type": "module",
6
6
  "main": "./build/atomaric.umd.cjs",
7
7
  "module": "./build/atomaric.js",
@@ -0,0 +1,71 @@
1
+ import { useSyncExternalStore } from 'react';
2
+ import { atom, configureAtomaric } from '../lib';
3
+ import { makeFullKey, wait } from '../utils';
4
+
5
+ configureAtomaric({
6
+ useSyncExternalStore,
7
+ keyPathSeparator: '.',
8
+ });
9
+
10
+ describe('Map', () => {
11
+ test('do actions', async () => {
12
+ type Value = number | { asasa: '' };
13
+ const testAtom = atom(new Map<string, Value>(), {
14
+ storeKey: 'map:test',
15
+ do: (set, get) => ({
16
+ filterKeyValues: () => {
17
+ const newMap = new Map();
18
+ get().forEach((value, key) => {
19
+ if (value) newMap.set(key, value);
20
+ });
21
+ set(newMap);
22
+ },
23
+ }),
24
+ });
25
+
26
+ testAtom.do.setValue('!', 1);
27
+ testAtom.do.setValue('@', 0);
28
+ testAtom.do.setValue('#', { asasa: '' });
29
+ testAtom.do.setValue('', 123);
30
+ await wait();
31
+
32
+ expect(localStorage[makeFullKey('map:test')]).toEqual(
33
+ '[{"\\"!\\"":1,"\\"@\\"":0,"\\"#\\"":{"asasa":""},"\\"\\"":123}]',
34
+ );
35
+
36
+ expect(testAtom.get()).toEqual(
37
+ new Map<string, Value>([
38
+ ['!', 1],
39
+ ['@', 0],
40
+ ['#', { asasa: '' }],
41
+ ['', 123],
42
+ ]),
43
+ );
44
+
45
+ testAtom.do.filterKeyValues();
46
+ await wait();
47
+
48
+ expect(localStorage[makeFullKey('map:test')]).toEqual('[{"\\"!\\"":1,"\\"#\\"":{"asasa":""},"\\"\\"":123}]');
49
+
50
+ testAtom.do.delete('#');
51
+ await wait();
52
+
53
+ expect(localStorage[makeFullKey('map:test')]).toEqual('[{"\\"!\\"":1,"\\"\\"":123}]');
54
+
55
+ testAtom.do.toggle('#', 555);
56
+ await wait();
57
+
58
+ expect(localStorage[makeFullKey('map:test')]).toEqual('[{"\\"!\\"":1,"\\"\\"":123,"\\"#\\"":555}]');
59
+
60
+ testAtom.do.toggle('', 999);
61
+ testAtom.do.toggle('!', 1234567890);
62
+ await wait();
63
+
64
+ expect(localStorage[makeFullKey('map:test')]).toEqual('[{"\\"#\\"":555}]');
65
+
66
+ testAtom.do.clear();
67
+ await wait();
68
+
69
+ expect(localStorage[makeFullKey('map:test')]).toEqual('[{}]');
70
+ });
71
+ });
@@ -0,0 +1,42 @@
1
+ import { Atom } from '../../types';
2
+ import { AtomDoActionsBasic } from './_Basic';
3
+
4
+ export class AtomMapDoActions<
5
+ MapValue extends Map<any, any>,
6
+ Key extends MapValue extends Map<infer K, any> ? K : never,
7
+ Value extends MapValue extends Map<any, infer V> ? V : never,
8
+ > extends AtomDoActionsBasic {
9
+ constructor(private atom: Atom<MapValue>, actions: Record<string, Function> | nil) {
10
+ super(actions);
11
+ this.atom = atom;
12
+ }
13
+
14
+ /** like the Map.prototype.set() method */
15
+ setValue = (key: Key, value: Value) => {
16
+ const newMap = new Map(this.atom.get());
17
+ newMap.set(key, value);
18
+ this.atom.set(newMap as never);
19
+ };
20
+
21
+ /** like the Map.prototype.delete() method */
22
+ delete = (key: Key) => {
23
+ const newMap = new Map(this.atom.get());
24
+ newMap.delete(key);
25
+ this.atom.set(newMap as never);
26
+ };
27
+
28
+ /** will add value if it doesn't exist, otherwise delete */
29
+ toggle = (key: Key, value: Value) => {
30
+ const newMap = new Map(this.atom.get());
31
+
32
+ if (newMap.has(key)) newMap.delete(key);
33
+ else newMap.set(key, value);
34
+
35
+ this.atom.set(newMap as never);
36
+ };
37
+
38
+ /** like the Map.prototype.clear() method */
39
+ clear = () => {
40
+ this.atom.set(new Map() as never);
41
+ };
42
+ }
@@ -8,7 +8,7 @@ configureAtomaric({
8
8
  });
9
9
 
10
10
  describe('Object', () => {
11
- test('setDeepPartial()', async () => {
11
+ test('do.setDeepPartial()', async () => {
12
12
  const b = { c: [{ d: 8, e: 'e', f: 'F', g: { h: 'HHH' } }] };
13
13
  const a = { f: { g: '' }, b };
14
14
  const testAtom = atom({ a, b });
@@ -29,7 +29,7 @@ describe('Object', () => {
29
29
  expect(testAtom.get().b.c[8].e).toEqual('EE');
30
30
  });
31
31
 
32
- test('setDeepPartial() with first numeric prop', async () => {
32
+ test('do.setDeepPartial() with first numeric prop', async () => {
33
33
  enum Num {
34
34
  num = 123,
35
35
  }
@@ -42,7 +42,17 @@ describe('Object', () => {
42
42
  expect(testAtom.get()[Num.num].a).toEqual('AA');
43
43
  });
44
44
 
45
- test('update()', async () => {
45
+ test('do.setPartial()', async () => {
46
+ const testAtom = atom((): Record<number, unknown> => ({ 2: { a: 'A' } }));
47
+
48
+ testAtom.do.setPartial({ 3: { b: 'B' } });
49
+ testAtom.do.setPartial({ 4: [] });
50
+ await wait();
51
+
52
+ expect(testAtom.get()).toEqual({ 2: { a: 'A' }, 3: { b: 'B' }, 4: [] });
53
+ });
54
+
55
+ test('do.update()', async () => {
46
56
  const init = { a: { b: { c: { d: { e: 'E' } }, f: { g: {} } }, h: { i: { j: {} } } } };
47
57
  const testAtom = atom(init);
48
58
 
package/types/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useSyncExternalStore } from 'react';
2
2
  import { AtomArrayDoActions } from '../src/do.classes/Array';
3
3
  import { AtomBooleanDoActions } from '../src/do.classes/Boolean';
4
+ import { AtomMapDoActions } from '../src/do.classes/Map';
4
5
  import { AtomNumberDoActions } from '../src/do.classes/Number';
5
6
  import { AtomObjectDoActions } from '../src/do.classes/Object';
6
7
  import { AtomSetDoActions } from '../src/do.classes/Set';
@@ -78,6 +79,8 @@ export type ObjectActionsSetDeepPartialDoAction<Value> = <
78
79
 
79
80
  export type DefaultActions<Value> = Value extends Set<infer Val>
80
81
  ? AtomSetDoActions<Val>
82
+ : Value extends Map<infer Key, infer Val>
83
+ ? AtomMapDoActions<Value, Key, Val>
81
84
  : Value extends boolean
82
85
  ? AtomBooleanDoActions
83
86
  : Value extends (infer Val)[]