@ntnyq/utils 0.6.4 → 0.7.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.cjs DELETED
@@ -1,928 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- Color: () => Color,
24
- NOOP: () => NOOP,
25
- RE_BLOCK_COMMENT: () => RE_BLOCK_COMMENT,
26
- RE_COMMENTS: () => RE_COMMENTS,
27
- RE_LINE_COMMENT: () => RE_LINE_COMMENT,
28
- SPECIAL_CHAR: () => SPECIAL_CHAR,
29
- at: () => at,
30
- cAF: () => cAF,
31
- chunk: () => chunk,
32
- clamp: () => clamp,
33
- cleanObject: () => cleanObject,
34
- createPadString: () => createPadString,
35
- days: () => days,
36
- debounce: () => debounce,
37
- enhance: () => enhance,
38
- ensurePrefix: () => ensurePrefix,
39
- ensureSuffix: () => ensureSuffix,
40
- escapeHTML: () => escapeHTML,
41
- flattenArrayable: () => flattenArrayable,
42
- getObjectType: () => getObjectType,
43
- hasOwn: () => hasOwn,
44
- hours: () => hours,
45
- interopDefault: () => interopDefault,
46
- intersect: () => intersect,
47
- isArray: () => isArray,
48
- isArrayEqual: () => isArrayEqual,
49
- isBigInt: () => isBigInt,
50
- isBoolean: () => isBoolean,
51
- isBrowser: () => isBrowser,
52
- isDeepEqual: () => isDeepEqual,
53
- isElementVisibleInViewport: () => isElementVisibleInViewport,
54
- isEmptyArray: () => isEmptyArray,
55
- isEmptyMap: () => isEmptyMap,
56
- isEmptyObject: () => isEmptyObject,
57
- isEmptySet: () => isEmptySet,
58
- isEmptyString: () => isEmptyString,
59
- isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
60
- isError: () => isError,
61
- isFunction: () => isFunction,
62
- isHTMLElement: () => isHTMLElement,
63
- isInteger: () => isInteger,
64
- isIterable: () => isIterable,
65
- isMap: () => isMap,
66
- isNaN: () => isNaN,
67
- isNativePromise: () => isNativePromise,
68
- isNil: () => isNil,
69
- isNonEmptyArray: () => isNonEmptyArray,
70
- isNonEmptyString: () => isNonEmptyString,
71
- isNull: () => isNull,
72
- isNullOrUndefined: () => isNullOrUndefined,
73
- isNumber: () => isNumber,
74
- isNumbericString: () => isNumbericString,
75
- isObject: () => isObject,
76
- isPromise: () => isPromise,
77
- isRegExp: () => isRegExp,
78
- isSet: () => isSet,
79
- isString: () => isString,
80
- isTruthy: () => isTruthy,
81
- isUndefined: () => isUndefined,
82
- isWhitespaceString: () => isWhitespaceString,
83
- isZero: () => isZero,
84
- join: () => join,
85
- last: () => last,
86
- mergeArrayable: () => mergeArrayable,
87
- minutes: () => minutes,
88
- noop: () => noop,
89
- omit: () => omit,
90
- once: () => once,
91
- openExternalURL: () => openExternalURL,
92
- pick: () => pick,
93
- rAF: () => rAF,
94
- randomHexColor: () => randomHexColor,
95
- randomNumber: () => randomNumber,
96
- randomRGBAColor: () => randomRGBAColor,
97
- randomRGBColor: () => randomRGBColor,
98
- randomString: () => randomString,
99
- resolveSubOptions: () => resolveSubOptions,
100
- scrollElementIntoView: () => scrollElementIntoView,
101
- seconds: () => seconds,
102
- slash: () => slash,
103
- slugify: () => slugify,
104
- sortObject: () => sortObject,
105
- throttle: () => throttle,
106
- toArray: () => toArray,
107
- unescapeHTML: () => unescapeHTML,
108
- unindent: () => unindent,
109
- unique: () => unique,
110
- uniqueBy: () => uniqueBy,
111
- waitFor: () => waitFor,
112
- warnOnce: () => warnOnce,
113
- weeks: () => weeks
114
- });
115
- module.exports = __toCommonJS(index_exports);
116
-
117
- // src/fn/noop.ts
118
- function noop() {
119
- }
120
- var NOOP = noop;
121
-
122
- // src/fn/once.ts
123
- function once(func) {
124
- let called = false;
125
- return function(...args) {
126
- if (called) {
127
- return false;
128
- }
129
- called = true;
130
- func.apply(this, args);
131
- return true;
132
- };
133
- }
134
-
135
- // src/is/dom.ts
136
- function isHTMLElement(value) {
137
- return typeof value === "object" && value !== null && "nodeType" in value && value.nodeType === Node.ELEMENT_NODE && value instanceof HTMLElement;
138
- }
139
-
140
- // src/is/core.ts
141
- function getObjectType(value) {
142
- return Object.prototype.toString.call(value).slice(8, -1);
143
- }
144
- function isUndefined(value) {
145
- return value === void 0;
146
- }
147
- function isNull(value) {
148
- return value === null;
149
- }
150
- function isNil(value) {
151
- return isNull(value) || isUndefined(value);
152
- }
153
- var isNullOrUndefined = isNil;
154
- function isString(value) {
155
- return typeof value === "string";
156
- }
157
- function isEmptyString(value) {
158
- return isString(value) && value.length === 0;
159
- }
160
- function isNonEmptyString(value) {
161
- return isString(value) && value.length > 0;
162
- }
163
- function isWhitespaceString(value) {
164
- return isString(value) && /^\s*$/.test(value);
165
- }
166
- function isEmptyStringOrWhitespace(value) {
167
- return isEmptyString(value) || isWhitespaceString(value);
168
- }
169
- function isNumbericString(value) {
170
- return isString(value) && !isEmptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
171
- }
172
- function isNumber(value) {
173
- return typeof value === "number";
174
- }
175
- function isZero(value) {
176
- return value === 0;
177
- }
178
- function isNaN(value) {
179
- return Number.isNaN(value);
180
- }
181
- function isInteger(value) {
182
- return Number.isInteger(value);
183
- }
184
- function isBigInt(value) {
185
- return typeof value === "bigint";
186
- }
187
- function isBoolean(value) {
188
- return typeof value === "boolean";
189
- }
190
- function isTruthy(value) {
191
- return Boolean(value);
192
- }
193
- function isFunction(value) {
194
- return typeof value === "function";
195
- }
196
- function isArray(value) {
197
- return Array.isArray(value);
198
- }
199
- function isEmptyArray(value) {
200
- return isArray(value) && value.length === 0;
201
- }
202
- function isNonEmptyArray(value) {
203
- return isArray(value) && value.length > 0;
204
- }
205
- function isObject(value) {
206
- return (typeof value === "object" || isFunction(value)) && !isNull(value);
207
- }
208
- function isEmptyObject(value) {
209
- return isObject(value) && !isMap(value) && !isSet(value) && Object.keys(value).length === 0;
210
- }
211
- function isMap(value) {
212
- return getObjectType(value) === "Map";
213
- }
214
- function isEmptyMap(value) {
215
- return isMap(value) && value.size === 0;
216
- }
217
- function isSet(value) {
218
- return getObjectType(value) === "Set";
219
- }
220
- function isEmptySet(value) {
221
- return isSet(value) && value.size === 0;
222
- }
223
- function isRegExp(value) {
224
- return getObjectType(value) === "RegExp";
225
- }
226
- function isError(value) {
227
- return getObjectType(value) === "Error";
228
- }
229
- function hasPromiseApi(value) {
230
- return (
231
- // eslint-disable-next-line @typescript-eslint/unbound-method
232
- isFunction(value?.then) && isFunction(value?.catch)
233
- );
234
- }
235
- function isNativePromise(value) {
236
- return getObjectType(value) === "Promise";
237
- }
238
- function isPromise(value) {
239
- return isNativePromise(value) || hasPromiseApi(value);
240
- }
241
- function isIterable(value) {
242
- return isFunction(value?.[Symbol.iterator]);
243
- }
244
-
245
- // src/is/isDeepEqual.ts
246
- function isDeepEqual(value1, value2) {
247
- const type1 = getObjectType(value1);
248
- const type2 = getObjectType(value2);
249
- if (type1 !== type2) {
250
- return false;
251
- }
252
- if (isArray(value1) && isArray(value2)) {
253
- if (value1.length !== value2.length) {
254
- return false;
255
- }
256
- return value1.every((item, index) => isDeepEqual(item, value2[index]));
257
- }
258
- if (isObject(value1) && isObject(value2)) {
259
- const keys = Object.keys(value1);
260
- if (keys.length !== Object.keys(value2).length) {
261
- return false;
262
- }
263
- return keys.every(
264
- (key) => isDeepEqual(
265
- value1[key],
266
- value2[key]
267
- )
268
- );
269
- }
270
- return Object.is(value1, value2);
271
- }
272
-
273
- // src/dom/scrollIntoView.ts
274
- function scrollElementIntoView(element, options = {}) {
275
- const body = document.body;
276
- const { parent = body, ...scrollIntoViewOptions } = options;
277
- if (parent === body) {
278
- parent.scrollIntoView(scrollIntoViewOptions);
279
- return;
280
- }
281
- const parentRect = parent.getBoundingClientRect();
282
- const elementRect = element.getBoundingClientRect();
283
- const isHorizontal = parent.scrollWidth > parent.scrollHeight;
284
- const isOutOfView = isHorizontal ? elementRect.left < parentRect.left || elementRect.right > parentRect.right : elementRect.top < parentRect.top || elementRect.bottom > parentRect.bottom;
285
- if (isOutOfView) {
286
- parent.scrollIntoView(scrollIntoViewOptions);
287
- }
288
- }
289
-
290
- // src/dom/openExternalURL.ts
291
- function openExternalURL(url, options = {}) {
292
- const { target = "_blank" } = options;
293
- const proxy = window.open(url, target);
294
- return proxy;
295
- }
296
-
297
- // src/dom/isVisibleInViewport.ts
298
- function isElementVisibleInViewport(element, targetWindow = window) {
299
- const { top, left, bottom, right } = element.getBoundingClientRect();
300
- const { innerWidth, innerHeight } = targetWindow;
301
- return (top >= 0 && top <= innerHeight || bottom >= 0 && bottom <= innerHeight) && (left >= 0 && left <= innerWidth || right >= 0 && right <= innerWidth);
302
- }
303
-
304
- // src/env/isBrowser.ts
305
- var isBrowser = () => typeof document !== "undefined";
306
-
307
- // src/html/escape.ts
308
- var htmlEscapeMap = {
309
- "&": "&amp;",
310
- "<": "&lt;",
311
- ">": "&gt;",
312
- "'": "&#39;",
313
- '"': "&quot;"
314
- };
315
- var htmlEscapeRegexp = /[&<>'"]/g;
316
- function escapeHTML(str) {
317
- return str.replace(
318
- htmlEscapeRegexp,
319
- (char) => htmlEscapeMap[char]
320
- );
321
- }
322
- var htmlUnescapeMap = {
323
- "&amp;": "&",
324
- "&#38;": "&",
325
- "&lt;": "<",
326
- "&#60;": "<",
327
- "&gt;": ">",
328
- "&#62;": ">",
329
- "&apos;": "'",
330
- "&#39;": "'",
331
- "&quot;": '"',
332
- "&#34;": '"'
333
- };
334
- var htmlUnescapeRegexp = /&(amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
335
- function unescapeHTML(str) {
336
- return str.replace(
337
- htmlUnescapeRegexp,
338
- (char) => htmlUnescapeMap[char]
339
- );
340
- }
341
-
342
- // src/misc/raf.ts
343
- var root = isBrowser() ? window : globalThis;
344
- var prev = Date.now();
345
- function mockRAF(fn) {
346
- const curr = Date.now();
347
- const ms = Math.max(0, 16 - (curr - prev));
348
- const id = setTimeout(fn, ms);
349
- prev = curr + ms;
350
- return id;
351
- }
352
- function rAF(fn) {
353
- const raf = root.requestAnimationFrame || mockRAF;
354
- return raf.call(root, fn);
355
- }
356
- function cAF(id) {
357
- const caf = root.cancelAnimationFrame || root.clearTimeout;
358
- return caf.call(root, id);
359
- }
360
-
361
- // src/misc/time.ts
362
- var ONE_SECOND = 1e3;
363
- var ONE_MINUTE = 60 * ONE_SECOND;
364
- var ONE_HOUR = 60 * ONE_MINUTE;
365
- var ONE_DAY = 24 * ONE_HOUR;
366
- var ONE_WEEK = 7 * ONE_DAY;
367
- function seconds(count) {
368
- return count * ONE_SECOND;
369
- }
370
- function minutes(count) {
371
- return count * ONE_MINUTE;
372
- }
373
- function hours(count) {
374
- return count * ONE_HOUR;
375
- }
376
- function days(count) {
377
- return count * ONE_DAY;
378
- }
379
- function weeks(count) {
380
- return count * ONE_WEEK;
381
- }
382
-
383
- // src/misc/clamp.ts
384
- function clamp(value, min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY) {
385
- return Math.min(Math.max(value, min), max);
386
- }
387
-
388
- // src/misc/waitFor.ts
389
- async function waitFor(ms) {
390
- return new Promise((resolve) => setTimeout(resolve, ms));
391
- }
392
-
393
- // src/misc/throttle.ts
394
- function throttle(delay, callback, options = {}) {
395
- const { isDebounce } = options;
396
- let lastExec = 0;
397
- let cancelled = false;
398
- let timeoutId;
399
- function clearExistingTimeout() {
400
- if (timeoutId) {
401
- clearTimeout(timeoutId);
402
- }
403
- }
404
- function cancel() {
405
- clearExistingTimeout();
406
- cancelled = true;
407
- }
408
- function wrapper(...args) {
409
- if (cancelled) return;
410
- const _this = this;
411
- const now = Date.now();
412
- const elapsed = now - lastExec;
413
- function clear() {
414
- timeoutId = void 0;
415
- }
416
- function exec(cur) {
417
- lastExec = cur || Date.now();
418
- callback.apply(_this, args);
419
- }
420
- if (isDebounce && !timeoutId) {
421
- exec(now);
422
- }
423
- clearExistingTimeout();
424
- if (!isDebounce && elapsed > delay) {
425
- exec(now);
426
- } else {
427
- timeoutId = setTimeout(
428
- isDebounce ? clear : exec,
429
- isDebounce ? delay : delay - elapsed
430
- );
431
- }
432
- }
433
- wrapper.cancel = cancel;
434
- return wrapper;
435
- }
436
- function debounce(delay, callback, options = {}) {
437
- return throttle(delay, callback, {
438
- ...options,
439
- isDebounce: true
440
- });
441
- }
442
-
443
- // src/misc/warnOnce.ts
444
- var warned = /* @__PURE__ */ new Set();
445
- function warnOnce(message) {
446
- if (warned.has(message)) {
447
- return;
448
- }
449
- warned.add(message);
450
- console.warn(message);
451
- }
452
-
453
- // src/array/at.ts
454
- function at(array, index) {
455
- const length = array.length;
456
- if (!length) return void 0;
457
- if (index < 0) {
458
- index += length;
459
- }
460
- return array[index];
461
- }
462
- function last(array) {
463
- return at(array, -1);
464
- }
465
-
466
- // src/array/chunk.ts
467
- function chunk(array, size) {
468
- const result = [];
469
- for (let i = 0; i < array.length; i += size) {
470
- result.push(array.slice(i, i + size));
471
- }
472
- return result;
473
- }
474
-
475
- // src/array/unique.ts
476
- function unique(array) {
477
- return Array.from(new Set(array));
478
- }
479
- function uniqueBy(array, equalFn) {
480
- return array.reduce((acc, cur) => {
481
- const idx = acc.findIndex((item) => equalFn(item, cur));
482
- if (idx === -1) {
483
- acc.push(cur);
484
- }
485
- return acc;
486
- }, []);
487
- }
488
-
489
- // src/array/toArray.ts
490
- function toArray(array) {
491
- array = array ?? [];
492
- return Array.isArray(array) ? array : [array];
493
- }
494
-
495
- // src/array/arrayable.ts
496
- function flattenArrayable(array) {
497
- return toArray(array).flat(1);
498
- }
499
- function mergeArrayable(...args) {
500
- return args.flatMap((i) => toArray(i));
501
- }
502
-
503
- // src/array/intersect.ts
504
- function intersect(a, b) {
505
- return a.filter((item) => b.includes(item));
506
- }
507
-
508
- // src/array/isArrayEqual.ts
509
- function isArrayEqual(array1, array2) {
510
- if (array1.length !== array2.length) {
511
- return false;
512
- }
513
- return array1.every((item, idx) => item === array2[idx]);
514
- }
515
-
516
- // src/string/pad.ts
517
- function createPadString(options) {
518
- const { length, char } = options;
519
- return (value) => (char.repeat(length) + value).slice(-length);
520
- }
521
-
522
- // src/string/join.ts
523
- function join(array, options = {}) {
524
- const { separator = "" } = options;
525
- if (!Array.isArray(array) || !array.length) return "";
526
- return array.filter((v) => Boolean(v) || v === 0).join(separator);
527
- }
528
-
529
- // src/string/slash.ts
530
- function slash(input) {
531
- return input.replace(/\\/g, "/");
532
- }
533
-
534
- // src/number/random.ts
535
- function randomNumber(min, max = 0, options = {}) {
536
- if (max === 0) {
537
- max = min;
538
- min = 0;
539
- }
540
- if (min > max) {
541
- ;
542
- [min, max] = [max, min];
543
- }
544
- return Math.trunc(
545
- Math.random() * (max - min + (options.includeMax ? 1 : 0)) + min
546
- );
547
- }
548
-
549
- // src/string/random.ts
550
- function randomString(length = 16, chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
551
- const result = [];
552
- for (let i = length; i > 0; --i) {
553
- result.push(chars[randomNumber(chars.length)]);
554
- }
555
- return result.join("");
556
- }
557
-
558
- // src/string/slugify.ts
559
- var rControl = /[\u0000-\u001F]/g;
560
- var rSpecial = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
561
- var rCombining = /[\u0300-\u036F]/g;
562
- function slugify(str) {
563
- return str.normalize("NFKD").replace(rCombining, "").replace(rControl, "").replace(rSpecial, "-").replace(/-{2,}/g, "-").replace(/^-+|-+$/g, "").replace(/^(\d)/, "_$1").toLowerCase();
564
- }
565
-
566
- // src/string/unindent.ts
567
- var _RE_FULL_WS = /^\s*$/;
568
- function unindent(input) {
569
- const lines = (typeof input === "string" ? input : input[0]).split("\n");
570
- const whitespaceLines = lines.map((line) => _RE_FULL_WS.test(line));
571
- const commonIndent = lines.reduce((min, line, idx) => {
572
- if (whitespaceLines[idx]) {
573
- return min;
574
- }
575
- const indent = line.match(/^\s*/)?.[0].length;
576
- return indent === void 0 ? min : Math.min(min, indent);
577
- }, Number.POSITIVE_INFINITY);
578
- let emptylinesHead = 0;
579
- while (emptylinesHead < lines.length && whitespaceLines[emptylinesHead]) {
580
- emptylinesHead++;
581
- }
582
- let emptylinesTail = 0;
583
- while (emptylinesTail < lines.length && whitespaceLines[lines.length - emptylinesTail - 1]) {
584
- emptylinesTail++;
585
- }
586
- return lines.slice(emptylinesHead, lines.length - emptylinesTail).map((line) => line.slice(commonIndent)).join("\n");
587
- }
588
-
589
- // src/string/ensurePrefix.ts
590
- function ensurePrefix(input, prefix) {
591
- return input.startsWith(prefix) ? input : `${prefix}${input}`;
592
- }
593
-
594
- // src/string/ensureSuffix.ts
595
- function ensureSuffix(input, suffix) {
596
- return input.endsWith(suffix) ? input : `${input}${suffix}`;
597
- }
598
-
599
- // src/color/color.ts
600
- var pad2 = createPadString({ length: 2, char: "0" });
601
- var RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
602
- function validateHexColor(hex) {
603
- if (hex.length !== 4 && hex.length !== 7) return false;
604
- if (!hex.startsWith("#")) return false;
605
- return RE_VALID_HEX_COLOR.test(hex);
606
- }
607
- function normalizeHexString(hex) {
608
- return hex.length === 6 ? hex : hex.replace(/./g, "$&$&");
609
- }
610
- var Color = class _Color {
611
- red = 0;
612
- green = 0;
613
- blue = 0;
614
- alpha = 1;
615
- constructor(red = 0, green = 0, blue = 0, alpha = 1) {
616
- this.red = red;
617
- this.green = green;
618
- this.blue = blue;
619
- this.alpha = alpha;
620
- }
621
- static fromRGB(red, green, blue) {
622
- return new _Color(red, green, blue);
623
- }
624
- static fromRGBA(red, green, blue, alpha) {
625
- return new _Color(red, green, blue, alpha);
626
- }
627
- static fromHex(hex) {
628
- if (!validateHexColor(hex)) {
629
- throw new Error("Invalid hex color");
630
- }
631
- const [red, green, blue] = normalizeHexString(hex.slice(1)).match(/.{2}/g)?.map((value) => Number.parseInt(value, 16)) ?? [0, 0, 0];
632
- return new _Color(red, green, blue);
633
- }
634
- get brightness() {
635
- return (this.red * 299 + this.green * 587 + this.blue * 114) / 1e3;
636
- }
637
- get isDark() {
638
- return this.brightness < 128;
639
- }
640
- get isLight() {
641
- return !this.isDark;
642
- }
643
- toHexString(isUpperCase = true) {
644
- const hexString = `#${pad2(this.red.toString(16))}${pad2(this.green.toString(16))}${pad2(this.blue.toString(16))}`;
645
- return isUpperCase ? hexString.toUpperCase() : hexString;
646
- }
647
- toRGBAString() {
648
- return `rgba(${this.red}, ${this.green}, ${this.blue}, ${this.alpha})`;
649
- }
650
- /**
651
- * add alpha value to {@link Color}
652
- *
653
- * @param alpha - alpha value
654
- * @returns instance of {@link Color}
655
- */
656
- withAlpha(alpha = 1) {
657
- return new _Color(this.red, this.green, this.blue, alpha);
658
- }
659
- /**
660
- * lighten the color by percentage
661
- *
662
- * @param percentage - percentage to lighten
663
- */
664
- lighten(percentage = 0) {
665
- const amount = Math.round(percentage / 100 * 255);
666
- return new _Color(
667
- Math.min(this.red + amount, 255),
668
- Math.min(this.green + amount, 255),
669
- Math.min(this.blue + amount, 255),
670
- this.alpha
671
- );
672
- }
673
- /**
674
- * darken the color by percentage
675
- *
676
- * @param percentage - percentage to darken
677
- */
678
- darken(percentage = 0) {
679
- const amount = Math.round(percentage / 100 * 255);
680
- return new _Color(
681
- Math.max(this.red - amount, 0),
682
- Math.max(this.green - amount, 0),
683
- Math.max(this.blue - amount, 0),
684
- this.alpha
685
- );
686
- }
687
- };
688
-
689
- // src/color/random.ts
690
- var MAX_RGB = 255;
691
- function randomRGBColor() {
692
- return `rgb(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)})`;
693
- }
694
- function randomRGBAColor() {
695
- return `rgba(${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${randomNumber(MAX_RGB)}, ${Math.random().toFixed(1)})`;
696
- }
697
- function randomHexColor() {
698
- return `#${Math.random().toString(16).slice(2, 8)}`;
699
- }
700
-
701
- // src/proxy/enhance.ts
702
- function enhance(module2, extra) {
703
- return new Proxy(module2, {
704
- get(target, key, receiver) {
705
- if (Reflect.has(extra, key)) {
706
- return Reflect.get(extra, key, receiver);
707
- }
708
- return Reflect.get(target, key, receiver);
709
- },
710
- has(target, key) {
711
- return Reflect.has(extra, key) || Reflect.has(target, key);
712
- }
713
- });
714
- }
715
-
716
- // src/module/interopDefault.ts
717
- async function interopDefault(mod) {
718
- const resolved = await mod;
719
- return resolved.default || resolved;
720
- }
721
-
722
- // src/module/resolveSubOptions.ts
723
- function resolveSubOptions(options, key) {
724
- return typeof options[key] === "boolean" ? {} : options[key] || {};
725
- }
726
-
727
- // src/object/omit.ts
728
- function omit(object, ...keys) {
729
- keys.forEach((key) => delete object[key]);
730
- return object;
731
- }
732
-
733
- // src/object/hasOwn.ts
734
- function hasOwn(object, key) {
735
- if (object === null) {
736
- return false;
737
- }
738
- return Object.prototype.hasOwnProperty.call(object, key);
739
- }
740
-
741
- // src/object/pick.ts
742
- function pick(object, keys) {
743
- return Object.assign(
744
- {},
745
- ...keys.map((key) => {
746
- if (object && hasOwn(object, key)) {
747
- return { [key]: object[key] };
748
- }
749
- })
750
- );
751
- }
752
-
753
- // src/object/clean.ts
754
- function cleanObject(obj, options = {}) {
755
- const {
756
- cleanUndefined = true,
757
- cleanNull = true,
758
- cleanNaN = true,
759
- cleanZero = false,
760
- cleanEmptyString = false,
761
- cleanEmptyArray = false,
762
- cleanEmptyObject = false,
763
- recursive = true
764
- } = options;
765
- Object.keys(obj).forEach((key) => {
766
- const v = obj[key];
767
- if (cleanUndefined && isUndefined(v)) {
768
- delete obj[key];
769
- }
770
- if (cleanNull && isNull(v)) {
771
- delete obj[key];
772
- }
773
- if (cleanZero && isZero(v)) {
774
- delete obj[key];
775
- }
776
- if (cleanNaN && isZero(v)) {
777
- delete obj[key];
778
- }
779
- if (cleanEmptyString && isEmptyString(v)) {
780
- delete obj[key];
781
- }
782
- if (cleanEmptyArray && isEmptyArray(v)) {
783
- delete obj[key];
784
- }
785
- if (cleanEmptyObject && isEmptyObject(v)) {
786
- delete obj[key];
787
- }
788
- if (recursive && isObject(v)) {
789
- cleanObject(v, options);
790
- }
791
- });
792
- return obj;
793
- }
794
-
795
- // src/object/isPlainObject.ts
796
- function isPlainObject(value) {
797
- if (!isObject(value)) return false;
798
- const prototype = Object.getPrototypeOf(value);
799
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
800
- }
801
-
802
- // src/object/sortObject.ts
803
- function sortObject(obj, options = {}) {
804
- const { compareFn = (a, b) => a.localeCompare(b) } = options;
805
- function sortKeys(obj2) {
806
- const sortedKeys = Object.keys(obj2).sort(compareFn);
807
- const result = {};
808
- for (const key of sortedKeys) {
809
- const value = obj2[key];
810
- let newValue;
811
- if (options.deep && isPlainObject(value)) {
812
- newValue = sortKeys(value);
813
- } else {
814
- newValue = value;
815
- }
816
- Object.defineProperty(result, key, {
817
- ...Object.getOwnPropertyDescriptor(obj2, key),
818
- value: newValue
819
- });
820
- }
821
- return result;
822
- }
823
- return sortKeys(obj);
824
- }
825
-
826
- // src/constants/char.ts
827
- var SPECIAL_CHAR = {
828
- newline: "\n"
829
- };
830
-
831
- // src/constants/regexp.ts
832
- var RE_COMMENTS = /(?:<!--|\/\*)([\s\S]*?)(?:-->|\*\/)/g;
833
- var RE_LINE_COMMENT = /\/\/.*/;
834
- var RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
835
- // Annotate the CommonJS export names for ESM import in node:
836
- 0 && (module.exports = {
837
- Color,
838
- NOOP,
839
- RE_BLOCK_COMMENT,
840
- RE_COMMENTS,
841
- RE_LINE_COMMENT,
842
- SPECIAL_CHAR,
843
- at,
844
- cAF,
845
- chunk,
846
- clamp,
847
- cleanObject,
848
- createPadString,
849
- days,
850
- debounce,
851
- enhance,
852
- ensurePrefix,
853
- ensureSuffix,
854
- escapeHTML,
855
- flattenArrayable,
856
- getObjectType,
857
- hasOwn,
858
- hours,
859
- interopDefault,
860
- intersect,
861
- isArray,
862
- isArrayEqual,
863
- isBigInt,
864
- isBoolean,
865
- isBrowser,
866
- isDeepEqual,
867
- isElementVisibleInViewport,
868
- isEmptyArray,
869
- isEmptyMap,
870
- isEmptyObject,
871
- isEmptySet,
872
- isEmptyString,
873
- isEmptyStringOrWhitespace,
874
- isError,
875
- isFunction,
876
- isHTMLElement,
877
- isInteger,
878
- isIterable,
879
- isMap,
880
- isNaN,
881
- isNativePromise,
882
- isNil,
883
- isNonEmptyArray,
884
- isNonEmptyString,
885
- isNull,
886
- isNullOrUndefined,
887
- isNumber,
888
- isNumbericString,
889
- isObject,
890
- isPromise,
891
- isRegExp,
892
- isSet,
893
- isString,
894
- isTruthy,
895
- isUndefined,
896
- isWhitespaceString,
897
- isZero,
898
- join,
899
- last,
900
- mergeArrayable,
901
- minutes,
902
- noop,
903
- omit,
904
- once,
905
- openExternalURL,
906
- pick,
907
- rAF,
908
- randomHexColor,
909
- randomNumber,
910
- randomRGBAColor,
911
- randomRGBColor,
912
- randomString,
913
- resolveSubOptions,
914
- scrollElementIntoView,
915
- seconds,
916
- slash,
917
- slugify,
918
- sortObject,
919
- throttle,
920
- toArray,
921
- unescapeHTML,
922
- unindent,
923
- unique,
924
- uniqueBy,
925
- waitFor,
926
- warnOnce,
927
- weeks
928
- });