Skip to content

Commit

Permalink
feat: init repo
Browse files Browse the repository at this point in the history
  • Loading branch information
haoziqaq committed Feb 27, 2024
1 parent 2852874 commit 1524630
Show file tree
Hide file tree
Showing 46 changed files with 170 additions and 2,351 deletions.
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="./logo.svg" />
<meta
<!-- <link rel="icon" type="image/svg+xml" href="./logo.svg" /> -->
<!-- <meta
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
name="viewport"
/>
<meta name="apple-mobile-web-app-capable" content="yes" />
/> -->
<!-- <meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-capable" content="yes" />
Expand All @@ -16,7 +16,7 @@
<meta property="og:title" content="Varlet,App,Template" />
<meta property="og:type" content="website" />
<meta property="og:image" content="./logo.svg" />
<meta property="og:description" content="A Varlet app template" />
<meta property="og:description" content="A Varlet app template" /> -->
<title>Varlet App Template</title>
</head>

Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "simple-git-hooks",
"dev": "vite",
"dev": "vite --force",
"build": "vite build",
"build:test": "vite build --mode test",
"preview": "vite preview",
Expand All @@ -28,11 +28,12 @@
"*.{vue,ts,tsx,js,jsx}": "pnpm lint"
},
"dependencies": {
"@material/material-color-utilities": "^0.2.7",
"@varlet/axle": "^0.6.0",
"@varlet/bounce-fixer": "^0.0.3",
"@varlet/touch-emulator": "3.0.3",
"@varlet/ui": "3.0.3",
"@varlet/use": "3.0.3",
"@varlet/touch-emulator": "3.0.5",
"@varlet/ui": "3.0.5",
"@varlet/use": "3.0.5",
"@vueuse/core": "^10.5.0",
"dayjs": "^1.11.8",
"mockjs": "^1.1.0",
Expand All @@ -50,7 +51,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.8",
"@typescript-eslint/parser": "^5.59.8",
"@unocss/preset-rem-to-px": "^0.58.2",
"@varlet/import-resolver": "3.0.3",
"@varlet/import-resolver": "3.0.5",
"@vitejs/plugin-vue": "^5.0.0",
"@vitejs/plugin-vue-jsx": "^3.1.0",
"@vitest/coverage-istanbul": "1.1.0",
Expand Down
57 changes: 32 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions postcss.config.js

This file was deleted.

115 changes: 112 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,120 @@
<script setup lang="ts">
import {
Scheme,
argbFromHex,
hexFromArgb,
themeFromSourceColor,
themeFromImage
} from '@material/material-color-utilities'
import { useDark } from './use'
import { useClipboard } from '@vueuse/core'
import { VarFile } from '@varlet/ui'
useDark()
const light = ref<Record<string, string>>()
const dark = ref<Record<string, string>>()
const source = ref('')
const files = ref([])
const image = ref<HTMLImageElement>()
const imageUrl = ref('')
const { copy } = useClipboard({ legacy: true })
const tokenMap = {
surface: '--color-body',
onSurface: '--color-text',
primary: '--color-primary',
secondary: '--color-info',
tertiary: '--color-warning',
error: '--color-danger',
onPrimary: '--color-on-primary',
onSecondary: '--color-on-info',
onTertiary: '--color-on-warning',
onError: '--color-on-danger',
primaryContainer: '--color-primary-container',
secondaryContainer: '--color-info-container',
tertiaryContainer: '--color-warning-container',
errorContainer: '--color-danger-container',
onPrimaryContainer: '--color-on-primary-container',
onSecondaryContainer: '--color-on-info-container',
onTertiaryContainer: '--color-on-warning-container',
onErrorContainer: '--color-on-danger-container',
inverseSurface: '--color-inverse-surface',
outline: '--color-outline',
onSurfaceVariant: '--color-on-surface-variant'
}
watch(() => source.value, generateSchemes)
function toHexScheme(scheme: Scheme) {
return Object.entries(scheme.toJSON()).reduce((scheme, [key, value]) => {
if (key in tokenMap) {
scheme[tokenMap[key as keyof typeof tokenMap]] = hexFromArgb(value)
}
return scheme
}, {} as Record<string, string>)
}
function generateSchemes() {
try {
const theme = themeFromSourceColor(argbFromHex(source.value))
light.value = toHexScheme(theme.schemes.light)
dark.value = toHexScheme(theme.schemes.dark)
} catch (e) {
console.log('Invalid color')
}
}
function copyThemes() {
const themes = {
light: light.value,
dark: dark.value
}
copy(JSON.stringify(themes, null, 2))
Snackbar.success('Themes copied!')
}
async function handleAfterRead(file: VarFile) {
imageUrl.value = file.url!
await nextTick()
const theme = await themeFromImage(image.value!)
light.value = toHexScheme(theme.schemes.light)
dark.value = toHexScheme(theme.schemes.dark)
}
</script>

<template>
<app-mobile-detector>
<router-view />
</app-mobile-detector>
<div class="flex flex-col justify-center items-center min-h-screen p-[24px]">
<var-input class="w-[300px]" placeholder="e.g. #f82506" variant="outlined" v-model.trim="source">
<template #append-icon>
<var-uploader hide-list v-model="files" @after-read="handleAfterRead">
<var-button type="primary">Upload Image</var-button>
</var-uploader>
</template>
</var-input>

<var-button class="mt-[20px]" type="success" v-if="light && dark" @click="copyThemes">Copy Themes</var-button>

<var-paper class="p-[30px] mt-[30px]" :elevation="2" :radius="12" v-if="light">
<div class="text-[22px] pb-[30px] px-[4px]">Light</div>
<var-space :size="[24, 24]">
<div class="flex flex-col items-center w-[50px]" v-for="i in light" :key="i">
<div class="rounded-[50%] w-[40px] h-[40px] mb-[10px]" :style="{ backgroundColor: i }"></div>
<div>{{ i }}</div>
</div>
</var-space>
</var-paper>

<var-paper class="p-[30px] mt-[30px]" :elevation="2" :radius="12" v-if="dark">
<div class="text-[22px] pb-[30px] px-[4px]">Dark</div>
<var-space :size="[24, 24]">
<div class="flex flex-col items-center w-[50px]" v-for="i in dark" :key="i">
<div class="rounded-[50%] w-[40px] h-[40px] mb-[10px]" :style="{ backgroundColor: i }"></div>
<div>{{ i }}</div>
</div>
</var-space>
</var-paper>

<img ref="image" class="opacity-0 fixed left-[-1000px] pointer-events-none" :src="imageUrl" />
</div>
</template>
18 changes: 0 additions & 18 deletions src/apis/card.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/apis/index.ts

This file was deleted.

Binary file removed src/assets/images/avatar.jpg
Binary file not shown.
30 changes: 0 additions & 30 deletions src/assets/images/logo.svg

This file was deleted.

Binary file removed src/assets/images/material-1.png
Binary file not shown.
Binary file removed src/assets/images/material-2.png
Binary file not shown.
Binary file removed src/assets/images/material.jpg
Binary file not shown.
17 changes: 0 additions & 17 deletions src/components/AppBack.vue

This file was deleted.

Loading

0 comments on commit 1524630

Please sign in to comment.