polpo 0.1.11 → 0.1.13

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/hooks.js CHANGED
@@ -1,3 +1,999 @@
1
1
  "use client";
2
- import{useCallback as p,useMemo as j,useReducer as F}from"react";import{useCallback as G,useLayoutEffect as w,useRef as B}from"react";var M=e=>{let t=B(!1);return w(()=>(t.current=!0,()=>{t.current=!1}),[]),G((...n)=>{t.current&&e(...n)},[e])};var _=(e,t)=>{switch(t.type){case"pending":return{status:"pending",data:null,error:null};case"resolved":return{status:"resolved",data:t.data,error:null};case"rejected":return{status:"rejected",data:null,error:t.error};default:throw new Error(`Unhandled action: ${JSON.stringify(t)}`)}},Qe=e=>{let[t,n]=F(_,{status:"idle",data:null,error:null,...e}),o=M(n),r=p(u=>{o({type:"pending"}),u.then(a=>{o({type:"resolved",data:a})},a=>{o({type:"rejected",error:a})})},[o]),s=p(u=>o({type:"resolved",data:u}),[o]),i=p(u=>o({type:"rejected",error:u}),[o]);return j(()=>({setData:s,setError:i,run:r,...t}),[t,r,s,i])};import{useMemo as $}from"react";var Ze=e=>$(()=>Object.entries(e).reduce((t,[n,o])=>o?[...t,n]:t,[]).join(" "),[e]);import{useEffect as U,useLayoutEffect as z,useRef as V}from"react";function l(e,t,n,o){let r=V(t);U(()=>{r.current=t},[t]),z(()=>{let s=n?.current??window;if(!(s&&s.addEventListener))return;let i=u=>r.current(u);return s.addEventListener(e,i,o),()=>{s.removeEventListener(e,i,o)}},[e,n,o])}var Y=(e,t)=>e.current&&!e.current.contains(t),rt=(e,t)=>{l("keydown",n=>{n.key==="Escape"&&t()}),l("mousedown",n=>{let o=n.target;if(!o?.isConnected)return;(Array.isArray(e)?e:[e]).every(s=>Y(s,o))&&t()})};import{useState as X}from"react";var at=e=>X(e)[0];import{useState as W,useCallback as O}from"react";var Q=e=>{let t=[];if(e.expires instanceof Date)t.push(`expires=${e.expires.toUTCString()}`);else if(typeof e.days=="number"){let n=new Date;n.setTime(n.getTime()+e.days*24*60*60*1e3),t.push(`expires=${n.toUTCString()}`)}return typeof e.maxAge=="number"&&t.push(`max-age=${e.maxAge}`),t.push(`path=${e.path??"/"}`),e.domain&&t.push(`domain=${e.domain}`),e.secure&&t.push("secure"),e.sameSite&&t.push(`SameSite=${e.sameSite}`),t.length>0?`; ${t.join("; ")}`:""},y=(e,t,n={})=>{if(typeof document>"u")return;let o=encodeURIComponent(t),r=Q(n);document.cookie=`${e}=${o}${r}`},J=e=>{if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie?document.cookie.split(";"):[];for(let o of n){let r=o.trim();if(r.indexOf(t)===0)return decodeURIComponent(r.substring(t.length))}return null},K=(e,t={})=>{typeof document>"u"||y(e,"",{...t,days:-1})},lt=(e,t,n={})=>{let[o,r]=W(()=>{let u=J(e);if(u!==null)try{return JSON.parse(u)}catch{return t}return t}),s=O((u,a={})=>{let c={...n,...a},m=JSON.stringify(u);y(e,m,c),r(u)},[e,n]),i=O(()=>{K(e,n),r(t)},[e,t,n]);return[o,s,i]};import{useEffect as Z,useState as q}from"react";var R=(e,t=500)=>{let[n,o]=q(e);return Z(()=>{let r=setTimeout(()=>o(e),t);return()=>{clearTimeout(r)}},[e,t]),n};import{useState as ee}from"react";var Et=(e,t=500)=>{let[n,o]=ee(e),r=R(n,t);return[n,r,o]};import{useState as ne}from"react";import{useEffect as te}from"react";var d=(e,t)=>{te(()=>{let n=Array.isArray(e)?e:[e],o=new ResizeObserver(t);return n.forEach(r=>r.current&&o.observe(r.current)),()=>{o.disconnect()}},[e,t])};var Rt=e=>{let[t,n]=ne({width:0,height:0});return d(e,([o])=>{if((o?.borderBoxSize??[])[0]){let{inlineSize:r,blockSize:s}=o.borderBoxSize[0];n({width:r,height:s})}else if(o.contentRect){let{width:r,height:s}=o.contentRect;n({width:r,height:s})}}),t};import{useEffect as oe,useState as re}from"react";var g=e=>{let t=document.getElementById(e);return t===null&&(t=document.createElement("div"),t.setAttribute("id",e),document.body.appendChild(t)),t},Pt=e=>{let[t,n]=re(()=>g(e));return oe(()=>{let o=document.getElementById(e);if(t===null||o===null){let r=g(e);n(r)}return()=>{t&&t.parentNode&&process.env.NODE_ENV==="production"&&document.body.removeChild(t)}},[t,e]),t};import{useEffect as ae,useState as ue}from"react";var h=(e,t=2)=>{if(e===0)return"0 Bytes";let n=1e3,o=t<0?0:t,r=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],s=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/Math.pow(n,s)).toFixed(o))+" "+r[s]};var P=({c:e,m:t,offset:n,position:o})=>{let r=e.y+e.h+n,s=e.x-(t.w-e.w)*(50/100);switch(o){case"top":case"top center":r=e.y-t.h-n,s=e.x-(t.w-e.w)/2;break;case"top left":r=e.y-t.h-n,s=e.x-t.w+e.w;break;case"top right":r=e.y-t.h-n,s=e.x;break;case"bottom":case"bottom center":r=e.y+e.h+n,s=e.x-(t.w-e.w)/2;break;case"bottom left":r=e.y+e.h+n,s=e.x-t.w+e.w;break;case"bottom right":r=e.y+e.h+n,s=e.x;break;case"left":case"left center":r=e.y-(t.h-e.h)/2,s=e.x-t.w-n;break;case"left top":r=e.y-t.h+e.h,s=e.x-t.w-n;break;case"left bottom":r=e.y,s=e.x-t.w-n;break;case"right":case"right center":r=e.y-(t.h-e.h)/2,s=e.x+e.w+n;break;case"right top":r=e.y-t.h+e.h,s=e.x+e.w+n;break;case"right bottom":r=e.y,s=e.x+e.w+n;break}return{left:Math.round(s),top:Math.round(r)}},se=({top:e,left:t},n,o,r)=>{let s=n.split(" "),i=[],u=t+r.w+o-window.innerWidth,a=e+r.h+o-window.innerHeight;for(let c of s)c==="top"&&e<o?i.push("bottom"):c==="left"&&t<o?i.push("right"):c==="bottom"&&a>0?i.push("top"):c==="right"&&u>0?i.push("left"):i.push(c);return i.join(" ")},ie=({top:e,left:t},n,o)=>{let r=t+n.w+o-window.innerWidth,s=e+n.h+o-window.innerHeight;return t=r>0?t-r:t,e=s>0?e-s:e,t=t<o?o:t,e=e<o?o:e,{top:e,left:t}},C=({c:e,m:t,offset:n,windowOffset:o,position:r})=>{let s={c:e,m:t,offset:n,position:r},i=P(s),u=se(i,r,o,t);u!==r&&(i=P({...s,position:u}));let a=ie(i,t,o);return{left:`${a.left}px`,top:`${a.top}px`}};var S=({position:e,windowOffset:t})=>{switch(e){case"center":return{top:"50%",left:"50%",transform:"translate(-50%, -50%)"};case"top":case"top center":return{top:`${t}px`,left:"50%",transform:"translateX(-50%)"};case"top left":case"left top":return{top:`${t}px`,left:`${t}px`};case"top right":case"right top":return{top:`${t}px`,right:`${t}px`};case"bottom":case"bottom center":return{bottom:`${t}px`,left:"50%",transform:"translateX(-50%)"};case"left bottom":case"bottom left":return{bottom:`${t}px`,left:`${t}px`};case"right bottom":case"bottom right":return{bottom:`${t}px`,right:`${t}px`};case"left":case"left center":return{top:"50%",left:`${t}px`,transform:"translateY(-50%)"};case"right":case"right center":return{top:"50%",right:`${t}px`,transform:"translateY(-50%)"}}return{top:"50%",left:"50%",transform:"translate(-50%, -50%)"}};var ce=(n=>(n.PNG="image/png",n.PDF="application/pdf",n))(ce||{}),It=e=>{let[t,n]=ue([]);return ae(()=>{let o=[],r=!1;if(!Array.isArray(e)||e.length===0)n([]);else{let s=e.map(i=>new Promise((u,a)=>{let c=new FileReader;o.push(c),c.onload=m=>{m.target?.result&&u({name:i.name,size:i.size,formatSize:h(i.size),type:i.type,url:m.target.result})},c.onabort=()=>{a(new Error("File reading aborted"))},c.onerror=()=>{a(new Error("Failed to read file"))},c.readAsDataURL(i)}));Promise.all(s).then(i=>{r||n(i)})}return()=>{r=!0,o.forEach(s=>{s.abort()})}},[e]),t};import{useEffect as le,useRef as me,useState as T}from"react";var Gt=()=>{let[e,t]=T(null),[n,o]=T(null),[r,s]=T(!0),i=me(null);return le(()=>{if(!navigator.geolocation){o({code:0,message:"Geolocation is not supported by your browser."}),s(!1);return}let u=c=>{t({...c.coords,timestamp:c.timestamp}),s(!1)},a=c=>{o({code:c.code,message:c.message}),s(!1)};return navigator.geolocation.getCurrentPosition(u,a),i.current=navigator.geolocation.watchPosition(u,a),()=>{i.current!==null&&navigator.geolocation.clearWatch(i.current)}},[]),{data:e,error:n,isLoading:r}};import{useCallback as L,useRef as de,useState as pe}from"react";var Ft=()=>{let[e,t]=pe(!1),n=de(null),o=L(()=>t(!0),[]),r=L(()=>t(!1),[]);return l("mouseenter",o,n),l("mouseleave",r,n),e};import{useRef as fe,useState as Ee}from"react";import{useEffect as Te}from"react";var k=(e,t,n={})=>{Te(()=>{let o=Array.isArray(e)?e:[e],r=new IntersectionObserver(t,n);return o.forEach(s=>s.current&&r.observe(s.current)),()=>{r.disconnect()}},[t,n,e])};var Xt=(e={})=>{let[t,n]=Ee(!1),o=fe(null);return k(o,([r])=>{n(r.isIntersecting)},e),{ref:o,inView:t}};import{useCallback as f,useState as ve}from"react";var Kt=({onBlur:e,onFocus:t,onChange:n}={})=>{let[o,r]=ve(!1),s=f(a=>{r(!0),t&&t(a)},[t]),i=f(a=>{r(!1),e&&e(a)},[e]),u=f(a=>{n&&n(a)},[n]);return{isFocus:o,handlers:{onFocus:s,onBlur:i,onChange:u}}};import{useEffect as be,useState as xe}from"react";var en=e=>{let[t,n]=xe(!1);return be(()=>{let o=window.matchMedia(e);o.matches!==t&&n(o.matches);let r=()=>{n(o.matches)};return o.addEventListener("change",r),()=>{o.removeEventListener("change",r)}},[t,e]),t};import{useRef as Me,useState as Oe}from"react";var on=()=>{let e=Me(null),[t,n]=Oe(!1);return{containerRef:e,isOpen:t,openModal:()=>{n(!0)},closeModal:()=>{n(!1)}}};import{useCallback as N,useLayoutEffect as ye,useRef as Re}from"react";var H=e=>({x:e.x,y:e.y,w:e.width,h:e.height,top:e.top,left:e.left}),pn=({offset:e=0,windowOffset:t=0,position:n="bottom",modalRef:o,containerRef:r,isOpen:s})=>{let i=Re(null),u=N((c,m)=>{let E=c.current?.getClientRects()[0],v=m.current?.getClientRects()[0];if(!E)return;let b=v?C({c:H(v),m:H(E),offset:e,windowOffset:t,position:n}):S({position:n,windowOffset:t});Object.keys(b).forEach(x=>{c.current?.style.setProperty(x,b[x])})},[n,t,e]),a=N(()=>{s&&u(o,r??i)},[u,s,r,o]);ye(a,[a]),d(r??i,a),d(o,a),l("resize",a),l("scroll",a,o)};import ge,{useCallback as I,useEffect as he,useLayoutEffect as Pe,useMemo as Ce}from"react";var Se=(r=>(r.OPENING="OPENING",r.OPEN="OPEN",r.CLOSING="CLOSING",r.CLOSED="CLOSED",r))(Se||{}),En=({transitionDuration:e=0,isOpen:t})=>{let[n,o]=ge.useState("CLOSED"),r=Ce(()=>n!=="CLOSED",[n]);he(()=>{document.documentElement.style.overflow=r?"hidden":"auto"},[r]);let s=I(()=>{["OPENING","OPEN"].includes(n)&&(e>0?(o("CLOSING"),setTimeout(()=>{o("CLOSED")},e)):o("CLOSED"))},[n,e]),i=I(()=>{["CLOSING","CLOSED"].includes(n)&&(e>0?(o("OPENING"),setTimeout(()=>{o("OPEN")},e)):o("OPEN"))},[n,e]);return Pe(()=>{n==="CLOSED"&&t?i():n==="OPEN"&&!t&&s()},[t,i,s,n]),{isVisible:r,modalState:n}};import{useRef as Le,useState as ke}from"react";var A=(e,t)=>{let{left:n,top:o}=e,r=n+window.scrollX,s=o+window.scrollY,i=t.pageX-r,u=t.pageY-s;return{x:t.pageX,y:t.pageY,elementX:i,elementY:u,elementPositionX:r,elementPositionY:s}},On=e=>{let t=Le(null),[n,o]=ke({x:null,y:null,elementX:null,elementY:null,elementPositionX:null,elementPositionY:null});return l("mousemove",s=>{let{clientX:i,clientY:u}=s;if(o(a=>({...a,x:i,y:u})),e?.current instanceof Element){let a=A(e.current.getBoundingClientRect(),s);o(c=>({...c,...a}))}else if(t.current instanceof Element){let a=A(t.current.getBoundingClientRect(),s);o(c=>({...c,...a}))}}),{...n,ref:t}};import{useState as Ne}from"react";var hn=()=>{let[e,t]=Ne(navigator.onLine);return l("online",()=>t(navigator.onLine)),l("offline",()=>t(navigator.onLine)),e};import{useEffect as He,useRef as Ie}from"react";var Sn=()=>{let e=Ie(1);return He(()=>{e.current++}),e.current};import{useEffect as Ae,useRef as De,useState as Ge}from"react";var Nn=()=>{let e=De(null),[t,n]=Ge([0,0]);return Ae(()=>{let o=e.current,r=()=>{o&&n([o.scrollLeft,o.scrollTop])};return o&&o.addEventListener("scroll",r),()=>{o&&o.removeEventListener("scroll",r)}},[]),{ref:e,position:t}};import{useEffect as we,useState as D}from"react";function Gn(e){let[t,n]=D(e),[o,r]=D([]);return we(()=>{t!==void 0&&r(s=>[...s,t])},[t]),[t,n,o]}import{useCallback as Be,useState as je}from"react";var jn=(e=!1)=>{let[t,n]=je(e),o=Be(()=>{n(r=>!r)},[]);return[t,o,n]};import{useCallback as Fe,useState as _e}from"react";var $n=(e,t=0)=>{let[n,o]=_e(t),r=Fe(s=>{o(s!==void 0?s:i=>(i+1)%e.length)},[e.length]);return[e[n],r]};import{useEffect as $e,useState as Ue}from"react";var Yn=()=>{let e=()=>{let{innerWidth:o,innerHeight:r}=window;return{width:o,height:r,orientation:o>r?"landscape":"portrait"}},[t,n]=Ue(e);return l("resize",()=>{n(e())}),$e(()=>{n(e())},[]),t};export{ce as FileTypeEnum,Se as ModalState,Qe as useAsync,Ze as useClassNames,rt as useClickOutside,at as useConstant,lt as useCookie,R as useDebounce,Et as useDebounceState,Rt as useDimensions,Pt as useDomContainer,l as useEventListener,It as useFileReader,Gt as useGeolocation,Ft as useHover,Xt as useInView,Kt as useInputHandlers,k as useIntersectionObserver,en as useMediaQuery,on as useModal,pn as useModalInContainer,En as useModalTransition,On as useMousePosition,hn as useOnlineStatus,Sn as useRenderCount,d as useResizeObserver,M as useSafeDispatch,Nn as useScroll,Gn as useStateHistory,jn as useToggle,$n as useToggleValues,Yn as useViewport};
2
+
3
+ // src/hooks/use-async.ts
4
+ import { useCallback as useCallback2, useMemo, useReducer } from "react";
5
+
6
+ // src/hooks/use-safe-dispatch.ts
7
+ import { useCallback, useLayoutEffect, useRef } from "react";
8
+ var useSafeDispatch = (dispatch) => {
9
+ const mounted = useRef(false);
10
+ useLayoutEffect(() => {
11
+ mounted.current = true;
12
+ return () => {
13
+ mounted.current = false;
14
+ };
15
+ }, []);
16
+ return useCallback(
17
+ (...args) => {
18
+ if (mounted.current) {
19
+ dispatch(...args);
20
+ }
21
+ },
22
+ [dispatch]
23
+ );
24
+ };
25
+
26
+ // src/hooks/use-async.ts
27
+ var asyncReducer = (_state, action) => {
28
+ switch (action.type) {
29
+ case "pending": {
30
+ return { status: "pending", data: null, error: null };
31
+ }
32
+ case "resolved": {
33
+ return { status: "resolved", data: action.data, error: null };
34
+ }
35
+ case "rejected": {
36
+ return { status: "rejected", data: null, error: action.error };
37
+ }
38
+ default: {
39
+ throw new Error(`Unhandled action: ${JSON.stringify(action)}`);
40
+ }
41
+ }
42
+ };
43
+ var useAsync = (initialState) => {
44
+ const [asyncState, unsafeDispatch] = useReducer(asyncReducer, {
45
+ status: "idle",
46
+ data: null,
47
+ error: null,
48
+ ...initialState
49
+ });
50
+ const dispatch = useSafeDispatch(unsafeDispatch);
51
+ const run = useCallback2(
52
+ (promise) => {
53
+ dispatch({ type: "pending" });
54
+ promise.then(
55
+ (data) => {
56
+ dispatch({ type: "resolved", data });
57
+ },
58
+ (error) => {
59
+ dispatch({ type: "rejected", error });
60
+ }
61
+ );
62
+ },
63
+ [dispatch]
64
+ );
65
+ const setData = useCallback2((data) => dispatch({ type: "resolved", data }), [dispatch]);
66
+ const setError = useCallback2((error) => dispatch({ type: "rejected", error }), [dispatch]);
67
+ return useMemo(
68
+ () => ({
69
+ setData,
70
+ setError,
71
+ run,
72
+ ...asyncState
73
+ }),
74
+ [asyncState, run, setData, setError]
75
+ );
76
+ };
77
+
78
+ // src/hooks/use-classnames.ts
79
+ import { useMemo as useMemo2 } from "react";
80
+ var useClassNames = (classes) => useMemo2(
81
+ () => Object.entries(classes).reduce(
82
+ (compiledClassNames, [classname, value]) => value ? [...compiledClassNames, classname] : compiledClassNames,
83
+ []
84
+ ).join(" "),
85
+ [classes]
86
+ );
87
+
88
+ // src/hooks/use-event-listener.ts
89
+ import { useEffect, useLayoutEffect as useLayoutEffect2, useRef as useRef2 } from "react";
90
+ function useEventListener(eventName, callback, element, options) {
91
+ const callbackRef = useRef2(callback);
92
+ useEffect(() => {
93
+ callbackRef.current = callback;
94
+ }, [callback]);
95
+ useLayoutEffect2(() => {
96
+ const targetElement = element?.current ?? window;
97
+ if (!(targetElement && targetElement.addEventListener)) return;
98
+ const listener = (event) => callbackRef.current(event);
99
+ targetElement.addEventListener(eventName, listener, options);
100
+ return () => {
101
+ targetElement.removeEventListener(eventName, listener, options);
102
+ };
103
+ }, [eventName, element, options]);
104
+ }
105
+
106
+ // src/hooks/use-click-outside.ts
107
+ var checkIsOutside = (ref, target) => {
108
+ return ref.current && !ref.current.contains(target);
109
+ };
110
+ var useClickOutside = (ref, callback) => {
111
+ useEventListener("keydown", (e) => {
112
+ if (e.key === "Escape") {
113
+ callback();
114
+ }
115
+ });
116
+ useEventListener("mousedown", (event) => {
117
+ const target = event.target;
118
+ if (!target?.isConnected) {
119
+ return;
120
+ }
121
+ const isOutside = (Array.isArray(ref) ? ref : [ref]).every((r) => checkIsOutside(r, target));
122
+ if (isOutside) {
123
+ callback();
124
+ }
125
+ });
126
+ };
127
+
128
+ // src/hooks/use-constant.ts
129
+ import { useState } from "react";
130
+ var useConstant = (initializer) => useState(initializer)[0];
131
+
132
+ // src/hooks/use-cookie.ts
133
+ import { useState as useState2, useCallback as useCallback3 } from "react";
134
+ var generateCookieAttributes = (options) => {
135
+ const parts = [];
136
+ if (options.expires instanceof Date) {
137
+ parts.push(`expires=${options.expires.toUTCString()}`);
138
+ } else if (typeof options.days === "number") {
139
+ const date = /* @__PURE__ */ new Date();
140
+ date.setTime(date.getTime() + options.days * 24 * 60 * 60 * 1e3);
141
+ parts.push(`expires=${date.toUTCString()}`);
142
+ }
143
+ if (typeof options.maxAge === "number") {
144
+ parts.push(`max-age=${options.maxAge}`);
145
+ }
146
+ parts.push(`path=${options.path ?? "/"}`);
147
+ if (options.domain) {
148
+ parts.push(`domain=${options.domain}`);
149
+ }
150
+ if (options.secure) {
151
+ parts.push("secure");
152
+ }
153
+ if (options.sameSite) {
154
+ parts.push(`SameSite=${options.sameSite}`);
155
+ }
156
+ return parts.length > 0 ? `; ${parts.join("; ")}` : "";
157
+ };
158
+ var setCookie = (name, value, options = {}) => {
159
+ if (typeof document === "undefined") {
160
+ return;
161
+ }
162
+ const encodedValue = encodeURIComponent(value);
163
+ const attributes = generateCookieAttributes(options);
164
+ document.cookie = `${name}=${encodedValue}${attributes}`;
165
+ };
166
+ var getCookie = (name) => {
167
+ if (typeof document === "undefined") {
168
+ return null;
169
+ }
170
+ const nameEq = `${name}=`;
171
+ const cookies = document.cookie ? document.cookie.split(";") : [];
172
+ for (const cookie of cookies) {
173
+ const cookieTrimmed = cookie.trim();
174
+ if (cookieTrimmed.indexOf(nameEq) === 0) {
175
+ return decodeURIComponent(cookieTrimmed.substring(nameEq.length));
176
+ }
177
+ }
178
+ return null;
179
+ };
180
+ var deleteCookie = (name, options = {}) => {
181
+ if (typeof document === "undefined") {
182
+ return;
183
+ }
184
+ setCookie(name, "", {
185
+ ...options,
186
+ days: -1
187
+ });
188
+ };
189
+ var useCookie = (cookieName, defaultValue, options = {}) => {
190
+ const [cookieValue, setCookieValue] = useState2(() => {
191
+ const rawCookie = getCookie(cookieName);
192
+ if (rawCookie !== null) {
193
+ try {
194
+ return JSON.parse(rawCookie);
195
+ } catch {
196
+ return defaultValue;
197
+ }
198
+ }
199
+ return defaultValue;
200
+ });
201
+ const updateCookie = useCallback3(
202
+ (value, overrideOptions = {}) => {
203
+ const mergedOptions = { ...options, ...overrideOptions };
204
+ const stringValue = JSON.stringify(value);
205
+ setCookie(cookieName, stringValue, mergedOptions);
206
+ setCookieValue(value);
207
+ },
208
+ [cookieName, options]
209
+ );
210
+ const removeCookie = useCallback3(() => {
211
+ deleteCookie(cookieName, options);
212
+ setCookieValue(defaultValue);
213
+ }, [cookieName, defaultValue, options]);
214
+ return [cookieValue, updateCookie, removeCookie];
215
+ };
216
+
217
+ // src/hooks/use-debounce.ts
218
+ import { useEffect as useEffect2, useState as useState3 } from "react";
219
+ var useDebounce = (value, delay = 500) => {
220
+ const [debouncedValue, setDebouncedValue] = useState3(value);
221
+ useEffect2(() => {
222
+ const timer = setTimeout(() => setDebouncedValue(value), delay);
223
+ return () => {
224
+ clearTimeout(timer);
225
+ };
226
+ }, [value, delay]);
227
+ return debouncedValue;
228
+ };
229
+
230
+ // src/hooks/use-debounce-state.ts
231
+ import { useState as useState4 } from "react";
232
+ var useDebounceState = (defaultValue, delay = 500) => {
233
+ const [value, setValue] = useState4(defaultValue);
234
+ const debouncedValue = useDebounce(value, delay);
235
+ return [value, debouncedValue, setValue];
236
+ };
237
+
238
+ // src/hooks/use-dimensions.ts
239
+ import { useState as useState5 } from "react";
240
+
241
+ // src/hooks/use-resize-observer.ts
242
+ import { useEffect as useEffect3 } from "react";
243
+ var useResizeObserver = (ref, callback) => {
244
+ useEffect3(() => {
245
+ const refs = Array.isArray(ref) ? ref : [ref];
246
+ const observer = new ResizeObserver(callback);
247
+ refs.forEach((r) => r.current && observer.observe(r.current));
248
+ return () => {
249
+ observer.disconnect();
250
+ };
251
+ }, [ref, callback]);
252
+ };
253
+
254
+ // src/hooks/use-dimensions.ts
255
+ var useDimensions = (ref) => {
256
+ const [dimensions, setDimensions] = useState5({ width: 0, height: 0 });
257
+ useResizeObserver(ref, ([entry]) => {
258
+ if ((entry?.borderBoxSize ?? [])[0]) {
259
+ const { inlineSize: width, blockSize: height } = entry.borderBoxSize[0];
260
+ setDimensions({ width, height });
261
+ } else if (entry.contentRect) {
262
+ const { width, height } = entry.contentRect;
263
+ setDimensions({ width, height });
264
+ }
265
+ });
266
+ return dimensions;
267
+ };
268
+
269
+ // src/hooks/use-dom-container.ts
270
+ import { useEffect as useEffect4, useState as useState6 } from "react";
271
+ var createContainer = (containerID) => {
272
+ let domContainer = document.getElementById(containerID);
273
+ if (domContainer === null) {
274
+ domContainer = document.createElement("div");
275
+ domContainer.setAttribute("id", containerID);
276
+ document.body.appendChild(domContainer);
277
+ }
278
+ return domContainer;
279
+ };
280
+ var useDomContainer = (containerID) => {
281
+ const [container, setContainer] = useState6(() => createContainer(containerID));
282
+ useEffect4(() => {
283
+ const domContainer = document.getElementById(containerID);
284
+ if (container === null || domContainer === null) {
285
+ const domContainer2 = createContainer(containerID);
286
+ setContainer(domContainer2);
287
+ }
288
+ return () => {
289
+ if (container && container.parentNode && process.env.NODE_ENV === "production") {
290
+ document.body.removeChild(container);
291
+ }
292
+ };
293
+ }, [container, containerID]);
294
+ return container;
295
+ };
296
+
297
+ // src/hooks/use-file-reader.ts
298
+ import { useEffect as useEffect5, useState as useState7 } from "react";
299
+
300
+ // src/helpers/format-bytes.ts
301
+ var formatBytes = (bytes, decimals = 2) => {
302
+ if (bytes === 0) return "0 Bytes";
303
+ const k = 1e3;
304
+ const dm = decimals < 0 ? 0 : decimals;
305
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
306
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
307
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
308
+ };
309
+
310
+ // src/helpers/get-modal-position.ts
311
+ var getModalPosition = ({ c, m, offset, position }) => {
312
+ let top = c.y + c.h + offset;
313
+ let left = c.x - (m.w - c.w) * (50 / 100);
314
+ switch (position) {
315
+ case "top" /* TOP */:
316
+ case "top center" /* TOP_CENTER */:
317
+ top = c.y - m.h - offset;
318
+ left = c.x - (m.w - c.w) / 2;
319
+ break;
320
+ case "top left" /* TOP_LEFT */:
321
+ top = c.y - m.h - offset;
322
+ left = c.x - m.w + c.w;
323
+ break;
324
+ case "top right" /* TOP_RIGHT */:
325
+ top = c.y - m.h - offset;
326
+ left = c.x;
327
+ break;
328
+ case "bottom" /* BOTTOM */:
329
+ case "bottom center" /* BOTTOM_CENTER */:
330
+ top = c.y + c.h + offset;
331
+ left = c.x - (m.w - c.w) / 2;
332
+ break;
333
+ case "bottom left" /* BOTTOM_LEFT */:
334
+ top = c.y + c.h + offset;
335
+ left = c.x - m.w + c.w;
336
+ break;
337
+ case "bottom right" /* BOTTOM_RIGHT */:
338
+ top = c.y + c.h + offset;
339
+ left = c.x;
340
+ break;
341
+ case "left" /* LEFT */:
342
+ case "left center" /* LEFT_CENTER */:
343
+ top = c.y - (m.h - c.h) / 2;
344
+ left = c.x - m.w - offset;
345
+ break;
346
+ case "left top" /* LEFT_TOP */:
347
+ top = c.y - m.h + c.h;
348
+ left = c.x - m.w - offset;
349
+ break;
350
+ case "left bottom" /* LEFT_BOTTOM */:
351
+ top = c.y;
352
+ left = c.x - m.w - offset;
353
+ break;
354
+ case "right" /* RIGHT */:
355
+ case "right center" /* RIGHT_CENTER */:
356
+ top = c.y - (m.h - c.h) / 2;
357
+ left = c.x + c.w + offset;
358
+ break;
359
+ case "right top" /* RIGHT_TOP */:
360
+ top = c.y - m.h + c.h;
361
+ left = c.x + c.w + offset;
362
+ break;
363
+ case "right bottom" /* RIGHT_BOTTOM */:
364
+ top = c.y;
365
+ left = c.x + c.w + offset;
366
+ break;
367
+ }
368
+ return {
369
+ left: Math.round(left),
370
+ top: Math.round(top)
371
+ };
372
+ };
373
+ var getOppositePosition = ({ top, left }, position, windowOffset, m) => {
374
+ const positions = position.split(" ");
375
+ const newPosition = [];
376
+ const rightOffset = left + m.w + windowOffset - window.innerWidth;
377
+ const bottomOffset = top + m.h + windowOffset - window.innerHeight;
378
+ for (const p of positions) {
379
+ if (p === "top" /* TOP */ && top < windowOffset) {
380
+ newPosition.push("bottom" /* BOTTOM */);
381
+ } else if (p === "left" /* LEFT */ && left < windowOffset) {
382
+ newPosition.push("right" /* RIGHT */);
383
+ } else if (p === "bottom" /* BOTTOM */ && bottomOffset > 0) {
384
+ newPosition.push("top" /* TOP */);
385
+ } else if (p === "right" /* RIGHT */ && rightOffset > 0) {
386
+ newPosition.push("left" /* LEFT */);
387
+ } else {
388
+ newPosition.push(p);
389
+ }
390
+ }
391
+ return newPosition.join(" ");
392
+ };
393
+ var fixModalPosition = ({ top, left }, m, windowOffset) => {
394
+ const rightOffset = left + m.w + windowOffset - window.innerWidth;
395
+ const bottomOffset = top + m.h + windowOffset - window.innerHeight;
396
+ left = rightOffset > 0 ? left - rightOffset : left;
397
+ top = bottomOffset > 0 ? top - bottomOffset : top;
398
+ left = left < windowOffset ? windowOffset : left;
399
+ top = top < windowOffset ? windowOffset : top;
400
+ return { top, left };
401
+ };
402
+ var getModalPositionRelativeToContainer = ({
403
+ c,
404
+ m,
405
+ offset,
406
+ windowOffset,
407
+ position
408
+ }) => {
409
+ const params = { c, m, offset, position };
410
+ let modalContainerStyle = getModalPosition(params);
411
+ const oppositePosition = getOppositePosition(modalContainerStyle, position, windowOffset, m);
412
+ if (oppositePosition !== position) {
413
+ modalContainerStyle = getModalPosition({
414
+ ...params,
415
+ position: oppositePosition
416
+ });
417
+ }
418
+ const fixedPosition = fixModalPosition(modalContainerStyle, m, windowOffset);
419
+ return {
420
+ left: `${fixedPosition.left}px`,
421
+ top: `${fixedPosition.top}px`
422
+ };
423
+ };
424
+
425
+ // src/helpers/get-modal-position-relative-to-screen.ts
426
+ var getModalPositionRelativeToScreen = ({
427
+ position,
428
+ windowOffset
429
+ }) => {
430
+ switch (position) {
431
+ case "center" /* CENTER */:
432
+ return {
433
+ top: "50%",
434
+ left: "50%",
435
+ transform: "translate(-50%, -50%)"
436
+ };
437
+ case "top" /* TOP */:
438
+ case "top center" /* TOP_CENTER */:
439
+ return {
440
+ top: `${windowOffset}px`,
441
+ left: "50%",
442
+ transform: "translateX(-50%)"
443
+ };
444
+ case "top left" /* TOP_LEFT */:
445
+ case "left top" /* LEFT_TOP */:
446
+ return {
447
+ top: `${windowOffset}px`,
448
+ left: `${windowOffset}px`
449
+ };
450
+ case "top right" /* TOP_RIGHT */:
451
+ case "right top" /* RIGHT_TOP */:
452
+ return {
453
+ top: `${windowOffset}px`,
454
+ right: `${windowOffset}px`
455
+ };
456
+ case "bottom" /* BOTTOM */:
457
+ case "bottom center" /* BOTTOM_CENTER */:
458
+ return {
459
+ bottom: `${windowOffset}px`,
460
+ left: "50%",
461
+ transform: "translateX(-50%)"
462
+ };
463
+ case "left bottom" /* LEFT_BOTTOM */:
464
+ case "bottom left" /* BOTTOM_LEFT */:
465
+ return {
466
+ bottom: `${windowOffset}px`,
467
+ left: `${windowOffset}px`
468
+ };
469
+ case "right bottom" /* RIGHT_BOTTOM */:
470
+ case "bottom right" /* BOTTOM_RIGHT */:
471
+ return {
472
+ bottom: `${windowOffset}px`,
473
+ right: `${windowOffset}px`
474
+ };
475
+ case "left" /* LEFT */:
476
+ case "left center" /* LEFT_CENTER */:
477
+ return {
478
+ top: "50%",
479
+ left: `${windowOffset}px`,
480
+ transform: "translateY(-50%)"
481
+ };
482
+ case "right" /* RIGHT */:
483
+ case "right center" /* RIGHT_CENTER */:
484
+ return {
485
+ top: "50%",
486
+ right: `${windowOffset}px`,
487
+ transform: "translateY(-50%)"
488
+ };
489
+ }
490
+ return {
491
+ top: "50%",
492
+ left: "50%",
493
+ transform: "translate(-50%, -50%)"
494
+ };
495
+ };
496
+
497
+ // src/hooks/use-file-reader.ts
498
+ var FileTypeEnum = /* @__PURE__ */ ((FileTypeEnum2) => {
499
+ FileTypeEnum2["PNG"] = "image/png";
500
+ FileTypeEnum2["PDF"] = "application/pdf";
501
+ return FileTypeEnum2;
502
+ })(FileTypeEnum || {});
503
+ var useFileReader = (inputFiles) => {
504
+ const [files, setFiles] = useState7([]);
505
+ useEffect5(() => {
506
+ const fileReaders = [];
507
+ let isCancel = false;
508
+ if (!Array.isArray(inputFiles) || inputFiles.length === 0) {
509
+ setFiles([]);
510
+ } else {
511
+ const promises = inputFiles.map((file) => {
512
+ return new Promise((resolve, reject) => {
513
+ const fileReader = new FileReader();
514
+ fileReaders.push(fileReader);
515
+ fileReader.onload = (e) => {
516
+ if (e.target?.result) {
517
+ resolve({
518
+ name: file.name,
519
+ size: file.size,
520
+ formatSize: formatBytes(file.size),
521
+ type: file.type,
522
+ url: e.target.result
523
+ });
524
+ }
525
+ };
526
+ fileReader.onabort = () => {
527
+ reject(new Error("File reading aborted"));
528
+ };
529
+ fileReader.onerror = () => {
530
+ reject(new Error("Failed to read file"));
531
+ };
532
+ fileReader.readAsDataURL(file);
533
+ });
534
+ });
535
+ Promise.all(promises).then((files2) => {
536
+ if (!isCancel) {
537
+ setFiles(files2);
538
+ }
539
+ });
540
+ }
541
+ return () => {
542
+ isCancel = true;
543
+ fileReaders.forEach((fileReader) => {
544
+ fileReader.abort();
545
+ });
546
+ };
547
+ }, [inputFiles]);
548
+ return files;
549
+ };
550
+
551
+ // src/hooks/use-geolocation.ts
552
+ import { useEffect as useEffect6, useRef as useRef3, useState as useState8 } from "react";
553
+ var useGeolocation = () => {
554
+ const [data, setData] = useState8(null);
555
+ const [error, setError] = useState8(null);
556
+ const [isLoading, setIsLoading] = useState8(true);
557
+ const watchIdRef = useRef3(null);
558
+ useEffect6(() => {
559
+ if (!navigator.geolocation) {
560
+ setError({
561
+ code: 0,
562
+ message: "Geolocation is not supported by your browser."
563
+ });
564
+ setIsLoading(false);
565
+ return;
566
+ }
567
+ const handleSuccess = (position) => {
568
+ setData({
569
+ ...position.coords,
570
+ timestamp: position.timestamp
571
+ });
572
+ setIsLoading(false);
573
+ };
574
+ const handleError = (geolocationError) => {
575
+ setError({
576
+ code: geolocationError.code,
577
+ message: geolocationError.message
578
+ });
579
+ setIsLoading(false);
580
+ };
581
+ navigator.geolocation.getCurrentPosition(handleSuccess, handleError);
582
+ watchIdRef.current = navigator.geolocation.watchPosition(handleSuccess, handleError);
583
+ return () => {
584
+ if (watchIdRef.current !== null) {
585
+ navigator.geolocation.clearWatch(watchIdRef.current);
586
+ }
587
+ };
588
+ }, []);
589
+ return { data, error, isLoading };
590
+ };
591
+
592
+ // src/hooks/use-hover.ts
593
+ import { useCallback as useCallback4, useRef as useRef4, useState as useState9 } from "react";
594
+ var useHover = () => {
595
+ const [isHovered, setIsHovered] = useState9(false);
596
+ const ref = useRef4(null);
597
+ const handleMouseEnter = useCallback4(() => setIsHovered(true), []);
598
+ const handleMouseLeave = useCallback4(() => setIsHovered(false), []);
599
+ useEventListener("mouseenter", handleMouseEnter, ref);
600
+ useEventListener("mouseleave", handleMouseLeave, ref);
601
+ return isHovered;
602
+ };
603
+
604
+ // src/hooks/use-in-view.ts
605
+ import { useRef as useRef5, useState as useState10 } from "react";
606
+
607
+ // src/hooks/use-intersection-observer.ts
608
+ import { useEffect as useEffect7 } from "react";
609
+ var useIntersectionObserver = (ref, callback, initOptions = {}) => {
610
+ useEffect7(() => {
611
+ const refs = Array.isArray(ref) ? ref : [ref];
612
+ const observer = new IntersectionObserver(callback, initOptions);
613
+ refs.forEach((r) => r.current && observer.observe(r.current));
614
+ return () => {
615
+ observer.disconnect();
616
+ };
617
+ }, [callback, initOptions, ref]);
618
+ };
619
+
620
+ // src/hooks/use-in-view.ts
621
+ var useInView = (initOptions = {}) => {
622
+ const [inView, setInView] = useState10(false);
623
+ const ref = useRef5(null);
624
+ useIntersectionObserver(
625
+ ref,
626
+ ([entry]) => {
627
+ setInView(entry.isIntersecting);
628
+ },
629
+ initOptions
630
+ );
631
+ return { ref, inView };
632
+ };
633
+
634
+ // src/hooks/use-input-handlers.ts
635
+ import { useCallback as useCallback5, useState as useState11 } from "react";
636
+ var useInputHandlers = ({
637
+ onBlur,
638
+ onFocus,
639
+ onChange
640
+ } = {}) => {
641
+ const [isFocus, setIsFocus] = useState11(false);
642
+ const handleFocus = useCallback5(
643
+ (e) => {
644
+ setIsFocus(true);
645
+ onFocus && onFocus(e);
646
+ },
647
+ [onFocus]
648
+ );
649
+ const handleBlur = useCallback5(
650
+ (e) => {
651
+ setIsFocus(false);
652
+ onBlur && onBlur(e);
653
+ },
654
+ [onBlur]
655
+ );
656
+ const handleChange = useCallback5(
657
+ (e) => {
658
+ onChange && onChange(e);
659
+ },
660
+ [onChange]
661
+ );
662
+ return {
663
+ isFocus,
664
+ handlers: {
665
+ onFocus: handleFocus,
666
+ onBlur: handleBlur,
667
+ onChange: handleChange
668
+ }
669
+ };
670
+ };
671
+
672
+ // src/hooks/use-media-query.ts
673
+ import { useEffect as useEffect8, useState as useState12 } from "react";
674
+ var useMediaQuery = (query) => {
675
+ const [matches, setMatches] = useState12(false);
676
+ useEffect8(() => {
677
+ const media = window.matchMedia(query);
678
+ if (media.matches !== matches) {
679
+ setMatches(media.matches);
680
+ }
681
+ const listener = () => {
682
+ setMatches(media.matches);
683
+ };
684
+ media.addEventListener("change", listener);
685
+ return () => {
686
+ media.removeEventListener("change", listener);
687
+ };
688
+ }, [matches, query]);
689
+ return matches;
690
+ };
691
+
692
+ // src/hooks/use-modal.ts
693
+ import { useRef as useRef6, useState as useState13 } from "react";
694
+ var useModal = () => {
695
+ const containerRef = useRef6(null);
696
+ const [isOpen, setIsOpen] = useState13(false);
697
+ const openModal = () => {
698
+ setIsOpen(true);
699
+ };
700
+ const closeModal = () => {
701
+ setIsOpen(false);
702
+ };
703
+ return {
704
+ containerRef,
705
+ isOpen,
706
+ openModal,
707
+ closeModal
708
+ };
709
+ };
710
+
711
+ // src/hooks/use-modal-in-container.ts
712
+ import { useCallback as useCallback6, useLayoutEffect as useLayoutEffect3, useRef as useRef7 } from "react";
713
+ var convertDOMRectToPosition = (rect) => ({
714
+ x: rect.x,
715
+ y: rect.y,
716
+ w: rect.width,
717
+ h: rect.height,
718
+ top: rect.top,
719
+ left: rect.left
720
+ });
721
+ var useModalInContainer = ({
722
+ offset = 0,
723
+ windowOffset = 0,
724
+ position = "bottom" /* BOTTOM */,
725
+ modalRef,
726
+ containerRef,
727
+ isOpen
728
+ }) => {
729
+ const containerTemporalRef = useRef7(null);
730
+ const getPosition = useCallback6(
731
+ (modalRef2, containerRef2) => {
732
+ const modal = modalRef2.current?.getClientRects()[0];
733
+ const container = containerRef2.current?.getClientRects()[0];
734
+ if (!modal) {
735
+ return;
736
+ }
737
+ const modalStyle = !container ? getModalPositionRelativeToScreen({ position, windowOffset }) : getModalPositionRelativeToContainer({
738
+ c: convertDOMRectToPosition(container),
739
+ m: convertDOMRectToPosition(modal),
740
+ offset,
741
+ windowOffset,
742
+ position
743
+ });
744
+ Object.keys(modalStyle).forEach((key) => {
745
+ modalRef2.current?.style.setProperty(key, modalStyle[key]);
746
+ });
747
+ },
748
+ [position, windowOffset, offset]
749
+ );
750
+ const callback = useCallback6(() => {
751
+ if (isOpen) {
752
+ getPosition(modalRef, containerRef ?? containerTemporalRef);
753
+ }
754
+ }, [getPosition, isOpen, containerRef, modalRef]);
755
+ useLayoutEffect3(callback, [callback]);
756
+ useResizeObserver(containerRef ?? containerTemporalRef, callback);
757
+ useResizeObserver(modalRef, callback);
758
+ useEventListener("resize", callback);
759
+ useEventListener("scroll", callback, modalRef);
760
+ };
761
+
762
+ // src/hooks/use-modal-transition.ts
763
+ import React3, { useCallback as useCallback7, useEffect as useEffect9, useLayoutEffect as useLayoutEffect4, useMemo as useMemo3 } from "react";
764
+ var ModalState = /* @__PURE__ */ ((ModalState2) => {
765
+ ModalState2["OPENING"] = "OPENING";
766
+ ModalState2["OPEN"] = "OPEN";
767
+ ModalState2["CLOSING"] = "CLOSING";
768
+ ModalState2["CLOSED"] = "CLOSED";
769
+ return ModalState2;
770
+ })(ModalState || {});
771
+ var useModalTransition = ({ transitionDuration = 0, isOpen }) => {
772
+ const [modalState, setModalState] = React3.useState("CLOSED" /* CLOSED */);
773
+ const isVisible = useMemo3(() => {
774
+ return modalState !== "CLOSED" /* CLOSED */;
775
+ }, [modalState]);
776
+ useEffect9(() => {
777
+ document.documentElement.style.overflow = isVisible ? "hidden" : "auto";
778
+ }, [isVisible]);
779
+ const closeModal = useCallback7(() => {
780
+ if (["OPENING" /* OPENING */, "OPEN" /* OPEN */].includes(modalState)) {
781
+ if (transitionDuration > 0) {
782
+ setModalState("CLOSING" /* CLOSING */);
783
+ setTimeout(() => {
784
+ setModalState("CLOSED" /* CLOSED */);
785
+ }, transitionDuration);
786
+ } else {
787
+ setModalState("CLOSED" /* CLOSED */);
788
+ }
789
+ }
790
+ }, [modalState, transitionDuration]);
791
+ const openModal = useCallback7(() => {
792
+ if (["CLOSING" /* CLOSING */, "CLOSED" /* CLOSED */].includes(modalState)) {
793
+ if (transitionDuration > 0) {
794
+ setModalState("OPENING" /* OPENING */);
795
+ setTimeout(() => {
796
+ setModalState("OPEN" /* OPEN */);
797
+ }, transitionDuration);
798
+ } else {
799
+ setModalState("OPEN" /* OPEN */);
800
+ }
801
+ }
802
+ }, [modalState, transitionDuration]);
803
+ useLayoutEffect4(() => {
804
+ if (modalState === "CLOSED" /* CLOSED */ && isOpen) {
805
+ openModal();
806
+ } else if (modalState === "OPEN" /* OPEN */ && !isOpen) {
807
+ closeModal();
808
+ }
809
+ }, [isOpen, openModal, closeModal, modalState]);
810
+ return {
811
+ isVisible,
812
+ modalState
813
+ };
814
+ };
815
+
816
+ // src/hooks/use-mouse-position.ts
817
+ import { useRef as useRef8, useState as useState14 } from "react";
818
+ var getMousePosition = (domRect, e) => {
819
+ const { left, top } = domRect;
820
+ const containerPositionX = left + window.scrollX;
821
+ const containerPositionY = top + window.scrollY;
822
+ const containerX = e.pageX - containerPositionX;
823
+ const containerY = e.pageY - containerPositionY;
824
+ return {
825
+ x: e.pageX,
826
+ y: e.pageY,
827
+ elementX: containerX,
828
+ elementY: containerY,
829
+ elementPositionX: containerPositionX,
830
+ elementPositionY: containerPositionY
831
+ };
832
+ };
833
+ var useMousePosition = (containerRef) => {
834
+ const ref = useRef8(null);
835
+ const [position, setPosition] = useState14({
836
+ x: null,
837
+ y: null,
838
+ elementX: null,
839
+ elementY: null,
840
+ elementPositionX: null,
841
+ elementPositionY: null
842
+ });
843
+ const mouseMove = (e) => {
844
+ const { clientX, clientY } = e;
845
+ setPosition((prev) => ({ ...prev, x: clientX, y: clientY }));
846
+ if (containerRef?.current instanceof Element) {
847
+ const newState = getMousePosition(containerRef.current.getBoundingClientRect(), e);
848
+ setPosition((prev) => ({
849
+ ...prev,
850
+ ...newState
851
+ }));
852
+ } else if (ref.current instanceof Element) {
853
+ const newState = getMousePosition(ref.current.getBoundingClientRect(), e);
854
+ setPosition((prev) => ({
855
+ ...prev,
856
+ ...newState
857
+ }));
858
+ }
859
+ };
860
+ useEventListener("mousemove", mouseMove);
861
+ return { ...position, ref };
862
+ };
863
+
864
+ // src/hooks/use-online-status.ts
865
+ import { useState as useState15 } from "react";
866
+ var useOnlineStatus = () => {
867
+ const [online, setOnline] = useState15(navigator.onLine);
868
+ useEventListener("online", () => setOnline(navigator.onLine));
869
+ useEventListener("offline", () => setOnline(navigator.onLine));
870
+ return online;
871
+ };
872
+
873
+ // src/hooks/use-render-count.ts
874
+ import { useEffect as useEffect10, useRef as useRef9 } from "react";
875
+ var useRenderCount = () => {
876
+ const count = useRef9(1);
877
+ useEffect10(() => {
878
+ count.current++;
879
+ });
880
+ return count.current;
881
+ };
882
+
883
+ // src/hooks/use-scroll.ts
884
+ import { useEffect as useEffect11, useRef as useRef10, useState as useState16 } from "react";
885
+ var useScroll = () => {
886
+ const ref = useRef10(null);
887
+ const [position, setPosition] = useState16([0, 0]);
888
+ useEffect11(() => {
889
+ const element = ref.current;
890
+ const handleScroll = () => {
891
+ if (!element) return;
892
+ setPosition([element.scrollLeft, element.scrollTop]);
893
+ };
894
+ if (element) {
895
+ element.addEventListener("scroll", handleScroll);
896
+ }
897
+ return () => {
898
+ if (element) {
899
+ element.removeEventListener("scroll", handleScroll);
900
+ }
901
+ };
902
+ }, []);
903
+ return {
904
+ ref,
905
+ position
906
+ };
907
+ };
908
+
909
+ // src/hooks/use-state-history.ts
910
+ import { useEffect as useEffect12, useState as useState17 } from "react";
911
+ function useStateHistory(initialState) {
912
+ const [state, setState] = useState17(initialState);
913
+ const [history, setHistory] = useState17([]);
914
+ useEffect12(() => {
915
+ if (state !== void 0) {
916
+ setHistory((prevHistory) => [...prevHistory, state]);
917
+ }
918
+ }, [state]);
919
+ return [state, setState, history];
920
+ }
921
+
922
+ // src/hooks/use-toggle.ts
923
+ import { useCallback as useCallback8, useState as useState18 } from "react";
924
+ var useToggle = (defaultValue = false) => {
925
+ const [value, setValue] = useState18(defaultValue);
926
+ const toggle = useCallback8(() => {
927
+ setValue((prev) => !prev);
928
+ }, []);
929
+ return [value, toggle, setValue];
930
+ };
931
+
932
+ // src/hooks/use-toggle-values.ts
933
+ import { useCallback as useCallback9, useState as useState19 } from "react";
934
+ var useToggleValues = (values, defaultIndex = 0) => {
935
+ const [index, setIndex] = useState19(defaultIndex);
936
+ const toggle = useCallback9(
937
+ (index2) => {
938
+ setIndex(index2 !== void 0 ? index2 : (prev) => (prev + 1) % values.length);
939
+ },
940
+ [values.length]
941
+ );
942
+ return [values[index], toggle];
943
+ };
944
+
945
+ // src/hooks/use-viewport.ts
946
+ import { useEffect as useEffect13, useState as useState20 } from "react";
947
+ var useViewport = () => {
948
+ const getData = () => {
949
+ const { innerWidth, innerHeight } = window;
950
+ return {
951
+ width: innerWidth,
952
+ height: innerHeight,
953
+ orientation: innerWidth > innerHeight ? "landscape" /* LANDSCAPE */ : "portrait" /* PORTRAIT */
954
+ };
955
+ };
956
+ const [data, setData] = useState20(getData);
957
+ useEventListener("resize", () => {
958
+ setData(getData());
959
+ });
960
+ useEffect13(() => {
961
+ setData(getData());
962
+ }, []);
963
+ return data;
964
+ };
965
+ export {
966
+ FileTypeEnum,
967
+ ModalState,
968
+ useAsync,
969
+ useClassNames,
970
+ useClickOutside,
971
+ useConstant,
972
+ useCookie,
973
+ useDebounce,
974
+ useDebounceState,
975
+ useDimensions,
976
+ useDomContainer,
977
+ useEventListener,
978
+ useFileReader,
979
+ useGeolocation,
980
+ useHover,
981
+ useInView,
982
+ useInputHandlers,
983
+ useIntersectionObserver,
984
+ useMediaQuery,
985
+ useModal,
986
+ useModalInContainer,
987
+ useModalTransition,
988
+ useMousePosition,
989
+ useOnlineStatus,
990
+ useRenderCount,
991
+ useResizeObserver,
992
+ useSafeDispatch,
993
+ useScroll,
994
+ useStateHistory,
995
+ useToggle,
996
+ useToggleValues,
997
+ useViewport
998
+ };
3
999
  //# sourceMappingURL=hooks.js.map