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EAAaS,YAAYa,gBAAgB,EAC3E,IAAIM,EAAgB,GAEpB,GAAIxD,OAAO+B,aAAaD,aAAeL,IACrCC,EAAa,EACT6B,GAAqB,CACvB,MAAMN,EAAOM,EAAoBJ,OAAO,EAAEC,KAAKH,KAC/B9D,KAAKC,MAAM4B,SAASC,cAAc,UAAU,EAAEkB,KAAK,EAEvDxC,SAASsD,CAAI,IACvBO,EAAgB,GAEpB,CAEFF,EAAOG,QAAUD,CACnB,CAAC,EAED,GAAI,kBAAmB7C,UAAW,CAChC,MAAM2C,EAAStC,SAAS0C,eAAe,0BAA0B,EAEjE,GAAIJ,EAAQ,CACV,MAAM1B,EAAe,MAAMjB,UAAUC,cAAc+C,MAEnDN,EAAezB,EAAc0B,CAAM,EAEnCA,EAAOrD,iBAAiB,SAAiB2D,GAAetD,EAAA,MAAfsD,CAAA,EAAe,UAAf,CAAEC,OAAAA,CAAO,EAAM,CAClDA,EAAOJ,QACT,MAAM9B,EAAyBC,CAAY,EAE3C,MAAMoB,EAA6BpB,CAAY,CAEnD,CAAC,EACH,CACF,CACF,CAAC,E,GCrFGkC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,EAAU,CAEtC,IAAIC,EAAeH,EAAyBE,CAAQ,EACpD,GAAIC,IAAiB,OACpB,OAAOA,EAAa,QAGrB,IAAIC,EAASJ,EAAyBE,CAAQ,EAAI,CAGjD,QAAS,CAAC,CACX,EAGA,OAAAG,EAAoBH,CAAQ,EAAE,KAAKE,EAAO,QAASA,EAAQA,EAAO,QAASH,CAAmB,EAGvFG,EAAO,OACf,C","sources":["webpack://metadecidim/./vendor/bundle/ruby/3.2.0/gems/decidim-core-0.29.2/app/packs/src/decidim/sw/a2hs.js","webpack://metadecidim/./vendor/bundle/ruby/3.2.0/gems/decidim-core-0.29.2/app/packs/src/decidim/sw/loader.js","webpack://metadecidim/./vendor/bundle/ruby/3.2.0/gems/decidim-core-0.29.2/app/packs/src/decidim/sw/push-permissions.js","webpack://metadecidim/webpack/bootstrap"],"sourcesContent":["const visitedPages = JSON.parse(sessionStorage.getItem(\"visitedPages\")) || []\nconst DELAYED_VISITS = 2\nlet deferredPrompt = null\n\nconst shouldCountVisitedPages = () => sessionStorage.getItem(\"userChoice\") !== \"dismissed\" && visitedPages.length < DELAYED_VISITS && !visitedPages.includes(location.pathname)\nconst shouldPrompt = () => {\n // Disable the application install prompt showing constantly.\n if (localStorage.getItem(\"pwaInstallPromptSeen\")) {\n return false\n }\n\n return deferredPrompt && sessionStorage.getItem(\"userChoice\") !== \"dismissed\" && visitedPages.length >= DELAYED_VISITS\n}\n\nwindow.addEventListener(\"beforeinstallprompt\", (event) => {\n event.preventDefault()\n deferredPrompt = event\n\n // allow the user browse through different locations before prompt them anything\n if (shouldCountVisitedPages()) {\n sessionStorage.setItem(\"visitedPages\", JSON.stringify([...visitedPages, location.pathname]))\n }\n});\n\n// to trigger the prompt, it must be a \"user gesture\"\nwindow.addEventListener(\"click\", async (event) => {\n if (shouldPrompt()) {\n event.preventDefault()\n deferredPrompt.prompt()\n\n const { outcome } = await deferredPrompt.userChoice;\n // store the user choice to avoid asking again in the current session\n sessionStorage.setItem(\"userChoice\", outcome)\n sessionStorage.removeItem(\"visitedPages\")\n localStorage.setItem(\"pwaInstallPromptSeen\", true)\n }\n});\n","// check if the browser supports serviceWorker at all\nwindow.addEventListener(\"load\", async () => {\n if (\"serviceWorker\" in navigator) {\n await navigator.serviceWorker.register(\"/sw.js\", { scope: \"/\" });\n\n const mandatoryElements = document.querySelector(\".js-sw-mandatory\");\n // Opera uses Opera for versions <= 12 and OPR for versions > 12\n const isOperaMini =\n ((navigator.userAgent.indexOf(\"OPR\") > -1) || (navigator.userAgent.indexOf(\"Opera\") > -1)) &&\n (navigator.userAgent.indexOf(\"Mini\") > -1);\n\n if (mandatoryElements && isOperaMini) {\n mandatoryElements.classList.add(\"hide\")\n }\n } else {\n console.log(\"Your browser does not support service workers 🤷‍♀️\");\n }\n});\n","window.addEventListener(\"DOMContentLoaded\", async () => {\n const GRANTED_PERMISSION = \"granted\"\n\n const hideReminder = function() {\n const reminder = document.querySelector(\"#push-notifications-reminder\")\n reminder.classList.add(\"hide\")\n }\n\n const subscribeToNotifications = async (registration) => {\n const permission = await window.Notification.requestPermission();\n\n if (registration && permission === GRANTED_PERMISSION) {\n const vapidElement = document.querySelector(\"#vapidPublicKey\")\n // element could not exist in DOM\n if (vapidElement) {\n const vapidPublicKeyElement = JSON.parse(vapidElement.value)\n const subscription = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: new Uint8Array(vapidPublicKeyElement)\n });\n\n if (subscription) {\n await fetch(\"/notifications_subscriptions\", {\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-CSRF-Token\": document.querySelector(\"meta[name=csrf-token]\")?.content\n },\n method: \"POST\",\n body: JSON.stringify(subscription)\n });\n }\n }\n hideReminder()\n } else {\n throw new Error(\"Permission not granted for Notification\");\n }\n }\n\n const unsubscribeFromNotifications = async (registration) => {\n /* eslint-disable no-shadow */\n const currentSubscription = await registration.pushManager.getSubscription()\n const auth = currentSubscription.toJSON().keys.auth\n await fetch(`/notifications_subscriptions/${auth}`, {\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-CSRF-Token\": document.querySelector(\"meta[name=csrf-token]\")?.content\n },\n method: \"DELETE\"\n });\n }\n\n const setToggleState = async (registration, toggle) => {\n const currentSubscription = await registration.pushManager.getSubscription()\n let toggleChecked = false\n\n if (window.Notification.permission === GRANTED_PERMISSION) {\n hideReminder()\n if (currentSubscription) {\n const auth = currentSubscription.toJSON().keys.auth\n const subKeys = JSON.parse(document.querySelector(\"#subKeys\").value)\n // Subscribed && browser notifications enabled\n if (subKeys.includes(auth)) {\n toggleChecked = true\n }\n }\n }\n toggle.checked = toggleChecked\n }\n\n if (\"serviceWorker\" in navigator) {\n const toggle = document.getElementById(\"allow_push_notifications\")\n\n if (toggle) {\n const registration = await navigator.serviceWorker.ready\n\n setToggleState(registration, toggle)\n\n toggle.addEventListener(\"change\", async ({ target }) => {\n if (target.checked) {\n await subscribeToNotifications(registration);\n } else {\n await unsubscribeFromNotifications(registration)\n }\n })\n }\n }\n});\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n"],"names":["visitedPages","JSON","parse","sessionStorage","getItem","DELAYED_VISITS","deferredPrompt","shouldCountVisitedPages","length","includes","location","pathname","shouldPrompt","localStorage","window","addEventListener","event","preventDefault","setItem","stringify","__async","prompt","outcome","userChoice","removeItem","navigator","serviceWorker","register","scope","mandatoryElements","document","querySelector","isOperaMini","userAgent","indexOf","classList","add","console","log","GRANTED_PERMISSION","hideReminder","subscribeToNotifications","registration","_a","permission","Notification","requestPermission","vapidElement","vapidPublicKeyElement","value","subscription","pushManager","subscribe","userVisibleOnly","applicationServerKey","Uint8Array","fetch","headers","content","method","body","Error","unsubscribeFromNotifications","auth","getSubscription","toJSON","keys","setToggleState","toggle","currentSubscription","toggleChecked","checked","getElementById","ready","_0","target","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","module","__webpack_modules__"],"sourceRoot":""}