@undp/design-system-react
Version:
React based design system for UNDP
42 lines (37 loc) • 17.1 kB
JavaScript
const e=require("./rolldown-runtime-mLOUI7ql.cjs"),t=require("./dist--OhUIyHO.cjs"),n=require("./dist-VI-VV5wq.cjs"),r=require("./dist-Cepu74FS.cjs");let i=require("react"),a=e.r(i,1);i=e.r(i);let o=require("react/jsx-runtime");var s=Object.defineProperty,c=(e,t)=>s(e,`name`,{value:t,configurable:!0}),l=`focusScope.autoFocusOnMount`,u=`focusScope.autoFocusOnUnmount`,d={bubbles:!1,cancelable:!0},f=a.forwardRef(c(function(e,i){let{loop:s=!1,trapped:f=!1,onMountAutoFocus:g,onUnmountAutoFocus:_,...v}=e,[x,S]=a.useState(null),w=r.t(g),T=r.t(_),E=a.useRef(null),D=t.i(i,S),O=a.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;a.useEffect(()=>{if(f){let e=function(e){if(O.paused||!x)return;let t=e.target;x.contains(t)?E.current=t:y(E.current,{select:!0})},t=function(e){if(O.paused||!x)return;let t=e.relatedTarget;t!==null&&(x.contains(t)||y(E.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(let t of e)t.removedNodes.length>0&&y(x)};c(e,`handleFocusIn`),c(t,`handleFocusOut`),c(n,`handleMutations`),document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t);let r=new MutationObserver(n);return x&&r.observe(x,{childList:!0,subtree:!0}),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t),r.disconnect()}}},[f,x,O.paused]),a.useEffect(()=>{if(x){b.add(O);let e=document.activeElement;if(!x.contains(e)){let t=new CustomEvent(l,d);x.addEventListener(l,w),x.dispatchEvent(t),t.defaultPrevented||(p(C(h(x)),{select:!0}),document.activeElement===e&&y(x))}return()=>{x.removeEventListener(l,w),setTimeout(()=>{let t=new CustomEvent(u,d);x.addEventListener(u,T),x.dispatchEvent(t),t.defaultPrevented||y(e??document.body,{select:!0}),x.removeEventListener(u,T),b.remove(O)},0)}}},[x,w,T,O]);let k=a.useCallback(e=>{if(!s&&!f||O.paused)return;let t=e.key===`Tab`&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){let t=e.currentTarget,[r,i]=m(t);r&&i?!e.shiftKey&&n===i?(e.preventDefault(),s&&y(r,{select:!0})):e.shiftKey&&n===r&&(e.preventDefault(),s&&y(i,{select:!0})):n===t&&e.preventDefault()}},[s,f,O.paused]);return(0,o.jsx)(n.t.div,{tabIndex:-1,...v,ref:D,onKeyDown:k})},`FocusScope`));function p(e,{select:t=!1}={}){let n=document.activeElement;for(let r of e)if(y(r,{select:t}),document.activeElement!==n)return}c(p,`focusFirst`);function m(e){let t=h(e);return[g(t,e),g(t.reverse(),e)]}c(m,`getTabbableEdges`);function h(e){let t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:c(e=>{let t=e.tagName===`INPUT`&&e.type===`hidden`;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP},`acceptNode`)});for(;n.nextNode();)t.push(n.currentNode);return t}c(h,`getTabbableCandidates`);function g(e,t){let n=typeof t.checkVisibility==`function`&&t.checkVisibility({checkVisibilityCSS:!0});for(let r of e)if(!(n?!r.checkVisibility({checkVisibilityCSS:!0}):_(r,{upTo:t})))return r}c(g,`findVisible`);function _(e,{upTo:t}){if(getComputedStyle(e).visibility===`hidden`)return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display===`none`)return!0;e=e.parentElement}return!1}c(_,`isHidden`);function v(e){return e instanceof HTMLInputElement&&`select`in e}c(v,`isSelectableInput`);function y(e,{select:t=!1}={}){if(e&&e.focus){let n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&v(e)&&t&&e.select()}}c(y,`focus`);var b=x();function x(){let e=[];return{add(t){let n=e[0];t!==n&&n?.pause(),e=S(e,t),e.unshift(t)},remove(t){e=S(e,t),e[0]?.resume()}}}c(x,`createFocusScopesStack`);function S(e,t){let n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}c(S,`arrayRemove`);function C(e){return e.filter(e=>e.tagName!==`A`)}c(C,`removeLinks`);var w=0,T=null;function E(){a.useEffect(()=>{T||={start:D(),end:D()};let{start:e,end:t}=T;return document.body.firstElementChild!==e&&document.body.insertAdjacentElement(`afterbegin`,e),document.body.lastElementChild!==t&&document.body.insertAdjacentElement(`beforeend`,t),w++,()=>{w===1&&(T?.start.remove(),T?.end.remove(),T=null),w=Math.max(0,w-1)}},[])}function D(){let e=document.createElement(`span`);return e.setAttribute(`data-radix-focus-guard`,``),e.tabIndex=0,e.style.outline=`none`,e.style.opacity=`0`,e.style.position=`fixed`,e.style.pointerEvents=`none`,e}var O=function(){return O=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},O.apply(this,arguments)};function k(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function ee(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}var A=`right-scroll-bar-position`,j=`width-before-scroll-bar`,te=`with-scroll-bars-hidden`,ne=`--removed-body-scroll-bar-size`;function M(e,t){return typeof e==`function`?e(t):e&&(e.current=t),e}function re(e,t){var n=(0,i.useState)(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(e){var t=n.value;t!==e&&(n.value=e,n.callback(e,t))}}}})[0];return n.callback=t,n.facade}var ie=typeof window<`u`?i.useLayoutEffect:i.useEffect,N=new WeakMap;function ae(e,t){var n=re(t||null,function(t){return e.forEach(function(e){return M(e,t)})});return ie(function(){var t=N.get(n);if(t){var r=new Set(t),i=new Set(e),a=n.current;r.forEach(function(e){i.has(e)||M(e,null)}),i.forEach(function(e){r.has(e)||M(e,a)})}N.set(n,e)},[e]),n}function oe(e){return e}function se(e,t){t===void 0&&(t=oe);var n=[],r=!1;return{read:function(){if(r)throw Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(e){var i=t(e,r);return n.push(i),function(){n=n.filter(function(e){return e!==i})}},assignSyncMedium:function(e){for(r=!0;n.length;){var t=n;n=[],t.forEach(e)}n={push:function(t){return e(t)},filter:function(){return n}}},assignMedium:function(e){r=!0;var t=[];if(n.length){var i=n;n=[],i.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},o=function(){return Promise.resolve().then(a)};o(),n={push:function(e){t.push(e),o()},filter:function(e){return t=t.filter(e),n}}}}}function ce(e){e===void 0&&(e={});var t=se(null);return t.options=O({async:!0,ssr:!1},e),t}var le=function(e){var t=e.sideCar,n=k(e,[`sideCar`]);if(!t)throw Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw Error(`Sidecar medium not found`);return i.createElement(r,O({},n))};le.isSideCarExport=!0;function ue(e,t){return e.useMedium(t),le}var de=ce(),P=function(){},F=i.forwardRef(function(e,t){var n=i.useRef(null),r=i.useState({onScrollCapture:P,onWheelCapture:P,onTouchMoveCapture:P}),a=r[0],o=r[1],s=e.forwardProps,c=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,p=e.sideCar,m=e.noRelative,h=e.noIsolation,g=e.inert,_=e.allowPinchZoom,v=e.as,y=v===void 0?`div`:v,b=e.gapMode,x=k(e,[`forwardProps`,`children`,`className`,`removeScrollBar`,`enabled`,`shards`,`sideCar`,`noRelative`,`noIsolation`,`inert`,`allowPinchZoom`,`as`,`gapMode`]),S=p,C=ae([n,t]),w=O(O({},x),a);return i.createElement(i.Fragment,null,d&&i.createElement(S,{sideCar:de,removeScrollBar:u,shards:f,noRelative:m,noIsolation:h,inert:g,setCallbacks:o,allowPinchZoom:!!_,lockRef:n,gapMode:b}),s?i.cloneElement(i.Children.only(c),O(O({},w),{ref:C})):i.createElement(y,O({},w,{className:l,ref:C}),c))});F.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},F.classNames={fullWidth:j,zeroRight:A};var I,fe=function(){if(I)return I;if(typeof __webpack_nonce__<`u`)return __webpack_nonce__};function pe(){if(!document)return null;var e=document.createElement(`style`);e.type=`text/css`;var t=fe();return t&&e.setAttribute(`nonce`,t),e}function me(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function he(e){(document.head||document.getElementsByTagName(`head`)[0]).appendChild(e)}var ge=function(){var e=0,t=null;return{add:function(n){e==0&&(t=pe())&&(me(t,n),he(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_e=function(){var e=ge();return function(t,n){i.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},L=function(){var e=_e();return function(t){var n=t.styles,r=t.dynamic;return e(n,r),null}},ve={left:0,top:0,right:0,gap:0},R=function(e){return parseInt(e||``,10)||0},ye=function(e){var t=window.getComputedStyle(document.body),n=t[e===`padding`?`paddingLeft`:`marginLeft`],r=t[e===`padding`?`paddingTop`:`marginTop`],i=t[e===`padding`?`paddingRight`:`marginRight`];return[R(n),R(r),R(i)]},be=function(e){if(e===void 0&&(e=`margin`),typeof window>`u`)return ve;var t=ye(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},xe=L(),z=`data-scroll-locked`,Se=function(e,t,n,r){var i=e.left,a=e.top,o=e.right,s=e.gap;return n===void 0&&(n=`margin`),`
.${te} {
overflow: hidden ${r};
padding-right: ${s}px ${r};
}
body[${z}] {
overflow: hidden ${r};
overscroll-behavior: contain;
${[t&&`position: relative ${r};`,n===`margin`&&`
padding-left: ${i}px;
padding-top: ${a}px;
padding-right: ${o}px;
margin-left:0;
margin-top:0;
margin-right: ${s}px ${r};
`,n===`padding`&&`padding-right: ${s}px ${r};`].filter(Boolean).join(``)}
}
.${A} {
right: ${s}px ${r};
}
.${j} {
margin-right: ${s}px ${r};
}
.${A} .${A} {
right: 0 ${r};
}
.${j} .${j} {
margin-right: 0 ${r};
}
body[${z}] {
${ne}: ${s}px;
}
`},B=function(){var e=parseInt(document.body.getAttribute(`data-scroll-locked`)||`0`,10);return isFinite(e)?e:0},Ce=function(){i.useEffect(function(){return document.body.setAttribute(z,(B()+1).toString()),function(){var e=B()-1;e<=0?document.body.removeAttribute(z):document.body.setAttribute(z,e.toString())}},[])},we=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,a=r===void 0?`margin`:r;Ce();var o=i.useMemo(function(){return be(a)},[a]);return i.createElement(xe,{styles:Se(o,!t,a,n?``:`!important`)})},V=!1;if(typeof window<`u`)try{var H=Object.defineProperty({},"passive",{get:function(){return V=!0,!0}});window.addEventListener(`test`,H,H),window.removeEventListener(`test`,H,H)}catch{V=!1}var U=V?{passive:!1}:!1,Te=function(e){return e.tagName===`TEXTAREA`},W=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!==`hidden`&&!(n.overflowY===n.overflowX&&!Te(e)&&n[t]===`visible`)},Ee=function(e){return W(e,`overflowY`)},De=function(e){return W(e,`overflowX`)},G=function(e,t){var n=t.ownerDocument,r=t;do{if(typeof ShadowRoot<`u`&&r instanceof ShadowRoot&&(r=r.host),K(e,r)){var i=Ae(e,r);if(i[1]>i[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Oe=function(e){return[e.scrollTop,e.scrollHeight,e.clientHeight]},ke=function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]},K=function(e,t){return e===`v`?Ee(t):De(t)},Ae=function(e,t){return e===`v`?Oe(t):ke(t)},je=function(e,t){return e===`h`&&t===`rtl`?-1:1},Me=function(e,t,n,r,i){var a=je(e,window.getComputedStyle(t).direction),o=a*r,s=n.target,c=t.contains(s),l=!1,u=o>0,d=0,f=0;do{if(!s)break;var p=Ae(e,s),m=p[0],h=p[1]-p[2]-a*m;(m||h)&&K(e,s)&&(d+=h,f+=m);var g=s.parentNode;s=g&&g.nodeType===Node.DOCUMENT_FRAGMENT_NODE?g.host:g}while(!c&&s!==document.body||c&&(t.contains(s)||t===s));return(u&&(i&&Math.abs(d)<1||!i&&o>d)||!u&&(i&&Math.abs(f)<1||!i&&-o>f))&&(l=!0),l},q=function(e){return`changedTouches`in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Ne=function(e){return[e.deltaX,e.deltaY]},Pe=function(e){return e&&`current`in e?e.current:e},Fe=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Ie=function(e){return`
.block-interactivity-${e} {pointer-events: none;}
.allow-interactivity-${e} {pointer-events: all;}
`},Le=0,J=[];function Re(e){var t=i.useRef([]),n=i.useRef([0,0]),r=i.useRef(),a=i.useState(Le++)[0],o=i.useState(L)[0],s=i.useRef(e);i.useEffect(function(){s.current=e},[e]),i.useEffect(function(){if(e.inert){document.body.classList.add(`block-interactivity-${a}`);var t=ee([e.lockRef.current],(e.shards||[]).map(Pe),!0).filter(Boolean);return t.forEach(function(e){return e.classList.add(`allow-interactivity-${a}`)}),function(){document.body.classList.remove(`block-interactivity-${a}`),t.forEach(function(e){return e.classList.remove(`allow-interactivity-${a}`)})}}},[e.inert,e.lockRef.current,e.shards]);var c=i.useCallback(function(e,t){if(`touches`in e&&e.touches.length===2||e.type===`wheel`&&e.ctrlKey)return!s.current.allowPinchZoom;var i=q(e),a=n.current,o=`deltaX`in e?e.deltaX:a[0]-i[0],c=`deltaY`in e?e.deltaY:a[1]-i[1],l,u=e.target,d=Math.abs(o)>Math.abs(c)?`h`:`v`;if(`touches`in e&&d===`h`&&u.type===`range`)return!1;var f=window.getSelection(),p=f&&f.anchorNode;if(p&&(p===u||p.contains(u)))return!1;var m=G(d,u);if(!m)return!0;if(m?l=d:(l=d===`v`?`h`:`v`,m=G(d,u)),!m)return!1;if(!r.current&&`changedTouches`in e&&(o||c)&&(r.current=l),!l)return!0;var h=r.current||l;return Me(h,t,e,h===`h`?o:c,!0)},[]),l=i.useCallback(function(e){var n=e;if(!(!J.length||J[J.length-1]!==o)){var r=`deltaY`in n?Ne(n):q(n),i=t.current.filter(function(e){return e.name===n.type&&(e.target===n.target||n.target===e.shadowParent)&&Fe(e.delta,r)})[0];if(i&&i.should){n.cancelable&&n.preventDefault();return}if(!i){var a=(s.current.shards||[]).map(Pe).filter(Boolean).filter(function(e){return e.contains(n.target)});(a.length>0?c(n,a[0]):!s.current.noIsolation)&&n.cancelable&&n.preventDefault()}}},[]),u=i.useCallback(function(e,n,r,i){var a={name:e,delta:n,target:r,should:i,shadowParent:ze(r)};t.current.push(a),setTimeout(function(){t.current=t.current.filter(function(e){return e!==a})},1)},[]),d=i.useCallback(function(e){n.current=q(e),r.current=void 0},[]),f=i.useCallback(function(t){u(t.type,Ne(t),t.target,c(t,e.lockRef.current))},[]),p=i.useCallback(function(t){u(t.type,q(t),t.target,c(t,e.lockRef.current))},[]);i.useEffect(function(){return J.push(o),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:p}),document.addEventListener(`wheel`,l,U),document.addEventListener(`touchmove`,l,U),document.addEventListener(`touchstart`,d,U),function(){J=J.filter(function(e){return e!==o}),document.removeEventListener(`wheel`,l,U),document.removeEventListener(`touchmove`,l,U),document.removeEventListener(`touchstart`,d,U)}},[]);var m=e.removeScrollBar,h=e.inert;return i.createElement(i.Fragment,null,h?i.createElement(o,{styles:Ie(a)}):null,m?i.createElement(we,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function ze(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var Be=ue(de,Re),Ve=i.forwardRef(function(e,t){return i.createElement(F,O({},e,{ref:t,sideCar:Be}))});Ve.classNames=F.classNames;var He=function(e){return typeof document>`u`?null:(Array.isArray(e)?e[0]:e).ownerDocument.body},Y=new WeakMap,X=new WeakMap,Z={},Q=0,$=function(e){return e&&(e.host||$(e.parentNode))},Ue=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=$(t);return n&&e.contains(n)?n:(console.error(`aria-hidden`,t,`in not contained inside`,e,`. Doing nothing`),null)}).filter(function(e){return!!e})},We=function(e,t,n,r){var i=Ue(t,Array.isArray(e)?e:[e]);Z[n]||(Z[n]=new WeakMap);var a=Z[n],o=[],s=new Set,c=new Set(i),l=function(e){!e||s.has(e)||(s.add(e),l(e.parentNode))};i.forEach(l);var u=function(e){!e||c.has(e)||Array.prototype.forEach.call(e.children,function(e){if(s.has(e))u(e);else try{var t=e.getAttribute(r),i=t!==null&&t!==`false`,c=(Y.get(e)||0)+1,l=(a.get(e)||0)+1;Y.set(e,c),a.set(e,l),o.push(e),c===1&&i&&X.set(e,!0),l===1&&e.setAttribute(n,`true`),i||e.setAttribute(r,`true`)}catch(t){console.error(`aria-hidden: cannot operate on `,e,t)}})};return u(t),s.clear(),Q++,function(){o.forEach(function(e){var t=Y.get(e)-1,i=a.get(e)-1;Y.set(e,t),a.set(e,i),t||(X.has(e)||e.removeAttribute(r),X.delete(e)),i||e.removeAttribute(n)}),Q--,Q||(Y=new WeakMap,Y=new WeakMap,X=new WeakMap,Z={})}},Ge=function(e,t,n){n===void 0&&(n=`data-aria-hidden`);var r=Array.from(Array.isArray(e)?e:[e]),i=t||He(e);return i?(r.push.apply(r,Array.from(i.querySelectorAll(`[aria-live], script`))),We(r,i,n,`aria-hidden`)):function(){return null}};Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Ge}});
//# sourceMappingURL=es2015-_DRMRzCt.cjs.map