-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbetter-dom.min.js
8 lines (8 loc) · 16.5 KB
/
better-dom.min.js
1
2
3
4
5
6
7
8
/**
* better-dom: Live extension playground
* @version 4.1.0 Tue, 24 Mar 2020 09:55:50 GMT
* @link https://github.com/chemerisuk/better-dom
* @copyright 2020 Maksim Chemerisuk
* @license MIT
*/
!function(){"use strict";function t(t){return t.ownerDocument.defaultView.getComputedStyle(t)}function e(t){if(t&&t.nodeType===E)return t.ownerDocument.getElementsByTagName("head")[0].appendChild(t)}function n(t,e,n){void 0===n&&(n="$Element");var r="http://chemerisuk.github.io/better-dom/"+n+".html#"+t,i="invalid call `"+n+("DOM"===n?".":"#")+t+"(";i+=O.call(e,String).join(", ")+")`. ",this.message=i+"Check "+r+" to verify the arguments"}function r(t,e){n.call(this,t,e,"DOM")}function i(t,e){n.call(this,t,e,"$Document")}function o(t){t&&(this[0]=t,t.__40100__=this)}function s(t){if(!(this instanceof s))return t?t.__40100__||new s(t):new s;o.call(this,t);var n=t.createElement("style");n.innerHTML=P,e(n),t[N]=n.sheet||n.styleSheet}function a(t){return this instanceof a?void o.call(this,t):t?t.__40100__||new a(t):new a}function c(t){return function(e){var r=this[0];if(!r||"string"!=typeof e)throw new n("create"+t,arguments);var i=t?[]:null,o=!i&&q.exec(e);if(o)return new a(r.createElement(o[1]));H.innerHTML=e.trim();for(var s;s=H.firstElementChild;){if(H.removeChild(s),r!==g&&(s=r.adoptNode(s)),!i){i=new a(s);break}i.push(new a(s))}return i||new a}}function f(t,e){var n=a(e),r=t.constructor;Object.keys(t).forEach(function(e){var i=t[e];i!==r&&(n[e]=i)}),r&&r.call(n)}function u(t,e){return function(r){if(r&&typeof r!==e)throw new n(t,arguments);var i=this[0],o=z(r),s=i?i.children:[];return"number"==typeof r?(r<0&&(r=s.length+r),a(s[r])):o?D.call(s,o).map(a):O.call(s,a)}}function p(t,e,n){return function(){var r=this,i=this[0];if(!i||e&&!i.parentNode)return this;for(var o=t?"":i.ownerDocument.createDocumentFragment(),c=arguments.length,f=new Array(c),u=0;u<c;u++)f[u]=arguments[u];return f.forEach(function(t){"function"==typeof t&&(t=t(r)),"string"==typeof t?"string"==typeof o?o+=t.trim():t=s(i.ownerDocument).createAll(t):t instanceof a&&(t=[t]),k(t)&&("string"==typeof o&&(t=s(i.ownerDocument).createAll(o).concat(t),o=i.ownerDocument.createDocumentFragment()),t.forEach(function(t){o.appendChild(t[0])}))}),"string"==typeof o?i.insertAdjacentHTML(t,o):n(i,o),this}}function l(t,e,r){return function(i){if(i&&"string"!=typeof i)throw new n(t,arguments);var o=this[0],s=r?[]:null;if(o){var c=z(i);!o||c&&"closest"===t||(o=o[e]);for(var f=o;f;f=f[e])if(!c||c(f)){if(!s){s=a(f);break}s.push(a(f))}}return s||new a}}function h(t,e){this.node=t,this.style=t.style,this.eventType=e?rt:nt,this.animationName=e}function y(e,r){return function(i,o){var s=this;if("string"!=typeof i&&(o=i,i=null),o&&"function"!=typeof o)throw new n(e,arguments);var a=this[0];if(!a)return this;var c=t(a);if(a&&c.width){var f=function(){a.style.visibility=r?"hidden":"inherit","function"==typeof o&&o(s)};a.ownerDocument.documentElement.contains(a)&&(i||0!==parseFloat(c["transition-duration"]))?i&&0===parseFloat(c["animation-duration"])?j(f):(a.style.visibility="visible",new it(a,i).start(f,r?"normal":"reverse")):j(f)}return this.set("aria-hidden",String(r))}}function v(t,e){return function(r){if("string"!=typeof r)throw new n(t,arguments);var i=this[0];if(!i)return e?[]:new o;var c;if(this instanceof s||this instanceof a){var f=ot.exec(r);if(f)c=f[1]?i.getElementsByTagName(r):i.getElementsByClassName(f[2]),c&&!e&&(c=c[0]);else if(this instanceof a){var u,p=i.getAttribute("id");p?u=p.replace(st,"\\$&"):(u="___40100__",i.setAttribute("id",u)),u="[id='"+u+"'] ",r=u+r.split(",").join(","+u),c=i["querySelector"+e](r),p||i.removeAttribute("id")}else c=i["querySelector"+e](r)}else c=i["querySelector"+e](r);return e?O.call(c,a):a(c)}}function m(t,e,n,r){this.context=t,this.node=e,this.options=n,this.args=r,n.selector&&(this.matcher=z(n.selector,e))}var d=window,g=document,w=g.documentElement,b=0,E=g.ELEMENT_NODE,A=g.DOCUMENT_NODE,C=["Webkit","O","Moz","ms"],T="v__40100__",N="__40100__sheet",S=d.WebKitAnimationEvent?"-webkit-":"",x=Array.prototype,L=x.every,_=x.forEach,D=x.filter,O=x.map,k=(x.slice,Array.isArray),M=Object.keys,j=d.requestAnimationFrame;n.prototype=new TypeError,r.prototype=new TypeError,i.prototype=new TypeError,o.prototype={toString:function(){return""},valueOf:function(){return b}};var P="@"+S+"keyframes "+T+" {from {opacity:.99} to {opacity:1}}",B=new o;s.prototype=B,B.valueOf=function(){var t=this[0];return t?A:b},B.toString=function(){return"#document"};var I=new o;a.prototype=I,I.valueOf=function(){var t=this[0];return t?E:b},I.toString=function(){var t=this[0];return t?"<"+t.tagName.toLowerCase()+">":"#unknown"};var F=new s(d.document),R=d.DOM;F.constructor=function(t){var e=t&&t.nodeType;return e===E?a(t):e===A?s(t):new o(t)},F.noConflict=function(){return d.DOM===F&&(d.DOM=R),F},d.DOM=F;var q=/^<([a-zA-Z-]+)\/?>$/,H=g.createElement("body");s.prototype.create=c(""),s.prototype.createAll=c("All");var U=/^(\w*)(?:#([\w\-]+))?(?:\[([\w\-\=]+)\])?(?:\.([\w\-]+))?$/,$=C.concat(null).map(function(t){return(t?t.toLowerCase()+"M":"m")+"atchesSelector"}).reduceRight(function(t,e){return t||e in w&&e},null),z=function(t,e){if("string"!=typeof t)return null;var n=U.exec(t);return n&&(n[1]&&(n[1]=n[1].toLowerCase()),n[3]&&(n[3]=n[3].split("=")),n[4]&&(n[4]=" "+n[4]+" ")),function(r){var i,o;for(n||$||(o=(e||r.ownerDocument).querySelectorAll(t));r&&1===r.nodeType;r=r.parentNode){if(n)i=(!n[1]||r.nodeName.toLowerCase()===n[1])&&(!n[2]||r.id===n[2])&&(!n[3]||(n[3][1]?r.getAttribute(n[3][0])===n[3][1]:r.hasAttribute(n[3][0])))&&(!n[4]||(" "+r.className+" ").indexOf(n[4])>=0);else if($)i=r[$](t);else for(var s=0,a=o.length;s<a;++s){var a=o[s];if(a===r)return a}if(i||!e||r===e)break}return i&&r}},W=[],X=S?"webkitAnimationStart":"animationstart",K=[S+"animation-name:"+T+" !important",S+"animation-duration:1ms !important"].join(";");s.prototype.extend=function(t,e){var n=this[0];if(!n)return this;if(1===arguments.length&&"object"==typeof t)return M(t).forEach(function(e){s.prototype[e]=t[e]}),this;if("*"===t)return M(e).forEach(function(t){a.prototype[t]=e[t]}),this;if("function"==typeof e&&(e={constructor:e}),!e||"object"!=typeof e)throw new i("extend",arguments);var r=z(t);W.push([r,e]),n.addEventListener(X,function(t){var n=t.target;t.animationName===T&&r(n)&&(t.stopPropagation(),n.style.setProperty(S+"animation-name","none","important"),f(e,n))},!0),_.call(n.querySelectorAll(t),function(t){t.style.setProperty(S+"animation-name","none","important"),d.setTimeout(function(){f(e,t)},0)}),this.importStyles(t,K)},s.prototype.mock=function(t){if(!t)return new a;var e=this.create(t),n=function r(t){W.forEach(function(e){var n=e[0],r=e[1];n(t)&&f(r,t)}),_.call(t.children,r)};return W.length&&n(e[0]),e},s.prototype.importScripts=function(){for(var t=this,n=arguments,r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];var a=function c(){var r=t[0];if(r){var s,a=o.shift(),f=typeof a;if("string"===f)s=r.createElement("script"),s.src=a,s.onload=c,s.async=!0,e(s);else if("function"===f)a();else if(a)throw new i("importScripts",n)}};a()},s.prototype.importStyles=function(t,e){var n=this[0];if(n){if(e||"string"!=typeof t||(e=t,t="@media screen"),"string"!=typeof t||"string"!=typeof e)throw new i("importStyles",arguments);var r=n[N],o=r.cssRules.length;t.split(",").forEach(function(t){try{o=r.insertRule(t+"{"+e+"}",o)}catch(n){}})}},a.prototype.child=u("child","number"),a.prototype.children=u("children","string");var V=/[\n\t\r]/g,Y=function(t){return(" "+t.className+" ").replace(V," ")};a.prototype.hasClass=function(t){if("string"!=typeof t)throw new n("hasClass",arguments);var e=this[0];return!!e&&(e.classList?e.classList.contains(t):Y(e).indexOf(" "+t+" ")>=0)},a.prototype.addClass=function(){for(var t=this,e=arguments,r=arguments.length,i=new Array(r),o=0;o<r;o++)i[o]=arguments[o];var s=this[0];return s&&i.forEach(function(r){if("string"!=typeof r)throw new n("addClass",e);s.classList?s.classList.add(r):t.hasClass(r)||(t[0].className+=" "+r)}),this},a.prototype.removeClass=function(){for(var t=arguments,e=arguments.length,r=new Array(e),i=0;i<e;i++)r[i]=arguments[i];var o=this[0];return o&&r.forEach(function(e){if("string"!=typeof e)throw new n("removeClass",t);o.classList?o.classList.remove(e):o.className=Y(o).replace(" "+e+" "," ").trim()}),this},a.prototype.toggleClass=function(t,e){if("string"!=typeof t)throw new n("toggleClass",arguments);"boolean"!=typeof e&&(e=!this.hasClass(t));var r=this[0];return r&&(e?this.addClass(t):this.removeClass(t)),e};var Z=/\-./g,G={get:{},set:{},find:function(t,e){var n=t.replace(Z,function(t){return t[1].toUpperCase()});return n in e||(n=C.map(function(t){return t+n[0].toUpperCase()+n.slice(1)}).filter(function(t){return t in e})[0]),this.get[t]=this.set[t]=n}},J=["Top","Right","Bottom","Left"],Q={font:["fontStyle","fontSize","/","lineHeight","fontFamily"],padding:J.map(function(t){return"padding"+t}),margin:J.map(function(t){return"margin"+t}),"border-width":J.map(function(t){return"border"+t+"Width"}),"border-style":J.map(function(t){return"border"+t+"Style"})};G.get["float"]=G.set["float"]="cssFloat","fill-opacity font-weight line-height opacity orphans widows z-index zoom".split(" ").forEach(function(t){var e=t.replace(Z,function(t){return t[1].toUpperCase()});G.get[t]=e,G.set[t]=function(t,n){n[e]=t.toString()}}),M(Q).forEach(function(t){var e=Q[t];G.get[t]=function(t){var n=[],r=function(e,r){return n.push("/"===e?e:t[e]),!n[r]};return e.some(r)?"":n.join(" ")},G.set[t]=function(n,r){n&&"cssText"in r?r.cssText+=";"+t+":"+n:e.forEach(function(t){return r[t]="number"==typeof n?n+"px":n.toString()})}});var tt=G;a.prototype.css=function(e,r){var i=this,o=arguments.length,s=this[0];if(s){var a,c=s.style;if(1===o&&("string"==typeof e||k(e))){var f=function(e){var n=tt.get[e]||tt.find(e,c),r="function"==typeof n?n(c):c[n];return r||(a||(a=t(s)),r="function"==typeof n?n(a):a[n]),r};return"string"==typeof e?f(e):e.map(f).reduce(function(t,n,r){return t[e[r]]=n,t},{})}if(2===o&&"string"==typeof e){var u=tt.set[e]||tt.find(e,c);"function"==typeof r&&(r=r(this)),null==r&&(r=""),"function"==typeof u?u(r,c):c[u]="number"==typeof r?r+"px":r.toString()}else{if(1!==o||!e||"object"!=typeof e)throw new n("css",arguments);M(e).forEach(function(t){i.css(t,e[t])})}return this}return 1===o&&k(e)?{}:1!==o||"string"!=typeof e?this:void 0},a.prototype.after=p("afterend",!0,function(t,e){t.parentNode.insertBefore(e,t.nextSibling)}),a.prototype.before=p("beforebegin",!0,function(t,e){t.parentNode.insertBefore(e,t)}),a.prototype.prepend=p("afterbegin",!1,function(t,e){t.insertBefore(e,t.firstChild)}),a.prototype.append=p("beforeend",!1,function(t,e){t.appendChild(e)}),a.prototype.replace=p("",!0,function(t,e){t.parentNode.replaceChild(e,t)}),a.prototype.remove=p("",!0,function(t){t.parentNode.removeChild(t)});var et={":focus":function(t){return t===t.ownerDocument.activeElement}};a.prototype.matches=function(t){if(!t||"string"!=typeof t)throw new n("matches",arguments);var e=et[t]||z(t);return!!e(this[0])},a.prototype.offset=function(){var t=this[0],e={top:0,left:0,right:0,bottom:0,width:0,height:0};if(t){var n=(t.ownerDocument||t).documentElement,r=n.clientTop,i=n.clientLeft,o=d.pageYOffset||n.scrollTop,s=d.pageXOffset||n.scrollLeft,a=t.getBoundingClientRect();e.top=a.top+o-r,e.left=a.left+s-i,e.right=a.right+s-i,e.bottom=a.bottom+o-r,e.width=a.right-a.left,e.height=a.bottom-a.top}return e},a.prototype.next=l("next","nextElementSibling"),a.prototype.prev=l("prev","previousElementSibling"),a.prototype.nextAll=l("nextAll","nextElementSibling",!0),a.prototype.prevAll=l("prevAll","previousElementSibling",!0),a.prototype.closest=l("closest","parentNode"),a.prototype.value=function(t){var e=this[0];if(!e)return t?this:void 0;var n=e.tagName;if(void 0===t)return"SELECT"===n?~e.selectedIndex?e.options[e.selectedIndex].value:"":"OPTION"===n?e.hasAttribute("value")?e.value:e.text:"INPUT"===n||"TEXTAREA"===n?e.value:e.textContent;switch(n){case"INPUT":case"OPTION":case"TEXTAREA":"function"==typeof t&&(t=t(e.value)),e.value=t;break;case"SELECT":"function"==typeof t&&(t=t(e.value)),L.call(e.options,function(e){return!(e.selected=e.value===t)})&&(e.selectedIndex=-1);break;default:"function"==typeof t&&(t=t(e.textContent)),e.textContent=t}return this},a.prototype.empty=function(){return this.value("")};var nt=S?"webkitTransitionEnd":"transitionend",rt=S?"webkitAnimationEnd":"animationend";h.prototype={handleEvent:function(t){this.animationName&&t.animationName!==this.animationName||(this.animationName&&(this.style.animationName="",this.style.animationDirection=""),this.node.removeEventListener(this.eventType,this,!0),"function"==typeof this.callback&&this.callback())},start:function(t,e){this.callback=t,this.animationName&&(this.style.animationName=this.animationName,this.style.animationDirection=e),this.node.addEventListener(this.eventType,this,!0)}};var it=h;a.prototype.show=y("show",!1),a.prototype.hide=y("hide",!0),o.prototype.clone=function(t){if("boolean"!=typeof t)throw new n("clone",arguments);var e=this[0];if(e){var r=e.cloneNode(t);if(this instanceof a)return new a(r);if(this instanceof s)return new s(r)}return new o},o.prototype.contains=function(t){var e=this[0];if(!e)return!1;if(t instanceof a){var r=t[0];return r===e||(e.contains?e.contains(r):16&e.compareDocumentPosition(r))}throw new n("contains",arguments)};var ot=/^(?:(\w+)|\.([\w\-]+))$/,st=/'|\\/g;o.prototype.find=v("find",""),o.prototype.findAll=v("findAll","All");var at={};"onfocusin"in w?(at.focus=function(t){t._type="focusin"},at.blur=function(t){t._type="focusout"}):at.focus=at.blur=function(t){t.options.capture=!0},g.createElement("input").validity&&(at.invalid=function(t){t.options.capture=!0});var ct=at,ft=!1;try{var ut=Object.defineProperty({},"passive",{get:function(){ft=!0}});d.addEventListener("test",null,ut)}catch(pt){}m.prototype={handleEvent:function(t){if(this.event=t,this.currentTarget=this.matcher?this.matcher(t.target):this.node,this.currentTarget){this.options.once===!0&&this.unsubscribe();var e=this.args.map(this.getEventProperty,this);this.callback.apply(this.context,e)===!1&&t.preventDefault()}},getEventProperty:function(t){var e=arguments,n=this.event;if("type"===t)return this.type;if("target"===t||"relatedTarget"===t)return a(n[t]);if("currentTarget"===t)return a(this.currentTarget);var r=n[t];return"function"==typeof r?function(){return r.apply(n,e)}:r},subscribe:function(t,e){var n=ct[t];this.type=t,this.callback=e,n&&n(this),this.node.addEventListener(this._type||this.type,this,this.getLastArgument())},unsubscribe:function(){this.node.removeEventListener(this._type||this.type,this,this.getLastArgument())},getLastArgument:function(){var t=!!this.options.capture;return this.options.passive&&ft&&(t={passive:!0,capture:t}),t}};var lt=m;o.prototype.fire=function(t,e){var r,i,o,s=this[0];if("string"!=typeof t)throw new n("fire",arguments);var a=ct[t],c={options:{}};if(a&&(c=a(c)||c),i=c._type||t,!s)return!0;if(r=(s.ownerDocument||s).createEvent("CustomEvent"),r.initCustomEvent(i,!0,!0,e),o=s.dispatchEvent(r),o&&s[t]){var f=lt.prototype.handleEvent;lt.prototype.handleEvent=function(e){if(this.type!==t)return f.call(this,e)},s[t](),lt.prototype.handleEvent=f}return o};var ht={get:{},set:{}};"tabIndex readOnly maxLength cellSpacing cellPadding rowSpan colSpan useMap frameBorder contentEditable".split(" ").forEach(function(t){ht.get[t.toLowerCase()]=function(e){return e[t]}}),ht.get.style=function(t){return t.style.cssText},ht.set.style=function(t,e){t.style.cssText=e},ht.get.type=function(t){return t.getAttribute("type")||t.type};var yt=ht;o.prototype.get=function(t,e){var r,i=this,o=this[0],s=yt.get[t];if(!o)return r;if(0===arguments.length)return o.innerHTML;if(s)r=s(o,t);else if("string"==typeof t)r=t in o?o[t]:this instanceof a?o.getAttribute(t):null;else{if(!k(t))throw new n("get",arguments);r=t.reduce(function(t,e){return t[e]=i.get(e),t},{})}return null!=r?r:e},o.prototype.on=function(t,e,r,i){if("string"==typeof t&&("string"==typeof e?e={selector:e}:"function"==typeof e?(i=e,e={},r=[]):"object"==typeof e&&k(e)&&(i=r,r=e,e={}),"function"==typeof r&&(i=r,r=[]),e&&"object"==typeof e&&"function"==typeof i)){var o=this[0];if(!o)return function(){};var s=new lt(this,o,e,r);return s.subscribe(t,i),function(){return s.unsubscribe()}}throw new n("on",arguments)},o.prototype.set=function(t,e){var r=this,i=this[0],o=arguments.length,s=yt.set[t];if(i)if("string"==typeof t)1===o&&(e=t,t="innerHTML"),"function"==typeof e&&(e=e(this.get(t))),s?s(i,e):null==e&&this instanceof a?i.removeAttribute(t):t in i?i[t]=e:this instanceof a&&i.setAttribute(t,e);else if(k(t))1===o?(i.textContent="",this.append.apply(this,t)):t.forEach(function(t){r.set(t,e)});else{if("object"!=typeof t)throw new n("set",arguments);M(t).forEach(function(e){r.set(e,t[e])})}return this}}();