{"version":3,"file":"index-B-A0Qe_G.js","sources":["../../../app/javascript/helpers/index.js"],"sourcesContent":["import moment from \"moment\"\nimport momentDurationFormatSetup from \"moment-duration-format\"\n\nmomentDurationFormatSetup(moment)\n\n\nconst helpers = {\n\n /**\n * Dorian - 2024-05-13\n * Use useDocumentVisibility (vueUse) instead\n */\n onVisibilitySwitch(onVisible = null, onHidden = null, disable = false) {\n // Set the name of the hidden property and the change event for visibility\n let hidden, visibilityChange\n if (typeof document.hidden !== \"undefined\") { // Opera 12.10 and Firefox 18 and later support\n hidden = \"hidden\"\n visibilityChange = \"visibilitychange\"\n } else if (typeof document.msHidden !== \"undefined\") {\n hidden = \"msHidden\"\n visibilityChange = \"msvisibilitychange\"\n } else if (typeof document.webkitHidden !== \"undefined\") {\n hidden = \"webkitHidden\"\n visibilityChange = \"webkitvisibilitychange\"\n }\n\n function handleVisibilityChange() {\n if (document[hidden]) {\n if(onHidden) onHidden()\n } else {\n if(onVisible) onVisible()\n }\n }\n\n disable ?\n document.removeEventListener(visibilityChange, handleVisibilityChange, false) :\n document.addEventListener( visibilityChange, handleVisibilityChange, false)\n },\n\n\n nameForScan(scan) {\n return scan?.user_name || \"Étudiant non trouvé\"\n },\n\n goToQuizEditor(quiz, router) {\n router.push({\n name: \"quizEditor\",\n params: { quizId: quiz.id },\n })\n },\n\n quizDuration(quiz) {\n return moment\n .duration(quiz.time_limit, \"seconds\")\n .format(\"H[h] m[min]\", { trunc: true })\n },\n\n /**\n * @params {Number} duration\n * @return {String}\n */\n scoreDuration(duration) {\n if(!duration) return \"-\"\n\n return moment\n .duration(new Date(duration * 1000))\n .format(\"H[h] m[min] s[s]\", { trunc: true })\n },\n\n quizDurationPerQuestion(quiz) {\n if(quiz.questions_count === 0) return \"0s 😇\"\n\n return moment\n .duration(quiz.time_limit / quiz.questions_count, \"seconds\")\n .format(\"H[h] m[min] ss[s]\", { trunc: true })\n },\n\n removeHTML(string) {\n if (!string) return \"\"\n\n const regex = /(<([^>]+)>)/ig\n return string.replace(regex, \"\")\n },\n\n emailIsValid (email) {\n email = email.trim()\n return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(email)\n },\n\n isSameDay(date1, date2) {\n const d1 = new Date(date1)\n const d2 = new Date(date2)\n return d1.getFullYear() === d2.getFullYear() &&\n d1.getMonth() === d2.getMonth() &&\n d1.getDate() === d2.getDate()\n },\n\n removeAccents(str) {\n return str.normalize(\"NFD\").replace(/[\\u0300-\\u036f]/g, \"\")\n },\n\n formatForSearch(str) {\n return this.removeAccents(str.toLocaleLowerCase())\n },\n\n isInIframe() {\n try {\n return window.self !== window.top\n } catch (e) {\n return true\n }\n },\n\n}\n\nexport default helpers\n"],"names":["momentDurationFormatSetup","moment","helpers","onVisible","onHidden","disable","hidden","visibilityChange","handleVisibilityChange","scan","quiz","router","duration","string","regex","email","date1","date2","d1","d2","str"],"mappings":"kbAGAA,EAA0BC,CAAM,EAG3B,MAACC,EAAU,CAMd,mBAAmBC,EAAY,KAAMC,EAAW,KAAMC,EAAU,GAAO,CAErE,IAAIC,EAAQC,EACR,OAAO,SAAS,QAAW,aAC7BD,EAAS,SACTC,EAAmB,oBACV,OAAO,SAAS,UAAa,aACtCD,EAAS,WACTC,EAAmB,sBACV,OAAO,SAAS,cAAiB,cAC1CD,EAAS,eACTC,EAAmB,0BAGrB,SAASC,GAAyB,CAC5B,SAASF,CAAM,EACdF,GAAUA,EAAQ,EAElBD,GAAWA,EAAS,CAE/B,CAEIE,EACE,SAAS,oBAAoBE,EAAkBC,EAAwB,EAAK,EAC5E,SAAS,iBAAoBD,EAAkBC,EAAwB,EAAK,CAC/E,EAGD,YAAYC,EAAM,CAChB,OAAOA,GAAA,YAAAA,EAAM,YAAa,qBAC3B,EAED,eAAeC,EAAMC,EAAQ,CAC3BA,EAAO,KAAK,CACV,KAAM,aACN,OAAQ,CAAE,OAAQD,EAAK,EAAI,CAC5B,CAAA,CACF,EAED,aAAaA,EAAM,CACjB,OAAOT,EACJ,SAASS,EA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