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
@@ -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(i){this.setAttribute("event",i)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(i=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof i)return n;throw new Error("Content not found")}swapContent(i=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let t=Array.from(this.getContent().childNodes);e instanceof HTMLTemplateElement?this.getContent().replaceChildren(e.content.cloneNode(!0)):this.getContent().replaceChildren(...e.childNodes),i&&setTimeout(()=>this.getContent().replaceChildren(...t),n)}}safeListener(i,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(i,n,t)}triggerListener(i,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var f=class extends l{constructor(){super()}get animationOptions(){let i={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?i[t]=Number(e):t==="easing"&&(i[t]=e))}return i}async animateElement(i={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=i,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 o=t.at(0),s=t.at(-1);if(o&&s){let a=["composite","easing","offset"];for(let m of a)delete o[m],delete s[m]}e.direction?.includes("reverse")&&([o,s]=[s,o]),Object.assign(n.style,o),await n.animate(t,e).finished,Object.assign(n.style,s)}}get keyframes(){let i=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...o]=n.split("-");if(n.startsWith("animation-keyframe-")){let s=o.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(t&&s){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let r=Number(t),a=i.find(m=>m.offset===r);a?a[s]=e:i.push({[s]:e,offset:r})}}}return i.sort((n,e)=>Number(n.offset)-Number(e.offset)),i}};customElements.define("drab-animate",f);})();
1
+ "use strict";(()=>{var l=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(i){this.setAttribute("event",i)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(i=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof i)return n;throw new Error("Content not found")}swapContent(i=!0,n=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),i&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(i,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(i,n,t)}triggerListener(i,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var f=class extends l{constructor(){super()}get animationOptions(){let i={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?i[t]=Number(e):t==="easing"&&(i[t]=e))}return i}async animateElement(i={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=i,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 m of a)delete s[m],delete o[m]}e.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(n.style,s),await n.animate(t,e).finished,Object.assign(n.style,o)}}get keyframes(){let i=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...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(t&&o){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let r=Number(t),a=i.find(m=>m.offset===r);a?a[o]=e:i.push({[o]:e,offset:r})}}}return i.sort((n,e)=>Number(n.offset)-Number(e.offset)),i}};customElements.define("drab-animate",f);})();
package/animate/define.js CHANGED
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-F5BEEHGA.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-animate",e);
1
+ import { Animate } from "./index.js";
2
+ customElements.define("drab-animate", Animate);
@@ -1,8 +1,7 @@
1
- import { Base } from '../base/index.js';
2
-
1
+ import { Base } from "../base/index.js";
3
2
  type AnimationKeyframe = `animation-keyframe-${"from" | "to" | number}-${string}`;
4
3
  type AnimationOption = `animation-option-${"easing" | "duration" | "delay"}`;
5
- type AnimateAttributes = Partial<{
4
+ export type AnimateAttributes = Partial<{
6
5
  [K in AnimationKeyframe | AnimationOption]: string;
7
6
  }>;
8
7
  /**
@@ -31,7 +30,7 @@ type AnimateAttributes = Partial<{
31
30
  *
32
31
  * `property` can be `duration`, `delay`, or `easing`.
33
32
  */
34
- declare class Animate extends Base {
33
+ export declare class Animate extends Base {
35
34
  constructor();
36
35
  /**
37
36
  * @returns An object containing the values of each `animation-option` attribute
@@ -55,5 +54,4 @@ declare class Animate extends Base {
55
54
  }): Promise<void>;
56
55
  get keyframes(): Keyframe[];
57
56
  }
58
-
59
- export { Animate, type AnimateAttributes };
57
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var m=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(i){this.setAttribute("event",i)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(i=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof i)return n;throw new Error("Content not found")}swapContent(i=!0,n=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let t=Array.from(this.getContent().childNodes);e instanceof HTMLTemplateElement?this.getContent().replaceChildren(e.content.cloneNode(!0)):this.getContent().replaceChildren(...e.childNodes),i&&setTimeout(()=>this.getContent().replaceChildren(...t),n)}}safeListener(i,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(i,n,t)}triggerListener(i,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#e.abort()}};var f=class extends m{constructor(){super()}get animationOptions(){let i={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?i[t]=Number(e):t==="easing"&&(i[t]=e))}return i}async animateElement(i={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=i,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 o=t.at(0),s=t.at(-1);if(o&&s){let a=["composite","easing","offset"];for(let l of a)delete o[l],delete s[l]}e.direction?.includes("reverse")&&([o,s]=[s,o]),Object.assign(n.style,o),await n.animate(t,e).finished,Object.assign(n.style,s)}}get keyframes(){let i=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...o]=n.split("-");if(n.startsWith("animation-keyframe-")){let s=o.map((r,a)=>a<1?r:r.at(0)?.toUpperCase()+r.slice(1)).join("");if(t&&s){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let r=Number(t),a=i.find(l=>l.offset===r);a?a[s]=e:i.push({[s]:e,offset:r})}}}return i.sort((n,e)=>Number(n.offset)-Number(e.offset)),i}};})();
1
+ "use strict";(()=>{var m=class extends HTMLElement{#e=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(i){this.setAttribute("event",i)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(i=HTMLElement){let n=this.querySelector(this.getAttribute("content")??"[data-content]");if(n instanceof i)return n;throw new Error("Content not found")}swapContent(i=!0,n=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),i&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(i,n,e=document.body,t={}){t.signal=this.#e.signal,e.addEventListener(i,n,t)}triggerListener(i,n=this.event){for(let e of this.getTrigger())e.addEventListener(n,i)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#e.abort()}};var f=class extends m{constructor(){super()}get animationOptions(){let i={};for(let n of this.getAttributeNames())if(n.startsWith("animation-option-")){let e=this.getAttribute(n),[,,t]=n.split("-");e&&(t==="duration"||t==="delay"?i[t]=Number(e):t==="easing"&&(i[t]=e))}return i}async animateElement(i={element:this.getContent(),options:{}}){let{element:n=this.getContent(),options:e={}}=i,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(n.style,s),await n.animate(t,e).finished,Object.assign(n.style,o)}}get keyframes(){let i=[];for(let n of this.getAttributeNames()){let e=this.getAttribute(n),[,,t,...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(t&&o){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let r=Number(t),a=i.find(l=>l.offset===r);a?a[o]=e:i.push({[o]:e,offset:r})}}}return i.sort((n,e)=>Number(n.offset)-Number(e.offset)),i}};})();
package/animate/index.js CHANGED
@@ -1 +1,138 @@
1
- import{a}from"../chunk-F5BEEHGA.js";import"../chunk-MXKU7AKV.js";export{a as Animate};
1
+ import { Base } from "../base/index.js";
2
+ /**
3
+ * The `Animate` base class provides a declarative way to use the
4
+ * [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API)
5
+ * through HTML attributes. The `animateElement` method uses these attributes and
6
+ * persists the final animation state. Other elements in **drab** extend this class
7
+ * to provide animations. You can also extend this class to create your own custom
8
+ * animated element.
9
+ *
10
+ * Keyframes can be set via HTML attributes on the element in the form of:
11
+ *
12
+ * ```html
13
+ * <drab-animate animation-keyframe-offset-property="value">
14
+ * ```
15
+ *
16
+ * `offset` can be `to`, `from`, or a `number`.
17
+ *
18
+ * `property` can be any animatable CSS property separated by dashes.
19
+ *
20
+ * Animations `options` can be set:
21
+ *
22
+ * ```html
23
+ * <drab-animate animation-option-property="value">
24
+ * ```
25
+ *
26
+ * `property` can be `duration`, `delay`, or `easing`.
27
+ */
28
+ export class Animate extends Base {
29
+ constructor() {
30
+ super();
31
+ }
32
+ /**
33
+ * @returns An object containing the values of each `animation-option` attribute
34
+ */
35
+ get animationOptions() {
36
+ const options = {};
37
+ for (const attributeName of this.getAttributeNames()) {
38
+ if (attributeName.startsWith("animation-option-")) {
39
+ const value = this.getAttribute(attributeName);
40
+ let [, , option] = attributeName.split("-");
41
+ if (value) {
42
+ if (option === "duration" || option === "delay") {
43
+ options[option] = Number(value);
44
+ }
45
+ else if (option === "easing") {
46
+ options[option] = value;
47
+ }
48
+ }
49
+ }
50
+ }
51
+ return options;
52
+ }
53
+ /**
54
+ * @description
55
+ * Animates a particular element using the web animations API.
56
+ *
57
+ * - Disables animation if the user prefers reduced motion.
58
+ * - Sets default options
59
+ * - Uses the keyframes provided from `this.keyframes`
60
+ * - Waits for the animation to complete
61
+ * - Sets the start and end styles based on the first and last keyframe
62
+ *
63
+ * @param animateOptions - animates `this.content()` by default
64
+ */
65
+ async animateElement(animateOptions = { element: this.getContent(), options: {} }) {
66
+ let { element = this.getContent(), options = {} } = animateOptions;
67
+ const keyframes = this.keyframes;
68
+ if (keyframes.length &&
69
+ !window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
70
+ // options passed in via JS override the html attributes
71
+ options = Object.assign(this.animationOptions, options);
72
+ // defaults
73
+ if (!options.duration)
74
+ options.duration = 200;
75
+ if (!options.easing)
76
+ options.easing = "ease-in-out";
77
+ let startStyles = keyframes.at(0);
78
+ let endStyles = keyframes.at(-1);
79
+ if (startStyles && endStyles) {
80
+ // Don't modify the start/end style based on these,
81
+ // everything else is a CSS property.
82
+ // This is instead of doing `fill` since it is discouraged:
83
+ // https://www.w3.org/TR/web-animations-1/#fill-behavior
84
+ const notStyles = ["composite", "easing", "offset"];
85
+ for (const key of notStyles) {
86
+ delete startStyles[key];
87
+ delete endStyles[key];
88
+ }
89
+ }
90
+ if (options.direction?.includes("reverse")) {
91
+ // swap the start and ending values
92
+ [startStyles, endStyles] = [endStyles, startStyles];
93
+ }
94
+ Object.assign(element.style, startStyles);
95
+ const animation = element.animate(keyframes, options);
96
+ await animation.finished;
97
+ Object.assign(element.style, endStyles);
98
+ }
99
+ }
100
+ get keyframes() {
101
+ const keyframes = [];
102
+ for (const attributeName of this.getAttributeNames()) {
103
+ /** the css property value, ex: "translate(100%,0)" */
104
+ const value = this.getAttribute(attributeName);
105
+ let [, , offset, ...propertyArray] = attributeName.split("-");
106
+ if (attributeName.startsWith("animation-keyframe-")) {
107
+ const property = propertyArray
108
+ .map((v, i) => {
109
+ if (i < 1)
110
+ return v;
111
+ return v.at(0)?.toUpperCase() + v.slice(1);
112
+ })
113
+ .join("");
114
+ if (offset && property) {
115
+ if (offset === "from")
116
+ offset = "0";
117
+ else if (offset === "to")
118
+ offset = "1";
119
+ else
120
+ offset = String(parseInt(offset) * 0.01);
121
+ const numberOffset = Number(offset);
122
+ const sameOffsetKeyframe = keyframes.find((v) => v.offset === numberOffset);
123
+ if (sameOffsetKeyframe) {
124
+ sameOffsetKeyframe[property] = value;
125
+ }
126
+ else {
127
+ keyframes.push({
128
+ [property]: value,
129
+ offset: numberOffset,
130
+ });
131
+ }
132
+ }
133
+ }
134
+ }
135
+ keyframes.sort((a, b) => Number(a.offset) - Number(b.offset));
136
+ return keyframes;
137
+ }
138
+ }
@@ -1,6 +1,5 @@
1
- import { Base } from './base/index.js';
2
-
3
- declare class BaseCopy extends Base {
1
+ import { Base } from "../index.js";
2
+ export declare class BaseCopy extends Base {
4
3
  constructor();
5
4
  /**
6
5
  * The value to copy or share.
@@ -15,5 +14,3 @@ declare class BaseCopy extends Base {
15
14
  */
16
15
  copy(text?: string): Promise<void>;
17
16
  }
18
-
19
- export { BaseCopy as B };
@@ -0,0 +1,25 @@
1
+ import { Base } from "../index.js";
2
+ export class BaseCopy extends Base {
3
+ constructor() {
4
+ super();
5
+ }
6
+ /**
7
+ * The value to copy or share.
8
+ *
9
+ * @default "" the empty string
10
+ */
11
+ get value() {
12
+ return this.getAttribute("value") ?? "";
13
+ }
14
+ set value(value) {
15
+ this.setAttribute("value", value);
16
+ }
17
+ /**
18
+ * Copies the `text`.
19
+ * @param text The `text` to share
20
+ */
21
+ async copy(text = this.value) {
22
+ await navigator.clipboard.writeText(text);
23
+ this.swapContent();
24
+ }
25
+ }
package/base/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()}};customElements.define("drab-base",s);})();
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 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 r=Array.from(this.getContent().childNodes),o=[];t instanceof HTMLTemplateElement?(o.push(t.content.cloneNode(!0)),t.content.replaceChildren(...r)):(o.push(...t.childNodes),t.replaceChildren(...r)),this.getContent().replaceChildren(...o),e&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(e,n,t=document.body,r={}){r.signal=this.#e.signal,t.addEventListener(e,n,r)}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()}};customElements.define("drab-base",s);})();
package/base/define.js CHANGED
@@ -1 +1,2 @@
1
- import{b as e}from"../chunk-MXKU7AKV.js";customElements.define("drab-base",e);
1
+ import { Base } from "./index.js";
2
+ customElements.define("drab-base", Base);
package/base/index.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * Each element can have multiple `trigger`s, but will only have one `content`.
12
12
  */
13
- declare class Base extends HTMLElement {
13
+ export declare class Base extends HTMLElement {
14
14
  #private;
15
15
  constructor();
16
16
  /**
@@ -51,19 +51,21 @@ declare class Base extends HTMLElement {
51
51
  * @param listener
52
52
  * @param options
53
53
  */
54
- safeListener<K extends keyof HTMLElementEventMap, T extends HTMLElement | Window | Document = HTMLElement>(type: K, listener: (this: T, ev: HTMLElementEventMap[K]) => any, element?: T, options?: AddEventListenerOptions): void;
54
+ safeListener<K extends keyof DocumentEventMap, T extends HTMLElement | Window | Document = HTMLElement>(type: K, listener: (this: T, ev: DocumentEventMap[K]) => any, element?: T, options?: AddEventListenerOptions): void;
55
55
  /**
56
56
  * @param listener Listener to attach to all of the `trigger` elements.
57
57
  */
58
- triggerListener<T extends HTMLElement, K extends keyof HTMLElementEventMap>(listener: (this: T, ev: HTMLElementEventMap[K]) => any, type?: K): void;
58
+ triggerListener<T extends HTMLElement, K extends keyof HTMLElementEventMap>(listener: (this: T, e: HTMLElementEventMap[K]) => any, type?: K): void;
59
59
  /**
60
- * Placeholder function is passed into `queueMicrotask` in `connectedCallback`. It is overridden in each component that needs to run `connectedCallback`.
60
+ * Passed into `queueMicrotask` in `connectedCallback`. It is overridden in each component that needs to run `connectedCallback`.
61
61
  *
62
62
  * The reason for this is to make these elements work better with frameworks like Svelte. For SSR this isn't necessary, but when client side rendering, the HTML within the custom element isn't available before `connectedCallback` is called. By waiting until the next microtask, the HTML content is available---then for example, listeners can be attached to elements inside.
63
63
  */
64
64
  mount(): void;
65
65
  connectedCallback(): void;
66
+ /**
67
+ * Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
68
+ */
69
+ destroy(): void;
66
70
  disconnectedCallback(): void;
67
71
  }
68
-
69
- export { Base };
@@ -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()}};})();
1
+ "use strict";(()=>{var o=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 r=Array.from(this.getContent().childNodes),s=[];t instanceof HTMLTemplateElement?(s.push(t.content.cloneNode(!0)),t.content.replaceChildren(...r)):(s.push(...t.childNodes),t.replaceChildren(...r)),this.getContent().replaceChildren(...s),e&&setTimeout(()=>this.swapContent(!1),n)}}safeListener(e,n,t=document.body,r={}){r.signal=this.#e.signal,t.addEventListener(e,n,r)}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()}};})();
package/base/index.js CHANGED
@@ -1 +1,131 @@
1
- import{b as a}from"../chunk-MXKU7AKV.js";export{a as Base};
1
+ /**
2
+ * Each element in the library extends the `Base` class. It provides methods
3
+ * for selecting elements via HTML attributes along with other helpers.
4
+ *
5
+ * By default, `trigger`s and `content` will be selected via the `data-trigger` and
6
+ * `data-content` attributes. Alternatively, you can set the `trigger` or
7
+ * `content` attribute to a CSS selector to change the default selector from
8
+ * `[data-trigger]` or `[data-content]` to a selector of your choosing.
9
+ * This can be useful if you have multiple elements within one another.
10
+ *
11
+ * Each element can have multiple `trigger`s, but will only have one `content`.
12
+ */
13
+ export class Base extends HTMLElement {
14
+ /**
15
+ * To clean up event listeners added to `document` when the element is removed.
16
+ */
17
+ #listenerController = new AbortController();
18
+ constructor() {
19
+ super();
20
+ }
21
+ /**
22
+ * Event for the `trigger` to execute.
23
+ *
24
+ * For example, set to `"mouseover"` to execute the event when the user hovers the mouse over the `trigger`, instead of when they click it.
25
+ *
26
+ * @default "click"
27
+ */
28
+ get event() {
29
+ return (this.getAttribute("event") ?? "click");
30
+ }
31
+ set event(value) {
32
+ this.setAttribute("event", value);
33
+ }
34
+ /**
35
+ * @returns All of the elements that match the `trigger` selector.
36
+ * @default this.querySelectorAll("[data-trigger]")
37
+ */
38
+ getTrigger() {
39
+ const triggers = this.querySelectorAll(this.getAttribute("trigger") ?? "[data-trigger]");
40
+ return triggers;
41
+ }
42
+ /**
43
+ * @param instance The instance of the desired element, ex: `HTMLDialogElement`.
44
+ * Defaults to `HTMLElement`.
45
+ * @returns The element that matches the `content` selector.
46
+ * @default this.querySelector("[data-content]")
47
+ */
48
+ getContent(instance = HTMLElement) {
49
+ const content = this.querySelector(this.getAttribute("content") ?? "[data-content]");
50
+ if (content instanceof instance)
51
+ return content;
52
+ throw new Error("Content not found");
53
+ }
54
+ /**
55
+ * Finds the `HTMLElement | HTMLTemplateElement` via the `swap` selector and
56
+ * swaps `this.content()` with the content of the element found.
57
+ *
58
+ * @param revert Swap back to old content
59
+ * @param delay Wait time before swapping back
60
+ */
61
+ swapContent(revert = true, delay = 800) {
62
+ // BREAKING TODO: `revert` and `delay` -- these could be one parameter
63
+ // revert: number = 800
64
+ /** The swap element, used to hold the replacement contents. */
65
+ const swap = this.querySelector(this.getAttribute("swap") ?? "[data-swap]");
66
+ if (swap) {
67
+ /** A copy of the content currently in `this.getContent()`. */
68
+ const currentContent = Array.from(this.getContent().childNodes);
69
+ /**
70
+ * The contents of the swap element, set based on whether the
71
+ * swap is a `template` or not.
72
+ */
73
+ const placeholder = [];
74
+ // Set the placeholder with the `swap` content, then replace the
75
+ // swap content with the `currentContent`
76
+ if (swap instanceof HTMLTemplateElement) {
77
+ // use `content` since it's a `template` element
78
+ placeholder.push(swap.content.cloneNode(true));
79
+ swap.content.replaceChildren(...currentContent);
80
+ }
81
+ else {
82
+ // not a `template`, replace children directly
83
+ placeholder.push(...swap.childNodes);
84
+ swap.replaceChildren(...currentContent);
85
+ }
86
+ // finally, set the content to the contents of the placeholder
87
+ this.getContent().replaceChildren(...placeholder);
88
+ if (revert) {
89
+ // wait and then run again to swap back
90
+ setTimeout(() => this.swapContent(false), delay);
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * Wrapper around `document.body.addEventListener` that ensures when the
96
+ * element is removed from the DOM, these event listeners are cleaned up.
97
+ * @param type
98
+ * @param listener
99
+ * @param options
100
+ */
101
+ safeListener(type, listener, element = document.body, options = {}) {
102
+ options.signal = this.#listenerController.signal;
103
+ //@ts-ignore - inferred listener type not working...?
104
+ element.addEventListener(type, listener, options);
105
+ }
106
+ /**
107
+ * @param listener Listener to attach to all of the `trigger` elements.
108
+ */
109
+ triggerListener(listener, type = this.event) {
110
+ for (const trigger of this.getTrigger()) {
111
+ trigger.addEventListener(type, listener);
112
+ }
113
+ }
114
+ /**
115
+ * Passed into `queueMicrotask` in `connectedCallback`. It is overridden in each component that needs to run `connectedCallback`.
116
+ *
117
+ * The reason for this is to make these elements work better with frameworks like Svelte. For SSR this isn't necessary, but when client side rendering, the HTML within the custom element isn't available before `connectedCallback` is called. By waiting until the next microtask, the HTML content is available---then for example, listeners can be attached to elements inside.
118
+ */
119
+ mount() { }
120
+ connectedCallback() {
121
+ queueMicrotask(() => this.mount());
122
+ }
123
+ /**
124
+ * Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
125
+ */
126
+ destroy() { }
127
+ disconnectedCallback() {
128
+ this.destroy();
129
+ this.#listenerController.abort();
130
+ }
131
+ }
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var r=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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...i),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var s=class extends r{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[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.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)}};customElements.define("drab-breakpoint",s);})();
1
+ "use strict";(()=>{var i=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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes),o=[];n instanceof HTMLTemplateElement?(o.push(n.content.cloneNode(!0)),n.content.replaceChildren(...r)):(o.push(...n.childNodes),n.replaceChildren(...r)),this.getContent().replaceChildren(...o),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,n=document.body,r={}){r.signal=this.#t.signal,n.addEventListener(t,e,r)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var s=class extends i{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[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.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)}};customElements.define("drab-breakpoint",s);})();
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-BCS5E3IH.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-breakpoint",e);
1
+ import { Breakpoint } from "./index.js";
2
+ customElements.define("drab-breakpoint", Breakpoint);
@@ -1,7 +1,6 @@
1
- import { Base } from '../base/index.js';
2
- import { A as Attributes } from '../index-J5TqSvEl.js';
3
-
4
- type BreakpointAttributes = Attributes<Breakpoint> & Partial<{
1
+ import { Base } from "../base/index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type BreakpointAttributes = Attributes<Breakpoint> & Partial<{
5
4
  [attr: `breakpoint-${string}`]: string;
6
5
  }>;
7
6
  type Breakpoints = {
@@ -17,12 +16,11 @@ type Breakpoints = {
17
16
  * <drab-breakpoint breakpoint-name="400">
18
17
  * ```
19
18
  */
20
- declare class Breakpoint extends Base {
19
+ export declare class Breakpoint extends Base {
21
20
  breakpoints: Breakpoints;
22
21
  constructor();
23
22
  /** finds the current breakpoint */
24
23
  get breakpoint(): string;
25
24
  mount(): void;
26
25
  }
27
-
28
- export { Breakpoint, type BreakpointAttributes };
26
+ export {};
@@ -1 +1 @@
1
- "use strict";(()=>{var r=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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...i),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var s=class extends r{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[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.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)}};})();
1
+ "use strict";(()=>{var i=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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes),s=[];n instanceof HTMLTemplateElement?(s.push(n.content.cloneNode(!0)),n.content.replaceChildren(...r)):(s.push(...n.childNodes),n.replaceChildren(...r)),this.getContent().replaceChildren(...s),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,n=document.body,r={}){r.signal=this.#t.signal,n.addEventListener(t,e,r)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var o=class extends i{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[,...n]=e.split("-");n&&t.push({name:n.join("-"),width:Number(this.getAttribute(e))})}t.length&&(this.breakpoints=t),this.breakpoints.sort((e,n)=>n.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)}};})();
@@ -1 +1,55 @@
1
- import{a}from"../chunk-BCS5E3IH.js";import"../chunk-MXKU7AKV.js";export{a as Breakpoint};
1
+ import { Base } from "../base/index.js";
2
+ /**
3
+ * Displays the current breakpoint and `window.innerWidth`, based on the `breakpoints` provided. Defaults to [TailwindCSS breakpoint sizes](https://tailwindcss.com/docs/responsive-design).
4
+ *
5
+ * Provide alternate breakpoints by specifying `breakpoint` attributes:
6
+ *
7
+ * ```html
8
+ * <drab-breakpoint breakpoint-name="400">
9
+ * ```
10
+ */
11
+ export class Breakpoint extends Base {
12
+ breakpoints = [
13
+ { name: "sm", width: 640 },
14
+ { name: "md", width: 768 },
15
+ { name: "lg", width: 1024 },
16
+ { name: "xl", width: 1280 },
17
+ { name: "2xl", width: 1536 },
18
+ ];
19
+ constructor() {
20
+ super();
21
+ const custom = [];
22
+ for (const attributeName of this.getAttributeNames()) {
23
+ if (attributeName.startsWith("breakpoint-")) {
24
+ const [, ...name] = attributeName.split("-");
25
+ if (name) {
26
+ custom.push({
27
+ name: name.join("-"),
28
+ width: Number(this.getAttribute(attributeName)),
29
+ });
30
+ }
31
+ }
32
+ }
33
+ if (custom.length)
34
+ this.breakpoints = custom;
35
+ // highest to lowest
36
+ this.breakpoints.sort((a, b) => b.width - a.width);
37
+ }
38
+ /** finds the current breakpoint */
39
+ get breakpoint() {
40
+ for (let i = 0; i < this.breakpoints.length; i++) {
41
+ const breakpoint = this.breakpoints[i];
42
+ if (breakpoint) {
43
+ if (window.innerWidth > breakpoint.width) {
44
+ return breakpoint.name;
45
+ }
46
+ }
47
+ }
48
+ return "none";
49
+ }
50
+ mount() {
51
+ const render = () => (this.getContent().innerHTML = `${this.breakpoint}:${window.innerWidth}`);
52
+ render();
53
+ this.safeListener("resize", render, window);
54
+ }
55
+ }
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
@@ -1 +1 @@
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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...i),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var m=class extends c{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let n=this.getAttribute(e),[,,i]=e.split("-");n&&(i==="duration"||i==="delay"?t[i]=Number(n):i==="easing"&&(t[i]=n))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:n={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){n=Object.assign(this.animationOptions,n),n.duration||(n.duration=200),n.easing||(n.easing="ease-in-out");let r=i.at(0),s=i.at(-1);if(r&&s){let a=["composite","easing","offset"];for(let l of a)delete r[l],delete s[l]}n.direction?.includes("reverse")&&([r,s]=[s,r]),Object.assign(e.style,r),await e.animate(i,n).finished,Object.assign(e.style,s)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let n=this.getAttribute(e),[,,i,...r]=e.split("-");if(e.startsWith("animation-keyframe-")){let s=r.map((o,a)=>a<1?o:o.at(0)?.toUpperCase()+o.slice(1)).join("");if(i&&s){i==="from"?i="0":i==="to"?i="1":i=String(parseInt(i)*.01);let o=Number(i),a=t.find(l=>l.offset===o);a?a[s]=n:t.push({[s]:n,offset:o})}}}return t.sort((e,n)=>Number(e.offset)-Number(n.offset)),t}};var f=class extends m{#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,n=window.scrollX,i=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,r=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,s=i+n,o=r+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let a=this.getContent().offsetWidth+24,l=this.getContent().offsetHeight+6,u=window.innerWidth,d=window.innerHeight;s+a>n+u&&(s=n+u-a),o+l>e+d&&(o=e+d-l),this.#e={x:s,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()})}};customElements.define("drab-contextmenu",f);})();
1
+ "use strict";(()=>{var l=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 n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let i=Array.from(this.getContent().childNodes),s=[];n instanceof HTMLTemplateElement?(s.push(n.content.cloneNode(!0)),n.content.replaceChildren(...i)):(s.push(...n.childNodes),n.replaceChildren(...i)),this.getContent().replaceChildren(...s),t&&setTimeout(()=>this.swapContent(!1),e)}}safeListener(t,e,n=document.body,i={}){i.signal=this.#t.signal,n.addEventListener(t,e,i)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var m=class extends l{constructor(){super()}get animationOptions(){let t={};for(let e of this.getAttributeNames())if(e.startsWith("animation-option-")){let n=this.getAttribute(e),[,,i]=e.split("-");n&&(i==="duration"||i==="delay"?t[i]=Number(n):i==="easing"&&(t[i]=n))}return t}async animateElement(t={element:this.getContent(),options:{}}){let{element:e=this.getContent(),options:n={}}=t,i=this.keyframes;if(i.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){n=Object.assign(this.animationOptions,n),n.duration||(n.duration=200),n.easing||(n.easing="ease-in-out");let s=i.at(0),o=i.at(-1);if(s&&o){let a=["composite","easing","offset"];for(let c of a)delete s[c],delete o[c]}n.direction?.includes("reverse")&&([s,o]=[o,s]),Object.assign(e.style,s),await e.animate(i,n).finished,Object.assign(e.style,o)}}get keyframes(){let t=[];for(let e of this.getAttributeNames()){let n=this.getAttribute(e),[,,i,...s]=e.split("-");if(e.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(c=>c.offset===r);a?a[o]=n:t.push({[o]:n,offset:r})}}}return t.sort((e,n)=>Number(e.offset)-Number(n.offset)),t}};var f=class extends m{#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,n=window.scrollX,i=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,s=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,o=i+n,r=s+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let a=this.getContent().offsetWidth+24,c=this.getContent().offsetHeight+6,h=window.innerWidth,d=window.innerHeight;o+a>n+h&&(o=n+h-a),r+c>e+d&&(r=e+d-c),this.#e={x:o,y:r},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()})}};customElements.define("drab-contextmenu",f);})();
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-AWUCZCAJ.js";import"../chunk-F5BEEHGA.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-contextmenu",e);
1
+ import { ContextMenu } from "./index.js";
2
+ customElements.define("drab-contextmenu", ContextMenu);
@@ -1,17 +1,13 @@
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 ContextMenuAttributes = Attributes<ContextMenu> & AnimateAttributes;
1
+ import { Animate, type AnimateAttributes } from "../animate/index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type ContextMenuAttributes = Attributes<ContextMenu> & AnimateAttributes;
6
4
  /**
7
5
  * Displays content when the `trigger` element is right clicked, or long pressed on mobile.
8
6
  */
9
- declare class ContextMenu extends Animate {
7
+ export declare class ContextMenu extends Animate {
10
8
  #private;
11
9
  constructor();
12
10
  show(e: MouseEvent | TouchEvent): Promise<void>;
13
11
  hide(): Promise<void>;
14
12
  mount(): void;
15
13
  }
16
-
17
- export { ContextMenu, type ContextMenuAttributes };