-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skarab42
committed
Nov 28, 2020
1 parent
cfed953
commit 3164dea
Showing
10 changed files
with
85 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
const { filesPath } = require("../../utils"); | ||
const fs = require("fs"); | ||
|
||
const allowedExts = ["ttf", "otf"]; | ||
|
||
function getFonts() { | ||
return fs.readdirSync(filesPath).filter((filename) => { | ||
const ext = filename.split(".").pop(); | ||
return allowedExts.includes(ext); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
getOS: () => { | ||
return process.platform; | ||
}, | ||
getFonts: () => { | ||
return getFonts(); | ||
}, | ||
}; |
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
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
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,29 @@ | ||
<script> | ||
import Select from "@/components/UI/Select.svelte"; | ||
import { createEventDispatcher } from "svelte"; | ||
import loadFonts from "./loadFonts"; | ||
const dispatch = createEventDispatcher(); | ||
export let font; | ||
function onChange({ detail: font }) { | ||
console.log({ font }); | ||
dispatch("font", font); | ||
} | ||
</script> | ||
|
||
<div class="p-2"> | ||
{#await loadFonts()} | ||
Loading fonts list... | ||
{:then fonts} | ||
<Select | ||
value="{font}" | ||
items="{fonts}" | ||
class="flex-auto" | ||
on:change="{onChange}" | ||
/> | ||
{:catch error} | ||
<div class="bg-red-600 text-light">{error.message}</div> | ||
{/await} | ||
</div> |
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,22 @@ | ||
import api from "@/api/app"; | ||
|
||
async function loadFont(name, url) { | ||
const fontFace = new FontFace(name, `url(${url})`); | ||
await fontFace.load(); | ||
document.fonts.add(fontFace); | ||
return fontFace; | ||
} | ||
|
||
export default async function loadFonts() { | ||
const fonts = await api.getFonts(); | ||
const fontNames = []; | ||
|
||
for (let i = 0, l = fonts.length; i < l; i++) { | ||
const filename = fonts[i]; | ||
const [name] = filename.split("."); | ||
const fontFace = await loadFont(name, `files/${filename}`); | ||
fontNames.push(fontFace.family); | ||
} | ||
|
||
return fontNames; | ||
} |