drab 5.3.1 → 5.3.2

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 R=(o,t)=>{for(var e in t)W(o,e,{get:t[e],enumerable:!0})};var H={};R(H,{Animate:()=>p,Base:()=>c,Breakpoint:()=>d,ContextMenu:()=>g,Copy:()=>y,Details:()=>b,Dialog:()=>A,Editor:()=>k,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),n=[];s instanceof HTMLTemplateElement?(n.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(n.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...n),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 n=i.at(0),r=i.at(-1);if(n&&r){let u=["composite","easing","offset"];for(let l of u)delete n[l],delete r[l]}s.direction?.includes("reverse")&&([n,r]=[r,n]),Object.assign(e.style,n),await e.animate(i,s).finished,Object.assign(e.style,r)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...n]=e.split("-");if(e.startsWith("animation-keyframe-")){let r=n.map((a,u)=>u<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(i&&r){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[r]=s:t.push({[r]: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#e(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,n=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,r=i+s,a=n+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;r+u>s+h&&(r=s+h-u),a+l>e+m&&(a=e+m-l),this.#e={x:r,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 y=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var b=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())})}};var k=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#e)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#e(){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#s(){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=j(this.text,t.value,e),this.text=j(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:n}=this.#a(),r=t.value.at(0);r&&i[n]?.startsWith(r)?i[n]=t.value.trim()+i[n]:i[n]=t.value+i[n],this.text=i.join(`
1
+ "use strict";(()=>{var R=Object.defineProperty;var W=(o,t)=>{for(var e in t)R(o,e,{get:t[e],enumerable:!0})};var H={};W(H,{Animate:()=>p,Base:()=>c,Breakpoint:()=>d,ContextMenu:()=>g,Copy:()=>y,Details:()=>b,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),n=[];s instanceof HTMLTemplateElement?(n.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(n.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...n),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 n=i.at(0),r=i.at(-1);if(n&&r){let u=["composite","easing","offset"];for(let l of u)delete n[l],delete r[l]}s.direction?.includes("reverse")&&([n,r]=[r,n]),Object.assign(e.style,n),await e.animate(i,s).finished,Object.assign(e.style,r)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...n]=e.split("-");if(e.startsWith("animation-keyframe-")){let r=n.map((a,u)=>u<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(i&&r){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[r]=s:t.push({[r]: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#e(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,n=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,r=i+s,a=n+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;r+u>s+h&&(r=s+h-u),a+l>e+m&&(a=e+m-l),this.#e={x:r,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 y=class extends f{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};var b=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.#e)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#e(){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#s(){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:n}=this.#a(),r=t.value.at(0);r&&i[n]?.startsWith(r)?i[n]=t.value.trim()+i[n]:i[n]=t.value+i[n],this.text=i.join(`
2
2
  `)}}async#h(t,e,s){let i=0,n=0;if(/[a-z]/i.test(t)){for(let r=s;r<this.text.length;r++)if(this.text[r]?.match(/[a-z]/i))i?n=r+1:i=r;else if(i)break}else i=e+t.length,n=s+t.length;this.#r(i,n),this.textArea.focus()}async#o(t){let e=this.#s,s=this.#i;await this.#c(t,s,e),this.#h(t.value,s,e)}#p(t){if(t){let e=[];this.#e.forEach(i=>{i.type==="block"&&e.push(i.value)});for(let i=0;i<e.length;i++){let n=e[i];if(n&&t.startsWith(n))return n}let s=P(t);if(s)return`${s}. `}return""}#a(){let t=this.text.split(`
3
3
  `),e=0;for(let s=0;s<t.length;s++){let i=t.at(s)?.length??0;if(e++,e+=i,e>this.#s)return{lines:t,lineNumber:s,columnNumber:this.#s-(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 n=s[i];if(n){let r=P(n);if(r){let a;if(e)if(r>1)a=r-1;else break;else a=r+1;s[i]=n.slice(String(r).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.#s]??"";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 n=this.#i-1,r=this.#s-1;this.text=x(this.text,n),this.text=x(this.text,r),setTimeout(()=>{this.#r(n,r)},0),this.#t.pop()}if(i===`
5
- `&&this.#i===this.#s){t.preventDefault();let n=this.#i-1,{lineNumber:r}=this.#a();this.#u(r,!0),this.text=x(this.text,n),setTimeout(async()=>{this.#r(n,n)},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:n,columnNumber:r}=this.#a(),a=i.at(n),u=this.#p(a),l=u,h=P(u);if(h&&(u=`${h+1}. `),u&&l.length<r)t.preventDefault(),h&&this.#u(n),await this.#o({type:"inline",value:`
6
- ${u}`});else if(u&&l.length===r){t.preventDefault();let m=this.#s,N=m-l.length;for(let D=0;D<l.length;D++)this.text=x(this.text,m-(D+1));setTimeout(async()=>{this.#r(N,N),this.textArea.focus(),await this.#o({type:"inline",value:`
4
+ `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],s=this.text[this.#s]??"";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 n=this.#i-1,r=this.#s-1;this.text=k(this.text,n),this.text=k(this.text,r),setTimeout(()=>{this.#r(n,r)},0),this.#t.pop()}if(i===`
5
+ `&&this.#i===this.#s){t.preventDefault();let n=this.#i-1,{lineNumber:r}=this.#a();this.#u(r,!0),this.text=k(this.text,n),setTimeout(async()=>{this.#r(n,n)},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:n,columnNumber:r}=this.#a(),a=i.at(n),u=this.#p(a),l=u,h=P(u);if(h&&(u=`${h+1}. `),u&&l.length<r)t.preventDefault(),h&&this.#u(n),await this.#o({type:"inline",value:`
6
+ ${u}`});else if(u&&l.length===r){t.preventDefault();let m=this.#s,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
7
  `})},0)}}else{let i=Object.values(this.keyPairs).includes(s),n=this.#i!==this.#s;if((t.ctrlKey||t.metaKey)&&this.#i===this.#s&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:r,lineNumber:a,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${a===0&&t.key==="x"?"":`
8
8
  `}${r[a]}`),t.key==="x"){let l=this.#i-u;r.splice(a,1),this.text=r.join(`
9
- `),setTimeout(()=>{this.#r(l,l)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#e.find(a=>a.key===t.key);r&&this.#o(r)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!n?(t.preventDefault(),this.#r(this.#i+1,this.#s+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.#s&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#s),this.text[this.#s-1]===" "&&this.#r(this.#i,this.#s-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},j=(o,t,e)=>o.slice(0,e)+t+o.slice(e),x=(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=[];#e=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#e.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 n of this.#t)n()}else{this.getContent().removeAttribute(s);for(let n of this.#e)n()}},{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{constructor(){super()}get#t(){return this.getAttribute("strategy")??"hover"}get#e(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!(r=>{if(document.querySelector(`link[href='${r}']`))return!0;let a=document.querySelectorAll(`script[type='${i}']`);for(let u of a)if(JSON.parse(u.textContent??"{}").prerender?.some(h=>"urls"in h&&h.urls?.includes(r)))return!0;return!1})(e))if(s&&HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}else{let r=document.createElement("link");r.rel="prefetch",r.as="document",r.href=e,document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#e,strategy:this.#t}){let{anchors:e=this.getTrigger(),prerender:s=this.#e,strategy:i=this.#t}=t,n,r=(l=200)=>h=>{let{href:m}=h.currentTarget;n=setTimeout(()=>this.appendTag({url:m,prerender:s}),l)},a=()=>clearTimeout(n),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",r()),l.addEventListener("mouseout",a),l.addEventListener("focus",r()),l.addEventListener("focusout",a),l.addEventListener("touchstart",r(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#e}),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($(e,this.#t(e))).forEach(s=>t.appendChild(s))})}},$=(o,t)=>(s,i)=>{let n=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)})(B(t?s:i,n),B(t?i:s,n))},B=(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#e(){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.#e||(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.#e&&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 r=this.#e.find(a=>a.key===t.key);r&&this.#o(r)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!n?(t.preventDefault(),this.#r(this.#i+1,this.#s+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.#s&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#s),this.text[this.#s-1]===" "&&this.#r(this.#i,this.#s-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=[];#e=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#e.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 n of this.#t)n()}else{this.getContent().removeAttribute(s);for(let n of this.#e)n()}},{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{constructor(){super()}get#t(){return this.getAttribute("strategy")??"hover"}get#e(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!(r=>{if(document.querySelector(`link[href='${r}']`))return!0;let a=document.querySelectorAll(`script[type='${i}']`);for(let u of a)if(JSON.parse(u.textContent??"{}").prerender?.some(h=>"urls"in h&&h.urls?.includes(r)))return!0;return!1})(e))if(s&&HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}else{let r=document.createElement("link");r.rel="prefetch",r.as="document",r.href=e,document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#e,strategy:this.#t}){let{anchors:e=this.getTrigger(),prerender:s=this.#e,strategy:i=this.#t}=t,n,r=(l=200)=>h=>{let{href:m}=h.currentTarget;n=setTimeout(()=>this.appendTag({url:m,prerender:s}),l)},a=()=>clearTimeout(n),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",r()),l.addEventListener("mouseout",a),l.addEventListener("focus",r()),l.addEventListener("focusout",a),l.addEventListener("touchstart",r(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#e}),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($(e,this.#t(e))).forEach(s=>t.appendChild(s))})}},$=(o,t)=>(s,i)=>{let n=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,n),j(t?i:s,n))},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#e(){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.#e||(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.#e&&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]);})();
@@ -1 +1 @@
1
- "use strict";(()=>{var m=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 i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof n)return i;throw new Error("Content not found")}swapContent(n=!0,i=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let t=Array.from(this.getContent().childNodes),s=[];e instanceof HTMLTemplateElement?(s.push(e.content.cloneNode(!0)),e.content.replaceChildren(...t)):(s.push(...e.childNodes),e.replaceChildren(...t)),this.getContent().replaceChildren(...s),n&&setTimeout(()=>this.swapContent(!1),i)}}safeListener(n,i,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(n,i,t)}triggerListener(n,i=this.event,e){for(let t of this.getTrigger())t.addEventListener(i,n,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var c=class extends m{constructor(){super()}get animationOptions(){let n={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let e=this.getAttribute(i),[,,t]=i.split("-");e&&(t==="duration"||t==="delay"?n[t]=Number(e):t==="easing"&&(n[t]=e))}return n}async animateElement(n={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:e={}}=n,t=this.keyframes;if(t.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let s=t.at(0),o=t.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let l of a)delete s[l],delete o[l]}e.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(i.style,s),await i.animate(t,e).finished,Object.assign(i.style,o)}}get keyframes(){let n=[];for(let i of this.getAttributeNames()){let e=this.getAttribute(i),[,,t,...s]=i.split("-");if(i.startsWith("animation-keyframe-")){let o=s.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(t&&o){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let r=Number(t),a=n.find(l=>l.offset===r);a?a[o]=e:n.push({[o]:e,offset:r})}}}return n.sort((i,e)=>Number(i.offset)-Number(e.offset)),n}};var f=class extends c{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",n=>{n.key==="Escape"&&this.dialog.open&&(n.preventDefault(),this.close())})}};customElements.define("drab-dialog",f);})();
1
+ "use strict";(()=>{var m=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 n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof t)return n;throw new Error("Content not found")}swapContent(t=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let i=Array.from(this.getContent().childNodes),s=[];e instanceof HTMLTemplateElement?(s.push(e.content.cloneNode(!0)),e.content.replaceChildren(...i)):(s.push(...e.childNodes),e.replaceChildren(...i)),this.getContent().replaceChildren(...s),t&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(t,n,e=document.body,i={}){i.signal=this.#t.signal,e.addEventListener(t,n,i)}triggerListener(t,n=this.event,e){for(let i of this.getTrigger())i.addEventListener(n,t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var c=class extends m{constructor(){super()}get animationOptions(){let t={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,i]=n.split("-");e&&(i==="duration"||i==="delay"?t[i]=Number(e):i==="easing"&&(t[i]=e))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let s=i.at(0),o=i.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let l of a)delete s[l],delete o[l]}e.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(n.style,s),await n.animate(i,e).finished,Object.assign(n.style,o)}}get keyframes(){let t=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,i,...s]=n.split("-");if(n.startsWith("animation-keyframe-")){let o=s.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(i&&o){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let r=Number(i),a=t.find(l=>l.offset===r);a?a[o]=e:t.push({[o]:e,offset:r})}}}return t.sort((n,e)=>Number(n.offset)-Number(e.offset)),t}};var f=class extends c{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 n=this.dialog.getBoundingClientRect();(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)&&this.close()})}};customElements.define("drab-dialog",f);})();
package/dialog/index.d.ts CHANGED
@@ -3,6 +3,11 @@ import type { Attributes } from "../types/index.js";
3
3
  export type DialogAttributes = Attributes<Dialog> & AnimateAttributes;
4
4
  /**
5
5
  * Provides triggers and animations for the `HTMLDialogElement`.
6
+ *
7
+ * `click-outside-close`
8
+ *
9
+ * By default, the `HTMLDialogElement` doesn't close if the user clicks outside of it.
10
+ * Add a `click-outside-close` attribute to close when the user clicks outside.
6
11
  */
7
12
  export declare class Dialog extends Animate {
8
13
  constructor();
@@ -1 +1 @@
1
- "use strict";(()=>{var m=class extends HTMLElement{#t=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 i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof n)return i;throw new Error("Content not found")}swapContent(n=!0,i=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let e=Array.from(this.getContent().childNodes),s=[];t instanceof HTMLTemplateElement?(s.push(t.content.cloneNode(!0)),t.content.replaceChildren(...e)):(s.push(...t.childNodes),t.replaceChildren(...e)),this.getContent().replaceChildren(...s),n&&setTimeout(()=>this.swapContent(!1),i)}}safeListener(n,i,t=document.body,e={}){e.signal=this.#t.signal,t.addEventListener(n,i,e)}triggerListener(n,i=this.event,t){for(let e of this.getTrigger())e.addEventListener(i,n,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var c=class extends m{constructor(){super()}get animationOptions(){let n={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let t=this.getAttribute(i),[,,e]=i.split("-");t&&(e==="duration"||e==="delay"?n[e]=Number(t):e==="easing"&&(n[e]=t))}return n}async animateElement(n={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:t={}}=n,e=this.keyframes;if(e.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){t=Object.assign(this.animationOptions,t),t.duration||(t.duration=200),t.easing||(t.easing="ease-in-out");let s=e.at(0),o=e.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let l of a)delete s[l],delete o[l]}t.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(i.style,s),await i.animate(e,t).finished,Object.assign(i.style,o)}}get keyframes(){let n=[];for(let i of this.getAttributeNames()){let t=this.getAttribute(i),[,,e,...s]=i.split("-");if(i.startsWith("animation-keyframe-")){let o=s.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(e&&o){e==="from"?e="0":e==="to"?e="1":e=String(parseInt(e)*.01);let r=Number(e),a=n.find(l=>l.offset===r);a?a[o]=t:n.push({[o]:t,offset:r})}}}return n.sort((i,t)=>Number(i.offset)-Number(t.offset)),n}};var u=class extends c{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",n=>{n.key==="Escape"&&this.dialog.open&&(n.preventDefault(),this.close())})}};})();
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 n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof t)return n;throw new Error("Content not found")}swapContent(t=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let i=Array.from(this.getContent().childNodes),s=[];e instanceof HTMLTemplateElement?(s.push(e.content.cloneNode(!0)),e.content.replaceChildren(...i)):(s.push(...e.childNodes),e.replaceChildren(...i)),this.getContent().replaceChildren(...s),t&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(t,n,e=document.body,i={}){i.signal=this.#t.signal,e.addEventListener(t,n,i)}triggerListener(t,n=this.event,e){for(let i of this.getTrigger())i.addEventListener(n,t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var m=class extends c{constructor(){super()}get animationOptions(){let t={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,i]=n.split("-");e&&(i==="duration"||i==="delay"?t[i]=Number(e):i==="easing"&&(t[i]=e))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let s=i.at(0),o=i.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let l of a)delete s[l],delete o[l]}e.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(n.style,s),await n.animate(i,e).finished,Object.assign(n.style,o)}}get keyframes(){let t=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,i,...s]=n.split("-");if(n.startsWith("animation-keyframe-")){let o=s.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(i&&o){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let r=Number(i),a=t.find(l=>l.offset===r);a?a[o]=e:t.push({[o]:e,offset:r})}}}return t.sort((n,e)=>Number(n.offset)-Number(e.offset)),t}};var d=class extends m{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 n=this.dialog.getBoundingClientRect();(t.clientX<n.left||t.clientX>n.right||t.clientY<n.top||t.clientY>n.bottom)&&this.close()})}};})();
package/dialog/index.js CHANGED
@@ -1,6 +1,11 @@
1
1
  import { Animate } from "../animate/index.js";
2
2
  /**
3
3
  * Provides triggers and animations for the `HTMLDialogElement`.
4
+ *
5
+ * `click-outside-close`
6
+ *
7
+ * By default, the `HTMLDialogElement` doesn't close if the user clicks outside of it.
8
+ * Add a `click-outside-close` attribute to close when the user clicks outside.
4
9
  */
5
10
  export class Dialog extends Animate {
6
11
  constructor() {
@@ -40,5 +45,17 @@ export class Dialog extends Animate {
40
45
  this.close();
41
46
  }
42
47
  });
48
+ if (this.hasAttribute("click-outside-close")) {
49
+ // https://blog.webdevsimplified.com/2023-04/html-dialog/#close-on-outside-click
50
+ this.dialog.addEventListener("click", (e) => {
51
+ const rect = this.dialog.getBoundingClientRect();
52
+ if (e.clientX < rect.left ||
53
+ e.clientX > rect.right ||
54
+ e.clientY < rect.top ||
55
+ e.clientY > rect.bottom) {
56
+ this.close();
57
+ }
58
+ });
59
+ }
43
60
  }
44
61
  }
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),n=[];s instanceof HTMLTemplateElement?(n.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(n.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...n),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 n=i.at(0),r=i.at(-1);if(n&&r){let u=["composite","easing","offset"];for(let a of u)delete n[a],delete r[a]}s.direction?.includes("reverse")&&([n,r]=[r,n]),Object.assign(e.style,n),await e.animate(i,s).finished,Object.assign(e.style,r)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...n]=e.split("-");if(e.startsWith("animation-keyframe-")){let r=n.map((o,u)=>u<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(i&&r){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let o=Number(i),u=t.find(a=>a.offset===o);u?u[r]=s:t.push({[r]:s,offset:o})}}}return t.sort((e,s)=>Number(e.offset)-Number(s.offset)),t}};var b=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#e(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,n=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,r=i+s,o=n+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,a=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;r+u>s+h&&(r=s+h-u),o+a>e+m&&(o=e+m-a),this.#e={x:r,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())})}};var E=class extends c{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#e)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#e(){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#s(){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:n}=this.#a(),r=t.value.at(0);r&&i[n]?.startsWith(r)?i[n]=t.value.trim()+i[n]:i[n]=t.value+i[n],this.text=i.join(`
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),n=[];s instanceof HTMLTemplateElement?(n.push(s.content.cloneNode(!0)),s.content.replaceChildren(...i)):(n.push(...s.childNodes),s.replaceChildren(...i)),this.getContent().replaceChildren(...n),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 n=i.at(0),r=i.at(-1);if(n&&r){let u=["composite","easing","offset"];for(let a of u)delete n[a],delete r[a]}s.direction?.includes("reverse")&&([n,r]=[r,n]),Object.assign(e.style,n),await e.animate(i,s).finished,Object.assign(e.style,r)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let s=this.getAttribute(e),[,,i,...n]=e.split("-");if(e.startsWith("animation-keyframe-")){let r=n.map((o,u)=>u<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(i&&r){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let o=Number(i),u=t.find(a=>a.offset===o);u?u[r]=s:t.push({[r]: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#e(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,n=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,r=i+s,o=n+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let u=this.getContent().offsetWidth+24,a=this.getContent().offsetHeight+6,h=window.innerWidth,m=window.innerHeight;r+u>s+h&&(r=s+h-u),o+a>e+m&&(o=e+m-a),this.#e={x:r,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.#e)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#e(){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#s(){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:n}=this.#a(),r=t.value.at(0);r&&i[n]?.startsWith(r)?i[n]=t.value.trim()+i[n]:i[n]=t.value+i[n],this.text=i.join(`
2
2
  `)}}async#h(t,e,s){let i=0,n=0;if(/[a-z]/i.test(t)){for(let r=s;r<this.text.length;r++)if(this.text[r]?.match(/[a-z]/i))i?n=r+1:i=r;else if(i)break}else i=e+t.length,n=s+t.length;this.#r(i,n),this.textArea.focus()}async#o(t){let e=this.#s,s=this.#i;await this.#c(t,s,e),this.#h(t.value,s,e)}#p(t){if(t){let e=[];this.#e.forEach(i=>{i.type==="block"&&e.push(i.value)});for(let i=0;i<e.length;i++){let n=e[i];if(n&&t.startsWith(n))return n}let s=w(t);if(s)return`${s}. `}return""}#a(){let t=this.text.split(`
3
3
  `),e=0;for(let s=0;s<t.length;s++){let i=t.at(s)?.length??0;if(e++,e+=i,e>this.#s)return{lines:t,lineNumber:s,columnNumber:this.#s-(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 n=s[i];if(n){let r=w(n);if(r){let o;if(e)if(r>1)o=r-1;else break;else o=r+1;s[i]=n.slice(String(r).length),s[i]=String(o)+s[i]}else break}}this.text=s.join(`
4
4
  `)}mount(){this.textArea.addEventListener("keydown",async t=>{let e=["ArrowUp","ArrowDown","Delete"],s=this.text[this.#s]??"";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 n=this.#i-1,r=this.#s-1;this.text=d(this.text,n),this.text=d(this.text,r),setTimeout(()=>{this.#r(n,r)},0),this.#t.pop()}if(i===`
5
5
  `&&this.#i===this.#s){t.preventDefault();let n=this.#i-1,{lineNumber:r}=this.#a();this.#u(r,!0),this.text=d(this.text,n),setTimeout(async()=>{this.#r(n,n)},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:n,columnNumber:r}=this.#a(),o=i.at(n),u=this.#p(o),a=u,h=w(u);if(h&&(u=`${h+1}. `),u&&a.length<r)t.preventDefault(),h&&this.#u(n),await this.#o({type:"inline",value:`
6
- ${u}`});else if(u&&a.length===r){t.preventDefault();let m=this.#s,g=m-a.length;for(let y=0;y<a.length;y++)this.text=d(this.text,m-(y+1));setTimeout(async()=>{this.#r(g,g),this.textArea.focus(),await this.#o({type:"inline",value:`
6
+ ${u}`});else if(u&&a.length===r){t.preventDefault();let m=this.#s,g=m-a.length;for(let b=0;b<a.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
7
  `})},0)}}else{let i=Object.values(this.keyPairs).includes(s),n=this.#i!==this.#s;if((t.ctrlKey||t.metaKey)&&this.#i===this.#s&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:r,lineNumber:o,columnNumber:u}=this.#a();if(await navigator.clipboard.writeText(`${o===0&&t.key==="x"?"":`
8
8
  `}${r[o]}`),t.key==="x"){let a=this.#i-u;r.splice(o,1),this.text=r.join(`
9
- `),setTimeout(()=>{this.#r(a,a)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#e.find(o=>o.key===t.key);r&&this.#o(r)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!n?(t.preventDefault(),this.#r(this.#i+1,this.#s+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.#s&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#s),this.text[this.#s-1]===" "&&this.#r(this.#i,this.#s-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},w=l=>{let t=l.match(/^(\d+)\./);return t?Number(t[1]):null},P=(l,t,e)=>l.slice(0,e)+t+l.slice(e),d=(l,t)=>l.slice(0,t)+l.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=[];#e=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#e.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 n of this.#t)n()}else{this.getContent().removeAttribute(s);for(let n of this.#e)n()}},{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{constructor(){super()}get#t(){return this.getAttribute("strategy")??"hover"}get#e(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!(r=>{if(document.querySelector(`link[href='${r}']`))return!0;let o=document.querySelectorAll(`script[type='${i}']`);for(let u of o)if(JSON.parse(u.textContent??"{}").prerender?.some(h=>"urls"in h&&h.urls?.includes(r)))return!0;return!1})(e))if(s&&HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}else{let r=document.createElement("link");r.rel="prefetch",r.as="document",r.href=e,document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#e,strategy:this.#t}){let{anchors:e=this.getTrigger(),prerender:s=this.#e,strategy:i=this.#t}=t,n,r=(a=200)=>h=>{let{href:m}=h.currentTarget;n=setTimeout(()=>this.appendTag({url:m,prerender:s}),a)},o=()=>clearTimeout(n),u=new IntersectionObserver(a=>{for(let h of a)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:s})});for(let a of e)i==="load"?this.appendTag({url:a.href,prerender:s}):i==="visible"?u.observe(a):(a.addEventListener("mouseover",r()),a.addEventListener("mouseout",o),a.addEventListener("focus",r()),a.addEventListener("focusout",o),a.addEventListener("touchstart",r(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#e}),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(B(e,this.#t(e))).forEach(s=>t.appendChild(s))})}},B=(l,t)=>(s,i)=>{let n=Array.from(l.parentNode?.children??[]).indexOf(l);return((o,u)=>{let a=l.dataset.type??"string";if(a==="string")return new Intl.Collator().compare(o,u);if(a==="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)})(j(t?s:i,n),j(t?i:s,n))},j=(l,t)=>{let e=l.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#e(){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.#e||(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.#e&&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(a,a)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#e.find(o=>o.key===t.key);r&&this.#o(r)}else i&&(s===t.key||t.key==="ArrowRight")&&this.#t.length&&!n?(t.preventDefault(),this.#r(this.#i+1,this.#s+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.#s&&(this.text[this.#i]===" "&&this.#r(this.#i+1,this.#s),this.text[this.#s-1]===" "&&this.#r(this.#i,this.#s-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#o(this.#l(t))})}},w=l=>{let t=l.match(/^(\d+)\./);return t?Number(t[1]):null},P=(l,t,e)=>l.slice(0,e)+t+l.slice(e),d=(l,t)=>l.slice(0,t)+l.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=[];#e=[];constructor(){super()}get#n(){return Number(this.getAttribute("threshold")??0)}onIntersect(t){this.#t.push(t)}onExit(t){this.#e.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 n of this.#t)n()}else{this.getContent().removeAttribute(s);for(let n of this.#e)n()}},{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{constructor(){super()}get#t(){return this.getAttribute("strategy")??"hover"}get#e(){return this.hasAttribute("prerender")}get#n(){return this.getAttribute("url")}appendTag(t){let{url:e,prerender:s}=t;if(e!==window.location.href){let i="speculationrules";if(!(r=>{if(document.querySelector(`link[href='${r}']`))return!0;let o=document.querySelectorAll(`script[type='${i}']`);for(let u of o)if(JSON.parse(u.textContent??"{}").prerender?.some(h=>"urls"in h&&h.urls?.includes(r)))return!0;return!1})(e))if(s&&HTMLScriptElement.supports&&HTMLScriptElement.supports(i)){let r=document.createElement("script");r.type=i,r.textContent=JSON.stringify({prerender:[{source:"list",urls:[e]}]}),document.head.append(r)}else{let r=document.createElement("link");r.rel="prefetch",r.as="document",r.href=e,document.head.append(r)}}}prefetch(t={anchors:this.getTrigger(),prerender:this.#e,strategy:this.#t}){let{anchors:e=this.getTrigger(),prerender:s=this.#e,strategy:i=this.#t}=t,n,r=(a=200)=>h=>{let{href:m}=h.currentTarget;n=setTimeout(()=>this.appendTag({url:m,prerender:s}),a)},o=()=>clearTimeout(n),u=new IntersectionObserver(a=>{for(let h of a)h.isIntersecting&&this.appendTag({url:h.target.href,prerender:s})});for(let a of e)i==="load"?this.appendTag({url:a.href,prerender:s}):i==="visible"?u.observe(a):(a.addEventListener("mouseover",r()),a.addEventListener("mouseout",o),a.addEventListener("focus",r()),a.addEventListener("focusout",o),a.addEventListener("touchstart",r(0),{passive:!0}))}mount(){this.#n&&this.appendTag({url:this.#n,prerender:this.#e}),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=(l,t)=>(s,i)=>{let n=Array.from(l.parentNode?.children??[]).indexOf(l);return((o,u)=>{let a=l.dataset.type??"string";if(a==="string")return new Intl.Collator().compare(o,u);if(a==="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,n),B(t?i:s,n))},B=(l,t)=>{let e=l.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#e(){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.#e||(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.#e&&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.1",
4
+ "version": "5.3.2",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {