INIT
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
export * from "./is-document-visible.svelte.js";
|
||||
+1
@@ -0,0 +1 @@
|
||||
export * from "./is-document-visible.svelte.js";
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { type ConfigurableDocument, type ConfigurableWindow } from "../../internal/configurable-globals.js";
|
||||
export type IsDocumentVisibleOptions = ConfigurableWindow & ConfigurableDocument;
|
||||
/**
|
||||
* Tracks whether the current document is visible (i.e., not hidden).
|
||||
* It listens to the "visibilitychange" event and updates reactively.
|
||||
*
|
||||
* @see {@link https://developer.mozilla.org/docs/Web/API/Document/visibilitychange_event}
|
||||
* @see {@link https://runed.dev/docs/utilities/is-document-visible}
|
||||
*/
|
||||
export declare class IsDocumentVisible {
|
||||
#private;
|
||||
constructor(options?: IsDocumentVisibleOptions);
|
||||
get current(): boolean;
|
||||
}
|
||||
Generated
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
import { defaultWindow, } from "../../internal/configurable-globals.js";
|
||||
import { on } from "svelte/events";
|
||||
/**
|
||||
* Tracks whether the current document is visible (i.e., not hidden).
|
||||
* It listens to the "visibilitychange" event and updates reactively.
|
||||
*
|
||||
* @see {@link https://developer.mozilla.org/docs/Web/API/Document/visibilitychange_event}
|
||||
* @see {@link https://runed.dev/docs/utilities/is-document-visible}
|
||||
*/
|
||||
export class IsDocumentVisible {
|
||||
#visible = $state(false);
|
||||
constructor(options = {}) {
|
||||
const window = options.window ?? defaultWindow;
|
||||
const document = options.document ?? window?.document;
|
||||
this.#visible = document ? !document.hidden : false;
|
||||
$effect(() => {
|
||||
if (!document)
|
||||
return;
|
||||
return on(document, "visibilitychange", () => {
|
||||
this.#visible = !document.hidden;
|
||||
});
|
||||
});
|
||||
}
|
||||
get current() {
|
||||
return this.#visible;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user