yann-core 0.0.1 → 1.1.0

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/index.js CHANGED
@@ -1,565 +1,6 @@
1
- import { ref as Ee, toValue as Ie } from "vue";
2
- var be = typeof global == "object" && global && global.Object === Object && global, Ce = typeof self == "object" && self && self.Object === Object && self, T = be || Ce || Function("return this")(), P = T.Symbol, ve = Object.prototype, Le = ve.hasOwnProperty, Me = ve.toString, x = P ? P.toStringTag : void 0;
3
- function Re(e) {
4
- var t = Le.call(e, x), r = e[x];
5
- try {
6
- e[x] = void 0;
7
- var n = !0;
8
- } catch {
9
- }
10
- var i = Me.call(e);
11
- return n && (t ? e[x] = r : delete e[x]), i;
12
- }
13
- var De = Object.prototype, Fe = De.toString;
14
- function Ge(e) {
15
- return Fe.call(e);
16
- }
17
- var Ne = "[object Null]", Ue = "[object Undefined]", V = P ? P.toStringTag : void 0;
18
- function M(e) {
19
- return e == null ? e === void 0 ? Ue : Ne : V && V in Object(e) ? Re(e) : Ge(e);
20
- }
21
- function I(e) {
22
- return e != null && typeof e == "object";
23
- }
24
- var G = Array.isArray;
25
- function Te(e) {
26
- var t = typeof e;
27
- return e != null && (t == "object" || t == "function");
28
- }
29
- var ze = "[object AsyncFunction]", Be = "[object Function]", He = "[object GeneratorFunction]", Ke = "[object Proxy]";
30
- function Ae(e) {
31
- if (!Te(e))
32
- return !1;
33
- var t = M(e);
34
- return t == Be || t == He || t == ze || t == Ke;
35
- }
36
- var B = T["__core-js_shared__"], k = function() {
37
- var e = /[^.]+$/.exec(B && B.keys && B.keys.IE_PROTO || "");
38
- return e ? "Symbol(src)_1." + e : "";
39
- }();
40
- function qe(e) {
41
- return !!k && k in e;
42
- }
43
- var We = Function.prototype, Xe = We.toString;
44
- function $(e) {
45
- if (e != null) {
46
- try {
47
- return Xe.call(e);
48
- } catch {
49
- }
50
- try {
51
- return e + "";
52
- } catch {
53
- }
54
- }
55
- return "";
56
- }
57
- var Je = /[\\^$.*+?()[\]{}|]/g, Ye = /^\[object .+?Constructor\]$/, Ze = Function.prototype, Qe = Object.prototype, Ve = Ze.toString, ke = Qe.hasOwnProperty, et = RegExp(
58
- "^" + Ve.call(ke).replace(Je, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
59
- );
60
- function tt(e) {
61
- if (!Te(e) || qe(e))
62
- return !1;
63
- var t = Ae(e) ? et : Ye;
64
- return t.test($(e));
65
- }
66
- function rt(e, t) {
67
- return e == null ? void 0 : e[t];
68
- }
69
- function S(e, t) {
70
- var r = rt(e, t);
71
- return tt(r) ? r : void 0;
72
- }
73
- var W = S(T, "WeakMap"), nt = 9007199254740991, at = /^(?:0|[1-9]\d*)$/;
74
- function it(e, t) {
75
- var r = typeof e;
76
- return t = t ?? nt, !!t && (r == "number" || r != "symbol" && at.test(e)) && e > -1 && e % 1 == 0 && e < t;
77
- }
78
- function me(e, t) {
79
- return e === t || e !== e && t !== t;
80
- }
81
- var ot = 9007199254740991;
82
- function we(e) {
83
- return typeof e == "number" && e > -1 && e % 1 == 0 && e <= ot;
84
- }
85
- function st(e) {
86
- return e != null && we(e.length) && !Ae(e);
87
- }
88
- var ut = Object.prototype;
89
- function ft(e) {
90
- var t = e && e.constructor, r = typeof t == "function" && t.prototype || ut;
91
- return e === r;
92
- }
93
- function ct(e, t) {
94
- for (var r = -1, n = Array(e); ++r < e; )
95
- n[r] = t(r);
96
- return n;
97
- }
98
- var lt = "[object Arguments]";
99
- function ee(e) {
100
- return I(e) && M(e) == lt;
101
- }
102
- var Oe = Object.prototype, pt = Oe.hasOwnProperty, dt = Oe.propertyIsEnumerable, gt = ee(/* @__PURE__ */ function() {
103
- return arguments;
104
- }()) ? ee : function(e) {
105
- return I(e) && pt.call(e, "callee") && !dt.call(e, "callee");
106
- };
107
- function _t() {
108
- return !1;
109
- }
110
- var $e = typeof exports == "object" && exports && !exports.nodeType && exports, te = $e && typeof module == "object" && module && !module.nodeType && module, ht = te && te.exports === $e, re = ht ? T.Buffer : void 0, yt = re ? re.isBuffer : void 0, X = yt || _t, bt = "[object Arguments]", vt = "[object Array]", Tt = "[object Boolean]", At = "[object Date]", mt = "[object Error]", wt = "[object Function]", Ot = "[object Map]", $t = "[object Number]", jt = "[object Object]", Pt = "[object RegExp]", St = "[object Set]", xt = "[object String]", Et = "[object WeakMap]", It = "[object ArrayBuffer]", Ct = "[object DataView]", Lt = "[object Float32Array]", Mt = "[object Float64Array]", Rt = "[object Int8Array]", Dt = "[object Int16Array]", Ft = "[object Int32Array]", Gt = "[object Uint8Array]", Nt = "[object Uint8ClampedArray]", Ut = "[object Uint16Array]", zt = "[object Uint32Array]", c = {};
111
- c[Lt] = c[Mt] = c[Rt] = c[Dt] = c[Ft] = c[Gt] = c[Nt] = c[Ut] = c[zt] = !0;
112
- c[bt] = c[vt] = c[It] = c[Tt] = c[Ct] = c[At] = c[mt] = c[wt] = c[Ot] = c[$t] = c[jt] = c[Pt] = c[St] = c[xt] = c[Et] = !1;
113
- function Bt(e) {
114
- return I(e) && we(e.length) && !!c[M(e)];
115
- }
116
- function Ht(e) {
117
- return function(t) {
118
- return e(t);
119
- };
120
- }
121
- var je = typeof exports == "object" && exports && !exports.nodeType && exports, E = je && typeof module == "object" && module && !module.nodeType && module, Kt = E && E.exports === je, H = Kt && be.process, ne = function() {
122
- try {
123
- var e = E && E.require && E.require("util").types;
124
- return e || H && H.binding && H.binding("util");
125
- } catch {
126
- }
127
- }(), ae = ne && ne.isTypedArray, Pe = ae ? Ht(ae) : Bt, qt = Object.prototype, Wt = qt.hasOwnProperty;
128
- function Xt(e, t) {
129
- var r = G(e), n = !r && gt(e), i = !r && !n && X(e), a = !r && !n && !i && Pe(e), u = r || n || i || a, o = u ? ct(e.length, String) : [], s = o.length;
130
- for (var f in e)
131
- Wt.call(e, f) && !(u && // Safari 9 has enumerable `arguments.length` in strict mode.
132
- (f == "length" || // Node.js 0.10 has enumerable non-index properties on buffers.
133
- i && (f == "offset" || f == "parent") || // PhantomJS 2 has enumerable non-index properties on typed arrays.
134
- a && (f == "buffer" || f == "byteLength" || f == "byteOffset") || // Skip index properties.
135
- it(f, s))) && o.push(f);
136
- return o;
137
- }
138
- function Jt(e, t) {
139
- return function(r) {
140
- return e(t(r));
141
- };
142
- }
143
- var Yt = Jt(Object.keys, Object), Zt = Object.prototype, Qt = Zt.hasOwnProperty;
144
- function Vt(e) {
145
- if (!ft(e))
146
- return Yt(e);
147
- var t = [];
148
- for (var r in Object(e))
149
- Qt.call(e, r) && r != "constructor" && t.push(r);
150
- return t;
151
- }
152
- function kt(e) {
153
- return st(e) ? Xt(e) : Vt(e);
154
- }
155
- var C = S(Object, "create");
156
- function er() {
157
- this.__data__ = C ? C(null) : {}, this.size = 0;
158
- }
159
- function tr(e) {
160
- var t = this.has(e) && delete this.__data__[e];
161
- return this.size -= t ? 1 : 0, t;
162
- }
163
- var rr = "__lodash_hash_undefined__", nr = Object.prototype, ar = nr.hasOwnProperty;
164
- function ir(e) {
165
- var t = this.__data__;
166
- if (C) {
167
- var r = t[e];
168
- return r === rr ? void 0 : r;
169
- }
170
- return ar.call(t, e) ? t[e] : void 0;
171
- }
172
- var or = Object.prototype, sr = or.hasOwnProperty;
173
- function ur(e) {
174
- var t = this.__data__;
175
- return C ? t[e] !== void 0 : sr.call(t, e);
176
- }
177
- var fr = "__lodash_hash_undefined__";
178
- function cr(e, t) {
179
- var r = this.__data__;
180
- return this.size += this.has(e) ? 0 : 1, r[e] = C && t === void 0 ? fr : t, this;
181
- }
182
- function O(e) {
183
- var t = -1, r = e == null ? 0 : e.length;
184
- for (this.clear(); ++t < r; ) {
185
- var n = e[t];
186
- this.set(n[0], n[1]);
187
- }
188
- }
189
- O.prototype.clear = er;
190
- O.prototype.delete = tr;
191
- O.prototype.get = ir;
192
- O.prototype.has = ur;
193
- O.prototype.set = cr;
194
- function lr() {
195
- this.__data__ = [], this.size = 0;
196
- }
197
- function U(e, t) {
198
- for (var r = e.length; r--; )
199
- if (me(e[r][0], t))
200
- return r;
201
- return -1;
202
- }
203
- var pr = Array.prototype, dr = pr.splice;
204
- function gr(e) {
205
- var t = this.__data__, r = U(t, e);
206
- if (r < 0)
207
- return !1;
208
- var n = t.length - 1;
209
- return r == n ? t.pop() : dr.call(t, r, 1), --this.size, !0;
210
- }
211
- function _r(e) {
212
- var t = this.__data__, r = U(t, e);
213
- return r < 0 ? void 0 : t[r][1];
214
- }
215
- function hr(e) {
216
- return U(this.__data__, e) > -1;
217
- }
218
- function yr(e, t) {
219
- var r = this.__data__, n = U(r, e);
220
- return n < 0 ? (++this.size, r.push([e, t])) : r[n][1] = t, this;
221
- }
222
- function A(e) {
223
- var t = -1, r = e == null ? 0 : e.length;
224
- for (this.clear(); ++t < r; ) {
225
- var n = e[t];
226
- this.set(n[0], n[1]);
227
- }
228
- }
229
- A.prototype.clear = lr;
230
- A.prototype.delete = gr;
231
- A.prototype.get = _r;
232
- A.prototype.has = hr;
233
- A.prototype.set = yr;
234
- var L = S(T, "Map");
235
- function br() {
236
- this.size = 0, this.__data__ = {
237
- hash: new O(),
238
- map: new (L || A)(),
239
- string: new O()
240
- };
241
- }
242
- function vr(e) {
243
- var t = typeof e;
244
- return t == "string" || t == "number" || t == "symbol" || t == "boolean" ? e !== "__proto__" : e === null;
245
- }
246
- function z(e, t) {
247
- var r = e.__data__;
248
- return vr(t) ? r[typeof t == "string" ? "string" : "hash"] : r.map;
249
- }
250
- function Tr(e) {
251
- var t = z(this, e).delete(e);
252
- return this.size -= t ? 1 : 0, t;
253
- }
254
- function Ar(e) {
255
- return z(this, e).get(e);
256
- }
257
- function mr(e) {
258
- return z(this, e).has(e);
259
- }
260
- function wr(e, t) {
261
- var r = z(this, e), n = r.size;
262
- return r.set(e, t), this.size += r.size == n ? 0 : 1, this;
263
- }
264
- function j(e) {
265
- var t = -1, r = e == null ? 0 : e.length;
266
- for (this.clear(); ++t < r; ) {
267
- var n = e[t];
268
- this.set(n[0], n[1]);
269
- }
270
- }
271
- j.prototype.clear = br;
272
- j.prototype.delete = Tr;
273
- j.prototype.get = Ar;
274
- j.prototype.has = mr;
275
- j.prototype.set = wr;
276
- function Or(e, t) {
277
- for (var r = -1, n = t.length, i = e.length; ++r < n; )
278
- e[i + r] = t[r];
279
- return e;
280
- }
281
- function $r() {
282
- this.__data__ = new A(), this.size = 0;
283
- }
284
- function jr(e) {
285
- var t = this.__data__, r = t.delete(e);
286
- return this.size = t.size, r;
287
- }
288
- function Pr(e) {
289
- return this.__data__.get(e);
290
- }
291
- function Sr(e) {
292
- return this.__data__.has(e);
293
- }
294
- var xr = 200;
295
- function Er(e, t) {
296
- var r = this.__data__;
297
- if (r instanceof A) {
298
- var n = r.__data__;
299
- if (!L || n.length < xr - 1)
300
- return n.push([e, t]), this.size = ++r.size, this;
301
- r = this.__data__ = new j(n);
302
- }
303
- return r.set(e, t), this.size = r.size, this;
304
- }
305
- function w(e) {
306
- var t = this.__data__ = new A(e);
307
- this.size = t.size;
308
- }
309
- w.prototype.clear = $r;
310
- w.prototype.delete = jr;
311
- w.prototype.get = Pr;
312
- w.prototype.has = Sr;
313
- w.prototype.set = Er;
314
- function Ir(e, t) {
315
- for (var r = -1, n = e == null ? 0 : e.length, i = 0, a = []; ++r < n; ) {
316
- var u = e[r];
317
- t(u, r, e) && (a[i++] = u);
318
- }
319
- return a;
320
- }
321
- function Cr() {
322
- return [];
323
- }
324
- var Lr = Object.prototype, Mr = Lr.propertyIsEnumerable, ie = Object.getOwnPropertySymbols, Rr = ie ? function(e) {
325
- return e == null ? [] : (e = Object(e), Ir(ie(e), function(t) {
326
- return Mr.call(e, t);
327
- }));
328
- } : Cr;
329
- function Dr(e, t, r) {
330
- var n = t(e);
331
- return G(e) ? n : Or(n, r(e));
332
- }
333
- function oe(e) {
334
- return Dr(e, kt, Rr);
335
- }
336
- var J = S(T, "DataView"), Y = S(T, "Promise"), Z = S(T, "Set"), se = "[object Map]", Fr = "[object Object]", ue = "[object Promise]", fe = "[object Set]", ce = "[object WeakMap]", le = "[object DataView]", Gr = $(J), Nr = $(L), Ur = $(Y), zr = $(Z), Br = $(W), m = M;
337
- (J && m(new J(new ArrayBuffer(1))) != le || L && m(new L()) != se || Y && m(Y.resolve()) != ue || Z && m(new Z()) != fe || W && m(new W()) != ce) && (m = function(e) {
338
- var t = M(e), r = t == Fr ? e.constructor : void 0, n = r ? $(r) : "";
339
- if (n)
340
- switch (n) {
341
- case Gr:
342
- return le;
343
- case Nr:
344
- return se;
345
- case Ur:
346
- return ue;
347
- case zr:
348
- return fe;
349
- case Br:
350
- return ce;
351
- }
352
- return t;
353
- });
354
- var pe = T.Uint8Array, Hr = "__lodash_hash_undefined__";
355
- function Kr(e) {
356
- return this.__data__.set(e, Hr), this;
357
- }
358
- function qr(e) {
359
- return this.__data__.has(e);
360
- }
361
- function N(e) {
362
- var t = -1, r = e == null ? 0 : e.length;
363
- for (this.__data__ = new j(); ++t < r; )
364
- this.add(e[t]);
365
- }
366
- N.prototype.add = N.prototype.push = Kr;
367
- N.prototype.has = qr;
368
- function Wr(e, t) {
369
- for (var r = -1, n = e == null ? 0 : e.length; ++r < n; )
370
- if (t(e[r], r, e))
371
- return !0;
372
- return !1;
373
- }
374
- function Xr(e, t) {
375
- return e.has(t);
376
- }
377
- var Jr = 1, Yr = 2;
378
- function Se(e, t, r, n, i, a) {
379
- var u = r & Jr, o = e.length, s = t.length;
380
- if (o != s && !(u && s > o))
381
- return !1;
382
- var f = a.get(e), g = a.get(t);
383
- if (f && g)
384
- return f == t && g == e;
385
- var d = -1, l = !0, y = r & Yr ? new N() : void 0;
386
- for (a.set(e, t), a.set(t, e); ++d < o; ) {
387
- var _ = e[d], h = t[d];
388
- if (n)
389
- var p = u ? n(h, _, d, t, e, a) : n(_, h, d, e, t, a);
390
- if (p !== void 0) {
391
- if (p)
392
- continue;
393
- l = !1;
394
- break;
395
- }
396
- if (y) {
397
- if (!Wr(t, function(b, v) {
398
- if (!Xr(y, v) && (_ === b || i(_, b, r, n, a)))
399
- return y.push(v);
400
- })) {
401
- l = !1;
402
- break;
403
- }
404
- } else if (!(_ === h || i(_, h, r, n, a))) {
405
- l = !1;
406
- break;
407
- }
408
- }
409
- return a.delete(e), a.delete(t), l;
410
- }
411
- function Zr(e) {
412
- var t = -1, r = Array(e.size);
413
- return e.forEach(function(n, i) {
414
- r[++t] = [i, n];
415
- }), r;
416
- }
417
- function Qr(e) {
418
- var t = -1, r = Array(e.size);
419
- return e.forEach(function(n) {
420
- r[++t] = n;
421
- }), r;
422
- }
423
- var Vr = 1, kr = 2, en = "[object Boolean]", tn = "[object Date]", rn = "[object Error]", nn = "[object Map]", an = "[object Number]", on = "[object RegExp]", sn = "[object Set]", un = "[object String]", fn = "[object Symbol]", cn = "[object ArrayBuffer]", ln = "[object DataView]", de = P ? P.prototype : void 0, K = de ? de.valueOf : void 0;
424
- function pn(e, t, r, n, i, a, u) {
425
- switch (r) {
426
- case ln:
427
- if (e.byteLength != t.byteLength || e.byteOffset != t.byteOffset)
428
- return !1;
429
- e = e.buffer, t = t.buffer;
430
- case cn:
431
- return !(e.byteLength != t.byteLength || !a(new pe(e), new pe(t)));
432
- case en:
433
- case tn:
434
- case an:
435
- return me(+e, +t);
436
- case rn:
437
- return e.name == t.name && e.message == t.message;
438
- case on:
439
- case un:
440
- return e == t + "";
441
- case nn:
442
- var o = Zr;
443
- case sn:
444
- var s = n & Vr;
445
- if (o || (o = Qr), e.size != t.size && !s)
446
- return !1;
447
- var f = u.get(e);
448
- if (f)
449
- return f == t;
450
- n |= kr, u.set(e, t);
451
- var g = Se(o(e), o(t), n, i, a, u);
452
- return u.delete(e), g;
453
- case fn:
454
- if (K)
455
- return K.call(e) == K.call(t);
456
- }
457
- return !1;
458
- }
459
- var dn = 1, gn = Object.prototype, _n = gn.hasOwnProperty;
460
- function hn(e, t, r, n, i, a) {
461
- var u = r & dn, o = oe(e), s = o.length, f = oe(t), g = f.length;
462
- if (s != g && !u)
463
- return !1;
464
- for (var d = s; d--; ) {
465
- var l = o[d];
466
- if (!(u ? l in t : _n.call(t, l)))
467
- return !1;
468
- }
469
- var y = a.get(e), _ = a.get(t);
470
- if (y && _)
471
- return y == t && _ == e;
472
- var h = !0;
473
- a.set(e, t), a.set(t, e);
474
- for (var p = u; ++d < s; ) {
475
- l = o[d];
476
- var b = e[l], v = t[l];
477
- if (n)
478
- var Q = u ? n(v, b, l, t, e, a) : n(b, v, l, e, t, a);
479
- if (!(Q === void 0 ? b === v || i(b, v, r, n, a) : Q)) {
480
- h = !1;
481
- break;
482
- }
483
- p || (p = l == "constructor");
484
- }
485
- if (h && !p) {
486
- var R = e.constructor, D = t.constructor;
487
- R != D && "constructor" in e && "constructor" in t && !(typeof R == "function" && R instanceof R && typeof D == "function" && D instanceof D) && (h = !1);
488
- }
489
- return a.delete(e), a.delete(t), h;
490
- }
491
- var yn = 1, ge = "[object Arguments]", _e = "[object Array]", F = "[object Object]", bn = Object.prototype, he = bn.hasOwnProperty;
492
- function vn(e, t, r, n, i, a) {
493
- var u = G(e), o = G(t), s = u ? _e : m(e), f = o ? _e : m(t);
494
- s = s == ge ? F : s, f = f == ge ? F : f;
495
- var g = s == F, d = f == F, l = s == f;
496
- if (l && X(e)) {
497
- if (!X(t))
498
- return !1;
499
- u = !0, g = !1;
500
- }
501
- if (l && !g)
502
- return a || (a = new w()), u || Pe(e) ? Se(e, t, r, n, i, a) : pn(e, t, s, r, n, i, a);
503
- if (!(r & yn)) {
504
- var y = g && he.call(e, "__wrapped__"), _ = d && he.call(t, "__wrapped__");
505
- if (y || _) {
506
- var h = y ? e.value() : e, p = _ ? t.value() : t;
507
- return a || (a = new w()), i(h, p, r, n, a);
508
- }
509
- }
510
- return l ? (a || (a = new w()), hn(e, t, r, n, i, a)) : !1;
511
- }
512
- function xe(e, t, r, n, i) {
513
- return e === t ? !0 : e == null || t == null || !I(e) && !I(t) ? e !== e && t !== t : vn(e, t, r, n, xe, i);
514
- }
515
- function Tn(e, t) {
516
- return xe(e, t);
517
- }
518
- function q(e) {
519
- return typeof e == "function";
520
- }
521
- const mn = (e, t) => {
522
- const r = Ee(Ie(e)), n = (a) => (r.value = q(t == null ? void 0 : t.beforeSet) ? t.beforeSet(a) : a, !0), i = (a) => (q(t == null ? void 0 : t.compare) ? t.compare(r.value, a) : Tn(r.value, a)) ? !1 : n(a);
523
- return t != null && t.diff || q(t == null ? void 0 : t.compare) ? [r, i] : [r, n];
524
- }, ye = 1e3 / 60;
525
- function wn(e, t = ye, r = {}) {
526
- const { type: n = "ignoreCallbackTime", loop: i = !0 } = r;
527
- t = typeof t == "number" ? t : ye;
528
- let a = "running", u = performance.now() + t, o = null, s = null, f = 0, g = typeof i == "number" ? Math.max(1, i) : i ? 1 / 0 : 1;
529
- const d = async () => {
530
- if (a !== "running") return;
531
- const p = performance.now(), b = u - p;
532
- if (b <= 0)
533
- try {
534
- const v = e();
535
- if (v instanceof Promise && await v, g = Math.max(0, g - 1), g === 0) {
536
- y();
537
- return;
538
- }
539
- u = n === "waitAfterCallback" ? performance.now() + t : p + t;
540
- } finally {
541
- l();
542
- }
543
- else
544
- l(b);
545
- }, l = (p = t) => {
546
- if (a !== "running") return;
547
- const b = t * 1.5, v = Math.max(0, p - 5);
548
- o && clearTimeout(o), s && cancelAnimationFrame(s), p > b ? o = setTimeout(() => {
549
- s = requestAnimationFrame(d);
550
- }, v) : s = requestAnimationFrame(d);
551
- }, y = () => {
552
- a = "stopped", o && clearTimeout(o), s && cancelAnimationFrame(s), o = s = null;
553
- }, _ = () => {
554
- a === "running" && (a = "paused", f = performance.now(), o && clearTimeout(o), s && cancelAnimationFrame(s), o = s = null);
555
- }, h = () => {
556
- if (a === "stopped" || a === "running") return;
557
- const p = performance.now() - f;
558
- u += p, a = "running", l();
559
- };
560
- return l(), { stop: y, pause: _, start: h };
561
- }
1
+ import { useState as o } from "./useState.js";
2
+ import { useRafTimer as f } from "./useTimer.js";
562
3
  export {
563
- wn as useRafTimer,
564
- mn as useState
4
+ f as useRafTimer,
5
+ o as useState
565
6
  };
@@ -1,2 +1,9 @@
1
- export { useState } from './useState';
2
- export { useRafTimer } from './useTimer';
1
+ /** @file 库统一出口,聚合导出全部 Hook 及其类型定义 */
2
+ /** 带差异比较能力的状态 Hook */
3
+ export { useState } from './useState/index.js';
4
+ /** 状态 Hook 关联类型:配置项、状态引用与返回元组 */
5
+ export type { UseStateConfig, UseStateRef, UseStateReturn } from './useState/index.js';
6
+ /** 基于 requestAnimationFrame 的定时器 Hook */
7
+ export { useRafTimer } from './useTimer/index.js';
8
+ /** 定时器 Hook 关联类型:回调、控制函数与配置项 */
9
+ export type { Callback, ControlFunctions, RafTimerOptions } from './useTimer/index.js';
@@ -1,8 +1,37 @@
1
- import { MaybeRefOrGetter, Ref } from 'vue';
2
- export type UseStateReturn<T> = [Ref<T>, (newVal: T) => boolean];
3
- export interface UseStateConfig<T> {
1
+ import { MaybeRefOrGetter, Ref, ShallowRef, UnwrapRef } from 'vue';
2
+ /** 检测类型 T 是否为 any;是 any 时取 Yes 分支,否则取 No */
3
+ type IfAny<T, Yes, No> = 0 extends (1 & T) ? Yes : No;
4
+ /** 深层的状态引用类型:普通 Ref 原样返回,其余展开为 UnwrapRef 包装 */
5
+ type DeepStateRef<T> = [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>;
6
+ /** 浅层的状态引用类型:仅做一层包装,避免深层解包 */
7
+ type ShallowStateRef<T> = Ref extends T ? T extends Ref ? IfAny<T, ShallowRef<T>, T> : ShallowRef<T> : ShallowRef<T>;
8
+ /** useState 返回的状态引用类型,按 shallow 开关在深浅两种引用间切换 */
9
+ export type UseStateRef<T, Shallow extends boolean = false> = Shallow extends true ? ShallowStateRef<T> : DeepStateRef<T>;
10
+ /** useState 的返回元组:[状态引用, 写入函数] */
11
+ export type UseStateReturn<T, Shallow extends boolean = false> = [
12
+ UseStateRef<T, Shallow>,
13
+ (newVal: T) => boolean
14
+ ];
15
+ /** useState 的配置项 */
16
+ export interface UseStateConfig<T, Shallow extends boolean = false> {
17
+ /** 是否使用浅层引用(true 时不做深层响应式转换) */
18
+ shallow?: Shallow;
19
+ /** 是否启用差异比较,相等则跳过写入 */
4
20
  diff?: boolean;
5
- compare?: (oldVal: T, newVal: T) => boolean;
21
+ /** 自定义相等判定,返回真表示新旧值相等、无需写入 */
22
+ compare?: (oldVal: UseStateRef<T, Shallow>['value'], newVal: T) => boolean;
23
+ /** 写入前的拦截钩子,可返回加工后的新值 */
6
24
  beforeSet?: (newVal: T) => T;
7
25
  }
8
- export declare const useState: <T>(source: MaybeRefOrGetter<T>, config?: UseStateConfig<T>) => UseStateReturn<T>;
26
+ /**
27
+ * 创建带差异比较与写入拦截能力的响应式状态
28
+ * @param source 初始值来源,支持值、Ref 或 getter
29
+ * @param config 配置项;shallow 为 true 时返回浅层引用
30
+ * @returns 元组 [状态引用, 写入函数],写入函数返回是否发生实际写入
31
+ */
32
+ export declare function useState<T>(source: MaybeRefOrGetter<T>, config: UseStateConfig<T, true> & {
33
+ shallow: true;
34
+ }): UseStateReturn<T, true>;
35
+ export declare function useState<T>(source: MaybeRefOrGetter<T>, config?: UseStateConfig<T, false>): UseStateReturn<T, false>;
36
+ export declare function useState<T>(source: MaybeRefOrGetter<T>, config?: UseStateConfig<T, boolean>): UseStateReturn<T, boolean>;
37
+ export {};
@@ -1,12 +1,28 @@
1
- type Callback = () => void | Promise<void>;
2
- type ControlFunctions = {
1
+ /** 定时器回调,可同步返回,也可返回 thenable 表示异步 */
2
+ export type Callback = () => void | PromiseLike<void>;
3
+ /** 定时器控制器 */
4
+ export interface ControlFunctions {
5
+ /** 永久停止并释放定时器,不可再启动 */
3
6
  stop: () => void;
7
+ /** 暂停计时,保持已消耗的逻辑时间 */
4
8
  pause: () => void;
9
+ /** 从暂停处恢复计时 */
5
10
  start: () => void;
6
- };
7
- interface RafTimerOptions {
11
+ }
12
+ /** 定时器配置项 */
13
+ export interface RafTimerOptions {
14
+ /** 计时基准:waitAfterCallback 回调完成后计时,ignoreCallbackTime 忽略回调耗时 */
8
15
  type?: 'waitAfterCallback' | 'ignoreCallbackTime';
16
+ /** 循环方式:true 无限循环、false 仅一次、数字表示循环次数 */
9
17
  loop?: boolean | number;
18
+ /** 回调同步抛错或返回的 thenable 拒绝时的处理器 */
19
+ onError?: (error: unknown) => void | PromiseLike<void>;
10
20
  }
21
+ /**
22
+ * 创建基于动画帧的定时器
23
+ * @param callback 每帧触发的回调
24
+ * @param interval 触发间隔(毫秒),缺省按 60fps 计算
25
+ * @param options 定时器配置项
26
+ * @returns 含 stop / pause / start 的控制器
27
+ */
11
28
  export declare function useRafTimer(callback: Callback, interval?: number, options?: RafTimerOptions): ControlFunctions;
12
- export {};