diff --git a/dist/vue-mq.cjs.js b/dist/vue-mq.cjs.js index 0b22e30..59e08b7 100644 --- a/dist/vue-mq.cjs.js +++ b/dist/vue-mq.cjs.js @@ -48,16 +48,16 @@ function convertBreakpointsToMediaQueries(breakpoints) { } function transformValuesFromBreakpoints(breakpoints, values, currentBreakpoint) { var findClosestValue = function findClosestValue(currentBreakpoint) { + if (values[currentBreakpoint] !== undefined) return values[currentBreakpoint]; var index = breakpoints.findIndex(function (b) { return b === currentBreakpoint; }); var newBreakpoint = index !== -1 || index !== 0 ? breakpoints[index - 1] : null; if (!newBreakpoint) return values[index]; - return values[newBreakpoint] || findClosestValue(newBreakpoint); + return values[newBreakpoint] !== undefined ? values[newBreakpoint] : findClosestValue(newBreakpoint); }; - var result = values[currentBreakpoint] || findClosestValue(currentBreakpoint); - return result; + return findClosestValue(currentBreakpoint); } function selectBreakpoints(breakpoints, currentBreakpoint) { var index = breakpoints.findIndex(function (b) { diff --git a/dist/vue-mq.es.js b/dist/vue-mq.es.js index 9641f90..cc2f761 100644 --- a/dist/vue-mq.es.js +++ b/dist/vue-mq.es.js @@ -44,16 +44,16 @@ function convertBreakpointsToMediaQueries(breakpoints) { } function transformValuesFromBreakpoints(breakpoints, values, currentBreakpoint) { var findClosestValue = function findClosestValue(currentBreakpoint) { + if (values[currentBreakpoint] !== undefined) return values[currentBreakpoint]; var index = breakpoints.findIndex(function (b) { return b === currentBreakpoint; }); var newBreakpoint = index !== -1 || index !== 0 ? breakpoints[index - 1] : null; if (!newBreakpoint) return values[index]; - return values[newBreakpoint] || findClosestValue(newBreakpoint); + return values[newBreakpoint] !== undefined ? values[newBreakpoint] : findClosestValue(newBreakpoint); }; - var result = values[currentBreakpoint] || findClosestValue(currentBreakpoint); - return result; + return findClosestValue(currentBreakpoint); } function selectBreakpoints(breakpoints, currentBreakpoint) { var index = breakpoints.findIndex(function (b) { diff --git a/dist/vue-mq.js b/dist/vue-mq.js index 51e5e6a..5241496 100644 --- a/dist/vue-mq.js +++ b/dist/vue-mq.js @@ -108,16 +108,16 @@ function convertBreakpointsToMediaQueries(breakpoints) { } function transformValuesFromBreakpoints(breakpoints, values, currentBreakpoint) { var findClosestValue = function findClosestValue(currentBreakpoint) { + if (values[currentBreakpoint] !== undefined) return values[currentBreakpoint]; var index = breakpoints.findIndex(function (b) { return b === currentBreakpoint; }); var newBreakpoint = index !== -1 || index !== 0 ? breakpoints[index - 1] : null; if (!newBreakpoint) return values[index]; - return values[newBreakpoint] || findClosestValue(newBreakpoint); + return values[newBreakpoint] !== undefined ? values[newBreakpoint] : findClosestValue(newBreakpoint); }; - var result = values[currentBreakpoint] || findClosestValue(currentBreakpoint); - return result; + return findClosestValue(currentBreakpoint); } function selectBreakpoints(breakpoints, currentBreakpoint) { var index = breakpoints.findIndex(function (b) { diff --git a/dist/vue-mq.min.js b/dist/vue-mq.min.js index 7ddbe73..09b5b1a 100644 --- a/dist/vue-mq.min.js +++ b/dist/vue-mq.min.js @@ -1,2 +1,2 @@ -!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.vueMq=t()}(this,function(){"use strict";var n=function(n){return n.replace(/[A-Z]/g,function(n){return"-"+n.toLowerCase()}).toLowerCase()},t=function(t){var e="",r=Object.keys(t);return r.forEach(function(i,u){var o=t[i];(function(n){return/[height|width]$/.test(n)})(i=n(i))&&"number"==typeof o&&(o+="px"),e+=!0===o?i:!1===o?"not "+i:"("+i+": "+o+")",u1&&void 0!==arguments[1]?arguments[1]:{}).breakpoints,e=void 0===t?u:t,o=new n({data:function(){return{currentBreakpoint:null}}}),c=r(e);Object.keys(c).map(function(n){!function(n,t){var e=window.matchMedia(n),r=function(n){var e=n.matches;e&&t()};e.addListener(r),r(e)}(c[n],function(){o.currentBreakpoint=n})}),n.filter("mq",function(n,t){return function(n,t,e){return t[e]||function e(r){var i=n.findIndex(function(n){return n===r}),u=-1!==i||0!==i?n[i-1]:null;return u?t[u]||e(u):t[i]}(e)}(Object.keys(e),t,n)}),n.mixin({computed:{$mq:function(){return o.currentBreakpoint}}}),n.prototype.$mqAvailableBreakpoints=e,n.component("MqLayout",i)}}}); +!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.vueMq=t()}(this,function(){"use strict";var n=function(n){return n.replace(/[A-Z]/g,function(n){return"-"+n.toLowerCase()}).toLowerCase()},t=function(t){var e="",r=Object.keys(t);return r.forEach(function(i,o){var u=t[i];(function(n){return/[height|width]$/.test(n)})(i=n(i))&&"number"==typeof u&&(u+="px"),e+=!0===u?i:!1===u?"not "+i:"("+i+": "+u+")",o1&&void 0!==arguments[1]?arguments[1]:{}).breakpoints,e=void 0===t?o:t,u=new n({data:function(){return{currentBreakpoint:null}}}),c=r(e);Object.keys(c).map(function(n){!function(n,t){var e=window.matchMedia(n),r=function(n){var e=n.matches;e&&t()};e.addListener(r),r(e)}(c[n],function(){u.currentBreakpoint=n})}),n.filter("mq",function(n,t){return function(n,t,e){return function e(r){if(void 0!==t[r])return t[r];var i=n.findIndex(function(n){return n===r}),o=-1!==i||0!==i?n[i-1]:null;return o?void 0!==t[o]?t[o]:e(o):t[i]}(e)}(Object.keys(e),t,n)}),n.mixin({computed:{$mq:function(){return u.currentBreakpoint}}}),n.prototype.$mqAvailableBreakpoints=e,n.component("MqLayout",i)}}}); //# sourceMappingURL=vue-mq.min.js.map diff --git a/dist/vue-mq.min.js.map b/dist/vue-mq.min.js.map index 91b08c7..6c4c112 100644 --- a/dist/vue-mq.min.js.map +++ b/dist/vue-mq.min.js.map @@ -1 +1 @@ -{"version":3,"file":"vue-mq.min.js","sources":["../node_modules/string-convert/camel2hyphen.js","../node_modules/json2mq/index.js","../src/helpers.js","../rollupPluginBabelHelpers","../src/component.js","../src/index.js"],"sourcesContent":["var camel2hyphen = function (str) {\n return str\n .replace(/[A-Z]/g, function (match) {\n return '-' + match.toLowerCase();\n })\n .toLowerCase();\n};\n\nmodule.exports = camel2hyphen;","var camel2hyphen = require('string-convert/camel2hyphen');\n\nvar isDimension = function (feature) {\n var re = /[height|width]$/;\n return re.test(feature);\n};\n\nvar obj2mq = function (obj) {\n var mq = '';\n var features = Object.keys(obj);\n features.forEach(function (feature, index) {\n var value = obj[feature];\n feature = camel2hyphen(feature);\n // Add px to dimension features\n if (isDimension(feature) && typeof value === 'number') {\n value = value + 'px';\n }\n if (value === true) {\n mq += feature;\n } else if (value === false) {\n mq += 'not ' + feature;\n } else {\n mq += '(' + feature + ': ' + value + ')';\n }\n if (index < features.length-1) {\n mq += ' and '\n }\n });\n return mq;\n};\n\nvar json2mq = function (query) {\n var mq = '';\n if (typeof query === 'string') {\n return query;\n }\n // Handling array of media queries\n if (query instanceof Array) {\n query.forEach(function (q, index) {\n mq += obj2mq(q);\n if (index < query.length-1) {\n mq += ', '\n }\n });\n return mq;\n }\n // Handling single media query\n return obj2mq(query);\n};\n\nmodule.exports = json2mq;","import json2mq from 'json2mq'\n\nexport function convertBreakpointsToMediaQueries(breakpoints) {\n const keys = Object.keys(breakpoints)\n const values = keys.map(key => breakpoints[key])\n const breakpointValues = [0, ...values.slice(0, -1)]\n const mediaQueries = breakpointValues.reduce((sum, value, index) => {\n const options = Object.assign(\n {\n minWidth: value,\n },\n index < keys.length - 1 ? { maxWidth: breakpointValues[index+1] - 1 } : {}\n )\n const mediaQuery = json2mq(options)\n return Object.assign(\n sum,\n {\n [keys[index]]: mediaQuery,\n }\n )\n }, {})\n return mediaQueries\n}\n\nexport function transformValuesFromBreakpoints(breakpoints, values, currentBreakpoint) {\n const findClosestValue = (currentBreakpoint) => {\n const index = breakpoints.findIndex(b => b === currentBreakpoint)\n const newBreakpoint = index !== -1 || index !== 0 ? breakpoints[index-1] : null\n if (!newBreakpoint) return values[index]\n return values[newBreakpoint] || findClosestValue(newBreakpoint)\n }\n const result = values[currentBreakpoint] || findClosestValue(currentBreakpoint)\n return result\n}\n\nexport function selectBreakpoints(breakpoints, currentBreakpoint) {\n const index = breakpoints.findIndex(b => b === currentBreakpoint)\n return breakpoints.slice(index)\n}\n","export { _typeof as typeof, _jsx as jsx, _asyncIterator as asyncIterator, _AwaitValue as AwaitValue, _AsyncGenerator as AsyncGenerator, _wrapAsyncGenerator as wrapAsyncGenerator, _awaitAsyncGenerator as awaitAsyncGenerator, _asyncGeneratorDelegate as asyncGeneratorDelegate, _asyncToGenerator as asyncToGenerator, _classCallCheck as classCallCheck, _createClass as createClass, _defineEnumerableProperties as defineEnumerableProperties, _defaults as defaults, _defineProperty as defineProperty, _extends as extends, _get as get, _inherits as inherits, _inheritsLoose as inheritsLoose, _wrapNativeSuper as wrapNativeSuper, _instanceof as instanceof, _interopRequireDefault as interopRequireDefault, _interopRequireWildcard as interopRequireWildcard, _newArrowCheck as newArrowCheck, _objectDestructuringEmpty as objectDestructuringEmpty, _objectWithoutProperties as objectWithoutProperties, _assertThisInitialized as assertThisInitialized, _possibleConstructorReturn as possibleConstructorReturn, _set as set, _slicedToArray as slicedToArray, _slicedToArrayLoose as slicedToArrayLoose, _taggedTemplateLiteral as taggedTemplateLiteral, _taggedTemplateLiteralLoose as taggedTemplateLiteralLoose, _temporalRef as temporalRef, _readOnlyError as readOnlyError, _classNameTDZError as classNameTDZError, _temporalUndefined as temporalUndefined, _toArray as toArray, _toConsumableArray as toConsumableArray, _skipFirstGeneratorNext as skipFirstGeneratorNext, _toPropertyKey as toPropertyKey, _initializerWarningHelper as initializerWarningHelper, _initializerDefineProperty as initializerDefineProperty, _applyDecoratedDescriptor as applyDecoratedDescriptor };\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n _typeof = function (obj) {\n return typeof obj;\n };\n } else {\n _typeof = function (obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n };\n }\n\n return _typeof(obj);\n}\n\nvar REACT_ELEMENT_TYPE;\n\nfunction _jsx(type, props, key, children) {\n if (!REACT_ELEMENT_TYPE) {\n REACT_ELEMENT_TYPE = typeof Symbol === \"function\" && Symbol.for && Symbol.for(\"react.element\") || 0xeac7;\n }\n\n var defaultProps = type && type.defaultProps;\n var childrenLength = arguments.length - 3;\n\n if (!props && childrenLength !== 0) {\n props = {\n children: void 0\n };\n }\n\n if (props && defaultProps) {\n for (var propName in defaultProps) {\n if (props[propName] === void 0) {\n props[propName] = defaultProps[propName];\n }\n }\n } else if (!props) {\n props = defaultProps || {};\n }\n\n if (childrenLength === 1) {\n props.children = children;\n } else if (childrenLength > 1) {\n var childArray = new Array(childrenLength);\n\n for (var i = 0; i < childrenLength; i++) {\n childArray[i] = arguments[i + 3];\n }\n\n props.children = childArray;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key === undefined ? null : '' + key,\n ref: null,\n props: props,\n _owner: null\n };\n}\n\nfunction _asyncIterator(iterable) {\n if (typeof Symbol === \"function\") {\n if (Symbol.asyncIterator) {\n var method = iterable[Symbol.asyncIterator];\n if (method != null) return method.call(iterable);\n }\n\n if (Symbol.iterator) {\n return iterable[Symbol.iterator]();\n }\n }\n\n throw new TypeError(\"Object is not async iterable\");\n}\n\nfunction _AwaitValue(value) {\n this.wrapped = value;\n}\n\nfunction _AsyncGenerator(gen) {\n var front, back;\n\n function send(key, arg) {\n return new Promise(function (resolve, reject) {\n var request = {\n key: key,\n arg: arg,\n resolve: resolve,\n reject: reject,\n next: null\n };\n\n if (back) {\n back = back.next = request;\n } else {\n front = back = request;\n resume(key, arg);\n }\n });\n }\n\n function resume(key, arg) {\n try {\n var result = gen[key](arg);\n var value = result.value;\n var wrappedAwait = value instanceof _AwaitValue;\n Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {\n if (wrappedAwait) {\n resume(\"next\", arg);\n return;\n }\n\n settle(result.done ? \"return\" : \"normal\", arg);\n }, function (err) {\n resume(\"throw\", err);\n });\n } catch (err) {\n settle(\"throw\", err);\n }\n }\n\n function settle(type, value) {\n switch (type) {\n case \"return\":\n front.resolve({\n value: value,\n done: true\n });\n break;\n\n case \"throw\":\n front.reject(value);\n break;\n\n default:\n front.resolve({\n value: value,\n done: false\n });\n break;\n }\n\n front = front.next;\n\n if (front) {\n resume(front.key, front.arg);\n } else {\n back = null;\n }\n }\n\n this._invoke = send;\n\n if (typeof gen.return !== \"function\") {\n this.return = undefined;\n }\n}\n\nif (typeof Symbol === \"function\" && Symbol.asyncIterator) {\n _AsyncGenerator.prototype[Symbol.asyncIterator] = function () {\n return this;\n };\n}\n\n_AsyncGenerator.prototype.next = function (arg) {\n return this._invoke(\"next\", arg);\n};\n\n_AsyncGenerator.prototype.throw = function (arg) {\n return this._invoke(\"throw\", arg);\n};\n\n_AsyncGenerator.prototype.return = function (arg) {\n return this._invoke(\"return\", arg);\n};\n\nfunction _wrapAsyncGenerator(fn) {\n return function () {\n return new _AsyncGenerator(fn.apply(this, arguments));\n };\n}\n\nfunction _awaitAsyncGenerator(value) {\n return new _AwaitValue(value);\n}\n\nfunction _asyncGeneratorDelegate(inner, awaitWrap) {\n var iter = {},\n waiting = false;\n\n function pump(key, value) {\n waiting = true;\n value = new Promise(function (resolve) {\n resolve(inner[key](value));\n });\n return {\n done: false,\n value: awaitWrap(value)\n };\n }\n\n ;\n\n if (typeof Symbol === \"function\" && Symbol.iterator) {\n iter[Symbol.iterator] = function () {\n return this;\n };\n }\n\n iter.next = function (value) {\n if (waiting) {\n waiting = false;\n return value;\n }\n\n return pump(\"next\", value);\n };\n\n if (typeof inner.throw === \"function\") {\n iter.throw = function (value) {\n if (waiting) {\n waiting = false;\n throw value;\n }\n\n return pump(\"throw\", value);\n };\n }\n\n if (typeof inner.return === \"function\") {\n iter.return = function (value) {\n return pump(\"return\", value);\n };\n }\n\n return iter;\n}\n\nfunction _asyncToGenerator(fn) {\n return function () {\n var self = this,\n args = arguments;\n return new Promise(function (resolve, reject) {\n var gen = fn.apply(self, args);\n\n function step(key, arg) {\n try {\n var info = gen[key](arg);\n var value = info.value;\n } catch (error) {\n reject(error);\n return;\n }\n\n if (info.done) {\n resolve(value);\n } else {\n Promise.resolve(value).then(_next, _throw);\n }\n }\n\n function _next(value) {\n step(\"next\", value);\n }\n\n function _throw(err) {\n step(\"throw\", err);\n }\n\n _next();\n });\n };\n}\n\nfunction _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nfunction _defineEnumerableProperties(obj, descs) {\n for (var key in descs) {\n var desc = descs[key];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, key, desc);\n }\n\n if (Object.getOwnPropertySymbols) {\n var objectSymbols = Object.getOwnPropertySymbols(descs);\n\n for (var i = 0; i < objectSymbols.length; i++) {\n var sym = objectSymbols[i];\n var desc = descs[sym];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, sym, desc);\n }\n }\n\n return obj;\n}\n\nfunction _defaults(obj, defaults) {\n var keys = Object.getOwnPropertyNames(defaults);\n\n for (var i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = Object.getOwnPropertyDescriptor(defaults, key);\n\n if (value && value.configurable && obj[key] === undefined) {\n Object.defineProperty(obj, key, value);\n }\n }\n\n return obj;\n}\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nfunction _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}\n\nfunction _get(object, property, receiver) {\n if (object === null) object = Function.prototype;\n var desc = Object.getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent === null) {\n return undefined;\n } else {\n return _get(parent, property, receiver);\n }\n } else if (\"value\" in desc) {\n return desc.value;\n } else {\n var getter = desc.get;\n\n if (getter === undefined) {\n return undefined;\n }\n\n return getter.call(receiver);\n }\n}\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;\n}\n\nfunction _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}\n\nvar _gPO = Object.getPrototypeOf || function _gPO(o) {\n return o.__proto__;\n};\n\nvar _sPO = Object.setPrototypeOf || function _sPO(o, p) {\n o.__proto__ = p;\n return o;\n};\n\nvar _construct = typeof Reflect === \"object\" && Reflect.construct || function _construct(Parent, args, Class) {\n var Constructor,\n a = [null];\n a.push.apply(a, args);\n Constructor = Parent.bind.apply(Parent, a);\n return _sPO(new Constructor(), Class.prototype);\n};\n\nvar _cache = typeof Map === \"function\" && new Map();\n\nfunction _wrapNativeSuper(Class) {\n if (typeof Class !== \"function\") {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n if (typeof _cache !== \"undefined\") {\n if (_cache.has(Class)) return _cache.get(Class);\n\n _cache.set(Class, Wrapper);\n }\n\n function Wrapper() {}\n\n Wrapper.prototype = Object.create(Class.prototype, {\n constructor: {\n value: Wrapper,\n enumerable: false,\n writeable: true,\n configurable: true\n }\n });\n return _sPO(Wrapper, _sPO(function Super() {\n return _construct(Class, arguments, _gPO(this).constructor);\n }, Class));\n}\n\nfunction _instanceof(left, right) {\n if (right != null && typeof Symbol !== \"undefined\" && right[Symbol.hasInstance]) {\n return right[Symbol.hasInstance](left);\n } else {\n return left instanceof right;\n }\n}\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n\nfunction _interopRequireWildcard(obj) {\n if (obj && obj.__esModule) {\n return obj;\n } else {\n var newObj = {};\n\n if (obj != null) {\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};\n\n if (desc.get || desc.set) {\n Object.defineProperty(newObj, key, desc);\n } else {\n newObj[key] = obj[key];\n }\n }\n }\n }\n\n newObj.default = obj;\n return newObj;\n }\n}\n\nfunction _newArrowCheck(innerThis, boundThis) {\n if (innerThis !== boundThis) {\n throw new TypeError(\"Cannot instantiate an arrow function\");\n }\n}\n\nfunction _objectDestructuringEmpty(obj) {\n if (obj == null) throw new TypeError(\"Cannot destructure undefined\");\n}\n\nfunction _objectWithoutProperties(source, excluded) {\n if (source == null) return {};\n var target = {};\n var sourceKeys = Object.keys(source);\n var key, i;\n\n for (i = 0; i < sourceKeys.length; i++) {\n key = sourceKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n target[key] = source[key];\n }\n\n if (Object.getOwnPropertySymbols) {\n var sourceSymbolKeys = Object.getOwnPropertySymbols(source);\n\n for (i = 0; i < sourceSymbolKeys.length; i++) {\n key = sourceSymbolKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;\n target[key] = source[key];\n }\n }\n\n return target;\n}\n\nfunction _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (typeof call === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nfunction _set(object, property, value, receiver) {\n var desc = Object.getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent !== null) {\n _set(parent, property, value, receiver);\n }\n } else if (\"value\" in desc && desc.writable) {\n desc.value = value;\n } else {\n var setter = desc.set;\n\n if (setter !== undefined) {\n setter.call(receiver, value);\n }\n }\n\n return value;\n}\n\nfunction _sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n\n try {\n for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nfunction _slicedToArray(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return _sliceIterator(arr, i);\n } else {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n }\n}\n\nfunction _slicedToArrayLoose(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n var _arr = [];\n\n for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {\n _arr.push(_step.value);\n\n if (i && _arr.length === i) break;\n }\n\n return _arr;\n } else {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n }\n}\n\nfunction _taggedTemplateLiteral(strings, raw) {\n return Object.freeze(Object.defineProperties(strings, {\n raw: {\n value: Object.freeze(raw)\n }\n }));\n}\n\nfunction _taggedTemplateLiteralLoose(strings, raw) {\n strings.raw = raw;\n return strings;\n}\n\nfunction _temporalRef(val, name) {\n if (val === _temporalUndefined) {\n throw new ReferenceError(name + \" is not defined - temporal dead zone\");\n } else {\n return val;\n }\n}\n\nfunction _readOnlyError(name) {\n throw new Error(\"\\\"\" + name + \"\\\" is read-only\");\n}\n\nfunction _classNameTDZError(name) {\n throw new Error(\"Class \\\"\" + name + \"\\\" cannot be referenced in computed property keys.\");\n}\n\nvar _temporalUndefined = {};\n\nfunction _toArray(arr) {\n return Array.isArray(arr) ? arr : Array.from(arr);\n}\n\nfunction _toConsumableArray(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];\n\n return arr2;\n } else {\n return Array.from(arr);\n }\n}\n\nfunction _skipFirstGeneratorNext(fn) {\n return function () {\n var it = fn.apply(this, arguments);\n it.next();\n return it;\n };\n}\n\nfunction _toPropertyKey(key) {\n if (typeof key === \"symbol\") {\n return key;\n } else {\n return String(key);\n }\n}\n\nfunction _initializerWarningHelper(descriptor, context) {\n throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and set to use loose mode. ' + 'To use proposal-class-properties in spec mode with decorators, wait for ' + 'the next major version of decorators in stage 2.');\n}\n\nfunction _initializerDefineProperty(target, property, descriptor, context) {\n if (!descriptor) return;\n Object.defineProperty(target, property, {\n enumerable: descriptor.enumerable,\n configurable: descriptor.configurable,\n writable: descriptor.writable,\n value: descriptor.initializer ? descriptor.initializer.call(context) : void 0\n });\n}\n\nfunction _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {\n var desc = {};\n Object['ke' + 'ys'](descriptor).forEach(function (key) {\n desc[key] = descriptor[key];\n });\n desc.enumerable = !!desc.enumerable;\n desc.configurable = !!desc.configurable;\n\n if ('value' in desc || desc.initializer) {\n desc.writable = true;\n }\n\n desc = decorators.slice().reverse().reduce(function (desc, decorator) {\n return decorator(target, property, desc) || desc;\n }, desc);\n\n if (context && desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(context) : void 0;\n desc.initializer = undefined;\n }\n\n if (desc.initializer === void 0) {\n Object['define' + 'Property'](target, property, desc);\n desc = null;\n }\n\n return desc;\n}","// USAGE\n// mq-layout(mq=\"lg\")\n// p I’m lg\nimport { selectBreakpoints } from './helpers'\nconst component = {\n props: {\n mq: {\n required: true,\n type: String,\n }\n },\n computed: {\n plusModifier() { return this.mq.slice(-1) === '+' },\n activeBreakpoints() {\n const breakpoints = Object.keys(this.$mqAvailableBreakpoints)\n const mq = this.plusModifier ? this.mq.slice(0, -1) : this.mq\n return this.plusModifier\n ? selectBreakpoints(breakpoints, mq)\n : [this.mq]\n }\n },\n render(h, props) {\n const shouldRenderChildren = this.activeBreakpoints.includes(this.$mq)\n return shouldRenderChildren ? h('div', this.$slots.default) : h()\n },\n}\n\nexport default component\n","import { convertBreakpointsToMediaQueries, transformValuesFromBreakpoints } from './helpers.js'\nimport MqLayout from './component.js'\n\nconst DEFAULT_BREAKPOINT = {\n sm: 450,\n md: 1250,\n lg: Infinity,\n}\n\nconst install = function (Vue, { breakpoints = DEFAULT_BREAKPOINT } = {}) {\n // Init reactive component\n const reactorComponent = new Vue({\n data: () => ({\n currentBreakpoint: null,\n })\n })\n\n const mediaQueries = convertBreakpointsToMediaQueries(breakpoints)\n Object.keys(mediaQueries).map((key) => {\n const mediaQuery = mediaQueries[key]\n const enter = () => { reactorComponent.currentBreakpoint = key }\n _subscribeToMediaQuery(mediaQuery, enter)\n })\n\n function _subscribeToMediaQuery(mediaQuery, enter) {\n const mql = window.matchMedia(mediaQuery)\n const cb = ({ matches }) => {\n if (matches) enter()\n }\n mql.addListener(cb) //subscribing\n cb(mql) //initial trigger\n }\n\n Vue.filter('mq', (currentBreakpoint, values) => {\n return transformValuesFromBreakpoints(Object.keys(breakpoints), values, currentBreakpoint)\n })\n Vue.mixin({\n computed: {\n $mq() {\n return reactorComponent.currentBreakpoint\n },\n }\n })\n Vue.prototype.$mqAvailableBreakpoints = breakpoints\n Vue.component('MqLayout', MqLayout)\n}\n\nexport default { install }\n"],"names":["str","replace","match","toLowerCase","obj2mq","obj","mq","features","Object","keys","forEach","feature","index","value","test","isDimension","camel2hyphen","length","query","Array","q","convertBreakpointsToMediaQueries","breakpoints","values","map","key","breakpointValues","arr","isArray","i","arr2","from","slice","reduce","sum","options","assign","mediaQuery","json2mq","defineProperty","enumerable","configurable","writable","component","String","this","$mqAvailableBreakpoints","plusModifier","currentBreakpoint","findIndex","b","selectBreakpoints","h","props","activeBreakpoints","includes","$mq","$slots","default","DEFAULT_BREAKPOINT","Infinity","Vue","reactorComponent","mediaQueries","enter","mql","window","matchMedia","cb","matches","addListener","filter","findClosestValue","newBreakpoint","transformValuesFromBreakpoints","mixin","prototype","MqLayout"],"mappings":"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"} \ No newline at end of file +{"version":3,"file":"vue-mq.min.js","sources":["../node_modules/string-convert/camel2hyphen.js","../node_modules/json2mq/index.js","../src/helpers.js","../rollupPluginBabelHelpers","../src/component.js","../src/index.js"],"sourcesContent":["var camel2hyphen = function (str) {\n return str\n .replace(/[A-Z]/g, function (match) {\n return '-' + match.toLowerCase();\n })\n .toLowerCase();\n};\n\nmodule.exports = camel2hyphen;","var camel2hyphen = require('string-convert/camel2hyphen');\n\nvar isDimension = function (feature) {\n var re = /[height|width]$/;\n return re.test(feature);\n};\n\nvar obj2mq = function (obj) {\n var mq = '';\n var features = Object.keys(obj);\n features.forEach(function (feature, index) {\n var value = obj[feature];\n feature = camel2hyphen(feature);\n // Add px to dimension features\n if (isDimension(feature) && typeof value === 'number') {\n value = value + 'px';\n }\n if (value === true) {\n mq += feature;\n } else if (value === false) {\n mq += 'not ' + feature;\n } else {\n mq += '(' + feature + ': ' + value + ')';\n }\n if (index < features.length-1) {\n mq += ' and '\n }\n });\n return mq;\n};\n\nvar json2mq = function (query) {\n var mq = '';\n if (typeof query === 'string') {\n return query;\n }\n // Handling array of media queries\n if (query instanceof Array) {\n query.forEach(function (q, index) {\n mq += obj2mq(q);\n if (index < query.length-1) {\n mq += ', '\n }\n });\n return mq;\n }\n // Handling single media query\n return obj2mq(query);\n};\n\nmodule.exports = json2mq;","import json2mq from 'json2mq'\n\nexport function convertBreakpointsToMediaQueries(breakpoints) {\n const keys = Object.keys(breakpoints)\n const values = keys.map(key => breakpoints[key])\n const breakpointValues = [0, ...values.slice(0, -1)]\n const mediaQueries = breakpointValues.reduce((sum, value, index) => {\n const options = Object.assign(\n {\n minWidth: value,\n },\n index < keys.length - 1 ? { maxWidth: breakpointValues[index+1] - 1 } : {}\n )\n const mediaQuery = json2mq(options)\n return Object.assign(\n sum,\n {\n [keys[index]]: mediaQuery,\n }\n )\n }, {})\n return mediaQueries\n}\n\nexport function transformValuesFromBreakpoints(breakpoints, values, currentBreakpoint) {\n const findClosestValue = (currentBreakpoint) => {\n if (values[currentBreakpoint] !== undefined) return values[currentBreakpoint]\n const index = breakpoints.findIndex(b => b === currentBreakpoint)\n const newBreakpoint = index !== -1 || index !== 0 ? breakpoints[index-1] : null\n if (!newBreakpoint) return values[index]\n return values[newBreakpoint] !== undefined ? values[newBreakpoint] : findClosestValue(newBreakpoint)\n }\n return findClosestValue(currentBreakpoint)\n}\n\nexport function selectBreakpoints(breakpoints, currentBreakpoint) {\n const index = breakpoints.findIndex(b => b === currentBreakpoint)\n return breakpoints.slice(index)\n}\n","export { _typeof as typeof, _jsx as jsx, _asyncIterator as asyncIterator, _AwaitValue as AwaitValue, _AsyncGenerator as AsyncGenerator, _wrapAsyncGenerator as wrapAsyncGenerator, _awaitAsyncGenerator as awaitAsyncGenerator, _asyncGeneratorDelegate as asyncGeneratorDelegate, _asyncToGenerator as asyncToGenerator, _classCallCheck as classCallCheck, _createClass as createClass, _defineEnumerableProperties as defineEnumerableProperties, _defaults as defaults, _defineProperty as defineProperty, _extends as extends, _get as get, _inherits as inherits, _inheritsLoose as inheritsLoose, _wrapNativeSuper as wrapNativeSuper, _instanceof as instanceof, _interopRequireDefault as interopRequireDefault, _interopRequireWildcard as interopRequireWildcard, _newArrowCheck as newArrowCheck, _objectDestructuringEmpty as objectDestructuringEmpty, _objectWithoutProperties as objectWithoutProperties, _assertThisInitialized as assertThisInitialized, _possibleConstructorReturn as possibleConstructorReturn, _set as set, _slicedToArray as slicedToArray, _slicedToArrayLoose as slicedToArrayLoose, _taggedTemplateLiteral as taggedTemplateLiteral, _taggedTemplateLiteralLoose as taggedTemplateLiteralLoose, _temporalRef as temporalRef, _readOnlyError as readOnlyError, _classNameTDZError as classNameTDZError, _temporalUndefined as temporalUndefined, _toArray as toArray, _toConsumableArray as toConsumableArray, _skipFirstGeneratorNext as skipFirstGeneratorNext, _toPropertyKey as toPropertyKey, _initializerWarningHelper as initializerWarningHelper, _initializerDefineProperty as initializerDefineProperty, _applyDecoratedDescriptor as applyDecoratedDescriptor };\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") {\n _typeof = function (obj) {\n return typeof obj;\n };\n } else {\n _typeof = function (obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj;\n };\n }\n\n return _typeof(obj);\n}\n\nvar REACT_ELEMENT_TYPE;\n\nfunction _jsx(type, props, key, children) {\n if (!REACT_ELEMENT_TYPE) {\n REACT_ELEMENT_TYPE = typeof Symbol === \"function\" && Symbol.for && Symbol.for(\"react.element\") || 0xeac7;\n }\n\n var defaultProps = type && type.defaultProps;\n var childrenLength = arguments.length - 3;\n\n if (!props && childrenLength !== 0) {\n props = {\n children: void 0\n };\n }\n\n if (props && defaultProps) {\n for (var propName in defaultProps) {\n if (props[propName] === void 0) {\n props[propName] = defaultProps[propName];\n }\n }\n } else if (!props) {\n props = defaultProps || {};\n }\n\n if (childrenLength === 1) {\n props.children = children;\n } else if (childrenLength > 1) {\n var childArray = new Array(childrenLength);\n\n for (var i = 0; i < childrenLength; i++) {\n childArray[i] = arguments[i + 3];\n }\n\n props.children = childArray;\n }\n\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key === undefined ? null : '' + key,\n ref: null,\n props: props,\n _owner: null\n };\n}\n\nfunction _asyncIterator(iterable) {\n if (typeof Symbol === \"function\") {\n if (Symbol.asyncIterator) {\n var method = iterable[Symbol.asyncIterator];\n if (method != null) return method.call(iterable);\n }\n\n if (Symbol.iterator) {\n return iterable[Symbol.iterator]();\n }\n }\n\n throw new TypeError(\"Object is not async iterable\");\n}\n\nfunction _AwaitValue(value) {\n this.wrapped = value;\n}\n\nfunction _AsyncGenerator(gen) {\n var front, back;\n\n function send(key, arg) {\n return new Promise(function (resolve, reject) {\n var request = {\n key: key,\n arg: arg,\n resolve: resolve,\n reject: reject,\n next: null\n };\n\n if (back) {\n back = back.next = request;\n } else {\n front = back = request;\n resume(key, arg);\n }\n });\n }\n\n function resume(key, arg) {\n try {\n var result = gen[key](arg);\n var value = result.value;\n var wrappedAwait = value instanceof _AwaitValue;\n Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {\n if (wrappedAwait) {\n resume(\"next\", arg);\n return;\n }\n\n settle(result.done ? \"return\" : \"normal\", arg);\n }, function (err) {\n resume(\"throw\", err);\n });\n } catch (err) {\n settle(\"throw\", err);\n }\n }\n\n function settle(type, value) {\n switch (type) {\n case \"return\":\n front.resolve({\n value: value,\n done: true\n });\n break;\n\n case \"throw\":\n front.reject(value);\n break;\n\n default:\n front.resolve({\n value: value,\n done: false\n });\n break;\n }\n\n front = front.next;\n\n if (front) {\n resume(front.key, front.arg);\n } else {\n back = null;\n }\n }\n\n this._invoke = send;\n\n if (typeof gen.return !== \"function\") {\n this.return = undefined;\n }\n}\n\nif (typeof Symbol === \"function\" && Symbol.asyncIterator) {\n _AsyncGenerator.prototype[Symbol.asyncIterator] = function () {\n return this;\n };\n}\n\n_AsyncGenerator.prototype.next = function (arg) {\n return this._invoke(\"next\", arg);\n};\n\n_AsyncGenerator.prototype.throw = function (arg) {\n return this._invoke(\"throw\", arg);\n};\n\n_AsyncGenerator.prototype.return = function (arg) {\n return this._invoke(\"return\", arg);\n};\n\nfunction _wrapAsyncGenerator(fn) {\n return function () {\n return new _AsyncGenerator(fn.apply(this, arguments));\n };\n}\n\nfunction _awaitAsyncGenerator(value) {\n return new _AwaitValue(value);\n}\n\nfunction _asyncGeneratorDelegate(inner, awaitWrap) {\n var iter = {},\n waiting = false;\n\n function pump(key, value) {\n waiting = true;\n value = new Promise(function (resolve) {\n resolve(inner[key](value));\n });\n return {\n done: false,\n value: awaitWrap(value)\n };\n }\n\n ;\n\n if (typeof Symbol === \"function\" && Symbol.iterator) {\n iter[Symbol.iterator] = function () {\n return this;\n };\n }\n\n iter.next = function (value) {\n if (waiting) {\n waiting = false;\n return value;\n }\n\n return pump(\"next\", value);\n };\n\n if (typeof inner.throw === \"function\") {\n iter.throw = function (value) {\n if (waiting) {\n waiting = false;\n throw value;\n }\n\n return pump(\"throw\", value);\n };\n }\n\n if (typeof inner.return === \"function\") {\n iter.return = function (value) {\n return pump(\"return\", value);\n };\n }\n\n return iter;\n}\n\nfunction _asyncToGenerator(fn) {\n return function () {\n var self = this,\n args = arguments;\n return new Promise(function (resolve, reject) {\n var gen = fn.apply(self, args);\n\n function step(key, arg) {\n try {\n var info = gen[key](arg);\n var value = info.value;\n } catch (error) {\n reject(error);\n return;\n }\n\n if (info.done) {\n resolve(value);\n } else {\n Promise.resolve(value).then(_next, _throw);\n }\n }\n\n function _next(value) {\n step(\"next\", value);\n }\n\n function _throw(err) {\n step(\"throw\", err);\n }\n\n _next();\n });\n };\n}\n\nfunction _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nfunction _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nfunction _defineEnumerableProperties(obj, descs) {\n for (var key in descs) {\n var desc = descs[key];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, key, desc);\n }\n\n if (Object.getOwnPropertySymbols) {\n var objectSymbols = Object.getOwnPropertySymbols(descs);\n\n for (var i = 0; i < objectSymbols.length; i++) {\n var sym = objectSymbols[i];\n var desc = descs[sym];\n desc.configurable = desc.enumerable = true;\n if (\"value\" in desc) desc.writable = true;\n Object.defineProperty(obj, sym, desc);\n }\n }\n\n return obj;\n}\n\nfunction _defaults(obj, defaults) {\n var keys = Object.getOwnPropertyNames(defaults);\n\n for (var i = 0; i < keys.length; i++) {\n var key = keys[i];\n var value = Object.getOwnPropertyDescriptor(defaults, key);\n\n if (value && value.configurable && obj[key] === undefined) {\n Object.defineProperty(obj, key, value);\n }\n }\n\n return obj;\n}\n\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nfunction _extends() {\n _extends = Object.assign || function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n\n return _extends.apply(this, arguments);\n}\n\nfunction _get(object, property, receiver) {\n if (object === null) object = Function.prototype;\n var desc = Object.getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent === null) {\n return undefined;\n } else {\n return _get(parent, property, receiver);\n }\n } else if (\"value\" in desc) {\n return desc.value;\n } else {\n var getter = desc.get;\n\n if (getter === undefined) {\n return undefined;\n }\n\n return getter.call(receiver);\n }\n}\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;\n}\n\nfunction _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}\n\nvar _gPO = Object.getPrototypeOf || function _gPO(o) {\n return o.__proto__;\n};\n\nvar _sPO = Object.setPrototypeOf || function _sPO(o, p) {\n o.__proto__ = p;\n return o;\n};\n\nvar _construct = typeof Reflect === \"object\" && Reflect.construct || function _construct(Parent, args, Class) {\n var Constructor,\n a = [null];\n a.push.apply(a, args);\n Constructor = Parent.bind.apply(Parent, a);\n return _sPO(new Constructor(), Class.prototype);\n};\n\nvar _cache = typeof Map === \"function\" && new Map();\n\nfunction _wrapNativeSuper(Class) {\n if (typeof Class !== \"function\") {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n if (typeof _cache !== \"undefined\") {\n if (_cache.has(Class)) return _cache.get(Class);\n\n _cache.set(Class, Wrapper);\n }\n\n function Wrapper() {}\n\n Wrapper.prototype = Object.create(Class.prototype, {\n constructor: {\n value: Wrapper,\n enumerable: false,\n writeable: true,\n configurable: true\n }\n });\n return _sPO(Wrapper, _sPO(function Super() {\n return _construct(Class, arguments, _gPO(this).constructor);\n }, Class));\n}\n\nfunction _instanceof(left, right) {\n if (right != null && typeof Symbol !== \"undefined\" && right[Symbol.hasInstance]) {\n return right[Symbol.hasInstance](left);\n } else {\n return left instanceof right;\n }\n}\n\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : {\n default: obj\n };\n}\n\nfunction _interopRequireWildcard(obj) {\n if (obj && obj.__esModule) {\n return obj;\n } else {\n var newObj = {};\n\n if (obj != null) {\n for (var key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};\n\n if (desc.get || desc.set) {\n Object.defineProperty(newObj, key, desc);\n } else {\n newObj[key] = obj[key];\n }\n }\n }\n }\n\n newObj.default = obj;\n return newObj;\n }\n}\n\nfunction _newArrowCheck(innerThis, boundThis) {\n if (innerThis !== boundThis) {\n throw new TypeError(\"Cannot instantiate an arrow function\");\n }\n}\n\nfunction _objectDestructuringEmpty(obj) {\n if (obj == null) throw new TypeError(\"Cannot destructure undefined\");\n}\n\nfunction _objectWithoutProperties(source, excluded) {\n if (source == null) return {};\n var target = {};\n var sourceKeys = Object.keys(source);\n var key, i;\n\n for (i = 0; i < sourceKeys.length; i++) {\n key = sourceKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n target[key] = source[key];\n }\n\n if (Object.getOwnPropertySymbols) {\n var sourceSymbolKeys = Object.getOwnPropertySymbols(source);\n\n for (i = 0; i < sourceSymbolKeys.length; i++) {\n key = sourceSymbolKeys[i];\n if (excluded.indexOf(key) >= 0) continue;\n if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;\n target[key] = source[key];\n }\n }\n\n return target;\n}\n\nfunction _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (typeof call === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nfunction _set(object, property, value, receiver) {\n var desc = Object.getOwnPropertyDescriptor(object, property);\n\n if (desc === undefined) {\n var parent = Object.getPrototypeOf(object);\n\n if (parent !== null) {\n _set(parent, property, value, receiver);\n }\n } else if (\"value\" in desc && desc.writable) {\n desc.value = value;\n } else {\n var setter = desc.set;\n\n if (setter !== undefined) {\n setter.call(receiver, value);\n }\n }\n\n return value;\n}\n\nfunction _sliceIterator(arr, i) {\n var _arr = [];\n var _n = true;\n var _d = false;\n var _e = undefined;\n\n try {\n for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {\n _arr.push(_s.value);\n\n if (i && _arr.length === i) break;\n }\n } catch (err) {\n _d = true;\n _e = err;\n } finally {\n try {\n if (!_n && _i[\"return\"] != null) _i[\"return\"]();\n } finally {\n if (_d) throw _e;\n }\n }\n\n return _arr;\n}\n\nfunction _slicedToArray(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n return _sliceIterator(arr, i);\n } else {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n }\n}\n\nfunction _slicedToArrayLoose(arr, i) {\n if (Array.isArray(arr)) {\n return arr;\n } else if (Symbol.iterator in Object(arr)) {\n var _arr = [];\n\n for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {\n _arr.push(_step.value);\n\n if (i && _arr.length === i) break;\n }\n\n return _arr;\n } else {\n throw new TypeError(\"Invalid attempt to destructure non-iterable instance\");\n }\n}\n\nfunction _taggedTemplateLiteral(strings, raw) {\n return Object.freeze(Object.defineProperties(strings, {\n raw: {\n value: Object.freeze(raw)\n }\n }));\n}\n\nfunction _taggedTemplateLiteralLoose(strings, raw) {\n strings.raw = raw;\n return strings;\n}\n\nfunction _temporalRef(val, name) {\n if (val === _temporalUndefined) {\n throw new ReferenceError(name + \" is not defined - temporal dead zone\");\n } else {\n return val;\n }\n}\n\nfunction _readOnlyError(name) {\n throw new Error(\"\\\"\" + name + \"\\\" is read-only\");\n}\n\nfunction _classNameTDZError(name) {\n throw new Error(\"Class \\\"\" + name + \"\\\" cannot be referenced in computed property keys.\");\n}\n\nvar _temporalUndefined = {};\n\nfunction _toArray(arr) {\n return Array.isArray(arr) ? arr : Array.from(arr);\n}\n\nfunction _toConsumableArray(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];\n\n return arr2;\n } else {\n return Array.from(arr);\n }\n}\n\nfunction _skipFirstGeneratorNext(fn) {\n return function () {\n var it = fn.apply(this, arguments);\n it.next();\n return it;\n };\n}\n\nfunction _toPropertyKey(key) {\n if (typeof key === \"symbol\") {\n return key;\n } else {\n return String(key);\n }\n}\n\nfunction _initializerWarningHelper(descriptor, context) {\n throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and set to use loose mode. ' + 'To use proposal-class-properties in spec mode with decorators, wait for ' + 'the next major version of decorators in stage 2.');\n}\n\nfunction _initializerDefineProperty(target, property, descriptor, context) {\n if (!descriptor) return;\n Object.defineProperty(target, property, {\n enumerable: descriptor.enumerable,\n configurable: descriptor.configurable,\n writable: descriptor.writable,\n value: descriptor.initializer ? descriptor.initializer.call(context) : void 0\n });\n}\n\nfunction _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {\n var desc = {};\n Object['ke' + 'ys'](descriptor).forEach(function (key) {\n desc[key] = descriptor[key];\n });\n desc.enumerable = !!desc.enumerable;\n desc.configurable = !!desc.configurable;\n\n if ('value' in desc || desc.initializer) {\n desc.writable = true;\n }\n\n desc = decorators.slice().reverse().reduce(function (desc, decorator) {\n return decorator(target, property, desc) || desc;\n }, desc);\n\n if (context && desc.initializer !== void 0) {\n desc.value = desc.initializer ? desc.initializer.call(context) : void 0;\n desc.initializer = undefined;\n }\n\n if (desc.initializer === void 0) {\n Object['define' + 'Property'](target, property, desc);\n desc = null;\n }\n\n return desc;\n}","// USAGE\n// mq-layout(mq=\"lg\")\n// p I’m lg\nimport { selectBreakpoints } from './helpers'\nconst component = {\n props: {\n mq: {\n required: true,\n type: String,\n }\n },\n computed: {\n plusModifier() { return this.mq.slice(-1) === '+' },\n activeBreakpoints() {\n const breakpoints = Object.keys(this.$mqAvailableBreakpoints)\n const mq = this.plusModifier ? this.mq.slice(0, -1) : this.mq\n return this.plusModifier\n ? selectBreakpoints(breakpoints, mq)\n : [this.mq]\n }\n },\n render(h, props) {\n const shouldRenderChildren = this.activeBreakpoints.includes(this.$mq)\n return shouldRenderChildren ? h('div', this.$slots.default) : h()\n },\n}\n\nexport default component\n","import { convertBreakpointsToMediaQueries, transformValuesFromBreakpoints } from './helpers.js'\nimport MqLayout from './component.js'\n\nconst DEFAULT_BREAKPOINT = {\n sm: 450,\n md: 1250,\n lg: Infinity,\n}\n\nconst install = function (Vue, { breakpoints = DEFAULT_BREAKPOINT } = {}) {\n // Init reactive component\n const reactorComponent = new Vue({\n data: () => ({\n currentBreakpoint: null,\n })\n })\n\n const mediaQueries = convertBreakpointsToMediaQueries(breakpoints)\n Object.keys(mediaQueries).map((key) => {\n const mediaQuery = mediaQueries[key]\n const enter = () => { reactorComponent.currentBreakpoint = key }\n _subscribeToMediaQuery(mediaQuery, enter)\n })\n\n function _subscribeToMediaQuery(mediaQuery, enter) {\n const mql = window.matchMedia(mediaQuery)\n const cb = ({ matches }) => {\n if (matches) enter()\n }\n mql.addListener(cb) //subscribing\n cb(mql) //initial trigger\n }\n\n Vue.filter('mq', (currentBreakpoint, values) => {\n return transformValuesFromBreakpoints(Object.keys(breakpoints), values, currentBreakpoint)\n })\n Vue.mixin({\n computed: {\n $mq() {\n return reactorComponent.currentBreakpoint\n },\n }\n })\n Vue.prototype.$mqAvailableBreakpoints = breakpoints\n Vue.component('MqLayout', MqLayout)\n}\n\nexport default { install }\n"],"names":["str","replace","match","toLowerCase","obj2mq","obj","mq","features","Object","keys","forEach","feature","index","value","test","isDimension","camel2hyphen","length","query","Array","q","convertBreakpointsToMediaQueries","breakpoints","values","map","key","breakpointValues","arr","isArray","i","arr2","from","slice","reduce","sum","options","assign","mediaQuery","json2mq","defineProperty","enumerable","configurable","writable","component","String","this","$mqAvailableBreakpoints","plusModifier","currentBreakpoint","findIndex","b","selectBreakpoints","h","props","activeBreakpoints","includes","$mq","$slots","default","DEFAULT_BREAKPOINT","Infinity","Vue","reactorComponent","mediaQueries","enter","mql","window","matchMedia","cb","matches","addListener","filter","findClosestValue","undefined","newBreakpoint","transformValuesFromBreakpoints","mixin","prototype","MqLayout"],"mappings":"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"} \ No newline at end of file diff --git a/package.json b/package.json index 32a92d1..a243198 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-mq", - "version": "0.1.2", + "version": "0.1.3", "description": "Handle media queries easily & build responsive design with Vue", "main": "dist/vue-mq.js", "module": "dist/vue-mq.es.js",