@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.
Files changed (35) hide show
  1. package/dist/helpers/TextareaAutogrow.js +5 -5
  2. package/dist/helpers/camelCase.js +3 -3
  3. package/dist/helpers/capitalize.js +3 -3
  4. package/dist/helpers/checkAvailability.js +9 -9
  5. package/dist/helpers/countryCodeToUnicodeFlag.js +7 -7
  6. package/dist/helpers/debounce.js +7 -7
  7. package/dist/helpers/debounceCallback.js +4 -4
  8. package/dist/helpers/debounceId.js +14 -14
  9. package/dist/helpers/fetchLocaleIp.js +6 -6
  10. package/dist/helpers/formatCurrency.js +18 -18
  11. package/dist/helpers/formatDate.js +10 -10
  12. package/dist/helpers/formatNumber.js +12 -12
  13. package/dist/helpers/formatPhoneNumber.js +6 -6
  14. package/dist/helpers/getBrowserLocale.js +6 -6
  15. package/dist/helpers/getCountryFlagUrl.js +6 -6
  16. package/dist/helpers/getErrorMessage.js +3 -3
  17. package/dist/helpers/idleTimeout.js +27 -27
  18. package/dist/helpers/index.js +58 -58
  19. package/dist/helpers/isClient.js +2 -2
  20. package/dist/helpers/isEqual.js +14 -14
  21. package/dist/helpers/isServer.js +2 -2
  22. package/dist/helpers/isStandaloneMode.js +6 -6
  23. package/dist/helpers/kebabCase.js +3 -3
  24. package/dist/helpers/normalizeString.js +22 -22
  25. package/dist/helpers/pascalCase.js +12 -12
  26. package/dist/helpers/scriptLoader.js +20 -20
  27. package/dist/helpers/sleep.js +3 -3
  28. package/dist/helpers/snakeCase.js +3 -3
  29. package/dist/helpers/swipeHandler.js +22 -22
  30. package/dist/helpers/throttle.js +7 -7
  31. package/dist/helpers/throttleId.js +11 -11
  32. package/dist/helpers/truthyFilter.js +3 -3
  33. package/dist/helpers/userVisibility.js +8 -8
  34. package/dist/index.js +58 -58
  35. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
- import { debounce as t } from "./debounce.js";
2
- class o {
1
+ import { debounce } from "./debounce.js";
2
+ class TextareaAutogrow {
3
3
  element;
4
- constructor(e) {
5
- this.element = e, this.onFocus = this.onFocus.bind(this), this.autogrow = this.autogrow.bind(this), this.onResize = t(this.onResize.bind(this), 200), this.connect();
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
- o as TextareaAutogrow
24
+ TextareaAutogrow
25
25
  };
@@ -1,6 +1,6 @@
1
- function l(r) {
2
- return r.replaceAll(/-(\w)/g, (a, e) => e ? e.toUpperCase() : "");
1
+ function camelCase(str) {
2
+ return str.replaceAll(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
3
3
  }
4
4
  export {
5
- l as camelCase
5
+ camelCase
6
6
  };
@@ -1,6 +1,6 @@
1
- function r(t) {
2
- return typeof t != "string" ? "" : t.charAt(0).toUpperCase() + t.slice(1);
1
+ function capitalize(value) {
2
+ return typeof value != "string" ? "" : value.charAt(0).toUpperCase() + value.slice(1);
3
3
  }
4
4
  export {
5
- r as capitalize
5
+ capitalize
6
6
  };
@@ -1,16 +1,16 @@
1
- function l(r, o, s) {
2
- const e = {
1
+ function checkAvailability(getRef, callback, options) {
2
+ const opts = {
3
3
  maxAttempts: 20,
4
4
  interval: 100,
5
- ...s
5
+ ...options
6
6
  };
7
- let t = 0;
8
- function a() {
9
- const i = r();
10
- i != null ? e.expectedValue !== void 0 && i !== e.expectedValue ? t < e.maxAttempts ? (t++, setTimeout(a, e.interval)) : e.onError?.(new Error(e.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${e.maxAttempts} attempts`)) : o(i) : t < e.maxAttempts ? (t++, setTimeout(a, e.interval)) : e.onError?.(new Error(e.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${e.maxAttempts} attempts`));
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
- a();
12
+ check();
13
13
  }
14
14
  export {
15
- l as checkAvailability
15
+ checkAvailability
16
16
  };
@@ -1,10 +1,10 @@
1
- import { truthyFilter as n } from "./truthyFilter.js";
2
- function i(r) {
3
- return [...r].map((o) => {
4
- const t = o.codePointAt(0);
5
- return t ? t % 32 + 127461 : void 0;
6
- }).filter(n).map((o) => String.fromCodePoint(o)).join("");
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
- i as countryCodeToUnicodeFlag
9
+ countryCodeToUnicodeFlag
10
10
  };
@@ -1,11 +1,11 @@
1
- function i(e, o) {
2
- let t;
3
- return function(...u) {
4
- clearTimeout(t), t = setTimeout(() => {
5
- e.apply(this, u);
6
- }, o);
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
- i as debounce
10
+ debounce
11
11
  };
@@ -1,7 +1,7 @@
1
- let e = null;
2
- function o(t, l) {
3
- e && clearTimeout(e), e = setTimeout(t, l);
1
+ let timeout = null;
2
+ function debounceCallback(callback, delay) {
3
+ timeout && clearTimeout(timeout), timeout = setTimeout(callback, delay);
4
4
  }
5
5
  export {
6
- o as debounceCallback
6
+ debounceCallback
7
7
  };
@@ -1,21 +1,21 @@
1
- function i(o, n, r) {
2
- const t = {};
3
- return function(...c) {
4
- t[o] || (t[o] = { timer: null, promise: null });
5
- const e = t[o];
6
- return e.timer && clearTimeout(e.timer), e.promise = new Promise((u, m) => {
7
- e.timer = setTimeout(async () => {
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
- u(await n(...c));
10
- } catch (s) {
11
- m(s);
9
+ resolve(await func(...args));
10
+ } catch (error) {
11
+ reject(error);
12
12
  } finally {
13
- delete t[o];
13
+ delete debouncedFunctions[identifier];
14
14
  }
15
- }, r);
16
- }), e.promise;
15
+ }, delay);
16
+ }), debounced.promise;
17
17
  };
18
18
  }
19
19
  export {
20
- i as debounceId
20
+ debounceId
21
21
  };
@@ -1,12 +1,12 @@
1
- async function c() {
1
+ async function fetchLocaleIp() {
2
2
  try {
3
- const o = await fetch("https://ipwho.is"), { country_code: t } = await o.json();
4
- return t;
5
- } catch (o) {
6
- console.error(`[maz-ui](fetchLocaleIp) ${o}`);
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
- c as fetchLocaleIp
11
+ fetchLocaleIp
12
12
  };
@@ -1,34 +1,34 @@
1
- const u = {
1
+ const DEFAULT_OPTIONS = {
2
2
  style: "currency",
3
3
  minimumFractionDigits: 2,
4
4
  round: !1
5
5
  };
6
- function o(t, r, e) {
7
- let i = +t;
8
- return e.round && (i = Math.floor(i), e.minimumFractionDigits = 0), new Intl.NumberFormat(r, e).format(i);
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 c(t, r, e) {
11
- if (t === void 0)
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 (r === void 0)
13
+ if (locale === void 0)
14
14
  throw new TypeError("[maz-ui](FilterCurrency) The `locale` attribute is required.");
15
- if (typeof r != "string")
15
+ if (typeof locale != "string")
16
16
  throw new TypeError("[maz-ui](FilterCurrency) The `locale` attribute must be a string.");
17
- if (e.currency === void 0)
17
+ if (options.currency === void 0)
18
18
  throw new TypeError("[maz-ui](FilterCurrency) The `options.currency` attribute is required.");
19
19
  }
20
- function a(t, r, e) {
21
- const i = {
22
- ...u,
23
- ...e
20
+ function formatCurrency(number, locale, options) {
21
+ const options_ = {
22
+ ...DEFAULT_OPTIONS,
23
+ ...options
24
24
  };
25
- c(t, r, i);
25
+ validRequiredAttributes(number, locale, options_);
26
26
  try {
27
- return o(t, r, i);
28
- } catch (n) {
29
- throw new Error(`[maz-ui](FilterCurrency) ${n}`);
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
- a as formatCurrency
33
+ formatCurrency
34
34
  };
@@ -1,21 +1,21 @@
1
- const a = {
1
+ const DEFAULT_OPTIONS = {
2
2
  month: "short",
3
3
  day: "numeric",
4
4
  year: "numeric"
5
5
  };
6
- function n(t, r, o) {
7
- if (r === void 0)
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 r != "string")
9
+ if (typeof locale != "string")
10
10
  throw new TypeError("[maz-ui](FilterDate) The `locale` attribute must be a string.");
11
- const i = o ?? a;
11
+ const opts = options ?? DEFAULT_OPTIONS;
12
12
  try {
13
- const e = t instanceof Date ? t : new Date(t);
14
- return new Intl.DateTimeFormat(r, i).format(e);
15
- } catch (e) {
16
- throw new Error(`[maz-ui](FilterDate) ${e}`);
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
- n as formatDate
20
+ formatDate
21
21
  };
@@ -1,23 +1,23 @@
1
- const u = {
1
+ const DEFAULT_OPTIONS = {
2
2
  minimumFractionDigits: 2
3
3
  };
4
- function m(t, r, e) {
5
- const i = {
6
- ...u,
7
- ...e
4
+ function formatNumber(number, locale, options) {
5
+ const filterOptions = {
6
+ ...DEFAULT_OPTIONS,
7
+ ...options
8
8
  };
9
- if (t === void 0)
9
+ if (number === void 0)
10
10
  throw new TypeError("[maz-ui](FilterNumber) The `number` attribute is required.");
11
- if (r === void 0)
11
+ if (locale === void 0)
12
12
  throw new TypeError("[maz-ui](FilterNumber) The `locale` attribute is required.");
13
- if (typeof r != "string")
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(r, i).format(Number(t));
17
- } catch (o) {
18
- throw new Error(`[maz-ui](FilterNumber) ${o}`);
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
- m as formatNumber
22
+ formatNumber
23
23
  };
@@ -1,10 +1,10 @@
1
- import { parsePhoneNumberFromString as o } from "libphonenumber-js";
2
- function t(r) {
3
- if (!r)
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 e = o(r);
6
- return e ? e.formatInternational() : r;
5
+ const parsedPhone = parsePhoneNumberFromString(phoneNumber);
6
+ return parsedPhone ? parsedPhone.formatInternational() : phoneNumber;
7
7
  }
8
8
  export {
9
- t as formatPhoneNumber
9
+ formatPhoneNumber
10
10
  };
@@ -1,11 +1,11 @@
1
- import { isServer as e } from "./isServer.js";
2
- function t() {
1
+ import { isServer } from "./isServer.js";
2
+ function getBrowserLocale() {
3
3
  try {
4
- return e() ? void 0 : globalThis.navigator.language;
5
- } catch (r) {
6
- throw new Error(`[MazInputPhoneNumber] (browserLocale) ${r}`);
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
- t as getBrowserLocale
10
+ getBrowserLocale
11
11
  };
@@ -1,9 +1,9 @@
1
- const t = ["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 n(m, u) {
3
- const s = m.toLowerCase();
4
- if (t.includes(s))
5
- return u ? `https://flagcdn.com/${u}/${s}.png` : `https://flagcdn.com/${s}.svg`;
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
- n as getCountryFlagUrl
8
+ getCountryFlagUrl
9
9
  };
@@ -1,6 +1,6 @@
1
- function e(t) {
2
- return t instanceof Error ? t.message : typeof t == "string" ? t : t && typeof t == "object" && "message" in t ? String(t.message) : t ? String(t) : "An unexpected error occurred";
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
- e as getErrorMessage
5
+ getErrorMessage
6
6
  };
@@ -1,10 +1,10 @@
1
- import { isClient as s } from "./isClient.js";
2
- class l {
3
- constructor(t, e) {
4
- this.callback = t, this.options = {
1
+ import { isClient } from "./isClient.js";
2
+ class IdleTimeout {
3
+ constructor(callback, options) {
4
+ this.callback = callback, this.options = {
5
5
  ...this.defaultOptions,
6
- ...e
7
- }, s() && this.start();
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 (!s()) {
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 t of this.eventNames)
46
- this.element.addEventListener(t, this.handleEvent);
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 t = this.startTime + this.options.timeout - Date.now();
51
- t <= 0 || (this.remainingTime = t, this.timeoutHandler && (clearTimeout(this.timeoutHandler), this.timeoutHandler = void 0));
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 (!s()) {
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 t of this.eventNames)
66
- this.element.removeEventListener(t, this.handleEvent);
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 = (t) => {
75
+ handleEvent = (event) => {
76
76
  try {
77
77
  if (this.remainingTime > 0)
78
78
  return;
79
- if (t.type === "mousemove") {
80
- const { clientX: e, clientY: i } = t;
81
- if (e === void 0 && i === void 0 || e === this.lastClientX && i === this.lastClientY)
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 = e, this.lastClientY = i;
83
+ this.lastClientX = clientX, this.lastClientY = clientY;
84
84
  }
85
- this.resetTimeout(), this.callback({ isIdle: this.isIdle, eventType: t.type, instance: this });
86
- } catch (e) {
87
- throw new Error(`[IdleTimeout](handleEvent) ${e}`);
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(t) {
100
- this.options.timeout = t;
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(t) {
106
- t ? this.handleTimeout() : this.reset(), this.callback({ isIdle: this.isIdle, instance: this });
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
- l as IdleTimeout
110
+ IdleTimeout
111
111
  };
@@ -1,60 +1,60 @@
1
- import { camelCase as e } from "./camelCase.js";
2
- import { capitalize as m } from "./capitalize.js";
3
- import { checkAvailability as f } from "./checkAvailability.js";
4
- import { countryCodeToUnicodeFlag as a } from "./countryCodeToUnicodeFlag.js";
5
- import { debounce as l } from "./debounce.js";
6
- import { debounceCallback as c } from "./debounceCallback.js";
7
- import { debounceId as d } from "./debounceId.js";
8
- import { formatCurrency as b } from "./formatCurrency.js";
9
- import { formatDate as g } from "./formatDate.js";
10
- import { formatNumber as S } from "./formatNumber.js";
11
- import { getCountryFlagUrl as k } from "./getCountryFlagUrl.js";
12
- import { getErrorMessage as I } from "./getErrorMessage.js";
13
- import { IdleTimeout as U } from "./idleTimeout.js";
14
- import { isClient as w } from "./isClient.js";
15
- import { isEqual as A } from "./isEqual.js";
16
- import { isServer as M } from "./isServer.js";
17
- import { isStandaloneMode as D } from "./isStandaloneMode.js";
18
- import { kebabCase as N } from "./kebabCase.js";
19
- import { normalizeString as j } from "./normalizeString.js";
20
- import { pascalCase as G } from "./pascalCase.js";
21
- import { ScriptLoader as J } from "./scriptLoader.js";
22
- import { sleep as O } from "./sleep.js";
23
- import { snakeCase as Q } from "./snakeCase.js";
24
- import { Swipe as W } from "./swipeHandler.js";
25
- import { TextareaAutogrow as Y } from "./TextareaAutogrow.js";
26
- import { throttle as _ } from "./throttle.js";
27
- import { throttleId as rr } from "./throttleId.js";
28
- import { truthyFilter as er } from "./truthyFilter.js";
29
- import { UserVisibility as mr } from "./userVisibility.js";
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
- U as IdleTimeout,
32
- J as ScriptLoader,
33
- W as Swipe,
34
- Y as TextareaAutogrow,
35
- mr as UserVisibility,
36
- e as camelCase,
37
- m as capitalize,
38
- f as checkAvailability,
39
- a as countryCodeToUnicodeFlag,
40
- l as debounce,
41
- c as debounceCallback,
42
- d as debounceId,
43
- b as formatCurrency,
44
- g as formatDate,
45
- S as formatNumber,
46
- k as getCountryFlagUrl,
47
- I as getErrorMessage,
48
- w as isClient,
49
- A as isEqual,
50
- M as isServer,
51
- D as isStandaloneMode,
52
- N as kebabCase,
53
- j as normalizeString,
54
- G as pascalCase,
55
- O as sleep,
56
- Q as snakeCase,
57
- _ as throttle,
58
- rr as throttleId,
59
- er as truthyFilter
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
  };
@@ -1,6 +1,6 @@
1
- function e() {
1
+ function isClient() {
2
2
  return typeof document < "u";
3
3
  }
4
4
  export {
5
- e as isClient
5
+ isClient
6
6
  };
@@ -1,26 +1,26 @@
1
- function i(e) {
2
- return e == null || typeof e == "string" || typeof e == "number" || typeof e == "boolean" || typeof e == "symbol" || typeof e == "bigint";
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 o(e, r) {
5
- if (e.length !== r.length)
4
+ function isEqualArrays(a, b) {
5
+ if (a.length !== b.length)
6
6
  return !1;
7
- for (const [t, n] of e.entries())
8
- if (!s(n, r[t]))
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 y(e, r) {
13
- const t = Object.keys(e), n = Object.keys(r);
14
- if (t.length !== n.length)
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 f of t)
17
- if (!n.includes(f) || !s(e[f], r[f]))
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 s(e, r) {
22
- return i(e) || i(r) ? e === r : e instanceof Date && r instanceof Date ? e.getTime() === r.getTime() : typeof e != typeof r || Array.isArray(e) !== Array.isArray(r) ? !1 : Array.isArray(e) && Array.isArray(r) ? o(e, r) : typeof e == "object" && typeof r == "object" ? y(e, r) : !1;
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
- s as isEqual
25
+ isEqual
26
26
  };
@@ -1,6 +1,6 @@
1
- function e() {
1
+ function isServer() {
2
2
  return typeof document > "u" || typeof globalThis.window > "u";
3
3
  }
4
4
  export {
5
- e as isServer
5
+ isServer
6
6
  };
@@ -1,10 +1,10 @@
1
- import { isClient as t } from "./isClient.js";
2
- function e() {
3
- if (!t())
1
+ import { isClient } from "./isClient.js";
2
+ function isStandaloneMode() {
3
+ if (!isClient())
4
4
  return !1;
5
- const a = navigator, n = globalThis.matchMedia("(display-mode: standalone)").matches;
6
- return a.standalone || n;
5
+ const nav = navigator, isStandalone = globalThis.matchMedia("(display-mode: standalone)").matches;
6
+ return nav.standalone || isStandalone;
7
7
  }
8
8
  export {
9
- e as isStandaloneMode
9
+ isStandaloneMode
10
10
  };
@@ -1,6 +1,6 @@
1
- function a(e) {
2
- return e.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, "");
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
- a as kebabCase
5
+ kebabCase
6
6
  };
@@ -1,8 +1,8 @@
1
- import { camelCase as t } from "./camelCase.js";
2
- import { kebabCase as i } from "./kebabCase.js";
3
- import { pascalCase as l } from "./pascalCase.js";
4
- import { snakeCase as m } from "./snakeCase.js";
5
- const n = {
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 u(r, s) {
17
- switch (s) {
16
+ function applyCaseTransform(str, caseFormat) {
17
+ switch (caseFormat) {
18
18
  case "kebab-case":
19
- return i(r);
19
+ return kebabCase(str);
20
20
  case "camelCase":
21
- return t(r);
21
+ return camelCase(str);
22
22
  case "PascalCase":
23
- return l(r);
23
+ return pascalCase(str);
24
24
  case "snake_case":
25
- return m(r);
25
+ return snakeCase(str);
26
26
  case "lowercase":
27
- return r.toLowerCase();
27
+ return str.toLowerCase();
28
28
  case "UPPERCASE":
29
- return r.toUpperCase();
29
+ return str.toUpperCase();
30
30
  default:
31
- return r;
31
+ return str;
32
32
  }
33
33
  }
34
- function S(r, s) {
35
- const a = { ...n, ...s }, c = {
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 e = r.toString();
85
- if (a.trim && (e = e.trim()), a.normalizeSpaces && (e = e.replaceAll(/\s+/g, " ")), a.replaceSpaces && (e = e.replaceAll(" ", "-")), a.removeNumbers && (e = e.replaceAll(/\d/g, "")), a.removeAccents && (e = e.replaceAll(/[ÀÁÂÃÄÅÇÈÉÊËÎÏÑÔÕÖØÙÚÛÜàáâãäåçèéêëíîïñóôõöøùúûüÿ]/g, (o) => c[o] || o), e = e.replaceAll(/[\u0300-\u036F]/g, "")), a.case ? e = u(e, a.case) : a.caseSensitive === !1 && (e = e.toLowerCase()), a.removeSpecialCharacters && (e = e.replaceAll(/[^\dA-Z-]/gi, "")), a.trim && (e = e.trim()), a.customNormalizationForms)
86
- for (const o of a.customNormalizationForms)
87
- e = e.normalize(o);
88
- return e;
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
- S as normalizeString
91
+ normalizeString
92
92
  };
@@ -1,16 +1,16 @@
1
- import { camelCase as o } from "./camelCase.js";
2
- import { capitalize as i } from "./capitalize.js";
3
- function p(e) {
4
- if (e === e.toUpperCase()) {
5
- if (e.includes("-"))
6
- return e.toLowerCase().split("-").map(i).join("");
7
- if (e.includes("_"))
8
- return e.toLowerCase().split("_").map(i).join("");
9
- if (e.includes(" "))
10
- return e.toLowerCase().split(" ").map(i).join("");
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 e.includes("-") ? e.toLowerCase().split("-").map(i).join("") : e.includes("_") ? e.toLowerCase().split("_").map(i).join("") : e.includes(" ") ? e.toLowerCase().split(" ").map(i).join("") : i(o(e));
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
- p as pascalCase
15
+ pascalCase
16
16
  };
@@ -1,43 +1,43 @@
1
- class s {
1
+ class ScriptLoader {
2
2
  src;
3
3
  script;
4
4
  once;
5
5
  async;
6
6
  defer;
7
7
  identifier;
8
- constructor({ src: e, identifier: t, once: o = !0, async: r = !0, defer: i = !0 }) {
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 (!e)
11
+ if (!src)
12
12
  throw new Error('[ScriptLoader]: You should provide the attribut "src"');
13
- if (!t)
13
+ if (!identifier)
14
14
  throw new Error('[ScriptLoader]: You should provide the attribut "identifier"');
15
- this.src = e, this.identifier = t, this.once = o, this.async = r, this.defer = i;
15
+ this.src = src, this.identifier = identifier, this.once = once, this.async = async, this.defer = defer;
16
16
  }
17
- removeTag(e) {
18
- typeof e == "string" ? document.head.querySelector(`[data-identifier="${e}"]`)?.remove() : e.remove();
17
+ removeTag(tag) {
18
+ typeof tag == "string" ? document.head.querySelector(`[data-identifier="${tag}"]`)?.remove() : tag.remove();
19
19
  }
20
20
  load() {
21
- const e = globalThis, t = document.head.querySelectorAll(`[data-identifier="${this.identifier}"]`);
22
- if (this.once && e[this.identifier] && t.length > 0)
23
- return this.script = e[this.identifier], Promise.resolve(this.script);
24
- if (!this.once && t.length > 0)
25
- for (const o of t)
26
- this.removeTag(o);
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 e = globalThis;
31
- return new Promise((t, o) => {
30
+ const windowInstance = globalThis;
31
+ return new Promise((resolve, reject) => {
32
32
  try {
33
- const r = document.createElement("script");
34
- r.src = this.src, r.async = this.async, r.defer = this.defer, r.dataset.identifier = this.identifier, r.addEventListener("error", (i) => o(new Error(`[ScriptLoader](injectScript) ${i.message}`))), r.addEventListener("load", (i) => (this.script = i, e[this.identifier] = i, t(i))), document.head.append(r);
35
- } catch (r) {
36
- throw new Error(`[ScriptLoader](init) ${r}`);
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
- s as ScriptLoader
42
+ ScriptLoader
43
43
  };
@@ -1,6 +1,6 @@
1
- function n(e) {
2
- return new Promise((t) => setTimeout(t, e));
1
+ function sleep(duration) {
2
+ return new Promise((resolve) => setTimeout(resolve, duration));
3
3
  }
4
4
  export {
5
- n as sleep
5
+ sleep
6
6
  };
@@ -1,6 +1,6 @@
1
- function a(e) {
2
- return e.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, "");
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
- a as snakeCase
5
+ snakeCase
6
6
  };
@@ -1,13 +1,13 @@
1
- const s = {
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 n {
9
- constructor(t) {
10
- this.inputOption = t, this.options = { ...s, ...t }, 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();
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(t) {
33
- if (!t) {
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 t == "string") {
40
- const e = document.querySelector(t);
41
- if (!(e instanceof HTMLElement)) {
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 = e;
45
+ this.element = foundElement;
46
46
  } else
47
- this.element = t;
47
+ this.element = element;
48
48
  }
49
- handleMouseWheel(t) {
50
- t.preventDefault();
49
+ handleMouseWheel(event) {
50
+ event.preventDefault();
51
51
  }
52
- toucheStartHandler(t) {
53
- this.xStart = t.touches[0].clientX, this.yStart = t.touches[0].clientY, this.emitValuesChanged();
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(t) {
66
- this.options.preventDefaultOnTouchMove && t.cancelable && t.preventDefault(), this.xEnd = t.touches[0].clientX, this.yEnd = t.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(t));
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(t) {
69
- this.runCallbacks(t), this.emitValuesChanged();
68
+ handleTouchEnd(event) {
69
+ this.runCallbacks(event), this.emitValuesChanged();
70
70
  }
71
- runCallbacks(t) {
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?.(t) : this.options.onRight?.(t) : this.yDiff > 0 ? this.options.onUp?.(t) : this.options.onDown?.(t), this.resetValues());
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
- n as Swipe
79
+ Swipe
80
80
  };
@@ -1,11 +1,11 @@
1
- function i(e, a) {
2
- let l = !1, n, t;
3
- return function(...o) {
4
- l ? (clearTimeout(n), n = setTimeout(() => {
5
- Date.now() - t >= a && (e.apply(this, o), t = Date.now());
6
- }, Math.max(a - (Date.now() - t), 0))) : (e.apply(this, o), t = Date.now(), l = !0);
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
- i as throttle
10
+ throttle
11
11
  };
@@ -1,19 +1,19 @@
1
- function c(s, o, t) {
2
- const l = {};
3
- return async (...m) => {
4
- const a = Date.now();
5
- return l[s] || (l[s] = { promise: null, lastCall: 0, lastArgs: [] }), a - l[s].lastCall >= t ? (l[s].lastCall = a, o(...m)) : (l[s].lastArgs = m, l[s].promise || (l[s].promise = new Promise((u) => {
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
- l[s].lastCall = Date.now();
9
- const p = await o(...l[s].lastArgs);
10
- l[s].promise = null, u(p);
8
+ state[identifier].lastCall = Date.now();
9
+ const result = await func(...state[identifier].lastArgs);
10
+ state[identifier].promise = null, resolve(result);
11
11
  },
12
- t - (a - l[s].lastCall)
12
+ interval - (now - state[identifier].lastCall)
13
13
  );
14
- })), l[s].promise);
14
+ })), state[identifier].promise);
15
15
  };
16
16
  }
17
17
  export {
18
- c as throttleId
18
+ throttleId
19
19
  };
@@ -1,6 +1,6 @@
1
- function r(t) {
2
- return !!t;
1
+ function truthyFilter(value) {
2
+ return !!value;
3
3
  }
4
4
  export {
5
- r as truthyFilter
5
+ truthyFilter
6
6
  };
@@ -1,10 +1,10 @@
1
- import { isClient as i } from "./isClient.js";
2
- class o {
3
- constructor(t, e) {
4
- this.callback = t, this.options = {
1
+ import { isClient } from "./isClient.js";
2
+ class UserVisibility {
3
+ constructor(callback, options) {
4
+ this.callback = callback, this.options = {
5
5
  ...this.defaultOptions,
6
- ...e
7
- }, this.eventHandlerFunction = this.eventHandler.bind(this), i() && this.start();
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 (!i()) {
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
- o as UserVisibility
49
+ UserVisibility
50
50
  };
package/dist/index.js CHANGED
@@ -1,60 +1,60 @@
1
- import { camelCase as e } from "./helpers/camelCase.js";
2
- import { capitalize as m } from "./helpers/capitalize.js";
3
- import { checkAvailability as f } from "./helpers/checkAvailability.js";
4
- import { countryCodeToUnicodeFlag as a } from "./helpers/countryCodeToUnicodeFlag.js";
5
- import { debounce as l } from "./helpers/debounce.js";
6
- import { debounceCallback as c } from "./helpers/debounceCallback.js";
7
- import { debounceId as d } from "./helpers/debounceId.js";
8
- import { formatCurrency as b } from "./helpers/formatCurrency.js";
9
- import { formatDate as g } from "./helpers/formatDate.js";
10
- import { formatNumber as S } from "./helpers/formatNumber.js";
11
- import { getCountryFlagUrl as k } from "./helpers/getCountryFlagUrl.js";
12
- import { getErrorMessage as I } from "./helpers/getErrorMessage.js";
13
- import { IdleTimeout as U } from "./helpers/idleTimeout.js";
14
- import { isClient as w } from "./helpers/isClient.js";
15
- import { isEqual as A } from "./helpers/isEqual.js";
16
- import { isServer as M } from "./helpers/isServer.js";
17
- import { isStandaloneMode as D } from "./helpers/isStandaloneMode.js";
18
- import { kebabCase as N } from "./helpers/kebabCase.js";
19
- import { normalizeString as j } from "./helpers/normalizeString.js";
20
- import { pascalCase as G } from "./helpers/pascalCase.js";
21
- import { ScriptLoader as J } from "./helpers/scriptLoader.js";
22
- import { sleep as O } from "./helpers/sleep.js";
23
- import { snakeCase as Q } from "./helpers/snakeCase.js";
24
- import { Swipe as W } from "./helpers/swipeHandler.js";
25
- import { TextareaAutogrow as Y } from "./helpers/TextareaAutogrow.js";
26
- import { throttle as _ } from "./helpers/throttle.js";
27
- import { throttleId as rr } from "./helpers/throttleId.js";
28
- import { truthyFilter as er } from "./helpers/truthyFilter.js";
29
- import { UserVisibility as mr } from "./helpers/userVisibility.js";
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
- U as IdleTimeout,
32
- J as ScriptLoader,
33
- W as Swipe,
34
- Y as TextareaAutogrow,
35
- mr as UserVisibility,
36
- e as camelCase,
37
- m as capitalize,
38
- f as checkAvailability,
39
- a as countryCodeToUnicodeFlag,
40
- l as debounce,
41
- c as debounceCallback,
42
- d as debounceId,
43
- b as formatCurrency,
44
- g as formatDate,
45
- S as formatNumber,
46
- k as getCountryFlagUrl,
47
- I as getErrorMessage,
48
- w as isClient,
49
- A as isEqual,
50
- M as isServer,
51
- D as isStandaloneMode,
52
- N as kebabCase,
53
- j as normalizeString,
54
- G as pascalCase,
55
- O as sleep,
56
- Q as snakeCase,
57
- _ as throttle,
58
- rr as throttleId,
59
- er as truthyFilter
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.0",
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": "96035148527e2e795db6a7ea06f42e45995335b2"
78
+ "gitHead": "31ae836325ee4ff3c8cb29aef2ecb52dba04db49"
79
79
  }