Refactor and fix

This commit is contained in:
schmelczerandras 2020-11-22 22:43:28 +01:00
parent 91d92f7f48
commit 4be519f052
22 changed files with 118 additions and 113 deletions

View file

@ -1,2 +1,3 @@
export const sum = (list: ArrayLike<number>): number =>
// @ts-ignore
Array.prototype.reduce.call(list, (a: number, sum: number) => a + sum, 0);

View file

@ -10,10 +10,12 @@
svg {
stroke: var(--normal-text-color);
transition: stroke var(--transition-time);
}
}
p {
@include main-font();
padding-bottom: var(--small-margin);
font-size: 0.9rem;
font-style: italic;

View file

@ -31,7 +31,7 @@ export class Image extends PageElement {
image.images
.slice(0, -1)
.map(d => `(max-width: ${d.width / Image.imageScreenRatio}px) ${d.width}px,`)
.join('\n') + `\n${last(image.images).width}px`
.join('\n') + `\n${last(image.images)!.width}px`
);
}
}

View file

@ -32,10 +32,15 @@
}
}
.loading,
.loading > svg {
.loading {
@include square(var(--large-icon-size));
@include absolute-center;
visibility: hidden;
& > svg {
@include square(var(--large-icon-size));
@include absolute-center;
}
}
iframe {
@ -52,9 +57,6 @@
.load-button {
visibility: hidden;
}
}
&.waiting {
.loading {
visibility: visible;
}

View file

@ -3,7 +3,6 @@ import { createElement } from '../../../helper/create-element';
import { generate } from './preview.html';
import { Image } from '../image/image';
import { ResponsiveImage } from '../../../types/responsive-image';
import { OnLoadEvent } from '../../../events/concrete-events/on-load-event';
export class Preview extends PageElement {
public constructor(
@ -18,14 +17,14 @@ export class Preview extends PageElement {
this.query('.load-button').addEventListener('click', this.loadContent.bind(this));
}
public handleOnLoadEvent(event: OnLoadEvent): OnLoadEvent {
public setParent(parent: PageElement) {
new IntersectionObserver(e => {
if (!e[0].isIntersecting) {
this.unloadContent();
}
}).observe(this.htmlRoot.parentElement);
}).observe(this.htmlRoot.parentElement!);
return event;
super.setParent(parent);
}
public loadContent() {

View file

@ -2,5 +2,5 @@ import './text.scss';
import { html } from '../../../types/html';
export const generate = (text: string): html => `
<p class="primitive-text">${text}</p>
<p class="text">${text}</p>
`;

View file

@ -1,3 +1,6 @@
.primitive-text {
@use '../../../style/mixins' as *;
.text {
@include main-font();
text-align: left;
}

View file

@ -9,16 +9,16 @@ export const generate = ({
mp4,
container,
}: {
poster: url;
options: string;
poster?: url;
options?: string;
webm: url;
mp4: url;
container: boolean;
container?: boolean;
}): html => `
${container ? `<div class="figure-container">` : ''}
${container === undefined || container ? `<div class="figure-container">` : ''}
<video loading="lazy" ${options} ${poster ? `poster="${poster}` : ''}" >
<source src="${webm}" type="video/webm"/>
<source src="${mp4}" type="video/mp4"/>
</video>
${container ? `</div>` : ''}
${container === undefined || container ? `</div>` : ''}
`;

View file

@ -4,13 +4,13 @@ import { generate } from './video.html';
import { url } from '../../../types/url';
export class Video extends PageElement {
public constructor(
poster: url,
mp4: url,
webm: url,
options?: string,
container = true
) {
super(createElement(generate({ poster, mp4, webm, options, container })));
public constructor(options: {
poster?: url;
mp4: url;
webm: url;
options?: string;
container?: boolean;
}) {
super(createElement(generate(options)));
}
}

View file

@ -11,7 +11,7 @@ export const generate = ({
lastEditText,
lastEdit,
}: Footer): html => `
<footer id="page-footer">
<footer id="footer">
<h2>${title}</h2>
<ul>
${curriculaVitae

View file

@ -1,6 +1,6 @@
@use '../../style/mixins' as *;
footer#page-footer {
#footer {
text-align: center;
margin-top: var(--large-margin);
@ -30,7 +30,8 @@ footer#page-footer {
img,
svg {
@include max-square(var(--icon-size));
max-width: var(--icon-size);
max-height: var(--icon-size);
margin-right: calc(var(--small-margin) / 2);
stroke: var(--normal-text-color);
}

View file

@ -1,11 +1,17 @@
@use '../../style/mixins' as *;
section#about {
@include card-base();
#about {
text-align: center;
box-shadow: var(--shadow);
padding: var(--normal-margin);
background-color: var(--accent-color);
font-size: 0;
::selection {
background-color: var(--very-light-text-color);
color: var(--accent-color);
}
$img-size: 125px;
h1,
img,

View file

@ -5,7 +5,7 @@ import { html } from '../../types/html';
export const generate = (): html => `
<section id="image-viewer">
<div id="container"></div>
<img image-viewer-ignore />
<div tabindex="0" id="cancel">${cancel}</div>
</section>
`;

View file

@ -1,20 +1,18 @@
@use '../../style/mixins' as *;
section#image-viewer {
#image-viewer {
@include center-children();
display: none;
@include blurred-background();
visibility: hidden;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
margin: 0;
z-index: 2;
background-color: rgba(0, 0, 0, 0.85);
#container > * {
width: auto;
height: auto;
img {
@include square(auto);
@include on-large-screen {
max-width: 80vw;
@ -22,17 +20,20 @@ section#image-viewer {
}
@include on-small-screen {
max-width: 95vw;
max-height: 95vh;
max-width: 92.5vw;
max-height: 92.5vh;
}
}
#cancel {
@include image-button(var(--large-icon-size));
@include square(calc(var(--large-icon-size) + var(--normal-margin) * 2));
position: absolute;
right: 0;
top: 0;
@include image-button(var(--large-icon-size));
svg {
stroke: var(--normal-text-color);
}
}
}

View file

@ -1,48 +1,36 @@
import { PageElement } from '../page-element';
import { generate } from './image-viewer.html';
import { createElement } from '../../helper/create-element';
import { OnLoadEvent } from '../../events/concrete-events/on-load-event';
import { OptionalEvent } from '../../events/optional-event';
export class PageImageViewer extends PageElement {
public constructor() {
super(createElement(generate()));
this.htmlRoot.onclick = () => PageImageViewer.hide(this.htmlRoot);
document.body.addEventListener('click', (event: MouseEvent) => {
if (
event.target instanceof HTMLImageElement &&
!event.target.attributes['image-viewer-ignore']
) {
this.showImage(event.target);
}
});
document.body.addEventListener('keydown', (event: KeyboardEvent) => {
if (event.key === 'Escape') {
this.hideImage();
}
});
this.htmlRoot.addEventListener('click', this.hideImage.bind(this));
}
public handleOnLoadEvent(event: OnLoadEvent): OptionalEvent {
document.body.addEventListener('keydown', this.handleKeydown.bind(this));
const media = Array.prototype.slice.call(document.querySelectorAll('img'));
media
.filter((e: HTMLElement) => !e.attributes['image-viewer-ignore'])
.forEach((e: HTMLImageElement) => (e.onclick = this.handleClick.bind(this)));
return super.handleOnLoadEvent(event);
private showImage(source: HTMLImageElement) {
const image = this.query('img') as HTMLImageElement;
image.src = source.src;
this.htmlRoot.style.visibility = 'visible';
}
private handleClick(event: Event) {
const container = this.query('#container');
container.firstElementChild?.remove();
const element: HTMLImageElement = new Image();
element.src = (event.target as HTMLImageElement).src;
container.appendChild(element);
PageImageViewer.show(this.htmlRoot);
}
private handleKeydown(event: KeyboardEvent) {
if (event.key === 'Escape') {
PageImageViewer.hide(this.htmlRoot);
}
}
private static show(e: HTMLElement) {
e.style.display = 'flex';
}
private static hide(e: HTMLElement) {
e.style.display = 'none';
private hideImage() {
this.htmlRoot.style.visibility = 'hidden';
}
}

View file

@ -7,9 +7,6 @@ import {
turnOnLightMode,
} from '../../style/dark-mode/dark-mode';
import { turnOffAnimations, turnOnAnimations } from '../../style/animations/animations';
import { OnLoadEvent } from '../../events/concrete-events/on-load-event';
import { OptionalEvent } from '../../events/optional-event';
import { OnPageThemeChangedEvent } from '../../events/concrete-events/on-page-theme-changed-event';
export class PageThemeSwitcher extends PageElement {
private static readonly localStorageKey = 'dark-mode';
@ -28,12 +25,10 @@ export class PageThemeSwitcher extends PageElement {
} else {
turnOnLightMode();
}
this.htmlRoot.onchange = this.handleThemeChange.bind(this);
}
public handleOnLoadEvent(event: OnLoadEvent): OptionalEvent {
this.htmlRoot.onchange = this.handleThemeChange.bind(this);
this.handleThemeChange();
return super.handleOnLoadEvent(event);
}
private handleThemeChange() {
@ -44,7 +39,6 @@ export class PageThemeSwitcher extends PageElement {
turnOnLightMode();
}
this.eventBroadcaster.broadcastEvent(new OnPageThemeChangedEvent(isDark));
PageThemeSwitcher.saveToLocalStorage(isDark);
}
@ -57,7 +51,7 @@ export class PageThemeSwitcher extends PageElement {
private static loadFromLocalStorage(): boolean | null {
try {
return JSON.parse(localStorage?.getItem(PageThemeSwitcher.localStorageKey));
return JSON.parse(localStorage!.getItem(PageThemeSwitcher.localStorageKey)!);
} catch {
return null;
}

View file

@ -16,7 +16,7 @@
}
}
section.timeline-element {
.timeline-element {
display: flex;
width: var(--body-width);
margin: auto;
@ -85,14 +85,14 @@ section.timeline-element {
}
.card {
@include card-base();
text-align: center;
box-shadow: var(--shadow);
border-radius: var(--border-radius);
background-color: var(--blurred-card-color);
backdrop-filter: blur(var(--blur-radius));
@supports not (backdrop-filter: blur(var(--blur-radius))) {
background-color: var(--card-color);
}
transition: background-color var(--transition-time);
@include blurred-background();
img,
video,
@ -131,12 +131,15 @@ section.timeline-element {
display: flex;
justify-content: center;
border-top: $border-width solid var(--normal-text-color);
transition: border-color var(--transition-time);
margin: 0;
padding: 0;
margin-top: var(--small-margin);
.info-button {
@include image-button(var(--icon-size));
@include main-font();
.svgContainer {
position: relative;
@ -145,10 +148,12 @@ section.timeline-element {
svg {
stroke: var(--normal-text-color);
transition: stroke var(--transition-time);
}
}
p {
@include main-font();
padding-bottom: var(--small-margin);
font-size: 0.9rem;
font-style: italic;
@ -162,6 +167,7 @@ section.timeline-element {
padding-top: var(--small-margin);
&:not(:last-child) {
border-right: $border-width solid var(--normal-text-color);
transition: border-color var(--transition-time);
}
}
}

View file

@ -6,7 +6,7 @@ import { createElement } from '../../../helper/create-element';
export class PageTimelineElement extends PageElement {
private isOpen: boolean;
private more: HTMLElement;
private more?: HTMLElement;
private showMore: string;
private showLess: string;
@ -22,7 +22,7 @@ export class PageTimelineElement extends PageElement {
super(root);
this.children = [content];
this.isOpen = false;
this.more = root.querySelector('.more');
this.more = this.query('.more');
this.more.appendChild(content.htmlRoot);
addEventListener('resize', this.handleResize.bind(this));
@ -35,6 +35,7 @@ export class PageTimelineElement extends PageElement {
this.showMore = showMore;
this.showLess = showLess;
this.isOpen = false;
}
private toggleOpen() {
@ -50,17 +51,17 @@ export class PageTimelineElement extends PageElement {
}
private openMore() {
const deltaHeight = this.more.scrollHeight;
this.more.style.height = `${deltaHeight.toString()}px`;
const deltaHeight = this.more!.scrollHeight;
this.more!.style.height = `${deltaHeight.toString()}px`;
}
private closeMore() {
this.more.style.height = '0';
this.more!.style.height = '0';
}
private handleResize() {
if (this.isOpen) {
this.more.style.height = 'auto';
this.more!.style.height = 'auto';
this.openMore.bind(this);
}
}

View file

@ -1,7 +1,7 @@
@use '../../style/mixins' as *;
@include on-large-screen {
div#timeline > :first-child {
#timeline > :first-child {
margin-top: var(--large-margin);
}
}

View file

@ -1,5 +1,5 @@
export const turnOnAnimations = () =>
document.body.parentElement.setAttribute('animations', 'on');
document.documentElement.setAttribute('animations', 'on');
export const turnOffAnimations = () =>
document.body.parentElement.setAttribute('animations', 'off');
document.documentElement.setAttribute('animations', 'off');

View file

@ -2,7 +2,7 @@ export const isSystemLevelDarkModeEnabled = (): boolean =>
matchMedia && matchMedia('(prefers-color-scheme: dark)').matches;
export const turnOnDarkMode = () =>
document.body.parentElement.setAttribute('theme', 'dark');
document.documentElement.setAttribute('theme', 'dark');
export const turnOnLightMode = () =>
document.body.parentElement.setAttribute('theme', 'light');
document.documentElement.setAttribute('theme', 'light');

View file

@ -43,11 +43,11 @@ $breakpoint-width: 925px !default;
transform: translateX(-50%) translateY(-50%);
}
@mixin card-base() {
text-align: center;
box-shadow: var(--shadow);
z-index: 1;
width: 100%;
@mixin blurred-background() {
backdrop-filter: blur(var(--blur-radius));
@supports not (backdrop-filter: blur(var(--blur-radius))) {
background-color: var(--card-color);
}
}
@mixin square($size) {
@ -55,16 +55,12 @@ $breakpoint-width: 925px !default;
height: $size;
}
@mixin max-square($size) {
max-width: $size;
max-height: $size;
}
@mixin title-font() {
font: 400 3rem 'Comfortaa', serif;
font-style: normal;
color: var(--normal-text-color);
line-height: 1;
transition: color var(--transition-time);
@include on-small-screen {
font-size: 3rem;
@ -76,18 +72,23 @@ $breakpoint-width: 925px !default;
font: 400 1.75rem 'Comfortaa', serif;
color: var(--normal-text-color);
font-style: normal;
hyphens: auto;
transition: color var(--transition-time);
}
@mixin main-font() {
font: 400 1.1rem 'Open Sans', sans-serif;
color: var(--normal-text-color);
line-height: 1.8;
hyphens: auto;
transition: color var(--transition-time);
}
@mixin special-text-font() {
font: 400 1rem 'Open Sans', sans-serif;
color: var(--special-text-color);
font-style: italic;
transition: color var(--transition-time);
}
@mixin link {