@cfpb/cfpb-design-system
Version:
CFPB's UI framework
3 lines (2 loc) • 12.9 kB
JavaScript
(()=>{var ye=Object.defineProperty;var U=(e,t)=>{for(var r in t)ye(e,r,{get:t[r],enumerable:!0})};var oe={};U(oe,{default:()=>we});var we={};var se={bpXS:{min:0,max:600},bpSM:{min:601,max:900},bpMED:{min:901,max:1020},bpLG:{min:1021,max:1200},bpXL:{min:1201}};function Y(){let e=getComputedStyle(document.body).fontSize;return e=e===""?-1:e,parseFloat(e)}function Le(e,t){let r=e.min,n=e.max;Y()>0&&Y()!==16&&(r=r/16*Y(),n=n/16*Y());let i=r||0,o=n||Number.POSITIVE_INFINITY;return i<=t&&t<=o}function Ae(e){let t={};e=e||window.innerWidth;let r;for(r in se)t[r]=Le(se[r],e);return t}var K="mobile",je="tablet",Te="desktop";function de(e){let t=!1,r=Ae();return(e===K&&r.bpXS||e===je&&r.bpSM||e===Te&&(r.bpMED||r.bpLG||r.bpXL))&&(t=!0),t}var E="data-js-hook",le="behavior_",be="state_";function y(){let e={};function t(a,i){return{}.hasOwnProperty.call(e,a)?e[a].push(i):e[a]=[i],this}function r(a,i){if(!{}.hasOwnProperty.call(e,a))return this;let o=e[a].indexOf(i);return o!==-1&&e[a].splice(o,1),this}function n(a,i){if(!{}.hasOwnProperty.call(e,a))return this;i=i||{};let o=e[a];for(let d=0,c=o.length;d<c;d++)o[d].call(this,i);return this}return this.addEventListener=t,this.removeEventListener=r,this.dispatchEvent=n,this.getRegisteredEvents=()=>e,this}function M(e,t){if(!e)return!1;let r=e.getAttribute(E);return r?(r=r.split(" "),r.indexOf(t)>-1):!1}function v(e,t){if(M(e,t))return t;if(t.indexOf(" ")!==-1){let n=E+" values cannot contain spaces!";throw new Error(n)}let r=e.getAttribute(E);return r!==null&&(t=r+" "+t),e.setAttribute(E,t),t}var ce=be+"atomic_init";function Oe(e,t){if(!e||!e.classList){let r=e+' is not valid. Check that element is a DOM node with class "'+t+'"';throw new Error(r)}return e}function ke(e,t){let r=e.classList.contains(t)?e:e.querySelector("."+t);if(!r){let n=t+" not found on or in passed DOM node.";throw new Error(n)}return r}function A(e,t){return Oe(e,t),ke(e,t)}function j(e){return M(e,ce)?!1:(v(e,ce),!0)}function T(e,t,r,n={}){let i=(r||document).querySelectorAll(e),o=[],d,c;for(let u=0,s=i.length;u<s;u++)c=i[u],M(c,ce)===!1&&(d=new t(c),d.init(n),o.push(d));return o}function ue(e,t){let r;if(M(e,t))return r=e,r;if(e){let n="["+E+"="+t+"]";r=e.querySelector(n)}if(!r){let n=t+" behavior not found on passed DOM node!";throw new Error(n)}return r}function f(e,t,r){let n=t,a=e;if(!r)throw new Error("Child transition argument must be defined!");let i=r,o,d,c,u=!1,s=!1,h=!1;if(typeof n.CSS_PROPERTY=="undefined"||typeof n.BASE_CLASS=="undefined")throw new Error("Transitions require CSS_PROPERTY and BASE_CLASS to be passed into BaseTransition.");function b(){d&&u?(a.addEventListener(d,c),i.dispatchEvent(f.BEGIN_EVENT,{target:i,type:f.BEGIN_EVENT}),a.classList.add(f.ANIMATING_CLASS),s=!0):(i.dispatchEvent(f.BEGIN_EVENT,{target:i,type:f.BEGIN_EVENT}),c())}function S(){a.removeEventListener(d,c)}function O(p){return p&&p.propertyName!==n.CSS_PROPERTY?!1:(S(),a.classList.remove(f.ANIMATING_CLASS),i.dispatchEvent(f.END_EVENT,{target:i,type:f.END_EVENT}),s=!1,!0)}function k(){let p;for(p in n)({}).hasOwnProperty.call(n,p)&&n[p]!==n.BASE_CLASS&&a.classList.contains(n[p])&&a.classList.remove(n[p])}function g(){s&&(a.style.webkitTransitionDuration="0",a.style.mozTransitionDuration="0",a.style.oTransitionDuration="0",a.style.transitionDuration="0",a.removeEventListener(d,c),c(),a.style.webkitTransitionDuration="",a.style.mozTransitionDuration="",a.style.oTransitionDuration="",a.style.transitionDuration="")}function w(){g(),k(),a.classList.remove(n.BASE_CLASS)}function C(){a.classList.remove(f.NO_ANIMATION_CLASS),u=!0}function R(){a.classList.add(f.NO_ANIMATION_CLASS),u=!1}function L(p){if(!p){let ae="Element does not have TransitionEnd event. It may be null!";throw new Error(ae)}let X,P={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},B;for(B in P)if({}.hasOwnProperty.call(P,B)&&typeof p.style[B]!="undefined"){X=P[B];break}return X}function D(p){w(),C(),a=p,a.classList.add(n.BASE_CLASS),d=L(a)}function ee(p){if(u=!a.classList.contains(f.NO_ANIMATION_CLASS),c=O.bind(this),D(a),!p)throw new Error("Transition needs to be passed an initial CSS class on initialization!");return a.classList.add(p),this}function te(p){return h||(k(),h=!0),a.classList.contains(p)?!1:(S(),a.classList.remove(o),o=p,b(),a.classList.add(o),!0)}return this.animateOff=R,this.animateOn=C,this.applyClass=te,this.halt=g,this.init=ee,this.isAnimated=()=>u,this.remove=w,this.setElement=D,this}f.BEGIN_EVENT="transitionbegin";f.END_EVENT="transitionend";f.NO_ANIMATION_CLASS="u-no-animation";f.ANIMATING_CLASS="u-is-animating";var V=le+"flyout-menu",Ie="["+E+"="+V;function I(e,t=!0){let r=ue(e,V),n=C(e),a=ue(e,V+"_content"),i=0,o=0,d=1,c=2,u=3,s,h,b,S=ae.bind(this),O=B.bind(this),k,g=!0,w=!1;function C(l){let m=[],x=l.querySelectorAll(`${Ie}_trigger]`),G,N,ne;for(let ie=x.length>>>0;ie--;){for(ne=!1,G=x[ie],N=G.parentElement;N!==l;)N.getAttribute(E)&&N.getAttribute(E).split(" ").indexOf(V)!==-1?(ne=!0,N=l):N=N.parentElement;ne||m.unshift(x[ie])}return m}function R(l=!1){return i=l?u:o,n.forEach(m=>{L("expanded",m,l),m.addEventListener("click",p.bind(this)),m.addEventListener("touchstart",D,{passive:!0}),m.addEventListener("mouseover",ee.bind(this)),m.addEventListener("mouseout",te.bind(this))}),a.setAttribute("data-open",l?"true":"false"),t&&!l&&a.setAttribute("hidden",""),me(),this}function L(l,m,x){let G=String(x);return m.setAttribute("aria-"+l,G),G}function D(){w=!0}function ee(l){g||(w||this.dispatchEvent("triggerover",{target:this,trigger:l.target,type:"triggerover"}),w=!1)}function te(l){g||this.dispatchEvent("triggerout",{target:this,trigger:l.target,type:"triggerout"})}function p(l){if(!g)switch(this.dispatchEvent("triggerclick",{target:this,trigger:l.target,type:"triggerclick"}),l.preventDefault(),i){case o:case d:this.expand();break;case c:case u:this.collapse();break}}function X(){if(s==null||s.halt(),i===c||i===u)return this;if(i=c,t&&a.removeAttribute("hidden"),this.dispatchEvent("expandbegin",{target:this,type:"expandbegin"}),!h||!b)return O(),this;let l=s==null?void 0:s.isAnimated();return l&&s.addEventListener(f.END_EVENT,O),h(),l||O(),this}function P(){if(s==null||s.halt(),i===d||i===o)return this;for(let m=0,x=n.length;m<x;m++)L("expanded",n[m],!1);if(a.setAttribute("data-open","false"),i=d,this.dispatchEvent("collapsebegin",{target:this,type:"collapsebegin"}),!b||!h)return S(),this;let l=s==null?void 0:s.isAnimated();return l&&s.addEventListener(f.END_EVENT,S),b(),l||S(),this}function B(){i=u,a.setAttribute("data-open","true"),s&&s.removeEventListener(f.END_EVENT,O),this.dispatchEvent("expandend",{target:this,type:"expandend"});for(let l=0,m=n.length;l<m;l++)L("expanded",n[l],!0)}function ae(){i=o,t&&a.setAttribute("hidden",""),s&&s.removeEventListener(f.END_EVENT,S),this.dispatchEvent("collapseend",{target:this,type:"collapseend"})}function ve(l,m,x){s=l,m&&m!==b&&(b=m),x&&x!==h&&(h=x)}function ge(){s&&s.remove();let l;s=l,h=l,b=l}function _e(){return{container:r,content:a,trigger:n}}function me(){return g&&(g=!1),!g}function xe(){return g||(g=!0),g}function Ee(l){return k=l,this}let re=new y;return this.addEventListener=re.addEventListener,this.removeEventListener=re.removeEventListener,this.dispatchEvent=re.dispatchEvent,this.init=R,this.expand=X,this.collapse=P,this.setTransition=ve,this.clearTransition=ge,this.getData=()=>k,this.getTransition=()=>s,this.getDom=_e,this.isAnimating=()=>i===c||i===d,this.isExpanded=()=>i===u,this.resume=me,this.setData=Ee,this.suspend=xe,I.BASE_CLASS=V,this}var $={CSS_PROPERTY:"max-height",BASE_CLASS:"u-max-height-transition",MH_DEFAULT:"u-max-height-default",MH_SUMMARY:"u-max-height-summary",MH_ZERO:"u-max-height-zero"};function _(e){let t=new y,r=new f(e,$,this),n=0;function a(){let b=e.scrollHeight+"px";e.style.maxHeight=b}function i(){window.removeEventListener("load",i),a()}function o(h){return r.init(h),window.addEventListener("load",i),window.addEventListener("resize",()=>{a()}),this}function d(){return a(),r.applyClass($.MH_DEFAULT),(!n||e.scrollHeight>n)&&(n=e.scrollHeight),this}function c(){return r.applyClass($.MH_SUMMARY),n=e.scrollHeight,this}function u(){return r.applyClass($.MH_ZERO),n=e.scrollHeight,this}function s(){return e.style.maxHeight="",r.remove()}return this.addEventListener=t.addEventListener,this.dispatchEvent=t.dispatchEvent,this.removeEventListener=t.removeEventListener,this.animateOff=r.animateOff,this.animateOn=r.animateOn,this.halt=r.halt,this.isAnimated=r.isAnimated,this.setElement=r.setElement,this.refresh=a,this.remove=s,this.init=o,this.maxHeightDefault=d,this.maxHeightSummary=c,this.maxHeightZero=u,this}_.CLASSES=$;var fe={};U(fe,{default:()=>Ne});var Ne={};var z="o-expandable";function H(e){let t=A(e,z),r,n,a,i,o;function d(){if(!j(t))return this;r=t.querySelector(`.${z}__header`),n=t.querySelector(`.${z}__content`),a=t.querySelector(`.${z}__label`);let s=t.classList.contains(`${z}--onload-open`);v(t,"behavior_flyout-menu"),v(r,"behavior_flyout-menu_trigger"),v(n,"behavior_flyout-menu_content");let h=s?_.CLASSES.MH_DEFAULT:_.CLASSES.MH_ZERO;return i=new _(n).init(h),o=new I(t),o.setTransition(i,i.maxHeightZero,i.maxHeightDefault),o.init(s),o.addEventListener("expandbegin",()=>{n.classList.remove("u-hidden"),this.dispatchEvent("expandbegin",{target:this})}),o.addEventListener("collapseend",()=>{n.classList.add("u-hidden")}),this}function c(){return a.textContent.trim()}this.init=d,this.expand=()=>o.expand(),this.collapse=()=>o.collapse(),this.isExpanded=()=>o.isExpanded(),this.refresh=()=>o.getTransition().refresh(),this.getLabelText=c;let u=new y;return this.addEventListener=u.addEventListener,this.removeEventListener=u.removeEventListener,this.dispatchEvent=u.dispatchEvent,this}H.BASE_CLASS=z;H.init=e=>T(`.${H.BASE_CLASS}`,H,e);var pe={};U(pe,{default:()=>Ce});var Ce={};var Z="o-expandable-group";function J(e){let t=A(e,Z),r=t.classList.contains(`${Z}--accordion`),n,a;function i(d){let c=d.target;a&&a!==c&&a.collapse(),a=c}function o(d){return j(t)?(r&&(n=d,n.forEach(c=>{c.addEventListener("expandbegin",i)})),this):this}return this.init=o,this}J.BASE_CLASS=Z;J.init=e=>{(e||document).querySelectorAll(`.${Z}`).forEach(n=>{let a=T(`.${H.BASE_CLASS}`,H,n);new J(n).init(a)})};var he={};U(he,{default:()=>ze});var ze={};var F="o-summary";function W(e){let t=A(e,F),r=t.classList.contains(`${F}--mobile`),n=t.querySelector(`.${F}__content`),a=t.querySelector(`.${F}__btn`),i,o,d;function c(){return j(t)?(window.addEventListener("load",u),this):this}function u(){window.removeEventListener("load",u),d=!S(),v(t,"behavior_flyout-menu"),v(n,"behavior_flyout-menu_content"),v(a,"behavior_flyout-menu_trigger"),o=new I(t,!1),i=new _(n),i.init(d?_.CLASSES.MH_SUMMARY:_.CLASSES.MH_DEFAULT),o.setTransition(i,i.maxHeightSummary,i.maxHeightDefault),o.addEventListener("triggerclick",O),o.init(),b(),window.addEventListener("resize",b),"onorientationchange"in window&&window.addEventListener("orientationchange",b),t.addEventListener("focusin",s),n.addEventListener("click",h)}function s(D){!d&&D.target!==a&&(a.click(),t.removeEventListener("focusin",s))}function h(D){D.target.tagName!=="A"&&o.isExpanded()&&i.refresh()}function b(){S()?R():C()}function S(){return r&&!de(K)||n.scrollHeight<=88}function O(){o.addEventListener("expandend",k)}function k(){w(),window.removeEventListener("resize",b),window.removeEventListener("orientationchange",b),o.removeEventListener("expandend",k),o.suspend(),i.remove()}function g(){a.classList.remove("u-hidden")}function w(){a.classList.add("u-hidden")}function C(){return d&&(o.collapse(),i.animateOn(),g(),d=!1),!d}function R(){return d||(i.animateOff(),o.expand(),w(),d=!0),d}let L=new y;return this.addEventListener=L.addEventListener,this.removeEventListener=L.removeEventListener,this.dispatchEvent=L.dispatchEvent,this.init=c,this}W.BASE_CLASS=F;W.init=e=>T(`.${F}`,W,e);var q="o-summary-minimal";function Q(e){let t=A(e,q),r=t.querySelector(`.${q}__content`),n=t.querySelector(`.${q}__btn`),a,i;function o(){return j(t)?(v(t,"behavior_flyout-menu"),v(r,"behavior_flyout-menu_content"),v(n,"behavior_flyout-menu_trigger"),window.addEventListener("load",d),this):this}function d(){window.removeEventListener("load",d),i=new I(t,!1),a=new _(r),a.init(_.CLASSES.MH_SUMMARY),i.setTransition(a,a.maxHeightSummary,a.maxHeightDefault),i.init(),t.addEventListener("focusin",c),r.addEventListener("click",u),i.collapse(),a.animateOn()}function c(h){h.target!==n&&(n.click(),t.removeEventListener("focusin",c))}function u(h){h.target.tagName!=="A"&&i.isExpanded()&&a.refresh()}let s=new y;return this.addEventListener=s.addEventListener,this.removeEventListener=s.removeEventListener,this.dispatchEvent=s.dispatchEvent,this.init=o,this}Q.BASE_CLASS=q;Q.init=e=>T(`.${q}`,Q,e);})();
//# sourceMappingURL=index.js.map