dgz-ui
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript
43 lines (37 loc) • 17.8 kB
JavaScript
;const ce=require("react"),Ce=require("./index-jFOWwfD3.cjs.js"),ue=require("./index-D9zW9Tk7.cjs.js"),z=require("./index-CN4RxFxN.cjs.js"),ie=require("react/jsx-runtime"),Re=require("react-dom"),Ae=require("./index-pQxT4IlV.cjs.js"),Te=e=>e&&e.__esModule?e:{default:e};function ke(e){if(e&&e.__esModule)return e;const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const u=ke(ce),Pe=Te(Re);var B="focusScope.autoFocusOnMount",j="focusScope.autoFocusOnUnmount",Z={bubbles:!1,cancelable:!0},Me="FocusScope",le=u.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:c,onUnmountAutoFocus:i,...l}=e,[a,S]=u.useState(null),b=z.useCallbackRef(c),p=z.useCallbackRef(i),f=u.useRef(null),v=Ce.useComposedRefs(t,o=>S(o)),h=u.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;u.useEffect(()=>{if(r){let o=function(g){if(h.paused||!a)return;const y=g.target;a.contains(y)?f.current=y:A(f.current,{select:!0})},s=function(g){if(h.paused||!a)return;const y=g.relatedTarget;y!==null&&(a.contains(y)||A(f.current,{select:!0}))},d=function(g){if(document.activeElement===document.body)for(const E of g)E.removedNodes.length>0&&A(a)};document.addEventListener("focusin",o),document.addEventListener("focusout",s);const m=new MutationObserver(d);return a&&m.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",o),document.removeEventListener("focusout",s),m.disconnect()}}},[r,a,h.paused]),u.useEffect(()=>{if(a){Q.add(h);const o=document.activeElement;if(!a.contains(o)){const d=new CustomEvent(B,Z);a.addEventListener(B,b),a.dispatchEvent(d),d.defaultPrevented||(Oe(xe(se(a)),{select:!0}),document.activeElement===o&&A(a))}return()=>{a.removeEventListener(B,b),setTimeout(()=>{const d=new CustomEvent(j,Z);a.addEventListener(j,p),a.dispatchEvent(d),d.defaultPrevented||A(o??document.body,{select:!0}),a.removeEventListener(j,p),Q.remove(h)},0)}}},[a,b,p,h]);const w=u.useCallback(o=>{if(!n&&!r||h.paused)return;const s=o.key==="Tab"&&!o.altKey&&!o.ctrlKey&&!o.metaKey,d=document.activeElement;if(s&&d){const m=o.currentTarget,[g,y]=Ne(m);g&&y?!o.shiftKey&&d===y?(o.preventDefault(),n&&A(g,{select:!0})):o.shiftKey&&d===g&&(o.preventDefault(),n&&A(y,{select:!0})):d===m&&o.preventDefault()}},[n,r,h.paused]);return ie.jsx(ue.Primitive.div,{tabIndex:-1,...l,ref:v,onKeyDown:w})});le.displayName=Me;function Oe(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(A(r,{select:t}),document.activeElement!==n)return}function Ne(e){const t=se(e),n=$(t,e),r=$(t.reverse(),e);return[n,r]}function se(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const c=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||c?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function $(e,t){for(const n of e)if(!_e(n,{upTo:t}))return n}function _e(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}function Fe(e){return e instanceof HTMLInputElement&&"select"in e}function A(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Fe(e)&&t&&e.select()}}var Q=Le();function Le(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=J(e,t),e.unshift(t)},remove(t){var n;e=J(e,t),(n=e[0])==null||n.resume()}}}function J(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function xe(e){return e.filter(t=>t.tagName!=="A")}var Ie="Portal",fe=u.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[c,i]=u.useState(!1);Ae.useLayoutEffect2(()=>i(!0),[]);const l=n||c&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return l?Pe.default.createPortal(ie.jsx(ue.Primitive.div,{...r,ref:t}),l):null});fe.displayName=Ie;var U=0;function De(){u.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??ee()),document.body.insertAdjacentElement("beforeend",e[1]??ee()),U++,()=>{U===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),U--}},[])}function ee(){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}exports.__assign=function(){return exports.__assign=Object.assign||function(t){for(var n,r=1,c=arguments.length;r<c;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},exports.__assign.apply(this,arguments)};function de(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 c=0,r=Object.getOwnPropertySymbols(e);c<r.length;c++)t.indexOf(r[c])<0&&Object.prototype.propertyIsEnumerable.call(e,r[c])&&(n[r[c]]=e[r[c]]);return n}function ve(e,t,n){if(n||arguments.length===2)for(var r=0,c=t.length,i;r<c;r++)(i||!(r in t))&&(i||(i=Array.prototype.slice.call(t,0,r)),i[r]=t[r]);return e.concat(i||Array.prototype.slice.call(t))}var x="right-scroll-bar-position",I="width-before-scroll-bar",We="with-scroll-bars-hidden",Be="--removed-body-scroll-bar-size";function K(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function je(e,t){var n=ce.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var c=n.value;c!==r&&(n.value=r,n.callback(r,c))}}}})[0];return n.callback=t,n.facade}var Ue=typeof window<"u"?u.useLayoutEffect:u.useEffect,te=new WeakMap;function Ke(e,t){var n=je(null,function(r){return e.forEach(function(c){return K(c,r)})});return Ue(function(){var r=te.get(n);if(r){var c=new Set(r),i=new Set(e),l=n.current;c.forEach(function(a){i.has(a)||K(a,null)}),i.forEach(function(a){c.has(a)||K(a,l)})}te.set(n,e)},[e]),n}function He(e){return e}function Ve(e,t){t===void 0&&(t=He);var n=[],r=!1,c={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(i){var l=t(i,r);return n.push(l),function(){n=n.filter(function(a){return a!==l})}},assignSyncMedium:function(i){for(r=!0;n.length;){var l=n;n=[],l.forEach(i)}n={push:function(a){return i(a)},filter:function(){return n}}},assignMedium:function(i){r=!0;var l=[];if(n.length){var a=n;n=[],a.forEach(i),l=n}var S=function(){var p=l;l=[],p.forEach(i)},b=function(){return Promise.resolve().then(S)};b(),n={push:function(p){l.push(p),b()},filter:function(p){return l=l.filter(p),n}}}};return c}function qe(e){e===void 0&&(e={});var t=Ve(null);return t.options=exports.__assign({async:!0,ssr:!1},e),t}var he=function(e){var t=e.sideCar,n=de(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return u.createElement(r,exports.__assign({},n))};he.isSideCarExport=!0;function Xe(e,t){return e.useMedium(t),he}var me=qe(),H=function(){},D=u.forwardRef(function(e,t){var n=u.useRef(null),r=u.useState({onScrollCapture:H,onWheelCapture:H,onTouchMoveCapture:H}),c=r[0],i=r[1],l=e.forwardProps,a=e.children,S=e.className,b=e.removeScrollBar,p=e.enabled,f=e.shards,v=e.sideCar,h=e.noRelative,w=e.noIsolation,o=e.inert,s=e.allowPinchZoom,d=e.as,m=d===void 0?"div":d,g=e.gapMode,y=de(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=v,C=Ke([n,t]),R=exports.__assign(exports.__assign({},y),c);return u.createElement(u.Fragment,null,p&&u.createElement(E,{sideCar:me,removeScrollBar:b,shards:f,noRelative:h,noIsolation:w,inert:o,setCallbacks:i,allowPinchZoom:!!s,lockRef:n,gapMode:g}),l?u.cloneElement(u.Children.only(a),exports.__assign(exports.__assign({},R),{ref:C})):u.createElement(m,exports.__assign({},R,{className:S,ref:C}),a))});D.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};D.classNames={fullWidth:I,zeroRight:x};var Ye=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ge(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ye();return t&&e.setAttribute("nonce",t),e}function ze(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Ze(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var $e=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ge())&&(ze(t,n),Ze(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Qe=function(){var e=$e();return function(t,n){u.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ge=function(){var e=Qe(),t=function(n){var r=n.styles,c=n.dynamic;return e(r,c),null};return t},Je={left:0,top:0,right:0,gap:0},V=function(e){return parseInt(e||"",10)||0},et=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],c=t[e==="padding"?"paddingRight":"marginRight"];return[V(n),V(r),V(c)]},tt=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Je;var t=et(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])}},nt=ge(),M="data-scroll-locked",rt=function(e,t,n,r){var c=e.left,i=e.top,l=e.right,a=e.gap;return n===void 0&&(n="margin"),`
.`.concat(We,` {
overflow: hidden `).concat(r,`;
padding-right: `).concat(a,"px ").concat(r,`;
}
body[`).concat(M,`] {
overflow: hidden `).concat(r,`;
overscroll-behavior: contain;
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
padding-left: `.concat(c,`px;
padding-top: `).concat(i,`px;
padding-right: `).concat(l,`px;
margin-left:0;
margin-top:0;
margin-right: `).concat(a,"px ").concat(r,`;
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
}
.`).concat(x,` {
right: `).concat(a,"px ").concat(r,`;
}
.`).concat(I,` {
margin-right: `).concat(a,"px ").concat(r,`;
}
.`).concat(x," .").concat(x,` {
right: 0 `).concat(r,`;
}
.`).concat(I," .").concat(I,` {
margin-right: 0 `).concat(r,`;
}
body[`).concat(M,`] {
`).concat(Be,": ").concat(a,`px;
}
`)},ne=function(){var e=parseInt(document.body.getAttribute(M)||"0",10);return isFinite(e)?e:0},at=function(){u.useEffect(function(){return document.body.setAttribute(M,(ne()+1).toString()),function(){var e=ne()-1;e<=0?document.body.removeAttribute(M):document.body.setAttribute(M,e.toString())}},[])},ot=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,c=r===void 0?"margin":r;at();var i=u.useMemo(function(){return tt(c)},[c]);return u.createElement(nt,{styles:rt(i,!t,c,n?"":"!important")})},X=!1;if(typeof window<"u")try{var N=Object.defineProperty({},"passive",{get:function(){return X=!0,!0}});window.addEventListener("test",N,N),window.removeEventListener("test",N,N)}catch{X=!1}var T=X?{passive:!1}:!1,ct=function(e){return e.tagName==="TEXTAREA"},pe=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!ct(e)&&n[t]==="visible")},ut=function(e){return pe(e,"overflowY")},it=function(e){return pe(e,"overflowX")},re=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var c=ye(e,r);if(c){var i=be(e,r),l=i[1],a=i[2];if(l>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},lt=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},st=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},ye=function(e,t){return e==="v"?ut(t):it(t)},be=function(e,t){return e==="v"?lt(t):st(t)},ft=function(e,t){return e==="h"&&t==="rtl"?-1:1},dt=function(e,t,n,r,c){var i=ft(e,window.getComputedStyle(t).direction),l=i*r,a=n.target,S=t.contains(a),b=!1,p=l>0,f=0,v=0;do{if(!a)break;var h=be(e,a),w=h[0],o=h[1],s=h[2],d=o-s-i*w;(w||d)&&ye(e,a)&&(f+=d,v+=w);var m=a.parentNode;a=m&&m.nodeType===Node.DOCUMENT_FRAGMENT_NODE?m.host:m}while(!S&&a!==document.body||S&&(t.contains(a)||t===a));return(p&&Math.abs(f)<1||!p&&Math.abs(v)<1)&&(b=!0),b},_=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},ae=function(e){return[e.deltaX,e.deltaY]},oe=function(e){return e&&"current"in e?e.current:e},vt=function(e,t){return e[0]===t[0]&&e[1]===t[1]},ht=function(e){return`
.block-interactivity-`.concat(e,` {pointer-events: none;}
.allow-interactivity-`).concat(e,` {pointer-events: all;}
`)},mt=0,k=[];function gt(e){var t=u.useRef([]),n=u.useRef([0,0]),r=u.useRef(),c=u.useState(mt++)[0],i=u.useState(ge)[0],l=u.useRef(e);u.useEffect(function(){l.current=e},[e]),u.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(c));var o=ve([e.lockRef.current],(e.shards||[]).map(oe),!0).filter(Boolean);return o.forEach(function(s){return s.classList.add("allow-interactivity-".concat(c))}),function(){document.body.classList.remove("block-interactivity-".concat(c)),o.forEach(function(s){return s.classList.remove("allow-interactivity-".concat(c))})}}},[e.inert,e.lockRef.current,e.shards]);var a=u.useCallback(function(o,s){if("touches"in o&&o.touches.length===2||o.type==="wheel"&&o.ctrlKey)return!l.current.allowPinchZoom;var d=_(o),m=n.current,g="deltaX"in o?o.deltaX:m[0]-d[0],y="deltaY"in o?o.deltaY:m[1]-d[1],E,C=o.target,R=Math.abs(g)>Math.abs(y)?"h":"v";if("touches"in o&&R==="h"&&C.type==="range")return!1;var Y=window.getSelection(),W=Y&&Y.anchorNode,we=W?W===C||W.contains(C):!1;if(we)return!1;var O=re(R,C);if(!O)return!0;if(O?E=R:(E=R==="v"?"h":"v",O=re(R,C)),!O)return!1;if(!r.current&&"changedTouches"in o&&(g||y)&&(r.current=E),!E)return!0;var G=r.current||E;return dt(G,s,o,G==="h"?g:y)},[]),S=u.useCallback(function(o){var s=o;if(!(!k.length||k[k.length-1]!==i)){var d="deltaY"in s?ae(s):_(s),m=t.current.filter(function(E){return E.name===s.type&&(E.target===s.target||s.target===E.shadowParent)&&vt(E.delta,d)})[0];if(m&&m.should){s.cancelable&&s.preventDefault();return}if(!m){var g=(l.current.shards||[]).map(oe).filter(Boolean).filter(function(E){return E.contains(s.target)}),y=g.length>0?a(s,g[0]):!l.current.noIsolation;y&&s.cancelable&&s.preventDefault()}}},[]),b=u.useCallback(function(o,s,d,m){var g={name:o,delta:s,target:d,should:m,shadowParent:pt(d)};t.current.push(g),setTimeout(function(){t.current=t.current.filter(function(y){return y!==g})},1)},[]),p=u.useCallback(function(o){n.current=_(o),r.current=void 0},[]),f=u.useCallback(function(o){b(o.type,ae(o),o.target,a(o,e.lockRef.current))},[]),v=u.useCallback(function(o){b(o.type,_(o),o.target,a(o,e.lockRef.current))},[]);u.useEffect(function(){return k.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:v}),document.addEventListener("wheel",S,T),document.addEventListener("touchmove",S,T),document.addEventListener("touchstart",p,T),function(){k=k.filter(function(o){return o!==i}),document.removeEventListener("wheel",S,T),document.removeEventListener("touchmove",S,T),document.removeEventListener("touchstart",p,T)}},[]);var h=e.removeScrollBar,w=e.inert;return u.createElement(u.Fragment,null,w?u.createElement(i,{styles:ht(c)}):null,h?u.createElement(ot,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function pt(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const yt=Xe(me,gt);var Ee=u.forwardRef(function(e,t){return u.createElement(D,exports.__assign({},e,{ref:t,sideCar:yt}))});Ee.classNames=D.classNames;var bt=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},P=new WeakMap,F=new WeakMap,L={},q=0,Se=function(e){return e&&(e.host||Se(e.parentNode))},Et=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Se(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},St=function(e,t,n,r){var c=Et(t,Array.isArray(e)?e:[e]);L[n]||(L[n]=new WeakMap);var i=L[n],l=[],a=new Set,S=new Set(c),b=function(f){!f||a.has(f)||(a.add(f),b(f.parentNode))};c.forEach(b);var p=function(f){!f||S.has(f)||Array.prototype.forEach.call(f.children,function(v){if(a.has(v))p(v);else try{var h=v.getAttribute(r),w=h!==null&&h!=="false",o=(P.get(v)||0)+1,s=(i.get(v)||0)+1;P.set(v,o),i.set(v,s),l.push(v),o===1&&w&&F.set(v,!0),s===1&&v.setAttribute(n,"true"),w||v.setAttribute(r,"true")}catch(d){console.error("aria-hidden: cannot operate on ",v,d)}})};return p(t),a.clear(),q++,function(){l.forEach(function(f){var v=P.get(f)-1,h=i.get(f)-1;P.set(f,v),i.set(f,h),v||(F.has(f)||f.removeAttribute(r),F.delete(f)),h||f.removeAttribute(n)}),q--,q||(P=new WeakMap,P=new WeakMap,F=new WeakMap,L={})}},wt=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),c=bt(e);return c?(r.push.apply(r,Array.from(c.querySelectorAll("[aria-live], script"))),St(r,c,n,"aria-hidden")):function(){return null}};exports.FocusScope=le;exports.Portal=fe;exports.ReactRemoveScroll=Ee;exports.__spreadArray=ve;exports.hideOthers=wt;exports.useFocusGuards=De;
//# sourceMappingURL=index-DG15yxNP.cjs.js.map