generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move PulseVisualization into its own component
- Loading branch information
1 parent
17956e6
commit efb5a9c
Showing
10 changed files
with
332 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,4 +33,4 @@ | |
"typescript": "4.4.4", | ||
"vue": "^3.2.26" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref } from "vue"; | ||
import { useCSSAnimationSynchronizer } from "../../hooks/useCSSAnimationSynchronizer"; | ||
import { Meter } from "../../models/Meter"; | ||
import { MetronomeSize } from "../../models/MetronomeSize"; | ||
const props = defineProps<{ | ||
started?: Boolean; | ||
onBeat: CallableFunction; | ||
meter?: Meter; | ||
currentBeat: number; | ||
size: MetronomeSize; | ||
}>(); | ||
const line = ref(null); | ||
const { haltAnimationStyle } = useCSSAnimationSynchronizer({ | ||
synchronizeElement: line, | ||
onBeat: props.onBeat, | ||
}); | ||
// We don't want to show a lot of dots | ||
const MAX_DOTS = 12; | ||
const dotsCount = computed(() => | ||
props.meter?.isValid() && props.meter.upper <= MAX_DOTS | ||
? props.meter.upper | ||
: 2 | ||
); | ||
const activeIndex = computed(() => props.currentBeat % dotsCount.value); | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-if="props.size !== 'small'" | ||
class="dots" | ||
:style="{ '--dots-count': dotsCount }" | ||
> | ||
<div | ||
v-for="x in dotsCount" | ||
:key="x" | ||
class="dot-wrap" | ||
:data-size="props.size" | ||
> | ||
<div class="dot-wrap-width-constraint"> | ||
<div | ||
:class="[ | ||
'dot', | ||
{ | ||
active: started && x === activeIndex + 1, | ||
downbeat: x === 1, | ||
}, | ||
]" | ||
></div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.dots { | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
max-width: 100%; | ||
margin: 0.5rem; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 0 5%; | ||
.dot-wrap { | ||
max-height: 100%; | ||
display: flex; | ||
align-items: center; | ||
flex-grow: 0; | ||
&[data-size="medium"] { | ||
--active-scale: 0.6; | ||
--inactive-scale: 0.35; | ||
width: calc(20% / var(--dots-count, 1)); | ||
} | ||
&[data-size="large"], | ||
&[data-size="xlarge"] { | ||
--active-scale: 1; | ||
--inactive-scale: 0.85; | ||
width: calc(80% / var(--dots-count, 1)); | ||
} | ||
.dot-wrap-width-constraint { | ||
width: calc(100% - calc(80% / var(--dots-count, 1))); | ||
margin: 0 auto; | ||
aspect-ratio: 1; | ||
display: flex; | ||
align-items: center; | ||
.dot { | ||
width: 100%; | ||
max-height: 100%; | ||
background: var(--text-faint); | ||
aspect-ratio: 1; | ||
border-radius: 100%; | ||
transform: scale(var(--inactive-scale, 0.5)); | ||
&.active { | ||
background: var(--text-accent); | ||
box-shadow: 0 0 0 0.5rem var(--background-primary-alt); | ||
transform: scale(var(--active-scale, 1)); | ||
&.downbeat { | ||
box-shadow: 0 0 0 0.5rem var(--background-primary-alt), | ||
0 0 0 0.75rem var(--text-accent), | ||
0 0 0 0.75rem var(--text-faint); | ||
position: relative; | ||
&::after { | ||
content: ""; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
transform: scale(0.5); | ||
border-radius: 100%; | ||
background-color: var(--background-primary-alt); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<script setup lang="ts"> | ||
import { useCSSAnimationSynchronizer } from "../../hooks/useCSSAnimationSynchronizer"; | ||
import { ref } from "vue"; | ||
const props = defineProps<{ | ||
started: boolean; | ||
onBeat: CallableFunction; | ||
onTick: CallableFunction; | ||
onTock: CallableFunction; | ||
}>(); | ||
const rootElement = ref(null); | ||
const tickColor = ref(""); | ||
const { haltAnimationStyle } = useCSSAnimationSynchronizer({ | ||
synchronizeElement: rootElement, | ||
onBeat: props.onBeat, | ||
}); | ||
props.onTick(() => (tickColor.value = "var(--text-accent)")); | ||
props.onTock(() => (tickColor.value = "var(--text-faint)")); | ||
</script> | ||
|
||
<template> | ||
<div | ||
class="pulse" | ||
ref="rootElement" | ||
:style="{ | ||
'--tick-color': tickColor, | ||
}" | ||
:data-started="props.started" | ||
></div> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
$metronome-resting-background-color: var(--background-primary-alt); | ||
.pulse { | ||
z-index: -1; | ||
position: absolute; | ||
top: 0; | ||
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
background-color: $metronome-resting-background-color; | ||
animation: metronome-pulse var(--metronome-duration) var(--sync-delay, "0s") | ||
infinite; | ||
@keyframes metronome-pulse { | ||
0% { | ||
background-color: var(--tick-color); | ||
} | ||
65%, | ||
100% { | ||
background-color: $metronome-resting-background-color; | ||
} | ||
} | ||
&[data-started="false"] { | ||
background: var(--scrollbar-bg); | ||
animation: none; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.