rattail 0.0.9 → 0.0.11
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/lib/index.cjs +542 -330
- package/lib/index.d.cts +160 -64
- package/lib/index.d.ts +160 -64
- package/lib/index.js +539 -330
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -53,6 +53,7 @@ __export(src_exports, {
|
|
|
53
53
|
call: () => call,
|
|
54
54
|
camelize: () => camelize,
|
|
55
55
|
cancelAnimationFrame: () => cancelAnimationFrame,
|
|
56
|
+
chunk: () => chunk,
|
|
56
57
|
clamp: () => clamp,
|
|
57
58
|
clampArrayRange: () => clampArrayRange,
|
|
58
59
|
classes: () => classes,
|
|
@@ -64,6 +65,8 @@ __export(src_exports, {
|
|
|
64
65
|
debounce: () => debounce,
|
|
65
66
|
delay: () => delay,
|
|
66
67
|
doubleRaf: () => doubleRaf,
|
|
68
|
+
ensurePrefix: () => ensurePrefix,
|
|
69
|
+
ensureSuffix: () => ensureSuffix,
|
|
67
70
|
find: () => find,
|
|
68
71
|
genNumberKey: () => genNumberKey,
|
|
69
72
|
genStringKey: () => genStringKey,
|
|
@@ -154,62 +157,148 @@ __export(src_exports, {
|
|
|
154
157
|
});
|
|
155
158
|
module.exports = __toCommonJS(src_exports);
|
|
156
159
|
|
|
157
|
-
// src/
|
|
160
|
+
// src/array/at.ts
|
|
161
|
+
function at(arr, index) {
|
|
162
|
+
if (!arr.length) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (index < 0) {
|
|
166
|
+
index += arr.length;
|
|
167
|
+
}
|
|
168
|
+
return arr[index];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// src/number/clamp.ts
|
|
172
|
+
function clamp(num, min, max) {
|
|
173
|
+
return Math.min(max, Math.max(min, num));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/number/clampArrayRange.ts
|
|
177
|
+
function clampArrayRange(index, arr) {
|
|
178
|
+
return clamp(index, 0, arr.length - 1);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// src/number/delay.ts
|
|
182
|
+
function delay(time) {
|
|
183
|
+
return new Promise((resolve) => {
|
|
184
|
+
setTimeout(resolve, time);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/number/randomNumber.ts
|
|
189
|
+
function randomNumber(min = 0, max = 100) {
|
|
190
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/number/times.ts
|
|
194
|
+
function times(num, fn) {
|
|
195
|
+
return Array.from({ length: num }, (_, index) => fn(index));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/general/inBrowser.ts
|
|
199
|
+
function inBrowser() {
|
|
200
|
+
return typeof window !== "undefined";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// src/general/getGlobalThis.ts
|
|
204
|
+
function getGlobalThis() {
|
|
205
|
+
if (typeof globalThis !== "undefined") {
|
|
206
|
+
return globalThis;
|
|
207
|
+
}
|
|
208
|
+
if (inBrowser()) {
|
|
209
|
+
return window;
|
|
210
|
+
}
|
|
211
|
+
return typeof global !== "undefined" ? global : self;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// src/general/hasOwn.ts
|
|
215
|
+
var { hasOwnProperty } = Object.prototype;
|
|
216
|
+
function hasOwn(val, key3) {
|
|
217
|
+
return hasOwnProperty.call(val, key3);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/general/inMobile.ts
|
|
221
|
+
function inMobile() {
|
|
222
|
+
return inBrowser() && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/general/isArray.ts
|
|
226
|
+
function isArray(val) {
|
|
227
|
+
return Array.isArray(val);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/general/toTypeString.ts
|
|
158
231
|
var objectToString = Object.prototype.toString;
|
|
159
232
|
function toTypeString(value) {
|
|
160
233
|
return objectToString.call(value);
|
|
161
234
|
}
|
|
162
|
-
|
|
163
|
-
|
|
235
|
+
|
|
236
|
+
// src/general/toRawType.ts
|
|
237
|
+
function toRawType(value) {
|
|
238
|
+
return toTypeString(value).slice(8, -1);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/general/isArrayBuffer.ts
|
|
242
|
+
function isArrayBuffer(val) {
|
|
243
|
+
return toRawType(val) === "ArrayBuffer";
|
|
164
244
|
}
|
|
245
|
+
|
|
246
|
+
// src/general/isBoolean.ts
|
|
165
247
|
function isBoolean(val) {
|
|
166
248
|
return typeof val === "boolean";
|
|
167
249
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return typeof val === "symbol";
|
|
250
|
+
|
|
251
|
+
// src/general/isDataView.ts
|
|
252
|
+
function isDataView(val) {
|
|
253
|
+
return toRawType(val) === "DataView";
|
|
173
254
|
}
|
|
174
|
-
|
|
175
|
-
|
|
255
|
+
|
|
256
|
+
// src/general/isDate.ts
|
|
257
|
+
function isDate(val) {
|
|
258
|
+
return toRawType(val) === "Date";
|
|
176
259
|
}
|
|
260
|
+
|
|
261
|
+
// src/general/isDOMException.ts
|
|
177
262
|
function isDOMException(val) {
|
|
178
263
|
return toRawType(val) === "DOMException";
|
|
179
264
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return toRawType(val) === "Object";
|
|
185
|
-
}
|
|
186
|
-
function isObject(val) {
|
|
187
|
-
return typeof val === "object" && val !== null;
|
|
188
|
-
}
|
|
189
|
-
function isPromise(val) {
|
|
190
|
-
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
265
|
+
|
|
266
|
+
// src/general/isEmpty.ts
|
|
267
|
+
function isEmpty(val) {
|
|
268
|
+
return val === void 0 || val === null || val === "" || isArray(val) && !val.length;
|
|
191
269
|
}
|
|
270
|
+
|
|
271
|
+
// src/general/isMap.ts
|
|
192
272
|
function isMap(val) {
|
|
193
273
|
return toRawType(val) === "Map";
|
|
194
274
|
}
|
|
275
|
+
|
|
276
|
+
// src/general/isPlainObject.ts
|
|
277
|
+
function isPlainObject(val) {
|
|
278
|
+
return toRawType(val) === "Object";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/general/isSet.ts
|
|
195
282
|
function isSet(val) {
|
|
196
283
|
return toRawType(val) === "Set";
|
|
197
284
|
}
|
|
198
|
-
|
|
199
|
-
|
|
285
|
+
|
|
286
|
+
// src/general/isObject.ts
|
|
287
|
+
function isObject(val) {
|
|
288
|
+
return typeof val === "object" && val !== null;
|
|
200
289
|
}
|
|
290
|
+
|
|
291
|
+
// src/general/isRegExp.ts
|
|
201
292
|
function isRegExp(val) {
|
|
202
293
|
return toRawType(val) === "RegExp";
|
|
203
294
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return toRawType(val) === "WeakSet";
|
|
209
|
-
}
|
|
210
|
-
function isArrayBuffer(val) {
|
|
211
|
-
return toRawType(val) === "ArrayBuffer";
|
|
295
|
+
|
|
296
|
+
// src/general/isError.ts
|
|
297
|
+
function isError(val) {
|
|
298
|
+
return toRawType(val) === "Error";
|
|
212
299
|
}
|
|
300
|
+
|
|
301
|
+
// src/general/isTypedArray.ts
|
|
213
302
|
function isTypedArray(val) {
|
|
214
303
|
return [
|
|
215
304
|
"Int8Array",
|
|
@@ -225,55 +314,8 @@ function isTypedArray(val) {
|
|
|
225
314
|
"BigUint64Array"
|
|
226
315
|
].includes(toRawType(val));
|
|
227
316
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
function toRawType(value) {
|
|
232
|
-
return toTypeString(value).slice(8, -1);
|
|
233
|
-
}
|
|
234
|
-
function isFunction(val) {
|
|
235
|
-
return typeof val === "function";
|
|
236
|
-
}
|
|
237
|
-
function isArray(val) {
|
|
238
|
-
return Array.isArray(val);
|
|
239
|
-
}
|
|
240
|
-
function isNullish(val) {
|
|
241
|
-
return val == null;
|
|
242
|
-
}
|
|
243
|
-
function isTruthy(v) {
|
|
244
|
-
return Boolean(v);
|
|
245
|
-
}
|
|
246
|
-
function isEmpty(val) {
|
|
247
|
-
return val === void 0 || val === null || val === "" || isArray(val) && !val.length;
|
|
248
|
-
}
|
|
249
|
-
function isWindow(val) {
|
|
250
|
-
return val === window;
|
|
251
|
-
}
|
|
252
|
-
function supportTouch() {
|
|
253
|
-
return inBrowser() && "ontouchstart" in window;
|
|
254
|
-
}
|
|
255
|
-
function inBrowser() {
|
|
256
|
-
return typeof window !== "undefined";
|
|
257
|
-
}
|
|
258
|
-
function inMobile() {
|
|
259
|
-
return inBrowser() && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
260
|
-
}
|
|
261
|
-
var { hasOwnProperty } = Object.prototype;
|
|
262
|
-
function hasOwn(val, key3) {
|
|
263
|
-
return hasOwnProperty.call(val, key3);
|
|
264
|
-
}
|
|
265
|
-
function getGlobalThis() {
|
|
266
|
-
if (typeof globalThis !== "undefined") {
|
|
267
|
-
return globalThis;
|
|
268
|
-
}
|
|
269
|
-
if (inBrowser()) {
|
|
270
|
-
return window;
|
|
271
|
-
}
|
|
272
|
-
return typeof global !== "undefined" ? global : self;
|
|
273
|
-
}
|
|
274
|
-
function isNonEmptyArray(val) {
|
|
275
|
-
return isArray(val) && !!val.length;
|
|
276
|
-
}
|
|
317
|
+
|
|
318
|
+
// src/general/isEqualWith.ts
|
|
277
319
|
function isEqualWith(value, other, fn) {
|
|
278
320
|
const valueStack = /* @__PURE__ */ new WeakMap();
|
|
279
321
|
const otherStack = /* @__PURE__ */ new WeakMap();
|
|
@@ -367,26 +409,112 @@ function isEqualWith(value, other, fn) {
|
|
|
367
409
|
}
|
|
368
410
|
return baseIsEqual(value, other, valueStack, otherStack);
|
|
369
411
|
}
|
|
412
|
+
|
|
413
|
+
// src/general/isEqual.ts
|
|
370
414
|
function isEqual(value, other) {
|
|
371
415
|
return isEqualWith(value, other, () => void 0);
|
|
372
416
|
}
|
|
373
417
|
|
|
374
|
-
// src/
|
|
375
|
-
function
|
|
376
|
-
return
|
|
418
|
+
// src/general/isFunction.ts
|
|
419
|
+
function isFunction(val) {
|
|
420
|
+
return typeof val === "function";
|
|
377
421
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
ret.push(i);
|
|
383
|
-
}
|
|
384
|
-
return ret;
|
|
385
|
-
}, []);
|
|
422
|
+
|
|
423
|
+
// src/general/isNonEmptyArray.ts
|
|
424
|
+
function isNonEmptyArray(val) {
|
|
425
|
+
return isArray(val) && !!val.length;
|
|
386
426
|
}
|
|
387
|
-
|
|
388
|
-
|
|
427
|
+
|
|
428
|
+
// src/general/isNullish.ts
|
|
429
|
+
function isNullish(val) {
|
|
430
|
+
return val == null;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/general/isNumber.ts
|
|
434
|
+
function isNumber(val) {
|
|
435
|
+
return typeof val === "number";
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/general/isString.ts
|
|
439
|
+
function isString(val) {
|
|
440
|
+
return typeof val === "string";
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/general/isNumeric.ts
|
|
444
|
+
function isNumeric(val) {
|
|
445
|
+
return isNumber(val) || isString(val) && /^[-+]?\d+$/.test(val);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// src/general/isPromise.ts
|
|
449
|
+
function isPromise(val) {
|
|
450
|
+
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// src/general/isSymbol.ts
|
|
454
|
+
function isSymbol(val) {
|
|
455
|
+
return typeof val === "symbol";
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/general/isTruthy.ts
|
|
459
|
+
function isTruthy(v) {
|
|
460
|
+
return Boolean(v);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// src/general/isWeakMap.ts
|
|
464
|
+
function isWeakMap(val) {
|
|
465
|
+
return toRawType(val) === "WeakMap";
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// src/general/isWeakSet.ts
|
|
469
|
+
function isWeakSet(val) {
|
|
470
|
+
return toRawType(val) === "WeakSet";
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// src/general/isWindow.ts
|
|
474
|
+
function isWindow(val) {
|
|
475
|
+
return val === window;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/general/supportTouch.ts
|
|
479
|
+
function supportTouch() {
|
|
480
|
+
return inBrowser() && "ontouchstart" in window;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// src/number/toNumber.ts
|
|
484
|
+
function toNumber(val) {
|
|
485
|
+
if (val == null) {
|
|
486
|
+
return 0;
|
|
487
|
+
}
|
|
488
|
+
if (isString(val)) {
|
|
489
|
+
val = parseFloat(val);
|
|
490
|
+
val = Number.isNaN(val) ? 0 : val;
|
|
491
|
+
return val;
|
|
492
|
+
}
|
|
493
|
+
if (isBoolean(val)) {
|
|
494
|
+
return Number(val);
|
|
495
|
+
}
|
|
496
|
+
return val;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/number/genNumberKey.ts
|
|
500
|
+
var key = 0;
|
|
501
|
+
function genNumberKey() {
|
|
502
|
+
return key++;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/array/chunk.ts
|
|
506
|
+
function chunk(arr, size = 1) {
|
|
507
|
+
size = clamp(size, 1, arr.length);
|
|
508
|
+
const result = [];
|
|
509
|
+
let index = 0;
|
|
510
|
+
while (index < arr.length) {
|
|
511
|
+
result.push(arr.slice(index, index + size));
|
|
512
|
+
index += size;
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
389
515
|
}
|
|
516
|
+
|
|
517
|
+
// src/array/removeItem.ts
|
|
390
518
|
function removeItem(arr, item) {
|
|
391
519
|
if (arr.length) {
|
|
392
520
|
const index = arr.indexOf(item);
|
|
@@ -395,14 +523,30 @@ function removeItem(arr, item) {
|
|
|
395
523
|
}
|
|
396
524
|
}
|
|
397
525
|
}
|
|
526
|
+
|
|
527
|
+
// src/array/toggleItem.ts
|
|
398
528
|
function toggleItem(arr, item) {
|
|
399
529
|
arr.includes(item) ? removeItem(arr, item) : arr.push(item);
|
|
400
530
|
return arr;
|
|
401
531
|
}
|
|
402
|
-
|
|
403
|
-
|
|
532
|
+
|
|
533
|
+
// src/array/uniq.ts
|
|
534
|
+
function uniq(arr) {
|
|
535
|
+
return [...new Set(arr)];
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// src/array/uniqBy.ts
|
|
539
|
+
function uniqBy(arr, fn) {
|
|
540
|
+
return arr.reduce((ret, i) => {
|
|
541
|
+
const index = ret.findIndex((j) => fn(i, j));
|
|
542
|
+
if (index === -1) {
|
|
543
|
+
ret.push(i);
|
|
544
|
+
}
|
|
545
|
+
return ret;
|
|
546
|
+
}, []);
|
|
404
547
|
}
|
|
405
|
-
|
|
548
|
+
|
|
549
|
+
// src/array/find.ts
|
|
406
550
|
function find(arr, fn, from = "start") {
|
|
407
551
|
let i = from === "start" ? 0 : arr.length - 1;
|
|
408
552
|
while (arr.length > 0 && i >= 0 && i <= arr.length - 1) {
|
|
@@ -414,15 +558,8 @@ function find(arr, fn, from = "start") {
|
|
|
414
558
|
}
|
|
415
559
|
return [null, -1];
|
|
416
560
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
if (index < 0) {
|
|
422
|
-
index += arr.length;
|
|
423
|
-
}
|
|
424
|
-
return arr[index];
|
|
425
|
-
}
|
|
561
|
+
|
|
562
|
+
// src/array/shuffle.ts
|
|
426
563
|
function shuffle(arr) {
|
|
427
564
|
for (let i = arr.length - 1; i > 0; i--) {
|
|
428
565
|
const j = Math.floor(Math.random() * (i + 1));
|
|
@@ -431,35 +568,107 @@ function shuffle(arr) {
|
|
|
431
568
|
return arr;
|
|
432
569
|
}
|
|
433
570
|
|
|
434
|
-
// src/
|
|
435
|
-
function
|
|
436
|
-
return
|
|
571
|
+
// src/array/removeArrayBlank.ts
|
|
572
|
+
function removeArrayBlank(arr) {
|
|
573
|
+
return arr.filter((item) => item != null);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// src/array/removeArrayEmpty.ts
|
|
577
|
+
function removeArrayEmpty(arr) {
|
|
578
|
+
return arr.filter((item) => item != null && item !== "");
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// src/array/normalizeToArray.ts
|
|
582
|
+
function normalizeToArray(value) {
|
|
583
|
+
return isArray(value) ? value : [value];
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/util/cancelAnimationFrame.ts
|
|
587
|
+
function cancelAnimationFrame(handle) {
|
|
588
|
+
const globalThis2 = getGlobalThis();
|
|
589
|
+
globalThis2.cancelAnimationFrame ? globalThis2.cancelAnimationFrame(handle) : globalThis2.clearTimeout(handle);
|
|
437
590
|
}
|
|
591
|
+
|
|
592
|
+
// src/util/classes.ts
|
|
593
|
+
function classes(...classes2) {
|
|
594
|
+
return classes2.map((className) => {
|
|
595
|
+
if (isArray(className)) {
|
|
596
|
+
const [condition, truthy, falsy = null] = className;
|
|
597
|
+
return condition ? truthy : falsy;
|
|
598
|
+
}
|
|
599
|
+
return className;
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// src/util/copyText.ts
|
|
604
|
+
function copyText(value) {
|
|
605
|
+
if (!value) {
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const textArea = document.createElement("textarea");
|
|
609
|
+
textArea.value = value;
|
|
610
|
+
textArea.style.position = "fixed";
|
|
611
|
+
textArea.style.opacity = "0";
|
|
612
|
+
document.body.appendChild(textArea);
|
|
613
|
+
textArea.select();
|
|
614
|
+
document.execCommand("copy");
|
|
615
|
+
document.body.removeChild(textArea);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/string/camelize.ts
|
|
438
619
|
function camelize(s) {
|
|
439
620
|
s = s.replace(/-(\w)/g, (_, p) => p.toUpperCase());
|
|
440
621
|
return s.replace(s.charAt(0), s.charAt(0).toLowerCase());
|
|
441
622
|
}
|
|
623
|
+
|
|
624
|
+
// src/string/ensurePrefix.ts
|
|
625
|
+
function ensurePrefix(s, prefix) {
|
|
626
|
+
return s.startsWith(prefix) ? s : prefix + s;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// src/string/ensureSuffix.ts
|
|
630
|
+
function ensureSuffix(s, suffix) {
|
|
631
|
+
return s.endsWith(suffix) ? s : s + suffix;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/string/genStringKey.ts
|
|
635
|
+
var key2 = 0;
|
|
636
|
+
function genStringKey() {
|
|
637
|
+
return `generated-key-${key2++}`;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/string/kebabCase.ts
|
|
442
641
|
function kebabCase(s) {
|
|
443
642
|
const ret = s.replace(/([A-Z])/g, " $1").trim();
|
|
444
643
|
return ret.split(" ").join("-").toLowerCase();
|
|
445
644
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
}
|
|
451
|
-
return path.replace(/\\/g, "/");
|
|
645
|
+
|
|
646
|
+
// src/string/pascalCase.ts
|
|
647
|
+
function pascalCase(s) {
|
|
648
|
+
return camelize(s).replace(s.charAt(0), s.charAt(0).toUpperCase());
|
|
452
649
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
650
|
+
|
|
651
|
+
// src/string/lowerFirst.ts
|
|
652
|
+
function lowerFirst(s) {
|
|
653
|
+
return s.charAt(0).toLowerCase() + s.slice(1);
|
|
456
654
|
}
|
|
655
|
+
|
|
656
|
+
// src/string/upperFirst.ts
|
|
457
657
|
function upperFirst(s) {
|
|
458
658
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
459
659
|
}
|
|
460
|
-
|
|
461
|
-
|
|
660
|
+
|
|
661
|
+
// src/string/randomColor.ts
|
|
662
|
+
function randomColor() {
|
|
663
|
+
const letters = "0123456789abcdef";
|
|
664
|
+
let color = "#";
|
|
665
|
+
for (let i = 0; i < 6; i++) {
|
|
666
|
+
color += letters[Math.floor(Math.random() * 16)];
|
|
667
|
+
}
|
|
668
|
+
return color;
|
|
462
669
|
}
|
|
670
|
+
|
|
671
|
+
// src/string/randomString.ts
|
|
463
672
|
function randomString(length = 10) {
|
|
464
673
|
let str = baseRandomString();
|
|
465
674
|
while (str.length < length) {
|
|
@@ -470,29 +679,44 @@ function randomString(length = 10) {
|
|
|
470
679
|
}
|
|
471
680
|
return str.slice(0, length);
|
|
472
681
|
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
682
|
+
|
|
683
|
+
// src/string/slash.ts
|
|
684
|
+
function slash(path) {
|
|
685
|
+
const isExtendedLengthPath = path.startsWith("\\\\?\\");
|
|
686
|
+
if (isExtendedLengthPath) {
|
|
687
|
+
return path;
|
|
478
688
|
}
|
|
479
|
-
return
|
|
689
|
+
return path.replace(/\\/g, "/");
|
|
480
690
|
}
|
|
481
691
|
|
|
482
|
-
// src/util.ts
|
|
692
|
+
// src/util/createNamespaceFn.ts
|
|
693
|
+
function createNamespaceFn(namespace) {
|
|
694
|
+
return (name) => {
|
|
695
|
+
const componentName = `${namespace}-${name}`;
|
|
696
|
+
const createBEM = (suffix) => {
|
|
697
|
+
if (!suffix) {
|
|
698
|
+
return componentName;
|
|
699
|
+
}
|
|
700
|
+
if (suffix[0] === "$") {
|
|
701
|
+
return suffix.replace("$", namespace);
|
|
702
|
+
}
|
|
703
|
+
return suffix.startsWith("--") ? `${componentName}${suffix}` : `${componentName}__${suffix}`;
|
|
704
|
+
};
|
|
705
|
+
return {
|
|
706
|
+
name: pascalCase(componentName),
|
|
707
|
+
n: createBEM,
|
|
708
|
+
classes
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/util/requestAnimationFrame.ts
|
|
483
714
|
function requestAnimationFrame(fn) {
|
|
484
715
|
const globalThis2 = getGlobalThis();
|
|
485
716
|
return globalThis2.requestAnimationFrame ? globalThis2.requestAnimationFrame(fn) : globalThis2.setTimeout(fn);
|
|
486
717
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
globalThis2.cancelAnimationFrame ? globalThis2.cancelAnimationFrame(handle) : globalThis2.clearTimeout(handle);
|
|
490
|
-
}
|
|
491
|
-
function raf() {
|
|
492
|
-
return new Promise((resolve) => {
|
|
493
|
-
requestAnimationFrame(resolve);
|
|
494
|
-
});
|
|
495
|
-
}
|
|
718
|
+
|
|
719
|
+
// src/util/doubleRaf.ts
|
|
496
720
|
function doubleRaf() {
|
|
497
721
|
return new Promise((resolve) => {
|
|
498
722
|
requestAnimationFrame(() => {
|
|
@@ -500,36 +724,13 @@ function doubleRaf() {
|
|
|
500
724
|
});
|
|
501
725
|
});
|
|
502
726
|
}
|
|
727
|
+
|
|
728
|
+
// src/util/getStyle.ts
|
|
503
729
|
function getStyle(element) {
|
|
504
730
|
return window.getComputedStyle(element);
|
|
505
731
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
const width = element.innerWidth;
|
|
509
|
-
const height = element.innerHeight;
|
|
510
|
-
const rect = {
|
|
511
|
-
x: 0,
|
|
512
|
-
y: 0,
|
|
513
|
-
top: 0,
|
|
514
|
-
left: 0,
|
|
515
|
-
right: width,
|
|
516
|
-
bottom: height,
|
|
517
|
-
width,
|
|
518
|
-
height
|
|
519
|
-
};
|
|
520
|
-
return __spreadProps(__spreadValues({}, rect), {
|
|
521
|
-
toJSON: () => rect
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
return element.getBoundingClientRect();
|
|
525
|
-
}
|
|
526
|
-
function inViewport(element) {
|
|
527
|
-
const { top, bottom, left, right } = getRect(element);
|
|
528
|
-
const { width, height } = getRect(window);
|
|
529
|
-
const xInViewport = left <= width && right >= 0;
|
|
530
|
-
const yInViewport = top <= height && bottom >= 0;
|
|
531
|
-
return xInViewport && yInViewport;
|
|
532
|
-
}
|
|
732
|
+
|
|
733
|
+
// src/util/getParentScroller.ts
|
|
533
734
|
function getParentScroller(el) {
|
|
534
735
|
let element = el;
|
|
535
736
|
while (element) {
|
|
@@ -548,6 +749,8 @@ function getParentScroller(el) {
|
|
|
548
749
|
}
|
|
549
750
|
return window;
|
|
550
751
|
}
|
|
752
|
+
|
|
753
|
+
// src/util/getAllParentScroller.ts
|
|
551
754
|
function getAllParentScroller(el) {
|
|
552
755
|
const allParentScroller = [];
|
|
553
756
|
let element = el;
|
|
@@ -557,58 +760,71 @@ function getAllParentScroller(el) {
|
|
|
557
760
|
}
|
|
558
761
|
return allParentScroller;
|
|
559
762
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
763
|
+
|
|
764
|
+
// src/util/getRect.ts
|
|
765
|
+
function getRect(element) {
|
|
766
|
+
if (isWindow(element)) {
|
|
767
|
+
const width = element.innerWidth;
|
|
768
|
+
const height = element.innerHeight;
|
|
769
|
+
const rect = {
|
|
770
|
+
x: 0,
|
|
771
|
+
y: 0,
|
|
772
|
+
top: 0,
|
|
773
|
+
left: 0,
|
|
774
|
+
right: width,
|
|
775
|
+
bottom: height,
|
|
776
|
+
width,
|
|
777
|
+
height
|
|
778
|
+
};
|
|
779
|
+
return __spreadProps(__spreadValues({}, rect), {
|
|
780
|
+
toJSON: () => rect
|
|
781
|
+
});
|
|
563
782
|
}
|
|
564
|
-
|
|
565
|
-
}
|
|
566
|
-
function getScrollTop(element) {
|
|
567
|
-
const top = "scrollTop" in element ? element.scrollTop : element.scrollY;
|
|
568
|
-
return Math.max(top, 0);
|
|
783
|
+
return element.getBoundingClientRect();
|
|
569
784
|
}
|
|
785
|
+
|
|
786
|
+
// src/util/getScrollLeft.ts
|
|
570
787
|
function getScrollLeft(element) {
|
|
571
788
|
const left = "scrollLeft" in element ? element.scrollLeft : element.scrollX;
|
|
572
789
|
return Math.max(left, 0);
|
|
573
790
|
}
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
791
|
+
|
|
792
|
+
// src/util/getScrollTop.ts
|
|
793
|
+
function getScrollTop(element) {
|
|
794
|
+
const top = "scrollTop" in element ? element.scrollTop : element.scrollY;
|
|
795
|
+
return Math.max(top, 0);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
// src/util/inViewport.ts
|
|
799
|
+
function inViewport(element) {
|
|
800
|
+
const { top, bottom, left, right } = getRect(element);
|
|
801
|
+
const { width, height } = getRect(window);
|
|
802
|
+
const xInViewport = left <= width && right >= 0;
|
|
803
|
+
const yInViewport = top <= height && bottom >= 0;
|
|
804
|
+
return xInViewport && yInViewport;
|
|
580
805
|
}
|
|
806
|
+
|
|
807
|
+
// src/util/prettyJSONObject.ts
|
|
581
808
|
function prettyJSONObject(jsonObject) {
|
|
582
809
|
return JSON.stringify(jsonObject, null, 2);
|
|
583
810
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
});
|
|
811
|
+
|
|
812
|
+
// src/util/preventDefault.ts
|
|
813
|
+
function preventDefault(event) {
|
|
814
|
+
if (event.cancelable === false) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
event.preventDefault();
|
|
592
818
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
if (suffix[0] === "$") {
|
|
601
|
-
return suffix.replace("$", namespace);
|
|
602
|
-
}
|
|
603
|
-
return suffix.startsWith("--") ? `${componentName}${suffix}` : `${componentName}__${suffix}`;
|
|
604
|
-
};
|
|
605
|
-
return {
|
|
606
|
-
name: pascalCase(componentName),
|
|
607
|
-
n: createBEM,
|
|
608
|
-
classes
|
|
609
|
-
};
|
|
610
|
-
};
|
|
819
|
+
|
|
820
|
+
// src/util/raf.ts
|
|
821
|
+
function raf() {
|
|
822
|
+
return new Promise((resolve) => {
|
|
823
|
+
requestAnimationFrame(resolve);
|
|
824
|
+
});
|
|
611
825
|
}
|
|
826
|
+
|
|
827
|
+
// src/util/storage.ts
|
|
612
828
|
function createStorage(storage) {
|
|
613
829
|
return __spreadProps(__spreadValues({}, storage), {
|
|
614
830
|
set(key3, value) {
|
|
@@ -633,23 +849,43 @@ function createStorage(storage) {
|
|
|
633
849
|
}
|
|
634
850
|
});
|
|
635
851
|
}
|
|
636
|
-
var sessionStorage = createStorage(
|
|
637
|
-
var localStorage = createStorage(
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
document.execCommand("copy");
|
|
647
|
-
document.body.removeChild(textArea);
|
|
852
|
+
var sessionStorage = createStorage(getGlobalThis().sessionStorage);
|
|
853
|
+
var localStorage = createStorage(getGlobalThis().localStorage);
|
|
854
|
+
|
|
855
|
+
// src/util/tryParseJSON.ts
|
|
856
|
+
function tryParseJSON(json) {
|
|
857
|
+
try {
|
|
858
|
+
return JSON.parse(json);
|
|
859
|
+
} catch (e) {
|
|
860
|
+
return void 0;
|
|
861
|
+
}
|
|
648
862
|
}
|
|
649
863
|
|
|
650
|
-
// src/function.ts
|
|
651
|
-
function
|
|
864
|
+
// src/function/call.ts
|
|
865
|
+
function call(fn, ...args) {
|
|
866
|
+
if (isArray(fn)) {
|
|
867
|
+
return fn.map((f) => f(...args));
|
|
868
|
+
}
|
|
869
|
+
if (fn) {
|
|
870
|
+
return fn(...args);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// src/function/once.ts
|
|
875
|
+
function once(fn) {
|
|
876
|
+
let called = false;
|
|
877
|
+
let result;
|
|
878
|
+
return function(...args) {
|
|
879
|
+
if (called) {
|
|
880
|
+
return result;
|
|
881
|
+
}
|
|
882
|
+
called = true;
|
|
883
|
+
result = fn.apply(this, args);
|
|
884
|
+
return result;
|
|
885
|
+
};
|
|
652
886
|
}
|
|
887
|
+
|
|
888
|
+
// src/function/debounce.ts
|
|
653
889
|
function debounce(fn, delay2 = 0) {
|
|
654
890
|
let timer;
|
|
655
891
|
return function(...args) {
|
|
@@ -661,6 +897,8 @@ function debounce(fn, delay2 = 0) {
|
|
|
661
897
|
}, delay2);
|
|
662
898
|
};
|
|
663
899
|
}
|
|
900
|
+
|
|
901
|
+
// src/function/throttle.ts
|
|
664
902
|
function throttle(fn, delay2 = 200) {
|
|
665
903
|
let timer;
|
|
666
904
|
let start = 0;
|
|
@@ -683,95 +921,12 @@ function throttle(fn, delay2 = 200) {
|
|
|
683
921
|
}
|
|
684
922
|
};
|
|
685
923
|
}
|
|
686
|
-
function call(fn, ...args) {
|
|
687
|
-
if (isArray(fn)) {
|
|
688
|
-
return fn.map((f) => f(...args));
|
|
689
|
-
}
|
|
690
|
-
if (fn) {
|
|
691
|
-
return fn(...args);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
function once(fn) {
|
|
695
|
-
let called = false;
|
|
696
|
-
let result;
|
|
697
|
-
return function(...args) {
|
|
698
|
-
if (called) {
|
|
699
|
-
return result;
|
|
700
|
-
}
|
|
701
|
-
called = true;
|
|
702
|
-
result = fn.apply(this, args);
|
|
703
|
-
return result;
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
924
|
|
|
707
|
-
// src/
|
|
708
|
-
function
|
|
709
|
-
if (val == null) {
|
|
710
|
-
return 0;
|
|
711
|
-
}
|
|
712
|
-
if (isString(val)) {
|
|
713
|
-
val = parseFloat(val);
|
|
714
|
-
val = Number.isNaN(val) ? 0 : val;
|
|
715
|
-
return val;
|
|
716
|
-
}
|
|
717
|
-
if (isBoolean(val)) {
|
|
718
|
-
return Number(val);
|
|
719
|
-
}
|
|
720
|
-
return val;
|
|
721
|
-
}
|
|
722
|
-
function clamp(num, min, max) {
|
|
723
|
-
return Math.min(max, Math.max(min, num));
|
|
724
|
-
}
|
|
725
|
-
function clampArrayRange(index, arr) {
|
|
726
|
-
return clamp(index, 0, arr.length - 1);
|
|
727
|
-
}
|
|
728
|
-
var key2 = 0;
|
|
729
|
-
function genNumberKey() {
|
|
730
|
-
return key2++;
|
|
731
|
-
}
|
|
732
|
-
function randomNumber(min = 0, max = 100) {
|
|
733
|
-
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
734
|
-
}
|
|
735
|
-
function times(num, fn) {
|
|
736
|
-
return Array.from({ length: num }, (_, index) => fn(index));
|
|
737
|
-
}
|
|
738
|
-
function delay(time) {
|
|
739
|
-
return new Promise((resolve) => {
|
|
740
|
-
setTimeout(resolve, time);
|
|
741
|
-
});
|
|
925
|
+
// src/function/NOOP.ts
|
|
926
|
+
function NOOP() {
|
|
742
927
|
}
|
|
743
928
|
|
|
744
|
-
// src/collection.ts
|
|
745
|
-
function mergeWith(object, source, fn) {
|
|
746
|
-
function baseMerge(target, src) {
|
|
747
|
-
for (const key3 in src) {
|
|
748
|
-
if (hasOwn(src, key3)) {
|
|
749
|
-
const srcValue = src[key3];
|
|
750
|
-
const targetValue = target[key3];
|
|
751
|
-
const customResult = fn(targetValue, srcValue, key3, object, source);
|
|
752
|
-
if (customResult !== void 0) {
|
|
753
|
-
target[key3] = customResult;
|
|
754
|
-
} else if (isObject(srcValue)) {
|
|
755
|
-
if (isObject(targetValue)) {
|
|
756
|
-
target[key3] = baseMerge(targetValue, srcValue);
|
|
757
|
-
} else {
|
|
758
|
-
target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
|
|
759
|
-
}
|
|
760
|
-
} else {
|
|
761
|
-
target[key3] = srcValue;
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
return target;
|
|
766
|
-
}
|
|
767
|
-
return baseMerge(object, source);
|
|
768
|
-
}
|
|
769
|
-
function merge(object, source) {
|
|
770
|
-
return mergeWith(object, source, () => void 0);
|
|
771
|
-
}
|
|
772
|
-
function cloneDeep(value) {
|
|
773
|
-
return cloneDeepWith(value, () => void 0);
|
|
774
|
-
}
|
|
929
|
+
// src/collection/cloneDeepWith.ts
|
|
775
930
|
function cloneDeepWith(value, fn) {
|
|
776
931
|
const cache = /* @__PURE__ */ new WeakMap();
|
|
777
932
|
function baseCloneDeep(value2, cache2) {
|
|
@@ -852,66 +1007,102 @@ function cloneDeepWith(value, fn) {
|
|
|
852
1007
|
return baseCloneDeep(value, cache);
|
|
853
1008
|
}
|
|
854
1009
|
|
|
855
|
-
// src/
|
|
856
|
-
function
|
|
1010
|
+
// src/collection/cloneDeep.ts
|
|
1011
|
+
function cloneDeep(value) {
|
|
1012
|
+
return cloneDeepWith(value, () => void 0);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// src/collection/mergeWith.ts
|
|
1016
|
+
function mergeWith(object, source, fn) {
|
|
1017
|
+
function baseMerge(target, src) {
|
|
1018
|
+
for (const key3 in src) {
|
|
1019
|
+
if (hasOwn(src, key3)) {
|
|
1020
|
+
const srcValue = src[key3];
|
|
1021
|
+
const targetValue = target[key3];
|
|
1022
|
+
const customResult = fn(targetValue, srcValue, key3, object, source);
|
|
1023
|
+
if (customResult !== void 0) {
|
|
1024
|
+
target[key3] = customResult;
|
|
1025
|
+
} else if (isObject(srcValue)) {
|
|
1026
|
+
if (isObject(targetValue)) {
|
|
1027
|
+
target[key3] = baseMerge(targetValue, srcValue);
|
|
1028
|
+
} else {
|
|
1029
|
+
target[key3] = baseMerge(isArray(srcValue) ? [] : {}, srcValue);
|
|
1030
|
+
}
|
|
1031
|
+
} else {
|
|
1032
|
+
target[key3] = srcValue;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
return target;
|
|
1037
|
+
}
|
|
1038
|
+
return baseMerge(object, source);
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
// src/collection/merge.ts
|
|
1042
|
+
function merge(object, source) {
|
|
1043
|
+
return mergeWith(object, source, () => void 0);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
// src/file/toArrayBuffer.ts
|
|
1047
|
+
function toArrayBuffer(file) {
|
|
857
1048
|
return new Promise((resolve) => {
|
|
858
1049
|
const fileReader = new FileReader();
|
|
859
1050
|
fileReader.onload = () => {
|
|
860
1051
|
resolve(fileReader.result);
|
|
861
1052
|
};
|
|
862
|
-
fileReader.
|
|
1053
|
+
fileReader.readAsArrayBuffer(file);
|
|
863
1054
|
});
|
|
864
1055
|
}
|
|
865
|
-
|
|
1056
|
+
|
|
1057
|
+
// src/file/toDataURL.ts
|
|
1058
|
+
function toDataURL(file) {
|
|
866
1059
|
return new Promise((resolve) => {
|
|
867
1060
|
const fileReader = new FileReader();
|
|
868
1061
|
fileReader.onload = () => {
|
|
869
1062
|
resolve(fileReader.result);
|
|
870
1063
|
};
|
|
871
|
-
fileReader.
|
|
1064
|
+
fileReader.readAsDataURL(file);
|
|
872
1065
|
});
|
|
873
1066
|
}
|
|
874
|
-
|
|
1067
|
+
|
|
1068
|
+
// src/file/toText.ts
|
|
1069
|
+
function toText(file) {
|
|
875
1070
|
return new Promise((resolve) => {
|
|
876
1071
|
const fileReader = new FileReader();
|
|
877
1072
|
fileReader.onload = () => {
|
|
878
1073
|
resolve(fileReader.result);
|
|
879
1074
|
};
|
|
880
|
-
fileReader.
|
|
1075
|
+
fileReader.readAsText(file);
|
|
881
1076
|
});
|
|
882
1077
|
}
|
|
883
1078
|
|
|
884
|
-
// src/math.ts
|
|
885
|
-
function sum(arr) {
|
|
886
|
-
return arr.reduce((ret, val) => ret + val, 0);
|
|
887
|
-
}
|
|
888
|
-
function sumBy(arr, fn) {
|
|
889
|
-
return arr.reduce((ret, val) => ret + fn(val), 0);
|
|
890
|
-
}
|
|
891
|
-
function minBy(arr, fn) {
|
|
892
|
-
if (!arr.length) {
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
return arr.reduce((result, item) => fn(result) < fn(item) ? result : item, arr[0]);
|
|
896
|
-
}
|
|
1079
|
+
// src/math/maxBy.ts
|
|
897
1080
|
function maxBy(arr, fn) {
|
|
898
1081
|
if (!arr.length) {
|
|
899
1082
|
return;
|
|
900
1083
|
}
|
|
901
1084
|
return arr.reduce((result, item) => fn(result) > fn(item) ? result : item, arr[0]);
|
|
902
1085
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
function meanBy(arr, fn) {
|
|
907
|
-
return sumBy(arr, fn) / arr.length;
|
|
908
|
-
}
|
|
909
|
-
function sample(arr) {
|
|
1086
|
+
|
|
1087
|
+
// src/math/minBy.ts
|
|
1088
|
+
function minBy(arr, fn) {
|
|
910
1089
|
if (!arr.length) {
|
|
911
1090
|
return;
|
|
912
1091
|
}
|
|
913
|
-
return arr
|
|
1092
|
+
return arr.reduce((result, item) => fn(result) < fn(item) ? result : item, arr[0]);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
// src/math/sum.ts
|
|
1096
|
+
function sum(arr) {
|
|
1097
|
+
return arr.reduce((ret, val) => ret + val, 0);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/math/sumBy.ts
|
|
1101
|
+
function sumBy(arr, fn) {
|
|
1102
|
+
return arr.reduce((ret, val) => ret + fn(val), 0);
|
|
914
1103
|
}
|
|
1104
|
+
|
|
1105
|
+
// src/math/sumHash.ts
|
|
915
1106
|
function sumHash(value) {
|
|
916
1107
|
function sum2(hash, value2) {
|
|
917
1108
|
for (let i = 0; i < value2.length; i++) {
|
|
@@ -947,6 +1138,24 @@ function sumHash(value) {
|
|
|
947
1138
|
return baseSumHash(0, value, "", []).toString(16).padStart(8, "0");
|
|
948
1139
|
}
|
|
949
1140
|
|
|
1141
|
+
// src/math/mean.ts
|
|
1142
|
+
function mean(arr) {
|
|
1143
|
+
return sum(arr) / arr.length;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// src/math/meanBy.ts
|
|
1147
|
+
function meanBy(arr, fn) {
|
|
1148
|
+
return sumBy(arr, fn) / arr.length;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/math/sample.ts
|
|
1152
|
+
function sample(arr) {
|
|
1153
|
+
if (!arr.length) {
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
return arr[randomNumber(0, arr.length - 1)];
|
|
1157
|
+
}
|
|
1158
|
+
|
|
950
1159
|
// src/index.ts
|
|
951
1160
|
__reExport(src_exports, require("mitt"), module.exports);
|
|
952
1161
|
var import_mitt = __toESM(require("mitt"), 1);
|
|
@@ -957,6 +1166,7 @@ var import_mitt = __toESM(require("mitt"), 1);
|
|
|
957
1166
|
call,
|
|
958
1167
|
camelize,
|
|
959
1168
|
cancelAnimationFrame,
|
|
1169
|
+
chunk,
|
|
960
1170
|
clamp,
|
|
961
1171
|
clampArrayRange,
|
|
962
1172
|
classes,
|
|
@@ -968,6 +1178,8 @@ var import_mitt = __toESM(require("mitt"), 1);
|
|
|
968
1178
|
debounce,
|
|
969
1179
|
delay,
|
|
970
1180
|
doubleRaf,
|
|
1181
|
+
ensurePrefix,
|
|
1182
|
+
ensureSuffix,
|
|
971
1183
|
find,
|
|
972
1184
|
genNumberKey,
|
|
973
1185
|
genStringKey,
|