{"version":3,"sources":["webpack:///./LeLab.Web/src/barba/popstate-trigger.js"],"names":["direction","getIndex","PageState","get","getPreviousIndex","sessionStorage","getItem","parseInt","set","setItem","barba","hooks","page","prevIndex","index","isTriggerBack"],"mappings":"yFAAA,6CAWA,IAAIA,EALwB,EAU5B,SAASC,IACL,MAAyC,iBAA9BC,IAAUC,IAfN,kBAgBJD,IAAUC,IAhBN,kBAkBR,KAMX,SAASC,IACL,OAAIC,eAAeC,QAxBK,2BAyBbC,SAASF,eAAeC,QAzBX,4BA2BjB,KAMQ,OAAfL,KACAC,IAAUM,IAnCK,iBAmCWJ,IAAqBA,IAAqB,EAAI,GAM5EC,eAAeI,QAxCa,0BAwCgBR,KAK5CS,IAAMC,MAAMC,KAAK,KACb,MAAMC,EAAYT,IAClB,IAAIU,EAAQb,IAEE,OAAVa,IACAA,EAAQD,EAAY,GAIpBb,EADc,OAAda,EAlDoB,EAqDfA,EAAYC,EAvDA,EA0DZD,EAAYC,GAzDF,EACK,EA+DxBZ,IAAUM,IAnEK,iBAmEWM,GAC1BT,eAAeI,QAnES,0BAmEoBK,KAMhD,MACMC,EAAgB,KAxEC,IAwEKf","file":"popstate-trigger.dd556509.js","sourcesContent":["import { barba, PageState } from \"barba\"\r\n\r\nconst INDEX_PROP = 'popstate-index'\r\nconst PREVIOUS_INDEX_PROP = 'popstate-previous-index'\r\nconst DIRECTION_FOWARD = 1\r\nconst DIRECTION_BACK = -1\r\nconst DIRECTION_UNDEFINED = 0\r\n\r\n\r\n\r\n// Vars\r\nlet direction = DIRECTION_UNDEFINED\r\n\r\n\r\n\r\n// Get an index for the page history\r\nfunction getIndex() {\r\n if (typeof PageState.get(INDEX_PROP) === \"number\") {\r\n return PageState.get(INDEX_PROP)\r\n }\r\n return null\r\n}\r\n\r\n\r\n\r\n// Get index of the last viewed page\r\nfunction getPreviousIndex() {\r\n if (sessionStorage.getItem(PREVIOUS_INDEX_PROP)) {\r\n return parseInt(sessionStorage.getItem(PREVIOUS_INDEX_PROP))\r\n }\r\n return null\r\n}\r\n\r\n\r\n\r\n// Initialize on page load if no history state\r\nif (getIndex() === null) {\r\n PageState.set(INDEX_PROP, getPreviousIndex() ? getPreviousIndex() + 1 : 0)\r\n}\r\n\r\n\r\n\r\n// On page load, reset last index to current\r\nsessionStorage.setItem(PREVIOUS_INDEX_PROP, getIndex())\r\n\r\n\r\n// Has soon there is a transition started, \r\n// update direction\r\nbarba.hooks.page(() => {\r\n const prevIndex = getPreviousIndex()\r\n let index = getIndex()\r\n\r\n if (index === null) {\r\n index = prevIndex + 1\r\n }\r\n \r\n if (prevIndex === null) {\r\n direction = DIRECTION_UNDEFINED\r\n }\r\n else if (prevIndex < index) {\r\n direction = DIRECTION_FOWARD\r\n }\r\n else if (prevIndex > index) {\r\n direction = DIRECTION_BACK\r\n }\r\n else {\r\n direction = DIRECTION_UNDEFINED\r\n }\r\n\r\n PageState.set(INDEX_PROP, index)\r\n sessionStorage.setItem(PREVIOUS_INDEX_PROP, index)\r\n})\r\n\r\n\r\n\r\n// Export helpers fuction\r\nconst isTriggerFoward = () => direction === DIRECTION_FOWARD\r\nconst isTriggerBack = () => direction === DIRECTION_BACK\r\n\r\nexport { isTriggerFoward, isTriggerBack }\r\nexport default { isTriggerFoward, isTriggerBack }\r\n"],"sourceRoot":""}