dgz-ui-shared
Version:
Custom ui library using React.js, Shadcn/ui, TailwindCSS, Typescript, dgz-ui library
62 lines (56 loc) • 18.9 kB
JavaScript
;const R=require("react"),A=require("./index-DqTIeHVj-C_gsDkBV.cjs"),we=require("react-dom");function Ee(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 i=Ee(R);var K="focusScope.autoFocusOnMount",q="focusScope.autoFocusOnUnmount",V={bubbles:!1,cancelable:!0},Se="FocusScope",ue=i.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:c,onUnmountAutoFocus:u,...s}=e,[o,b]=i.useState(null),y=A.n(c),v=A.n(u),d=i.useRef(null),f=A.x(t,a=>b(a)),p=i.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;i.useEffect(()=>{if(r){let a=function(h){if(p.paused||!o)return;const g=h.target;o.contains(g)?d.current=g:N(d.current,{select:!0})},l=function(h){if(p.paused||!o)return;const g=h.relatedTarget;g!==null&&(o.contains(g)||N(d.current,{select:!0}))},m=function(h){if(document.activeElement===document.body)for(const g of h)g.removedNodes.length>0&&N(o)};document.addEventListener("focusin",a),document.addEventListener("focusout",l);const w=new MutationObserver(m);return o&&w.observe(o,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",a),document.removeEventListener("focusout",l),w.disconnect()}}},[r,o,p.paused]),i.useEffect(()=>{if(o){Q.add(p);const a=document.activeElement;if(!o.contains(a)){const l=new CustomEvent(K,V);o.addEventListener(K,y),o.dispatchEvent(l),l.defaultPrevented||(Ce(Le(ie(o)),{select:!0}),document.activeElement===a&&N(o))}return()=>{o.removeEventListener(K,y),setTimeout(()=>{const l=new CustomEvent(q,V);o.addEventListener(q,v),o.dispatchEvent(l),l.defaultPrevented||N(a??document.body,{select:!0}),o.removeEventListener(q,v),Q.remove(p)},0)}}},[o,y,v,p]);const S=i.useCallback(a=>{if(!n&&!r||p.paused)return;const l=a.key==="Tab"&&!a.altKey&&!a.ctrlKey&&!a.metaKey,m=document.activeElement;if(l&&m){const w=a.currentTarget,[h,g]=ke(w);h&&g?!a.shiftKey&&m===g?(a.preventDefault(),n&&N(h,{select:!0})):a.shiftKey&&m===h&&(a.preventDefault(),n&&N(g,{select:!0})):m===w&&a.preventDefault()}},[n,r,p.paused]);return A.ae.jsx(A.h.div,{tabIndex:-1,...s,ref:f,onKeyDown:S})});ue.displayName=Se;function Ce(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(N(r,{select:t}),document.activeElement!==n)return}function ke(e){const t=ie(e),n=J(t,e),r=J(t.reverse(),e);return[n,r]}function ie(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 J(e,t){for(const n of e)if(!Ne(n,{upTo:t}))return n}function Ne(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 Ae(e){return e instanceof HTMLInputElement&&"select"in e}function N(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ae(e)&&t&&e.select()}}var Q=Re();function Re(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=G(e,t),e.unshift(t)},remove(t){var n;e=G(e,t),(n=e[0])==null||n.resume()}}}function G(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Le(e){return e.filter(t=>t.tagName!=="A")}var Me="Portal",le=i.forwardRef((e,t)=>{var n;const{container:r,...c}=e,[u,s]=i.useState(!1);A.w(()=>s(!0),[]);const o=r||u&&((n=globalThis==null?void 0:globalThis.document)==null?void 0:n.body);return o?we.createPortal(A.ae.jsx(A.h.div,{...c,ref:t}),o):null});le.displayName=Me;var X=0;function Te(){i.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??ee()),document.body.insertAdjacentElement("beforeend",e[1]??ee()),X++,()=>{X===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),X--}},[])}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}var C=function(){return C=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var c in t)Object.prototype.hasOwnProperty.call(t,c)&&(e[c]=t[c])}return e},C.apply(this,arguments)};function se(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 xe(e,t,n){for(var r=0,c=t.length,u;r<c;r++)(u||!(r in t))&&(u||(u=Array.prototype.slice.call(t,0,r)),u[r]=t[r]);return e.concat(u||Array.prototype.slice.call(t))}var D="right-scroll-bar-position",F="width-before-scroll-bar",Pe="with-scroll-bars-hidden",Oe="--removed-body-scroll-bar-size";function Y(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function We(e,t){var n=R.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"?i.useLayoutEffect:i.useEffect,te=new WeakMap;function Ie(e,t){var n=We(null,function(r){return e.forEach(function(c){return Y(c,r)})});return je(function(){var r=te.get(n);if(r){var c=new Set(r),u=new Set(e),s=n.current;c.forEach(function(o){u.has(o)||Y(o,null)}),u.forEach(function(o){c.has(o)||Y(o,s)})}te.set(n,e)},[e]),n}function _e(e){return e}function De(e,t){t===void 0&&(t=_e);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(u){var s=t(u,r);return n.push(s),function(){n=n.filter(function(o){return o!==s})}},assignSyncMedium:function(u){for(r=!0;n.length;){var s=n;n=[],s.forEach(u)}n={push:function(o){return u(o)},filter:function(){return n}}},assignMedium:function(u){r=!0;var s=[];if(n.length){var o=n;n=[],o.forEach(u),s=n}var b=function(){var v=s;s=[],v.forEach(u)},y=function(){return Promise.resolve().then(b)};y(),n={push:function(v){s.push(v),y()},filter:function(v){return s=s.filter(v),n}}}};return c}function Fe(e){e===void 0&&(e={});var t=De(null);return t.options=C({async:!0,ssr:!1},e),t}var de=function(e){var t=e.sideCar,n=se(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 i.createElement(r,C({},n))};de.isSideCarExport=!0;function Be(e,t){return e.useMedium(t),de}var fe=Fe(),Z=function(){},B=i.forwardRef(function(e,t){var n=i.useRef(null),r=i.useState({onScrollCapture:Z,onWheelCapture:Z,onTouchMoveCapture:Z}),c=r[0],u=r[1],s=e.forwardProps,o=e.children,b=e.className,y=e.removeScrollBar,v=e.enabled,d=e.shards,f=e.sideCar,p=e.noRelative,S=e.noIsolation,a=e.inert,l=e.allowPinchZoom,m=e.as,w=m===void 0?"div":m,h=e.gapMode,g=se(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=f,L=Ie([n,t]),k=C(C({},g),c);return i.createElement(i.Fragment,null,v&&i.createElement(E,{sideCar:fe,removeScrollBar:y,shards:d,noRelative:p,noIsolation:S,inert:a,setCallbacks:u,allowPinchZoom:!!l,lockRef:n,gapMode:h}),s?i.cloneElement(i.Children.only(o),C(C({},k),{ref:L})):i.createElement(w,C({},k,{className:b,ref:L}),o))});B.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};B.classNames={fullWidth:F,zeroRight:D};var Ke=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function qe(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ke();return t&&e.setAttribute("nonce",t),e}function Xe(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Ye(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Ze=function(){var e=0,t=null;return{add:function(n){e==0&&(t=qe())&&(Xe(t,n),Ye(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},ze=function(){var e=Ze();return function(t,n){i.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ve=function(){var e=ze(),t=function(n){var r=n.styles,c=n.dynamic;return e(r,c),null};return t},He={left:0,top:0,right:0,gap:0},z=function(e){return parseInt(e||"",10)||0},Ue=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[z(n),z(r),z(c)]},$e=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return He;var t=Ue(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])}},Ve=ve(),P="data-scroll-locked",Je=function(e,t,n,r){var c=e.left,u=e.top,s=e.right,o=e.gap;return n===void 0&&(n="margin"),`
.`.concat(Pe,` {
overflow: hidden `).concat(r,`;
padding-right: `).concat(o,"px ").concat(r,`;
}
body[`).concat(P,`] {
overflow: hidden `).concat(r,`;
overscroll-behavior: contain;
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
padding-left: `.concat(c,`px;
padding-top: `).concat(u,`px;
padding-right: `).concat(s,`px;
margin-left:0;
margin-top:0;
margin-right: `).concat(o,"px ").concat(r,`;
`),n==="padding"&&"padding-right: ".concat(o,"px ").concat(r,";")].filter(Boolean).join(""),`
}
.`).concat(D,` {
right: `).concat(o,"px ").concat(r,`;
}
.`).concat(F,` {
margin-right: `).concat(o,"px ").concat(r,`;
}
.`).concat(D," .").concat(D,` {
right: 0 `).concat(r,`;
}
.`).concat(F," .").concat(F,` {
margin-right: 0 `).concat(r,`;
}
body[`).concat(P,`] {
`).concat(Oe,": ").concat(o,`px;
}
`)},ne=function(){var e=parseInt(document.body.getAttribute(P)||"0",10);return isFinite(e)?e:0},Qe=function(){i.useEffect(function(){return document.body.setAttribute(P,(ne()+1).toString()),function(){var e=ne()-1;e<=0?document.body.removeAttribute(P):document.body.setAttribute(P,e.toString())}},[])},Ge=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,c=r===void 0?"margin":r;Qe();var u=i.useMemo(function(){return $e(c)},[c]);return i.createElement(Ve,{styles:Je(u,!t,c,n?"":"!important")})},U=!1;if(typeof window<"u")try{var W=Object.defineProperty({},"passive",{get:function(){return U=!0,!0}});window.addEventListener("test",W,W),window.removeEventListener("test",W,W)}catch{U=!1}var M=U?{passive:!1}:!1,et=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&&!et(e)&&n[t]==="visible")},tt=function(e){return pe(e,"overflowY")},nt=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=me(e,r);if(c){var u=he(e,r),s=u[1],o=u[2];if(s>o)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},rt=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},ot=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},me=function(e,t){return e==="v"?tt(t):nt(t)},he=function(e,t){return e==="v"?rt(t):ot(t)},at=function(e,t){return e==="h"&&t==="rtl"?-1:1},ct=function(e,t,n,r,c){var u=at(e,window.getComputedStyle(t).direction),s=u*r,o=n.target,b=t.contains(o),y=!1,v=s>0,d=0,f=0;do{var p=he(e,o),S=p[0],a=p[1],l=p[2],m=a-l-u*S;(S||m)&&me(e,o)&&(d+=m,f+=S),o=o.parentNode.host||o.parentNode}while(!b&&o!==document.body||b&&(t.contains(o)||t===o));return(v&&Math.abs(d)<1||!v&&Math.abs(f)<1)&&(y=!0),y},j=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},oe=function(e){return[e.deltaX,e.deltaY]},ae=function(e){return e&&"current"in e?e.current:e},ut=function(e,t){return e[0]===t[0]&&e[1]===t[1]},it=function(e){return`
.block-interactivity-`.concat(e,` {pointer-events: none;}
.allow-interactivity-`).concat(e,` {pointer-events: all;}
`)},lt=0,T=[];function st(e){var t=i.useRef([]),n=i.useRef([0,0]),r=i.useRef(),c=i.useState(lt++)[0],u=i.useState(ve)[0],s=i.useRef(e);i.useEffect(function(){s.current=e},[e]),i.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(c));var a=xe([e.lockRef.current],(e.shards||[]).map(ae)).filter(Boolean);return a.forEach(function(l){return l.classList.add("allow-interactivity-".concat(c))}),function(){document.body.classList.remove("block-interactivity-".concat(c)),a.forEach(function(l){return l.classList.remove("allow-interactivity-".concat(c))})}}},[e.inert,e.lockRef.current,e.shards]);var o=i.useCallback(function(a,l){if("touches"in a&&a.touches.length===2||a.type==="wheel"&&a.ctrlKey)return!s.current.allowPinchZoom;var m=j(a),w=n.current,h="deltaX"in a?a.deltaX:w[0]-m[0],g="deltaY"in a?a.deltaY:w[1]-m[1],E,L=a.target,k=Math.abs(h)>Math.abs(g)?"h":"v";if("touches"in a&&k==="h"&&L.type==="range")return!1;var O=re(k,L);if(!O)return!0;if(O?E=k:(E=k==="v"?"h":"v",O=re(k,L)),!O)return!1;if(!r.current&&"changedTouches"in a&&(h||g)&&(r.current=E),!E)return!0;var $=r.current||E;return ct($,l,a,$==="h"?h:g)},[]),b=i.useCallback(function(a){var l=a;if(!(!T.length||T[T.length-1]!==u)){var m="deltaY"in l?oe(l):j(l),w=t.current.filter(function(E){return E.name===l.type&&(E.target===l.target||l.target===E.shadowParent)&&ut(E.delta,m)})[0];if(w&&w.should){l.cancelable&&l.preventDefault();return}if(!w){var h=(s.current.shards||[]).map(ae).filter(Boolean).filter(function(E){return E.contains(l.target)}),g=h.length>0?o(l,h[0]):!s.current.noIsolation;g&&l.cancelable&&l.preventDefault()}}},[]),y=i.useCallback(function(a,l,m,w){var h={name:a,delta:l,target:m,should:w,shadowParent:dt(m)};t.current.push(h),setTimeout(function(){t.current=t.current.filter(function(g){return g!==h})},1)},[]),v=i.useCallback(function(a){n.current=j(a),r.current=void 0},[]),d=i.useCallback(function(a){y(a.type,oe(a),a.target,o(a,e.lockRef.current))},[]),f=i.useCallback(function(a){y(a.type,j(a),a.target,o(a,e.lockRef.current))},[]);i.useEffect(function(){return T.push(u),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",b,M),document.addEventListener("touchmove",b,M),document.addEventListener("touchstart",v,M),function(){T=T.filter(function(a){return a!==u}),document.removeEventListener("wheel",b,M),document.removeEventListener("touchmove",b,M),document.removeEventListener("touchstart",v,M)}},[]);var p=e.removeScrollBar,S=e.inert;return i.createElement(i.Fragment,null,S?i.createElement(u,{styles:it(c)}):null,p?i.createElement(Ge,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function dt(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ft=Be(fe,st);var ge=i.forwardRef(function(e,t){return i.createElement(B,C({},e,{ref:t,sideCar:ft}))});ge.classNames=B.classNames;var vt=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},x=new WeakMap,I=new WeakMap,_={},H=0,ye=function(e){return e&&(e.host||ye(e.parentNode))},pt=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=ye(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})},mt=function(e,t,n,r){var c=pt(t,Array.isArray(e)?e:[e]);_[n]||(_[n]=new WeakMap);var u=_[n],s=[],o=new Set,b=new Set(c),y=function(d){!d||o.has(d)||(o.add(d),y(d.parentNode))};c.forEach(y);var v=function(d){!d||b.has(d)||Array.prototype.forEach.call(d.children,function(f){if(o.has(f))v(f);else try{var p=f.getAttribute(r),S=p!==null&&p!=="false",a=(x.get(f)||0)+1,l=(u.get(f)||0)+1;x.set(f,a),u.set(f,l),s.push(f),a===1&&S&&I.set(f,!0),l===1&&f.setAttribute(n,"true"),S||f.setAttribute(r,"true")}catch(m){console.error("aria-hidden: cannot operate on ",f,m)}})};return v(t),o.clear(),H++,function(){s.forEach(function(d){var f=x.get(d)-1,p=u.get(d)-1;x.set(d,f),u.set(d,p),f||(I.has(d)||d.removeAttribute(r),I.delete(d)),p||d.removeAttribute(n)}),H--,H||(x=new WeakMap,x=new WeakMap,I=new WeakMap,_={})}},ht=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),c=vt(e);return c?(r.push.apply(r,Array.from(c.querySelectorAll("[aria-live], script"))),mt(r,c,n,"aria-hidden")):function(){return null}};/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const gt=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),yt=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(t,n,r)=>r?r.toUpperCase():n.toLowerCase()),ce=e=>{const t=yt(e);return t.charAt(0).toUpperCase()+t.slice(1)},be=(...e)=>e.filter((t,n,r)=>!!t&&t.trim()!==""&&r.indexOf(t)===n).join(" ").trim(),bt=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0};/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/var wt={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const Et=R.forwardRef(({color:e="currentColor",size:t=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:c="",children:u,iconNode:s,...o},b)=>R.createElement("svg",{ref:b,...wt,width:t,height:t,stroke:e,strokeWidth:r?Number(n)*24/Number(t):n,className:be("lucide",c),...!u&&!bt(o)&&{"aria-hidden":"true"},...o},[...s.map(([y,v])=>R.createElement(y,v)),...Array.isArray(u)?u:[u]]));/**
* @license lucide-react v0.511.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const St=(e,t)=>{const n=R.forwardRef(({className:r,...c},u)=>R.createElement(Et,{ref:u,iconNode:t,className:be(`lucide-${gt(ce(e))}`,`lucide-${e}`,r),...c}));return n.displayName=ce(e),n};exports.Ct=Te;exports.Me=le;exports.Rt=ht;exports.Se=ue;exports.dt=ge;exports.k=St;