@zodash/dom
Advanced tools
Comparing version 0.1.19 to 0.1.20
@@ -6,2 +6,10 @@ # Change Log | ||
## [0.1.20](https://github.com/zcorky/zodash/compare/@zodash/dom@0.1.19...@zodash/dom@0.1.20) (2022-09-29) | ||
**Note:** Version bump only for package @zodash/dom | ||
## [0.1.19](https://github.com/zcorky/zodash/compare/@zodash/dom@0.1.18...@zodash/dom@0.1.19) (2022-09-04) | ||
@@ -8,0 +16,0 @@ |
@@ -5,4 +5,5 @@ import { Unsubscibe } from './types'; | ||
export declare function isPageVisible(): boolean; | ||
export declare function onVisibleChange(callback: (visible: boolean) => void): () => void; | ||
export declare const onShow: typeof onPageShow; | ||
export declare const onHide: typeof onPageHide; | ||
export declare const isVisible: typeof isPageVisible; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isVisible = exports.onHide = exports.onShow = exports.isPageVisible = exports.onPageHide = exports.onPageShow = void 0; | ||
exports.isVisible = exports.onHide = exports.onShow = exports.onVisibleChange = exports.isPageVisible = exports.onPageHide = exports.onPageShow = void 0; | ||
function onPageShow(cb) { | ||
const handler = () => { | ||
if (document.visibilityState === 'visible') { | ||
return cb && cb(); | ||
return onVisibleChange((visible) => { | ||
if (!!visible) { | ||
return cb === null || cb === void 0 ? void 0 : cb(); | ||
} | ||
}; | ||
document.addEventListener('visibilitychange', handler); | ||
return () => { | ||
document.removeEventListener('visibilitychange', handler); | ||
}; | ||
}); | ||
} | ||
exports.onPageShow = onPageShow; | ||
function onPageHide(cb) { | ||
return onVisibleChange((visible) => { | ||
if (!visible) { | ||
return cb === null || cb === void 0 ? void 0 : cb(); | ||
} | ||
}); | ||
} | ||
exports.onPageHide = onPageHide; | ||
function isPageVisible() { | ||
return document.visibilityState === 'visible' || !document.hidden; | ||
} | ||
exports.isPageVisible = isPageVisible; | ||
function onVisibleChange(callback) { | ||
const handler = () => { | ||
if (document.visibilityState === 'hidden') { | ||
return cb && cb(); | ||
} | ||
callback === null || callback === void 0 ? void 0 : callback(isPageVisible()); | ||
}; | ||
@@ -27,7 +33,3 @@ document.addEventListener('visibilitychange', handler); | ||
} | ||
exports.onPageHide = onPageHide; | ||
function isPageVisible() { | ||
return document.visibilityState === 'visible' || !document.hidden; | ||
} | ||
exports.isPageVisible = isPageVisible; | ||
exports.onVisibleChange = onVisibleChange; | ||
// alias | ||
@@ -34,0 +36,0 @@ exports.onShow = onPageShow; |
{ | ||
"name": "@zodash/dom", | ||
"version": "0.1.19", | ||
"version": "0.1.20", | ||
"description": "DOM Utils", | ||
@@ -78,3 +78,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a40d51eb88772d0265808e9deef01f821c76e262" | ||
"gitHead": "73166585f7ca0a376be2ac042da5a56369e53ede" | ||
} |
20657
379