File size: 1,711 Bytes
3a1d71c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script setup lang="ts">
// @ts-ignore
import { Splitpanes, Pane } from 'splitpanes'
import ImgSliSide from './ImgSliSide.vue'
import { asyncComputed, useElementSize } from '@vueuse/core'
import { ref } from 'vue'
import { FileNodeInfo } from '@/api/files'
import { toRawFileUrl } from '@/util/file'
import { createImage } from '@/util'

const props = defineProps<{
  left: FileNodeInfo,
  right: FileNodeInfo
}>()

const percent = ref(50)
const onResize = ([{ size }]: { size: number }[]) => {
  percent.value = size
}

const wrapperEl = ref<HTMLDivElement>()
const { width } = useElementSize(wrapperEl)

const requestFullScreen = () => {
  wrapperEl.value?.requestFullscreen()
}
defineExpose({ requestFullScreen })


const maxEdge = asyncComputed(async () => {
  if (!props.left) {
    return 'width'
  }
  const l = await createImage(toRawFileUrl(props.left))
  const aspectRatio = l.width / l.height
  const clientAR = document.body.clientWidth / document.body.clientHeight
  return aspectRatio > clientAR ? 'width' : 'height'
})
</script>
<template>
  <div ref="wrapperEl" style="height: 100%;">
    <splitpanes class="default-theme" @resize="onResize">
      <pane v-if="left">
        <ImgSliSide side="left" :max-edge="maxEdge" :container-width="width" :percent="percent" :img="left" />
      </pane>
      <pane v-if="right">
        <ImgSliSide :max-edge="maxEdge" :percent="percent" :img="right" side="right" :container-width="width" />
      </pane>
    </splitpanes>
  </div>
</template>


<style lang="scss">
.img-sli .default-theme {

  .splitpanes__splitter {
    background-color: #ccc;
    position: relative;
    width: 4px;
  }

  .splitpanes {
    background-color: #f8f8f8;
  }

}
</style>