First commit
This commit is contained in:
54
frontend/app/components/ManaCost.vue
Normal file
54
frontend/app/components/ManaCost.vue
Normal file
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
const props = defineProps<{ cost?: string }>()
|
||||
|
||||
const groups = computed(() => (props.cost ?? '')
|
||||
.split('//')
|
||||
.map(group => group.match(/\{([^}]+)\}/g)?.map(token => token.slice(1, -1)) ?? [])
|
||||
.filter(group => group.length > 0))
|
||||
|
||||
/** mana-font names a few symbols differently from Scryfall's code. */
|
||||
const ALIASES: Record<string, string> = { T: 'tap', Q: 'untap', '∞': 'infinity' }
|
||||
|
||||
function classOf(symbol: string): string {
|
||||
return ALIASES[symbol.toUpperCase()] ?? symbol.replaceAll('/', '').toLowerCase()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<span
|
||||
v-if="groups.length"
|
||||
class="mana-cost"
|
||||
role="img"
|
||||
:aria-label="`Mana cost ${cost}`"
|
||||
>
|
||||
<template v-for="(group, groupIndex) in groups" :key="groupIndex">
|
||||
<span v-if="groupIndex" class="mana-separator" aria-hidden="true">//</span>
|
||||
<i
|
||||
v-for="(symbol, index) in group"
|
||||
:key="`${symbol}-${index}`"
|
||||
class="ms ms-cost mana-symbol"
|
||||
:class="`ms-${classOf(symbol)}`"
|
||||
:title="`{${symbol}}`"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</template>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.mana-cost {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.mana-symbol {
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
.mana-separator {
|
||||
color: var(--muted);
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user