UNPKG

@cfpb/cfpb-design-system

Version:
3 lines (2 loc) 11.4 kB
(()=>{var mt=Object.defineProperty;var Et=(t,i)=>{for(var e in i)mt(t,e,{get:i[e],enumerable:!0})};var J={};Et(J,{default:()=>vt});var vt={};var Z={bpXS:{min:0,max:600},bpSM:{min:601,max:900},bpMED:{min:901,max:1020},bpLG:{min:1021,max:1200},bpXL:{min:1201}};function F(){let t=getComputedStyle(document.body).fontSize;return t=t===""?-1:t,parseFloat(t)}function bt(t,i){let e=t.min,r=t.max;F()>0&&F()!==16&&(e=e/16*F(),r=r/16*F());let s=e||0,u=r||Number.POSITIVE_INFINITY;return s<=i&&i<=u}function _t(t){let i={};t=t||window.innerWidth;let e;for(e in Z)i[e]=bt(Z[e],t);return i}var et="mobile",At="tablet",yt="desktop";function xt(t){let i=!1,e=_t();return(t===et&&e.bpXS||t===At&&e.bpSM||t===yt&&(e.bpMED||e.bpLG||e.bpXL))&&(i=!0),i}var m="data-js-hook",w="behavior_",$="state_";function _(){let t={};function i(n,s){return{}.hasOwnProperty.call(t,n)?t[n].push(s):t[n]=[s],this}function e(n,s){if(!{}.hasOwnProperty.call(t,n))return this;let u=t[n].indexOf(s);return u!==-1&&t[n].splice(u,1),this}function r(n,s){if(!{}.hasOwnProperty.call(t,n))return this;s=s||{};let u=t[n];for(let l=0,d=u.length;l<d;l++)u[l].call(this,s);return this}return this.addEventListener=i,this.removeEventListener=e,this.dispatchEvent=r,this.getRegisteredEvents=()=>t,this}function S(t,i){if(!t)return!1;let e=t.getAttribute(m);return e?(e=e.split(" "),e.indexOf(i)>-1):!1}function W(t,i){if(S(t,i))return i;if(i.indexOf(" ")!==-1){let r=m+" values cannot contain spaces!";throw new Error(r)}let e=t.getAttribute(m);return e!==null&&(i=e+" "+i),t.setAttribute(m,i),i}var Q=$+"atomic_init";function St(t,i){if(!t||!t.classList){let e=t+' is not valid. Check that element is a DOM node with class "'+i+'"';throw new Error(e)}return t}function Lt(t,i){let e=t.classList.contains(i)?t:t.querySelector("."+i);if(!e){let r=i+" not found on or in passed DOM node.";throw new Error(r)}return e}function Ot(t,i){return St(t,i),Lt(t,i)}function Tt(t){return S(t,Q)?!1:(W(t,Q),!0)}function wt(t,i,e,r={}){let s=(e||document).querySelectorAll(t),u=[],l,d;for(let p=0,a=s.length;p<a;p++)d=s[p],S(d,Q)===!1&&(l=new i(d),l.init(r),u.push(l));return u}function it(t,i){i=i||document;let e=[];try{e=i.querySelectorAll(t)}catch(r){let n=`${t} not found in DOM! ${r}`;throw new Error(n)}return e.length===0&&t.indexOf(w)===-1&&(e=nt(t,i)),e}function It(t,i,e,r){let n=[];t instanceof NodeList?n=t:t instanceof Node?n=[t]:typeof t=="string"&&(n=it(t,r));for(let s=0,u=n.length;s<u;s++)n[s].addEventListener(i,e,!1);return n}function k(t,i){let e;if(S(t,i))return e=t,e;if(t){let r="["+m+"="+i+"]";e=t.querySelector(r)}if(!e){let r=i+" behavior not found on passed DOM node!";throw new Error(r)}return e}function nt(t,i){return t=m+"*="+w+t,t="["+t+"]",it(t,i)}var B=Object.prototype.toString;function rt(t){return typeof t=="undefined"}function Nt(t){return typeof t!="undefined"}function Mt(t){return t!==null&&typeof t=="object"}function st(t){return B.call(t)==="[object String]"}function Ct(t){return B.call(t)==="[object Number]"}function Bt(t){return B.call(t)==="[object Date]"}var Dt=Array.isArray||function(i){return B.call(i)==="[object Array]"};function Pt(t){return B.call(t)==="[object Function]"}function Ht(t){return rt(t)||t===null||st(t)&&t.length<=0||/^\s*$/.test(t)}function Rt(){return!!new RegExp(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i).test(navigator.userAgent)}function c(t,i,e){let r=i,n=t;if(!e)throw new Error("Child transition argument must be defined!");let s=e,u,l,d,p=!1,a=!1,E=!1;if(typeof r.CSS_PROPERTY=="undefined"||typeof r.BASE_CLASS=="undefined")throw new Error("Transitions require CSS_PROPERTY and BASE_CLASS to be passed into BaseTransition.");function b(){l&&p?(n.addEventListener(l,d),s.dispatchEvent(c.BEGIN_EVENT,{target:s,type:c.BEGIN_EVENT}),n.classList.add(c.ANIMATING_CLASS),a=!0):(s.dispatchEvent(c.BEGIN_EVENT,{target:s,type:c.BEGIN_EVENT}),d())}function y(){n.removeEventListener(l,d)}function L(f){return f&&f.propertyName!==r.CSS_PROPERTY?!1:(y(),n.classList.remove(c.ANIMATING_CLASS),s.dispatchEvent(c.END_EVENT,{target:s,type:c.END_EVENT}),a=!1,!0)}function I(){let f;for(f in r)({}).hasOwnProperty.call(r,f)&&r[f]!==r.BASE_CLASS&&n.classList.contains(r[f])&&n.classList.remove(r[f])}function g(){a&&(n.style.webkitTransitionDuration="0",n.style.mozTransitionDuration="0",n.style.oTransitionDuration="0",n.style.transitionDuration="0",n.removeEventListener(l,d),d(),n.style.webkitTransitionDuration="",n.style.mozTransitionDuration="",n.style.oTransitionDuration="",n.style.transitionDuration="")}function O(){g(),I(),n.classList.remove(r.BASE_CLASS)}function H(){n.classList.remove(c.NO_ANIMATION_CLASS),p=!0}function X(){n.classList.add(c.NO_ANIMATION_CLASS),p=!1}function N(f){if(!f){let U="Element does not have TransitionEnd event. It may be null!";throw new Error(U)}let j,M={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},T;for(T in M)if({}.hasOwnProperty.call(M,T)&&typeof f.style[T]!="undefined"){j=M[T];break}return j}function R(f){O(),H(),n=f,n.classList.add(r.BASE_CLASS),l=N(n)}function z(f){if(p=!n.classList.contains(c.NO_ANIMATION_CLASS),d=L.bind(this),R(n),!f)throw new Error("Transition needs to be passed an initial CSS class on initialization!");return n.classList.add(f),this}function G(f){return E||(I(),E=!0),n.classList.contains(f)?!1:(y(),n.classList.remove(u),u=f,b(),n.classList.add(u),!0)}return this.animateOff=X,this.animateOn=H,this.applyClass=G,this.halt=g,this.init=z,this.isAnimated=()=>p,this.remove=O,this.setElement=R,this}c.BEGIN_EVENT="transitionbegin";c.END_EVENT="transitionend";c.NO_ANIMATION_CLASS="u-no-animation";c.ANIMATING_CLASS="u-is-animating";var D=w+"flyout-menu",Ft="["+m+"="+D;function ot(t,i=!0){let e=k(t,D),r=H(t),n=k(t,D+"_content"),s=0,u=0,l=1,d=2,p=3,a,E,b,y=U.bind(this),L=T.bind(this),I,g=!0,O=!1;function H(o){let h=[],v=o.querySelectorAll(`${Ft}_trigger]`),C,x,K;for(let q=v.length>>>0;q--;){for(K=!1,C=v[q],x=C.parentElement;x!==o;)x.getAttribute(m)&&x.getAttribute(m).split(" ").indexOf(D)!==-1?(K=!0,x=o):x=x.parentElement;K||h.unshift(v[q])}return h}function X(o=!1){return s=o?p:u,r.forEach(h=>{N("expanded",h,o),h.addEventListener("click",f.bind(this)),h.addEventListener("touchstart",R,{passive:!0}),h.addEventListener("mouseover",z.bind(this)),h.addEventListener("mouseout",G.bind(this))}),n.setAttribute("data-open",o?"true":"false"),i&&!o&&n.setAttribute("hidden",""),tt(),this}function N(o,h,v){let C=String(v);return h.setAttribute("aria-"+o,C),C}function R(){O=!0}function z(o){g||(O||this.dispatchEvent("triggerover",{target:this,trigger:o.target,type:"triggerover"}),O=!1)}function G(o){g||this.dispatchEvent("triggerout",{target:this,trigger:o.target,type:"triggerout"})}function f(o){if(!g)switch(this.dispatchEvent("triggerclick",{target:this,trigger:o.target,type:"triggerclick"}),o.preventDefault(),s){case u:case l:this.expand();break;case d:case p:this.collapse();break}}function j(){if(a==null||a.halt(),s===d||s===p)return this;if(s=d,i&&n.removeAttribute("hidden"),this.dispatchEvent("expandbegin",{target:this,type:"expandbegin"}),!E||!b)return L(),this;let o=a==null?void 0:a.isAnimated();return o&&a.addEventListener(c.END_EVENT,L),E(),o||L(),this}function M(){if(a==null||a.halt(),s===l||s===u)return this;for(let h=0,v=r.length;h<v;h++)N("expanded",r[h],!1);if(n.setAttribute("data-open","false"),s=l,this.dispatchEvent("collapsebegin",{target:this,type:"collapsebegin"}),!b||!E)return y(),this;let o=a==null?void 0:a.isAnimated();return o&&a.addEventListener(c.END_EVENT,y),b(),o||y(),this}function T(){s=p,n.setAttribute("data-open","true"),a&&a.removeEventListener(c.END_EVENT,L),this.dispatchEvent("expandend",{target:this,type:"expandend"});for(let o=0,h=r.length;o<h;o++)N("expanded",r[o],!0)}function U(){s=u,i&&n.setAttribute("hidden",""),a&&a.removeEventListener(c.END_EVENT,y),this.dispatchEvent("collapseend",{target:this,type:"collapseend"})}function dt(o,h,v){a=o,h&&h!==b&&(b=h),v&&v!==E&&(E=v)}function lt(){a&&a.remove();let o;a=o,E=o,b=o}function ft(){return{container:e,content:n,trigger:r}}function tt(){return g&&(g=!1),!g}function ht(){return g||(g=!0),g}function pt(o){return I=o,this}let Y=new _;return this.addEventListener=Y.addEventListener,this.removeEventListener=Y.removeEventListener,this.dispatchEvent=Y.dispatchEvent,this.init=X,this.expand=j,this.collapse=M,this.setTransition=dt,this.clearTransition=lt,this.getData=()=>I,this.getTransition=()=>a,this.getDom=ft,this.isAnimating=()=>s===d||s===l,this.isExpanded=()=>s===p,this.resume=tt,this.setData=pt,this.suspend=ht,ot.BASE_CLASS=D,this}var V={CSS_PROPERTY:"opacity",BASE_CLASS:"u-alpha-transition",ALPHA_100:"u-alpha-100",ALPHA_0:"u-alpha-0"};function at(t){let i=new _,e=new c(t,V,this);function r(u){return e.init(u),this}function n(){return e.applyClass(V.ALPHA_100),this}function s(){return e.applyClass(V.ALPHA_0),this}return this.addEventListener=i.addEventListener,this.dispatchEvent=i.dispatchEvent,this.removeEventListener=i.removeEventListener,this.animateOff=e.animateOff,this.animateOn=e.animateOn,this.halt=e.halt,this.isAnimated=e.isAnimated,this.remove=e.remove,this.setElement=e.setElement,this.fadeIn=n,this.fadeOut=s,this.init=r,this}at.CLASSES=V;var P={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 ut(t){let i=new _,e=new c(t,P,this),r=0;function n(){let b=t.scrollHeight+"px";t.style.maxHeight=b}function s(){window.removeEventListener("load",s),n()}function u(E){return e.init(E),window.addEventListener("load",s),window.addEventListener("resize",()=>{n()}),this}function l(){return n(),e.applyClass(P.MH_DEFAULT),(!r||t.scrollHeight>r)&&(r=t.scrollHeight),this}function d(){return e.applyClass(P.MH_SUMMARY),r=t.scrollHeight,this}function p(){return e.applyClass(P.MH_ZERO),r=t.scrollHeight,this}function a(){return t.style.maxHeight="",e.remove()}return this.addEventListener=i.addEventListener,this.dispatchEvent=i.dispatchEvent,this.removeEventListener=i.removeEventListener,this.animateOff=e.animateOff,this.animateOn=e.animateOn,this.halt=e.halt,this.isAnimated=e.isAnimated,this.setElement=e.setElement,this.refresh=n,this.remove=a,this.init=u,this.maxHeightDefault=l,this.maxHeightSummary=d,this.maxHeightZero=p,this}ut.CLASSES=P;var A={CSS_PROPERTY:"transform",BASE_CLASS:"u-move-transition",MOVE_TO_ORIGIN:"u-move-to-origin",MOVE_LEFT:"u-move-left",MOVE_LEFT_2X:"u-move-left-2x",MOVE_LEFT_3X:"u-move-left-3x",MOVE_RIGHT:"u-move-right",MOVE_UP:"u-move-up"};function ct(t){let i=new _,e=new c(t,A,this);function r(d){return e.init(d),this}function n(){return e.applyClass(A.MOVE_TO_ORIGIN),this}function s(d){d=d||1;let p=[A.MOVE_LEFT,A.MOVE_LEFT_2X,A.MOVE_LEFT_3X];return e.applyClass(p[d-1]),this}function u(){return e.applyClass(A.MOVE_RIGHT),this}function l(){return e.applyClass(A.MOVE_UP),this}return this.addEventListener=i.addEventListener,this.dispatchEvent=i.dispatchEvent,this.removeEventListener=i.removeEventListener,this.animateOff=e.animateOff,this.animateOn=e.animateOn,this.halt=e.halt,this.isAnimated=e.isAnimated,this.setElement=e.setElement,this.remove=e.remove,this.init=r,this.moveLeft=()=>s(1),this.moveLeft2=()=>s(2),this.moveLeft3=()=>s(3),this.moveRight=u,this.moveToOrigin=n,this.moveUp=l,this}ct.CLASSES=A;})(); //# sourceMappingURL=index.js.map