apply "prettier" styling

This commit is contained in:
Jörn-Michael Miehe 2023-09-07 01:17:14 +00:00
parent 4be3e38962
commit 40284c4061
17 changed files with 147 additions and 93 deletions

View file

@ -51,7 +51,7 @@ export default class extends Vue {
"days/visible_days", "days/visible_days",
(visible_days: number) => { (visible_days: number) => {
this.visible_days = visible_days; this.visible_days = visible_days;
} },
); );
} }
} }

View file

@ -1,8 +1,12 @@
<template> <template>
<nav class="breadcrumb has-succeeds-separator"> <nav class="breadcrumb has-succeeds-separator">
<ul> <ul>
<li v-for="(step, index) in steps" :key="`step-${index}`" :class="modelValue === index ? 'is-active' : ''" <li
@click="change_step(index)"> v-for="(step, index) in steps"
:key="`step-${index}`"
:class="modelValue === index ? 'is-active' : ''"
@click="change_step(index)"
>
<a> <a>
<span class="icon is-small"> <span class="icon is-small">
<font-awesome-icon :icon="step.icon" /> <font-awesome-icon :icon="step.icon" />

View file

@ -5,8 +5,14 @@
<figure class="image"> <figure class="image">
<img :src="$advent22.api_url('general/background')" /> <img :src="$advent22.api_url('general/background')" />
<ThouCanvas> <ThouCanvas>
<CalendarDoor v-for="(_, index) in doors" :key="`door-${index}`" :door="doors[index]" @doorClick="door_click" <CalendarDoor
@doorSuccess="door_success" @doorFailure="door_failure" /> v-for="(_, index) in doors"
:key="`door-${index}`"
:door="doors[index]"
@doorClick="door_click"
@doorSuccess="door_success"
@doorFailure="door_failure"
/>
</ThouCanvas> </ThouCanvas>
</figure> </figure>
</section> </section>

View file

@ -16,11 +16,7 @@ import SVGRect from "./rects/SVGRect.vue";
props: { props: {
door: Door, door: Door,
}, },
emits: [ emits: ["doorClick", "doorSuccess", "doorFailure"],
"doorClick",
"doorSuccess",
"doorFailure",
],
}) })
export default class extends Vue { export default class extends Vue {
public door!: Door; public door!: Door;
@ -35,9 +31,9 @@ export default class extends Vue {
let msg = "Unbekannter Fehler, bitte wiederholen!"; let msg = "Unbekannter Fehler, bitte wiederholen!";
if ( if (
(reason instanceof AxiosError) reason instanceof AxiosError &&
&& (reason.response !== undefined) reason.response !== undefined &&
&& (reason.response.status === 401) reason.response.status === 401
) { ) {
msg = "Netter Versuch :)"; msg = "Netter Versuch :)";
} }

View file

@ -13,7 +13,11 @@
<figure class="image"> <figure class="image">
<img :src="$advent22.api_url('general/background')" /> <img :src="$advent22.api_url('general/background')" />
<ThouCanvas> <ThouCanvas>
<PreviewDoor v-for="(_, index) in doors" :key="`door-${index}`" v-model:door="doors[index]" /> <PreviewDoor
v-for="(_, index) in doors"
:key="`door-${index}`"
v-model:door="doors[index]"
/>
</ThouCanvas> </ThouCanvas>
</figure> </figure>
</section> </section>

View file

@ -10,7 +10,12 @@
</div> </div>
<figure class="image"> <figure class="image">
<img :src="$advent22.api_url('general/background')" /> <img :src="$advent22.api_url('general/background')" />
<RectangleCanvas :rectangles="rectangles" @draw="on_draw" @drag="on_drag" @remove="on_remove" /> <RectangleCanvas
:rectangles="rectangles"
@draw="on_draw"
@drag="on_drag"
@remove="on_remove"
/>
</figure> </figure>
</section> </section>
</template> </template>

View file

@ -1,12 +1,27 @@
<template> <template>
<SVGRect :rectangle="door.position" :focused="editing" /> <SVGRect :rectangle="door.position" :focused="editing" />
<foreignObject :x="Math.round(parent_aspect_ratio * door.position.left)" :y="door.position.top" <foreignObject
:width="Math.round(parent_aspect_ratio * door.position.width)" :height="door.position.height" :x="Math.round(parent_aspect_ratio * door.position.left)"
:style="`transform: scaleX(${1 / parent_aspect_ratio})`"> :y="door.position.top"
<div xmlns="http://www.w3.org/1999/xhtml" class="is-flex is-align-items-center is-justify-content-center" :width="Math.round(parent_aspect_ratio * door.position.width)"
@click.left="on_click"> :height="door.position.height"
<input v-if="editing" v-model="day_str" ref="day_input" class="input is-large" type="number" min="-1" :style="`transform: scaleX(${1 / parent_aspect_ratio})`"
placeholder="Tag" @keydown="on_keydown" /> >
<div
xmlns="http://www.w3.org/1999/xhtml"
class="is-flex is-align-items-center is-justify-content-center"
@click.left="on_click"
>
<input
v-if="editing"
v-model="day_str"
ref="day_input"
class="input is-large"
type="number"
min="-1"
placeholder="Tag"
@keydown="on_keydown"
/>
<div v-else class="is-size-1 has-text-weight-bold"> <div v-else class="is-size-1 has-text-weight-bold">
<template v-if="door.day >= 0">{{ door.day }}</template> <template v-if="door.day >= 0">{{ door.day }}</template>
</div> </div>

View file

@ -1,7 +1,18 @@
<template> <template>
<ThouCanvas @mousedown.left="draw_start" @mouseup.left="draw_finish" @mousedown.right="drag_start" <ThouCanvas
@mouseup.right="drag_finish" @mousemove="on_mousemove" @click.middle="remove_rect" @dblclick.left="remove_rect"> @mousedown.left="draw_start"
<SVGRect v-for="(rect, index) in rectangles" :key="`rect-${index}`" :rectangle="rect" /> @mouseup.left="draw_finish"
@mousedown.right="drag_start"
@mouseup.right="drag_finish"
@mousemove="on_mousemove"
@click.middle="remove_rect"
@dblclick.left="remove_rect"
>
<SVGRect
v-for="(rect, index) in rectangles"
:key="`rect-${index}`"
:rectangle="rect"
/>
<SVGRect v-if="preview_visible" :focused="true" :rectangle="preview_rect" /> <SVGRect v-if="preview_visible" :focused="true" :rectangle="preview_rect" />
</ThouCanvas> </ThouCanvas>
</template> </template>

View file

@ -10,7 +10,7 @@ export class Door {
} }
public get day(): number { public get day(): number {
return this._day return this._day;
} }
public set day(day: unknown) { public set day(day: unknown) {

View file

@ -1,6 +1,11 @@
<template> <template>
<rect :class="focused ? 'focus' : ''" :x="rectangle.left" :y="rectangle.top" :width="rectangle.width" <rect
:height="rectangle.height" /> :class="focused ? 'focus' : ''"
:x="rectangle.left"
:y="rectangle.top"
:width="rectangle.width"
:height="rectangle.height"
/>
</template> </template>
<script lang="ts"> <script lang="ts">

View file

@ -1,7 +1,16 @@
<template> <template>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 1000 1000" preserveAspectRatio="none" <svg
@contextmenu.prevent @mousedown="transform_mouse_event" @mousemove="transform_mouse_event" xmlns="http://www.w3.org/2000/svg"
@mouseup="transform_mouse_event" @click="transform_mouse_event" @dblclick="transform_mouse_event"> version="1.1"
viewBox="0 0 1000 1000"
preserveAspectRatio="none"
@contextmenu.prevent
@mousedown="transform_mouse_event"
@mousemove="transform_mouse_event"
@mouseup="transform_mouse_event"
@click="transform_mouse_event"
@dblclick="transform_mouse_event"
>
<slot name="default" /> <slot name="default" />
</svg> </svg>
</template> </template>
@ -19,7 +28,7 @@ function get_event_thous(event: MouseEvent): Vector2D {
return new Vector2D( return new Vector2D(
Math.round((event.offsetX / target.clientWidth) * 1000), Math.round((event.offsetX / target.clientWidth) * 1000),
Math.round((event.offsetY / target.clientHeight) * 1000) Math.round((event.offsetY / target.clientHeight) * 1000),
); );
} }

View file

@ -20,8 +20,7 @@ export class Vector2D {
} }
public equals(other: Vector2D): boolean { public equals(other: Vector2D): boolean {
return this.x === other.x && return this.x === other.x && this.y === other.y;
this.y === other.y;
} }
} }
@ -38,7 +37,7 @@ export class Rectangle {
return new Vector2D( return new Vector2D(
Math.min(this.corner_1.x, this.corner_2.x), Math.min(this.corner_1.x, this.corner_2.x),
Math.min(this.corner_1.y, this.corner_2.y), Math.min(this.corner_1.y, this.corner_2.y),
) );
} }
public get left(): number { public get left(): number {
@ -53,7 +52,7 @@ export class Rectangle {
return new Vector2D( return new Vector2D(
Math.max(this.corner_1.x, this.corner_2.x), Math.max(this.corner_1.x, this.corner_2.x),
Math.max(this.corner_1.y, this.corner_2.y), Math.max(this.corner_1.y, this.corner_2.y),
) );
} }
public get size(): Vector2D { public get size(): Vector2D {
@ -69,7 +68,7 @@ export class Rectangle {
} }
public get middle(): Vector2D { public get middle(): Vector2D {
return this.origin.plus(this.size.scale(0.5)) return this.origin.plus(this.size.scale(0.5));
} }
public get area(): number { public get area(): number {
@ -77,22 +76,20 @@ export class Rectangle {
} }
public equals(other: Rectangle): boolean { public equals(other: Rectangle): boolean {
return this.origin.equals(other.origin) && return this.origin.equals(other.origin) && this.corner.equals(other.corner);
this.corner.equals(other.corner);
} }
public contains(point: Vector2D): boolean { public contains(point: Vector2D): boolean {
return point.x >= this.origin.x && return (
point.x >= this.origin.x &&
point.y >= this.origin.y && point.y >= this.origin.y &&
point.x <= this.corner.x && point.x <= this.corner.x &&
point.y <= this.corner.y; point.y <= this.corner.y
);
} }
public update(corner_1?: Vector2D, corner_2?: Vector2D): Rectangle { public update(corner_1?: Vector2D, corner_2?: Vector2D): Rectangle {
return new Rectangle( return new Rectangle(corner_1 || this.corner_1, corner_2 || this.corner_2);
corner_1 || this.corner_1,
corner_2 || this.corner_2,
);
} }
public move(vector: Vector2D): Rectangle { public move(vector: Vector2D): Rectangle {

View file

@ -1,6 +1,6 @@
/* eslint-disable */ /* eslint-disable */
declare module '*.vue' { declare module "*.vue" {
import type { DefineComponent } from 'vue' import type { DefineComponent } from "vue";
const component: DefineComponent<{}, {}, any> const component: DefineComponent<{}, {}, any>;
export default component export default component;
} }

View file

@ -1,12 +1,12 @@
import { Advent22Plugin } from "@/plugins/advent22" import { Advent22Plugin } from "@/plugins/advent22";
import { FontAwesomePlugin } from "@/plugins/fontawesome" import { FontAwesomePlugin } from "@/plugins/fontawesome";
import { createApp } from 'vue' import { createApp } from "vue";
import App from './App.vue' import App from "./App.vue";
import "@/main.scss" import "@/main.scss";
const app = createApp(App) const app = createApp(App);
app.use(Advent22Plugin) app.use(Advent22Plugin);
app.use(FontAwesomePlugin) app.use(FontAwesomePlugin);
app.mount('#app') app.mount("#app");

View file

@ -1,5 +1,5 @@
import axios, { AxiosInstance, ResponseType } from 'axios'; import axios, { AxiosInstance, ResponseType } from "axios";
import { App, Plugin } from 'vue'; import { App, Plugin } from "vue";
export class Advent22 { export class Advent22 {
private axios: AxiosInstance; private axios: AxiosInstance;
@ -13,7 +13,6 @@ export class Advent22 {
// in production mode, return "//host/api" // in production mode, return "//host/api"
if (process.env.NODE_ENV === "production") { if (process.env.NODE_ENV === "production") {
return `//${window.location.host}/api`; return `//${window.location.host}/api`;
} else if (process.env.NODE_ENV !== "development") { } else if (process.env.NODE_ENV !== "development") {
// not in prouction or development mode // not in prouction or development mode
console.warn("Unexpected NODE_ENV value"); console.warn("Unexpected NODE_ENV value");
@ -24,11 +23,13 @@ export class Advent22 {
} }
public api_url(endpoint?: string): string { public api_url(endpoint?: string): string {
if (endpoint === undefined) if (endpoint === undefined) {
return this.api_baseurl; return this.api_baseurl;
}
while (endpoint.startsWith('/')) while (endpoint.startsWith("/")) {
endpoint = endpoint.substring(1); endpoint = endpoint.substring(1);
}
return `${this.api_baseurl}/${endpoint}`; return `${this.api_baseurl}/${endpoint}`;
} }
@ -52,7 +53,8 @@ export class Advent22 {
responseType: responseType, responseType: responseType,
}; };
this.axios.get<T>(this.api_url(endpoint), req_data) this.axios
.get<T>(this.api_url(endpoint), req_data)
.then((response) => on_success(response.data)) .then((response) => on_success(response.data))
.catch((reason) => on_failure(endpoint, reason)); .catch((reason) => on_failure(endpoint, reason));
} }
@ -68,12 +70,12 @@ export class Advent22 {
const reader = new FileReader(); const reader = new FileReader();
reader.readAsDataURL(data); reader.readAsDataURL(data);
reader.onloadend = () => { reader.onloadend = () => {
if (typeof reader.result === "string") if (typeof reader.result === "string") {
on_success(reader.result); on_success(reader.result);
} else {
else
on_failure(endpoint, "failed data url"); on_failure(endpoint, "failed data url");
} }
};
}, },
on_failure, on_failure,
"blob", "blob",
@ -112,5 +114,5 @@ export class Advent22 {
export const Advent22Plugin: Plugin = { export const Advent22Plugin: Plugin = {
install(app: App) { install(app: App) {
app.config.globalProperties.$advent22 = new Advent22(); app.config.globalProperties.$advent22 = new Advent22();
} },
} };

View file

@ -1,20 +1,20 @@
import { App, Plugin } from 'vue'; import { App, Plugin } from "vue";
/* import the fontawesome core */ /* import the fontawesome core */
import { library } from '@fortawesome/fontawesome-svg-core'; import { library } from "@fortawesome/fontawesome-svg-core";
/* import specific icons */ /* import specific icons */
import { fab } from '@fortawesome/free-brands-svg-icons'; import { fab } from "@fortawesome/free-brands-svg-icons";
import { fas } from '@fortawesome/free-solid-svg-icons'; import { fas } from "@fortawesome/free-solid-svg-icons";
/* add icons to the library */ /* add icons to the library */
library.add(fas, fab); library.add(fas, fab);
/* import font awesome icon component */ /* import font awesome icon component */
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
export const FontAwesomePlugin: Plugin = { export const FontAwesomePlugin: Plugin = {
install(app: App) { install(app: App) {
app.component('font-awesome-icon', FontAwesomeIcon); app.component("font-awesome-icon", FontAwesomeIcon);
} },
} };