drab 6.5.0 → 7.0.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 (39) hide show
  1. package/dist/announcer/index.d.ts +2 -0
  2. package/dist/base/index.d.ts +101 -1536
  3. package/dist/base/index.js +87 -76
  4. package/dist/contextmenu/index.d.ts +1045 -3
  5. package/dist/contextmenu/index.js +15 -15
  6. package/dist/define.d.ts +11 -1
  7. package/dist/define.js +11 -5
  8. package/dist/dialog/index.d.ts +1047 -6
  9. package/dist/dialog/index.js +22 -22
  10. package/dist/editor/index.d.ts +1047 -12
  11. package/dist/editor/index.js +36 -36
  12. package/dist/fullscreen/index.d.ts +1045 -7
  13. package/dist/fullscreen/index.js +8 -8
  14. package/dist/index.d.ts +0 -3
  15. package/dist/index.js +0 -3
  16. package/dist/intersect/index.d.ts +1059 -16
  17. package/dist/intersect/index.js +26 -33
  18. package/dist/prefetch/index.d.ts +706 -25
  19. package/dist/prefetch/index.js +25 -44
  20. package/dist/share/index.d.ts +1413 -11
  21. package/dist/share/index.js +50 -18
  22. package/dist/tablesort/index.d.ts +1390 -5
  23. package/dist/tablesort/index.js +5 -5
  24. package/dist/tabs/index.d.ts +702 -4
  25. package/dist/tabs/index.js +3 -3
  26. package/dist/types/index.d.ts +29 -0
  27. package/dist/wakelock/index.d.ts +1390 -6
  28. package/dist/wakelock/index.js +16 -16
  29. package/package.json +14 -24
  30. package/dist/base/define.js +0 -3
  31. package/dist/copy/define.d.ts +0 -1
  32. package/dist/copy/define.js +0 -3
  33. package/dist/copy/index.d.ts +0 -30
  34. package/dist/copy/index.js +0 -39
  35. package/dist/youtube/define.d.ts +0 -1
  36. package/dist/youtube/define.js +0 -3
  37. package/dist/youtube/index.d.ts +0 -31
  38. package/dist/youtube/index.js +0 -56
  39. /package/dist/{base/define.d.ts → types/index.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { Base } from "../base/index.js";
1
+ import { Announce, Content, Lifecycle, Trigger, } from "../base/index.js";
2
2
  /**
3
3
  * `WakeLock` uses the
4
4
  * [WakeLock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API)
@@ -7,7 +7,6 @@ import { Base } from "../base/index.js";
7
7
  * that needs to stay on, or you are displaying a QR code.
8
8
  *
9
9
  * - Use `content` and `swap` elements to adjust the UI based on the current state.
10
- * - `request` and `release` methods are provided to set the WakeLock with JavaScript.
11
10
  * - `trigger` is disabled if not supported.
12
11
  * - WakeLock is released when the element is removed from the DOM.
13
12
  *
@@ -24,8 +23,8 @@ import { Base } from "../base/index.js";
24
23
  * WakeLock can be toggled with a `trigger`, or will be requested if the element has
25
24
  * a `locked` attribute when connected.
26
25
  */
27
- export class WakeLock extends Base {
28
- wakeLock = null;
26
+ export class WakeLock extends Lifecycle(Trigger(Content(Announce()))) {
27
+ #wakeLock = null;
29
28
  constructor() {
30
29
  super();
31
30
  }
@@ -34,7 +33,8 @@ export class WakeLock extends Base {
34
33
  return "wakeLock" in navigator;
35
34
  }
36
35
  /**
37
- * the `auto-lock` attribute controls whether an active WakeLock should be restored when navigating back to the page.
36
+ * the `auto-lock` attribute controls whether an active WakeLock should be restored when navigating back to
37
+ * the page.
38
38
  */
39
39
  get #autoLock() {
40
40
  return this.hasAttribute("auto-lock");
@@ -42,42 +42,42 @@ export class WakeLock extends Base {
42
42
  /** Requests WakeLock on the current page. */
43
43
  async request() {
44
44
  if (this.#wakeLockSupported() && document.visibilityState === "visible") {
45
- this.wakeLock = await navigator.wakeLock.request("screen");
45
+ this.#wakeLock = await navigator.wakeLock.request("screen");
46
46
  this.setAttribute("locked", "");
47
47
  this.announce("screen wake lock activated");
48
- this.swapContent(false);
49
- this.wakeLock.addEventListener("release", () => {
48
+ this.swap(false);
49
+ this.#wakeLock.addEventListener("release", () => {
50
50
  this.removeAttribute("locked");
51
51
  this.announce("screen wake lock deactivated");
52
- this.swapContent(false);
52
+ this.swap(false);
53
53
  if (!this.#autoLock) {
54
54
  // set to null is required, used to determine if screen should be
55
55
  // locked again, see visibilitychange listener
56
- this.wakeLock = null;
56
+ this.#wakeLock = null;
57
57
  }
58
58
  });
59
59
  }
60
60
  }
61
61
  /** Releases the WakeLock, sets `this.wakeLock` to null. */
62
62
  async release() {
63
- await this.wakeLock?.release();
64
- this.wakeLock = null;
63
+ await this.#wakeLock?.release();
64
+ this.#wakeLock = null;
65
65
  }
66
66
  mount() {
67
67
  // lock on mount if the `locked` attribute is present
68
68
  if (this.hasAttribute("locked")) {
69
69
  this.request();
70
70
  }
71
- this.triggerListener(() => {
71
+ this.listener(() => {
72
72
  // toggle
73
- if (this.wakeLock) {
73
+ if (this.#wakeLock) {
74
74
  this.release();
75
75
  }
76
76
  else {
77
77
  this.request();
78
78
  }
79
79
  });
80
- for (const trigger of this.getTrigger()) {
80
+ for (const trigger of this.triggers()) {
81
81
  if (!this.#wakeLockSupported() && "disabled" in trigger) {
82
82
  // disable `trigger` if not supported
83
83
  trigger.disabled = true;
@@ -88,7 +88,7 @@ export class WakeLock extends Base {
88
88
  // When the tab is not visible, the wakeLock is automatically released.
89
89
  // This requests it back if it exists, if it is `null`, that
90
90
  // means it was removed. In which case, it shouldn't be requested again.
91
- if (this.wakeLock) {
91
+ if (this.#wakeLock) {
92
92
  this.request();
93
93
  }
94
94
  }, document);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drab",
3
3
  "description": "Interactivity for You",
4
- "version": "6.5.0",
4
+ "version": "7.0.0",
5
5
  "homepage": "https://drab.robino.dev",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -12,7 +12,6 @@
12
12
  "web components",
13
13
  "custom elements",
14
14
  "contextmenu",
15
- "copy",
16
15
  "dialog",
17
16
  "editor",
18
17
  "fullscreen",
@@ -20,8 +19,8 @@
20
19
  "prefetch",
21
20
  "share",
22
21
  "tablesort",
23
- "wakelock",
24
- "youtube"
22
+ "tabs",
23
+ "wakelock"
25
24
  ],
26
25
  "repository": {
27
26
  "type": "git",
@@ -54,10 +53,6 @@
54
53
  "types": "./dist/base/index.d.ts",
55
54
  "default": "./dist/base/index.js"
56
55
  },
57
- "./base/define": {
58
- "types": "./dist/base/define.d.ts",
59
- "default": "./dist/base/define.js"
60
- },
61
56
  "./breakpoint": {
62
57
  "types": "./dist/breakpoint/index.d.ts",
63
58
  "default": "./dist/breakpoint/index.js"
@@ -74,14 +69,6 @@
74
69
  "types": "./dist/contextmenu/define.d.ts",
75
70
  "default": "./dist/contextmenu/define.js"
76
71
  },
77
- "./copy": {
78
- "types": "./dist/copy/index.d.ts",
79
- "default": "./dist/copy/index.js"
80
- },
81
- "./copy/define": {
82
- "types": "./dist/copy/define.d.ts",
83
- "default": "./dist/copy/define.js"
84
- },
85
72
  "./dialog": {
86
73
  "types": "./dist/dialog/index.d.ts",
87
74
  "default": "./dist/dialog/index.js"
@@ -138,6 +125,17 @@
138
125
  "types": "./dist/tablesort/define.d.ts",
139
126
  "default": "./dist/tablesort/define.js"
140
127
  },
128
+ "./tabs": {
129
+ "types": "./dist/tabs/index.d.ts",
130
+ "default": "./dist/tabs/index.js"
131
+ },
132
+ "./tabs/define": {
133
+ "types": "./dist/tabs/define.d.ts",
134
+ "default": "./dist/tabs/define.js"
135
+ },
136
+ "./types": {
137
+ "types": "./dist/types/index.d.ts"
138
+ },
141
139
  "./wakelock": {
142
140
  "types": "./dist/wakelock/index.d.ts",
143
141
  "default": "./dist/wakelock/index.js"
@@ -145,14 +143,6 @@
145
143
  "./wakelock/define": {
146
144
  "types": "./dist/wakelock/define.d.ts",
147
145
  "default": "./dist/wakelock/define.js"
148
- },
149
- "./youtube": {
150
- "types": "./dist/youtube/index.d.ts",
151
- "default": "./dist/youtube/index.js"
152
- },
153
- "./youtube/define": {
154
- "types": "./dist/youtube/define.d.ts",
155
- "default": "./dist/youtube/define.js"
156
146
  }
157
147
  },
158
148
  "files": [
@@ -1,3 +0,0 @@
1
- import { define } from "../util/define.js";
2
- import { Base } from "./index.js";
3
- define("drab-base", Base);
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { define } from "../util/define.js";
2
- import { Copy } from "./index.js";
3
- define("drab-copy", Copy);
@@ -1,30 +0,0 @@
1
- import { Base, type BaseAttributes } from "../base/index.js";
2
- export type CopyAttributes = BaseAttributes & {
3
- value: string;
4
- };
5
- /**
6
- * Uses the
7
- * [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
8
- * to copy text.
9
- *
10
- * ### Attributes
11
- *
12
- * `value`
13
- *
14
- * Text to copy.
15
- */
16
- export declare class Copy extends Base {
17
- constructor();
18
- /**
19
- * The value to copy.
20
- *
21
- * @default ""
22
- */
23
- get value(): string;
24
- set value(value: string);
25
- /**
26
- * @param value The `value` to copy
27
- */
28
- copy(value?: string): Promise<void>;
29
- mount(): void;
30
- }
@@ -1,39 +0,0 @@
1
- import { Base } from "../base/index.js";
2
- /**
3
- * Uses the
4
- * [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/writeText)
5
- * to copy text.
6
- *
7
- * ### Attributes
8
- *
9
- * `value`
10
- *
11
- * Text to copy.
12
- */
13
- export class Copy extends Base {
14
- constructor() {
15
- super();
16
- }
17
- /**
18
- * The value to copy.
19
- *
20
- * @default ""
21
- */
22
- get value() {
23
- return this.getAttribute("value") ?? "";
24
- }
25
- set value(value) {
26
- this.setAttribute("value", value);
27
- }
28
- /**
29
- * @param value The `value` to copy
30
- */
31
- copy(value = this.value) {
32
- this.announce("copied text to clipboard");
33
- this.swapContent();
34
- return navigator.clipboard.writeText(value);
35
- }
36
- mount() {
37
- this.triggerListener(() => this.copy());
38
- }
39
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import { define } from "../util/define.js";
2
- import { YouTube } from "./index.js";
3
- define("drab-youtube", YouTube);
@@ -1,31 +0,0 @@
1
- import { Base, type BaseAttributes } from "../base/index.js";
2
- export type YouTubeAttributes = BaseAttributes & {
3
- autoplay?: boolean;
4
- start?: number;
5
- uid: string;
6
- };
7
- /**
8
- * Embeds a YouTube video iframe into a website with the video uid, using www.youtube-nocookie.com.
9
- */
10
- export declare class YouTube extends Base {
11
- static observedAttributes: readonly ["autoplay", "start", "uid"];
12
- constructor();
13
- /** The `HTMLIFrameElement` within the element. */
14
- get iframe(): HTMLIFrameElement;
15
- /** Whether the video should start playing when loaded. */
16
- get autoplay(): boolean;
17
- set autoplay(value: boolean);
18
- /** The start time of the video (seconds). */
19
- get start(): string;
20
- set start(value: string);
21
- /**
22
- * The video's YouTube uid, found within the url of the video.
23
- *
24
- * For example if the video url is https://youtu.be/gouiY85kD2o,
25
- * the `uid` is `"gouiY85kD2o"`.
26
- */
27
- get uid(): string;
28
- set uid(v: string);
29
- mount(): void;
30
- attributeChangedCallback(): void;
31
- }
@@ -1,56 +0,0 @@
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
- }
File without changes