drab 5.4.2 → 6.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.
- package/dist/announcer/define.js +3 -0
- package/dist/announcer/index.d.ts +49 -0
- package/dist/announcer/index.js +80 -0
- package/{base → dist/base}/copy/index.d.ts +4 -1
- package/{base → dist/base}/copy/index.js +1 -0
- package/dist/base/define.js +3 -0
- package/{base → dist/base}/index.d.ts +16 -11
- package/{base → dist/base}/index.js +19 -15
- package/dist/contextmenu/define.js +3 -0
- package/dist/contextmenu/index.d.ts +12 -0
- package/{contextmenu → dist/contextmenu}/index.js +6 -12
- package/dist/copy/define.js +3 -0
- package/{copy → dist/copy}/index.d.ts +2 -3
- package/dist/define.js +5 -0
- package/dist/dialog/define.js +3 -0
- package/{dialog → dist/dialog}/index.d.ts +7 -8
- package/{dialog → dist/dialog}/index.js +3 -9
- package/dist/editor/define.js +3 -0
- package/{editor → dist/editor}/index.d.ts +7 -3
- package/dist/fullscreen/define.js +3 -0
- package/{fullscreen → dist/fullscreen}/index.d.ts +3 -7
- package/{fullscreen → dist/fullscreen}/index.js +2 -3
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/intersect/define.js +3 -0
- package/{intersect → dist/intersect}/index.d.ts +4 -5
- package/dist/prefetch/define.js +3 -0
- package/{prefetch → dist/prefetch}/index.d.ts +7 -10
- package/dist/share/define.js +3 -0
- package/{share → dist/share}/index.d.ts +2 -3
- package/dist/tablesort/define.js +3 -0
- package/{tablesort → dist/tablesort}/index.d.ts +6 -3
- package/{tablesort → dist/tablesort}/index.js +33 -21
- package/dist/util/define.d.ts +8 -0
- package/dist/util/define.js +11 -0
- package/dist/wakelock/define.js +3 -0
- package/{wakelock → dist/wakelock}/index.d.ts +5 -6
- package/{wakelock → dist/wakelock}/index.js +2 -0
- package/dist/youtube/define.js +3 -0
- package/{youtube → dist/youtube}/index.d.ts +6 -3
- package/{youtube → dist/youtube}/index.js +0 -1
- package/package.json +109 -145
- package/LICENSE.md +0 -21
- package/README.md +0 -49
- package/animate/define.iife.js +0 -1
- package/animate/define.js +0 -2
- package/animate/index.d.ts +0 -57
- package/animate/index.iife.js +0 -1
- package/animate/index.js +0 -138
- package/base/define.iife.js +0 -1
- package/base/define.js +0 -2
- package/base/index.iife.js +0 -1
- package/breakpoint/define.iife.js +0 -1
- package/breakpoint/define.js +0 -2
- package/breakpoint/index.d.ts +0 -26
- package/breakpoint/index.iife.js +0 -1
- package/breakpoint/index.js +0 -55
- package/contextmenu/define.iife.js +0 -1
- package/contextmenu/define.js +0 -2
- package/contextmenu/index.d.ts +0 -13
- package/contextmenu/index.iife.js +0 -1
- package/copy/define.iife.js +0 -1
- package/copy/define.js +0 -2
- package/copy/index.iife.js +0 -1
- package/define.iife.js +0 -9
- package/define.js +0 -4
- package/details/define.iife.js +0 -1
- package/details/define.js +0 -2
- package/details/index.d.ts +0 -21
- package/details/index.iife.js +0 -1
- package/details/index.js +0 -46
- package/dialog/define.iife.js +0 -1
- package/dialog/define.js +0 -2
- package/dialog/index.iife.js +0 -1
- package/editor/define.iife.js +0 -9
- package/editor/define.js +0 -2
- package/editor/index.iife.js +0 -9
- package/fullscreen/define.iife.js +0 -1
- package/fullscreen/define.js +0 -2
- package/fullscreen/index.iife.js +0 -1
- package/index.d.ts +0 -17
- package/index.iife.js +0 -9
- package/index.js +0 -17
- package/intersect/define.iife.js +0 -1
- package/intersect/define.js +0 -2
- package/intersect/index.iife.js +0 -1
- package/popover/define.iife.js +0 -1
- package/popover/define.js +0 -2
- package/popover/index.d.ts +0 -25
- package/popover/index.iife.js +0 -1
- package/popover/index.js +0 -72
- package/prefetch/define.iife.js +0 -1
- package/prefetch/define.js +0 -2
- package/prefetch/index.iife.js +0 -1
- package/share/define.iife.js +0 -1
- package/share/define.js +0 -2
- package/share/index.iife.js +0 -1
- package/tablesort/define.d.ts +0 -1
- package/tablesort/define.iife.js +0 -1
- package/tablesort/define.js +0 -2
- package/tablesort/index.iife.js +0 -1
- package/types/index.d.ts +0 -11
- package/types/index.js +0 -1
- package/wakelock/define.d.ts +0 -1
- package/wakelock/define.iife.js +0 -1
- package/wakelock/define.js +0 -2
- package/wakelock/index.iife.js +0 -1
- package/youtube/define.d.ts +0 -1
- package/youtube/define.iife.js +0 -1
- package/youtube/define.js +0 -2
- package/youtube/index.iife.js +0 -1
- /package/{animate → dist/announcer}/define.d.ts +0 -0
- /package/{base → dist/base}/define.d.ts +0 -0
- /package/{breakpoint → dist/contextmenu}/define.d.ts +0 -0
- /package/{contextmenu → dist/copy}/define.d.ts +0 -0
- /package/{copy → dist/copy}/index.js +0 -0
- /package/{copy → dist}/define.d.ts +0 -0
- /package/{define.d.ts → dist/dialog/define.d.ts} +0 -0
- /package/{details → dist/editor}/define.d.ts +0 -0
- /package/{editor → dist/editor}/index.js +0 -0
- /package/{dialog → dist/fullscreen}/define.d.ts +0 -0
- /package/{editor → dist/intersect}/define.d.ts +0 -0
- /package/{intersect → dist/intersect}/index.js +0 -0
- /package/{fullscreen → dist/prefetch}/define.d.ts +0 -0
- /package/{prefetch → dist/prefetch}/index.js +0 -0
- /package/{intersect → dist/share}/define.d.ts +0 -0
- /package/{share → dist/share}/index.js +0 -0
- /package/{popover → dist/tablesort}/define.d.ts +0 -0
- /package/{prefetch → dist/wakelock}/define.d.ts +0 -0
- /package/{share → dist/youtube}/define.d.ts +0 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
/**
|
2
|
+
* Use the `Announcer` element to create a visually hidden ARIA live region
|
3
|
+
* that announces content changes to screen readers. Use this element when you
|
4
|
+
* need to announce changes to screen readers that something has changed. If changed
|
5
|
+
* element is visible on the page, add the appropriate ARIA live attribute to the
|
6
|
+
* visible element instead of using this announcer.
|
7
|
+
*
|
8
|
+
* It's recommended to create this element with JavaScript using the `Announcer.init` method,
|
9
|
+
* then you can reuse the same announcer throughout the application to
|
10
|
+
* [avoid duplicate regions](https://www.sarasoueidan.com/blog/accessible-notifications-with-aria-live-regions-part-2/#limit-the-number-of-live-regions-on-the-page)
|
11
|
+
* (see below).
|
12
|
+
*
|
13
|
+
* `aria-live`
|
14
|
+
*
|
15
|
+
* By default, the announcer is created with the
|
16
|
+
* [`polite` ARIA live attribute](https://www.sarasoueidan.com/blog/accessible-notifications-with-aria-live-regions-part-1/#1.-using-the-aria-live-attribute).
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
*
|
20
|
+
* ```ts
|
21
|
+
* import { Announcer } from "drab/announcer";
|
22
|
+
*
|
23
|
+
* // creates and appends a new announcer to the body element
|
24
|
+
* const announcer = Announcer.init();
|
25
|
+
*
|
26
|
+
* // create announcement
|
27
|
+
* announcer.announce("message");
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* > The `Base` element creates a single `Announcer` to share between all elements
|
31
|
+
* > that can be accessed through `this.announce`. If you are using one of drab's other
|
32
|
+
* > elements you can call `announce` directly on the element to announce changes.
|
33
|
+
*/
|
34
|
+
export declare class Announcer extends HTMLElement {
|
35
|
+
constructor();
|
36
|
+
connectedCallback(): void;
|
37
|
+
/**
|
38
|
+
* @param message message to announce to screen readers
|
39
|
+
*/
|
40
|
+
announce(message: string): void;
|
41
|
+
/**
|
42
|
+
* Helper method to create a new `Announcer` element named `drab-announcer`
|
43
|
+
* and append the element to the `<body>` tag. If an announcer already exists
|
44
|
+
* on the page it will return the existing element.
|
45
|
+
*
|
46
|
+
* @returns the created or existing `Announcer` element
|
47
|
+
*/
|
48
|
+
static init(): Announcer;
|
49
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { define } from "../util/define.js";
|
2
|
+
/**
|
3
|
+
* Use the `Announcer` element to create a visually hidden ARIA live region
|
4
|
+
* that announces content changes to screen readers. Use this element when you
|
5
|
+
* need to announce changes to screen readers that something has changed. If changed
|
6
|
+
* element is visible on the page, add the appropriate ARIA live attribute to the
|
7
|
+
* visible element instead of using this announcer.
|
8
|
+
*
|
9
|
+
* It's recommended to create this element with JavaScript using the `Announcer.init` method,
|
10
|
+
* then you can reuse the same announcer throughout the application to
|
11
|
+
* [avoid duplicate regions](https://www.sarasoueidan.com/blog/accessible-notifications-with-aria-live-regions-part-2/#limit-the-number-of-live-regions-on-the-page)
|
12
|
+
* (see below).
|
13
|
+
*
|
14
|
+
* `aria-live`
|
15
|
+
*
|
16
|
+
* By default, the announcer is created with the
|
17
|
+
* [`polite` ARIA live attribute](https://www.sarasoueidan.com/blog/accessible-notifications-with-aria-live-regions-part-1/#1.-using-the-aria-live-attribute).
|
18
|
+
*
|
19
|
+
* @example
|
20
|
+
*
|
21
|
+
* ```ts
|
22
|
+
* import { Announcer } from "drab/announcer";
|
23
|
+
*
|
24
|
+
* // creates and appends a new announcer to the body element
|
25
|
+
* const announcer = Announcer.init();
|
26
|
+
*
|
27
|
+
* // create announcement
|
28
|
+
* announcer.announce("message");
|
29
|
+
* ```
|
30
|
+
*
|
31
|
+
* > The `Base` element creates a single `Announcer` to share between all elements
|
32
|
+
* > that can be accessed through `this.announce`. If you are using one of drab's other
|
33
|
+
* > elements you can call `announce` directly on the element to announce changes.
|
34
|
+
*/
|
35
|
+
export class Announcer extends HTMLElement {
|
36
|
+
constructor() {
|
37
|
+
super();
|
38
|
+
}
|
39
|
+
connectedCallback() {
|
40
|
+
this.style.position = "absolute";
|
41
|
+
this.style.width = "1px";
|
42
|
+
this.style.height = "1px";
|
43
|
+
this.style.padding = "0";
|
44
|
+
this.style.margin = "-1px";
|
45
|
+
this.style.overflow = "hidden";
|
46
|
+
this.style.clipPath = "rect(0, 0, 0, 0)";
|
47
|
+
this.style.whiteSpace = "nowrap";
|
48
|
+
this.style.borderWidth = "0";
|
49
|
+
if (!this.ariaLive)
|
50
|
+
this.ariaLive = "polite";
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* @param message message to announce to screen readers
|
54
|
+
*/
|
55
|
+
announce(message) {
|
56
|
+
// this ensures multiple messages will be read in succession
|
57
|
+
const span = document.createElement("span");
|
58
|
+
span.textContent = message;
|
59
|
+
this.append(span);
|
60
|
+
// https://www.sarasoueidan.com/blog/accessible-notifications-with-aria-live-regions-part-2/#empty-the-live-region-and-wait-a-bit-in-between-updates
|
61
|
+
setTimeout(() => span.remove(), 10000);
|
62
|
+
}
|
63
|
+
/**
|
64
|
+
* Helper method to create a new `Announcer` element named `drab-announcer`
|
65
|
+
* and append the element to the `<body>` tag. If an announcer already exists
|
66
|
+
* on the page it will return the existing element.
|
67
|
+
*
|
68
|
+
* @returns the created or existing `Announcer` element
|
69
|
+
*/
|
70
|
+
static init() {
|
71
|
+
define("drab-announcer", this);
|
72
|
+
const name = "drab-announcer";
|
73
|
+
let announcer = document.querySelector(name);
|
74
|
+
if (!announcer) {
|
75
|
+
announcer = document.createElement(name);
|
76
|
+
document.body.append(announcer);
|
77
|
+
}
|
78
|
+
return announcer;
|
79
|
+
}
|
80
|
+
}
|
@@ -1,3 +1,8 @@
|
|
1
|
+
export type BaseAttributes = {
|
2
|
+
trigger?: string;
|
3
|
+
content?: string;
|
4
|
+
swap?: string;
|
5
|
+
};
|
1
6
|
/**
|
2
7
|
* Each element in the library extends the `Base` class. It provides methods
|
3
8
|
* for selecting elements via HTML attributes along with other helpers.
|
@@ -22,14 +27,18 @@ export declare class Base extends HTMLElement {
|
|
22
27
|
*/
|
23
28
|
get event(): keyof HTMLElementEventMap;
|
24
29
|
set event(value: keyof HTMLElementEventMap);
|
30
|
+
/**
|
31
|
+
* @param message message to announce to screen readers
|
32
|
+
*/
|
33
|
+
announce(message: string): void;
|
25
34
|
/**
|
26
35
|
* @returns All of the elements that match the `trigger` selector.
|
27
36
|
* @default this.querySelectorAll("[data-trigger]")
|
28
37
|
*/
|
29
38
|
getTrigger<T extends HTMLElement = HTMLElement>(): NodeListOf<T>;
|
30
39
|
/**
|
31
|
-
* @param instance The instance of the desired element
|
32
|
-
* Defaults to `HTMLElement`.
|
40
|
+
* @param instance The instance of the desired element to validate against,
|
41
|
+
* ex: `HTMLDialogElement`. Defaults to `HTMLElement`.
|
33
42
|
* @returns The element that matches the `content` selector.
|
34
43
|
* @default this.querySelector("[data-content]")
|
35
44
|
*/
|
@@ -40,10 +49,10 @@ export declare class Base extends HTMLElement {
|
|
40
49
|
* Finds the `HTMLElement | HTMLTemplateElement` via the `swap` selector and
|
41
50
|
* swaps `this.content()` with the content of the element found.
|
42
51
|
*
|
43
|
-
* @param revert
|
44
|
-
*
|
52
|
+
* @param revert Wait time (ms) before swapping back, set to `false` to not revert.
|
53
|
+
* default: `800`
|
45
54
|
*/
|
46
|
-
swapContent(revert?:
|
55
|
+
swapContent(revert?: number | false): void;
|
47
56
|
/**
|
48
57
|
* Wrapper around `document.body.addEventListener` that ensures when the
|
49
58
|
* element is removed from the DOM, these event listeners are cleaned up.
|
@@ -62,16 +71,12 @@ export declare class Base extends HTMLElement {
|
|
62
71
|
* 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
72
|
*/
|
64
73
|
mount(): void;
|
65
|
-
/**
|
66
|
-
* Called when custom element is added to the page.
|
67
|
-
*/
|
74
|
+
/** Called when custom element is added to the page. */
|
68
75
|
connectedCallback(): void;
|
69
76
|
/**
|
70
77
|
* Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
|
71
78
|
*/
|
72
79
|
destroy(): void;
|
73
|
-
/**
|
74
|
-
* Called when custom element is removed from the page.
|
75
|
-
*/
|
80
|
+
/** Called when custom element is removed from the page. */
|
76
81
|
disconnectedCallback(): void;
|
77
82
|
}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { Announcer } from "../announcer/index.js";
|
1
2
|
/**
|
2
3
|
* Each element in the library extends the `Base` class. It provides methods
|
3
4
|
* for selecting elements via HTML attributes along with other helpers.
|
@@ -12,8 +13,11 @@
|
|
12
13
|
*/
|
13
14
|
export class Base extends HTMLElement {
|
14
15
|
/**
|
15
|
-
*
|
16
|
+
* A single `Announcer` element to share between all drab elements to announce
|
17
|
+
* interactive changes.
|
16
18
|
*/
|
19
|
+
static #announcer = Announcer.init();
|
20
|
+
/** To clean up event listeners added to `document` when the element is removed. */
|
17
21
|
#listenerController = new AbortController();
|
18
22
|
constructor() {
|
19
23
|
super();
|
@@ -31,6 +35,12 @@ export class Base extends HTMLElement {
|
|
31
35
|
set event(value) {
|
32
36
|
this.setAttribute("event", value);
|
33
37
|
}
|
38
|
+
/**
|
39
|
+
* @param message message to announce to screen readers
|
40
|
+
*/
|
41
|
+
announce(message) {
|
42
|
+
Base.#announcer.announce(message);
|
43
|
+
}
|
34
44
|
/**
|
35
45
|
* @returns All of the elements that match the `trigger` selector.
|
36
46
|
* @default this.querySelectorAll("[data-trigger]")
|
@@ -40,8 +50,8 @@ export class Base extends HTMLElement {
|
|
40
50
|
return triggers;
|
41
51
|
}
|
42
52
|
/**
|
43
|
-
* @param instance The instance of the desired element
|
44
|
-
* Defaults to `HTMLElement`.
|
53
|
+
* @param instance The instance of the desired element to validate against,
|
54
|
+
* ex: `HTMLDialogElement`. Defaults to `HTMLElement`.
|
45
55
|
* @returns The element that matches the `content` selector.
|
46
56
|
* @default this.querySelector("[data-content]")
|
47
57
|
*/
|
@@ -55,12 +65,10 @@ export class Base extends HTMLElement {
|
|
55
65
|
* Finds the `HTMLElement | HTMLTemplateElement` via the `swap` selector and
|
56
66
|
* swaps `this.content()` with the content of the element found.
|
57
67
|
*
|
58
|
-
* @param revert
|
59
|
-
*
|
68
|
+
* @param revert Wait time (ms) before swapping back, set to `false` to not revert.
|
69
|
+
* default: `800`
|
60
70
|
*/
|
61
|
-
swapContent(revert =
|
62
|
-
// BREAKING TODO: `revert` and `delay` -- these could be one parameter
|
63
|
-
// revert: number = 800
|
71
|
+
swapContent(revert = 800) {
|
64
72
|
/** The swap element, used to hold the replacement contents. */
|
65
73
|
const swap = this.querySelector(this.getAttribute("swap") ?? "[data-swap]");
|
66
74
|
if (swap) {
|
@@ -87,7 +95,7 @@ export class Base extends HTMLElement {
|
|
87
95
|
this.getContent().replaceChildren(...placeholder);
|
88
96
|
if (revert) {
|
89
97
|
// wait and then run again to swap back
|
90
|
-
setTimeout(() => this.swapContent(
|
98
|
+
setTimeout(() => this.swapContent(0), revert);
|
91
99
|
}
|
92
100
|
}
|
93
101
|
}
|
@@ -117,9 +125,7 @@ export class Base extends HTMLElement {
|
|
117
125
|
* 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
126
|
*/
|
119
127
|
mount() { }
|
120
|
-
/**
|
121
|
-
* Called when custom element is added to the page.
|
122
|
-
*/
|
128
|
+
/** Called when custom element is added to the page. */
|
123
129
|
connectedCallback() {
|
124
130
|
queueMicrotask(() => this.mount());
|
125
131
|
}
|
@@ -127,9 +133,7 @@ export class Base extends HTMLElement {
|
|
127
133
|
* Passed into `disconnectedCallback`, since `Base` needs to run `disconnectedCallback` as well. It is overridden in each element that needs to run `disconnectedCallback`.
|
128
134
|
*/
|
129
135
|
destroy() { }
|
130
|
-
/**
|
131
|
-
* Called when custom element is removed from the page.
|
132
|
-
*/
|
136
|
+
/** Called when custom element is removed from the page. */
|
133
137
|
disconnectedCallback() {
|
134
138
|
this.destroy();
|
135
139
|
this.#listenerController.abort();
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
2
|
+
export type ContextMenuAttributes = BaseAttributes;
|
3
|
+
/**
|
4
|
+
* Displays content when the `trigger` element is right clicked, or long pressed on mobile.
|
5
|
+
*/
|
6
|
+
export declare class ContextMenu extends Base {
|
7
|
+
#private;
|
8
|
+
constructor();
|
9
|
+
show(e: MouseEvent | TouchEvent): Promise<void>;
|
10
|
+
hide(): Promise<void>;
|
11
|
+
mount(): void;
|
12
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { Base } from "../base/index.js";
|
2
2
|
/**
|
3
3
|
* Displays content when the `trigger` element is right clicked, or long pressed on mobile.
|
4
4
|
*/
|
5
|
-
export class ContextMenu extends
|
5
|
+
export class ContextMenu extends Base {
|
6
6
|
/** Tracks the long press duration on mobile. */
|
7
7
|
#touchTimer;
|
8
8
|
constructor() {
|
@@ -17,12 +17,12 @@ export class ContextMenu extends Animate {
|
|
17
17
|
// find coordinates of the click
|
18
18
|
const scrollY = window.scrollY;
|
19
19
|
const scrollX = window.scrollX;
|
20
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0]?.clientX ?? 0;
|
21
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0]?.clientY ?? 0;
|
20
|
+
const clientX = e instanceof MouseEvent ? e.clientX : (e.touches[0]?.clientX ?? 0);
|
21
|
+
const clientY = e instanceof MouseEvent ? e.clientY : (e.touches[0]?.clientY ?? 0);
|
22
22
|
let x = clientX + scrollX;
|
23
23
|
let y = clientY + scrollY;
|
24
24
|
this.getContent().style.position = "absolute";
|
25
|
-
this.getContent().
|
25
|
+
this.getContent().setAttribute("data-open", "");
|
26
26
|
const offsetWidth = this.getContent().offsetWidth + 24;
|
27
27
|
const offsetHeight = this.getContent().offsetHeight + 6;
|
28
28
|
const innerWidth = window.innerWidth;
|
@@ -35,15 +35,9 @@ export class ContextMenu extends Animate {
|
|
35
35
|
y = scrollY + innerHeight - offsetHeight;
|
36
36
|
}
|
37
37
|
this.#coordinates = { x, y };
|
38
|
-
await this.animateElement();
|
39
38
|
}
|
40
39
|
async hide() {
|
41
|
-
|
42
|
-
await this.animateElement({
|
43
|
-
options: { direction: "reverse" },
|
44
|
-
});
|
45
|
-
this.getContent().style.display = "none";
|
46
|
-
}
|
40
|
+
this.getContent().removeAttribute("data-open");
|
47
41
|
}
|
48
42
|
mount() {
|
49
43
|
// mouse
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { BaseCopy } from "../base/copy/index.js";
|
2
|
-
|
3
|
-
export type CopyAttributes = Attributes<Copy, "value">;
|
1
|
+
import { BaseCopy, type BaseCopyAttributes } from "../base/copy/index.js";
|
2
|
+
export type CopyAttributes = BaseCopyAttributes;
|
4
3
|
/**
|
5
4
|
* Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
|
6
5
|
* to copy text.
|
package/dist/define.js
ADDED
@@ -1,11 +1,10 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
"
|
5
|
-
|
6
|
-
}>;
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
2
|
+
export type DialogAttributes = BaseAttributes & {
|
3
|
+
"click-outside-close"?: boolean;
|
4
|
+
"remove-body-scroll"?: boolean;
|
5
|
+
};
|
7
6
|
/**
|
8
|
-
* Provides triggers
|
7
|
+
* Provides triggers for the `HTMLDialogElement`.
|
9
8
|
*
|
10
9
|
* `click-outside-close`
|
11
10
|
*
|
@@ -17,7 +16,7 @@ export type DialogAttributes = Attributes<Dialog> & AnimateAttributes & Partial<
|
|
17
16
|
* Add the `remove-body-scroll` attribute to remove the scroll from `document.body` when the dialog
|
18
17
|
* is open.
|
19
18
|
*/
|
20
|
-
export declare class Dialog extends
|
19
|
+
export declare class Dialog extends Base {
|
21
20
|
#private;
|
22
21
|
constructor();
|
23
22
|
/** The `HTMLDialogElement` within the element. */
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { Base } from "../base/index.js";
|
2
2
|
/**
|
3
|
-
* Provides triggers
|
3
|
+
* Provides triggers for the `HTMLDialogElement`.
|
4
4
|
*
|
5
5
|
* `click-outside-close`
|
6
6
|
*
|
@@ -12,7 +12,7 @@ import { Animate } from "../animate/index.js";
|
|
12
12
|
* Add the `remove-body-scroll` attribute to remove the scroll from `document.body` when the dialog
|
13
13
|
* is open.
|
14
14
|
*/
|
15
|
-
export class Dialog extends
|
15
|
+
export class Dialog extends Base {
|
16
16
|
/** The initial margin-right value of the body element. */
|
17
17
|
#initialBodyMarginRight = parseInt(getComputedStyle(document.body).marginRight);
|
18
18
|
constructor() {
|
@@ -38,15 +38,9 @@ export class Dialog extends Animate {
|
|
38
38
|
async show() {
|
39
39
|
this.dialog.showModal();
|
40
40
|
this.#toggleBodyScroll(true);
|
41
|
-
await this.animateElement();
|
42
41
|
}
|
43
42
|
/** `HTMLDialogElement.close()` with animation. */
|
44
43
|
async close() {
|
45
|
-
await this.animateElement({
|
46
|
-
options: {
|
47
|
-
direction: "reverse",
|
48
|
-
},
|
49
|
-
});
|
50
44
|
this.#toggleBodyScroll(false);
|
51
45
|
this.dialog.close();
|
52
46
|
}
|
@@ -1,6 +1,10 @@
|
|
1
|
-
import { Base } from "../base/index.js";
|
2
|
-
|
3
|
-
export type
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
2
|
+
export type EditorAttributes = BaseAttributes;
|
3
|
+
export type EditorTriggerAttributes = {
|
4
|
+
"data-value": string;
|
5
|
+
"data-key": string;
|
6
|
+
"data-type": "block" | "wrap" | "inline";
|
7
|
+
};
|
4
8
|
/**
|
5
9
|
* A piece of content to insert into the `textarea`.
|
6
10
|
*/
|
@@ -1,21 +1,17 @@
|
|
1
|
-
import { Base } from "../base/index.js";
|
2
|
-
|
3
|
-
export type FullscreenAttributes = Attributes<Fullscreen>;
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
2
|
+
export type FullscreenAttributes = BaseAttributes;
|
4
3
|
/**
|
5
4
|
* Toggles the `documentElement` or `content` element to fullscreen mode.
|
6
5
|
*
|
7
6
|
* Disables the `trigger` if fullscreen is not supported.
|
8
7
|
*/
|
9
8
|
export declare class Fullscreen extends Base {
|
9
|
+
#private;
|
10
10
|
constructor();
|
11
11
|
/**
|
12
12
|
* @returns `true` if fullscreen is currently enabled.
|
13
13
|
*/
|
14
14
|
isFullscreen(): boolean;
|
15
|
-
/**
|
16
|
-
* @returns `true` if fullscreen is supported.
|
17
|
-
*/
|
18
|
-
fullscreenSupported(): boolean;
|
19
15
|
/** Enables or disables fullscreen mode based on the current state. */
|
20
16
|
toggle(): void;
|
21
17
|
mount(): void;
|
@@ -17,8 +17,7 @@ export class Fullscreen extends Base {
|
|
17
17
|
/**
|
18
18
|
* @returns `true` if fullscreen is supported.
|
19
19
|
*/
|
20
|
-
fullscreenSupported() {
|
21
|
-
// BREAKING TODO: make private like in WakeLock
|
20
|
+
#fullscreenSupported() {
|
22
21
|
return Boolean(document.documentElement.requestFullscreen);
|
23
22
|
}
|
24
23
|
/** Enables or disables fullscreen mode based on the current state. */
|
@@ -38,7 +37,7 @@ export class Fullscreen extends Base {
|
|
38
37
|
mount() {
|
39
38
|
this.triggerListener(() => this.toggle());
|
40
39
|
for (const trigger of this.getTrigger()) {
|
41
|
-
if (!this
|
40
|
+
if (!this.#fullscreenSupported() && "disabled" in trigger) {
|
42
41
|
trigger.disabled = true;
|
43
42
|
}
|
44
43
|
}
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
export * from "./announcer/index.js";
|
2
|
+
export * from "./base/index.js";
|
3
|
+
export * from "./contextmenu/index.js";
|
4
|
+
export * from "./copy/index.js";
|
5
|
+
export * from "./dialog/index.js";
|
6
|
+
export * from "./editor/index.js";
|
7
|
+
export * from "./fullscreen/index.js";
|
8
|
+
export * from "./intersect/index.js";
|
9
|
+
export * from "./prefetch/index.js";
|
10
|
+
export * from "./share/index.js";
|
11
|
+
export * from "./tablesort/index.js";
|
12
|
+
export * from "./wakelock/index.js";
|
13
|
+
export * from "./youtube/index.js";
|
package/dist/index.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
export * from "./announcer/index.js";
|
2
|
+
export * from "./base/index.js";
|
3
|
+
export * from "./contextmenu/index.js";
|
4
|
+
export * from "./copy/index.js";
|
5
|
+
export * from "./dialog/index.js";
|
6
|
+
export * from "./editor/index.js";
|
7
|
+
export * from "./fullscreen/index.js";
|
8
|
+
export * from "./intersect/index.js";
|
9
|
+
export * from "./prefetch/index.js";
|
10
|
+
export * from "./share/index.js";
|
11
|
+
export * from "./tablesort/index.js";
|
12
|
+
export * from "./wakelock/index.js";
|
13
|
+
export * from "./youtube/index.js";
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import { Base } from "../base/index.js";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}>;
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
2
|
+
export type IntersectAttributes = BaseAttributes & {
|
3
|
+
threshold?: number;
|
4
|
+
};
|
6
5
|
type IntersectCallback = () => any;
|
7
6
|
/**
|
8
7
|
* Uses the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) to add a `data-intersect` attribute to `content` when the `trigger` is intersecting.
|
@@ -1,11 +1,10 @@
|
|
1
|
-
import { Base } from "../base/index.js";
|
2
|
-
import type { Attributes } from "../types/index.js";
|
1
|
+
import { Base, type BaseAttributes } from "../base/index.js";
|
3
2
|
type Strategy = "hover" | "load" | "visible";
|
4
|
-
export type PrefetchAttributes =
|
5
|
-
strategy
|
6
|
-
prerender
|
7
|
-
url
|
8
|
-
}
|
3
|
+
export type PrefetchAttributes = BaseAttributes & {
|
4
|
+
strategy?: Strategy;
|
5
|
+
prerender?: boolean;
|
6
|
+
url?: string;
|
7
|
+
};
|
9
8
|
/**
|
10
9
|
* The `Prefetch` element can prefetch a url, or enhance the `HTMLAnchorElement` by loading the HTML for a page before it is navigated to. This element speeds up the navigation for multi-page applications (MPAs).
|
11
10
|
*
|
@@ -60,9 +59,7 @@ export declare class Prefetch extends Base {
|
|
60
59
|
prefetch(options?: {
|
61
60
|
/** The anchors to prefetch. Defaults to `trigger` elements. */
|
62
61
|
anchors?: NodeListOf<HTMLAnchorElement>;
|
63
|
-
/**
|
64
|
-
* Uses the Speculation Rules API when supported to prerender on the client.
|
65
|
-
*/
|
62
|
+
/** Uses the Speculation Rules API when supported to prerender on the client. */
|
66
63
|
prerender?: boolean;
|
67
64
|
/**
|
68
65
|
* Determines when the prefetch takes place.
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { BaseCopy } from "../base/copy/index.js";
|
2
|
-
|
3
|
-
export type ShareAttributes = Attributes<Share, "value">;
|
1
|
+
import { BaseCopy, type BaseCopyAttributes } from "../base/copy/index.js";
|
2
|
+
export type ShareAttributes = BaseCopyAttributes;
|
4
3
|
/**
|
5
4
|
* 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.
|
6
5
|
*/
|