UNPKG

breakjs

Version:

Responsive breakpoints in Javascript made simple.

1 lines 2.5 kB
!function e(n,r,t){function a(i,o){if(!r[i]){if(!n[i]){var f="function"==typeof require&&require;if(!o&&f)return f(i,!0);if(u)return u(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var s=r[i]={exports:{}};n[i][0].call(s.exports,function(e){var r=n[i][1][e];return a(r?r:e)},s,s.exports,e,n,r,t)}return r[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)a(t[i]);return a}({1:[function(e,n,r){"use strict";function t(e,n){for(var r=e.length-1;r>=0;r--)if(n(e[r]))return e[r]}Object.defineProperty(r,"__esModule",{value:!0});var a={between:function(e,n){return window.matchMedia("screen and (min-width: "+e+"px) and "+("(max-width: "+(n-1)+"px)"))},atLeast:function(e){return window.matchMedia("screen and (min-width: "+e+"px)")},atMost:function(e){return window.matchMedia("screen and (max-width: "+(e-1)+"px)")}},u=function(e,n){return{is:"number"==typeof n?a.between(e,n):a.atLeast(e),atLeast:a.atLeast(e),atMost:a.atMost(n||Number.MAX_VALUE)}},i=function(e){function n(e){var n=t(o,function(n){return n.name===e});if(!n)throw new Error("invalid breakpoint name");return n}if(!e)throw new Error("No breakpoints were defined!");var r=[],a=function(n){var a={name:n,value:e[n]};if(t(r,function(e){return e.value===a.value}))throw new Error("Breakpoint values must be unique.");r.push(a)};for(var i in e)a(i);var o=r.sort(function(e,n){return e.value>n.value}).map(function(e,n){if("string"!=typeof e.name)throw new Error("Invalid breakpoint name -- should be a string.");if("number"!=typeof e.value||e.value<0)throw new Error("Invalid breakpoint value for "+e.name+": "+e.value);var t={name:e.name};return 1===r.length?t.query=u(0,null):n===r.length-1?t.query=u(e.value,null):t.query=u(e.value,r[n+1].value),t}),f=[];return{breakpoints:r,is:function(e){return n(e).query.is.matches},atLeast:function(e){return n(e).query.atLeast.matches},atMost:function(e){return n(e).query.atMost.matches},current:function(){var e=t(o,function(e){return e.query.is.matches});return e?e.name:void 0},addChangeListener:function(e){var n=this;o.forEach(function(r){var t=function(){var t=n.current();t===r.name&&e(t)};f.push({original:e,created:t}),r.query.is.addListener(t)})},removeChangeListener:function(e){o.forEach(function(n){var r=t(f,function(n){return n.original===e});r&&(n.query.is.removeListener(r.created),f.splice(f.indexOf(r),1))})}}};"undefined"!=typeof window&&(window.Breakjs=i),r["default"]=i,n.exports=r["default"]},{}]},{},[1]);