11<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'
311import { injectKeyStore } from ' ./types'
412
513const props = defineProps <{ layout? : ' horizontal' | ' vertical' }>()
614const isVertical = computed (() => props .layout === ' vertical' )
715
816const container = ref ()
17+ const previewRef = inject <MaybeRefOrGetter <HTMLDivElement >>(' preview-ref' )!
918
1019// mobile only
1120const store = inject (injectKeyStore )!
@@ -14,6 +23,8 @@ const showOutput = toRef(store, 'showOutput')
1423const state = reactive ({
1524 dragging: false ,
1625 split: 50 ,
26+ viewHeight: 0 ,
27+ viewWidth: 0 ,
1728})
1829
1930const boundSplit = computed (() => {
@@ -28,6 +39,8 @@ function dragStart(e: MouseEvent) {
2839 state .dragging = true
2940 startPosition = isVertical .value ? e .pageY : e .pageX
3041 startSplit = boundSplit .value
42+
43+ changeViewSize ()
3144}
3245
3346function dragMove(e : MouseEvent ) {
@@ -38,12 +51,24 @@ function dragMove(e: MouseEvent) {
3851 : container .value .offsetWidth
3952 const dp = position - startPosition
4053 state .split = startSplit + + ((dp / totalSize ) * 100 ).toFixed (2 )
54+
55+ changeViewSize ()
4156 }
4257}
4358
4459function dragEnd() {
4560 state .dragging = false
4661}
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+ })
4772 </script >
4873
4974<template >
@@ -70,6 +95,9 @@ function dragEnd() {
7095 class =" right"
7196 :style =" { [isVertical ? 'height' : 'width']: 100 - boundSplit + '%' }"
7297 >
98+ <div class =" view-size" v-show =" state.dragging" >
99+ {{ `${state.viewWidth}px x ${state.viewHeight}px` }}
100+ </div >
73101 <slot name =" right" />
74102 </div >
75103
@@ -97,6 +125,14 @@ function dragEnd() {
97125 position : relative ;
98126 height : 100% ;
99127}
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+ }
100136.left {
101137 border-right : 1px solid var (--border );
102138}
0 commit comments