-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
153 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script lang="ts" setup> | ||
import { decode } from 'blurhash' | ||
// Props | ||
interface Props { | ||
mode?: string | ||
blurhash?: string | ||
src: string | ||
srcset?: string | ||
} | ||
const props = withDefaults(defineProps<Props>(), { | ||
mode: 'img', | ||
}) | ||
// Refs and state | ||
const placeholderSrc = ref<string>() | ||
const isLoaded = ref(false) | ||
const isImgMode = props.mode === 'img' | ||
const attrs = useAttrs() | ||
const url = computed(() => isLoaded.value || !placeholderSrc.value ? props.src : placeholderSrc.value) | ||
// Utility function for creating a data URL from an array of pixels | ||
function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) { | ||
if (typeof w === 'undefined' || typeof h === 'undefined') | ||
w = h = Math.sqrt(arr.length / 4) | ||
const canvas = document.createElement('canvas') | ||
const ctx = canvas.getContext('2d')! | ||
canvas.width = w | ||
canvas.height = h | ||
const imgData = ctx.createImageData(w, h) | ||
imgData.data.set(arr) | ||
ctx.putImageData(imgData, 0, 0) | ||
return canvas.toDataURL() | ||
} | ||
onMounted(() => { | ||
// Create a temporary image to check when the image has loaded | ||
const img = document.createElement('img') | ||
img.onload = () => { | ||
isLoaded.value = true | ||
} | ||
img.src = props.src | ||
if (props.srcset) | ||
img.srcset = props.srcset | ||
// Fallback to mark as loaded after a timeout in case the image takes too long | ||
setTimeout(() => { | ||
isLoaded.value = true | ||
}, 3000) | ||
// Decode the blurhash if available | ||
if (props.blurhash) { | ||
const pixels = decode(props.blurhash, 32, 32) | ||
placeholderSrc.value = getDataUrlFromArr(pixels, 32, 32) | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<img v-if="isImgMode" v-bind="attrs" :src="url" :srcset> | ||
<div v-else v-bind="attrs" :style="{ backgroundImage: `url(${url})`, backgroundSize: 'cover' }" /> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts" setup> | ||
</script> | ||
|
||
<template> | ||
<div> | ||
222 | ||
</div> | ||
</template> | ||
|
||
<style> | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts" setup> | ||
</script> | ||
|
||
<template> | ||
<div> | ||
11 | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
// import { OctokitCtx } from '../constants' | ||
|
||
import type { User } from '~/types' | ||
import { useOctokit } from '../utils/github' | ||
|
||
export default defineEventHandler(async () => { | ||
// const { | ||
// data, | ||
// } = await OctokitCtx.rest.users.getAuthenticated() | ||
|
||
// return data | ||
|
||
if (import.meta.dev) | ||
return (await import('~/mock/user.json')).default as User | ||
|
||
return $fetch<User>('https://api.github.com/users/zyyv') | ||
const { data } = await useOctokit().request('GET /user') | ||
return data | ||
}) |
Oops, something went wrong.