@maz-ui/utils 5.0.0-canary.ef64a02.0 → 5.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/helpers/TextareaAutogrow.js +25 -1
  3. package/dist/helpers/camelCase.js +6 -1
  4. package/dist/helpers/capitalize.js +6 -1
  5. package/dist/helpers/checkAvailability.js +16 -1
  6. package/dist/helpers/cookie.d.ts +38 -0
  7. package/dist/helpers/cookie.js +23 -0
  8. package/dist/helpers/countryCodeToUnicodeFlag.js +10 -1
  9. package/dist/helpers/debounce.js +11 -1
  10. package/dist/helpers/debounceCallback.js +7 -1
  11. package/dist/helpers/debounceId.js +24 -1
  12. package/dist/helpers/fetchLocaleIp.js +12 -1
  13. package/dist/helpers/formatCurrency.js +30 -1
  14. package/dist/helpers/formatDate.js +19 -1
  15. package/dist/helpers/formatJson.js +6 -1
  16. package/dist/helpers/formatNumber.js +18 -1
  17. package/dist/helpers/formatPhoneNumber.js +9 -1
  18. package/dist/helpers/getBrowserLocale.js +11 -1
  19. package/dist/helpers/getCountryFlagUrl.js +8 -1
  20. package/dist/helpers/getErrorMessage.js +6 -1
  21. package/dist/helpers/idleTimeout.js +121 -1
  22. package/dist/helpers/index.d.ts +6 -0
  23. package/dist/helpers/index.js +38 -1
  24. package/dist/helpers/isClient.js +6 -1
  25. package/dist/helpers/isEqual.js +21 -1
  26. package/dist/helpers/isIos.d.ts +1 -0
  27. package/dist/helpers/isIos.js +9 -0
  28. package/dist/helpers/isServer.js +6 -1
  29. package/dist/helpers/isStandaloneMode.js +10 -1
  30. package/dist/helpers/kebabCase.js +6 -1
  31. package/dist/helpers/normalizeString.js +87 -1
  32. package/dist/helpers/pascalCase.js +13 -1
  33. package/dist/helpers/preventIosInputZoom.d.ts +12 -0
  34. package/dist/helpers/preventIosInputZoom.js +15 -0
  35. package/dist/helpers/scriptLoader.js +38 -1
  36. package/dist/helpers/sleep.js +6 -1
  37. package/dist/helpers/snakeCase.js +6 -1
  38. package/dist/helpers/swipeHandler.d.ts +21 -13
  39. package/dist/helpers/swipeHandler.js +83 -1
  40. package/dist/helpers/throttle.js +13 -1
  41. package/dist/helpers/throttleId.js +20 -1
  42. package/dist/helpers/truthyFilter.js +6 -1
  43. package/dist/helpers/upperFirst.js +6 -1
  44. package/dist/helpers/userVisibility.js +47 -1
  45. package/dist/index.js +39 -1
  46. package/package.json +24 -4
package/README.md CHANGED
@@ -163,7 +163,7 @@ const phone = formatPhoneNumber('+33123456789', 'international')
163
163
 
164
164
  ## Requirements
165
165
 
166
- - Node.js >= 18.0.0
166
+ - Node.js >= 22.12.0
167
167
  - TypeScript support included
168
168
  - Tree-shakeable for optimal bundle size
169
169
 
@@ -1 +1,25 @@
1
- import{debounce}from"./debounce.js";var TextareaAutogrow=class{element;constructor(element){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()}connect(){this.element.addEventListener(`focus`,this.onFocus),this.element.style.resize=`none`,this.element.style.boxSizing=`border-box`}disconnect(){window.removeEventListener(`resize`,this.onResize),this.element.removeEventListener(`input`,this.autogrow)}onFocus(){this.autogrow(),this.element.addEventListener(`input`,this.autogrow),window.addEventListener(`resize`,this.onResize),this.element.removeEventListener(`focus`,this.onFocus)}onResize(){this.autogrow()}autogrow(){this.element.style.height=`auto`,this.element.style.overflow=`hidden`,this.element.style.height=`${this.element.scrollHeight}px`}};export{TextareaAutogrow};
1
+ import { debounce } from "./debounce.js";
2
+ //#region src/helpers/TextareaAutogrow.ts
3
+ var TextareaAutogrow = class {
4
+ element;
5
+ constructor(element) {
6
+ 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();
7
+ }
8
+ connect() {
9
+ this.element.addEventListener("focus", this.onFocus), this.element.style.resize = "none", this.element.style.boxSizing = "border-box";
10
+ }
11
+ disconnect() {
12
+ window.removeEventListener("resize", this.onResize), this.element.removeEventListener("input", this.autogrow);
13
+ }
14
+ onFocus() {
15
+ this.autogrow(), this.element.addEventListener("input", this.autogrow), window.addEventListener("resize", this.onResize), this.element.removeEventListener("focus", this.onFocus);
16
+ }
17
+ onResize() {
18
+ this.autogrow();
19
+ }
20
+ autogrow() {
21
+ this.element.style.height = "auto", this.element.style.overflow = "hidden", this.element.style.height = `${this.element.scrollHeight}px`;
22
+ }
23
+ };
24
+ //#endregion
25
+ export { TextareaAutogrow };
@@ -1 +1,6 @@
1
- function camelCase(str){return str.replaceAll(/-(\w)/g,(_,c)=>c?c.toUpperCase():``)}export{camelCase};
1
+ //#region src/helpers/camelCase.ts
2
+ function camelCase(str) {
3
+ return str.replaceAll(/-(\w)/g, (_, c) => c ? c.toUpperCase() : "");
4
+ }
5
+ //#endregion
6
+ export { camelCase };
@@ -1 +1,6 @@
1
- function capitalize(value){return typeof value==`string`?value.charAt(0).toUpperCase()+value.slice(1):``}export{capitalize};
1
+ //#region src/helpers/capitalize.ts
2
+ function capitalize(value) {
3
+ return typeof value == "string" ? value.charAt(0).toUpperCase() + value.slice(1) : "";
4
+ }
5
+ //#endregion
6
+ export { capitalize };
@@ -1 +1,16 @@
1
- function checkAvailability(getRef,callback,options){let opts={maxAttempts:20,interval:100,...options};let attempts=0;function check(){let ref=getRef();ref==null||opts.expectedValue!==void 0&&ref!==opts.expectedValue?attempts<opts.maxAttempts?(attempts++,setTimeout(check,opts.interval)):opts.onError?.(Error(opts.errorMessage||`[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`)):callback(ref)}check()}export{checkAvailability};
1
+ //#region src/helpers/checkAvailability.ts
2
+ function checkAvailability(getRef, callback, options) {
3
+ let opts = {
4
+ maxAttempts: 20,
5
+ interval: 100,
6
+ ...options
7
+ };
8
+ let attempts = 0;
9
+ function check() {
10
+ let ref = getRef();
11
+ ref == null || opts.expectedValue !== void 0 && ref !== opts.expectedValue ? attempts < opts.maxAttempts ? (attempts++, setTimeout(check, opts.interval)) : opts.onError?.(Error(opts.errorMessage || `[maz-ui](checkAvailability) Nothing found after ${opts.maxAttempts} attempts`)) : callback(ref);
12
+ }
13
+ check();
14
+ }
15
+ //#endregion
16
+ export { checkAvailability };
@@ -0,0 +1,38 @@
1
+ export type CookieSameSite = 'Lax' | 'Strict' | 'None' | 'lax' | 'strict' | 'none';
2
+ export interface CookieOptions {
3
+ /** Path attribute. Defaults to `'/'`. Pass `null` to omit. */
4
+ path?: string | null;
5
+ /** Domain attribute. */
6
+ domain?: string;
7
+ /** Lifetime in seconds. Defaults to one year. Pass `null` to omit (session cookie). */
8
+ maxAge?: number | null;
9
+ /** Explicit expiration date. Takes precedence over `maxAge` when both are set. */
10
+ expires?: Date;
11
+ /** Restrict the cookie to HTTPS connections. */
12
+ secure?: boolean;
13
+ /** Same-site policy. Defaults to `'Lax'`. Pass `null` to omit. */
14
+ sameSite?: CookieSameSite | null;
15
+ /** Mark the cookie as partitioned (CHIPS). */
16
+ partitioned?: boolean;
17
+ }
18
+ /**
19
+ * Read a cookie by key.
20
+ *
21
+ * - On the client, the cookie is read from `document.cookie`.
22
+ * - On the server, pass the raw `Cookie` request header via `cookieHeader`
23
+ * (e.g. from `useSSRContext().event.node.req.headers.cookie` in Nuxt) to
24
+ * resolve the value during SSR. Without it, the function returns `null`.
25
+ */
26
+ export declare function getCookie(key: string, cookieHeader?: string): string | null;
27
+ /**
28
+ * Write a cookie via `document.cookie` with full attribute support.
29
+ *
30
+ * No-op on the server. `HttpOnly` is intentionally omitted as it cannot be set
31
+ * from `document.cookie` (browsers reject it).
32
+ */
33
+ export declare function setCookie(key: string, value: string, options?: CookieOptions): void;
34
+ /**
35
+ * Delete a cookie by writing `max-age=0`. `path` and `domain` must match the
36
+ * cookie's original attributes for the browser to actually drop it.
37
+ */
38
+ export declare function deleteCookie(key: string, options?: Pick<CookieOptions, 'path' | 'domain'>): void;
@@ -0,0 +1,23 @@
1
+ import { isServer } from "./isServer.js";
2
+ //#region src/helpers/cookie.ts
3
+ var ONE_YEAR_SECONDS = 31536e3;
4
+ function getCookie(key, cookieHeader) {
5
+ let source = isServer() ? cookieHeader : document.cookie;
6
+ if (!source) return null;
7
+ let cookie = source.split(";").find((c) => c.trim().startsWith(`${key}=`));
8
+ return cookie ? decodeURIComponent(cookie.split("=")[1]) : null;
9
+ }
10
+ function setCookie(key, value, options = {}) {
11
+ if (isServer()) return;
12
+ let { path = "/", domain, maxAge = ONE_YEAR_SECONDS, expires, secure, sameSite = "Lax", partitioned } = options;
13
+ let parts = [`${key}=${encodeURIComponent(value)}`];
14
+ path != null && parts.push(`path=${path}`), domain && parts.push(`domain=${domain}`), maxAge != null && parts.push(`max-age=${maxAge}`), expires && parts.push(`expires=${expires.toUTCString()}`), secure && parts.push("secure"), sameSite != null && parts.push(`SameSite=${sameSite}`), partitioned && parts.push("partitioned"), document.cookie = parts.join("; ");
15
+ }
16
+ function deleteCookie(key, options = {}) {
17
+ setCookie(key, "", {
18
+ ...options,
19
+ maxAge: 0
20
+ });
21
+ }
22
+ //#endregion
23
+ export { deleteCookie, getCookie, setCookie };
@@ -1 +1,10 @@
1
- import{truthyFilter}from"./truthyFilter.js";function countryCodeToUnicodeFlag(locale){return Array.from(locale,letter=>{let code=letter.codePointAt(0);return code?code%32+127461:void 0}).filter(truthyFilter).map(n=>String.fromCodePoint(n)).join(``)}export{countryCodeToUnicodeFlag};
1
+ import { truthyFilter } from "./truthyFilter.js";
2
+ //#region src/helpers/countryCodeToUnicodeFlag.ts
3
+ function countryCodeToUnicodeFlag(locale) {
4
+ return Array.from(locale, (letter) => {
5
+ let code = letter.codePointAt(0);
6
+ return code ? code % 32 + 127461 : void 0;
7
+ }).filter(truthyFilter).map((n) => String.fromCodePoint(n)).join("");
8
+ }
9
+ //#endregion
10
+ export { countryCodeToUnicodeFlag };
@@ -1 +1,11 @@
1
- function debounce(fn,delay){let timeout;return function(...args){clearTimeout(timeout),timeout=setTimeout(()=>{fn.apply(this,args)},delay)}}export{debounce};
1
+ //#region src/helpers/debounce.ts
2
+ function debounce(fn, delay) {
3
+ let timeout;
4
+ return function(...args) {
5
+ clearTimeout(timeout), timeout = setTimeout(() => {
6
+ fn.apply(this, args);
7
+ }, delay);
8
+ };
9
+ }
10
+ //#endregion
11
+ export { debounce };
@@ -1 +1,7 @@
1
- var timeout=null;function debounceCallback(callback,delay){timeout&&clearTimeout(timeout),timeout=setTimeout(callback,delay)}export{debounceCallback};
1
+ //#region src/helpers/debounceCallback.ts
2
+ var timeout = null;
3
+ function debounceCallback(callback, delay) {
4
+ timeout && clearTimeout(timeout), timeout = setTimeout(callback, delay);
5
+ }
6
+ //#endregion
7
+ export { debounceCallback };
@@ -1 +1,24 @@
1
- function debounceId(identifier,func,delay){let debouncedFunctions={};return function(...args){debouncedFunctions[identifier]||(debouncedFunctions[identifier]={timer:null,promise:null});let debounced=debouncedFunctions[identifier];return debounced.timer&&clearTimeout(debounced.timer),debounced.promise=new Promise((resolve,reject)=>{debounced.timer=setTimeout(async()=>{try{resolve(await func(...args))}catch(error){reject(error)}finally{delete debouncedFunctions[identifier]}},delay)}),debounced.promise}}export{debounceId};
1
+ //#region src/helpers/debounceId.ts
2
+ function debounceId(identifier, func, delay) {
3
+ let debouncedFunctions = {};
4
+ return function(...args) {
5
+ debouncedFunctions[identifier] || (debouncedFunctions[identifier] = {
6
+ timer: null,
7
+ promise: null
8
+ });
9
+ let debounced = debouncedFunctions[identifier];
10
+ return debounced.timer && clearTimeout(debounced.timer), debounced.promise = new Promise((resolve, reject) => {
11
+ debounced.timer = setTimeout(async () => {
12
+ try {
13
+ resolve(await func(...args));
14
+ } catch (error) {
15
+ reject(error);
16
+ } finally {
17
+ delete debouncedFunctions[identifier];
18
+ }
19
+ }, delay);
20
+ }), debounced.promise;
21
+ };
22
+ }
23
+ //#endregion
24
+ export { debounceId };
@@ -1 +1,12 @@
1
- async function fetchLocaleIp(){try{let{country_code}=await(await fetch(`https://ipwho.is`)).json();return country_code}catch(error){console.error(`[maz-ui](fetchLocaleIp) ${error}`);return}}export{fetchLocaleIp};
1
+ //#region src/helpers/fetchLocaleIp.ts
2
+ async function fetchLocaleIp() {
3
+ try {
4
+ let { country_code } = await (await fetch("https://ipwho.is")).json();
5
+ return country_code;
6
+ } catch (error) {
7
+ console.error(`[maz-ui](fetchLocaleIp) ${error}`);
8
+ return;
9
+ }
10
+ }
11
+ //#endregion
12
+ export { fetchLocaleIp };
@@ -1 +1,30 @@
1
- var DEFAULT_OPTIONS={style:`currency`,minimumFractionDigits:2,round:!1};function getFormattedCurrency(number,locale,options){let numberToFormat=+number;return options.round&&(numberToFormat=Math.floor(numberToFormat),options.minimumFractionDigits=0),new Intl.NumberFormat(locale,options).format(numberToFormat)}function validRequiredAttributes(number,locale,options){if(number===void 0)throw TypeError("[maz-ui](FilterCurrency) The `number` attribute is required.");if(locale===void 0)throw TypeError("[maz-ui](FilterCurrency) The `locale` attribute is required.");if(typeof locale!=`string`)throw TypeError("[maz-ui](FilterCurrency) The `locale` attribute must be a string.");if(options.currency===void 0)throw TypeError("[maz-ui](FilterCurrency) The `options.currency` attribute is required.")}function formatCurrency(number,locale,options){let options_={...DEFAULT_OPTIONS,...options};validRequiredAttributes(number,locale,options_);try{return getFormattedCurrency(number,locale,options_)}catch(error){throw Error(`[maz-ui](FilterCurrency) ${error}`,{cause:error})}}export{formatCurrency};
1
+ //#region src/helpers/formatCurrency.ts
2
+ var DEFAULT_OPTIONS = {
3
+ style: "currency",
4
+ minimumFractionDigits: 2,
5
+ round: !1
6
+ };
7
+ function getFormattedCurrency(number, locale, options) {
8
+ let numberToFormat = +number;
9
+ return options.round && (numberToFormat = Math.floor(numberToFormat), options.minimumFractionDigits = 0), new Intl.NumberFormat(locale, options).format(numberToFormat);
10
+ }
11
+ function validRequiredAttributes(number, locale, options) {
12
+ if (number === void 0) throw TypeError("[maz-ui](FilterCurrency) The `number` attribute is required.");
13
+ if (locale === void 0) throw TypeError("[maz-ui](FilterCurrency) The `locale` attribute is required.");
14
+ if (typeof locale != "string") throw TypeError("[maz-ui](FilterCurrency) The `locale` attribute must be a string.");
15
+ if (options.currency === void 0) throw TypeError("[maz-ui](FilterCurrency) The `options.currency` attribute is required.");
16
+ }
17
+ function formatCurrency(number, locale, options) {
18
+ let options_ = {
19
+ ...DEFAULT_OPTIONS,
20
+ ...options
21
+ };
22
+ validRequiredAttributes(number, locale, options_);
23
+ try {
24
+ return getFormattedCurrency(number, locale, options_);
25
+ } catch (error) {
26
+ throw Error(`[maz-ui](FilterCurrency) ${error}`, { cause: error });
27
+ }
28
+ }
29
+ //#endregion
30
+ export { formatCurrency };
@@ -1 +1,19 @@
1
- var DEFAULT_OPTIONS={month:`short`,day:`numeric`,year:`numeric`};function formatDate(date,locale,options){if(locale===void 0)throw TypeError("[maz-ui](FilterDate) The `locale` attribute is required.");if(typeof locale!=`string`)throw TypeError("[maz-ui](FilterDate) The `locale` attribute must be a string.");let opts=options??DEFAULT_OPTIONS;try{let usedDate=date instanceof Date?date:new Date(date);return new Intl.DateTimeFormat(locale,opts).format(usedDate)}catch(error){throw Error(`[maz-ui](FilterDate) ${error}`,{cause:error})}}export{formatDate};
1
+ //#region src/helpers/formatDate.ts
2
+ var DEFAULT_OPTIONS = {
3
+ month: "short",
4
+ day: "numeric",
5
+ year: "numeric"
6
+ };
7
+ function formatDate(date, locale, options) {
8
+ if (locale === void 0) throw TypeError("[maz-ui](FilterDate) The `locale` attribute is required.");
9
+ if (typeof locale != "string") throw TypeError("[maz-ui](FilterDate) The `locale` attribute must be a string.");
10
+ let opts = options ?? DEFAULT_OPTIONS;
11
+ try {
12
+ let usedDate = date instanceof Date ? date : new Date(date);
13
+ return new Intl.DateTimeFormat(locale, opts).format(usedDate);
14
+ } catch (error) {
15
+ throw Error(`[maz-ui](FilterDate) ${error}`, { cause: error });
16
+ }
17
+ }
18
+ //#endregion
19
+ export { formatDate };
@@ -1 +1,6 @@
1
- function formatJson(json,indent=2){return JSON.stringify(json,null,indent)}export{formatJson};
1
+ //#region src/helpers/formatJson.ts
2
+ function formatJson(json, indent = 2) {
3
+ return JSON.stringify(json, null, indent);
4
+ }
5
+ //#endregion
6
+ export { formatJson };
@@ -1 +1,18 @@
1
- var DEFAULT_OPTIONS={minimumFractionDigits:2};function formatNumber(number,locale,options){let filterOptions={...DEFAULT_OPTIONS,...options};if(number===void 0)throw TypeError("[maz-ui](FilterNumber) The `number` attribute is required.");if(locale===void 0)throw TypeError("[maz-ui](FilterNumber) The `locale` attribute is required.");if(typeof locale!=`string`)throw TypeError("[maz-ui](FilterNumber) The `locale` attribute must be a string.");try{return new Intl.NumberFormat(locale,filterOptions).format(Number(number))}catch(error){throw Error(`[maz-ui](FilterNumber) ${error}`,{cause:error})}}export{formatNumber};
1
+ //#region src/helpers/formatNumber.ts
2
+ var DEFAULT_OPTIONS = { minimumFractionDigits: 2 };
3
+ function formatNumber(number, locale, options) {
4
+ let filterOptions = {
5
+ ...DEFAULT_OPTIONS,
6
+ ...options
7
+ };
8
+ if (number === void 0) throw TypeError("[maz-ui](FilterNumber) The `number` attribute is required.");
9
+ if (locale === void 0) throw TypeError("[maz-ui](FilterNumber) The `locale` attribute is required.");
10
+ if (typeof locale != "string") throw TypeError("[maz-ui](FilterNumber) The `locale` attribute must be a string.");
11
+ try {
12
+ return new Intl.NumberFormat(locale, filterOptions).format(Number(number));
13
+ } catch (error) {
14
+ throw Error(`[maz-ui](FilterNumber) ${error}`, { cause: error });
15
+ }
16
+ }
17
+ //#endregion
18
+ export { formatNumber };
@@ -1 +1,9 @@
1
- import{parsePhoneNumberFromString}from"libphonenumber-js";function formatPhoneNumber(phoneNumber){if(!phoneNumber)throw TypeError("[maz-ui](formatPhoneNumber) The `phoneNumber` argument is required.");let parsedPhone=parsePhoneNumberFromString(phoneNumber);return parsedPhone?parsedPhone.formatInternational():phoneNumber}export{formatPhoneNumber};
1
+ import { parsePhoneNumberFromString } from "libphonenumber-js";
2
+ //#region src/helpers/formatPhoneNumber.ts
3
+ function formatPhoneNumber(phoneNumber) {
4
+ if (!phoneNumber) throw TypeError("[maz-ui](formatPhoneNumber) The `phoneNumber` argument is required.");
5
+ let parsedPhone = parsePhoneNumberFromString(phoneNumber);
6
+ return parsedPhone ? parsedPhone.formatInternational() : phoneNumber;
7
+ }
8
+ //#endregion
9
+ export { formatPhoneNumber };
@@ -1 +1,11 @@
1
- import{isServer}from"./isServer.js";function getBrowserLocale(){try{return isServer()?void 0:globalThis.navigator.language}catch(error){throw Error(`[MazInputPhoneNumber] (browserLocale) ${error}`,{cause:error})}}export{getBrowserLocale};
1
+ import { isServer } from "./isServer.js";
2
+ //#region src/helpers/getBrowserLocale.ts
3
+ function getBrowserLocale() {
4
+ try {
5
+ return isServer() ? void 0 : globalThis.navigator.language;
6
+ } catch (error) {
7
+ throw Error(`[MazInputPhoneNumber] (browserLocale) ${error}`, { cause: error });
8
+ }
9
+ }
10
+ //#endregion
11
+ export { getBrowserLocale };
@@ -1 +1,8 @@
1
- var _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`.split(`.`);function getCountryFlagUrl(countryIsoCode,size){let code=countryIsoCode.toLowerCase();if(_supportedCodes.includes(code))return size?`https://flagcdn.com/${size}/${code}.png`:`https://flagcdn.com/${code}.svg`}export{getCountryFlagUrl};
1
+ //#region src/helpers/getCountryFlagUrl.ts
2
+ var _supportedCodes = /* @__PURE__ */ "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".split(".");
3
+ function getCountryFlagUrl(countryIsoCode, size) {
4
+ let code = countryIsoCode.toLowerCase();
5
+ if (_supportedCodes.includes(code)) return size ? `https://flagcdn.com/${size}/${code}.png` : `https://flagcdn.com/${code}.svg`;
6
+ }
7
+ //#endregion
8
+ export { getCountryFlagUrl };
@@ -1 +1,6 @@
1
- function getErrorMessage(error){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`}export{getErrorMessage};
1
+ //#region src/helpers/getErrorMessage.ts
2
+ function getErrorMessage(error) {
3
+ 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";
4
+ }
5
+ //#endregion
6
+ export { getErrorMessage };
@@ -1 +1,121 @@
1
- import{isClient}from"./isClient.js";var IdleTimeout=class{defaultOptions={element:void 0,timeout:60*1e3*5,once:!1,immediate:!0};options;timeoutHandler;isIdle=!1;isDestroy=!1;startTime=0;remainingTime=0;lastClientX=-1;lastClientY=-1;eventNames=[`DOMMouseScroll`,`mousedown`,`mousemove`,`mousewheel`,`MSPointerDown`,`MSPointerMove`,`keydown`,`touchmove`,`touchstart`,`wheel`,`click`];constructor(callback,options){this.callback=callback,this.options={...this.defaultOptions,...options},isClient()&&this.start()}get element(){return this.options.element??document.body}start(){if(!isClient()){console.warn(`[IdleTimeout](start) you should run this method on client side`);return}for(let eventName of this.eventNames)this.element.addEventListener(eventName,this.handleEvent);this.resetTimeout(),this.options.immediate&&this.callback({isIdle:!1,instance:this})}pause(){let remainingTime=this.startTime+this.options.timeout-Date.now();remainingTime<=0||(this.remainingTime=remainingTime,this.timeoutHandler&&=(clearTimeout(this.timeoutHandler),void 0))}resume(){this.remainingTime<=0||(this.resetTimeout(),this.callback({isIdle:this.isIdle,instance:this}),this.remainingTime=0)}reset(){this.isDestroy=!1,this.isIdle=!1,this.remainingTime=0,this.resetTimeout(),this.callback({isIdle:this.isIdle,instance:this})}destroy(){if(!isClient()){console.warn(`[IdleTimeout](destroy) you should run this method on client side`);return}this.isDestroy=!0;for(let eventName of this.eventNames)this.element.removeEventListener(eventName,this.handleEvent);this.timeoutHandler&&clearTimeout(this.timeoutHandler)}resetTimeout(){this.isIdle=!1,this.timeoutHandler&&=(clearTimeout(this.timeoutHandler),void 0),this.timeoutHandler=setTimeout(this.handleTimeout.bind(this),this.remainingTime||this.options.timeout),this.startTime=Date.now()}handleEvent=event=>{try{if(this.remainingTime>0)return;if(event.type===`mousemove`){let{clientX,clientY}=event;if(clientX===void 0&&clientY===void 0||clientX===this.lastClientX&&clientY===this.lastClientY)return;this.lastClientX=clientX,this.lastClientY=clientY}this.resetTimeout(),this.callback({isIdle:this.isIdle,eventType:event.type,instance:this})}catch(error){throw Error(`[IdleTimeout](handleEvent) ${error}`,{cause:error})}};handleTimeout(){this.isIdle=!0,this.callback({isIdle:this.isIdle,instance:this}),this.options.once&&this.destroy()}get destroyed(){return this.isDestroy}get timeout(){return this.options.timeout}set timeout(value){this.options.timeout=value}get idle(){return this.isIdle}set idle(value){value?this.handleTimeout():this.reset(),this.callback({isIdle:this.isIdle,instance:this})}};export{IdleTimeout};
1
+ import { isClient } from "./isClient.js";
2
+ //#region src/helpers/idleTimeout.ts
3
+ var IdleTimeout = class {
4
+ callback;
5
+ defaultOptions = {
6
+ element: void 0,
7
+ timeout: 3e5,
8
+ once: !1,
9
+ immediate: !0
10
+ };
11
+ options;
12
+ timeoutHandler;
13
+ isIdle = !1;
14
+ isDestroy = !1;
15
+ startTime = 0;
16
+ remainingTime = 0;
17
+ lastClientX = -1;
18
+ lastClientY = -1;
19
+ eventNames = [
20
+ "DOMMouseScroll",
21
+ "mousedown",
22
+ "mousemove",
23
+ "mousewheel",
24
+ "MSPointerDown",
25
+ "MSPointerMove",
26
+ "keydown",
27
+ "touchmove",
28
+ "touchstart",
29
+ "wheel",
30
+ "click"
31
+ ];
32
+ constructor(callback, options) {
33
+ this.callback = callback, this.options = {
34
+ ...this.defaultOptions,
35
+ ...options
36
+ }, isClient() && this.start();
37
+ }
38
+ get element() {
39
+ return this.options.element ?? document.body;
40
+ }
41
+ start() {
42
+ if (!isClient()) console.warn("[IdleTimeout](start) you should run this method on client side");
43
+ else {
44
+ for (let eventName of this.eventNames) this.element.addEventListener(eventName, this.handleEvent);
45
+ this.resetTimeout(), this.options.immediate && this.callback({
46
+ isIdle: !1,
47
+ instance: this
48
+ });
49
+ }
50
+ }
51
+ pause() {
52
+ let remainingTime = this.startTime + this.options.timeout - Date.now();
53
+ remainingTime <= 0 || (this.remainingTime = remainingTime, this.timeoutHandler &&= (clearTimeout(this.timeoutHandler), void 0));
54
+ }
55
+ resume() {
56
+ this.remainingTime <= 0 || (this.resetTimeout(), this.callback({
57
+ isIdle: this.isIdle,
58
+ instance: this
59
+ }), this.remainingTime = 0);
60
+ }
61
+ reset() {
62
+ this.isDestroy = !1, this.isIdle = !1, this.remainingTime = 0, this.resetTimeout(), this.callback({
63
+ isIdle: this.isIdle,
64
+ instance: this
65
+ });
66
+ }
67
+ destroy() {
68
+ if (!isClient()) console.warn("[IdleTimeout](destroy) you should run this method on client side");
69
+ else {
70
+ this.isDestroy = !0;
71
+ for (let eventName of this.eventNames) this.element.removeEventListener(eventName, this.handleEvent);
72
+ this.timeoutHandler && clearTimeout(this.timeoutHandler);
73
+ }
74
+ }
75
+ resetTimeout() {
76
+ this.isIdle = !1, this.timeoutHandler &&= (clearTimeout(this.timeoutHandler), void 0), this.timeoutHandler = setTimeout(this.handleTimeout.bind(this), this.remainingTime || this.options.timeout), this.startTime = Date.now();
77
+ }
78
+ handleEvent = (event) => {
79
+ try {
80
+ if (this.remainingTime > 0) return;
81
+ if (event.type === "mousemove") {
82
+ let { clientX, clientY } = event;
83
+ if (clientX === void 0 && clientY === void 0 || clientX === this.lastClientX && clientY === this.lastClientY) return;
84
+ this.lastClientX = clientX, this.lastClientY = clientY;
85
+ }
86
+ this.resetTimeout(), this.callback({
87
+ isIdle: this.isIdle,
88
+ eventType: event.type,
89
+ instance: this
90
+ });
91
+ } catch (error) {
92
+ throw Error(`[IdleTimeout](handleEvent) ${error}`, { cause: error });
93
+ }
94
+ };
95
+ handleTimeout() {
96
+ this.isIdle = !0, this.callback({
97
+ isIdle: this.isIdle,
98
+ instance: this
99
+ }), this.options.once && this.destroy();
100
+ }
101
+ get destroyed() {
102
+ return this.isDestroy;
103
+ }
104
+ get timeout() {
105
+ return this.options.timeout;
106
+ }
107
+ set timeout(value) {
108
+ this.options.timeout = value;
109
+ }
110
+ get idle() {
111
+ return this.isIdle;
112
+ }
113
+ set idle(value) {
114
+ value ? this.handleTimeout() : this.reset(), this.callback({
115
+ isIdle: this.isIdle,
116
+ instance: this
117
+ });
118
+ }
119
+ };
120
+ //#endregion
121
+ export { IdleTimeout };
@@ -1,24 +1,30 @@
1
1
  export * from './camelCase';
2
2
  export * from './capitalize';
3
3
  export * from './checkAvailability';
4
+ export * from './cookie';
4
5
  export * from './countryCodeToUnicodeFlag';
5
6
  export * from './debounce';
6
7
  export * from './debounceCallback';
7
8
  export * from './debounceId';
9
+ export * from './fetchLocaleIp';
8
10
  export * from './formatCurrency';
9
11
  export * from './formatDate';
10
12
  export * from './formatJson';
11
13
  export * from './formatNumber';
14
+ export * from './formatPhoneNumber';
15
+ export * from './getBrowserLocale';
12
16
  export * from './getCountryFlagUrl';
13
17
  export * from './getErrorMessage';
14
18
  export * from './idleTimeout';
15
19
  export * from './isClient';
16
20
  export * from './isEqual';
21
+ export * from './isIos';
17
22
  export * from './isServer';
18
23
  export * from './isStandaloneMode';
19
24
  export * from './kebabCase';
20
25
  export * from './normalizeString';
21
26
  export * from './pascalCase';
27
+ export * from './preventIosInputZoom';
22
28
  export * from './scriptLoader';
23
29
  export * from './sleep';
24
30
  export * from './snakeCase';
@@ -1 +1,38 @@
1
- import{camelCase}from"./camelCase.js";import{capitalize}from"./capitalize.js";import{checkAvailability}from"./checkAvailability.js";import{truthyFilter}from"./truthyFilter.js";import{countryCodeToUnicodeFlag}from"./countryCodeToUnicodeFlag.js";import{debounce}from"./debounce.js";import{debounceCallback}from"./debounceCallback.js";import{debounceId}from"./debounceId.js";import{formatCurrency}from"./formatCurrency.js";import{formatDate}from"./formatDate.js";import{formatJson}from"./formatJson.js";import{formatNumber}from"./formatNumber.js";import{getCountryFlagUrl}from"./getCountryFlagUrl.js";import{getErrorMessage}from"./getErrorMessage.js";import{isClient}from"./isClient.js";import{IdleTimeout}from"./idleTimeout.js";import{isEqual}from"./isEqual.js";import{isServer}from"./isServer.js";import{isStandaloneMode}from"./isStandaloneMode.js";import{kebabCase}from"./kebabCase.js";import{pascalCase}from"./pascalCase.js";import{snakeCase}from"./snakeCase.js";import{normalizeString}from"./normalizeString.js";import{ScriptLoader}from"./scriptLoader.js";import{sleep}from"./sleep.js";import{Swipe}from"./swipeHandler.js";import{TextareaAutogrow}from"./TextareaAutogrow.js";import{throttle}from"./throttle.js";import{throttleId}from"./throttleId.js";import{upperFirst}from"./upperFirst.js";import{UserVisibility}from"./userVisibility.js";export{IdleTimeout,ScriptLoader,Swipe,TextareaAutogrow,UserVisibility,camelCase,capitalize,checkAvailability,countryCodeToUnicodeFlag,debounce,debounceCallback,debounceId,formatCurrency,formatDate,formatJson,formatNumber,getCountryFlagUrl,getErrorMessage,isClient,isEqual,isServer,isStandaloneMode,kebabCase,normalizeString,pascalCase,sleep,snakeCase,throttle,throttleId,truthyFilter,upperFirst};
1
+ import { camelCase } from "./camelCase.js";
2
+ import { capitalize } from "./capitalize.js";
3
+ import { checkAvailability } from "./checkAvailability.js";
4
+ import { isServer } from "./isServer.js";
5
+ import { deleteCookie, getCookie, setCookie } from "./cookie.js";
6
+ import { truthyFilter } from "./truthyFilter.js";
7
+ import { countryCodeToUnicodeFlag } from "./countryCodeToUnicodeFlag.js";
8
+ import { debounce } from "./debounce.js";
9
+ import { debounceCallback } from "./debounceCallback.js";
10
+ import { debounceId } from "./debounceId.js";
11
+ import { fetchLocaleIp } from "./fetchLocaleIp.js";
12
+ import { formatCurrency } from "./formatCurrency.js";
13
+ import { formatDate } from "./formatDate.js";
14
+ import { formatJson } from "./formatJson.js";
15
+ import { formatNumber } from "./formatNumber.js";
16
+ import { formatPhoneNumber } from "./formatPhoneNumber.js";
17
+ import { getBrowserLocale } from "./getBrowserLocale.js";
18
+ import { getCountryFlagUrl } from "./getCountryFlagUrl.js";
19
+ import { getErrorMessage } from "./getErrorMessage.js";
20
+ import { isClient } from "./isClient.js";
21
+ import { IdleTimeout } from "./idleTimeout.js";
22
+ import { isEqual } from "./isEqual.js";
23
+ import { isIos } from "./isIos.js";
24
+ import { isStandaloneMode } from "./isStandaloneMode.js";
25
+ import { kebabCase } from "./kebabCase.js";
26
+ import { pascalCase } from "./pascalCase.js";
27
+ import { snakeCase } from "./snakeCase.js";
28
+ import { normalizeString } from "./normalizeString.js";
29
+ import { addViewportMaximumScale, preventIosInputZoom } from "./preventIosInputZoom.js";
30
+ import { ScriptLoader } from "./scriptLoader.js";
31
+ import { sleep } from "./sleep.js";
32
+ import { Swipe } from "./swipeHandler.js";
33
+ import { TextareaAutogrow } from "./TextareaAutogrow.js";
34
+ import { throttle } from "./throttle.js";
35
+ import { throttleId } from "./throttleId.js";
36
+ import { upperFirst } from "./upperFirst.js";
37
+ import { UserVisibility } from "./userVisibility.js";
38
+ export { IdleTimeout, ScriptLoader, Swipe, TextareaAutogrow, UserVisibility, addViewportMaximumScale, camelCase, capitalize, checkAvailability, countryCodeToUnicodeFlag, debounce, debounceCallback, debounceId, deleteCookie, fetchLocaleIp, formatCurrency, formatDate, formatJson, formatNumber, formatPhoneNumber, getBrowserLocale, getCookie, getCountryFlagUrl, getErrorMessage, isClient, isEqual, isIos, isServer, isStandaloneMode, kebabCase, normalizeString, pascalCase, preventIosInputZoom, setCookie, sleep, snakeCase, throttle, throttleId, truthyFilter, upperFirst };
@@ -1 +1,6 @@
1
- function isClient(){return typeof document<`u`}export{isClient};
1
+ //#region src/helpers/isClient.ts
2
+ function isClient() {
3
+ return typeof document < "u";
4
+ }
5
+ //#endregion
6
+ export { isClient };
@@ -1 +1,21 @@
1
- function isPrimitive(value){return value==null||typeof value==`string`||typeof value==`number`||typeof value==`boolean`||typeof value==`symbol`||typeof value==`bigint`}function isEqualArrays(a,b){if(a.length!==b.length)return!1;for(let[i,element]of a.entries())if(!isEqual(element,b[i]))return!1;return!0}function isEqualObjects(a,b){let keysA=Object.keys(a);let keysB=Object.keys(b);if(keysA.length!==keysB.length)return!1;for(let key of keysA)if(!keysB.includes(key)||!isEqual(a[key],b[key]))return!1;return!0}function isEqual(a,b){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}export{isEqual};
1
+ //#region src/helpers/isEqual.ts
2
+ function isPrimitive(value) {
3
+ return value == null || typeof value == "string" || typeof value == "number" || typeof value == "boolean" || typeof value == "symbol" || typeof value == "bigint";
4
+ }
5
+ function isEqualArrays(a, b) {
6
+ if (a.length !== b.length) return !1;
7
+ for (let [i, element] of a.entries()) if (!isEqual(element, b[i])) return !1;
8
+ return !0;
9
+ }
10
+ function isEqualObjects(a, b) {
11
+ let keysA = Object.keys(a);
12
+ let keysB = Object.keys(b);
13
+ if (keysA.length !== keysB.length) return !1;
14
+ for (let key of keysA) if (!keysB.includes(key) || !isEqual(a[key], b[key])) return !1;
15
+ return !0;
16
+ }
17
+ function isEqual(a, b) {
18
+ 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);
19
+ }
20
+ //#endregion
21
+ export { isEqual };
@@ -0,0 +1 @@
1
+ export declare function isIos(): boolean;
@@ -0,0 +1,9 @@
1
+ import { isClient } from "./isClient.js";
2
+ //#region src/helpers/isIos.ts
3
+ function isIos() {
4
+ if (!isClient()) return !1;
5
+ let userAgent = navigator.userAgent;
6
+ return /iPhone|iPad|iPod/.test(userAgent) || /Macintosh/.test(userAgent) && navigator.maxTouchPoints > 1;
7
+ }
8
+ //#endregion
9
+ export { isIos };
@@ -1 +1,6 @@
1
- function isServer(){return typeof document>`u`||globalThis.window===void 0}export{isServer};
1
+ //#region src/helpers/isServer.ts
2
+ function isServer() {
3
+ return typeof document > "u" || globalThis.window === void 0;
4
+ }
5
+ //#endregion
6
+ export { isServer };
@@ -1 +1,10 @@
1
- import{isClient}from"./isClient.js";function isStandaloneMode(){if(!isClient())return!1;let nav=navigator;let isStandalone=globalThis.matchMedia(`(display-mode: standalone)`).matches;return nav.standalone||isStandalone}export{isStandaloneMode};
1
+ import { isClient } from "./isClient.js";
2
+ //#region src/helpers/isStandaloneMode.ts
3
+ function isStandaloneMode() {
4
+ if (!isClient()) return !1;
5
+ let nav = navigator;
6
+ let isStandalone = globalThis.matchMedia("(display-mode: standalone)").matches;
7
+ return nav.standalone || isStandalone;
8
+ }
9
+ //#endregion
10
+ export { isStandaloneMode };
@@ -1 +1,6 @@
1
- function kebabCase(str){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,``)}export{kebabCase};
1
+ //#region src/helpers/kebabCase.ts
2
+ function kebabCase(str) {
3
+ 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, "");
4
+ }
5
+ //#endregion
6
+ export { kebabCase };