@maz-ui/utils 5.0.0-beta.4 → 5.0.0-beta.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/cookie.d.ts +38 -0
- package/dist/helpers/cookie.js +1 -0
- package/dist/helpers/getCountryFlagUrl.js +1 -1
- package/dist/helpers/idleTimeout.js +1 -1
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/isEqual.js +1 -1
- package/dist/helpers/scriptLoader.js +1 -1
- package/dist/helpers/swipeHandler.d.ts +21 -13
- package/dist/helpers/swipeHandler.js +1 -1
- package/dist/helpers/userVisibility.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +11 -3
|
@@ -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 @@
|
|
|
1
|
+
import{isServer}from"./isServer.js";var ONE_YEAR_SECONDS=31536e3;function getCookie(key,cookieHeader){let source=isServer()?cookieHeader:document.cookie;if(!source)return null;let cookie=source.split(`;`).find(c=>c.trim().startsWith(`${key}=`));return cookie?decodeURIComponent(cookie.split(`=`)[1]):null}function setCookie(key,value,options={}){if(isServer())return;let{path=`/`,domain,maxAge=ONE_YEAR_SECONDS,expires,secure,sameSite=`Lax`,partitioned}=options;let parts=[`${key}=${encodeURIComponent(value)}`];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(`; `)}function deleteCookie(key,options={}){setCookie(key,``,{...options,maxAge:0})}export{deleteCookie,getCookie,setCookie};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var _supportedCodes
|
|
1
|
+
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(`.`);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 +1 @@
|
|
|
1
|
-
import{isClient}from"./isClient.js";var IdleTimeout=class{defaultOptions={element:void 0,timeout:
|
|
1
|
+
import{isClient}from"./isClient.js";var IdleTimeout=class{callback;defaultOptions={element:void 0,timeout:3e5,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};
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
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';
|
package/dist/helpers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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{
|
|
1
|
+
import{camelCase}from"./camelCase.js";import{capitalize}from"./capitalize.js";import{checkAvailability}from"./checkAvailability.js";import{isServer}from"./isServer.js";import{deleteCookie,getCookie,setCookie}from"./cookie.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{fetchLocaleIp}from"./fetchLocaleIp.js";import{formatCurrency}from"./formatCurrency.js";import{formatDate}from"./formatDate.js";import{formatJson}from"./formatJson.js";import{formatNumber}from"./formatNumber.js";import{formatPhoneNumber}from"./formatPhoneNumber.js";import{getBrowserLocale}from"./getBrowserLocale.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{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,deleteCookie,fetchLocaleIp,formatCurrency,formatDate,formatJson,formatNumber,formatPhoneNumber,getBrowserLocale,getCookie,getCountryFlagUrl,getErrorMessage,isClient,isEqual,isServer,isStandaloneMode,kebabCase,normalizeString,pascalCase,setCookie,sleep,snakeCase,throttle,throttleId,truthyFilter,upperFirst};
|
package/dist/helpers/isEqual.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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)}export{isEqual};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var ScriptLoader=class{src;script;once;async;defer;identifier;constructor({src,identifier,once=!0,async=!0,defer=!0}){if(globalThis.window===void 0)throw TypeError(`[ScriptLoader]: Is supported only on browser side`);if(!src)throw Error(`[ScriptLoader]: You should provide the attribut "src"`);if(!identifier)throw Error(`[ScriptLoader]: You should provide the attribut "identifier"`);this.src=src,this.identifier=identifier,this.once=once,this.async=async,this.defer=defer}removeTag(tag){typeof tag==`string`?document.head.querySelector(`[data-identifier="${tag}"]`)?.remove():tag.remove()}load(){let windowInstance=globalThis;let scriptTags=document.head.querySelectorAll(`[data-identifier="${this.identifier}"]`);if(this.once&&windowInstance[this.identifier]&&scriptTags.length>0)return this.script=windowInstance[this.identifier],Promise.resolve(this.script);if(!this.once&&scriptTags.length>0)for(let tag of scriptTags)this.removeTag(tag);return this.injectScript()}injectScript(){let windowInstance=globalThis;return new Promise((resolve,reject)=>{try{let script=document.createElement(`script`);script.src=this.src,script.async=this.async,script.defer=this.defer,script.dataset.identifier=this.identifier,script.addEventListener(`error`,error=>reject(Error(`[ScriptLoader](injectScript) ${error.message}`))),script.addEventListener(`load`,success=>(this.script=success,windowInstance[this.identifier]=success,resolve(success))),document.head.append(script)}catch(error){throw Error(`[ScriptLoader](init) ${error}`,{cause:error})}})}};export{ScriptLoader};
|
|
1
|
+
var ScriptLoader=class{src;script;once;async;defer;identifier;constructor({src,identifier,once=!0,async=!0,defer=!0}){if(globalThis.window===void 0)throw TypeError(`[ScriptLoader]: Is supported only on browser side`);if(!src)throw Error(`[ScriptLoader]: You should provide the attribut "src"`);if(!identifier)throw Error(`[ScriptLoader]: You should provide the attribut "identifier"`);this.src=src,this.identifier=identifier,this.once=once,this.async=async,this.defer=defer}removeTag(tag){typeof tag==`string`?document.head.querySelector(`[data-identifier="${tag}"]`)?.remove():tag.remove()}load(){let windowInstance=globalThis;let scriptTags=document.head.querySelectorAll(`[data-identifier="${this.identifier}"]`);if(this.once&&windowInstance[this.identifier]&&scriptTags.length>0)return this.script=windowInstance[this.identifier],Promise.resolve(this.script);if(!this.once&&scriptTags.length>0)for(let tag of scriptTags)this.removeTag(tag);return this.injectScript()}injectScript(){let windowInstance=globalThis;return new Promise((resolve,reject)=>{try{let script=document.createElement(`script`);script.src=this.src,script.async=this.async,script.defer=this.defer,script.dataset.identifier=this.identifier,script.addEventListener(`error`,error=>reject(/* @__PURE__ */ Error(`[ScriptLoader](injectScript) ${error.message}`))),script.addEventListener(`load`,success=>(this.script=success,windowInstance[this.identifier]=success,resolve(success))),document.head.append(script)}catch(error){throw Error(`[ScriptLoader](init) ${error}`,{cause:error})}})}};export{ScriptLoader};
|
|
@@ -6,7 +6,7 @@ export interface SwipeValues {
|
|
|
6
6
|
xDiff: number | undefined;
|
|
7
7
|
yDiff: number | undefined;
|
|
8
8
|
}
|
|
9
|
-
export type SwipeEventCallback = (event:
|
|
9
|
+
export type SwipeEventCallback = (event: PointerEvent) => void;
|
|
10
10
|
export type SwipeValuesCallback = (values: SwipeValues) => void;
|
|
11
11
|
/**
|
|
12
12
|
* Options for handling swipe events.
|
|
@@ -48,28 +48,34 @@ export interface SwipeOptions {
|
|
|
48
48
|
*/
|
|
49
49
|
threshold?: number;
|
|
50
50
|
/**
|
|
51
|
-
* Whether to prevent the default behavior of
|
|
51
|
+
* Whether to prevent the default behavior of the pointer move event (the move listener
|
|
52
|
+
* becomes non-passive when enabled).
|
|
52
53
|
* @default false
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
+
preventDefaultOnMove?: boolean;
|
|
55
56
|
/**
|
|
56
57
|
* Whether to prevent the default behavior of mousewheel event.
|
|
57
58
|
* @default false
|
|
58
59
|
*/
|
|
59
60
|
preventDefaultOnMouseWheel?: boolean;
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* Pointer types that can trigger the swipe.
|
|
63
|
+
* @default ['mouse', 'touch', 'pen']
|
|
64
|
+
*/
|
|
65
|
+
pointerTypes?: ('mouse' | 'touch' | 'pen')[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether to start listening immediately on instantiation.
|
|
62
68
|
* @default false
|
|
63
69
|
*/
|
|
64
70
|
immediate?: boolean;
|
|
65
71
|
/**
|
|
66
|
-
* Whether to trigger the swipe event on
|
|
67
|
-
* If set to true, the swipe event will be triggered only when the user lifts their finger/
|
|
72
|
+
* Whether to trigger the swipe event on pointer up.
|
|
73
|
+
* If set to true, the swipe event will be triggered only when the user lifts their finger/pointer.
|
|
68
74
|
* @default false
|
|
69
75
|
*/
|
|
70
76
|
triggerOnEnd?: boolean;
|
|
71
77
|
}
|
|
72
|
-
type DefaultSwipeOptions = Required<Pick<SwipeOptions, '
|
|
78
|
+
type DefaultSwipeOptions = Required<Pick<SwipeOptions, 'preventDefaultOnMove' | 'preventDefaultOnMouseWheel' | 'threshold' | 'immediate' | 'triggerOnEnd'>>;
|
|
73
79
|
type SwipeOptionsWithDefaults = SwipeOptions & DefaultSwipeOptions;
|
|
74
80
|
export declare class Swipe {
|
|
75
81
|
readonly inputOption: SwipeOptions;
|
|
@@ -80,9 +86,10 @@ export declare class Swipe {
|
|
|
80
86
|
yEnd: number | undefined;
|
|
81
87
|
xDiff: number | undefined;
|
|
82
88
|
yDiff: number | undefined;
|
|
83
|
-
private
|
|
84
|
-
private readonly
|
|
85
|
-
private readonly
|
|
89
|
+
private pointerDown;
|
|
90
|
+
private readonly onPointerDownCallback;
|
|
91
|
+
private readonly onPointerMoveCallback;
|
|
92
|
+
private readonly onPointerUpCallback;
|
|
86
93
|
private readonly onMouseWheelCallback;
|
|
87
94
|
readonly start: (element?: typeof this.options.element) => void;
|
|
88
95
|
readonly stop: () => void;
|
|
@@ -91,11 +98,12 @@ export declare class Swipe {
|
|
|
91
98
|
private startListening;
|
|
92
99
|
private stopListening;
|
|
93
100
|
private setElement;
|
|
101
|
+
private isPointerAllowed;
|
|
94
102
|
private handleMouseWheel;
|
|
95
|
-
private
|
|
103
|
+
private handlePointerDown;
|
|
96
104
|
private emitValuesChanged;
|
|
97
|
-
private
|
|
98
|
-
private
|
|
105
|
+
private handlePointerMove;
|
|
106
|
+
private handlePointerUp;
|
|
99
107
|
private runCallbacks;
|
|
100
108
|
private resetValues;
|
|
101
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var defaultOptions={
|
|
1
|
+
var defaultOptions={preventDefaultOnMove:!1,preventDefaultOnMouseWheel:!1,threshold:50,immediate:!1,triggerOnEnd:!1};var Swipe=class{inputOption;element;xStart;yStart;xEnd;yEnd;xDiff;yDiff;pointerDown=!1;onPointerDownCallback;onPointerMoveCallback;onPointerUpCallback;onMouseWheelCallback;start;stop;options;constructor(inputOption){this.inputOption=inputOption,this.options={...defaultOptions,...inputOption},this.onPointerDownCallback=this.handlePointerDown.bind(this),this.onPointerMoveCallback=this.handlePointerMove.bind(this),this.onPointerUpCallback=this.handlePointerUp.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()}startListening(){this.setElement(this.options.element),this.element?.addEventListener(`pointerdown`,this.onPointerDownCallback,{passive:!0}),this.element?.addEventListener(`pointermove`,this.onPointerMoveCallback,{passive:!this.options.preventDefaultOnMove}),this.element?.addEventListener(`pointerup`,this.onPointerUpCallback,{passive:!0}),this.element?.addEventListener(`pointercancel`,this.onPointerUpCallback,{passive:!0}),this.options.preventDefaultOnMouseWheel&&this.element?.addEventListener(`mousewheel`,this.onMouseWheelCallback,{passive:!1})}stopListening(){this.element?.removeEventListener(`pointerdown`,this.onPointerDownCallback),this.element?.removeEventListener(`pointermove`,this.onPointerMoveCallback),this.element?.removeEventListener(`pointerup`,this.onPointerUpCallback),this.element?.removeEventListener(`pointercancel`,this.onPointerUpCallback),this.options.preventDefaultOnMouseWheel&&this.element?.removeEventListener(`mousewheel`,this.onMouseWheelCallback)}setElement(element){if(!element){console.error(`[maz-ui][SwipeHandler](setElement) Element should be provided. Its can be a string selector or an HTMLElement`);return}if(typeof element==`string`){let foundElement=document.querySelector(element);if(!(foundElement instanceof HTMLElement)){console.error(`[maz-ui][SwipeHandler](setElement) String selector for element is not found`);return}this.element=foundElement}else this.element=element}isPointerAllowed(event){let type=event.pointerType;return!this.options.pointerTypes||!type||this.options.pointerTypes.includes(type)}handleMouseWheel(event){event.preventDefault()}handlePointerDown(event){this.isPointerAllowed(event)&&(this.pointerDown=!0,this.xStart=event.clientX,this.yStart=event.clientY,this.emitValuesChanged())}emitValuesChanged(){this.options.onValuesChanged?.({xStart:this.xStart,yStart:this.yStart,xEnd:this.xEnd,yEnd:this.yEnd,xDiff:this.xDiff,yDiff:this.yDiff})}handlePointerMove(event){this.pointerDown&&(this.options.preventDefaultOnMove&&event.cancelable&&event.preventDefault(),this.xEnd=event.clientX,this.yEnd=event.clientY,this.xStart!==void 0&&this.yStart!==void 0&&(this.xDiff=this.xStart-this.xEnd,this.yDiff=this.yStart-this.yEnd,this.emitValuesChanged(),this.options.triggerOnEnd||this.runCallbacks(event)))}handlePointerUp(event){this.options.triggerOnEnd&&(this.runCallbacks(event),this.emitValuesChanged()),this.pointerDown=!1}runCallbacks(event){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()))}resetValues(){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()}};export{Swipe};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isClient}from"./isClient.js";var UserVisibility=class{eventHandlerFunction;event=`visibilitychange`;timeoutHandler;options;defaultOptions={timeout:5e3,once:!1,immediate:!0};isVisible=!1;constructor(callback,options){this.callback=callback,this.options={...this.defaultOptions,...options},this.eventHandlerFunction=this.eventHandler.bind(this),isClient()&&this.start()}start(){if(!isClient()){console.warn(`[UserVisibility](start) you should run this method on client side`);return}this.options.immediate&&this.emitCallback(),this.addEventListener()}emitCallback(){this.isVisible=document.visibilityState===`visible`,this.callback({isVisible:this.isVisible}),this.options.once&&this.destroy()}eventHandler(){document.visibilityState===`visible`&&!this.isVisible?(this.clearTimeout(),this.emitCallback()):document.visibilityState===`hidden`&&this.initTimeout()}clearTimeout(){this.timeoutHandler&&=(clearTimeout(this.timeoutHandler),void 0)}initTimeout(){this.clearTimeout(),this.timeoutHandler=setTimeout(this.emitCallback.bind(this),this.options.timeout)}addEventListener(){document.addEventListener(this.event,this.eventHandlerFunction)}removeEventListener(){document.removeEventListener(this.event,this.eventHandlerFunction)}destroy(){this.removeEventListener(),this.timeoutHandler&&clearTimeout(this.timeoutHandler)}};export{UserVisibility};
|
|
1
|
+
import{isClient}from"./isClient.js";var UserVisibility=class{callback;eventHandlerFunction;event=`visibilitychange`;timeoutHandler;options;defaultOptions={timeout:5e3,once:!1,immediate:!0};isVisible=!1;constructor(callback,options){this.callback=callback,this.options={...this.defaultOptions,...options},this.eventHandlerFunction=this.eventHandler.bind(this),isClient()&&this.start()}start(){if(!isClient()){console.warn(`[UserVisibility](start) you should run this method on client side`);return}this.options.immediate&&this.emitCallback(),this.addEventListener()}emitCallback(){this.isVisible=document.visibilityState===`visible`,this.callback({isVisible:this.isVisible}),this.options.once&&this.destroy()}eventHandler(){document.visibilityState===`visible`&&!this.isVisible?(this.clearTimeout(),this.emitCallback()):document.visibilityState===`hidden`&&this.initTimeout()}clearTimeout(){this.timeoutHandler&&=(clearTimeout(this.timeoutHandler),void 0)}initTimeout(){this.clearTimeout(),this.timeoutHandler=setTimeout(this.emitCallback.bind(this),this.options.timeout)}addEventListener(){document.addEventListener(this.event,this.eventHandlerFunction)}removeEventListener(){document.removeEventListener(this.event,this.eventHandlerFunction)}destroy(){this.removeEventListener(),this.timeoutHandler&&clearTimeout(this.timeoutHandler)}};export{UserVisibility};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{camelCase}from"./helpers/camelCase.js";import{capitalize}from"./helpers/capitalize.js";import{checkAvailability}from"./helpers/checkAvailability.js";import{truthyFilter}from"./helpers/truthyFilter.js";import{countryCodeToUnicodeFlag}from"./helpers/countryCodeToUnicodeFlag.js";import{debounce}from"./helpers/debounce.js";import{debounceCallback}from"./helpers/debounceCallback.js";import{debounceId}from"./helpers/debounceId.js";import{formatCurrency}from"./helpers/formatCurrency.js";import{formatDate}from"./helpers/formatDate.js";import{formatJson}from"./helpers/formatJson.js";import{formatNumber}from"./helpers/formatNumber.js";import{
|
|
1
|
+
import{camelCase}from"./helpers/camelCase.js";import{capitalize}from"./helpers/capitalize.js";import{checkAvailability}from"./helpers/checkAvailability.js";import{isServer}from"./helpers/isServer.js";import{deleteCookie,getCookie,setCookie}from"./helpers/cookie.js";import{truthyFilter}from"./helpers/truthyFilter.js";import{countryCodeToUnicodeFlag}from"./helpers/countryCodeToUnicodeFlag.js";import{debounce}from"./helpers/debounce.js";import{debounceCallback}from"./helpers/debounceCallback.js";import{debounceId}from"./helpers/debounceId.js";import{fetchLocaleIp}from"./helpers/fetchLocaleIp.js";import{formatCurrency}from"./helpers/formatCurrency.js";import{formatDate}from"./helpers/formatDate.js";import{formatJson}from"./helpers/formatJson.js";import{formatNumber}from"./helpers/formatNumber.js";import{formatPhoneNumber}from"./helpers/formatPhoneNumber.js";import{getBrowserLocale}from"./helpers/getBrowserLocale.js";import{getCountryFlagUrl}from"./helpers/getCountryFlagUrl.js";import{getErrorMessage}from"./helpers/getErrorMessage.js";import{isClient}from"./helpers/isClient.js";import{IdleTimeout}from"./helpers/idleTimeout.js";import{isEqual}from"./helpers/isEqual.js";import{isStandaloneMode}from"./helpers/isStandaloneMode.js";import{kebabCase}from"./helpers/kebabCase.js";import{pascalCase}from"./helpers/pascalCase.js";import{snakeCase}from"./helpers/snakeCase.js";import{normalizeString}from"./helpers/normalizeString.js";import{ScriptLoader}from"./helpers/scriptLoader.js";import{sleep}from"./helpers/sleep.js";import{Swipe}from"./helpers/swipeHandler.js";import{TextareaAutogrow}from"./helpers/TextareaAutogrow.js";import{throttle}from"./helpers/throttle.js";import{throttleId}from"./helpers/throttleId.js";import{upperFirst}from"./helpers/upperFirst.js";import{UserVisibility}from"./helpers/userVisibility.js";import"./helpers/index.js";export{IdleTimeout,ScriptLoader,Swipe,TextareaAutogrow,UserVisibility,camelCase,capitalize,checkAvailability,countryCodeToUnicodeFlag,debounce,debounceCallback,debounceId,deleteCookie,fetchLocaleIp,formatCurrency,formatDate,formatJson,formatNumber,formatPhoneNumber,getBrowserLocale,getCookie,getCountryFlagUrl,getErrorMessage,isClient,isEqual,isServer,isStandaloneMode,kebabCase,normalizeString,pascalCase,setCookie,sleep,snakeCase,throttle,throttleId,truthyFilter,upperFirst};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maz-ui/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.0-beta.
|
|
4
|
+
"version": "5.0.0-beta.46",
|
|
5
5
|
"description": "Utils of maz-ui for JavaScript/TypeScript users",
|
|
6
6
|
"author": "Louis Mazel <me@loicmazuel.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -61,8 +61,17 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=18.0.0"
|
|
63
63
|
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"libphonenumber-js": ">= 1 < 2"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"libphonenumber-js": {
|
|
69
|
+
"optional": true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
64
72
|
"devDependencies": {
|
|
65
|
-
"
|
|
73
|
+
"@maz-ui/vite-config": "0.0.0",
|
|
74
|
+
"libphonenumber-js": "^1.13.14"
|
|
66
75
|
},
|
|
67
76
|
"lint-staged": {
|
|
68
77
|
"*.{js,jsx,ts,tsx,mjs,mts,cjs,md,yml,json}": [
|
|
@@ -70,7 +79,6 @@
|
|
|
70
79
|
]
|
|
71
80
|
},
|
|
72
81
|
"scripts": {
|
|
73
|
-
"codegen": "nx build",
|
|
74
82
|
"build": "vite build",
|
|
75
83
|
"build:watch": "vite build --watch --mode development",
|
|
76
84
|
"typecheck": "tsc --noEmit --skipLibCheck",
|