Load fonts on-demand

The same set of fonts are not used across RTL and LTR languages. This
change only loads fonts that are being used
This commit is contained in:
0x1eef 2024-09-30 15:50:08 -03:00
parent 2324189992
commit 4d44e72954
2 changed files with 23 additions and 22 deletions

View file

@ -17,18 +17,20 @@ import { formatNumber } from "~/lib/t";
const style: HTMLStyleElement = doc.querySelector(".css.postman")!;
const progressBar: HTMLProgressElement = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
const fonts = (() => {
if (doc.dir === "rtl") {
return [
item.font("Cairo Regular", "url(/fonts/cairo-regular.ttf)"),
item.font("Cairo Bold", "url(/fonts/cairo-bold.ttf)"),
];
} else {
return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")];
}
})();
postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-index.js?v=${rev}`, { id: "1" }),
item.font(
"Cairo Regular",
"url(/fonts/cairo-regular.ttf) format('truetype')",
),
item.font("Cairo Bold", "url(/fonts/cairo-bold.ttf) format('truetype')"),
item.font(
"Kanit Regular",
"url(/fonts/kanit-regular.ttf) format('truetype')",
),
...fonts,
item.progress((percent: number) => {
progressBar.value = percent;
progressNumber.innerText = formatNumber(

View file

@ -18,22 +18,21 @@ import { formatNumber } from "~/lib/t";
const style = doc.querySelector(".css.postman")!;
const progressBar = loader.querySelector("progress")!;
const progressNumber: HTMLSpanElement = loader.querySelector(".percentage")!;
const fonts = (() => {
if (doc.dir === "rtl") {
return [
item.font("Cairo Regular", "url(/fonts/cairo-regular.ttf)"),
item.font("Cairo Bold", "url(/fonts/cairo-bold.ttf)"),
item.font("Amiri Quran Regular", "url(/fonts/amiri-quran-regular.ttf)"),
];
} else {
return [item.font("Kanit Regular", "url(/fonts/kanit-regular.ttf)")];
}
})();
postman(
item.script(`/js/main/vendor.js?v=${rev}`, { id: "0" }),
item.script(`/js/main/surah-stream.js?v=${rev}`, { id: "1" }),
item.font(
"Cairo Regular",
"url(/fonts/cairo-regular.ttf) format('truetype')",
),
item.font("Cairo Bold", "url(/fonts/cairo-bold.ttf) format('truetype')"),
item.font(
"Amiri Quran Regular",
"url(/fonts/amiri-quran-regular.ttf) format('truetype')",
),
item.font(
"Kanit Regular",
"url(/fonts/kanit-regular.ttf) format('truetype')",
),
...fonts,
/* eslint-disable */
item.json(`/json/${doc.lang}/${surahId}/info.json?v=${rev}`, { className: "json surahinfo" }),
item.json(`/json/${doc.lang}/${surahId}/surah.json?v=${rev}`, { className: "json surah" }),