@maz-ui/utils 5.0.0-beta.3 → 5.0.0-beta.39

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.
@@ -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=3600*24*365;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
- 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";var IdleTimeout=class{callback;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,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';
@@ -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{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";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};
@@ -6,7 +6,7 @@ export interface SwipeValues {
6
6
  xDiff: number | undefined;
7
7
  yDiff: number | undefined;
8
8
  }
9
- export type SwipeEventCallback = (event: TouchEvent) => void;
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 touchmove event.
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
- preventDefaultOnTouchMove?: boolean;
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
- * Whether to trigger the swipe event immediately on touchstart/mousedown.
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 touchend/mouseup.
67
- * If set to true, the swipe event will be triggered only when the user lifts their finger/mouse.
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, 'preventDefaultOnTouchMove' | 'preventDefaultOnMouseWheel' | 'threshold' | 'immediate' | 'triggerOnEnd'>>;
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 readonly onToucheStartCallback;
84
- private readonly onToucheMoveCallback;
85
- private readonly onToucheEndCallback;
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 toucheStartHandler;
103
+ private handlePointerDown;
96
104
  private emitValuesChanged;
97
- private handleTouchMove;
98
- private handleTouchEnd;
105
+ private handlePointerMove;
106
+ private handlePointerUp;
99
107
  private runCallbacks;
100
108
  private resetValues;
101
109
  }
@@ -1 +1 @@
1
- var defaultOptions={preventDefaultOnTouchMove:!1,preventDefaultOnMouseWheel:!1,threshold:50,immediate:!1,triggerOnEnd:!1};var Swipe=class{element;xStart;yStart;xEnd;yEnd;xDiff;yDiff;onToucheStartCallback;onToucheMoveCallback;onToucheEndCallback;onMouseWheelCallback;start;stop;options;constructor(inputOption){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()}startListening(){this.setElement(this.options.element),this.element?.addEventListener(`touchstart`,this.onToucheStartCallback,{passive:!0}),this.element?.addEventListener(`touchmove`,this.onToucheMoveCallback,{passive:!0}),this.options.triggerOnEnd&&this.element?.addEventListener(`touchend`,this.onToucheEndCallback,{passive:!0}),this.options.preventDefaultOnMouseWheel&&this.element?.addEventListener(`mousewheel`,this.onMouseWheelCallback,{passive:!1})}stopListening(){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)}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}handleMouseWheel(event){event.preventDefault()}toucheStartHandler(event){this.xStart=event.touches[0].clientX,this.yStart=event.touches[0].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})}handleTouchMove(event){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))}handleTouchEnd(event){this.runCallbacks(event),this.emitValuesChanged()}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
+ 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{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{isServer}from"./helpers/isServer.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,formatCurrency,formatDate,formatJson,formatNumber,getCountryFlagUrl,getErrorMessage,isClient,isEqual,isServer,isStandaloneMode,kebabCase,normalizeString,pascalCase,sleep,snakeCase,throttle,throttleId,truthyFilter,upperFirst};
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.3",
4
+ "version": "5.0.0-beta.39",
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
- "libphonenumber-js": "^1.12.42"
73
+ "libphonenumber-js": "^1.13.6",
74
+ "@maz-ui/vite-config": "0.0.0"
66
75
  },
67
76
  "lint-staged": {
68
77
  "*.{js,jsx,ts,tsx,mjs,mts,cjs,md,yml,json}": [