drab 5.0.1 → 5.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/animate/define.d.ts +1 -2
  2. package/animate/define.js +2 -1
  3. package/animate/index.d.ts +4 -6
  4. package/animate/index.js +138 -1
  5. package/{index-0rvQCq2U.d.ts → base/copy/index.d.ts} +2 -5
  6. package/base/copy/index.js +25 -0
  7. package/base/define.d.ts +1 -2
  8. package/base/define.js +2 -1
  9. package/base/index.d.ts +1 -3
  10. package/base/index.js +108 -1
  11. package/breakpoint/define.d.ts +1 -2
  12. package/breakpoint/define.js +2 -1
  13. package/breakpoint/index.d.ts +5 -7
  14. package/breakpoint/index.js +55 -1
  15. package/contextmenu/define.d.ts +1 -2
  16. package/contextmenu/define.js +2 -1
  17. package/contextmenu/index.d.ts +4 -8
  18. package/contextmenu/index.js +71 -1
  19. package/copy/define.d.ts +1 -2
  20. package/copy/define.iife.js +1 -1
  21. package/copy/define.js +2 -1
  22. package/copy/index.d.ts +4 -8
  23. package/copy/index.js +13 -1
  24. package/define/index.iife.js +1 -1
  25. package/define.d.ts +1 -0
  26. package/define.js +4 -0
  27. package/details/define.d.ts +1 -2
  28. package/details/define.iife.js +1 -1
  29. package/details/define.js +2 -1
  30. package/details/index.d.ts +4 -8
  31. package/details/index.js +46 -1
  32. package/dialog/define.d.ts +1 -2
  33. package/dialog/define.js +2 -1
  34. package/dialog/index.d.ts +4 -8
  35. package/dialog/index.js +44 -1
  36. package/editor/define.d.ts +1 -2
  37. package/editor/define.js +2 -1
  38. package/editor/index.d.ts +5 -8
  39. package/editor/index.js +480 -1
  40. package/fullscreen/define.d.ts +1 -2
  41. package/fullscreen/define.iife.js +1 -1
  42. package/fullscreen/define.js +2 -1
  43. package/fullscreen/index.d.ts +4 -7
  44. package/fullscreen/index.iife.js +1 -1
  45. package/fullscreen/index.js +45 -1
  46. package/index.d.ts +14 -15
  47. package/index.iife.js +1 -1
  48. package/index.js +14 -1
  49. package/package.json +5 -4
  50. package/popover/define.d.ts +1 -2
  51. package/popover/define.js +2 -1
  52. package/popover/index.d.ts +4 -8
  53. package/popover/index.js +74 -1
  54. package/share/define.d.ts +1 -2
  55. package/share/define.js +2 -1
  56. package/share/index.d.ts +4 -8
  57. package/share/index.js +34 -1
  58. package/tablesort/define.d.ts +1 -2
  59. package/tablesort/define.js +2 -1
  60. package/tablesort/index.d.ts +4 -7
  61. package/tablesort/index.js +109 -1
  62. package/types/index.d.ts +11 -0
  63. package/types/index.js +1 -0
  64. package/youtube/define.d.ts +1 -2
  65. package/youtube/define.js +2 -1
  66. package/youtube/index.d.ts +4 -7
  67. package/youtube/index.js +56 -1
  68. package/chunk-3ASUSP4D.js +0 -1
  69. package/chunk-4WBITBA6.js +0 -1
  70. package/chunk-5JV4T7GM.js +0 -1
  71. package/chunk-7F7CQUEG.js +0 -1
  72. package/chunk-AWUCZCAJ.js +0 -1
  73. package/chunk-BCS5E3IH.js +0 -1
  74. package/chunk-DKKPV7QP.js +0 -1
  75. package/chunk-F5BEEHGA.js +0 -1
  76. package/chunk-GPET75FT.js +0 -9
  77. package/chunk-H4RNP4O4.js +0 -1
  78. package/chunk-LHXOPRVC.js +0 -1
  79. package/chunk-MXKU7AKV.js +0 -1
  80. package/chunk-VEVFQB5N.js +0 -1
  81. package/chunk-XAP2U34A.js +0 -1
  82. package/define/index.d.ts +0 -2
  83. package/define/index.js +0 -1
  84. package/index-J5TqSvEl.d.ts +0 -12
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.0.2",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -149,9 +149,10 @@
149
149
  "preview": "vite preview",
150
150
  "format": "prettier --write .",
151
151
  "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",
152
+ "package:json": "bun src/lib/scripts/packageJson/index.ts && prettier --write package.json",
153
+ "package:copy": "cp package.json ./package && cp README.md ./package && cp LICENSE.md ./package",
154
+ "package:tsc": "tsc --project tsconfig.package.json",
155
+ "package": "bun package:json && tsup && bun package:tsc && bun package:copy",
155
156
  "pub": "bun i && bun doc && bun package && npm publish --access public ./package"
156
157
  },
157
158
  "devDependencies": {
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
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 };
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 {};
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 };
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,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,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 {};
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};
package/youtube/define.js CHANGED
@@ -1 +1,2 @@
1
- import{a as e}from"../chunk-VEVFQB5N.js";import"../chunk-MXKU7AKV.js";customElements.define("drab-youtube",e);
1
+ import { YouTube } from "./index.js";
2
+ customElements.define("drab-youtube", YouTube);
@@ -1,11 +1,10 @@
1
- import { Base } from '../base/index.js';
2
- import { A as Attributes } from '../index-J5TqSvEl.js';
3
-
4
- type YouTubeAttributes = Attributes<YouTube, "uid">;
1
+ import { Base } from "../base/index.js";
2
+ import type { Attributes } from "../types/index.js";
3
+ export type YouTubeAttributes = Attributes<YouTube, "uid">;
5
4
  /**
6
5
  * Embeds a YouTube video iframe into a website with the video uid, using www.youtube-nocookie.com.
7
6
  */
8
- declare class YouTube extends Base {
7
+ export declare class YouTube extends Base {
9
8
  static observedAttributes: readonly ["autoplay", "start", "uid"];
10
9
  constructor();
11
10
  /** The `HTMLIFrameElement` within the element. */
@@ -27,5 +26,3 @@ declare class YouTube extends Base {
27
26
  mount(): void;
28
27
  attributeChangedCallback(): void;
29
28
  }
30
-
31
- export { YouTube, type YouTubeAttributes };
package/youtube/index.js CHANGED
@@ -1 +1,56 @@
1
- import{a}from"../chunk-VEVFQB5N.js";import"../chunk-MXKU7AKV.js";export{a as YouTube};
1
+ import { Base } from "../base/index.js";
2
+ /**
3
+ * Embeds a YouTube video iframe into a website with the video uid, using www.youtube-nocookie.com.
4
+ */
5
+ export class YouTube extends Base {
6
+ static observedAttributes = ["autoplay", "start", "uid"];
7
+ constructor() {
8
+ super();
9
+ }
10
+ /** The `HTMLIFrameElement` within the element. */
11
+ get iframe() {
12
+ return this.getContent(HTMLIFrameElement);
13
+ }
14
+ /** Whether the video should start playing when loaded. */
15
+ get autoplay() {
16
+ return this.hasAttribute("autoplay");
17
+ }
18
+ set autoplay(value) {
19
+ if (value)
20
+ this.setAttribute("autoplay", "");
21
+ else
22
+ this.removeAttribute("autoplay");
23
+ }
24
+ /** The start time of the video (seconds). */
25
+ get start() {
26
+ return this.getAttribute("start") ?? "0";
27
+ }
28
+ set start(value) {
29
+ this.setAttribute("start", value);
30
+ }
31
+ /**
32
+ * The video's YouTube uid, found within the url of the video.
33
+ *
34
+ * For example if the video url is https://youtu.be/gouiY85kD2o,
35
+ * the `uid` is `"gouiY85kD2o"`.
36
+ */
37
+ get uid() {
38
+ const uid = this.getAttribute("uid");
39
+ if (!uid)
40
+ throw new Error("YouTube: missing `uid` attribute.");
41
+ return uid;
42
+ }
43
+ set uid(v) {
44
+ this.setAttribute("uid", v);
45
+ }
46
+ mount() {
47
+ this.iframe.allowFullscreen = true;
48
+ this.iframe.allow =
49
+ "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";
50
+ }
51
+ attributeChangedCallback() {
52
+ queueMicrotask(() => {
53
+ this.iframe.src = `https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay ? "&autoplay=1" : ""}`;
54
+ });
55
+ }
56
+ }
package/chunk-3ASUSP4D.js DELETED
@@ -1 +0,0 @@
1
- import{a as C}from"./chunk-VEVFQB5N.js";import{a as E}from"./chunk-GPET75FT.js";import{a as h}from"./chunk-5JV4T7GM.js";import{a as x}from"./chunk-DKKPV7QP.js";import{a as v}from"./chunk-4WBITBA6.js";import{a as f}from"./chunk-AWUCZCAJ.js";import{a as y}from"./chunk-XAP2U34A.js";import{a as d}from"./chunk-LHXOPRVC.js";import{a as T}from"./chunk-H4RNP4O4.js";import{a as A}from"./chunk-F5BEEHGA.js";import{a as c}from"./chunk-BCS5E3IH.js";import{a as S,b as u}from"./chunk-MXKU7AKV.js";var g={};S(g,{Animate:()=>A,Base:()=>u,Breakpoint:()=>c,ContextMenu:()=>f,Copy:()=>y,Details:()=>d,Dialog:()=>T,Editor:()=>E,Fullscreen:()=>h,Popover:()=>x,Share:()=>v,TableSort:()=>m,YouTube:()=>C});var m=class extends u{constructor(){super()}#t(t){let e="data-asc",r="data-desc";for(let s of this.getTrigger())s!==t&&(s.removeAttribute(e),s.removeAttribute(r));return t.hasAttribute(e)?(t.removeAttribute(e),t.setAttribute(r,""),!1):(t.removeAttribute(r),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(L(e,this.#t(e))).forEach(r=>t.appendChild(r))})}},L=(o,t)=>(r,s)=>{let l=Array.from(o.parentNode?.children??[]).indexOf(o);return((i,a)=>{let p=o.dataset.type??"string";if(p==="string")return new Intl.Collator().compare(i,a);if(p==="boolean"){let n=b=>["0","false","null","undefined"].includes(b)?!1:!!b;return n(i)===n(a)?0:n(i)?-1:1}else return Number(i)-Number(a)})(M(t?r:s,l),M(t?s:r,l))},M=(o,t)=>{let e=o.children[t];return e instanceof HTMLElement?e.dataset.value??e.textContent??"":""};export{m as a,g as b};
package/chunk-4WBITBA6.js DELETED
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-7F7CQUEG.js";var a=class extends e{constructor(){super()}async share(t=this.value){if(navigator.canShare&&navigator.canShare({url:t}))try{await navigator.share({url:t})}catch(r){r?.name!=="AbortError"&&console.error(r)}else this.copy()}mount(){this.triggerListener(async()=>await this.share())}};export{a};
package/chunk-5JV4T7GM.js DELETED
@@ -1 +0,0 @@
1
- import{b as t}from"./chunk-MXKU7AKV.js";var r=class extends t{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 e of this.getTrigger())!this.fullscreenSupported()&&"disabled"in e&&(e.disabled=!0)}};export{r as a};
package/chunk-7F7CQUEG.js DELETED
@@ -1 +0,0 @@
1
- import{b as e}from"./chunk-MXKU7AKV.js";var r=class extends e{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()}};export{r as a};
package/chunk-AWUCZCAJ.js DELETED
@@ -1 +0,0 @@
1
- import{a as l}from"./chunk-F5BEEHGA.js";var a=class extends l{#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,i=window.scrollX,u=t instanceof MouseEvent?t.clientX:t.touches[0]?.clientX??0,d=t instanceof MouseEvent?t.clientY:t.touches[0]?.clientY??0,s=u+i,n=d+e;this.getContent().style.position="absolute",this.getContent().style.display="block";let o=this.getContent().offsetWidth+24,r=this.getContent().offsetHeight+6,h=window.innerWidth,c=window.innerHeight;s+o>i+h&&(s=i+h-o),n+r>e+c&&(n=e+c-r),this.#e={x:s,y:n},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()})}};export{a};
package/chunk-BCS5E3IH.js DELETED
@@ -1 +0,0 @@
1
- import{b as n}from"./chunk-MXKU7AKV.js";var r=class extends n{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)}};export{r as a};
package/chunk-DKKPV7QP.js DELETED
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-F5BEEHGA.js";var i=class extends e{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())})}};export{i as a};
package/chunk-F5BEEHGA.js DELETED
@@ -1 +0,0 @@
1
- import{b as m}from"./chunk-MXKU7AKV.js";var p=class extends m{constructor(){super()}get animationOptions(){let n={};for(let i of this.getAttributeNames())if(i.startsWith("animation-option-")){let e=this.getAttribute(i),[,,t]=i.split("-");e&&(t==="duration"||t==="delay"?n[t]=Number(e):t==="easing"&&(n[t]=e))}return n}async animateElement(n={element:this.getContent(),options:{}}){let{element:i=this.getContent(),options:e={}}=n,t=this.keyframes;if(t.length&&!window.matchMedia("(prefers-reduced-motion: reduce)").matches){e=Object.assign(this.animationOptions,e),e.duration||(e.duration=200),e.easing||(e.easing="ease-in-out");let o=t.at(0),s=t.at(-1);if(o&&s){let r=["composite","easing","offset"];for(let f of r)delete o[f],delete s[f]}e.direction?.includes("reverse")&&([o,s]=[s,o]),Object.assign(i.style,o),await i.animate(t,e).finished,Object.assign(i.style,s)}}get keyframes(){let n=[];for(let i of this.getAttributeNames()){let e=this.getAttribute(i),[,,t,...o]=i.split("-");if(i.startsWith("animation-keyframe-")){let s=o.map((a,r)=>r<1?a:a.at(0)?.toUpperCase()+a.slice(1)).join("");if(t&&s){t==="from"?t="0":t==="to"?t="1":t=String(parseInt(t)*.01);let a=Number(t),r=n.find(f=>f.offset===a);r?r[s]=e:n.push({[s]:e,offset:a})}}}return n.sort((i,e)=>Number(i.offset)-Number(e.offset)),n}};export{p as a};
package/chunk-GPET75FT.js DELETED
@@ -1,9 +0,0 @@
1
- import{b as p}from"./chunk-MXKU7AKV.js";var x=class extends p{#s=[];keyPairs={"(":")","{":"}","[":"]","<":">",'"':'"',"`":"`"};constructor(){super();for(let t of this.#h)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#h(){let t=[];for(let s of this.getTrigger())t.push(this.#l(s));return t}get#o(){let t=this.text.split("```"),s=0;for(let[i,e]of t.entries())if(s+=e.length+3,this.#e<s)return i;return 0}get#t(){return this.textArea.selectionEnd}get#e(){return this.textArea.selectionStart}#i(t,s){this.textArea.setSelectionRange(t,s)}#l(t){let s=t.dataset.type,i=t.dataset.value,e=t.dataset.key??void 0;return{type:s,value:i,key:e}}async#c(t,s,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=k(this.text,t.value,s),this.text=k(this.text,this.keyPairs[t.value],i+t.value.length),t.value.length<2&&this.#s.push(t.value);else if(t.type==="block"){let{lines:e,lineNumber:n}=this.#r(),r=t.value.at(0);r&&e[n]?.startsWith(r)?e[n]=t.value.trim()+e[n]:e[n]=t.value+e[n],this.text=e.join(`
2
- `)}}async#u(t,s,i){let e=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))e?n=r+1:e=r;else if(e)break}else e=s+t.length,n=i+t.length;this.#i(e,n),this.textArea.focus()}async#n(t){let s=this.#t,i=this.#e;await this.#c(t,i,s),this.#u(t.value,i,s)}#f(t){if(t){let s=[];this.#h.forEach(e=>{e.type==="block"&&s.push(e.value)});for(let e=0;e<s.length;e++){let n=s[e];if(n&&t.startsWith(n))return n}let i=g(t);if(i)return`${i}. `}return""}#r(){let t=this.text.split(`
3
- `),s=0;for(let i=0;i<t.length;i++){let e=t.at(i)?.length??0;if(s++,s+=e,s>this.#t)return{lines:t,lineNumber:i,columnNumber:this.#t-(s-e-1)}}return{lines:t,lineNumber:0,columnNumber:0}}#a(t,s=!1){let{lines:i}=this.#r();for(let e=t+1;e<i.length;e++){let n=i[e];if(n){let r=g(n);if(r){let h;if(s)if(r>1)h=r-1;else break;else h=r+1;i[e]=n.slice(String(r).length),i[e]=String(h)+i[e]}else break}}this.text=i.join(`
4
- `)}mount(){this.textArea.addEventListener("keydown",async t=>{let s=["ArrowUp","ArrowDown","Delete"],i=this.text[this.#t]??"";if(s.includes(t.key))this.#s=[];else if(t.key==="Backspace"){let e=this.text[this.#e-1];if(e&&e in this.keyPairs&&i===this.keyPairs[e]){t.preventDefault();let n=this.#e-1,r=this.#t-1;this.text=c(this.text,n),this.text=c(this.text,r),setTimeout(()=>{this.#i(n,r)},0),this.#s.pop()}if(e===`
5
- `&&this.#e===this.#t){t.preventDefault();let n=this.#e-1,{lineNumber:r}=this.#r();this.#a(r,!0),this.text=c(this.text,n),setTimeout(async()=>{this.#i(n,n)},0)}}else if(t.key==="Tab")this.#o%2!==0&&(t.preventDefault(),await this.#n({type:"inline",value:" "}));else if(t.key==="Enter"){let{lines:e,lineNumber:n,columnNumber:r}=this.#r(),h=e.at(n),a=this.#f(h),o=a,u=g(a);if(u&&(a=`${u+1}. `),a&&o.length<r)t.preventDefault(),u&&this.#a(n),await this.#n({type:"inline",value:`
6
- ${a}`});else if(a&&o.length===r){t.preventDefault();let m=this.#t,y=m-o.length;for(let f=0;f<o.length;f++)this.text=c(this.text,m-(f+1));setTimeout(async()=>{this.#i(y,y),this.textArea.focus(),await this.#n({type:"inline",value:`
7
- `})},0)}}else{let e=Object.values(this.keyPairs).includes(i),n=this.#e!==this.#t;if((t.ctrlKey||t.metaKey)&&this.#e===this.#t&&(t.key==="c"||t.key==="x")){t.preventDefault();let{lines:r,lineNumber:h,columnNumber:a}=this.#r();if(await navigator.clipboard.writeText(`${h===0&&t.key==="x"?"":`
8
- `}${r[h]}`),t.key==="x"){let o=this.#e-a;r.splice(h,1),this.text=r.join(`
9
- `),setTimeout(()=>{this.#i(o,o)},0)}}if((t.ctrlKey||t.metaKey)&&t.key){let r=this.#h.find(h=>h.key===t.key);r&&this.#n(r)}else e&&(i===t.key||t.key==="ArrowRight")&&this.#s.length&&!n?(t.preventDefault(),this.#i(this.#e+1,this.#t+1),this.#s.pop()):t.key in this.keyPairs&&(t.preventDefault(),await this.#n({type:"wrap",value:t.key}),this.#s.push(t.key))}}),this.textArea.addEventListener("dblclick",()=>{this.#e!==this.#t&&(this.text[this.#e]===" "&&this.#i(this.#e+1,this.#t),this.text[this.#t-1]===" "&&this.#i(this.#e,this.#t-1))}),this.textArea.addEventListener("click",()=>this.#s=[]);for(let t of this.getTrigger())t.addEventListener(this.event,()=>{this.#n(this.#l(t))})}},g=l=>{let t=l.match(/^(\d+)\./);return t?Number(t[1]):null},k=(l,t,s)=>l.slice(0,s)+t+l.slice(s),c=(l,t)=>l.slice(0,t)+l.slice(t+1);export{x as a};
package/chunk-H4RNP4O4.js DELETED
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-F5BEEHGA.js";var i=class extends e{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())})}};export{i as a};
package/chunk-LHXOPRVC.js DELETED
@@ -1 +0,0 @@
1
- import{a as e}from"./chunk-F5BEEHGA.js";var i=class extends e{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()})}};export{i as a};
package/chunk-MXKU7AKV.js DELETED
@@ -1 +0,0 @@
1
- var o=Object.defineProperty;var l=(s,e)=>{for(var t in e)o(s,t,{get:e[t],enumerable:!0})};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 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()}};export{l as a,i as b};
package/chunk-VEVFQB5N.js DELETED
@@ -1 +0,0 @@
1
- import{b as e}from"./chunk-MXKU7AKV.js";var r=class extends e{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":""}`})}};export{r as a};
package/chunk-XAP2U34A.js DELETED
@@ -1 +0,0 @@
1
- import{a as t}from"./chunk-7F7CQUEG.js";var e=class extends t{constructor(){super()}mount(){this.triggerListener(async()=>await this.copy())}};export{e as a};
package/define/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
-
2
- export { }
package/define/index.js DELETED
@@ -1 +0,0 @@
1
- import{b 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";for(let o in e)customElements.define(`drab-${o.toLowerCase()}`,e[o]);
@@ -1,12 +0,0 @@
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
- type Attributes<CustomElement, Required extends keyof CustomElement = never> = Pick<CustomElement, Required> & Partial<Omit<CustomElement, Required>> & Partial<BaseAttributes>;
11
-
12
- export type { Attributes as A };