mirror of
https://github.com/Pandipipas/scoreko-dev.git
synced 2026-06-06 03:32:06 +00:00
Match Runback scoreboard fonts and auto-fit behavior
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useHead } from '@unhead/vue';
|
import { useHead } from '@unhead/vue';
|
||||||
import { computed } from 'vue';
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||||
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
|
import { playersReplicant, scoreboardReplicant } from '../../browser_shared/replicants';
|
||||||
import { resolveCountryCode } from '../../shared/countries';
|
import { resolveCountryCode } from '../../shared/countries';
|
||||||
import type { Schemas } from '../../types';
|
import type { Schemas } from '../../types';
|
||||||
@@ -77,6 +77,76 @@ const leftFlagUrl = computed(() => getFlagUrl(scoreboard.value.leftCountryOverri
|
|||||||
const rightFlagUrl = computed(() => getFlagUrl(scoreboard.value.rightCountryOverride));
|
const rightFlagUrl = computed(() => getFlagUrl(scoreboard.value.rightCountryOverride));
|
||||||
|
|
||||||
const roundText = computed(() => scoreboard.value.round || 'Round');
|
const roundText = computed(() => scoreboard.value.round || 'Round');
|
||||||
|
|
||||||
|
const progressTextWrapperRef = ref<HTMLElement | null>(null);
|
||||||
|
const progressTextRef = ref<HTMLElement | null>(null);
|
||||||
|
const p1NameTextWrapperRef = ref<HTMLElement | null>(null);
|
||||||
|
const p1NameTextRef = ref<HTMLElement | null>(null);
|
||||||
|
const p2NameTextWrapperRef = ref<HTMLElement | null>(null);
|
||||||
|
const p2NameTextRef = ref<HTMLElement | null>(null);
|
||||||
|
const p1ScoreWrapperRef = ref<HTMLElement | null>(null);
|
||||||
|
const p1ScoreTextRef = ref<HTMLElement | null>(null);
|
||||||
|
const p2ScoreWrapperRef = ref<HTMLElement | null>(null);
|
||||||
|
const p2ScoreTextRef = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
const fitText = (container: HTMLElement | null, textElement: HTMLElement | null, maxSize: number, minSize = 1) => {
|
||||||
|
if (!container || !textElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let size = maxSize;
|
||||||
|
textElement.style.fontSize = `${size}px`;
|
||||||
|
|
||||||
|
while (size > minSize) {
|
||||||
|
const overflowsWidth = textElement.scrollWidth > container.clientWidth;
|
||||||
|
const overflowsHeight = textElement.scrollHeight > container.clientHeight;
|
||||||
|
if (!overflowsWidth && !overflowsHeight) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
size -= 1;
|
||||||
|
textElement.style.fontSize = `${size}px`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const refitText = () => {
|
||||||
|
fitText(progressTextWrapperRef.value, progressTextRef.value, 35);
|
||||||
|
fitText(p1NameTextWrapperRef.value, p1NameTextRef.value, 45);
|
||||||
|
fitText(p2NameTextWrapperRef.value, p2NameTextRef.value, 45);
|
||||||
|
fitText(p1ScoreWrapperRef.value, p1ScoreTextRef.value, 55);
|
||||||
|
fitText(p2ScoreWrapperRef.value, p2ScoreTextRef.value, 55);
|
||||||
|
};
|
||||||
|
|
||||||
|
const scheduleRefit = () => {
|
||||||
|
void nextTick(() => {
|
||||||
|
refitText();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
window.addEventListener('resize', refitText);
|
||||||
|
scheduleRefit();
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('resize', refitText);
|
||||||
|
});
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => [
|
||||||
|
roundText.value,
|
||||||
|
leftTeam.value,
|
||||||
|
rightTeam.value,
|
||||||
|
leftName.value,
|
||||||
|
rightName.value,
|
||||||
|
scoreboard.value.leftScore,
|
||||||
|
scoreboard.value.rightScore,
|
||||||
|
],
|
||||||
|
() => {
|
||||||
|
scheduleRefit();
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -96,26 +166,40 @@ const roundText = computed(() => scoreboard.value.round || 'Round');
|
|||||||
alt=""
|
alt=""
|
||||||
>
|
>
|
||||||
|
|
||||||
<div id="progress-text-wrapper">
|
<div
|
||||||
<div id="progress-text">
|
id="progress-text-wrapper"
|
||||||
|
ref="progressTextWrapperRef"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
id="progress-text"
|
||||||
|
ref="progressTextRef"
|
||||||
|
>
|
||||||
{{ roundText }}
|
{{ roundText }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="p1-games-text-wrapper"
|
id="p1-games-text-wrapper"
|
||||||
|
ref="p1ScoreWrapperRef"
|
||||||
class="games-text-wrapper"
|
class="games-text-wrapper"
|
||||||
>
|
>
|
||||||
<div class="games-text">
|
<div
|
||||||
|
ref="p1ScoreTextRef"
|
||||||
|
class="games-text"
|
||||||
|
>
|
||||||
{{ scoreboard.leftScore }}
|
{{ scoreboard.leftScore }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
id="p2-games-text-wrapper"
|
id="p2-games-text-wrapper"
|
||||||
|
ref="p2ScoreWrapperRef"
|
||||||
class="games-text-wrapper"
|
class="games-text-wrapper"
|
||||||
>
|
>
|
||||||
<div class="games-text">
|
<div
|
||||||
|
ref="p2ScoreTextRef"
|
||||||
|
class="games-text"
|
||||||
|
>
|
||||||
{{ scoreboard.rightScore }}
|
{{ scoreboard.rightScore }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -131,17 +215,20 @@ const roundText = computed(() => scoreboard.value.round || 'Round');
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="p1-name-text-wrapper"
|
id="p1-name-text-wrapper"
|
||||||
|
ref="p1NameTextWrapperRef"
|
||||||
class="name-text-wrapper"
|
class="name-text-wrapper"
|
||||||
>
|
>
|
||||||
<span
|
<div ref="p1NameTextRef">
|
||||||
v-if="leftTeam"
|
<span
|
||||||
class="team-text"
|
v-if="leftTeam"
|
||||||
>
|
class="team-text"
|
||||||
{{ leftTeam }}
|
>
|
||||||
</span>
|
{{ leftTeam }}
|
||||||
<span class="gamertag-text">
|
</span>
|
||||||
{{ leftName }}
|
<span class="gamertag-text">
|
||||||
</span>
|
{{ leftName }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -170,17 +257,20 @@ const roundText = computed(() => scoreboard.value.round || 'Round');
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
id="p2-name-text-wrapper"
|
id="p2-name-text-wrapper"
|
||||||
|
ref="p2NameTextWrapperRef"
|
||||||
class="name-text-wrapper"
|
class="name-text-wrapper"
|
||||||
>
|
>
|
||||||
<span
|
<div ref="p2NameTextRef">
|
||||||
v-if="rightTeam"
|
<span
|
||||||
class="team-text"
|
v-if="rightTeam"
|
||||||
>
|
class="team-text"
|
||||||
{{ rightTeam }}
|
>
|
||||||
</span>
|
{{ rightTeam }}
|
||||||
<span class="gamertag-text">
|
</span>
|
||||||
{{ rightName }}
|
<span class="gamertag-text">
|
||||||
</span>
|
{{ rightName }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@@ -288,8 +378,8 @@ img {
|
|||||||
|
|
||||||
#progress-text {
|
#progress-text {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-family: 'Bebas Neue', 'Bebas Neue Regular', 'Roboto Condensed', sans-serif;
|
font-family: 'Bebas Neue Regular', 'Rounded Mplus Regular', sans-serif;
|
||||||
font-size: 32px;
|
font-size: 35px;
|
||||||
letter-spacing: 0.08em;
|
letter-spacing: 0.08em;
|
||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -346,14 +436,20 @@ img {
|
|||||||
height: var(--name-text-height);
|
height: var(--name-text-height);
|
||||||
width: var(--name-text-width);
|
width: var(--name-text-width);
|
||||||
line-height: var(--name-text-height);
|
line-height: var(--name-text-height);
|
||||||
font-family: 'Bebas Neue', 'Bebas Neue Bold', 'Roboto Condensed', sans-serif;
|
font-family: 'Bebas Neue Bold', 'Rounded Mplus Bold', sans-serif;
|
||||||
font-size: 40px;
|
font-size: 45px;
|
||||||
letter-spacing: 0.02em;
|
letter-spacing: 0.02em;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.name-text-wrapper > div {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
.team-text {
|
.team-text {
|
||||||
color: #a5a5a5;
|
color: #a5a5a5;
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
@@ -399,9 +495,9 @@ img {
|
|||||||
|
|
||||||
.games-text {
|
.games-text {
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
font-family: 'Gilroy', 'Bebas Neue', 'Roboto Condensed', sans-serif;
|
font-family: 'Gilroy', sans-serif;
|
||||||
font-weight: 700;
|
font-weight: bold;
|
||||||
font-size: 42px;
|
font-size: 55px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gamertag-text {
|
.gamertag-text {
|
||||||
|
|||||||
Reference in New Issue
Block a user