@verifiedinc-public/shared-ui-elements 6.3.0 → 6.4.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.
@@ -0,0 +1 @@
1
+ "use strict";import{useRef as m,useInsertionEffect as k,useCallback as f,useState as d,useId as D,useEffect as w,useLayoutEffect as L,useSyncExternalStore as q,useMemo as S}from"react";import{d as I}from"./useOnClickOutside-LHfgekbP.mjs";import A from"qr-code-styling";import{j as N}from"./jsx-runtime-Bwwz4kRH.mjs";function P(e){return{set:r=>{const i=typeof r=="string"?r:JSON.stringify(r);localStorage.setItem(e,i)},get:()=>{const r=localStorage.getItem(e);if(r)try{return JSON.parse(r)}catch{return r}return null},remove:()=>{localStorage.removeItem(e)}}}function O(e,r=[]){const i=m(()=>{throw new Error("Cannot call an event handler while rendering.")});return k(()=>{i.current=e}),f((...o)=>{var s;return(s=i.current)==null?void 0:s.call(i,...o)},r)}function j(e={}){const{onClose:r,onOpen:i,open:o,id:s}=e,n=O(i),a=O(r),[l,u]=d(e.defaultOpen??!1),t=o??l,c=o!==void 0,g=D(),p=s??`disclosure-${g}`,h=f(()=>{c||u(!1),a?.()},[c,a]),y=f(()=>{c||u(!0),n?.()},[c,n]),E=f(()=>{t?h():y()},[t,y,h]);function C(v={}){return{...v,"aria-expanded":t,"aria-controls":p,onClick(x){var b;(b=v.onClick)==null||b.call(v,x),E()}}}function T(v={}){return{...v,hidden:!t,id:p}}return{open:t,onOpen:y,onClose:h,onToggle:E,isControlled:c,getButtonProps:C,getDisclosureProps:T}}function H(e){return new URLSearchParams(e??window.location.search)}function R(e,r={addToHead:!1,removeOnUnmount:!1,nonce:void 0}){const[i,o]=d("loading"),s=m(r);return w(()=>{let n=document.querySelector(`script[src="${e}"]`);const a=n?.getAttribute("data-status");if(a){o(a);return}if(n===null){n=document.createElement("script"),n.src=e,n.async=!0,n.setAttribute("data-status","loading"),s.current.nonce&&n.setAttribute("nonce",s.current.nonce),s.current.addToHead?document.head.appendChild(n):document.body.appendChild(n);const l=()=>{n?.setAttribute("data-status","ready"),o("ready"),t()},u=()=>{n?.setAttribute("data-status","error"),o("error"),t()},t=()=>{n?.removeEventListener("load",l),n?.removeEventListener("error",u)};n.addEventListener("load",l),n.addEventListener("error",u);const c=s.current.removeOnUnmount;return()=>{c&&(n?.remove(),t())}}else o("unknown")},[e]),i}function U(e,r=500){const[i,o]=d(e),s=m(Date.now());return w(()=>{const n=Date.now(),a=n-s.current;if(a>=r)s.current=n,o(e);else{const l=r-a,u=window.setTimeout(()=>{s.current=Date.now(),o(e)},l);return()=>{window.clearTimeout(u)}}},[e,r]),i}function W(e){const[r,i]=d(()=>typeof e=="boolean"?e:!!e),o=f(s=>{if(typeof s=="boolean"){i(s);return}i(n=>!n)},[]);return[r,o]}function z(){const[e,r]=d({x:0,y:0}),i=f((...o)=>{if(o.length===1&&typeof o[0]=="object")window.scrollTo(o[0]);else if(o.length===2)window.scrollTo(o[0],o[1]);else throw new Error("Invalid arguments passed to scrollTo. Expected either ScrollToOptions object or x,y coordinates. See https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo")},[]);return L(()=>{const o=()=>{r({x:window.scrollX,y:window.scrollY})};return o(),window.addEventListener("scroll",o),()=>{window.removeEventListener("scroll",o)}},[]),{...e,scrollTo:i}}function B(){const[e,r]=d({width:window.innerWidth,height:window.innerHeight});return L(()=>{const i=()=>{r({width:window.innerWidth,height:window.innerHeight})};return window.addEventListener("resize",i),()=>{window.removeEventListener("resize",i)}},[]),e}function J(e,{threshold:r=0,root:i=null,rootMargin:o="0%",freezeOnceVisible:s=!1}={}){const[n,a]=d({isIntersecting:!1,entry:null});return w(()=>{const l=e?.current;let u;if(l){if(s&&n.isIntersecting)return;const t=g=>{const[p]=g;a({isIntersecting:p.isIntersecting,entry:p})},c=new IntersectionObserver(t,{threshold:r,root:i,rootMargin:o});c.observe(l),u=()=>{c.disconnect()}}return()=>{u&&u()}},[e,r,i,o,s,n.isIntersecting]),n}function M(){return q(e=>typeof window>"u"?()=>{}:(window.addEventListener("online",e),window.addEventListener("offline",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}),()=>typeof navigator>"u"?!0:navigator.onLine,()=>!0)}function $(e,r=500,i){const o=m(),s=S(()=>{const n=I(e,r,i),a=(...l)=>n(...l);return a.cancel=()=>{n.cancel()},a.isPending=()=>!!o.current,a.flush=()=>n.flush(),a},[e,r,i]);return w(()=>{o.current=I(e,r,i)},[e,r,i]),w(()=>()=>{o.current&&o.current.cancel()},[]),s}function X({options:e,className:r}){function i(t){return{width:t?.width??300,height:t?.height??300,type:t?.type??"svg",data:t?.data,image:t?.image,qrOptions:{typeNumber:0,mode:"Byte",errorCorrectionLevel:"Q",...t?.qrOptions},imageOptions:{crossOrigin:"anonymous",margin:20,...t?.imageOptions},dotsOptions:{color:"#000000",type:"square",...t?.dotsOptions},cornersSquareOptions:t?.cornersSquareOptions,cornersDotOptions:t?.cornersDotOptions,backgroundOptions:{color:"#ffffff",...t?.backgroundOptions}}}const[o]=d(i(e)),[s]=d(new A(o)),n=m(null),a=S(()=>()=>N.jsx("div",{className:r,ref:n}),[r]),l=async t=>await s.getRawData(t),u=async(t,c)=>{await s.download({name:t,extension:c})};return w(()=>{n.current&&s.append(n.current)},[s,n]),w(()=>{s&&s.update(i(e))},[s,e]),{Component:a,getRawData:l,download:u}}export{j as a,O as b,H as c,R as d,U as e,W as f,z as g,B as h,J as i,M as j,$ as k,X as l,P as u};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verifiedinc-public/shared-ui-elements",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "A set of UI components, utilities that is shareable with the core apps.",
5
5
  "private": false,
6
6
  "keywords": [],
@@ -125,6 +125,7 @@
125
125
  "libphonenumber-js": ">=1.11.11",
126
126
  "notistack": ">=3.0.1",
127
127
  "qrcode": ">=1.5.4",
128
+ "qr-code-styling": ">=1.9.2 <2",
128
129
  "react": ">=18",
129
130
  "react-dnd": ">=16.0.1",
130
131
  "react-dnd-html5-backend": ">=16.0.1",
@@ -1 +0,0 @@
1
- "use strict";import{useRef as h,useInsertionEffect as x,useCallback as w,useState as d,useId as k,useEffect as g,useLayoutEffect as I,useSyncExternalStore as A,useMemo as P}from"react";import{d as S}from"./useOnClickOutside-LHfgekbP.mjs";function D(e){return{set:r=>{const o=typeof r=="string"?r:JSON.stringify(r);localStorage.setItem(e,o)},get:()=>{const r=localStorage.getItem(e);if(r)try{return JSON.parse(r)}catch{return r}return null},remove:()=>{localStorage.removeItem(e)}}}function E(e,r=[]){const o=h(()=>{throw new Error("Cannot call an event handler while rendering.")});return x(()=>{o.current=e}),w((...t)=>{var i;return(i=o.current)==null?void 0:i.call(o,...t)},r)}function H(e={}){const{onClose:r,onOpen:o,open:t,id:i}=e,n=E(o),s=E(r),[c,l]=d(e.defaultOpen??!1),u=t??c,a=t!==void 0,m=k(),f=i??`disclosure-${m}`,p=w(()=>{a||l(!1),s?.()},[a,s]),y=w(()=>{a||l(!0),n?.()},[a,n]),b=w(()=>{u?p():y()},[u,y,p]);function T(v={}){return{...v,"aria-expanded":u,"aria-controls":f,onClick(O){var L;(L=v.onClick)==null||L.call(v,O),b()}}}function C(v={}){return{...v,hidden:!u,id:f}}return{open:u,onOpen:y,onClose:p,onToggle:b,isControlled:a,getButtonProps:T,getDisclosureProps:C}}function U(e){return new URLSearchParams(e??window.location.search)}function W(e,r={addToHead:!1,removeOnUnmount:!1,nonce:void 0}){const[o,t]=d("loading"),i=h(r);return g(()=>{let n=document.querySelector(`script[src="${e}"]`);const s=n?.getAttribute("data-status");if(s){t(s);return}if(n===null){n=document.createElement("script"),n.src=e,n.async=!0,n.setAttribute("data-status","loading"),i.current.nonce&&n.setAttribute("nonce",i.current.nonce),i.current.addToHead?document.head.appendChild(n):document.body.appendChild(n);const c=()=>{n?.setAttribute("data-status","ready"),t("ready"),u()},l=()=>{n?.setAttribute("data-status","error"),t("error"),u()},u=()=>{n?.removeEventListener("load",c),n?.removeEventListener("error",l)};n.addEventListener("load",c),n.addEventListener("error",l);const a=i.current.removeOnUnmount;return()=>{a&&(n?.remove(),u())}}else t("unknown")},[e]),o}function j(e,r=500){const[o,t]=d(e),i=h(Date.now());return g(()=>{const n=Date.now(),s=n-i.current;if(s>=r)i.current=n,t(e);else{const c=r-s,l=window.setTimeout(()=>{i.current=Date.now(),t(e)},c);return()=>{window.clearTimeout(l)}}},[e,r]),o}function z(e){const[r,o]=d(()=>typeof e=="boolean"?e:!!e),t=w(i=>{if(typeof i=="boolean"){o(i);return}o(n=>!n)},[]);return[r,t]}function J(){const[e,r]=d({x:0,y:0}),o=w((...t)=>{if(t.length===1&&typeof t[0]=="object")window.scrollTo(t[0]);else if(t.length===2)window.scrollTo(t[0],t[1]);else throw new Error("Invalid arguments passed to scrollTo. Expected either ScrollToOptions object or x,y coordinates. See https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo")},[]);return I(()=>{const t=()=>{r({x:window.scrollX,y:window.scrollY})};return t(),window.addEventListener("scroll",t),()=>{window.removeEventListener("scroll",t)}},[]),{...e,scrollTo:o}}function M(){const[e,r]=d({width:window.innerWidth,height:window.innerHeight});return I(()=>{const o=()=>{r({width:window.innerWidth,height:window.innerHeight})};return window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o)}},[]),e}function N(e,{threshold:r=0,root:o=null,rootMargin:t="0%",freezeOnceVisible:i=!1}={}){const[n,s]=d({isIntersecting:!1,entry:null});return g(()=>{const c=e?.current;let l;if(c){if(i&&n.isIntersecting)return;const u=m=>{const[f]=m;s({isIntersecting:f.isIntersecting,entry:f})},a=new IntersectionObserver(u,{threshold:r,root:o,rootMargin:t});a.observe(c),l=()=>{a.disconnect()}}return()=>{l&&l()}},[e,r,o,t,i,n.isIntersecting]),n}function R(){return A(e=>typeof window>"u"?()=>{}:(window.addEventListener("online",e),window.addEventListener("offline",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e)}),()=>typeof navigator>"u"?!0:navigator.onLine,()=>!0)}function $(e,r=500,o){const t=h(),i=P(()=>{const n=S(e,r,o),s=(...c)=>n(...c);return s.cancel=()=>{n.cancel()},s.isPending=()=>!!t.current,s.flush=()=>n.flush(),s},[e,r,o]);return g(()=>{t.current=S(e,r,o)},[e,r,o]),g(()=>()=>{t.current&&t.current.cancel()},[]),i}export{H as a,E as b,U as c,W as d,j as e,z as f,J as g,M as h,N as i,R as j,$ as k,D as u};