@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
6 lines (5 loc) • 18.3 kB
JavaScript
/*! All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://github.com/Esri/calcite-design-system/blob/dev/LICENSE.md for details.
v3.2.1 */
import{a as ue}from"./CKRTMNFR.js";import{a as ne,l as ie}from"./3ADX47DD.js";import{O as re}from"./BJZTU5BQ.js";var se=["input:not([inert])","select:not([inert])","textarea:not([inert])","a[href]:not([inert])","button:not([inert])","[tabindex]:not(slot):not([inert])","audio[controls]:not([inert])","video[controls]:not([inert])",'[contenteditable]:not([contenteditable="false"]):not([inert])',"details>summary:first-of-type:not([inert])","details:not([inert])"],B=se.join(","),ce=typeof Element>"u",D=ce?function(){}:Element.prototype.matches||Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector,K=!ce&&Element.prototype.getRootNode?function(r){var e;return r==null||(e=r.getRootNode)===null||e===void 0?void 0:e.call(r)}:function(r){return r?.ownerDocument},j=function r(e,t){var a;t===void 0&&(t=!0);var o=e==null||(a=e.getAttribute)===null||a===void 0?void 0:a.call(e,"inert"),s=o===""||o==="true",n=s||t&&e&&r(e.parentNode);return n},Se=function(e){var t,a=e==null||(t=e.getAttribute)===null||t===void 0?void 0:t.call(e,"contenteditable");return a===""||a==="true"},le=function(e,t,a){if(j(e))return[];var o=Array.prototype.slice.apply(e.querySelectorAll(B));return t&&D.call(e,B)&&o.unshift(e),o=o.filter(a),o},fe=function r(e,t,a){for(var o=[],s=Array.from(e);s.length;){var n=s.shift();if(!j(n,!1))if(n.tagName==="SLOT"){var d=n.assignedElements(),l=d.length?d:n.children,y=r(l,!0,a);a.flatten?o.push.apply(o,y):o.push({scopeParent:n,candidates:y})}else{var T=D.call(n,B);T&&a.filter(n)&&(t||!e.includes(n))&&o.push(n);var w=n.shadowRoot||typeof a.getShadowRoot=="function"&&a.getShadowRoot(n),S=!j(w,!1)&&(!a.shadowRootFilter||a.shadowRootFilter(n));if(w&&S){var C=r(w===!0?n.children:w.children,!0,a);a.flatten?o.push.apply(o,C):o.push({scopeParent:n,candidates:C})}else s.unshift.apply(s,n.children)}}return o},de=function(e){return!isNaN(parseInt(e.getAttribute("tabindex"),10))},E=function(e){if(!e)throw new Error("No node provided");return e.tabIndex<0&&(/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName)||Se(e))&&!de(e)?0:e.tabIndex},ke=function(e,t){var a=E(e);return a<0&&t&&!de(e)?0:a},De=function(e,t){return e.tabIndex===t.tabIndex?e.documentOrder-t.documentOrder:e.tabIndex-t.tabIndex},ve=function(e){return e.tagName==="INPUT"},Oe=function(e){return ve(e)&&e.type==="hidden"},Ce=function(e){var t=e.tagName==="DETAILS"&&Array.prototype.slice.apply(e.children).some(function(a){return a.tagName==="SUMMARY"});return t},Ae=function(e,t){for(var a=0;a<e.length;a++)if(e[a].checked&&e[a].form===t)return e[a]},Re=function(e){if(!e.name)return!0;var t=e.form||K(e),a=function(d){return t.querySelectorAll('input[type="radio"][name="'+d+'"]')},o;if(typeof window<"u"&&typeof window.CSS<"u"&&typeof window.CSS.escape=="function")o=a(window.CSS.escape(e.name));else try{o=a(e.name)}catch(n){return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s",n.message),!1}var s=Ae(o,e.form);return!s||s===e},Ie=function(e){return ve(e)&&e.type==="radio"},Pe=function(e){return Ie(e)&&!Re(e)},xe=function(e){var t,a=e&&K(e),o=(t=a)===null||t===void 0?void 0:t.host,s=!1;if(a&&a!==e){var n,d,l;for(s=!!((n=o)!==null&&n!==void 0&&(d=n.ownerDocument)!==null&&d!==void 0&&d.contains(o)||e!=null&&(l=e.ownerDocument)!==null&&l!==void 0&&l.contains(e));!s&&o;){var y,T,w;a=K(o),o=(y=a)===null||y===void 0?void 0:y.host,s=!!((T=o)!==null&&T!==void 0&&(w=T.ownerDocument)!==null&&w!==void 0&&w.contains(o))}}return s},oe=function(e){var t=e.getBoundingClientRect(),a=t.width,o=t.height;return a===0&&o===0},Le=function(e,t){var a=t.displayCheck,o=t.getShadowRoot;if(getComputedStyle(e).visibility==="hidden")return!0;var s=D.call(e,"details>summary:first-of-type"),n=s?e.parentElement:e;if(D.call(n,"details:not([open]) *"))return!0;if(!a||a==="full"||a==="legacy-full"){if(typeof o=="function"){for(var d=e;e;){var l=e.parentElement,y=K(e);if(l&&!l.shadowRoot&&o(l)===!0)return oe(e);e.assignedSlot?e=e.assignedSlot:!l&&y!==e.ownerDocument?e=y.host:e=l}e=d}if(xe(e))return!e.getClientRects().length;if(a!=="legacy-full")return!0}else if(a==="non-zero-area")return oe(e);return!1},Be=function(e){if(/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))for(var t=e.parentElement;t;){if(t.tagName==="FIELDSET"&&t.disabled){for(var a=0;a<t.children.length;a++){var o=t.children.item(a);if(o.tagName==="LEGEND")return D.call(t,"fieldset[disabled] *")?!0:!o.contains(e)}return!0}t=t.parentElement}return!1},M=function(e,t){return!(t.disabled||j(t)||Oe(t)||Le(t,e)||Ce(t)||Be(t))},$=function(e,t){return!(Pe(t)||E(t)<0||!M(e,t))},Ke=function(e){var t=parseInt(e.getAttribute("tabindex"),10);return!!(isNaN(t)||t>=0)},je=function r(e){var t=[],a=[];return e.forEach(function(o,s){var n=!!o.scopeParent,d=n?o.scopeParent:o,l=ke(d,n),y=n?r(o.candidates):d;l===0?n?t.push.apply(t,y):t.push(d):a.push({documentOrder:s,tabIndex:l,item:o,isScope:n,content:y})}),a.sort(De).reduce(function(o,s){return s.isScope?o.push.apply(o,s.content):o.push(s.content),o},[]).concat(t)},be=function(e,t){t=t||{};var a;return t.getShadowRoot?a=fe([e],t.includeContainer,{filter:$.bind(null,t),flatten:!1,getShadowRoot:t.getShadowRoot,shadowRootFilter:Ke}):a=le(e,t.includeContainer,$.bind(null,t)),je(a)},he=function(e,t){t=t||{};var a;return t.getShadowRoot?a=fe([e],t.includeContainer,{filter:M.bind(null,t),flatten:!0,getShadowRoot:t.getShadowRoot}):a=le(e,t.includeContainer,M.bind(null,t)),a},O=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return D.call(e,B)===!1?!1:$(t,e)},Me=se.concat("iframe").join(","),G=function(e,t){if(t=t||{},!e)throw new Error("No node provided");return D.call(e,Me)===!1?!1:M(t,e)};function Y(r,e){(e==null||e>r.length)&&(e=r.length);for(var t=0,a=Array(e);t<e;t++)a[t]=r[t];return a}function Ge(r){if(Array.isArray(r))return Y(r)}function qe(r,e,t){return(e=$e(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}function Ue(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function Ve(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function pe(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(r);e&&(a=a.filter(function(o){return Object.getOwnPropertyDescriptor(r,o).enumerable})),t.push.apply(t,a)}return t}function ye(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?pe(Object(t),!0).forEach(function(a){qe(r,a,t[a])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):pe(Object(t)).forEach(function(a){Object.defineProperty(r,a,Object.getOwnPropertyDescriptor(t,a))})}return r}function _e(r){return Ge(r)||Ue(r)||Ye(r)||Ve()}function We(r,e){if(typeof r!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var a=t.call(r,e||"default");if(typeof a!="object")return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function $e(r){var e=We(r,"string");return typeof e=="symbol"?e:e+""}function Ye(r,e){if(r){if(typeof r=="string")return Y(r,e);var t={}.toString.call(r).slice(8,-1);return t==="Object"&&r.constructor&&(t=r.constructor.name),t==="Map"||t==="Set"?Array.from(r):t==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?Y(r,e):void 0}}var ge={activateTrap:function(e,t){if(e.length>0){var a=e[e.length-1];a!==t&&a._setPausedState(!0)}var o=e.indexOf(t);o===-1||e.splice(o,1),e.push(t)},deactivateTrap:function(e,t){var a=e.indexOf(t);a!==-1&&e.splice(a,1),e.length>0&&!e[e.length-1]._isManuallyPaused()&&e[e.length-1]._setPausedState(!1)}},Ze=function(e){return e.tagName&&e.tagName.toLowerCase()==="input"&&typeof e.select=="function"},ze=function(e){return e?.key==="Escape"||e?.key==="Esc"||e?.keyCode===27},x=function(e){return e?.key==="Tab"||e?.keyCode===9},Xe=function(e){return x(e)&&!e.shiftKey},He=function(e){return x(e)&&e.shiftKey},me=function(e){return setTimeout(e,0)},P=function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),o=1;o<t;o++)a[o-1]=arguments[o];return typeof e=="function"?e.apply(void 0,a):e},q=function(e){return e.target.shadowRoot&&typeof e.composedPath=="function"?e.composedPath()[0]:e.target},Je=[],we=function(e,t){var a=t?.document||document,o=t?.trapStack||Je,s=ye({returnFocusOnDeactivate:!0,escapeDeactivates:!0,delayInitialFocus:!0,isKeyForward:Xe,isKeyBackward:He},t),n={containers:[],containerGroups:[],tabbableGroups:[],nodeFocusedBeforeActivation:null,mostRecentlyFocusedNode:null,active:!1,paused:!1,manuallyPaused:!1,delayInitialFocusTimer:void 0,recentNavEvent:void 0},d,l=function(i,u,c){return i&&i[u]!==void 0?i[u]:s[c||u]},y=function(i,u){var c=typeof u?.composedPath=="function"?u.composedPath():void 0;return n.containerGroups.findIndex(function(v){var b=v.container,p=v.tabbableNodes;return b.contains(i)||c?.includes(b)||p.find(function(f){return f===i})})},T=function(i){var u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},c=u.hasFallback,v=c===void 0?!1:c,b=u.params,p=b===void 0?[]:b,f=s[i];if(typeof f=="function"&&(f=f.apply(void 0,_e(p))),f===!0&&(f=void 0),!f){if(f===void 0||f===!1)return f;throw new Error("`".concat(i,"` was specified but was not a node, or did not return a node"))}var g=f;if(typeof f=="string"){try{g=a.querySelector(f)}catch(m){throw new Error("`".concat(i,'` appears to be an invalid selector; error="').concat(m.message,'"'))}if(!g&&!v)throw new Error("`".concat(i,"` as selector refers to no known node"))}return g},w=function(){var i=T("initialFocus",{hasFallback:!0});if(i===!1)return!1;if(i===void 0||i&&!G(i,s.tabbableOptions))if(y(a.activeElement)>=0)i=a.activeElement;else{var u=n.tabbableGroups[0],c=u&&u.firstTabbableNode;i=c||T("fallbackFocus")}else i===null&&(i=T("fallbackFocus"));if(!i)throw new Error("Your focus-trap needs to have at least one focusable element");return i},S=function(){if(n.containerGroups=n.containers.map(function(i){var u=be(i,s.tabbableOptions),c=he(i,s.tabbableOptions),v=u.length>0?u[0]:void 0,b=u.length>0?u[u.length-1]:void 0,p=c.find(function(m){return O(m)}),f=c.slice().reverse().find(function(m){return O(m)}),g=!!u.find(function(m){return E(m)>0});return{container:i,tabbableNodes:u,focusableNodes:c,posTabIndexesFound:g,firstTabbableNode:v,lastTabbableNode:b,firstDomTabbableNode:p,lastDomTabbableNode:f,nextTabbableNode:function(k){var R=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,N=u.indexOf(k);return N<0?R?c.slice(c.indexOf(k)+1).find(function(I){return O(I)}):c.slice(0,c.indexOf(k)).reverse().find(function(I){return O(I)}):u[N+(R?1:-1)]}}}),n.tabbableGroups=n.containerGroups.filter(function(i){return i.tabbableNodes.length>0}),n.tabbableGroups.length<=0&&!T("fallbackFocus"))throw new Error("Your focus-trap must have at least one container with at least one tabbable node in it at all times");if(n.containerGroups.find(function(i){return i.posTabIndexesFound})&&n.containerGroups.length>1)throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.")},C=function(i){var u=i.activeElement;if(u)return u.shadowRoot&&u.shadowRoot.activeElement!==null?C(u.shadowRoot):u},F=function(i){if(i!==!1&&i!==C(document)){if(!i||!i.focus){F(w());return}i.focus({preventScroll:!!s.preventScroll}),n.mostRecentlyFocusedNode=i,Ze(i)&&i.select()}},Z=function(i){var u=T("setReturnFocus",{params:[i]});return u||(u===!1?!1:i)},z=function(i){var u=i.target,c=i.event,v=i.isBackward,b=v===void 0?!1:v;u=u||q(c),S();var p=null;if(n.tabbableGroups.length>0){var f=y(u,c),g=f>=0?n.containerGroups[f]:void 0;if(f<0)b?p=n.tabbableGroups[n.tabbableGroups.length-1].lastTabbableNode:p=n.tabbableGroups[0].firstTabbableNode;else if(b){var m=n.tabbableGroups.findIndex(function(_){var W=_.firstTabbableNode;return u===W});if(m<0&&(g.container===u||G(u,s.tabbableOptions)&&!O(u,s.tabbableOptions)&&!g.nextTabbableNode(u,!1))&&(m=f),m>=0){var k=m===0?n.tabbableGroups.length-1:m-1,R=n.tabbableGroups[k];p=E(u)>=0?R.lastTabbableNode:R.lastDomTabbableNode}else x(c)||(p=g.nextTabbableNode(u,!1))}else{var N=n.tabbableGroups.findIndex(function(_){var W=_.lastTabbableNode;return u===W});if(N<0&&(g.container===u||G(u,s.tabbableOptions)&&!O(u,s.tabbableOptions)&&!g.nextTabbableNode(u))&&(N=f),N>=0){var I=N===n.tabbableGroups.length-1?0:N+1,ae=n.tabbableGroups[I];p=E(u)>=0?ae.firstTabbableNode:ae.firstDomTabbableNode}else x(c)||(p=g.nextTabbableNode(u))}}else p=T("fallbackFocus");return p},L=function(i){var u=q(i);if(!(y(u,i)>=0)){if(P(s.clickOutsideDeactivates,i)){d.deactivate({returnFocus:s.returnFocusOnDeactivate});return}P(s.allowOutsideClick,i)||i.preventDefault()}},X=function(i){var u=q(i),c=y(u,i)>=0;if(c||u instanceof Document)c&&(n.mostRecentlyFocusedNode=u);else{i.stopImmediatePropagation();var v,b=!0;if(n.mostRecentlyFocusedNode)if(E(n.mostRecentlyFocusedNode)>0){var p=y(n.mostRecentlyFocusedNode),f=n.containerGroups[p].tabbableNodes;if(f.length>0){var g=f.findIndex(function(m){return m===n.mostRecentlyFocusedNode});g>=0&&(s.isKeyForward(n.recentNavEvent)?g+1<f.length&&(v=f[g+1],b=!1):g-1>=0&&(v=f[g-1],b=!1))}}else n.containerGroups.some(function(m){return m.tabbableNodes.some(function(k){return E(k)>0})})||(b=!1);else b=!1;b&&(v=z({target:n.mostRecentlyFocusedNode,isBackward:s.isKeyBackward(n.recentNavEvent)})),F(v||n.mostRecentlyFocusedNode||w())}n.recentNavEvent=void 0},Ne=function(i){var u=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1;n.recentNavEvent=i;var c=z({event:i,isBackward:u});c&&(x(i)&&i.preventDefault(),F(c))},H=function(i){(s.isKeyForward(i)||s.isKeyBackward(i))&&Ne(i,s.isKeyBackward(i))},J=function(i){ze(i)&&P(s.escapeDeactivates,i)!==!1&&(i.preventDefault(),d.deactivate())},Q=function(i){var u=q(i);y(u,i)>=0||P(s.clickOutsideDeactivates,i)||P(s.allowOutsideClick,i)||(i.preventDefault(),i.stopImmediatePropagation())},ee=function(){if(n.active)return ge.activateTrap(o,d),n.delayInitialFocusTimer=s.delayInitialFocus?me(function(){F(w())}):F(w()),a.addEventListener("focusin",X,!0),a.addEventListener("mousedown",L,{capture:!0,passive:!1}),a.addEventListener("touchstart",L,{capture:!0,passive:!1}),a.addEventListener("click",Q,{capture:!0,passive:!1}),a.addEventListener("keydown",H,{capture:!0,passive:!1}),a.addEventListener("keydown",J),d},te=function(){if(n.active)return a.removeEventListener("focusin",X,!0),a.removeEventListener("mousedown",L,!0),a.removeEventListener("touchstart",L,!0),a.removeEventListener("click",Q,!0),a.removeEventListener("keydown",H,!0),a.removeEventListener("keydown",J),d},Ee=function(i){var u=i.some(function(c){var v=Array.from(c.removedNodes);return v.some(function(b){return b===n.mostRecentlyFocusedNode})});u&&F(w())},V=typeof window<"u"&&"MutationObserver"in window?new MutationObserver(Ee):void 0,A=function(){V&&(V.disconnect(),n.active&&!n.paused&&n.containers.map(function(i){V.observe(i,{subtree:!0,childList:!0})}))};return d={get active(){return n.active},get paused(){return n.paused},activate:function(i){if(n.active)return this;var u=l(i,"onActivate"),c=l(i,"onPostActivate"),v=l(i,"checkCanFocusTrap");v||S(),n.active=!0,n.paused=!1,n.nodeFocusedBeforeActivation=a.activeElement,u?.();var b=function(){v&&S(),ee(),A(),c?.()};return v?(v(n.containers.concat()).then(b,b),this):(b(),this)},deactivate:function(i){if(!n.active)return this;var u=ye({onDeactivate:s.onDeactivate,onPostDeactivate:s.onPostDeactivate,checkCanReturnFocus:s.checkCanReturnFocus},i);clearTimeout(n.delayInitialFocusTimer),n.delayInitialFocusTimer=void 0,te(),n.active=!1,n.paused=!1,A(),ge.deactivateTrap(o,d);var c=l(u,"onDeactivate"),v=l(u,"onPostDeactivate"),b=l(u,"checkCanReturnFocus"),p=l(u,"returnFocus","returnFocusOnDeactivate");c?.();var f=function(){me(function(){p&&F(Z(n.nodeFocusedBeforeActivation)),v?.()})};return p&&b?(b(Z(n.nodeFocusedBeforeActivation)).then(f,f),this):(f(),this)},pause:function(i){return n.active?(n.manuallyPaused=!0,this._setPausedState(!0,i)):this},unpause:function(i){return n.active?(n.manuallyPaused=!1,o[o.length-1]!==this?this:this._setPausedState(!1,i)):this},updateContainerElements:function(i){var u=[].concat(i).filter(Boolean);return n.containers=u.map(function(c){return typeof c=="string"?a.querySelector(c):c}),n.active&&S(),A(),this}},Object.defineProperties(d,{_isManuallyPaused:{value:function(){return n.manuallyPaused}},_setPausedState:{value:function(i,u){if(n.paused===i)return this;if(n.paused=i,i){var c=l(u,"onPause"),v=l(u,"onPostPause");c?.(),te(),A(),v?.()}else{var b=l(u,"onUnpause"),p=l(u,"onPostUnpause");b?.(),S(),ee(),A(),p?.()}return this}}}),d.updateContainerElements(e),d};var U=new WeakSet;function Qe(r,e){let t=e?.fallbackFocus||r,a=e?.clickOutsideDeactivates??!0;return{fallbackFocus:t,setReturnFocus:o=>(U.has(r)||ie(o),!1),...e,document:r.ownerDocument,tabbableOptions:ne,trapStack:re,clickOutsideDeactivates:o=>(U.has(r)||U.add(r),typeof a=="function"?a(o):a),onPostDeactivate:()=>{U.delete(r)}}}function Te(r,{focusTrapOptions:e},t){return!e?.extraContainers&&!t?r:[r,...Fe(e?.extraContainers),...Fe(t)]}function Fe(r=[]){return Array.isArray(r)?r:[r]}var ot=r=>ue((e,t)=>{let a,o,s,n=r.focusTrapOptions;t.onConnected(()=>{e[r.triggerProp]&&a&&d.activate()}),t.onUpdate(l=>{e.hasUpdated&&l.has("focusTrapDisabled")&&(e.focusTrapDisabled?d.deactivate():d.activate())}),t.onDisconnected(()=>d.deactivate());let d={activate:()=>{let l=o||e.el;if(l.isConnected){if(!a){let y={...n,...e.focusTrapOptions};s||=Te(l,e),a=we(s,Qe(l,y))}(typeof e.focusTrapDisabledOverride=="function"?!e.focusTrapDisabledOverride():!e.focusTrapDisabled)&&a.activate()}},deactivate:()=>a?.deactivate(),overrideFocusTrapEl:l=>{if(a)throw new Error("Focus trap already created");o=l},setExtraContainers:l=>{let y=o||e.el;s=Te(y,e,l)},updateContainerElements:()=>a?.updateContainerElements(s)};return d});export{ot as a};