atomaric 0.0.71 → 0.0.72

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