Skip to content

Commit

Permalink
add font loader and switcher, move fonts to /public, move eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
hyvyys committed Aug 27, 2019
1 parent 3329de8 commit 528668d
Show file tree
Hide file tree
Showing 94 changed files with 340 additions and 111 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
env: {
node: true
},
extends: ["plugin:vue/essential", "eslint:recommended"],
rules: {
"comma-dangle": ["error", "always-multiline"]
},
parserOptions: {
parser: "babel-eslint"
},
overrides: [
{
files: ["**/__tests__/*.{j,t}s?(x)"],
env: {
jest: true
}
}
]
};
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 2 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"opentype.js": "^1.1.0",
"vue": "^2.6.10",
"vue-router": "^3.0.3",
"vuebar": "github:hyvyys/vuebar"
"vuebar": "github:hyvyys/vuebar",
"vuex": "^3.1.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.11.0",
Expand All @@ -41,30 +42,6 @@
"vue-template-compiler": "^2.6.10",
"ware-loader": "^0.2.4"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
},
"overrides": [
{
"files": [
"**/__tests__/*.{j,t}s?(x)"
],
"env": {
"jest": true
}
}
]
},
"postcss": {
"plugins": {
"autoprefixer": {}
Expand Down
File renamed without changes.
130 changes: 96 additions & 34 deletions src/components/FontLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,105 @@
<UiSelect
v-if="gui"
class="font-select dark"
:value="fonts[selectedFontIndex]"
v-model="selectedFont"
:keys="fontOptionKeys"
:options="fonts"
/>
>
<div slot="option" slot-scope="props" :style="optionStyle">
<div class="font-family">{{ props.option && props.option.family }}</div>
<div
class="font-family-sample"
:style="optionSampleStyle(props.option)"
>{{ props.option && sampleText }}</div>
</div>
</UiSelect>

<FileDrop @files-dropped="loadFonts" />
</div>
</template>

<script>
var opentype = require("opentype.js");
import util from "util";
const loadFont = util.promisify(opentype.load);
import UiSelect from "keen-ui/src/UiSelect.vue";
import FileDrop from "@/components/FileDrop";
import eventBus from "@/eventBus";
import FileDrop from "@/components/FileDrop.vue";
import FontParser from "@/models/FontParser";
import styles from "@/utils/styles";
import { Promise } from "q";
export default {
name: "FontTester",
components: {
FileDrop,
UiSelect
UiSelect,
},
props: {
gui: {
type: Boolean,
default: true
}
default: true,
},
},
data() {
return {
selectedFontIndex: 0,
fonts: ["Alegreya Sans"]
fontOptionKeys: {
class: "class",
label: "family",
image: "image",
},
selectedFont: { family: "" },
fonts: [],
sampleText: "Abg123",
optionStyle: `
display: flex;
align-items: baseline;
width: 100%;
`,
optionSampleStyle: option => `
flex: 1;
font-family: ${option.family};
font-weight: normal;
text-align: right;
`,
};
},
computed: {},
watch: {},
beforeMount() {},
watch: {
selectedFont() {
this.updateFont();
},
},
beforeMount() {
const dir = "/fonts/";
const fonts = [
"alegreya-sans/alegreya-sans-v10-latin-ext_cyrillic_cyrillic-ext_latin_vietnamese_greek-ext_greek-regular.ttf",
"Rywalka-Regular.ttf",
];
this.loadFonts({ urls: fonts.map(f => dir + f) });
},
methods: {
async loadFonts(files) {
let first = true;
for (let file of files) {
let url = URL.createObjectURL(file);
await loadFont(url)
.then(font => {
// processFont(font, url);
// if (first) {
// fontSelect.selectedIndex = fontSelect.options.length - 1;
// fireEvent(fontSelect, "change");
// first = false;
// }
console.log(font);
})
.catch(err => {
// console.error("Font could not be loaded: " + err);
async loadFonts({ files = [], urls = [] } = {}) {
if (!urls.length) urls = files.map(file => URL.createObjectURL(file));
Promise.all(urls.map(url => FontParser.parse(url)))
.then(fonts => {
fonts.forEach(font => {
this.fonts.push(font);
styles.add(font.fontFace);
});
}
}
}
this.selectedFont = fonts[0];
// this.selectFont()
})
.catch(error => {
console.log(error);
});
},
updateFont() {
eventBus.$emit("font-change", this.selectedFont.family);
},
/* ^^^ methods ^^^ */
},
};
</script>

Expand All @@ -72,7 +113,28 @@ export default {
@include flex();
.ui-select.font-select {
margin-bottom: .75em;
.ui-select__display {
@include pseudo();
&::before {
z-index: -1;
mix-blend-mode: hard-light;
background: rgba(#333, 0.8);
border-radius: 3px;
box-shadow: inset 0 0 5px #000;
pointer-events: none;
}
padding: 2px 8px;
width: 10em;
border-radius: 3px;
}
margin-bottom: 0.1em;
}
.option {
display: flex;
.font-family-sample {
flex: 1;
}
}
}
</style>
10 changes: 5 additions & 5 deletions src/components/FontSample.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="font-sample"
contenteditable
spellcheck="false"
:style="`font-size: ${fontSize}${fontSizeUnit}`"
:style="`font-family: ${fontFamily}, ${fallbackFontFamily}; font-size: ${fontSize}${fontSizeUnit}`"
@input="onInput"
v-html="html"
/>
Expand All @@ -18,9 +18,9 @@ export default {
props: {
html: {
type: String,
default: "",
default: ""
},
...settings,
...settings
},
methods: {
onInput(e) {
Expand All @@ -30,8 +30,8 @@ export default {
notifyWindow() {
// trigger resize event so that Fitter can be positioned
window.dispatchEvent(new Event("resize"));
},
},
}
}
};
</script>

Expand Down
10 changes: 3 additions & 7 deletions src/components/SiteHeader.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="site-header">
<div class="flex dark">
<div class="dark">
<div class="logo">
<SiteLogo class />
</div>
Expand Down Expand Up @@ -72,12 +72,6 @@ $header-background: linear-gradient(to right, $light, $accent);
background-size: 100vw 150px;
}
.flex {
flex: 1;
display: flex;
align-items: stretch;
}
.site-header {
display: flex;
align-items: stretch;
Expand All @@ -91,9 +85,11 @@ $header-background: linear-gradient(to right, $light, $accent);
.light {
background: $light;
}
.dark {
flex: 1;
display: flex;
margin-top: -8px;
align-items: center;
}
Expand Down
8 changes: 2 additions & 6 deletions src/components/layout/Fitter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<script>
import throttle from "lodash.throttle";
import viewport from "@/utils/viewport";
export default {
name: "Fitter",
Expand Down Expand Up @@ -49,11 +50,6 @@ export default {
},
methods: {
position() {
const viewportHeight = Math.max(
document.documentElement.clientHeight,
window.innerHeight || 0
);
const header = window.document.querySelector(this.topSelector);
if (header) {
const { bottom } = header.getBoundingClientRect();
Expand All @@ -65,7 +61,7 @@ export default {
const footer = window.document.querySelector(this.bottomSelector);
if (footer) {
const { top } = footer.getBoundingClientRect();
this.bottom = Math.max(0, viewportHeight - top);
this.bottom = Math.max(0, viewport.height - top);
} else {
console.error(`Fitter didn't find element ${this.bottomSelector}.`);
}
Expand Down
5 changes: 5 additions & 0 deletions src/eventBus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Vue from "vue";

const bus = new Vue();

export default bus;
7 changes: 3 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import Vue from "vue";
Vue.config.productionTip = false;

import Vuebar from "vuebar";
Vue.use(Vuebar);

import "./scss/styles.scss";

import App from "./App.vue";
import router from "./router";

Vue.config.productionTip = false;
Vue.use(Vuebar);

new Vue({
router,
render: h => h(App)
Expand Down
Loading

0 comments on commit 528668d

Please sign in to comment.