@maz-ui/utils 4.1.7-beta.0 → 4.1.7-beta.3
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/helpers/TextareaAutogrow.js +5 -5
- package/dist/helpers/camelCase.js +3 -3
- package/dist/helpers/capitalize.js +3 -3
- package/dist/helpers/checkAvailability.js +9 -9
- package/dist/helpers/countryCodeToUnicodeFlag.js +7 -7
- package/dist/helpers/debounce.js +7 -7
- package/dist/helpers/debounceCallback.js +4 -4
- package/dist/helpers/debounceId.js +14 -14
- package/dist/helpers/fetchLocaleIp.js +6 -6
- package/dist/helpers/formatCurrency.js +18 -18
- package/dist/helpers/formatDate.js +10 -10
- package/dist/helpers/formatNumber.js +12 -12
- package/dist/helpers/formatPhoneNumber.js +6 -6
- package/dist/helpers/getBrowserLocale.js +6 -6
- package/dist/helpers/getCountryFlagUrl.js +6 -6
- package/dist/helpers/getErrorMessage.js +3 -3
- package/dist/helpers/idleTimeout.js +27 -27
- package/dist/helpers/index.js +58 -58
- package/dist/helpers/isClient.js +2 -2
- package/dist/helpers/isEqual.js +14 -14
- package/dist/helpers/isServer.js +2 -2
- package/dist/helpers/isStandaloneMode.js +6 -6
- package/dist/helpers/kebabCase.js +3 -3
- package/dist/helpers/normalizeString.js +22 -22
- package/dist/helpers/pascalCase.js +12 -12
- package/dist/helpers/scriptLoader.js +20 -20
- package/dist/helpers/sleep.js +3 -3
- package/dist/helpers/snakeCase.js +3 -3
- package/dist/helpers/swipeHandler.js +22 -22
- package/dist/helpers/throttle.js +7 -7
- package/dist/helpers/throttleId.js +11 -11
- package/dist/helpers/truthyFilter.js +3 -3
- package/dist/helpers/userVisibility.js +8 -8
- package/dist/index.js +58 -58
- package/package.json +2 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { debounce
|
|
2
|
-
class
|
|
1
|
+
import { debounce } from "./debounce.js";
|
|
2
|
+
class TextareaAutogrow {
|
|
3
3
|
element;
|
|
4
|
-
constructor(
|
|
5
|
-
this.element =
|
|
4
|
+
constructor(element) {
|
|
5
|
+
this.element = element, this.onFocus = this.onFocus.bind(this), this.autogrow = this.autogrow.bind(this), this.onResize = debounce(this.onResize.bind(this), 200), this.connect();
|
|
6
6
|
}
|
|
7
7
|
connect() {
|
|
8
8
|
this.element.addEventListener("focus", this.onFocus), this.element.style.resize = "none", this.element.style.boxSizing = "border-box";
|
|
@@ -21,5 +21,5 @@ class o {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
export {
|
|
24
|
-
|
|
24
|
+
TextareaAutogrow
|
|
25
25
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
1
|
+
function checkAvailability(getRef, callback, options) {
|
|
2
|
+
const opts = {
|
|
3
3
|
maxAttempts: 20,
|
|
4
4
|
interval: 100,
|
|
5
|
-
...
|
|
5
|
+
...options
|
|
6
6
|
};
|
|
7
|
-
let
|
|
8
|
-
function
|
|
9
|
-
const
|
|
10
|
-
|
|
7
|
+
let attempts = 0;
|
|
8
|
+
function check() {
|
|
9
|
+
const ref = getRef();
|
|
10
|
+
ref != null ? opts.expectedValue !== void 0 && ref !== opts.expectedValue ? attempts < opts.maxAttempts ? (attempts++, setTimeout(check, opts.interval)) : opts.onError?.(new Error(opts.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`)) : callback(ref) : attempts < opts.maxAttempts ? (attempts++, setTimeout(check, opts.interval)) : opts.onError?.(new Error(opts.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`));
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
check();
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
checkAvailability
|
|
16
16
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { truthyFilter
|
|
2
|
-
function
|
|
3
|
-
return [...
|
|
4
|
-
const
|
|
5
|
-
return
|
|
6
|
-
}).filter(
|
|
1
|
+
import { truthyFilter } from "./truthyFilter.js";
|
|
2
|
+
function countryCodeToUnicodeFlag(locale) {
|
|
3
|
+
return [...locale].map((letter) => {
|
|
4
|
+
const code = letter.codePointAt(0);
|
|
5
|
+
return code ? code % 32 + 127461 : void 0;
|
|
6
|
+
}).filter(truthyFilter).map((n) => String.fromCodePoint(n)).join("");
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
countryCodeToUnicodeFlag
|
|
10
10
|
};
|
package/dist/helpers/debounce.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function
|
|
2
|
-
let
|
|
3
|
-
return function(...
|
|
4
|
-
clearTimeout(
|
|
5
|
-
|
|
6
|
-
},
|
|
1
|
+
function debounce(fn, delay) {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function(...args) {
|
|
4
|
+
clearTimeout(timeout), timeout = setTimeout(() => {
|
|
5
|
+
fn.apply(this, args);
|
|
6
|
+
}, delay);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
debounce
|
|
11
11
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
let
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
let timeout = null;
|
|
2
|
+
function debounceCallback(callback, delay) {
|
|
3
|
+
timeout && clearTimeout(timeout), timeout = setTimeout(callback, delay);
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
debounceCallback
|
|
7
7
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
return function(...
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
return
|
|
7
|
-
|
|
1
|
+
function debounceId(identifier, func, delay) {
|
|
2
|
+
const debouncedFunctions = {};
|
|
3
|
+
return function(...args) {
|
|
4
|
+
debouncedFunctions[identifier] || (debouncedFunctions[identifier] = { timer: null, promise: null });
|
|
5
|
+
const debounced = debouncedFunctions[identifier];
|
|
6
|
+
return debounced.timer && clearTimeout(debounced.timer), debounced.promise = new Promise((resolve, reject) => {
|
|
7
|
+
debounced.timer = setTimeout(async () => {
|
|
8
8
|
try {
|
|
9
|
-
|
|
10
|
-
} catch (
|
|
11
|
-
|
|
9
|
+
resolve(await func(...args));
|
|
10
|
+
} catch (error) {
|
|
11
|
+
reject(error);
|
|
12
12
|
} finally {
|
|
13
|
-
delete
|
|
13
|
+
delete debouncedFunctions[identifier];
|
|
14
14
|
}
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
15
|
+
}, delay);
|
|
16
|
+
}), debounced.promise;
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
debounceId
|
|
21
21
|
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
async function
|
|
1
|
+
async function fetchLocaleIp() {
|
|
2
2
|
try {
|
|
3
|
-
const
|
|
4
|
-
return
|
|
5
|
-
} catch (
|
|
6
|
-
console.error(`[maz-ui](fetchLocaleIp) ${
|
|
3
|
+
const reponse = await fetch("https://ipwho.is"), { country_code } = await reponse.json();
|
|
4
|
+
return country_code;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
console.error(`[maz-ui](fetchLocaleIp) ${error}`);
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export {
|
|
11
|
-
|
|
11
|
+
fetchLocaleIp
|
|
12
12
|
};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
const
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
2
|
style: "currency",
|
|
3
3
|
minimumFractionDigits: 2,
|
|
4
4
|
round: !1
|
|
5
5
|
};
|
|
6
|
-
function
|
|
7
|
-
let
|
|
8
|
-
return
|
|
6
|
+
function getFormattedCurrency(number, locale, options) {
|
|
7
|
+
let numberToFormat = +number;
|
|
8
|
+
return options.round && (numberToFormat = Math.floor(numberToFormat), options.minimumFractionDigits = 0), new Intl.NumberFormat(locale, options).format(numberToFormat);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
if (
|
|
10
|
+
function validRequiredAttributes(number, locale, options) {
|
|
11
|
+
if (number === void 0)
|
|
12
12
|
throw new TypeError("[maz-ui](FilterCurrency) The `number` attribute is required.");
|
|
13
|
-
if (
|
|
13
|
+
if (locale === void 0)
|
|
14
14
|
throw new TypeError("[maz-ui](FilterCurrency) The `locale` attribute is required.");
|
|
15
|
-
if (typeof
|
|
15
|
+
if (typeof locale != "string")
|
|
16
16
|
throw new TypeError("[maz-ui](FilterCurrency) The `locale` attribute must be a string.");
|
|
17
|
-
if (
|
|
17
|
+
if (options.currency === void 0)
|
|
18
18
|
throw new TypeError("[maz-ui](FilterCurrency) The `options.currency` attribute is required.");
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
...
|
|
23
|
-
...
|
|
20
|
+
function formatCurrency(number, locale, options) {
|
|
21
|
+
const options_ = {
|
|
22
|
+
...DEFAULT_OPTIONS,
|
|
23
|
+
...options
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
validRequiredAttributes(number, locale, options_);
|
|
26
26
|
try {
|
|
27
|
-
return
|
|
28
|
-
} catch (
|
|
29
|
-
throw new Error(`[maz-ui](FilterCurrency) ${
|
|
27
|
+
return getFormattedCurrency(number, locale, options_);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
throw new Error(`[maz-ui](FilterCurrency) ${error}`);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
formatCurrency
|
|
34
34
|
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
2
|
month: "short",
|
|
3
3
|
day: "numeric",
|
|
4
4
|
year: "numeric"
|
|
5
5
|
};
|
|
6
|
-
function
|
|
7
|
-
if (
|
|
6
|
+
function formatDate(date, locale, options) {
|
|
7
|
+
if (locale === void 0)
|
|
8
8
|
throw new TypeError("[maz-ui](FilterDate) The `locale` attribute is required.");
|
|
9
|
-
if (typeof
|
|
9
|
+
if (typeof locale != "string")
|
|
10
10
|
throw new TypeError("[maz-ui](FilterDate) The `locale` attribute must be a string.");
|
|
11
|
-
const
|
|
11
|
+
const opts = options ?? DEFAULT_OPTIONS;
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
return new Intl.DateTimeFormat(
|
|
15
|
-
} catch (
|
|
16
|
-
throw new Error(`[maz-ui](FilterDate) ${
|
|
13
|
+
const usedDate = date instanceof Date ? date : new Date(date);
|
|
14
|
+
return new Intl.DateTimeFormat(locale, opts).format(usedDate);
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw new Error(`[maz-ui](FilterDate) ${error}`);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
export {
|
|
20
|
-
|
|
20
|
+
formatDate
|
|
21
21
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
const
|
|
1
|
+
const DEFAULT_OPTIONS = {
|
|
2
2
|
minimumFractionDigits: 2
|
|
3
3
|
};
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
...
|
|
7
|
-
...
|
|
4
|
+
function formatNumber(number, locale, options) {
|
|
5
|
+
const filterOptions = {
|
|
6
|
+
...DEFAULT_OPTIONS,
|
|
7
|
+
...options
|
|
8
8
|
};
|
|
9
|
-
if (
|
|
9
|
+
if (number === void 0)
|
|
10
10
|
throw new TypeError("[maz-ui](FilterNumber) The `number` attribute is required.");
|
|
11
|
-
if (
|
|
11
|
+
if (locale === void 0)
|
|
12
12
|
throw new TypeError("[maz-ui](FilterNumber) The `locale` attribute is required.");
|
|
13
|
-
if (typeof
|
|
13
|
+
if (typeof locale != "string")
|
|
14
14
|
throw new TypeError("[maz-ui](FilterNumber) The `locale` attribute must be a string.");
|
|
15
15
|
try {
|
|
16
|
-
return new Intl.NumberFormat(
|
|
17
|
-
} catch (
|
|
18
|
-
throw new Error(`[maz-ui](FilterNumber) ${
|
|
16
|
+
return new Intl.NumberFormat(locale, filterOptions).format(Number(number));
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`[maz-ui](FilterNumber) ${error}`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export {
|
|
22
|
-
|
|
22
|
+
formatNumber
|
|
23
23
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { parsePhoneNumberFromString
|
|
2
|
-
function
|
|
3
|
-
if (!
|
|
1
|
+
import { parsePhoneNumberFromString } from "libphonenumber-js";
|
|
2
|
+
function formatPhoneNumber(phoneNumber) {
|
|
3
|
+
if (!phoneNumber)
|
|
4
4
|
throw new TypeError("[maz-ui](formatPhoneNumber) The `phoneNumber` argument is required.");
|
|
5
|
-
const
|
|
6
|
-
return
|
|
5
|
+
const parsedPhone = parsePhoneNumberFromString(phoneNumber);
|
|
6
|
+
return parsedPhone ? parsedPhone.formatInternational() : phoneNumber;
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
formatPhoneNumber
|
|
10
10
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { isServer
|
|
2
|
-
function
|
|
1
|
+
import { isServer } from "./isServer.js";
|
|
2
|
+
function getBrowserLocale() {
|
|
3
3
|
try {
|
|
4
|
-
return
|
|
5
|
-
} catch (
|
|
6
|
-
throw new Error(`[MazInputPhoneNumber] (browserLocale) ${
|
|
4
|
+
return isServer() ? void 0 : globalThis.navigator.language;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
throw new Error(`[MazInputPhoneNumber] (browserLocale) ${error}`);
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
getBrowserLocale
|
|
11
11
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
if (
|
|
5
|
-
return
|
|
1
|
+
const _supportedCodes = ["ad", "ae", "af", "ag", "ai", "al", "am", "ao", "aq", "ar", "as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bl", "bm", "bn", "bo", "bq", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cw", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", "eu", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gb-eng", "gb-nir", "gb-sct", "gb-wls", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "je", "jm", "jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mf", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "ss", "st", "sv", "sx", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tr", "tt", "tv", "tw", "tz", "ua", "ug", "um", "un", "us", "us-ak", "us-al", "us-ar", "us-az", "us-ca", "us-co", "us-ct", "us-de", "us-fl", "us-ga", "us-hi", "us-ia", "us-id", "us-il", "us-in", "us-ks", "us-ky", "us-la", "us-ma", "us-md", "us-me", "us-mi", "us-mn", "us-mo", "us-ms", "us-mt", "us-nc", "us-nd", "us-ne", "us-nh", "us-nj", "us-nm", "us-nv", "us-ny", "us-oh", "us-ok", "us-or", "us-pa", "us-ri", "us-sc", "us-sd", "us-tn", "us-tx", "us-ut", "us-va", "us-vt", "us-wa", "us-wi", "us-wv", "us-wy", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "xk", "ye", "yt", "za", "zm", "zw"];
|
|
2
|
+
function getCountryFlagUrl(countryIsoCode, size) {
|
|
3
|
+
const code = countryIsoCode.toLowerCase();
|
|
4
|
+
if (_supportedCodes.includes(code))
|
|
5
|
+
return size ? `https://flagcdn.com/${size}/${code}.png` : `https://flagcdn.com/${code}.svg`;
|
|
6
6
|
}
|
|
7
7
|
export {
|
|
8
|
-
|
|
8
|
+
getCountryFlagUrl
|
|
9
9
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
1
|
+
function getErrorMessage(error) {
|
|
2
|
+
return error instanceof Error ? error.message : typeof error == "string" ? error : error && typeof error == "object" && "message" in error ? String(error.message) : error ? String(error) : "An unexpected error occurred";
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
getErrorMessage
|
|
6
6
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isClient
|
|
2
|
-
class
|
|
3
|
-
constructor(
|
|
4
|
-
this.callback =
|
|
1
|
+
import { isClient } from "./isClient.js";
|
|
2
|
+
class IdleTimeout {
|
|
3
|
+
constructor(callback, options) {
|
|
4
|
+
this.callback = callback, this.options = {
|
|
5
5
|
...this.defaultOptions,
|
|
6
|
-
...
|
|
7
|
-
},
|
|
6
|
+
...options
|
|
7
|
+
}, isClient() && this.start();
|
|
8
8
|
}
|
|
9
9
|
defaultOptions = {
|
|
10
10
|
element: void 0,
|
|
@@ -38,17 +38,17 @@ class l {
|
|
|
38
38
|
return this.options.element ?? document.body;
|
|
39
39
|
}
|
|
40
40
|
start() {
|
|
41
|
-
if (!
|
|
41
|
+
if (!isClient()) {
|
|
42
42
|
console.warn("[IdleTimeout](start) you should run this method on client side");
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
for (const
|
|
46
|
-
this.element.addEventListener(
|
|
45
|
+
for (const eventName of this.eventNames)
|
|
46
|
+
this.element.addEventListener(eventName, this.handleEvent);
|
|
47
47
|
this.resetTimeout(), this.options.immediate && this.callback({ isIdle: !1, instance: this });
|
|
48
48
|
}
|
|
49
49
|
pause() {
|
|
50
|
-
const
|
|
51
|
-
|
|
50
|
+
const remainingTime = this.startTime + this.options.timeout - Date.now();
|
|
51
|
+
remainingTime <= 0 || (this.remainingTime = remainingTime, this.timeoutHandler && (clearTimeout(this.timeoutHandler), this.timeoutHandler = void 0));
|
|
52
52
|
}
|
|
53
53
|
resume() {
|
|
54
54
|
this.remainingTime <= 0 || (this.resetTimeout(), this.callback({ isIdle: this.isIdle, instance: this }), this.remainingTime = 0);
|
|
@@ -57,13 +57,13 @@ class l {
|
|
|
57
57
|
this.isDestroy = !1, this.isIdle = !1, this.remainingTime = 0, this.resetTimeout(), this.callback({ isIdle: this.isIdle, instance: this });
|
|
58
58
|
}
|
|
59
59
|
destroy() {
|
|
60
|
-
if (!
|
|
60
|
+
if (!isClient()) {
|
|
61
61
|
console.warn("[IdleTimeout](destroy) you should run this method on client side");
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
this.isDestroy = !0;
|
|
65
|
-
for (const
|
|
66
|
-
this.element.removeEventListener(
|
|
65
|
+
for (const eventName of this.eventNames)
|
|
66
|
+
this.element.removeEventListener(eventName, this.handleEvent);
|
|
67
67
|
this.timeoutHandler && clearTimeout(this.timeoutHandler);
|
|
68
68
|
}
|
|
69
69
|
resetTimeout() {
|
|
@@ -72,19 +72,19 @@ class l {
|
|
|
72
72
|
this.remainingTime || this.options.timeout
|
|
73
73
|
), this.startTime = Date.now();
|
|
74
74
|
}
|
|
75
|
-
handleEvent = (
|
|
75
|
+
handleEvent = (event) => {
|
|
76
76
|
try {
|
|
77
77
|
if (this.remainingTime > 0)
|
|
78
78
|
return;
|
|
79
|
-
if (
|
|
80
|
-
const { clientX
|
|
81
|
-
if (
|
|
79
|
+
if (event.type === "mousemove") {
|
|
80
|
+
const { clientX, clientY } = event;
|
|
81
|
+
if (clientX === void 0 && clientY === void 0 || clientX === this.lastClientX && clientY === this.lastClientY)
|
|
82
82
|
return;
|
|
83
|
-
this.lastClientX =
|
|
83
|
+
this.lastClientX = clientX, this.lastClientY = clientY;
|
|
84
84
|
}
|
|
85
|
-
this.resetTimeout(), this.callback({ isIdle: this.isIdle, eventType:
|
|
86
|
-
} catch (
|
|
87
|
-
throw new Error(`[IdleTimeout](handleEvent) ${
|
|
85
|
+
this.resetTimeout(), this.callback({ isIdle: this.isIdle, eventType: event.type, instance: this });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
throw new Error(`[IdleTimeout](handleEvent) ${error}`);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
handleTimeout() {
|
|
@@ -96,16 +96,16 @@ class l {
|
|
|
96
96
|
get timeout() {
|
|
97
97
|
return this.options.timeout;
|
|
98
98
|
}
|
|
99
|
-
set timeout(
|
|
100
|
-
this.options.timeout =
|
|
99
|
+
set timeout(value) {
|
|
100
|
+
this.options.timeout = value;
|
|
101
101
|
}
|
|
102
102
|
get idle() {
|
|
103
103
|
return this.isIdle;
|
|
104
104
|
}
|
|
105
|
-
set idle(
|
|
106
|
-
|
|
105
|
+
set idle(value) {
|
|
106
|
+
value ? this.handleTimeout() : this.reset(), this.callback({ isIdle: this.isIdle, instance: this });
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
export {
|
|
110
|
-
|
|
110
|
+
IdleTimeout
|
|
111
111
|
};
|
package/dist/helpers/index.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { camelCase
|
|
2
|
-
import { capitalize
|
|
3
|
-
import { checkAvailability
|
|
4
|
-
import { countryCodeToUnicodeFlag
|
|
5
|
-
import { debounce
|
|
6
|
-
import { debounceCallback
|
|
7
|
-
import { debounceId
|
|
8
|
-
import { formatCurrency
|
|
9
|
-
import { formatDate
|
|
10
|
-
import { formatNumber
|
|
11
|
-
import { getCountryFlagUrl
|
|
12
|
-
import { getErrorMessage
|
|
13
|
-
import { IdleTimeout
|
|
14
|
-
import { isClient
|
|
15
|
-
import { isEqual
|
|
16
|
-
import { isServer
|
|
17
|
-
import { isStandaloneMode
|
|
18
|
-
import { kebabCase
|
|
19
|
-
import { normalizeString
|
|
20
|
-
import { pascalCase
|
|
21
|
-
import { ScriptLoader
|
|
22
|
-
import { sleep
|
|
23
|
-
import { snakeCase
|
|
24
|
-
import { Swipe
|
|
25
|
-
import { TextareaAutogrow
|
|
26
|
-
import { throttle
|
|
27
|
-
import { throttleId
|
|
28
|
-
import { truthyFilter
|
|
29
|
-
import { UserVisibility
|
|
1
|
+
import { camelCase } from "./camelCase.js";
|
|
2
|
+
import { capitalize } from "./capitalize.js";
|
|
3
|
+
import { checkAvailability } from "./checkAvailability.js";
|
|
4
|
+
import { countryCodeToUnicodeFlag } from "./countryCodeToUnicodeFlag.js";
|
|
5
|
+
import { debounce } from "./debounce.js";
|
|
6
|
+
import { debounceCallback } from "./debounceCallback.js";
|
|
7
|
+
import { debounceId } from "./debounceId.js";
|
|
8
|
+
import { formatCurrency } from "./formatCurrency.js";
|
|
9
|
+
import { formatDate } from "./formatDate.js";
|
|
10
|
+
import { formatNumber } from "./formatNumber.js";
|
|
11
|
+
import { getCountryFlagUrl } from "./getCountryFlagUrl.js";
|
|
12
|
+
import { getErrorMessage } from "./getErrorMessage.js";
|
|
13
|
+
import { IdleTimeout } from "./idleTimeout.js";
|
|
14
|
+
import { isClient } from "./isClient.js";
|
|
15
|
+
import { isEqual } from "./isEqual.js";
|
|
16
|
+
import { isServer } from "./isServer.js";
|
|
17
|
+
import { isStandaloneMode } from "./isStandaloneMode.js";
|
|
18
|
+
import { kebabCase } from "./kebabCase.js";
|
|
19
|
+
import { normalizeString } from "./normalizeString.js";
|
|
20
|
+
import { pascalCase } from "./pascalCase.js";
|
|
21
|
+
import { ScriptLoader } from "./scriptLoader.js";
|
|
22
|
+
import { sleep } from "./sleep.js";
|
|
23
|
+
import { snakeCase } from "./snakeCase.js";
|
|
24
|
+
import { Swipe } from "./swipeHandler.js";
|
|
25
|
+
import { TextareaAutogrow } from "./TextareaAutogrow.js";
|
|
26
|
+
import { throttle } from "./throttle.js";
|
|
27
|
+
import { throttleId } from "./throttleId.js";
|
|
28
|
+
import { truthyFilter } from "./truthyFilter.js";
|
|
29
|
+
import { UserVisibility } from "./userVisibility.js";
|
|
30
30
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
IdleTimeout,
|
|
32
|
+
ScriptLoader,
|
|
33
|
+
Swipe,
|
|
34
|
+
TextareaAutogrow,
|
|
35
|
+
UserVisibility,
|
|
36
|
+
camelCase,
|
|
37
|
+
capitalize,
|
|
38
|
+
checkAvailability,
|
|
39
|
+
countryCodeToUnicodeFlag,
|
|
40
|
+
debounce,
|
|
41
|
+
debounceCallback,
|
|
42
|
+
debounceId,
|
|
43
|
+
formatCurrency,
|
|
44
|
+
formatDate,
|
|
45
|
+
formatNumber,
|
|
46
|
+
getCountryFlagUrl,
|
|
47
|
+
getErrorMessage,
|
|
48
|
+
isClient,
|
|
49
|
+
isEqual,
|
|
50
|
+
isServer,
|
|
51
|
+
isStandaloneMode,
|
|
52
|
+
kebabCase,
|
|
53
|
+
normalizeString,
|
|
54
|
+
pascalCase,
|
|
55
|
+
sleep,
|
|
56
|
+
snakeCase,
|
|
57
|
+
throttle,
|
|
58
|
+
throttleId,
|
|
59
|
+
truthyFilter
|
|
60
60
|
};
|
package/dist/helpers/isClient.js
CHANGED
package/dist/helpers/isEqual.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
1
|
+
function isPrimitive(value) {
|
|
2
|
+
return value == null || typeof value == "string" || typeof value == "number" || typeof value == "boolean" || typeof value == "symbol" || typeof value == "bigint";
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
if (
|
|
4
|
+
function isEqualArrays(a, b) {
|
|
5
|
+
if (a.length !== b.length)
|
|
6
6
|
return !1;
|
|
7
|
-
for (const [
|
|
8
|
-
if (!
|
|
7
|
+
for (const [i, element] of a.entries())
|
|
8
|
+
if (!isEqual(element, b[i]))
|
|
9
9
|
return !1;
|
|
10
10
|
return !0;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
12
|
+
function isEqualObjects(a, b) {
|
|
13
|
+
const keysA = Object.keys(a), keysB = Object.keys(b);
|
|
14
|
+
if (keysA.length !== keysB.length)
|
|
15
15
|
return !1;
|
|
16
|
-
for (const
|
|
17
|
-
if (!
|
|
16
|
+
for (const key of keysA)
|
|
17
|
+
if (!keysB.includes(key) || !isEqual(a[key], b[key]))
|
|
18
18
|
return !1;
|
|
19
19
|
return !0;
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
return
|
|
21
|
+
function isEqual(a, b) {
|
|
22
|
+
return isPrimitive(a) || isPrimitive(b) ? a === b : a instanceof Date && b instanceof Date ? a.getTime() === b.getTime() : typeof a != typeof b || Array.isArray(a) !== Array.isArray(b) ? !1 : Array.isArray(a) && Array.isArray(b) ? isEqualArrays(a, b) : typeof a == "object" && typeof b == "object" ? isEqualObjects(a, b) : !1;
|
|
23
23
|
}
|
|
24
24
|
export {
|
|
25
|
-
|
|
25
|
+
isEqual
|
|
26
26
|
};
|
package/dist/helpers/isServer.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isClient
|
|
2
|
-
function
|
|
3
|
-
if (!
|
|
1
|
+
import { isClient } from "./isClient.js";
|
|
2
|
+
function isStandaloneMode() {
|
|
3
|
+
if (!isClient())
|
|
4
4
|
return !1;
|
|
5
|
-
const
|
|
6
|
-
return
|
|
5
|
+
const nav = navigator, isStandalone = globalThis.matchMedia("(display-mode: standalone)").matches;
|
|
6
|
+
return nav.standalone || isStandalone;
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
isStandaloneMode
|
|
10
10
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
1
|
+
function kebabCase(str) {
|
|
2
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase().replace(/-+/g, "-").replace(/(^-)|(-$)/g, "");
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
kebabCase
|
|
6
6
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { camelCase
|
|
2
|
-
import { kebabCase
|
|
3
|
-
import { pascalCase
|
|
4
|
-
import { snakeCase
|
|
5
|
-
const
|
|
1
|
+
import { camelCase } from "./camelCase.js";
|
|
2
|
+
import { kebabCase } from "./kebabCase.js";
|
|
3
|
+
import { pascalCase } from "./pascalCase.js";
|
|
4
|
+
import { snakeCase } from "./snakeCase.js";
|
|
5
|
+
const defaultOptions = {
|
|
6
6
|
removeAccents: !0,
|
|
7
7
|
caseSensitive: !1,
|
|
8
8
|
replaceSpaces: !0,
|
|
@@ -13,26 +13,26 @@ const n = {
|
|
|
13
13
|
case: void 0,
|
|
14
14
|
customNormalizationForms: ["NFC", "NFKD"]
|
|
15
15
|
};
|
|
16
|
-
function
|
|
17
|
-
switch (
|
|
16
|
+
function applyCaseTransform(str, caseFormat) {
|
|
17
|
+
switch (caseFormat) {
|
|
18
18
|
case "kebab-case":
|
|
19
|
-
return
|
|
19
|
+
return kebabCase(str);
|
|
20
20
|
case "camelCase":
|
|
21
|
-
return
|
|
21
|
+
return camelCase(str);
|
|
22
22
|
case "PascalCase":
|
|
23
|
-
return
|
|
23
|
+
return pascalCase(str);
|
|
24
24
|
case "snake_case":
|
|
25
|
-
return
|
|
25
|
+
return snakeCase(str);
|
|
26
26
|
case "lowercase":
|
|
27
|
-
return
|
|
27
|
+
return str.toLowerCase();
|
|
28
28
|
case "UPPERCASE":
|
|
29
|
-
return
|
|
29
|
+
return str.toUpperCase();
|
|
30
30
|
default:
|
|
31
|
-
return
|
|
31
|
+
return str;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
const
|
|
34
|
+
function normalizeString(input, options) {
|
|
35
|
+
const finalOptions = { ...defaultOptions, ...options }, accentsMap = {
|
|
36
36
|
À: "A",
|
|
37
37
|
Á: "A",
|
|
38
38
|
Â: "A",
|
|
@@ -81,12 +81,12 @@ function S(r, s) {
|
|
|
81
81
|
ñ: "n",
|
|
82
82
|
ó: "o"
|
|
83
83
|
};
|
|
84
|
-
let
|
|
85
|
-
if (
|
|
86
|
-
for (const
|
|
87
|
-
|
|
88
|
-
return
|
|
84
|
+
let result = input.toString();
|
|
85
|
+
if (finalOptions.trim && (result = result.trim()), finalOptions.normalizeSpaces && (result = result.replaceAll(/\s+/g, " ")), finalOptions.replaceSpaces && (result = result.replaceAll(" ", "-")), finalOptions.removeNumbers && (result = result.replaceAll(/\d/g, "")), finalOptions.removeAccents && (result = result.replaceAll(/[ÀÁÂÃÄÅÇÈÉÊËÎÏÑÔÕÖØÙÚÛÜàáâãäåçèéêëíîïñóôõöøùúûüÿ]/g, (char) => accentsMap[char] || char), result = result.replaceAll(/[\u0300-\u036F]/g, "")), finalOptions.case ? result = applyCaseTransform(result, finalOptions.case) : finalOptions.caseSensitive === !1 && (result = result.toLowerCase()), finalOptions.removeSpecialCharacters && (result = result.replaceAll(/[^\dA-Z-]/gi, "")), finalOptions.trim && (result = result.trim()), finalOptions.customNormalizationForms)
|
|
86
|
+
for (const form of finalOptions.customNormalizationForms)
|
|
87
|
+
result = result.normalize(form);
|
|
88
|
+
return result;
|
|
89
89
|
}
|
|
90
90
|
export {
|
|
91
|
-
|
|
91
|
+
normalizeString
|
|
92
92
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { camelCase
|
|
2
|
-
import { capitalize
|
|
3
|
-
function
|
|
4
|
-
if (
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
1
|
+
import { camelCase } from "./camelCase.js";
|
|
2
|
+
import { capitalize } from "./capitalize.js";
|
|
3
|
+
function pascalCase(str) {
|
|
4
|
+
if (str === str.toUpperCase()) {
|
|
5
|
+
if (str.includes("-"))
|
|
6
|
+
return str.toLowerCase().split("-").map(capitalize).join("");
|
|
7
|
+
if (str.includes("_"))
|
|
8
|
+
return str.toLowerCase().split("_").map(capitalize).join("");
|
|
9
|
+
if (str.includes(" "))
|
|
10
|
+
return str.toLowerCase().split(" ").map(capitalize).join("");
|
|
11
11
|
}
|
|
12
|
-
return
|
|
12
|
+
return str.includes("-") ? str.toLowerCase().split("-").map(capitalize).join("") : str.includes("_") ? str.toLowerCase().split("_").map(capitalize).join("") : str.includes(" ") ? str.toLowerCase().split(" ").map(capitalize).join("") : capitalize(camelCase(str));
|
|
13
13
|
}
|
|
14
14
|
export {
|
|
15
|
-
|
|
15
|
+
pascalCase
|
|
16
16
|
};
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ScriptLoader {
|
|
2
2
|
src;
|
|
3
3
|
script;
|
|
4
4
|
once;
|
|
5
5
|
async;
|
|
6
6
|
defer;
|
|
7
7
|
identifier;
|
|
8
|
-
constructor({ src
|
|
8
|
+
constructor({ src, identifier, once = !0, async = !0, defer = !0 }) {
|
|
9
9
|
if (typeof globalThis.window > "u")
|
|
10
10
|
throw new TypeError("[ScriptLoader]: Is supported only on browser side");
|
|
11
|
-
if (!
|
|
11
|
+
if (!src)
|
|
12
12
|
throw new Error('[ScriptLoader]: You should provide the attribut "src"');
|
|
13
|
-
if (!
|
|
13
|
+
if (!identifier)
|
|
14
14
|
throw new Error('[ScriptLoader]: You should provide the attribut "identifier"');
|
|
15
|
-
this.src =
|
|
15
|
+
this.src = src, this.identifier = identifier, this.once = once, this.async = async, this.defer = defer;
|
|
16
16
|
}
|
|
17
|
-
removeTag(
|
|
18
|
-
typeof
|
|
17
|
+
removeTag(tag) {
|
|
18
|
+
typeof tag == "string" ? document.head.querySelector(`[data-identifier="${tag}"]`)?.remove() : tag.remove();
|
|
19
19
|
}
|
|
20
20
|
load() {
|
|
21
|
-
const
|
|
22
|
-
if (this.once &&
|
|
23
|
-
return this.script =
|
|
24
|
-
if (!this.once &&
|
|
25
|
-
for (const
|
|
26
|
-
this.removeTag(
|
|
21
|
+
const windowInstance = globalThis, scriptTags = document.head.querySelectorAll(`[data-identifier="${this.identifier}"]`);
|
|
22
|
+
if (this.once && windowInstance[this.identifier] && scriptTags.length > 0)
|
|
23
|
+
return this.script = windowInstance[this.identifier], Promise.resolve(this.script);
|
|
24
|
+
if (!this.once && scriptTags.length > 0)
|
|
25
|
+
for (const tag of scriptTags)
|
|
26
|
+
this.removeTag(tag);
|
|
27
27
|
return this.injectScript();
|
|
28
28
|
}
|
|
29
29
|
injectScript() {
|
|
30
|
-
const
|
|
31
|
-
return new Promise((
|
|
30
|
+
const windowInstance = globalThis;
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
32
|
try {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
} catch (
|
|
36
|
-
throw new Error(`[ScriptLoader](init) ${
|
|
33
|
+
const script = document.createElement("script");
|
|
34
|
+
script.src = this.src, script.async = this.async, script.defer = this.defer, script.dataset.identifier = this.identifier, script.addEventListener("error", (error) => reject(new Error(`[ScriptLoader](injectScript) ${error.message}`))), script.addEventListener("load", (success) => (this.script = success, windowInstance[this.identifier] = success, resolve(success))), document.head.append(script);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(`[ScriptLoader](init) ${error}`);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
export {
|
|
42
|
-
|
|
42
|
+
ScriptLoader
|
|
43
43
|
};
|
package/dist/helpers/sleep.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function
|
|
2
|
-
return
|
|
1
|
+
function snakeCase(str) {
|
|
2
|
+
return str.replace(/([a-z])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").replace(/[\s-]+/g, "_").toLowerCase().replace(/_+/g, "_").replace(/(^_)|(_$)/g, "");
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
snakeCase
|
|
6
6
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
const
|
|
1
|
+
const defaultOptions = {
|
|
2
2
|
preventDefaultOnTouchMove: !1,
|
|
3
3
|
preventDefaultOnMouseWheel: !1,
|
|
4
4
|
threshold: 50,
|
|
5
5
|
immediate: !1,
|
|
6
6
|
triggerOnEnd: !1
|
|
7
7
|
};
|
|
8
|
-
class
|
|
9
|
-
constructor(
|
|
10
|
-
this.inputOption =
|
|
8
|
+
class Swipe {
|
|
9
|
+
constructor(inputOption) {
|
|
10
|
+
this.inputOption = inputOption, this.options = { ...defaultOptions, ...inputOption }, this.onToucheStartCallback = this.toucheStartHandler.bind(this), this.onToucheMoveCallback = this.handleTouchMove.bind(this), this.onToucheEndCallback = this.handleTouchEnd.bind(this), this.onMouseWheelCallback = this.handleMouseWheel.bind(this), this.start = this.startListening.bind(this), this.stop = this.stopListening.bind(this), this.options.element && this.setElement(this.options.element), this.options.immediate && this.start();
|
|
11
11
|
}
|
|
12
12
|
element;
|
|
13
13
|
xStart;
|
|
@@ -29,28 +29,28 @@ class n {
|
|
|
29
29
|
stopListening() {
|
|
30
30
|
this.element?.removeEventListener("touchstart", this.onToucheStartCallback), this.element?.removeEventListener("touchmove", this.onToucheMoveCallback), this.element?.removeEventListener("touchend", this.onToucheEndCallback), this.options.preventDefaultOnMouseWheel && this.element?.removeEventListener("mousewheel", this.onMouseWheelCallback);
|
|
31
31
|
}
|
|
32
|
-
setElement(
|
|
33
|
-
if (!
|
|
32
|
+
setElement(element) {
|
|
33
|
+
if (!element) {
|
|
34
34
|
console.error(
|
|
35
35
|
"[maz-ui][SwipeHandler](setElement) Element should be provided. Its can be a string selector or an HTMLElement"
|
|
36
36
|
);
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
if (typeof
|
|
40
|
-
const
|
|
41
|
-
if (!(
|
|
39
|
+
if (typeof element == "string") {
|
|
40
|
+
const foundElement = document.querySelector(element);
|
|
41
|
+
if (!(foundElement instanceof HTMLElement)) {
|
|
42
42
|
console.error("[maz-ui][SwipeHandler](setElement) String selector for element is not found");
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
-
this.element =
|
|
45
|
+
this.element = foundElement;
|
|
46
46
|
} else
|
|
47
|
-
this.element =
|
|
47
|
+
this.element = element;
|
|
48
48
|
}
|
|
49
|
-
handleMouseWheel(
|
|
50
|
-
|
|
49
|
+
handleMouseWheel(event) {
|
|
50
|
+
event.preventDefault();
|
|
51
51
|
}
|
|
52
|
-
toucheStartHandler(
|
|
53
|
-
this.xStart =
|
|
52
|
+
toucheStartHandler(event) {
|
|
53
|
+
this.xStart = event.touches[0].clientX, this.yStart = event.touches[0].clientY, this.emitValuesChanged();
|
|
54
54
|
}
|
|
55
55
|
emitValuesChanged() {
|
|
56
56
|
this.options.onValuesChanged?.({
|
|
@@ -62,19 +62,19 @@ class n {
|
|
|
62
62
|
yDiff: this.yDiff
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
handleTouchMove(
|
|
66
|
-
this.options.preventDefaultOnTouchMove &&
|
|
65
|
+
handleTouchMove(event) {
|
|
66
|
+
this.options.preventDefaultOnTouchMove && event.cancelable && event.preventDefault(), this.xEnd = event.touches[0].clientX, this.yEnd = event.touches[0].clientY, !(!this.xStart || !this.yStart) && (this.xDiff = this.xStart - this.xEnd, this.yDiff = this.yStart - this.yEnd, this.emitValuesChanged(), this.options.triggerOnEnd || this.runCallbacks(event));
|
|
67
67
|
}
|
|
68
|
-
handleTouchEnd(
|
|
69
|
-
this.runCallbacks(
|
|
68
|
+
handleTouchEnd(event) {
|
|
69
|
+
this.runCallbacks(event), this.emitValuesChanged();
|
|
70
70
|
}
|
|
71
|
-
runCallbacks(
|
|
72
|
-
typeof this.xDiff != "number" || typeof this.yDiff != "number" || Math.abs(this.xDiff) < this.options.threshold && Math.abs(this.yDiff) < this.options.threshold || (Math.abs(this.xDiff) > Math.abs(this.yDiff) ? this.xDiff > 0 ? this.options.onLeft?.(
|
|
71
|
+
runCallbacks(event) {
|
|
72
|
+
typeof this.xDiff != "number" || typeof this.yDiff != "number" || Math.abs(this.xDiff) < this.options.threshold && Math.abs(this.yDiff) < this.options.threshold || (Math.abs(this.xDiff) > Math.abs(this.yDiff) ? this.xDiff > 0 ? this.options.onLeft?.(event) : this.options.onRight?.(event) : this.yDiff > 0 ? this.options.onUp?.(event) : this.options.onDown?.(event), this.resetValues());
|
|
73
73
|
}
|
|
74
74
|
resetValues() {
|
|
75
75
|
this.xStart = void 0, this.yStart = void 0, this.xEnd = void 0, this.yEnd = void 0, this.xDiff = void 0, this.yDiff = void 0, this.emitValuesChanged();
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
export {
|
|
79
|
-
|
|
79
|
+
Swipe
|
|
80
80
|
};
|
package/dist/helpers/throttle.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function
|
|
2
|
-
let
|
|
3
|
-
return function(...
|
|
4
|
-
|
|
5
|
-
Date.now() -
|
|
6
|
-
}, Math.max(
|
|
1
|
+
function throttle(func, limit) {
|
|
2
|
+
let inThrottle = !1, lastFunc, lastRan;
|
|
3
|
+
return function(...args) {
|
|
4
|
+
inThrottle ? (clearTimeout(lastFunc), lastFunc = setTimeout(() => {
|
|
5
|
+
Date.now() - lastRan >= limit && (func.apply(this, args), lastRan = Date.now());
|
|
6
|
+
}, Math.max(limit - (Date.now() - lastRan), 0))) : (func.apply(this, args), lastRan = Date.now(), inThrottle = !0);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
throttle
|
|
11
11
|
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
return async (...
|
|
4
|
-
const
|
|
5
|
-
return
|
|
1
|
+
function throttleId(identifier, func, interval) {
|
|
2
|
+
const state = {};
|
|
3
|
+
return async (...args) => {
|
|
4
|
+
const now = Date.now();
|
|
5
|
+
return state[identifier] || (state[identifier] = { promise: null, lastCall: 0, lastArgs: [] }), now - state[identifier].lastCall >= interval ? (state[identifier].lastCall = now, func(...args)) : (state[identifier].lastArgs = args, state[identifier].promise || (state[identifier].promise = new Promise((resolve) => {
|
|
6
6
|
setTimeout(
|
|
7
7
|
async () => {
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
state[identifier].lastCall = Date.now();
|
|
9
|
+
const result = await func(...state[identifier].lastArgs);
|
|
10
|
+
state[identifier].promise = null, resolve(result);
|
|
11
11
|
},
|
|
12
|
-
|
|
12
|
+
interval - (now - state[identifier].lastCall)
|
|
13
13
|
);
|
|
14
|
-
})),
|
|
14
|
+
})), state[identifier].promise);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
throttleId
|
|
19
19
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isClient
|
|
2
|
-
class
|
|
3
|
-
constructor(
|
|
4
|
-
this.callback =
|
|
1
|
+
import { isClient } from "./isClient.js";
|
|
2
|
+
class UserVisibility {
|
|
3
|
+
constructor(callback, options) {
|
|
4
|
+
this.callback = callback, this.options = {
|
|
5
5
|
...this.defaultOptions,
|
|
6
|
-
...
|
|
7
|
-
}, this.eventHandlerFunction = this.eventHandler.bind(this),
|
|
6
|
+
...options
|
|
7
|
+
}, this.eventHandlerFunction = this.eventHandler.bind(this), isClient() && this.start();
|
|
8
8
|
}
|
|
9
9
|
eventHandlerFunction;
|
|
10
10
|
event = "visibilitychange";
|
|
@@ -17,7 +17,7 @@ class o {
|
|
|
17
17
|
};
|
|
18
18
|
isVisible = !1;
|
|
19
19
|
start() {
|
|
20
|
-
if (!
|
|
20
|
+
if (!isClient()) {
|
|
21
21
|
console.warn("[UserVisibility](start) you should run this method on client side");
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
@@ -46,5 +46,5 @@ class o {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
export {
|
|
49
|
-
|
|
49
|
+
UserVisibility
|
|
50
50
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { camelCase
|
|
2
|
-
import { capitalize
|
|
3
|
-
import { checkAvailability
|
|
4
|
-
import { countryCodeToUnicodeFlag
|
|
5
|
-
import { debounce
|
|
6
|
-
import { debounceCallback
|
|
7
|
-
import { debounceId
|
|
8
|
-
import { formatCurrency
|
|
9
|
-
import { formatDate
|
|
10
|
-
import { formatNumber
|
|
11
|
-
import { getCountryFlagUrl
|
|
12
|
-
import { getErrorMessage
|
|
13
|
-
import { IdleTimeout
|
|
14
|
-
import { isClient
|
|
15
|
-
import { isEqual
|
|
16
|
-
import { isServer
|
|
17
|
-
import { isStandaloneMode
|
|
18
|
-
import { kebabCase
|
|
19
|
-
import { normalizeString
|
|
20
|
-
import { pascalCase
|
|
21
|
-
import { ScriptLoader
|
|
22
|
-
import { sleep
|
|
23
|
-
import { snakeCase
|
|
24
|
-
import { Swipe
|
|
25
|
-
import { TextareaAutogrow
|
|
26
|
-
import { throttle
|
|
27
|
-
import { throttleId
|
|
28
|
-
import { truthyFilter
|
|
29
|
-
import { UserVisibility
|
|
1
|
+
import { camelCase } from "./helpers/camelCase.js";
|
|
2
|
+
import { capitalize } from "./helpers/capitalize.js";
|
|
3
|
+
import { checkAvailability } from "./helpers/checkAvailability.js";
|
|
4
|
+
import { countryCodeToUnicodeFlag } from "./helpers/countryCodeToUnicodeFlag.js";
|
|
5
|
+
import { debounce } from "./helpers/debounce.js";
|
|
6
|
+
import { debounceCallback } from "./helpers/debounceCallback.js";
|
|
7
|
+
import { debounceId } from "./helpers/debounceId.js";
|
|
8
|
+
import { formatCurrency } from "./helpers/formatCurrency.js";
|
|
9
|
+
import { formatDate } from "./helpers/formatDate.js";
|
|
10
|
+
import { formatNumber } from "./helpers/formatNumber.js";
|
|
11
|
+
import { getCountryFlagUrl } from "./helpers/getCountryFlagUrl.js";
|
|
12
|
+
import { getErrorMessage } from "./helpers/getErrorMessage.js";
|
|
13
|
+
import { IdleTimeout } from "./helpers/idleTimeout.js";
|
|
14
|
+
import { isClient } from "./helpers/isClient.js";
|
|
15
|
+
import { isEqual } from "./helpers/isEqual.js";
|
|
16
|
+
import { isServer } from "./helpers/isServer.js";
|
|
17
|
+
import { isStandaloneMode } from "./helpers/isStandaloneMode.js";
|
|
18
|
+
import { kebabCase } from "./helpers/kebabCase.js";
|
|
19
|
+
import { normalizeString } from "./helpers/normalizeString.js";
|
|
20
|
+
import { pascalCase } from "./helpers/pascalCase.js";
|
|
21
|
+
import { ScriptLoader } from "./helpers/scriptLoader.js";
|
|
22
|
+
import { sleep } from "./helpers/sleep.js";
|
|
23
|
+
import { snakeCase } from "./helpers/snakeCase.js";
|
|
24
|
+
import { Swipe } from "./helpers/swipeHandler.js";
|
|
25
|
+
import { TextareaAutogrow } from "./helpers/TextareaAutogrow.js";
|
|
26
|
+
import { throttle } from "./helpers/throttle.js";
|
|
27
|
+
import { throttleId } from "./helpers/throttleId.js";
|
|
28
|
+
import { truthyFilter } from "./helpers/truthyFilter.js";
|
|
29
|
+
import { UserVisibility } from "./helpers/userVisibility.js";
|
|
30
30
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
IdleTimeout,
|
|
32
|
+
ScriptLoader,
|
|
33
|
+
Swipe,
|
|
34
|
+
TextareaAutogrow,
|
|
35
|
+
UserVisibility,
|
|
36
|
+
camelCase,
|
|
37
|
+
capitalize,
|
|
38
|
+
checkAvailability,
|
|
39
|
+
countryCodeToUnicodeFlag,
|
|
40
|
+
debounce,
|
|
41
|
+
debounceCallback,
|
|
42
|
+
debounceId,
|
|
43
|
+
formatCurrency,
|
|
44
|
+
formatDate,
|
|
45
|
+
formatNumber,
|
|
46
|
+
getCountryFlagUrl,
|
|
47
|
+
getErrorMessage,
|
|
48
|
+
isClient,
|
|
49
|
+
isEqual,
|
|
50
|
+
isServer,
|
|
51
|
+
isStandaloneMode,
|
|
52
|
+
kebabCase,
|
|
53
|
+
normalizeString,
|
|
54
|
+
pascalCase,
|
|
55
|
+
sleep,
|
|
56
|
+
snakeCase,
|
|
57
|
+
throttle,
|
|
58
|
+
throttleId,
|
|
59
|
+
truthyFilter
|
|
60
60
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.1.7-beta.
|
|
4
|
+
"version": "4.1.7-beta.3",
|
|
5
5
|
"description": "Utils of maz-ui for JavaScript/TypeScript users",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"eslint --fix"
|
|
76
76
|
]
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "31ae836325ee4ff3c8cb29aef2ecb52dba04db49"
|
|
79
79
|
}
|