-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDominar.js
12 lines (12 loc) · 4.4 KB
/
Dominar.js
1
2
3
4
5
6
7
8
9
10
11
12
/**
* **Dominar** from KPVERSE
*
* Updated on July 12, 2023.
*
* Copyright © 2023-present, Kartavya Patel. All rights reserved.
*
* @author Kartavya Patel <[email protected]>
*
* @license {@link https://github.com/patelka2211/dominar/blob/main/LICENSE MIT}
*/
!function(){"use strict";function e(e,n){for(var t in n)if(Object.prototype.hasOwnProperty.call(n,t)){var r=n[t];"string"==typeof r||"number"==typeof r?e.setAttribute(t,""===r?" ":String(r)):e.setAttribute(t,"")}return e}var n=function(e){var n,t=(new DOMParser).parseFromString(e,"image/svg+xml");this.svg=t.querySelector("svg"),null!==(null===(n=this.svg)||void 0===n?void 0:n.querySelector("parsererror"))&&(this.svg=null)};function t(e){return e instanceof n}function r(e,n){return Object.entries(n).forEach((function(n){var t=n[0],r=n[1];e.addEventListener(t,r)})),e}function i(e,n,t){e["on".concat(n)]=t}function o(e,n){Object.entries(n).forEach((function(n){var t=n[0],r=n[1];i(e,t,r)}))}var a=function(){function n(n,t){if(this.renderedTag=document.createElement(n),t){var i=t.attributes,a=t.children,s=t.addEventListeners,u=t.attachEventListeners;i&&e(this.renderedTag,i),a&&f(this.renderedTag,a),s&&r(this.renderedTag,s),u&&o(this.renderedTag,u)}}return n.prototype.additionally=function(e){return e(this.renderedTag),this},n}();function s(e){return e instanceof a}var u=function(e){var n=this;this.renderedTagList=[],e.forEach((function(e){"string"==typeof e||"number"==typeof e?n.renderedTagList.push(String(e)):s(e)?n.renderedTagList.push(e.renderedTag):t(e)&&null!==e.svg?n.renderedTagList.push(e.svg):e instanceof HTMLElement&&n.renderedTagList.push(e)}))};function c(e){return e instanceof u}function f(e,n,r){if(void 0===r&&(r="append"),"string"==typeof n||"number"==typeof n)e[r](String(n));else if(s(n))e[r](n.renderedTag);else if(c(n))for(var i=n.renderedTagList,o=i.length,a=0;a<o;a++)e[r](i["append"===r?a:o-1-a]);else t(n)&&null!==n.svg?e[r](n.svg):n instanceof HTMLElement&&e[r](n);return e}function l(e,n){i(e,n,null)}var d=function(e,n,t,r){return new(t||(t=Promise))((function(i,o){function a(e){try{u(r.next(e))}catch(e){o(e)}}function s(e){try{u(r.throw(e))}catch(e){o(e)}}function u(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,s)}u((r=r.apply(e,n||[])).next())}))},p=function(e,n){var t,r,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(u){return function(s){if(t)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(t=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,r=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=n.call(e,a)}catch(e){s=[6,e],r=0}finally{t=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}};var v=Object.freeze({__proto__:null,SVGParser:function(e){return new n(e)},addEventListeners:r,attachEventListeners:o,detachEventListeners:function(e,n){"string"==typeof n?l(document.body,n):"object"==typeof n&&n.forEach((function(n){l(e,n)}))},insertChildren:f,isInstanceOfDominarTag:s,isInstanceOfDominarTagList:c,isInstanceOfParsedSVG:t,removeEventListeners:function(e,n){return Object.entries(n).forEach((function(n){var t=n[0],r=n[1];e.removeEventListener(t,r)})),e},render:function(e,n,t){return void 0===t&&(t={clearBeforeRender:!0}),d(this,void 0,void 0,(function(){var r,i;return p(this,(function(o){if(!(e instanceof HTMLElement))throw Error("Root is null!");if(r=t.clearBeforeRender,i=t.insertType,"boolean"!=typeof r&&(r=!0),!0===r&&(e.innerHTML="",i="append"),i||(i="append"),"append"!==i&&"prepend"!==i)throw Error("'insertType' in options can be 'append' or 'prepend' but not '".concat(i,"'."));return f(e,n,i),[2]}))}))},setAttributes:e,tag:function(e,n){return new a(e,n)},tagList:function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new u(e)}});window.Dominar=v}();