forked from Kholid060/inspect-css
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditPalette.vue
More file actions
84 lines (74 loc) · 2.3 KB
/
EditPalette.vue
File metadata and controls
84 lines (74 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<div class="website-palettes px-4">
<div class="text-center" v-if="state.loading">
<ui-spinner size="32" class="my-4"></ui-spinner>
<p class="text-gray-300">
Extracting Colors...
</p>
</div>
<template v-else>
<div class="mb-4 flex items-center">
<p class="flex-1">Website Color Palettes</p>
<button title="Refresh" @click="getColorPalettes(true)">
<ui-icon name="restart" size="20"></ui-icon>
</button>
</div>
<div class="content gap-2 grid grid-cols-2">
<div
v-for="(color, index) in state.palette"
:key="color"
class="h-32 flex items-center rounded-lg justify-center cursor-pointer flex-col color-card"
:style="{ backgroundColor: color.hex }"
@click="copyColor(color.hex, index)"
>
<p class="color-card__text uppercase leading-none" :style="{ color: color.title }">
{{ color.hex }}
</p>
<p class="color-card__copy-text text-sm invisible opacity-0" :style="{ color: color.title }">
{{ color.copied ? 'copied' : 'Copy color' }}
</p>
</div>
</div>
</template>
</div>
</template>
<script>
import { reactive, onMounted } from 'vue';
import extractColors from '@/utils/extractColors';
import { copyToClipboard } from '@/utils/helper';
import screenshot from '@/utils/screenshot';
export default {
setup() {
const state = reactive({
palette: [],
loading: false,
});
async function getColorPalettes(refresh) {
state.loading = true;
const paletteFromSession = JSON.parse(sessionStorage.getItem('color-palettes'));
if (paletteFromSession && !refresh) {
state.palette = paletteFromSession || [];
state.loading = false;
return;
}
const image = await screenshot.captureAll();
const palettes = await extractColors(image);
state.palette = palettes;
state.loading = false;
}
function copyColor(color, index) {
state.palette[index].copied = true;
copyToClipboard(color);
setTimeout(() => {
state.palette[index].copied = false;
}, 1400);
}
onMounted(getColorPalettes);
return {
state,
copyColor,
getColorPalettes,
};
},
};
</script>