@ctlyst.id/utils 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),B=n=>n!=null&&typeof n=="object"&&"nodeType"in n&&n.nodeType===Node.ELEMENT_NODE,C=n=>B(n)?n.ownerDocument??document:document,w=(n,t)=>{var o;const e=n.target;return n.button>0||e&&!C(e).contains(e)?!1:!((o=t.current)!=null&&o.contains(e))},O=()=>!!(typeof window<"u"&&window.document&&window.document.createElement),M=O(),k=(n,t=[])=>{const e=l.useRef(n);return l.useEffect(()=>{e.current=n}),l.useCallback((...o)=>{var a;return(a=e.current)==null?void 0:a.call(e,...o)},t)},E=k;var $=function(){var n=document.getSelection();if(!n.rangeCount)return function(){};for(var t=document.activeElement,e=[],o=0;o<n.rangeCount;o++)e.push(n.getRangeAt(o));switch(t.tagName.toUpperCase()){case"INPUT":case"TEXTAREA":t.blur();break;default:t=null;break}return n.removeAllRanges(),function(){n.type==="Caret"&&n.removeAllRanges(),n.rangeCount||e.forEach(function(a){n.addRange(a)}),t&&t.focus()}},A=$,S={"text/plain":"Text","text/html":"Url",default:"Text"},I="Copy to clipboard: #{key}, Enter";function V(n){var t=(/mac os x/i.test(navigator.userAgent)?"⌘":"Ctrl")+"+C";return n.replace(/#{\s*key\s*}/g,t)}function U(n,t){var e,o,a,s,c,r,i=!1;t||(t={}),e=t.debug||!1;try{a=A(),s=document.createRange(),c=document.getSelection(),r=document.createElement("span"),r.textContent=n,r.ariaHidden="true",r.style.all="unset",r.style.position="fixed",r.style.top=0,r.style.clip="rect(0, 0, 0, 0)",r.style.whiteSpace="pre",r.style.webkitUserSelect="text",r.style.MozUserSelect="text",r.style.msUserSelect="text",r.style.userSelect="text",r.addEventListener("copy",function(u){if(u.stopPropagation(),t.format)if(u.preventDefault(),typeof u.clipboardData>"u"){e&&console.warn("unable to use e.clipboardData"),e&&console.warn("trying IE specific stuff"),window.clipboardData.clearData();var f=S[t.format]||S.default;window.clipboardData.setData(f,n)}else u.clipboardData.clearData(),u.clipboardData.setData(t.format,n);t.onCopy&&(u.preventDefault(),t.onCopy(u.clipboardData))}),document.body.appendChild(r),s.selectNodeContents(r),c.addRange(s);var d=document.execCommand("copy");if(!d)throw new Error("copy command was unsuccessful");i=!0}catch(u){e&&console.error("unable to copy using execCommand: ",u),e&&console.warn("trying IE specific stuff");try{window.clipboardData.setData(t.format||"text",n),t.onCopy&&t.onCopy(window.clipboardData),i=!0}catch(f){e&&console.error("unable to copy using clipboardData: ",f),e&&console.error("falling back to prompt"),o=V("message"in t?t.message:I),window.prompt(o,n)}}finally{c&&(typeof c.removeRange=="function"?c.removeRange(s):c.removeAllRanges()),r&&document.body.removeChild(r),a()}return i}var F=U;const W=({value:n="",optionsOrTimeout:t={}}={})=>{const[e,o]=l.useState(!1),[a,s]=l.useState(n);l.useEffect(()=>s(n),[n]);const{timeout:c=1500,...r}=typeof t=="number"?{timeout:t}:t,i=l.useCallback(()=>{const d=F(a,r);o(d)},[a,r]);return l.useEffect(()=>{let d=null;return e&&(d=window.setTimeout(()=>{o(!1)},c)),()=>{d&&window.clearTimeout(d)}},[c,e]),{value:a,setValue:s,onCopy:i,hasCopied:e}},z=W,H=({value:n,thousandSeparator:t=".",decimalLength:e,decimalSeparator:o=",",code:a=""})=>{const c=(r=>{const i=r.toString().split("."),d=i[0].replace(/\B(?=(\d{3})+(?!\d))/g,t);let u="";return e!==void 0?i.length>1&&e>0?u=o+i[1].padEnd(e,"0").slice(0,e):e>0&&(u=o+"0".repeat(e)):i.length>1&&(u=o+i[1]),d+u})(n);return a?a+c:c},Q=H,j=({value:n,delay:t=500})=>{const[e,o]=l.useState(n);return l.useEffect(()=>{const a=setTimeout(()=>o(n),t||500);return()=>{clearTimeout(a)}},[n,t]),e},q=j;var K=process.env.NODE_ENV==="production",D="Invariant failed";function L(n,t){if(!n){if(K)throw new Error(D);var e=typeof t=="function"?t():t,o=e?"".concat(D,": ").concat(e):D;throw new Error(o)}}var b=function(t){var e=t.top,o=t.right,a=t.bottom,s=t.left,c=o-s,r=a-e,i={top:e,right:o,bottom:a,left:s,width:c,height:r,x:s,y:e,center:{x:(o+s)/2,y:(a+e)/2}};return i},X=function(t,e){return{top:t.top-e.top,left:t.left-e.left,bottom:t.bottom+e.bottom,right:t.right+e.right}},R=function(t,e){return{top:t.top+e.top,left:t.left+e.left,bottom:t.bottom-e.bottom,right:t.right-e.right}},y={top:0,right:0,bottom:0,left:0},G=function(t){var e=t.borderBox,o=t.margin,a=o===void 0?y:o,s=t.border,c=s===void 0?y:s,r=t.padding,i=r===void 0?y:r,d=b(X(e,a)),u=b(R(e,c)),f=b(R(u,i));return{marginBox:d,borderBox:b(e),paddingBox:u,contentBox:f,margin:a,border:c,padding:i}},m=function(t){var e=t.slice(0,-2),o=t.slice(-2);if(o!=="px")return 0;var a=Number(e);return isNaN(a)&&(process.env.NODE_ENV!=="production"?L(!1,"Could not parse value [raw: "+t+", without suffix: "+e+"]"):L(!1)),a},J=function(t,e){var o={top:m(e.marginTop),right:m(e.marginRight),bottom:m(e.marginBottom),left:m(e.marginLeft)},a={top:m(e.paddingTop),right:m(e.paddingRight),bottom:m(e.paddingBottom),left:m(e.paddingLeft)},s={top:m(e.borderTopWidth),right:m(e.borderRightWidth),bottom:m(e.borderBottomWidth),left:m(e.borderLeftWidth)};return G({borderBox:t,margin:o,padding:a,border:s})},Y=function(t){var e=t.getBoundingClientRect(),o=window.getComputedStyle(t);return J(e,o)};const Z=M?l.useLayoutEffect:l.useEffect,T=Z,_=(n,t)=>{const[e,o]=l.useState(null),a=l.useRef();return T(()=>{const s=()=>{const c=n.current;c&&(a.current=requestAnimationFrame(()=>{const r=Y(c);o(r)}))};return s(),t&&(window.addEventListener("resize",s),window.addEventListener("scroll",s)),()=>{t&&(window.removeEventListener("resize",s),window.removeEventListener("scroll",s)),a.current&&cancelAnimationFrame(a.current)}},[t]),e},ee=_,te=({onClose:n,onOpen:t,isOpen:e,defaultIsOpen:o,id:a}={})=>{const[s,c]=l.useState(o||!1),r=e!==void 0?e:s,i=e!==void 0,d=l.useId(),u=a??`disclosure-${d}`,f=E(t),v=E(n),p=l.useCallback(()=>{i||c(!1),v==null||v()},[i,v]),h=l.useCallback(()=>{i||c(!0),f==null||f()},[i,f]),x=l.useCallback(()=>{r?p():h()},[r,h,p]);return{onClose:p,onOpen:h,onToggle:x,getButtonProps:({onClick:g,...P}={})=>({...P,"aria-expanded":r,"aria-controls":u,onClick(N){g==null||g(N),x()}}),getDisclosureProps:({...g}={})=>({...g,hidden:!r,id:u}),isOpen:r}},ne=te,oe=(n,t={})=>{const{ssr:e=!0,fallback:o}=t,a=Array.isArray(n)?n:[n];let s=Array.isArray(o)?o:[o];s=s.filter(i=>i!=null);const[c,r]=l.useState(()=>a.map((i,d)=>({media:i,matches:e?!!s[d]:window.matchMedia(i).matches})));return l.useEffect(()=>{const i=window;r(a.map(f=>({media:f,matches:i.matchMedia(f).matches})));const d=a.map(f=>i.matchMedia(f)),u=f=>{r(v=>v.slice().map(p=>p.media===f.media?{...p,matches:f.matches}:p))};return d.forEach(f=>{f.addEventListener("change",u)}),()=>{d.forEach(f=>{f.removeEventListener("change",u)})}},[window]),c.map(i=>i.matches)},re=oe,ae=()=>{const[n,t]=l.useState(navigator.onLine);return l.useEffect(()=>{const e=()=>t(navigator.onLine);return window.addEventListener("online",e),window.addEventListener("offline",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}},[]),{isOnline:n,isOffline:!n}},se=ae,ie=({enabled:n=!0,ref:t,handler:e})=>{const o=E(e),s=l.useRef({isPointerDown:!1,ignoreEmulatedMouseEvents:!1}).current;l.useEffect(()=>{if(!n)return;const c=u=>{w(u,t)&&(s.isPointerDown=!0)},r=u=>{if(s.ignoreEmulatedMouseEvents){s.ignoreEmulatedMouseEvents=!1;return}s.isPointerDown&&e&&w(u,t)&&(s.isPointerDown=!1,o(u))},i=u=>{s.ignoreEmulatedMouseEvents=!0,e&&s.isPointerDown&&w(u,t)&&(s.isPointerDown=!1,o(u))},d=C(t.current);return d.addEventListener("mousedown",c,!0),d.addEventListener("mouseup",r,!0),d.addEventListener("touchstart",c,!0),d.addEventListener("touchend",i,!0),()=>{d.removeEventListener("mousedown",c,!0),d.removeEventListener("mouseup",r,!0),d.removeEventListener("touchstart",c,!0),d.removeEventListener("touchend",i,!0)}},[e,t,o,s,n])},ue=ie;exports.canUseDOM=O;exports.getOwnerDocument=C;exports.isBrowser=M;exports.isElement=B;exports.isValidEvent=w;exports.useCallbackRef=E;exports.useClipboard=z;exports.useCurrencyFormatter=Q;exports.useDebounce=q;exports.useDimensions=ee;exports.useDisclosure=ne;exports.useMediaQuery=re;exports.useOnlineStatus=se;exports.useOutsideClick=ue;exports.useSafeLayoutEffect=T;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef as L, useEffect as m, useCallback as b, useState as v, useLayoutEffect as
|
|
2
|
-
const
|
|
1
|
+
import { useRef as L, useEffect as m, useCallback as b, useState as v, useLayoutEffect as P, useId as $ } from "react";
|
|
2
|
+
const A = (n) => n != null && typeof n == "object" && "nodeType" in n && n.nodeType === Node.ELEMENT_NODE, T = (n) => A(n) ? n.ownerDocument ?? document : document, D = (n, t) => {
|
|
3
3
|
var o;
|
|
4
4
|
const e = n.target;
|
|
5
5
|
return n.button > 0 || e && !T(e).contains(e) ? !1 : !((o = t.current) != null && o.contains(e));
|
|
@@ -8,8 +8,8 @@ const $ = (n) => n != null && typeof n == "object" && "nodeType" in n && n.nodeT
|
|
|
8
8
|
return m(() => {
|
|
9
9
|
e.current = n;
|
|
10
10
|
}), b((...o) => {
|
|
11
|
-
var
|
|
12
|
-
return (
|
|
11
|
+
var a;
|
|
12
|
+
return (a = e.current) == null ? void 0 : a.call(e, ...o);
|
|
13
13
|
}, t);
|
|
14
14
|
}, x = V;
|
|
15
15
|
var U = function() {
|
|
@@ -29,105 +29,118 @@ var U = function() {
|
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
31
|
return n.removeAllRanges(), function() {
|
|
32
|
-
n.type === "Caret" && n.removeAllRanges(), n.rangeCount || e.forEach(function(
|
|
33
|
-
n.addRange(
|
|
32
|
+
n.type === "Caret" && n.removeAllRanges(), n.rangeCount || e.forEach(function(a) {
|
|
33
|
+
n.addRange(a);
|
|
34
34
|
}), t && t.focus();
|
|
35
35
|
};
|
|
36
|
-
},
|
|
36
|
+
}, F = U, S = {
|
|
37
37
|
"text/plain": "Text",
|
|
38
38
|
"text/html": "Url",
|
|
39
39
|
default: "Text"
|
|
40
|
-
},
|
|
41
|
-
function
|
|
40
|
+
}, W = "Copy to clipboard: #{key}, Enter";
|
|
41
|
+
function z(n) {
|
|
42
42
|
var t = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
|
|
43
43
|
return n.replace(/#{\s*key\s*}/g, t);
|
|
44
44
|
}
|
|
45
45
|
function H(n, t) {
|
|
46
|
-
var e, o,
|
|
46
|
+
var e, o, a, s, u, r, i = !1;
|
|
47
47
|
t || (t = {}), e = t.debug || !1;
|
|
48
48
|
try {
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
49
|
+
a = F(), s = document.createRange(), u = document.getSelection(), r = document.createElement("span"), r.textContent = n, r.ariaHidden = "true", r.style.all = "unset", r.style.position = "fixed", r.style.top = 0, r.style.clip = "rect(0, 0, 0, 0)", r.style.whiteSpace = "pre", r.style.webkitUserSelect = "text", r.style.MozUserSelect = "text", r.style.msUserSelect = "text", r.style.userSelect = "text", r.addEventListener("copy", function(c) {
|
|
50
|
+
if (c.stopPropagation(), t.format)
|
|
51
|
+
if (c.preventDefault(), typeof c.clipboardData > "u") {
|
|
52
52
|
e && console.warn("unable to use e.clipboardData"), e && console.warn("trying IE specific stuff"), window.clipboardData.clearData();
|
|
53
53
|
var l = S[t.format] || S.default;
|
|
54
54
|
window.clipboardData.setData(l, n);
|
|
55
55
|
} else
|
|
56
|
-
|
|
57
|
-
t.onCopy && (
|
|
58
|
-
}), document.body.appendChild(
|
|
56
|
+
c.clipboardData.clearData(), c.clipboardData.setData(t.format, n);
|
|
57
|
+
t.onCopy && (c.preventDefault(), t.onCopy(c.clipboardData));
|
|
58
|
+
}), document.body.appendChild(r), s.selectNodeContents(r), u.addRange(s);
|
|
59
59
|
var d = document.execCommand("copy");
|
|
60
60
|
if (!d)
|
|
61
61
|
throw new Error("copy command was unsuccessful");
|
|
62
|
-
|
|
63
|
-
} catch (
|
|
64
|
-
e && console.error("unable to copy using execCommand: ",
|
|
62
|
+
i = !0;
|
|
63
|
+
} catch (c) {
|
|
64
|
+
e && console.error("unable to copy using execCommand: ", c), e && console.warn("trying IE specific stuff");
|
|
65
65
|
try {
|
|
66
|
-
window.clipboardData.setData(t.format || "text", n), t.onCopy && t.onCopy(window.clipboardData),
|
|
66
|
+
window.clipboardData.setData(t.format || "text", n), t.onCopy && t.onCopy(window.clipboardData), i = !0;
|
|
67
67
|
} catch (l) {
|
|
68
|
-
e && console.error("unable to copy using clipboardData: ", l), e && console.error("falling back to prompt"), o =
|
|
68
|
+
e && console.error("unable to copy using clipboardData: ", l), e && console.error("falling back to prompt"), o = z("message" in t ? t.message : W), window.prompt(o, n);
|
|
69
69
|
}
|
|
70
70
|
} finally {
|
|
71
|
-
|
|
71
|
+
u && (typeof u.removeRange == "function" ? u.removeRange(s) : u.removeAllRanges()), r && document.body.removeChild(r), a();
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return i;
|
|
74
74
|
}
|
|
75
75
|
var Q = H;
|
|
76
76
|
const j = ({ value: n = "", optionsOrTimeout: t = {} } = {}) => {
|
|
77
|
-
const [e, o] = v(!1), [
|
|
78
|
-
m(() =>
|
|
79
|
-
const { timeout:
|
|
80
|
-
const d = Q(
|
|
77
|
+
const [e, o] = v(!1), [a, s] = v(n);
|
|
78
|
+
m(() => s(n), [n]);
|
|
79
|
+
const { timeout: u = 1500, ...r } = typeof t == "number" ? { timeout: t } : t, i = b(() => {
|
|
80
|
+
const d = Q(a, r);
|
|
81
81
|
o(d);
|
|
82
|
-
}, [
|
|
82
|
+
}, [a, r]);
|
|
83
83
|
return m(() => {
|
|
84
84
|
let d = null;
|
|
85
85
|
return e && (d = window.setTimeout(() => {
|
|
86
86
|
o(!1);
|
|
87
|
-
},
|
|
87
|
+
}, u)), () => {
|
|
88
88
|
d && window.clearTimeout(d);
|
|
89
89
|
};
|
|
90
|
-
}, [
|
|
91
|
-
value:
|
|
92
|
-
setValue:
|
|
93
|
-
onCopy:
|
|
90
|
+
}, [u, e]), {
|
|
91
|
+
value: a,
|
|
92
|
+
setValue: s,
|
|
93
|
+
onCopy: i,
|
|
94
94
|
hasCopied: e
|
|
95
95
|
};
|
|
96
|
-
},
|
|
96
|
+
}, ue = j, q = ({
|
|
97
|
+
value: n,
|
|
98
|
+
thousandSeparator: t = ".",
|
|
99
|
+
decimalLength: e,
|
|
100
|
+
decimalSeparator: o = ",",
|
|
101
|
+
code: a = ""
|
|
102
|
+
}) => {
|
|
103
|
+
const u = ((r) => {
|
|
104
|
+
const i = r.toString().split("."), d = i[0].replace(/\B(?=(\d{3})+(?!\d))/g, t);
|
|
105
|
+
let c = "";
|
|
106
|
+
return e !== void 0 ? i.length > 1 && e > 0 ? c = o + i[1].padEnd(e, "0").slice(0, e) : e > 0 && (c = o + "0".repeat(e)) : i.length > 1 && (c = o + i[1]), d + c;
|
|
107
|
+
})(n);
|
|
108
|
+
return a ? a + u : u;
|
|
109
|
+
}, de = q, K = ({ value: n, delay: t = 500 }) => {
|
|
97
110
|
const [e, o] = v(n);
|
|
98
111
|
return m(() => {
|
|
99
|
-
const
|
|
112
|
+
const a = setTimeout(() => o(n), t || 500);
|
|
100
113
|
return () => {
|
|
101
|
-
clearTimeout(
|
|
114
|
+
clearTimeout(a);
|
|
102
115
|
};
|
|
103
116
|
}, [n, t]), e;
|
|
104
|
-
},
|
|
105
|
-
var
|
|
117
|
+
}, le = K;
|
|
118
|
+
var X = process.env.NODE_ENV === "production", y = "Invariant failed";
|
|
106
119
|
function B(n, t) {
|
|
107
120
|
if (!n) {
|
|
108
|
-
if (
|
|
121
|
+
if (X)
|
|
109
122
|
throw new Error(y);
|
|
110
123
|
var e = typeof t == "function" ? t() : t, o = e ? "".concat(y, ": ").concat(e) : y;
|
|
111
124
|
throw new Error(o);
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
127
|
var E = function(t) {
|
|
115
|
-
var e = t.top, o = t.right,
|
|
128
|
+
var e = t.top, o = t.right, a = t.bottom, s = t.left, u = o - s, r = a - e, i = {
|
|
116
129
|
top: e,
|
|
117
130
|
right: o,
|
|
118
|
-
bottom:
|
|
119
|
-
left:
|
|
120
|
-
width:
|
|
121
|
-
height:
|
|
122
|
-
x:
|
|
131
|
+
bottom: a,
|
|
132
|
+
left: s,
|
|
133
|
+
width: u,
|
|
134
|
+
height: r,
|
|
135
|
+
x: s,
|
|
123
136
|
y: e,
|
|
124
137
|
center: {
|
|
125
|
-
x: (o +
|
|
126
|
-
y: (
|
|
138
|
+
x: (o + s) / 2,
|
|
139
|
+
y: (a + e) / 2
|
|
127
140
|
}
|
|
128
141
|
};
|
|
129
|
-
return
|
|
130
|
-
},
|
|
142
|
+
return i;
|
|
143
|
+
}, G = function(t, e) {
|
|
131
144
|
return {
|
|
132
145
|
top: t.top - e.top,
|
|
133
146
|
left: t.left - e.left,
|
|
@@ -146,125 +159,125 @@ var E = function(t) {
|
|
|
146
159
|
right: 0,
|
|
147
160
|
bottom: 0,
|
|
148
161
|
left: 0
|
|
149
|
-
},
|
|
150
|
-
var e = t.borderBox, o = t.margin,
|
|
162
|
+
}, J = function(t) {
|
|
163
|
+
var e = t.borderBox, o = t.margin, a = o === void 0 ? C : o, s = t.border, u = s === void 0 ? C : s, r = t.padding, i = r === void 0 ? C : r, d = E(G(e, a)), c = E(O(e, u)), l = E(O(c, i));
|
|
151
164
|
return {
|
|
152
165
|
marginBox: d,
|
|
153
166
|
borderBox: E(e),
|
|
154
|
-
paddingBox:
|
|
167
|
+
paddingBox: c,
|
|
155
168
|
contentBox: l,
|
|
156
|
-
margin:
|
|
157
|
-
border:
|
|
158
|
-
padding:
|
|
169
|
+
margin: a,
|
|
170
|
+
border: u,
|
|
171
|
+
padding: i
|
|
159
172
|
};
|
|
160
173
|
}, f = function(t) {
|
|
161
174
|
var e = t.slice(0, -2), o = t.slice(-2);
|
|
162
175
|
if (o !== "px")
|
|
163
176
|
return 0;
|
|
164
|
-
var
|
|
165
|
-
return isNaN(
|
|
166
|
-
},
|
|
177
|
+
var a = Number(e);
|
|
178
|
+
return isNaN(a) && (process.env.NODE_ENV !== "production" ? B(!1, "Could not parse value [raw: " + t + ", without suffix: " + e + "]") : B(!1)), a;
|
|
179
|
+
}, Y = function(t, e) {
|
|
167
180
|
var o = {
|
|
168
181
|
top: f(e.marginTop),
|
|
169
182
|
right: f(e.marginRight),
|
|
170
183
|
bottom: f(e.marginBottom),
|
|
171
184
|
left: f(e.marginLeft)
|
|
172
|
-
},
|
|
185
|
+
}, a = {
|
|
173
186
|
top: f(e.paddingTop),
|
|
174
187
|
right: f(e.paddingRight),
|
|
175
188
|
bottom: f(e.paddingBottom),
|
|
176
189
|
left: f(e.paddingLeft)
|
|
177
|
-
},
|
|
190
|
+
}, s = {
|
|
178
191
|
top: f(e.borderTopWidth),
|
|
179
192
|
right: f(e.borderRightWidth),
|
|
180
193
|
bottom: f(e.borderBottomWidth),
|
|
181
194
|
left: f(e.borderLeftWidth)
|
|
182
195
|
};
|
|
183
|
-
return
|
|
196
|
+
return J({
|
|
184
197
|
borderBox: t,
|
|
185
198
|
margin: o,
|
|
186
|
-
padding:
|
|
187
|
-
border:
|
|
199
|
+
padding: a,
|
|
200
|
+
border: s
|
|
188
201
|
});
|
|
189
|
-
},
|
|
202
|
+
}, Z = function(t) {
|
|
190
203
|
var e = t.getBoundingClientRect(), o = window.getComputedStyle(t);
|
|
191
|
-
return
|
|
204
|
+
return Y(e, o);
|
|
192
205
|
};
|
|
193
|
-
const
|
|
194
|
-
const [e, o] = v(null),
|
|
195
|
-
return
|
|
196
|
-
const
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
o(
|
|
206
|
+
const _ = k ? P : m, ee = _, te = (n, t) => {
|
|
207
|
+
const [e, o] = v(null), a = L();
|
|
208
|
+
return ee(() => {
|
|
209
|
+
const s = () => {
|
|
210
|
+
const u = n.current;
|
|
211
|
+
u && (a.current = requestAnimationFrame(() => {
|
|
212
|
+
const r = Z(u);
|
|
213
|
+
o(r);
|
|
201
214
|
}));
|
|
202
215
|
};
|
|
203
|
-
return
|
|
204
|
-
t && (window.removeEventListener("resize",
|
|
216
|
+
return s(), t && (window.addEventListener("resize", s), window.addEventListener("scroll", s)), () => {
|
|
217
|
+
t && (window.removeEventListener("resize", s), window.removeEventListener("scroll", s)), a.current && cancelAnimationFrame(a.current);
|
|
205
218
|
};
|
|
206
219
|
}, [t]), e;
|
|
207
|
-
},
|
|
220
|
+
}, fe = te, ne = ({
|
|
208
221
|
onClose: n,
|
|
209
222
|
onOpen: t,
|
|
210
223
|
isOpen: e,
|
|
211
224
|
defaultIsOpen: o,
|
|
212
|
-
id:
|
|
225
|
+
id: a
|
|
213
226
|
} = {}) => {
|
|
214
|
-
const [
|
|
215
|
-
|
|
216
|
-
}, [
|
|
217
|
-
|
|
218
|
-
}, [
|
|
219
|
-
|
|
220
|
-
}, [
|
|
227
|
+
const [s, u] = v(o || !1), r = e !== void 0 ? e : s, i = e !== void 0, d = $(), c = a ?? `disclosure-${d}`, l = x(t), g = x(n), p = b(() => {
|
|
228
|
+
i || u(!1), g == null || g();
|
|
229
|
+
}, [i, g]), h = b(() => {
|
|
230
|
+
i || u(!0), l == null || l();
|
|
231
|
+
}, [i, l]), R = b(() => {
|
|
232
|
+
r ? p() : h();
|
|
233
|
+
}, [r, h, p]);
|
|
221
234
|
return {
|
|
222
235
|
onClose: p,
|
|
223
236
|
onOpen: h,
|
|
224
237
|
onToggle: R,
|
|
225
238
|
getButtonProps: ({ onClick: w, ...M } = {}) => ({
|
|
226
239
|
...M,
|
|
227
|
-
"aria-expanded":
|
|
228
|
-
"aria-controls":
|
|
229
|
-
onClick(
|
|
230
|
-
w == null || w(
|
|
240
|
+
"aria-expanded": r,
|
|
241
|
+
"aria-controls": c,
|
|
242
|
+
onClick(N) {
|
|
243
|
+
w == null || w(N), R();
|
|
231
244
|
}
|
|
232
245
|
}),
|
|
233
246
|
getDisclosureProps: ({ ...w } = {}) => ({
|
|
234
247
|
...w,
|
|
235
|
-
hidden: !
|
|
236
|
-
id:
|
|
248
|
+
hidden: !r,
|
|
249
|
+
id: c
|
|
237
250
|
}),
|
|
238
|
-
isOpen:
|
|
251
|
+
isOpen: r
|
|
239
252
|
};
|
|
240
|
-
},
|
|
241
|
-
const { ssr: e = !0, fallback: o } = t,
|
|
242
|
-
let
|
|
243
|
-
|
|
244
|
-
const [
|
|
245
|
-
media:
|
|
246
|
-
matches: e ? !!
|
|
253
|
+
}, me = ne, oe = (n, t = {}) => {
|
|
254
|
+
const { ssr: e = !0, fallback: o } = t, a = Array.isArray(n) ? n : [n];
|
|
255
|
+
let s = Array.isArray(o) ? o : [o];
|
|
256
|
+
s = s.filter((i) => i != null);
|
|
257
|
+
const [u, r] = v(() => a.map((i, d) => ({
|
|
258
|
+
media: i,
|
|
259
|
+
matches: e ? !!s[d] : window.matchMedia(i).matches
|
|
247
260
|
})));
|
|
248
261
|
return m(() => {
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
const i = window;
|
|
263
|
+
r(
|
|
264
|
+
a.map((l) => ({
|
|
252
265
|
media: l,
|
|
253
|
-
matches:
|
|
266
|
+
matches: i.matchMedia(l).matches
|
|
254
267
|
}))
|
|
255
268
|
);
|
|
256
|
-
const d =
|
|
257
|
-
|
|
269
|
+
const d = a.map((l) => i.matchMedia(l)), c = (l) => {
|
|
270
|
+
r((g) => g.slice().map((p) => p.media === l.media ? { ...p, matches: l.matches } : p));
|
|
258
271
|
};
|
|
259
272
|
return d.forEach((l) => {
|
|
260
|
-
l.addEventListener("change",
|
|
273
|
+
l.addEventListener("change", c);
|
|
261
274
|
}), () => {
|
|
262
275
|
d.forEach((l) => {
|
|
263
|
-
l.removeEventListener("change",
|
|
276
|
+
l.removeEventListener("change", c);
|
|
264
277
|
});
|
|
265
278
|
};
|
|
266
|
-
}, [window]),
|
|
267
|
-
},
|
|
279
|
+
}, [window]), u.map((i) => i.matches);
|
|
280
|
+
}, pe = oe, re = () => {
|
|
268
281
|
const [n, t] = v(navigator.onLine);
|
|
269
282
|
return m(() => {
|
|
270
283
|
const e = () => t(navigator.onLine);
|
|
@@ -272,43 +285,44 @@ const Z = k ? N : m, _ = Z, ee = (n, t) => {
|
|
|
272
285
|
window.removeEventListener("online", e), window.removeEventListener("offline", e);
|
|
273
286
|
};
|
|
274
287
|
}, []), { isOnline: n, isOffline: !n };
|
|
275
|
-
},
|
|
276
|
-
const o = x(e),
|
|
288
|
+
}, ve = re, ae = ({ enabled: n = !0, ref: t, handler: e }) => {
|
|
289
|
+
const o = x(e), s = L({
|
|
277
290
|
isPointerDown: !1,
|
|
278
291
|
ignoreEmulatedMouseEvents: !1
|
|
279
292
|
}).current;
|
|
280
293
|
m(() => {
|
|
281
294
|
if (!n)
|
|
282
295
|
return;
|
|
283
|
-
const
|
|
284
|
-
D(
|
|
285
|
-
},
|
|
286
|
-
if (
|
|
287
|
-
|
|
296
|
+
const u = (c) => {
|
|
297
|
+
D(c, t) && (s.isPointerDown = !0);
|
|
298
|
+
}, r = (c) => {
|
|
299
|
+
if (s.ignoreEmulatedMouseEvents) {
|
|
300
|
+
s.ignoreEmulatedMouseEvents = !1;
|
|
288
301
|
return;
|
|
289
302
|
}
|
|
290
|
-
|
|
291
|
-
},
|
|
292
|
-
|
|
303
|
+
s.isPointerDown && e && D(c, t) && (s.isPointerDown = !1, o(c));
|
|
304
|
+
}, i = (c) => {
|
|
305
|
+
s.ignoreEmulatedMouseEvents = !0, e && s.isPointerDown && D(c, t) && (s.isPointerDown = !1, o(c));
|
|
293
306
|
}, d = T(t.current);
|
|
294
|
-
return d.addEventListener("mousedown",
|
|
295
|
-
d.removeEventListener("mousedown",
|
|
307
|
+
return d.addEventListener("mousedown", u, !0), d.addEventListener("mouseup", r, !0), d.addEventListener("touchstart", u, !0), d.addEventListener("touchend", i, !0), () => {
|
|
308
|
+
d.removeEventListener("mousedown", u, !0), d.removeEventListener("mouseup", r, !0), d.removeEventListener("touchstart", u, !0), d.removeEventListener("touchend", i, !0);
|
|
296
309
|
};
|
|
297
|
-
}, [e, t, o,
|
|
298
|
-
},
|
|
310
|
+
}, [e, t, o, s, n]);
|
|
311
|
+
}, ge = ae;
|
|
299
312
|
export {
|
|
300
313
|
I as canUseDOM,
|
|
301
314
|
T as getOwnerDocument,
|
|
302
315
|
k as isBrowser,
|
|
303
|
-
|
|
316
|
+
A as isElement,
|
|
304
317
|
D as isValidEvent,
|
|
305
318
|
x as useCallbackRef,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
319
|
+
ue as useClipboard,
|
|
320
|
+
de as useCurrencyFormatter,
|
|
321
|
+
le as useDebounce,
|
|
322
|
+
fe as useDimensions,
|
|
323
|
+
me as useDisclosure,
|
|
324
|
+
pe as useMediaQuery,
|
|
325
|
+
ve as useOnlineStatus,
|
|
326
|
+
ge as useOutsideClick,
|
|
327
|
+
ee as useSafeLayoutEffect
|
|
314
328
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface NumberSeparatorProps {
|
|
2
|
+
value: number;
|
|
3
|
+
thousandSeparator?: string;
|
|
4
|
+
decimalLength?: number;
|
|
5
|
+
decimalSeparator?: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const useCurrencyFormatter: ({ value, thousandSeparator, decimalLength, decimalSeparator, code, }: NumberSeparatorProps) => string;
|
|
9
|
+
export default useCurrencyFormatter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ctlyst.id/utils",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Utilities library for voila user facing library.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
+
"@vanilla-extract/vite-plugin": "^3.8.0",
|
|
37
38
|
"ts-dedent": "^2.2.0"
|
|
38
39
|
},
|
|
39
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "df86aef119d346aaf8eef07f71aba98b5c18da29"
|
|
40
41
|
}
|