min-dom.min.js 4.4 KB

1
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).MinDom={})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}const n=Object.prototype.toString,r=Object.prototype.hasOwnProperty;function o(e,t){return r.call(e,t)}function i(e,t){let r,i;if(void 0===e)return;const c=function(e){return"[object Array]"===n.call(e)}(e)?u:l;for(let n in e)if(o(e,n)&&(r=e[n],i=t(r,c(n)),!1===i))return r}function l(e){return e}function u(e){return Number(e)}const c=Object.prototype.toString;function a(e){if(!e||!e.nodeType)throw new Error("A DOM element reference is required");this.el=e,this.list=e.classList}function d(e,t){return e&&"function"==typeof e.matches&&e.matches(t)}function s(e,t,n){for(var r=n?e:e.parentNode;r&&r.nodeType!==document.DOCUMENT_NODE&&r.nodeType!==document.DOCUMENT_FRAGMENT_NODE;){if(d(r,t))return r;r=r.parentNode}return d(r,t)?r:null}a.prototype.add=function(e){return this.list.add(e),this},a.prototype.remove=function(e){return"[object RegExp]"==c.call(e)?this.removeMatching(e):(this.list.remove(e),this)},a.prototype.removeMatching=function(e){const t=this.array();for(let n=0;n<t.length;n++)e.test(t[n])&&this.remove(t[n]);return this},a.prototype.toggle=function(e,t){return void 0!==t?t!==this.list.toggle(e,t)&&this.list.toggle(e):this.list.toggle(e),this},a.prototype.array=function(){return Array.from(this.list)},a.prototype.has=a.prototype.contains=function(e){return this.list.contains(e)};var f,p,h,y={};function g(){f=window.addEventListener?"addEventListener":"attachEvent",p=window.removeEventListener?"removeEventListener":"detachEvent",h="addEventListener"!==f?"on":""}var b=t({__proto__:null,bind:y.bind=function(e,t,n,r){return f||g(),e[f](h+t,n,r||!1),n},unbind:y.unbind=function(e,t,n,r){return p||g(),e[p](h+t,n,r||!1),n},default:y},[y]),v=["focus","blur"];var m,E={bind:function(e,t,n,r,o){return-1!==v.indexOf(n)&&(o=!0),b.bind(e,n,(function(n){var o=n.target||n.srcElement;n.delegateTarget=s(o,t,!0),n.delegateTarget&&r.call(e,n)}),o)},unbind:function(e,t,n,r){return-1!==v.indexOf(t)&&(r=!0),b.unbind(e,t,n,r)}},O=function(e,t){if("string"!=typeof e)throw new TypeError("String expected");t||(t=document);var n=/<([\w:]+)/.exec(e);if(!n)return t.createTextNode(e);e=e.replace(/^\s+|\s+$/g,"");var r=n[1];if("body"==r){return(o=t.createElement("html")).innerHTML=e,o.removeChild(o.lastChild)}var o,i=Object.prototype.hasOwnProperty.call(T,r)?T[r]:T._default,l=i[0],u=i[1],c=i[2];(o=t.createElement("div")).innerHTML=u+e+c;for(;l--;)o=o.lastChild;if(o.firstChild==o.lastChild)return o.removeChild(o.firstChild);var a=t.createDocumentFragment();for(;o.firstChild;)a.appendChild(o.removeChild(o.firstChild));return a},w=!1;"undefined"!=typeof document&&((m=document.createElement("div")).innerHTML=' <link/><table></table><a href="/a">a</a><input type="checkbox"/>',w=!m.getElementsByTagName("link").length,m=void 0);var T={legend:[1,"<fieldset>","</fieldset>"],tr:[2,"<table><tbody>","</tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],_default:w?[1,"X<div>","</div>"]:[0,"",""]};T.td=T.th=[3,"<table><tbody><tr>","</tr></tbody></table>"],T.option=T.optgroup=[1,'<select multiple="multiple">',"</select>"],T.thead=T.tbody=T.colgroup=T.caption=T.tfoot=[1,"<table>","</table>"],T.polyline=T.ellipse=T.polygon=T.circle=T.text=T.line=T.path=T.rect=T.g=[1,'<svg xmlns="http://www.w3.org/2000/svg" version="1.1">',"</svg>"];var C=O;e.assignStyle=function(e,...t){const n=e.style;return i(t,(function(e){e&&i(e,(function(e,t){n[t]=e}))})),e},e.attr=function(e,t,n){return 2==arguments.length?e.getAttribute(t):null===n?e.removeAttribute(t):(e.setAttribute(t,n),e)},e.classes=function(e){return new a(e)},e.clear=function(e){for(var t;e.childNodes.length;)t=e.childNodes[0],e.removeChild(t);return e},e.closest=s,e.delegate=E,e.domify=C,e.event=b,e.matches=d,e.query=function(e,t){return(t=t||document).querySelector(e)},e.queryAll=function(e,t){return(t=t||document).querySelectorAll(e)},e.remove=function(e){e.parentNode&&e.parentNode.removeChild(e)},Object.defineProperty(e,"__esModule",{value:!0})}));