forked from rikschennink/conditioner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditioner-core.min.js
2 lines (2 loc) · 4.16 KB
/
conditioner-core.min.js
1
2
/* conditioner-core 2.3.1 */
!function(n,t){if("function"==typeof define&&define.amd)define(["exports"],t);else if("undefined"!=typeof exports)t(exports);else{var e={exports:{}};t(e.exports),n.conditioner=e.exports}}(this,function(n){"use strict";function t(n){if(Array.isArray(n)){for(var t=0,e=Array(n.length);t<n.length;t++)e[t]=n[t];return e}return Array.from(n)}Object.defineProperty(n,"__esModule",{value:!0});var e=function(){function n(n,t){var e=[],r=!0,o=!1,u=void 0;try{for(var i,c=n[Symbol.iterator]();!(r=(i=c.next()).done)&&(e.push(i.value),!t||e.length!==t);r=!0);}catch(n){o=!0,u=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw u}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return n(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r=function(n){var e=x("moduleGetName",n),r=A("moduleSetName",e),o={destruct:null,mounting:!1},u={alias:e,name:r,element:n,mounted:!1,unmount:function(){o.destruct&&u.mounted&&(g("moduleWillUnmount",u),o.destruct(),u.mounted=!1,g("moduleDidUnmount",u),u.onunmount.apply(n))},mount:function(){if(!u.mounted&&!o.mounting)return g("moduleWillMount",u),x("moduleImport",r).catch(function(t){throw o.mounting=!1,g("moduleDidCatch",t,u),u.onmounterror.apply(n,[t,u]),new Error("Conditioner: "+t)}).then(function(e){o.destruct=x("moduleGetDestructor",x("moduleGetConstructor",e).apply(void 0,t(x("moduleSetConstructorArguments",r,n)))),u.mounted=!0,o.mounting=!1,g("moduleDidMount",u),u.onmount.apply(n,[u])}),u},onmounterror:function(){},onmount:function(){},onunmount:function(){},destroy:function(){}};return u},o=/(was)? ?(not)? ?@([a-z]+) ?(.*)?/,u=/(?:was )?(?:not )?@[a-z]+ ?.*?(?:(?= and (?:was )?(?:not )?@[a-z])|$)/g,i=function(n){return void 0===n||"true"===n||"false"!==n&&n},c=function(n){var t=n.match(o),r=e(t,5),u=r[1],c=r[2],a=r[3],f=r[4];return[a,i(f),"not"===c,"was"===u]},a=function(n){return n.match(u).map(c)},f=function(n,t,e){return n.invert=t,n.retain=e,n.matched=!1,n},m=function(n,t,e){return y("monitor").find(function(n){return n.name===t}).create(e,n)},d=function(n){return n.reduce(function(n,t){if(!n)return!1;var e=t.invert?!t.matches:t.matches;return e&&(t.matched=!0),!(!t.retain||!t.matched)||e},!0)},l=n.monitor=function(n,e){var r={matches:!1,active:!1,onchange:function(){},start:function(){r.active||(r.active=!0,o.forEach(function(n){return n.forEach(function(n){return n.addListener(u)})}),u())},stop:function(){r.active=!1,o.forEach(function(n){return n.forEach(function(n){n.removeListener&&n.removeListener(u)})})},destroy:function(){r.stop(),o.length=0}},o=n.split(" or ").map(function(n){return a(n).map(function(n){return f.apply(void 0,[m.apply(void 0,[e].concat(t(n)))].concat(t(n.splice(2))))})}),u=function(){var n=o.reduce(function(n,t){return!!n||d(t)},!1);r.matches=n,r.onchange(n)};return r},s=function(n,t){var e=l(n,t.element);return e.onchange=function(n){return n?t.mount():t.unmount()},e.start(),t},p=function(n){var t=r(n),e=x("moduleGetContext",n);return e?s(e,t):t.mount()},h=(n.hydrate=function(n){return[].concat(t(x("moduleSelector",n))).map(p)},[]),v=function(n,t){return n.indexOf(t)>-1},y=function(n){return h.filter(function(t){return v(Object.keys(t),n)}).map(function(t){return t[n]})},g=function(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];return y(n).forEach(function(n){return n.apply(void 0,e)})},A=function(n){for(var e=arguments.length,r=Array(e>1?e-1:0),o=1;o<e;o++)r[o-1]=arguments[o];return y(n).reduce(function(n,e){return[e.apply(void 0,t(n))]},r).shift()},x=function(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;r<t;r++)e[r-1]=arguments[r];return y(n).pop().apply(void 0,e)};(n.addPlugin=function(n){return h.push(n)})({moduleSelector:function(n){return n.querySelectorAll("[data-module]")},moduleGetContext:function(n){return n.dataset.context},moduleImport:function(n){return new Promise(function(t,e){if(self[n])return t(self[n])})},moduleGetConstructor:function(n){return n},moduleGetDestructor:function(n){return n},moduleSetConstructorArguments:function(n,t){return[t]},moduleGetName:function(n){return n.dataset.module},monitor:{name:"media",create:function(n){return self.matchMedia(n)}}})});