Reformat code

This commit is contained in:
schmelczerandras 2020-09-24 14:16:45 +02:00
parent 7b9f4469c8
commit d48786971b
22 changed files with 85 additions and 122 deletions

View file

@ -1,28 +1,29 @@
{ {
"root": true, "root": true,
"env": { "env": {
"browser": true, "browser": true,
"es2020": true "es2020": true
}, },
"extends": [ "extends": [
"eslint:recommended", "eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended",
"prettier", "prettier",
"prettier/@typescript-eslint" "prettier/@typescript-eslint"
], ],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"ecmaVersion": 11, "ecmaVersion": 11,
"sourceType": "module" "sourceType": "module"
}, },
"plugins": ["unused-imports", "@typescript-eslint", "prettier"], "plugins": ["unused-imports", "@typescript-eslint", "prettier"],
"rules": { "rules": {
"prettier/prettier": "error", "prettier/prettier": "error",
"no-unused-vars": "off", "no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": "error", "unused-imports/no-unused-imports-ts": "error",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off" "@typescript-eslint/explicit-module-boundary-types": "off",
} "@typescript-eslint/no-non-null-assertion": "off"
} }
}

View file

@ -1,6 +1,7 @@
{ {
"trailingComma": "es5", "trailingComma": "es5",
"tabWidth": 2, "tabWidth": 2,
"printWidth": 90,
"singleQuote": true, "singleQuote": true,
"endOfLine": "lf" "endOfLine": "lf"
} }

View file

@ -4,9 +4,7 @@ import { OnLoadEvent } from './events/concrete-events/on-load-event';
export class ContainerPage extends PageElement { export class ContainerPage extends PageElement {
public constructor(rootElement: HTMLElement, children: Array<PageElement>) { public constructor(rootElement: HTMLElement, children: Array<PageElement>) {
children children.filter(e => e.element).forEach(e => rootElement.appendChild(e.element));
.filter(e => e.element)
.forEach(e => rootElement.appendChild(e.element));
super(rootElement, children); super(rootElement, children);
} }

View file

@ -26,9 +26,7 @@ export abstract class EventHandler {
return event; return event;
} }
public handleOnPageThemeChangedEvent( public handleOnPageThemeChangedEvent(event: OnPageThemeChangedEvent): OptionalEvent {
event: OnPageThemeChangedEvent
): OptionalEvent {
return event; return event;
} }
} }

View file

@ -1,6 +1,6 @@
export const getHeight = (e: HTMLElement): number => { export const getHeight = (e: HTMLElement): number => {
// ignores margin collapse // ignores margin collapse
const computedStyle = window.getComputedStyle(e); const computedStyle = getComputedStyle(e);
return ( return (
e.clientHeight + e.clientHeight +
parseInt(computedStyle.marginTop) + parseInt(computedStyle.marginTop) +

View file

@ -1,11 +1,7 @@
export type hex = string; export type hex = string;
export type rgb = [number, number, number]; export type rgb = [number, number, number];
export const mixColors = ( export const mixColors = (hexColorA: hex, hexColorB: hex, quantityA: number): hex => {
hexColorA: hex,
hexColorB: hex,
quantityA: number
): hex => {
const colorA = hexToRGB(hexColorA); const colorA = hexToRGB(hexColorA);
const colorB = hexToRGB(hexColorB); const colorB = hexToRGB(hexColorB);

View file

@ -7,9 +7,7 @@ export class Random {
public get next(): number { public get next(): number {
// result is in [0, 1) // result is in [0, 1)
return ( return ((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31;
((2 ** 31 - 1) & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31
);
} }
public choose<T>(list: Array<T>): T { public choose<T>(list: Array<T>): T {

View file

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

View file

@ -5,8 +5,7 @@ import { Event } from './events/event';
import { OnLoadEvent } from './events/concrete-events/on-load-event'; import { OnLoadEvent } from './events/concrete-events/on-load-event';
import { OptionalEvent } from './events/optional-event'; import { OptionalEvent } from './events/optional-event';
export abstract class PageElement extends EventHandler export abstract class PageElement extends EventHandler implements EventBroadcaster {
implements EventBroadcaster {
protected eventBroadcaster: EventBroadcaster; protected eventBroadcaster: EventBroadcaster;
protected constructor( protected constructor(

View file

@ -2,10 +2,7 @@ import { Primitive } from '../primitive';
import { html, url } from '../../model/misc'; import { html, url } from '../../model/misc';
export class Anchor implements Primitive { export class Anchor implements Primitive {
public constructor( public constructor(private readonly href: url, private readonly text: string) {}
private readonly href: url,
private readonly text: string
) {}
public toHTML(): html { public toHTML(): html {
return ` return `
@ -14,6 +11,7 @@ export class Anchor implements Primitive {
rel="noreferrer" rel="noreferrer"
target="_blank" target="_blank"
>${this.text}</a> >${this.text}</a>
<br/>
`; `;
} }
} }

View file

@ -26,10 +26,7 @@ export class Image implements Primitive {
return ( return (
this.image.images this.image.images
.slice(0, -1) .slice(0, -1)
.map( .map(d => `(max-width: ${d.width / Image.IMAGE_SCREEN_RATIO}px) ${d.width}px,`)
d =>
`(max-width: ${d.width / Image.IMAGE_SCREEN_RATIO}px) ${d.width}px,`
)
.join('\n') + `\n${last(this.image.images).width}px` .join('\n') + `\n${last(this.image.images).width}px`
); );
} }

View file

@ -11,9 +11,7 @@ export class Video implements Primitive {
public toHTML(container = false): string { public toHTML(container = false): string {
return ` return `
${container ? `<div class="figure-container">` : ''} ${container ? `<div class="figure-container">` : ''}
<video ${this.options} ${ <video ${this.options} ${this.poster ? `poster="${this.poster}` : ''}" >
this.poster ? `poster="${this.poster}` : ''
}" >
<source src="${this.webm}" type="video/webm"/> <source src="${this.webm}" type="video/webm"/>
<source src="${this.mp4}" type="video/mp4"/> <source src="${this.mp4}" type="video/mp4"/>
</video> </video>

View file

@ -1,6 +1,5 @@
export const isSystemLevelDarkModeEnabled = (): boolean => export const isSystemLevelDarkModeEnabled = (): boolean =>
window.matchMedia && matchMedia && matchMedia('(prefers-color-scheme: dark)').matches;
window.matchMedia('(prefers-color-scheme: dark)').matches;
export const turnOnDarkMode = () => export const turnOnDarkMode = () =>
document.body.parentElement.setAttribute('theme', 'dark'); document.body.parentElement.setAttribute('theme', 'dark');

View file

@ -17,10 +17,7 @@ export class Animation<T> {
return; return;
} }
this.elapsedTime = Math.min( this.elapsedTime = Math.min(this.elapsedTime + deltaTimeInMs, this.intervalInMs);
this.elapsedTime + deltaTimeInMs,
this.intervalInMs
);
const q = this.elapsedTime / this.intervalInMs; const q = this.elapsedTime / this.intervalInMs;
this._value = this.interpolator(this.from, this.to, q); this._value = this.interpolator(this.from, this.to, q);

View file

@ -51,22 +51,33 @@ export class PageBackground extends PageElement {
return super.handleOnBodyDimensionsChangedEvent(event); return super.handleOnBodyDimensionsChangedEvent(event);
} }
public handleOnPageThemeChangedEvent( public handleOnPageThemeChangedEvent(event: OnPageThemeChangedEvent): OptionalEvent {
event: OnPageThemeChangedEvent
): OptionalEvent {
Blob.changeTheme(event.isDark); Blob.changeTheme(event.isDark);
this.blobs.forEach(b => b.decideColor()); this.blobs.forEach(b => b.decideColor());
return super.handleOnPageThemeChangedEvent(event); return super.handleOnPageThemeChangedEvent(event);
} }
private bindListeners() { private bindListeners() {
window.addEventListener('resize', () => this.resize()); addEventListener('resize', () => this.resize());
window.addEventListener('load', e => { addEventListener('load', e => {
this.resize(); this.resize();
this.createBlobs();
this.redraw(e.timeStamp); this.redraw(e.timeStamp);
}); });
} }
private createBlobs() {
const requiredBlobCount = Math.max(
PageBackground.MIN_BLOB_COUNT,
(this.backgroundSize.value.x * this.backgroundSize.value.y) /
PageBackground.BLOB_SPACING ** 2
);
while (requiredBlobCount > this.blobs.length) {
this.blobs.push(new Blob());
}
}
private resize(heightChange?: number) { private resize(heightChange?: number) {
this.resizeCanvas(); this.resizeCanvas();
this.resizeBackground(heightChange); this.resizeBackground(heightChange);
@ -106,10 +117,7 @@ export class PageBackground extends PageElement {
q q
); );
const topOffset = variableOffset(getHeight(this.start.element), 1); const topOffset = variableOffset(getHeight(this.start.element), 1);
const topLeft = this.convertFrom2Dto3D( const topLeft = this.convertFrom2Dto3D(new Vec2(0, topOffset), blob.z);
new Vec2(0, topOffset),
blob.z
);
const bottomOffset = variableOffset(getHeight(this.end.element), 0.2); const bottomOffset = variableOffset(getHeight(this.end.element), 0.2);
@ -137,19 +145,10 @@ export class PageBackground extends PageElement {
this.blobs.forEach(b => b.step(deltaTime)); this.blobs.forEach(b => b.step(deltaTime));
this.scrollPosition = this.parent.element.scrollTop; this.scrollPosition = this.parent.element.scrollTop;
const requiredBlobCount = this.requiredBlobCount;
while (requiredBlobCount > this.blobs.length) {
this.blobs.push(new Blob());
}
this.blobs.sort((b1, b2) => b2.z - b1.z); this.blobs.sort((b1, b2) => b2.z - b1.z);
this.blobs.forEach((blob, i) => { this.blobs.forEach(blob => {
if (i >= requiredBlobCount) {
return;
}
const topLeft = this.convertFrom3Dto2D(blob.topLeft); const topLeft = this.convertFrom3Dto2D(blob.topLeft);
const bottomRight = this.convertFrom3Dto2D( const bottomRight = this.convertFrom3Dto2D(
blob.topLeft.add(Vec3.from(blob.size, 0)) blob.topLeft.add(Vec3.from(blob.size, 0))
@ -160,23 +159,18 @@ export class PageBackground extends PageElement {
} }
}); });
window.requestAnimationFrame(timestamp => this.redraw(timestamp)); requestAnimationFrame(timestamp => this.redraw(timestamp));
} }
private getDeltaTime(timestamp: DOMHighResTimeStamp): number { private getDeltaTime(timestamp: DOMHighResTimeStamp): number {
const deltaTime = this.previousTimestamp const deltaTime = this.previousTimestamp ? timestamp - this.previousTimestamp : 0;
? timestamp - this.previousTimestamp
: 0;
this.previousTimestamp = timestamp; this.previousTimestamp = timestamp;
return Math.max(0, deltaTime); return Math.max(0, deltaTime);
} }
private convertFrom3Dto2D(p: Vec3): Vec2 { private convertFrom3Dto2D(p: Vec3): Vec2 {
const m = PageBackground.PERSPECTIVE / (PageBackground.PERSPECTIVE + p.z); const m = PageBackground.PERSPECTIVE / (PageBackground.PERSPECTIVE + p.z);
return new Vec2( return new Vec2(m * (p.z / 2 + p.x), m * (p.z / 2 + p.y - this.scrollPosition));
m * (p.z / 2 + p.x),
m * (p.z / 2 + p.y - this.scrollPosition)
);
} }
private convertFrom2Dto3D(p: Vec2, z: number, scrollPosition = 0): Vec2 { private convertFrom2Dto3D(p: Vec2, z: number, scrollPosition = 0): Vec2 {
@ -192,14 +186,4 @@ export class PageBackground extends PageElement {
(0 <= bottomRight.y && bottomRight.y <= this.canvas.height)) (0 <= bottomRight.y && bottomRight.y <= this.canvas.height))
); );
} }
private get requiredBlobCount(): number {
return Math.max(
PageBackground.MIN_BLOB_COUNT,
Math.round(
(this.backgroundSize.value.x * this.backgroundSize.value.y) /
PageBackground.BLOB_SPACING ** 2
)
);
}
} }

View file

@ -32,10 +32,7 @@ export class Blob {
private _positionScale = new Vec2(0, 0); private _positionScale = new Vec2(0, 0);
private _positionOffset = new Vec2(0, 0); private _positionOffset = new Vec2(0, 0);
private readonly _size = new Vec2( private readonly _size = new Vec2(140, Blob.CREATOR_RANDOM.randomInInterval(260, 740));
140,
Blob.CREATOR_RANDOM.randomInInterval(260, 740)
);
public constructor() { public constructor() {
this.decideColor(); this.decideColor();
@ -47,8 +44,7 @@ export class Blob {
Blob.colorPickerRandom.choose( Blob.colorPickerRandom.choose(
Blob.isDarkThemed ? Blob.DARK_COLORS : Blob.LIGHT_COLORS Blob.isDarkThemed ? Blob.DARK_COLORS : Blob.LIGHT_COLORS
), ),
(this.z - PageBackground.Z_MIN) / (this.z - PageBackground.Z_MIN) / (PageBackground.Z_MAX - PageBackground.Z_MIN)
(PageBackground.Z_MAX - PageBackground.Z_MIN)
); );
this.color = new Animation<string>( this.color = new Animation<string>(

View file

@ -18,9 +18,7 @@ export class PageImageViewer extends PageElement {
media media
.filter((e: HTMLElement) => e.parentElement !== this.element) .filter((e: HTMLElement) => e.parentElement !== this.element)
.forEach( .forEach((e: HTMLImageElement) => (e.onclick = this.handleClick.bind(this)));
(e: HTMLImageElement) => (e.onclick = this.handleClick.bind(this))
);
return super.handleOnLoadEvent(event); return super.handleOnLoadEvent(event);
} }

View file

@ -21,8 +21,7 @@ export class PageThemeSwitcher extends PageElement {
super(createElement(generate())); super(createElement(generate()));
const storedIsDark = PageThemeSwitcher.loadFromLocalStorage(); const storedIsDark = PageThemeSwitcher.loadFromLocalStorage();
const isDark = const isDark = storedIsDark !== null ? storedIsDark : isSystemLevelDarkModeEnabled();
storedIsDark !== null ? storedIsDark : isSystemLevelDarkModeEnabled();
if (isDark) { if (isDark) {
(this.element as HTMLInputElement).checked = true; (this.element as HTMLInputElement).checked = true;
@ -53,7 +52,7 @@ export class PageThemeSwitcher extends PageElement {
} }
private static saveToLocalStorage(darkModeEnabled: boolean) { private static saveToLocalStorage(darkModeEnabled: boolean) {
window.localStorage?.setItem( localStorage?.setItem(
PageThemeSwitcher.LOCAL_STORAGE_KEY, PageThemeSwitcher.LOCAL_STORAGE_KEY,
JSON.stringify(darkModeEnabled) JSON.stringify(darkModeEnabled)
); );
@ -61,9 +60,7 @@ export class PageThemeSwitcher extends PageElement {
private static loadFromLocalStorage(): boolean | null { private static loadFromLocalStorage(): boolean | null {
try { try {
return JSON.parse( return JSON.parse(localStorage?.getItem(PageThemeSwitcher.LOCAL_STORAGE_KEY));
window.localStorage?.getItem(PageThemeSwitcher.LOCAL_STORAGE_KEY)
);
} catch { } catch {
return null; return null;
} }

View file

@ -0,0 +1 @@
<svg enable-background="new 0 0 482.239 482.239" height="512" viewBox="0 0 482.239 482.239" width="512" xmlns="http://www.w3.org/2000/svg"><path d="m0 17.223v120.56h34.446v-103.337h103.337v-34.446h-120.56c-9.52 0-17.223 7.703-17.223 17.223z"/><path d="m465.016 0h-120.56v34.446h103.337v103.337h34.446v-120.56c0-9.52-7.703-17.223-17.223-17.223z"/><path d="m447.793 447.793h-103.337v34.446h120.56c9.52 0 17.223-7.703 17.223-17.223v-120.56h-34.446z"/><path d="m34.446 344.456h-34.446v120.56c0 9.52 7.703 17.223 17.223 17.223h120.56v-34.446h-103.337z"/></svg>

After

Width:  |  Height:  |  Size: 555 B

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<path d="M256,0C114.833,0,0,114.844,0,256s114.833,256,256,256s256-114.844,256-256S397.167,0,256,0z M256,490.667
C126.604,490.667,21.333,385.396,21.333,256S126.604,21.333,256,21.333S490.667,126.604,490.667,256S385.396,490.667,256,490.667
z"/>
<path d="M357.771,247.031l-149.333-96c-3.271-2.135-7.5-2.25-10.875-0.396C194.125,152.51,192,156.094,192,160v192
c0,3.906,2.125,7.49,5.563,9.365c1.583,0.865,3.354,1.302,5.104,1.302c2,0,4.021-0.563,5.771-1.698l149.333-96
c3.042-1.958,4.896-5.344,4.896-8.969S360.813,248.99,357.771,247.031z M213.333,332.458V179.542L332.271,256L213.333,332.458z"
/>
</svg>

After

Width:  |  Height:  |  Size: 880 B

BIN
src/static/media/sdf2d.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View file

@ -52,23 +52,19 @@ html {
hyphens: auto; hyphens: auto;
} }
img,
video,
.figure-container {
width: 100%;
height: auto;
}
.figure-container { .figure-container {
font-size: 0; font-size: 0;
box-shadow: var(--inset-shadow); box-shadow: var(--inset-shadow);
pointer-events: none; pointer-events: none;
cursor: pointer; cursor: pointer;
* { img,
video,
iframe {
pointer-events: all; pointer-events: all;
position: relative; position: relative;
z-index: -2; z-index: -2;
width: 100%;
} }
} }