Skip to content

Commit

Permalink
Add auto calculate on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolobok12309 committed Mar 6, 2024
1 parent f9f35c9 commit 7cb4846
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions components/FontComparer/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</span>
</div>

<details>
<details class="mt-4">
<summary class="cursor-pointer">Css <b>@font-face</b></summary>

<FontFaceCssPreview
Expand Down Expand Up @@ -72,6 +72,11 @@ const { t } = useI18n({
});
const target = ref('Montserrat');
let targetIsChanged = false;
watch(target, () => {
targetIsChanged = true;
});
const src = ref('Arial');
const assumption = ref(0);
const text = ref(defaultText);
Expand Down Expand Up @@ -109,8 +114,24 @@ const onClickText = async () => {
sizeAdjust.value = res.sizeAdjust;
ascentOverride.value = res.lineHeightOpts;
console.log('res', res);
descentOverride.value = 0;
lineGapOverride.value = 0;
console.log(`res ${target.value}:${src.value}`, res);
};
onMounted(async () => {
// @ts-ignore
let fontFaces = [...(await document.fonts.ready)];
// Wait for loading default target
while (!fontFaces.find(({ family }) => target.value === family)) {
if (targetIsChanged) return;
await sleep(50);
// @ts-ignore
fontFaces = [...(await document.fonts.ready)];
}
await onClickText();
});
</script>

<i18n lang="json">
Expand Down
2 changes: 1 addition & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</NuxtLink>
</Blockquote>

<FontComparer />
<FontComparer class="mt-4" />
</div>
</template>

Expand Down

0 comments on commit 7cb4846

Please sign in to comment.