Repository navigation
Expand file tree
/
Copy pathbreakpoints.min.js
More file actions
1 lines (1 loc) · 1.54 KB
/
Copy pathbreakpoints.min.js
File metadata and controls
1 lines (1 loc) · 1.54 KB
1
export default class Breakpoints{constructor(t){this.config=t||[["xs",0],["sm",480],["md",768],["lg",1024],["xl",1280],["x2",1440],["x3",1690],["x4",1920],["x5",2560]],this.b={},this.n={},this.w=0,this.handleResize=this.debounce(this.setValues.bind(this),100),window.addEventListener("resize",this.handleResize),this.setValues()}debounce(t,e){let s;return function(){clearTimeout(s),s=setTimeout((()=>{t.apply(this,arguments)}),e)}}setValues(){let t=window.innerWidth;this.w!==t&&(this.w=t,this.config.forEach(((e,s,i)=>{let n=e[0],o=e[1];if(void 0!==i[s+1]){let e=i[s+1][1];this.n[n]=o,this.b[n]=o<=t&&t<e}else this.n[n]=o,this.b[n]=o<=t})))}getKeyByValue(t,e){return Object.keys(t).find((s=>t[s]===e))}lte(t){return this.setValues(),void 0===this.n[t]?(console.warn(`Breakpoint label \`${t}\` not found.`),!1):this.w<=this.n[t]||this.b[t]}gte(t){return this.setValues(),void 0===this.n[t]?(console.warn(`Breakpoint label \`${t}\` not found.`),!1):this.w>=this.n[t]}is(t){return this.setValues(),void 0===this.n[t]?(console.warn(`Breakpoint label \`${t}\` not found.`),!1):this.b[t]}get(){return this.setValues(),this.getKeyByValue(this.b,!0)}between(t,e){return this.setValues(),void 0===this.n[t]||void 0===this.n[e]?(void 0===this.n[t]&&void 0===this.n[e]?console.warn(`Breakpoint labels \`${t}\` && \`${e}\` not found.`):void 0===this.n[t]?console.warn(`Breakpoint label \`${t}\` not found.`):void 0===this.n[e]&&console.warn(`Breakpoint label \`${e}\` not found.`),!1):this.n[t]<=this.w&&this.w<=this.n[e]}destroy(){window.removeEventListener("resize",this.handleResize)}}