atomaric 0.0.71 → 0.0.73

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