ivt
Version:
Ivt Components Library
3 lines (2 loc) • 15.5 kB
JavaScript
import*as e from"react";import{useState as t}from"react";import{u as n}from"./index-C-j8pU3U.mjs";import{P as r}from"./index-DiPp8h7C.mjs";import{u as o}from"./index-DSUHCtxx.mjs";import{jsx as a}from"react/jsx-runtime";import{_ as c,a as u,b as i}from"./tslib.es6-Bvey-QDo.mjs";var s="focusScope.autoFocusOnMount",l="focusScope.autoFocusOnUnmount",d={bubbles:!1,cancelable:!0},f=e.forwardRef((t,c)=>{const{loop:u=!1,trapped:i=!1,onMountAutoFocus:f,onUnmountAutoFocus:p,...y}=t,[E,b]=e.useState(null),w=o(f),S=o(p),C=e.useRef(null),k=n(c,e=>b(e)),M=e.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;e.useEffect(()=>{if(i){let e=function(e){if(M.paused||!E)return;const t=e.target;E.contains(t)?C.current=t:h(C.current,{select:!0})},t=function(e){if(M.paused||!E)return;const t=e.relatedTarget;null!==t&&(E.contains(t)||h(C.current,{select:!0}))},n=function(e){if(document.activeElement===document.body)for(const t of e)t.removedNodes.length>0&&h(E)};document.addEventListener("focusin",e),document.addEventListener("focusout",t);const r=new MutationObserver(n);return E&&r.observe(E,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",e),document.removeEventListener("focusout",t),r.disconnect()}}},[i,E,M.paused]),e.useEffect(()=>{if(E){g.add(M);const t=document.activeElement;if(!E.contains(t)){const n=new CustomEvent(s,d);E.addEventListener(s,w),E.dispatchEvent(n),n.defaultPrevented||(!function(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(h(r,{select:t}),document.activeElement!==n)return}((e=v(E),e.filter(e=>"A"!==e.tagName)),{select:!0}),document.activeElement===t&&h(E))}return()=>{E.removeEventListener(s,w),setTimeout(()=>{const e=new CustomEvent(l,d);E.addEventListener(l,S),E.dispatchEvent(e),e.defaultPrevented||h(t??document.body,{select:!0}),E.removeEventListener(l,S),g.remove(M)},0)}}var e},[E,w,S,M]);const N=e.useCallback(e=>{if(!u&&!i)return;if(M.paused)return;const t="Tab"===e.key&&!e.altKey&&!e.ctrlKey&&!e.metaKey,n=document.activeElement;if(t&&n){const t=e.currentTarget,[r,o]=function(e){const t=v(e),n=m(t,e),r=m(t.reverse(),e);return[n,r]}(t);r&&o?e.shiftKey||n!==o?e.shiftKey&&n===r&&(e.preventDefault(),u&&h(o,{select:!0})):(e.preventDefault(),u&&h(r,{select:!0})):n===t&&e.preventDefault()}},[u,i,M.paused]);return a(r.div,{tabIndex:-1,...y,ref:k,onKeyDown:N})});function v(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function m(e,t){for(const n of e)if(!p(n,{upTo:t}))return n}function p(e,{upTo:t}){if("hidden"===getComputedStyle(e).visibility)return!0;for(;e;){if(void 0!==t&&e===t)return!1;if("none"===getComputedStyle(e).display)return!0;e=e.parentElement}return!1}function h(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&function(e){return e instanceof HTMLInputElement&&"select"in e}(e)&&t&&e.select()}}f.displayName="FocusScope";var g=function(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=y(e,t),e.unshift(t)},remove(t){e=y(e,t),e[0]?.resume()}}}();function y(e,t){const n=[...e],r=n.indexOf(t);return-1!==r&&n.splice(r,1),n}var E=0;function b(){e.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??w()),document.body.insertAdjacentElement("beforeend",e[1]??w()),E++,()=>{1===E&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),E--}},[])}function w(){const 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 S="right-scroll-bar-position",C="width-before-scroll-bar";function k(e,t){return"function"==typeof e?e(t):e&&(e.current=t),e}var M="undefined"!=typeof window?e.useLayoutEffect:e.useEffect,N=new WeakMap;function R(e,n){var r,o,a,c=(r=null,o=function(t){return e.forEach(function(e){return k(e,t)})},(a=t(function(){return{value:r,callback:o,facade:{get current(){return a.value},set current(e){var t=a.value;t!==e&&(a.value=e,a.callback(e,t))}}}})[0]).callback=o,a.facade);return M(function(){var t=N.get(c);if(t){var n=new Set(t),r=new Set(e),o=c.current;n.forEach(function(e){r.has(e)||k(e,null)}),r.forEach(function(e){n.has(e)||k(e,o)})}N.set(c,e)},[e]),c}function A(e){return e}var T=function(t){var n=t.sideCar,r=u(t,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var o=n.read();if(!o)throw new Error("Sidecar medium not found");return e.createElement(o,c({},r))};T.isSideCarExport=!0;var L=function(e){void 0===e&&(e={});var t=function(e,t){void 0===t&&(t=A);var n=[],r=!1;return{read:function(){if(r)throw new 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 o=t(e,r);return n.push(o),function(){n=n.filter(function(e){return e!==o})}},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 o=n;n=[],o.forEach(e),t=n}var a=function(){var n=t;t=[],n.forEach(e)},c=function(){return Promise.resolve().then(a)};c(),n={push:function(e){t.push(e),c()},filter:function(e){return t=t.filter(e),n}}}}}(null);return t.options=c({async:!0,ssr:!1},e),t}(),x=function(){},P=e.forwardRef(function(t,n){var r=e.useRef(null),o=e.useState({onScrollCapture:x,onWheelCapture:x,onTouchMoveCapture:x}),a=o[0],i=o[1],s=t.forwardProps,l=t.children,d=t.className,f=t.removeScrollBar,v=t.enabled,m=t.shards,p=t.sideCar,h=t.noRelative,g=t.noIsolation,y=t.inert,E=t.allowPinchZoom,b=t.as,w=void 0===b?"div":b,S=t.gapMode,C=u(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=p,M=R([r,n]),N=c(c({},C),a);return e.createElement(e.Fragment,null,v&&e.createElement(k,{sideCar:L,removeScrollBar:f,shards:m,noRelative:h,noIsolation:g,inert:y,setCallbacks:i,allowPinchZoom:!!E,lockRef:r,gapMode:S}),s?e.cloneElement(e.Children.only(l),c(c({},N),{ref:M})):e.createElement(w,c({},N,{className:d,ref:M}),l))});P.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},P.classNames={fullWidth:C,zeroRight:S};function F(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=function(){if("undefined"!=typeof __webpack_nonce__)return __webpack_nonce__}();return t&&e.setAttribute("nonce",t),e}var I=function(){var e=0,t=null;return{add:function(n){var r,o;0==e&&(t=F())&&(o=n,(r=t).styleSheet?r.styleSheet.cssText=o:r.appendChild(document.createTextNode(o)),function(e){(document.head||document.getElementsByTagName("head")[0]).appendChild(e)}(t)),e++},remove:function(){! --e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_=function(){var t,n=(t=I(),function(n,r){e.useEffect(function(){return t.add(n),function(){t.remove()}},[n&&r])});return function(e){var t=e.styles,r=e.dynamic;return n(t,r),null}},W={left:0,top:0,right:0,gap:0},B=function(e){return parseInt(e||"",10)||0},D=function(e){if(void 0===e&&(e="margin"),"undefined"==typeof window)return W;var t=function(e){var t=window.getComputedStyle(document.body),n=t["padding"===e?"paddingLeft":"marginLeft"],r=t["padding"===e?"paddingTop":"marginTop"],o=t["padding"===e?"paddingRight":"marginRight"];return[B(n),B(r),B(o)]}(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])}},j=_(),K="data-scroll-locked",O=function(e,t,n,r){var o=e.left,a=e.top,c=e.right,u=e.gap;return void 0===n&&(n="margin"),"\n .".concat("with-scroll-bars-hidden"," {\n overflow: hidden ").concat(r,";\n padding-right: ").concat(u,"px ").concat(r,";\n }\n body[").concat(K,"] {\n overflow: hidden ").concat(r,";\n overscroll-behavior: contain;\n ").concat([t&&"position: relative ".concat(r,";"),"margin"===n&&"\n padding-left: ".concat(o,"px;\n padding-top: ").concat(a,"px;\n padding-right: ").concat(c,"px;\n margin-left:0;\n margin-top:0;\n margin-right: ").concat(u,"px ").concat(r,";\n "),"padding"===n&&"padding-right: ".concat(u,"px ").concat(r,";")].filter(Boolean).join(""),"\n }\n \n .").concat(S," {\n right: ").concat(u,"px ").concat(r,";\n }\n \n .").concat(C," {\n margin-right: ").concat(u,"px ").concat(r,";\n }\n \n .").concat(S," .").concat(S," {\n right: 0 ").concat(r,";\n }\n \n .").concat(C," .").concat(C," {\n margin-right: 0 ").concat(r,";\n }\n \n body[").concat(K,"] {\n ").concat("--removed-body-scroll-bar-size",": ").concat(u,"px;\n }\n")},X=function(){var e=parseInt(document.body.getAttribute(K)||"0",10);return isFinite(e)?e:0},Y=function(t){var n=t.noRelative,r=t.noImportant,o=t.gapMode,a=void 0===o?"margin":o;e.useEffect(function(){return document.body.setAttribute(K,(X()+1).toString()),function(){var e=X()-1;e<=0?document.body.removeAttribute(K):document.body.setAttribute(K,e.toString())}},[]);var c=e.useMemo(function(){return D(a)},[a]);return e.createElement(j,{styles:O(c,!n,a,r?"":"!important")})},H=!1;if("undefined"!=typeof window)try{var U=Object.defineProperty({},"passive",{get:function(){return H=!0,!0}});window.addEventListener("test",U,U),window.removeEventListener("test",U,U)}catch(e){H=!1}var Z=!!H&&{passive:!1},q=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return"hidden"!==n[t]&&!(n.overflowY===n.overflowX&&!function(e){return"TEXTAREA"===e.tagName}(e)&&"visible"===n[t])},z=function(e,t){var n=t.ownerDocument,r=t;do{if("undefined"!=typeof ShadowRoot&&r instanceof ShadowRoot&&(r=r.host),G(e,r)){var o=J(e,r);if(o[1]>o[2])return!0}r=r.parentNode}while(r&&r!==n.body);return!1},G=function(e,t){return"v"===e?function(e){return q(e,"overflowY")}(t):function(e){return q(e,"overflowX")}(t)},J=function(e,t){return"v"===e?[(n=t).scrollTop,n.scrollHeight,n.clientHeight]:function(e){return[e.scrollLeft,e.scrollWidth,e.clientWidth]}(t);var n},Q=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},V=function(e){return[e.deltaX,e.deltaY]},$=function(e){return e&&"current"in e?e.current:e},ee=function(e){return"\n .block-interactivity-".concat(e," {pointer-events: none;}\n .allow-interactivity-").concat(e," {pointer-events: all;}\n")},te=0,ne=[];function re(e){for(var t=null;null!==e;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}var oe,ae=(oe=function(t){var n=e.useRef([]),r=e.useRef([0,0]),o=e.useRef(),a=e.useState(te++)[0],c=e.useState(_)[0],u=e.useRef(t);e.useEffect(function(){u.current=t},[t]),e.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(a));var e=i([t.lockRef.current],(t.shards||[]).map($),!0).filter(Boolean);return e.forEach(function(e){return e.classList.add("allow-interactivity-".concat(a))}),function(){document.body.classList.remove("block-interactivity-".concat(a)),e.forEach(function(e){return e.classList.remove("allow-interactivity-".concat(a))})}}},[t.inert,t.lockRef.current,t.shards]);var s=e.useCallback(function(e,t){if("touches"in e&&2===e.touches.length||"wheel"===e.type&&e.ctrlKey)return!u.current.allowPinchZoom;var n,a=Q(e),c=r.current,i="deltaX"in e?e.deltaX:c[0]-a[0],s="deltaY"in e?e.deltaY:c[1]-a[1],l=e.target,d=Math.abs(i)>Math.abs(s)?"h":"v";if("touches"in e&&"h"===d&&"range"===l.type)return!1;var f=z(d,l);if(!f)return!0;if(f?n=d:(n="v"===d?"h":"v",f=z(d,l)),!f)return!1;if(!o.current&&"changedTouches"in e&&(i||s)&&(o.current=n),!n)return!0;var v=o.current||n;return function(e,t,n,r){var o=function(e,t){return"h"===e&&"rtl"===t?-1:1}(e,window.getComputedStyle(t).direction),a=o*r,c=n.target,u=t.contains(c),i=!1,s=a>0,l=0,d=0;do{if(!c)break;var f=J(e,c),v=f[0],m=f[1]-f[2]-o*v;(v||m)&&G(e,c)&&(l+=m,d+=v);var p=c.parentNode;c=p&&p.nodeType===Node.DOCUMENT_FRAGMENT_NODE?p.host:p}while(!u&&c!==document.body||u&&(t.contains(c)||t===c));return(s&&Math.abs(l)<1||!s&&Math.abs(d)<1)&&(i=!0),i}(v,t,e,"h"===v?i:s)},[]),l=e.useCallback(function(e){var t=e;if(ne.length&&ne[ne.length-1]===c){var r="deltaY"in t?V(t):Q(t),o=n.current.filter(function(e){return e.name===t.type&&(e.target===t.target||t.target===e.shadowParent)&&(n=e.delta,o=r,n[0]===o[0]&&n[1]===o[1]);var n,o})[0];if(o&&o.should)t.cancelable&&t.preventDefault();else if(!o){var a=(u.current.shards||[]).map($).filter(Boolean).filter(function(e){return e.contains(t.target)});(a.length>0?s(t,a[0]):!u.current.noIsolation)&&t.cancelable&&t.preventDefault()}}},[]),d=e.useCallback(function(e,t,r,o){var a={name:e,delta:t,target:r,should:o,shadowParent:re(r)};n.current.push(a),setTimeout(function(){n.current=n.current.filter(function(e){return e!==a})},1)},[]),f=e.useCallback(function(e){r.current=Q(e),o.current=void 0},[]),v=e.useCallback(function(e){d(e.type,V(e),e.target,s(e,t.lockRef.current))},[]),m=e.useCallback(function(e){d(e.type,Q(e),e.target,s(e,t.lockRef.current))},[]);e.useEffect(function(){return ne.push(c),t.setCallbacks({onScrollCapture:v,onWheelCapture:v,onTouchMoveCapture:m}),document.addEventListener("wheel",l,Z),document.addEventListener("touchmove",l,Z),document.addEventListener("touchstart",f,Z),function(){ne=ne.filter(function(e){return e!==c}),document.removeEventListener("wheel",l,Z),document.removeEventListener("touchmove",l,Z),document.removeEventListener("touchstart",f,Z)}},[]);var p=t.removeScrollBar,h=t.inert;return e.createElement(e.Fragment,null,h?e.createElement(c,{styles:ee(a)}):null,p?e.createElement(Y,{noRelative:t.noRelative,gapMode:t.gapMode}):null)},L.useMedium(oe),T),ce=e.forwardRef(function(t,n){return e.createElement(P,c({},t,{ref:n,sideCar:ae}))});ce.classNames=P.classNames;var ue=new WeakMap,ie=new WeakMap,se={},le=0,de=function(e){return e&&(e.host||de(e.parentNode))},fe=function(e,t,n,r){var o=function(e,t){return t.map(function(t){if(e.contains(t))return t;var n=de(t);return n&&e.contains(n)?n:null}).filter(function(e){return Boolean(e)})}(t,Array.isArray(e)?e:[e]);se[n]||(se[n]=new WeakMap);var a=se[n],c=[],u=new Set,i=new Set(o),s=function(e){e&&!u.has(e)&&(u.add(e),s(e.parentNode))};o.forEach(s);var l=function(e){e&&!i.has(e)&&Array.prototype.forEach.call(e.children,function(e){if(u.has(e))l(e);else try{var t=e.getAttribute(r),o=null!==t&&"false"!==t,i=(ue.get(e)||0)+1,s=(a.get(e)||0)+1;ue.set(e,i),a.set(e,s),c.push(e),1===i&&o&&ie.set(e,!0),1===s&&e.setAttribute(n,"true"),o||e.setAttribute(r,"true")}catch(e){}})};return l(t),u.clear(),le++,function(){c.forEach(function(e){var t=ue.get(e)-1,o=a.get(e)-1;ue.set(e,t),a.set(e,o),t||(ie.has(e)||e.removeAttribute(r),ie.delete(e)),o||e.removeAttribute(n)}),--le||(ue=new WeakMap,ue=new WeakMap,ie=new WeakMap,se={})}},ve=function(e,t,n){void 0===n&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=function(e){return"undefined"==typeof document?null:(Array.isArray(e)?e[0]:e).ownerDocument.body}(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),fe(r,o,n,"aria-hidden")):function(){return null}};export{f as F,ce as R,ve as h,b as u};
//# sourceMappingURL=index-lVEpnR8T.mjs.map