forked from webfansplz/vite-plugin-vue-devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssetDetails.vue
184 lines (170 loc) · 4.72 KB
/
AssetDetails.vue
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<script setup lang="ts">
import { useDevToolsClient } from '~/logic/client'
import { rpc } from '~/logic/rpc'
const props = defineProps<{
asset: AssetInfo
}>()
const origin = window.parent.location.origin
const imageMeta = computedAsync(() => {
if (props.asset.type !== 'image')
return undefined
return rpc.getImageMeta(props.asset.filePath)
})
const textContent = computedAsync(() => {
if (props.asset.type !== 'text')
return undefined
return rpc.getTextAssetContent(props.asset.filePath)
})
const copy = useCopy()
const timeago = useTimeAgo(() => props.asset.mtime)
const fileSize = computed(() => {
const size = props.asset.size
if (size < 1024)
return `${size} B`
if (size < 1024 * 1024)
return `${(size / 1024).toFixed(2)} KB`
return `${(size / 1024 / 1024).toFixed(2)} MB`
})
const aspectRatio = computed(() => {
if (!imageMeta.value?.width || !imageMeta.value?.height)
return ''
const gcd = (a: number, b: number): number => {
if (!b)
return a
return gcd(b, a % b)
}
const ratio = gcd(imageMeta.value.width, imageMeta.value.height)
if (ratio > 3)
return `${imageMeta.value.width / ratio}:${imageMeta.value.height / ratio}`
return ''
})
const supportsPreview = computed(() => {
return [
'image',
'text',
'video',
'font',
].includes(props.asset.type)
})
const client = useDevToolsClient()
</script>
<template>
<div flex="~ col gap-4" min-h-full w-full of-hidden p4>
<template v-if="supportsPreview">
<div flex="~ gap2" mb--2 items-center op50>
<div x-divider />
<div flex-none>
Preview
</div>
<div x-divider />
</div>
<div flex="~" items-center justify-center>
<AssetPreview
border="~ base"
detail max-h-80 min-h-20 min-w-20 w-auto rounded
:asset="asset"
:text-content="textContent"
/>
</div>
</template>
<div flex="~ gap2" mb--2 items-center op50>
<div x-divider />
<div flex-none>
Details
</div>
<div x-divider />
</div>
<table max-w-full w-full table-fixed>
<tbody>
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
Filepath
</td>
<td>
<div flex="~ gap-1" w-full items-center>
<FilepathItem :filepath="asset.filePath" text-left />
<VDIconButton
flex-none
title="Open in Editor"
icon="carbon-launch"
@click="client.openInEditor(asset.filePath)"
/>
</div>
</td>
</tr>
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
Public Path
</td>
<td>
<div flex="~ gap-1" w-full items-center of-hidden>
<div flex-auto of-hidden truncate ws-pre font-mono>
{{ asset.publicPath }}
</div>
<VDIconButton
flex-none
title="Copy public path"
icon="carbon-copy"
@click="copy(asset.publicPath)"
/>
<VDIconButton
flex-none
:to="`${origin}${asset.publicPath}`"
icon="carbon-launch"
target="_blank"
title="Open in browser"
/>
</div>
</td>
</tr>
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
Type
</td>
<td capitalize>
{{ asset.type }}
</td>
</tr>
<template v-if="imageMeta?.width">
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
Image Size
</td>
<td>{{ imageMeta.width }} x {{ imageMeta.height }}</td>
</tr>
<tr v-if="aspectRatio">
<td w-30 ws-nowrap pr5 text-right op50>
Aspect Ratio
</td>
<td>{{ aspectRatio }}</td>
</tr>
</template>
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
File size
</td>
<td>{{ fileSize }}</td>
</tr>
<tr>
<td w-30 ws-nowrap pr5 text-right op50>
Last modified
</td>
<td>{{ new Date(asset.mtime).toLocaleString() }} <span op70>({{ timeago }})</span></td>
</tr>
</tbody>
</table>
<div flex="~ gap2" mb--2 items-center op50>
<div x-divider />
<div flex-none>
Actions
</div>
<div x-divider />
</div>
<div flex="~ gap2 wrap">
<VDButton :to="`${origin}${asset.publicPath}`" download target="_blank" icon="carbon-download">
Download
</VDButton>
</div>
<div flex-auto />
</div>
</template>