UNPKG

dgz-ui

Version:

Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript

42 lines (36 loc) 17.4 kB
"use strict";const oe=require("react"),Ee=require("./index-t1JFNXJ1.cjs"),ce=require("./index-CMmIsz5H.cjs"),z=require("./index-hwV4SK1V.cjs"),ue=require("./jsx-runtime-DUiatUiq.cjs"),Se=require("react-dom"),we=require("./index-DcWZbXs6.cjs");function Ce(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=Ce(oe);var D="focusScope.autoFocusOnMount",_="focusScope.autoFocusOnUnmount",G={bubbles:!1,cancelable:!0},Re="FocusScope",ie=u.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:c,onUnmountAutoFocus:i,...l}=e,[a,S]=u.useState(null),y=z.useCallbackRef(c),p=z.useCallbackRef(i),f=u.useRef(null),v=Ee.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(m){if(h.paused||!a)return;const g=m.target;a.contains(g)?f.current=g:P(f.current,{select:!0})},s=function(m){if(h.paused||!a)return;const g=m.relatedTarget;g!==null&&(a.contains(g)||P(f.current,{select:!0}))},d=function(m){if(document.activeElement===document.body)for(const b of m)b.removedNodes.length>0&&P(a)};document.addEventListener("focusin",o),document.addEventListener("focusout",s);const E=new MutationObserver(d);return a&&E.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",o),document.removeEventListener("focusout",s),E.disconnect()}}},[r,a,h.paused]),u.useEffect(()=>{if(a){$.add(h);const o=document.activeElement;if(!a.contains(o)){const d=new CustomEvent(D,G);a.addEventListener(D,y),a.dispatchEvent(d),d.defaultPrevented||(Pe(Me(le(a)),{select:!0}),document.activeElement===o&&P(a))}return()=>{a.removeEventListener(D,y),setTimeout(()=>{const d=new CustomEvent(_,G);a.addEventListener(_,p),a.dispatchEvent(d),d.defaultPrevented||P(o??document.body,{select:!0}),a.removeEventListener(_,p),$.remove(h)},0)}}},[a,y,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 E=o.currentTarget,[m,g]=ke(E);m&&g?!o.shiftKey&&d===g?(o.preventDefault(),n&&P(m,{select:!0})):o.shiftKey&&d===m&&(o.preventDefault(),n&&P(g,{select:!0})):d===E&&o.preventDefault()}},[n,r,h.paused]);return ue.jsxRuntimeExports.jsx(ce.Primitive.div,{tabIndex:-1,...l,ref:v,onKeyDown:w})});ie.displayName=Re;function Pe(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(P(r,{select:t}),document.activeElement!==n)return}function ke(e){const t=le(e),n=Z(t,e),r=Z(t.reverse(),e);return[n,r]}function le(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 Z(e,t){for(const n of e)if(!Ae(n,{upTo:t}))return n}function Ae(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 Te(e){return e instanceof HTMLInputElement&&"select"in e}function P(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Te(e)&&t&&e.select()}}var $=Oe();function Oe(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Q(e,t),e.unshift(t)},remove(t){var n;e=Q(e,t),(n=e[0])==null||n.resume()}}}function Q(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Me(e){return e.filter(t=>t.tagName!=="A")}var Ne="Portal",se=u.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[c,i]=u.useState(!1);we.useLayoutEffect2(()=>i(!0),[]);const l=n||c&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return l?Se.createPortal(ue.jsxRuntimeExports.jsx(ce.Primitive.div,{...r,ref:t}),l):null});se.displayName=Ne;var U=0;function xe(){u.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??J()),document.body.insertAdjacentElement("beforeend",e[1]??J()),U++,()=>{U===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),U--}},[])}function J(){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 C=function(){return C=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},C.apply(this,arguments)};function fe(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 Fe(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 W="right-scroll-bar-position",j="width-before-scroll-bar",Le="with-scroll-bars-hidden",Ie="--removed-body-scroll-bar-size";function K(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function We(e,t){var n=oe.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 je=typeof window<"u"?u.useLayoutEffect:u.useEffect,ee=new WeakMap;function Be(e,t){var n=We(null,function(r){return e.forEach(function(c){return K(c,r)})});return je(function(){var r=ee.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)})}ee.set(n,e)},[e]),n}function De(e){return e}function _e(e,t){t===void 0&&(t=De);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)},y=function(){return Promise.resolve().then(S)};y(),n={push:function(p){l.push(p),y()},filter:function(p){return l=l.filter(p),n}}}};return c}function Ue(e){e===void 0&&(e={});var t=_e(null);return t.options=C({async:!0,ssr:!1},e),t}var de=function(e){var t=e.sideCar,n=fe(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,C({},n))};de.isSideCarExport=!0;function Ke(e,t){return e.useMedium(t),de}var ve=Ue(),H=function(){},B=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,y=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,E=d===void 0?"div":d,m=e.gapMode,g=fe(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),b=v,k=Be([n,t]),R=C(C({},g),c);return u.createElement(u.Fragment,null,p&&u.createElement(b,{sideCar:ve,removeScrollBar:y,shards:f,noRelative:h,noIsolation:w,inert:o,setCallbacks:i,allowPinchZoom:!!s,lockRef:n,gapMode:m}),l?u.cloneElement(u.Children.only(a),C(C({},R),{ref:k})):u.createElement(E,C({},R,{className:S,ref:k}),a))});B.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};B.classNames={fullWidth:j,zeroRight:W};var He=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ve(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=He();return t&&e.setAttribute("nonce",t),e}function qe(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Xe(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Ye=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Ve())&&(qe(t,n),Xe(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},ze=function(){var e=Ye();return function(t,n){u.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},he=function(){var e=ze(),t=function(n){var r=n.styles,c=n.dynamic;return e(r,c),null};return t},Ge={left:0,top:0,right:0,gap:0},V=function(e){return parseInt(e||"",10)||0},Ze=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)]},$e=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Ge;var t=Ze(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])}},Qe=he(),M="data-scroll-locked",Je=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(Le,` { 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(W,` { right: `).concat(a,"px ").concat(r,`; } .`).concat(j,` { margin-right: `).concat(a,"px ").concat(r,`; } .`).concat(W," .").concat(W,` { right: 0 `).concat(r,`; } .`).concat(j," .").concat(j,` { margin-right: 0 `).concat(r,`; } body[`).concat(M,`] { `).concat(Ie,": ").concat(a,`px; } `)},te=function(){var e=parseInt(document.body.getAttribute(M)||"0",10);return isFinite(e)?e:0},et=function(){u.useEffect(function(){return document.body.setAttribute(M,(te()+1).toString()),function(){var e=te()-1;e<=0?document.body.removeAttribute(M):document.body.setAttribute(M,e.toString())}},[])},tt=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,c=r===void 0?"margin":r;et();var i=u.useMemo(function(){return $e(c)},[c]);return u.createElement(Qe,{styles:Je(i,!t,c,n?"":"!important")})},X=!1;if(typeof window<"u")try{var x=Object.defineProperty({},"passive",{get:function(){return X=!0,!0}});window.addEventListener("test",x,x),window.removeEventListener("test",x,x)}catch{X=!1}var A=X?{passive:!1}:!1,nt=function(e){return e.tagName==="TEXTAREA"},me=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!nt(e)&&n[t]==="visible")},rt=function(e){return me(e,"overflowY")},at=function(e){return me(e,"overflowX")},ne=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var c=pe(e,r);if(c){var i=ge(e,r),l=i[1],a=i[2];if(l>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},ot=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},ct=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},pe=function(e,t){return e==="v"?rt(t):at(t)},ge=function(e,t){return e==="v"?ot(t):ct(t)},ut=function(e,t){return e==="h"&&t==="rtl"?-1:1},it=function(e,t,n,r,c){var i=ut(e,window.getComputedStyle(t).direction),l=i*r,a=n.target,S=t.contains(a),y=!1,p=l>0,f=0,v=0;do{var h=ge(e,a),w=h[0],o=h[1],s=h[2],d=o-s-i*w;(w||d)&&pe(e,a)&&(f+=d,v+=w),a=a.parentNode.host||a.parentNode}while(!S&&a!==document.body||S&&(t.contains(a)||t===a));return(p&&Math.abs(f)<1||!p&&Math.abs(v)<1)&&(y=!0),y},F=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},re=function(e){return[e.deltaX,e.deltaY]},ae=function(e){return e&&"current"in e?e.current:e},lt=function(e,t){return e[0]===t[0]&&e[1]===t[1]},st=function(e){return` .block-interactivity-`.concat(e,` {pointer-events: none;} .allow-interactivity-`).concat(e,` {pointer-events: all;} `)},ft=0,T=[];function dt(e){var t=u.useRef([]),n=u.useRef([0,0]),r=u.useRef(),c=u.useState(ft++)[0],i=u.useState(he)[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=Fe([e.lockRef.current],(e.shards||[]).map(ae),!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=F(o),E=n.current,m="deltaX"in o?o.deltaX:E[0]-d[0],g="deltaY"in o?o.deltaY:E[1]-d[1],b,k=o.target,R=Math.abs(m)>Math.abs(g)?"h":"v";if("touches"in o&&R==="h"&&k.type==="range")return!1;var N=ne(R,k);if(!N)return!0;if(N?b=R:(b=R==="v"?"h":"v",N=ne(R,k)),!N)return!1;if(!r.current&&"changedTouches"in o&&(m||g)&&(r.current=b),!b)return!0;var Y=r.current||b;return it(Y,s,o,Y==="h"?m:g)},[]),S=u.useCallback(function(o){var s=o;if(!(!T.length||T[T.length-1]!==i)){var d="deltaY"in s?re(s):F(s),E=t.current.filter(function(b){return b.name===s.type&&(b.target===s.target||s.target===b.shadowParent)&&lt(b.delta,d)})[0];if(E&&E.should){s.cancelable&&s.preventDefault();return}if(!E){var m=(l.current.shards||[]).map(ae).filter(Boolean).filter(function(b){return b.contains(s.target)}),g=m.length>0?a(s,m[0]):!l.current.noIsolation;g&&s.cancelable&&s.preventDefault()}}},[]),y=u.useCallback(function(o,s,d,E){var m={name:o,delta:s,target:d,should:E,shadowParent:vt(d)};t.current.push(m),setTimeout(function(){t.current=t.current.filter(function(g){return g!==m})},1)},[]),p=u.useCallback(function(o){n.current=F(o),r.current=void 0},[]),f=u.useCallback(function(o){y(o.type,re(o),o.target,a(o,e.lockRef.current))},[]),v=u.useCallback(function(o){y(o.type,F(o),o.target,a(o,e.lockRef.current))},[]);u.useEffect(function(){return T.push(i),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:v}),document.addEventListener("wheel",S,A),document.addEventListener("touchmove",S,A),document.addEventListener("touchstart",p,A),function(){T=T.filter(function(o){return o!==i}),document.removeEventListener("wheel",S,A),document.removeEventListener("touchmove",S,A),document.removeEventListener("touchstart",p,A)}},[]);var h=e.removeScrollBar,w=e.inert;return u.createElement(u.Fragment,null,w?u.createElement(i,{styles:st(c)}):null,h?u.createElement(tt,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function vt(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ht=Ke(ve,dt);var ye=u.forwardRef(function(e,t){return u.createElement(B,C({},e,{ref:t,sideCar:ht}))});ye.classNames=B.classNames;var mt=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},O=new WeakMap,L=new WeakMap,I={},q=0,be=function(e){return e&&(e.host||be(e.parentNode))},pt=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=be(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})},gt=function(e,t,n,r){var c=pt(t,Array.isArray(e)?e:[e]);I[n]||(I[n]=new WeakMap);var i=I[n],l=[],a=new Set,S=new Set(c),y=function(f){!f||a.has(f)||(a.add(f),y(f.parentNode))};c.forEach(y);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=(O.get(v)||0)+1,s=(i.get(v)||0)+1;O.set(v,o),i.set(v,s),l.push(v),o===1&&w&&L.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=O.get(f)-1,h=i.get(f)-1;O.set(f,v),i.set(f,h),v||(L.has(f)||f.removeAttribute(r),L.delete(f)),h||f.removeAttribute(n)}),q--,q||(O=new WeakMap,O=new WeakMap,L=new WeakMap,I={})}},yt=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),c=mt(e);return c?(r.push.apply(r,Array.from(c.querySelectorAll("[aria-live], script"))),gt(r,c,n,"aria-hidden")):function(){return null}};exports.FocusScope=ie;exports.Portal=se;exports.ReactRemoveScroll=ye;exports.hideOthers=yt;exports.useFocusGuards=xe;