File size: 4,501 Bytes
89ce340 |
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
<template>
<div class="ruler">
<div
class="h"
:style="{
width: viewportStyles.width * canvasScale + 'px',
left: viewportStyles.left + 'px',
}"
>
<div
class="ruler-marker-100"
:class="{ 'hide': markerSize < 36, 'omit': markerSize < 72 }"
v-for="marker in 20"
:key="`h-marker-100-${marker}`"
:style="{ width: markerSize + 'px' }"
>
<span v-if="marker * 100 <= viewportSize">{{ marker * 100 }}</span>
</div>
<div class="range"
v-if="elementListRange"
:style="{
left: elementListRange.minX * canvasScale + 'px',
width: (elementListRange.maxX - elementListRange.minX) * canvasScale + 'px',
}"
></div>
</div>
<div
class="v"
:style="{
height: viewportStyles.height * canvasScale + 'px',
top: viewportStyles.top + 'px',
}"
>
<div
class="ruler-marker-100"
:class="{ 'hide': markerSize < 36, 'omit': markerSize < 72 }"
v-for="marker in 20"
:key="`v-marker-100-${marker}`"
:style="{ height: markerSize + 'px' }"
>
<span v-if="marker * 100 <= viewportSize * viewportRatio">{{ marker * 100 }}</span>
</div>
<div class="range"
v-if="elementListRange"
:style="{
top: elementListRange.minY * canvasScale + 'px',
height: (elementListRange.maxY - elementListRange.minY) * canvasScale + 'px',
}"
></div>
</div>
</div>
</template>
<script lang="ts" setup>
import { watchEffect, computed, ref } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore } from '@/store'
import { getElementListRange } from '@/utils/element'
import type { PPTElement } from '@/types/slides'
interface ViewportStyles {
top: number
left: number
width: number
height: number
}
const props = defineProps<{
viewportStyles: ViewportStyles
elementList: PPTElement[]
}>()
const { canvasScale, activeElementIdList } = storeToRefs(useMainStore())
const { viewportRatio, viewportSize } = storeToRefs(useSlidesStore())
const elementListRange = ref<null | ReturnType<typeof getElementListRange>>(null)
watchEffect(() => {
const els = props.elementList.filter(el => activeElementIdList.value.includes(el.id))
if (!els.length) return elementListRange.value = null
elementListRange.value = getElementListRange(els)
})
const markerSize = computed(() => {
return props.viewportStyles.width * canvasScale.value / (viewportSize.value / 100)
})
</script>
<style lang="scss" scoped>
.ruler {
font-size: 12px;
}
.h {
position: absolute;
background-color: #fff;
border: 1px solid $borderColor;
height: 20px;
top: 5px;
display: flex;
justify-content: space-between;
align-items: center;
overflow: hidden;
.range {
position: absolute;
top: 0;
bottom: 0;
background-color: rgba($color: $themeColor, $alpha: .1);
}
.ruler-marker-100 {
height: 100%;
line-height: 20px;
text-align: right;
flex-shrink: 0;
padding-right: 5px;
position: relative;
&.hide span {
display: none;
}
&.omit::before {
display: none;
}
&:not(:last-child)::after {
content: '';
width: .1px;
height: 12px;
position: absolute;
right: 0;
bottom: 0;
background-color: #999;
}
&::before {
content: '';
width: .1px;
height: 8px;
position: absolute;
right: 50%;
bottom: 0;
background-color: #999;
}
}
}
.v {
position: absolute;
background-color: #fff;
border: 1px solid $borderColor;
width: 20px;
left: 5px;
overflow: hidden;
.range {
position: absolute;
left: 0;
right: 0;
background-color: rgba($color: $themeColor, $alpha: .1);
}
.ruler-marker-100 {
width: 100%;
line-height: 20px;
text-align: right;
padding-bottom: 5px;
position: relative;
writing-mode: vertical-rl;
&.hide span {
display: none;
}
&.omit::before {
display: none;
}
&:not(:last-child)::after {
content: '';
height: .1px;
width: 12px;
position: absolute;
bottom: 0;
right: 0;
background-color: #999;
}
&::before {
content: '';
height: .1px;
width: 8px;
position: absolute;
bottom: 50%;
right: 0;
background-color: #999;
}
}
}
</style> |