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