1
1
<script setup lang="ts">
2
- import { computed , inject , reactive , ref , toRef } from ' vue'
2
+ import {
3
+ type MaybeRefOrGetter ,
4
+ computed ,
5
+ inject ,
6
+ reactive ,
7
+ ref ,
8
+ toRef ,
9
+ toValue ,
10
+ } from ' vue'
3
11
import { injectKeyStore } from ' ./types'
4
12
5
13
const props = defineProps <{ layout? : ' horizontal' | ' vertical' }>()
6
14
const isVertical = computed (() => props .layout === ' vertical' )
7
15
8
16
const container = ref ()
17
+ const previewRef = inject <MaybeRefOrGetter <HTMLDivElement >>(' preview-ref' )!
9
18
10
19
// mobile only
11
20
const store = inject (injectKeyStore )!
@@ -14,6 +23,8 @@ const showOutput = toRef(store, 'showOutput')
14
23
const state = reactive ({
15
24
dragging: false ,
16
25
split: 50 ,
26
+ viewHeight: 0 ,
27
+ viewWidth: 0 ,
17
28
})
18
29
19
30
const boundSplit = computed (() => {
@@ -28,6 +39,8 @@ function dragStart(e: MouseEvent) {
28
39
state .dragging = true
29
40
startPosition = isVertical .value ? e .pageY : e .pageX
30
41
startSplit = boundSplit .value
42
+
43
+ changeViewSize ()
31
44
}
32
45
33
46
function dragMove(e : MouseEvent ) {
@@ -38,12 +51,24 @@ function dragMove(e: MouseEvent) {
38
51
: container .value .offsetWidth
39
52
const dp = position - startPosition
40
53
state .split = startSplit + + ((dp / totalSize ) * 100 ).toFixed (2 )
54
+
55
+ changeViewSize ()
41
56
}
42
57
}
43
58
44
59
function dragEnd() {
45
60
state .dragging = false
46
61
}
62
+
63
+ function changeViewSize() {
64
+ const el = toValue (previewRef )
65
+ state .viewHeight = el .offsetHeight
66
+ state .viewWidth = el .offsetWidth
67
+ }
68
+
69
+ defineExpose ({
70
+ changeViewSize ,
71
+ })
47
72
</script >
48
73
49
74
<template >
@@ -70,6 +95,9 @@ function dragEnd() {
70
95
class =" right"
71
96
:style =" { [isVertical ? 'height' : 'width']: 100 - boundSplit + '%' }"
72
97
>
98
+ <div class =" view-size" v-show =" state.dragging" >
99
+ {{ `${state.viewWidth}px x ${state.viewHeight}px` }}
100
+ </div >
73
101
<slot name =" right" />
74
102
</div >
75
103
@@ -97,6 +125,14 @@ function dragEnd() {
97
125
position : relative ;
98
126
height : 100% ;
99
127
}
128
+ .view-size {
129
+ position : absolute ;
130
+ top : 40px ;
131
+ left : 10px ;
132
+ font-size : 12px ;
133
+ color : var (--text-light );
134
+ z-index : 100 ;
135
+ }
100
136
.left {
101
137
border-right : 1px solid var (--border );
102
138
}
0 commit comments