drab 5.3.3 → 5.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/define.iife.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";(()=>{var W=Object.defineProperty;var I=(o,t)=>{for(var e in t)W(o,e,{get:t[e],enumerable:!0})};var H={};I(H,{Animate:()=>p,Base:()=>c,Breakpoint:()=>d,ContextMenu:()=>g,Copy:()=>b,Details:()=>y,Dialog:()=>A,Editor:()=>x,Fullscreen:()=>v,Intersect:()=>w,Popover:()=>E,Prefetch:()=>T,Share:()=>L,TableSort:()=>C,WakeLock:()=>M,YouTube:()=>S});var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let s=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(s){let i=Array.from(this.getContent().childNodes),r=[];s instanceof HTMLTemplateElement?(r.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(r.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...r),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,s=document.body,i={}){i.signal=this.#t.signal,s.addEventListener(t,e,i)}triggerListener(t,e=this.event,s){for(let i of this.getTrigger())i.addEventListener(e,t,s)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var p=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let s=this.getAttribute(e),[,,i]=e.split("-");s&&(i==="duration"||i==="delay"?t[i]=Number(s):i==="easing"&&(t[i]=s))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:s={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){s=Object.assign(this.animationOptions,s),s.duration||(s.duration=200),s.easing||(s.easing="ease-in-out");let r=i.at(0),n=i.at(-1);if(r&&n){let u=["composite","easing","offset"];for(let l of u)delete r[l],delete n[l]}s.direction?.includes("reverse")&&([r,n]=[n,r]),Object.assign(e.style,r),await e.animate(i,s).finished,Object.assign(e.style,n)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let n=r.map((a,u)=>u<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(i&&n){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let a=Number(i),u=t.find(l=>l.offset===a);u?u[n]=s:t.push({[n]:s,offset:a})}}}return t.sort((e,s)=>Number(e.offset)-Number(s.offset)),t}};var d=class extends c{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...s]=e.split("-");s&&t.push({name:s.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,s)=>s.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};var g=class extends p{#t;constructor(){super()}set#s(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,s=window.scrollX,i=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,n=i+s,a=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;n+u>s+h&&(n=s+h-u),a+l>e+m&&(a=e+m-l),this.#s={x:n,y:a},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart",{passive:!0});let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend",{passive:!0}),this.triggerListener(t,"touchcancel",{passive:!0}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends c{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(t){this.setAttribute("value",t)}async copy(t=this.value){await navigator.clipboard.writeText(t),this.swapContent()}};var b=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var y=class extends p{constructor(){super()}get details(){let t=this.getContent(HTMLElement).parentElement;if(!(t instanceof HTMLDetailsElement))throw new Error("Details: HTMLDetailsElement not found.");return t}async open(){this.details.open=!0,await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.details.open=!1}toggle(){this.details.open?this.close():this.open()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()})}};var A=class extends p{constructor(){super()}get dialog(){return this.getContent(HTMLDialogElement)}async show(){this.dialog.showModal(),await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.dialog.close()}async toggle(){this.dialog.open?this.close():this.show()}mount(){this.triggerListener(()=>this.toggle()),this.safeListener("keydown",t=>{t.key==="Escape"&&this.dialog.open&&(t.preventDefault(),this.close())}),this.hasAttribute("click-outside-close")&&this.dialog.addEventListener("click",t=>{let e=this.dialog.getBoundingClientRect();(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this.close()})}};var x=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#s)t.type==="wrap"&&(this.keyPairs[t.value]=t.value)}get textArea(){return this.getContent(HTMLTextAreaElement)}get text(){return this.textArea.value}set text(t){this.textArea.value=t}get#s(){let t=[];for(let e of this.getTrigger())t.push(this.#l(e));return t}get#n(){let t=this.text.split("```"),e=0;for(let[s,i]of t.entries())if(e+=i.length+3,this.#i<e)return s;return 0}get#e(){return this.textArea.selectionEnd}get#i(){return this.textArea.selectionStart}#r(t,e){this.textArea.setSelectionRange(t,e)}#l(t){let e=t.dataset.type,s=t.dataset.value,i=t.dataset.key??void 0;return{type:e,value:s,key:i}}async#c(t,e,s){if(t.type==="inline")this.text=`${this.text.slice(0,s)}${t.value}${this.text.slice(s)}`;else if(t.type==="wrap")this.text=B(this.text,t.value,e),this.text=B(this.text,this.keyPairs[t.value],s+t.value.length),t.value.length<2&&this.#t.push(t.value);else if(t.type==="block"){let{lines:i,lineNumber:r}=this.#a(),n=t.value.at(0);n&&i[r]?.startsWith(n)?i[r]=t.value.trim()+i[r]:i[r]=t.value+i[r],this.text=i.join(`
2
- `)}}async#h(t,e,s){let i=0,r=0;if(/[a-z]/i.test(t)){for(let n=s;n<this.text.length;n++)if(this.text[n]?.match(/[a-z]/i))i?r=n+1:i=n;else if(i)break}else i=e+t.length,r=s+t.length;this.#r(i,r),this.textArea.focus()}async#o(t){let e=this.#e,s=this.#i;await this.#c(t,s,e),this.#h(t.value,s,e)}#p(t){if(t){let e=[];this.#s.forEach(i=>{i.type==="block"&&e.push(i.value)});for(let i=0;i<e.length;i++){let r=e[i];if(r&&t.startsWith(r))return r}let s=P(t);if(s)return`${s}. `}return""}#a(){let t=this.text.split(`
3
- `),e=0;for(let s=0;s<t.length;s++){let i=t.at(s)?.length??0;if(e++,e+=i,e>this.#e)return{lines:t,lineNumber:s,columnNumber:this.#e-(e-i-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#u(t,e=!1){let{lines:s}=this.#a();for(let i=t+1;i<s.length;i++){let r=s[i];if(r){let n=P(r);if(n){let a;if(e)if(n>1)a=n-1;else break;else a=n+1;s[i]=r.slice(String(n).length),s[i]=String(a)+s[i]}else break}}this.text=s.join(`
4
- `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],s=this.text[this.#e]??"";if(e.includes(t.key))this.#t=[];else if(t.key==="Backspace"){let i=this.text[this.#i-1];if(i&&i in this.keyPairs&&s===this.keyPairs[i]){t.preventDefault();let r=this.#i-1,n=this.#e-1;this.text=k(this.text,r),this.text=k(this.text,n),setTimeout(()=>{this.#r(r,n)},0),this.#t.pop()}if(i===`
5
- `&&this.#i===this.#e){t.preventDefault();let r=this.#i-1,{lineNumber:n}=this.#a();this.#u(n,!0),this.text=k(this.text,r),setTimeout(async()=>{this.#r(r,r)},0)}}else if(t.key==="Tab")this.#n%2!==0&&(t.preventDefault(),await this.#o({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:i,lineNumber:r,columnNumber:n}=this.#a(),a=i.at(r),u=this.#p(a),l=u,h=P(u);if(h&&(u=`${h+1}. `),u&&l.length<n)t.preventDefault(),h&&this.#u(r),await this.#o({type:"inline",value:`
1
+ "use strict";(()=>{var W=Object.defineProperty;var I=(o,t)=>{for(var e in t)W(o,e,{get:t[e],enumerable:!0})};var H={};I(H,{Animate:()=>p,Base:()=>c,Breakpoint:()=>d,ContextMenu:()=>g,Copy:()=>b,Details:()=>y,Dialog:()=>A,Editor:()=>x,Fullscreen:()=>v,Intersect:()=>w,Popover:()=>E,Prefetch:()=>T,Share:()=>L,TableSort:()=>C,WakeLock:()=>M,YouTube:()=>S});var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let i=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(i){let s=Array.from(this.getContent().childNodes),r=[];i instanceof HTMLTemplateElement?(r.push(i.content.cloneNode(!0)),i.content.replaceChildren(...s)):(r.push(...i.childNodes),i.replaceChildren(...s)),this.getContent().replaceChildren(...r),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,i=document.body,s={}){s.signal=this.#t.signal,i.addEventListener(t,e,s)}triggerListener(t,e=this.event,i){for(let s of this.getTrigger())s.addEventListener(e,t,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var p=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let i=this.getAttribute(e),[,,s]=e.split("-");i&&(s==="duration"||s==="delay"?t[s]=Number(i):s==="easing"&&(t[s]=i))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:i={}}=t,s=this.keyframes;if(s.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){i=Object.assign(this.animationOptions,i),i.duration||(i.duration=200),i.easing||(i.easing="ease-in-out");let r=s.at(0),n=s.at(-1);if(r&&n){let u=["composite","easing","offset"];for(let l of u)delete r[l],delete n[l]}i.direction?.includes("reverse")&&([r,n]=[n,r]),Object.assign(e.style,r),await e.animate(s,i).finished,Object.assign(e.style,n)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let i=this.getAttribute(e),[,,s,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let n=r.map((a,u)=>u<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(s&&n){s==="from"?s="0":s==="to"?s="1":s=String(parseInt(s)*.01);let a=Number(s),u=t.find(l=>l.offset===a);u?u[n]=i:t.push({[n]:i,offset:a})}}}return t.sort((e,i)=>Number(e.offset)-Number(i.offset)),t}};var d=class extends c{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...i]=e.split("-");i&&t.push({name:i.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,i)=>i.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};var g=class extends p{#t;constructor(){super()}set#s(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,i=window.scrollX,s=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,n=s+i,a=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;n+u>i+h&&(n=i+h-u),a+l>e+m&&(a=e+m-l),this.#s={x:n,y:a},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart",{passive:!0});let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend",{passive:!0}),this.triggerListener(t,"touchcancel",{passive:!0}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends c{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(t){this.setAttribute("value",t)}async copy(t=this.value){await navigator.clipboard.writeText(t),this.swapContent()}};var b=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var y=class extends p{constructor(){super()}get details(){let t=this.getContent(HTMLElement).parentElement;if(!(t instanceof HTMLDetailsElement))throw new Error("Details: HTMLDetailsElement not found.");return t}async open(){this.details.open=!0,await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.details.open=!1}toggle(){this.details.open?this.close():this.open()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()})}};var A=class extends p{constructor(){super()}get dialog(){return this.getContent(HTMLDialogElement)}async show(){this.dialog.showModal(),await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.dialog.close()}async toggle(){this.dialog.open?this.close():this.show()}mount(){this.triggerListener(()=>this.toggle()),this.safeListener("keydown",t=>{t.key==="Escape"&&this.dialog.open&&(t.preventDefault(),this.close())}),this.hasAttribute("click-outside-close")&&this.dialog.addEventListener("click",t=>{let e=this.dialog.getBoundingClientRect();(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this.close()})}};var x=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#s)t.type==="wrap"&&(this.keyPairs[t.value]=t.value)}get textArea(){return this.getContent(HTMLTextAreaElement)}get text(){return this.textArea.value}set text(t){this.textArea.value=t}get#s(){let t=[];for(let e of this.getTrigger())t.push(this.#l(e));return t}get#n(){let t=this.text.split("```"),e=0;for(let[i,s]of t.entries())if(e+=s.length+3,this.#i<e)return i;return 0}get#e(){return this.textArea.selectionEnd}get#i(){return this.textArea.selectionStart}#r(t,e){this.textArea.setSelectionRange(t,e)}#l(t){let e=t.dataset.type,i=t.dataset.value,s=t.dataset.key??void 0;return{type:e,value:i,key:s}}async#c(t,e,i){if(t.type==="inline")this.text=`${this.text.slice(0,i)}${t.value}${this.text.slice(i)}`;else if(t.type==="wrap")this.text=B(this.text,t.value,e),this.text=B(this.text,this.keyPairs[t.value],i+t.value.length),t.value.length<2&&this.#t.push(t.value);else if(t.type==="block"){let{lines:s,lineNumber:r}=this.#a(),n=t.value.at(0);n&&s[r]?.startsWith(n)?s[r]=t.value.trim()+s[r]:s[r]=t.value+s[r],this.text=s.join(`
2
+ `)}}async#h(t,e,i){let s=0,r=0;if(/[a-z]/i.test(t)){for(let n=i;n<this.text.length;n++)if(this.text[n]?.match(/[a-z]/i))s?r=n+1:s=n;else if(s)break}else s=e+t.length,r=i+t.length;this.#r(s,r),this.textArea.focus()}async#o(t){let e=this.#e,i=this.#i;await this.#c(t,i,e),this.#h(t.value,i,e)}#p(t){if(t){let e=[];this.#s.forEach(s=>{s.type==="block"&&e.push(s.value)});for(let s=0;s<e.length;s++){let r=e[s];if(r&&t.startsWith(r))return r}let i=P(t);if(i)return`${i}. `}return""}#a(){let t=this.text.split(`
3
+ `),e=0;for(let i=0;i<t.length;i++){let s=t.at(i)?.length??0;if(e++,e+=s,e>this.#e)return{lines:t,lineNumber:i,columnNumber:this.#e-(e-s-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#u(t,e=!1){let{lines:i}=this.#a();for(let s=t+1;s<i.length;s++){let r=i[s];if(r){let n=P(r);if(n){let a;if(e)if(n>1)a=n-1;else break;else a=n+1;i[s]=r.slice(String(n).length),i[s]=String(a)+i[s]}else break}}this.text=i.join(`
4
+ `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],i=this.text[this.#e]??"";if(e.includes(t.key))this.#t=[];else if(t.key==="Backspace"){let s=this.text[this.#i-1];if(s&&s in this.keyPairs&&i===this.keyPairs[s]){t.preventDefault();let r=this.#i-1,n=this.#e-1;this.text=k(this.text,r),this.text=k(this.text,n),setTimeout(()=>{this.#r(r,n)},0),this.#t.pop()}if(s===`
5
+ `&&this.#i===this.#e){t.preventDefault();let r=this.#i-1,{lineNumber:n}=this.#a();this.#u(n,!0),this.text=k(this.text,r),setTimeout(async()=>{this.#r(r,r)},0)}}else if(t.key==="Tab")this.#n%2!==0&&(t.preventDefault(),await this.#o({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:s,lineNumber:r,columnNumber:n}=this.#a(),a=s.at(r),u=this.#p(a),l=u,h=P(u);if(h&&(u=`${h+1}. `),u&&l.length<n)t.preventDefault(),h&&this.#u(r),await this.#o({type:"inline",value:`
6
6
  ${u}`});else if(u&&l.length===n){t.preventDefault();let m=this.#e,N=m-l.length;for(let D=0;D<l.length;D++)this.text=k(this.text,m-(D+1));setTimeout(async()=>{this.#r(N,N),this.textArea.focus(),await this.#o({type:"inline",value:`
7
- `})},0)}}else{let i=Object.values(this.keyPairs).includes(s),r=this.#i!==this.#e;if((t.ctrlKey||t.metaKey)&&this.#i===this.#e&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:n,lineNumber:a,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${a===0&&t.key==="x"?"":`
7
+ `})},0)}}else{let s=Object.values(this.keyPairs).includes(i),r=this.#i!==this.#e;if((t.ctrlKey||t.metaKey)&&this.#i===this.#e&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:n,lineNumber:a,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${a===0&&t.key==="x"?"":`
8
8
  `}${n[a]}`),t.key==="x"){let l=this.#i-u;n.splice(a,1),this.text=n.join(`
9
- `),setTimeout(()=>{this.#r(l,l)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let n=this.#s.find(a=>a.key===t.key);n&&this.#o(n)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!r?(t.preventDefault(),this.#r(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#o({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#r(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},P=o=>{let t=o.match(/^(\d+)\./);return t?Number(t[1]):null},B=(o,t,e)=>o.slice(0,e)+t+o.slice(e),k=(o,t)=>o.slice(0,t)+o.slice(t+1);var v=class extends c{constructor(){super()}isFullscreen(){return document.fullscreenElement!==null}fullscreenSupported(){return!!document.documentElement.requestFullscreen}toggle(){if(this.isFullscreen())document.exitFullscreen();else try{this.getContent(HTMLElement).requestFullscreen()}catch{document.documentElement.requestFullscreen()}}mount(){this.triggerListener(()=>this.toggle());for(let t of this.getTrigger())!this.fullscreenSupported()&&"disabled"in t&&(t.disabled=!0)}};var w=class extends c{#t=[];#s=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#s.push(t)}mount(){let t=new IntersectionObserver(e=>{let s="data-intersect";for(let i of e)if(i.isIntersecting){this.getContent().setAttribute(s,"");for(let r of this.#t)r()}else{this.getContent().removeAttribute(s);for(let r of this.#s)r()}},{threshold:this.#n});for(let e of this.getTrigger())t.observe(e)}};var E=class extends p{constructor(){super()}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}async show(){this.getContent().showPopover(),await this.animateElement()}async hide(){await this.animateElement({options:{direction:"reverse"}}),this.getContent().hidePopover()}async toggle(){this.open?this.hide():this.show()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",t=>{t.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",t=>{t.key==="Escape"&&this.open&&(t.preventDefault(),this.hide())})}};var T=class extends c{#t=[];constructor(){super()}get#s(){return this.getAttribute("strategy")??"hover"}get#n(){return this.hasAttribute("prerender")}get#e(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!this.#t.includes(e)){if(HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({[s?"prerender":"prefetch"]:[{source:"list",urls:[e]}]}),document.head.append(r)}else fetch(e,{priority:"low"}).catch(r=>console.error(r));this.#t.push(e)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#n,strategy:this.#s}){let{anchors:e=this.getTrigger(),prerender:s=this.#n,strategy:i=this.#s}=t,r,n=(l=200)=>h=>{let{href:m}=h.currentTarget;r=setTimeout(()=>this.appendTag({url:m,prerender:s}),l)},a=()=>clearTimeout(r),u=new IntersectionObserver(l=>{for(let h of l)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:s})});for(let l of e)i==="load"?this.appendTag({url:l.href,prerender:s}):i==="visible"?u.observe(l):(l.addEventListener("mouseover",n()),l.addEventListener("mouseout",a),l.addEventListener("focus",n()),l.addEventListener("focusout",a),l.addEventListener("touchstart",n(0),{passive:!0}))}mount(){this.#e&&this.appendTag({url:this.#e,prerender:this.#n}),this.prefetch()}};var L=class extends f{constructor(){super()}async share(t=this.value){if(navigator.canShare&&navigator.canShare({url:t}))try{await navigator.share({url:t})}catch(e){e?.name!=="AbortError"&&console.error(e)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};var C=class extends c{constructor(){super()}#t(t){let e="data-asc",s="data-desc";for(let i of this.getTrigger())i!==t&&(i.removeAttribute(e),i.removeAttribute(s));return t.hasAttribute(e)?(t.removeAttribute(e),t.setAttribute(s,""),!1):(t.removeAttribute(s),t.setAttribute(e,""),!0)}mount(){let t=this.getContent(HTMLTableSectionElement);for(let e of this.getTrigger())e.addEventListener(this.event,()=>{Array.from(t.querySelectorAll("tr")).sort(K(e,this.#t(e))).forEach(s=>t.appendChild(s))})}},K=(o,t)=>(s,i)=>{let r=Array.from(o.parentNode?.children??[]).indexOf(o);return((a,u)=>{let l=o.dataset.type??"string";if(l==="string")return new Intl.Collator().compare(a,u);if(l==="boolean"){let h=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return h(a)===h(u)?0:h(a)?-1:1}else return Number(a)-Number(u)})(j(t?s:i,r),j(t?i:s,r))},j=(o,t)=>{let e=o.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var M=class extends c{wakeLock=null;constructor(){super()}#t(){return"wakeLock"in navigator}get#s(){return this.hasAttribute("auto-lock")}async request(){this.#t()&&document.visibilityState==="visible"&&(this.wakeLock=await navigator.wakeLock.request("screen"),this.setAttribute("locked",""),this.swapContent(!1),this.wakeLock.addEventListener("release",()=>{this.removeAttribute("locked"),this.swapContent(!1),this.#s||(this.wakeLock=null)}))}async release(){await this.wakeLock?.release(),this.wakeLock=null}mount(){this.hasAttribute("locked")&&this.request(),this.triggerListener(()=>{this.wakeLock?this.release():this.request()});for(let t of this.getTrigger())!this.#t()&&"disabled"in t&&(t.disabled=!0);this.#s&&this.safeListener("visibilitychange",()=>{this.wakeLock&&this.request()},document)}destroy(){this.release()}};var S=class extends c{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};for(let o in H)customElements.define(`drab-${o.toLowerCase()}`,H[o]);})();
9
+ `),setTimeout(()=>{this.#r(l,l)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let n=this.#s.find(a=>a.key===t.key);n&&this.#o(n)}else s&&(i===t.key||t.key==="ArrowRight")&&this.#t.length&&!r?(t.preventDefault(),this.#r(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#o({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#r(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},P=o=>{let t=o.match(/^(\d+)\./);return t?Number(t[1]):null},B=(o,t,e)=>o.slice(0,e)+t+o.slice(e),k=(o,t)=>o.slice(0,t)+o.slice(t+1);var v=class extends c{constructor(){super()}isFullscreen(){return document.fullscreenElement!==null}fullscreenSupported(){return!!document.documentElement.requestFullscreen}toggle(){if(this.isFullscreen())document.exitFullscreen();else try{this.getContent(HTMLElement).requestFullscreen()}catch{document.documentElement.requestFullscreen()}}mount(){this.triggerListener(()=>this.toggle());for(let t of this.getTrigger())!this.fullscreenSupported()&&"disabled"in t&&(t.disabled=!0)}};var w=class extends c{#t=[];#s=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#s.push(t)}mount(){let t=new IntersectionObserver(e=>{let i="data-intersect";for(let s of e)if(s.isIntersecting){this.getContent().setAttribute(i,"");for(let r of this.#t)r()}else{this.getContent().removeAttribute(i);for(let r of this.#s)r()}},{threshold:this.#n});for(let e of this.getTrigger())t.observe(e)}};var E=class extends p{constructor(){super()}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}async show(){this.getContent().showPopover(),await this.animateElement()}async hide(){await this.animateElement({options:{direction:"reverse"}}),this.getContent().hidePopover()}async toggle(){this.open?this.hide():this.show()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",t=>{t.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",t=>{t.key==="Escape"&&this.open&&(t.preventDefault(),this.hide())})}};var T=class extends c{#t=[];constructor(){super()}get#s(){return this.getAttribute("strategy")??"hover"}get#n(){return this.hasAttribute("prerender")}get#e(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:i}=t;if(e!==window.location.href&&!this.#t.includes(e)){this.#t.push(e);let s=document.createElement("link");if(s.rel="prefetch",s.as="document",s.href=e,document.head.append(s),i){let r=document.createElement("script");r.type="speculationrules",r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#n,strategy:this.#s}){let{anchors:e=this.getTrigger(),prerender:i=this.#n,strategy:s=this.#s}=t,r,n=(l=200)=>h=>{let{href:m}=h.currentTarget;r=setTimeout(()=>this.appendTag({url:m,prerender:i}),l)},a=()=>clearTimeout(r),u=new IntersectionObserver(l=>{for(let h of l)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:i})});for(let l of e)s==="load"?this.appendTag({url:l.href,prerender:i}):s==="visible"?u.observe(l):(l.addEventListener("mouseover",n()),l.addEventListener("mouseout",a),l.addEventListener("focus",n()),l.addEventListener("focusout",a),l.addEventListener("touchstart",n(0),{passive:!0}))}mount(){this.#e&&this.appendTag({url:this.#e,prerender:this.#n}),this.prefetch()}};var L=class extends f{constructor(){super()}async share(t=this.value){if(navigator.canShare&&navigator.canShare({url:t}))try{await navigator.share({url:t})}catch(e){e?.name!=="AbortError"&&console.error(e)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};var C=class extends c{constructor(){super()}#t(t){let e="data-asc",i="data-desc";for(let s of this.getTrigger())s!==t&&(s.removeAttribute(e),s.removeAttribute(i));return t.hasAttribute(e)?(t.removeAttribute(e),t.setAttribute(i,""),!1):(t.removeAttribute(i),t.setAttribute(e,""),!0)}mount(){let t=this.getContent(HTMLTableSectionElement);for(let e of this.getTrigger())e.addEventListener(this.event,()=>{Array.from(t.querySelectorAll("tr")).sort(K(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},K=(o,t)=>(i,s)=>{let r=Array.from(o.parentNode?.children??[]).indexOf(o);return((a,u)=>{let l=o.dataset.type??"string";if(l==="string")return new Intl.Collator().compare(a,u);if(l==="boolean"){let h=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return h(a)===h(u)?0:h(a)?-1:1}else return Number(a)-Number(u)})(j(t?i:s,r),j(t?s:i,r))},j=(o,t)=>{let e=o.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var M=class extends c{wakeLock=null;constructor(){super()}#t(){return"wakeLock"in navigator}get#s(){return this.hasAttribute("auto-lock")}async request(){this.#t()&&document.visibilityState==="visible"&&(this.wakeLock=await navigator.wakeLock.request("screen"),this.setAttribute("locked",""),this.swapContent(!1),this.wakeLock.addEventListener("release",()=>{this.removeAttribute("locked"),this.swapContent(!1),this.#s||(this.wakeLock=null)}))}async release(){await this.wakeLock?.release(),this.wakeLock=null}mount(){this.hasAttribute("locked")&&this.request(),this.triggerListener(()=>{this.wakeLock?this.release():this.request()});for(let t of this.getTrigger())!this.#t()&&"disabled"in t&&(t.disabled=!0);this.#s&&this.safeListener("visibilitychange",()=>{this.wakeLock&&this.request()},document)}destroy(){this.release()}};var S=class extends c{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};for(let o in H)customElements.define(`drab-${o.toLowerCase()}`,H[o]);})();
package/index.iife.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";(()=>{var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let s=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(s){let i=Array.from(this.getContent().childNodes),r=[];s instanceof HTMLTemplateElement?(r.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(r.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...r),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,s=document.body,i={}){i.signal=this.#t.signal,s.addEventListener(t,e,i)}triggerListener(t,e=this.event,s){for(let i of this.getTrigger())i.addEventListener(e,t,s)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var p=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let s=this.getAttribute(e),[,,i]=e.split("-");s&&(i==="duration"||i==="delay"?t[i]=Number(s):i==="easing"&&(t[i]=s))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:s={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){s=Object.assign(this.animationOptions,s),s.duration||(s.duration=200),s.easing||(s.easing="ease-in-out");let r=i.at(0),n=i.at(-1);if(r&&n){let u=["composite","easing","offset"];for(let l of u)delete r[l],delete n[l]}s.direction?.includes("reverse")&&([r,n]=[n,r]),Object.assign(e.style,r),await e.animate(i,s).finished,Object.assign(e.style,n)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let n=r.map((o,u)=>u<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(i&&n){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let o=Number(i),u=t.find(l=>l.offset===o);u?u[n]=s:t.push({[n]:s,offset:o})}}}return t.sort((e,s)=>Number(e.offset)-Number(s.offset)),t}};var y=class extends c{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...s]=e.split("-");s&&t.push({name:s.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,s)=>s.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};var A=class extends p{#t;constructor(){super()}set#s(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,s=window.scrollX,i=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,n=i+s,o=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;n+u>s+h&&(n=s+h-u),o+l>e+m&&(o=e+m-l),this.#s={x:n,y:o},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart",{passive:!0});let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend",{passive:!0}),this.triggerListener(t,"touchcancel",{passive:!0}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends c{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(t){this.setAttribute("value",t)}async copy(t=this.value){await navigator.clipboard.writeText(t),this.swapContent()}};var x=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var k=class extends p{constructor(){super()}get details(){let t=this.getContent(HTMLElement).parentElement;if(!(t instanceof HTMLDetailsElement))throw new Error("Details: HTMLDetailsElement not found.");return t}async open(){this.details.open=!0,await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.details.open=!1}toggle(){this.details.open?this.close():this.open()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()})}};var v=class extends p{constructor(){super()}get dialog(){return this.getContent(HTMLDialogElement)}async show(){this.dialog.showModal(),await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.dialog.close()}async toggle(){this.dialog.open?this.close():this.show()}mount(){this.triggerListener(()=>this.toggle()),this.safeListener("keydown",t=>{t.key==="Escape"&&this.dialog.open&&(t.preventDefault(),this.close())}),this.hasAttribute("click-outside-close")&&this.dialog.addEventListener("click",t=>{let e=this.dialog.getBoundingClientRect();(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this.close()})}};var E=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#s)t.type==="wrap"&&(this.keyPairs[t.value]=t.value)}get textArea(){return this.getContent(HTMLTextAreaElement)}get text(){return this.textArea.value}set text(t){this.textArea.value=t}get#s(){let t=[];for(let e of this.getTrigger())t.push(this.#l(e));return t}get#n(){let t=this.text.split("```"),e=0;for(let[s,i]of t.entries())if(e+=i.length+3,this.#i<e)return s;return 0}get#e(){return this.textArea.selectionEnd}get#i(){return this.textArea.selectionStart}#r(t,e){this.textArea.setSelectionRange(t,e)}#l(t){let e=t.dataset.type,s=t.dataset.value,i=t.dataset.key??void 0;return{type:e,value:s,key:i}}async#c(t,e,s){if(t.type==="inline")this.text=`${this.text.slice(0,s)}${t.value}${this.text.slice(s)}`;else if(t.type==="wrap")this.text=P(this.text,t.value,e),this.text=P(this.text,this.keyPairs[t.value],s+t.value.length),t.value.length<2&&this.#t.push(t.value);else if(t.type==="block"){let{lines:i,lineNumber:r}=this.#a(),n=t.value.at(0);n&&i[r]?.startsWith(n)?i[r]=t.value.trim()+i[r]:i[r]=t.value+i[r],this.text=i.join(`
2
- `)}}async#h(t,e,s){let i=0,r=0;if(/[a-z]/i.test(t)){for(let n=s;n<this.text.length;n++)if(this.text[n]?.match(/[a-z]/i))i?r=n+1:i=n;else if(i)break}else i=e+t.length,r=s+t.length;this.#r(i,r),this.textArea.focus()}async#o(t){let e=this.#e,s=this.#i;await this.#c(t,s,e),this.#h(t.value,s,e)}#p(t){if(t){let e=[];this.#s.forEach(i=>{i.type==="block"&&e.push(i.value)});for(let i=0;i<e.length;i++){let r=e[i];if(r&&t.startsWith(r))return r}let s=w(t);if(s)return`${s}. `}return""}#a(){let t=this.text.split(`
3
- `),e=0;for(let s=0;s<t.length;s++){let i=t.at(s)?.length??0;if(e++,e+=i,e>this.#e)return{lines:t,lineNumber:s,columnNumber:this.#e-(e-i-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#u(t,e=!1){let{lines:s}=this.#a();for(let i=t+1;i<s.length;i++){let r=s[i];if(r){let n=w(r);if(n){let o;if(e)if(n>1)o=n-1;else break;else o=n+1;s[i]=r.slice(String(n).length),s[i]=String(o)+s[i]}else break}}this.text=s.join(`
4
- `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],s=this.text[this.#e]??"";if(e.includes(t.key))this.#t=[];else if(t.key==="Backspace"){let i=this.text[this.#i-1];if(i&&i in this.keyPairs&&s===this.keyPairs[i]){t.preventDefault();let r=this.#i-1,n=this.#e-1;this.text=d(this.text,r),this.text=d(this.text,n),setTimeout(()=>{this.#r(r,n)},0),this.#t.pop()}if(i===`
5
- `&&this.#i===this.#e){t.preventDefault();let r=this.#i-1,{lineNumber:n}=this.#a();this.#u(n,!0),this.text=d(this.text,r),setTimeout(async()=>{this.#r(r,r)},0)}}else if(t.key==="Tab")this.#n%2!==0&&(t.preventDefault(),await this.#o({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:i,lineNumber:r,columnNumber:n}=this.#a(),o=i.at(r),u=this.#p(o),l=u,h=w(u);if(h&&(u=`${h+1}. `),u&&l.length<n)t.preventDefault(),h&&this.#u(r),await this.#o({type:"inline",value:`
1
+ "use strict";(()=>{var c=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let i=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(i){let s=Array.from(this.getContent().childNodes),r=[];i instanceof HTMLTemplateElement?(r.push(i.content.cloneNode(!0)),i.content.replaceChildren(...s)):(r.push(...i.childNodes),i.replaceChildren(...s)),this.getContent().replaceChildren(...r),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,i=document.body,s={}){s.signal=this.#t.signal,i.addEventListener(t,e,s)}triggerListener(t,e=this.event,i){for(let s of this.getTrigger())s.addEventListener(e,t,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var p=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let i=this.getAttribute(e),[,,s]=e.split("-");i&&(s==="duration"||s==="delay"?t[s]=Number(i):s==="easing"&&(t[s]=i))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:i={}}=t,s=this.keyframes;if(s.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){i=Object.assign(this.animationOptions,i),i.duration||(i.duration=200),i.easing||(i.easing="ease-in-out");let r=s.at(0),n=s.at(-1);if(r&&n){let u=["composite","easing","offset"];for(let l of u)delete r[l],delete n[l]}i.direction?.includes("reverse")&&([r,n]=[n,r]),Object.assign(e.style,r),await e.animate(s,i).finished,Object.assign(e.style,n)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let i=this.getAttribute(e),[,,s,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let n=r.map((o,u)=>u<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(s&&n){s==="from"?s="0":s==="to"?s="1":s=String(parseInt(s)*.01);let o=Number(s),u=t.find(l=>l.offset===o);u?u[n]=i:t.push({[n]:i,offset:o})}}}return t.sort((e,i)=>Number(e.offset)-Number(i.offset)),t}};var y=class extends c{breakpoints=[{name:"sm",width:640},{name:"md",width:768},{name:"lg",width:1024},{name:"xl",width:1280},{name:"2xl",width:1536}];constructor(){super();let t=[];for(let e of this.getAttributeNames())if(e.startsWith("breakpoint-")){let[,...i]=e.split("-");i&&t.push({name:i.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,i)=>i.width-e.width)}get breakpoint(){for(let t=0;t<this.breakpoints.length;t++){let e=this.breakpoints[t];if(e&&window.innerWidth>e.width)return e.name}return"none"}mount(){let t=()=>this.getContent().innerHTML=`${this.breakpoint}:${window.innerWidth}`;t(),this.safeListener("resize",t,window)}};var A=class extends p{#t;constructor(){super()}set#s(t){this.getContent().style.left=`${t.x}px`,this.getContent().style.top=`${t.y}px`}async show(t){let e=window.scrollY,i=window.scrollX,s=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,n=s+i,o=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;n+u>i+h&&(n=i+h-u),o+l>e+m&&(o=e+m-l),this.#s={x:n,y:o},await this.animateElement()}async hide(){this.getContent().style.display!=="none"&&(await this.animateElement({options:{direction:"reverse"}}),this.getContent().style.display="none")}mount(){this.triggerListener(e=>{e.preventDefault(),this.show(e)},"contextmenu"),this.safeListener("click",()=>this.hide()),this.triggerListener(e=>{this.#t=setTimeout(()=>{this.show(e)},800)},"touchstart",{passive:!0});let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend",{passive:!0}),this.triggerListener(t,"touchcancel",{passive:!0}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends c{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(t){this.setAttribute("value",t)}async copy(t=this.value){await navigator.clipboard.writeText(t),this.swapContent()}};var k=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var x=class extends p{constructor(){super()}get details(){let t=this.getContent(HTMLElement).parentElement;if(!(t instanceof HTMLDetailsElement))throw new Error("Details: HTMLDetailsElement not found.");return t}async open(){this.details.open=!0,await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.details.open=!1}toggle(){this.details.open?this.close():this.open()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()})}};var v=class extends p{constructor(){super()}get dialog(){return this.getContent(HTMLDialogElement)}async show(){this.dialog.showModal(),await this.animateElement()}async close(){await this.animateElement({options:{direction:"reverse"}}),this.dialog.close()}async toggle(){this.dialog.open?this.close():this.show()}mount(){this.triggerListener(()=>this.toggle()),this.safeListener("keydown",t=>{t.key==="Escape"&&this.dialog.open&&(t.preventDefault(),this.close())}),this.hasAttribute("click-outside-close")&&this.dialog.addEventListener("click",t=>{let e=this.dialog.getBoundingClientRect();(t.clientX<e.left||t.clientX>e.right||t.clientY<e.top||t.clientY>e.bottom)&&this.close()})}};var E=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#s)t.type==="wrap"&&(this.keyPairs[t.value]=t.value)}get textArea(){return this.getContent(HTMLTextAreaElement)}get text(){return this.textArea.value}set text(t){this.textArea.value=t}get#s(){let t=[];for(let e of this.getTrigger())t.push(this.#l(e));return t}get#n(){let t=this.text.split("```"),e=0;for(let[i,s]of t.entries())if(e+=s.length+3,this.#i<e)return i;return 0}get#e(){return this.textArea.selectionEnd}get#i(){return this.textArea.selectionStart}#r(t,e){this.textArea.setSelectionRange(t,e)}#l(t){let e=t.dataset.type,i=t.dataset.value,s=t.dataset.key??void 0;return{type:e,value:i,key:s}}async#c(t,e,i){if(t.type==="inline")this.text=`${this.text.slice(0,i)}${t.value}${this.text.slice(i)}`;else if(t.type==="wrap")this.text=P(this.text,t.value,e),this.text=P(this.text,this.keyPairs[t.value],i+t.value.length),t.value.length<2&&this.#t.push(t.value);else if(t.type==="block"){let{lines:s,lineNumber:r}=this.#a(),n=t.value.at(0);n&&s[r]?.startsWith(n)?s[r]=t.value.trim()+s[r]:s[r]=t.value+s[r],this.text=s.join(`
2
+ `)}}async#h(t,e,i){let s=0,r=0;if(/[a-z]/i.test(t)){for(let n=i;n<this.text.length;n++)if(this.text[n]?.match(/[a-z]/i))s?r=n+1:s=n;else if(s)break}else s=e+t.length,r=i+t.length;this.#r(s,r),this.textArea.focus()}async#o(t){let e=this.#e,i=this.#i;await this.#c(t,i,e),this.#h(t.value,i,e)}#p(t){if(t){let e=[];this.#s.forEach(s=>{s.type==="block"&&e.push(s.value)});for(let s=0;s<e.length;s++){let r=e[s];if(r&&t.startsWith(r))return r}let i=w(t);if(i)return`${i}. `}return""}#a(){let t=this.text.split(`
3
+ `),e=0;for(let i=0;i<t.length;i++){let s=t.at(i)?.length??0;if(e++,e+=s,e>this.#e)return{lines:t,lineNumber:i,columnNumber:this.#e-(e-s-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#u(t,e=!1){let{lines:i}=this.#a();for(let s=t+1;s<i.length;s++){let r=i[s];if(r){let n=w(r);if(n){let o;if(e)if(n>1)o=n-1;else break;else o=n+1;i[s]=r.slice(String(n).length),i[s]=String(o)+i[s]}else break}}this.text=i.join(`
4
+ `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],i=this.text[this.#e]??"";if(e.includes(t.key))this.#t=[];else if(t.key==="Backspace"){let s=this.text[this.#i-1];if(s&&s in this.keyPairs&&i===this.keyPairs[s]){t.preventDefault();let r=this.#i-1,n=this.#e-1;this.text=d(this.text,r),this.text=d(this.text,n),setTimeout(()=>{this.#r(r,n)},0),this.#t.pop()}if(s===`
5
+ `&&this.#i===this.#e){t.preventDefault();let r=this.#i-1,{lineNumber:n}=this.#a();this.#u(n,!0),this.text=d(this.text,r),setTimeout(async()=>{this.#r(r,r)},0)}}else if(t.key==="Tab")this.#n%2!==0&&(t.preventDefault(),await this.#o({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:s,lineNumber:r,columnNumber:n}=this.#a(),o=s.at(r),u=this.#p(o),l=u,h=w(u);if(h&&(u=`${h+1}. `),u&&l.length<n)t.preventDefault(),h&&this.#u(r),await this.#o({type:"inline",value:`
6
6
  ${u}`});else if(u&&l.length===n){t.preventDefault();let m=this.#e,g=m-l.length;for(let b=0;b<l.length;b++)this.text=d(this.text,m-(b+1));setTimeout(async()=>{this.#r(g,g),this.textArea.focus(),await this.#o({type:"inline",value:`
7
- `})},0)}}else{let i=Object.values(this.keyPairs).includes(s),r=this.#i!==this.#e;if((t.ctrlKey||t.metaKey)&&this.#i===this.#e&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:n,lineNumber:o,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${o===0&&t.key==="x"?"":`
7
+ `})},0)}}else{let s=Object.values(this.keyPairs).includes(i),r=this.#i!==this.#e;if((t.ctrlKey||t.metaKey)&&this.#i===this.#e&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:n,lineNumber:o,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${o===0&&t.key==="x"?"":`
8
8
  `}${n[o]}`),t.key==="x"){let l=this.#i-u;n.splice(o,1),this.text=n.join(`
9
- `),setTimeout(()=>{this.#r(l,l)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let n=this.#s.find(o=>o.key===t.key);n&&this.#o(n)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!r?(t.preventDefault(),this.#r(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#o({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#r(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},w=a=>{let t=a.match(/^(\d+)\./);return t?Number(t[1]):null},P=(a,t,e)=>a.slice(0,e)+t+a.slice(e),d=(a,t)=>a.slice(0,t)+a.slice(t+1);var T=class extends c{constructor(){super()}isFullscreen(){return document.fullscreenElement!==null}fullscreenSupported(){return!!document.documentElement.requestFullscreen}toggle(){if(this.isFullscreen())document.exitFullscreen();else try{this.getContent(HTMLElement).requestFullscreen()}catch{document.documentElement.requestFullscreen()}}mount(){this.triggerListener(()=>this.toggle());for(let t of this.getTrigger())!this.fullscreenSupported()&&"disabled"in t&&(t.disabled=!0)}};var L=class extends c{#t=[];#s=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#s.push(t)}mount(){let t=new IntersectionObserver(e=>{let s="data-intersect";for(let i of e)if(i.isIntersecting){this.getContent().setAttribute(s,"");for(let r of this.#t)r()}else{this.getContent().removeAttribute(s);for(let r of this.#s)r()}},{threshold:this.#n});for(let e of this.getTrigger())t.observe(e)}};var C=class extends p{constructor(){super()}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}async show(){this.getContent().showPopover(),await this.animateElement()}async hide(){await this.animateElement({options:{direction:"reverse"}}),this.getContent().hidePopover()}async toggle(){this.open?this.hide():this.show()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",t=>{t.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",t=>{t.key==="Escape"&&this.open&&(t.preventDefault(),this.hide())})}};var M=class extends c{#t=[];constructor(){super()}get#s(){return this.getAttribute("strategy")??"hover"}get#n(){return this.hasAttribute("prerender")}get#e(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!this.#t.includes(e)){if(HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({[s?"prerender":"prefetch"]:[{source:"list",urls:[e]}]}),document.head.append(r)}else fetch(e,{priority:"low"}).catch(r=>console.error(r));this.#t.push(e)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#n,strategy:this.#s}){let{anchors:e=this.getTrigger(),prerender:s=this.#n,strategy:i=this.#s}=t,r,n=(l=200)=>h=>{let{href:m}=h.currentTarget;r=setTimeout(()=>this.appendTag({url:m,prerender:s}),l)},o=()=>clearTimeout(r),u=new IntersectionObserver(l=>{for(let h of l)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:s})});for(let l of e)i==="load"?this.appendTag({url:l.href,prerender:s}):i==="visible"?u.observe(l):(l.addEventListener("mouseover",n()),l.addEventListener("mouseout",o),l.addEventListener("focus",n()),l.addEventListener("focusout",o),l.addEventListener("touchstart",n(0),{passive:!0}))}mount(){this.#e&&this.appendTag({url:this.#e,prerender:this.#n}),this.prefetch()}};var S=class extends f{constructor(){super()}async share(t=this.value){if(navigator.canShare&&navigator.canShare({url:t}))try{await navigator.share({url:t})}catch(e){e?.name!=="AbortError"&&console.error(e)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};var H=class extends c{constructor(){super()}#t(t){let e="data-asc",s="data-desc";for(let i of this.getTrigger())i!==t&&(i.removeAttribute(e),i.removeAttribute(s));return t.hasAttribute(e)?(t.removeAttribute(e),t.setAttribute(s,""),!1):(t.removeAttribute(s),t.setAttribute(e,""),!0)}mount(){let t=this.getContent(HTMLTableSectionElement);for(let e of this.getTrigger())e.addEventListener(this.event,()=>{Array.from(t.querySelectorAll("tr")).sort(j(e,this.#t(e))).forEach(s=>t.appendChild(s))})}},j=(a,t)=>(s,i)=>{let r=Array.from(a.parentNode?.children??[]).indexOf(a);return((o,u)=>{let l=a.dataset.type??"string";if(l==="string")return new Intl.Collator().compare(o,u);if(l==="boolean"){let h=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return h(o)===h(u)?0:h(o)?-1:1}else return Number(o)-Number(u)})(B(t?s:i,r),B(t?i:s,r))},B=(a,t)=>{let e=a.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var N=class extends c{wakeLock=null;constructor(){super()}#t(){return"wakeLock"in navigator}get#s(){return this.hasAttribute("auto-lock")}async request(){this.#t()&&document.visibilityState==="visible"&&(this.wakeLock=await navigator.wakeLock.request("screen"),this.setAttribute("locked",""),this.swapContent(!1),this.wakeLock.addEventListener("release",()=>{this.removeAttribute("locked"),this.swapContent(!1),this.#s||(this.wakeLock=null)}))}async release(){await this.wakeLock?.release(),this.wakeLock=null}mount(){this.hasAttribute("locked")&&this.request(),this.triggerListener(()=>{this.wakeLock?this.release():this.request()});for(let t of this.getTrigger())!this.#t()&&"disabled"in t&&(t.disabled=!0);this.#s&&this.safeListener("visibilitychange",()=>{this.wakeLock&&this.request()},document)}destroy(){this.release()}};var D=class extends c{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};})();
9
+ `),setTimeout(()=>{this.#r(l,l)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let n=this.#s.find(o=>o.key===t.key);n&&this.#o(n)}else s&&(i===t.key||t.key==="ArrowRight")&&this.#t.length&&!r?(t.preventDefault(),this.#r(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#o({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#r(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},w=a=>{let t=a.match(/^(\d+)\./);return t?Number(t[1]):null},P=(a,t,e)=>a.slice(0,e)+t+a.slice(e),d=(a,t)=>a.slice(0,t)+a.slice(t+1);var T=class extends c{constructor(){super()}isFullscreen(){return document.fullscreenElement!==null}fullscreenSupported(){return!!document.documentElement.requestFullscreen}toggle(){if(this.isFullscreen())document.exitFullscreen();else try{this.getContent(HTMLElement).requestFullscreen()}catch{document.documentElement.requestFullscreen()}}mount(){this.triggerListener(()=>this.toggle());for(let t of this.getTrigger())!this.fullscreenSupported()&&"disabled"in t&&(t.disabled=!0)}};var L=class extends c{#t=[];#s=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#s.push(t)}mount(){let t=new IntersectionObserver(e=>{let i="data-intersect";for(let s of e)if(s.isIntersecting){this.getContent().setAttribute(i,"");for(let r of this.#t)r()}else{this.getContent().removeAttribute(i);for(let r of this.#s)r()}},{threshold:this.#n});for(let e of this.getTrigger())t.observe(e)}};var C=class extends p{constructor(){super()}get open(){return this.hasAttribute("open")}set open(t){t?this.setAttribute("open",""):this.removeAttribute("open")}async show(){this.getContent().showPopover(),await this.animateElement()}async hide(){await this.animateElement({options:{direction:"reverse"}}),this.getContent().hidePopover()}async toggle(){this.open?this.hide():this.show()}mount(){this.triggerListener(t=>{t.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",t=>{t.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",t=>{t.key==="Escape"&&this.open&&(t.preventDefault(),this.hide())})}};var M=class extends c{#t=[];constructor(){super()}get#s(){return this.getAttribute("strategy")??"hover"}get#n(){return this.hasAttribute("prerender")}get#e(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:i}=t;if(e!==window.location.href&&!this.#t.includes(e)){this.#t.push(e);let s=document.createElement("link");if(s.rel="prefetch",s.as="document",s.href=e,document.head.append(s),i){let r=document.createElement("script");r.type="speculationrules",r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#n,strategy:this.#s}){let{anchors:e=this.getTrigger(),prerender:i=this.#n,strategy:s=this.#s}=t,r,n=(l=200)=>h=>{let{href:m}=h.currentTarget;r=setTimeout(()=>this.appendTag({url:m,prerender:i}),l)},o=()=>clearTimeout(r),u=new IntersectionObserver(l=>{for(let h of l)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:i})});for(let l of e)s==="load"?this.appendTag({url:l.href,prerender:i}):s==="visible"?u.observe(l):(l.addEventListener("mouseover",n()),l.addEventListener("mouseout",o),l.addEventListener("focus",n()),l.addEventListener("focusout",o),l.addEventListener("touchstart",n(0),{passive:!0}))}mount(){this.#e&&this.appendTag({url:this.#e,prerender:this.#n}),this.prefetch()}};var S=class extends f{constructor(){super()}async share(t=this.value){if(navigator.canShare&&navigator.canShare({url:t}))try{await navigator.share({url:t})}catch(e){e?.name!=="AbortError"&&console.error(e)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};var H=class extends c{constructor(){super()}#t(t){let e="data-asc",i="data-desc";for(let s of this.getTrigger())s!==t&&(s.removeAttribute(e),s.removeAttribute(i));return t.hasAttribute(e)?(t.removeAttribute(e),t.setAttribute(i,""),!1):(t.removeAttribute(i),t.setAttribute(e,""),!0)}mount(){let t=this.getContent(HTMLTableSectionElement);for(let e of this.getTrigger())e.addEventListener(this.event,()=>{Array.from(t.querySelectorAll("tr")).sort(j(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},j=(a,t)=>(i,s)=>{let r=Array.from(a.parentNode?.children??[]).indexOf(a);return((o,u)=>{let l=a.dataset.type??"string";if(l==="string")return new Intl.Collator().compare(o,u);if(l==="boolean"){let h=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return h(o)===h(u)?0:h(o)?-1:1}else return Number(o)-Number(u)})(B(t?i:s,r),B(t?s:i,r))},B=(a,t)=>{let e=a.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var N=class extends c{wakeLock=null;constructor(){super()}#t(){return"wakeLock"in navigator}get#s(){return this.hasAttribute("auto-lock")}async request(){this.#t()&&document.visibilityState==="visible"&&(this.wakeLock=await navigator.wakeLock.request("screen"),this.setAttribute("locked",""),this.swapContent(!1),this.wakeLock.addEventListener("release",()=>{this.removeAttribute("locked"),this.swapContent(!1),this.#s||(this.wakeLock=null)}))}async release(){await this.wakeLock?.release(),this.wakeLock=null}mount(){this.hasAttribute("locked")&&this.request(),this.triggerListener(()=>{this.wakeLock?this.release():this.request()});for(let t of this.getTrigger())!this.#t()&&"disabled"in t&&(t.disabled=!0);this.#s&&this.safeListener("visibilitychange",()=>{this.wakeLock&&this.request()},document)}destroy(){this.release()}};var D=class extends c{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};})();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drab",
3
3
  "description": "A headless custom element library",
4
- "version": "5.3.3",
4
+ "version": "5.3.5",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -184,16 +184,16 @@
184
184
  },
185
185
  "devDependencies": {
186
186
  "@tailwindcss/typography": "^0.5.10",
187
- "@types/node": "^20.11.19",
187
+ "@types/node": "^20.11.24",
188
188
  "@vercel/analytics": "^1.2.2",
189
- "autoprefixer": "^10.4.17",
190
- "domco": "^0.5.2",
189
+ "autoprefixer": "^10.4.18",
190
+ "domco": "^0.5.3",
191
191
  "prettier": "^3.2.5",
192
192
  "prettier-plugin-tailwindcss": "^0.5.11",
193
193
  "robino": "^0.1.0",
194
194
  "tailwindcss": "^3.4.1",
195
195
  "tsup": "^8.0.2",
196
- "typedoc": "^0.25.8",
196
+ "typedoc": "^0.25.9",
197
197
  "typedoc-plugin-markdown": "^3.17.1",
198
198
  "typescript": "^5.3.3",
199
199
  "uico": "^0.2.2",
@@ -1 +1 @@
1
- "use strict";(()=>{var a=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(r){this.setAttribute("event",r)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(r=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof r)return e;throw new Error("Content not found")}swapContent(r=!0,e=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let n=Array.from(this.getContent().childNodes),s=[];t instanceof HTMLTemplateElement?(s.push(t.content.cloneNode(!0)),t.content.replaceChildren(...n)):(s.push(...t.childNodes),t.replaceChildren(...n)),this.getContent().replaceChildren(...s),r&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(r,e,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(r,e,n)}triggerListener(r,e=this.event,t){for(let n of this.getTrigger())n.addEventListener(e,r,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var c=class extends a{#e=[];constructor(){super()}get#r(){return this.getAttribute("strategy")??"hover"}get#t(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(r){let{url:e,prerender:t}=r;if(e!==window.location.href){let n="speculationrules";if(!this.#e.includes(e)){if(HTMLScriptElement.supports&&HTMLScriptElement.supports(n)){let s=document.createElement("script");s.type=n,s.textContent=JSON.stringify({[t?"prerender":"prefetch"]:[{source:"list",urls:[e]}]}),document.head.append(s)}else fetch(e,{priority:"low"}).catch(s=>console.error(s));this.#e.push(e)}}}prefetch(r={anchors:this.getTrigger(),prerender:this.#t,strategy:this.#r}){let{anchors:e=this.getTrigger(),prerender:t=this.#t,strategy:n=this.#r}=r,s,l=(o=200)=>i=>{let{href:p}=i.currentTarget;s=setTimeout(()=>this.appendTag({url:p,prerender:t}),o)},u=()=>clearTimeout(s),h=new IntersectionObserver(o=>{for(let i of o)i.isIntersecting&&this.appendTag({url:i.target.href,prerender:t})});for(let o of e)n==="load"?this.appendTag({url:o.href,prerender:t}):n==="visible"?h.observe(o):(o.addEventListener("mouseover",l()),o.addEventListener("mouseout",u),o.addEventListener("focus",l()),o.addEventListener("focusout",u),o.addEventListener("touchstart",l(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#t}),this.prefetch()}};customElements.define("drab-prefetch",c);})();
1
+ "use strict";(()=>{var a=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(n){this.setAttribute("event",n)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(n=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof n)return e;throw new Error("Content not found")}swapContent(n=!0,e=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let r=Array.from(this.getContent().childNodes),o=[];t instanceof HTMLTemplateElement?(o.push(t.content.cloneNode(!0)),t.content.replaceChildren(...r)):(o.push(...t.childNodes),t.replaceChildren(...r)),this.getContent().replaceChildren(...o),n&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(n,e,t=document.body,r={}){r.signal=this.#e.signal,t.addEventListener(n,e,r)}triggerListener(n,e=this.event,t){for(let r of this.getTrigger())r.addEventListener(e,n,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var c=class extends a{#e=[];constructor(){super()}get#r(){return this.getAttribute("strategy")??"hover"}get#t(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(n){let{url:e,prerender:t}=n;if(e!==window.location.href&&!this.#e.includes(e)){this.#e.push(e);let r=document.createElement("link");if(r.rel="prefetch",r.as="document",r.href=e,document.head.append(r),t){let o=document.createElement("script");o.type="speculationrules",o.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(o)}}}prefetch(n={anchors:this.getTrigger(),prerender:this.#t,strategy:this.#r}){let{anchors:e=this.getTrigger(),prerender:t=this.#t,strategy:r=this.#r}=n,o,l=(s=200)=>i=>{let{href:p}=i.currentTarget;o=setTimeout(()=>this.appendTag({url:p,prerender:t}),s)},u=()=>clearTimeout(o),h=new IntersectionObserver(s=>{for(let i of s)i.isIntersecting&&this.appendTag({url:i.target.href,prerender:t})});for(let s of e)r==="load"?this.appendTag({url:s.href,prerender:t}):r==="visible"?h.observe(s):(s.addEventListener("mouseover",l()),s.addEventListener("mouseout",u),s.addEventListener("focus",l()),s.addEventListener("focusout",u),s.addEventListener("touchstart",l(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#t}),this.prefetch()}};customElements.define("drab-prefetch",c);})();
@@ -23,7 +23,7 @@ export type PrefetchAttributes = Attributes<Prefetch> & Partial<{
23
23
  *
24
24
  * Use the `prerender` attribute to use the Speculation Rules API when supported to prerender on the client. This allows you to run client side JavaScript in advance instead of only fetching the HTML.
25
25
  *
26
- * Browsers that do not support will still use `fetch` with low priority instead.
26
+ * Browsers that do not support will still use `<link rel="prefetch">` instead.
27
27
  *
28
28
  * [Speculation Rules Reference](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API)
29
29
  *
@@ -38,7 +38,7 @@ export declare class Prefetch extends Base {
38
38
  #private;
39
39
  constructor();
40
40
  /**
41
- * Fetches the `url`, or appends `<script type="speculationrules">` to the head of the document.
41
+ * Appends `<link rel="prefetch">` or `<script type="speculationrules">` to the head of the document.
42
42
  *
43
43
  * @param options Configuration options.
44
44
  */
@@ -1 +1 @@
1
- "use strict";(()=>{var a=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(r){this.setAttribute("event",r)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(r=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof r)return e;throw new Error("Content not found")}swapContent(r=!0,e=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let n=Array.from(this.getContent().childNodes),s=[];t instanceof HTMLTemplateElement?(s.push(t.content.cloneNode(!0)),t.content.replaceChildren(...n)):(s.push(...t.childNodes),t.replaceChildren(...n)),this.getContent().replaceChildren(...s),r&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(r,e,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(r,e,n)}triggerListener(r,e=this.event,t){for(let n of this.getTrigger())n.addEventListener(e,r,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var u=class extends a{#e=[];constructor(){super()}get#r(){return this.getAttribute("strategy")??"hover"}get#t(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(r){let{url:e,prerender:t}=r;if(e!==window.location.href){let n="speculationrules";if(!this.#e.includes(e)){if(HTMLScriptElement.supports&&HTMLScriptElement.supports(n)){let s=document.createElement("script");s.type=n,s.textContent=JSON.stringify({[t?"prerender":"prefetch"]:[{source:"list",urls:[e]}]}),document.head.append(s)}else fetch(e,{priority:"low"}).catch(s=>console.error(s));this.#e.push(e)}}}prefetch(r={anchors:this.getTrigger(),prerender:this.#t,strategy:this.#r}){let{anchors:e=this.getTrigger(),prerender:t=this.#t,strategy:n=this.#r}=r,s,l=(o=200)=>i=>{let{href:p}=i.currentTarget;s=setTimeout(()=>this.appendTag({url:p,prerender:t}),o)},c=()=>clearTimeout(s),h=new IntersectionObserver(o=>{for(let i of o)i.isIntersecting&&this.appendTag({url:i.target.href,prerender:t})});for(let o of e)n==="load"?this.appendTag({url:o.href,prerender:t}):n==="visible"?h.observe(o):(o.addEventListener("mouseover",l()),o.addEventListener("mouseout",c),o.addEventListener("focus",l()),o.addEventListener("focusout",c),o.addEventListener("touchstart",l(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#t}),this.prefetch()}};})();
1
+ "use strict";(()=>{var a=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(n){this.setAttribute("event",n)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(n=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof n)return e;throw new Error("Content not found")}swapContent(n=!0,e=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let r=Array.from(this.getContent().childNodes),o=[];t instanceof HTMLTemplateElement?(o.push(t.content.cloneNode(!0)),t.content.replaceChildren(...r)):(o.push(...t.childNodes),t.replaceChildren(...r)),this.getContent().replaceChildren(...o),n&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(n,e,t=document.body,r={}){r.signal=this.#e.signal,t.addEventListener(n,e,r)}triggerListener(n,e=this.event,t){for(let r of this.getTrigger())r.addEventListener(e,n,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var u=class extends a{#e=[];constructor(){super()}get#r(){return this.getAttribute("strategy")??"hover"}get#t(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(n){let{url:e,prerender:t}=n;if(e!==window.location.href&&!this.#e.includes(e)){this.#e.push(e);let r=document.createElement("link");if(r.rel="prefetch",r.as="document",r.href=e,document.head.append(r),t){let o=document.createElement("script");o.type="speculationrules",o.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(o)}}}prefetch(n={anchors:this.getTrigger(),prerender:this.#t,strategy:this.#r}){let{anchors:e=this.getTrigger(),prerender:t=this.#t,strategy:r=this.#r}=n,o,l=(s=200)=>i=>{let{href:p}=i.currentTarget;o=setTimeout(()=>this.appendTag({url:p,prerender:t}),s)},c=()=>clearTimeout(o),h=new IntersectionObserver(s=>{for(let i of s)i.isIntersecting&&this.appendTag({url:i.target.href,prerender:t})});for(let s of e)r==="load"?this.appendTag({url:s.href,prerender:t}):r==="visible"?h.observe(s):(s.addEventListener("mouseover",l()),s.addEventListener("mouseout",c),s.addEventListener("focus",l()),s.addEventListener("focusout",c),s.addEventListener("touchstart",l(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#t}),this.prefetch()}};})();
package/prefetch/index.js CHANGED
@@ -16,7 +16,7 @@ import { Base } from "../base/index.js";
16
16
  *
17
17
  * Use the `prerender` attribute to use the Speculation Rules API when supported to prerender on the client. This allows you to run client side JavaScript in advance instead of only fetching the HTML.
18
18
  *
19
- * Browsers that do not support will still use `fetch` with low priority instead.
19
+ * Browsers that do not support will still use `<link rel="prefetch">` instead.
20
20
  *
21
21
  * [Speculation Rules Reference](https://developer.mozilla.org/en-US/docs/Web/API/Speculation_Rules_API)
22
22
  *
@@ -45,38 +45,33 @@ export class Prefetch extends Base {
45
45
  return this.getAttribute("url");
46
46
  }
47
47
  /**
48
- * Fetches the `url`, or appends `<script type="speculationrules">` to the head of the document.
48
+ * Appends `<link rel="prefetch">` or `<script type="speculationrules">` to the head of the document.
49
49
  *
50
50
  * @param options Configuration options.
51
51
  */
52
52
  appendTag(options) {
53
53
  const { url, prerender } = options;
54
- // if not the current page
55
- if (!(url === window.location.href)) {
56
- // minifies
57
- const speculationrules = "speculationrules";
58
- if (!this.#prefetchedUrls.includes(url)) {
59
- if (HTMLScriptElement.supports &&
60
- HTMLScriptElement.supports(speculationrules)) {
61
- const script = document.createElement("script");
62
- script.type = speculationrules;
63
- script.textContent = JSON.stringify({
64
- [prerender ? "prerender" : "prefetch"]: [
65
- {
66
- source: "list",
67
- urls: [url],
68
- },
69
- ],
70
- });
71
- document.head.append(script);
72
- }
73
- else {
74
- fetch(url, {
75
- //@ts-ignore - typedoc error with priority
76
- priority: "low",
77
- }).catch((e) => console.error(e));
78
- }
79
- this.#prefetchedUrls.push(url);
54
+ // if not the current page and not already prefetched
55
+ if (!(url === window.location.href) &&
56
+ !this.#prefetchedUrls.includes(url)) {
57
+ this.#prefetchedUrls.push(url);
58
+ const link = document.createElement("link");
59
+ link.rel = "prefetch";
60
+ link.as = "document";
61
+ link.href = url;
62
+ document.head.append(link);
63
+ if (prerender) {
64
+ const script = document.createElement("script");
65
+ script.type = "speculationrules";
66
+ script.textContent = JSON.stringify({
67
+ prerender: [
68
+ {
69
+ source: "list",
70
+ urls: [url],
71
+ },
72
+ ],
73
+ });
74
+ document.head.append(script);
80
75
  }
81
76
  }
82
77
  }