UNPKG

@!!!!!/elemental

Version:
67 lines (65 loc) 30 kB
var lu=[Uint16Array,Uint32Array,Uint8Array,Uint8ClampedArray,Int16Array,Int32Array,Int8Array,Float32Array,Float64Array,globalThis.BigInt64Array,globalThis.BigUint64Array].filter(u=>u),Eu=new Set([RegExp,Date,URL,...lu,globalThis.ArrayBuffer,globalThis.DataView]),Bu=Object.getPrototypeOf(Object.getPrototypeOf([][Symbol.iterator]())),Gu=Object.getPrototypeOf([][Symbol.iterator]),Ku=Object.getPrototypeOf(new Map()[Symbol.iterator]),qu=Object.getPrototypeOf(new Set()[Symbol.iterator]),_=class{},fu=class{},du=class{},M=class{},U=class{};try{_=eval("(async function(){}).constructor"),fu=eval("(function*(){}).constructor"),du=eval("(async function*(){}).constructor"),M=eval("((function*(){})()).constructor"),U=eval("((async function*(){})()).constructor")}catch(u){}var pu=u=>!(u instanceof Object),Ju=u=>u instanceof Object&&Object.getPrototypeOf(u).constructor==Object,Zu=u=>pu(u)||u instanceof Date||u instanceof RegExp||u instanceof URL,yu=u=>Bu.isPrototypeOf(u),hu=u=>{if(u instanceof Object){if(yu(u))return!0;let e=u.constructor;return e==M||e==U}return!1},gu=function(u){return u&&typeof u[Symbol.asyncIterator]=="function"},Xu=function(u){return u&&typeof u[Symbol.iterator]=="function"},Yu=function(u){return u instanceof Object&&(typeof u[Symbol.iterator]=="function"||typeof u[Symbol.asyncIterator]=="function")},Qu=function(u){return u instanceof Object||typeof u=="string"},mu=function(u){return u instanceof Object&&typeof u[Symbol.iterator]=="function"},T=Symbol.for("deepCopy"),u0=Symbol(),N=Symbol();Object.getPrototypeOf(function(){})[N]=function(){return this};function S(u,e=[],t=new Map){if(e.push(u),u==null||!(u instanceof Object))return u;if(t.has(u))return t.get(u);if(u[T]instanceof Function){let o=u[T](t);return t.set(u,o),o}if(hu(u))throw Error(`Sadly built-in generators cannot be deep copied. And I found a generator along this path: ${e.reverse().map(o=>`${o}, `)}`);let r,n,D;u instanceof Date?r=new Date(u.getTime()):u instanceof RegExp?r=new RegExp(u):u instanceof URL?r=new URL(u):u instanceof Function?(n=u[N](),r=u.bind(n)):Eu.has(u.constructor)?r=new u.constructor(u):u instanceof Array?r=[]:u instanceof Set?r=new Set:u instanceof Map&&(r=new Map),t.set(u,r),r instanceof Function&&(D=S(n,e,t),r=r.bind(D));let i=r;try{i.constructor=u.constructor}catch{}Object.setPrototypeOf(i,Object.getPrototypeOf(u));let F={};for(let[o,s]of Object.entries(Object.getOwnPropertyDescriptors(u))){let{value:A,get:c,set:a,...l}=s,E=c instanceof Function,g=a instanceof Function;if(E||g)F[o]={...l,get:c?function(...C){return c.apply(i,C)}:void 0,set:a?function(...C){return a.apply(i,C)}:void 0};else{if(o=="length"&&i instanceof Array)continue;F[o]={...l,value:S(A,e,t)}}}return Object.defineProperties(i,F),i}var e0=u=>S(u),t0=u=>Object.keys(u).sort().reduce((e,t)=>(e[t]=u[t],e),{}),k=(u,e=new Map)=>{if(u instanceof Object){if(e.has(u))return e.get(u);if(u instanceof Array){let t=[];e.set(u,t);for(let r of u)t.push(k(r,e));return t}else{let t={};e.set(u,t);for(let r of Object.keys(u).sort())t[r]=k(u[r],e);return t}}else return u},r0=(u,...e)=>JSON.stringify(k(u),...e),n0=function(u){let e=[];if(u==null)return[];for(u instanceof Object||(u=Object.getPrototypeOf(u));u;)e=e.concat(Reflect.ownKeys(u)),u=Object.getPrototypeOf(u);return e},D0=Object.getOwnPropertyDescriptors,o0=function(u,e={includingBuiltin:!1}){var{includingBuiltin:t}={...e};let r=[];if(u==null)return{};u instanceof Object||(u=Object.getPrototypeOf(u));let n=Object.getPrototypeOf({}),D;for(;u&&u!=D&&!(!t&&u==n);)r=r.concat(Object.entries(Object.getOwnPropertyDescriptors(u))),D=u,u=Object.getPrototypeOf(u);return r.reverse(),Object.fromEntries(r)};var C0=Object.getPrototypeOf({});var L=function*(){}(),bu=u=>u==null?L:u[Symbol.iterator]instanceof Function||u[Symbol.asyncIterator]instanceof Function?u:Object.getPrototypeOf(u).constructor==Object?Object.entries(u):L,g0=Symbol("iterationStop"),xu=u=>{let e=bu(u);return e[Symbol.asyncIterator]?e[Symbol.asyncIterator]():e[Symbol.iterator]()};async function wu(u){let e=[];for await(let t of u)e.push(t);return e}var V=function*(...u){for(u=u.map(e=>xu(e));;){let e=u.map(t=>t.next());if(e.every(t=>t.done))break;yield e.map(t=>t.value)}};var H="Threw while mapping.";function W({iterator:u,transformFunction:e,poolLimit:t=null,awaitAll:r=!1}){t=t||W.defaultPoolLimit;let n=new TransformStream({async transform(F,o){try{let s=await F;o.enqueue(s)}catch(s){s instanceof AggregateError&&s.message==H&&o.error(s)}}}),D=(async()=>{let F=n.writable.getWriter(),o=[];try{let s=0;for await(let A of u){let c=Promise.resolve().then(()=>e(A,s));s++,F.write(c);let a=c.then(()=>o.splice(o.indexOf(a),1));o.push(a),o.length>=t&&await Promise.race(o)}await Promise.all(o),F.close()}catch{let s=[];for(let A of await Promise.allSettled(o))A.status=="rejected"&&s.push(A.reason);F.write(Promise.reject(new AggregateError(s,H))).catch(()=>{})}})(),i=n.readable[Symbol.asyncIterator]();return r?D.then(()=>wu(i)):i}W.defaultPoolLimit=40;var O=({string:u,by:e=" ",noLead:t=!1})=>(t?"":e)+u.replace(/\n/g,` `+e),b=u=>typeof u=="symbol"||u instanceof Object?q(u):u!=null?u.toString():`${u}`;var G=Symbol.for("representation"),K=Symbol.for("Deno.customInspect"),q=u=>{let e=new Set,t=n=>{if(n instanceof Object){if(e.has(n))return"[Self Reference]";e.add(n)}let D;if(n===void 0)D="undefined";else if(n===null)D="null";else if(typeof n=="string")D=JSON.stringify(n);else if(typeof n=="symbol")n.description?Symbol.for(n.description)==n?D=`Symbol.for(${JSON.stringify(n.description)})`:D=`Symbol(${JSON.stringify(n.description)})`:D="Symbol()";else if(n instanceof Date)D=`new Date(${n.getTime()})`;else if(n instanceof Array)D=`[${n.map(i=>t(i)).join(",")}]`;else if(n instanceof Set)D=`new Set(${[...n].map(i=>t(i)).join(",")})`;else if(n instanceof Object&&n.constructor==Object)D=r(n);else if(n instanceof Map){let i="new Map(";for(let[F,o]of n.entries()){let s=t(F),A=t(o);s.match(/\n/g)?i+=` [${O({string:s,by:" ",noLead:!0})}, ${O({string:A,by:" ",noLead:!0})}],`:i+=` [${s}, ${O({string:A,by:" ",noLead:!0})}],`}i+=` )`,D=i}else{if(n[G]instanceof Function)try{return D=n[G](),D}catch{}if(n[K]instanceof Function)try{return D=n[K](),D}catch{}try{if(D=n.toString(),D!=="[object Object]")return D}catch{}try{if(n.constructor instanceof Function&&n.prototype&&typeof n.name=="string")return D=`class ${n.name} { /*...*/ }`,D}catch{}try{if(n.constructor instanceof Function&&typeof n.constructor.name=="string")return D=`new ${n.constructor.name}(${r(n)})`,D}catch{}return r(n)}return D},r=n=>{let D="{";for(let[i,F]of Object.entries(n)){let o=t(i),s=t(F);D+=` ${o}: ${O({string:s,by:" ",noLead:!0})},`}return D+=` }`,D};return t(u)};var Y={"&":"\\x26","!":"\\x21","#":"\\x23",$:"\\$","%":"\\x25","*":"\\*","+":"\\+",",":"\\x2c",".":"\\.",":":"\\x3a",";":"\\x3b","<":"\\x3c","=":"\\x3d",">":"\\x3e","?":"\\?","@":"\\x40","^":"\\^","`":"\\x60","~":"\\x7e","(":"\\(",")":"\\)","[":"\\[","]":"\\]","{":"\\{","}":"\\}","/":"\\/","-":"\\x2d","\\":"\\\\","|":"\\|"},Ou=new RegExp(`[${Object.values(Y).join("")}]`,"gu");function Su(u){return u.replaceAll(Ou,e=>Y[e])}var j=Symbol("regexpProxy"),J=RegExp.prototype.exec;RegExp.prototype.exec=function(...u){return this[j]?J.apply(this[j],u):J.apply(this,u)};var P,ku=Object.freeze({get(u,e){return typeof e=="string"&&e.match(/^[igmusyv]+$/)?P(u,e):e==j?u:u[e]},set(u,e,t){return u[e]=t,!0}});P=(u,e)=>{let t=new RegExp(u,e),r=new Proxy(t,ku);return Object.setPrototypeOf(r,Object.getPrototypeOf(t)),r};function Q(u){return(e,...t)=>{let r="";for(let[n,D]of V(e,t))r+=n,D instanceof RegExp?(!u&&D.flags.replace(/g/,"").length>0&&console.warn(`Warning: flags inside of regex: The RegExp trigging this warning is: ${D} When calling the regex interpolater (e.g. regex\`something\${stuff}\`) one of the \${} values (the one above) was a RegExp with a flag enabled e.g. /stuff/i <- i = ignoreCase flag enabled When the /stuff/i gets interpolated, its going to loose its flags (thats what I'm warning you about) To disable/ignore this warning do: regex.stripFlags\`something\${/stuff/i}\` If you want to add flags to the output of regex\`something\${stuff}\` do: regex\`something\${stuff}\`.i // ignoreCase regex\`something\${stuff}\`.ig // ignoreCase and global regex\`something\${stuff}\`.gi // functionally equivlent `),r+=`(?:${D.source})`):D!=null&&(r+=Su(b(D)));return P(r,"")}}var ju=Q(!1);ju.stripFlags=Q(!0);var Z=new TextDecoder("utf-8"),X=new TextEncoder("utf-8"),x0=Z.decode.bind(Z),w0=X.encode.bind(X);var Pu=[Uint16Array,Uint32Array,Uint8Array,Uint8ClampedArray,Int16Array,Int32Array,Int8Array,Float32Array,Float64Array,globalThis.BigInt64Array,globalThis.BigUint64Array].filter(u=>u),S0=function(u){let e=[];if(u==null)return[];for(u instanceof Object||(u=Object.getPrototypeOf(u));u;)e=e.concat(Reflect.ownKeys(u)),u=Object.getPrototypeOf(u);return e},k0=Object.getOwnPropertyDescriptors,eu=function(u,e={includingBuiltin:!1}){var{includingBuiltin:t}={...e};let r=[];if(u==null)return{};u instanceof Object||(u=Object.getPrototypeOf(u));let n=Object.getPrototypeOf({}),D;for(;u&&u!=D&&!(!t&&u==n);)r=r.concat(Object.entries(Object.getOwnPropertyDescriptors(u))),D=u,u=Object.getPrototypeOf(u);return r.reverse(),Object.fromEntries(r)},Iu=Object.getPrototypeOf(new Map().keys()),$u=Object.getPrototypeOf(new Set().keys()),tu=class{},ru=class{};try{tu=eval("((function*(){})()).constructor"),ru=eval("((async function*(){})()).constructor")}catch(u){}var vu=u=>{if(u instanceof Object){let e=Object.getPrototypeOf(u);if(e==Iu||e==$u)return!0;let t=u.constructor;return t==tu||t==ru}return!1},uu=Symbol.for("deepCopy"),j0=Symbol(),nu=Symbol();Object.getPrototypeOf(function(){})[nu]=function(){return this};function I(u,e=[],t=new Map){if(e.push(u),u==null||!(u instanceof Object))return u;if(t.has(u))return t.get(u);if(u[uu]instanceof Function){let o=u[uu]();return t.set(u,o),o}if(vu(u))throw Error(`Sadly built-in generators cannot be deep copied. And I found a generator along this path: ${e.reverse().map(o=>`${o}, `)}`);let r,n,D;u instanceof Date?r=new Date(u.getTime()):u instanceof RegExp?r=new RegExp(u):u instanceof Function?(n=u[nu](),r=function(...o){return u.apply(D,o)}):Pu.includes(u.constructor)?r=new u.constructor([...u]):u instanceof Array?r=[]:u instanceof Set?r=new Set:u instanceof Map&&(r=new Map),t.set(u,r),r instanceof Function&&(D=I(n,e,t));let i=r;try{i.constructor=u.constructor}catch{}Object.setPrototypeOf(i,Object.getPrototypeOf(u));let F={};for(let[o,s]of Object.entries(Object.getOwnPropertyDescriptors(u))){let{value:A,get:c,set:a,...l}=s,E=c instanceof Function,g=a instanceof Function;if(E||g)F[o]={...l,get:c?function(...C){return c.apply(i,C)}:void 0,set:a?function(...C){return a.apply(i,C)}:void 0};else{if(o=="length"&&i instanceof Array)continue;F[o]={...l,value:I(A,e,t)}}}return Object.defineProperties(i,F),i}var P0=u=>I(u),I0=u=>Object.keys(u).sort().reduce((e,t)=>(e[t]=u[t],e),{}),$=(u,e=new Map)=>{if(u instanceof Object){if(e.has(u))return e.get(u);if(u instanceof Array){let t=[];e.set(u,t);for(let r of u)t.push($(r,e));return t}else{let t={};e.set(u,t);for(let r of Object.keys(u).sort())t[r]=$(u[r],e);return t}}else return u},$0=(u,...e)=>JSON.stringify($(u),...e);var zu="\uE000",Du="\uE001";function h(u){let e=this,t=0,r=[null],n=0,D,i,F,o=[],s=0,A,c=0,a=!1,l=(C,B=[],x)=>{let m=0;return C=!x&&C===Du?o[s++].slice(1,-1):C.replace(/\ue001/g,f=>o[s++]),C&&(C.replace(/\ue000/g,(f,p)=>(p&&B.push(C.slice(m,p)),m=p+1,B.push(arguments[++n]))),m<C.length&&B.push(C.slice(m)),B.length>1?B:B[0])},E=()=>{[r,A,...D]=r,r.push(e(A,...D)),a===c--&&(a=!1)};return u.join(zu).replace(/<!--[^]*?-->/g,"").replace(/<!\[CDATA\[[^]*\]\]>/g,"").replace(/('|")[^\1]*?\1/g,C=>(o.push(C),Du)).replace(/(?:^|>)((?:[^<]|<[^\w\ue000\/?!>])*)(?:$|<)/g,(C,B,x,m)=>{let f,p;if(x&&m.slice(t,x).replace(/(\S)\/$/,"$1 /").split(/\s+/).map((y,Cu)=>{if(y[0]==="/"){if(y=y.slice(1),iu[y])return;p=f||y||1}else if(Cu){if(y){let R=r[2]||(r[2]={});y.slice(0,3)==="..."?Object.assign(R,arguments[++n]):([i,F]=y.split("="),Array.isArray(F=R[l(i)]=F?l(F):!0)&&(F.toString=F.join.bind(F,"")))}}else{if(f=l(y),typeof f=="string")for(;v[r[1]+f];)E();r=[r,f,null],c++,!a&&Ru[f]&&(a=c),iu[f]&&(p=f)}}),p)for(r[0]||ou(`Wrong close tag \`${p}\``),E();A!==p&&v[A];)E();t=x+C.length,a||(B=B.replace(/\s*\n\s*/g,"").replace(/\s+/g," ")),B&&l((A=0,B),r,!0)}),r[0]&&v[r[1]]&&E(),c&&ou(`Unclosed \`${r[1]}\`.`),r.length<3?r[1]:(r.shift(),r)}var ou=u=>{throw SyntaxError(u)},iu=h.empty={},v=h.close={},Ru=h.pre={};"area base basefont bgsound br col command embed frame hr image img input keygen link meta param source track wbr ! !doctype ? ?xml".split(" ").map(u=>h.empty[u]=!0);var su={li:"",dt:"dd",dd:"dt",p:"address article aside blockquote details div dl fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hgroup hr main menu nav ol pre section table",rt:"rp",rp:"rt",optgroup:"",option:"optgroup",caption:"tbody thead tfoot tr colgroup",colgroup:"thead tbody tfoot tr caption",thead:"tbody tfoot caption",tbody:"tfoot caption",tfoot:"caption",tr:"tbody tfoot",td:"th tr",th:"td tr tbody"};for(let u in su)for(let e of[...su[u].split(" "),u])h.close[u]=h.close[u+e]=!0;"pre textarea".split(" ").map(u=>h.pre[u]=!0);var Tu=h,_u=Object.freeze(new Set(["accent-color","align-content","align-items","align-self","align-tracks","all","animation","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-timeline","animation-timing-function","appearance","ascent-override","aspect-ratio","backdrop-filter","backface-visibility","background","background-attachment","background-blend-mode","background-clip","background-color","background-image","background-origin","background-position","background-position-x","background-position-y","background-repeat","background-size","bleed","block-overflow","block-size","border","border-block","border-block-color","border-block-end","border-block-end-color","border-block-end-style","border-block-end-width","border-block-start","border-block-start-color","border-block-start-style","border-block-start-width","border-block-style","border-block-width","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-end-end-radius","border-end-start-radius","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-inline","border-inline-color","border-inline-end","border-inline-end-color","border-inline-end-style","border-inline-end-width","border-inline-start","border-inline-start-color","border-inline-start-style","border-inline-start-width","border-inline-style","border-inline-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-start-end-radius","border-start-start-radius","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-decoration-break","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","caret-color","clear","clip","clip-path","color","color-scheme","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","content","content-visibility","counter-increment","counter-reset","counter-set","cursor","length","angle","descent-override","direction","display","resolution","empty-cells","fallback","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","flex_value","float","font","font-display","font-family","font-feature-settings","font-kerning","font-language-override","font-optical-sizing","font-size","font-size-adjust","font-stretch","font-style","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-ligatures","font-variant-numeric","font-variant-position","font-variation-settings","font-weight","forced-color-adjust","gap","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","frequency","hanging-punctuation","height","hyphenate-character","hyphens","image-orientation","image-rendering","image-resolution","inherit","inherits","initial","initial-letter","initial-letter-align","initial-value","inline-size","input-security","inset","inset-block","inset-block-end","inset-block-start","inset-inline","inset-inline-end","inset-inline-start","isolation","justify-content","justify-items","justify-self","justify-tracks","left","letter-spacing","line-break","line-clamp","line-gap-override","line-height","line-height-step","list-style","list-style-image","list-style-position","list-style-type","margin","margin-block","margin-block-end","margin-block-start","margin-bottom","margin-inline","margin-inline-end","margin-inline-start","margin-left","margin-right","margin-top","margin-trim","marks","mask","mask-border","mask-border-mode","mask-border-outset","mask-border-repeat","mask-border-slice","mask-border-source","mask-border-width","mask-clip","mask-composite","mask-image","mask-mode","mask-origin","mask-position","mask-repeat","mask-size","mask-type","masonry-auto-flow","math-style","max-block-size","max-height","max-inline-size","max-lines","max-width","max-zoom","min-block-size","min-height","min-inline-size","min-width","min-zoom","mix-blend-mode","time","negative","object-fit","object-position","offset","offset-anchor","offset-distance","offset-path","offset-position","offset-rotate","opacity","order","orientation","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-anchor","overflow-block","overflow-clip-margin","overflow-inline","overflow-wrap","overflow-x","overflow-y","overscroll-behavior","overscroll-behavior-block","overscroll-behavior-inline","overscroll-behavior-x","overscroll-behavior-y","Pseudo-classes","Pseudo-elements","pad","padding","padding-block","padding-block-end","padding-block-start","padding-bottom","padding-inline","padding-inline-end","padding-inline-start","padding-left","padding-right","padding-top","page-break-after","page-break-before","page-break-inside","paint-order","perspective","perspective-origin","place-content","place-items","place-self","pointer-events","position","prefix","print-color-adjust","quotes","range","resize","revert","right","rotate","row-gap","ruby-align","ruby-merge","ruby-position","scale","scroll-behavior","scroll-margin","scroll-margin-block","scroll-margin-block-end","scroll-margin-block-start","scroll-margin-bottom","scroll-margin-inline","scroll-margin-inline-end","scroll-margin-inline-start","scroll-margin-left","scroll-margin-right","scroll-margin-top","scroll-padding","scroll-padding-block","scroll-padding-block-end","scroll-padding-block-start","scroll-padding-bottom","scroll-padding-inline","scroll-padding-inline-end","scroll-padding-inline-start","scroll-padding-left","scroll-padding-right","scroll-padding-top","scroll-snap-align","scroll-snap-stop","scroll-snap-type","scrollbar-color","scrollbar-gutter","scrollbar-width","shape-image-threshold","shape-margin","shape-outside","size","size-adjust","speak-as","src","suffix","symbols","syntax","system","tab-size","table-layout","text-align","text-align-last","text-combine-upright","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-skip-ink","text-decoration-style","text-decoration-thickness","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-indent","text-justify","text-orientation","text-overflow","text-rendering","text-shadow","text-size-adjust","text-transform","text-underline-offset","text-underline-position","top","touch-action","transform","transform-box","transform-origin","transform-style","transition","transition-delay","transition-duration","transition-property","transition-timing-function","translate","unicode-bidi","unicode-range","unset","user-select","user-zoom","vertical-align","viewport-fit","visibility","white-space","widows","width","will-change","word-break","word-spacing","word-wrap","writing-mode","z-index","zoom"])),Mu=Object.freeze(new Set(["class","style","value","id","contenteditable","href","hidden","autofocus","src","name","accept","accesskey","action","align","alt","async","autocomplete","autoplay","border","charset","checked","cite","cols","colspan","content","controls","coords","data","datetime","default","defer","dir","dirname","disabled","download","draggable","enctype","for","form","formaction","headers","high","hreflang","http","ismap","kind","label","lang","list","loop","low","max","maxlength","media","method","min","multiple","muted","novalidate","open","optimum","pattern","placeholder","poster","preload","readonly","rel","required","reversed","rows","rowspan","sandbox","scope","selected","shape","size","sizes","span","spellcheck","srcdoc","srclang","srcset","start","step","tabindex","target","title","translate","type","usemap","wrap","bgcolor","width","color","height"])),Uu=u=>u.startsWith("-")||_u.has(u),Fu=u=>u.replace(/[a-z]([A-Z])(?=[a-z])/g,e=>`${e[0]}-${e.slice(1).toLowerCase()}`),Nu=u=>!!u.prototype&&!!u.prototype.constructor.name,z=(u,e)=>{let t=eu(u),r={};for(let[n,D]of Object.entries(t))["constructor","prototype","length"].includes(n)||(r[n]={get:()=>u[n]});return Object.defineProperties(e,r),e},Au=Symbol.for("toHtmlElement"),d=class u{constructor(e={},t={}){let{middleware:r,errorComponentFactory:n,defaultPlaceholderFactory:D}=t||{};this.components=e||{},this.middleware=r||{},this.defaultPlaceholderFactory=D||(()=>document.createElement("div")),this.errorComponentFactory=n||au,this.html=this.createElement.bind(this),this.xhtm=Tu.bind((...i)=>this.createElement(...i))}static debug=!1;static allTags=Symbol.for("allTags");static exclusivelySvgElements=new Set(["svg","animate","animateMotion","animateTransform","circle","clipPath","defs","desc","discard","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","foreignObject","g","hatch","hatchpath","image","line","linearGradient","marker","mask","mesh","meshgradient","meshpatch","meshrow","metadata","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","switch","symbol","text","textPath","tspan","unknown","use","view"]);static randomId=e=>`${e}${Math.random()}`.replace(".","");static makeHtmlElement=function(e){if(e instanceof Node||e instanceof Element||e instanceof HTMLDocument)return e;if(e==null)return new window.Text("");if(typeof e=="string")return new window.Text(e);if(typeof e=="symbol")return new window.Text(e.toString());if(e instanceof Object){if(e[Au]!=null)return u.makeHtmlElement(e[Au]);throw Error(`Cannot coerce ${e} into an html element`)}else return new window.Text(`${e}`)};static appendChildren=function(e,...t){let{element:r,insertBefore:n}=e,D=i=>e.appendChild(i);n&&!(n instanceof Function)&&(e=r,D=i=>e.insertBefore(n,i));for(let i of t)if(i instanceof Array)u.appendChildren(e,...i);else if(i instanceof Function)u.appendChildren(e,i());else if(i instanceof Promise){let F=i,o=F.placeholder||document.createElement("div");D(o),setTimeout(async()=>{try{let s=await F;if(s instanceof Array){let A=o.parentElement;A||(A=await new Promise((c,a)=>{let l=setInterval(()=>{o.parentElement&&(c(o.parentElement),clearInterval(l))},70)}));for(let c of s)try{u.appendChildren({element:A,insertBefore:o},c)}catch(a){A.insertBefore(o,cu(`When async component ${b(e)} resolved, it created an array. One of those elements in the array caused an error when it tried to be added as a child: ${b(a)}`))}}else{let A=u.makeHtmlElement(s);o.replaceWith(A)}}catch(s){o.replaceWith(au({...properties,children:t},key,s))}},0)}else D(u.makeHtmlElement(i));return e};static css=function(e,...t){if(typeof e=="string")return e;if(e==null)return"";if(e instanceof Array){let r=e,n=t,D="";for(let i of r)if(D+=i,n.length>0){let F=n.shift();F instanceof Object?D+=w.css(F):D+=`${F}`}return D}else if(e instanceof Object){let r="";for(let[n,D]of Object.entries(e))D!=null&&(r+=`${Fu(n)}: ${D};`);return r}else return e};static combineClasses=(...e)=>{e=e.filter(r=>r!=null);let t=[];for(let r of e)if(typeof r=="string"&&(r=r.split(" ")),r instanceof Array){r=r.flat(1/0);for(let n of r)t.push(n)}else if(r instanceof Object)for(let[n,D]of Object.entries(r))D&&t.push(n);return t};createElement(...e){if(e[0]instanceof Array)return this.xhtm(...e);{u.debug&&console.debug("args is:",e);for(let o of(this.middleware[u.allTags]||[]).concat(this.middleware[e[0]]||[]))try{e=eachMiddleWare(e)}catch{console.error("[ElementalClass] one of the middleware functions failed:",eachMiddleWare,e)}let[t,r,...n]=e;if(u.debug&&console.debug("key, properties, children is:",t,r,n),this.components[t]instanceof Function&&(t=this.components[t]),t instanceof Function){let o;try{o=Nu(t)?new t({...r,children:n}):t({...r,children:n})}catch(s){return this.errorComponentFactory({...r,children:n},t,s)}if(o instanceof Promise){let s=o,A=s.placeholder||this.defaultPlaceholderFactory(o);return setTimeout(async()=>{try{let c=await s;if(c instanceof Array){let a=A.parentElement;a||(a=await new Promise((l,E)=>{let g=setInterval(()=>{A.parentElement&&(l(A.parentElement),clearInterval(g))},70)}));for(let l of c)try{u.appendChildren({element:a,insertBefore:A},l)}catch(E){a.insertBefore(A,cu(`Something returned a promise, which resolved to an array, and then something tried to append those to an element (this element: ${i}). One of the items in the array ${l} caused an error when it tried to be added as a child: ${b(E)}`))}}else{let a=u.makeHtmlElement(c);A.replaceWith(a)}}catch(c){A.replaceWith(this.errorComponentFactory({...r,children:n},t,c))}},0),A}else return o}let D=u.exclusivelySvgElements.has(t),i=D?document.createElementNS("http://www.w3.org/2000/svg",t):document.createElement(t),F="";if(r instanceof Object)for(let[o,s]of Object.entries(r)){if(o=="style"){F+=u.css(s);continue}if(o.slice(0,2)=="on"&&o.slice(2,3).toLowerCase()!==o.slice(2,3)&&s instanceof Function&&i.addEventListener(o.slice(2).toLowerCase(),s),o=="class"){if(s instanceof Array)s=s.join(" ");else if(s instanceof Object){let A="";for(let[c,a]of Object.entries(s))a&&(A+=c);s=A}}if(D){s instanceof Array&&(s=s.join(" ")),i.setAttribute(Fu(o),s);continue}s!=null&&!(s instanceof Object)&&Mu.has(o)&&i.setAttribute(o,s);try{i[o]=s}catch{}Uu(o)&&(F+=`;${o}: ${s};`)}return F&&i.setAttribute("style",F),u.appendChildren(i,...n)}}extend(e={},t={}){let{middleware:r,...n}=t||{};return w({...this.components,...e},{middleware:{...this.middleware,...r},...n})}},w=(...u)=>{let e=new d(...u),t=e.createElement.bind(e);return z(d,t),z(e,t),t};z(d,w);function cu(u){let e=document.createElement("div");e.setAttribute("style",` all: unset; display: flex; flex-direction: column; padding: 1.5rem; background-color: #f5a5a8; color: white; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; font-size: 18px; font-weight: 400; overflow: auto; `),e.innerHTML=`I'm sorry, there was an error when loading this part of the page \u{1F641}.<br>Here's the error message: ${Option(b(u!=null&&u.message||u)).innerHTML}`}function au({children:u,...e},t,r){let n=document.createElement("div"),D=document.createElement("code"),i=document.createElement("div");n.setAttribute("style",` all: unset; display: flex; flex-direction: column; padding: 1.5rem; background-color: #f5a5a8; color: white; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; font-size: 18px; font-weight: 400; overflow: auto; `),n.innerHTML="I'm sorry, there was an error when loading this part of the page \u{1F641} ";let F;if(typeof t=="string")F=`<${t} />`;else try{F=`<${t.prototype.constructor.name} />`}catch{try{F=`<${t.name} />`}catch{F=`<${t} />`}}let o={};for(let[s,A]of Object.entries(e))try{o[s]=JSON.parse(JSON.stringify(A))}catch{o[s]=`${A}`}return D.innerHTML=`tag: ${F} properties: ${JSON.stringify(o,0,4)} error: ${r}`,D.setAttribute("style",` padding: 1rem; background-color: #161b22; color: #789896; white-space: pre; max-width: 85vw; overflow: auto; `),n.appendChild(D),i.setAttribute("style",` all: unset display: flex flex-direction: column margin-top: 1.3rem `),d.appendChildren(i,u),n.appendChild(i),n}try{let u=document.head;Object.defineProperty(document,"head",{set:e=>d.appendChildren(u,...e.childNodes),get:()=>u,writable:!0})}catch{}var Lu=d.combineClasses,Hu=w(),Vu=d.css,Wu=d.allTags,M0={Elemental:w,html:Hu,css:Vu,allTags:Wu,combineClasses:Lu};export{w as Elemental,Wu as allTags,Lu as combineClasses,Vu as css,M0 as default,Hu as html,Au as toHtmlElement};