UNPKG

6.4 kBJavaScriptView Raw
1"use strict";function elementEvent(n,t,e,o){void 0===o&&(o={});var i=t+".ph."+e;n.dispatchEvent(new CustomEvent(i,{detail:o}))}function pageEvent(n,t,e){void 0===e&&(e={});var o=t+"."+n;window.dispatchEvent(new CustomEvent(o,{detail:e})),document.dispatchEvent(new CustomEvent(o,{detail:e}))}function winDocEvent(n,t,e){void 0===e&&(e={});var o=n+".ph."+t;window.dispatchEvent(new CustomEvent(o,{detail:e})),document.dispatchEvent(new CustomEvent(o,{detail:e}))}var dispatch={elementEvent:elementEvent,pageEvent:pageEvent,winDocEvent:winDocEvent};function onError(){"undefined"!=typeof window&&window.addEventListener("error",function(n){console.error("-- Phonon Error --"),console.error("An error has occured! You can pen an issue here: https://github.com/quark-dev/Phonon-Framework/issues"),console.error(JSON.stringify(n))})}var availableEvents=["mousedown","mousemove","mouseup"],touchScreen=!1;"undefined"!=typeof window&&(("ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch)&&(touchScreen=!0,availableEvents=["touchstart","touchmove","touchend","touchcancel"]),window.navigator.pointerEnabled?availableEvents=["pointerdown","pointermove","pointerup","pointercancel"]:window.navigator.msPointerEnabled&&(availableEvents=["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerCancel"]));var transitions=[{name:"transition",start:"transitionstart",end:"transitionend"},{name:"MozTransition",start:"transitionstart",end:"transitionend"},{name:"msTransition",start:"msTransitionStart",end:"msTransitionEnd"},{name:"WebkitTransition",start:"webkitTransitionStart",end:"webkitTransitionEnd"}],animations=[{name:"animation",start:"animationstart",end:"animationend"},{name:"MozAnimation",start:"animationstart",end:"animationend"},{name:"msAnimation",start:"msAnimationStart",end:"msAnimationEnd"},{name:"WebkitAnimation",start:"webkitAnimationStart",end:"webkitAnimationEnd"}],el=window.document.createElement("div"),transition=transitions.find(function(n){return void 0!==el.style[n.name]}),animation=animations.find(function(n){return void 0!==el.style[n.name]}),transitionStart=transition?transition.start:"transitionstart",transitionEnd=transition?transition.end:"transitionend",animationStart=animation?animation.start:"animationstart",animationEnd=animation?animation.end:"animationend",events={TOUCH_SCREEN:touchScreen,NETWORK_ONLINE:"online",NETWORK_OFFLINE:"offline",NETWORK_RECONNECTING:"reconnecting",NETWORK_RECONNECTING_SUCCESS:"reconnect.success",NETWORK_RECONNECTING_FAILURE:"reconnect.failure",SHOW:"show",SHOWN:"shown",HIDE:"hide",HIDDEN:"hidden",HASH:"hash",START:availableEvents[0],MOVE:availableEvents[1],END:availableEvents[2],CANCEL:void 0===availableEvents[3]?null:availableEvents[3],CLICK:"click",TRANSITION_START:transitionStart,TRANSITION_END:transitionEnd,ANIMATION_START:animationStart,ANIMATION_END:animationEnd,ITEM_SELECTED:"itemSelected"};function closest(n,t){Element.prototype.matches;var e=n;do{if(e.matches(t))return e;e=e.parentElement||e.parentNode}while(null!==e&&1===e.nodeType);return null}function attrConfig(n){if(!n)return null;var t=n.getAttribute("data-config");if(!t)return null;try{return JSON.parse(t)}catch(n){}var e=(t.match(/(\w+)\s*:\s*(["'])?/gim)||[]).map(function(n){return n.replace(/(\w+)\s*:\s*(["'])?/gim,"$1")}),i=t.match(/[^:]+(?=,|$)/gim)||[],a={};return e.forEach(function(n,t){var e=i[t].replace(/ /g,"").replace(/\'|"/g,""),o="";o="true"===e||"false"===e?"true"===e:isNaN(e)?e:parseFloat(e),a[n]=o}),a}function removeClasses(e,n,o){void 0===o&&(o=null),n.forEach(function(n){var t=o?o+"-"+n:n;e.classList.contains(t)&&e.classList.remove(t)})}function isElement(n){return 1===n.nodeType&&"string"==typeof n.className}var selector={attrConfig:attrConfig,removeClasses:removeClasses,closest:closest,isElement:isElement},components={};function getName(n){return"string"==typeof n?n.toLowerCase():n.constructor.name.toLowerCase()}function addComponent(n){var t=getName(n);components[t]||(components[t]=[]),components[t].push(n)}function removeComponent(n,t){var e=getName(n),o=(components[e]||[]).findIndex(function(n){return n.getElement()===t});-1!==o&&(components[e][o].destroy(),components[e].splice(o,1))}function getComponent(n,t){var e=getName(n),o=t.element;if(!o)return null;var i="string"==typeof o?document.querySelector(o):o,a=(components[e]||[]).find(function(n){return n.getElement()===i});return a?(t&&a.setProps(t),a):null}var stack={addComponent:addComponent,getComponent:getComponent,removeComponent:removeComponent},mutatorSubscribers=[];function subscribe(t){mutatorSubscribers.push(t),document.body&&Array.from(document.body.querySelectorAll("."+t.componentClass)||[]).filter(function(n){return null===n.getAttribute("data-no-boot")}).forEach(function(n){dispatchChangeEvent(t,"onAdded",n,stack.addComponent)})}function dispatchChangeEvent(n,t){for(var e=[],o=2;o<arguments.length;o++)e[o-2]=arguments[o];var i=n[t];i&&i.apply(i,e)}function nodeFn(n,t){if(void 0===t&&(t=!0),null===n.getAttribute("data-no-boot")){var e=n.className.split(" "),o=mutatorSubscribers.find(function(n){return-1<e.indexOf(n.componentClass)});if(o){var i=t?"onAdded":"onRemoved",a=t?[n,stack.addComponent]:[n,stack.removeComponent];dispatchChangeEvent.apply(void 0,[o,i].concat(a))}}}function apply(n,t){void 0===t&&(t=!0),nodeFn(n,t);for(var e=n.firstElementChild;e;){var o=e.nextElementSibling;isElement(e)&&apply(e,t),e=o}}function getElements(n){return Array.from(n).filter(function(n){return isElement(n)})}function observe(){new MutationObserver(function(n){return n.forEach(function(n){if("attributes"!==n.type){var t=n.addedNodes,e=n.removedNodes;getElements(t).forEach(function(n){return apply(n,!0)}),getElements(e).forEach(function(n){return apply(n,!1)})}})}).observe(document,{childList:!0,subtree:!0,characterData:!0,attributes:!0})}function boot(){if("MutationObserver"in window)if(document.body)observe();else{var n=new MutationObserver(function(){document.body&&(n.disconnect(),observe())});n.observe(document,{childList:!0,subtree:!0})}}boot();var observer={subscribe:subscribe,getComponent:stack.getComponent},sleep=function(t){return new Promise(function(n){setTimeout(n,t)})};onError();var utils={sleep:sleep,Event:events,Dispatch:dispatch,Selector:selector,Observer:observer};module.exports=utils;
2//# sourceMappingURL=/home/qathom/Workspaces/Web/phonon/dist/js/util.min.js.map
\No newline at end of file