UNPKG

@efflore/ui-element

Version:

UIElement - minimal reactive framework based on Web Components

2 lines (1 loc) 31 kB
const e=e=>t=>typeof t===e,t=e("object"),a=e("function"),s=e=>null==e,n=e=>null!=e,i=e=>n(e)&&(t(e)||a(e)),r=(e,t)=>a(e[t]),o=e=>e.nodeType!==Node.COMMENT_NODE,l=e=>s(e)?[]:[e],c="warn",u="error",d=(e,t,a="debug")=>([u,c].includes(a)&&console[a](t,e),e);let h;const{enqueue:p,cleanup:g}=(()=>{const e=new Map,t=new Map;let a;const s=(e,t)=>{try{e()}catch(e){d(e,t,u)}},n=()=>{a=null;for(const[t,a]of e)for(const[e,n]of a)s(n(t),` Effect ${e} on ${t?.localName||"unknown"} failed`);e.clear();for(const e of t.values())s(e,"Cleanup failed");t.clear()},i=e=>(t,s)=>{const i=!e.has(t);e.set(t,s),i&&(a&&cancelAnimationFrame(a),a=requestAnimationFrame(n))};return queueMicrotask(n),{enqueue:(t,a,s)=>{return i((n=t,e.has(n)||e.set(n,new Map),e.get(n)))(a,s);var n},cleanup:i(t)}})(),m=e=>i(e)&&r(e,"set"),f=e=>m(e)||(e=>i(e)&&r(e,"run")&&"effects"in e)(e),b=e=>{const t=()=>(h&&t.effects.add(h),e);return t.effects=new Set,t.set=s=>{const n=e;e=a(s)&&!f(s)?s(e):s,Object.is(e,n)||(e=>{for(const t of e)t.run()})(t.effects)},t},v=e=>{const t=new Set,s=()=>{const n=h;h=s;const i=e(((e,a,s)=>{p(e,a,s),t.add(e)}));a(i)&&g(s,i),h=n};s.run=()=>s(),s.targets=t,s()},y="context-request";class k extends Event{context;callback;subscribe;constructor(e,t,a=!1){super(y,{bubbles:!0,composed:!0}),this.context=e,this.callback=t,this.subscribe=a}}const x=e=>async t=>{await t.host.constructor.registry.whenDefined(t.target.localName);for(const[s,n]of Object.entries(e))t.target.set(s,f(n)?n:a(n)?b(n):t.host.signal(n));return t},w=(e,t)=>a=>(a.target.addEventListener(e,t),a),F=e=>[n(e[0])],A=e=>e.map((e=>parseInt(e,10))).filter(Number.isFinite),C=(e,t,n,i,r,o)=>(e.host.set(t,a(t)?t:i,!1),v((a=>{if(e.host.has(t)){const i=e.host.get(t);a(e.target,n,s(i)?r:o(i))}})),e),$=e=>t=>{const a=t.target.textContent||"",s=e=>t=>()=>{Array.from(t.childNodes).filter(o).forEach((e=>e.remove())),t.append(document.createTextNode(e))};return C(t,e,"t",a,s(a),s)},E=(e,t=e)=>a=>{const s=t=>a=>()=>a[e]=t;return C(a,t,`p-${String(e)}`,a.target[e],s(null),s)},S=(e,t=e)=>a=>C(a,t,`a-${e}`,a.target.getAttribute(e),(t=>()=>t.removeAttribute(e)),(t=>a=>()=>a.setAttribute(e,t))),M=(e,t=e)=>a=>{const s=t=>a=>()=>a.toggleAttribute(e,t);return C(a,t,`a-${e}`,a.target.hasAttribute(e),s(!1),s)},N=(e,t=e)=>a=>C(a,t,`c-${e}`,a.target.classList.contains(e),(t=>()=>t.classList.remove(e)),(t=>a=>()=>a.classList.toggle(e,t))),L=e=>a(e)?L(e()):e;class _ extends HTMLElement{static registry=customElements;static attributeMap={};static consumedContexts;static providedContexts;static define(e){try{this.registry.get(e)||this.registry.define(e,this)}catch(t){d(e,t.message,u)}}#e=new Map;self=[{host:this,target:this}];root=this.shadowRoot||this;attributeChangedCallback(e,t,s){if(s===t)return;const n=this.constructor.attributeMap[e];this.set(e,a(n)?n(l(s),this,t)[0]:s)}connectedCallback(){(e=>{const t=e.constructor,s=t.consumedContexts||[];for(const t of s)e.set(String(t),void 0,!1);setTimeout((()=>{for(const t of s)e.dispatchEvent(new k(t,(a=>e.set(String(t),a))))}));const n=t.providedContexts||[];n.length&&e.addEventListener(y,(t=>{const{context:s,callback:i}=t;n.includes(s)&&a(i)&&(t.stopPropagation(),i(e.get(String(s))))}))})(this)}disconnectedCallback(){}has(e){return this.#e.has(e)}get(e){return L(this.#e.get(e))}set(e,t,a=!0){if(this.#e.has(e)){if(a){const a=this.#e.get(e);m(a)&&a.set(t)}}else this.#e.set(e,f(t)?t:b(t))}delete(e){return this.#e.delete(e)}signal(e){return this.#e.get(e)}first(e){return l(this.root.querySelector(e)).map((e=>({host:this,target:e})))}all(e){return Array.from(this.root.querySelectorAll(e)).map((e=>({host:this,target:e})))}}var T=function(e){var t=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,a=0,s={},n={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(t){return t instanceof i?new i(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/\u00a0/g," ")},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,"__id",{value:++a}),e.__id},clone:function e(t,a){var s,i;switch(a=a||{},n.util.type(t)){case"Object":if(i=n.util.objId(t),a[i])return a[i];for(var r in s={},a[i]=s,t)t.hasOwnProperty(r)&&(s[r]=e(t[r],a));return s;case"Array":return i=n.util.objId(t),a[i]?a[i]:(s=[],a[i]=s,t.forEach((function(t,n){s[n]=e(t,a)})),s);default:return t}},getLanguage:function(e){for(;e;){var a=t.exec(e.className);if(a)return a[1].toLowerCase();e=e.parentElement}return"none"},setLanguage:function(e,a){e.className=e.className.replace(RegExp(t,"gi"),""),e.classList.add("language-"+a)},currentScript:function(){if("undefined"==typeof document)return null;if("currentScript"in document)return document.currentScript;try{throw new Error}catch(s){var e=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(s.stack)||[])[1];if(e){var t=document.getElementsByTagName("script");for(var a in t)if(t[a].src==e)return t[a]}return null}},isActive:function(e,t,a){for(var s="no-"+t;e;){var n=e.classList;if(n.contains(t))return!0;if(n.contains(s))return!1;e=e.parentElement}return!!a}},languages:{plain:s,plaintext:s,text:s,txt:s,extend:function(e,t){var a=n.util.clone(n.languages[e]);for(var s in t)a[s]=t[s];return a},insertBefore:function(e,t,a,s){var i=(s=s||n.languages)[e],r={};for(var o in i)if(i.hasOwnProperty(o)){if(o==t)for(var l in a)a.hasOwnProperty(l)&&(r[l]=a[l]);a.hasOwnProperty(o)||(r[o]=i[o])}var c=s[e];return s[e]=r,n.languages.DFS(n.languages,(function(t,a){a===c&&t!=e&&(this[t]=r)})),r},DFS:function e(t,a,s,i){i=i||{};var r=n.util.objId;for(var o in t)if(t.hasOwnProperty(o)){a.call(t,o,t[o],s||o);var l=t[o],c=n.util.type(l);"Object"!==c||i[r(l)]?"Array"!==c||i[r(l)]||(i[r(l)]=!0,e(l,a,o,i)):(i[r(l)]=!0,e(l,a,null,i))}}},plugins:{},highlightAll:function(e,t){n.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,a){var s={callback:a,container:e,selector:'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'};n.hooks.run("before-highlightall",s),s.elements=Array.prototype.slice.apply(s.container.querySelectorAll(s.selector)),n.hooks.run("before-all-elements-highlight",s);for(var i,r=0;i=s.elements[r++];)n.highlightElement(i,!0===t,s.callback)},highlightElement:function(t,a,s){var i=n.util.getLanguage(t),r=n.languages[i];n.util.setLanguage(t,i);var o=t.parentElement;o&&"pre"===o.nodeName.toLowerCase()&&n.util.setLanguage(o,i);var l={element:t,language:i,grammar:r,code:t.textContent};function c(e){l.highlightedCode=e,n.hooks.run("before-insert",l),l.element.innerHTML=l.highlightedCode,n.hooks.run("after-highlight",l),n.hooks.run("complete",l),s&&s.call(l.element)}if(n.hooks.run("before-sanity-check",l),(o=l.element.parentElement)&&"pre"===o.nodeName.toLowerCase()&&!o.hasAttribute("tabindex")&&o.setAttribute("tabindex","0"),!l.code)return n.hooks.run("complete",l),void(s&&s.call(l.element));if(n.hooks.run("before-highlight",l),l.grammar)if(a&&e.Worker){var u=new Worker(n.filename);u.onmessage=function(e){c(e.data)},u.postMessage(JSON.stringify({language:l.language,code:l.code,immediateClose:!0}))}else c(n.highlight(l.code,l.grammar,l.language));else c(n.util.encode(l.code))},highlight:function(e,t,a){var s={code:e,grammar:t,language:a};if(n.hooks.run("before-tokenize",s),!s.grammar)throw new Error('The language "'+s.language+'" has no grammar.');return s.tokens=n.tokenize(s.code,s.grammar),n.hooks.run("after-tokenize",s),i.stringify(n.util.encode(s.tokens),s.language)},tokenize:function(e,t){var a=t.rest;if(a){for(var s in a)t[s]=a[s];delete t.rest}var n=new l;return c(n,n.head,e),o(e,n,t,n.head,0),function(e){for(var t=[],a=e.head.next;a!==e.tail;)t.push(a.value),a=a.next;return t}(n)},hooks:{all:{},add:function(e,t){var a=n.hooks.all;a[e]=a[e]||[],a[e].push(t)},run:function(e,t){var a=n.hooks.all[e];if(a&&a.length)for(var s,i=0;s=a[i++];)s(t)}},Token:i};function i(e,t,a,s){this.type=e,this.content=t,this.alias=a,this.length=0|(s||"").length}function r(e,t,a,s){e.lastIndex=t;var n=e.exec(a);if(n&&s&&n[1]){var i=n[1].length;n.index+=i,n[0]=n[0].slice(i)}return n}function o(e,t,a,s,l,d){for(var h in a)if(a.hasOwnProperty(h)&&a[h]){var p=a[h];p=Array.isArray(p)?p:[p];for(var g=0;g<p.length;++g){if(d&&d.cause==h+","+g)return;var m=p[g],f=m.inside,b=!!m.lookbehind,v=!!m.greedy,y=m.alias;if(v&&!m.pattern.global){var k=m.pattern.toString().match(/[imsuy]*$/)[0];m.pattern=RegExp(m.pattern.source,k+"g")}for(var x=m.pattern||m,w=s.next,F=l;w!==t.tail&&!(d&&F>=d.reach);F+=w.value.length,w=w.next){var A=w.value;if(t.length>e.length)return;if(!(A instanceof i)){var C,$=1;if(v){if(!(C=r(x,F,e,b))||C.index>=e.length)break;var E=C.index,S=C.index+C[0].length,M=F;for(M+=w.value.length;E>=M;)M+=(w=w.next).value.length;if(F=M-=w.value.length,w.value instanceof i)continue;for(var N=w;N!==t.tail&&(M<S||"string"==typeof N.value);N=N.next)$++,M+=N.value.length;$--,A=e.slice(F,M),C.index-=F}else if(!(C=r(x,0,A,b)))continue;E=C.index;var L=C[0],_=A.slice(0,E),T=A.slice(E+L.length),j=F+A.length;d&&j>d.reach&&(d.reach=j);var q=w.prev;if(_&&(q=c(t,q,_),F+=_.length),u(t,q,$),w=c(t,q,new i(h,f?n.tokenize(L,f):L,y,L)),T&&c(t,w,T),$>1){var D={cause:h+","+g,reach:j};o(e,t,a,w.prev,F,D),d&&D.reach>d.reach&&(d.reach=D.reach)}}}}}}function l(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function c(e,t,a){var s=t.next,n={value:a,prev:t,next:s};return t.next=n,s.prev=n,e.length++,n}function u(e,t,a){for(var s=t.next,n=0;n<a&&s!==e.tail;n++)s=s.next;t.next=s,s.prev=t,e.length-=n}if(e.Prism=n,i.stringify=function e(t,a){if("string"==typeof t)return t;if(Array.isArray(t)){var s="";return t.forEach((function(t){s+=e(t,a)})),s}var i={type:t.type,content:e(t.content,a),tag:"span",classes:["token",t.type],attributes:{},language:a},r=t.alias;r&&(Array.isArray(r)?Array.prototype.push.apply(i.classes,r):i.classes.push(r)),n.hooks.run("wrap",i);var o="";for(var l in i.attributes)o+=" "+l+'="'+(i.attributes[l]||"").replace(/"/g,"&quot;")+'"';return"<"+i.tag+' class="'+i.classes.join(" ")+'"'+o+">"+i.content+"</"+i.tag+">"},!e.document)return e.addEventListener?(n.disableWorkerMessageHandler||e.addEventListener("message",(function(t){var a=JSON.parse(t.data),s=a.language,i=a.code,r=a.immediateClose;e.postMessage(n.highlight(i,n.languages[s],s)),r&&e.close()}),!1),n):n;var d=n.util.currentScript();function h(){n.manual||n.highlightAll()}if(d&&(n.filename=d.src,d.hasAttribute("data-manual")&&(n.manual=!0)),!n.manual){var p=document.readyState;"loading"===p||"interactive"===p&&d&&d.defer?document.addEventListener("DOMContentLoaded",h):window.requestAnimationFrame?window.requestAnimationFrame(h):window.setTimeout(h,16)}return n}("undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{});"undefined"!=typeof module&&module.exports&&(module.exports=T),"undefined"!=typeof global&&(global.Prism=T),T.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:"attr-equals"},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:"named-entity"},/&#x?[\da-f]{1,8};/i]},T.languages.markup.tag.inside["attr-value"].inside.entity=T.languages.markup.entity,T.languages.markup.doctype.inside["internal-subset"].inside=T.languages.markup,T.hooks.add("wrap",(function(e){"entity"===e.type&&(e.attributes.title=e.content.replace(/&amp;/,"&"))})),Object.defineProperty(T.languages.markup.tag,"addInlined",{value:function(e,t){var a={};a["language-"+t]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:T.languages[t]},a.cdata=/^<!\[CDATA\[|\]\]>$/i;var s={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:a}};s["language-"+t]={pattern:/[\s\S]+/,inside:T.languages[t]};var n={};n[e]={pattern:RegExp("(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[^])*?(?=</__>)".replace(/__/g,(function(){return e})),"i"),lookbehind:!0,greedy:!0,inside:s},T.languages.insertBefore("markup","cdata",n)}}),Object.defineProperty(T.languages.markup.tag,"addAttribute",{value:function(e,t){T.languages.markup.tag.inside["special-attr"].push({pattern:RegExp("(^|[\"'\\s])(?:"+e+")\\s*=\\s*(?:\"[^\"]*\"|'[^']*'|[^\\s'\">=]+(?=[\\s>]))","i"),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,"language-"+t],inside:T.languages[t]},punctuation:[{pattern:/^=/,alias:"attr-equals"},/"|'/]}}}})}}),T.languages.html=T.languages.markup,T.languages.mathml=T.languages.markup,T.languages.svg=T.languages.markup,T.languages.xml=T.languages.extend("markup",{}),T.languages.ssml=T.languages.xml,T.languages.atom=T.languages.xml,T.languages.rss=T.languages.xml,function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp("@[\\w-](?:[^;{\\s\"']|\\s+(?!\\s)|"+t.source+")*?(?:;|(?=\\s*\\{))"),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:"selector"},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp("\\burl\\((?:"+t.source+"|(?:[^\\\\\r\n()\"']|\\\\[^])*)\\)","i"),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp("^"+t.source+"$"),alias:"url"}}},selector:{pattern:RegExp("(^|[{}\\s])[^{}\\s](?:[^{};\"'\\s]|\\s+(?![\\s{])|"+t.source+")*(?=\\s*\\{)"),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var a=e.languages.markup;a&&(a.tag.addInlined("style","css"),a.tag.addAttribute("style","css"))}(T),T.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},T.languages.javascript=T.languages.extend("clike",{"class-name":[T.languages.clike["class-name"],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp("(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])"),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),T.languages.javascript["class-name"][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,T.languages.insertBefore("javascript","keyword",{regex:{pattern:RegExp("((?:^|[^$\\w\\xA0-\\uFFFF.\"'\\])\\s]|\\b(?:return|yield))\\s*)/(?:(?:\\[(?:[^\\]\\\\\r\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.|\\[(?:[^[\\]\\\\\r\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\r\n])+/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|/\\*(?:[^*]|\\*(?!/))*\\*/)*(?:$|[\r\n,.;:})\\]]|//))"),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:"language-regex",inside:T.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:"function"},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:T.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:T.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:T.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:T.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),T.languages.insertBefore("javascript","string",{hashbang:{pattern:/^#!.*/,greedy:!0,alias:"comment"},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:"string"},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"},rest:T.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:"property"}}),T.languages.insertBefore("javascript","operator",{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:"property"}}),T.languages.markup&&(T.languages.markup.tag.addInlined("script","javascript"),T.languages.markup.tag.addAttribute("on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)","javascript")),T.languages.js=T.languages.javascript;(class extends _{static observedAttributes=["count"];static attributeMap={count:A};connectedCallback(){this.set("parity",(()=>this.get("count")%2?"odd":"even")),this.first(".increment").map(w("click",(()=>this.set("count",(e=>++e))))),this.first(".decrement").map(w("click",(()=>this.set("count",(e=>--e))))),this.first(".count").map($("count")),this.first(".parity").map($("parity"))}}).define("my-counter");(class extends _{static observedAttributes=["collapsed"];static attributeMap={collapsed:F};connectedCallback(){const e=this.getAttribute("language")||"html",t=this.querySelector("code");this.set("code",t.textContent.trim(),!1),v((a=>{const s=document.createElement("code");s.innerHTML=T.highlight(this.get("code"),T.languages[e],e),a(t,"h",(e=>()=>{Array.from(e.childNodes).filter((e=>e.nodeType!==Node.COMMENT_NODE)).forEach((e=>e.remove())),Array.from(s.childNodes).forEach((t=>e.appendChild(t)))}))})),this.first(".copy").map((e=>w("click",(async()=>{const a=e.target,s=a.textContent;let n="success";try{await navigator.clipboard.writeText(t.textContent)}catch(e){console.error("Error when trying to use navigator.clipboard.writeText()",e),n="error"}a.set("disabled",!0),a.set("label",e.host.getAttribute(`copy-${n}`)),setTimeout((()=>{a.set("disabled",!1),a.set("label",s)}),"success"===n?1e3:3e3)}))(e))),this.first(".overlay").map(w("click",(()=>this.set("collapsed",!1)))),this.self.map(M("collapsed"))}}).define("code-block");(class extends _{static observedAttributes=["accordion"];static attributeMap={accordion:F};static consumedContexts=["media-viewport"];connectedCallback(){super.connectedCallback(),this.set("active",0,!1),setTimeout((()=>{this.get("media-viewport")&&this.set("accordion",(()=>["xs","sm"].includes(this.get("media-viewport"))))}),0),this.self.map(M("accordion")),this.first(".tab-nav").map(E("ariaHidden","accordion")),this.all(".tab-nav button").map(((e,t)=>E("ariaPressed",(()=>this.get("active")===t))(e))).map(((e,t)=>w("click",(()=>this.set("active",t)))(e))),this.all("accordion-panel").map(((e,t)=>x({open:()=>e.host.get("active")===t,collapsible:"accordion"})(e)))}}).define("tab-list");(class extends _{connectedCallback(){this.set("open",this.hasAttribute("open")),this.set("collapsible",this.hasAttribute("collapsible")),this.self.map(M("open")).map(M("collapsible")).map(E("ariaHidden",(()=>!this.get("open")&&!this.get("collapsible")))),this.first("details").map(E("open")).map(E("ariaDisabled",(()=>!this.get("collapsible"))))}}).define("accordion-panel");(class extends _{static observedAttributes=["disabled"];static attributeMap={disabled:F};connectedCallback(){this.first("button").map($("label")).map(E("disabled"))}}).define("input-button");const j=e=>"number"==typeof e,q=(e,t=!1)=>t?parseInt(e,10):parseFloat(e);(class extends _{static observedAttributes=["value","description"];static attributeMap={value:e=>this.isNumber?e.map((e=>q(e,this.isInteger))).filter(Number.isFinite):e};connectedCallback(){this.input=this.querySelector("input"),this.isNumber=this.input&&"number"===this.input.type,this.isInteger=this.hasAttribute("integer"),this.set("value",this.isNumber?this.input.valueAsNumber:this.input.value,!1),this.set("length",this.input.value.length),this.set("empty",(()=>!this.get("length"))),this.#t(),this.#a(),this.#s(),this.#n(),this.input.onchange=()=>this.#i(this.isNumber?this.input.valueAsNumber:this.input.value),this.input.oninput=()=>this.set("length",this.input.value.length),v((async()=>{const e=this.get("value"),t=this.getAttribute("validate");if(e&&t&&await fetch(`${t}?name=${this.input.name}value=${this.input.value}`).then((async e=>{const t=await e.text();this.input.setCustomValidity(t),this.set("error",t)})).catch((e=>this.set("error",e.message))),this.isNumber&&!j(e))return this.set("value",q(e,this.isInteger));this.isNumber&&!Number.isNaN(e)&&(this.input.value=e)}))}clear(){this.input.value="",this.set("value",""),this.set("length",0),this.input.focus()}#i=e=>{this.set("value",e),this.set("error",this.input.validationMessage),"function"==typeof e&&(e=this.get("value")),this.input.value!==String(e)&&this.dispatchEvent(new CustomEvent("value-change",{detail:e,bubbles:!0}))};#t(){const e=this.first(".error");this.set("ariaInvalid",(()=>String(Boolean(this.get("error"))))),this.set("aria-errormessage",(()=>this.get("error")?e[0]?.target.id:void 0)),e.map($("error")),this.first("input").map(E("ariaInvalid")).map(S("aria-errormessage"))}#a(){const e=this.first(".description");if(!e[0])return;const t=this.first("input"),a=this.input.maxLength,s=a&&e[0].target.dataset.remaining,n=e[0].target.textContent;this.set("description",s?()=>{const e=this.get("length");return e>0?s.replace("${x}",a-e):n}:n),this.set("aria-describedby",(()=>this.get("description")?e[0].target.id:void 0)),e.forEach($("description")),t.forEach(S("aria-describedby"))}#s(){const e=this.querySelector(".spinbutton");if(!this.isNumber||!e)return;const t=e=>l(q(this.input[e],this.isInteger)).filter(Number.isFinite)[0],a=q(e.dataset.step,this.isInteger),[s,n,i]=Number.isFinite(a)?[a,t("min"),t("max")]:[],r=e=>{const t=Math.round((i-n)/s);let a=Math.round((e-n)*t/(i-n))/t;a=Math.min(Math.max(a,0),1);const r=a*(i-n)+n;return this.isInteger?Math.round(r):r};this.stepDown=(e=s)=>this.#i((t=>r(t-e))),this.stepUp=(e=s)=>this.#i((t=>r(t+e))),this.set("decrement-disabled",(()=>j(n)&&this.get("value")-s<n)),this.set("increment-disabled",(()=>j(i)&&this.get("value")+s>i)),this.first(".decrement").map(E("disabled","decrement-disabled")).forEach(w("click",(e=>this.stepDown(e.shiftKey?10*s:s)))),this.first(".increment").map(E("disabled","increment-disabled")).forEach(w("click",(e=>this.stepUp(e.shiftKey?10*s:s)))),this.input.onkeydown=e=>{["ArrowUp","ArrowDown"].includes(e.key)&&(e.stopPropagation(),e.preventDefault(),"ArrowDown"===e.key&&this.stepDown(e.shiftKey?10*s:s),"ArrowUp"===e.key&&this.stepUp(e.shiftKey?10*s:s))}}#n(){this.first(".clear").map(N("hidden","empty")).forEach(w("click",(()=>{this.clear(),this.input.focus()})))}}).define("input-field");(class extends _{static observedAttributes=["checked"];static attributeMap={checked:F};connectedCallback(){this.first("input").map(w("change",(e=>this.set("checked",Boolean(e.target.checked))))).map(E("checked")),this.self.map(M("checked"))}}).define("input-checkbox");class D extends _{static observedAttributes=["value"];connectedCallback(){this.self.map(S("value")),this.all("input").map(w("change",(e=>this.set("value",e.target.value)))),this.all("label").map((e=>N("selected",(()=>e.host.get("value")===e.target.querySelector("input").value))(e)))}}D.define("input-radiogroup");(class extends _{connectedCallback(){this.set("error",""),this.set("content",(()=>{fetch(this.getAttribute("src")).then((async e=>e.ok?this.set("content",await e.text()):this.set("error",e.statusText))).catch((e=>this.set("error",e)))}));const e=this.querySelector(".loading"),t=this.querySelector(".error");v((a=>{const s=this.get("error");s&&t&&(e&&a(e,"r",(e=>()=>e.remove())),a(t,"t",(e=>()=>e.textContent=s)))})),v((a=>{const s=this.get("content");s&&(this.root=this.shadowRoot||this.attachShadow({mode:"open"}),a(this.root,"h",(e=>()=>{e.innerHTML=s,e.querySelectorAll("script").forEach((t=>{const a=document.createElement("script");a.appendChild(document.createTextNode(t.textContent)),e.appendChild(a),t.remove()}))})),e&&a(e,"r",(e=>()=>e.remove())),t&&a(t,"r",(e=>()=>e.remove())))}))}}).define("lazy-load");const O="media-motion",I="media-theme",z="media-viewport",P="media-orientation";(class extends _{static providedContexts=[O,I,z,P];connectedCallback(){super.connectedCallback();const e="light",t="dark",a="landscape",s="portrait",n=(()=>{const e=e=>{const t=this.getAttribute(e)?.trim();if(!t)return null;const a=t.match(/em$/)?"em":"px",s=l(parseFloat(t)).filter(Number.isFinite)[0];return s?s+a:null};return{sm:e("sm")||"32em",md:e("md")||"48em",lg:e("lg")||"72em",xl:e("xl")||"108em"}})(),i=matchMedia("(prefers-reduced-motion: reduce)"),r=matchMedia("(prefers-color-scheme: dark)"),o=matchMedia(`(min-width: ${n.sm})`),c=matchMedia(`(min-width: ${n.md})`),u=matchMedia(`(min-width: ${n.lg})`),d=matchMedia(`(min-width: ${n.xl})`),h=matchMedia("(orientation: landscape)"),p=()=>d.matches?"xl":u.matches?"lg":c.matches?"md":o.matches?"sm":"xs";this.set(O,i.matches),this.set(I,r.matches?t:e),this.set(z,p()),this.set(P,h.matches?a:s),i.addEventListener("change",(e=>this.set(O,e.matches))),r.addEventListener("change",(a=>this.set(I,a.matches?t:e))),o.addEventListener("change",(()=>this.set(z,p()))),c.addEventListener("change",(()=>this.set(z,p()))),u.addEventListener("change",(()=>this.set(z,p()))),d.addEventListener("change",(()=>this.set(z,p()))),h.addEventListener("change",(e=>this.set(I,e.matches?a:s)))}}).define("media-context");(class extends _{connectedCallback(){const e=this.querySelector("input-field");this.first("form").map(w("submit",(t=>{t.preventDefault(),setTimeout((()=>{this.dispatchEvent(new CustomEvent("add-todo",{bubbles:!0,detail:e.get("value")})),e.clear()}),0)}))),this.first("input-button").map(x({disabled:()=>e.get("empty")}))}}).define("todo-form");(class extends _{connectedCallback(){const[e,t]=["todo-list","input-radiogroup"].map((e=>this.querySelector(e)));this.self.map(w("add-todo",(t=>e?.addItem(t.detail)))),this.first("todo-count").map(x({active:()=>e?.get("count").active})),this.first("todo-list").map(x({filter:()=>t?.get("value")})),this.first(".clear-completed").map(w("click",(()=>e?.clearCompleted()))).map(x({disabled:()=>!e?.get("count").completed}))}}).define("todo-app");(class extends _{connectedCallback(){this.set("active",0,!1),this.first(".count").map($("active")),this.first(".singular").map(E("ariaHidden",(()=>this.get("active")>1))),this.first(".plural").map(E("ariaHidden",(()=>1===this.get("active")))),this.first(".remaining").map(E("ariaHidden",(()=>!this.get("active")))),this.first(".all-done").map(E("ariaHidden",(()=>!!this.get("active"))))}}).define("todo-count");(class extends _{connectedCallback(){this.set("filter","all"),this.#r(),this.self.map(w("click",(e=>{"button"===e.target.localName&&this.removeItem(e.target)}))).map(S("filter")),this.set("count",(()=>{const e=this.get("tasks").map((e=>e.signal("checked"))),t=e.filter((e=>e())).length,a=e.length;return{active:a-t,completed:t,total:a}}))}addItem=e=>{const t=this.querySelector("template").content.cloneNode(!0);t.querySelector("span").textContent=e,this.querySelector("ol").appendChild(t),this.#r()};removeItem=e=>{e.closest("li").remove(),this.#r()};clearCompleted=()=>{this.get("tasks").filter((e=>e.get("checked"))).forEach((e=>e.parentElement.remove())),this.#r()};#r(){this.set("tasks",Array.from(this.querySelectorAll("input-checkbox")))}}).define("todo-list");export{D as InputRadiogroup};