muzika-gromche/Frontend/src/components/timeline/clip/TimelineClipView.vue

112 lines
3.5 KiB
Vue
Raw Normal View History

WIP: Add frontend web app player & editor in Vue 3 + Vite TODO: - implement viewing & editing. - Add links to deployment, and CHANGELOG. style.css package.json vite config .vscode eslint use --cache .vscode add vite-css-modules editorconfig tsconfig and updated vue-tsc (fixes most of the type checking bugs) fix last type errors audiowaveform gitignore ESLint ESLint: ignore autogenerated JSON lint:fix tsconfig and vite config migrate icon generating script to TS eslint src/lib/ eslint stores eslint src/*.ts eslint audio pnpm update update icon eslint ahh import new tracks json instructions on jq codenames codenames.json fix styles broken by import order eslint audio app error screen footer copyright year global header loading screen transition search field preview track info inspector control controls controls range controls impl controls index eslint no-console off AudioTrack view inspector cards and sliders more controls master volume slider playhead library page player page timeline markers timeline markers header tick timestamp timeline clip index clip empty clip lyrics clip palette clip fadeout clip default import order timeline timeline panel timeline track header timeline trackview clip view clip audio audio waveform scrollsync easy lints eslint store eslint no mutating props off pnpm catalog off add unhead dep use head eslint inspector eslint easy minor stuff eslint audiowaveform easy fix eslint use :key with v-for fix audio waveforms inspector makes more sense season remove debug inspector Merge codenames into main json bump pnpm pnpm in particular enabled monospace Game Over Move JSON to assets to avoid caching issues update pnpm pnpm update Add Pop1 SFX
2025-11-27 14:57:28 +00:00
<script setup lang="ts">
import type { TimelineClipData, TimelineTrackData } from '@/lib/Timeline'
import { useCssVar, useElementBounding } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import { computed, shallowRef, useTemplateRef } from 'vue'
import { timelineClipColor, toAbsoluteDuration, toAbsoluteTime } from '@/lib/Timeline'
import { toPx, usePx } from '@/lib/usePx'
import { useTimelineStore } from '@/store/TimelineStore'
import { getComponentFor } from '.'
const {
timelineTrack,
timelineClip,
} = defineProps<{
timelineTrack: TimelineTrackData
timelineClip: TimelineClipData
}>()
const timeline = useTimelineStore()
const { audioTrack } = storeToRefs(timeline)
const contentView = computed(() => getComponentFor(timelineTrack))
const left = computed(() => {
const t = toAbsoluteTime(audioTrack.value, timelineTrack.reference, timelineClip.clipIn)
const px = timeline.secondsToPixels(t)
return toPx(px)
})
const width = usePx(() => {
const t = toAbsoluteDuration(audioTrack.value, timelineTrack.reference, timelineClip.duration)
const px = timeline.secondsToPixels(t)
return px
})
const autorepeat = computed(() => timelineClip.autorepeat)
const color = computed(() => timelineClipColor(timelineTrack, timelineClip))
const isSelected = shallowRef(false)
function selectClip() {
// TODO: make selection manager
isSelected.value = !isSelected.value
}
// style:
// - always thin outer border style
// - regular (non-autorepeat):
// - outer border is 50% black
// - if not selected, do nothing
// - if selected, red (inner) outline
// - autorepeat:
// - outer border is transparent (but still occupies 1px of space)
// - always dashed thick outer border style
// - if not selected, custom colored border
// - if selected, red outline
/* NOTE: the following is "would do anything to avoid hardcoding 4px width limit" */
const selectionRef = useTemplateRef('selection')
const { width: selectionWidth } = useElementBounding(selectionRef)
const outlineSelectedWidth = useCssVar('--timeline-clip-outline-selected-width', selectionRef)
const innerBorderVisible = computed(() => outlineSelectedWidth.value ? selectionWidth.value > 2 * Number.parseInt(outlineSelectedWidth.value, 10) : false)
</script>
<template>
<div
class="tw:absolute tw:h-full tw:border tw:rounded-(--timeline-clip-border-radius) tw:overflow-hidden"
:style="{
left,
width: width.string,
maxWidth: width.string,
borderColor: autorepeat ? 'transparent' : 'var(--timeline-clip-border-color)',
}"
@click="selectClip"
>
<!-- background color within outline borders -->
<div
v-if="!autorepeat"
class="tw:absolute tw:size-full"
:style="{ backgroundColor: color }"
/>
<component :is="contentView" :track="timelineTrack" :clip="timelineClip" :width="width.number" />
<!-- selection outline, above content -->
<div
v-if="isSelected || autorepeat" ref="selection"
class="tw:absolute tw:size-full tw:max-w-full tw:pointer-events-none tw:select-none"
:class="{ selection: isSelected, autorepeat }"
:style="!isSelected ? { borderColor: color } : null"
>
<div
v-if="!autorepeat && innerBorderVisible"
class="tw:absolute tw:size-full tw:max-w-full selection-inner"
/>
</div>
</div>
</template>
<style scoped>
.selection {
border: var(--timeline-clip-outline-selected);
}
.autorepeat {
border-width: var(--timeline-clip-outline-selected-width);
border-style: dashed;
}
.selection-inner {
border: 1px solid var(--timeline-clip-border-color-inner);
}
</style>