diff --git a/docs/.vitepress/composables/state.js b/docs/.vitepress/composables/state.js index 23bb3df..b570e4b 100644 --- a/docs/.vitepress/composables/state.js +++ b/docs/.vitepress/composables/state.js @@ -1,6 +1,6 @@ import { reactive, computed, toRef, onMounted } from "vue"; -import { useRefHistory } from '@vueuse/core' +import { useRefHistory, useIntervalFn } from '@vueuse/core' export const state = reactive({ @@ -22,7 +22,6 @@ export const state = reactive({ loop: 0, setPair(pair) { state.pair = pair - clearInterval(state.loop) } }) @@ -38,7 +37,7 @@ export function useState() { }) }) onMounted(() => { - state.loop = setInterval(() => { + state.loop = useIntervalFn(() => { state.generatePair() }, 2000) }) diff --git a/src/main.ts b/src/main.ts index 95c1d19..963b009 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,3 @@ - - const cache = {}; // stores already generated avatars export interface AvatarOptions { @@ -63,7 +61,7 @@ export function gunAvatar({ // FUNCTIONS -function parsePub(pub: string) { +export function parsePub(pub: string) { const split = pub.split("."); const decoded = split.map((single) => decodeUrlSafeBase64(single)); return { @@ -73,7 +71,7 @@ function parsePub(pub: string) { } } -function validatePub(pub: string): boolean { +export function validatePub(pub: string): boolean { if ( pub && typeof pub == 'string' @@ -86,6 +84,23 @@ function validatePub(pub: string): boolean { } } +export function decodeUrlSafeBase64(st: string): number[] { + const symbols = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + const symbolArray = symbols.split(""); + let arr = []; + let i = 0; + for (let letter of st) { + arr[i++] = symbolArray.indexOf(letter) / 64; + } + return arr; +} + +export function chunkIt(list: number[], chunkSize = 3) { + return [...Array(Math.ceil(list.length / chunkSize))].map(() => + list.splice(0, chunkSize) + ); +} function drawGradient( { @@ -166,22 +181,4 @@ function drawCircles(data: number[], ctx: CanvasRenderingContext2D, size: number ctx.fill(); } }); -} - -function decodeUrlSafeBase64(st: string): number[] { - const symbols = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - const symbolArray = symbols.split(""); - let arr = []; - let i = 0; - for (let letter of st) { - arr[i++] = symbolArray.indexOf(letter) / 64; - } - return arr; -} - -function chunkIt(list: number[], chunkSize = 3) { - return [...Array(Math.ceil(list.length / chunkSize))].map(() => - list.splice(0, chunkSize) - ); } \ No newline at end of file