@yorkjs/web-page
Advanced tools
Comparing version 0.0.5 to 0.0.6
/** | ||
* web-page.js v0.0.5 | ||
* web-page.js v0.0.6 | ||
* (c) 2021-2022 musicode | ||
@@ -12,4 +12,4 @@ * Released under the MIT License. | ||
let isInitCalled = false; | ||
let isPageAlive = false; | ||
let isPageFrozen = false; | ||
let visible; | ||
@@ -50,3 +50,3 @@ let persisted; | ||
events[type] = data; | ||
if (isInitCalled && isPageAlive) { | ||
if (isPageAlive && !isPageFrozen) { | ||
fireEventData(type, data); | ||
@@ -100,10 +100,12 @@ } | ||
} | ||
// @ts-ignore | ||
persisted = event.persisted === true; | ||
fireEvent(LEAVE, event); | ||
isPageAlive = false; | ||
}, 200); | ||
function onPageFreeze() { | ||
isPageFrozen = true; | ||
} | ||
function onPageResume() { | ||
isPageFrozen = false; | ||
} | ||
function init() { | ||
isInitCalled = true; | ||
updateVisible(); | ||
} | ||
@@ -126,2 +128,3 @@ function addEventListener(type, listener) { | ||
} | ||
updateVisible(); | ||
if (supportEvent(document, 'visibilitychange')) { | ||
@@ -138,2 +141,8 @@ addDOMEventListener(document, 'visibilitychange', onVisibilityChange); | ||
addDOMEventListener(window, 'beforeunload', onPageLeave); | ||
if (supportEvent(window, 'freeze')) { | ||
addDOMEventListener(window, 'freeze', onPageFreeze); | ||
} | ||
if (supportEvent(window, 'resume')) { | ||
addDOMEventListener(window, 'resume', onPageResume); | ||
} | ||
@@ -143,5 +152,5 @@ /** | ||
*/ | ||
const version = "0.0.5"; | ||
const version = "0.0.6"; | ||
export { ENTER, HIDE, LEAVE, SHOW, addEventListener, init, version }; | ||
//# sourceMappingURL=web-page.esm.js.map |
@@ -1,2 +0,2 @@ | ||
const n="show",e="hide",t="enter",i="leave";let o,c,s=!1,d=!1;const u={},r={};function a(n,e){return`on${e}`in n}function f(n,e,t){n.addEventListener?n.addEventListener(e,t,!0):n.attachEvent&&n.attachEvent("on"+e,t)}function h(n,e){let t;return function(){t||(n(arguments[0]),t=setTimeout((function(){t=void 0}),e))}}function l(n,e){const t={event:e,visible:o,persisted:c};u[n]=t,s&&d&&w(n,t)}function w(n,e){const t=r[n];if(t)for(let n=0,i=t.length;n<i;n++)t[n]&&t[n](e)}function v(){const n=document.visibilityState;o="visible"===n||"hidden"!==n&&void 0}const p=h((function(n){d||(d=!0,c=!0===n.persisted,l("enter",n))}),200),g=h((function(n){d&&(c=!0===n.persisted,l("leave",n),d=!1)}),200);function b(){s=!0,v()}function m(n,e){const t=r[n]||(r[n]=[]);return t.push(e),"enter"===n&&u[n]&&w(n,u[n]),{remove(){for(let n=0,i=t.length;n<i;n++)t[n]===e&&t.splice(n,1)}}}a(document,"visibilitychange")&&f(document,"visibilitychange",(function(n){v(),!0===o?l("show",n):!1===o&&l("hide",n)})),a(window,"pageshow")&&f(window,"pageshow",p),f(window,"load",p),a(window,"pagehide")&&f(window,"pagehide",g),f(window,"beforeunload",g);const E="0.0.5";export{t as ENTER,e as HIDE,i as LEAVE,n as SHOW,m as addEventListener,b as init,E as version}; | ||
const n="show",e="hide",t="enter",i="leave";let o,c,d=!1,s=!1;const u={},w={};function r(n,e){return`on${e}`in n}function f(n,e,t){n.addEventListener?n.addEventListener(e,t,!0):n.attachEvent&&n.attachEvent("on"+e,t)}function a(n,e){let t;return function(){t||(n(arguments[0]),t=setTimeout((function(){t=void 0}),e))}}function h(n,e){const t={event:e,visible:o,persisted:c};u[n]=t,d&&!s&&l(n,t)}function l(n,e){const t=w[n];if(t)for(let n=0,i=t.length;n<i;n++)t[n]&&t[n](e)}function v(){const n=document.visibilityState;o="visible"===n||"hidden"!==n&&void 0}const p=a((function(n){d||(d=!0,c=!0===n.persisted,h("enter",n))}),200),g=a((function(n){d&&(h("leave",n),d=!1)}),200);function m(){}function b(n,e){const t=w[n]||(w[n]=[]);return t.push(e),"enter"===n&&u[n]&&l(n,u[n]),{remove(){for(let n=0,i=t.length;n<i;n++)t[n]===e&&t.splice(n,1)}}}v(),r(document,"visibilitychange")&&f(document,"visibilitychange",(function(n){v(),!0===o?h("show",n):!1===o&&h("hide",n)})),r(window,"pageshow")&&f(window,"pageshow",p),f(window,"load",p),r(window,"pagehide")&&f(window,"pagehide",g),f(window,"beforeunload",g),r(window,"freeze")&&f(window,"freeze",(function(){s=!0})),r(window,"resume")&&f(window,"resume",(function(){s=!1}));const E="0.0.6";export{t as ENTER,e as HIDE,i as LEAVE,n as SHOW,b as addEventListener,m as init,E as version}; | ||
//# sourceMappingURL=web-page.esm.min.js.map |
/** | ||
* web-page.js v0.0.5 | ||
* web-page.js v0.0.6 | ||
* (c) 2021-2022 musicode | ||
@@ -18,4 +18,4 @@ * Released under the MIT License. | ||
var isInitCalled = false; | ||
var isPageAlive = false; | ||
var isPageFrozen = false; | ||
var visible; | ||
@@ -56,3 +56,3 @@ var persisted; | ||
events[type] = data; | ||
if (isInitCalled && isPageAlive) { | ||
if (isPageAlive && !isPageFrozen) { | ||
fireEventData(type, data); | ||
@@ -106,10 +106,12 @@ } | ||
} | ||
// @ts-ignore | ||
persisted = event.persisted === true; | ||
fireEvent(LEAVE, event); | ||
isPageAlive = false; | ||
}, 200); | ||
function onPageFreeze() { | ||
isPageFrozen = true; | ||
} | ||
function onPageResume() { | ||
isPageFrozen = false; | ||
} | ||
function init() { | ||
isInitCalled = true; | ||
updateVisible(); | ||
} | ||
@@ -132,2 +134,3 @@ function addEventListener(type, listener) { | ||
} | ||
updateVisible(); | ||
if (supportEvent(document, 'visibilitychange')) { | ||
@@ -144,2 +147,8 @@ addDOMEventListener(document, 'visibilitychange', onVisibilityChange); | ||
addDOMEventListener(window, 'beforeunload', onPageLeave); | ||
if (supportEvent(window, 'freeze')) { | ||
addDOMEventListener(window, 'freeze', onPageFreeze); | ||
} | ||
if (supportEvent(window, 'resume')) { | ||
addDOMEventListener(window, 'resume', onPageResume); | ||
} | ||
@@ -149,3 +158,3 @@ /** | ||
*/ | ||
var version = "0.0.5"; | ||
var version = "0.0.6"; | ||
@@ -152,0 +161,0 @@ exports.ENTER = ENTER; |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).WebPage={})}(this,(function(e){"use strict";var n,i,t="show",o="hide",d="enter",r="leave",f=!1,u=!1,a={},s={};function c(e,n){return"on"+n in e}function v(e,n,i){e.addEventListener?e.addEventListener(n,i,!0):e.attachEvent&&e.attachEvent("on"+n,i)}function l(e,n){var i;return function(){i||(e(arguments[0]),i=setTimeout((function(){i=void 0}),n))}}function h(e,t){var o={event:t,visible:n,persisted:i};a[e]=o,f&&u&&p(e,o)}function p(e,n){var i=s[e];if(i)for(var t=0,o=i.length;t<o;t++)i[t]&&i[t](n)}function w(){var e=document.visibilityState;n="visible"===e||"hidden"!==e&&void 0}var b=l((function(e){u||(u=!0,i=!0===e.persisted,h(d,e))}),200),g=l((function(e){u&&(i=!0===e.persisted,h(r,e),u=!1)}),200);c(document,"visibilitychange")&&v(document,"visibilitychange",(function(e){w(),!0===n?h(t,e):!1===n&&h(o,e)})),c(window,"pageshow")&&v(window,"pageshow",b),v(window,"load",b),c(window,"pagehide")&&v(window,"pagehide",g),v(window,"beforeunload",g);e.ENTER=d,e.HIDE=o,e.LEAVE=r,e.SHOW=t,e.addEventListener=function(e,n){var i=s[e]||(s[e]=[]);return i.push(n),e===d&&a[e]&&p(e,a[e]),{remove:function(){for(var e=0,t=i.length;e<t;e++)i[e]===n&&i.splice(e,1)}}},e.init=function(){f=!0,w()},e.version="0.0.5",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).WebPage={})}(this,(function(e){"use strict";var n,i,t="show",o="hide",d="enter",f="leave",r=!1,u=!1,a={},s={};function c(e,n){return"on"+n in e}function v(e,n,i){e.addEventListener?e.addEventListener(n,i,!0):e.attachEvent&&e.attachEvent("on"+n,i)}function w(e,n){var i;return function(){i||(e(arguments[0]),i=setTimeout((function(){i=void 0}),n))}}function l(e,t){var o={event:t,visible:n,persisted:i};a[e]=o,r&&!u&&h(e,o)}function h(e,n){var i=s[e];if(i)for(var t=0,o=i.length;t<o;t++)i[t]&&i[t](n)}function p(){var e=document.visibilityState;n="visible"===e||"hidden"!==e&&void 0}var b=w((function(e){r||(r=!0,i=!0===e.persisted,l(d,e))}),200),g=w((function(e){r&&(l(f,e),r=!1)}),200);p(),c(document,"visibilitychange")&&v(document,"visibilitychange",(function(e){p(),!0===n?l(t,e):!1===n&&l(o,e)})),c(window,"pageshow")&&v(window,"pageshow",b),v(window,"load",b),c(window,"pagehide")&&v(window,"pagehide",g),v(window,"beforeunload",g),c(window,"freeze")&&v(window,"freeze",(function(){u=!0})),c(window,"resume")&&v(window,"resume",(function(){u=!1}));e.ENTER=d,e.HIDE=o,e.LEAVE=f,e.SHOW=t,e.addEventListener=function(e,n){var i=s[e]||(s[e]=[]);return i.push(n),e===d&&a[e]&&h(e,a[e]),{remove:function(){for(var e=0,t=i.length;e<t;e++)i[e]===n&&i.splice(e,1)}}},e.init=function(){},e.version="0.0.6",Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=web-page.min.js.map |
{ | ||
"name": "@yorkjs/web-page", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "web page life cycle", | ||
@@ -5,0 +5,0 @@ "main": "dist/web-page.js", |
@@ -6,2 +6,2 @@ export { SHOW, HIDE, ENTER, LEAVE, } from './constant'; | ||
*/ | ||
export declare const version = "0.0.5"; | ||
export declare const version = "0.0.6"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14958
333