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