mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-03-02 17:21:15 +01:00
1 line
23 KiB
Plaintext
1 line
23 KiB
Plaintext
|
{"version":3,"file":"OtpDisplay-ytUtG8ZN.js","sources":["../../../resources/js/components/TotpLooper.vue","../../../resources/js/components/Dots.vue","../../../resources/js/components/OtpDisplay.vue"],"sourcesContent":["<script setup>\n const props = defineProps({\n step_count: {\n type: Number,\n default: 10\n },\n period : Number,\n generated_at: Number,\n autostart: {\n type: Boolean,\n default: true\n },\n })\n\n const generatedAt = ref(null)\n const remainingTimeout = ref(null)\n const initialStepToNextStepTimeout = ref(null)\n const stepToStepInterval = ref(null)\n const stepIndex = ref(null)\n\n // |<----period p----->|\n // | | |\n // |------- ··· ------------|--------|----------|---------->\n // | | | |\n // unix T0 Tp.start Tgen_at Tp.end\n // | | |\n // elapsedTimeInCurrentPeriod--|<------>| |\n // (in ms) | | |\n // ● ● ● ● ●|● ◌ ◌ ◌ ◌ |\n // | | || |\n // | | |<-------->|--remainingTimeBeforeEndOfPeriod (for remainingTimeout)\n // durationBetweenTwoSteps-->|-|< || \n // (for stepToStepInterval) | | >||<---durationFromInitialToNextStep (for initialStepToNextStepTimeout)\n // |\n // |\n // stepIndex\n\n const elapsedTimeInCurrentPeriod = computed(() => {\n return generatedAt.value % props.period\n })\n\n const remainingTimeBeforeEndOfPeriod = computed(() => {\n return props.period - elapsedTimeInCurrentPeriod.value\n })\n\n const durationBetweenTwoSteps = computed(() => {\n return props.period / props.step_count\n })\n\n const initialStepIndex = computed(() => {\n let relativePosition = (elapsedTimeInCurrentPeriod.value * props.step_count) / props.period\n\n return (Math.floor(relativePosition) + 0)\n })\n\n const emit = defineEmits(['loop-started', 'loop-ended', 'stepped-up'])\n\n /**\n * Starts looping\n */\n const startLoop = (generated_at = null) => {\n clearLooper()\n generatedAt.value = generated_at != null ? generated_at : props.generated_at\n\n emit('loop-started', initialStepIndex.value)\n\n stepIndex.value = initialStepIndex.value\n\n // Main timeout that runs until the end of the period\n remainingTimeout.value = setTimeout(function() {\n clearLooper()\n emit('loop-ended')\n }, remainingTimeBeforeEndOfPeriod.value * 1000);\n\n // During the remainingTimeout countdown we emit an event every durationBetweenTwoSteps seconds,\n // except for the first next dot\n let durationFromInitialToNextStep = (Math.ceil(elapsedTimeInCurrentPeriod.value / durationBetweenTwoSteps.value) * durationBetweenTwoSteps.value) - elapsedTimeInCurrentPeriod.value\n\n initialStepToNextStepTimeout.value = setTimeout(function() {\n if( durationFromInitialToNextStep > 0 ) {\n stepIndex.value += 1\n emit('stepped-up', stepIndex.value)\n }\n stepToStepInterval.value = setInterval(function() {\n stepIndex.value += 1\n emit('stepped-up', stepIndex.value)\n }, durationBetweenTwoSteps.value * 1000)\n }, durationFromInitialToNextStep * 1000)\n }\n\n /**\n * Resets all timers and internal vars\n */\n const clearLooper = () => {\n clearTimeout(remainingTimeout.value)\n clearTimeout(initialStepToNextStepTimeout.value)\n clearInterval(stepToStepInterval.value)\n stepIndex.v
|