drab 5.0.1 → 5.1.0

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.
Files changed (112) hide show
  1. package/animate/define.d.ts +1 -2
  2. package/animate/define.iife.js +1 -1
  3. package/animate/define.js +2 -1
  4. package/animate/index.d.ts +4 -6
  5. package/animate/index.iife.js +1 -1
  6. package/animate/index.js +138 -1
  7. package/{index-0rvQCq2U.d.ts → base/copy/index.d.ts} +2 -5
  8. package/base/copy/index.js +25 -0
  9. package/base/define.d.ts +1 -2
  10. package/base/define.iife.js +1 -1
  11. package/base/define.js +2 -1
  12. package/base/index.d.ts +8 -6
  13. package/base/index.iife.js +1 -1
  14. package/base/index.js +131 -1
  15. package/breakpoint/define.d.ts +1 -2
  16. package/breakpoint/define.iife.js +1 -1
  17. package/breakpoint/define.js +2 -1
  18. package/breakpoint/index.d.ts +5 -7
  19. package/breakpoint/index.iife.js +1 -1
  20. package/breakpoint/index.js +55 -1
  21. package/contextmenu/define.d.ts +1 -2
  22. package/contextmenu/define.iife.js +1 -1
  23. package/contextmenu/define.js +2 -1
  24. package/contextmenu/index.d.ts +4 -8
  25. package/contextmenu/index.iife.js +1 -1
  26. package/contextmenu/index.js +71 -1
  27. package/copy/define.d.ts +1 -2
  28. package/copy/define.iife.js +1 -1
  29. package/copy/define.js +2 -1
  30. package/copy/index.d.ts +4 -8
  31. package/copy/index.iife.js +1 -1
  32. package/copy/index.js +13 -1
  33. package/define/index.iife.js +9 -9
  34. package/define.d.ts +1 -0
  35. package/define.js +4 -0
  36. package/details/define.d.ts +1 -2
  37. package/details/define.iife.js +1 -1
  38. package/details/define.js +2 -1
  39. package/details/index.d.ts +4 -8
  40. package/details/index.iife.js +1 -1
  41. package/details/index.js +46 -1
  42. package/dialog/define.d.ts +1 -2
  43. package/dialog/define.iife.js +1 -1
  44. package/dialog/define.js +2 -1
  45. package/dialog/index.d.ts +4 -8
  46. package/dialog/index.iife.js +1 -1
  47. package/dialog/index.js +44 -1
  48. package/editor/define.d.ts +1 -2
  49. package/editor/define.iife.js +4 -4
  50. package/editor/define.js +2 -1
  51. package/editor/index.d.ts +5 -8
  52. package/editor/index.iife.js +4 -4
  53. package/editor/index.js +480 -1
  54. package/fullscreen/define.d.ts +1 -2
  55. package/fullscreen/define.iife.js +1 -1
  56. package/fullscreen/define.js +2 -1
  57. package/fullscreen/index.d.ts +4 -7
  58. package/fullscreen/index.iife.js +1 -1
  59. package/fullscreen/index.js +46 -1
  60. package/index.d.ts +15 -15
  61. package/index.iife.js +9 -9
  62. package/index.js +15 -1
  63. package/package.json +14 -4
  64. package/popover/define.d.ts +1 -2
  65. package/popover/define.iife.js +1 -1
  66. package/popover/define.js +2 -1
  67. package/popover/index.d.ts +4 -8
  68. package/popover/index.iife.js +1 -1
  69. package/popover/index.js +74 -1
  70. package/share/define.d.ts +1 -2
  71. package/share/define.iife.js +1 -1
  72. package/share/define.js +2 -1
  73. package/share/index.d.ts +4 -8
  74. package/share/index.iife.js +1 -1
  75. package/share/index.js +34 -1
  76. package/tablesort/define.d.ts +1 -2
  77. package/tablesort/define.iife.js +1 -1
  78. package/tablesort/define.js +2 -1
  79. package/tablesort/index.d.ts +4 -7
  80. package/tablesort/index.iife.js +1 -1
  81. package/tablesort/index.js +109 -1
  82. package/types/index.d.ts +11 -0
  83. package/types/index.js +1 -0
  84. package/wakelock/define.d.ts +1 -0
  85. package/wakelock/define.iife.js +1 -0
  86. package/wakelock/define.js +2 -0
  87. package/wakelock/index.d.ts +32 -0
  88. package/wakelock/index.iife.js +1 -0
  89. package/wakelock/index.js +88 -0
  90. package/youtube/define.d.ts +1 -2
  91. package/youtube/define.iife.js +1 -1
  92. package/youtube/define.js +2 -1
  93. package/youtube/index.d.ts +4 -7
  94. package/youtube/index.iife.js +1 -1
  95. package/youtube/index.js +56 -1
  96. package/chunk-3ASUSP4D.js +0 -1
  97. package/chunk-4WBITBA6.js +0 -1
  98. package/chunk-5JV4T7GM.js +0 -1
  99. package/chunk-7F7CQUEG.js +0 -1
  100. package/chunk-AWUCZCAJ.js +0 -1
  101. package/chunk-BCS5E3IH.js +0 -1
  102. package/chunk-DKKPV7QP.js +0 -1
  103. package/chunk-F5BEEHGA.js +0 -1
  104. package/chunk-GPET75FT.js +0 -9
  105. package/chunk-H4RNP4O4.js +0 -1
  106. package/chunk-LHXOPRVC.js +0 -1
  107. package/chunk-MXKU7AKV.js +0 -1
  108. package/chunk-VEVFQB5N.js +0 -1
  109. package/chunk-XAP2U34A.js +0 -1
  110. package/define/index.d.ts +0 -2
  111. package/define/index.js +0 -1
  112. package/index-J5TqSvEl.d.ts +0 -12
package/index.iife.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";(()=>{var h=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);i instanceof HTMLTemplateElement?this.getContent().replaceChildren(i.content.cloneNode(!0)):this.getContent().replaceChildren(...i.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...s),e)}}safeListener(t,e,i=document.body,s={}){s.signal=this.#t.signal,i.addEventListener(t,e,s)}triggerListener(t,e=this.event){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var m=class extends h{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 l=["composite","easing","offset"];for(let u of l)delete r[u],delete n[u]}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,l)=>l<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),l=t.find(u=>u.offset===o);l?l[n]=i:t.push({[n]:i,offset:o})}}}return t.sort((e,i)=>Number(e.offset)-Number(i.offset)),t}};var b=class extends h{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 m{#t;constructor(){super()}set#r(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 l=this.getContent().offsetWidth+24,u=this.getContent().offsetHeight+6,c=window.innerWidth,p=window.innerHeight;n+l>i+c&&(n=i+c-l),o+u>e+p&&(o=e+p-u),this.#r={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");let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend"),this.triggerListener(t,"touchcancel"),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends h{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 w=class extends m{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 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())})}};var k=class extends h{#t=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#r)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#r(){let t=[];for(let e of this.getTrigger())t.push(this.#a(e));return t}get#u(){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}#s(t,e){this.textArea.setSelectionRange(t,e)}#a(t){let e=t.dataset.type,i=t.dataset.value,s=t.dataset.key??void 0;return{type:e,value:i,key:s}}async#h(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=S(this.text,t.value,e),this.text=S(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.#o(),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#c(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.#s(s,r),this.textArea.focus()}async#n(t){let e=this.#e,i=this.#i;await this.#h(t,i,e),this.#c(t.value,i,e)}#m(t){if(t){let e=[];this.#r.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=E(t);if(i)return`${i}. `}return""}#o(){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}}#l(t,e=!1){let{lines:i}=this.#o();for(let s=t+1;s<i.length;s++){let r=i[s];if(r){let n=E(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=g(this.text,r),this.text=g(this.text,n),setTimeout(()=>{this.#s(r,n)},0),this.#t.pop()}if(s===`
5
- `&&this.#i===this.#e){t.preventDefault();let r=this.#i-1,{lineNumber:n}=this.#o();this.#l(n,!0),this.text=g(this.text,r),setTimeout(async()=>{this.#s(r,r)},0)}}else if(t.key==="Tab")this.#u%2!==0&&(t.preventDefault(),await this.#n({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:s,lineNumber:r,columnNumber:n}=this.#o(),o=s.at(r),l=this.#m(o),u=l,c=E(l);if(c&&(l=`${c+1}. `),l&&u.length<n)t.preventDefault(),c&&this.#l(r),await this.#n({type:"inline",value:`
6
- ${l}`});else if(l&&u.length===n){t.preventDefault();let p=this.#e,d=p-u.length;for(let y=0;y<u.length;y++)this.text=g(this.text,p-(y+1));setTimeout(async()=>{this.#s(d,d),this.textArea.focus(),await this.#n({type:"inline",value:`
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:l}=this.#o();if(await navigator.clipboard.writeText(`${o===0&&t.key==="x"?"":`
8
- `}${n[o]}`),t.key==="x"){let u=this.#i-l;n.splice(o,1),this.text=n.join(`
9
- `),setTimeout(()=>{this.#s(u,u)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let n=this.#r.find(o=>o.key===t.key);n&&this.#n(n)}else s&&(i===t.key||t.key==="ArrowRight")&&this.#t.length&&!r?(t.preventDefault(),this.#s(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#n({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#s(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#s(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#n(this.#a(t))})}},E=a=>{let t=a.match(/^(\d+)\./);return t?Number(t[1]):null},S=(a,t,e)=>a.slice(0,e)+t+a.slice(e),g=(a,t)=>a.slice(0,t)+a.slice(t+1);var T=class extends h{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 C=class extends m{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 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 M=class extends h{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(D(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},D=(a,t)=>(i,s)=>{let r=Array.from(a.parentNode?.children??[]).indexOf(a);return((o,l)=>{let u=a.dataset.type??"string";if(u==="string")return new Intl.Collator().compare(o,l);if(u==="boolean"){let c=p=>["0","false","null","undefined"].includes(p)?!1:!!p;return c(o)===c(l)?0:c(o)?-1:1}else return Number(o)-Number(l)})(N(t?i:s,r),N(t?s:i,r))},N=(a,t)=>{let e=a.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var H=class extends h{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":""}`})}};})();
1
+ "use strict";(()=>{var u=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),n=[];i instanceof HTMLTemplateElement?(n.push(i.content.cloneNode(!0)),i.content.replaceChildren(...s)):(n.push(...i.childNodes),i.replaceChildren(...s)),this.getContent().replaceChildren(...n),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){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var p=class extends u{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 n=s.at(0),r=s.at(-1);if(n&&r){let l=["composite","easing","offset"];for(let h of l)delete n[h],delete r[h]}i.direction?.includes("reverse")&&([n,r]=[r,n]),Object.assign(e.style,n),await e.animate(s,i).finished,Object.assign(e.style,r)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let i=this.getAttribute(e),[,,s,...n]=e.split("-");if(e.startsWith("animation-keyframe-")){let r=n.map((a,l)=>l<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(s&&r){s==="from"?s="0":s==="to"?s="1":s=String(parseInt(s)*.01);let a=Number(s),l=t.find(h=>h.offset===a);l?l[r]=i:t.push({[r]:i,offset:a})}}}return t.sort((e,i)=>Number(e.offset)-Number(i.offset)),t}};var b=class extends u{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,n=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,r=s+i,a=n+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let l=this.getContent().offsetWidth+24,h=this.getContent().offsetHeight+6,c=window.innerWidth,m=window.innerHeight;r+l>i+c&&(r=i+c-l),a+h>e+m&&(a=e+m-h),this.#s={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");let t=()=>clearTimeout(this.#t);this.triggerListener(t,"touchend"),this.triggerListener(t,"touchcancel"),this.safeListener("keydown",e=>{e.key==="Escape"&&this.hide()})}};var f=class extends u{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 w=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 u{#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.#a(e));return t}get#u(){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}#n(t,e){this.textArea.setSelectionRange(t,e)}#a(t){let e=t.dataset.type,i=t.dataset.value,s=t.dataset.key??void 0;return{type:e,value:i,key:s}}async#h(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=N(this.text,t.value,e),this.text=N(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:n}=this.#o(),r=t.value.at(0);r&&s[n]?.startsWith(r)?s[n]=t.value.trim()+s[n]:s[n]=t.value+s[n],this.text=s.join(`
2
+ `)}}async#c(t,e,i){let s=0,n=0;if(/[a-z]/i.test(t)){for(let r=i;r<this.text.length;r++)if(this.text[r]?.match(/[a-z]/i))s?n=r+1:s=r;else if(s)break}else s=e+t.length,n=i+t.length;this.#n(s,n),this.textArea.focus()}async#r(t){let e=this.#e,i=this.#i;await this.#h(t,i,e),this.#c(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 n=e[s];if(n&&t.startsWith(n))return n}let i=v(t);if(i)return`${i}. `}return""}#o(){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}}#l(t,e=!1){let{lines:i}=this.#o();for(let s=t+1;s<i.length;s++){let n=i[s];if(n){let r=v(n);if(r){let a;if(e)if(r>1)a=r-1;else break;else a=r+1;i[s]=n.slice(String(r).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 n=this.#i-1,r=this.#e-1;this.text=d(this.text,n),this.text=d(this.text,r),setTimeout(()=>{this.#n(n,r)},0),this.#t.pop()}if(s===`
5
+ `&&this.#i===this.#e){t.preventDefault();let n=this.#i-1,{lineNumber:r}=this.#o();this.#l(r,!0),this.text=d(this.text,n),setTimeout(async()=>{this.#n(n,n)},0)}}else if(t.key==="Tab")this.#u%2!==0&&(t.preventDefault(),await this.#r({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:s,lineNumber:n,columnNumber:r}=this.#o(),a=s.at(n),l=this.#p(a),h=l,c=v(l);if(c&&(l=`${c+1}. `),l&&h.length<r)t.preventDefault(),c&&this.#l(n),await this.#r({type:"inline",value:`
6
+ ${l}`});else if(l&&h.length===r){t.preventDefault();let m=this.#e,g=m-h.length;for(let y=0;y<h.length;y++)this.text=d(this.text,m-(y+1));setTimeout(async()=>{this.#n(g,g),this.textArea.focus(),await this.#r({type:"inline",value:`
7
+ `})},0)}}else{let s=Object.values(this.keyPairs).includes(i),n=this.#i!==this.#e;if((t.ctrlKey||t.metaKey)&&this.#i===this.#e&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:r,lineNumber:a,columnNumber:l}=this.#o();if(await navigator.clipboard.writeText(`${a===0&&t.key==="x"?"":`
8
+ `}${r[a]}`),t.key==="x"){let h=this.#i-l;r.splice(a,1),this.text=r.join(`
9
+ `),setTimeout(()=>{this.#n(h,h)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#s.find(a=>a.key===t.key);r&&this.#r(r)}else s&&(i===t.key||t.key==="ArrowRight")&&this.#t.length&&!n?(t.preventDefault(),this.#n(this.#i+1,this.#e+1),this.#t.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#r({type:"wrap",value:t.key}),this.#t.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#i!==this.#e&&(this.text[this.#i]===" "&&this.#n(this.#i+1,this.#e),this.text[this.#e-1]===" "&&this.#n(this.#i,this.#e-1))}),this.textArea.addEventListener("click",()=>this.#t=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#r(this.#a(t))})}},v=o=>{let t=o.match(/^(\d+)\./);return t?Number(t[1]):null},N=(o,t,e)=>o.slice(0,e)+t+o.slice(e),d=(o,t)=>o.slice(0,t)+o.slice(t+1);var L=class extends u{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 T=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 C=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 M=class extends u{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(P(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},P=(o,t)=>(i,s)=>{let n=Array.from(o.parentNode?.children??[]).indexOf(o);return((a,l)=>{let h=o.dataset.type??"string";if(h==="string")return new Intl.Collator().compare(a,l);if(h==="boolean"){let c=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return c(a)===c(l)?0:c(a)?-1:1}else return Number(a)-Number(l)})(D(t?i:s,n),D(t?s:i,n))},D=(o,t)=>{let e=o.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};var S=class extends u{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 H=class extends u{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/index.js CHANGED
@@ -1 +1,15 @@
1
- import{a as l}from"./chunk-3ASUSP4D.js";import{a as m}from"./chunk-VEVFQB5N.js";import{a as h}from"./chunk-GPET75FT.js";import{a as i}from"./chunk-5JV4T7GM.js";import{a as j}from"./chunk-DKKPV7QP.js";import{a as k}from"./chunk-4WBITBA6.js";import{a as d}from"./chunk-AWUCZCAJ.js";import{a as e}from"./chunk-XAP2U34A.js";import"./chunk-7F7CQUEG.js";import{a as f}from"./chunk-LHXOPRVC.js";import{a as g}from"./chunk-H4RNP4O4.js";import{a as b}from"./chunk-F5BEEHGA.js";import{a as c}from"./chunk-BCS5E3IH.js";import{b as a}from"./chunk-MXKU7AKV.js";export{b as Animate,a as Base,c as Breakpoint,d as ContextMenu,e as Copy,f as Details,g as Dialog,h as Editor,i as Fullscreen,j as Popover,k as Share,l as TableSort,m as YouTube};
1
+ import { Base } from "./base/index.js";
2
+ import { Animate } from "./animate/index.js";
3
+ import { Breakpoint } from "./breakpoint/index.js";
4
+ import { ContextMenu, } from "./contextmenu/index.js";
5
+ import { Copy } from "./copy/index.js";
6
+ import { Details } from "./details/index.js";
7
+ import { Dialog } from "./dialog/index.js";
8
+ import { Editor } from "./editor/index.js";
9
+ import { Fullscreen } from "./fullscreen/index.js";
10
+ import { Popover } from "./popover/index.js";
11
+ import { Share } from "./share/index.js";
12
+ import { TableSort } from "./tablesort/index.js";
13
+ import { WakeLock } from "./wakelock/index.js";
14
+ import { YouTube } from "./youtube/index.js";
15
+ export { Base, Animate, Breakpoint, ContextMenu, Copy, Details, Dialog, Editor, Fullscreen, Popover, Share, TableSort, WakeLock, YouTube, };
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.0.1",
4
+ "version": "5.1.0",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -12,6 +12,7 @@
12
12
  "web components",
13
13
  "custom elements",
14
14
  "animate",
15
+ "wakelock",
15
16
  "contextmenu",
16
17
  "details",
17
18
  "youtube",
@@ -46,6 +47,14 @@
46
47
  "types": "./animate/define.d.ts",
47
48
  "default": "./animate/define.js"
48
49
  },
50
+ "./wakelock": {
51
+ "types": "./wakelock/index.d.ts",
52
+ "default": "./wakelock/index.js"
53
+ },
54
+ "./wakelock/define": {
55
+ "types": "./wakelock/define.d.ts",
56
+ "default": "./wakelock/define.js"
57
+ },
49
58
  "./contextmenu": {
50
59
  "types": "./contextmenu/index.d.ts",
51
60
  "default": "./contextmenu/index.js"
@@ -149,9 +158,10 @@
149
158
  "preview": "vite preview",
150
159
  "format": "prettier --write .",
151
160
  "doc": "typedoc --out src/lib/docs --plugin typedoc-plugin-markdown src/package/index.ts --hideBreadcrumbs --hideInPageTOC --githubPages false --publicPath /docs/ && bun src/lib/scripts/doc/index.ts && bun format",
152
- "copy": "cp package.json ./package && cp README.md ./package && cp LICENSE.md ./package",
153
- "json": "bun src/lib/scripts/packageJson/index.ts && prettier --write package.json",
154
- "package": "bun json && tsup && bun copy",
161
+ "package:json": "bun src/lib/scripts/packageJson/index.ts && prettier --write package.json",
162
+ "package:copy": "cp package.json ./package && cp README.md ./package && cp LICENSE.md ./package",
163
+ "package:tsc": "tsc --project tsconfig.package.json",
164
+ "package": "bun package:json && tsup && bun package:tsc && bun package:copy",
155
165
  "pub": "bun i && bun doc && bun package && npm publish --access public ./package"
156
166
  },
157
167
  "devDependencies": {
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var l=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof e)return i;throw new Error("Content not found")}swapContent(e=!0,i=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let n=Array.from(this.getContent().childNodes);t instanceof HTMLTemplateElement?this.getContent().replaceChildren(t.content.cloneNode(!0)):this.getContent().replaceChildren(...t.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...n),i)}}safeListener(e,i,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(e,i,n)}triggerListener(e,i=this.event){for(let t of this.getTrigger())t.addEventListener(i,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var f=class extends l{constructor(){super()}get animationOptions(){let e={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let t=this.getAttribute(i),[,,n]=i.split("-");t&&(n==="duration"||n==="delay"?e[n]=Number(t):n==="easing"&&(e[n]=t))}return e}async animateElement(e={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:t={}}=e,n=this.keyframes;if(n.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 o=n.at(0),s=n.at(-1);if(o&&s){let a=["composite","easing","offset"];for(let m of a)delete o[m],delete s[m]}t.direction?.includes("reverse")&&([o,s]=[s,o]),Object.assign(i.style,o),await i.animate(n,t).finished,Object.assign(i.style,s)}}get keyframes(){let e=[];for(let i of this.getAttributeNames()){let t=this.getAttribute(i),[,,n,...o]=i.split("-");if(i.startsWith("animation-keyframe-")){let s=o.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(n&&s){n==="from"?n="0":n==="to"?n="1":n=String(parseInt(n)*.01);let r=Number(n),a=e.find(m=>m.offset===r);a?a[s]=t:e.push({[s]:t,offset:r})}}}return e.sort((i,t)=>Number(i.offset)-Number(t.offset)),e}};var p=class extends f{constructor(){super()}get open(){return this.hasAttribute("open")}set open(e){e?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(e=>{e.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",e=>{e.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.open&&(e.preventDefault(),this.hide())})}};customElements.define("drab-popover",p);})();
1
+ "use strict";(()=>{var l=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof e)return i;throw new Error("Content not found")}swapContent(e=!0,i=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),e&&setTimeout(()=>this.swapContent(!1),i)}}safeListener(e,i,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(e,i,n)}triggerListener(e,i=this.event){for(let t of this.getTrigger())t.addEventListener(i,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var f=class extends l{constructor(){super()}get animationOptions(){let e={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let t=this.getAttribute(i),[,,n]=i.split("-");t&&(n==="duration"||n==="delay"?e[n]=Number(t):n==="easing"&&(e[n]=t))}return e}async animateElement(e={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:t={}}=e,n=this.keyframes;if(n.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=n.at(0),o=n.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let m of a)delete s[m],delete o[m]}t.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(i.style,s),await i.animate(n,t).finished,Object.assign(i.style,o)}}get keyframes(){let e=[];for(let i of this.getAttributeNames()){let t=this.getAttribute(i),[,,n,...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(n&&o){n==="from"?n="0":n==="to"?n="1":n=String(parseInt(n)*.01);let r=Number(n),a=e.find(m=>m.offset===r);a?a[o]=t:e.push({[o]:t,offset:r})}}}return e.sort((i,t)=>Number(i.offset)-Number(t.offset)),e}};var p=class extends f{constructor(){super()}get open(){return this.hasAttribute("open")}set open(e){e?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(e=>{e.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",e=>{e.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.open&&(e.preventDefault(),this.hide())})}};customElements.define("drab-popover",p);})();
package/popover/define.js CHANGED
@@ -1 +1,2 @@
1
- import{a as o}from"../chunk-DKKPV7QP.js";import"../chunk-F5BEEHGA.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-popover",o);
1
+ import { Popover } from "./index.js";
2
+ customElements.define("drab-popover", Popover);
@@ -1,8 +1,6 @@
1
- import { AnimateAttributes, Animate } from '../animate/index.js';
2
- import { A as Attributes } from '../index-J5TqSvEl.js';
3
- import '../base/index.js';
4
-
5
- type PopoverAttributes = Attributes<Popover> & AnimateAttributes;
1
+ import { Animate, type AnimateAttributes } from "../animate/index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type PopoverAttributes = Attributes<Popover> & AnimateAttributes;
6
4
  /**
7
5
  * Provides animations for the Popover API.
8
6
  *
@@ -11,7 +9,7 @@ type PopoverAttributes = Attributes<Popover> & AnimateAttributes;
11
9
  * This component can be deprecated once it can be animated with CSS only,
12
10
  * currently [only available in Chrome](https://developer.chrome.com/blog/introducing-popover-api#interactive_entry_and_exit).
13
11
  */
14
- declare class Popover extends Animate {
12
+ export declare class Popover extends Animate {
15
13
  constructor();
16
14
  /**
17
15
  * Whether the popover is open or closed. This doesn't get set
@@ -27,5 +25,3 @@ declare class Popover extends Animate {
27
25
  toggle(): Promise<void>;
28
26
  mount(): void;
29
27
  }
30
-
31
- export { Popover, type PopoverAttributes };
@@ -1 +1 @@
1
- "use strict";(()=>{var m=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof e)return i;throw new Error("Content not found")}swapContent(e=!0,i=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let n=Array.from(this.getContent().childNodes);t instanceof HTMLTemplateElement?this.getContent().replaceChildren(t.content.cloneNode(!0)):this.getContent().replaceChildren(...t.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...n),i)}}safeListener(e,i,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(e,i,n)}triggerListener(e,i=this.event){for(let t of this.getTrigger())t.addEventListener(i,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var f=class extends m{constructor(){super()}get animationOptions(){let e={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let t=this.getAttribute(i),[,,n]=i.split("-");t&&(n==="duration"||n==="delay"?e[n]=Number(t):n==="easing"&&(e[n]=t))}return e}async animateElement(e={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:t={}}=e,n=this.keyframes;if(n.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 o=n.at(0),s=n.at(-1);if(o&&s){let a=["composite","easing","offset"];for(let l of a)delete o[l],delete s[l]}t.direction?.includes("reverse")&&([o,s]=[s,o]),Object.assign(i.style,o),await i.animate(n,t).finished,Object.assign(i.style,s)}}get keyframes(){let e=[];for(let i of this.getAttributeNames()){let t=this.getAttribute(i),[,,n,...o]=i.split("-");if(i.startsWith("animation-keyframe-")){let s=o.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(n&&s){n==="from"?n="0":n==="to"?n="1":n=String(parseInt(n)*.01);let r=Number(n),a=e.find(l=>l.offset===r);a?a[s]=t:e.push({[s]:t,offset:r})}}}return e.sort((i,t)=>Number(i.offset)-Number(t.offset)),e}};var c=class extends f{constructor(){super()}get open(){return this.hasAttribute("open")}set open(e){e?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(e=>{e.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",e=>{e.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.open&&(e.preventDefault(),this.hide())})}};})();
1
+ "use strict";(()=>{var m=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let i=this.querySelector(this.getAttribute("content")??"[data-content]");if(i instanceof e)return i;throw new Error("Content not found")}swapContent(e=!0,i=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),e&&setTimeout(()=>this.swapContent(!1),i)}}safeListener(e,i,t=document.body,n={}){n.signal=this.#e.signal,t.addEventListener(e,i,n)}triggerListener(e,i=this.event){for(let t of this.getTrigger())t.addEventListener(i,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var f=class extends m{constructor(){super()}get animationOptions(){let e={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let t=this.getAttribute(i),[,,n]=i.split("-");t&&(n==="duration"||n==="delay"?e[n]=Number(t):n==="easing"&&(e[n]=t))}return e}async animateElement(e={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:t={}}=e,n=this.keyframes;if(n.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=n.at(0),o=n.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(n,t).finished,Object.assign(i.style,o)}}get keyframes(){let e=[];for(let i of this.getAttributeNames()){let t=this.getAttribute(i),[,,n,...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(n&&o){n==="from"?n="0":n==="to"?n="1":n=String(parseInt(n)*.01);let r=Number(n),a=e.find(l=>l.offset===r);a?a[o]=t:e.push({[o]:t,offset:r})}}}return e.sort((i,t)=>Number(i.offset)-Number(t.offset)),e}};var c=class extends f{constructor(){super()}get open(){return this.hasAttribute("open")}set open(e){e?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(e=>{e.preventDefault(),this.toggle()}),this.getContent().addEventListener("toggle",e=>{e.newState==="open"?this.open=!0:this.open=!1}),this.safeListener("keydown",e=>{e.key==="Escape"&&this.open&&(e.preventDefault(),this.hide())})}};})();
package/popover/index.js CHANGED
@@ -1 +1,74 @@
1
- import{a}from"../chunk-DKKPV7QP.js";import"../chunk-F5BEEHGA.js";import"../chunk-MXKU7AKV.js";export{a as Popover};
1
+ import { Animate } from "../animate/index.js";
2
+ /**
3
+ * Provides animations for the Popover API.
4
+ *
5
+ * The Popover API is not currently support in FireFox. [See the latest browser compatibility on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API#browser_compatibility).
6
+ *
7
+ * This component can be deprecated once it can be animated with CSS only,
8
+ * currently [only available in Chrome](https://developer.chrome.com/blog/introducing-popover-api#interactive_entry_and_exit).
9
+ */
10
+ export class Popover extends Animate {
11
+ constructor() {
12
+ super();
13
+ }
14
+ /**
15
+ * Whether the popover is open or closed. This doesn't get set
16
+ * automatically on the element like with the `HTMLDialogElement`.
17
+ */
18
+ get open() {
19
+ return this.hasAttribute("open");
20
+ }
21
+ set open(value) {
22
+ if (value) {
23
+ this.setAttribute("open", "");
24
+ }
25
+ else {
26
+ this.removeAttribute("open");
27
+ }
28
+ }
29
+ /** `HTMLElement.showPopover()` with animation. */
30
+ async show() {
31
+ // @ts-ignore - not supported in FF
32
+ this.getContent().showPopover();
33
+ await this.animateElement();
34
+ }
35
+ /** `HTMLElement.hidePopover()` with animation. */
36
+ async hide() {
37
+ await this.animateElement({
38
+ options: {
39
+ direction: "reverse",
40
+ },
41
+ });
42
+ // @ts-ignore - not supported in FF
43
+ this.getContent().hidePopover();
44
+ }
45
+ /** `show` or `hide` depending on the current state. */
46
+ async toggle() {
47
+ if (this.open)
48
+ this.hide();
49
+ else
50
+ this.show();
51
+ }
52
+ mount() {
53
+ this.triggerListener((e) => {
54
+ e.preventDefault();
55
+ this.toggle();
56
+ });
57
+ this.getContent().addEventListener("toggle", (e) => {
58
+ //@ts-expect-error - not supported in FF as of 1/23/24
59
+ if (e.newState === "open") {
60
+ this.open = true;
61
+ }
62
+ else {
63
+ this.open = false;
64
+ }
65
+ });
66
+ this.safeListener("keydown", (e) => {
67
+ if (e.key === "Escape" && this.open) {
68
+ // to execute animation
69
+ e.preventDefault();
70
+ this.hide();
71
+ }
72
+ });
73
+ }
74
+ }
package/share/define.d.ts CHANGED
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var i=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var o=class extends i{constructor(){super()}async share(e=this.value){if(navigator.canShare&&navigator.canShare({url:e}))try{await navigator.share({url:e})}catch(t){t?.name!=="AbortError"&&console.error(t)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};customElements.define("drab-share",o);})();
1
+ "use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes),a=[];n instanceof HTMLTemplateElement?(a.push(n.content.cloneNode(!0)),n.content.replaceChildren(...r)):(a.push(...n.childNodes),n.replaceChildren(...r)),this.getContent().replaceChildren(...a),e&&setTimeout(()=>this.swapContent(!1),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var o=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var i=class extends o{constructor(){super()}async share(e=this.value){if(navigator.canShare&&navigator.canShare({url:e}))try{await navigator.share({url:e})}catch(t){t?.name!=="AbortError"&&console.error(t)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};customElements.define("drab-share",i);})();
package/share/define.js CHANGED
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-4WBITBA6.js";import"../chunk-7F7CQUEG.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-share",e);
1
+ import { Share } from "./index.js";
2
+ customElements.define("drab-share", Share);
package/share/index.d.ts CHANGED
@@ -1,12 +1,10 @@
1
- import { B as BaseCopy } from '../index-0rvQCq2U.js';
2
- import { A as Attributes } from '../index-J5TqSvEl.js';
3
- import '../base/index.js';
4
-
5
- type ShareAttributes = Attributes<Share, "value">;
1
+ import { BaseCopy } from "../base/copy/index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type ShareAttributes = Attributes<Share, "value">;
6
4
  /**
7
5
  * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) to share a url. If `share` is not supported, falls back to copy the text instead.
8
6
  */
9
- declare class Share extends BaseCopy {
7
+ export declare class Share extends BaseCopy {
10
8
  constructor();
11
9
  /**
12
10
  * Shares or copies the `value`.
@@ -17,5 +15,3 @@ declare class Share extends BaseCopy {
17
15
  share(url?: string): Promise<void>;
18
16
  mount(): void;
19
17
  }
20
-
21
- export { Share, type ShareAttributes };
@@ -1 +1 @@
1
- "use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),e&&setTimeout(()=>this.getContent().replaceChildren(...r),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var i=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var a=class extends i{constructor(){super()}async share(e=this.value){if(navigator.canShare&&navigator.canShare({url:e}))try{await navigator.share({url:e})}catch(t){t?.name!=="AbortError"&&console.error(t)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};})();
1
+ "use strict";(()=>{var s=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let t=this.querySelector(this.getAttribute("content")??"[data-content]");if(t instanceof e)return t;throw new Error("Content not found")}swapContent(e=!0,t=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes),i=[];n instanceof HTMLTemplateElement?(i.push(n.content.cloneNode(!0)),n.content.replaceChildren(...r)):(i.push(...n.childNodes),n.replaceChildren(...r)),this.getContent().replaceChildren(...i),e&&setTimeout(()=>this.swapContent(!1),t)}}safeListener(e,t,n=document.body,r={}){r.signal=this.#e.signal,n.addEventListener(e,t,r)}triggerListener(e,t=this.event){for(let n of this.getTrigger())n.addEventListener(t,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var o=class extends s{constructor(){super()}get value(){return this.getAttribute("value")??""}set value(e){this.setAttribute("value",e)}async copy(e=this.value){await navigator.clipboard.writeText(e),this.swapContent()}};var c=class extends o{constructor(){super()}async share(e=this.value){if(navigator.canShare&&navigator.canShare({url:e}))try{await navigator.share({url:e})}catch(t){t?.name!=="AbortError"&&console.error(t)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};})();
package/share/index.js CHANGED
@@ -1 +1,34 @@
1
- import{a}from"../chunk-4WBITBA6.js";import"../chunk-7F7CQUEG.js";import"../chunk-MXKU7AKV.js";export{a as Share};
1
+ import { BaseCopy } from "../base/copy/index.js";
2
+ /**
3
+ * Uses the [Navigator API](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share) to share a url. If `share` is not supported, falls back to copy the text instead.
4
+ */
5
+ export class Share extends BaseCopy {
6
+ constructor() {
7
+ super();
8
+ }
9
+ /**
10
+ * Shares or copies the `value`.
11
+ * @param url The `url` to share, defaults to `this.value`
12
+ * @returns An object containing a `result` - whether the `url` was copied or shared
13
+ * depending on browser support.
14
+ */
15
+ async share(url = this.value) {
16
+ if (navigator.canShare && navigator.canShare({ url })) {
17
+ try {
18
+ await navigator.share({ url });
19
+ }
20
+ catch (error) {
21
+ if (error?.name !== "AbortError") {
22
+ console.error(error);
23
+ }
24
+ }
25
+ }
26
+ else {
27
+ // progressively enhance, copy the link
28
+ this.copy();
29
+ }
30
+ }
31
+ mount() {
32
+ this.triggerListener(async () => await this.share());
33
+ }
34
+ }
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var n=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);i instanceof HTMLTemplateElement?this.getContent().replaceChildren(i.content.cloneNode(!0)):this.getContent().replaceChildren(...i.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...s),e)}}safeListener(t,e,i=document.body,s={}){s.signal=this.#t.signal,i.addEventListener(t,e,s)}triggerListener(t,e=this.event){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var o=class extends n{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(d(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},d=(r,t)=>(i,s)=>{let c=Array.from(r.parentNode?.children??[]).indexOf(r);return((a,h)=>{let m=r.dataset.type??"string";if(m==="string")return new Intl.Collator().compare(a,h);if(m==="boolean"){let l=p=>["0","false","null","undefined"].includes(p)?!1:!!p;return l(a)===l(h)?0:l(a)?-1:1}else return Number(a)-Number(h)})(f(t?i:s,c),f(t?s:i,c))},f=(r,t)=>{let e=r.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};customElements.define("drab-tablesort",o);})();
1
+ "use strict";(()=>{var n=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),o=[];i instanceof HTMLTemplateElement?(o.push(i.content.cloneNode(!0)),i.content.replaceChildren(...s)):(o.push(...i.childNodes),i.replaceChildren(...s)),this.getContent().replaceChildren(...o),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){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var a=class extends n{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(g(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},g=(r,t)=>(i,s)=>{let o=Array.from(r.parentNode?.children??[]).indexOf(r);return((l,c)=>{let p=r.dataset.type??"string";if(p==="string")return new Intl.Collator().compare(l,c);if(p==="boolean"){let u=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return u(l)===u(c)?0:u(l)?-1:1}else return Number(l)-Number(c)})(f(t?i:s,o),f(t?s:i,o))},f=(r,t)=>{let e=r.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};customElements.define("drab-tablesort",a);})();
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-3ASUSP4D.js";import"../chunk-VEVFQB5N.js";import"../chunk-GPET75FT.js";import"../chunk-5JV4T7GM.js";import"../chunk-DKKPV7QP.js";import"../chunk-4WBITBA6.js";import"../chunk-AWUCZCAJ.js";import"../chunk-XAP2U34A.js";import"../chunk-7F7CQUEG.js";import"../chunk-LHXOPRVC.js";import"../chunk-H4RNP4O4.js";import"../chunk-F5BEEHGA.js";import"../chunk-BCS5E3IH.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-tablesort",e);
1
+ import { TableSort } from "./index.js";
2
+ customElements.define("drab-tablesort", TableSort);
@@ -1,7 +1,6 @@
1
- import { Base } from '../base/index.js';
2
- import { A as Attributes } from '../index-J5TqSvEl.js';
3
-
4
- type TableSortAttributes = Attributes<TableSort>;
1
+ import { Base } from "../index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type TableSortAttributes = Attributes<TableSort>;
5
4
  /**
6
5
  * Wrap a `HTMLTableElement` in the `TableSort` element to have sortable column
7
6
  * headers. Set each `th` that you want to sort to the `trigger`. Set the `tbody`
@@ -15,10 +14,8 @@ type TableSortAttributes = Attributes<TableSort>;
15
14
  * datatype `number` or `boolean`, set `data-type="number"` on the corresponding
16
15
  * `th`/`trigger` element. The data will be converted to the specified type before sorting.
17
16
  */
18
- declare class TableSort extends Base {
17
+ export declare class TableSort extends Base {
19
18
  #private;
20
19
  constructor();
21
20
  mount(): void;
22
21
  }
23
-
24
- export { TableSort, type TableSortAttributes };
@@ -1 +1 @@
1
- "use strict";(()=>{var n=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);i instanceof HTMLTemplateElement?this.getContent().replaceChildren(i.content.cloneNode(!0)):this.getContent().replaceChildren(...i.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...s),e)}}safeListener(t,e,i=document.body,s={}){s.signal=this.#t.signal,i.addEventListener(t,e,s)}triggerListener(t,e=this.event){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var h=class extends n{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(d(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},d=(r,t)=>(i,s)=>{let c=Array.from(r.parentNode?.children??[]).indexOf(r);return((o,u)=>{let m=r.dataset.type??"string";if(m==="string")return new Intl.Collator().compare(o,u);if(m==="boolean"){let a=p=>["0","false","null","undefined"].includes(p)?!1:!!p;return a(o)===a(u)?0:a(o)?-1:1}else return Number(o)-Number(u)})(f(t?i:s,c),f(t?s:i,c))},f=(r,t)=>{let e=r.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};})();
1
+ "use strict";(()=>{var n=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),o=[];i instanceof HTMLTemplateElement?(o.push(i.content.cloneNode(!0)),i.content.replaceChildren(...s)):(o.push(...i.childNodes),i.replaceChildren(...s)),this.getContent().replaceChildren(...o),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){for(let i of this.getTrigger())i.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var c=class extends n{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(g(e,this.#t(e))).forEach(i=>t.appendChild(i))})}},g=(r,t)=>(i,s)=>{let o=Array.from(r.parentNode?.children??[]).indexOf(r);return((a,h)=>{let p=r.dataset.type??"string";if(p==="string")return new Intl.Collator().compare(a,h);if(p==="boolean"){let l=m=>["0","false","null","undefined"].includes(m)?!1:!!m;return l(a)===l(h)?0:l(a)?-1:1}else return Number(a)-Number(h)})(f(t?i:s,o),f(t?s:i,o))},f=(r,t)=>{let e=r.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};})();
@@ -1 +1,109 @@
1
- import{a}from"../chunk-3ASUSP4D.js";import"../chunk-VEVFQB5N.js";import"../chunk-GPET75FT.js";import"../chunk-5JV4T7GM.js";import"../chunk-DKKPV7QP.js";import"../chunk-4WBITBA6.js";import"../chunk-AWUCZCAJ.js";import"../chunk-XAP2U34A.js";import"../chunk-7F7CQUEG.js";import"../chunk-LHXOPRVC.js";import"../chunk-H4RNP4O4.js";import"../chunk-F5BEEHGA.js";import"../chunk-BCS5E3IH.js";import"../chunk-MXKU7AKV.js";export{a as TableSort};
1
+ import { Base } from "../index.js";
2
+ /**
3
+ * Wrap a `HTMLTableElement` in the `TableSort` element to have sortable column
4
+ * headers. Set each `th` that you want to sort to the `trigger`. Set the `tbody`
5
+ * element to the `content`.
6
+ *
7
+ * The values of each cell default to the cell's `textContent`. If you would like to
8
+ * provide an alternate value than what appears in the cell to sort by instead,
9
+ * you can set a different value using the `data-value` attribute on the cell.
10
+ *
11
+ * The cells will be sorted as `string` by default. If you want to provide a different
12
+ * datatype `number` or `boolean`, set `data-type="number"` on the corresponding
13
+ * `th`/`trigger` element. The data will be converted to the specified type before sorting.
14
+ */
15
+ export class TableSort extends Base {
16
+ constructor() {
17
+ super();
18
+ }
19
+ /**
20
+ * Removes `data-asc` or `data-desc` from other triggers then sets the correct attribute on the selected trigger.
21
+ *
22
+ * @param trigger
23
+ * @returns true if ascending, false if descending
24
+ */
25
+ #setAttributes(trigger) {
26
+ const asc = "data-asc";
27
+ const desc = "data-desc";
28
+ for (const t of this.getTrigger()) {
29
+ if (t !== trigger) {
30
+ t.removeAttribute(asc);
31
+ t.removeAttribute(desc);
32
+ }
33
+ }
34
+ if (trigger.hasAttribute(asc)) {
35
+ trigger.removeAttribute(asc);
36
+ trigger.setAttribute(desc, "");
37
+ return false;
38
+ }
39
+ trigger.removeAttribute(desc);
40
+ trigger.setAttribute(asc, "");
41
+ return true;
42
+ }
43
+ mount() {
44
+ const tbody = this.getContent(HTMLTableSectionElement);
45
+ for (const trigger of this.getTrigger()) {
46
+ trigger.addEventListener(this.event, () => {
47
+ Array.from(tbody.querySelectorAll("tr"))
48
+ .sort(comparer(trigger, this.#setAttributes(trigger)))
49
+ .forEach((tr) => tbody.appendChild(tr));
50
+ });
51
+ }
52
+ }
53
+ }
54
+ // adapted from: https://stackoverflow.com/questions/14267781/sorting-html-table-with-javascript/49041392#49041392
55
+ const comparer = (th, ascending) => {
56
+ // this function is returned and used by `sort`
57
+ const sorter = (a, b) => {
58
+ // find the column to sort by using the index of the `th`
59
+ const columnIndex = Array.from(th.parentNode?.children ?? []).indexOf(th);
60
+ const compare = (aVal, bVal) => {
61
+ // default to `string` sorting
62
+ const dataType = (th.dataset.type ?? "string");
63
+ if (dataType === "string") {
64
+ const collator = new Intl.Collator();
65
+ return collator.compare(aVal, bVal);
66
+ }
67
+ else if (dataType === "boolean") {
68
+ /**
69
+ * if value is one of these and type is boolean
70
+ * it should be considered falsy
71
+ * since actually `Boolean("false") === true`
72
+ * @param val string pulled from the textContent or attr
73
+ * @returns a boolean of the provided string
74
+ */
75
+ const convertToBoolean = (val) => {
76
+ const falsy = ["0", "false", "null", "undefined"];
77
+ if (falsy.includes(val)) {
78
+ return false;
79
+ }
80
+ return Boolean(val);
81
+ };
82
+ return convertToBoolean(aVal) === convertToBoolean(bVal)
83
+ ? 0
84
+ : convertToBoolean(aVal)
85
+ ? -1
86
+ : 1;
87
+ }
88
+ else {
89
+ // "number"
90
+ return Number(aVal) - Number(bVal);
91
+ }
92
+ };
93
+ return compare(getValue(ascending ? a : b, columnIndex), getValue(ascending ? b : a, columnIndex));
94
+ };
95
+ return sorter;
96
+ };
97
+ /**
98
+ * @param tr the row
99
+ * @param i index of the `td` to find
100
+ * @returns a string, the `data-value` attribute, or the `textContent`
101
+ */
102
+ const getValue = (tr, i) => {
103
+ const cell = tr.children[i];
104
+ if (cell instanceof HTMLElement) {
105
+ // first look for `data-value` attribute, then use `textContent`
106
+ return cell.dataset.value ?? cell.textContent ?? "";
107
+ }
108
+ return "";
109
+ };
@@ -0,0 +1,11 @@
1
+ type BaseAttributes = {
2
+ trigger: string;
3
+ content: string;
4
+ swap: string;
5
+ };
6
+ /**
7
+ * Creates a partial of the custom element's type. Makes some attributes required
8
+ * if passed in.
9
+ */
10
+ export type Attributes<CustomElement, Required extends keyof CustomElement = never> = Pick<CustomElement, Required> & Partial<Omit<CustomElement, Required>> & Partial<BaseAttributes>;
11
+ export {};
package/types/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var i=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(e){this.setAttribute("event",e)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(e=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof e)return n;throw new Error("Content not found")}swapContent(e=!0,n=800){let t=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(t){let s=Array.from(this.getContent().childNodes),o=[];t instanceof HTMLTemplateElement?(o.push(t.content.cloneNode(!0)),t.content.replaceChildren(...s)):(o.push(...t.childNodes),t.replaceChildren(...s)),this.getContent().replaceChildren(...o),e&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(e,n,t=document.body,s={}){s.signal=this.#e.signal,t.addEventListener(e,n,s)}triggerListener(e,n=this.event){for(let t of this.getTrigger())t.addEventListener(n,e)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var r=class extends i{wakeLock=null;constructor(){super()}#e(){return"wakeLock"in navigator}get#t(){return this.hasAttribute("auto-lock")}async request(){this.#e()&&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.#t||(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 e of this.getTrigger())!this.#e()&&"disabled"in e&&(e.disabled=!0);this.#t&&this.safeListener("visibilitychange",()=>{this.wakeLock&&this.request()},document)}destroy(){this.release()}};customElements.define("drab-wakelock",r);})();
@@ -0,0 +1,2 @@
1
+ import { WakeLock } from "./index.js";
2
+ customElements.define("drab-wakelock", WakeLock);