123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <template v-for="(track, index) in trackList" :key="index">
- <div
- v-if="isTrackMode"
- class="score-container"
- :class="[focusedTrack(track) && 'score-animation']"
- :style="computeTopAndLeft(track)"
- >
- <span
- class="tw-m-auto"
- :id="'a' + track.mainNumber + track.subNumber + track.offsetY"
- >
- {{ track.score }}
- </span>
- </div>
- </template>
- <template v-for="(tag, index) in specialTagList" :key="index">
- <div class="score-container" :style="computeTopAndLeft(tag)">
- <span class="tw-m-auto">
- {{ tag.tagName }}
- </span>
- </div>
- </template>
- </template>
- <script setup lang="ts">
- import { ModeEnum } from "@/types";
- import type { SpecialTag, Track } from "@/types";
- import { computed, defineProps, toRefs, watch } from "vue";
- import { store } from "./store";
- const props = defineProps<{
- trackList: Array<Track>;
- specialTagList: Array<SpecialTag>;
- sliceImage: HTMLImageElement;
- dx: number;
- dy: number;
- }>();
- const { trackList, sliceImage, dx, dy } = toRefs(props);
- const isTrackMode = computed(() => store.setting.mode === ModeEnum.TRACK);
- const computeTopAndLeft = (track: Track | SpecialTag) => {
- const topInsideSlice = track.offsetY - dy.value;
- const leftInsideSlice = track.offsetX - dx.value;
- return {
- top: (topInsideSlice / sliceImage.value.naturalHeight) * 100 + "%",
- left: (leftInsideSlice / sliceImage.value.naturalWidth) * 100 + "%",
- "font-size":
- (store.setting.uiSetting["score.fontSize.scale"] || 1) *
- store.setting.uiSetting["answer.paper.scale"] *
- 2.2 +
- "em",
- };
- };
- const focusedTrack = (track: Track) => {
- return store.focusTracks.includes(track);
- };
- watch(
- () => store.focusTracks.length,
- () => {
- if (store.focusTracks.length === 0) return;
- const minImageIndex = Math.min(
- ...store.focusTracks.map((t) => t.offsetIndex)
- );
- const minImageOffsetY = Math.min(
- ...store.focusTracks
- .filter((t) => t.offsetIndex === minImageIndex)
- .map((t) => t.offsetY)
- );
- const topTrack = store.focusTracks.find(
- (t) => t.offsetIndex === minImageIndex && t.offsetY === minImageOffsetY
- );
- if (topTrack) {
- document
- .querySelector(
- `#a${topTrack.mainNumber + topTrack.subNumber + topTrack.offsetY}`
- )
- ?.scrollIntoView({ behavior: "smooth" });
- }
- }
- );
- </script>
- <style scoped>
- .score-container {
- position: absolute;
- display: flex;
- place-content: center;
- color: red;
- /* to center score */
- width: 200px;
- height: 200px;
- margin-top: -100px;
- margin-left: -100px;
- /* to click through div */
- pointer-events: none;
- }
- .score-animation {
- animation: 2s ease-in-out 0s infinite alternate change_size;
- }
- @keyframes change_size {
- from {
- font-size: 2em;
- margin-top: -100px;
- margin-left: -100px;
- }
- to {
- font-size: 4em;
- margin-top: -80px;
- margin-left: -80px;
- }
- }
- </style>
|