drab 5.0.2 → 5.2.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 (46) hide show
  1. package/animate/define.iife.js +1 -1
  2. package/animate/index.iife.js +1 -1
  3. package/base/define.iife.js +1 -1
  4. package/base/index.d.ts +8 -4
  5. package/base/index.iife.js +1 -1
  6. package/base/index.js +28 -5
  7. package/breakpoint/define.iife.js +1 -1
  8. package/breakpoint/index.iife.js +1 -1
  9. package/contextmenu/define.iife.js +1 -1
  10. package/contextmenu/index.iife.js +1 -1
  11. package/copy/define.iife.js +1 -1
  12. package/copy/index.iife.js +1 -1
  13. package/define/index.iife.js +9 -9
  14. package/details/define.iife.js +1 -1
  15. package/details/index.iife.js +1 -1
  16. package/dialog/define.iife.js +1 -1
  17. package/dialog/index.iife.js +1 -1
  18. package/editor/define.iife.js +4 -4
  19. package/editor/index.iife.js +5 -5
  20. package/fullscreen/define.iife.js +1 -1
  21. package/fullscreen/index.iife.js +1 -1
  22. package/fullscreen/index.js +2 -1
  23. package/index.d.ts +3 -1
  24. package/index.iife.js +9 -9
  25. package/index.js +3 -1
  26. package/package.json +19 -1
  27. package/popover/define.iife.js +1 -1
  28. package/popover/index.iife.js +1 -1
  29. package/prefetch/define.d.ts +1 -0
  30. package/prefetch/define.iife.js +1 -0
  31. package/prefetch/define.js +2 -0
  32. package/prefetch/index.d.ts +80 -0
  33. package/prefetch/index.iife.js +1 -0
  34. package/prefetch/index.js +164 -0
  35. package/share/define.iife.js +1 -1
  36. package/share/index.iife.js +1 -1
  37. package/tablesort/define.iife.js +1 -1
  38. package/tablesort/index.iife.js +1 -1
  39. package/wakelock/define.d.ts +1 -0
  40. package/wakelock/define.iife.js +1 -0
  41. package/wakelock/define.js +2 -0
  42. package/wakelock/index.d.ts +32 -0
  43. package/wakelock/index.iife.js +1 -0
  44. package/wakelock/index.js +88 -0
  45. package/youtube/define.iife.js +1 -1
  46. package/youtube/index.iife.js +1 -1
@@ -0,0 +1,88 @@
1
+ import { Base } from "../base/index.js";
2
+ /**
3
+ * `WakeLock` uses the [WakeLock API](https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API) to ensure the screen does not turn off when viewing the page on supported devices. Use your best judgement for when this is necessary, for example, if you have a timer that needs to stay on, or you are displaying a QR code.
4
+ *
5
+ * - WakeLock can be toggled with a `trigger`, or will be requested if the element has a `locked` attribute when connected.
6
+ * - Use `content` and `swap` elements to adjust the UI based on the current state.
7
+ * - `request` and `release` methods are provided to set the WakeLock with JavaScript.
8
+ * - `trigger` is disabled if not supported.
9
+ * - WakeLock is released when the element is removed from the DOM.
10
+ *
11
+ * `auto-lock`
12
+ *
13
+ * - By default, the WakeLock will be released when the tab is not active. Use the `auto-lock` attribute to automatically request the WakeLock when the user views the tab again.
14
+ *
15
+ *
16
+ */
17
+ export class WakeLock extends Base {
18
+ wakeLock = null;
19
+ constructor() {
20
+ super();
21
+ }
22
+ /** If the WakeLock API is supported on the user's device. */
23
+ #wakeLockSupported() {
24
+ return "wakeLock" in navigator;
25
+ }
26
+ /**
27
+ * the `auto-lock` attribute controls whether an active WakeLock should be restored when navigating back to the page.
28
+ */
29
+ get #autoLock() {
30
+ return this.hasAttribute("auto-lock");
31
+ }
32
+ /** Requests WakeLock on the current page. */
33
+ async request() {
34
+ if (this.#wakeLockSupported() && document.visibilityState === "visible") {
35
+ this.wakeLock = await navigator.wakeLock.request("screen");
36
+ this.setAttribute("locked", "");
37
+ this.swapContent(false);
38
+ this.wakeLock.addEventListener("release", () => {
39
+ this.removeAttribute("locked");
40
+ this.swapContent(false);
41
+ if (!this.#autoLock) {
42
+ // set to null is required, used to determine if screen should be
43
+ // locked again, see visibilitychange listener
44
+ this.wakeLock = null;
45
+ }
46
+ });
47
+ }
48
+ }
49
+ /** Releases the WakeLock, sets `this.wakeLock` to null. */
50
+ async release() {
51
+ await this.wakeLock?.release();
52
+ this.wakeLock = null;
53
+ }
54
+ mount() {
55
+ // lock on mount if the `locked` attribute is present
56
+ if (this.hasAttribute("locked")) {
57
+ this.request();
58
+ }
59
+ this.triggerListener(() => {
60
+ // toggle
61
+ if (this.wakeLock) {
62
+ this.release();
63
+ }
64
+ else {
65
+ this.request();
66
+ }
67
+ });
68
+ for (const trigger of this.getTrigger()) {
69
+ if (!this.#wakeLockSupported() && "disabled" in trigger) {
70
+ // disable `trigger` if not supported
71
+ trigger.disabled = true;
72
+ }
73
+ }
74
+ if (this.#autoLock) {
75
+ this.safeListener("visibilitychange", () => {
76
+ // When the tab is not visible, the wakeLock is automatically released.
77
+ // This requests it back if it exists, if it is `null`, that
78
+ // means it was removed. In which case, it shouldn't be requested again.
79
+ if (this.wakeLock) {
80
+ this.request();
81
+ }
82
+ }, document);
83
+ }
84
+ }
85
+ destroy() {
86
+ this.release();
87
+ }
88
+ }
@@ -1 +1 @@
1
- "use strict";(()=>{var s=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 r=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(r){let n=Array.from(this.getContent().childNodes);r instanceof HTMLTemplateElement?this.getContent().replaceChildren(r.content.cloneNode(!0)):this.getContent().replaceChildren(...r.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...n),e)}}safeListener(t,e,r=document.body,n={}){n.signal=this.#t.signal,r.addEventListener(t,e,n)}triggerListener(t,e=this.event){for(let r of this.getTrigger())r.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var i=class extends s{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":""}`})}};customElements.define("drab-youtube",i);})();
1
+ "use strict";(()=>{var s=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 r=this.querySelector(this.getAttribute("content")??"[data-content]");if(r instanceof t)return r;throw new Error("Content not found")}swapContent(t=!0,r=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let n=Array.from(this.getContent().childNodes),o=[];e instanceof HTMLTemplateElement?(o.push(e.content.cloneNode(!0)),e.content.replaceChildren(...n)):(o.push(...e.childNodes),e.replaceChildren(...n)),this.getContent().replaceChildren(...o),t&&setTimeout(()=>this.swapContent(!1),r)}}safeListener(t,r,e=document.body,n={}){n.signal=this.#t.signal,e.addEventListener(t,r,n)}triggerListener(t,r=this.event){for(let e of this.getTrigger())e.addEventListener(r,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var i=class extends s{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":""}`})}};customElements.define("drab-youtube",i);})();
@@ -1 +1 @@
1
- "use strict";(()=>{var s=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 r=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(r){let n=Array.from(this.getContent().childNodes);r instanceof HTMLTemplateElement?this.getContent().replaceChildren(r.content.cloneNode(!0)):this.getContent().replaceChildren(...r.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...n),e)}}safeListener(t,e,r=document.body,n={}){n.signal=this.#t.signal,r.addEventListener(t,e,n)}triggerListener(t,e=this.event){for(let r of this.getTrigger())r.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var i=class extends s{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};})();
1
+ "use strict";(()=>{var s=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 r=this.querySelector(this.getAttribute("content")??"[data-content]");if(r instanceof t)return r;throw new Error("Content not found")}swapContent(t=!0,r=800){let e=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(e){let n=Array.from(this.getContent().childNodes),i=[];e instanceof HTMLTemplateElement?(i.push(e.content.cloneNode(!0)),e.content.replaceChildren(...n)):(i.push(...e.childNodes),e.replaceChildren(...n)),this.getContent().replaceChildren(...i),t&&setTimeout(()=>this.swapContent(!1),r)}}safeListener(t,r,e=document.body,n={}){n.signal=this.#t.signal,e.addEventListener(t,r,n)}triggerListener(t,r=this.event){for(let e of this.getTrigger())e.addEventListener(r,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}destroy(){}disconnectedCallback(){this.destroy(),this.#t.abort()}};var o=class extends s{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":""}`})}};})();