function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:String(e)}function _toPrimitive(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var i=r.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function _classStaticPrivateMethodGet(t,e,r){return _classCheckPrivateStaticAccess(t,e),r}function _classCheckPrivateStaticAccess(t,e){if(t!==e)throw new TypeError("Private static access of wrong provenance")}export default class clrly{static new(t="div",e,...r){if(e=e||{},"clrly"==t||"string"!=typeof t)return"string"!=typeof t&&(e.from=t),_classStaticPrivateMethodGet(this,clrly,_newElementFromComponent).call(this,e,r);if("clear"==t)return this.render(r),this.editAttributes(r,e),r;var i=_classStaticPrivateMethodGet(this,clrly,_newElement).call(this,t,!1!==e.render&&"false"!==e.render);return this.editAttributes(i,e),_classStaticPrivateMethodGet(this,clrly,_appendChildrenToElement).call(this,i,r),i.editAttributes=function(t){return clrly.editAttributes(i,t)},i.isClearlyHTML=!0,i}static render(t,e=!0,r=document.body){if(Array.isArray(t)){for(let i of t)this.render(i,e,r);return}let i=t.isClearlyComponent?t.HTML:t;e?r.appendChild(i):i.remove()}static editAttributes(t,e){if(Array.isArray(t)){for(var r of t)this.editAttributes(r,e);return t}if(e){var i=t.isClearlyComponent;for(var n in e){if("parent"!=n&&"innerHTML"!=n){var a=typeof e[n];"function"==a||"object"==a||i?t[n]=e[n]:t.setAttribute(n,e[n])}if(e.parent)e.parent.appendChild(t);e.innerHTML&&(t.innerHTML=e.innerHTML)}}return t}static add(t,e=document.documentElement){try{return e.innerHTML+=t,t}catch(t){}}static id(t){return this.xid(document,t)}static class(t){return this.xclass(document,t)}static tag(t){return this.xtag(document,t)}static $(t){return this.x$(document,t)}static attribute(t,e){return this.xattribute(document,t,e)}static import(t,e,r){return Array.isArray(t)||(t=[t]),_classStaticPrivateMethodGet(this,clrly,_importRec).call(this,t,e,r,0),t}static title(t){return document.title=t}static ogTitle(t){return Array.from(clrly.attribute("property","og:title")).forEach((function(t){t.remove()})),clrly.new("meta",{parent:document.head,property:"og:title",content:t}),clrly.attribute("property","og:title")[0].href}static description(t){return Array.from(clrly.attribute("name","description")).forEach((function(t){t.remove()})),clrly.new("meta",{parent:document.head,name:"description",content:t}),clrly.attribute("name","description")[0].href}static ogDescription(t){return Array.from(clrly.attribute("property","og:description")).forEach((function(t){t.remove()})),clrly.new("meta",{parent:document.head,property:"og:description",content:t}),clrly.attribute("property","og:description")[0].href}static icon(t){return Array.from(clrly.attribute("rel","icon")).forEach((function(t){t.remove()})),clrly.new("link",{parent:document.head,rel:"icon",href:t}),clrly.attribute("rel","icon")[0].href}static ogImage(t){return Array.from(clrly.attribute("property","og:image")).forEach((function(t){t.remove()})),clrly.new("meta",{parent:document.head,property:"og:image",content:t}),clrly.attribute("property","og:image")[0].href}static theme(t){return Array.from(clrly.attribute("name","theme-color")).concat(Array.from(clrly.attribute("name","apple-mobile-web-app-status-bar-style"))).forEach((function(t){t.remove()})),clrly.new("meta",{parent:document.head,name:"theme-color",content:t}),clrly.new("meta",{parent:document.head,name:"apple-mobile-web-app-status-bar-style",content:t}),clrly.attribute("name","theme-color")[0].content}static dir(t){document.body.dir=t}static mobileFriendly(t=!0){var e="app"==t?", user-scalable=no":"";return clrly.new("meta",{parent:document.head,name:"viewport",content:`width=device-width, initial-scale=1.0${e}`})}static initialize(t){var e=[];const r=[["title",this.title],["ogTitle",this.ogTitle],["description",this.description],["ogDescription",this.ogDescription],["icon",this.icon],["ogImage",this.ogImage],["theme",this.theme],["dir",this.dir],["mobile",this.mobileFriendly]];for(let i of r)t[i[0]]&&e.push(i[1](t[i[0]]));return e}static style(t){return clrly.new("style",{parent:document.head,innerHTML:t})}static toRGB(t){t=3==t.length?t.replace(/(.)/g,"$1$1"):t;var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return e?{r:parseInt(e[1],16),g:parseInt(e[2],16),b:parseInt(e[3],16)}:""}static toHEX(t){function e(t){return 1==(t=t.toString(16)).length?"0"+t:t}return"#"+e(t.r)+e(t.g)+e(t.b)}static colorBrightness(t,e){var r=this.toRGB(t);return e=(e+100)/100,this.toHEX({r:Math.min(255,Math.floor(r.r*e)),g:Math.min(255,Math.floor(r.g*e)),b:Math.min(255,Math.floor(r.b*e))})}static get url(){return window.location.href}static get pageUrl(){return this.url.replace(window.location.search,"").replace(window.location.hash,"")}static get hash(){return decodeURI(window.location.hash.substring(1))}static get search(){return new URL(window.location.href).searchParams}static reload(){window.location.reload()}static redirect(t){window.location.replace(t)}static go(t,e){e?window.open(t):window.location.href=t}static duplicate(){this.go(this.url,!0)}static cookie(t,e,r,i,n){let a="31 Dec 2036";return void 0!==r&&void 0!==i&&void 0!==n&&(a=r+" "+(i=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"][i-1])+" "+n),document.cookie=t+"="+e+"; expires="+a+" 23:59:59 UTC; path=/",e}static deleteCookie(t){document.cookie=t+"=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/"}static getCookie(t){for(var e=t+"=",r=decodeURIComponent(document.cookie).split(";"),i=0;i<r.length;i++){for(var n=r[i];" "==n.charAt(0);)n=n.substring(1);if(0==n.indexOf(e))return n.substring(e.length,n.length)}return""}static ajax(t,e,r){fetch(t,e).then((t=>t.text())).then((t=>r(t)))}static json(t,e,r){fetch(t,e).then((t=>t.json())).then((t=>r(t)))}static getXML(t,e){var r=new XMLHttpRequest;r.onreadystatechange=function(){4==this.readyState&&200==this.status&&e(this.responseXML)},r.open("GET",t,!0),r.send()}static xid(t,e){return t.getElementById(e)||void 0}static xclass(t,e){return t.getElementsByClassName(e)||[]}static xtag(t,e){return t.getElementsByTagName(e)||[]}static x$(t,e){try{return t.querySelectorAll(e)||[]}catch(t){return[]}}static xattribute(t,e,r){return this.x$(t,`[${e}="${r}"]`)}static xvalue(t){return t.firstChild.nodeValue}static random(t,e){return Math.random()*(e-t)+t}static randomInt(t,e){return Math.floor(Math.random()*(e-t+1))+t}static toFile(t,e="text/html"){return URL.createObjectURL(new Blob([t],{type:e}))}static download(t,e){var r=clrly.new("a",{href:t,download:e});r.click(),r.remove()}}function _appendChildrenToElement(t,e){if(e)for(var r of e)if(Array.isArray(r))_classStaticPrivateMethodGet(this,clrly,_appendChildrenToElement).call(this,t,r);else try{r.isClearlyComponent&&(r=r.HTML),t.appendChild(null==r.nodeType?document.createTextNode(r.toString()):r)}catch(t){}}function _newElement(t,e=!0){var r=document.createElement(t);return e&&this.render(r,e),r}function _newElementFromComponent(t,e){var r=t.from;if(!r)throw new Error("Cannot find the component");t.children=e;var i=new r(t),n=i.element;return i.style&&(n.style=i.style),i.HTML=n,i.isClearlyComponent=!0,i.start&&i.start(t),i}function _importRec(t,e,r,i){var n,a=t[i];for(var o in n=a.includes(".css")?clrly.new("link",{parent:document.head,href:a,rel:"stylesheet"}):clrly.new("script",{parent:document.head,src:a}),e)n.setAttribute(o,e[o]);n.onload=function(){i===t.length-1?r&&r():_classStaticPrivateMethodGet(clrly,clrly,_importRec).call(clrly,t,o,r,i+1)}}_defineProperty(clrly,"component",class{constructor(t){if(this.constructor===clrly.component)throw new Error("clrly.component is not an initializeable object, make your own component")}start(){}get element(){throw new Error("get element() does not exist")}get style(){return""}update(t=!0){var e=this.element;e.style=this.style,this.HTML.parentNode.replaceChild(e,this.HTML),this.HTML=e,t&&this.start()}registerUpdate(t,e,r){var i=this;i[t]||(i[t]={}),i[t]=new Proxy(i[t],{set:function(t,n,a){return t[n]=a,i.update(e),r&&r(n,a),!0}})}unregisterUpdate(t){this[t]={...this[t]}}});class Switchable extends clrly.component{constructor(t){super(t)}appendTo(t,e={}){this.switcherParent=t,this.sProps=e,this.start(),this.update()}start(){this.HTML.editAttributes({parent:this.switcherParent})}onSwitch(){}get isSwitchable(){return!0}}class _SwitcherRouterBase extends clrly.component{constructor(t){super(t),this.state=t,this.registerUpdate("state"),this.clear()}get element(){const t=clrly.new("div");let e=this.state.current;if(this._switchables=={}||null==e)return t;let r=this._get(this instanceof Router?e.route:e.name);return r&&r.isSwitchable&&(this instanceof Router&&window.history.pushState({},"",e.route),r.appendTo(t,e.props),r.onSwitch()),t}add(t,e){return this._switchables[t]=e,e.HTML.remove(),t}set current(t){this.state.current=t}clear(){this._switchables={}}}class Switcher extends _SwitcherRouterBase{constructor(t){super(t)}_get(t){return this._switchables[t]}get currentName(){return this.state.current.name}}class Router extends _SwitcherRouterBase{static get NOT_FOUND_PATH(){return"/404"}constructor(t){super(t),window.onpopstate=this.initialize}_get(t){for(let e in this._switchables)if(e.match(`^${t}/?$`))return this._switchables[e];return this._switchables[Router.NOT_FOUND_PATH]}get currentRoute(){return this.state.current.route}clear(){super.clear(),this.add(Router.NOT_FOUND_PATH,this.state.notFound)}async initialize(){this.current={route:window.location.pathname,props:{}}}}class Sdiv extends Switchable{constructor(t){super(t),this.state=t,this.registerUpdate("state")}get element(){return clrly.new("div",{},...this.state.children)}onSwitch(){this.state.onSwitch&&this.state.onSwitch()}}export{clrly,Switchable,Switcher,Router,Sdiv};