@gaddario98/react-core 2.0.8 → 2.0.9
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/dist/auth/index.d.ts +2 -2
- package/dist/auth/index.js +184 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +183 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/form/index.js +263 -3959
- package/dist/form/index.js.map +1 -1
- package/dist/form/index.mjs +213 -3909
- package/dist/form/index.mjs.map +1 -1
- package/dist/index.d.ts +623 -93
- package/dist/index.js +5381 -16418
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5372 -16409
- package/dist/index.mjs.map +1 -1
- package/dist/localization/index.js +184 -2
- package/dist/localization/index.js.map +1 -1
- package/dist/localization/index.mjs +183 -1
- package/dist/localization/index.mjs.map +1 -1
- package/dist/notifications/index.d.ts +2 -2
- package/dist/notifications/index.js +185 -3
- package/dist/notifications/index.js.map +1 -1
- package/dist/notifications/index.mjs +184 -2
- package/dist/notifications/index.mjs.map +1 -1
- package/dist/pages/index.js +1536 -1680
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/index.mjs +1522 -1666
- package/dist/pages/index.mjs.map +1 -1
- package/dist/queries/index.js +393 -7439
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +385 -7431
- package/dist/queries/index.mjs.map +1 -1
- package/dist/state/index.js +10 -1783
- package/dist/state/index.js.map +1 -1
- package/dist/state/index.mjs +2 -1775
- package/dist/state/index.mjs.map +1 -1
- package/package.json +8 -6
package/dist/state/index.js
CHANGED
|
@@ -1,821 +1,4 @@
|
|
|
1
|
-
'use strict';var compilerRuntime=require('react/compiler-runtime'),
|
|
2
|
-
// https://tools.ietf.org/html/rfc1951
|
|
3
|
-
// You may also wish to take a look at the guide I made about this program:
|
|
4
|
-
// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad
|
|
5
|
-
// Some of the following code is similar to that of UZIP.js:
|
|
6
|
-
// https://github.com/photopea/UZIP.js
|
|
7
|
-
// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.
|
|
8
|
-
// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint
|
|
9
|
-
// is better for memory in most engines (I *think*).
|
|
10
|
-
|
|
11
|
-
// aliases for shorter compressed code (most minifers don't do this)
|
|
12
|
-
var u8 = Uint8Array,
|
|
13
|
-
u16 = Uint16Array,
|
|
14
|
-
i32 = Int32Array;
|
|
15
|
-
// fixed length extra bits
|
|
16
|
-
var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */0, 0, /* impossible */0]);
|
|
17
|
-
// fixed distance extra bits
|
|
18
|
-
var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */0, 0]);
|
|
19
|
-
// code length index map
|
|
20
|
-
var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
21
|
-
// get base, reverse index map from extra bits
|
|
22
|
-
var freb = function (eb, start) {
|
|
23
|
-
var b = new u16(31);
|
|
24
|
-
for (var i = 0; i < 31; ++i) {
|
|
25
|
-
b[i] = start += 1 << eb[i - 1];
|
|
26
|
-
}
|
|
27
|
-
// numbers here are at max 18 bits
|
|
28
|
-
var r = new i32(b[30]);
|
|
29
|
-
for (var i = 1; i < 30; ++i) {
|
|
30
|
-
for (var j = b[i]; j < b[i + 1]; ++j) {
|
|
31
|
-
r[j] = j - b[i] << 5 | i;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
b: b,
|
|
36
|
-
r: r
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
var _a = freb(fleb, 2),
|
|
40
|
-
fl = _a.b,
|
|
41
|
-
revfl = _a.r;
|
|
42
|
-
// we can ignore the fact that the other numbers are wrong; they never happen anyway
|
|
43
|
-
fl[28] = 258, revfl[258] = 28;
|
|
44
|
-
var _b = freb(fdeb, 0),
|
|
45
|
-
fd = _b.b,
|
|
46
|
-
revfd = _b.r;
|
|
47
|
-
// map of value to reverse (assuming 16 bits)
|
|
48
|
-
var rev = new u16(32768);
|
|
49
|
-
for (var i = 0; i < 32768; ++i) {
|
|
50
|
-
// reverse table algorithm from SO
|
|
51
|
-
var x = (i & 0xAAAA) >> 1 | (i & 0x5555) << 1;
|
|
52
|
-
x = (x & 0xCCCC) >> 2 | (x & 0x3333) << 2;
|
|
53
|
-
x = (x & 0xF0F0) >> 4 | (x & 0x0F0F) << 4;
|
|
54
|
-
rev[i] = ((x & 0xFF00) >> 8 | (x & 0x00FF) << 8) >> 1;
|
|
55
|
-
}
|
|
56
|
-
// create huffman tree from u8 "map": index -> code length for code index
|
|
57
|
-
// mb (max bits) must be at most 15
|
|
58
|
-
// TODO: optimize/split up?
|
|
59
|
-
var hMap = function (cd, mb, r) {
|
|
60
|
-
var s = cd.length;
|
|
61
|
-
// index
|
|
62
|
-
var i = 0;
|
|
63
|
-
// u16 "map": index -> # of codes with bit length = index
|
|
64
|
-
var l = new u16(mb);
|
|
65
|
-
// length of cd must be 288 (total # of codes)
|
|
66
|
-
for (; i < s; ++i) {
|
|
67
|
-
if (cd[i]) ++l[cd[i] - 1];
|
|
68
|
-
}
|
|
69
|
-
// u16 "map": index -> minimum code for bit length = index
|
|
70
|
-
var le = new u16(mb);
|
|
71
|
-
for (i = 1; i < mb; ++i) {
|
|
72
|
-
le[i] = le[i - 1] + l[i - 1] << 1;
|
|
73
|
-
}
|
|
74
|
-
var co;
|
|
75
|
-
if (r) {
|
|
76
|
-
// u16 "map": index -> number of actual bits, symbol for code
|
|
77
|
-
co = new u16(1 << mb);
|
|
78
|
-
// bits to remove for reverser
|
|
79
|
-
var rvb = 15 - mb;
|
|
80
|
-
for (i = 0; i < s; ++i) {
|
|
81
|
-
// ignore 0 lengths
|
|
82
|
-
if (cd[i]) {
|
|
83
|
-
// num encoding both symbol and bits read
|
|
84
|
-
var sv = i << 4 | cd[i];
|
|
85
|
-
// free bits
|
|
86
|
-
var r_1 = mb - cd[i];
|
|
87
|
-
// start value
|
|
88
|
-
var v = le[cd[i] - 1]++ << r_1;
|
|
89
|
-
// m is end value
|
|
90
|
-
for (var m = v | (1 << r_1) - 1; v <= m; ++v) {
|
|
91
|
-
// every 16 bit value starting with the code yields the same result
|
|
92
|
-
co[rev[v] >> rvb] = sv;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} else {
|
|
97
|
-
co = new u16(s);
|
|
98
|
-
for (i = 0; i < s; ++i) {
|
|
99
|
-
if (cd[i]) {
|
|
100
|
-
co[i] = rev[le[cd[i] - 1]++] >> 15 - cd[i];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return co;
|
|
105
|
-
};
|
|
106
|
-
// fixed length tree
|
|
107
|
-
var flt = new u8(288);
|
|
108
|
-
for (var i = 0; i < 144; ++i) flt[i] = 8;
|
|
109
|
-
for (var i = 144; i < 256; ++i) flt[i] = 9;
|
|
110
|
-
for (var i = 256; i < 280; ++i) flt[i] = 7;
|
|
111
|
-
for (var i = 280; i < 288; ++i) flt[i] = 8;
|
|
112
|
-
// fixed distance tree
|
|
113
|
-
var fdt = new u8(32);
|
|
114
|
-
for (var i = 0; i < 32; ++i) fdt[i] = 5;
|
|
115
|
-
// fixed length map
|
|
116
|
-
var flm = /*#__PURE__*/hMap(flt, 9, 0),
|
|
117
|
-
flrm = /*#__PURE__*/hMap(flt, 9, 1);
|
|
118
|
-
// fixed distance map
|
|
119
|
-
var fdm = /*#__PURE__*/hMap(fdt, 5, 0),
|
|
120
|
-
fdrm = /*#__PURE__*/hMap(fdt, 5, 1);
|
|
121
|
-
// find max of array
|
|
122
|
-
var max = function (a) {
|
|
123
|
-
var m = a[0];
|
|
124
|
-
for (var i = 1; i < a.length; ++i) {
|
|
125
|
-
if (a[i] > m) m = a[i];
|
|
126
|
-
}
|
|
127
|
-
return m;
|
|
128
|
-
};
|
|
129
|
-
// read d, starting at bit p and mask with m
|
|
130
|
-
var bits = function (d, p, m) {
|
|
131
|
-
var o = p / 8 | 0;
|
|
132
|
-
return (d[o] | d[o + 1] << 8) >> (p & 7) & m;
|
|
133
|
-
};
|
|
134
|
-
// read d, starting at bit p continuing for at least 16 bits
|
|
135
|
-
var bits16 = function (d, p) {
|
|
136
|
-
var o = p / 8 | 0;
|
|
137
|
-
return (d[o] | d[o + 1] << 8 | d[o + 2] << 16) >> (p & 7);
|
|
138
|
-
};
|
|
139
|
-
// get end of byte
|
|
140
|
-
var shft = function (p) {
|
|
141
|
-
return (p + 7) / 8 | 0;
|
|
142
|
-
};
|
|
143
|
-
// typed array slice - allows garbage collector to free original reference,
|
|
144
|
-
// while being more compatible than .slice
|
|
145
|
-
var slc = function (v, s, e) {
|
|
146
|
-
if (s == null || s < 0) s = 0;
|
|
147
|
-
if (e == null || e > v.length) e = v.length;
|
|
148
|
-
// can't use .constructor in case user-supplied
|
|
149
|
-
return new u8(v.subarray(s, e));
|
|
150
|
-
};
|
|
151
|
-
// error codes
|
|
152
|
-
var ec = ['unexpected EOF', 'invalid block type', 'invalid length/literal', 'invalid distance', 'stream finished', 'no stream handler',, 'no callback', 'invalid UTF-8 data', 'extra field too long', 'date not in range 1980-2099', 'filename too long', 'stream finishing', 'invalid zip data'
|
|
153
|
-
// determined by unknown compression method
|
|
154
|
-
];
|
|
155
|
-
var err = function (ind, msg, nt) {
|
|
156
|
-
var e = new Error(msg || ec[ind]);
|
|
157
|
-
e.code = ind;
|
|
158
|
-
if (Error.captureStackTrace) Error.captureStackTrace(e, err);
|
|
159
|
-
if (!nt) throw e;
|
|
160
|
-
return e;
|
|
161
|
-
};
|
|
162
|
-
// expands raw DEFLATE data
|
|
163
|
-
var inflt = function (dat, st, buf, dict) {
|
|
164
|
-
// source length dict length
|
|
165
|
-
var sl = dat.length,
|
|
166
|
-
dl = 0;
|
|
167
|
-
if (!sl || st.f && !st.l) return buf || new u8(0);
|
|
168
|
-
var noBuf = !buf;
|
|
169
|
-
// have to estimate size
|
|
170
|
-
var resize = noBuf || st.i != 2;
|
|
171
|
-
// Assumes roughly 33% compression ratio average
|
|
172
|
-
if (noBuf) buf = new u8(sl * 3);
|
|
173
|
-
// ensure buffer can fit at least l elements
|
|
174
|
-
var cbuf = function (l) {
|
|
175
|
-
var bl = buf.length;
|
|
176
|
-
// need to increase size to fit
|
|
177
|
-
if (l > bl) {
|
|
178
|
-
// Double or set to necessary, whichever is greater
|
|
179
|
-
var nbuf = new u8(Math.max(bl * 2, l));
|
|
180
|
-
nbuf.set(buf);
|
|
181
|
-
buf = nbuf;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
// last chunk bitpos bytes
|
|
185
|
-
var final = st.f || 0,
|
|
186
|
-
pos = st.p || 0,
|
|
187
|
-
bt = st.b || 0,
|
|
188
|
-
lm = st.l,
|
|
189
|
-
dm = st.d,
|
|
190
|
-
lbt = st.m,
|
|
191
|
-
dbt = st.n;
|
|
192
|
-
// total bits
|
|
193
|
-
var tbts = sl * 8;
|
|
194
|
-
do {
|
|
195
|
-
if (!lm) {
|
|
196
|
-
// BFINAL - this is only 1 when last chunk is next
|
|
197
|
-
final = bits(dat, pos, 1);
|
|
198
|
-
// type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman
|
|
199
|
-
var type = bits(dat, pos + 1, 3);
|
|
200
|
-
pos += 3;
|
|
201
|
-
if (!type) {
|
|
202
|
-
// go to end of byte boundary
|
|
203
|
-
var s = shft(pos) + 4,
|
|
204
|
-
l = dat[s - 4] | dat[s - 3] << 8,
|
|
205
|
-
t = s + l;
|
|
206
|
-
if (t > sl) {
|
|
207
|
-
err(0);
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
// ensure size
|
|
211
|
-
if (resize) cbuf(bt + l);
|
|
212
|
-
// Copy over uncompressed data
|
|
213
|
-
buf.set(dat.subarray(s, t), bt);
|
|
214
|
-
// Get new bitpos, update byte count
|
|
215
|
-
st.b = bt += l, st.p = pos = t * 8, st.f = final;
|
|
216
|
-
continue;
|
|
217
|
-
} else if (type == 1) lm = flrm, dm = fdrm, lbt = 9, dbt = 5;else if (type == 2) {
|
|
218
|
-
// literal lengths
|
|
219
|
-
var hLit = bits(dat, pos, 31) + 257,
|
|
220
|
-
hcLen = bits(dat, pos + 10, 15) + 4;
|
|
221
|
-
var tl = hLit + bits(dat, pos + 5, 31) + 1;
|
|
222
|
-
pos += 14;
|
|
223
|
-
// length+distance tree
|
|
224
|
-
var ldt = new u8(tl);
|
|
225
|
-
// code length tree
|
|
226
|
-
var clt = new u8(19);
|
|
227
|
-
for (var i = 0; i < hcLen; ++i) {
|
|
228
|
-
// use index map to get real code
|
|
229
|
-
clt[clim[i]] = bits(dat, pos + i * 3, 7);
|
|
230
|
-
}
|
|
231
|
-
pos += hcLen * 3;
|
|
232
|
-
// code lengths bits
|
|
233
|
-
var clb = max(clt),
|
|
234
|
-
clbmsk = (1 << clb) - 1;
|
|
235
|
-
// code lengths map
|
|
236
|
-
var clm = hMap(clt, clb, 1);
|
|
237
|
-
for (var i = 0; i < tl;) {
|
|
238
|
-
var r = clm[bits(dat, pos, clbmsk)];
|
|
239
|
-
// bits read
|
|
240
|
-
pos += r & 15;
|
|
241
|
-
// symbol
|
|
242
|
-
var s = r >> 4;
|
|
243
|
-
// code length to copy
|
|
244
|
-
if (s < 16) {
|
|
245
|
-
ldt[i++] = s;
|
|
246
|
-
} else {
|
|
247
|
-
// copy count
|
|
248
|
-
var c = 0,
|
|
249
|
-
n = 0;
|
|
250
|
-
if (s == 16) n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];else if (s == 17) n = 3 + bits(dat, pos, 7), pos += 3;else if (s == 18) n = 11 + bits(dat, pos, 127), pos += 7;
|
|
251
|
-
while (n--) ldt[i++] = c;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
// length tree distance tree
|
|
255
|
-
var lt = ldt.subarray(0, hLit),
|
|
256
|
-
dt = ldt.subarray(hLit);
|
|
257
|
-
// max length bits
|
|
258
|
-
lbt = max(lt);
|
|
259
|
-
// max dist bits
|
|
260
|
-
dbt = max(dt);
|
|
261
|
-
lm = hMap(lt, lbt, 1);
|
|
262
|
-
dm = hMap(dt, dbt, 1);
|
|
263
|
-
} else err(1);
|
|
264
|
-
if (pos > tbts) {
|
|
265
|
-
err(0);
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
// Make sure the buffer can hold this + the largest possible addition
|
|
270
|
-
// Maximum chunk size (practically, theoretically infinite) is 2^17
|
|
271
|
-
if (resize) cbuf(bt + 131072);
|
|
272
|
-
var lms = (1 << lbt) - 1,
|
|
273
|
-
dms = (1 << dbt) - 1;
|
|
274
|
-
var lpos = pos;
|
|
275
|
-
for (;; lpos = pos) {
|
|
276
|
-
// bits read, code
|
|
277
|
-
var c = lm[bits16(dat, pos) & lms],
|
|
278
|
-
sym = c >> 4;
|
|
279
|
-
pos += c & 15;
|
|
280
|
-
if (pos > tbts) {
|
|
281
|
-
err(0);
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
if (!c) err(2);
|
|
285
|
-
if (sym < 256) buf[bt++] = sym;else if (sym == 256) {
|
|
286
|
-
lpos = pos, lm = null;
|
|
287
|
-
break;
|
|
288
|
-
} else {
|
|
289
|
-
var add = sym - 254;
|
|
290
|
-
// no extra bits needed if less
|
|
291
|
-
if (sym > 264) {
|
|
292
|
-
// index
|
|
293
|
-
var i = sym - 257,
|
|
294
|
-
b = fleb[i];
|
|
295
|
-
add = bits(dat, pos, (1 << b) - 1) + fl[i];
|
|
296
|
-
pos += b;
|
|
297
|
-
}
|
|
298
|
-
// dist
|
|
299
|
-
var d = dm[bits16(dat, pos) & dms],
|
|
300
|
-
dsym = d >> 4;
|
|
301
|
-
if (!d) err(3);
|
|
302
|
-
pos += d & 15;
|
|
303
|
-
var dt = fd[dsym];
|
|
304
|
-
if (dsym > 3) {
|
|
305
|
-
var b = fdeb[dsym];
|
|
306
|
-
dt += bits16(dat, pos) & (1 << b) - 1, pos += b;
|
|
307
|
-
}
|
|
308
|
-
if (pos > tbts) {
|
|
309
|
-
err(0);
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
if (resize) cbuf(bt + 131072);
|
|
313
|
-
var end = bt + add;
|
|
314
|
-
if (bt < dt) {
|
|
315
|
-
var shift = dl - dt,
|
|
316
|
-
dend = Math.min(dt, end);
|
|
317
|
-
if (shift + bt < 0) err(3);
|
|
318
|
-
for (; bt < dend; ++bt) buf[bt] = dict[shift + bt];
|
|
319
|
-
}
|
|
320
|
-
for (; bt < end; ++bt) buf[bt] = buf[bt - dt];
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
st.l = lm, st.p = lpos, st.b = bt, st.f = final;
|
|
324
|
-
if (lm) final = 1, st.m = lbt, st.d = dm, st.n = dbt;
|
|
325
|
-
} while (!final);
|
|
326
|
-
// don't reallocate for streams or user buffers
|
|
327
|
-
return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);
|
|
328
|
-
};
|
|
329
|
-
// starting at p, write the minimum number of bits that can hold v to d
|
|
330
|
-
var wbits = function (d, p, v) {
|
|
331
|
-
v <<= p & 7;
|
|
332
|
-
var o = p / 8 | 0;
|
|
333
|
-
d[o] |= v;
|
|
334
|
-
d[o + 1] |= v >> 8;
|
|
335
|
-
};
|
|
336
|
-
// starting at p, write the minimum number of bits (>8) that can hold v to d
|
|
337
|
-
var wbits16 = function (d, p, v) {
|
|
338
|
-
v <<= p & 7;
|
|
339
|
-
var o = p / 8 | 0;
|
|
340
|
-
d[o] |= v;
|
|
341
|
-
d[o + 1] |= v >> 8;
|
|
342
|
-
d[o + 2] |= v >> 16;
|
|
343
|
-
};
|
|
344
|
-
// creates code lengths from a frequency table
|
|
345
|
-
var hTree = function (d, mb) {
|
|
346
|
-
// Need extra info to make a tree
|
|
347
|
-
var t = [];
|
|
348
|
-
for (var i = 0; i < d.length; ++i) {
|
|
349
|
-
if (d[i]) t.push({
|
|
350
|
-
s: i,
|
|
351
|
-
f: d[i]
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
var s = t.length;
|
|
355
|
-
var t2 = t.slice();
|
|
356
|
-
if (!s) return {
|
|
357
|
-
t: et,
|
|
358
|
-
l: 0
|
|
359
|
-
};
|
|
360
|
-
if (s == 1) {
|
|
361
|
-
var v = new u8(t[0].s + 1);
|
|
362
|
-
v[t[0].s] = 1;
|
|
363
|
-
return {
|
|
364
|
-
t: v,
|
|
365
|
-
l: 1
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
t.sort(function (a, b) {
|
|
369
|
-
return a.f - b.f;
|
|
370
|
-
});
|
|
371
|
-
// after i2 reaches last ind, will be stopped
|
|
372
|
-
// freq must be greater than largest possible number of symbols
|
|
373
|
-
t.push({
|
|
374
|
-
s: -1,
|
|
375
|
-
f: 25001
|
|
376
|
-
});
|
|
377
|
-
var l = t[0],
|
|
378
|
-
r = t[1],
|
|
379
|
-
i0 = 0,
|
|
380
|
-
i1 = 1,
|
|
381
|
-
i2 = 2;
|
|
382
|
-
t[0] = {
|
|
383
|
-
s: -1,
|
|
384
|
-
f: l.f + r.f,
|
|
385
|
-
l: l,
|
|
386
|
-
r: r
|
|
387
|
-
};
|
|
388
|
-
// efficient algorithm from UZIP.js
|
|
389
|
-
// i0 is lookbehind, i2 is lookahead - after processing two low-freq
|
|
390
|
-
// symbols that combined have high freq, will start processing i2 (high-freq,
|
|
391
|
-
// non-composite) symbols instead
|
|
392
|
-
// see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/
|
|
393
|
-
while (i1 != s - 1) {
|
|
394
|
-
l = t[t[i0].f < t[i2].f ? i0++ : i2++];
|
|
395
|
-
r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];
|
|
396
|
-
t[i1++] = {
|
|
397
|
-
s: -1,
|
|
398
|
-
f: l.f + r.f,
|
|
399
|
-
l: l,
|
|
400
|
-
r: r
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
var maxSym = t2[0].s;
|
|
404
|
-
for (var i = 1; i < s; ++i) {
|
|
405
|
-
if (t2[i].s > maxSym) maxSym = t2[i].s;
|
|
406
|
-
}
|
|
407
|
-
// code lengths
|
|
408
|
-
var tr = new u16(maxSym + 1);
|
|
409
|
-
// max bits in tree
|
|
410
|
-
var mbt = ln(t[i1 - 1], tr, 0);
|
|
411
|
-
if (mbt > mb) {
|
|
412
|
-
// more algorithms from UZIP.js
|
|
413
|
-
// TODO: find out how this code works (debt)
|
|
414
|
-
// ind debt
|
|
415
|
-
var i = 0,
|
|
416
|
-
dt = 0;
|
|
417
|
-
// left cost
|
|
418
|
-
var lft = mbt - mb,
|
|
419
|
-
cst = 1 << lft;
|
|
420
|
-
t2.sort(function (a, b) {
|
|
421
|
-
return tr[b.s] - tr[a.s] || a.f - b.f;
|
|
422
|
-
});
|
|
423
|
-
for (; i < s; ++i) {
|
|
424
|
-
var i2_1 = t2[i].s;
|
|
425
|
-
if (tr[i2_1] > mb) {
|
|
426
|
-
dt += cst - (1 << mbt - tr[i2_1]);
|
|
427
|
-
tr[i2_1] = mb;
|
|
428
|
-
} else break;
|
|
429
|
-
}
|
|
430
|
-
dt >>= lft;
|
|
431
|
-
while (dt > 0) {
|
|
432
|
-
var i2_2 = t2[i].s;
|
|
433
|
-
if (tr[i2_2] < mb) dt -= 1 << mb - tr[i2_2]++ - 1;else ++i;
|
|
434
|
-
}
|
|
435
|
-
for (; i >= 0 && dt; --i) {
|
|
436
|
-
var i2_3 = t2[i].s;
|
|
437
|
-
if (tr[i2_3] == mb) {
|
|
438
|
-
--tr[i2_3];
|
|
439
|
-
++dt;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
mbt = mb;
|
|
443
|
-
}
|
|
444
|
-
return {
|
|
445
|
-
t: new u8(tr),
|
|
446
|
-
l: mbt
|
|
447
|
-
};
|
|
448
|
-
};
|
|
449
|
-
// get the max length and assign length codes
|
|
450
|
-
var ln = function (n, l, d) {
|
|
451
|
-
return n.s == -1 ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1)) : l[n.s] = d;
|
|
452
|
-
};
|
|
453
|
-
// length codes generation
|
|
454
|
-
var lc = function (c) {
|
|
455
|
-
var s = c.length;
|
|
456
|
-
// Note that the semicolon was intentional
|
|
457
|
-
while (s && !c[--s]);
|
|
458
|
-
var cl = new u16(++s);
|
|
459
|
-
// ind num streak
|
|
460
|
-
var cli = 0,
|
|
461
|
-
cln = c[0],
|
|
462
|
-
cls = 1;
|
|
463
|
-
var w = function (v) {
|
|
464
|
-
cl[cli++] = v;
|
|
465
|
-
};
|
|
466
|
-
for (var i = 1; i <= s; ++i) {
|
|
467
|
-
if (c[i] == cln && i != s) ++cls;else {
|
|
468
|
-
if (!cln && cls > 2) {
|
|
469
|
-
for (; cls > 138; cls -= 138) w(32754);
|
|
470
|
-
if (cls > 2) {
|
|
471
|
-
w(cls > 10 ? cls - 11 << 5 | 28690 : cls - 3 << 5 | 12305);
|
|
472
|
-
cls = 0;
|
|
473
|
-
}
|
|
474
|
-
} else if (cls > 3) {
|
|
475
|
-
w(cln), --cls;
|
|
476
|
-
for (; cls > 6; cls -= 6) w(8304);
|
|
477
|
-
if (cls > 2) w(cls - 3 << 5 | 8208), cls = 0;
|
|
478
|
-
}
|
|
479
|
-
while (cls--) w(cln);
|
|
480
|
-
cls = 1;
|
|
481
|
-
cln = c[i];
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return {
|
|
485
|
-
c: cl.subarray(0, cli),
|
|
486
|
-
n: s
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
|
-
// calculate the length of output from tree, code lengths
|
|
490
|
-
var clen = function (cf, cl) {
|
|
491
|
-
var l = 0;
|
|
492
|
-
for (var i = 0; i < cl.length; ++i) l += cf[i] * cl[i];
|
|
493
|
-
return l;
|
|
494
|
-
};
|
|
495
|
-
// writes a fixed block
|
|
496
|
-
// returns the new bit pos
|
|
497
|
-
var wfblk = function (out, pos, dat) {
|
|
498
|
-
// no need to write 00 as type: TypedArray defaults to 0
|
|
499
|
-
var s = dat.length;
|
|
500
|
-
var o = shft(pos + 2);
|
|
501
|
-
out[o] = s & 255;
|
|
502
|
-
out[o + 1] = s >> 8;
|
|
503
|
-
out[o + 2] = out[o] ^ 255;
|
|
504
|
-
out[o + 3] = out[o + 1] ^ 255;
|
|
505
|
-
for (var i = 0; i < s; ++i) out[o + i + 4] = dat[i];
|
|
506
|
-
return (o + 4 + s) * 8;
|
|
507
|
-
};
|
|
508
|
-
// writes a block
|
|
509
|
-
var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
|
|
510
|
-
wbits(out, p++, final);
|
|
511
|
-
++lf[256];
|
|
512
|
-
var _a = hTree(lf, 15),
|
|
513
|
-
dlt = _a.t,
|
|
514
|
-
mlb = _a.l;
|
|
515
|
-
var _b = hTree(df, 15),
|
|
516
|
-
ddt = _b.t,
|
|
517
|
-
mdb = _b.l;
|
|
518
|
-
var _c = lc(dlt),
|
|
519
|
-
lclt = _c.c,
|
|
520
|
-
nlc = _c.n;
|
|
521
|
-
var _d = lc(ddt),
|
|
522
|
-
lcdt = _d.c,
|
|
523
|
-
ndc = _d.n;
|
|
524
|
-
var lcfreq = new u16(19);
|
|
525
|
-
for (var i = 0; i < lclt.length; ++i) ++lcfreq[lclt[i] & 31];
|
|
526
|
-
for (var i = 0; i < lcdt.length; ++i) ++lcfreq[lcdt[i] & 31];
|
|
527
|
-
var _e = hTree(lcfreq, 7),
|
|
528
|
-
lct = _e.t,
|
|
529
|
-
mlcb = _e.l;
|
|
530
|
-
var nlcc = 19;
|
|
531
|
-
for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc);
|
|
532
|
-
var flen = bl + 5 << 3;
|
|
533
|
-
var ftlen = clen(lf, flt) + clen(df, fdt) + eb;
|
|
534
|
-
var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];
|
|
535
|
-
if (bs >= 0 && flen <= ftlen && flen <= dtlen) return wfblk(out, p, dat.subarray(bs, bs + bl));
|
|
536
|
-
var lm, ll, dm, dl;
|
|
537
|
-
wbits(out, p, 1 + (dtlen < ftlen)), p += 2;
|
|
538
|
-
if (dtlen < ftlen) {
|
|
539
|
-
lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;
|
|
540
|
-
var llm = hMap(lct, mlcb, 0);
|
|
541
|
-
wbits(out, p, nlc - 257);
|
|
542
|
-
wbits(out, p + 5, ndc - 1);
|
|
543
|
-
wbits(out, p + 10, nlcc - 4);
|
|
544
|
-
p += 14;
|
|
545
|
-
for (var i = 0; i < nlcc; ++i) wbits(out, p + 3 * i, lct[clim[i]]);
|
|
546
|
-
p += 3 * nlcc;
|
|
547
|
-
var lcts = [lclt, lcdt];
|
|
548
|
-
for (var it = 0; it < 2; ++it) {
|
|
549
|
-
var clct = lcts[it];
|
|
550
|
-
for (var i = 0; i < clct.length; ++i) {
|
|
551
|
-
var len = clct[i] & 31;
|
|
552
|
-
wbits(out, p, llm[len]), p += lct[len];
|
|
553
|
-
if (len > 15) wbits(out, p, clct[i] >> 5 & 127), p += clct[i] >> 12;
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
lm = flm, ll = flt, dm = fdm, dl = fdt;
|
|
558
|
-
}
|
|
559
|
-
for (var i = 0; i < li; ++i) {
|
|
560
|
-
var sym = syms[i];
|
|
561
|
-
if (sym > 255) {
|
|
562
|
-
var len = sym >> 18 & 31;
|
|
563
|
-
wbits16(out, p, lm[len + 257]), p += ll[len + 257];
|
|
564
|
-
if (len > 7) wbits(out, p, sym >> 23 & 31), p += fleb[len];
|
|
565
|
-
var dst = sym & 31;
|
|
566
|
-
wbits16(out, p, dm[dst]), p += dl[dst];
|
|
567
|
-
if (dst > 3) wbits16(out, p, sym >> 5 & 8191), p += fdeb[dst];
|
|
568
|
-
} else {
|
|
569
|
-
wbits16(out, p, lm[sym]), p += ll[sym];
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
wbits16(out, p, lm[256]);
|
|
573
|
-
return p + ll[256];
|
|
574
|
-
};
|
|
575
|
-
// deflate options (nice << 13) | chain
|
|
576
|
-
var deo = /*#__PURE__*/new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);
|
|
577
|
-
// empty
|
|
578
|
-
var et = /*#__PURE__*/new u8(0);
|
|
579
|
-
// compresses data into a raw DEFLATE buffer
|
|
580
|
-
var dflt = function (dat, lvl, plvl, pre, post, st) {
|
|
581
|
-
var s = st.z || dat.length;
|
|
582
|
-
var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);
|
|
583
|
-
// writing to this writes to the output buffer
|
|
584
|
-
var w = o.subarray(pre, o.length - post);
|
|
585
|
-
var lst = st.l;
|
|
586
|
-
var pos = (st.r || 0) & 7;
|
|
587
|
-
if (lvl) {
|
|
588
|
-
if (pos) w[0] = st.r >> 3;
|
|
589
|
-
var opt = deo[lvl - 1];
|
|
590
|
-
var n = opt >> 13,
|
|
591
|
-
c = opt & 8191;
|
|
592
|
-
var msk_1 = (1 << plvl) - 1;
|
|
593
|
-
// prev 2-byte val map curr 2-byte val map
|
|
594
|
-
var prev = st.p || new u16(32768),
|
|
595
|
-
head = st.h || new u16(msk_1 + 1);
|
|
596
|
-
var bs1_1 = Math.ceil(plvl / 3),
|
|
597
|
-
bs2_1 = 2 * bs1_1;
|
|
598
|
-
var hsh = function (i) {
|
|
599
|
-
return (dat[i] ^ dat[i + 1] << bs1_1 ^ dat[i + 2] << bs2_1) & msk_1;
|
|
600
|
-
};
|
|
601
|
-
// 24576 is an arbitrary number of maximum symbols per block
|
|
602
|
-
// 424 buffer for last block
|
|
603
|
-
var syms = new i32(25000);
|
|
604
|
-
// length/literal freq distance freq
|
|
605
|
-
var lf = new u16(288),
|
|
606
|
-
df = new u16(32);
|
|
607
|
-
// l/lcnt exbits index l/lind waitdx blkpos
|
|
608
|
-
var lc_1 = 0,
|
|
609
|
-
eb = 0,
|
|
610
|
-
i = st.i || 0,
|
|
611
|
-
li = 0,
|
|
612
|
-
wi = st.w || 0,
|
|
613
|
-
bs = 0;
|
|
614
|
-
for (; i + 2 < s; ++i) {
|
|
615
|
-
// hash value
|
|
616
|
-
var hv = hsh(i);
|
|
617
|
-
// index mod 32768 previous index mod
|
|
618
|
-
var imod = i & 32767,
|
|
619
|
-
pimod = head[hv];
|
|
620
|
-
prev[imod] = pimod;
|
|
621
|
-
head[hv] = imod;
|
|
622
|
-
// We always should modify head and prev, but only add symbols if
|
|
623
|
-
// this data is not yet processed ("wait" for wait index)
|
|
624
|
-
if (wi <= i) {
|
|
625
|
-
// bytes remaining
|
|
626
|
-
var rem = s - i;
|
|
627
|
-
if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {
|
|
628
|
-
pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
629
|
-
li = lc_1 = eb = 0, bs = i;
|
|
630
|
-
for (var j = 0; j < 286; ++j) lf[j] = 0;
|
|
631
|
-
for (var j = 0; j < 30; ++j) df[j] = 0;
|
|
632
|
-
}
|
|
633
|
-
// len dist chain
|
|
634
|
-
var l = 2,
|
|
635
|
-
d = 0,
|
|
636
|
-
ch_1 = c,
|
|
637
|
-
dif = imod - pimod & 32767;
|
|
638
|
-
if (rem > 2 && hv == hsh(i - dif)) {
|
|
639
|
-
var maxn = Math.min(n, rem) - 1;
|
|
640
|
-
var maxd = Math.min(32767, i);
|
|
641
|
-
// max possible length
|
|
642
|
-
// not capped at dif because decompressors implement "rolling" index population
|
|
643
|
-
var ml = Math.min(258, rem);
|
|
644
|
-
while (dif <= maxd && --ch_1 && imod != pimod) {
|
|
645
|
-
if (dat[i + l] == dat[i + l - dif]) {
|
|
646
|
-
var nl = 0;
|
|
647
|
-
for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl);
|
|
648
|
-
if (nl > l) {
|
|
649
|
-
l = nl, d = dif;
|
|
650
|
-
// break out early when we reach "nice" (we are satisfied enough)
|
|
651
|
-
if (nl > maxn) break;
|
|
652
|
-
// now, find the rarest 2-byte sequence within this
|
|
653
|
-
// length of literals and search for that instead.
|
|
654
|
-
// Much faster than just using the start
|
|
655
|
-
var mmd = Math.min(dif, nl - 2);
|
|
656
|
-
var md = 0;
|
|
657
|
-
for (var j = 0; j < mmd; ++j) {
|
|
658
|
-
var ti = i - dif + j & 32767;
|
|
659
|
-
var pti = prev[ti];
|
|
660
|
-
var cd = ti - pti & 32767;
|
|
661
|
-
if (cd > md) md = cd, pimod = ti;
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
// check the previous match
|
|
666
|
-
imod = pimod, pimod = prev[imod];
|
|
667
|
-
dif += imod - pimod & 32767;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
// d will be nonzero only when a match was found
|
|
671
|
-
if (d) {
|
|
672
|
-
// store both dist and len data in one int32
|
|
673
|
-
// Make sure this is recognized as a len/dist with 28th bit (2^28)
|
|
674
|
-
syms[li++] = 268435456 | revfl[l] << 18 | revfd[d];
|
|
675
|
-
var lin = revfl[l] & 31,
|
|
676
|
-
din = revfd[d] & 31;
|
|
677
|
-
eb += fleb[lin] + fdeb[din];
|
|
678
|
-
++lf[257 + lin];
|
|
679
|
-
++df[din];
|
|
680
|
-
wi = i + l;
|
|
681
|
-
++lc_1;
|
|
682
|
-
} else {
|
|
683
|
-
syms[li++] = dat[i];
|
|
684
|
-
++lf[dat[i]];
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
for (i = Math.max(i, wi); i < s; ++i) {
|
|
689
|
-
syms[li++] = dat[i];
|
|
690
|
-
++lf[dat[i]];
|
|
691
|
-
}
|
|
692
|
-
pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);
|
|
693
|
-
if (!lst) {
|
|
694
|
-
st.r = pos & 7 | w[pos / 8 | 0] << 3;
|
|
695
|
-
// shft(pos) now 1 less if pos & 7 != 0
|
|
696
|
-
pos -= 7;
|
|
697
|
-
st.h = head, st.p = prev, st.i = i, st.w = wi;
|
|
698
|
-
}
|
|
699
|
-
} else {
|
|
700
|
-
for (var i = st.w || 0; i < s + lst; i += 65535) {
|
|
701
|
-
// end
|
|
702
|
-
var e = i + 65535;
|
|
703
|
-
if (e >= s) {
|
|
704
|
-
// write final block
|
|
705
|
-
w[pos / 8 | 0] = lst;
|
|
706
|
-
e = s;
|
|
707
|
-
}
|
|
708
|
-
pos = wfblk(w, pos + 1, dat.subarray(i, e));
|
|
709
|
-
}
|
|
710
|
-
st.i = s;
|
|
711
|
-
}
|
|
712
|
-
return slc(o, 0, pre + shft(pos) + post);
|
|
713
|
-
};
|
|
714
|
-
// deflate with opts
|
|
715
|
-
var dopt = function (dat, opt, pre, post, st) {
|
|
716
|
-
if (!st) {
|
|
717
|
-
st = {
|
|
718
|
-
l: 1
|
|
719
|
-
};
|
|
720
|
-
if (opt.dictionary) {
|
|
721
|
-
var dict = opt.dictionary.subarray(-32768);
|
|
722
|
-
var newDat = new u8(dict.length + dat.length);
|
|
723
|
-
newDat.set(dict);
|
|
724
|
-
newDat.set(dat, dict.length);
|
|
725
|
-
dat = newDat;
|
|
726
|
-
st.w = dict.length;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20 : 12 + opt.mem, pre, post, st);
|
|
730
|
-
};
|
|
731
|
-
/**
|
|
732
|
-
* Compresses data with DEFLATE without any wrapper
|
|
733
|
-
* @param data The data to compress
|
|
734
|
-
* @param opts The compression options
|
|
735
|
-
* @returns The deflated version of the data
|
|
736
|
-
*/
|
|
737
|
-
function deflateSync(data, opts) {
|
|
738
|
-
return dopt(data, opts || {}, 0, 0);
|
|
739
|
-
}
|
|
740
|
-
/**
|
|
741
|
-
* Expands DEFLATE data with no wrapper
|
|
742
|
-
* @param data The data to decompress
|
|
743
|
-
* @param opts The decompression options
|
|
744
|
-
* @returns The decompressed version of the data
|
|
745
|
-
*/
|
|
746
|
-
function inflateSync(data, opts) {
|
|
747
|
-
return inflt(data, {
|
|
748
|
-
i: 2
|
|
749
|
-
}, opts, opts);
|
|
750
|
-
}
|
|
751
|
-
// text encoder
|
|
752
|
-
var te = typeof TextEncoder != 'undefined' && /*#__PURE__*/new TextEncoder();
|
|
753
|
-
// text decoder
|
|
754
|
-
var td = typeof TextDecoder != 'undefined' && /*#__PURE__*/new TextDecoder();
|
|
755
|
-
try {
|
|
756
|
-
td.decode(et, {
|
|
757
|
-
stream: true
|
|
758
|
-
});
|
|
759
|
-
} catch (e) {}
|
|
760
|
-
// decode UTF8
|
|
761
|
-
var dutf8 = function (d) {
|
|
762
|
-
for (var r = '', i = 0;;) {
|
|
763
|
-
var c = d[i++];
|
|
764
|
-
var eb = (c > 127) + (c > 223) + (c > 239);
|
|
765
|
-
if (i + eb > d.length) return {
|
|
766
|
-
s: r,
|
|
767
|
-
r: slc(d, i - 1)
|
|
768
|
-
};
|
|
769
|
-
if (!eb) r += String.fromCharCode(c);else if (eb == 3) {
|
|
770
|
-
c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | d[i++] & 63) - 65536, r += String.fromCharCode(55296 | c >> 10, 56320 | c & 1023);
|
|
771
|
-
} else if (eb & 1) r += String.fromCharCode((c & 31) << 6 | d[i++] & 63);else r += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | d[i++] & 63);
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
/**
|
|
775
|
-
* Converts a string into a Uint8Array for use with compression/decompression methods
|
|
776
|
-
* @param str The string to encode
|
|
777
|
-
* @param latin1 Whether or not to interpret the data as Latin-1. This should
|
|
778
|
-
* not need to be true unless decoding a binary string.
|
|
779
|
-
* @returns The string encoded in UTF-8/Latin-1 binary
|
|
780
|
-
*/
|
|
781
|
-
function strToU8(str, latin1) {
|
|
782
|
-
var i;
|
|
783
|
-
if (te) return te.encode(str);
|
|
784
|
-
var l = str.length;
|
|
785
|
-
var ar = new u8(str.length + (str.length >> 1));
|
|
786
|
-
var ai = 0;
|
|
787
|
-
var w = function (v) {
|
|
788
|
-
ar[ai++] = v;
|
|
789
|
-
};
|
|
790
|
-
for (var i = 0; i < l; ++i) {
|
|
791
|
-
if (ai + 5 > ar.length) {
|
|
792
|
-
var n = new u8(ai + 8 + (l - i << 1));
|
|
793
|
-
n.set(ar);
|
|
794
|
-
ar = n;
|
|
795
|
-
}
|
|
796
|
-
var c = str.charCodeAt(i);
|
|
797
|
-
if (c < 128 || latin1) w(c);else if (c < 2048) w(192 | c >> 6), w(128 | c & 63);else if (c > 55295 && c < 57344) c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);else w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
|
798
|
-
}
|
|
799
|
-
return slc(ar, 0, ai);
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Converts a Uint8Array to a string
|
|
803
|
-
* @param dat The data to decode to string
|
|
804
|
-
* @param latin1 Whether or not to interpret the data as Latin-1. This should
|
|
805
|
-
* not need to be true unless encoding to binary string.
|
|
806
|
-
* @returns The original UTF-8/Latin-1 string
|
|
807
|
-
*/
|
|
808
|
-
function strFromU8(dat, latin1) {
|
|
809
|
-
var r; if (td) {
|
|
810
|
-
return td.decode(dat);
|
|
811
|
-
} else {
|
|
812
|
-
var _a = dutf8(dat),
|
|
813
|
-
s = _a.s,
|
|
814
|
-
r = _a.r;
|
|
815
|
-
if (r.length) err(8);
|
|
816
|
-
return s;
|
|
817
|
-
}
|
|
818
|
-
}const RAW_PREFIX = 'storage:raw:';
|
|
1
|
+
'use strict';var fflate=require('fflate'),compilerRuntime=require('react/compiler-runtime'),jotai=require('jotai'),utils=require('jotai/utils');const RAW_PREFIX = 'storage:raw:';
|
|
819
2
|
const DEFLATE_PREFIX = 'storage:deflate:v1:';
|
|
820
3
|
const isProbablyJson = value => {
|
|
821
4
|
if (!value) return false;
|
|
@@ -856,8 +39,8 @@ const createCompressedStorage = (base, options = {}) => {
|
|
|
856
39
|
base.setItem(key, RAW_PREFIX + value);
|
|
857
40
|
continue;
|
|
858
41
|
}
|
|
859
|
-
const input = strToU8(value);
|
|
860
|
-
const compressed = deflateSync(input, {
|
|
42
|
+
const input = fflate.strToU8(value);
|
|
43
|
+
const compressed = fflate.deflateSync(input, {
|
|
861
44
|
level: deflateLevel
|
|
862
45
|
});
|
|
863
46
|
base.setItem(key, DEFLATE_PREFIX + u8ToBase64(compressed));
|
|
@@ -894,8 +77,8 @@ const createCompressedStorage = (base, options = {}) => {
|
|
|
894
77
|
if (stored.startsWith(DEFLATE_PREFIX)) {
|
|
895
78
|
const b64 = stored.slice(DEFLATE_PREFIX.length);
|
|
896
79
|
const bytes = base64ToU8(b64);
|
|
897
|
-
const decompressed = inflateSync(bytes);
|
|
898
|
-
return strFromU8(decompressed);
|
|
80
|
+
const decompressed = fflate.inflateSync(bytes);
|
|
81
|
+
return fflate.strFromU8(decompressed);
|
|
899
82
|
}
|
|
900
83
|
// Back-compat: older versions may have stored raw JSON without any prefix
|
|
901
84
|
if (isProbablyJson(stored)) return stored;
|
|
@@ -948,963 +131,7 @@ const baseStorage = {
|
|
|
948
131
|
exports.storage = createCompressedStorage(baseStorage);
|
|
949
132
|
const setCustomStorage = newStorage => {
|
|
950
133
|
exports.storage = newStorage;
|
|
951
|
-
}
|
|
952
|
-
return "init" in atom;
|
|
953
|
-
}
|
|
954
|
-
function isActuallyWritableAtom(atom) {
|
|
955
|
-
return !!atom.write;
|
|
956
|
-
}
|
|
957
|
-
function isAtomStateInitialized(atomState) {
|
|
958
|
-
return "v" in atomState || "e" in atomState;
|
|
959
|
-
}
|
|
960
|
-
function returnAtomValue(atomState) {
|
|
961
|
-
if ("e" in atomState) {
|
|
962
|
-
throw atomState.e;
|
|
963
|
-
}
|
|
964
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && !("v" in atomState)) {
|
|
965
|
-
throw new Error("[Bug] atom state is not initialized");
|
|
966
|
-
}
|
|
967
|
-
return atomState.v;
|
|
968
|
-
}
|
|
969
|
-
const promiseStateMap = /* @__PURE__ */ new WeakMap();
|
|
970
|
-
function isPendingPromise(value) {
|
|
971
|
-
var _a;
|
|
972
|
-
return isPromiseLike$1(value) && !!((_a = promiseStateMap.get(value)) == null ? void 0 : _a[0]);
|
|
973
|
-
}
|
|
974
|
-
function abortPromise(promise) {
|
|
975
|
-
const promiseState = promiseStateMap.get(promise);
|
|
976
|
-
if (promiseState == null ? void 0 : promiseState[0]) {
|
|
977
|
-
promiseState[0] = false;
|
|
978
|
-
promiseState[1].forEach((fn) => fn());
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
function registerAbortHandler(promise, abortHandler) {
|
|
982
|
-
let promiseState = promiseStateMap.get(promise);
|
|
983
|
-
if (!promiseState) {
|
|
984
|
-
promiseState = [true, /* @__PURE__ */ new Set()];
|
|
985
|
-
promiseStateMap.set(promise, promiseState);
|
|
986
|
-
const settle = () => {
|
|
987
|
-
promiseState[0] = false;
|
|
988
|
-
};
|
|
989
|
-
promise.then(settle, settle);
|
|
990
|
-
}
|
|
991
|
-
promiseState[1].add(abortHandler);
|
|
992
|
-
}
|
|
993
|
-
function isPromiseLike$1(p) {
|
|
994
|
-
return typeof (p == null ? void 0 : p.then) === "function";
|
|
995
|
-
}
|
|
996
|
-
function addPendingPromiseToDependency(atom, promise, dependencyAtomState) {
|
|
997
|
-
if (!dependencyAtomState.p.has(atom)) {
|
|
998
|
-
dependencyAtomState.p.add(atom);
|
|
999
|
-
const cleanup = () => dependencyAtomState.p.delete(atom);
|
|
1000
|
-
promise.then(cleanup, cleanup);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
function getMountedOrPendingDependents(atom, atomState, mountedMap) {
|
|
1004
|
-
var _a;
|
|
1005
|
-
const dependents = /* @__PURE__ */ new Set();
|
|
1006
|
-
for (const a of ((_a = mountedMap.get(atom)) == null ? void 0 : _a.t) || []) {
|
|
1007
|
-
dependents.add(a);
|
|
1008
|
-
}
|
|
1009
|
-
for (const atomWithPendingPromise of atomState.p) {
|
|
1010
|
-
dependents.add(atomWithPendingPromise);
|
|
1011
|
-
}
|
|
1012
|
-
return dependents;
|
|
1013
|
-
}
|
|
1014
|
-
const BUILDING_BLOCK_atomRead = (_store, atom, ...params) => atom.read(...params);
|
|
1015
|
-
const BUILDING_BLOCK_atomWrite = (_store, atom, ...params) => atom.write(...params);
|
|
1016
|
-
const BUILDING_BLOCK_atomOnInit = (store, atom) => {
|
|
1017
|
-
var _a;
|
|
1018
|
-
return (_a = atom.INTERNAL_onInit) == null ? void 0 : _a.call(atom, store);
|
|
1019
|
-
};
|
|
1020
|
-
const BUILDING_BLOCK_atomOnMount = (_store, atom, setAtom) => {
|
|
1021
|
-
var _a;
|
|
1022
|
-
return (_a = atom.onMount) == null ? void 0 : _a.call(atom, setAtom);
|
|
1023
|
-
};
|
|
1024
|
-
const BUILDING_BLOCK_ensureAtomState = (store, atom) => {
|
|
1025
|
-
var _a;
|
|
1026
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1027
|
-
const atomStateMap = buildingBlocks[0];
|
|
1028
|
-
const storeHooks = buildingBlocks[6];
|
|
1029
|
-
const atomOnInit = buildingBlocks[9];
|
|
1030
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && !atom) {
|
|
1031
|
-
throw new Error("Atom is undefined or null");
|
|
1032
|
-
}
|
|
1033
|
-
let atomState = atomStateMap.get(atom);
|
|
1034
|
-
if (!atomState) {
|
|
1035
|
-
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
|
|
1036
|
-
atomStateMap.set(atom, atomState);
|
|
1037
|
-
(_a = storeHooks.i) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1038
|
-
atomOnInit == null ? void 0 : atomOnInit(store, atom);
|
|
1039
|
-
}
|
|
1040
|
-
return atomState;
|
|
1041
|
-
};
|
|
1042
|
-
const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
1043
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1044
|
-
const mountedMap = buildingBlocks[1];
|
|
1045
|
-
const changedAtoms = buildingBlocks[3];
|
|
1046
|
-
const mountCallbacks = buildingBlocks[4];
|
|
1047
|
-
const unmountCallbacks = buildingBlocks[5];
|
|
1048
|
-
const storeHooks = buildingBlocks[6];
|
|
1049
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1050
|
-
const errors = [];
|
|
1051
|
-
const call = (fn) => {
|
|
1052
|
-
try {
|
|
1053
|
-
fn();
|
|
1054
|
-
} catch (e) {
|
|
1055
|
-
errors.push(e);
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
do {
|
|
1059
|
-
if (storeHooks.f) {
|
|
1060
|
-
call(storeHooks.f);
|
|
1061
|
-
}
|
|
1062
|
-
const callbacks = /* @__PURE__ */ new Set();
|
|
1063
|
-
const add = callbacks.add.bind(callbacks);
|
|
1064
|
-
changedAtoms.forEach((atom) => {
|
|
1065
|
-
var _a;
|
|
1066
|
-
return (_a = mountedMap.get(atom)) == null ? void 0 : _a.l.forEach(add);
|
|
1067
|
-
});
|
|
1068
|
-
changedAtoms.clear();
|
|
1069
|
-
unmountCallbacks.forEach(add);
|
|
1070
|
-
unmountCallbacks.clear();
|
|
1071
|
-
mountCallbacks.forEach(add);
|
|
1072
|
-
mountCallbacks.clear();
|
|
1073
|
-
callbacks.forEach(call);
|
|
1074
|
-
if (changedAtoms.size) {
|
|
1075
|
-
recomputeInvalidatedAtoms(store);
|
|
1076
|
-
}
|
|
1077
|
-
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
|
|
1078
|
-
if (errors.length) {
|
|
1079
|
-
throw new AggregateError(errors);
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
const BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
1083
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1084
|
-
const mountedMap = buildingBlocks[1];
|
|
1085
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
1086
|
-
const changedAtoms = buildingBlocks[3];
|
|
1087
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1088
|
-
const readAtomState = buildingBlocks[14];
|
|
1089
|
-
const mountDependencies = buildingBlocks[17];
|
|
1090
|
-
const topSortedReversed = [];
|
|
1091
|
-
const visiting = /* @__PURE__ */ new WeakSet();
|
|
1092
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
1093
|
-
const stack = Array.from(changedAtoms);
|
|
1094
|
-
while (stack.length) {
|
|
1095
|
-
const a = stack[stack.length - 1];
|
|
1096
|
-
const aState = ensureAtomState(store, a);
|
|
1097
|
-
if (visited.has(a)) {
|
|
1098
|
-
stack.pop();
|
|
1099
|
-
continue;
|
|
1100
|
-
}
|
|
1101
|
-
if (visiting.has(a)) {
|
|
1102
|
-
if (invalidatedAtoms.get(a) === aState.n) {
|
|
1103
|
-
topSortedReversed.push([a, aState]);
|
|
1104
|
-
} else if ((undefined ? undefined.MODE : void 0) !== "production" && invalidatedAtoms.has(a)) {
|
|
1105
|
-
throw new Error("[Bug] invalidated atom exists");
|
|
1106
|
-
}
|
|
1107
|
-
visited.add(a);
|
|
1108
|
-
stack.pop();
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
visiting.add(a);
|
|
1112
|
-
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
1113
|
-
if (!visiting.has(d)) {
|
|
1114
|
-
stack.push(d);
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
for (let i = topSortedReversed.length - 1; i >= 0; --i) {
|
|
1119
|
-
const [a, aState] = topSortedReversed[i];
|
|
1120
|
-
let hasChangedDeps = false;
|
|
1121
|
-
for (const dep of aState.d.keys()) {
|
|
1122
|
-
if (dep !== a && changedAtoms.has(dep)) {
|
|
1123
|
-
hasChangedDeps = true;
|
|
1124
|
-
break;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
if (hasChangedDeps) {
|
|
1128
|
-
readAtomState(store, a);
|
|
1129
|
-
mountDependencies(store, a);
|
|
1130
|
-
}
|
|
1131
|
-
invalidatedAtoms.delete(a);
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
const storeMutationSet = /* @__PURE__ */ new WeakSet();
|
|
1135
|
-
const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
1136
|
-
var _a, _b;
|
|
1137
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1138
|
-
const mountedMap = buildingBlocks[1];
|
|
1139
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
1140
|
-
const changedAtoms = buildingBlocks[3];
|
|
1141
|
-
const storeHooks = buildingBlocks[6];
|
|
1142
|
-
const atomRead = buildingBlocks[7];
|
|
1143
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1144
|
-
const flushCallbacks = buildingBlocks[12];
|
|
1145
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1146
|
-
const readAtomState = buildingBlocks[14];
|
|
1147
|
-
const writeAtomState = buildingBlocks[16];
|
|
1148
|
-
const mountDependencies = buildingBlocks[17];
|
|
1149
|
-
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
1150
|
-
const atomState = ensureAtomState(store, atom);
|
|
1151
|
-
if (isAtomStateInitialized(atomState)) {
|
|
1152
|
-
if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
|
|
1153
|
-
return atomState;
|
|
1154
|
-
}
|
|
1155
|
-
let hasChangedDeps = false;
|
|
1156
|
-
for (const [a, n] of atomState.d) {
|
|
1157
|
-
if (readAtomState(store, a).n !== n) {
|
|
1158
|
-
hasChangedDeps = true;
|
|
1159
|
-
break;
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
if (!hasChangedDeps) {
|
|
1163
|
-
return atomState;
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
atomState.d.clear();
|
|
1167
|
-
let isSync = true;
|
|
1168
|
-
function mountDependenciesIfAsync() {
|
|
1169
|
-
if (mountedMap.has(atom)) {
|
|
1170
|
-
mountDependencies(store, atom);
|
|
1171
|
-
recomputeInvalidatedAtoms(store);
|
|
1172
|
-
flushCallbacks(store);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
function getter(a) {
|
|
1176
|
-
var _a2;
|
|
1177
|
-
if (a === atom) {
|
|
1178
|
-
const aState2 = ensureAtomState(store, a);
|
|
1179
|
-
if (!isAtomStateInitialized(aState2)) {
|
|
1180
|
-
if (hasInitialValue(a)) {
|
|
1181
|
-
setAtomStateValueOrPromise(store, a, a.init);
|
|
1182
|
-
} else {
|
|
1183
|
-
throw new Error("no atom init");
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
return returnAtomValue(aState2);
|
|
1187
|
-
}
|
|
1188
|
-
const aState = readAtomState(store, a);
|
|
1189
|
-
try {
|
|
1190
|
-
return returnAtomValue(aState);
|
|
1191
|
-
} finally {
|
|
1192
|
-
atomState.d.set(a, aState.n);
|
|
1193
|
-
if (isPendingPromise(atomState.v)) {
|
|
1194
|
-
addPendingPromiseToDependency(atom, atomState.v, aState);
|
|
1195
|
-
}
|
|
1196
|
-
if (mountedMap.has(atom)) {
|
|
1197
|
-
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom);
|
|
1198
|
-
}
|
|
1199
|
-
if (!isSync) {
|
|
1200
|
-
mountDependenciesIfAsync();
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
let controller;
|
|
1205
|
-
let setSelf;
|
|
1206
|
-
const options = {
|
|
1207
|
-
get signal() {
|
|
1208
|
-
if (!controller) {
|
|
1209
|
-
controller = new AbortController();
|
|
1210
|
-
}
|
|
1211
|
-
return controller.signal;
|
|
1212
|
-
},
|
|
1213
|
-
get setSelf() {
|
|
1214
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1215
|
-
console.warn(
|
|
1216
|
-
"[DEPRECATED] setSelf is deprecated and will be removed in v3."
|
|
1217
|
-
);
|
|
1218
|
-
}
|
|
1219
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom)) {
|
|
1220
|
-
console.warn("setSelf function cannot be used with read-only atom");
|
|
1221
|
-
}
|
|
1222
|
-
if (!setSelf && isActuallyWritableAtom(atom)) {
|
|
1223
|
-
setSelf = (...args) => {
|
|
1224
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && isSync) {
|
|
1225
|
-
console.warn("setSelf function cannot be called in sync");
|
|
1226
|
-
}
|
|
1227
|
-
if (!isSync) {
|
|
1228
|
-
try {
|
|
1229
|
-
return writeAtomState(store, atom, ...args);
|
|
1230
|
-
} finally {
|
|
1231
|
-
recomputeInvalidatedAtoms(store);
|
|
1232
|
-
flushCallbacks(store);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
return setSelf;
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
const prevEpochNumber = atomState.n;
|
|
1241
|
-
try {
|
|
1242
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1243
|
-
storeMutationSet.delete(store);
|
|
1244
|
-
}
|
|
1245
|
-
const valueOrPromise = atomRead(store, atom, getter, options);
|
|
1246
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && storeMutationSet.has(store)) {
|
|
1247
|
-
console.warn(
|
|
1248
|
-
"Detected store mutation during atom read. This is not supported."
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
setAtomStateValueOrPromise(store, atom, valueOrPromise);
|
|
1252
|
-
if (isPromiseLike$1(valueOrPromise)) {
|
|
1253
|
-
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
|
|
1254
|
-
valueOrPromise.then(mountDependenciesIfAsync, mountDependenciesIfAsync);
|
|
1255
|
-
}
|
|
1256
|
-
(_a = storeHooks.r) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1257
|
-
return atomState;
|
|
1258
|
-
} catch (error) {
|
|
1259
|
-
delete atomState.v;
|
|
1260
|
-
atomState.e = error;
|
|
1261
|
-
++atomState.n;
|
|
1262
|
-
return atomState;
|
|
1263
|
-
} finally {
|
|
1264
|
-
isSync = false;
|
|
1265
|
-
if (prevEpochNumber !== atomState.n && invalidatedAtoms.get(atom) === prevEpochNumber) {
|
|
1266
|
-
invalidatedAtoms.set(atom, atomState.n);
|
|
1267
|
-
changedAtoms.add(atom);
|
|
1268
|
-
(_b = storeHooks.c) == null ? void 0 : _b.call(storeHooks, atom);
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
const BUILDING_BLOCK_invalidateDependents = (store, atom) => {
|
|
1273
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1274
|
-
const mountedMap = buildingBlocks[1];
|
|
1275
|
-
const invalidatedAtoms = buildingBlocks[2];
|
|
1276
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1277
|
-
const stack = [atom];
|
|
1278
|
-
while (stack.length) {
|
|
1279
|
-
const a = stack.pop();
|
|
1280
|
-
const aState = ensureAtomState(store, a);
|
|
1281
|
-
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
1282
|
-
const dState = ensureAtomState(store, d);
|
|
1283
|
-
invalidatedAtoms.set(d, dState.n);
|
|
1284
|
-
stack.push(d);
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
};
|
|
1288
|
-
const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
|
|
1289
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1290
|
-
const changedAtoms = buildingBlocks[3];
|
|
1291
|
-
const storeHooks = buildingBlocks[6];
|
|
1292
|
-
const atomWrite = buildingBlocks[8];
|
|
1293
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1294
|
-
const flushCallbacks = buildingBlocks[12];
|
|
1295
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1296
|
-
const readAtomState = buildingBlocks[14];
|
|
1297
|
-
const invalidateDependents = buildingBlocks[15];
|
|
1298
|
-
const writeAtomState = buildingBlocks[16];
|
|
1299
|
-
const mountDependencies = buildingBlocks[17];
|
|
1300
|
-
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
1301
|
-
let isSync = true;
|
|
1302
|
-
const getter = (a) => returnAtomValue(readAtomState(store, a));
|
|
1303
|
-
const setter = (a, ...args2) => {
|
|
1304
|
-
var _a;
|
|
1305
|
-
const aState = ensureAtomState(store, a);
|
|
1306
|
-
try {
|
|
1307
|
-
if (a === atom) {
|
|
1308
|
-
if (!hasInitialValue(a)) {
|
|
1309
|
-
throw new Error("atom not writable");
|
|
1310
|
-
}
|
|
1311
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1312
|
-
storeMutationSet.add(store);
|
|
1313
|
-
}
|
|
1314
|
-
const prevEpochNumber = aState.n;
|
|
1315
|
-
const v = args2[0];
|
|
1316
|
-
setAtomStateValueOrPromise(store, a, v);
|
|
1317
|
-
mountDependencies(store, a);
|
|
1318
|
-
if (prevEpochNumber !== aState.n) {
|
|
1319
|
-
changedAtoms.add(a);
|
|
1320
|
-
invalidateDependents(store, a);
|
|
1321
|
-
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
1322
|
-
}
|
|
1323
|
-
return void 0;
|
|
1324
|
-
} else {
|
|
1325
|
-
return writeAtomState(store, a, ...args2);
|
|
1326
|
-
}
|
|
1327
|
-
} finally {
|
|
1328
|
-
if (!isSync) {
|
|
1329
|
-
recomputeInvalidatedAtoms(store);
|
|
1330
|
-
flushCallbacks(store);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
};
|
|
1334
|
-
try {
|
|
1335
|
-
return atomWrite(store, atom, getter, setter, ...args);
|
|
1336
|
-
} finally {
|
|
1337
|
-
isSync = false;
|
|
1338
|
-
}
|
|
1339
|
-
};
|
|
1340
|
-
const BUILDING_BLOCK_mountDependencies = (store, atom) => {
|
|
1341
|
-
var _a;
|
|
1342
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1343
|
-
const mountedMap = buildingBlocks[1];
|
|
1344
|
-
const changedAtoms = buildingBlocks[3];
|
|
1345
|
-
const storeHooks = buildingBlocks[6];
|
|
1346
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1347
|
-
const invalidateDependents = buildingBlocks[15];
|
|
1348
|
-
const mountAtom = buildingBlocks[18];
|
|
1349
|
-
const unmountAtom = buildingBlocks[19];
|
|
1350
|
-
const atomState = ensureAtomState(store, atom);
|
|
1351
|
-
const mounted = mountedMap.get(atom);
|
|
1352
|
-
if (mounted && !isPendingPromise(atomState.v)) {
|
|
1353
|
-
for (const [a, n] of atomState.d) {
|
|
1354
|
-
if (!mounted.d.has(a)) {
|
|
1355
|
-
const aState = ensureAtomState(store, a);
|
|
1356
|
-
const aMounted = mountAtom(store, a);
|
|
1357
|
-
aMounted.t.add(atom);
|
|
1358
|
-
mounted.d.add(a);
|
|
1359
|
-
if (n !== aState.n) {
|
|
1360
|
-
changedAtoms.add(a);
|
|
1361
|
-
invalidateDependents(store, a);
|
|
1362
|
-
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
1363
|
-
}
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
for (const a of mounted.d) {
|
|
1367
|
-
if (!atomState.d.has(a)) {
|
|
1368
|
-
mounted.d.delete(a);
|
|
1369
|
-
const aMounted = unmountAtom(store, a);
|
|
1370
|
-
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
const BUILDING_BLOCK_mountAtom = (store, atom) => {
|
|
1376
|
-
var _a;
|
|
1377
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1378
|
-
const mountedMap = buildingBlocks[1];
|
|
1379
|
-
const mountCallbacks = buildingBlocks[4];
|
|
1380
|
-
const storeHooks = buildingBlocks[6];
|
|
1381
|
-
const atomOnMount = buildingBlocks[10];
|
|
1382
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1383
|
-
const flushCallbacks = buildingBlocks[12];
|
|
1384
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1385
|
-
const readAtomState = buildingBlocks[14];
|
|
1386
|
-
const writeAtomState = buildingBlocks[16];
|
|
1387
|
-
const mountAtom = buildingBlocks[18];
|
|
1388
|
-
const atomState = ensureAtomState(store, atom);
|
|
1389
|
-
let mounted = mountedMap.get(atom);
|
|
1390
|
-
if (!mounted) {
|
|
1391
|
-
readAtomState(store, atom);
|
|
1392
|
-
for (const a of atomState.d.keys()) {
|
|
1393
|
-
const aMounted = mountAtom(store, a);
|
|
1394
|
-
aMounted.t.add(atom);
|
|
1395
|
-
}
|
|
1396
|
-
mounted = {
|
|
1397
|
-
l: /* @__PURE__ */ new Set(),
|
|
1398
|
-
d: new Set(atomState.d.keys()),
|
|
1399
|
-
t: /* @__PURE__ */ new Set()
|
|
1400
|
-
};
|
|
1401
|
-
mountedMap.set(atom, mounted);
|
|
1402
|
-
if (isActuallyWritableAtom(atom)) {
|
|
1403
|
-
const processOnMount = () => {
|
|
1404
|
-
let isSync = true;
|
|
1405
|
-
const setAtom = (...args) => {
|
|
1406
|
-
try {
|
|
1407
|
-
return writeAtomState(store, atom, ...args);
|
|
1408
|
-
} finally {
|
|
1409
|
-
if (!isSync) {
|
|
1410
|
-
recomputeInvalidatedAtoms(store);
|
|
1411
|
-
flushCallbacks(store);
|
|
1412
|
-
}
|
|
1413
|
-
}
|
|
1414
|
-
};
|
|
1415
|
-
try {
|
|
1416
|
-
const onUnmount = atomOnMount(store, atom, setAtom);
|
|
1417
|
-
if (onUnmount) {
|
|
1418
|
-
mounted.u = () => {
|
|
1419
|
-
isSync = true;
|
|
1420
|
-
try {
|
|
1421
|
-
onUnmount();
|
|
1422
|
-
} finally {
|
|
1423
|
-
isSync = false;
|
|
1424
|
-
}
|
|
1425
|
-
};
|
|
1426
|
-
}
|
|
1427
|
-
} finally {
|
|
1428
|
-
isSync = false;
|
|
1429
|
-
}
|
|
1430
|
-
};
|
|
1431
|
-
mountCallbacks.add(processOnMount);
|
|
1432
|
-
}
|
|
1433
|
-
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1434
|
-
}
|
|
1435
|
-
return mounted;
|
|
1436
|
-
};
|
|
1437
|
-
const BUILDING_BLOCK_unmountAtom = (store, atom) => {
|
|
1438
|
-
var _a, _b;
|
|
1439
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1440
|
-
const mountedMap = buildingBlocks[1];
|
|
1441
|
-
const unmountCallbacks = buildingBlocks[5];
|
|
1442
|
-
const storeHooks = buildingBlocks[6];
|
|
1443
|
-
const ensureAtomState = buildingBlocks[11];
|
|
1444
|
-
const unmountAtom = buildingBlocks[19];
|
|
1445
|
-
const atomState = ensureAtomState(store, atom);
|
|
1446
|
-
let mounted = mountedMap.get(atom);
|
|
1447
|
-
if (!mounted || mounted.l.size) {
|
|
1448
|
-
return mounted;
|
|
1449
|
-
}
|
|
1450
|
-
let isDependent = false;
|
|
1451
|
-
for (const a of mounted.t) {
|
|
1452
|
-
if ((_a = mountedMap.get(a)) == null ? void 0 : _a.d.has(atom)) {
|
|
1453
|
-
isDependent = true;
|
|
1454
|
-
break;
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
if (!isDependent) {
|
|
1458
|
-
if (mounted.u) {
|
|
1459
|
-
unmountCallbacks.add(mounted.u);
|
|
1460
|
-
}
|
|
1461
|
-
mounted = void 0;
|
|
1462
|
-
mountedMap.delete(atom);
|
|
1463
|
-
for (const a of atomState.d.keys()) {
|
|
1464
|
-
const aMounted = unmountAtom(store, a);
|
|
1465
|
-
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
1466
|
-
}
|
|
1467
|
-
(_b = storeHooks.u) == null ? void 0 : _b.call(storeHooks, atom);
|
|
1468
|
-
return void 0;
|
|
1469
|
-
}
|
|
1470
|
-
return mounted;
|
|
1471
|
-
};
|
|
1472
|
-
const BUILDING_BLOCK_setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
|
|
1473
|
-
const ensureAtomState = getInternalBuildingBlocks(store)[11];
|
|
1474
|
-
const atomState = ensureAtomState(store, atom);
|
|
1475
|
-
const hasPrevValue = "v" in atomState;
|
|
1476
|
-
const prevValue = atomState.v;
|
|
1477
|
-
if (isPromiseLike$1(valueOrPromise)) {
|
|
1478
|
-
for (const a of atomState.d.keys()) {
|
|
1479
|
-
addPendingPromiseToDependency(
|
|
1480
|
-
atom,
|
|
1481
|
-
valueOrPromise,
|
|
1482
|
-
ensureAtomState(store, a)
|
|
1483
|
-
);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
atomState.v = valueOrPromise;
|
|
1487
|
-
delete atomState.e;
|
|
1488
|
-
if (!hasPrevValue || !Object.is(prevValue, atomState.v)) {
|
|
1489
|
-
++atomState.n;
|
|
1490
|
-
if (isPromiseLike$1(prevValue)) {
|
|
1491
|
-
abortPromise(prevValue);
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
};
|
|
1495
|
-
const BUILDING_BLOCK_storeGet = (store, atom) => {
|
|
1496
|
-
const readAtomState = getInternalBuildingBlocks(store)[14];
|
|
1497
|
-
return returnAtomValue(readAtomState(store, atom));
|
|
1498
|
-
};
|
|
1499
|
-
const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
|
|
1500
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1501
|
-
const flushCallbacks = buildingBlocks[12];
|
|
1502
|
-
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1503
|
-
const writeAtomState = buildingBlocks[16];
|
|
1504
|
-
try {
|
|
1505
|
-
return writeAtomState(store, atom, ...args);
|
|
1506
|
-
} finally {
|
|
1507
|
-
recomputeInvalidatedAtoms(store);
|
|
1508
|
-
flushCallbacks(store);
|
|
1509
|
-
}
|
|
1510
|
-
};
|
|
1511
|
-
const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
|
|
1512
|
-
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1513
|
-
const flushCallbacks = buildingBlocks[12];
|
|
1514
|
-
const mountAtom = buildingBlocks[18];
|
|
1515
|
-
const unmountAtom = buildingBlocks[19];
|
|
1516
|
-
const mounted = mountAtom(store, atom);
|
|
1517
|
-
const listeners = mounted.l;
|
|
1518
|
-
listeners.add(listener);
|
|
1519
|
-
flushCallbacks(store);
|
|
1520
|
-
return () => {
|
|
1521
|
-
listeners.delete(listener);
|
|
1522
|
-
unmountAtom(store, atom);
|
|
1523
|
-
flushCallbacks(store);
|
|
1524
|
-
};
|
|
1525
|
-
};
|
|
1526
|
-
const buildingBlockMap = /* @__PURE__ */ new WeakMap();
|
|
1527
|
-
const getInternalBuildingBlocks = (store) => {
|
|
1528
|
-
const buildingBlocks = buildingBlockMap.get(store);
|
|
1529
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && !buildingBlocks) {
|
|
1530
|
-
throw new Error(
|
|
1531
|
-
"Store must be created by buildStore to read its building blocks"
|
|
1532
|
-
);
|
|
1533
|
-
}
|
|
1534
|
-
return buildingBlocks;
|
|
1535
|
-
};
|
|
1536
|
-
function buildStore(...buildArgs) {
|
|
1537
|
-
const store = {
|
|
1538
|
-
get(atom) {
|
|
1539
|
-
const storeGet = getInternalBuildingBlocks(store)[21];
|
|
1540
|
-
return storeGet(store, atom);
|
|
1541
|
-
},
|
|
1542
|
-
set(atom, ...args) {
|
|
1543
|
-
const storeSet = getInternalBuildingBlocks(store)[22];
|
|
1544
|
-
return storeSet(store, atom, ...args);
|
|
1545
|
-
},
|
|
1546
|
-
sub(atom, listener) {
|
|
1547
|
-
const storeSub = getInternalBuildingBlocks(store)[23];
|
|
1548
|
-
return storeSub(store, atom, listener);
|
|
1549
|
-
}
|
|
1550
|
-
};
|
|
1551
|
-
const buildingBlocks = [
|
|
1552
|
-
// store state
|
|
1553
|
-
/* @__PURE__ */ new WeakMap(),
|
|
1554
|
-
// atomStateMap
|
|
1555
|
-
/* @__PURE__ */ new WeakMap(),
|
|
1556
|
-
// mountedMap
|
|
1557
|
-
/* @__PURE__ */ new WeakMap(),
|
|
1558
|
-
// invalidatedAtoms
|
|
1559
|
-
/* @__PURE__ */ new Set(),
|
|
1560
|
-
// changedAtoms
|
|
1561
|
-
/* @__PURE__ */ new Set(),
|
|
1562
|
-
// mountCallbacks
|
|
1563
|
-
/* @__PURE__ */ new Set(),
|
|
1564
|
-
// unmountCallbacks
|
|
1565
|
-
{},
|
|
1566
|
-
// storeHooks
|
|
1567
|
-
// atom interceptors
|
|
1568
|
-
BUILDING_BLOCK_atomRead,
|
|
1569
|
-
BUILDING_BLOCK_atomWrite,
|
|
1570
|
-
BUILDING_BLOCK_atomOnInit,
|
|
1571
|
-
BUILDING_BLOCK_atomOnMount,
|
|
1572
|
-
// building-block functions
|
|
1573
|
-
BUILDING_BLOCK_ensureAtomState,
|
|
1574
|
-
BUILDING_BLOCK_flushCallbacks,
|
|
1575
|
-
BUILDING_BLOCK_recomputeInvalidatedAtoms,
|
|
1576
|
-
BUILDING_BLOCK_readAtomState,
|
|
1577
|
-
BUILDING_BLOCK_invalidateDependents,
|
|
1578
|
-
BUILDING_BLOCK_writeAtomState,
|
|
1579
|
-
BUILDING_BLOCK_mountDependencies,
|
|
1580
|
-
BUILDING_BLOCK_mountAtom,
|
|
1581
|
-
BUILDING_BLOCK_unmountAtom,
|
|
1582
|
-
BUILDING_BLOCK_setAtomStateValueOrPromise,
|
|
1583
|
-
BUILDING_BLOCK_storeGet,
|
|
1584
|
-
BUILDING_BLOCK_storeSet,
|
|
1585
|
-
BUILDING_BLOCK_storeSub,
|
|
1586
|
-
void 0
|
|
1587
|
-
].map((fn, i) => buildArgs[i] || fn);
|
|
1588
|
-
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
|
|
1589
|
-
return store;
|
|
1590
|
-
}let keyCount = 0;
|
|
1591
|
-
function atom(read, write) {
|
|
1592
|
-
const key = `atom${++keyCount}`;
|
|
1593
|
-
const config = {
|
|
1594
|
-
toString() {
|
|
1595
|
-
return (undefined ? undefined.MODE : void 0) !== "production" && this.debugLabel ? key + ":" + this.debugLabel : key;
|
|
1596
|
-
}
|
|
1597
|
-
};
|
|
1598
|
-
if (typeof read === "function") {
|
|
1599
|
-
config.read = read;
|
|
1600
|
-
} else {
|
|
1601
|
-
config.init = read;
|
|
1602
|
-
config.read = defaultRead;
|
|
1603
|
-
config.write = defaultWrite;
|
|
1604
|
-
}
|
|
1605
|
-
if (write) {
|
|
1606
|
-
config.write = write;
|
|
1607
|
-
}
|
|
1608
|
-
return config;
|
|
1609
|
-
}
|
|
1610
|
-
function defaultRead(get) {
|
|
1611
|
-
return get(this);
|
|
1612
|
-
}
|
|
1613
|
-
function defaultWrite(get, set, arg) {
|
|
1614
|
-
return set(
|
|
1615
|
-
this,
|
|
1616
|
-
typeof arg === "function" ? arg(get(this)) : arg
|
|
1617
|
-
);
|
|
1618
|
-
}
|
|
1619
|
-
function createStore() {
|
|
1620
|
-
return buildStore();
|
|
1621
|
-
}
|
|
1622
|
-
let defaultStore;
|
|
1623
|
-
function getDefaultStore() {
|
|
1624
|
-
if (!defaultStore) {
|
|
1625
|
-
defaultStore = createStore();
|
|
1626
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1627
|
-
globalThis.__JOTAI_DEFAULT_STORE__ || (globalThis.__JOTAI_DEFAULT_STORE__ = defaultStore);
|
|
1628
|
-
if (globalThis.__JOTAI_DEFAULT_STORE__ !== defaultStore) {
|
|
1629
|
-
console.warn(
|
|
1630
|
-
"Detected multiple Jotai instances. It may cause unexpected behavior with the default store. https://github.com/pmndrs/jotai/discussions/2044"
|
|
1631
|
-
);
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
return defaultStore;
|
|
1636
|
-
}const StoreContext = React.createContext(
|
|
1637
|
-
void 0
|
|
1638
|
-
);
|
|
1639
|
-
function useStore(options) {
|
|
1640
|
-
const store = React.useContext(StoreContext);
|
|
1641
|
-
return store || getDefaultStore();
|
|
1642
|
-
}
|
|
1643
|
-
|
|
1644
|
-
const isPromiseLike = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
1645
|
-
const attachPromiseStatus = (promise) => {
|
|
1646
|
-
if (!promise.status) {
|
|
1647
|
-
promise.status = "pending";
|
|
1648
|
-
promise.then(
|
|
1649
|
-
(v) => {
|
|
1650
|
-
promise.status = "fulfilled";
|
|
1651
|
-
promise.value = v;
|
|
1652
|
-
},
|
|
1653
|
-
(e) => {
|
|
1654
|
-
promise.status = "rejected";
|
|
1655
|
-
promise.reason = e;
|
|
1656
|
-
}
|
|
1657
|
-
);
|
|
1658
|
-
}
|
|
1659
|
-
};
|
|
1660
|
-
const use = React.use || // A shim for older React versions
|
|
1661
|
-
((promise) => {
|
|
1662
|
-
if (promise.status === "pending") {
|
|
1663
|
-
throw promise;
|
|
1664
|
-
} else if (promise.status === "fulfilled") {
|
|
1665
|
-
return promise.value;
|
|
1666
|
-
} else if (promise.status === "rejected") {
|
|
1667
|
-
throw promise.reason;
|
|
1668
|
-
} else {
|
|
1669
|
-
attachPromiseStatus(promise);
|
|
1670
|
-
throw promise;
|
|
1671
|
-
}
|
|
1672
|
-
});
|
|
1673
|
-
const continuablePromiseMap = /* @__PURE__ */ new WeakMap();
|
|
1674
|
-
const createContinuablePromise = (promise, getValue) => {
|
|
1675
|
-
let continuablePromise = continuablePromiseMap.get(promise);
|
|
1676
|
-
if (!continuablePromise) {
|
|
1677
|
-
continuablePromise = new Promise((resolve, reject) => {
|
|
1678
|
-
let curr = promise;
|
|
1679
|
-
const onFulfilled = (me) => (v) => {
|
|
1680
|
-
if (curr === me) {
|
|
1681
|
-
resolve(v);
|
|
1682
|
-
}
|
|
1683
|
-
};
|
|
1684
|
-
const onRejected = (me) => (e) => {
|
|
1685
|
-
if (curr === me) {
|
|
1686
|
-
reject(e);
|
|
1687
|
-
}
|
|
1688
|
-
};
|
|
1689
|
-
const onAbort = () => {
|
|
1690
|
-
try {
|
|
1691
|
-
const nextValue = getValue();
|
|
1692
|
-
if (isPromiseLike(nextValue)) {
|
|
1693
|
-
continuablePromiseMap.set(nextValue, continuablePromise);
|
|
1694
|
-
curr = nextValue;
|
|
1695
|
-
nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
|
|
1696
|
-
registerAbortHandler(nextValue, onAbort);
|
|
1697
|
-
} else {
|
|
1698
|
-
resolve(nextValue);
|
|
1699
|
-
}
|
|
1700
|
-
} catch (e) {
|
|
1701
|
-
reject(e);
|
|
1702
|
-
}
|
|
1703
|
-
};
|
|
1704
|
-
promise.then(onFulfilled(promise), onRejected(promise));
|
|
1705
|
-
registerAbortHandler(promise, onAbort);
|
|
1706
|
-
});
|
|
1707
|
-
continuablePromiseMap.set(promise, continuablePromise);
|
|
1708
|
-
}
|
|
1709
|
-
return continuablePromise;
|
|
1710
|
-
};
|
|
1711
|
-
function useAtomValue(atom, options) {
|
|
1712
|
-
const { delay, unstable_promiseStatus: promiseStatus = !React.use } = {};
|
|
1713
|
-
const store = useStore();
|
|
1714
|
-
const [[valueFromReducer, storeFromReducer, atomFromReducer], rerender] = React.useReducer(
|
|
1715
|
-
(prev) => {
|
|
1716
|
-
const nextValue = store.get(atom);
|
|
1717
|
-
if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
|
|
1718
|
-
return prev;
|
|
1719
|
-
}
|
|
1720
|
-
return [nextValue, store, atom];
|
|
1721
|
-
},
|
|
1722
|
-
void 0,
|
|
1723
|
-
() => [store.get(atom), store, atom]
|
|
1724
|
-
);
|
|
1725
|
-
let value = valueFromReducer;
|
|
1726
|
-
if (storeFromReducer !== store || atomFromReducer !== atom) {
|
|
1727
|
-
rerender();
|
|
1728
|
-
value = store.get(atom);
|
|
1729
|
-
}
|
|
1730
|
-
React.useEffect(() => {
|
|
1731
|
-
const unsub = store.sub(atom, () => {
|
|
1732
|
-
if (promiseStatus) {
|
|
1733
|
-
try {
|
|
1734
|
-
const value2 = store.get(atom);
|
|
1735
|
-
if (isPromiseLike(value2)) {
|
|
1736
|
-
attachPromiseStatus(
|
|
1737
|
-
createContinuablePromise(value2, () => store.get(atom))
|
|
1738
|
-
);
|
|
1739
|
-
}
|
|
1740
|
-
} catch (e) {
|
|
1741
|
-
}
|
|
1742
|
-
}
|
|
1743
|
-
if (typeof delay === "number") {
|
|
1744
|
-
setTimeout(rerender, delay);
|
|
1745
|
-
return;
|
|
1746
|
-
}
|
|
1747
|
-
rerender();
|
|
1748
|
-
});
|
|
1749
|
-
rerender();
|
|
1750
|
-
return unsub;
|
|
1751
|
-
}, [store, atom, delay, promiseStatus]);
|
|
1752
|
-
React.useDebugValue(value);
|
|
1753
|
-
if (isPromiseLike(value)) {
|
|
1754
|
-
const promise = createContinuablePromise(value, () => store.get(atom));
|
|
1755
|
-
if (promiseStatus) {
|
|
1756
|
-
attachPromiseStatus(promise);
|
|
1757
|
-
}
|
|
1758
|
-
return use(promise);
|
|
1759
|
-
}
|
|
1760
|
-
return value;
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
function useSetAtom(atom, options) {
|
|
1764
|
-
const store = useStore();
|
|
1765
|
-
const setAtom = React.useCallback(
|
|
1766
|
-
(...args) => {
|
|
1767
|
-
if ((undefined ? undefined.MODE : void 0) !== "production" && !("write" in atom)) {
|
|
1768
|
-
throw new Error("not writable atom");
|
|
1769
|
-
}
|
|
1770
|
-
return store.set(atom, ...args);
|
|
1771
|
-
},
|
|
1772
|
-
[store, atom]
|
|
1773
|
-
);
|
|
1774
|
-
return setAtom;
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
function useAtom(atom, options) {
|
|
1778
|
-
return [
|
|
1779
|
-
useAtomValue(atom),
|
|
1780
|
-
// We do wrong type assertion here, which results in throwing an error.
|
|
1781
|
-
useSetAtom(atom)
|
|
1782
|
-
];
|
|
1783
|
-
}const RESET = /* @__PURE__ */ Symbol(
|
|
1784
|
-
(undefined ? undefined.MODE : void 0) !== "production" ? "RESET" : ""
|
|
1785
|
-
);
|
|
1786
|
-
|
|
1787
|
-
const isPromiseLike$2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
1788
|
-
function createJSONStorage(getStringStorage = () => {
|
|
1789
|
-
try {
|
|
1790
|
-
return window.localStorage;
|
|
1791
|
-
} catch (e) {
|
|
1792
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1793
|
-
if (typeof window !== "undefined") {
|
|
1794
|
-
console.warn(e);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
return void 0;
|
|
1798
|
-
}
|
|
1799
|
-
}, options) {
|
|
1800
|
-
var _a;
|
|
1801
|
-
let lastStr;
|
|
1802
|
-
let lastValue;
|
|
1803
|
-
const storage = {
|
|
1804
|
-
getItem: (key, initialValue) => {
|
|
1805
|
-
var _a2, _b;
|
|
1806
|
-
const parse = (str2) => {
|
|
1807
|
-
str2 = str2 || "";
|
|
1808
|
-
if (lastStr !== str2) {
|
|
1809
|
-
try {
|
|
1810
|
-
lastValue = JSON.parse(str2, void 0 );
|
|
1811
|
-
} catch (e) {
|
|
1812
|
-
return initialValue;
|
|
1813
|
-
}
|
|
1814
|
-
lastStr = str2;
|
|
1815
|
-
}
|
|
1816
|
-
return lastValue;
|
|
1817
|
-
};
|
|
1818
|
-
const str = (_b = (_a2 = getStringStorage()) == null ? void 0 : _a2.getItem(key)) != null ? _b : null;
|
|
1819
|
-
if (isPromiseLike$2(str)) {
|
|
1820
|
-
return str.then(parse);
|
|
1821
|
-
}
|
|
1822
|
-
return parse(str);
|
|
1823
|
-
},
|
|
1824
|
-
setItem: (key, newValue) => {
|
|
1825
|
-
var _a2;
|
|
1826
|
-
return (_a2 = getStringStorage()) == null ? void 0 : _a2.setItem(
|
|
1827
|
-
key,
|
|
1828
|
-
JSON.stringify(newValue, void 0 )
|
|
1829
|
-
);
|
|
1830
|
-
},
|
|
1831
|
-
removeItem: (key) => {
|
|
1832
|
-
var _a2;
|
|
1833
|
-
return (_a2 = getStringStorage()) == null ? void 0 : _a2.removeItem(key);
|
|
1834
|
-
}
|
|
1835
|
-
};
|
|
1836
|
-
const createHandleSubscribe = (subscriber2) => (key, callback, initialValue) => subscriber2(key, (v) => {
|
|
1837
|
-
let newValue;
|
|
1838
|
-
try {
|
|
1839
|
-
newValue = JSON.parse(v || "");
|
|
1840
|
-
} catch (e) {
|
|
1841
|
-
newValue = initialValue;
|
|
1842
|
-
}
|
|
1843
|
-
callback(newValue);
|
|
1844
|
-
});
|
|
1845
|
-
let subscriber;
|
|
1846
|
-
try {
|
|
1847
|
-
subscriber = (_a = getStringStorage()) == null ? void 0 : _a.subscribe;
|
|
1848
|
-
} catch (e) {
|
|
1849
|
-
}
|
|
1850
|
-
if (!subscriber && typeof window !== "undefined" && typeof window.addEventListener === "function" && window.Storage) {
|
|
1851
|
-
subscriber = (key, callback) => {
|
|
1852
|
-
if (!(getStringStorage() instanceof window.Storage)) {
|
|
1853
|
-
return () => {
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
const storageEventCallback = (e) => {
|
|
1857
|
-
if (e.storageArea === getStringStorage() && e.key === key) {
|
|
1858
|
-
callback(e.newValue);
|
|
1859
|
-
}
|
|
1860
|
-
};
|
|
1861
|
-
window.addEventListener("storage", storageEventCallback);
|
|
1862
|
-
return () => {
|
|
1863
|
-
window.removeEventListener("storage", storageEventCallback);
|
|
1864
|
-
};
|
|
1865
|
-
};
|
|
1866
|
-
}
|
|
1867
|
-
if (subscriber) {
|
|
1868
|
-
storage.subscribe = createHandleSubscribe(subscriber);
|
|
1869
|
-
}
|
|
1870
|
-
return storage;
|
|
1871
|
-
}
|
|
1872
|
-
const defaultStorage = createJSONStorage();
|
|
1873
|
-
function atomWithStorage(key, initialValue, storage = defaultStorage, options) {
|
|
1874
|
-
const baseAtom = atom(
|
|
1875
|
-
initialValue
|
|
1876
|
-
);
|
|
1877
|
-
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1878
|
-
baseAtom.debugPrivate = true;
|
|
1879
|
-
}
|
|
1880
|
-
baseAtom.onMount = (setAtom) => {
|
|
1881
|
-
setAtom(storage.getItem(key, initialValue));
|
|
1882
|
-
let unsub;
|
|
1883
|
-
if (storage.subscribe) {
|
|
1884
|
-
unsub = storage.subscribe(key, setAtom, initialValue);
|
|
1885
|
-
}
|
|
1886
|
-
return unsub;
|
|
1887
|
-
};
|
|
1888
|
-
const anAtom = atom(
|
|
1889
|
-
(get) => get(baseAtom),
|
|
1890
|
-
(get, set, update) => {
|
|
1891
|
-
const nextValue = typeof update === "function" ? update(get(baseAtom)) : update;
|
|
1892
|
-
if (nextValue === RESET) {
|
|
1893
|
-
set(baseAtom, initialValue);
|
|
1894
|
-
return storage.removeItem(key);
|
|
1895
|
-
}
|
|
1896
|
-
if (isPromiseLike$2(nextValue)) {
|
|
1897
|
-
return nextValue.then((resolvedValue) => {
|
|
1898
|
-
set(baseAtom, resolvedValue);
|
|
1899
|
-
return storage.setItem(key, resolvedValue);
|
|
1900
|
-
});
|
|
1901
|
-
}
|
|
1902
|
-
set(baseAtom, nextValue);
|
|
1903
|
-
return storage.setItem(key, nextValue);
|
|
1904
|
-
}
|
|
1905
|
-
);
|
|
1906
|
-
return anAtom;
|
|
1907
|
-
}// Implementazione
|
|
134
|
+
};// Implementazione
|
|
1908
135
|
function atomStateGenerator({
|
|
1909
136
|
key,
|
|
1910
137
|
defaultValue,
|
|
@@ -1913,14 +140,14 @@ function atomStateGenerator({
|
|
|
1913
140
|
}) {
|
|
1914
141
|
const resolvedStorage = customStorage || exports.storage;
|
|
1915
142
|
// Usa atomWithStorage solo se persist è true, altrimenti atom normale
|
|
1916
|
-
const jotaiAtom = persist ? atomWithStorage(key, defaultValue, createJSONStorage(() => resolvedStorage)) : atom(defaultValue);
|
|
143
|
+
const jotaiAtom = persist ? utils.atomWithStorage(key, defaultValue, utils.createJSONStorage(() => resolvedStorage)) : jotai.atom(defaultValue);
|
|
1917
144
|
const useValue = () => {
|
|
1918
|
-
const [value] = useAtom(jotaiAtom);
|
|
145
|
+
const [value] = jotai.useAtom(jotaiAtom);
|
|
1919
146
|
return value;
|
|
1920
147
|
};
|
|
1921
148
|
const useState = () => {
|
|
1922
149
|
const $ = compilerRuntime.c(3);
|
|
1923
|
-
const [value, setValue] = useAtom(jotaiAtom);
|
|
150
|
+
const [value, setValue] = jotai.useAtom(jotaiAtom);
|
|
1924
151
|
let t0;
|
|
1925
152
|
if ($[0] !== setValue || $[1] !== value) {
|
|
1926
153
|
t0 = [value, setValue];
|
|
@@ -1934,7 +161,7 @@ function atomStateGenerator({
|
|
|
1934
161
|
};
|
|
1935
162
|
const useReset = () => {
|
|
1936
163
|
const $ = compilerRuntime.c(2);
|
|
1937
|
-
const [, setValue] = useAtom(jotaiAtom);
|
|
164
|
+
const [, setValue] = jotai.useAtom(jotaiAtom);
|
|
1938
165
|
let t0;
|
|
1939
166
|
if ($[0] !== setValue) {
|
|
1940
167
|
t0 = () => {
|