@maz-ui/utils 4.1.7-beta.0 → 4.1.7-beta.5
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 +5 -5
|
@@ -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