@stanfordspezi/spezi-web-design-system
Version:
Stanford Biodesign Digital Health Spezi Web Design System
42 lines (36 loc) • 17.3 kB
JavaScript
;const oe=require("react"),ce=require("./index-CajSSBH7.js");require("react-dom");const ue=require("react/jsx-runtime"),G=require("./index-CzY-WZXL.js");function be(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=be(oe);var Se=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=Se.reduce((e,t)=>{const n=ce.createSlot(`Primitive.${t}`),r=i.forwardRef((c,u)=>{const{asChild:l,...a}=c,S=l?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),ue.jsx(S,{...a,ref:u})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{}),j="focusScope.autoFocusOnMount",_="focusScope.autoFocusOnUnmount",z={bubbles:!1,cancelable:!0},we="FocusScope",ie=i.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:c,onUnmountAutoFocus:u,...l}=e,[a,S]=i.useState(null),b=G.useCallbackRef(c),g=G.useCallbackRef(u),f=i.useRef(null),v=ce.useComposedRefs(t,o=>S(o)),h=i.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;i.useEffect(()=>{if(r){let o=function(p){if(h.paused||!a)return;const y=p.target;a.contains(y)?f.current=y:k(f.current,{select:!0})},s=function(p){if(h.paused||!a)return;const y=p.relatedTarget;y!==null&&(a.contains(y)||k(f.current,{select:!0}))},d=function(p){if(document.activeElement===document.body)for(const E of p)E.removedNodes.length>0&&k(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]),i.useEffect(()=>{if(a){$.add(h);const o=document.activeElement;if(!a.contains(o)){const d=new CustomEvent(j,z);a.addEventListener(j,b),a.dispatchEvent(d),d.defaultPrevented||(Ce(Ne(le(a)),{select:!0}),document.activeElement===o&&k(a))}return()=>{a.removeEventListener(j,b),setTimeout(()=>{const d=new CustomEvent(_,z);a.addEventListener(_,g),a.dispatchEvent(d),d.defaultPrevented||k(o??document.body,{select:!0}),a.removeEventListener(_,g),$.remove(h)},0)}}},[a,b,g,h]);const w=i.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,[p,y]=Re(m);p&&y?!o.shiftKey&&d===y?(o.preventDefault(),n&&k(p,{select:!0})):o.shiftKey&&d===p&&(o.preventDefault(),n&&k(y,{select:!0})):d===m&&o.preventDefault()}},[n,r,h.paused]);return ue.jsx(Ee.div,{tabIndex:-1,...l,ref:v,onKeyDown:w})});ie.displayName=we;function Ce(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(k(r,{select:t}),document.activeElement!==n)return}function Re(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(!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 k(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ae(e)&&t&&e.select()}}var $=Te();function Te(){let e=[];return{add(t){const n=e[0];t!==n&&n?.pause(),e=Q(e,t),e.unshift(t)},remove(t){e=Q(e,t),e[0]?.resume()}}}function Q(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Ne(e){return e.filter(t=>t.tagName!=="A")}var U=0;function Oe(){i.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 u in n)Object.prototype.hasOwnProperty.call(n,u)&&(t[u]=n[u])}return t},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 Pe(e,t,n){if(n||arguments.length===2)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 W="right-scroll-bar-position",D="width-before-scroll-bar",Me="with-scroll-bars-hidden",Fe="--removed-body-scroll-bar-size";function K(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Le(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 xe=typeof window<"u"?i.useLayoutEffect:i.useEffect,ee=new WeakMap;function Ie(e,t){var n=Le(null,function(r){return e.forEach(function(c){return K(c,r)})});return xe(function(){var r=ee.get(n);if(r){var c=new Set(r),u=new Set(e),l=n.current;c.forEach(function(a){u.has(a)||K(a,null)}),u.forEach(function(a){c.has(a)||K(a,l)})}ee.set(n,e)},[e]),n}function We(e){return e}function De(e,t){t===void 0&&(t=We);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 l=t(u,r);return n.push(l),function(){n=n.filter(function(a){return a!==l})}},assignSyncMedium:function(u){for(r=!0;n.length;){var l=n;n=[],l.forEach(u)}n={push:function(a){return u(a)},filter:function(){return n}}},assignMedium:function(u){r=!0;var l=[];if(n.length){var a=n;n=[],a.forEach(u),l=n}var S=function(){var g=l;l=[],g.forEach(u)},b=function(){return Promise.resolve().then(S)};b(),n={push:function(g){l.push(g),b()},filter:function(g){return l=l.filter(g),n}}}};return c}function Be(e){e===void 0&&(e={});var t=De(null);return t.options=C({async:!0,ssr:!1},e),t}var fe=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))};fe.isSideCarExport=!0;function je(e,t){return e.useMedium(t),fe}var de=Be(),H=function(){},B=i.forwardRef(function(e,t){var n=i.useRef(null),r=i.useState({onScrollCapture:H,onWheelCapture:H,onTouchMoveCapture:H}),c=r[0],u=r[1],l=e.forwardProps,a=e.children,S=e.className,b=e.removeScrollBar,g=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,p=e.gapMode,y=se(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=v,A=Ie([n,t]),R=C(C({},y),c);return i.createElement(i.Fragment,null,g&&i.createElement(E,{sideCar:de,removeScrollBar:b,shards:f,noRelative:h,noIsolation:w,inert:o,setCallbacks:u,allowPinchZoom:!!s,lockRef:n,gapMode:p}),l?i.cloneElement(i.Children.only(a),C(C({},R),{ref:A})):i.createElement(m,C({},R,{className:S,ref:A}),a))});B.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};B.classNames={fullWidth:D,zeroRight:W};var _e=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Ue(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=_e();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=Ue())&&(Ke(t,n),He(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Xe=function(){var e=Ve();return function(t,n){i.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},ve=function(){var e=Xe(),t=function(n){var r=n.styles,c=n.dynamic;return e(r,c),null};return t},Ye={left:0,top:0,right:0,gap:0},V=function(e){return parseInt(e||"",10)||0},qe=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)]},Ge=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Ye;var t=qe(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])}},ze=ve(),P="data-scroll-locked",Ze=function(e,t,n,r){var c=e.left,u=e.top,l=e.right,a=e.gap;return n===void 0&&(n="margin"),`
.`.concat(Me,` {
overflow: hidden `).concat(r,`;
padding-right: `).concat(a,"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(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(D,` {
margin-right: `).concat(a,"px ").concat(r,`;
}
.`).concat(W," .").concat(W,` {
right: 0 `).concat(r,`;
}
.`).concat(D," .").concat(D,` {
margin-right: 0 `).concat(r,`;
}
body[`).concat(P,`] {
`).concat(Fe,": ").concat(a,`px;
}
`)},te=function(){var e=parseInt(document.body.getAttribute(P)||"0",10);return isFinite(e)?e:0},$e=function(){i.useEffect(function(){return document.body.setAttribute(P,(te()+1).toString()),function(){var e=te()-1;e<=0?document.body.removeAttribute(P):document.body.setAttribute(P,e.toString())}},[])},Qe=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,c=r===void 0?"margin":r;$e();var u=i.useMemo(function(){return Ge(c)},[c]);return i.createElement(ze,{styles:Ze(u,!t,c,n?"":"!important")})},Y=!1;if(typeof window<"u")try{var F=Object.defineProperty({},"passive",{get:function(){return Y=!0,!0}});window.addEventListener("test",F,F),window.removeEventListener("test",F,F)}catch{Y=!1}var T=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 c=me(e,r);if(c){var u=pe(e,r),l=u[1],a=u[2];if(l>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)},pe=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,c){var u=at(e,window.getComputedStyle(t).direction),l=u*r,a=n.target,S=t.contains(a),b=!1,g=l>0,f=0,v=0;do{if(!a)break;var h=pe(e,a),w=h[0],o=h[1],s=h[2],d=o-s-u*w;(w||d)&&me(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(g&&Math.abs(f)<1||!g&&Math.abs(v)<1)&&(b=!0),b},L=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,N=[];function lt(e){var t=i.useRef([]),n=i.useRef([0,0]),r=i.useRef(),c=i.useState(it++)[0],u=i.useState(ve)[0],l=i.useRef(e);i.useEffect(function(){l.current=e},[e]),i.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(c));var o=Pe([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=i.useCallback(function(o,s){if("touches"in o&&o.touches.length===2||o.type==="wheel"&&o.ctrlKey)return!l.current.allowPinchZoom;var d=L(o),m=n.current,p="deltaX"in o?o.deltaX:m[0]-d[0],y="deltaY"in o?o.deltaY:m[1]-d[1],E,A=o.target,R=Math.abs(p)>Math.abs(y)?"h":"v";if("touches"in o&&R==="h"&&A.type==="range")return!1;var M=ne(R,A);if(!M)return!0;if(M?E=R:(E=R==="v"?"h":"v",M=ne(R,A)),!M)return!1;if(!r.current&&"changedTouches"in o&&(p||y)&&(r.current=E),!E)return!0;var q=r.current||E;return ot(q,s,o,q==="h"?p:y)},[]),S=i.useCallback(function(o){var s=o;if(!(!N.length||N[N.length-1]!==u)){var d="deltaY"in s?re(s):L(s),m=t.current.filter(function(E){return E.name===s.type&&(E.target===s.target||s.target===E.shadowParent)&&ct(E.delta,d)})[0];if(m&&m.should){s.cancelable&&s.preventDefault();return}if(!m){var p=(l.current.shards||[]).map(ae).filter(Boolean).filter(function(E){return E.contains(s.target)}),y=p.length>0?a(s,p[0]):!l.current.noIsolation;y&&s.cancelable&&s.preventDefault()}}},[]),b=i.useCallback(function(o,s,d,m){var p={name:o,delta:s,target:d,should:m,shadowParent:st(d)};t.current.push(p),setTimeout(function(){t.current=t.current.filter(function(y){return y!==p})},1)},[]),g=i.useCallback(function(o){n.current=L(o),r.current=void 0},[]),f=i.useCallback(function(o){b(o.type,re(o),o.target,a(o,e.lockRef.current))},[]),v=i.useCallback(function(o){b(o.type,L(o),o.target,a(o,e.lockRef.current))},[]);i.useEffect(function(){return N.push(u),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:v}),document.addEventListener("wheel",S,T),document.addEventListener("touchmove",S,T),document.addEventListener("touchstart",g,T),function(){N=N.filter(function(o){return o!==u}),document.removeEventListener("wheel",S,T),document.removeEventListener("touchmove",S,T),document.removeEventListener("touchstart",g,T)}},[]);var h=e.removeScrollBar,w=e.inert;return i.createElement(i.Fragment,null,w?i.createElement(u,{styles:ut(c)}):null,h?i.createElement(Qe,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function st(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const ft=je(de,lt);var ge=i.forwardRef(function(e,t){return i.createElement(B,C({},e,{ref:t,sideCar:ft}))});ge.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},O=new WeakMap,x=new WeakMap,I={},X=0,ye=function(e){return e&&(e.host||ye(e.parentNode))},vt=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})},ht=function(e,t,n,r){var c=vt(t,Array.isArray(e)?e:[e]);I[n]||(I[n]=new WeakMap);var u=I[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 g=function(f){!f||S.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=(O.get(v)||0)+1,s=(u.get(v)||0)+1;O.set(v,o),u.set(v,s),l.push(v),o===1&&w&&x.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 g(t),a.clear(),X++,function(){l.forEach(function(f){var v=O.get(f)-1,h=u.get(f)-1;O.set(f,v),u.set(f,h),v||(x.has(f)||f.removeAttribute(r),x.delete(f)),h||f.removeAttribute(n)}),X--,X||(O=new WeakMap,O=new WeakMap,x=new WeakMap,I={})}},mt=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),c=dt(e);return c?(r.push.apply(r,Array.from(c.querySelectorAll("[aria-live], script"))),ht(r,c,n,"aria-hidden")):function(){return null}};exports.FocusScope=ie;exports.ReactRemoveScroll=ge;exports.hideOthers=mt;exports.useFocusGuards=Oe;