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